Changeset 1518
- Timestamp:
- Jun 2, 2008, 9:15:15 PM (16 years ago)
- Location:
- code/branches/network/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/core/ConsoleCommand.h
r1505 r1518 42 42 43 43 #define SetConsoleCommandGeneric(fakevariable, classname, command, bCreateShortcut) \ 44 ConsoleCommand& fakevariable =ClassManager<classname>::getIdentifier()->addConsoleCommand(command, bCreateShortcut)44 orxonox::ConsoleCommand& fakevariable = orxonox::ClassManager<classname>::getIdentifier()->addConsoleCommand(command, bCreateShortcut) 45 45 46 46 … … 52 52 53 53 #define SetConsoleCommandShortcutGeneric(fakevariable, command) \ 54 ConsoleCommand& fakevariable =CommandExecutor::addConsoleCommandShortcut(command)54 orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command) 55 55 56 56 -
code/branches/network/src/network/Client.cc
r1505 r1518 42 42 #include "Synchronisable.h" 43 43 #include "core/CoreIncludes.h" 44 #include "core/ConsoleCommand.h" 45 #include "Server.h" 44 46 45 47 namespace network 46 48 { 49 SetConsoleCommandShortcut(Client, Chat); 50 47 51 Client* Client::_sClient = 0; 48 52 … … 142 146 143 147 148 void Client::Chat( std::string message ){ 149 if(Client::getSingleton()) 150 Client::getSingleton()->sendChat(message); 151 else if(Server::getSingleton()) 152 Server::getSingleton()->sendChat(message); 153 } 144 154 145 155 … … 224 234 } 225 235 226 void Client::processChat( chat *data ){227 COUT( 0) << "Server: "<< data->message << std::endl;236 void Client::processChat( chat *data, int clientId){ 237 COUT(1) << data->message << std::endl; 228 238 delete[] data->message; 229 239 delete data; -
code/branches/network/src/network/Client.h
r1505 r1518 75 75 bool closeConnection(); 76 76 77 bool sendChat( std::string message );77 static void Chat( std::string message ); 78 78 79 79 int getShipID(){return shipID_;} … … 96 96 bool isSynched_; 97 97 98 bool sendChat( std::string message ); 99 98 100 // implement data processing functions of PacketDecoder 99 101 void processGamestate( GameStateCompressed *data, int clientID); 100 102 void processClassid(classid *clid); 101 void processChat( chat *data );103 void processChat( chat *data, int clientId ); 102 104 bool processWelcome( welcome *w ); 103 105 int clientID_; // this is the id the server gave to us -
code/branches/network/src/network/ConnectionManager.cc
r1505 r1518 168 168 boost::recursive_mutex::scoped_lock lock(enet_mutex_); 169 169 for(ClientInformation *i=head_->next(); i!=0; i=i->next()){ 170 if(enet_peer_send(i->getPeer(), (enet_uint8)i->getID(), packet)!=0) 170 COUT(3) << "adding broadcast packet for client: " << i->getID() << std::endl; 171 if(enet_peer_send(i->getPeer(), 0, packet)!=0) 171 172 return false; 172 173 } -
code/branches/network/src/network/Server.cc
r1516 r1518 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 } … … 288 315 } 289 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 290 327 bool Server::addClient(ENetEvent *event){ 291 328 ClientInformation *temp = clients->insertBack(new ClientInformation); -
code/branches/network/src/network/Server.h
r1505 r1518 53 53 namespace network 54 54 { 55 #define CLIENTID_SERVER 0 56 55 57 /** 56 58 * This class is the root class of the network module for a server. … … 59 61 class _NetworkExport Server : public PacketDecoder, public orxonox::Tickable{ 60 62 public: 61 Server(); 62 Server(int port); 63 Server(int port, std::string bindAddress); 64 Server(int port, const char *bindAddress); 63 static Server *createSingleton(); 64 static Server *createSingleton(int port); 65 static Server *createSingleton(int port, std::string bindAddress); 66 static Server *createSingleton(int port, const char *bindAddress); 67 68 static Server *getSingleton(); 69 65 70 void open(); 66 71 void close(); 67 bool send MSG(std::string msg);68 bool send MSG(const char *msg);72 bool sendChat(std::string msg); 73 bool sendChat(const char *msg); 69 74 void tick(float time); 70 75 protected: … … 72 77 void updateGamestate(); 73 78 private: 79 Server(); 80 Server(int port); 81 Server(int port, std::string bindAddress); 82 Server(int port, const char *bindAddress); 83 84 static Server *instance_; 85 74 86 bool addClient(ENetEvent *event); 75 87 bool createClient(int clientID); … … 82 94 bool processConnectRequest( connectRequest *con, int clientID ); 83 95 void processGamestate( GameStateCompressed *data, int clientID); 96 void processChat( chat *data, int clientId); 84 97 ConnectionManager *connection; 85 98 GameStateManager *gamestates; -
code/branches/network/src/orxonox/Orxonox.cc
r1512 r1518 127 127 network::Client::destroySingleton(); 128 128 if (server_g) 129 delete server_g;129 delete network::Server::getSingleton(); 130 130 } 131 131 … … 303 303 COUT(2) << "Loading level in server mode" << std::endl; 304 304 305 server_g = new network::Server(serverPort_); 305 //server_g = new network::Server(serverPort_); 306 server_g = network::Server::createSingleton(serverPort_); 306 307 307 308 if (!loadScene())
Note: See TracChangeset
for help on using the changeset viewer.