Changeset 7161 for code/branches/presentation3
- Timestamp:
- Jul 28, 2010, 8:29:32 PM (14 years ago)
- Location:
- code/branches/presentation3
- Files:
-
- 6 added
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation3/data/gui/layouts/MultiplayerMenu.layout
r6746 r7161 16 16 <Property Name="VertFormatting" Value="TopAligned" /> 17 17 <Property Name="UnifiedAreaRect" Value="{{0.25,0},{0.2875,0},{0.75,0},{0.6375,0}}" /> 18 <Window Type="MenuWidgets/Listbox" Name="orxonox/MultiplayerL evelListbox" >18 <Window Type="MenuWidgets/Listbox" Name="orxonox/MultiplayerListbox" > 19 19 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> 20 20 <Property Name="UnifiedAreaRect" Value="{{0.05,0},{0.15,0},{0.95,0},{0.8,0}}" /> -
code/branches/presentation3/data/gui/scripts/MultiplayerMenu.lua
r6746 r7161 4 4 5 5 function P.onLoad() 6 listbox = winMgr:getWindow("orxonox/MultiplayerLevelListbox") 7 preselect = orxonox.LevelManager:getInstance():getDefaultLevel() 6 P.multiplayerMode = "startClient" 7 end 8 9 function P.onShow() 10 if P.multiplayerMode == "startClient" then 11 local window = winMgr:getWindow("orxonox/MultiplayerJoinButton") 12 local button = tolua.cast(window,"CEGUI::RadioButton") 13 button:setSelected(true) 14 P.showServerList() 15 end 16 if P.multiplayerMode == "startServer" then 17 local window = winMgr:getWindow("orxonox/MultiplayerHostButton") 18 local button = tolua.cast(window,"CEGUI::RadioButton") 19 button:setSelected(true) 20 P.showLevelList() 21 end 22 if P.multiplayerMode == "startDedicated" then 23 local window = winMgr:getWindow("orxonox/MultiplayerDedicatedButton") 24 local button = tolua.cast(window,"CEGUI::RadioButton") 25 button:setSelected(true) 26 P.showLevelList() 27 end 28 end 29 30 function P.MultiplayerJoinButton_clicked(e) 31 P.multiplayerMode = "startClient" 32 P.showServerList() 33 end 34 35 function P.MultiplayerHostButton_clicked(e) 36 P.multiplayerMode = "startServer" 37 P.showLevelList() 38 end 39 40 function P.MultiplayerDedicatedButton_clicked(e) 41 P.multiplayerMode = "startDedicated" 42 P.showLevelList() 43 end 44 45 function P.MultiplayerStartButton_clicked(e) 46 local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem() 47 if P.multiplayerMode == "startClient" then 48 if choice then 49 local client = orxonox.Client:getInstance() 50 local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID() 51 client:setDestination( P.serverList[index][2], 55556 ) 52 else 53 return 54 end 55 else 56 if choice then 57 orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw") 58 else 59 return 60 end 61 end 62 orxonox.execute(P.multiplayerMode) 63 hideAllMenuSheets() 64 end 65 66 function P.MultiplayerBackButton_clicked(e) 67 hideMenuSheet(P.name) 68 end 69 70 function P.showLevelList() 71 local listbox = winMgr:getWindow("orxonox/MultiplayerListbox") 72 CEGUI.toListbox(listbox):resetList() 73 local preselect = orxonox.LevelManager:getInstance():getDefaultLevel() 8 74 orxonox.LevelManager:getInstance():compileAvailableLevelList() 9 75 local levelList = {} … … 19 85 end 20 86 table.sort(levelList) 87 index = 1 21 88 for k,v in pairs(levelList) do 22 item = CEGUI.createListboxTextItem(v)89 local item = CEGUI.createListboxTextItem(v) 23 90 item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") 91 item:setID(index) 92 index = index + 1 24 93 CEGUI.toListbox(listbox):addItem(item) 25 94 if v .. ".oxw" == preselect then … … 27 96 end 28 97 end 29 local multiplayerMode = "startClient"30 if multiplayerMode == "startClient" then31 window = winMgr:getWindow("orxonox/MultiplayerJoinButton")32 button = tolua.cast(window,"CEGUI::RadioButton")33 button:setSelected(true)34 98 end 35 if multiplayerMode == "startServer" then 36 window = winMgr:getWindow("orxonox/MultiplayerHostButton") 37 button = tolua.cast(window,"CEGUI::RadioButton") 38 button:setSelected(true) 99 100 function P.showServerList() 101 local listbox = winMgr:getWindow("orxonox/MultiplayerListbox") 102 CEGUI.toListbox(listbox):resetList() 103 local discovery = orxonox.LANDiscovery:getInstance() 104 discovery:discover() 105 P.serverList = {} 106 local index = 0 107 local servername = "" 108 local serverip = "" 109 while true do 110 servername = discovery:getServerListItemName(index) 111 if servername == "" then 112 break 113 end 114 serverip = discovery:getServerListItemIP(index) 115 if serverip == "" then 116 break 117 end 118 table.insert(P.serverList, {servername, serverip}) 119 index = index + 1 39 120 end 40 if multiplayerMode == "startDedicated" then 41 window = winMgr:getWindow("orxonox/MultiplayerDedicatedButton") 42 button = tolua.cast(window,"CEGUI::RadioButton") 43 button:setSelected(true) 121 index = 1 122 for k,v in pairs(P.serverList) do 123 local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] ) 124 item:setID(index) 125 index = index + 1 126 item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") 127 CEGUI.toListbox(listbox):addItem(item) 44 128 end 45 end46 47 function P.MultiplayerJoinButton_clicked(e)48 multiplayerMode = "startClient"49 end50 51 function P.MultiplayerHostButton_clicked(e)52 multiplayerMode = "startServer"53 end54 55 function P.MultiplayerDedicatedButton_clicked(e)56 multiplayerMode = "startDedicated"57 end58 59 function P.MultiplayerStartButton_clicked(e)60 local choice = winMgr:getWindow("orxonox/MultiplayerLevelListbox"):getFirstSelectedItem()61 if choice then62 orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")63 orxonox.execute(multiplayerMode)64 hideAllMenuSheets()65 end66 end67 68 function P.MultiplayerBackButton_clicked(e)69 hideMenuSheet(P.name)70 129 end 71 130 -
code/branches/presentation3/src/libraries/network/CMakeLists.txt
r7135 r7161 29 29 GamestateClient.cc 30 30 GamestateHandler.cc 31 LANDiscoverable.cc 32 LANDiscovery.cc 31 33 NetworkFunction.cc 32 34 Host.cc … … 48 50 GamestateManager.h 49 51 Host.h 52 LANDiscoverable.h 53 LANDiscovery.h 50 54 NetworkFunction.h 51 55 NetworkPrecompiledHeaders.h … … 60 64 61 65 ORXONOX_ADD_LIBRARY(network 66 TOLUA_FILES 67 Client.h 68 LANDiscovery.h 62 69 PCH_FILE 63 70 NetworkPrecompiledHeaders.h -
code/branches/presentation3/src/libraries/network/Client.cc
r6417 r7161 50 50 #include "FunctionCallManager.h" 51 51 #include "core/CoreIncludes.h" 52 #include "core/CommandLineParser.h" 52 53 #include "core/Game.h" 54 #include "core/ScopedSingletonManager.h" 53 55 54 56 namespace orxonox 55 57 { 56 58 59 ManageScopedSingleton( Client, ScopeID::Root, true ); 57 60 58 61 /** … … 61 64 */ 62 65 Client::Client(): 66 gamestate(0), 63 67 isSynched_(false), 64 68 gameStateFailure_(false), 65 69 timeSinceLastUpdate_(0) 66 70 { 67 } 68 69 /** 70 * Constructor for the Client class 71 * @param address the server address 72 * @param port port of the application on the server 73 */ 74 Client::Client(const std::string& address, int port): 75 isSynched_(false), 76 gameStateFailure_(false), 77 timeSinceLastUpdate_(0) 78 { 79 setPort( port ); 80 setServerAddress( address ); 81 } 82 83 Client::~Client(){ 71 this->setDestination( CommandLineParser::getValue("dest").getString(), CommandLineParser::getValue("port") ); 72 } 73 74 Client::~Client() 75 { 84 76 if ( ClientConnection::isConnected() ) 85 77 closeConnection(); … … 90 82 * @return true/false 91 83 */ 92 bool Client::establishConnection(){ 84 bool Client::establishConnection() 85 { 93 86 Synchronisable::setClient(true); 94 return ClientConnection::establishConnection(); 87 this->gamestate = new GamestateClient(); 88 if( ClientConnection::establishConnection() ) 89 { 90 Host::setActive(true); 91 return true; 92 } 93 else 94 return false; 95 95 } 96 96 … … 99 99 * @return true/false 100 100 */ 101 bool Client::closeConnection(){ 101 bool Client::closeConnection() 102 { 103 assert(this->gamestate); 104 delete this->gamestate; 105 this->gamestate = 0; 106 Host::setActive(false); 102 107 return ClientConnection::closeConnection(); 103 108 } 104 105 bool Client::queuePacket(ENetPacket *packet, int clientID){ 109 110 void Client::setDestination(const std::string& serverAddress, unsigned int port) 111 { 112 ClientConnection::setServerAddress(serverAddress); 113 ClientConnection::setPort(port); 114 } 115 116 bool Client::queuePacket(ENetPacket *packet, int clientID) 117 { 106 118 bool b = ClientConnection::addPacket(packet); 107 119 assert(b); … … 109 121 } 110 122 111 bool Client::processChat(const std::string& message, unsigned int playerID){ 123 bool Client::processChat(const std::string& message, unsigned int playerID) 124 { 112 125 // COUT(1) << "Player " << playerID << ": " << message << std::endl; 113 126 return true; 114 127 } 115 128 116 void Client::printRTT(){ 129 void Client::printRTT() 130 { 117 131 COUT(0) << "Round trip time to server is " << ClientConnection::getRTT() << " ms" << endl; 118 132 } … … 123 137 * @return result(true/false) 124 138 */ 125 bool Client::chat(const std::string& message){ 139 bool Client::chat(const std::string& message) 140 { 126 141 packet::Chat *m = new packet::Chat(message, Host::getPlayerID()); 127 142 return m->send(); … … 133 148 * @param time 134 149 */ 135 void Client::update(const Clock& time){ 150 void Client::update(const Clock& time) 151 { 136 152 //this steers our network frequency 137 153 timeSinceLastUpdate_+=time.getDeltaTime(); … … 143 159 { 144 160 COUT(4) << "popping partial gamestate: " << std::endl; 145 packet::Gamestate *gs = gamestate .getGamestate();161 packet::Gamestate *gs = gamestate->getGamestate(); 146 162 //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now 147 163 if(gs){ … … 157 173 158 174 Connection::processQueue(); 159 if(gamestate .processGamestates())175 if(gamestate->processGamestates()) 160 176 { 161 177 if(!isSynched_) 162 178 isSynched_=true; 163 179 } 164 gamestate .cleanup();180 gamestate->cleanup(); 165 181 Connection::sendPackets(); 166 182 … … 184 200 } 185 201 202 203 186 204 } -
code/branches/presentation3/src/libraries/network/Client.h
r5961 r7161 47 47 48 48 #include "util/UtilPrereqs.h" 49 #include "util/Singleton.h" 49 50 #include "ClientConnection.h" 50 51 #include "GamestateClient.h" 51 52 #include "Host.h" 53 #include "LANDiscovery.h" 54 #include "packet/ServerInformation.h" 52 55 56 // tolua_begin 53 57 namespace orxonox 54 58 { 59 // tolua_end 55 60 /** 56 61 Client *client; … … 60 65 * 61 66 */ 62 class _NetworkExport Client : public Host, public ClientConnection{ 67 class _NetworkExport Client // tolua_export 68 : public Host, protected ClientConnection, public Singleton<Client> 69 { // tolua_export 70 friend class Singleton<Client>; 63 71 public: 64 72 Client(); 65 Client(const std::string& address, int port);66 73 ~Client(); 74 75 static Client* getInstance(){ return singletonPtr_s; } // tolua_export 67 76 68 77 bool establishConnection(); 78 void setDestination( const std::string& serverAddress, unsigned int port ); // tolua_export 69 79 bool closeConnection(); 70 80 bool queuePacket(ENetPacket *packet, int clientID); … … 81 91 virtual bool isServer_(){return false;} 82 92 83 GamestateClient gamestate; 93 static Client* singletonPtr_s; 94 GamestateClient* gamestate; 84 95 bool isSynched_; 85 96 86 97 bool gameStateFailure_; 87 98 float timeSinceLastUpdate_; 88 }; 99 }; // tolua_export 89 100 90 101 91 } 102 } // tolua_export 92 103 93 104 #endif /* _Client_H__ */ -
code/branches/presentation3/src/libraries/network/Connection.cc
r6417 r7161 36 36 namespace orxonox 37 37 { 38 Connection *Connection::instance_=0;38 // Connection *Connection::instance_=0; 39 39 40 40 Connection::Connection(): 41 41 host_(0) 42 42 { 43 assert(instance_==0);44 Connection::instance_=this;43 // assert(instance_==0); 44 // Connection::instance_=this; 45 45 enet_initialize(); 46 46 atexit(enet_deinitialize); … … 48 48 49 49 Connection::~Connection(){ 50 Connection::instance_=0;50 // Connection::instance_=0; 51 51 } 52 52 … … 67 67 68 68 bool Connection::sendPackets() { 69 if ( !Connection::instance_ ||this->host_==NULL )69 if ( /*!Connection::instance_ || */this->host_==NULL ) 70 70 return false; 71 71 enet_host_flush(this->host_); -
code/branches/presentation3/src/libraries/network/Connection.h
r6417 r7161 61 61 protected: 62 62 Connection(); 63 static Connection* getInstance(){ return Connection::instance_; }63 // static Connection* getInstance(){ return Connection::instance_; } 64 64 65 65 int service(ENetEvent* event); … … 75 75 ENetAddress *bindAddress_; 76 76 77 static Connection *instance_;77 // static Connection *instance_; 78 78 79 79 }; -
code/branches/presentation3/src/libraries/network/Host.cc
r5961 r7161 38 38 namespace orxonox { 39 39 40 SetConsoleCommandShortcut(Host, Chat);40 SetConsoleCommandShortcut(Host, Chat); 41 41 42 Host *Host::instance_=0; 42 // Host* Host::instance_=0; 43 uint32_t Host::clientID_s=0; 44 uint32_t Host::shipID_s=-1; 45 std::vector<Host*> Host::instances_s; 43 46 44 /**45 * @brief Constructor: assures that only one reference will be created and sets the pointer46 */47 Host::Host()48 {49 clientID_=0;50 assert(instance_==0);51 instance_=this;52 this->printRTTCC_ = createConsoleCommand( createFunctor(&Host::printRTT, this), "printRTT");53 CommandExecutor::addConsoleCommandShortcut( this->printRTTCC_ );54 }47 /** 48 * @brief Constructor: assures that only one reference will be created and sets the pointer 49 */ 50 Host::Host() 51 { 52 // assert(instance_==0); 53 instances_s.push_back(this); 54 this->printRTTCC_ = createConsoleCommand( createFunctor(&Host::printRTT, this), "printRTT" ); 55 CommandExecutor::addConsoleCommandShortcut( this->printRTTCC_ ); 56 this->bIsActive_ = false; 57 } 55 58 56 59 57 /** 58 * @brief Destructor: resets the instance pointer to 0 59 */ 60 Host::~Host() 61 { 62 instance_=0; 63 if( this->printRTTCC_ ) 64 delete this->printRTTCC_; 65 } 60 /** 61 * @brief Destructor: resets the instance pointer to 0 62 */ 63 Host::~Host() 64 { 65 assert( std::find( instances_s.begin(), instances_s.end(), this )!=instances_s.end() ); 66 instances_s.erase(std::find( instances_s.begin(), instances_s.end(), this )); 67 if( this->printRTTCC_ ) 68 delete this->printRTTCC_; 69 } 66 70 67 /** 68 * This function is used to add an enetpacket to be sent to another peer 69 * @param packet Packet to be added 70 * @param clientID ID of the client the packet should be sent to 71 * @return success? 72 */ 73 bool Host::addPacket(ENetPacket *packet, int clientID){ 74 if(instance_) 75 return instance_->queuePacket(packet, clientID); 76 else 77 return false; 78 } 71 /** 72 * This function is used to add an enetpacket to be sent to another peer 73 * @param packet Packet to be added 74 * @param clientID ID of the client the packet should be sent to 75 * @return success? 76 */ 77 bool Host::addPacket(ENetPacket *packet, int clientID) 78 { 79 bool result = true; 80 for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it ) 81 { 82 if( (*it)->isActive() ) 83 { 84 if( !(*it)->queuePacket(packet, clientID) ) 85 result = false; 86 } 87 } 88 return result; 89 } 79 90 80 /** 81 * This function returns the ID of the player 82 * @return playerID 83 */ 84 unsigned int Host::getPlayerID(){ 85 if(!instance_) 86 return 0; 87 return instance_->clientID_; 88 } 91 bool Host::Chat(const std::string& message) 92 { 93 if(instances_s.size()==0) 94 { 95 for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it) 96 it->incomingChat(message, 0); 97 return true; 98 } 99 else 100 { 101 bool result = true; 102 for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it ) 103 { 104 if( (*it)->isActive() ) 105 { 106 if( !(*it)->chat(message) ) 107 result = false; 108 } 109 } 110 return result; 111 } 112 } 89 113 90 bool Host::Chat(const std::string& message){ 91 if(!instance_) 114 bool Host::Broadcast(const std::string& message) 115 { 116 if(instances_s.size()==0) 117 { 118 for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it) 119 it->incomingChat(message, CLIENTID_UNKNOWN); 120 return true; 121 } 122 else 123 { 124 bool result = true; 125 for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it ) 126 { 127 if( (*it)->isActive() ) 128 { 129 if( !(*it)->broadcast(message) ) 130 result = false; 131 } 132 } 133 return result; 134 } 135 } 136 137 bool Host::incomingChat(const std::string& message, unsigned int playerID) 92 138 { 93 139 for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it) 94 it->incomingChat(message, 0); 95 return true; 140 it->incomingChat(message, playerID); 141 142 bool result = true; 143 for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it ) 144 { 145 if( (*it)->isActive() ) 146 { 147 if( !(*it)->processChat(message, playerID) ) 148 result = false; 149 } 150 } 151 return result; 96 152 } 97 return instance_->chat(message);98 }99 153 100 bool Host::Broadcast(const std::string& message){ 101 if(!instance_) 154 bool Host::isServer() 102 155 { 103 for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it) 104 it->incomingChat(message, CLIENTID_UNKNOWN); 105 return true; 156 for (std::vector<Host*>::iterator it=instances_s.begin(); it!=instances_s.end(); ++it ) 157 { 158 if( (*it)->isServer_() ) 159 return true; 160 } 161 return false; 106 162 } 107 else108 return instance_->broadcast(message);109 }110 111 bool Host::incomingChat(const std::string& message, unsigned int playerID){112 for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)113 it->incomingChat(message, playerID);114 115 return instance_->processChat(message, playerID);116 }117 163 118 164 }//namespace orxonox -
code/branches/presentation3/src/libraries/network/Host.h
r7153 r7161 33 33 #include "core/CorePrereqs.h" 34 34 35 #include <vector> 36 35 37 namespace orxonox { 36 38 … … 63 65 Host(); 64 66 virtual ~Host(); 65 static Host *instance_; 66 unsigned int clientID_; 67 unsigned int shipID_; 67 void setActive( bool bActive ){ bIsActive_ = bActive; } 68 // static Host *instance_; 68 69 69 70 public: 70 static bool running(){return instance_!=0;} 71 // static Host* getInstance(){ return instance_; } 72 static bool running(){ return instances_s.size(); } 71 73 static bool addPacket(ENetPacket *packet, int clientID=0); 72 74 //static bool chat(std::string& message); 73 75 // static bool receiveChat(packet::Chat *message, unsigned int clientID); 74 static unsigned int getPlayerID() ;75 static unsigned int getShipID(){return instance_->shipID_;}76 static void setClientID(unsigned int id){ instance_->clientID_= id; }77 static void setShipID(unsigned int id){ instance_->shipID_= id; }78 static bool isServer() { return instance_->isServer_(); }76 static unsigned int getPlayerID(){ return clientID_s; } 77 static unsigned int getShipID(){return shipID_s;} 78 static void setClientID(unsigned int id){ clientID_s = id; } 79 static void setShipID(unsigned int id){ shipID_s = id; } 80 static bool isServer(); 79 81 static bool Chat(const std::string& message); 80 82 static bool Broadcast(const std::string& message); 81 83 static bool incomingChat(const std::string& message, unsigned int playerID); 82 84 virtual void printRTT()=0; 85 bool isActive(){ return bIsActive_; } 83 86 private: 84 87 ConsoleCommand* printRTTCC_; 88 static uint32_t clientID_s; 89 static uint32_t shipID_s; 90 static std::vector<Host*> instances_s; 91 bool bIsActive_; 85 92 }; 86 93 -
code/branches/presentation3/src/libraries/network/NetworkPrereqs.h
r6417 r7161 64 64 namespace orxonox 65 65 { 66 static const unsigned int GAMESTATEID_INITIAL = static_cast<unsigned int>(-1); 67 static const unsigned int CLIENTID_UNKNOWN = static_cast<unsigned int>(-2); 66 static const unsigned int GAMESTATEID_INITIAL = static_cast<unsigned int>(-1); 67 static const unsigned int CLIENTID_UNKNOWN = static_cast<unsigned int>(-2); 68 extern const char* LAN_DISCOVERY_MESSAGE; 69 extern const char* LAN_DISCOVERY_ACK; 70 static const unsigned int LAN_DISCOVERY_PORT = 55557; 68 71 } 69 72 -
code/branches/presentation3/src/libraries/network/Server.cc
r6417 r7161 69 69 * 70 70 */ 71 Server::Server() { 71 Server::Server() 72 { 72 73 this->timeSinceLastUpdate_=0; 73 74 } 74 75 75 Server::Server(int port){ 76 Server::Server(int port) 77 { 76 78 this->setPort( port ); 77 79 this->timeSinceLastUpdate_=0; … … 83 85 * @param bindAddress Address to listen on 84 86 */ 85 Server::Server(int port, const std::string& bindAddress) { 87 Server::Server(int port, const std::string& bindAddress) 88 { 86 89 this->setPort( port ); 87 90 this->setBindAddress( bindAddress ); … … 92 95 * @brief Destructor 93 96 */ 94 Server::~Server(){ 97 Server::~Server() 98 { 95 99 } 96 100 … … 98 102 * This function opens the server by creating the listener thread 99 103 */ 100 void Server::open() { 104 void Server::open() 105 { 106 Host::setActive(true); 101 107 COUT(4) << "opening server" << endl; 102 108 this->openListener(); 109 LANDiscoverable::setActivity(true); 103 110 return; 104 111 } … … 107 114 * This function closes the server 108 115 */ 109 void Server::close() { 116 void Server::close() 117 { 118 Host::setActive(false); 110 119 COUT(4) << "closing server" << endl; 111 120 this->disconnectClients(); 112 121 this->closeListener(); 122 LANDiscoverable::setActivity(false); 113 123 return; 114 124 } 115 125 116 bool Server::processChat(const std::string& message, unsigned int playerID){ 126 bool Server::processChat(const std::string& message, unsigned int playerID) 127 { 117 128 ClientInformation *temp = ClientInformation::getBegin(); 118 129 packet::Chat *chat; … … 134 145 * @param time time since last tick 135 146 */ 136 void Server::update(const Clock& time) { 147 void Server::update(const Clock& time) 148 { 137 149 // receive incoming packets 138 150 Connection::processQueue(); 151 // receive and process incoming discovery packets 152 LANDiscoverable::update(); 139 153 140 154 if ( ClientInformation::hasClients() ) … … 157 171 } 158 172 159 bool Server::queuePacket(ENetPacket *packet, int clientID){ 173 bool Server::queuePacket(ENetPacket *packet, int clientID) 174 { 160 175 return ServerConnection::addPacket(packet, clientID); 161 176 } … … 164 179 * @brief: returns ping time to client in milliseconds 165 180 */ 166 unsigned int Server::getRTT(unsigned int clientID){ 181 unsigned int Server::getRTT(unsigned int clientID) 182 { 167 183 assert(ClientInformation::findClient(clientID)); 168 184 return ClientInformation::findClient(clientID)->getRTT(); … … 178 194 * @brief: return packet loss ratio to client (scales from 0 to 1) 179 195 */ 180 double Server::getPacketLoss(unsigned int clientID){ 196 double Server::getPacketLoss(unsigned int clientID) 197 { 181 198 assert(ClientInformation::findClient(clientID)); 182 199 return ClientInformation::findClient(clientID)->getPacketLoss(); … … 186 203 * takes a new snapshot of the gamestate and sends it to the clients 187 204 */ 188 void Server::updateGamestate() { 205 void Server::updateGamestate() 206 { 189 207 if( ClientInformation::getBegin()==NULL ) 190 208 //no client connected … … 208 226 * sends the gamestate 209 227 */ 210 bool Server::sendGameState() { 228 bool Server::sendGameState() 229 { 211 230 // COUT(5) << "Server: starting function sendGameState" << std::endl; 212 231 // ClientInformation *temp = ClientInformation::getBegin(); … … 244 263 } 245 264 246 bool Server::sendObjectDeletes(){ 265 bool Server::sendObjectDeletes() 266 { 247 267 ClientInformation *temp = ClientInformation::getBegin(); 248 268 if( temp == NULL ) … … 257 277 // COUT(3) << "sending DeleteObjects" << std::endl; 258 278 while(temp != NULL){ 259 if( !(temp->getSynched()) ){ 279 if( !(temp->getSynched()) ) 280 { 260 281 COUT(5) << "Server: not sending gamestate" << std::endl; 261 282 temp=temp->next(); … … 276 297 277 298 278 void Server::addPeer(ENetEvent *event){ 299 void Server::addPeer(ENetEvent *event) 300 { 279 301 static unsigned int newid=1; 280 302 281 303 COUT(2) << "Server: adding client" << std::endl; 282 304 ClientInformation *temp = ClientInformation::insertBack(new ClientInformation); 283 if(!temp){ 305 if(!temp) 306 { 284 307 COUT(2) << "Server: could not add client" << std::endl; 285 308 } … … 310 333 } 311 334 312 bool Server::createClient(int clientID){ 335 bool Server::createClient(int clientID) 336 { 313 337 ClientInformation *temp = ClientInformation::findClient(clientID); 314 if(!temp){ 338 if(!temp) 339 { 315 340 COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl; 316 341 return false; … … 345 370 } 346 371 347 void Server::disconnectClient( ClientInformation *client ){ 372 void Server::disconnectClient( ClientInformation *client ) 373 { 348 374 ServerConnection::disconnectClient( client ); 349 375 GamestateManager::removeClient(client); … … 352 378 } 353 379 354 bool Server::chat(const std::string& message){ 380 bool Server::chat(const std::string& message) 381 { 355 382 return this->sendChat(message, Host::getPlayerID()); 356 383 } 357 384 358 bool Server::broadcast(const std::string& message){ 385 bool Server::broadcast(const std::string& message) 386 { 359 387 return this->sendChat(message, CLIENTID_UNKNOWN); 360 388 } 361 389 362 bool Server::sendChat(const std::string& message, unsigned int clientID){ 390 bool Server::sendChat(const std::string& message, unsigned int clientID) 391 { 363 392 ClientInformation *temp = ClientInformation::getBegin(); 364 393 packet::Chat *chat; 365 while(temp){ 394 while(temp) 395 { 366 396 chat = new packet::Chat(message, clientID); 367 397 chat->setClientID(temp->getID()); … … 377 407 } 378 408 379 void Server::syncClassid(unsigned int clientID) { 409 void Server::syncClassid(unsigned int clientID) 410 { 380 411 int failures=0; 381 412 packet::ClassID *classid = new packet::ClassID(); -
code/branches/presentation3/src/libraries/network/Server.h
r6417 r7161 37 37 #include "GamestateManager.h" 38 38 #include "ServerConnection.h" 39 #include "LANDiscoverable.h" 39 40 40 41 namespace orxonox … … 45 46 * It implements all functions necessary for a Server 46 47 */ 47 class _NetworkExport Server : public Host, public ServerConnection, public GamestateManager {48 class _NetworkExport Server : public Host, public ServerConnection, public GamestateManager, public LANDiscoverable{ 48 49 public: 49 50 Server(); -
code/branches/presentation3/src/libraries/network/ServerConnection.cc
r6417 r7161 94 94 95 95 bool ServerConnection::addPacketAll(ENetPacket *packet) { 96 if ( !Connection::getInstance() )97 return false;98 enet_host_broadcast( Connection::get Instance()->getHost(), 0, packet);96 // if ( !Connection::getInstance() ) 97 // return false; 98 enet_host_broadcast( Connection::getHost(), 0, packet); 99 99 return true; 100 100 } -
code/branches/presentation3/src/libraries/network/ServerConnection.h
r6417 r7161 56 56 bool openListener(); 57 57 bool closeListener(); 58 staticbool addPacket(ENetPacket *packet, unsigned int ID);59 staticbool addPacketAll(ENetPacket *packet);58 bool addPacket(ENetPacket *packet, unsigned int ID); 59 bool addPacketAll(ENetPacket *packet); 60 60 virtual void disconnectClient(ClientInformation *client); 61 61 void disconnectClient(int clientID); -
code/branches/presentation3/src/libraries/network/packet/CMakeLists.txt
r5929 r7161 11 11 Welcome.cc 12 12 COMPILATION_END 13 ServerInformation.cc 13 14 ) 14 15 … … 23 24 Gamestate.h 24 25 Packet.h 26 ServerInformation.h 25 27 Welcome.h 26 28 ) -
code/branches/presentation3/src/libraries/network/packet/Packet.cc
r7153 r7161 62 62 std::map<size_t, Packet *> Packet::packetMap_; 63 63 64 Packet::Packet(){ 64 Packet::Packet() 65 { 65 66 flags_ = PACKET_FLAG_DEFAULT; 66 67 packetDirection_ = Direction::Outgoing; … … 71 72 } 72 73 73 Packet::Packet(uint8_t *data, unsigned int clientID){ 74 Packet::Packet(uint8_t *data, unsigned int clientID) 75 { 74 76 flags_ = PACKET_FLAG_DEFAULT; 75 77 packetDirection_ = Direction::Incoming; -
code/branches/presentation3/src/libraries/network/synchronisable/Synchronisable.cc
r7153 r7161 54 54 static uint32_t idCounter=0; 55 55 objectMode_=0x1; // by default do not send data to server 56 if ( GameMode::isMaster() || ( Host::running() && Host::isServer() ))56 if ( GameMode::isMaster()/* || ( Host::running() && Host::isServer() )*/ ) 57 57 { 58 58 this->setObjectID( idCounter++ ); -
code/branches/presentation3/src/libraries/util/Serialise.h
r7127 r7161 53 53 template <class T> inline bool checkEquality( const T& variable, uint8_t* mem ); 54 54 55 56 // =========== char* 57 58 inline uint32_t returnSize( char*& variable ) 59 { 60 return strlen(variable)+1; 61 } 62 63 inline void saveAndIncrease( char*& variable, uint8_t*& mem ) 64 { 65 strcpy((char*)mem, variable); 66 mem += returnSize(variable); 67 } 68 69 inline void loadAndIncrease( char*& variable, uint8_t*& mem ) 70 { 71 if( variable ) 72 delete variable; 73 uint32_t len = strlen((char*)mem)+1; 74 variable = new char[len]; 75 strcpy((char*)variable, (char*)mem); 76 mem += len; 77 } 78 79 inline bool checkEquality( char*& variable, uint8_t* mem ) 80 { 81 return strcmp(variable, (char*)mem)==0; 82 } 83 55 84 // =================== Template specialisation stuff ============= 56 85 … … 394 423 return memcmp(&temp, mem, sizeof(uint64_t))==0; 395 424 } 396 425 397 426 // =========== string 398 427 -
code/branches/presentation3/src/orxonox/CameraManager.cc
r6417 r7161 68 68 void CameraManager::requestFocus(Camera* camera) 69 69 { 70 COUT(0) << "bliub" << endl; 70 71 // notify old camera (if it exists) 71 72 if (!this->cameraList_.empty()) -
code/branches/presentation3/src/orxonox/Main.cc
r6105 r7161 40 40 #include "core/LuaState.h" 41 41 #include "ToluaBindOrxonox.h" 42 #include "ToluaBindNetwork.h" 42 43 #include "Main.h" 43 44 … … 51 52 52 53 DeclareToluaInterface(Orxonox); 54 DeclareToluaInterface(Network); 53 55 54 56 namespace orxonox -
code/branches/presentation3/src/orxonox/gamestates/GSClient.cc
r7122 r7161 44 44 GSClient::GSClient(const GameStateInfo& info) 45 45 : GameState(info) 46 , client_(0)47 46 { 48 47 } … … 56 55 GameMode::setIsClient(true); 57 56 58 this->client_ = new Client(CommandLineParser::getValue("dest").getString(), CommandLineParser::getValue("port")); 57 // this->client_ = new Client(); 58 // this->client_->setDestination(CommandLineParser::getValue("dest").getString(), CommandLineParser::getValue("port") ); 59 59 60 if( !client_->establishConnection())60 if( !Client::getInstance()->establishConnection() ) 61 61 { 62 delete this->client_;63 62 ThrowException(InitialisationFailed, "Could not establish connection with server."); 64 63 } 65 64 66 client_->update(Game::getInstance().getGameClock());65 Client::getInstance()->update(Game::getInstance().getGameClock()); 67 66 } 68 67 69 68 void GSClient::deactivate() 70 69 { 71 client_->closeConnection();70 Client::getInstance()->closeConnection(); 72 71 73 72 // destroy client 74 delete this->client_;73 // delete this->client_; 75 74 76 75 GameMode::setIsClient(false); … … 79 78 void GSClient::update(const Clock& time) 80 79 { 81 client_->update(time);80 Client::getInstance()->update(time); 82 81 } 83 82 } -
code/branches/presentation3/src/orxonox/gamestates/GSClient.h
r5929 r7161 46 46 void deactivate(); 47 47 void update(const Clock& time); 48 49 private:50 Client* client_;51 48 }; 52 49 }
Note: See TracChangeset
for help on using the changeset viewer.