Changeset 1502 for code/trunk/src/network/Client.cc
- Timestamp:
- Jun 1, 2008, 3:54:20 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/network/Client.cc
r1360 r1502 85 85 isConnected=false; 86 86 isSynched_=false; 87 gameStateFailure_=false; 87 88 } 88 89 … … 95 96 isConnected=false; 96 97 isSynched_=false; 98 gameStateFailure_=false; 97 99 } 98 100 … … 105 107 isConnected=false; 106 108 isSynched_=false; 109 gameStateFailure_=false; 107 110 } 108 111 … … 120 123 isConnected=client_connection.createConnection(); 121 124 if(isConnected){ 122 COUT(3) << "sending connectrequest" << std::endl;123 if(!client_connection.addPacket(pck_gen.generateConnectRequest()) || !client_connection.sendPackets())124 COUT(1) << "could not create connection" << std::endl;125 // COUT(3) << "sending connectrequest" << std::endl; 126 // if(!client_connection.addPacket(pck_gen.generateConnectRequest()) || !client_connection.sendPackets()) 127 // COUT(1) << "could not send connection request !!!!!!!!!" << std::endl; 125 128 }else 126 COUT(1) << "could not create connection " << std::endl;129 COUT(1) << "could not create connection laber" << std::endl; 127 130 return isConnected; 128 131 } … … 137 140 } 138 141 139 /** 140 * submits a MouseAction to the server 141 * @param x x Coordinate 142 * @param y y Coordinate 143 * @return true/false 144 */ 145 bool Client::sendMouse(double x, double y){ 146 // generate packet and add it to the queue 147 if(!isConnected) 148 return false; 149 if(!client_connection.addPacket(pck_gen.mousem(x, y))) 150 return false; 151 // send packets 152 return client_connection.sendPackets(); 153 } 154 155 /** 156 * submits a Keystrike to the server 157 * @param key_code code to submit 158 * @return true/false 159 */ 160 bool Client::sendKeyboard(char key_code){ 161 // generate packet and add it to queue 162 if(!isConnected) 163 return false; 164 if(!client_connection.addPacket(pck_gen.keystrike(key_code))) 165 return false; 166 // send packets 167 return client_connection.sendPackets(); 168 } 142 143 144 169 145 170 146 /** … … 177 153 if(!isConnected) 178 154 return false; 179 if(client_connection.addPacket(pck_gen.chatMessage( message.c_str() )))180 return client_connection.sendPackets();155 return client_connection.addPacket(pck_gen.chatMessage( message.c_str() )); 156 //return client_connection.sendPackets(); 181 157 // send packets 182 158 return false; 183 }184 185 /**186 * Adds a MouseAction to the PacketQueue187 * @param x x Coordinate188 * @param y y Coordinate189 * @return true/false190 */191 bool Client::addMouse(double x, double y){192 // generate packet and add it to the queue193 if(client_connection.addPacket(pck_gen.mousem(x, y)))194 return true;195 else196 return false;197 }198 199 /**200 * Adds a Keystrike to the PacketQueue201 * @param key_code202 * @return true/false203 */204 bool Client::addKeyboard(char key_code){205 // generate packet and add it to queue206 if(client_connection.addPacket(pck_gen.keystrike(key_code)))207 return true;208 else209 return false;210 }211 212 /**213 * Sends out all the packets queued by addXXX214 */215 bool Client::sendPackets(){216 if(!isConnected)217 return false;218 ENetEvent event;219 // send packets220 client_connection.sendPackets(&event);221 if(event.type==ENET_EVENT_TYPE_NONE)222 return true;223 else224 return false;225 159 } 226 160 … … 243 177 } 244 178 } 245 ENet Packet *packet;179 ENetEvent *event; 246 180 // stop if the packet queue is empty 247 181 while(!(client_connection.queueEmpty())){ 248 packet = client_connection.getPacket(); 249 COUT(5) << "tick packet size " << packet->dataLength << std::endl; 250 elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server) 251 } 252 if(!client_connection.sendPackets()) 253 COUT(3) << "Problem sending packets to server" << std::endl; 254 return; 255 } 256 257 void Client::processGamestate( GameStateCompressed *data, int clientID){ 258 int id = data->id; 259 COUT(5) << "received gamestate id: " << data->id << std::endl; 260 if(gamestate.pushGameState(data)){ 182 event = client_connection.getEvent(); 183 COUT(5) << "tick packet size " << event->packet->dataLength << std::endl; 184 elaborate(event->packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server) 185 } 186 int gameStateID = gamestate.processGameState(); 187 if(gameStateID==GAMESTATEID_INITIAL) 188 if(gameStateFailure_){ 189 if(!client_connection.addPacket(pck_gen.acknowledgement(GAMESTATEID_INITIAL))) 190 COUT(3) << "could not (negatively) ack gamestate" << std::endl; 191 else 192 COUT(4) << "negatively acked a gamestate" << std::endl; 193 } 194 else 195 gameStateFailure_=true; 196 else if(gameStateID!=0){ 197 // ack gamestate and set synched 261 198 if(!isSynched_) 262 199 isSynched_=true; 263 if(!client_connection.addPacket(pck_gen.acknowledgement(id))) 264 return; 265 // we do this at the end of a tick 266 if(!client_connection.sendPackets()) 267 COUT(2) << "Could not send acknowledgment" << std::endl; 268 } 200 gameStateFailure_=false; 201 if(!client_connection.addPacket(pck_gen.acknowledgement(gameStateID))) 202 COUT(3) << "could not ack gamestate" << std::endl; 203 }// otherwise we had no gamestate to load 204 gamestate.cleanup(); 205 /*if(!client_connection.sendPackets()) 206 COUT(3) << "Problem sending packets to server" << std::endl;*/ 207 return; 208 } 209 210 void Client::processGamestate( GameStateCompressed *data, int clientID){ 211 COUT(5) << "received gamestate id: " << data->id << std::endl; 212 gamestate.addGameState(data); 269 213 } 270 214 … … 275 219 id->setNetworkID(clid->clid); 276 220 COUT(4) << "Client: received and set network id: " << clid->clid << "; classname: " << clid->message << std::endl; 221 COUT(4) << "id(classid)->getName " << ID((unsigned int)clid->clid)->getName() << std::endl; 277 222 delete clid; 278 223 return;
Note: See TracChangeset
for help on using the changeset viewer.