[Orxonox-commit 3642] r8327 - in code/trunk: . src/libraries/core src/libraries/network src/libraries/network/packet src/libraries/network/synchronisable src/modules/overlays/hud src/orxonox src/orxonox/gamestates src/orxonox/gametypes src/orxonox/infos
scheusso at orxonox.net
scheusso at orxonox.net
Mon Apr 25 20:22:36 CEST 2011
Author: scheusso
Date: 2011-04-25 20:22:36 +0200 (Mon, 25 Apr 2011)
New Revision: 8327
Added:
code/trunk/src/libraries/core/ThreadWin.cc
Removed:
code/trunk/src/libraries/network/ClientInformation.cc
code/trunk/src/libraries/network/ClientInformation.h
code/trunk/src/libraries/network/GamestateClient.cc
code/trunk/src/libraries/network/GamestateClient.h
Modified:
code/trunk/
code/trunk/src/libraries/core/Thread.cc
code/trunk/src/libraries/network/CMakeLists.txt
code/trunk/src/libraries/network/Client.cc
code/trunk/src/libraries/network/ClientConnection.cc
code/trunk/src/libraries/network/ClientConnection.h
code/trunk/src/libraries/network/ClientConnectionListener.cc
code/trunk/src/libraries/network/ClientConnectionListener.h
code/trunk/src/libraries/network/Connection.cc
code/trunk/src/libraries/network/Connection.h
code/trunk/src/libraries/network/GamestateHandler.h
code/trunk/src/libraries/network/GamestateManager.cc
code/trunk/src/libraries/network/GamestateManager.h
code/trunk/src/libraries/network/Host.cc
code/trunk/src/libraries/network/NetworkPrereqs.h
code/trunk/src/libraries/network/Server.cc
code/trunk/src/libraries/network/Server.h
code/trunk/src/libraries/network/ServerConnection.cc
code/trunk/src/libraries/network/ServerConnection.h
code/trunk/src/libraries/network/WANDiscovery.cc
code/trunk/src/libraries/network/packet/Gamestate.cc
code/trunk/src/libraries/network/packet/Packet.cc
code/trunk/src/libraries/network/packet/Packet.h
code/trunk/src/libraries/network/synchronisable/Synchronisable.cc
code/trunk/src/modules/overlays/hud/ChatOverlay.cc
code/trunk/src/orxonox/ChatHistory.cc
code/trunk/src/orxonox/ChatInputHandler.cc
code/trunk/src/orxonox/PlayerManager.cc
code/trunk/src/orxonox/gamestates/GSRoot.cc
code/trunk/src/orxonox/gametypes/Dynamicmatch.cc
code/trunk/src/orxonox/gametypes/Gametype.cc
code/trunk/src/orxonox/gametypes/LastManStanding.cc
code/trunk/src/orxonox/gametypes/LastTeamStanding.cc
code/trunk/src/orxonox/gametypes/TeamBaseMatch.cc
code/trunk/src/orxonox/gametypes/UnderAttack.cc
code/trunk/src/orxonox/infos/GametypeInfo.cc
code/trunk/src/orxonox/infos/HumanPlayer.cc
code/trunk/src/orxonox/infos/PlayerInfo.cc
Log:
merging network6 into trunk
Property changes on: code/trunk
___________________________________________________________________
Modified: svn:mergeinfo
- /code/branches/ai:6592-7033
/code/branches/buildsystem:1874-2276,2278-2400
/code/branches/buildsystem2:2506-2658
/code/branches/buildsystem3:2662-2708
/code/branches/ceguilua:1802-1808
/code/branches/chat:6527-6797
/code/branches/chat2:6836-6910
/code/branches/console:5941-6104
/code/branches/consolecommands2:6451-7178
/code/branches/consolecommands3:7178-7283
/code/branches/core3:1572-1739
/code/branches/core4:3221-3224,3227,3234-3238,3242,3244-3250,3252-3254,3256,3259-3261,3264-3265,3268-3275,3277-3278,3280,3284-3285,3287,3289-3294,3305,3309-3310
/code/branches/core5:5768-5928,6009
/code/branches/data_cleanup:7537-7686
/code/branches/doc:7290-7400
/code/branches/dynamicmatch:6584-7030
/code/branches/fps:6591-7072
/code/branches/gamestate:6430-6572,6621-6661
/code/branches/gamestates2:6594-6745
/code/branches/gametypes:2826-3031
/code/branches/gcc43:1580
/code/branches/gui:1635-1723,2795-2894
/code/branches/hudelements:6584-6941
/code/branches/ingamemenu:6000-6023
/code/branches/input:1629-1636
/code/branches/ipv6:7293-7458
/code/branches/kicklib:7975-7977
/code/branches/lastmanstanding:7479-7644
/code/branches/lastmanstanding3:7903-8175
/code/branches/libraries:5612-5692
/code/branches/libraries2:5703-5737
/code/branches/lod:6586-6911
/code/branches/lodfinal:2372-2411
/code/branches/map:2801-3086,3089
/code/branches/masterserver:7502-7738
/code/branches/menu:5941-6146,6148,7536-7687
/code/branches/miniprojects:2754-2824
/code/branches/netp2:2835-2988
/code/branches/netp3:2988-3082
/code/branches/netp6:3214-3302
/code/branches/network:2356
/code/branches/network2:6434-6465
/code/branches/network3:7196-7344
/code/branches/network4:7497-7755
/code/branches/network5:7757-7781
/code/branches/network64:2210-2355
/code/branches/notifications:7314-7401
/code/branches/objecthierarchy:1911-2085,2100,2110-2169
/code/branches/objecthierarchy2:2171-2479
/code/branches/overlay:2117-2385
/code/branches/particles:2829-3085
/code/branches/particles2:6050-6106,6109
/code/branches/pch:3113-3194
/code/branches/physics:1912-2055,2107-2439
/code/branches/physics_merge:2436-2457
/code/branches/pickup2:5942-6405
/code/branches/pickup3:6418-6523
/code/branches/pickup4:6594-6710
/code/branches/pickups:1926-2086,2127,2827-2915
/code/branches/pickups2:2107-2497,2915-3071
/code/branches/png2:7262-7263
/code/branches/ppspickups1:6552-6708
/code/branches/ppspickups2:6527-6532,6554-6709
/code/branches/ppspickups3:6757-6997
/code/branches/ppspickups4:7003-7089
/code/branches/presentation:2369-2652,2654-2660,7736-7786
/code/branches/presentation2:6106-6416,7787-7800
/code/branches/presentation3:6913-7162
/code/branches/questsystem:1894-2088
/code/branches/questsystem2:2107-2259
/code/branches/questsystem5:2776-2905
/code/branches/releasetodo:7614-7647
/code/branches/resource:3327-3366
/code/branches/resource2:3372-5694
/code/branches/rocket:6523-6950
/code/branches/rocket2:6953-6970
/code/branches/script_trigger:1295-1953,1955
/code/branches/skybox2:6559-6989
/code/branches/sound:2829-3010
/code/branches/sound3:5941-6102
/code/branches/steering:5949-6091
/code/branches/tetris:8100-8107
/code/branches/usability:7915-8078
/code/branches/weapon:1925-2094
/code/branches/weapon2:2107-2488
/code/branches/weapons:2897-3051
/code/branches/weaponsystem:2742-2890
+ /code/branches/ai:6592-7033
/code/branches/buildsystem:1874-2276,2278-2400
/code/branches/buildsystem2:2506-2658
/code/branches/buildsystem3:2662-2708
/code/branches/ceguilua:1802-1808
/code/branches/chat:6527-6797
/code/branches/chat2:6836-6910
/code/branches/console:5941-6104
/code/branches/consolecommands2:6451-7178
/code/branches/consolecommands3:7178-7283
/code/branches/core3:1572-1739
/code/branches/core4:3221-3224,3227,3234-3238,3242,3244-3250,3252-3254,3256,3259-3261,3264-3265,3268-3275,3277-3278,3280,3284-3285,3287,3289-3294,3305,3309-3310
/code/branches/core5:5768-5928,6009
/code/branches/data_cleanup:7537-7686
/code/branches/doc:7290-7400
/code/branches/dynamicmatch:6584-7030
/code/branches/fps:6591-7072
/code/branches/gamestate:6430-6572,6621-6661
/code/branches/gamestates2:6594-6745
/code/branches/gametypes:2826-3031
/code/branches/gcc43:1580
/code/branches/gui:1635-1723,2795-2894
/code/branches/hudelements:6584-6941
/code/branches/ingamemenu:6000-6023
/code/branches/input:1629-1636
/code/branches/ipv6:7293-7458
/code/branches/kicklib:7975-7977
/code/branches/lastmanstanding:7479-7644
/code/branches/lastmanstanding3:7903-8175
/code/branches/libraries:5612-5692
/code/branches/libraries2:5703-5737
/code/branches/lod:6586-6911
/code/branches/lodfinal:2372-2411
/code/branches/map:2801-3086,3089
/code/branches/masterserver:7502-7738
/code/branches/menu:5941-6146,6148,7536-7687
/code/branches/miniprojects:2754-2824
/code/branches/netp2:2835-2988
/code/branches/netp3:2988-3082
/code/branches/netp6:3214-3302
/code/branches/network:2356
/code/branches/network2:6434-6465
/code/branches/network3:7196-7344
/code/branches/network4:7497-7755
/code/branches/network5:7757-7781
/code/branches/network6:7823-8315
/code/branches/network64:2210-2355
/code/branches/notifications:7314-7401
/code/branches/objecthierarchy:1911-2085,2100,2110-2169
/code/branches/objecthierarchy2:2171-2479
/code/branches/overlay:2117-2385
/code/branches/particles:2829-3085
/code/branches/particles2:6050-6106,6109
/code/branches/pch:3113-3194
/code/branches/physics:1912-2055,2107-2439
/code/branches/physics_merge:2436-2457
/code/branches/pickup2:5942-6405
/code/branches/pickup3:6418-6523
/code/branches/pickup4:6594-6710
/code/branches/pickups:1926-2086,2127,2827-2915
/code/branches/pickups2:2107-2497,2915-3071
/code/branches/png2:7262-7263
/code/branches/ppspickups1:6552-6708
/code/branches/ppspickups2:6527-6532,6554-6709
/code/branches/ppspickups3:6757-6997
/code/branches/ppspickups4:7003-7089
/code/branches/presentation:2369-2652,2654-2660,7736-7786
/code/branches/presentation2:6106-6416,7787-7800
/code/branches/presentation3:6913-7162
/code/branches/questsystem:1894-2088
/code/branches/questsystem2:2107-2259
/code/branches/questsystem5:2776-2905
/code/branches/releasetodo:7614-7647
/code/branches/resource:3327-3366
/code/branches/resource2:3372-5694
/code/branches/rocket:6523-6950
/code/branches/rocket2:6953-6970
/code/branches/script_trigger:1295-1953,1955
/code/branches/skybox2:6559-6989
/code/branches/sound:2829-3010
/code/branches/sound3:5941-6102
/code/branches/steering:5949-6091
/code/branches/tetris:8100-8107
/code/branches/usability:7915-8078
/code/branches/weapon:1925-2094
/code/branches/weapon2:2107-2488
/code/branches/weapons:2897-3051
/code/branches/weaponsystem:2742-2890
Modified: code/trunk/src/libraries/core/Thread.cc
===================================================================
--- code/trunk/src/libraries/core/Thread.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/core/Thread.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -26,6 +26,11 @@
*
*/
+#if defined(ORXONOX_PLATFORM_WINDOWS)
+ #include "ThreadWin.cc"
+#elif defined(ORXONOX_PLATFORM_UNIX)
+
+
#include "Thread.h"
#include <cassert>
@@ -90,9 +95,9 @@
bool stopThread = false;
while( !stopThread )
{
- //this->executorMutex_->lock();
+ this->executorMutex_->lock();
ExecutorPtr executor = this->executor_;
- //this->executorMutex_->unlock();
+ this->executorMutex_->unlock();
if( executor )
{
(*executor)();
@@ -107,9 +112,9 @@
{
this->workerThread_->yield();
}
- //this->stopThreadMutex_->lock();
+ this->stopThreadMutex_->lock();
stopThread = this->stopThread_;
- //this->stopThreadMutex_->unlock();
+ this->stopThreadMutex_->unlock();
}
}
@@ -126,3 +131,5 @@
}
}
}
+
+#endif
Copied: code/trunk/src/libraries/core/ThreadWin.cc (from rev 8315, code/branches/network6/src/libraries/core/ThreadWin.cc)
===================================================================
--- code/trunk/src/libraries/core/ThreadWin.cc (rev 0)
+++ code/trunk/src/libraries/core/ThreadWin.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -0,0 +1,132 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Oliver Scheuss
+ * Co-authors:
+ * ...
+ *
+ */
+
+
+#include "Thread.h"
+
+#include <cassert>
+// #include <boost/thread/thread.hpp>
+// #include <boost/bind.hpp>
+// #include <boost/thread/mutex.hpp>
+// #include <boost/thread/thread_time.hpp>
+
+// #include "util/Sleep.h"
+#include "command/Executor.h"
+
+namespace orxonox
+{
+// boost::posix_time::millisec THREAD_WAIT_BEFORE_DETACH(1000);
+
+
+ Thread::Thread():
+ executor_(0),
+ isWorking_(false),
+ stopThread_(false)
+ {
+// this->executorMutex_ = new boost::mutex;
+// this->isWorkingMutex_ = new boost::mutex;
+// this->stopThreadMutex_ = new boost::mutex;
+// this->workerThread_ = new boost::thread( boost::bind(&Thread::threadLoop, this) );
+ }
+
+ Thread::~Thread()
+ {
+// this->stopThreadMutex_->lock();
+// this->stopThread_ = true;
+// this->stopThreadMutex_->unlock();
+// if( !this->workerThread_->timed_join( THREAD_WAIT_BEFORE_DETACH ) )
+// assert(0); // this should not happen
+// delete this->workerThread_;
+// delete this->executorMutex_;
+// delete this->stopThreadMutex_;
+// delete this->isWorkingMutex_;
+ }
+
+ bool Thread::isWorking()
+ {
+// this->isWorkingMutex_->lock();
+// bool isWorking = this->isWorking_;
+// this->isWorkingMutex_->unlock();
+// return isWorking;
+ return false;
+ }
+
+ bool Thread::evaluateExecutor( const ExecutorPtr& executor )
+ {
+// this->isWorkingMutex_->lock();
+// this->isWorking_=true;
+// this->isWorkingMutex_->unlock();
+// this->executorMutex_->lock();
+// this->executor_ = executor;
+// this->executorMutex_->unlock();
+ (*executor)();
+ return true;
+ }
+
+ void Thread::threadLoop()
+ {
+// bool stopThread = false;
+// while( !stopThread )
+// {
+// this->executorMutex_->lock();
+// ExecutorPtr executor = this->executor_;
+// this->executorMutex_->unlock();
+// if( executor )
+// {
+// (*executor)();
+// this->executorMutex_->lock();
+// this->executor_ = 0;
+// this->executorMutex_->unlock();
+// this->isWorkingMutex_->lock();
+// this->isWorking_=false;
+// this->isWorkingMutex_->unlock();
+// }
+// else
+// {
+// this->workerThread_->yield();
+// }
+// this->stopThreadMutex_->lock();
+// stopThread = this->stopThread_;
+// this->stopThreadMutex_->unlock();
+// }
+ }
+
+ void Thread::waitUntilFinished()
+ {
+// bool stillWorking = true;
+// while( stillWorking )
+// {
+// this->isWorkingMutex_->lock();
+// stillWorking = this->isWorking_;
+// this->isWorkingMutex_->unlock();
+// if( stillWorking )
+// msleep( 1 );
+// }
+ }
+}
+
Modified: code/trunk/src/libraries/network/CMakeLists.txt
===================================================================
--- code/trunk/src/libraries/network/CMakeLists.txt 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/CMakeLists.txt 2011-04-25 18:22:36 UTC (rev 8327)
@@ -21,7 +21,6 @@
ChatListener.cc
Client.cc
ClientConnection.cc
- ClientInformation.cc
ClientConnectionListener.cc
Connection.cc
FunctionCall.cc
@@ -49,7 +48,6 @@
Client.h
ClientConnection.h
ClientConnectionListener.h
- ClientInformation.h
Connection.h
FunctionCall.h
FunctionCallManager.h
Modified: code/trunk/src/libraries/network/Client.cc
===================================================================
--- code/trunk/src/libraries/network/Client.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/Client.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -154,12 +154,14 @@
{
COUT(4) << "popping partial gamestate: " << std::endl;
// packet::Gamestate *gs = GamestateClient::getGamestate();
- GamestateManager::update();
- std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates();
- std::vector<packet::Gamestate*>::iterator it;
- for( it = gamestates.begin(); it != gamestates.end(); ++it )
+ if( GamestateManager::update() )
{
- (*it)->send( static_cast<Host*>(this) );
+ std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates();
+ std::vector<packet::Gamestate*>::iterator it;
+ for( it = gamestates.begin(); it != gamestates.end(); ++it )
+ {
+ (*it)->send( static_cast<Host*>(this) );
+ }
}
//assert(gs); <--- there might be the case that no data has to be sent, so its commented out now
// if(gs){
@@ -206,7 +208,7 @@
{
if( packet->isReliable() )
{
- if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )
+ if( this->getLastReceivedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )
packet->process(static_cast<Host*>(this));
else
this->packetQueue_.push_back(packet);
Modified: code/trunk/src/libraries/network/ClientConnection.cc
===================================================================
--- code/trunk/src/libraries/network/ClientConnection.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/ClientConnection.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -41,6 +41,7 @@
ClientConnection::ClientConnection():
+ Connection(NETWORK_PEER_ID_SERVER),
established_(false),
server_(NULL)
{
@@ -102,6 +103,10 @@
{
if( enet_host_service(this->host_, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && event.type == ENET_EVENT_TYPE_CONNECT )
{
+ // manually add server to list of peers
+ /*incomingEvent inEvent = */Connection::preprocessConnectEvent(event);
+// addPeer(inEvent.peerID);
+ // start communication thread
this->established_=true;
Connection::startCommunicationThread();
return true;
@@ -117,6 +122,8 @@
if ( !this->established_ )
return true;
this->established_ = false;
+
+ // stop communication thread and disconnect server
Connection::stopCommunicationThread();
enet_peer_disconnect(this->server_, 0);
for( unsigned int i=0; i<NETWORK_CLIENT_CONNECTION_TIMEOUT/NETWORK_CLIENT_WAIT_TIME; i++)
@@ -147,14 +154,16 @@
void ClientConnection::addPacket(ENetPacket *packet, uint8_t channelID) {
assert( this->server_ );
assert( packet );
- return Connection::addPacket( packet, this->server_, channelID );
+// return Connection::addPacket( packet, NETWORK_PEER_ID_SERVER, channelID );
+ // HACK: actually there should be a way to do this using addPacket and the correct peerID
+ return Connection::broadcastPacket(packet, channelID);
}
- void ClientConnection::addPeer(ENetEvent* event)
+ void ClientConnection::addPeer(uint32_t peerID)
{
assert(0);
}
- void ClientConnection::removePeer(ENetEvent* event)
+ void ClientConnection::removePeer(uint32_t peerID)
{
this->established_=false;
COUT(1) << "Received disconnect Packet from Server!" << endl;
Modified: code/trunk/src/libraries/network/ClientConnection.h
===================================================================
--- code/trunk/src/libraries/network/ClientConnection.h 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/ClientConnection.h 2011-04-25 18:22:36 UTC (rev 8327)
@@ -56,8 +56,8 @@
virtual void connectionClosed()=0;
uint32_t getRTT();
private:
- virtual void addPeer(ENetEvent* event);
- virtual void removePeer(ENetEvent* event);
+ virtual void addPeer(uint32_t peerID);
+ virtual void removePeer(uint32_t peerID);
bool disconnectConnection();
// enet stuff
Modified: code/trunk/src/libraries/network/ClientConnectionListener.cc
===================================================================
--- code/trunk/src/libraries/network/ClientConnectionListener.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/ClientConnectionListener.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -30,7 +30,7 @@
#include "core/CoreIncludes.h"
#include "core/GameMode.h"
-#include "ClientInformation.h"
+// #include "ClientInformation.h"
namespace orxonox
{
@@ -51,15 +51,15 @@
it->clientDisconnected(clientID);
}
- void ClientConnectionListener::getConnectedClients()
- {
- ClientInformation* client = ClientInformation::getBegin();
- while (client)
- {
- this->clientConnected(client->getID());
- client = client->next();
- }
- }
+// void ClientConnectionListener::getConnectedClients()
+// {
+// ClientInformation* client = ClientInformation::getBegin();
+// while (client)
+// {
+// this->clientConnected(client->getID());
+// client = client->next();
+// }
+// }
}
Modified: code/trunk/src/libraries/network/ClientConnectionListener.h
===================================================================
--- code/trunk/src/libraries/network/ClientConnectionListener.h 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/ClientConnectionListener.h 2011-04-25 18:22:36 UTC (rev 8327)
@@ -47,7 +47,7 @@
virtual void clientDisconnected(unsigned int clientID) = 0;
protected:
- void getConnectedClients();
+// void getConnectedClients();
};
}
Deleted: code/trunk/src/libraries/network/ClientInformation.cc
===================================================================
--- code/trunk/src/libraries/network/ClientInformation.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/ClientInformation.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -1,251 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * ...
- * Co-authors:
- * ...
- *
- */
-
-//
-// C++ Implementation: ClientInformation
-//
-// Description:
-//
-//
-// Author: <>, (C) 2007
-//
-// Copyright: See COPYING file that comes with this distribution
-//
-//
-
-#include "ClientInformation.h"
-#define WIN32_LEAN_AND_MEAN
-#include <enet/enet.h>
-#include "ClientConnectionListener.h"
-
-namespace orxonox
-{
-
-
- ClientInformation *ClientInformation::head_=0;
-
- ClientInformation::ClientInformation() {
- if(!head_)
- head_=this;
- gamestateID_=GAMESTATEID_INITIAL;
- preve=0;
- nexte=0;
- synched_=false;
- }
-
- ClientInformation::~ClientInformation() {
- if(prev()!=0)
- prev()->setNext(this->next());
- if(next()!=0)
- next()->setPrev(this->prev());
- if(this==head_)
- head_=next();
- ClientConnectionListener::broadcastClientDisconnected( this->getID() );
- }
-
- ClientInformation *ClientInformation::next() {
- if(this!=0)
- return this->nexte;
- else
- return 0;
- }
- ClientInformation *ClientInformation::prev() {
- if(this!=0)
- return this->preve;
- else
- return 0;
- }
-
- bool ClientInformation::setPrev(ClientInformation *prev) {
- if(this==head_)
- head_=prev;
- this->preve = prev;
- return true;
- }
-
- bool ClientInformation::setNext(ClientInformation *next) {
- this->nexte = next;
- return true;
- }
-
- ClientInformation *ClientInformation::insertAfter(ClientInformation *ins) {
- this->next()->setPrev(ins);
- ins->setNext(this->next());
- ins->setPrev(this);
- this->nexte = ins;
- return ins;
- }
-
- ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){
- if(!this)
- return NULL;
- this->prev()->setNext(ins);
- ins->setPrev(this->prev());
- this->preve=ins;
- ins->setNext(this);
- return ins;
- }
-
- void ClientInformation::setID(int clientID){
- if(!this)
- return;
- clientID_ = clientID;
- }
-
- bool ClientInformation::setPeer(ENetPeer *peer){
- if(!this)
- return false;
- peer_ = peer;
- return true;
- }
-
- bool ClientInformation::setGamestateID(int id){
- if(!this)
- return false;
- gamestateID_=id;
- return true;
- }
-
- unsigned int ClientInformation::getID() {
- if(!this)
- return CLIENTID_UNKNOWN;
- else
- return clientID_;
- }
-
- ENetPeer *ClientInformation::getPeer() {
- if(this)
- return peer_;
- else
- return NULL;
- }
-
- uint32_t ClientInformation::getRTT(){
- return this->peer_->roundTripTime;
- }
-
- double ClientInformation::getPacketLoss(){
- return static_cast<double>(this->peer_->packetLoss)/ENET_PEER_PACKET_LOSS_SCALE;
- }
-
- unsigned int ClientInformation::getGamestateID() {
- if(this)
- return gamestateID_;
- else
- return static_cast<unsigned int>(-1);
- }
-
- ClientInformation *ClientInformation::insertBack(ClientInformation *ins) {
- ClientInformation *temp = head_;
- if(temp==ins){
- return head_;
- }
- while(temp->next()!=0){
- temp = temp->next();
- }
- temp->setNext(ins);
- ins->setPrev(temp);
- return ins;
- }
-
- bool ClientInformation::removeClient(unsigned int clientID) {
- if(clientID==CLIENTID_UNKNOWN)
- return false;
- ClientInformation *temp = head_;
- while(temp!=0 && temp->getID()!=clientID)
- temp = temp->next();
- if(temp==0)
- return false;
- delete temp;
- return true;
- }
-
- bool ClientInformation::removeClient(ENetPeer *peer) {
- if(!peer)
- return false;
- ClientInformation *temp = head_;
- while(temp!=0){
- if(!memcmp(& temp->getPeer()->address, & peer->address, sizeof(peer->address)))
- break;
- temp = temp->next();
- }
- if(temp==0)
- return false;
- delete temp;
- return true;
- }
-
- /**
- * This function goes forward through the list and looks for an element with clientID
- * This function should only be applied to the head of the list
- * @param clientID id to look for
- * @param look_backwards FIXME - add doc? parameter unused?
- * @return pointer to the last element in the list or 0 if the search was unsuccessfull
- */
- ClientInformation *ClientInformation::findClient(unsigned int clientID, bool look_backwards) {
- ClientInformation *temp = head_;
- while(temp!=0 && temp->getID()!=clientID){
- temp = temp->next();
- }
- // returns 0 if nothing has been found
- return temp;
- }
-
- /**
- * This function goes forward through the list and looks for an element with clientID
- * This function should only be applied to the head of the list
- * @param address peer to look for
- * @param look_backwards FIXME - add doc? parameter unused?
- * @return pointer to the element in the list
- */
- ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) {
- ClientInformation *temp = head_;
- while(temp!=0){
- if(!memcmp(& temp->getPeer()->address, address, sizeof(*address)))
- break;
- temp = temp->next();
- }
- // returns 0 if nothing has been found
- return temp;
- }
-
- bool ClientInformation::setSynched(bool s) {
- if(!this)
- return false;
- synched_=s;
- return true;
- }
-
- bool ClientInformation::getSynched() {
- if(this)
- return synched_;
- else
- return false;
- }
-
-}
Deleted: code/trunk/src/libraries/network/ClientInformation.h
===================================================================
--- code/trunk/src/libraries/network/ClientInformation.h 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/ClientInformation.h 2011-04-25 18:22:36 UTC (rev 8327)
@@ -1,110 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * ...
- * Co-authors:
- * ...
- *
- */
-
-//
-// C++ Interface: ClientInformation
-//
-// Description:
-//
-//
-// Author: <>, (C) 2007
-//
-// Copyright: See COPYING file that comes with this distribution
-//
-//
-#ifndef _ClientInformation_H__
-#define _ClientInformation_H__
-
-#include "NetworkPrereqs.h"
-
-// WATCH OUT: THE CLIENTINFORMATION LIST IS NOT THREADSAFE ANYMORE
-
-namespace orxonox
-{
-
- /**
- * This class implements a list for client information
- * @author Oliver Scheuss
- */
- class _NetworkExport ClientInformation{
- public:
- ClientInformation();
- // ClientInformation(ClientInformation *prev, ClientInformation *next);
- // ClientInformation(ClientInformation *prev);
- ~ClientInformation();
- ClientInformation *next();
- ClientInformation *prev();
- static ClientInformation *insertBack(ClientInformation *ins);
-
- // set functions
- void setID(int clientID);
- bool setPeer(ENetPeer *peer);
- bool setGamestateID(int id);
- inline void setShipID(unsigned int id){ShipID_=id;}
-
- // get functions
- inline unsigned int getShipID(){return ShipID_;}
- unsigned int getID();
- unsigned int getGamestateID();
- ENetPeer *getPeer();
-
- uint32_t getRTT();
- double getPacketLoss();
-
- static bool removeClient(unsigned int clientID);
- static bool removeClient(ENetPeer *peer);
- static ClientInformation *findClient(unsigned int clientID, bool look_backwards=false);
- static ClientInformation *findClient(ENetAddress *address, bool look_backwards=false);
- static ClientInformation *getBegin(){return head_;}
- static bool hasClients(){ return ClientInformation::head_!=0; }
-
- bool setSynched(bool s);
- bool getSynched();
-
- private:
- static ClientInformation *head_;
-
- bool setNext(ClientInformation *next);
- bool setPrev(ClientInformation *prev);
- ClientInformation *insertAfter(ClientInformation *ins);
- ClientInformation *insertBefore(ClientInformation *ins);
-
- ClientInformation *preve;
- ClientInformation *nexte;
- //actual information:
- ENetPeer *peer_;
- unsigned int clientID_;
- unsigned int gamestateID_;
- unsigned int ShipID_; // this is the unique objectID
- bool synched_;
-
- };
-
-}
-
-#endif /* _ClientInformation_H__ */
Modified: code/trunk/src/libraries/network/Connection.cc
===================================================================
--- code/trunk/src/libraries/network/Connection.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/Connection.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -37,18 +37,21 @@
#include <boost/date_time.hpp>
#include "packet/Packet.h"
+#include <util/Sleep.h>
namespace orxonox
{
- const boost::posix_time::millisec NETWORK_COMMUNICATION_THREAD_WAIT_TIME(20);
+ const boost::posix_time::millisec NETWORK_COMMUNICATION_THREAD_WAIT_TIME(200);
+ const unsigned int NETWORK_DISCONNECT_TIMEOUT = 500;
- Connection::Connection():
- host_(0), bCommunicationThreadRunning_(false)
+ Connection::Connection(uint32_t firstPeerID):
+ host_(0), bCommunicationThreadRunning_(false), nextPeerID_(firstPeerID)
{
enet_initialize();
atexit(enet_deinitialize);
this->incomingEventsMutex_ = new boost::mutex;
this->outgoingEventsMutex_ = new boost::mutex;
+// this->overallMutex_ = new boost::mutex;
}
Connection::~Connection()
@@ -74,38 +77,46 @@
delete this->communicationThread_;
}
-
-// int Connection::service(ENetEvent* event) {
-// return enet_host_service( this->host_, event, NETWORK_WAIT_TIMEOUT );
-// }
-
- void Connection::disconnectPeer(ENetPeer *peer)
+ void Connection::disconnectPeer(uint32_t peerID)
{
- assert(peer);
- outgoingEvent outEvent = { peer, outgoingEventType::disconnectPeer, (ENetPacket*)10, 15 };
+// this->overallMutex_->lock();
+ outgoingEvent outEvent = { peerID, outgoingEventType::disconnectPeer, 0, 0 };
this->outgoingEventsMutex_->lock();
this->outgoingEvents_.push_back(outEvent);
this->outgoingEventsMutex_->unlock();
+// this->overallMutex_->unlock();
}
+
+ void Connection::disconnectPeers()
+ {
+ outgoingEvent outEvent = { 0, outgoingEventType::disconnectPeers, 0, 0 };
+
+ this->outgoingEventsMutex_->lock();
+ this->outgoingEvents_.push_back(outEvent);
+ this->outgoingEventsMutex_->unlock();
+ }
- void Connection::addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID)
+ void Connection::addPacket(ENetPacket* packet, uint32_t peerID, uint8_t channelID)
{
- assert(peer);
- outgoingEvent outEvent = { peer, outgoingEventType::sendPacket, packet, channelID };
+// this->overallMutex_->lock();
+ outgoingEvent outEvent = { peerID, outgoingEventType::sendPacket, packet, channelID };
this->outgoingEventsMutex_->lock();
this->outgoingEvents_.push_back(outEvent);
this->outgoingEventsMutex_->unlock();
+// this->overallMutex_->unlock();
}
void Connection::broadcastPacket(ENetPacket* packet, uint8_t channelID)
{
- outgoingEvent outEvent = { (ENetPeer*)15, outgoingEventType::broadcastPacket, packet, channelID };
+// this->overallMutex_->lock();
+ outgoingEvent outEvent = { 0, outgoingEventType::broadcastPacket, packet, channelID };
this->outgoingEventsMutex_->lock();
this->outgoingEvents_.push_back(outEvent);
this->outgoingEventsMutex_->unlock();
+// this->overallMutex_->unlock();
}
@@ -113,18 +124,19 @@
{
ENetEvent event;
+// this->overallMutex_->lock();
while( bCommunicationThreadRunning_ )
{
// Receive all pending incoming Events (such as packets, connects and disconnects)
while( enet_host_check_events( this->host_, &event ) > 0 )
{
-// COUT(0) << "incoming event" << endl;
- // received an event
- this->incomingEventsMutex_->lock();
- this->incomingEvents_.push_back(event);
- this->incomingEventsMutex_->unlock();
+ processIncomingEvent(event);
}
+// this->overallMutex_->unlock();
+ msleep(1);
+// this->overallMutex_->lock();
+
// Send all waiting outgoing packets
this->outgoingEventsMutex_->lock();
uint32_t outgoingEventsCount = this->outgoingEvents_.size();
@@ -137,20 +149,8 @@
this->outgoingEvents_.pop_front();
this->outgoingEventsMutex_->unlock();
- switch( outEvent.type )
- {
- case outgoingEventType::sendPacket:
- enet_peer_send( outEvent.peer, outEvent.channelID, outEvent.packet );
- break;
- case outgoingEventType::disconnectPeer:
- enet_peer_disconnect(outEvent.peer, 0);
- break;
- case outgoingEventType::broadcastPacket:
- enet_host_broadcast( this->host_, outEvent.channelID, outEvent.packet );
- break;
- default:
- assert(0);
- }
+ processOutgoingEvent(outEvent);
+
this->outgoingEventsMutex_->lock();
outgoingEventsCount = this->outgoingEvents_.size();
this->outgoingEventsMutex_->unlock();
@@ -159,61 +159,203 @@
// Wait for incoming events (at most NETWORK_WAIT_TIMEOUT ms)
if( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
{
-// COUT(0) << "incoming event after wait" << endl;
- //received an event
- this->incomingEventsMutex_->lock();
- this->incomingEvents_.push_back(event);
- this->incomingEventsMutex_->unlock();
+ processIncomingEvent(event);
}
}
+// this->overallMutex_->unlock();
}
+
+ void Connection::processIncomingEvent(ENetEvent& event)
+ {
+ incomingEvent inEvent;
+ // preprocess event
+ switch( event.type )
+ {
+ case ENET_EVENT_TYPE_CONNECT:
+ inEvent = preprocessConnectEvent(event);
+ break;
+ case ENET_EVENT_TYPE_RECEIVE:
+ inEvent = preprocessReceiveEvent(event);
+ break;
+ case ENET_EVENT_TYPE_DISCONNECT:
+ inEvent = preprocessDisconnectEvent(event);
+ break;
+ case ENET_EVENT_TYPE_NONE:
+ default:
+ return;
+ }
+
+ // pushing event to queue
+ this->incomingEventsMutex_->lock();
+ this->incomingEvents_.push_back(inEvent);
+ this->incomingEventsMutex_->unlock();
+ }
+
+ void Connection::processOutgoingEvent(outgoingEvent& event)
+ {
+ ENetPeer* peer;
+ switch( event.type )
+ {
+ case outgoingEventType::sendPacket:
+ // check whether the peer is still/already in the peer list
+ if( this->peerMap_.find(event.peerID) != this->peerMap_.end() )
+ {
+ peer = this->peerMap_[event.peerID];
+ enet_peer_send( peer, event.channelID, event.packet );
+ }
+ else
+ {
+ // peer probably already disconnected so just discard packet
+ assert(event.peerID<this->nextPeerID_);
+ enet_packet_destroy(event.packet);
+ }
+ break;
+ case outgoingEventType::disconnectPeer:
+ if( this->peerMap_.find(event.peerID) != this->peerMap_.end() )
+ {
+ peer = this->peerMap_[event.peerID];
+ enet_peer_disconnect(peer, 0);
+ }
+ else
+ {
+ // peer probably already disconnected so just discard disconnect event
+ assert(event.peerID<this->nextPeerID_);
+ }
+ break;
+ case outgoingEventType::disconnectPeers:
+ disconnectPeersInternal();
+ break;
+ case outgoingEventType::broadcastPacket:
+ enet_host_broadcast( this->host_, event.channelID, event.packet );
+ break;
+ default:
+ assert(0);
+ }
+ }
+
+ void Connection::disconnectPeersInternal()
+ {
+ std::map<uint32_t, ENetPeer*>::iterator it;
+ for( it=this->peerMap_.begin(); it!=this->peerMap_.end(); ++it )
+ {
+ enet_peer_disconnect(it->second, 0);
+ }
+ uint32_t iterations = NETWORK_DISCONNECT_TIMEOUT/NETWORK_WAIT_TIMEOUT;
+ uint32_t i = 0;
+ while( this->peerMap_.size() && i++ < iterations )
+ {
+ ENetEvent event;
+ if( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
+ {
+ processIncomingEvent(event);
+ }
+ }
+ }
+
void Connection::processQueue()
{
- ENetEvent event;
+ incomingEvent inEvent;
this->incomingEventsMutex_->lock();
uint32_t incomingEventsCount = this->incomingEvents_.size();
this->incomingEventsMutex_->unlock();
while( incomingEventsCount > 0 )
{
- packet::Packet* p;
+ // pop event from queue
this->incomingEventsMutex_->lock();
- event = this->incomingEvents_.front();
+ inEvent = this->incomingEvents_.front();
this->incomingEvents_.pop_front();
this->incomingEventsMutex_->unlock();
- switch(event.type)
+ // process event
+ switch( inEvent.type )
{
- // log handling ================
- case ENET_EVENT_TYPE_CONNECT:
- addPeer( &event );
+ case incomingEventType::peerConnect:
+ addPeer(inEvent.peerID);
break;
- case ENET_EVENT_TYPE_DISCONNECT:
- removePeer( &event );
+ case incomingEventType::peerDisconnect:
+ removePeer(inEvent.peerID);
break;
- case ENET_EVENT_TYPE_RECEIVE:
-// COUT(0) << "ENET_EVENT_TYPE_RECEIVE" << endl;
- p = createPacket( &event );
- processPacket(p);
+ case incomingEventType::receivePacket:
+ processPacket(inEvent.packet);
break;
- case ENET_EVENT_TYPE_NONE:
+ default:
break;
}
+ // check whether there are still events in the queue
this->incomingEventsMutex_->lock();
incomingEventsCount = this->incomingEvents_.size();
this->incomingEventsMutex_->unlock();
}
}
+
+ void Connection::waitOutgoingQueue()
+ {
+ uint32_t outgoingEventsCount;
+ this->outgoingEventsMutex_->lock();
+ outgoingEventsCount = this->outgoingEvents_.size();
+ this->outgoingEventsMutex_->unlock();
+ while( outgoingEventsCount )
+ {
+ msleep(1);
+ this->outgoingEventsMutex_->lock();
+ outgoingEventsCount = this->outgoingEvents_.size();
+ this->outgoingEventsMutex_->unlock();
+ }
+ }
- packet::Packet* Connection::createPacket(ENetEvent* event)
+
+ incomingEvent Connection::preprocessConnectEvent(ENetEvent& event)
{
- packet::Packet *p = packet::Packet::createPacket(event->packet, event->peer);
- return p;
-// return p->process();
+ // make sure this peer doesn't exist
+ assert( this->peerMap_.find(this->nextPeerID_) == this->peerMap_.end() );
+ assert( this->peerIDMap_.find(event.peer) == this->peerIDMap_.end() );
+
+ // give peer a new id and increase peerID for next peer
+ uint32_t peerID = this->nextPeerID_;
+ ++this->nextPeerID_;
+
+ // add peer/peerID into peerMap_ and peerIDMap_
+ this->peerMap_[peerID] = event.peer;
+ this->peerIDMap_[event.peer] = peerID;
+
+ // create new peerEvent and return it
+ incomingEvent inEvent = { peerID, incomingEventType::peerConnect, 0 };
+ return inEvent;
}
+ incomingEvent Connection::preprocessDisconnectEvent(ENetEvent& event)
+ {
+ // assert that the peer exists and get peerID
+ assert( this->peerIDMap_.find(event.peer) != this->peerIDMap_.end() );
+ uint32_t peerID = this->peerIDMap_[event.peer];
+
+ // remove peer/peerID from maps
+ this->peerIDMap_.erase(this->peerIDMap_.find(event.peer));
+ this->peerMap_.erase(this->peerMap_.find(peerID));
+
+ // create new peerEvent and return it
+ incomingEvent inEvent = { peerID, incomingEventType::peerDisconnect, 0 };
+ return inEvent;
+ }
+
+ incomingEvent Connection::preprocessReceiveEvent(ENetEvent& event)
+ {
+ // assert that the peer exists and get peerID
+ assert( this->peerIDMap_.find(event.peer) != this->peerIDMap_.end() );
+ uint32_t peerID = this->peerIDMap_[event.peer];
+
+ // create new Packet from ENetPacket
+ packet::Packet* p = packet::Packet::createPacket(event.packet, peerID);
+
+ // create new peerEvent and return it
+ incomingEvent inEvent = { peerID, incomingEventType::receivePacket, p };
+ return inEvent;
+ }
+
+
void Connection::enableCompression()
{
enet_host_compress_with_range_coder( this->host_ );
Modified: code/trunk/src/libraries/network/Connection.h
===================================================================
--- code/trunk/src/libraries/network/Connection.h 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/Connection.h 2011-04-25 18:22:36 UTC (rev 8327)
@@ -43,7 +43,9 @@
#include "NetworkPrereqs.h"
#include <deque>
+#include <map>
#include <enet/enet.h>
+#include <boost/concept_check.hpp>
namespace boost
{
@@ -58,20 +60,39 @@
const unsigned int NETWORK_WAIT_TIMEOUT = 1;
const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5;
+ namespace incomingEventType
+ {
+ enum Value
+ {
+ receivePacket = 1, // incoming packet
+ peerConnect = 2, // incoming connect request
+ peerDisconnect = 3 // incoming disconnect request
+ };
+
+ }
+
namespace outgoingEventType
{
enum Value
{
- sendPacket = 1,
- disconnectPeer = 2,
- broadcastPacket = 3
+ sendPacket = 1, // outgoing packet
+ broadcastPacket = 2, // outgoing broadcast packet
+ disconnectPeer = 3, // outgoing disconnect request
+ disconnectPeers = 4 // outgoing disconnect request
};
}
+ struct _NetworkExport incomingEvent
+ {
+ uint32_t peerID;
+ incomingEventType::Value type;
+ packet::Packet* packet;
+ };
+
struct _NetworkExport outgoingEvent
{
- ENetPeer* peer;
+ uint32_t peerID;
outgoingEventType::Value type;
ENetPacket* packet;
ENetChannelID channelID;
@@ -82,40 +103,50 @@
public:
virtual ~Connection();
- void addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID);
- void broadcastPacket(ENetPacket* packet, uint8_t channelID);
-// ENetHost* getHost(){ return this->host_; }
-
protected:
- Connection();
-// static Connection* getInstance(){ return Connection::instance_; }
-
-// int service(ENetEvent* event);
+ Connection(uint32_t firstPeerID = NETWORK_PEER_ID_SERVER+1);
+
void startCommunicationThread();
void stopCommunicationThread();
- void communicationThread();
- virtual void disconnectPeer(ENetPeer *peer);
+ void addPacket(ENetPacket *packet, uint32_t peerID, uint8_t channelID);
+ void broadcastPacket(ENetPacket* packet, uint8_t channelID);
+ void disconnectPeer(uint32_t peerID);
+ void disconnectPeers();
+
void enableCompression();
void processQueue();
- virtual void addPeer(ENetEvent* event)=0;
- virtual void removePeer(ENetEvent* event)=0;
+ void waitOutgoingQueue(); // wait for the outgoing queue to become empty (everything processed by communication thread)
+ virtual void addPeer(uint32_t peerID)=0;
+ virtual void removePeer(uint32_t peerID)=0;
virtual void processPacket( packet::Packet* packet)=0;
- virtual packet::Packet* createPacket(ENetEvent* event);
+
+ incomingEvent preprocessConnectEvent(ENetEvent& event);
+ incomingEvent preprocessDisconnectEvent(ENetEvent& event);
+ incomingEvent preprocessReceiveEvent(ENetEvent& event);
+
+ void processIncomingEvent(ENetEvent& event);
+ void processOutgoingEvent(outgoingEvent& event);
+
+ void disconnectPeersInternal();
- ENetHost* host_;
+ ENetHost* host_;
private:
- boost::thread* communicationThread_;
- bool bCommunicationThreadRunning_;
- ENetAddress* bindAddress_;
- std::deque<ENetEvent> incomingEvents_;
- std::deque<outgoingEvent> outgoingEvents_;
- boost::mutex* incomingEventsMutex_;
- boost::mutex* outgoingEventsMutex_;
+ void communicationThread();
+
+ boost::thread* communicationThread_;
+ bool bCommunicationThreadRunning_;
+ ENetAddress* bindAddress_;
+ std::deque<incomingEvent> incomingEvents_;
+ std::deque<outgoingEvent> outgoingEvents_;
+ boost::mutex* incomingEventsMutex_;
+ boost::mutex* outgoingEventsMutex_;
+ boost::mutex* overallMutex_;
+ std::map<uint32_t, ENetPeer*> peerMap_;
+ std::map<ENetPeer*, uint32_t> peerIDMap_;
+ uint32_t nextPeerID_;
-// static Connection *instance_;
-
};
}
Deleted: code/trunk/src/libraries/network/GamestateClient.cc
===================================================================
--- code/trunk/src/libraries/network/GamestateClient.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/GamestateClient.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -1,211 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Oliver Scheuss
- * Co-authors:
- * Dumeni Manatschal
- *
- */
-
-#include "GamestateClient.h"
-
-#include "util/Debug.h"
-#include "core/ObjectList.h"
-#include "synchronisable/Synchronisable.h"
-#include "synchronisable/NetworkCallbackManager.h"
-#include "packet/Acknowledgement.h"
-#include "packet/Gamestate.h"
-
-
-namespace orxonox
-{
- struct _NetworkExport GameStateItem
- {
- packet::Gamestate *state;
- unsigned int id;
- };
-
- GamestateClient::GamestateClient()
- {
- COUT(5) << "this: " << this << std::endl;
- lastAckedGamestateID_=GAMESTATEID_INITIAL-1;
- lastProcessedGamestateID_=GAMESTATEID_INITIAL-1;
- tempGamestate_=NULL;
- }
-
- GamestateClient::~GamestateClient()
- {
- std::map<unsigned int, packet::Gamestate *>::iterator it;
- for ( it = this->gamestateMap_.begin(); it != this->gamestateMap_.end(); ++it )
- delete it->second;
- if( this->tempGamestate_ )
- delete this->tempGamestate_;
- }
-
- bool GamestateClient::ackGamestate(unsigned int gamestateID, unsigned int clientID)
- {
- return true;
- }
-
- bool GamestateClient::addGamestate(packet::Gamestate *gs, unsigned int clientID)
- {
- if(tempGamestate_!=NULL)
- {
- //delete the obsolete gamestate
- if(tempGamestate_->getID()>gs->getID())
- return false;
- delete tempGamestate_;
- }
- tempGamestate_=gs;
- return true;
- }
-
- bool GamestateClient::processGamestates()
- {
- if(tempGamestate_==NULL)
- return false;
- bool isDiffed = tempGamestate_->isDiffed();
- int id = GAMESTATEID_INITIAL;
- packet::Gamestate *processed = processGamestate(tempGamestate_);
- assert(processed);
-
- //now call the queued callbacks
- NetworkCallbackManager::callCallbacks();
-
- if (!processed)
- {
- assert(0);
- sendAck(0);
- return false;
- }
- //successfully loaded data from gamestate. now save gamestate for diff and delete the old gs
- tempGamestate_=NULL;
- gamestateMap_[processed->getID()]=processed;
- lastProcessedGamestateID_ = processed->getID();
- if(isDiffed)
- lastAckedGamestateID_ = processed->getBaseID();
- id = processed->getID();
- sendAck(id);
- return true;
- }
-
-
- /**
- * This function removes a Synchronisable out of the universe
- * @param it iterator of the list pointing to the object
- * @return iterator pointing to the next object in the list
- */
- void GamestateClient::removeObject(ObjectListIterator<Synchronisable> &it)
- {
- ObjectListIterator<Synchronisable> temp=it;
- ++it;
- temp->destroy(); // or delete?
- }
-
- packet::Gamestate *GamestateClient::getGamestate()
- {
- packet::Gamestate *gs = new packet::Gamestate();
- if(!gs->collectData(this->getLastProcessedGamestateID(NETWORK_PEER_ID_SERVER), 0x2))
- {
- delete gs;
- return 0;
- }
- return gs;
- }
-
- void GamestateClient::cleanup()
- {
- std::map<unsigned int, packet::Gamestate*>::iterator temp, it = gamestateMap_.begin();
- while(it!=gamestateMap_.end())
- {
- if(it->first>=lastAckedGamestateID_)
- break;
- // otherwise delete that stuff
- delete it->second;
- temp=it++;
- gamestateMap_.erase(temp);
- }
- tempGamestate_=NULL;
- }
-
- void GamestateClient::printGamestateMap()
- {
- std::map<unsigned int, packet::Gamestate*>::iterator it;
- COUT(4) << "gamestates: ";
- for(it=gamestateMap_.begin(); it!=gamestateMap_.end(); it++)
- {
- COUT(4) << it->first << ':' << it->second << '|';
- }
- COUT(4) << std::endl;
-
- }
-
- bool GamestateClient::sendAck(unsigned int gamestateID)
- {
- packet::Acknowledgement *ack = new packet::Acknowledgement(gamestateID, 0);
- if(!ack->send())
- {
- COUT(3) << "could not ack gamestate: " << gamestateID << std::endl;
- return false;
- }
- else
- {
- COUT(5) << "acked a gamestate: " << gamestateID << std::endl;
- return true;
- }
- }
-
- packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs)
- {
- if(gs->isCompressed())
- {
- bool b = gs->decompressData();
- assert(b);
- }
- if(gs->isDiffed())
- {
- assert(0);
-// packet::Gamestate *base = gamestateMap_[gs->getBaseID()];
-// if(!base)
-// {
-// COUT(0) << "could not find base gamestate id: " << gs->getBaseID() << endl;
-// assert(0);
-// delete gs;
-// return 0;
-// }
-// packet::Gamestate *undiffed = gs->undiff(base);
-// delete gs;
-// gs=undiffed;
-// COUT(5) << "successfully undiffed gamestate id: " << undiffed->getID() << std::endl;
- }
- if(gs->spreadData(0x2))
- return gs;
- else
- {
- COUT(0) << "could not spread gamestate" << endl;
- assert(0);
- return NULL;
- }
- }
-
-}
-
Deleted: code/trunk/src/libraries/network/GamestateClient.h
===================================================================
--- code/trunk/src/libraries/network/GamestateClient.h 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/GamestateClient.h 2011-04-25 18:22:36 UTC (rev 8327)
@@ -1,82 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Oliver Scheuss
- * Co-authors:
- * Dumeni Manatschal
- *
- */
-
-//
-// C++ Interface: GameStateClient
-//
-// Description:
-//
-//
-// Author: Oliver Scheuss, (C) 2007
-//
-// Copyright: See COPYING file that comes with this distribution
-//
-//
-#ifndef _GamestateClient_H__
-#define _GamestateClient_H__
-
-#include "NetworkPrereqs.h"
-
-#include <map>
-#include "core/CorePrereqs.h"
-#include "GamestateHandler.h"
-
-const unsigned int GAMESTATEID_INITIAL = static_cast<unsigned int>(-1);
-
-namespace orxonox
-{
- class _NetworkExport GamestateClient: public GamestateHandler
- {
- public:
- GamestateClient();
- ~GamestateClient();
-
- virtual bool addGamestate(packet::Gamestate *gs, unsigned int clientID);
- virtual bool ackGamestate(unsigned int gamestateID, unsigned int clientID);
- virtual uint32_t getLastProcessedGamestateID(unsigned int clientID=0) { return this->lastProcessedGamestateID_; }
- virtual uint32_t getCurrentGamestateID(){ return this->lastProcessedGamestateID_; }
-
- bool processGamestates();
- packet::Gamestate *getGamestate();
- void cleanup();
- private:
- packet::Gamestate *processGamestate(packet::Gamestate *gs);
- void removeObject(ObjectListIterator<Synchronisable> &it);
- void printGamestateMap();
- bool sendAck(unsigned int gamestateID);
-
- unsigned int lastAckedGamestateID_;
- unsigned int lastProcessedGamestateID_;
- std::map<unsigned int, packet::Gamestate *> gamestateMap_;
- packet::Gamestate *tempGamestate_; // we save the received gamestates here during processQueue
-
- };
-
-}
-
-#endif /* _GamestateClient_H__ */
Modified: code/trunk/src/libraries/network/GamestateHandler.h
===================================================================
--- code/trunk/src/libraries/network/GamestateHandler.h 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/GamestateHandler.h 2011-04-25 18:22:36 UTC (rev 8327)
@@ -50,7 +50,7 @@
public:
virtual bool addGamestate(packet::Gamestate* gs, unsigned int clientID) = 0;
virtual bool ackGamestate(unsigned int gamestateID, unsigned int clientID) = 0;
- virtual uint32_t getLastProcessedGamestateID( unsigned int clientID )=0;
+ virtual uint32_t getLastReceivedGamestateID( unsigned int clientID )=0;
virtual uint32_t getCurrentGamestateID()=0;
};
Modified: code/trunk/src/libraries/network/GamestateManager.cc
===================================================================
--- code/trunk/src/libraries/network/GamestateManager.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/GamestateManager.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -56,7 +56,7 @@
// #include "TrafficControl.h"
namespace orxonox
-{
+{
GamestateManager::GamestateManager() :
currentGamestate_(0), id_(0)
{
@@ -121,6 +121,7 @@
bool GamestateManager::sendAck(unsigned int gamestateID, uint32_t peerID)
{
+ assert( gamestateID != ACKID_NACK );
packet::Acknowledgement *ack = new packet::Acknowledgement(gamestateID, peerID);
if( !this->sendPacket(ack))
{
@@ -138,7 +139,6 @@
bool GamestateManager::getSnapshot(){
if ( currentGamestate_ != 0 )
delete currentGamestate_;
- currentGamestate_ = new packet::Gamestate();
uint8_t gsMode;
if( GameMode::isMaster() )
gsMode = packet::GAMESTATE_MODE_SERVER;
@@ -148,11 +148,22 @@
if( GameMode::isMaster() )
newID = ++id_;
else
- newID = peerMap_[NETWORK_PEER_ID_SERVER].lastProcessedGamestateID;
+ {
+ assert(peerMap_.size()!=0);
+ newID = peerMap_[NETWORK_PEER_ID_SERVER].lastReceivedGamestateID;
+ if( newID == GAMESTATEID_INITIAL )
+ {
+ return false;
+ }
+ }
- if(!currentGamestate_->collectData(newID, gsMode)){ //we have no data to send
+ currentGamestate_ = new packet::Gamestate();
+
+ if(!currentGamestate_->collectData(newID, gsMode))
+ { //we have no data to send
delete currentGamestate_;
currentGamestate_=0;
+ return false;
}
return true;
}
@@ -171,7 +182,7 @@
COUT(5) << "Server: not sending gamestate" << std::endl;
continue;
}
- COUT(4) << "client id: " << peerIt->first << std::endl;
+ COUT(5) << "client id: " << peerIt->first << std::endl;
COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
int peerID = peerIt->first; //get client id
@@ -186,7 +197,7 @@
baseGamestate = it->second;
}
- peerGamestates.push_back(0); // insert an empty gamestate* to change
+ peerGamestates.push_back(0); // insert an empty gamestate* to be changed
finishGamestate( peerID, peerGamestates.back(), baseGamestate, currentGamestate_ );
if( peerGamestates.back()==0 )
// nothing to send to remove pointer from vector
@@ -243,7 +254,7 @@
// bool b = gs->compressData();
// assert(b);
clock.capture();
- COUT(4) << "diff and compress time: " << clock.getDeltaTime() << endl;
+ COUT(5) << "diff and compress time: " << clock.getDeltaTime() << endl;
// COUT(5) << "sending gamestate with id " << gs->getID();
// if(gamestate->isDiffed())
// COUT(5) << " and baseid " << gs->getBaseID() << endl;
@@ -262,20 +273,23 @@
assert(it!=this->peerMap_.end());
unsigned int curid = it->second.lastAckedGamestateID;
- if(gamestateID == ACKID_NACK){
- it->second.lastAckedGamestateID = GAMESTATEID_INITIAL;
-// temp->setGamestateID(GAMESTATEID_INITIAL);
- // now delete all saved gamestates for this client
- std::map<uint32_t, packet::Gamestate*>::iterator it2;
- for(it2 = it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ++it2 ){
- delete it2->second;
- }
- it->second.gamestates.clear();
- return true;
- }
+ assert(gamestateID != ACKID_NACK);
+// if(gamestateID == ACKID_NACK){
+// it->second.lastAckedGamestateID = GAMESTATEID_INITIAL;
+// // temp->setGamestateID(GAMESTATEID_INITIAL);
+// // now delete all saved gamestates for this client
+// std::map<uint32_t, packet::Gamestate*>::iterator it2;
+// for(it2 = it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ++it2 ){
+// delete it2->second;
+// }
+// it->second.gamestates.clear();
+// return true;
+// }
- assert(curid==GAMESTATEID_INITIAL || curid<=gamestateID);
- COUT(5) << "acking gamestate " << gamestateID << " for peerID: " << peerID << " curid: " << curid << std::endl;
+// assert(curid==GAMESTATEID_INITIAL || curid<=gamestateID); // this line is commented out because acknowledgements are unreliable and may arrive in distorted order
+ if( gamestateID <= curid )
+ return true;
+COUT(4) << "acking gamestate " << gamestateID << " for peerID: " << peerID << " curid: " << curid << std::endl;
std::map<uint32_t, packet::Gamestate*>::iterator it2;
for( it2=it->second.gamestates.begin(); it2!=it->second.gamestates.end(); )
{
@@ -299,11 +313,11 @@
return true;
}
- uint32_t GamestateManager::getLastProcessedGamestateID(unsigned int peerID)
+ uint32_t GamestateManager::getLastReceivedGamestateID(unsigned int peerID)
{
assert( this->peerMap_.find(peerID)!=this->peerMap_.end() );
if( this->peerMap_.find(peerID) != this->peerMap_.end() )
- return this->peerMap_[peerID].lastProcessedGamestateID;
+ return this->peerMap_[peerID].lastReceivedGamestateID;
else
return GAMESTATEID_INITIAL;
}
@@ -313,7 +327,7 @@
{
assert(peerMap_.find(peerID)==peerMap_.end());
peerMap_[peerID].peerID = peerID;
- peerMap_[peerID].lastProcessedGamestateID = GAMESTATEID_INITIAL;
+ peerMap_[peerID].lastReceivedGamestateID = GAMESTATEID_INITIAL;
peerMap_[peerID].lastAckedGamestateID = GAMESTATEID_INITIAL;
if( GameMode::isMaster() )
peerMap_[peerID].isSynched = false;
@@ -359,7 +373,7 @@
gsMode = packet::GAMESTATE_MODE_CLIENT;
if( gs->spreadData(gsMode) )
{
- this->peerMap_[gs->getPeerID()].lastProcessedGamestateID = gs->getID();
+ this->peerMap_[gs->getPeerID()].lastReceivedGamestateID = gs->getID();
return true;
}
else
Modified: code/trunk/src/libraries/network/GamestateManager.h
===================================================================
--- code/trunk/src/libraries/network/GamestateManager.h 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/GamestateManager.h 2011-04-25 18:22:36 UTC (rev 8327)
@@ -72,8 +72,8 @@
struct peerInfo
{
uint32_t peerID;
- uint32_t lastProcessedGamestateID;
- uint32_t lastAckedGamestateID;
+ uint32_t lastReceivedGamestateID; //!< id of the last gamestate which was received (and processed) from the peer
+ uint32_t lastAckedGamestateID; //!< id of the last gamestate on which we received an ack from the peer
bool isSynched;
std::map< uint32_t, packet::Gamestate* > gamestates;
};
@@ -85,7 +85,7 @@
virtual bool addGamestate(packet::Gamestate *gs, unsigned int peerID);
virtual bool ackGamestate(unsigned int gamestateID, unsigned int peerID);
- virtual uint32_t getLastProcessedGamestateID( unsigned int peerID );
+ virtual uint32_t getLastReceivedGamestateID( unsigned int peerID );
virtual uint32_t getCurrentGamestateID(){ return currentGamestate_->getID(); }
bool processGamestates();
@@ -100,6 +100,7 @@
void setSynched( uint32_t peerID )
{ assert(peerMap_.find(peerID)!=peerMap_.end()); peerMap_[peerID].isSynched = true; }
void removePeer( uint32_t peerID );
+ bool hasPeers(){ return this->peerMap_.size()!=0; }
// void removeClient(ClientInformation *client);
protected:
virtual bool sendPacket( packet::Packet* packet ) = 0;
Modified: code/trunk/src/libraries/network/Host.cc
===================================================================
--- code/trunk/src/libraries/network/Host.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/Host.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -116,7 +116,7 @@
if(instances_s.size()==0)
{
for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
- it->incomingChat(message, CLIENTID_UNKNOWN);
+ it->incomingChat(message, NETWORK_PEER_ID_BROADCAST);
return true;
}
else
Modified: code/trunk/src/libraries/network/NetworkPrereqs.h
===================================================================
--- code/trunk/src/libraries/network/NetworkPrereqs.h 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/NetworkPrereqs.h 2011-04-25 18:22:36 UTC (rev 8327)
@@ -64,11 +64,12 @@
namespace orxonox
{
static const unsigned int GAMESTATEID_INITIAL = static_cast<unsigned int>(-1);
- static const unsigned int CLIENTID_UNKNOWN = static_cast<unsigned int>(-2);
extern const char* LAN_DISCOVERY_MESSAGE;
extern const char* LAN_DISCOVERY_ACK;
static const unsigned int LAN_DISCOVERY_PORT = 55558;
static const unsigned int NETWORK_PEER_ID_SERVER = 0;
+ static const unsigned int NETWORK_PEER_ID_BROADCAST = static_cast<unsigned int>(-1);
+ static const unsigned int NETWORK_PEER_ID_UNKNOWN = static_cast<unsigned int>(-2);
static const unsigned int NETWORK_CHANNEL_DEFAULT = 0;
static const unsigned int NETWORK_CHANNEL_UNRELIABLE = 1;
static const unsigned int NETWORK_CHANNEL_COUNT = 2;
Modified: code/trunk/src/libraries/network/Server.cc
===================================================================
--- code/trunk/src/libraries/network/Server.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/Server.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -56,7 +56,7 @@
#include "packet/Gamestate.h"
#include "packet/Welcome.h"
#include "ChatListener.h"
-#include "ClientInformation.h"
+// #include "ClientInformation.h"
#include "FunctionCallManager.h"
#include "GamestateManager.h"
#include "WANDiscovery.h"
@@ -151,15 +151,15 @@
bool Server::processChat(const std::string& message, unsigned int playerID)
{
- ClientInformation *temp = ClientInformation::getBegin();
+// ClientInformation *temp = ClientInformation::getBegin();
packet::Chat *chat;
- while(temp){
- chat = new packet::Chat(message, playerID);
- chat->setPeerID(temp->getID());
- if(!chat->send( static_cast<Host*>(this) ))
- COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
- temp = temp->next();
- }
+// while(temp){
+ chat = new packet::Chat(message, playerID);
+ chat->setPeerID(NETWORK_PEER_ID_BROADCAST);
+ chat->send( static_cast<Host*>(this) );
+// COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
+// temp = temp->next();
+// }
// COUT(1) << "Player " << playerID << ": " << message << std::endl;
return true;
}
@@ -206,7 +206,7 @@
/* todo */
//helper_HandleMasterServerRequests();
- if ( ClientInformation::hasClients() )
+ if ( GamestateManager::hasPeers() )
{
// process incoming gamestates
GamestateManager::processGamestates();
@@ -236,14 +236,16 @@
*/
unsigned int Server::getRTT(unsigned int clientID)
{
- assert(ClientInformation::findClient(clientID));
- return ClientInformation::findClient(clientID)->getRTT();
+// assert(ClientInformation::findClient(clientID));
+// return ClientInformation::findClient(clientID)->getRTT();
+ // TODO: reimplement
+ return 0;
}
void Server::printRTT()
{
- for( ClientInformation* temp=ClientInformation::getBegin(); temp!=0; temp=temp->next() )
- COUT(0) << "Round trip time to client with ID: " << temp->getID() << " is " << temp->getRTT() << " ms" << endl;
+// for( ClientInformation* temp=ClientInformation::getBegin(); temp!=0; temp=temp->next() )
+// COUT(0) << "Round trip time to client with ID: " << temp->getID() << " is " << temp->getRTT() << " ms" << endl;
}
/**
@@ -251,8 +253,9 @@
*/
double Server::getPacketLoss(unsigned int clientID)
{
- assert(ClientInformation::findClient(clientID));
- return ClientInformation::findClient(clientID)->getPacketLoss();
+// assert(ClientInformation::findClient(clientID));
+// return ClientInformation::findClient(clientID)->getPacketLoss();
+ return 0.;
}
/**
@@ -260,7 +263,7 @@
*/
void Server::updateGamestate()
{
- if( ClientInformation::getBegin()==NULL )
+ if( this->clientIDs_.size()==0 )
//no client connected
return;
GamestateManager::update();
@@ -290,9 +293,10 @@
bool Server::sendObjectDeletes()
{
- ClientInformation *temp = ClientInformation::getBegin();
- if( temp == NULL )
+// ClientInformation *temp = ClientInformation::getBegin();
+// if( temp == NULL )
//no client connected
+ if( this->clientIDs_.size()==0 )
return true;
packet::DeleteObjects *del = new packet::DeleteObjects();
if(!del->fetchIDs())
@@ -301,70 +305,81 @@
return true; //everything ok (no deletes this tick)
}
// COUT(3) << "sending DeleteObjects" << std::endl;
- while(temp != NULL){
- if( !(temp->getSynched()) )
- {
- COUT(5) << "Server: not sending gamestate" << std::endl;
- temp=temp->next();
- continue;
- }
- int cid = temp->getID(); //get client id
- packet::DeleteObjects *cd = new packet::DeleteObjects(*del);
- assert(cd);
- cd->setPeerID(cid);
- if ( !cd->send( static_cast<Host*>(this) ) )
- COUT(3) << "Server: packet with client id (cid): " << cid << " not sended" << std::endl;
- temp=temp->next();
+// while(temp != NULL){
+// if( !(temp->getSynched()) )
+// {
+// COUT(5) << "Server: not sending gamestate" << std::endl;
+// temp=temp->next();
+// continue;
+// }
+// int cid = temp->getID(); //get client id
+// packet::DeleteObjects *cd = new packet::DeleteObjects(*del);
+// assert(cd);
+ del->setPeerID(NETWORK_PEER_ID_BROADCAST);
+ if ( !del->send( static_cast<Host*>(this) ) )
+ COUT(3) << "Server: could not broadcast deleteObjects packet" << std::endl;
+// temp=temp->next();
// gs gets automatically deleted by enet callback
- }
- delete del;
+// }
+// delete del;
return true;
}
- void Server::addPeer(ENetEvent *event)
+ void Server::addPeer(uint32_t peerID)
{
- static unsigned int newid=1;
+// static unsigned int newid=1;
+//
+// COUT(2) << "Server: adding client" << std::endl;
+// ClientInformation *temp = ClientInformation::insertBack(new ClientInformation);
+// if(!temp)
+// {
+// COUT(2) << "Server: could not add client" << std::endl;
+// }
+// temp->setID(newid);
+// temp->setPeer(event->peer);
- COUT(2) << "Server: adding client" << std::endl;
- ClientInformation *temp = ClientInformation::insertBack(new ClientInformation);
- if(!temp)
- {
- COUT(2) << "Server: could not add client" << std::endl;
- }
- temp->setID(newid);
- temp->setPeer(event->peer);
-
// inform all the listeners
- ClientConnectionListener::broadcastClientConnected(newid);
- GamestateManager::addPeer(newid);
+ this->clientIDs_.push_back(peerID);
+ ClientConnectionListener::broadcastClientConnected(peerID);
+ GamestateManager::addPeer(peerID);
- ++newid;
+// ++newid;
- COUT(3) << "Server: added client id: " << temp->getID() << std::endl;
- createClient(temp->getID());
+ COUT(3) << "Server: added client id: " << peerID << std::endl;
+ createClient(peerID);
}
- void Server::removePeer(ENetEvent *event)
+ void Server::removePeer(uint32_t peerID)
{
COUT(4) << "removing client from list" << std::endl;
- ClientInformation *client = ClientInformation::findClient(&event->peer->address);
- if(!client)
- return;
- else
+// ClientInformation *client = ClientInformation::findClient(&event->peer->address);
+// if(!client)
+// return;
+// else
+// {
+ std::vector<uint32_t>::iterator it;
+ for( it=this->clientIDs_.begin(); it!=this->clientIDs_.end(); ++it )
+ {
+ if( *it == peerID )
{
- GamestateManager::removePeer(client->getID());
+ this->clientIDs_.erase(it);
+ break;
+ }
+ }
+ ClientConnectionListener::broadcastClientDisconnected(peerID);
+ GamestateManager::removePeer(peerID);
//ServerConnection::disconnectClient( client );
//ClientConnectionListener::broadcastClientDisconnected( client->getID() ); //this is done in ClientInformation now
- delete client;
- }
+// delete client;
+// }
}
void Server::processPacket(packet::Packet* packet)
{
if( packet->isReliable() )
{
- if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )
+ if( this->getLastReceivedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )
packet->process(static_cast<Host*>(this));
else
this->packetQueue_.push_back(packet);
@@ -376,16 +391,16 @@
bool Server::createClient(int clientID)
{
- ClientInformation *temp = ClientInformation::findClient(clientID);
- if(!temp)
- {
- COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;
- return false;
- }
- COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
+// ClientInformation *temp = ClientInformation::findClient(clientID);
+// if(!temp)
+// {
+// COUT(2) << "Server. could not create client with id: " << clientID << std::endl;
+// return false;
+// }
+// COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
// synchronise class ids
- syncClassid(temp->getID());
+ syncClassid(clientID);
// now synchronise functionIDs
packet::FunctionIDs *fIDs = new packet::FunctionIDs();
@@ -393,31 +408,31 @@
bool b = fIDs->send( static_cast<Host*>(this) );
assert(b);
- temp->setSynched(true);
+// temp->setSynched(true);
GamestateManager::setSynched(clientID);
COUT(4) << "sending welcome" << std::endl;
- packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID());
- w->setPeerID(temp->getID());
+ packet::Welcome *w = new packet::Welcome(clientID, OBJECTID_UNKNOWN);
+ w->setPeerID(clientID);
b = w->send( static_cast<Host*>(this) );
assert(b);
- packet::Gamestate *g = new packet::Gamestate();
- g->setPeerID(temp->getID());
- b = g->collectData(0,packet::GAMESTATE_MODE_SERVER);
- assert(b);
- if(!b)
- return false; //no data for the client
-// b = g->compressData();
+// packet::Gamestate *g = new packet::Gamestate();
+// g->setPeerID(clientID);
+// b = g->collectData(0,packet::GAMESTATE_MODE_SERVER);
// assert(b);
- b = g->send( static_cast<Host*>(this) );
- assert(b);
+// if(!b)
+// return false; //no data for the client
+// // b = g->compressData();
+// // assert(b);
+// b = g->send( static_cast<Host*>(this) );
+// assert(b);
return true;
}
- void Server::disconnectClient( ClientInformation *client )
+ void Server::disconnectClient( uint32_t clientID )
{
- ServerConnection::disconnectClient( client );
- GamestateManager::removePeer(client->getID());
+ ServerConnection::disconnectClient( clientID );
+ GamestateManager::removePeer( clientID );
// inform all the listeners
// ClientConnectionListener::broadcastClientDisconnected(client->getID()); // this is done in ClientInformation now
}
@@ -429,20 +444,20 @@
bool Server::broadcast(const std::string& message)
{
- return this->sendChat(message, CLIENTID_UNKNOWN);
+ return this->sendChat(message, NETWORK_PEER_ID_BROADCAST);
}
bool Server::sendChat(const std::string& message, unsigned int clientID)
{
- ClientInformation *temp = ClientInformation::getBegin();
+// ClientInformation *temp = ClientInformation::getBegin();
packet::Chat *chat;
- while(temp)
+// while(temp)
{
chat = new packet::Chat(message, clientID);
- chat->setPeerID(temp->getID());
- if(!chat->send( static_cast<Host*>(this) ))
- COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
- temp = temp->next();
+ chat->setPeerID(NETWORK_PEER_ID_BROADCAST);
+ chat->send( static_cast<Host*>(this) );
+// COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
+// temp = temp->next();
}
// COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl;
for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
Modified: code/trunk/src/libraries/network/Server.h
===================================================================
--- code/trunk/src/libraries/network/Server.h 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/Server.h 2011-04-25 18:22:36 UTC (rev 8327)
@@ -32,6 +32,7 @@
#include "NetworkPrereqs.h"
#include <deque>
+#include <vector>
#include "util/UtilPrereqs.h"
#include "core/CorePrereqs.h"
@@ -79,12 +80,12 @@
virtual bool isServer_(){return true;}
unsigned int playerID(){return 0;}
- void addPeer(ENetEvent *event);
- void removePeer(ENetEvent *event);
+ void addPeer(uint32_t peerID);
+ void removePeer(uint32_t peerID);
void processPacket(packet::Packet* packet);
bool createClient(int clientID);
- void disconnectClient( ClientInformation *client);
+ void disconnectClient( uint32_t clientID );
bool sendGameStates();
bool sendObjectDeletes();
virtual bool chat(const std::string& message);
@@ -94,6 +95,7 @@
float timeSinceLastUpdate_;
std::deque<packet::Packet*> packetQueue_;
+ std::vector<uint32_t> clientIDs_;
};
Modified: code/trunk/src/libraries/network/ServerConnection.cc
===================================================================
--- code/trunk/src/libraries/network/ServerConnection.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/ServerConnection.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -34,7 +34,8 @@
#include <enet/enet.h>
#include "util/Debug.h"
-#include "ClientInformation.h"
+#include <util/Sleep.h>
+// #include "ClientInformation.h"
namespace orxonox
{
@@ -43,9 +44,10 @@
bListening_(false)
{
this->bindAddress_ = new ENetAddress();
- memset(this->bindAddress_, 0, sizeof(ENetAddress));
+// memset(this->bindAddress_, 0, sizeof(ENetAddress));
this->bindAddress_->host = ENET_HOST_ANY;
this->bindAddress_->port = NETWORK_PORT;
+ this->bindAddress_->scopeID = 0;
}
ServerConnection::~ServerConnection()
@@ -103,58 +105,54 @@
void ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID, uint8_t channelID)
{
- if ( clientID == CLIENTID_UNKNOWN )
+ if ( clientID == NETWORK_PEER_ID_BROADCAST )
{
broadcastPacket(packet, channelID);
}
else
{
- ClientInformation *temp = ClientInformation::findClient(clientID);
- if(!temp){
- COUT(3) << "C.Man: addPacket findClient failed" << std::endl;
- }
- Connection::addPacket(packet, temp->getPeer(), channelID);
+// ClientInformation *temp = ClientInformation::findClient(clientID);
+// if(!temp){
+// COUT(3) << "C.Man: addPacket findClient failed" << std::endl;
+// }
+ Connection::addPacket(packet, clientID, channelID);
}
}
- void ServerConnection::disconnectClient(ClientInformation *client)
- {
- Connection::disconnectPeer( client->getPeer() );
- }
+// void ServerConnection::disconnectClient(ClientInformation *client)
+// {
+// Connection::disconnectPeer( client->getPeer() );
+// }
void ServerConnection::disconnectClient(int clientID)
{
- ClientInformation *client = ClientInformation::findClient(clientID);
- if(client)
- ServerConnection::disconnectClient(client);
+// ClientInformation *client = ClientInformation::findClient(clientID);
+// if(client)
+ ServerConnection::disconnectClient(clientID);
}
void ServerConnection::disconnectClients()
{
- ClientInformation *temp = ClientInformation::getBegin();
- while(temp!=0)
- {
- ServerConnection::disconnectClient( temp );
- temp = temp->next();
- }
+ Connection::disconnectPeers();
+ Connection::waitOutgoingQueue();
return;
}
- int ServerConnection::getClientID(ENetPeer* peer)
- {
- return getClientID(&(peer->address));
- }
+// int ServerConnection::getClientID(ENetPeer* peer)
+// {
+// return getClientID(&(peer->address));
+// }
- int ServerConnection::getClientID(ENetAddress* address)
- {
- return ClientInformation::findClient(address)->getID();
- }
+// int ServerConnection::getClientID(ENetAddress* address)
+// {
+// return ClientInformation::findClient(address)->getID();
+// }
+//
+// ENetPeer *ServerConnection::getClientPeer(int clientID)
+// {
+// return ClientInformation::findClient(clientID)->getPeer();
+// }
- ENetPeer *ServerConnection::getClientPeer(int clientID)
- {
- return ClientInformation::findClient(clientID)->getPeer();
- }
-
}
Modified: code/trunk/src/libraries/network/ServerConnection.h
===================================================================
--- code/trunk/src/libraries/network/ServerConnection.h 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/ServerConnection.h 2011-04-25 18:22:36 UTC (rev 8327)
@@ -56,16 +56,16 @@
bool openListener();
bool closeListener();
void addPacket(ENetPacket *packet, unsigned int ID, uint8_t channelID);
- virtual void disconnectClient(ClientInformation *client);
+// virtual void disconnectClient(ClientInformation *client);
void disconnectClient(int clientID);
protected:
ServerConnection();
void disconnectClients();
private:
- int getClientID(ENetPeer* peer);
- int getClientID(ENetAddress* address);
- ENetPeer* getClientPeer(int clientID);
+// int getClientID(ENetPeer* peer);
+// int getClientID(ENetAddress* address);
+// ENetPeer* getClientPeer(int clientID);
ENetAddress* bindAddress_;
Modified: code/trunk/src/libraries/network/WANDiscovery.cc
===================================================================
--- code/trunk/src/libraries/network/WANDiscovery.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/WANDiscovery.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -70,7 +70,7 @@
/* update msaddress string from orxonox.ini config file, if it
* has changed.
*/
- SetConfigValue( msaddress, "orxonox.net");
+ SetConfigValue( msaddress, "master.orxonox.net");
}
WANDiscovery::~WANDiscovery()
Modified: code/trunk/src/libraries/network/packet/Gamestate.cc
===================================================================
--- code/trunk/src/libraries/network/packet/Gamestate.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/packet/Gamestate.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -106,7 +106,7 @@
assert(data_==0);
uint32_t size = calcGamestateSize(id, mode);
- COUT(4) << "G.ST.Man: producing gamestate with id: " << id << std::endl;
+ COUT(5) << "G.ST.Man: producing gamestate with id: " << id << std::endl;
if(size==0)
return false;
data_ = new uint8_t[size + GamestateHeader::getSize()];
@@ -157,6 +157,7 @@
//start write gamestate header
header_.setDataSize( currentsize );
+ header_.setCompSize( 0 );
header_.setID( id );
header_.setBaseID( GAMESTATEID_INITIAL );
header_.setDiffed( false );
Modified: code/trunk/src/libraries/network/packet/Packet.cc
===================================================================
--- code/trunk/src/libraries/network/packet/Packet.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/packet/Packet.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -46,7 +46,7 @@
#include "Gamestate.h"
#include "Welcome.h"
#include "network/Host.h"
-#include "network/ClientInformation.h"
+// #include "network/ClientInformation.h"
namespace orxonox{
@@ -84,7 +84,8 @@
}
-Packet::Packet(const Packet &p){
+Packet::Packet(const Packet &p)
+{
enetPacket_=p.enetPacket_;
flags_=p.flags_;
packetDirection_ = p.packetDirection_;
@@ -103,12 +104,15 @@
That also means destroying the ENetPacket if one exists. There
*/
-Packet::~Packet(){
+Packet::~Packet()
+{
// Deallocate data_ memory if necessary.
- if (this->bDataENetAllocated_){
+ if (this->bDataENetAllocated_)
+ {
// In this case ENet allocated data_ and will destroy it.
}
- else if (this->data_) {
+ else if (this->data_)
+ {
// This destructor was probably called as a consequence of ENet executing our callback.
// It simply serves us to be able to deallocate the packet content (data_) ourselves since
// we have created it in the first place.
@@ -118,18 +122,22 @@
// Destroy the ENetPacket if necessary.
// Note: For the case ENet used the callback to destroy the packet, we have already set
// enetPacket_ to NULL to avoid destroying it again.
- if (this->enetPacket_){
+ if (this->enetPacket_)
+ {
// enetPacket_->data gets destroyed too by ENet if it was allocated by it.
enet_packet_destroy(enetPacket_);
}
}
-bool Packet::send(orxonox::Host* host){
- if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional ){
+bool Packet::send(orxonox::Host* host)
+{
+ if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional )
+ {
assert(0);
return false;
}
- if(!enetPacket_){
+ if(!enetPacket_)
+ {
if(!data_){
assert(0);
return false;
@@ -174,13 +182,14 @@
return true;
}
-Packet *Packet::createPacket(ENetPacket *packet, ENetPeer *peer){
+Packet *Packet::createPacket(ENetPacket* packet, uint32_t peerID)
+{
uint8_t *data = packet->data;
- assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer());
- unsigned int peerID = ClientInformation::findClient(&peer->address)->getID();
+// assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer());
+// unsigned int peerID = ClientInformation::findClient(&peer->address)->getID();
// HACK
- if( peerID==static_cast<unsigned int>(-2))
- peerID = NETWORK_PEER_ID_SERVER;
+// if( peerID==static_cast<unsigned int>(-2))
+// peerID = NETWORK_PEER_ID_SERVER;
Packet *p = 0;
// COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl;
switch( *(Type::Value *)(data + _PACKETID) )
@@ -234,7 +243,8 @@
ENet calls this method whenever it wants to destroy a packet that contains
data we allocated ourselves.
*/
-void Packet::deletePacket(ENetPacket *enetPacket){
+void Packet::deletePacket(ENetPacket *enetPacket)
+{
// Get our Packet from a global map with all Packets created in the send() method of Packet.
Packet::packetMapMutex_.lock();
std::map<size_t, Packet*>::iterator it = packetMap_.find(reinterpret_cast<size_t>(enetPacket));
Modified: code/trunk/src/libraries/network/packet/Packet.h
===================================================================
--- code/trunk/src/libraries/network/packet/Packet.h 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/packet/Packet.h 2011-04-25 18:22:36 UTC (rev 8327)
@@ -31,19 +31,25 @@
#include "network/NetworkPrereqs.h"
#include <map>
-namespace orxonox {
+namespace orxonox
+{
-namespace packet{
+namespace packet
+{
-namespace Direction{
- enum Value{
+namespace Direction
+{
+ enum Value
+ {
Incoming,
Outgoing,
Bidirectional
};
}
-namespace Type{
- enum Value{
+namespace Type
+{
+ enum Value
+ {
Acknowledgement,
Chat,
ClassID,
@@ -58,14 +64,15 @@
/**
@author Oliver Scheuss <scheusso [at] ee.ethz.ch>
*/
-class _NetworkExport Packet{
+class _NetworkExport Packet
+{
public:
Packet(const Packet &p);
virtual ~Packet();
- static Packet *createPacket(ENetPacket *packet, ENetPeer *peer);
- static void deletePacket(ENetPacket *packet);
+ static Packet* createPacket(ENetPacket* packet, uint32_t peerID);
+ static void deletePacket(ENetPacket* packet);
- virtual unsigned char *getData(){ return data_; };
+ virtual unsigned char* getData(){ return data_; };
virtual unsigned int getSize() const =0;
virtual bool process(orxonox::Host* host)=0;
inline uint32_t getFlags()
Modified: code/trunk/src/libraries/network/synchronisable/Synchronisable.cc
===================================================================
--- code/trunk/src/libraries/network/synchronisable/Synchronisable.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/libraries/network/synchronisable/Synchronisable.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -294,7 +294,7 @@
* This function takes a bytestream and loads the data into the registered variables
* @param mem pointer to the bytestream
* @param mode same as in getData
- * @param forceCallback FIXME - add doc!
+ * @param forceCallback this makes updateData call each callback
* @return true/false
*/
bool Synchronisable::updateData(uint8_t*& mem, uint8_t mode, bool forceCallback)
@@ -371,13 +371,14 @@
/**
* This function determines, wheter the object should be saved to the bytestream (according to its syncmode/direction)
* @param id gamestate id
- * @param mode FIXME - add doc!
+ * @param mode Synchronisation mode (toclient, toserver or bidirectional)
* @return true/false
*/
bool Synchronisable::doSync(int32_t id, uint8_t mode)
{
- if(mode==0x0)
- mode=state_;
+// if(mode==0x0)
+// mode=state_;
+ assert(mode!=0x0);
return ( (this->objectMode_ & mode)!=0 && (!syncList_.empty() ) );
}
Modified: code/trunk/src/modules/overlays/hud/ChatOverlay.cc
===================================================================
--- code/trunk/src/modules/overlays/hud/ChatOverlay.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/modules/overlays/hud/ChatOverlay.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -70,7 +70,7 @@
{
std::string text;
- if (senderID != CLIENTID_UNKNOWN)
+ if (senderID != NETWORK_PEER_ID_UNKNOWN)
{
std::string name = "unknown";
Modified: code/trunk/src/orxonox/ChatHistory.cc
===================================================================
--- code/trunk/src/orxonox/ChatHistory.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/orxonox/ChatHistory.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -81,7 +81,7 @@
#ifndef CHATTEST
/* get sender ID and prepend it to the message */
- if (senderID != CLIENTID_UNKNOWN)
+ if (senderID != NETWORK_PEER_ID_UNKNOWN)
{
/* if we can't find anything, use "unknown" as default */
std::string name = "unknown";
Modified: code/trunk/src/orxonox/ChatInputHandler.cc
===================================================================
--- code/trunk/src/orxonox/ChatInputHandler.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/orxonox/ChatInputHandler.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -219,7 +219,7 @@
std::string text, name = "unknown";
/* setup player name info */
- if (senderID != CLIENTID_UNKNOWN)
+ if (senderID != NETWORK_PEER_ID_UNKNOWN)
{
PlayerInfo* player = PlayerManager::getInstance().getClient(senderID);
if (player)
Modified: code/trunk/src/orxonox/PlayerManager.cc
===================================================================
--- code/trunk/src/orxonox/PlayerManager.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/orxonox/PlayerManager.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -44,7 +44,7 @@
{
RegisterRootObject(PlayerManager);
- this->getConnectedClients();
+// this->getConnectedClients();
}
PlayerManager::~PlayerManager()
Modified: code/trunk/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSRoot.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/orxonox/gamestates/GSRoot.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -182,7 +182,7 @@
void GSRoot::changedTimeFactor(float factor_new, float factor_old)
{
if (!GameMode::isStandalone())
- callStaticNetworkFunction(&TimeFactorListener::setTimeFactor, CLIENTID_UNKNOWN, factor_new);
+ callStaticNetworkFunction(&TimeFactorListener::setTimeFactor, NETWORK_PEER_ID_BROADCAST, factor_new);
}
/*static*/ void GSRoot::delayedStartMainMenu(void)
Modified: code/trunk/src/orxonox/gametypes/Dynamicmatch.cc
===================================================================
--- code/trunk/src/orxonox/gametypes/Dynamicmatch.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/orxonox/gametypes/Dynamicmatch.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -451,7 +451,7 @@
{
if (!it->first)//in order to catch nullpointer
continue;
- if (it->first->getClientID() == CLIENTID_UNKNOWN)
+ if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
continue;
this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f));
}
@@ -466,7 +466,7 @@
{
if (!it->first)//in order to catch nullpointer
continue;
- if (it->first->getClientID() == CLIENTID_UNKNOWN)
+ if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
continue;
else if (it->second==chaser)
{
@@ -500,7 +500,7 @@
{
if (!it->first)//in order to catch nullpointer
continue;
- if (it->first->getClientID() == CLIENTID_UNKNOWN)
+ if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
continue;
this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f));
}
@@ -515,7 +515,7 @@
{
if (!it->first)
continue;
- if (it->first->getClientID() == CLIENTID_UNKNOWN)
+ if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
continue;
else if (it->second==chaser)
{
@@ -550,7 +550,7 @@
{
if (!it->first)//in order to catch nullpointer
continue;
- if (it->first->getClientID() == CLIENTID_UNKNOWN)
+ if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
continue;
this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f));
}
@@ -565,7 +565,7 @@
{
if (!it->first)
continue;
- if (it->first->getClientID() == CLIENTID_UNKNOWN)
+ if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
continue;
else if (it->second==chaser)
{
@@ -631,7 +631,7 @@
{
for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it)
{
- if (it->first->getClientID() == CLIENTID_UNKNOWN)
+ if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
continue;
this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f));
}
Modified: code/trunk/src/orxonox/gametypes/Gametype.cc
===================================================================
--- code/trunk/src/orxonox/gametypes/Gametype.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/orxonox/gametypes/Gametype.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -262,9 +262,9 @@
{
it->second.frags_++;
- if (killer->getPlayer()->getClientID() != CLIENTID_UNKNOWN)
+ if (killer->getPlayer()->getClientID() != NETWORK_PEER_ID_UNKNOWN)
this->gtinfo_->sendKillMessage("You killed " + victim->getPlayer()->getName(), killer->getPlayer()->getClientID());
- if (victim->getPlayer()->getClientID() != CLIENTID_UNKNOWN)
+ if (victim->getPlayer()->getClientID() != NETWORK_PEER_ID_UNKNOWN)
this->gtinfo_->sendDeathMessage("You were killed by " + killer->getPlayer()->getName(), victim->getPlayer()->getClientID());
}
}
Modified: code/trunk/src/orxonox/gametypes/LastManStanding.cc
===================================================================
--- code/trunk/src/orxonox/gametypes/LastManStanding.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/orxonox/gametypes/LastManStanding.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -85,7 +85,7 @@
std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
if (it != this->players_.end())
{
- if (it->first->getClientID()== CLIENTID_UNKNOWN)
+ if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
return true;
const std::string& message = ""; // resets Camper-Warning-message
this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
@@ -130,7 +130,7 @@
for (std::map<PlayerInfo*, int>::iterator it = this->playerLives_.begin(); it != this->playerLives_.end(); ++it)
{
- if (it->first->getClientID() == CLIENTID_UNKNOWN)
+ if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
continue;
if (it->second > 0)
@@ -193,7 +193,7 @@
std::map<PlayerInfo*, Player>::iterator it = this->players_.find(player);
if (it != this->players_.end())
{
- if (it->first->getClientID()== CLIENTID_UNKNOWN)
+ if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
return;
const std::string& message = ""; // resets Camper-Warning-message
this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
@@ -248,7 +248,7 @@
if (playerDelayTime_[it->first]<=0)
this->inGame_[it->first]=true;
- if (it->first->getClientID()== CLIENTID_UNKNOWN)
+ if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
continue;
int output=1+(int)playerDelayTime_[it->first];
const std::string& message = "Respawn in " +multi_cast<std::string>(output)+ " seconds." ;//Countdown
@@ -260,7 +260,7 @@
if (playerGetLives(it->first)>0)
{
this->punishPlayer(it->first);
- if (it->first->getClientID()== CLIENTID_UNKNOWN)
+ if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
return;
const std::string& message = ""; // resets Camper-Warning-message
this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
@@ -268,7 +268,7 @@
}
else if (it->second<timeRemaining/5)//Warning message
{
- if (it->first->getClientID()== CLIENTID_UNKNOWN)
+ if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
continue;
const std::string& message = "Camper Warning! Don't forget to shoot.";
this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
Modified: code/trunk/src/orxonox/gametypes/LastTeamStanding.cc
===================================================================
--- code/trunk/src/orxonox/gametypes/LastTeamStanding.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/orxonox/gametypes/LastTeamStanding.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -29,6 +29,7 @@
#include "LastTeamStanding.h"
#include "core/CoreIncludes.h"
+#include "network/NetworkPrereqs.h"
#include "network/Host.h"
#include "infos/PlayerInfo.h"
#include "worldentities/pawns/Pawn.h"
@@ -134,7 +135,7 @@
std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
if (it != this->players_.end())
{
- if (it->first->getClientID()== CLIENTID_UNKNOWN)
+ if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
return true;
const std::string& message = ""; // resets Camper-Warning-message
this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
@@ -168,7 +169,7 @@
std::map<PlayerInfo*, Player>::iterator it = this->players_.find(player);
if (it != this->players_.end())
{
- if (it->first->getClientID()== CLIENTID_UNKNOWN)
+ if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
return;
const std::string& message = ""; // resets Camper-Warning-message
this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
@@ -195,7 +196,7 @@
if (playerDelayTime_[it->first] <= 0)
this->inGame_[it->first] = true;
- if (it->first->getClientID()== CLIENTID_UNKNOWN)
+ if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
continue;
int output = 1 + (int)playerDelayTime_[it->first];
const std::string& message = "Respawn in " +multi_cast<std::string>(output)+ " seconds." ;//Countdown
@@ -207,7 +208,7 @@
if (playerGetLives(it->first) > 0)
{
this->punishPlayer(it->first);
- if (it->first->getClientID() == CLIENTID_UNKNOWN)
+ if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
return;
const std::string& message = ""; // resets Camper-Warning-message
this->gtinfo_->sendFadingMessage(message, it->first->getClientID());
@@ -215,7 +216,7 @@
}
else if (it->second < timeRemaining/5)//Warning message
{
- if (it->first->getClientID()== CLIENTID_UNKNOWN)
+ if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
continue;
const std::string& message = "Camper Warning! Don't forget to shoot.";
this->gtinfo_->sendFadingMessage(message, it->first->getClientID());
@@ -231,7 +232,7 @@
//find a player who survived
for (std::map<PlayerInfo*, int>::iterator it = this->playerLives_.begin(); it != this->playerLives_.end(); ++it)
{
- if (it->first->getClientID() == CLIENTID_UNKNOWN)
+ if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
continue;
if (it->second > 0)//a player that is alive
@@ -246,7 +247,7 @@
//victory message to all team members, loose message to everyone else
for (std::map<PlayerInfo*, int>::iterator it3 = this->teamnumbers_.begin(); it3 != this->teamnumbers_.end(); ++it3)
{
- if (it3->first->getClientID() == CLIENTID_UNKNOWN)
+ if (it3->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
continue;
if (it3->second == party)
{this->gtinfo_->sendAnnounceMessage("You have won the match!", it3->first->getClientID());}
Modified: code/trunk/src/orxonox/gametypes/TeamBaseMatch.cc
===================================================================
--- code/trunk/src/orxonox/gametypes/TeamBaseMatch.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/orxonox/gametypes/TeamBaseMatch.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -189,7 +189,7 @@
for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
{
- if (it->first->getClientID() == CLIENTID_UNKNOWN)
+ if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
continue;
if (it->second == winningteam)
Modified: code/trunk/src/orxonox/gametypes/UnderAttack.cc
===================================================================
--- code/trunk/src/orxonox/gametypes/UnderAttack.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/orxonox/gametypes/UnderAttack.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -75,7 +75,7 @@
for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
{
- if (it->first->getClientID() == CLIENTID_UNKNOWN)
+ if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
continue;
if (it->second == 0)
@@ -157,7 +157,7 @@
for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
{
- if (it->first->getClientID() == CLIENTID_UNKNOWN)
+ if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
continue;
if (it->second == 1)
Modified: code/trunk/src/orxonox/infos/GametypeInfo.cc
===================================================================
--- code/trunk/src/orxonox/infos/GametypeInfo.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/orxonox/infos/GametypeInfo.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -73,7 +73,7 @@
{
if (GameMode::isMaster())
{
- callMemberNetworkFunction(GametypeInfo, dispatchAnnounceMessage, this->getObjectID(), CLIENTID_UNKNOWN, message);
+ callMemberNetworkFunction(GametypeInfo, dispatchAnnounceMessage, this->getObjectID(), NETWORK_PEER_ID_BROADCAST, message);
this->dispatchAnnounceMessage(message);
}
}
Modified: code/trunk/src/orxonox/infos/HumanPlayer.cc
===================================================================
--- code/trunk/src/orxonox/infos/HumanPlayer.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/orxonox/infos/HumanPlayer.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -31,7 +31,7 @@
#include "core/CoreIncludes.h"
#include "core/ConfigValueIncludes.h"
#include "core/GameMode.h"
-#include "network/ClientInformation.h"
+// #include "network/ClientInformation.h"
#include "network/Host.h"
#include "controllers/HumanController.h"
#include "controllers/NewHumanController.h"
@@ -143,12 +143,14 @@
float HumanPlayer::getPing() const
{
- return static_cast<float>(ClientInformation::findClient(this->getClientID())->getRTT());
+// return static_cast<float>(ClientInformation::findClient(this->getClientID())->getRTT());
+ return 0.; //TODO: reimplement this
}
float HumanPlayer::getPacketLossRatio() const
{
- return static_cast<float>(ClientInformation::findClient(this->getClientID())->getPacketLoss());
+ // return static_cast<float>(ClientInformation::findClient(this->getClientID())->getPacketLoss());
+ return 0.; //TODO: reimplement this
}
void HumanPlayer::setClientID(unsigned int clientID)
Modified: code/trunk/src/orxonox/infos/PlayerInfo.cc
===================================================================
--- code/trunk/src/orxonox/infos/PlayerInfo.cc 2011-04-25 13:29:58 UTC (rev 8326)
+++ code/trunk/src/orxonox/infos/PlayerInfo.cc 2011-04-25 18:22:36 UTC (rev 8327)
@@ -31,7 +31,7 @@
#include "PlayerInfo.h"
#include "core/CoreIncludes.h"
-#include "network/ClientInformation.h"
+// #include "network/ClientInformation.h"
#include "gametypes/Gametype.h"
#include "worldentities/ControllableEntity.h"
#include "controllers/Controller.h"
@@ -42,7 +42,7 @@
{
RegisterObject(PlayerInfo);
- this->clientID_ = CLIENTID_UNKNOWN;
+ this->clientID_ = NETWORK_PEER_ID_UNKNOWN;
this->bHumanPlayer_ = false;
this->bLocalPlayer_ = false;
this->bReadyToSpawn_ = false;
More information about the Orxonox-commit
mailing list