Changeset 1953 for code/branches/objecthierarchy/src/network
- Timestamp:
- Oct 19, 2008, 9:50:36 PM (16 years ago)
- Location:
- code/branches/objecthierarchy/src/network
- Files:
-
- 2 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/network/CMakeLists.txt
r1940 r1953 1 1 SET( NETWORK_SRC_FILES 2 ChatListener.cc 2 3 Client.cc 3 4 ClientConnection.cc -
code/branches/objecthierarchy/src/network/Client.cc
r1917 r1953 46 46 #include "core/CoreIncludes.h" 47 47 #include "packet/Packet.h" 48 48 49 // #include "packet/Acknowledgement.h" 49 50 … … 69 70 * @param port port of the application on the server 70 71 */ 71 Client::Client( std::stringaddress, int port) : client_connection(port, address){72 Client::Client(const std::string& address, int port) : client_connection(port, address){ 72 73 isConnected=false; 73 74 isSynched_=false; … … 116 117 } 117 118 118 bool Client::processChat( std::stringmessage, unsigned int playerID){119 COUT(1) << "Player " << playerID << ": " << message << std::endl;119 bool Client::processChat(const std::string& message, unsigned int playerID){ 120 // COUT(1) << "Player " << playerID << ": " << message << std::endl; 120 121 return true; 121 122 } 122 123 123 124 /** 124 125 * This function implements the method of sending a chat message to the server 125 * @param message message to be sent 126 * @param message message to be sent 126 127 * @return result(true/false) 127 128 */ 128 bool Client::chat( std::stringmessage){129 bool Client::chat(const std::string& message){ 129 130 packet::Chat *m = new packet::Chat(message, Host::getPlayerID()); 130 131 return m->send(); … … 134 135 /** 135 136 * Processes incoming packets, sends a gamestate to the server and does the cleanup 136 * @param time 137 * @param time 137 138 */ 138 139 void Client::tick(float time){ -
code/branches/objecthierarchy/src/network/Client.h
r1907 r1953 66 66 public: 67 67 Client(); 68 Client( std::stringaddress, int port);68 Client(const std::string& address, int port); 69 69 Client(const char *address, int port); 70 70 ~Client(); 71 71 72 72 bool establishConnection(); 73 73 bool closeConnection(); 74 74 bool queuePacket(ENetPacket *packet, int clientID); 75 bool processChat(std::string message, unsigned int playerID); 76 virtual bool chat(std::string message); 75 bool processChat(const std::string& message, unsigned int playerID); 76 virtual bool chat(const std::string& message); 77 virtual bool broadcast(const std::string& message) { return false; } 77 78 //bool sendChat(packet::Chat *chat); 78 79 // static void Chat( std::string message ); 80 81 //static void setShipID( unsigned int shipID){ dynamic_cast<Client *>(instance_)->shipID_=shipID; } 82 static void setClientID( unsigned int clientID){ dynamic_cast<Client *>(instance_)->clientID_=clientID; } 83 79 84 80 void tick(float time); 85 81 86 82 private: 87 83 virtual bool isServer_(){return false;} 88 84 89 85 ClientConnection client_connection; 90 86 GamestateClient gamestate; 91 87 bool isConnected; 92 88 bool isSynched_; 93 89 94 90 bool gameStateFailure_; 95 91 }; -
code/branches/objecthierarchy/src/network/ClientConnection.cc
r1907 r1953 54 54 boost::recursive_mutex ClientConnection::enet_mutex_; 55 55 56 ClientConnection::ClientConnection(int port, std::stringaddress) {56 ClientConnection::ClientConnection(int port, const std::string& address) { 57 57 quit=false; 58 58 server=NULL; -
code/branches/objecthierarchy/src/network/ClientConnection.h
r1916 r1953 62 62 class _NetworkExport ClientConnection{ 63 63 public: 64 ClientConnection(int port, std::stringaddress);64 ClientConnection(int port, const std::string& address); 65 65 ClientConnection(int port, const char* address); 66 66 ~ClientConnection(); -
code/branches/objecthierarchy/src/network/ClientInformation.cc
r1952 r1953 45 45 namespace network 46 46 { 47 47 48 48 ClientInformation *ClientInformation::head_=0; 49 49 50 50 ClientInformation::ClientInformation() { 51 51 if(!head_) … … 129 129 return true; 130 130 } 131 131 132 132 bool ClientInformation::setPartialGamestateID(int id){ 133 133 if(!this) … … 150 150 return NULL; 151 151 } 152 152 153 153 int ClientInformation::getFailures(){ 154 154 return failures_; … … 160 160 failures_=0; 161 161 } 162 162 163 163 enet_uint32 ClientInformation::getRTT(){ 164 164 return peer_->roundTripTime; 165 165 } 166 166 167 167 enet_uint32 ClientInformation::getPacketLoss(){ 168 168 return peer_->packetLoss; … … 175 175 return -1; 176 176 } 177 177 178 178 int ClientInformation::getPartialGamestateID() { 179 179 if(this) … … 197 197 198 198 bool ClientInformation::removeClient(int clientID) { 199 if( clientID==CLIENTID_UNKNOWN)199 if((unsigned int)clientID==CLIENTID_UNKNOWN) 200 200 return false; 201 201 ClientInformation *temp = head_; -
code/branches/objecthierarchy/src/network/ClientInformation.h
r1916 r1953 47 47 48 48 #define GAMESTATEID_INITIAL -1 49 #define CLIENTID_UNKNOWN -250 49 51 50 // WATCH OUT: THE CLIENTINFORMATION LIST IS NOT THREADSAFE ANYMORE … … 53 52 namespace network 54 53 { 54 static const unsigned int CLIENTID_UNKNOWN = (unsigned int)-2; 55 55 56 /** 56 57 * This class implements a list for client informations -
code/branches/objecthierarchy/src/network/ConnectionManager.cc
r1916 r1953 88 88 } 89 89 90 ConnectionManager::ConnectionManager(int port, std::stringaddress) :receiverThread_(0) {90 ConnectionManager::ConnectionManager(int port, const std::string& address) :receiverThread_(0) { 91 91 assert(instance_==0); 92 92 instance_=this; -
code/branches/objecthierarchy/src/network/ConnectionManager.h
r1916 r1953 79 79 ConnectionManager(int port); 80 80 ConnectionManager(int port, const char *address); 81 ConnectionManager(int port, std::stringaddress);81 ConnectionManager(int port, const std::string& address); 82 82 ~ConnectionManager(); 83 83 //ENetPacket *getPacket(ENetAddress &address); // thread1 -
code/branches/objecthierarchy/src/network/Host.cc
r1907 r1953 32 32 #include "core/ConsoleCommand.h" 33 33 #include "packet/Packet.h" 34 #include "ChatListener.h" 34 35 35 36 namespace network { … … 38 39 39 40 Host *Host::instance_=0; 40 41 41 42 /** 42 43 * @brief Constructor: assures that only one reference will be created and sets the pointer … … 90 91 * @return playerID 91 92 */ 92 unsigned int Host::getPlayerID(){ 93 unsigned int Host::getPlayerID(){ 93 94 if(!instance_) 94 95 return 0; … … 96 97 } 97 98 98 bool Host::Chat( std::stringmessage){99 bool Host::Chat(const std::string& message){ 99 100 if(!instance_) 100 101 return false; … … 102 103 } 103 104 104 bool Host::incomingChat(std::string message, unsigned int playerID){ 105 bool Host::Broadcast(const std::string& message){ 106 if(!instance_) 107 return false; 108 return instance_->broadcast(message); 109 } 110 111 bool Host::incomingChat(const std::string& message, unsigned int playerID){ 112 for (orxonox::ObjectList<ChatListener>::iterator it = orxonox::ObjectList<ChatListener>::begin(); it != orxonox::ObjectList<ChatListener>::end(); ++it) 113 it->incomingChat(message, playerID); 114 105 115 return instance_->processChat(message, playerID); 106 116 } -
code/branches/objecthierarchy/src/network/Host.h
r1916 r1953 50 50 //virtual bool sendChat(packet::Chat *chat)=0; 51 51 virtual bool queuePacket(ENetPacket *packet, int clientID)=0; 52 virtual bool chat(std::string message)=0; 53 virtual bool processChat(std::string message, unsigned int playerID)=0; 52 virtual bool chat(const std::string& message)=0; 53 virtual bool broadcast(const std::string& message)=0; 54 virtual bool processChat(const std::string& message, unsigned int playerID)=0; 54 55 virtual bool isServer_()=0; 55 56 … … 73 74 static void setShipID(unsigned int id){ instance_->shipID_ = id; } 74 75 static bool isServer(){ return instance_->isServer_(); } 75 static bool Chat(std::string message); 76 static bool incomingChat(std::string message, unsigned int playerID); 76 static bool Chat(const std::string& message); 77 static bool Broadcast(const std::string& message); 78 static bool incomingChat(const std::string& message, unsigned int playerID); 77 79 private: 78 80 }; -
code/branches/objecthierarchy/src/network/Server.cc
r1952 r1953 58 58 #include "packet/DeleteObjects.h" 59 59 #include <util/Convert.h> 60 #include "ChatListener.h" 60 61 61 62 namespace network … … 85 86 * @param bindAddress Address to listen on 86 87 */ 87 Server::Server(int port, std::stringbindAddress) {88 Server::Server(int port, const std::string& bindAddress) { 88 89 timeSinceLastUpdate_=0; 89 90 connection = new ConnectionManager(port, bindAddress); … … 128 129 } 129 130 130 bool Server::processChat( std::stringmessage, unsigned int playerID){131 bool Server::processChat(const std::string& message, unsigned int playerID){ 131 132 ClientInformation *temp = ClientInformation::getBegin(); 132 133 packet::Chat *chat; … … 138 139 temp = temp->next(); 139 140 } 140 COUT(1) << "Player " << playerID << ": " << message << std::endl;141 // COUT(1) << "Player " << playerID << ": " << message << std::endl; 141 142 return true; 142 143 } … … 304 305 listener++; 305 306 } 306 307 307 308 newid++; 308 309 … … 367 368 } 368 369 369 bool Server::chat(std::string message){ 370 bool Server::chat(const std::string& message){ 371 return this->sendChat(message, Host::getPlayerID()); 372 } 373 374 bool Server::broadcast(const std::string& message){ 375 return this->sendChat(message, CLIENTID_UNKNOWN); 376 } 377 378 bool Server::sendChat(const std::string& message, unsigned int clientID){ 370 379 ClientInformation *temp = ClientInformation::getBegin(); 371 380 packet::Chat *chat; 372 381 while(temp){ 373 chat = new packet::Chat(message, Host::getPlayerID());382 chat = new packet::Chat(message, clientID); 374 383 chat->setClientID(temp->getID()); 375 384 if(!chat->send()) … … 377 386 temp = temp->next(); 378 387 } 379 COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl; 388 // COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl; 389 for (orxonox::ObjectList<ChatListener>::iterator it = orxonox::ObjectList<ChatListener>::begin(); it != orxonox::ObjectList<ChatListener>::end(); ++it) 390 it->incomingChat(message, clientID); 391 380 392 return true; 381 393 } -
code/branches/objecthierarchy/src/network/Server.h
r1916 r1953 61 61 Server(); 62 62 Server(int port); 63 Server(int port, std::stringbindAddress);63 Server(int port, const std::string& bindAddress); 64 64 Server(int port, const char *bindAddress); 65 65 ~Server(); … … 67 67 void open(); 68 68 void close(); 69 bool processChat( std::stringmessage, unsigned int playerID);69 bool processChat(const std::string& message, unsigned int playerID); 70 70 bool queuePacket(ENetPacket *packet, int clientID); 71 71 void tick(float time); … … 86 86 bool sendGameState(); 87 87 bool sendObjectDeletes(); 88 virtual bool chat(std::string message); 88 virtual bool chat(const std::string& message); 89 virtual bool broadcast(const std::string& message); 90 bool sendChat(const std::string& message, unsigned int clientID); 89 91 90 92 //void processChat( chat *data, int clientId);
Note: See TracChangeset
for help on using the changeset viewer.