Changeset 1534 for code/trunk/src/network/Server.cc
- Timestamp:
- Jun 4, 2008, 8:53:10 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/network/Server.cc
r1505 r1534 51 51 #include "util/Sleep.h" 52 52 #include "objects/SpaceShip.h" 53 53 #include "core/ConsoleCommand.h" 54 54 55 55 namespace network 56 56 { 57 58 59 #define MAX_FAILURES 20; 60 #define NETWORK_FREQUENCY 30 57 #define MAX_FAILURES 20; 58 #define NETWORK_FREQUENCY 30 59 60 Server *Server::instance_=0; 61 62 Server *Server::createSingleton(){ 63 if(!instance_) 64 instance_ = new Server(); 65 return instance_; 66 } 67 Server *Server::createSingleton(int port){ 68 if(!instance_) 69 instance_ = new Server(port); 70 return instance_; 71 } 72 Server *Server::createSingleton(int port, std::string bindAddress){ 73 if(!instance_) 74 instance_ = new Server(port, bindAddress); 75 return instance_; 76 } 77 Server *Server::createSingleton(int port, const char *bindAddress){ 78 if(!instance_) 79 instance_ = new Server(port, bindAddress); 80 return instance_; 81 } 82 83 Server *Server::getSingleton(){ 84 return instance_; 85 } 86 61 87 62 88 /** … … 127 153 * @return true/false 128 154 */ 129 bool Server::sendMSG(std::string msg) { 130 ENetPacket *packet = packet_gen.chatMessage(msg.c_str()); 131 //std::cout <<"adding packets" << std::endl; 132 return connection->addPacketAll(packet); 155 bool Server::sendChat(std::string msg) { 156 return sendChat(msg.c_str()); 133 157 } 134 158 … … 138 162 * @return true/false 139 163 */ 140 bool Server::sendMSG(const char *msg) { 141 ENetPacket *packet = packet_gen.chatMessage(msg); 142 COUT(4) <<"Server: adding Packets" << std::endl; 164 bool Server::sendChat(const char *msg) { 165 char *message = new char [strlen(msg)+10+1]; 166 sprintf(message, "Player %d: %s", CLIENTID_SERVER, msg); 167 COUT(1) << message << std::endl; 168 ENetPacket *packet = packet_gen.chatMessage(message); 169 COUT(5) <<"Server: adding Packets" << std::endl; 143 170 return connection->addPacketAll(packet); 144 171 } … … 202 229 void Server::updateGamestate() { 203 230 gamestates->update(); 204 COUT( 4) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;231 COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl; 205 232 //std::cout << "updated gamestate, sending it" << std::endl; 206 233 //if(clients->getGamestateID()!=GAMESTATEID_INITIAL) 207 234 sendGameState(); 208 COUT( 4) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;235 COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl; 209 236 //std::cout << "sent gamestate" << std::endl; 210 237 } … … 229 256 continue; 230 257 } 258 COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl; 231 259 COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl; 232 260 int gid = temp->getGamestateID(); //get gamestate id … … 287 315 } 288 316 317 void Server::processChat( chat *data, int clientId){ 318 char *message = new char [strlen(data->message)+10+1]; 319 sprintf(message, "Player %d: %s", clientId, data->message); 320 COUT(1) << message << std::endl; 321 ENetPacket *pck = packet_gen.chatMessage(message); 322 connection->addPacketAll(pck); 323 delete[] data->message; 324 delete data; 325 } 326 289 327 bool Server::addClient(ENetEvent *event){ 290 328 ClientInformation *temp = clients->insertBack(new ClientInformation); … … 312 350 COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl; 313 351 connection->syncClassid(temp->getID()); 314 COUT( 4) << "creating spaceship for clientid: " << temp->getID() << std::endl;352 COUT(5) << "creating spaceship for clientid: " << temp->getID() << std::endl; 315 353 // TODO: this is only a hack, untill we have a possibility to define default player-join actions 316 354 if(!createShip(temp))
Note: See TracChangeset
for help on using the changeset viewer.