Changeset 1793 for code/branches/network/src/network/Server.cc
- Timestamp:
- Sep 17, 2008, 5:24:56 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/Server.cc
r1775 r1793 122 122 } 123 123 124 bool Server::processChat( packet::Chat *message, unsigned int clientID){124 bool Server::processChat(std::string message, unsigned int playerID){ 125 125 ClientInformation *temp = ClientInformation::getBegin(); 126 packet::Chat *chat; 126 127 while(temp){ 127 message->setClientID(temp->getID()); 128 if(!message->send()) 129 COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 130 temp = temp->next(); 131 } 132 return message->process(); 133 } 134 135 /** 136 * This function sends out a message to all clients 137 * @param msg message 138 * @return true/false 139 */ 140 bool Server::sendChat(packet::Chat *chat) { 141 //TODO: change this (no informations about who wrote a message) 142 assert(0); 143 ClientInformation *temp = ClientInformation::getBegin(); 144 while(temp){ 128 chat = new packet::Chat(message, playerID); 145 129 chat->setClientID(temp->getID()); 146 130 if(!chat->send()) 147 131 COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 148 } 149 return chat->process();; 150 } 151 152 /** 153 * This function sends out a message to all clients 154 * @param msg message 155 * @return true/false 156 */ 157 // bool Server::sendChat(const char *msg) { 158 // char *message = new char [strlen(msg)+10+1]; 159 // sprintf(message, "Player %d: %s", CLIENTID_SERVER, msg); 160 // COUT(1) << message << std::endl; 161 // ENetPacket *packet = packet_gen.chatMessage(message); 162 // COUT(5) <<"Server: adding Packets" << std::endl; 163 // return connection->addPacketAll(packet); 164 // } 132 temp = temp->next(); 133 } 134 COUT(1) << "Player " << playerID << ": " << message << std::endl; 135 return true; 136 } 137 165 138 166 139 /** … … 175 148 if(timeSinceLastUpdate_>=(1./NETWORK_FREQUENCY)){ 176 149 timeSinceLastUpdate_=(float)((int)(timeSinceLastUpdate_*NETWORK_FREQUENCY))/timeSinceLastUpdate_; 177 // timeSinceLastUpdate_-=1./NETWORK_FREQUENCY;178 150 gamestates_->processGamestates(); 179 151 updateGamestate(); 180 152 } 181 /*while(timeSinceLastUpdate_>1./NETWORK_FREQUENCY)182 timeSinceLastUpdate_-=1./NETWORK_FREQUENCY;*/183 // usleep(5000); // TODO remove184 return;185 153 } 186 154 … … 303 271 return true; 304 272 } 305 306 // void Server::processChat( chat *data, int clientId){ 307 // char *message = new char [strlen(data->message)+10+1]; 308 // sprintf(message, "Player %d: %s", clientId, data->message); 309 // COUT(1) << message << std::endl; 310 // ENetPacket *pck = packet_gen.chatMessage(message); 311 // connection->addPacketAll(pck); 312 // delete[] data->message; 313 // delete data; 314 // } 273 315 274 316 275 bool Server::addClient(ENetEvent *event){ … … 417 376 gamestates_->removeClient(client); 418 377 } 378 379 bool Server::chat(std::string message){ 380 ClientInformation *temp = ClientInformation::getBegin(); 381 packet::Chat *chat; 382 while(temp){ 383 chat = new packet::Chat(message, Host::getPlayerID()); 384 chat->setClientID(temp->getID()); 385 if(!chat->send()) 386 COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 387 temp = temp->next(); 388 } 389 COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl; 390 return true; 391 } 419 392 420 393 }
Note: See TracChangeset
for help on using the changeset viewer.