Changeset 7650 for code/branches/masterserver/src/libraries/network
- Timestamp:
- Nov 17, 2010, 4:05:13 PM (14 years ago)
- Location:
- code/branches/masterserver/src/libraries/network
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/masterserver/src/libraries/network/MasterServerComm.cc
r7632 r7650 111 111 /* address buffer */ 112 112 char *addrconv = NULL; 113 int retval = 0; 113 114 114 115 /* check what type of event it is and react accordingly */ … … 136 137 /* call the supplied callback, if any. */ 137 138 if( (*callback) != NULL ) 138 (*callback)( addrconv, &(this->event) );139 retval = (*callback)( addrconv, &(this->event) ); 139 140 140 141 enet_packet_destroy( event.packet ); … … 145 146 146 147 /* event handled, return 0 */ 147 return 0;148 return retval; 148 149 } 149 150 … … 158 159 ENetPacket * packet = enet_packet_create( data, 159 160 strlen( data ) + 1, 161 ENET_PACKET_FLAG_RELIABLE); 162 163 /* Send the packet to the peer over channel id 0. */ 164 enet_peer_send (this->peer, 0, packet); 165 166 /* One could just use enet_host_service() instead. */ 167 enet_host_flush( this->client ); 168 if( packet ) free( packet ); 169 170 /* all done. */ 171 return 0; 172 } 173 174 int MasterServerComm::sendRequest( std::string data ) 175 { 176 /* send the data to the friend */ 177 /* Create a reliable packet of size 7 containing "packet\0" */ 178 ENetPacket * packet = enet_packet_create( data.c_str(), 179 data.length() + 1, 160 180 ENET_PACKET_FLAG_RELIABLE); 161 181 -
code/branches/masterserver/src/libraries/network/MasterServerComm.h
r7631 r7650 29 29 #include <cstdlib> 30 30 #include <cstdio> 31 #include <string> 31 32 #include <cstring> 32 33 #include <enet/enet.h> … … 65 66 int sendRequest( char *data ); 66 67 68 /** \param data The data to be sent. 69 * \return 0 for success, other for error. 70 * 71 * Send a request to the master server containing data specified in data 72 * (string version) 73 */ 74 int sendRequest( std::string data ); 75 67 76 /** \param callback The callback function to call with data receivced. 68 77 * \return 0 for success, other for error -
code/branches/masterserver/src/libraries/network/Server.cc
r7634 r7650 105 105 /* initialize it and see if it worked */ 106 106 if( msc.initialize() ) 107 COUT(1) << "Error: could not initialize master server communications!\n"; 107 { COUT(1) << "Error: could not initialize master server communications!\n"; 108 return; 109 } 108 110 109 111 /* connect and see if it worked */ 110 112 if( msc.connect( MS_ADDRESS, 1234 ) ) 111 COUT(1) << "Error: could not connect to master server!\n"; 112 113 /* TODO */ 113 { COUT(1) << "Error: could not connect to master server!\n"; 114 return; 115 } 116 114 117 /* now send the master server some note we're here */ 118 msc.sendRequest( MSPROTO_GAME_SERVER " " MSPROTO_REGISTER_SERVER ); 115 119 } 116 120 … … 164 168 165 169 /* TODO */ 166 int rep lyhandler( char *addr, ENetEvent *ev )170 int rephandler( char *addr, ENetEvent *ev ) 167 171 { 168 172 /* handle incoming data */ … … 174 178 void Server::helper_HandleMasterServerRequests() 175 179 { 176 this->msc.pollForReply( rep lyhandler );180 this->msc.pollForReply( rephandler ); 177 181 } 178 182 -
code/branches/masterserver/src/libraries/network/Server.h
r7634 r7650 39 39 #include "LANDiscoverable.h" 40 40 #include "MasterServerComm.h" 41 #include "MasterServerProtocol.h" 41 42 42 /* proto (move to central point soon) */43 #define MS_ADDRESS "localhost"44 43 45 44 namespace orxonox … … 57 56 ~Server(); 58 57 58 /* helpers */ 59 59 void helper_ConnectToMasterserver(); 60 void helper_HandleMasterServerRequests(); 61 int replyhandler( char *addr, ENetEvent *ev ); 62 60 63 void open(); 61 64 void close(); -
code/branches/masterserver/src/libraries/network/WANDiscovery.cc
r7631 r7650 63 63 /* callback for the network reply poller */ 64 64 /* NOTE implement protocol-specific part here. */ 65 int r eplyhandler( char *addr, ENetEvent *ev )65 int rhandler( char *addr, ENetEvent *ev ) 66 66 { 67 /* handle incoming data 68 * if a list entry arrives add to list 69 * if a done entry arrives set done to true 70 */ 67 /* handle incoming data */ 68 /* if a list entry arrives add to list */ 69 if( !strncmp( ev->packet->data, MSPROTO_SERVERLIST_ITEM, 70 MSPROTO_SERVERLIST_ITEM_LEN ) ) 71 { 72 /* create server structure from that item */ 73 ServerInformation toadd; 74 75 /* fill in data */ 76 toadd->setName( std::string(ev->packet->data + 77 MSPROTO_SERVERLIST_ITEM_LEN) ); 78 toadd->setIP( std::string(ev->packet->data + 79 MSPROTO_SERVERLIST_ITEM_LEN) ); 80 81 /* add to list */ 82 this->servers_.add( toadd ); 83 } 84 else if( !strncmp( ev->packet->data, MSPROTO_SERVERLIST_END, 85 MSPROTO_SERVERLIST_END_LEN ) ) 86 { return 1; } 71 87 72 88 /* done handling, return all ok code 0 */ … … 80 96 81 97 /* send request to server */ 82 msc.sendRequest( MSPROTO_CLIENT MSPROTO_REQ_LIST );98 msc.sendRequest( MSPROTO_CLIENT " " MSPROTO_REQ_LIST ); 83 99 84 100 /* deal with replies */ 85 while( msc.pollForReply( replyhandler ) )101 while( !msc.pollForReply( rhandler ) ) 86 102 /* nothing */; 87 103 -
code/branches/masterserver/src/libraries/network/WANDiscovery.h
r7631 r7650 34 34 #include "util/Singleton.h" 35 35 #include "MasterServerComm.h" 36 #include "MasterServerProtocol.h" 36 37 37 38 #include <vector> 38 39 39 /* master server address (to be moved elsewhere later) */40 #define MS_ADDRESS "localhost"41 42 /* protocol (to be moved elsewhere later) */43 #define MSPROTO_CLIENT "CL "44 #define MSPROTO_REQ_LIST "REQ:LIST"45 40 46 41 // tolua_begin
Note: See TracChangeset
for help on using the changeset viewer.