[Orxonox-commit 682] r3214 - in trunk/src: core network network/packet network/synchronisable orxonox orxonox/objects/worldentities/pawns util
scheusso at orxonox.net
scheusso at orxonox.net
Tue Jun 23 18:02:26 CEST 2009
Author: scheusso
Date: 2009-06-23 18:02:25 +0200 (Tue, 23 Jun 2009)
New Revision: 3214
Added:
trunk/src/network/Connection.cc
trunk/src/network/Connection.h
trunk/src/network/ServerConnection.cc
trunk/src/network/ServerConnection.h
Removed:
trunk/src/network/ConnectionManager.cc
trunk/src/network/ConnectionManager.h
Modified:
trunk/src/core/Core.cc
trunk/src/core/CorePrecompiledHeaders.h
trunk/src/network/CMakeLists.txt
trunk/src/network/ChatListener.cc
trunk/src/network/ChatListener.h
trunk/src/network/Client.cc
trunk/src/network/Client.h
trunk/src/network/ClientConnection.cc
trunk/src/network/ClientConnection.h
trunk/src/network/ClientConnectionListener.cc
trunk/src/network/ClientConnectionListener.h
trunk/src/network/ClientInformation.cc
trunk/src/network/FunctionCallManager.h
trunk/src/network/GamestateClient.cc
trunk/src/network/GamestateClient.h
trunk/src/network/GamestateHandler.cc
trunk/src/network/GamestateHandler.h
trunk/src/network/GamestateManager.cc
trunk/src/network/GamestateManager.h
trunk/src/network/Host.cc
trunk/src/network/Host.h
trunk/src/network/NetworkFunction.cc
trunk/src/network/NetworkFunction.h
trunk/src/network/NetworkPrecompiledHeaders.h
trunk/src/network/NetworkPrereqs.h
trunk/src/network/PacketBuffer.cc
trunk/src/network/Server.cc
trunk/src/network/Server.h
trunk/src/network/TrafficControl.cc
trunk/src/network/TrafficControl.h
trunk/src/network/packet/Acknowledgement.cc
trunk/src/network/packet/Acknowledgement.h
trunk/src/network/packet/Chat.cc
trunk/src/network/packet/Chat.h
trunk/src/network/packet/ClassID.cc
trunk/src/network/packet/ClassID.h
trunk/src/network/packet/DeleteObjects.cc
trunk/src/network/packet/DeleteObjects.h
trunk/src/network/packet/FunctionCalls.cc
trunk/src/network/packet/FunctionCalls.h
trunk/src/network/packet/FunctionIDs.cc
trunk/src/network/packet/FunctionIDs.h
trunk/src/network/packet/Gamestate.cc
trunk/src/network/packet/Gamestate.h
trunk/src/network/packet/Packet.cc
trunk/src/network/packet/Packet.h
trunk/src/network/packet/Welcome.cc
trunk/src/network/packet/Welcome.h
trunk/src/network/synchronisable/NetworkCallback.h
trunk/src/network/synchronisable/NetworkCallbackManager.cc
trunk/src/network/synchronisable/NetworkCallbackManager.h
trunk/src/network/synchronisable/Synchronisable.cc
trunk/src/network/synchronisable/Synchronisable.h
trunk/src/network/synchronisable/SynchronisableSpecialisations.cc
trunk/src/network/synchronisable/SynchronisableVariable.cc
trunk/src/network/synchronisable/SynchronisableVariable.h
trunk/src/orxonox/OrxonoxPrecompiledHeaders.h
trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc
trunk/src/orxonox/objects/worldentities/pawns/Pawn.h
trunk/src/util/Clipboard.cc
trunk/src/util/Math.h
trunk/src/util/Sleep.cc
Log:
merged netp5 back to trunk
Modified: trunk/src/core/Core.cc
===================================================================
--- trunk/src/core/Core.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/core/Core.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -46,6 +46,8 @@
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h>
+# undef min
+# undef max
#elif defined(ORXONOX_PLATFORM_APPLE)
# include <sys/param.h>
# include <mach-o/dyld.h>
Modified: trunk/src/core/CorePrecompiledHeaders.h
===================================================================
--- trunk/src/core/CorePrecompiledHeaders.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/core/CorePrecompiledHeaders.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -34,42 +34,44 @@
#include "CorePrereqs.h"
+#include <cassert>
#include <fstream>
#include <iostream>
#include <list>
+#include <locale>
#include <map>
+#include <queue>
#include <set>
#include <sstream>
+#include <stack>
#include <string>
#include <vector>
#ifdef ORXONOX_COMPILER_MSVC
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#undef max
-#undef min
+#include <OgreMath.h>
+#include <OgreVector2.h>
+#include <OgreVector3.h>
+#include <OgreVector4.h>
+#include <OgreQuaternion.h>
+#include <OgreColourValue.h>
-#include <ois/OISKeyboard.h>
-#include <ois/OISMouse.h>
-#include <ois/OISJoyStick.h>
-#include <tinyxml/ticpp.h>
+#include <boost/shared_ptr.hpp> // 12
+#include <boost/preprocessor/cat.hpp> // 12
// Included by both filesystem and thread but still relatively small
-#include <boost/iterator/iterator_facade.hpp>
+#include <boost/iterator/iterator_facade.hpp> // 10
+// Just in case some header included windows.h
+#undef min
+#undef max
+
#endif /* ORXONOX_COMPILER_MSVC */
-#include "util/Convert.h"
#include "util/Debug.h"
-#include "util/Exception.h"
#include "util/Math.h"
-#include "util/mbool.h"
#include "util/MultiType.h"
-#include "util/OrxAssert.h"
-#include "util/OrxEnum.h"
-#include "util/String.h"
#include "util/SubString.h"
Modified: trunk/src/network/CMakeLists.txt
===================================================================
--- trunk/src/network/CMakeLists.txt 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/CMakeLists.txt 2009-06-23 16:02:25 UTC (rev 3214)
@@ -23,7 +23,7 @@
ClientConnection.cc
ClientInformation.cc
ClientConnectionListener.cc
- ConnectionManager.cc
+ Connection.cc
FunctionCallManager.cc
GamestateManager.cc
GamestateClient.cc
@@ -32,6 +32,7 @@
Host.cc
PacketBuffer.cc
Server.cc
+ ServerConnection.cc
TrafficControl.cc
)
ADD_SUBDIRECTORY(packet)
Modified: trunk/src/network/ChatListener.cc
===================================================================
--- trunk/src/network/ChatListener.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/ChatListener.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -27,7 +27,6 @@
*/
#include "ChatListener.h"
-
#include "core/CoreIncludes.h"
namespace orxonox
Modified: trunk/src/network/ChatListener.h
===================================================================
--- trunk/src/network/ChatListener.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/ChatListener.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -30,8 +30,6 @@
#define _NETWORK_ChatListener__
#include "NetworkPrereqs.h"
-
-#include "ClientInformation.h"
#include "core/OrxonoxClass.h"
namespace orxonox
Modified: trunk/src/network/Client.cc
===================================================================
--- trunk/src/network/Client.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/Client.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -38,33 +38,29 @@
//
//
+#include "Client.h"
+
#include <cassert>
-#include <enet/enet.h>
-#include "Client.h"
-#include "Host.h"
-#include "synchronisable/Synchronisable.h"
+#include "util/Debug.h"
#include "core/Clock.h"
-#include "core/CoreIncludes.h"
-#include "packet/Packet.h"
+#include "synchronisable/Synchronisable.h"
+#include "packet/Chat.h"
+#include "packet/Gamestate.h"
#include "FunctionCallManager.h"
-// #include "packet/Acknowledgement.h"
-
namespace orxonox
{
-// SetConsoleCommandShortcut(Client, chat);
/**
* Constructor for the Client class
* initializes the address and the port to default localhost:NETWORK_PORT
*/
- Client::Client(): client_connection(NETWORK_PORT,"127.0.0.1"){
- // set server address to localhost
- isConnected=false;
- isSynched_=false;
- gameStateFailure_=false;
+ Client::Client():
+ isSynched_(false),
+ gameStateFailure_(false)
+ {
}
/**
@@ -72,25 +68,16 @@
* @param address the server address
* @param port port of the application on the server
*/
- Client::Client(const std::string& address, int port) : client_connection(port, address){
- isConnected=false;
- isSynched_=false;
- gameStateFailure_=false;
+ Client::Client(const std::string& address, int port):
+ isSynched_(false),
+ gameStateFailure_(false)
+ {
+ setPort( port );
+ setServerAddress( address );
}
- /**
- * Constructor for the Client class
- * @param address the server address
- * @param port port of the application on the server
- */
- Client::Client(const char *address, int port) : client_connection(port, address){
- isConnected=false;
- isSynched_=false;
- gameStateFailure_=false;
- }
-
Client::~Client(){
- if(isConnected)
+ if ( ClientConnection::isConnected() )
closeConnection();
}
@@ -100,10 +87,7 @@
*/
bool Client::establishConnection(){
Synchronisable::setClient(true);
- isConnected=client_connection.createConnection();
- if(!isConnected)
- COUT(1) << "could not create connection laber" << std::endl;
- return isConnected;
+ return ClientConnection::establishConnection();
}
/**
@@ -111,12 +95,13 @@
* @return true/false
*/
bool Client::closeConnection(){
- isConnected=false;
- return client_connection.closeConnection();
+ return ClientConnection::closeConnection();
}
bool Client::queuePacket(ENetPacket *packet, int clientID){
- return client_connection.addPacket(packet);
+ bool b = ClientConnection::addPacket(packet);
+ assert(b);
+ return b;
}
bool Client::processChat(const std::string& message, unsigned int playerID){
@@ -142,10 +127,12 @@
void Client::update(const Clock& time){
//this steers our network frequency
timeSinceLastUpdate_+=time.getDeltaTime();
- if(timeSinceLastUpdate_>=NETWORK_PERIOD){
+ if(timeSinceLastUpdate_>=NETWORK_PERIOD)
+ {
timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
// COUT(3) << ".";
- if(client_connection.isConnected() && isSynched_){
+ if ( isConnected() && isSynched_ )
+ {
COUT(4) << "popping partial gamestate: " << std::endl;
packet::Gamestate *gs = gamestate.getGamestate();
//assert(gs); <--- there might be the case that no data has to be sent, so its commented out now
@@ -158,18 +145,9 @@
FunctionCallManager::sendCalls();
}
}
+ sendPackets(); // flush the enet queue
- ENetEvent *event;
- // stop if the packet queue is empty
- while(!(client_connection.queueEmpty())){
- event = client_connection.getEvent();
- COUT(5) << "tick packet size " << event->packet->dataLength << std::endl;
- packet::Packet *packet = packet::Packet::createPacket(event->packet, event->peer);
- // note: packet commits suicide here except for the GameState. That is then deleted by a GamestateHandler
- bool b = packet->process();
- assert(b);
- delete event;
- }
+ Connection::processQueue();
if(gamestate.processGamestates())
{
if(!isSynched_)
Modified: trunk/src/network/Client.h
===================================================================
--- trunk/src/network/Client.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/Client.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -44,13 +44,10 @@
#include "NetworkPrereqs.h"
#include <string>
-
-#include "Host.h"
-#include "packet/Chat.h"
#include "ClientConnection.h"
#include "GamestateClient.h"
+#include "Host.h"
-
namespace orxonox
{
/**
@@ -60,11 +57,10 @@
* It is the root class of the network module
*
*/
- class _NetworkExport Client : public Host{
+ class _NetworkExport Client : public Host, public ClientConnection{
public:
Client();
Client(const std::string& address, int port);
- Client(const char *address, int port);
~Client();
bool establishConnection();
@@ -73,7 +69,6 @@
bool processChat(const std::string& message, unsigned int playerID);
virtual bool chat(const std::string& message);
virtual bool broadcast(const std::string& message) { return false; }
- //bool sendChat(packet::Chat *chat);
void update(const Clock& time);
@@ -81,9 +76,7 @@
Client(const Client& copy); // not used
virtual bool isServer_(){return false;}
- ClientConnection client_connection;
GamestateClient gamestate;
- bool isConnected;
bool isSynched_;
bool gameStateFailure_;
Modified: trunk/src/network/ClientConnection.cc
===================================================================
--- trunk/src/network/ClientConnection.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/ClientConnection.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -26,240 +26,120 @@
*
*/
-//
-// C++ Interface: ClientConnection
-//
-// Description: The Class ClientConnection manages the servers conenctions to the clients.
-// each connection is provided by a new process. communication between master process and
-// connection processes is provided by ...
-//
-//
-// Author: Oliver Scheuss
-//
-
#include "ClientConnection.h"
-#include <enet/enet.h>
-#include <iostream>
#include <cassert>
-// boost.thread library for multithreading support
-#include <boost/thread/thread.hpp>
-#include <boost/bind.hpp>
-#include <boost/thread/recursive_mutex.hpp>
-
-#include "util/Sleep.h"
+#include <enet/enet.h>
#include "util/Debug.h"
namespace orxonox
{
- //static boost::thread_group network_threads;
+ const unsigned int NETWORK_CLIENT_WAIT_TIME = 1;
+ const unsigned int NETWORK_CLIENT_CONNECTION_TIMEOUT = 3000; //millisecs
+ const unsigned int NETWORK_CLIENT_MAX_CONNECTIONS = 5;
+ const unsigned int NETWORK_CLIENT_CHANNELS = 2;
- static boost::recursive_mutex enet_mutex_g;
- ClientConnection::ClientConnection(int port, const std::string& address) {
- quit_=false;
- server=NULL;
- serverAddress = new ENetAddress();
- enet_address_set_host(serverAddress, address.c_str());
- serverAddress->port = port;
- established=false;
+ ClientConnection::ClientConnection():
+ established_(false),
+ server_(NULL)
+ {
+ this->serverAddress_ = new ENetAddress();
+ //set standard address and port
+ enet_address_set_host(this->serverAddress_, "127.0.0.1");
+ serverAddress_->port = NETWORK_PORT;
}
- ClientConnection::ClientConnection(int port, const char *address) {
- quit_=false;
- server=NULL;
- serverAddress = new ENetAddress();
- enet_address_set_host(serverAddress, address);
- serverAddress->port = port;
- established=false;
- }
-
- bool ClientConnection::waitEstablished(int milisec) {
- for(int i=0; i<=milisec && !established; i++)
- msleep(1);
-
- return established;
- }
-
ClientConnection::~ClientConnection(){
- if(established)
+ if(this->established_)
closeConnection();
- delete serverAddress; // surely was created
+ delete this->serverAddress_; // surely was created
}
- ENetEvent *ClientConnection::getEvent(){
- if(!buffer.isEmpty())
- return buffer.pop();
- else
- return NULL;
+ void ClientConnection::setServerAddress( const std::string& serverAddress ) {
+ enet_address_set_host (this->serverAddress_, serverAddress.c_str());
}
- bool ClientConnection::queueEmpty() {
- return buffer.isEmpty();
+ void ClientConnection::setPort( unsigned int port ) {
+ this->serverAddress_->port = port;
}
- bool ClientConnection::createConnection() {
- receiverThread_ = new boost::thread(boost::bind(&ClientConnection::receiverThread, this));
- //network_threads.create_thread(boost::bind(boost::mem_fn(&ClientConnection::receiverThread), this));
- // wait 10 seconds for the connection to be established
- return waitEstablished(NETWORK_CLIENT_CONNECT_TIMEOUT);
- }
-
- bool ClientConnection::closeConnection() {
- quit_=true;
- //network_threads.join_all();
- receiverThread_->join();
- established=false;
- return true;
- }
-
-
- bool ClientConnection::addPacket(ENetPacket *packet) {
- if(server==NULL)
+ bool ClientConnection::establishConnection()
+ {
+ ENetEvent event;
+
+ this->host_ = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0);
+ if ( this->host_ == NULL )
+ {
+ COUT(2) << "ClientConnection: host_ == NULL" << std::endl;
+ // error handling
return false;
- if(packet==NULL){
- COUT(3) << "Cl.con: addpacket: invalid packet" << std::endl;
- return false;
}
- boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
- if(enet_peer_send(server, 0, packet)<0)
- return false;
- else
- return true;
- }
-
- bool ClientConnection::sendPackets() {
- if(server==NULL)
- return false;
- boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
- enet_host_flush(client);
- lock.unlock();
- return true;
- }
-
- void ClientConnection::receiverThread() {
- // what about some error-handling here ?
- atexit(enet_deinitialize);
- ENetEvent *event;
+ this->server_ = enet_host_connect(this->host_, serverAddress_, NETWORK_CLIENT_CHANNELS);
+ if ( this->server_==NULL )
{
- boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
- enet_initialize();
- client = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0);
- lock.unlock();
+ COUT(2) << "ClientConnection: server == NULL" << std::endl;
+ // error handling
+ return false;
}
- if(client==NULL) {
- COUT(2) << "ClientConnection: could not create client host" << std::endl;
- // add some error handling here ==========================
- quit_=true;
- }
- //connect to the server
- if(!establishConnection()){
- COUT(2) << "clientConn: receiver thread: could not establishConnection" << std::endl;
- quit_=true;
- return;
- }
- event = new ENetEvent;
- //main loop
- while(!quit_){
- //std::cout << "connection loop" << std::endl;
+ // handshake
+ for( unsigned int i=0; i<NETWORK_CLIENT_CONNECTION_TIMEOUT/NETWORK_CLIENT_WAIT_TIME; i++ )
+ {
+ if( enet_host_service(this->host_, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && event.type == ENET_EVENT_TYPE_CONNECT )
{
- boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
- if(enet_host_service(client, event, NETWORK_CLIENT_WAIT_TIME)<0){
- // we should never reach this point
-// assert(0);
- printf("ClientConnection: ENet returned with an error!\n");
-// quit_=true;
- continue;
- // add some error handling here ========================
- }
- lock.unlock();
+ this->established_=true;
+ return true;
}
- switch(event->type){
- // log handling ================
- case ENET_EVENT_TYPE_CONNECT:
- break;
- case ENET_EVENT_TYPE_RECEIVE:
- //COUT(5) << "Cl.Con: receiver-Thread while loop: got new packet" << std::endl;
- if ( !processData(event) ) COUT(2) << "Current packet was not pushed to packetBuffer -> ev ongoing SegFault" << std::endl;
- //COUT(5) << "Cl.Con: processed Data in receiver-thread while loop" << std::endl;
- event = new ENetEvent;
- break;
- case ENET_EVENT_TYPE_DISCONNECT:
- quit_=true;
- printf("Received disconnect Packet from Server!\n");
- // server closed the connection
- return;
- break;
- case ENET_EVENT_TYPE_NONE:
- //receiverThread_->yield();
- msleep(1);
- break;
- }
}
- delete event;
- // now disconnect
-
- if(!disconnectConnection())
- {
- printf("could not disconnect properly\n");
- // if disconnecting failed destroy conn.
- boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
- enet_peer_reset(server);
- }
- else
- printf("properly disconnected\n");
- return;
+ COUT(1) << "Could not connect to server" << endl;
+ return false;
}
- bool ClientConnection::disconnectConnection() {
+ bool ClientConnection::closeConnection() {
ENetEvent event;
- if(this->quit_)
+
+ if ( !this->established_ )
return true;
- boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
- enet_peer_disconnect(server, 0);
- while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME) >= 0){
- switch (event.type)
+ this->established_ = false;
+ enet_peer_disconnect(this->server_, 0);
+ for( unsigned int i=0; i<NETWORK_CLIENT_CONNECTION_TIMEOUT/NETWORK_CLIENT_WAIT_TIME; i++)
+ {
+ if ( enet_host_service(this->host_, &event, NETWORK_CLIENT_WAIT_TIME) >= 0 )
{
- case ENET_EVENT_TYPE_NONE:
- case ENET_EVENT_TYPE_CONNECT:
- case ENET_EVENT_TYPE_RECEIVE:
- enet_packet_destroy(event.packet);
- break;
- case ENET_EVENT_TYPE_DISCONNECT:
- printf("received disconnect confirmation from server");
- return true;
+ switch (event.type)
+ {
+ case ENET_EVENT_TYPE_NONE:
+ case ENET_EVENT_TYPE_CONNECT:
+ break;
+ case ENET_EVENT_TYPE_RECEIVE:
+ enet_packet_destroy(event.packet);
+ break;
+ case ENET_EVENT_TYPE_DISCONNECT:
+ COUT(4) << "received disconnect confirmation from server" << endl;
+ return true;
+ }
}
}
- enet_peer_reset(server);
+ enet_peer_reset( this->server_ );
return false;
}
- bool ClientConnection::establishConnection() {
- ENetEvent event;
- // connect to peer (server is type ENetPeer*)
- boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
- server = enet_host_connect(client, serverAddress, NETWORK_CLIENT_CHANNELS);
- if(server==NULL) {
- COUT(2) << "ClientConnection: server == NULL" << std::endl;
- // error handling
- return false;
- }
- // handshake
- while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && !quit_){
- if( event.type == ENET_EVENT_TYPE_CONNECT ){
- established=true;
- return true;
- }
- }
- COUT(2) << "ClientConnection: enet_host_service < 0 or event.type != ENET_EVENT_TYPE_CONNECT # EVENT:" << event.type << std::endl;
- return false;
+
+ bool ClientConnection::addPacket(ENetPacket *packet) {
+ assert( this->server_ );
+ assert( packet );
+ return Connection::addPacket( packet, this->server_ );
}
- bool ClientConnection::processData(ENetEvent *event) {
- COUT(5) << "Cl.Con: got packet, pushing to queue" << std::endl;
- // just add packet to the buffer
- // this can be extended with some preprocessing
- return buffer.push(event);
+ void ClientConnection::addClient(ENetEvent* event)
+ {
+ assert(0);
}
+ void ClientConnection::disconnectPeer(ENetEvent* event)
+ {
+ this->established_=false;
+ COUT(1) << "Received disconnect Packet from Server!" << endl;
+ // server closed the connection
+ }
}
Modified: trunk/src/network/ClientConnection.h
===================================================================
--- trunk/src/network/ClientConnection.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/ClientConnection.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -25,85 +25,46 @@
* ...
*
*/
-
-//
-// C++ Interface: ClientConnection
-//
-// Description:
-//
-//
-// Author: Oliver Scheuss, (C) 2007
-//
-// Copyright: See COPYING file that comes with this distribution
-//
-//
+
#ifndef _ClientConnection_H__
#define _ClientConnection_H__
#include "NetworkPrereqs.h"
+#include "Connection.h"
-#include <string>
-#include "PacketBuffer.h"
-
-namespace boost { class thread; }
-
namespace orxonox
{
- const int NETWORK_PORT = 55556;
- const int NETWORK_CLIENT_MAX_CONNECTIONS = 5;
- const int NETWORK_CLIENT_WAIT_TIME = 10;
- const int NETWORK_CLIENT_CONNECT_TIMEOUT = 3000; // miliseconds
- const int NETWORK_CLIENT_CHANNELS = 2;
-
-
- class _NetworkExport ClientConnection{
+ class _NetworkExport ClientConnection: public Connection{
public:
- ClientConnection(int port, const std::string& address);
- ClientConnection(int port, const char* address);
- ~ClientConnection();
+ ClientConnection();
+ virtual ~ClientConnection();
+
+ void setServerAddress( const std::string& serverAddress );
+ void setPort( unsigned int port );
+
ENetEvent *getEvent();
// check wheter the packet queue is empty
bool queueEmpty();
// create a new listener thread
- bool createConnection();
- bool closeConnection();
+ virtual bool establishConnection();
+ virtual bool closeConnection();
// add a packet to queue for the server
bool addPacket(ENetPacket *packet);
- // send out all queued packets
- bool sendPackets();
- // send out all queued packets and save result in event
- //bool sendPackets(ENetEvent *event);
- bool waitEstablished(int milisec);
- inline bool isConnected(){return established;}
- inline bool checkConnection(){ return !quit_ && isConnected(); }
+ inline bool isConnected(){ return this->established_; }
private:
- ClientConnection(const ClientConnection& copy); // not used
- bool processData(ENetEvent *event);
- // implementation of the listener
- void receiverThread(); //thread2
- //packetbuffer
- bool establishConnection();
+ virtual void addClient(ENetEvent* event);
+ virtual void disconnectPeer(ENetEvent* event);
+
bool disconnectConnection();
- PacketBuffer buffer;
// enet stuff
- ENetHost *client;
- ENetAddress *serverAddress;
- // quit-variable (communication with threads)
- bool quit_;
- bool established;
+ ENetAddress *serverAddress_;
+ bool established_;
// clientlist
- ENetPeer *server;
- boost::thread *receiverThread_;
+ ENetPeer *server_;
};
-
-
-
-
-
-
}
#endif /* _ClientConnection_H__ */
Modified: trunk/src/network/ClientConnectionListener.cc
===================================================================
--- trunk/src/network/ClientConnectionListener.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/ClientConnectionListener.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -27,8 +27,10 @@
*/
#include "ClientConnectionListener.h"
+
#include "core/CoreIncludes.h"
#include "core/GameMode.h"
+#include "ClientInformation.h"
namespace orxonox{
Modified: trunk/src/network/ClientConnectionListener.h
===================================================================
--- trunk/src/network/ClientConnectionListener.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/ClientConnectionListener.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -1,8 +1,35 @@
-#ifndef _NETWORK_CLIENTCONNECTIONLISTENER__
-#define _NETWORK_CLIENTCONNECTIONLISTENER__
+/*
+ * 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 <scheusso [at] ee.ethz.ch>, (C) 2008
+ * Co-authors:
+ * ...
+ *
+ */
+#ifndef _ClientConnectionListener_H__
+#define _ClientConnectionListener_H__
+
#include "NetworkPrereqs.h"
-#include "ClientInformation.h"
#include "core/OrxonoxClass.h"
namespace orxonox{
@@ -25,4 +52,4 @@
}
-#endif
+#endif /* _ClientConnectionListener_H__ */
Modified: trunk/src/network/ClientInformation.cc
===================================================================
--- trunk/src/network/ClientInformation.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/ClientInformation.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -39,9 +39,7 @@
//
#include "ClientInformation.h"
-
#include <enet/enet.h>
-#include <iostream> //debug
namespace orxonox
{
Added: trunk/src/network/Connection.cc
===================================================================
--- trunk/src/network/Connection.cc (rev 0)
+++ trunk/src/network/Connection.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -0,0 +1,105 @@
+/*
+ * 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 "Connection.h"
+
+#include <cassert>
+#include <enet/enet.h>
+#include <OgreTimer.h>
+#include "packet/Packet.h"
+
+namespace orxonox
+{
+ Connection *Connection::instance_=0;
+
+ Connection::Connection():
+ host_(0)
+ {
+ assert(instance_==0);
+ Connection::instance_=this;
+ enet_initialize();
+ atexit(enet_deinitialize);
+ }
+
+ Connection::~Connection(){
+ Connection::instance_=0;
+ }
+
+ int Connection::service(ENetEvent* event) {
+ return enet_host_service( this->host_, event, NETWORK_WAIT_TIMEOUT );
+ }
+
+ void Connection::disconnectPeer(ENetPeer *peer) {
+ enet_peer_disconnect(peer, 0);
+ }
+
+ bool Connection::addPacket(ENetPacket *packet, ENetPeer *peer) {
+ if(enet_peer_send(peer, NETWORK_DEFAULT_CHANNEL, packet)!=0)
+ return false;
+ else
+ return true;
+ }
+
+ bool Connection::sendPackets() {
+ if ( !Connection::instance_ || this->host_==NULL )
+ return false;
+ enet_host_flush(this->host_);
+ return true;
+ }
+
+ void Connection::processQueue() {
+ ENetEvent event;
+
+ assert(this->host_);
+ Ogre::Timer timer;
+
+ while( timer.getMilliseconds()<NETWORK_MAX_QUEUE_PROCESS_TIME && enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
+ {
+ switch(event.type){
+ // log handling ================
+ case ENET_EVENT_TYPE_CONNECT:
+ addClient( &event );
+ break;
+ case ENET_EVENT_TYPE_DISCONNECT:
+ disconnectPeer( &event );
+ break;
+ case ENET_EVENT_TYPE_RECEIVE:
+ processPacket( &event );
+ break;
+ case ENET_EVENT_TYPE_NONE:
+ break;
+ }
+ }
+ }
+
+ bool Connection::processPacket(ENetEvent* event) {
+ packet::Packet *p = packet::Packet::createPacket(event->packet, event->peer);
+ return p->process();
+ }
+
+}
Added: trunk/src/network/Connection.h
===================================================================
--- trunk/src/network/Connection.h (rev 0)
+++ trunk/src/network/Connection.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -0,0 +1,83 @@
+/*
+ * 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:
+ * ...
+ *
+ */
+
+//
+// C++ Interface: Connection
+//
+// Description:
+//
+//
+// Author: Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef _Connection_H__
+#define _Connection_H__
+
+#include "NetworkPrereqs.h"
+
+namespace orxonox
+{
+ const unsigned int NETWORK_PORT = 55556;
+ const unsigned int NETWORK_MAX_CONNECTIONS = 50;
+ const unsigned int NETWORK_WAIT_TIMEOUT = 0;
+ const unsigned int NETWORK_DEFAULT_CHANNEL = 0;
+ const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5;
+
+ class _NetworkExport Connection{
+ public:
+ virtual ~Connection();
+
+ static bool addPacket(ENetPacket *packet, ENetPeer *peer);
+ bool sendPackets();
+ ENetHost* getHost(){ return this->host_; }
+
+ protected:
+ Connection();
+ static Connection* getInstance(){ return Connection::instance_; }
+
+ int service(ENetEvent* event);
+ void disconnectPeer(ENetPeer *peer);
+
+ void processQueue();
+ virtual void addClient(ENetEvent* event)=0;
+ virtual void disconnectPeer(ENetEvent* event)=0;
+ virtual bool processPacket(ENetEvent* event);
+
+ ENetHost *host_;
+ private:
+ ENetAddress *bindAddress_;
+
+ static Connection *instance_;
+
+ };
+
+}
+
+#endif /* _Connection_H__ */
Deleted: trunk/src/network/ConnectionManager.cc
===================================================================
--- trunk/src/network/ConnectionManager.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/ConnectionManager.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -1,315 +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, (C) 2007
- * Co-authors:
- * ...
- *
- */
-
-//
-// C++ Interface: ConnectionManager
-//
-// Description: The Class ConnectionManager manages the servers conenctions to the clients.
-// each connection is provided by a new process. communication between master process and
-// connection processes is provided by ...
-//
-//
-// Author: Oliver Scheuss
-//
-
-#include "ConnectionManager.h"
-
-#include <enet/enet.h>
-#include <iostream>
-#include <cassert>
-// boost.thread library for multithreading support
-#include <boost/thread/thread.hpp>
-#include <boost/bind.hpp>
-#include <boost/thread/recursive_mutex.hpp>
-
-#include "util/Debug.h"
-#include "util/Math.h"
-#include "util/Sleep.h"
-#include "ClientInformation.h"
-#include "synchronisable/Synchronisable.h"
-#include "packet/ClassID.h"
-
-namespace std
-{
- bool operator< (ENetAddress a, ENetAddress b) {
- return a.host <= b.host;
- }
-}
-
-namespace orxonox
-{
- //boost::thread_group network_threads;
- static boost::recursive_mutex enet_mutex_g;
-
- ConnectionManager *ConnectionManager::instance_=0;
-
- ConnectionManager::ConnectionManager():receiverThread_(0){
- assert(instance_==0);
- instance_=this;
- quit_=false;
- bindAddress = new ENetAddress();
- bindAddress->host = ENET_HOST_ANY;
- bindAddress->port = NETWORK_PORT;
- }
-
- ConnectionManager::ConnectionManager(int port){
- assert(instance_==0);
- instance_=this;
- quit_=false;
- bindAddress = new ENetAddress();
- bindAddress->host = ENET_HOST_ANY;
- bindAddress->port = port;
- }
-
- ConnectionManager::ConnectionManager(int port, const std::string& address) :receiverThread_(0) {
- assert(instance_==0);
- instance_=this;
- quit_=false;
- bindAddress = new ENetAddress();
- enet_address_set_host (bindAddress, address.c_str());
- bindAddress->port = NETWORK_PORT;
- }
-
- ConnectionManager::ConnectionManager(int port, const char *address) : receiverThread_(0) {
- assert(instance_==0);
- instance_=this;
- quit_=false;
- bindAddress = new ENetAddress();
- enet_address_set_host (bindAddress, address);
- bindAddress->port = NETWORK_PORT;
- }
-
- ConnectionManager::~ConnectionManager(){
- if(!quit_)
- quitListener();
- instance_=0;
- delete bindAddress;
- }
-
-
- ENetEvent *ConnectionManager::getEvent(){
- if(!buffer.isEmpty())
- return buffer.pop();
- else
- return NULL;
- }
-
- bool ConnectionManager::queueEmpty() {
- return buffer.isEmpty();
- }
-
- void ConnectionManager::createListener() {
- receiverThread_ = new boost::thread(boost::bind(&ConnectionManager::receiverThread, this));
- return;
- }
-
- bool ConnectionManager::quitListener() {
- quit_=true;
- receiverThread_->join();
- delete receiverThread_;
- return true;
- }
-
-
- bool ConnectionManager::addPacket(ENetPacket *packet, ENetPeer *peer) {
- boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
- if(enet_peer_send(peer, NETWORK_DEFAULT_CHANNEL, packet)!=0)
- return false;
- return true;
- }
-
- bool ConnectionManager::addPacket(ENetPacket *packet, unsigned int clientID) {
- if ( clientID == CLIENTID_UNKNOWN )
- {
- return addPacketAll(packet);
- }
- else
- {
- ClientInformation *temp = ClientInformation::findClient(clientID);
- if(!temp){
- COUT(3) << "C.Man: addPacket findClient failed" << std::endl;
- return false;
- }
- return addPacket(packet, temp->getPeer());
- }
- }
-
- bool ConnectionManager::addPacketAll(ENetPacket *packet) {
- if(!instance_)
- return false;
- boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-// for(ClientInformation *i=ClientInformation::getBegin()->next(); i!=0; i=i->next()){
-// COUT(3) << "adding broadcast packet for client: " << i->getID() << std::endl;
-// if(enet_peer_send(i->getPeer(), 0, packet)!=0)
-// return false;
-// }
- enet_host_broadcast( instance_->server, 0, packet);
- return true;
- }
-
- // we actually dont need that function, because host_service does that for us
- bool ConnectionManager::sendPackets() {
- if(server==NULL || !instance_)
- return false;
- boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
- enet_host_flush(server);
- lock.unlock();
- return true;
- }
-
- void ConnectionManager::receiverThread() {
- // what about some error-handling here ?
- ENetEvent *event;
- atexit(enet_deinitialize);
- { //scope of the mutex
- boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
- enet_initialize();
- server = enet_host_create(bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0);
- lock.unlock();
- }
- if(server==NULL){
- // add some error handling here ==========================
- quit_=true;
- return;
- }
-
- event = new ENetEvent;
- while(!quit_)
- {
- { //mutex scope
- boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
- if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){
- // we should never reach this point
- printf("ConnectionManager: ENet returned with an error\n");
-// quit_=true;
-// printf("waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhh\n");
- continue;
- // add some error handling here ========================
- }
- lock.unlock();
- }
- switch(event->type){
- // log handling ================
- case ENET_EVENT_TYPE_CONNECT:
-// printf("====================================================================");
- case ENET_EVENT_TYPE_DISCONNECT:
-// printf("====================================================================");
- case ENET_EVENT_TYPE_RECEIVE:
- processData(event);
- event = new ENetEvent;
- break;
- case ENET_EVENT_TYPE_NONE:
- //receiverThread_->yield();
- msleep(1);
- break;
- }
-// usleep(100);
- //receiverThread_->yield(); //TODO: find apropriate
- }
- disconnectClients();
- // if we're finishied, destroy server
- {
- boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
- enet_host_destroy(server);
- lock.unlock();
- }
- }
-
- //### added some bugfixes here, but we cannot test them because
- //### the server crashes everytime because of some gamestates
- //### (trying to resolve that now)
- void ConnectionManager::disconnectClients() {
- ENetEvent event;
- ClientInformation *temp = ClientInformation::getBegin()->next();
- while(temp!=0){
- {
- boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
- enet_peer_disconnect(temp->getPeer(), 0);
- lock.unlock();
- }
- temp = temp->next();
- }
- //bugfix: might be the reason why server crashes when clients disconnects
- temp = ClientInformation::getBegin()->next();
- boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
- while( temp!=0 && enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT) >= 0){
- switch (event.type)
- {
- case ENET_EVENT_TYPE_NONE: break;
- case ENET_EVENT_TYPE_CONNECT: break;
- case ENET_EVENT_TYPE_RECEIVE:
- enet_packet_destroy(event.packet);
- break;
- case ENET_EVENT_TYPE_DISCONNECT:
- COUT(4) << "disconnecting all clients" << std::endl;
- if(ClientInformation::findClient(&(event.peer->address)))
- delete ClientInformation::findClient(&(event.peer->address));
- //maybe needs bugfix: might also be a reason for the server to crash
- temp = temp->next();
- break;
- }
- }
- return;
- }
-
-
- int ConnectionManager::getClientID(ENetPeer* peer) {
- return getClientID(&(peer->address));
- }
-
- int ConnectionManager::getClientID(ENetAddress* address) {
- return ClientInformation::findClient(address)->getID();
- }
-
- ENetPeer *ConnectionManager::getClientPeer(int clientID) {
- return ClientInformation::findClient(clientID)->getPeer();
- }
-
-
- void ConnectionManager::syncClassid(unsigned int clientID) {
- int failures=0;
- packet::ClassID *classid = new packet::ClassID();
- classid->setClientID(clientID);
- while(!classid->send() && failures < 10){
- failures++;
- }
- assert(failures<10);
- COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl;
- }
-
-
- void ConnectionManager::disconnectClient(ClientInformation *client){
- {
- boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
- enet_peer_disconnect(client->getPeer(), 0);
- lock.unlock();
- }
- }
-
-
-}
Deleted: trunk/src/network/ConnectionManager.h
===================================================================
--- trunk/src/network/ConnectionManager.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/ConnectionManager.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -1,107 +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, (C) 2007
- * Co-authors:
- * ...
- *
- */
-
-//
-// C++ Interface: ConnectionManager
-//
-// Description:
-//
-//
-// Author: Oliver Scheuss, (C) 2007
-//
-// Copyright: See COPYING file that comes with this distribution
-//
-//
-#ifndef _ConnectionManager_H__
-#define _ConnectionManager_H__
-
-#include "NetworkPrereqs.h"
-
-#include <string>
-#include <map>
-
-#include "PacketBuffer.h"
-#include "packet/Packet.h"
-
-namespace boost { class thread; }
-
-namespace orxonox
-{
- const int NETWORK_PORT = 55556;
- const int NETWORK_MAX_CONNECTIONS = 50;
- const int NETWORK_WAIT_TIMEOUT = 1;
- const int NETWORK_DEFAULT_CHANNEL = 0;
-
- struct _NetworkExport ClientList{
- ENetEvent *event;
- int ID;
- ClientList *next;
- };
-
- class _NetworkExport ConnectionManager{
- public:
- ConnectionManager();
- ConnectionManager(int port);
- ConnectionManager(int port, const char *address);
- ConnectionManager(int port, const std::string& address);
- ~ConnectionManager();
- ENetEvent *getEvent();
- bool queueEmpty();
- void createListener();
- bool quitListener();
- static bool addPacket(ENetPacket *packet, ENetPeer *peer);
- static bool addPacket(ENetPacket *packet, unsigned int ID);
- static bool addPacketAll(ENetPacket *packet);
- bool sendPackets();
- void disconnectClient(ClientInformation *client);
- void syncClassid(unsigned int clientID);
- bool checkReceiverThread(){ return !quit_; }
-
- private:
- ConnectionManager(const ConnectionManager& copy); // not used
- inline bool processData(ENetEvent *event){ return buffer.push(event); }
- void receiverThread();
- void disconnectClients();
- int getClientID(ENetPeer* peer);
- int getClientID(ENetAddress* address);
- ENetPeer *getClientPeer(int clientID);
- PacketBuffer buffer;
-
- ENetHost *server;
- ENetAddress *bindAddress;
-
- bool quit_; // quit-variable (communication with threads)
-
- boost::thread *receiverThread_;
- static ConnectionManager *instance_;
-
- };
-
-}
-
-#endif /* _ConnectionManager_H__ */
Modified: trunk/src/network/FunctionCallManager.h
===================================================================
--- trunk/src/network/FunctionCallManager.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/FunctionCallManager.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -1,19 +1,44 @@
+/*
+ * 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 <scheusso [at] ee.ethz.ch>, (C) 2008
+ * Co-authors:
+ * ...
+ *
+ */
-#ifndef NETWORKFUNCTIONCALLMANAGER_H
-#define NETWORKFUNCTIONCALLMANAGER_H
+#ifndef _FunctionCallManager_H__
+#define _FunctionCallManager_H__
#include "NetworkPrereqs.h"
-#include "packet/FunctionCalls.h"
+
#include <map>
+#include "util/UtilPrereqs.h"
-
namespace orxonox {
/**
@author
*/
-class MultiType;
-
class _NetworkExport FunctionCallManager
{
public:
@@ -41,4 +66,4 @@
} //namespace orxonox
-#endif
+#endif /* _FunctionCallManager_H__ */
Modified: trunk/src/network/GamestateClient.cc
===================================================================
--- trunk/src/network/GamestateClient.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/GamestateClient.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -28,14 +28,12 @@
#include "GamestateClient.h"
-#include <cassert>
-#include <zlib.h>
-
-#include "core/CoreIncludes.h"
-#include "core/BaseObject.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
Modified: trunk/src/network/GamestateClient.h
===================================================================
--- trunk/src/network/GamestateClient.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/GamestateClient.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -40,11 +40,10 @@
#ifndef _GamestateClient_H__
#define _GamestateClient_H__
-#include <map>
-//
#include "NetworkPrereqs.h"
+
+#include <map>
#include "core/CorePrereqs.h"
-#include "packet/Gamestate.h"
#include "GamestateHandler.h"
const unsigned int GAMESTATEID_INITIAL = (unsigned int)-1;
Modified: trunk/src/network/GamestateHandler.cc
===================================================================
--- trunk/src/network/GamestateHandler.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/GamestateHandler.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -1,7 +1,33 @@
-#include <cassert>
+/*
+ * 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 <scheusso [at] ee.ethz.ch>, (C) 2008
+ * Co-authors:
+ * ...
+ *
+ */
#include "GamestateHandler.h"
-#include "packet/Packet.h"
+#include <cassert>
namespace orxonox {
Modified: trunk/src/network/GamestateHandler.h
===================================================================
--- trunk/src/network/GamestateHandler.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/GamestateHandler.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -25,13 +25,11 @@
* ...
*
*/
-#ifndef NETWORKGAMESTATEHANDLER_H
-#define NETWORKGAMESTATEHANDLER_H
-#include <string>
+#ifndef _GamestateHandler_H__
+#define _GamestateHandler_H__
#include "NetworkPrereqs.h"
-#include "packet/Chat.h"
namespace orxonox {
@@ -57,4 +55,4 @@
}
-#endif
+#endif /* _GamestateHandler_H__ */
Modified: trunk/src/network/GamestateManager.cc
===================================================================
--- trunk/src/network/GamestateManager.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/GamestateManager.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -40,17 +40,14 @@
#include "GamestateManager.h"
-#include <utility>
-#include <iostream>
-#include <zlib.h>
#include <cassert>
-#include "core/CoreIncludes.h"
-#include "core/BaseObject.h"
+#include "util/Debug.h"
#include "ClientInformation.h"
-#include "synchronisable/Synchronisable.h"
-#include "synchronisable/NetworkCallbackManager.h"
#include "packet/Acknowledgement.h"
+#include "packet/Gamestate.h"
+#include "synchronisable/NetworkCallbackManager.h"
+#include "TrafficControl.h"
namespace orxonox
{
Modified: trunk/src/network/GamestateManager.h
===================================================================
--- trunk/src/network/GamestateManager.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/GamestateManager.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -41,16 +41,14 @@
#define _GamestateManager_H__
#include "NetworkPrereqs.h"
-#include "GamestateHandler.h"
-#include "TrafficControl.h"
+
#include <map>
+#include "GamestateHandler.h"
-#include "packet/Gamestate.h"
-
namespace orxonox
{
- const int KEEP_GAMESTATES = 10;
+ const int KEEP_GAMESTATES = 10;
/**
* This Class implements a manager for gamestates:
Modified: trunk/src/network/Host.cc
===================================================================
--- trunk/src/network/Host.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/Host.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -26,11 +26,13 @@
*
*/
+#include "Host.h"
+
#include <cassert>
+#include <string>
-#include "Host.h"
#include "core/ConsoleCommand.h"
-#include "packet/Packet.h"
+#include "core/ObjectList.h"
#include "ChatListener.h"
namespace orxonox {
Modified: trunk/src/network/Host.h
===================================================================
--- trunk/src/network/Host.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/Host.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -25,13 +25,11 @@
* ...
*
*/
-#ifndef NETWORKHOST_H
-#define NETWORKHOST_H
-#include <string>
+#ifndef _NETWORK_Host_H__
+#define _NETWORK_Host_H__
#include "NetworkPrereqs.h"
-#include "packet/Chat.h"
namespace orxonox {
@@ -85,4 +83,4 @@
}
-#endif
+#endif /* _NETWORK_Host_H__ */
Modified: trunk/src/network/NetworkFunction.cc
===================================================================
--- trunk/src/network/NetworkFunction.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/NetworkFunction.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -27,8 +27,7 @@
*/
#include "NetworkFunction.h"
-#include <string>
-#include "synchronisable/Synchronisable.h"
+#include "core/CoreIncludes.h"
namespace orxonox
{
@@ -41,7 +40,7 @@
std::map<NetworkFunctionPointer, NetworkMemberFunctionBase*> NetworkMemberFunctionBase::functorMap_;
std::map<uint32_t, NetworkMemberFunctionBase*> NetworkMemberFunctionBase::idMap_;
- NetworkFunctionBase::NetworkFunctionBase(std::string name)
+ NetworkFunctionBase::NetworkFunctionBase(const std::string& name)
{
RegisterRootObject(NetworkFunctionBase);
@@ -57,7 +56,7 @@
- NetworkFunctionStatic::NetworkFunctionStatic(FunctorStatic* functor, std::string name, const NetworkFunctionPointer& p):
+ NetworkFunctionStatic::NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p):
NetworkFunctionBase(name)
{
RegisterObject(NetworkFunctionStatic);
@@ -74,7 +73,7 @@
- NetworkMemberFunctionBase::NetworkMemberFunctionBase(std::string name, const NetworkFunctionPointer& p):
+ NetworkMemberFunctionBase::NetworkMemberFunctionBase(const std::string& name, const NetworkFunctionPointer& p):
NetworkFunctionBase(name)
{
RegisterObject(NetworkMemberFunctionBase);
Modified: trunk/src/network/NetworkFunction.h
===================================================================
--- trunk/src/network/NetworkFunction.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/NetworkFunction.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -26,23 +26,22 @@
*
*/
-#ifndef NETWORKFUNCTION_H
-#define NETWORKFUNCTION_H
+#ifndef _NetworkFunction_H__
+#define _NetworkFunction_H__
#include "NetworkPrereqs.h"
-#include "core/OrxonoxClass.h"
+#include <cassert>
+#include <cstring>
+#include <map>
#include <string>
-#include <map>
-#include <cassert>
#include <boost/preprocessor/cat.hpp>
-#include "util/MultiType.h"
+
+#include "core/OrxonoxClass.h"
#include "core/Functor.h"
+#include "FunctionCallManager.h"
#include "synchronisable/Synchronisable.h"
-#include "OrxonoxConfig.h"
-#include "FunctionCallManager.h"
-
namespace orxonox
{
@@ -71,15 +70,15 @@
class _NetworkExport NetworkFunctionBase: virtual public OrxonoxClass {
public:
- NetworkFunctionBase(std::string name);
+ NetworkFunctionBase(const std::string& name);
~NetworkFunctionBase();
- inline void setNetworkID(uint32_t id) { this->networkID_ = id; }
+ virtual void setNetworkID(uint32_t id) { this->networkID_ = id; }
inline uint32_t getNetworkID() const { return this->networkID_; }
- inline std::string getName() const { return name_; }
+ inline const std::string& getName() const { return name_; }
static inline bool isStatic( uint32_t networkID ) { return isStaticMap_[networkID]; }
- static inline void setNetworkID(std::string name, uint32_t id){ assert( nameMap_.find(name)!=nameMap_.end() ); nameMap_[name]->setNetworkID(id); }
+ static inline void setNetworkID(const std::string& name, uint32_t id){ assert( nameMap_.find(name)!=nameMap_.end() ); nameMap_[name]->setNetworkID(id); }
protected:
static std::map<uint32_t, bool> isStaticMap_;
@@ -94,7 +93,7 @@
class _NetworkExport NetworkFunctionStatic: public NetworkFunctionBase {
public:
- NetworkFunctionStatic(FunctorStatic* functor, std::string name, const NetworkFunctionPointer& p);
+ NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p);
~NetworkFunctionStatic();
inline void call(){ (*this->functor_)(); }
@@ -104,6 +103,7 @@
inline void call(const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4){ (*this->functor_)(mt1, mt2, mt3, mt4); }
inline void call(const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5){ (*this->functor_)(mt1, mt2, mt3, mt4, mt5); }
+ virtual void setNetworkID( uint32_t id ){ NetworkFunctionBase::setNetworkID( id ); idMap_[id] = this; }
static inline NetworkFunctionStatic* getNetworkFunction( uint32_t id){ assert( idMap_.find(id)!=idMap_.end() ); return idMap_[id]; }
static NetworkFunctionStatic* getFunction( uint32_t id ){ assert( idMap_.find(id) != idMap_.end() ); return idMap_[id]; }
static NetworkFunctionStatic* getFunction( const NetworkFunctionPointer& p ){ assert( functorMap_.find(p) != functorMap_.end() ); return functorMap_[p]; }
@@ -119,9 +119,10 @@
class _NetworkExport NetworkMemberFunctionBase: public NetworkFunctionBase {
public:
- NetworkMemberFunctionBase(std::string name, const NetworkFunctionPointer& p);
+ NetworkMemberFunctionBase(const std::string& name, const NetworkFunctionPointer& p);
~NetworkMemberFunctionBase();
+ virtual void setNetworkID( uint32_t id ){ NetworkFunctionBase::setNetworkID( id ); idMap_[id] = this; }
static inline NetworkMemberFunctionBase* getNetworkFunction( uint32_t id){ assert( idMap_.find(id)!=idMap_.end() ); return idMap_[id]; }
static NetworkMemberFunctionBase* getFunction( uint32_t id ){ assert( idMap_.find(id) != idMap_.end() ); return idMap_[id]; }
static NetworkMemberFunctionBase* getFunction( const NetworkFunctionPointer& p ){ assert( functorMap_.find(p) != functorMap_.end() ); return functorMap_[p]; }
@@ -142,7 +143,7 @@
template <class T> class NetworkMemberFunction: public NetworkMemberFunctionBase {
public:
- NetworkMemberFunction(FunctorMember<T>* functor, std::string name, const NetworkFunctionPointer& p);
+ NetworkMemberFunction(FunctorMember<T>* functor, const std::string& name, const NetworkFunctionPointer& p);
~NetworkMemberFunction();
inline void call(uint32_t objectID)
@@ -180,7 +181,7 @@
FunctorMember<T>* functor_;
};
-template <class T> NetworkMemberFunction<T>::NetworkMemberFunction(FunctorMember<T>* functor, std::string name, const NetworkFunctionPointer& p):
+template <class T> NetworkMemberFunction<T>::NetworkMemberFunction(FunctorMember<T>* functor, const std::string& name, const NetworkFunctionPointer& p):
NetworkMemberFunctionBase(name, p), functor_(functor)
{
}
@@ -198,7 +199,7 @@
// *((uint32_t*)destptr+i) = p2>>32*i;
}
-template<class T> inline void* registerStaticNetworkFunctionFct( T ptr, std::string name )
+template<class T> inline void* registerStaticNetworkFunctionFct( T ptr, const std::string& name )
{
NetworkFunctionPointer destptr;
copyPtr( ptr, destptr );
@@ -206,7 +207,7 @@
return 0;
}
-template<class T, class PT> inline void* registerMemberNetworkFunctionFct( PT ptr, std::string name )
+template<class T, class PT> inline void* registerMemberNetworkFunctionFct( PT ptr, const std::string& name )
{
NetworkFunctionPointer destptr;
copyPtr( ptr, destptr );
@@ -236,4 +237,4 @@
}
-#endif
+#endif /* _NetworkFunction_H__ */
Modified: trunk/src/network/NetworkPrecompiledHeaders.h
===================================================================
--- trunk/src/network/NetworkPrecompiledHeaders.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/NetworkPrecompiledHeaders.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -34,10 +34,12 @@
#include "NetworkPrereqs.h"
+#include <cassert>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
+#include <queue>
#include <set>
#include <sstream>
#include <string>
@@ -46,24 +48,19 @@
#ifdef ORXONOX_COMPILER_MSVC
+#include <OgreMath.h>
+#include <OgreVector2.h>
+#include <OgreVector3.h>
+#include <OgreVector4.h>
+#include <OgreQuaternion.h>
+#include <OgreColourValue.h>
+
#define WIN32_LEAN_AND_MEAN
#include <enet/enet.h>
#undef max
#undef min
-// Too larg PCH file if you include this and only 10% faster
-//#include <boost/thread/recursive_mutex.hpp>
-
-#include "util/CRC32.h"
#include "util/Debug.h"
-#include "util/Math.h"
-#include "util/mbool.h"
-#include "util/MultiType.h"
-#include "util/String.h"
+#include "core/Identifier.h"
-#include "core/Core.h"
-#include "core/CoreIncludes.h"
-#include "core/Functor.h"
-#include "core/GameMode.h"
-
#endif /* ORXONOX_COMPILER_MSVC */
Modified: trunk/src/network/NetworkPrereqs.h
===================================================================
--- trunk/src/network/NetworkPrereqs.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/NetworkPrereqs.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -88,7 +88,7 @@
class ClientConnectionListener;
class ClientFrameListener;
class ClientInformation;
- class ConnectionManager;
+ class Connection;
class FunctionCallManager;
class GamestateClient;
class GamestateManager;
@@ -103,6 +103,7 @@
struct NetworkFunctionPointer;
class PacketBuffer;
class Server;
+ class ServerConnection;
class ServerFrameListener;
class Synchronisable;
class SynchronisableVariableBase;
@@ -112,6 +113,7 @@
struct PacketEnvelope;
struct QueueItem;
struct syncData;
+ class TrafficControl;
class obj;
class objInfo;
@@ -126,6 +128,16 @@
class NetworkIDs;
class Packet;
class Welcome;
+
+ namespace PacketFlag
+ {
+ enum Enum
+ {
+ Reliable = 1,
+ Unsequence = 2,
+ NoAllocate = 4
+ };
+ }
}
}
Modified: trunk/src/network/PacketBuffer.cc
===================================================================
--- trunk/src/network/PacketBuffer.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/PacketBuffer.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -32,12 +32,7 @@
#include "PacketBuffer.h"
-#include <enet/enet.h>
-#include <iostream>
-#include <queue>
-#include <string>
-#include <boost/bind.hpp>
-#include <boost/thread/mutex.hpp>
+//#include <iostream>
#include <boost/thread/recursive_mutex.hpp>
namespace orxonox
Modified: trunk/src/network/Server.cc
===================================================================
--- trunk/src/network/Server.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/Server.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -41,28 +41,23 @@
#include "Server.h"
#include <enet/enet.h>
-#include <iostream>
#include <cassert>
+#include <string>
-
-#include "ConnectionManager.h"
-#include "ClientConnectionListener.h"
-#include "GamestateManager.h"
-#include "ClientInformation.h"
-#include "util/Sleep.h"
+#include "util/Debug.h"
#include "core/Clock.h"
-#include "core/ConsoleCommand.h"
-#include "core/CoreIncludes.h"
+#include "core/ObjectList.h"
#include "packet/Chat.h"
-#include "packet/Packet.h"
-#include "packet/Welcome.h"
+#include "packet/ClassID.h"
#include "packet/DeleteObjects.h"
-#include "util/Convert.h"
+#include "packet/FunctionIDs.h"
+#include "packet/Gamestate.h"
+#include "packet/Welcome.h"
#include "ChatListener.h"
+#include "ClientInformation.h"
#include "FunctionCallManager.h"
-#include "packet/FunctionIDs.h"
+#include "GamestateManager.h"
-
namespace orxonox
{
const unsigned int MAX_FAILURES = 20;
@@ -73,13 +68,12 @@
*/
Server::Server() {
timeSinceLastUpdate_=0;
- connection = new ConnectionManager();
gamestates_ = new GamestateManager();
}
Server::Server(int port){
+ this->setPort( port );
timeSinceLastUpdate_=0;
- connection = new ConnectionManager(port);
gamestates_ = new GamestateManager();
}
@@ -89,28 +83,16 @@
* @param bindAddress Address to listen on
*/
Server::Server(int port, const std::string& bindAddress) {
+ this->setPort( port );
+ this->setBindAddress( bindAddress );
timeSinceLastUpdate_=0;
- connection = new ConnectionManager(port, bindAddress);
gamestates_ = new GamestateManager();
}
/**
- * Constructor
- * @param port Port to listen on
- * @param bindAddress Address to listen on
- */
- Server::Server(int port, const char *bindAddress) {
- timeSinceLastUpdate_=0;
- connection = new ConnectionManager(port, bindAddress);
- gamestates_ = new GamestateManager();
- }
-
- /**
* @brief Destructor
*/
Server::~Server(){
- if(connection)
- delete connection;
if(gamestates_)
delete gamestates_;
}
@@ -119,7 +101,8 @@
* This function opens the server by creating the listener thread
*/
void Server::open() {
- connection->createListener();
+ COUT(4) << "opening server" << endl;
+ this->openListener();
return;
}
@@ -127,16 +110,9 @@
* This function closes the server
*/
void Server::close() {
- ClientInformation *temp = ClientInformation::getBegin();
- ClientInformation *temp2;
- // disconnect all connected clients
- while( temp )
- {
- temp2 = temp;
- temp = temp->next();
- disconnectClient( temp2 );
- }
- connection->quitListener();
+ COUT(4) << "closing server" << endl;
+ this->disconnectClients();
+ this->closeListener();
return;
}
@@ -161,19 +137,21 @@
* @param time time since last tick
*/
void Server::update(const Clock& time) {
- processQueue();
+ Connection::processQueue();
gamestates_->processGamestates();
//this steers our network frequency
timeSinceLastUpdate_+=time.getDeltaTime();
- if(timeSinceLastUpdate_>=NETWORK_PERIOD){
+ if(timeSinceLastUpdate_>=NETWORK_PERIOD)
+ {
timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
updateGamestate();
FunctionCallManager::sendCalls();
}
+ sendPackets(); // flush the enet queue
}
bool Server::queuePacket(ENetPacket *packet, int clientID){
- return connection->addPacket(packet, clientID);
+ return ServerConnection::addPacket(packet, clientID);
}
/**
@@ -191,39 +169,6 @@
assert(ClientInformation::findClient(clientID));
return ClientInformation::findClient(clientID)->getPacketLoss();
}
-
- /**
- * processes all the packets waiting in the queue
- */
- void Server::processQueue() {
- ENetEvent *event;
- while(!connection->queueEmpty()){
- //std::cout << "Client " << clientID << " sent: " << std::endl;
- //clientID here is a reference to grab clientID from ClientInformation
- event = connection->getEvent();
- if(!event)
- continue;
- assert(event->type != ENET_EVENT_TYPE_NONE);
- switch( event->type ) {
- case ENET_EVENT_TYPE_CONNECT:
- COUT(4) << "processing event_Type_connect" << std::endl;
- addClient(event);
- break;
- case ENET_EVENT_TYPE_DISCONNECT:
- if(ClientInformation::findClient(&event->peer->address))
- disconnectClient(event);
- break;
- case ENET_EVENT_TYPE_RECEIVE:
- if(!processPacket(event->packet, event->peer))
- COUT(3) << "processing incoming packet failed" << std::endl;
- break;
- default:
- break;
- }
- delete event;
- //if statement to catch case that packetbuffer is empty
- }
- }
/**
* takes a new snapshot of the gamestate and sends it to the clients
@@ -317,20 +262,14 @@
}
- bool Server::addClient(ENetEvent *event){
+ void Server::addClient(ENetEvent *event){
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;
- return false;
}
- /*if(temp==ClientInformation::getBegin()) { //not good if you use anything else than insertBack
- newid=1;
- }
- else
- newid=temp->prev()->getID()+1;*/
temp->setID(newid);
temp->setPeer(event->peer);
@@ -341,10 +280,10 @@
listener++;
}
- newid++;
+ ++newid;
COUT(3) << "Server: added client id: " << temp->getID() << std::endl;
- return createClient(temp->getID());
+ createClient(temp->getID());
}
bool Server::createClient(int clientID){
@@ -356,7 +295,7 @@
COUT(5) << "Con.Man: creating client id: " << temp->getID() << std::endl;
// synchronise class ids
- connection->syncClassid(temp->getID());
+ syncClassid(temp->getID());
// now synchronise functionIDs
packet::FunctionIDs *fIDs = new packet::FunctionIDs();
@@ -381,28 +320,9 @@
assert(b);
return true;
}
-
- bool Server::disconnectClient(ENetEvent *event){
- COUT(4) << "removing client from list" << std::endl;
- //return removeClient(head_->findClient(&(peer->address))->getID());
-
- //boost::recursive_mutex::scoped_lock lock(head_->mutex_);
- ClientInformation *client = ClientInformation::findClient(&event->peer->address);
- if(!client)
- return false;
- else
- disconnectClient( client );
- return true;
- }
-
- void Server::disconnectClient(int clientID){
- ClientInformation *client = ClientInformation::findClient(clientID);
- if(client)
- disconnectClient(client);
- }
- void Server::disconnectClient( ClientInformation *client){
- connection->disconnectClient(client);
+ void Server::disconnectClient( ClientInformation *client ){
+ ServerConnection::disconnectClient( client );
gamestates_->removeClient(client);
// inform all the listeners
ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
@@ -438,4 +358,15 @@
return true;
}
+ void Server::syncClassid(unsigned int clientID) {
+ int failures=0;
+ packet::ClassID *classid = new packet::ClassID();
+ classid->setClientID(clientID);
+ while(!classid->send() && failures < 10){
+ failures++;
+ }
+ assert(failures<10);
+ COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl;
+ }
+
}
Modified: trunk/src/network/Server.h
===================================================================
--- trunk/src/network/Server.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/Server.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -31,10 +31,9 @@
#include "NetworkPrereqs.h"
-#include <string>
-
+#include "core/CorePrereqs.h"
#include "Host.h"
-#include "GamestateManager.h"
+#include "ServerConnection.h"
namespace orxonox
{
@@ -43,12 +42,11 @@
* This class is the root class of the network module for a server.
* It implements all functions necessary for a Server
*/
- class _NetworkExport Server : public Host{
+ class _NetworkExport Server : public Host, public ServerConnection{
public:
Server();
Server(int port);
Server(int port, const std::string& bindAddress);
- Server(int port, const char *bindAddress);
~Server();
void open();
@@ -59,17 +57,14 @@
unsigned int getPing(unsigned int clientID);
double getPacketLoss(unsigned int clientID);
protected:
- void processQueue();
void updateGamestate();
private:
virtual bool isServer_(){return true;}
unsigned int shipID(){return 0;}
unsigned int playerID(){return 0;}
- bool addClient(ENetEvent *event);
+ void addClient(ENetEvent *event);
bool createClient(int clientID);
- bool disconnectClient(ENetEvent *event);
- void disconnectClient(int clientID);
void disconnectClient( ClientInformation *client);
bool processPacket( ENetPacket *packet, ENetPeer *peer );
bool sendGameState();
@@ -77,9 +72,8 @@
virtual bool chat(const std::string& message);
virtual bool broadcast(const std::string& message);
bool sendChat(const std::string& message, unsigned int clientID);
+ void syncClassid(unsigned int clientID);
- //void processChat( chat *data, int clientId);
- ConnectionManager *connection;
GamestateManager *gamestates_;
Added: trunk/src/network/ServerConnection.cc
===================================================================
--- trunk/src/network/ServerConnection.cc (rev 0)
+++ trunk/src/network/ServerConnection.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -0,0 +1,166 @@
+/*
+ * 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 "ServerConnection.h"
+
+#include <cassert>
+#include <string>
+#include <enet/enet.h>
+
+#include "util/Debug.h"
+#include "ClientInformation.h"
+
+namespace orxonox
+{
+
+ ServerConnection::ServerConnection():
+ bListening_(false)
+ {
+ this->bindAddress_ = new ENetAddress();
+ this->bindAddress_->host = ENET_HOST_ANY;
+ this->bindAddress_->port = NETWORK_PORT;
+ }
+
+ ServerConnection::~ServerConnection(){
+ if ( this->bListening_ )
+ closeListener();
+ delete this->bindAddress_;
+ }
+
+ void ServerConnection::setBindAddress( const std::string& bindAddress ) {
+ enet_address_set_host (this->bindAddress_, bindAddress.c_str());
+ }
+
+ void ServerConnection::setPort( unsigned int port ) {
+ this->bindAddress_->port = port;
+ }
+
+ bool ServerConnection::openListener() {
+ this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, 0, 0);
+ if ( this->host_ == NULL )
+ return false;
+ else
+ return true;
+ }
+
+ bool ServerConnection::closeListener() {
+ this->bListening_=false;
+ disconnectClients();
+ enet_host_destroy(this->host_);
+ return true;
+ }
+
+ bool ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID) {
+ if ( clientID == CLIENTID_UNKNOWN )
+ {
+ return addPacketAll(packet);
+ }
+ else
+ {
+ ClientInformation *temp = ClientInformation::findClient(clientID);
+ if(!temp){
+ COUT(3) << "C.Man: addPacket findClient failed" << std::endl;
+ return false;
+ }
+ return Connection::addPacket(packet, temp->getPeer());
+ }
+ }
+
+ bool ServerConnection::addPacketAll(ENetPacket *packet) {
+ if ( !Connection::getInstance() )
+ return false;
+ enet_host_broadcast( Connection::getInstance()->getHost(), 0, packet);
+ return true;
+ }
+
+ void ServerConnection::disconnectClient(ClientInformation *client)
+ {
+ Connection::disconnectPeer( client->getPeer() );
+ delete client;
+ }
+
+ void ServerConnection::disconnectPeer( ENetEvent* event )
+ {
+ COUT(4) << "removing client from list" << std::endl;
+ ClientInformation *client = ClientInformation::findClient(&event->peer->address);
+ if(!client)
+ return;
+ else
+ ServerConnection::disconnectClient( client );
+ }
+
+ void ServerConnection::disconnectClient(int clientID){
+ ClientInformation *client = ClientInformation::findClient(clientID);
+ if(client)
+ disconnectClient(client);
+ }
+
+ void ServerConnection::disconnectClients() {
+ ENetEvent event;
+ ClientInformation *temp = ClientInformation::getBegin();
+ while(temp!=0){
+ disconnectPeer( &event );
+ temp = temp->next();
+ }
+ temp = ClientInformation::getBegin();
+ while( temp!=0 ){
+ if( service( &event ) )
+ {
+ switch (event.type)
+ {
+ case ENET_EVENT_TYPE_NONE: break;
+ case ENET_EVENT_TYPE_CONNECT: break;
+ case ENET_EVENT_TYPE_RECEIVE:
+ enet_packet_destroy(event.packet);
+ break;
+ case ENET_EVENT_TYPE_DISCONNECT:
+ if(ClientInformation::findClient(&(event.peer->address)))
+ delete ClientInformation::findClient(&(event.peer->address));
+ temp = ClientInformation::getBegin();
+ break;
+ }
+ }
+ }
+ return;
+ }
+
+
+ int ServerConnection::getClientID(ENetPeer* peer) {
+ return getClientID(&(peer->address));
+ }
+
+ int ServerConnection::getClientID(ENetAddress* address) {
+ return ClientInformation::findClient(address)->getID();
+ }
+
+ ENetPeer *ServerConnection::getClientPeer(int clientID) {
+ return ClientInformation::findClient(clientID)->getPeer();
+ }
+
+
+}
Added: trunk/src/network/ServerConnection.h
===================================================================
--- trunk/src/network/ServerConnection.h (rev 0)
+++ trunk/src/network/ServerConnection.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -0,0 +1,80 @@
+/*
+ * 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:
+ * ...
+ *
+ */
+
+//
+// C++ Interface: ServerConnection
+//
+// Description:
+//
+//
+// Author: Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef _ServerConnection_H__
+#define _ServerConnection_H__
+
+#include "NetworkPrereqs.h"
+#include "Connection.h"
+
+namespace orxonox
+{
+
+ class _NetworkExport ServerConnection : public Connection{
+ public:
+ ~ServerConnection();
+
+ void setBindAddress( const std::string& bindAddress );
+ void setPort( unsigned int port );
+
+ bool openListener();
+ bool closeListener();
+ static bool addPacket(ENetPacket *packet, unsigned int ID);
+ static bool addPacketAll(ENetPacket *packet);
+ virtual void disconnectClient(ClientInformation *client);
+ void disconnectPeer( ENetEvent* event );
+ void disconnectClient(int clientID);
+ protected:
+ ServerConnection();
+ void disconnectClients();
+
+ private:
+ int getClientID(ENetPeer* peer);
+ int getClientID(ENetAddress* address);
+ ENetPeer* getClientPeer(int clientID);
+
+ ENetAddress* bindAddress_;
+
+ bool bListening_;
+
+ };
+
+}
+
+#endif /* _ServerConnection_H__ */
Modified: trunk/src/network/TrafficControl.cc
===================================================================
--- trunk/src/network/TrafficControl.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/TrafficControl.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -28,13 +28,13 @@
#include "TrafficControl.h"
-#include "synchronisable/Synchronisable.h"
+#include <cassert>
+#include <boost/bind.hpp>
+
#include "core/CoreIncludes.h"
#include "core/ConfigValueIncludes.h"
+#include "synchronisable/Synchronisable.h"
-#include <cassert>
-#include <boost/bind.hpp>
-
namespace orxonox {
static const unsigned int SCHED_PRIORITY_OFFSET = (unsigned int)-1;
Modified: trunk/src/network/TrafficControl.h
===================================================================
--- trunk/src/network/TrafficControl.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/TrafficControl.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -24,18 +24,15 @@
* Co-authors:
* ...
*
+
*/
-#ifndef NETWORK_TRAFFICCONTROL_H
-#define NETWORK_TRAFFICCONTROL_H
+#ifndef _TrafficControl_H__
+#define _TrafficControl_H__
#include "NetworkPrereqs.h"
-#include <string>
#include <list>
#include <map>
-#include <utility>
-#include <algorithm>
-#include "core/OrxonoxClass.h"
#include "network/ClientConnectionListener.h"
namespace orxonox {
@@ -142,5 +139,4 @@
}
-#endif
-
+#endif /* _TrafficControl_H__ */
Modified: trunk/src/network/packet/Acknowledgement.cc
===================================================================
--- trunk/src/network/packet/Acknowledgement.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/packet/Acknowledgement.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -26,11 +26,10 @@
*
*/
-
#include "Acknowledgement.h"
-#include "network/Host.h"
+
+#include "util/Debug.h"
#include "network/GamestateHandler.h"
-#include "core/CoreIncludes.h"
namespace orxonox {
namespace packet {
Modified: trunk/src/network/packet/Acknowledgement.h
===================================================================
--- trunk/src/network/packet/Acknowledgement.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/packet/Acknowledgement.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -25,15 +25,15 @@
* ...
*
*/
-#ifndef NETWORKACKNOLEDGEMENT_H
-#define NETWORKACKNOLEDGEMENT_H
-#include "../NetworkPrereqs.h"
+#ifndef _Acknowledgement_H__
+#define _Acknowledgement_H__
+
+#include "network/NetworkPrereqs.h"
#include "Packet.h"
+namespace orxonox {
const unsigned int ACKID_NACK = 0;
-
-namespace orxonox {
namespace packet {
/**
@author
@@ -55,4 +55,4 @@
} //namespace packet
} //namespace orxonox
-#endif
+#endif /* _Acknowledgement_H__ */
Modified: trunk/src/network/packet/Chat.cc
===================================================================
--- trunk/src/network/packet/Chat.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/packet/Chat.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -28,20 +28,20 @@
#include "Chat.h"
-#include <enet/enet.h>
-#include <cassert>
+#include <cstring>
+#include <string>
#include "network/Host.h"
namespace orxonox {
namespace packet {
-#define PACKET_FLAGS_CHAT ENET_PACKET_FLAG_RELIABLE
+#define PACKET_FLAGS_CHAT PacketFlag::Reliable
#define _PACKETID 0
const int _PLAYERID = _PACKETID + sizeof(ENUM::Type);
#define _MESSAGELENGTH _PLAYERID + sizeof(uint32_t)
#define _MESSAGE _MESSAGELENGTH + sizeof(uint32_t)
-Chat::Chat( std::string message, unsigned int playerID )
+Chat::Chat( const std::string& message, unsigned int playerID )
: Packet()
{
flags_ = flags_ | PACKET_FLAGS_CHAT;
Modified: trunk/src/network/packet/Chat.h
===================================================================
--- trunk/src/network/packet/Chat.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/packet/Chat.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -1,12 +1,35 @@
+/*
+ * 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 <scheusso [at] ee.ethz.ch>
+ * Co-authors:
+ * ...
+ *
+ */
-#ifndef NETWORKCHAT_H
-#define NETWORKCHAT_H
+#ifndef _NETWORK_Chat_H__
+#define _NETWORK_Chat_H__
-#include "../NetworkPrereqs.h"
-
-#include <string>
-#include <cstring>
-
+#include "network/NetworkPrereqs.h"
#include "Packet.h"
namespace orxonox {
@@ -17,7 +40,7 @@
class _NetworkExport Chat : public Packet
{
public:
- Chat( std::string message, unsigned int playerID );
+ Chat( const std::string& message, unsigned int playerID );
Chat( uint8_t* data, unsigned int clientID );
~Chat();
@@ -34,4 +57,4 @@
} //namespace packet
} //namespace orxonox
-#endif
+#endif /* _NETWORK_Chat_H__ */
Modified: trunk/src/network/packet/ClassID.cc
===================================================================
--- trunk/src/network/packet/ClassID.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/packet/ClassID.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -26,23 +26,22 @@
*
*/
-
-
#include "ClassID.h"
-#include <enet/enet.h>
-#include "core/CoreIncludes.h"
-#include "core/Factory.h"
-#include <cstring>
-#include <string>
+
#include <cassert>
+#include <cstdlib>
+#include <cstring>
#include <map>
#include <queue>
+#include <string>
+#include "core/CoreIncludes.h"
+
namespace orxonox {
namespace packet {
-#define PACKET_FLAGS_CLASSID ENET_PACKET_FLAG_RELIABLE
+#define PACKET_FLAGS_CLASSID PacketFlag::Reliable
#define _PACKETID 0
Modified: trunk/src/network/packet/ClassID.h
===================================================================
--- trunk/src/network/packet/ClassID.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/packet/ClassID.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -25,13 +25,11 @@
* ...
*
*/
-#ifndef NETWORKCLASSID_H
-#define NETWORKCLASSID_H
-#include "../NetworkPrereqs.h"
+#ifndef _NETWORK_ClassID_H__
+#define _NETWORK_ClassID_H__
-#include <string>
-
+#include "network/NetworkPrereqs.h"
#include "Packet.h"
namespace orxonox {
@@ -57,4 +55,4 @@
} //namespace packet
} //namespace orxonox
-#endif
+#endif /* _NETWORK_ClassID_H__ */
Modified: trunk/src/network/packet/DeleteObjects.cc
===================================================================
--- trunk/src/network/packet/DeleteObjects.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/packet/DeleteObjects.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -28,15 +28,15 @@
#include "DeleteObjects.h"
-#include <enet/enet.h>
+
+#include <cassert>
+#include "util/Debug.h"
#include "network/synchronisable/Synchronisable.h"
-#include "core/CoreIncludes.h"
-#include <cassert>
namespace orxonox {
namespace packet {
-#define PACKET_FLAG_DELETE ENET_PACKET_FLAG_RELIABLE
+#define PACKET_FLAG_DELETE PacketFlag::Reliable
#define _PACKETID 0
#define _QUANTITY _PACKETID + sizeof(ENUM::Type)
#define _OBJECTIDS _QUANTITY + sizeof(uint32_t)
@@ -89,6 +89,7 @@
COUT(4) << "deleting object with id: " << *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) << std::endl;
Synchronisable::deleteObject( *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) );
}
+ delete this;
return true;
}
Modified: trunk/src/network/packet/DeleteObjects.h
===================================================================
--- trunk/src/network/packet/DeleteObjects.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/packet/DeleteObjects.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -25,14 +25,12 @@
* ...
*
*/
-#ifndef NETWORKPACKETDELETEOBJECTS_H
-#define NETWORKPACKETDELETEOBJECTS_H
+#ifndef _DeleteObjects_H__
+#define _DeleteObjects_H__
-#include "../NetworkPrereqs.h"
-
+#include "network/NetworkPrereqs.h"
#include "Packet.h"
-
namespace orxonox {
namespace packet {
/**
@@ -56,4 +54,4 @@
} //namespace packet
} //namespace orxonox
-#endif
+#endif /* _DeleteObjects_H__ */
Modified: trunk/src/network/packet/FunctionCalls.cc
===================================================================
--- trunk/src/network/packet/FunctionCalls.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/packet/FunctionCalls.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -28,17 +28,15 @@
#include "FunctionCalls.h"
-#include <enet/enet.h>
#include <cassert>
#include <cstring>
-#include "network/Host.h"
-#include "network/NetworkFunction.h"
#include "util/MultiType.h"
+#include "network/NetworkFunction.h"
namespace orxonox {
namespace packet {
-#define PACKET_FLAGS_FUNCTIONCALLS ENET_PACKET_FLAG_RELIABLE
+#define PACKET_FLAGS_FUNCTIONCALLS PacketFlag::Reliable
#define _PACKETID 0
const unsigned int FUNCTIONCALLS_MEM_ALLOCATION = 1000;
Modified: trunk/src/network/packet/FunctionCalls.h
===================================================================
--- trunk/src/network/packet/FunctionCalls.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/packet/FunctionCalls.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -1,19 +1,42 @@
+/*
+ * 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 <scheusso [at] ee.ethz.ch>
+ * Co-authors:
+ * ...
+ *
+ */
-#ifndef NETWORKFUNCTIONCALLS_H
-#define NETWORKFUNCTIONCALLS_H
+#ifndef _FunctionCalls_H__
+#define _FunctionCalls_H__
-#include "../NetworkPrereqs.h"
+#include "network/NetworkPrereqs.h"
-#include <string>
-#include <cstring>
-
+#include <cassert>
+#include "util/UtilPrereqs.h"
#include "Packet.h"
-#include <cassert>
namespace orxonox {
-class MultiType;
-
namespace packet {
/**
@author
@@ -43,4 +66,4 @@
} //namespace packet
} //namespace orxonox
-#endif
+#endif /* _FunctionCalls_H__ */
Modified: trunk/src/network/packet/FunctionIDs.cc
===================================================================
--- trunk/src/network/packet/FunctionIDs.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/packet/FunctionIDs.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -26,21 +26,22 @@
*
*/
+#include "FunctionIDs.h"
-
-#include "FunctionIDs.h"
-#include "network/NetworkFunction.h"
-#include <enet/enet.h>
-#include "core/CoreIncludes.h"
-#include <string>
#include <cassert>
+#include <cstring>
#include <queue>
+#include <string>
+#include "util/Debug.h"
+#include "core/ObjectList.h"
+#include "network/NetworkFunction.h"
+
namespace orxonox {
namespace packet {
-#define PACKET_FLAGS_FUNCTIONIDS ENET_PACKET_FLAG_RELIABLE
+#define PACKET_FLAGS_FUNCTIONIDS PacketFlag::Reliable
#define _PACKETID 0
Modified: trunk/src/network/packet/FunctionIDs.h
===================================================================
--- trunk/src/network/packet/FunctionIDs.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/packet/FunctionIDs.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -25,13 +25,11 @@
* ...
*
*/
-#ifndef NETWORKFUNCTIONIDS_H
-#define NETWORKFUNCTIONIDS_H
-#include "../NetworkPrereqs.h"
+#ifndef _FunctionIDs_H__
+#define _FunctionIDs_H__
-#include <string>
-
+#include "network/NetworkPrereqs.h"
#include "Packet.h"
namespace orxonox {
@@ -57,4 +55,4 @@
} //namespace packet
} //namespace orxonox
-#endif
+#endif /* _FunctionIDs_H__ */
Modified: trunk/src/network/packet/Gamestate.cc
===================================================================
--- trunk/src/network/packet/Gamestate.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/packet/Gamestate.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -27,25 +27,22 @@
*/
#include "Gamestate.h"
-#include <enet/enet.h>
+
#include <zlib.h>
-#include <cassert>
-#include "../GamestateHandler.h"
-#include "../synchronisable/Synchronisable.h"
-#include "../TrafficControl.h"
+
+#include "util/Debug.h"
#include "core/GameMode.h"
-#include "core/CoreIncludes.h"
+#include "core/ObjectList.h"
+#include "network/synchronisable/Synchronisable.h"
+#include "network/GamestateHandler.h"
-
-
-
namespace orxonox {
namespace packet {
#define GAMESTATE_START(data) (data + GamestateHeader::getSize())
-#define PACKET_FLAG_GAMESTATE ENET_PACKET_FLAG_RELIABLE
+#define PACKET_FLAG_GAMESTATE PacketFlag::Reliable
Gamestate::Gamestate()
Modified: trunk/src/network/packet/Gamestate.h
===================================================================
--- trunk/src/network/packet/Gamestate.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/packet/Gamestate.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -27,20 +27,18 @@
*/
-#ifndef NETWORK_PACKETGAMESTATE_H
-#define NETWORK_PACKETGAMESTATE_H
+#ifndef _Gamestate_H__
+#define _Gamestate_H__
#include "network/NetworkPrereqs.h"
-#include "Packet.h"
-#include "network/TrafficControl.h"
-#include <string.h>
-#include <map>
-#include <vector>
#include <cassert>
-#ifndef NDEBUG
+#include <cstring>
+#include <list>
+
#include "util/CRC32.h"
-#endif
+#include "network/TrafficControl.h"
+#include "Packet.h"
namespace orxonox {
@@ -137,4 +135,4 @@
}
-#endif
+#endif /* _Gamestate_H__ */
Modified: trunk/src/network/packet/Packet.cc
===================================================================
--- trunk/src/network/packet/Packet.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/packet/Packet.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -30,34 +30,35 @@
#include "Packet.h"
#include <cassert>
+#include <cstring>
#include <enet/enet.h>
-#include <boost/bind.hpp>
-#include <boost/thread/recursive_mutex.hpp>
+#include <boost/static_assert.hpp>
-#include "network/ConnectionManager.h"
-#include "network/ClientInformation.h"
-
+#include "util/Debug.h"
#include "Acknowledgement.h"
-#include "DeleteObjects.h"
#include "Chat.h"
#include "ClassID.h"
+#include "DeleteObjects.h"
#include "FunctionCalls.h"
#include "FunctionIDs.h"
#include "Gamestate.h"
#include "Welcome.h"
#include "network/Host.h"
-#include "core/CoreIncludes.h"
+#include "network/ClientInformation.h"
namespace orxonox{
namespace packet{
-#define PACKET_FLAG_DEFAULT ENET_PACKET_FLAG_NO_ALLOCATE
+// Make sure we assume the right values
+BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Reliable) == static_cast<int>(ENET_PACKET_FLAG_RELIABLE));
+BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Unsequence) == static_cast<int>(ENET_PACKET_FLAG_UNSEQUENCED));
+BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::NoAllocate) == static_cast<int>(ENET_PACKET_FLAG_NO_ALLOCATE));
+
+#define PACKET_FLAG_DEFAULT PacketFlag::NoAllocate
#define _PACKETID 0
std::map<size_t, Packet *> Packet::packetMap_;
-//! Static mutex for any packetMap_ access
-static boost::recursive_mutex packetMap_mutex_g;
Packet::Packet(){
flags_ = PACKET_FLAG_DEFAULT;
@@ -107,7 +108,7 @@
// In this case ENet allocated data_ and will destroy it.
}
else if (this->data_) {
- // This destructor was probably called as a consequence to ENet executing our callback.
+ // 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.
delete[] this->data_;
@@ -141,7 +142,6 @@
{
// Assures we don't create a packet and destroy it right after in another thread
// without having a reference in the packetMap_
- boost::recursive_mutex::scoped_lock lock(packetMap_mutex_g);
packetMap_[(size_t)(void*)enetPacket_] = this;
}
}
@@ -217,6 +217,7 @@
// Data was created by ENet
p->bDataENetAllocated_ = true;
+ p->enetPacket_ = packet;
return p;
}
@@ -227,7 +228,6 @@
data we allocated ourselves.
*/
void Packet::deletePacket(ENetPacket *enetPacket){
- boost::recursive_mutex::scoped_lock lock(packetMap_mutex_g);
// Get our Packet from a gloabal map with all Packets created in the send() method of Packet.
std::map<size_t, Packet*>::iterator it = packetMap_.find((size_t)enetPacket);
assert(it != packetMap_.end());
@@ -235,7 +235,7 @@
it->second->enetPacket_ = 0;
delete it->second;
packetMap_.erase(it);
- COUT(4) << "PacketMap size: " << packetMap_.size() << std::endl;
+ COUT(6) << "PacketMap size: " << packetMap_.size() << std::endl;
}
} // namespace packet
Modified: trunk/src/network/packet/Packet.h
===================================================================
--- trunk/src/network/packet/Packet.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/packet/Packet.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -25,11 +25,10 @@
* ...
*
*/
-#ifndef NETWORKPACKET_H
-#define NETWORKPACKET_H
+#ifndef _NETWORK_Packet_H__
+#define _NETWORK_Packet_H__
#include "network/NetworkPrereqs.h"
-
#include <map>
namespace orxonox {
@@ -101,4 +100,4 @@
} //namespace orxonox
-#endif
+#endif /* _NETWORK_Packet_H__ */
Modified: trunk/src/network/packet/Welcome.cc
===================================================================
--- trunk/src/network/packet/Welcome.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/packet/Welcome.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -28,18 +28,17 @@
*
*/
-
#include "Welcome.h"
-#include <enet/enet.h>
+
#include <cassert>
+#include "util/Debug.h"
#include "network/Host.h"
#include "network/synchronisable/Synchronisable.h"
-#include "core/CoreIncludes.h"
namespace orxonox {
namespace packet {
-#define PACKET_FLAGS_CLASSID ENET_PACKET_FLAG_RELIABLE
+#define PACKET_FLAGS_CLASSID PacketFlag::Reliable
#define _PACKETID 0
#define _CLIENTID _PACKETID + sizeof(ENUM::Type)
#define _ENDIANTEST _CLIENTID + sizeof(uint32_t)
Modified: trunk/src/network/packet/Welcome.h
===================================================================
--- trunk/src/network/packet/Welcome.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/packet/Welcome.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -25,11 +25,10 @@
* ...
*
*/
-#ifndef NETWORKWELCOME_H
-#define NETWORKWELCOME_H
+#ifndef _NETWORK_Welcome_H__
+#define _NETWORK_Welcome_H__
-#include "../NetworkPrereqs.h"
-
+#include "network/NetworkPrereqs.h"
#include "Packet.h"
namespace orxonox {
@@ -55,4 +54,4 @@
} //namespace packet
} //namespace orxonox
-#endif
+#endif /* _NETWORK_Welcome_H__ */
Modified: trunk/src/network/synchronisable/NetworkCallback.h
===================================================================
--- trunk/src/network/synchronisable/NetworkCallback.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/synchronisable/NetworkCallback.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -27,8 +27,8 @@
*/
-#ifndef _NETWORK_CALLBACK__
-#define _NETWORK_CALLBACK__
+#ifndef _NetworkCallback_H__
+#define _NetworkCallback_H__
#include "network/NetworkPrereqs.h"
#include "NetworkCallbackManager.h"
@@ -60,4 +60,4 @@
}
-#endif
+#endif /* _NetworkCallback_H__ */
Modified: trunk/src/network/synchronisable/NetworkCallbackManager.cc
===================================================================
--- trunk/src/network/synchronisable/NetworkCallbackManager.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/synchronisable/NetworkCallbackManager.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -26,7 +26,6 @@
*
*/
-
#include "NetworkCallbackManager.h"
#include "NetworkCallback.h"
Modified: trunk/src/network/synchronisable/NetworkCallbackManager.h
===================================================================
--- trunk/src/network/synchronisable/NetworkCallbackManager.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/synchronisable/NetworkCallbackManager.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -27,10 +27,11 @@
*/
-#ifndef _NETWORK_CALLBACKMANAGER__
-#define _NETWORK_CALLBACKMANAGER__
+#ifndef _NetworkCallbackManager_H__
+#define _NetworkCallbackManager_H__
#include "network/NetworkPrereqs.h"
+
#include <set>
#include <queue>
@@ -51,4 +52,4 @@
}
-#endif
+#endif /* _NetworkCallbackManager_H__ */
Modified: trunk/src/network/synchronisable/Synchronisable.cc
===================================================================
--- trunk/src/network/synchronisable/Synchronisable.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/synchronisable/Synchronisable.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -30,16 +30,11 @@
#include "Synchronisable.h"
-#include <cstring>
-#include <string>
-#include <iostream>
-#include <cassert>
-
+#include <cstdlib>
#include "core/CoreIncludes.h"
#include "core/BaseObject.h"
-// #include "core/Identifier.h"
-
#include "network/Host.h"
+
namespace orxonox
{
Modified: trunk/src/network/synchronisable/Synchronisable.h
===================================================================
--- trunk/src/network/synchronisable/Synchronisable.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/synchronisable/Synchronisable.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -31,17 +31,16 @@
#include "network/NetworkPrereqs.h"
-#include <list>
+#include <cassert>
+#include <cstring>
#include <vector>
#include <map>
#include <queue>
-#include <cassert>
-#include <string>
-#include "util/Math.h"
+
#include "util/mbool.h"
#include "core/OrxonoxClass.h"
-#include "NetworkCallback.h"
#include "SynchronisableVariable.h"
+#include "NetworkCallback.h"
/*#define REGISTERDATA(varname, ...) \
registerVariable((void*)&varname, sizeof(varname), DATA, __VA_ARGS__)
Modified: trunk/src/network/synchronisable/SynchronisableSpecialisations.cc
===================================================================
--- trunk/src/network/synchronisable/SynchronisableSpecialisations.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/synchronisable/SynchronisableSpecialisations.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -27,8 +27,10 @@
*
*/
-#include "network/synchronisable/Synchronisable.h"
#include <string>
+#include "util/Math.h"
+#include "Synchronisable.h"
+#include "SynchronisableVariable.h"
// ================ template spezialisation
Modified: trunk/src/network/synchronisable/SynchronisableVariable.cc
===================================================================
--- trunk/src/network/synchronisable/SynchronisableVariable.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/synchronisable/SynchronisableVariable.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -28,7 +28,6 @@
#include "SynchronisableVariable.h"
-
namespace orxonox{
uint8_t SynchronisableVariableBase::state_ = 0;
Modified: trunk/src/network/synchronisable/SynchronisableVariable.h
===================================================================
--- trunk/src/network/synchronisable/SynchronisableVariable.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/network/synchronisable/SynchronisableVariable.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -27,18 +27,15 @@
*/
-#ifndef _NETWORK_SYNCHRONISABLEVARIABLE__
-#define _NETWORK_SYNCHRONISABLEVARIABLE__
+#ifndef _SynchronisableVariable_H__
+#define _SynchronisableVariable_H__
#include "network/NetworkPrereqs.h"
-#include <string>
#include <cassert>
+#include <cstring>
#include "util/Serialise.h"
-#include "core/Core.h"
-#include "core/CoreIncludes.h"
#include "core/GameMode.h"
-#include "network/synchronisable/NetworkCallback.h"
#include "network/synchronisable/NetworkCallbackManager.h"
namespace orxonox{
@@ -252,4 +249,4 @@
}
-#endif
+#endif /* _SynchronisableVariable_H__ */
Modified: trunk/src/orxonox/OrxonoxPrecompiledHeaders.h
===================================================================
--- trunk/src/orxonox/OrxonoxPrecompiledHeaders.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/orxonox/OrxonoxPrecompiledHeaders.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -34,6 +34,7 @@
#include "OrxonoxPrereqs.h"
+#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
@@ -83,8 +84,6 @@
#include "util/Exception.h"
#include "util/Math.h"
#include "util/OgreForwardRefs.h"
-#include "util/OrxAssert.h"
-#include "util/String.h"
#include "util/SubString.h"
#include "core/BaseObject.h"
Modified: trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc
===================================================================
--- trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -58,8 +58,6 @@
PawnManager::touch();
this->bAlive_ = true;
- this->fire_ = 0x0;
- this->firehack_ = 0x0;
this->bReload_ = false;
this->health_ = 0;
@@ -121,7 +119,6 @@
registerVariable(this->bAlive_, variableDirection::toclient);
registerVariable(this->health_, variableDirection::toclient);
registerVariable(this->initialHealth_, variableDirection::toclient);
- registerVariable(this->fire_, variableDirection::toserver);
registerVariable(this->bReload_, variableDirection::toserver);
}
@@ -129,18 +126,6 @@
{
SUPER(Pawn, tick, dt);
-// if (this->weaponSystem_ && GameMode::isMaster())
-// {
-// for (unsigned int firemode = 0; firemode < WeaponSystem::MAX_FIRE_MODES; firemode++)
-// if (this->fire_ & WeaponSystem::getFiremodeMask(firemode))
-// this->weaponSystem_->fire(firemode);
-//
-// if (this->bReload_)
-// this->weaponSystem_->reload();
-// }
-//
-// this->fire_ = this->firehack_;
-// this->firehack_ = 0x0;
this->bReload_ = false;
if (GameMode::isMaster())
Modified: trunk/src/orxonox/objects/worldentities/pawns/Pawn.h
===================================================================
--- trunk/src/orxonox/objects/worldentities/pawns/Pawn.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/orxonox/objects/worldentities/pawns/Pawn.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -136,8 +136,6 @@
Pawn* lastHitOriginator_;
WeaponSystem* weaponSystem_;
- unsigned int fire_;
- unsigned int firehack_;
bool bReload_;
std::string spawnparticlesource_;
Modified: trunk/src/util/Clipboard.cc
===================================================================
--- trunk/src/util/Clipboard.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/util/Clipboard.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -41,7 +41,12 @@
// Windows //
/////////////
+#ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+#endif
#include <windows.h>
+#undef min
+#undef max
#include "Debug.h"
namespace orxonox
Modified: trunk/src/util/Math.h
===================================================================
--- trunk/src/util/Math.h 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/util/Math.h 2009-06-23 16:02:25 UTC (rev 3214)
@@ -46,10 +46,15 @@
#include <OgreQuaternion.h>
#include <OgreColourValue.h>
-// Certain headers might define min and max macros
-#if defined(max) || defined(min) || defined(sgn) || defined(clamp) || defined(square) || defined(mod)
-# error An inline math function was overridden by a macro
-#endif
+// Certain headers might define unwanted macros...
+#undef max
+#undef min
+#undef sgn
+#undef clamp
+#undef sqrt
+#undef square
+#undef mod
+#undef rnd
namespace orxonox
{
Modified: trunk/src/util/Sleep.cc
===================================================================
--- trunk/src/util/Sleep.cc 2009-06-23 15:44:33 UTC (rev 3213)
+++ trunk/src/util/Sleep.cc 2009-06-23 16:02:25 UTC (rev 3214)
@@ -36,7 +36,12 @@
#include "Debug.h"
#ifdef ORXONOX_PLATFORM_WINDOWS
+#ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+#endif
#include <windows.h>
+#undef min
+#undef max
namespace orxonox
{
More information about the Orxonox-commit
mailing list