Changeset 1953 for code/branches/objecthierarchy
- Timestamp:
- Oct 19, 2008, 9:50:36 PM (16 years ago)
- Location:
- code/branches/objecthierarchy/src
- Files:
-
- 4 added
- 20 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); -
code/branches/objecthierarchy/src/orxonox/CMakeLists.txt
r1940 r1953 33 33 overlays/hud/HUDRadar.cc 34 34 overlays/hud/HUDSpeedBar.cc 35 overlays/hud/ChatOverlay.cc 35 36 36 37 tools/BillboardSet.cc -
code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.cc
r1950 r1953 34 34 #include "objects/infos/PlayerInfo.h" 35 35 36 #include "network/Host.h" 37 36 38 namespace orxonox 37 39 { … … 54 56 return (*it); 55 57 58 return 0; 59 } 60 61 PlayerInfo* Gametype::getClient(unsigned int clientID) 62 { 63 Gametype* gametype = Gametype::getCurrentGametype(); 64 if (gametype) 65 { 66 std::map<unsigned int, PlayerInfo*>::const_iterator it = gametype->clients_.find(clientID); 67 if (it != gametype->clients_.end()) 68 return it->second; 69 } 70 else 71 { 72 for (ObjectList<PlayerInfo>::iterator it = ObjectList<PlayerInfo>::begin(); it != ObjectList<PlayerInfo>::end(); ++it) 73 if (it->getClientID() == clientID) 74 return (*it); 75 } 56 76 return 0; 57 77 } … … 112 132 void Gametype::playerJoined(PlayerInfo* player) 113 133 { 114 COUT(0) << "player " << player->getName() << " joined" << std::endl; 134 std::string message = player->getName() + " entered the game"; 135 COUT(0) << message << std::endl; 136 network::Host::Broadcast(message); 115 137 } 116 138 117 139 void Gametype::playerLeft(PlayerInfo* player) 118 140 { 119 COUT(0) << "player " << player->getName() << " left" << std::endl; 141 std::string message = player->getName() + " left the game"; 142 COUT(0) << message << std::endl; 143 network::Host::Broadcast(message); 120 144 } 121 145 … … 126 150 if (player->getName() != player->getOldName()) 127 151 { 128 COUT(0) << "player " << player->getOldName() << " changed name to " << player->getName() << std::endl; 152 std::string message = player->getOldName() + " changed name to " + player->getName(); 153 COUT(0) << message << std::endl; 154 network::Host::Broadcast(message); 129 155 } 130 156 } -
code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.h
r1950 r1953 50 50 static void listPlayers(); 51 51 52 inline const std::map<unsigned int, PlayerInfo*>& getClients() const 53 { return this->clients_; } 54 inline const std::set<PlayerInfo*>& getPlayers() const 55 { return this->players_; } 56 static PlayerInfo* getClient(unsigned int clientID); 57 52 58 protected: 53 59 virtual void clientConnected(unsigned int clientID); -
code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc
r1950 r1953 51 51 52 52 this->ping_ = -1; 53 this->clientID_ = (unsigned int)-1;53 this->clientID_ = network::CLIENTID_UNKNOWN; 54 54 this->bLocalPlayer_ = Core::isStandalone(); 55 55 this->bLocalPlayer_ = false; … … 60 60 this->registerVariables(); 61 61 62 62 //COUT(0) << "created PlayerInfo (" << this->getObjectID() << ")" << std::endl; 63 63 } 64 64 … … 68 68 if (gametype) 69 69 gametype->removePlayer(this); 70 70 //COUT(0) << "destroyed PlayerInfo (" << this->getObjectID() << ")" << std::endl; 71 71 } 72 72 73 73 void PlayerInfo::setConfigValues() 74 74 { 75 SetConfigValue( playerName_, "Player").callback(this, &PlayerInfo::checkName);75 SetConfigValue(nick_, "Player").callback(this, &PlayerInfo::checkNick); 76 76 } 77 77 78 void PlayerInfo::checkN ame()78 void PlayerInfo::checkNick() 79 79 { 80 std::cout << "# PI(" << this->getObjectID() << "): checkName: " << this->bLocalPlayer_ << std::endl; 81 if (this->bLocalPlayer_ && Core::isMaster()) 82 this->setName(this->playerName_); 80 //std::cout << "# PI(" << this->getObjectID() << "): checkName: " << this->bLocalPlayer_ << std::endl; 81 if (this->bLocalPlayer_) 82 { 83 this->playerName_ = this->nick_; 84 85 if (Core::isMaster()) 86 this->setName(this->playerName_); 87 } 83 88 } 84 89 85 90 void PlayerInfo::changedName() 86 91 { 87 std::cout << "# PI(" << this->getObjectID() << "): changedName to " << this->getName() << std::endl;92 //std::cout << "# PI(" << this->getObjectID() << "): changedName to " << this->getName() << std::endl; 88 93 Gametype* gametype = Gametype::getCurrentGametype(); 89 94 if (gametype) … … 103 108 void PlayerInfo::clientChangedName() 104 109 { 105 std::cout << "# PI(" << this->getObjectID() << "): clientChangedName()to " << this->playerName_ << std::endl;110 //std::cout << "# PI(" << this->getObjectID() << "): clientChangedName() from " << this->getName() << " to " << this->playerName_ << std::endl; 106 111 this->setName(this->playerName_); 107 112 } … … 109 114 void PlayerInfo::checkClientID() 110 115 { 111 std::cout << "# PI(" << this->getObjectID() << "): checkClientID()" << std::endl;116 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID()" << std::endl; 112 117 this->bHumanPlayer_ = true; 113 118 114 119 if (this->clientID_ == network::Host::getPlayerID()) 115 120 { 116 std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): it's the client's ID" << std::endl;121 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): it's the client's ID" << std::endl; 117 122 this->bLocalPlayer_ = true; 123 this->playerName_ = this->nick_; 118 124 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): name: " << this->getName() << std::endl; 119 125 120 126 if (Core::isClient()) 121 127 { 122 std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're on a client: set object mode to bidirectional" << std::endl;128 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're on a client: set object mode to bidirectional" << std::endl; 123 129 this->setObjectMode(network::direction::bidirectional); 124 this->playerName_ += "blub"; 125 std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): proposed name: " << this->playerName_ << std::endl; 130 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): proposed name: " << this->playerName_ << std::endl; 126 131 } 127 132 else 128 133 { 129 std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're not on a client: finish setup" << std::endl;134 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're not on a client: finish setup" << std::endl; 130 135 this->clientChangedName(); 131 136 this->bFinishedSetup_ = true; … … 137 142 void PlayerInfo::finishedSetup() 138 143 { 139 std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): " << this->bFinishedSetup_ << std::endl;144 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): " << this->bFinishedSetup_ << std::endl; 140 145 if (Core::isClient()) 141 146 { 142 std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a client: finish setup" << std::endl;147 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a client: finish setup" << std::endl; 143 148 this->bFinishedSetup_ = true; 144 149 } 145 150 else if (this->bFinishedSetup_) 146 151 { 147 std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: add player" << std::endl;152 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: add player" << std::endl; 148 153 Gametype* gametype = Gametype::getCurrentGametype(); 149 154 if (gametype) … … 152 157 else 153 158 { 154 std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: client not yet finished" << std::endl;159 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: client not yet finished" << std::endl; 155 160 } 156 161 } -
code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.h
r1946 r1953 60 60 void checkClientID(); 61 61 void finishedSetup(); 62 void checkN ame();62 void checkNick(); 63 63 void clientChangedName(); 64 64 … … 70 70 71 71 std::string playerName_; 72 std::string nick_; 72 73 }; 73 74 } -
code/branches/objecthierarchy/src/orxonox/overlays/console/InGameConsole.cc
r1879 r1953 613 613 @return The converted string 614 614 */ 615 /*static*/ Ogre::UTFString InGameConsole::convert2UTF( std::string s)615 /*static*/ Ogre::UTFString InGameConsole::convert2UTF(const std::string& text) 616 616 { 617 617 Ogre::UTFString utf; 618 618 Ogre::UTFString::code_point cp; 619 for (unsigned int i = 0; i < s.size(); ++i)620 { 621 cp = s[i];619 for (unsigned int i = 0; i < text.size(); ++i) 620 { 621 cp = text[i]; 622 622 cp &= 0xFF; 623 623 utf.append(1, cp); -
code/branches/objecthierarchy/src/orxonox/overlays/console/InGameConsole.h
r1879 r1953 61 61 static void closeConsole(); 62 62 63 static Ogre::UTFString convert2UTF(const std::string& text); 64 63 65 private: // functions 64 66 InGameConsole(const InGameConsole& other); … … 83 85 // config value related 84 86 void bHidesAllInputChanged(); 85 86 static Ogre::UTFString convert2UTF(std::string s);87 87 88 88 private: // variables
Note: See TracChangeset
for help on using the changeset viewer.