Changeset 7793
- Timestamp:
- Dec 22, 2010, 3:05:31 AM (14 years ago)
- Location:
- code/branches/presentation2/src/libraries/network
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/libraries/network/CMakeLists.txt
r7788 r7793 32 32 LANDiscoverable.cc 33 33 LANDiscovery.cc 34 WANDiscoverable.cc 34 35 WANDiscovery.cc 35 36 MasterServerComm.cc … … 59 60 LANDiscoverable.h 60 61 LANDiscovery.h 62 WANDiscoverable.h 61 63 WANDiscovery.h 62 64 MasterServerComm.h -
code/branches/presentation2/src/libraries/network/Connection.cc
r7788 r7793 112 112 void Connection::communicationThread() 113 113 { 114 COUT(0) << "starting communication thread" << endl;115 114 ENetEvent event; 116 115 -
code/branches/presentation2/src/libraries/network/MasterServerComm.cc
r7788 r7793 48 48 49 49 /* initialize the event holder */ 50 this->event = (ENetEvent *)calloc( sizeof(ENetEvent), 1 );50 // this->event = (ENetEvent *)calloc( sizeof(ENetEvent), 1 ); 51 51 52 52 … … 90 90 91 91 /* Wait up to 2 seconds for the connection attempt to succeed. */ 92 if (enet_host_service (this->client, this->event, 500) > 0 &&93 this->event ->type == ENET_EVENT_TYPE_CONNECT )92 if (enet_host_service (this->client, &this->event, 500) > 0 && 93 this->event.type == ENET_EVENT_TYPE_CONNECT ) 94 94 COUT(3) << "Connection to master server succeeded.\n"; 95 95 else … … 103 103 return 0; 104 104 } 105 106 void MasterServerComm::update() 107 { 108 while( enet_host_service( this->client, &this->event, 1 ) ); 109 } 110 105 111 106 112 int MasterServerComm::disconnect( void ) 107 113 { 114 while( enet_host_service( this->client, &this->event, 1 ) ); 108 115 enet_peer_disconnect( this->peer, 0 ); 109 116 … … 111 118 * and drop any packets received packets. 112 119 */ 113 while (enet_host_service (this->client, this->event, 1000) > 0)120 while (enet_host_service (this->client, &this->event, 1000) > 0) 114 121 { 115 switch (this->event ->type)122 switch (this->event.type) 116 123 { 117 124 case ENET_EVENT_TYPE_RECEIVE: 118 enet_packet_destroy (event ->packet);125 enet_packet_destroy (event.packet); 119 126 break; 120 127 … … 154 161 /* enet_host_service returns 0 if no event occured */ 155 162 /* just newly set below test to >0 from >= 0, to be tested */ 156 if( enet_host_service( this->client, this->event, delayms ) > 0 )163 if( enet_host_service( this->client, &this->event, delayms ) > 0 ) 157 164 { 158 165 /* check what type of event it is and react accordingly */ 159 switch (this->event ->type)166 switch (this->event.type) 160 167 { /* new connection, not supposed to happen. */ 161 168 case ENET_EVENT_TYPE_CONNECT: break; … … 173 180 174 181 /* resolve IP */ 175 enet_address_get_host_ip( &(this->event ->peer->address),182 enet_address_get_host_ip( &(this->event.peer->address), 176 183 addrconv, 49 ); 177 184 178 185 /* DEBUG */ 179 186 COUT(3) << "MasterServer Debug: A packet of length " 180 << this->event ->packet->dataLength181 << " containing " << this->event ->packet->data187 << this->event.packet->dataLength 188 << " containing " << this->event.packet->data 182 189 << " was received from " << addrconv 183 << " on channel " << this->event ->channelID;190 << " on channel " << this->event.channelID; 184 191 /* END DEBUG */ 185 192 186 193 /* call the supplied callback, if any. */ 187 194 if( (*callback) != NULL ) 188 retval = (*callback)( addrconv, (this->event) );195 retval = (*callback)( addrconv, &(this->event) ); 189 196 190 197 /* clean up */ 191 enet_packet_destroy( event ->packet );198 enet_packet_destroy( event.packet ); 192 199 if( addrconv ) 193 200 free( addrconv ); … … 220 227 221 228 /* free the packet */ 222 enet_packet_destroy( packet ); 229 // PLEASE: never do this, because enet will free the packet once it's delivered. this will cause double frees 230 // enet_packet_destroy( packet ); 223 231 224 232 /* all done. */ … … 239 247 /* One could just use enet_host_service() instead. */ 240 248 enet_host_flush( this->client ); 241 enet_packet_destroy( packet ); 249 // PLEASE: never do this, because enet will free the packet once it's delivered. this will cause double frees 250 // enet_packet_destroy( packet ); 242 251 243 252 /* all done. */ -
code/branches/presentation2/src/libraries/network/MasterServerComm.h
r7770 r7793 53 53 */ 54 54 int initialize(); 55 56 void update(); 55 57 56 58 … … 92 94 private: 93 95 /** client handle */ 94 ENetHost *client;96 ENetHost* client; 95 97 96 98 /** event data holder */ 97 ENetEvent *event;99 ENetEvent event; 98 100 99 101 /** address holder */ … … 101 103 102 104 /** peer data holder */ 103 ENetPeer *peer;105 ENetPeer* peer; 104 106 }; 105 107 -
code/branches/presentation2/src/libraries/network/Server.cc
r7788 r7793 104 104 void Server::helper_ConnectToMasterserver() 105 105 { 106 WANDiscovery::getInstance().msc.sendRequest( MSPROTO_GAME_SERVER " "107 MSPROTO_REGISTER_SERVER );106 // WANDiscovery::getInstance().msc.sendRequest( MSPROTO_GAME_SERVER " " 107 // MSPROTO_REGISTER_SERVER ); 108 108 } 109 109 … … 121 121 122 122 /* make discoverable on WAN */ 123 WANDiscoverable::setActivity(true); 123 124 /* TODO this needs to be optional, we need a switch from the UI to 124 125 * enable/disable this 125 126 */ 126 helper_ConnectToMasterserver();127 // helper_ConnectToMasterserver(); 127 128 128 129 /* done */ … … 142 143 /* tell master server we're closing */ 143 144 COUT(2) << "disconnecting." << endl; 144 WANDiscovery::getInstance().msc.sendRequest( MSPROTO_GAME_SERVER " " 145 MSPROTO_SERVERDC ); 145 WANDiscoverable::setActivity(false); 146 146 COUT(2) << "disconnecting done" << endl; 147 147 … … 202 202 // receive and process incoming discovery packets 203 203 LANDiscoverable::update(); 204 204 205 205 // receive and process requests from master server 206 206 /* todo */ -
code/branches/presentation2/src/libraries/network/Server.h
r7788 r7793 40 40 #include "ServerConnection.h" 41 41 #include "LANDiscoverable.h" 42 #include "MasterServerComm.h" 43 #include "MasterServerProtocol.h" 42 #include "WANDiscoverable.h" 43 // #include "MasterServerComm.h" 44 // #include "MasterServerProtocol.h" 44 45 45 46 … … 51 52 * It implements all functions necessary for a Server 52 53 */ 53 class _NetworkExport Server : public Host, public ServerConnection, public LANDiscoverable{ 54 class _NetworkExport Server : public Host, public ServerConnection, public LANDiscoverable, public WANDiscoverable 55 { 54 56 public: 55 57 Server(); -
code/branches/presentation2/src/libraries/network/packet/ServerInformation.cc
r7745 r7793 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Oliver Scheuss 24 24 * Co-authors: 25 25 * ... … … 60 60 61 61 /* Fabian, what is this used for? it crashes the masterserver, hence commenting it */ 62 //assert(strcmp(ack, (const char*)LAN_DISCOVERY_ACK)==0); 62 // written by Oli: this is just to make sure that loadAndIncrease really writes the whole ACK string into char* ack 63 // assert(strcmp(ack, (const char*)LAN_DISCOVERY_ACK)==0); 63 64 64 65 // Save Server Name -
code/branches/presentation2/src/libraries/network/packet/ServerInformation.h
r7739 r7793 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Oliver Scheuss 24 24 * Co-authors: 25 25 * ...
Note: See TracChangeset
for help on using the changeset viewer.