Changeset 7756
- Timestamp:
- Dec 11, 2010, 9:07:55 PM (14 years ago)
- Location:
- code/branches/presentation/src/libraries/network
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation/src/libraries/network/MasterServer.cc
r7750 r7756 185 185 packet::ServerInformation( event ).getServerIP() << "\n"; 186 186 } 187 188 /* TODO add hook for disconnect here */ 187 189 } 188 190 else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT, … … 218 220 } 219 221 222 /* TODO schedule pings for servers somewhere here */ 220 223 221 224 /* create an iterator for the loop */ -
code/branches/presentation/src/libraries/network/MasterServerComm.cc
r7745 r7756 38 38 } 39 39 40 41 40 int MasterServerComm::initialize() 42 41 { … … 52 51 /* install atexit handler for enet */ 53 52 atexit( enet_deinitialize ); 54 55 53 56 54 /* initiate the client */ … … 87 85 if (this->peer == NULL ) 88 86 { COUT(2) << "ERROR: No available peers for initiating an ENet connection.\n"; 89 return -1;87 return -1; 90 88 } 91 89 … … 102 100 } 103 101 104 return 0; 105 } 106 107 int MasterServerComm::pollForReply( int (*callback)( char*, ENetEvent* ) ) 102 /* all fine */ 103 return 0; 104 } 105 106 /* NOTE this is to be reimplemented soon to return 107 * a structure containing 108 * - addrconv 109 * - the event 110 * so we can also make callbacks from objects 111 */ 112 int MasterServerComm::pollForReply( int (*callback)( char*, ENetEvent* ), 113 int delayms ) 108 114 { 109 115 /* see whether anything happened */ … … 117 123 /* enet_host_service returns 0 if no event occured */ 118 124 /* just newly set below test to >0 from >= 0, to be tested */ 119 if( enet_host_service( this->client, this->event, 1000) > 0 )125 if( enet_host_service( this->client, this->event, delayms ) > 0 ) 120 126 { 121 127 /* check what type of event it is and react accordingly */ … … 140 146 141 147 /* DEBUG */ 142 COUT(3) << "A packet of length " << this->event->packet->dataLength 148 COUT(3) << "MasterServer Debug: A packet of length " 149 << this->event->packet->dataLength 143 150 << " containing " << this->event->packet->data 144 151 << " was received from " << addrconv 145 152 << " on channel " << this->event->channelID; 146 //printf( "A packet of length %u containing %s was "147 //"received from %s on channel %u.\n",148 //this->event->packet->dataLength,149 //this->event->packet->data,150 //addrconv,151 //this->event->channelID );152 153 /* END DEBUG */ 153 154 … … 156 157 retval = (*callback)( addrconv, (this->event) ); 157 158 159 /* clean up */ 158 160 enet_packet_destroy( event->packet ); 159 if( addrconv ) free( addrconv ); 161 if( addrconv ) 162 free( addrconv ); 163 160 164 break; 161 165 default: break; … … 211 215 212 216 } 213 214 215 /* DON'T DELETE THIS I MIGHT NEED IT AGAIN -smerkli */216 /* not needed anymore, only here for testing purposes */217 /*218 //[> sample callback to output debugging info. <]219 //int callb( char *addr, ENetEvent *ev )220 //{221 //printf( "A packet of length %u containing %s was "222 //"received from %s on channel %u.\n",223 //ev->packet->dataLength,224 //ev->packet->data,225 //addr,226 //ev->channelID );227 //return 0;228 //}229 230 //[> small testing implementation <]231 //int232 //main( int argc, char *argv[] )233 //{234 //[> setup object and connect <]235 //MasterServerComm msc = MasterServerComm();236 //if( msc.connect( argv[1], 1234 ) )237 //exit(EXIT_FAILURE);238 239 //[> send some data and poll for replies <]240 //char *theinput = (char *)calloc( 100,1 );241 //while( true )242 //{243 //fgets( theinput, 90, stdin );244 //if( !strncmp( theinput, "quit", 4 ) )245 //break;246 247 //msc.sendRequest( theinput );248 //msc.pollForReply( &callb );249 //}250 251 //}252 */ -
code/branches/presentation/src/libraries/network/MasterServerComm.h
r7745 r7756 81 81 * 82 82 * Poll the master server for new data and act accordingly */ 83 int pollForReply( int (*callback)( char*, ENetEvent* ) );83 int pollForReply( int (*callback)( char*, ENetEvent* ), int delayms ); 84 84 85 85 private: -
code/branches/presentation/src/libraries/network/MasterServerProtocol.h
r7750 r7756 33 33 #define MS_ADDRESS "129.132.3.8" 34 34 35 36 /*** CLIENT COMMUNICATIONS ***/ 35 37 /* Client token (shows that the party sending data is a client */ 36 38 #define MSPROTO_CLIENT "CL" … … 44 46 45 47 48 /*** GAME SERVER COMMUNICATIONS ***/ 46 49 /* Game server token (shows that the party sending data is a game server) */ 47 50 #define MSPROTO_GAME_SERVER "GS" … … 62 65 #define MSPROTO_SERVERLIST_END_LEN 6 63 66 67 /* ping request from server */ 68 #define MSPROTO_PING_GAMESERVER "PING" 69 #define MSPROTO_PING_GAMESERVER_LEN 4 70 71 /* ping reply */ 72 #define MSPROTO_ACK "ACK" 73 #define MSPROTO_ACK_LEN 3 74 64 75 65 76 -
code/branches/presentation/src/libraries/network/Server.cc
r7750 r7756 134 134 135 135 /* make discoverable on WAN */ 136 /* TODO this needs to be optional, we need a switch from the UI to 137 * enable/disable this 138 */ 136 139 helper_ConnectToMasterserver(); 137 140 … … 169 172 170 173 171 /* TODO*/174 /* handle incoming data */ 172 175 int rephandler( char *addr, ENetEvent *ev ) 173 176 { 174 /* handle incoming data */ 175 /* TODO this is to be implemented. */ 177 /* reply to pings */ 178 if( !strncmp( (char *)ev->packet->data, MSPROTO_PING_GAMESERVER, 179 MSPROTO_PING_GAMESERVER_LEN ) ) 180 //this->msc.sendRequest( MSPROTO_ACK ); 181 /* NOTE implement this after pollForReply 182 * reimplementation 183 */ 184 return 0; 176 185 177 186 /* done handling, return all ok code 0 */ … … 184 193 * has to be done or changed. 185 194 */ 186 this->msc.pollForReply( rephandler );195 this->msc.pollForReply( rephandler, 10 ); 187 196 } 188 197 -
code/branches/presentation/src/libraries/network/WANDiscovery.cc
r7750 r7756 133 133 { 134 134 /* poll for reply and act according to what was received */ 135 switch( this->msc.pollForReply( rhandler ) )135 switch( this->msc.pollForReply( rhandler, 1000 ) ) 136 136 { case 0: /* no event occured, decrease timeout */ 137 137 --i; break;
Note: See TracChangeset
for help on using the changeset viewer.