- Timestamp:
- Dec 9, 2005, 12:31:01 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 24 edited
- 6 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Makefile.am
r5944 r5996 24 24 lib/parser/ini_parser/libIniParser.a \ 25 25 lib/gui/gl_gui/libORXglgui.a \ 26 lib/shell/libORXshell.a 26 lib/shell/libORXshell.a \ 27 lib/network/libORXnet.a 27 28 28 29 orxonox_LDADD = util/libORXutils.a \ … … 41 42 lib/gui/gl_gui/libORXglgui.a \ 42 43 lib/shell/libORXshell.a \ 44 lib/network/libORXnet.a \ 43 45 $(GTK2_LIBS) $(GTHREAD_LIBS) $(CURL_LIBS) 44 46 -
trunk/src/defs/class_id.h
r5915 r5996 224 224 CL_NETWORK_PROTOCOL = 0x00000b02, 225 225 CL_NETWORK_SOCKET = 0x00000b03, 226 CL_CONNECTION_MONITOR = 0x00000b04, 226 CL_SERVER_SOCKET = 0X00000b04, 227 CL_CONNECTION_MONITOR = 0x00000b05, 227 228 228 229 -
trunk/src/defs/debug.h
r5944 r5996 110 110 #endif 111 111 #ifndef NO_SHELL 112 #define PRINT_EXEC ShellBuffer::addBufferLineStatic112 #define PRINT_EXEC printf //ShellBuffer::addBufferLineStatic 113 113 #else /* NO_SHELL */ 114 114 #define PRINT_EXEC printf -
trunk/src/defs/globals.h
r5978 r5996 91 91 92 92 #define ORXONOX_LICENSE_SHORT \ 93 "orxonox - the future of 3D-vertical-scrollers\n" \ 94 "\n" \ 95 "Copyright (C) 2004 orx\n" \ 96 "\n" \ 97 "This program is free software; you can redistribute it and/or modify\n" \ 98 "it under the terms of the GNU General Public License as published by\n" \ 99 "the Free Software Foundation; either version 2, or (at your option)\n" \ 100 "any later version.\n" 93 "Orxonox - The Future of 3D-Action-Game\n" \ 94 "\n" \ 95 "Copyright (C) 2004 orx\n" \ 96 "\n" \ 97 "This program is free software; you can redistribute it and/or modify\n" \ 98 "it under the terms of the GNU General Public License as published by\n" \ 99 "the Free Software Foundation; either version 2, or (at your option)\n" \ 100 "any later version.\n" \ 101 "\n" \ 102 "This program is distributed in the hope that it will be useful,\n" \ 103 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \ 104 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" \ 105 "GNU General Public License for more details.\n" \ 106 "\n" \ 107 "You should have received a copy of the GNU General Public License\n" \ 108 "along with this program; if not, write to the Free Software Foundation,\n" \ 109 "Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n" 101 110 102 111 -
trunk/src/lib/network/Makefile.am
r5822 r5996 10 10 network_stream.cc \ 11 11 data_stream.cc \ 12 network_protocol.cc 12 network_protocol.cc \ 13 server_socket.cc 13 14 14 15 … … 20 21 network_stream.h \ 21 22 data_stream.h \ 22 network_protocol.h 23 network_protocol.h \ 24 server_socket.h 23 25 -
trunk/src/lib/network/network_manager.cc
r5885 r5996 35 35 36 36 37 /************************************ 38 What you will see here are the function definitions from the header file (network_manager.h) with doxygen documentation. Here is an example: 39 40 41 In file network_manager.h 42 43 class NetworkManager 44 { 45 int doSomeStuff(float argument, float* pointer); 46 } 47 48 will be implemented in the source file as follows: 49 50 In file network_manager.cc 51 52 / ** 53 * this is the short description for this function: it just does some stuff 54 * @param argument: this is the first argument, stuff... 55 * @param pointer: this is the pointer to nowhereland 56 * return: whatever the function returns: for example an index, number, etc. 57 * / 58 int NetworkManager::doSomeStuff(float argument, float* pointer) 59 { 60 // whaterver you want to do 61 } 62 63 64 if you want to make automake compile your files: you will want to add the file names to the local Makefile.am 65 66 ************************************/ 67 68 37 NetworkManager* NetworkManager::singletonRef = NULL; 69 38 70 39 /** … … 79 48 this->netStreamList = NULL; 80 49 this->syncList = NULL; 50 this->tmpStream = NULL; 81 51 82 52 PRINTF(0)("NetworkManager created\n"); … … 114 84 * creates a connection from one object to a host 115 85 * @param hostName: the name of the destination host 116 * @param synchronizeable: reference to the sync object117 86 */ 118 NetworkStream& establishConnection(const char& hostName, const Synchronizeable& sync) 119 {} 87 int NetworkManager::establishConnection(const char* name, unsigned int port) 88 { 89 IPaddress ipAddress; 90 int error = SDLNet_ResolveHost(&ipAddress, name, port); 91 if( error == -1) { 92 printf("\n\nerror on address resolution, program inconsistency\n\n"); 93 return -1; 94 } 95 96 this->tmpStream = new NetworkStream(ipAddress, NET_CLIENT); 97 return 1; 98 } 99 100 101 /** 102 * creates a new NetworkStream of server type 103 * @param port: number of the TCP port 104 */ 105 int NetworkManager::createServer(unsigned int port) 106 { 107 this->tmpStream = new NetworkStream(port, NET_SERVER); 108 SDL_Delay(20); 109 return 1; 110 } 120 111 121 112 … … 127 118 NetworkStream& NetworkManager::establishConnection(IPaddress& address, Synchronizeable& sync) 128 119 { 129 printf("Establish connection to server %s, on port %u\n", SDLNet_ResolveIP(&address), address.port);130 120 /* creating a new network stream, it will register itself automaticaly to the class list */ 131 NetworkStream* netStream = new NetworkStream(address, sync, NET_CLIENT);121 this->tmpStream = new NetworkStream(address, sync, NET_CLIENT); 132 122 } 123 133 124 134 125 /** … … 140 131 PRINTF(0)("Create a new server socket\n"); 141 132 /* creating a new network stream, it will register itself automaticaly to the class list */ 142 NetworkStream* netStream = new NetworkStream(port, sync, NET_SERVER);133 this->tmpStream = new NetworkStream(port, sync, NET_SERVER); 143 134 } 144 135 … … 153 144 154 145 146 void NetworkManager::connectSynchronizeable(Synchronizeable& sync) 147 { 148 this->tmpStream->connectSynchronizeable(sync); 149 } 150 155 151 156 152 /** … … 163 159 std::list<BaseObject*>::const_iterator stream; 164 160 for (stream = this->netStreamList->begin(); stream != this->netStreamList->end(); ++stream) 165 static_cast<NetworkStream*>(*stream)->processData(); 161 if( static_cast<NetworkStream*>(*stream)->isActive()) 162 static_cast<NetworkStream*>(*stream)->processData(); 163 166 164 } 167 165 -
trunk/src/lib/network/network_manager.h
r5885 r5996 19 19 class NetworkStream; 20 20 class Synchronizeable; 21 template<typename> class tList; 21 template<typename> 22 class tList; 22 23 23 24 /* and here is the class itsself*/ … … 25 26 { 26 27 27 public:28 public: 28 29 29 NetworkManager(); 30 ~NetworkManager(); 30 inline static NetworkManager* getInstance() { if (!NetworkManager::singletonRef) NetworkManager::singletonRef = new NetworkManager(); 31 return NetworkManager::singletonRef; } 32 ~NetworkManager(); 31 33 32 void initialize();33 void shutdown();34 void initialize(); 35 void shutdown(); 34 36 35 NetworkStream& establishConnection(IPaddress& address, Synchronizeable& sync); 36 NetworkStream& establishConnection(const char& hostName, const Synchronizeable& sync); 37 NetworkStream& createServer(Synchronizeable& sync, unsigned int port); 38 void shutdownConnection(); 37 int establishConnection(const char* name, unsigned int port); 38 int createServer(unsigned int port); 39 39 40 void synchronize(); 40 NetworkStream& establishConnection(IPaddress& address, Synchronizeable& sync); 41 NetworkStream& createServer(Synchronizeable& sync, unsigned int port); 42 void shutdownConnection(); 43 41 44 42 45 private: 43 const std::list<BaseObject*>* netStreamList; // list with refs to all network streams 44 const std::list<BaseObject*>* syncList; // list of synchronizeables 46 void connectSynchronizeable(Synchronizeable& sync); 47 void synchronize(); 48 49 50 private: 51 NetworkManager(); 52 53 54 private: 55 const std::list<BaseObject*>* netStreamList; // list with refs to all network streams 56 const std::list<BaseObject*>* syncList; // list of synchronizeables 57 static NetworkManager* singletonRef; //!< Pointer to the only instance of this Class 58 NetworkStream* tmpStream; //!< FIXME: this is only for testing purposes 45 59 46 60 }; -
trunk/src/lib/network/network_socket.cc
r5822 r5996 47 47 48 48 49 NetworkSocket::NetworkSocket( TCPsocket sock ) 50 { 51 this->init(); 52 this->tcpSocket = sock; 53 54 SDL_CreateThread(thread_read, (void*)this); 55 SDL_CreateThread(thread_write, (void*)this); 56 } 57 49 58 void NetworkSocket::init() 50 59 { … … 75 84 } 76 85 86 87 77 88 /** 78 89 * Default destructor … … 85 96 PRINTF(5)("SDL_net shutdown\n"); 86 97 87 _isListening = false;88 89 98 SDL_DestroyMutex(incomingBufferMutex); 90 99 SDL_DestroyMutex(outgoingBufferMutex); … … 113 122 } 114 123 115 _isListening = false;116 117 124 SDL_CreateThread(thread_read, (void*)this); 118 125 SDL_CreateThread(thread_write, (void*)this); 119 126 } 120 127 121 /**122 * Tells the NetworkSocket to listen on a specific port for incoming connections.123 * NetworkSocket::writeBytes(...) will have no effect until there is a valuable connection.124 * @param port125 */126 void NetworkSocket::listen(unsigned int port)127 {128 _isListening = true;129 //check if not already connected or listening130 if (tcpSocket)131 {132 PRINTF(1)("NetworkSocket::listen: tcpSocket!=NULL! maybe you already called listen or connectToServer or did not call disconnectServer()!\n");133 _isListening = false;134 return;135 }136 137 IPaddress ip;138 139 if (SDLNet_ResolveHost(&ip, NULL, port)==-1)140 {141 PRINTF(1)("SDLNet_ResolveHost: %s\n", SDLNet_GetError());142 _isListening = false;143 return;144 }145 146 tcpSocket = SDLNet_TCP_Open(&ip);147 148 if (!tcpSocket)149 {150 PRINTF(1)("SDLNet_TCP_Open: %s\n", SDLNet_GetError());151 _isListening = false;152 return;153 }154 155 SDL_CreateThread(thread_listen, (void*)this);156 SDL_CreateThread(thread_write, (void*)this);157 }158 128 159 129 /** … … 184 154 PRINTF(0)("NetworkSocket::writeBytes()\n"); 185 155 #ifdef _USE_OUTGOING_BUFFER 186 187 //printf("length=%d, bufsize=%d\n", length, _OUTGOING_BUFFER_SIZE);188 // if (length>_OUTGOING_BUFFER_SIZE)189 // {190 // int res = 0;191 // int n = length / _OUTGOING_BUFFER_SIZE;192 // if (length % _OUTGOING_BUFFER_SIZE != 0)193 // n++;194 // // printf("n=%d\n", n);195 // SDL_Delay(500);196 // for (int i = 0; i<n; i++)197 // {198 // // printf("i=%d\n", i);199 // if (i==n-1)200 // {201 // res += writeBytes(data + i*_OUTGOING_BUFFER_SIZE, length-i*_OUTGOING_BUFFER_SIZE);202 // // printf("res = %d\n", res);203 // }204 // else205 // {206 // res += writeBytes(data + i*_OUTGOING_BUFFER_SIZE, _OUTGOING_BUFFER_SIZE);207 // // printf("res = %d\n", res);208 // }209 // }210 // return res;211 // }212 156 213 157 #define min(a,b) (a<b)?a:b … … 256 200 int NetworkSocket::readBytes(byte * data, int length) 257 201 { 202 PRINTF(0)("NetworkSocket::readBytes()\n"); 258 203 if (data==NULL) 259 204 return 0; … … 299 244 } 300 245 301 /**302 * used to create a thread to listen303 * will call thrad_read when established connection304 * @param data: pointer to NetwortSocket305 */306 int NetworkSocket::thread_listen( void * data )307 {308 NetworkSocket * self = (NetworkSocket*)data;309 self->_isListening = true;310 TCPsocket tempsocket;311 312 tempsocket = SDLNet_TCP_Accept(self->tcpSocket);313 314 while (!tempsocket && !self->terminateThread)315 tempsocket = SDLNet_TCP_Accept(self->tcpSocket);316 317 SDL_mutexP(self->socketMutex);318 SDLNet_TCP_Close(self->tcpSocket);319 self->tcpSocket = NULL;320 321 if (!tempsocket)322 {323 printf("SDLNet_TCP_Accept: %s\n", SDLNet_GetError());324 //printf("SDLNet_TCP_Accept: %s\n", SDLNet_GetError());325 SDL_mutexV(self->socketMutex);326 self->_isListening = false;327 return -1;328 }329 330 self->tcpSocket = tempsocket;331 332 SDL_mutexV(self->socketMutex);333 334 self->_isListening = false;335 return thread_read(data);336 }337 246 338 247 /** … … 354 263 355 264 //if buffer is full 356 if (nbytestoread<=0 || self->_isListening)265 if (nbytestoread<=0) 357 266 { 358 267 SDL_Delay(_MSECONDS_SLEEP_FULL_BUFFER); … … 405 314 406 315 //if buffer is full 407 if (nbytestowrite<=0 || self->_isListening)316 if (nbytestowrite<=0) 408 317 { 409 318 SDL_Delay(_MSECONDS_SLEEP_EMPTY_BUFFER); … … 442 351 } 443 352 353 bool NetworkSocket::writePacket( byte * data, int length ) 354 { 355 PRINTF(0)("NetworkSocket::writePacket()\n"); 356 if (length>255) 357 { 358 PRINTF(1)("Packet length > 255!\n"); 359 return false; 360 } 361 362 byte blen = length; 363 364 writeBytes(&blen, 1); 365 writeBytes(data, length); 366 } 367 368 int NetworkSocket::readPacket( byte * data, int maxLength ) 369 { 370 PRINTF(0)("NetworkSocket::readPacket()\n"); 371 if (incomingBufferLength<1) 372 { 373 return 0; 374 } 375 376 byte blen = incomingBuffer[0]; 377 378 if (blen>maxLength) 379 { 380 PRINTF(1)("Buffersize is too small (%d) for packet (%d)\n", maxLength, blen); 381 return 0; 382 } 383 384 if (blen>incomingBufferLength) 385 { 386 return 0; 387 } 388 389 readBytes(&blen, 1); 390 int res = readBytes(data, blen); 391 392 if (res!=blen) 393 return -1; 394 else 395 return blen; 396 397 } 398 399 -
trunk/src/lib/network/network_socket.h
r5822 r5996 18 18 //sleep if outgoing buffer is empty 19 19 #define _MSECONDS_SLEEP_EMPTY_BUFFER 10 20 20 21 21 22 /* contains memmove and memcpy */ … … 62 63 bool terminateThread; 63 64 64 static int thread_listen(void * data);65 65 static int thread_read(void * data); 66 66 #ifdef _USE_OUTGOING_BUFFER … … 68 68 #endif 69 69 70 bool _isListening; 70 int writeBytes(byte * data, int length); 71 int readBytes(byte * data, int length); 72 int readBlock(byte * data, int length); 73 74 void init(); 71 75 72 76 public: … … 74 78 NetworkSocket(); 75 79 NetworkSocket(IPaddress ip); 80 NetworkSocket(TCPsocket sock); 76 81 ~NetworkSocket(); 77 82 78 83 void connectToServer(IPaddress ip); 79 void listen(unsigned int port);80 84 void disconnectServer(); 81 int writeBytes(byte * data, int length);82 int readBytes(byte * data, int length);83 int readBlock(byte * data, int length);84 85 85 private: 86 void init();86 bool writePacket(byte * data, int length); 87 int readPacket(byte * data, int maxLength); 87 88 88 89 }; -
trunk/src/lib/network/network_stream.cc
r5822 r5996 40 40 41 41 NetworkStream::NetworkStream() 42 : DataStream()42 : DataStream() 43 43 { 44 44 this->init(); 45 45 /* initialize the references */ 46 this->type = NET_CLIENT; 46 47 this->networkSocket = new NetworkSocket(); 47 48 this->networkProtocol = new NetworkProtocol(); … … 50 51 } 51 52 53 NetworkStream::NetworkStream(IPaddress& address, NodeType type) 54 { 55 this->type = type; 56 this->init(); 57 this->networkSocket = new NetworkSocket(address); 58 this->networkProtocol = new NetworkProtocol(); 59 this->synchronizeables = NULL; 60 this->connectionMonitor = new ConnectionMonitor(); 61 } 62 63 64 NetworkStream::NetworkStream(unsigned int port, NodeType type) 65 { 66 this->type = type; 67 this->init(); 68 this->networkSocket = new NetworkSocket(); 69 // this->networkSocket->listen(port); 70 this->networkProtocol = new NetworkProtocol(); 71 this->synchronizeables = NULL; 72 this->connectionMonitor = new ConnectionMonitor(); 73 } 74 52 75 53 76 NetworkStream::NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type) 54 : DataStream() 55 { 77 : DataStream() 78 { 79 this->type = type; 56 80 this->init(); 57 81 this->networkSocket = new NetworkSocket(address); … … 59 83 this->synchronizeables = &sync; 60 84 this->connectionMonitor = new ConnectionMonitor(); 85 this->bActive = true; 61 86 } 62 87 63 88 64 89 NetworkStream::NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type) 65 : DataStream() 66 { 90 : DataStream() 91 { 92 this->type = type; 67 93 this->init(); 68 94 this->networkSocket = new NetworkSocket(); 69 this->networkSocket->listen(port);95 // this->networkSocket->listen(port); 70 96 this->networkProtocol = new NetworkProtocol(); 71 97 this->synchronizeables = &sync; 72 98 this->connectionMonitor = new ConnectionMonitor(); 99 this->bActive = true; 73 100 } 74 101 … … 79 106 this->setClassID(CL_NETWORK_STREAM, "NetworkStream"); 80 107 this->state = NET_REC_HEADER; 108 this->bActive = false; 81 109 } 82 110 … … 85 113 { 86 114 87 networkSocket->disconnectServer(); 88 89 if( this->networkSocket) 90 delete networkSocket; 91 92 delete connectionMonitor; 93 delete networkProtocol; 94 } 115 networkSocket->disconnectServer(); 116 117 if( this->networkSocket) 118 delete networkSocket; 119 120 delete connectionMonitor; 121 delete networkProtocol; 122 } 123 124 125 void NetworkStream::connectSynchronizeable(Synchronizeable& sync) 126 { 127 this->synchronizeables = &sync; 128 if( this->networkSocket != NULL) 129 this->bActive = true; 130 } 131 95 132 96 133 void NetworkStream::processData() … … 102 139 PRINT(0)("============= DOWNSTREAM:===============\n"); 103 140 /* first of all read the synchronizeable's data: */ 104 dataLength = this->synchronizeables->readBytes((byte*)downBuffer); 105 106 /* send the received data to connectionMonitor */ 107 this->connectionMonitor->processPacket((byte*)downBuffer, dataLength); 108 109 dataLength = this->networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE, 110 *(this->synchronizeables), 12/* some random number (no real id)*/); 111 112 /* pass the data to the network socket */ 113 dataLength = this->networkSocket->writeBytes((byte*)downBuffer, dataLength); 114 /* check if there was an error */ 115 if( dataLength == -1) { PRINTF(0)("Error in writing data to the NetworkSocket\n");} 116 141 if( this->isServer()) 142 dataLength = this->synchronizeables->readBytes((byte*)downBuffer); 143 144 if( dataLength > 0) 145 { 146 /* send the received data to connectionMonitor */ 147 this->connectionMonitor->processPacket((byte*)downBuffer, dataLength); 148 149 dataLength = this->networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE, 150 *(this->synchronizeables), 12/* some random number (no real id)*/); 151 152 /* pass the data to the network socket */ 153 // dataLength = this->networkSocket->writeBytes((byte*)downBuffer, dataLength); 154 /* check if there was an error */ 155 if( dataLength == -1) 156 { 157 PRINTF(0)("Error in writing data to the NetworkSocket\n"); 158 } 159 } 117 160 118 161 … … 124 167 if( this->state == NET_REC_HEADER) 125 168 { 126 dataLength = this->networkSocket->readBlock((byte*)upBuffer, sizeof(Header));169 // dataLength = this->networkSocket->readBlock((byte*)upBuffer, sizeof(Header)); 127 170 if( dataLength == sizeof(Header)) 128 171 { … … 139 182 { 140 183 /* now read the data */ 141 dataLength = this->networkSocket->readBlock((byte*)upBuffer, this->packetHeader.length);184 // dataLength = this->networkSocket->readBlock((byte*)upBuffer, this->packetHeader.length); 142 185 /* check if the data is available and process it if so */ 143 186 if( dataLength == this->packetHeader.length) 144 187 { 145 printf("NetworkStream::processData() - Got Data: \n");188 printf("NetworkStream::processData() - Got Data: %i bytes\n", dataLength); 146 189 /* send the received data to connectionMonitor */ 147 190 this->connectionMonitor->processPacket((byte*)upBuffer, this->packetHeader.length); 148 191 /* now pass the data to the sync object */ 149 this->synchronizeables->writeBytes((byte*)upBuffer, this->packetHeader.length); 192 if( !this->isServer()) 193 this->synchronizeables->writeBytes((byte*)upBuffer, this->packetHeader.length); 150 194 151 195 this->state = NET_REC_HEADER; -
trunk/src/lib/network/network_stream.h
r5822 r5996 28 28 { 29 29 30 public: 31 NetworkStream(); 32 NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type); 33 NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type); 34 ~NetworkStream(); 30 public: 31 NetworkStream(); 32 NetworkStream(IPaddress& address, NodeType type); 33 NetworkStream(unsigned int port, NodeType type); 35 34 36 void init(); 35 NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type); 36 NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type); 37 ~NetworkStream(); 38 void init(); 37 39 38 inline bool isServer() { return (this->type == NET_SERVER)? true:false; } 39 virtual void processData(); 40 void connectSynchronizeable(Synchronizeable& sync); 40 41 41 private: 42 NetworkProtocol* networkProtocol; 43 //NetworkSocket* networkSockets; 44 ConnectionMonitor* connectionMonitor; 45 // tList<Synchronizeable>* synchronizeables; 46 Synchronizeable* synchronizeables; 47 NetworkSocket* networkSocket; 48 int type; 49 int state; 50 Header packetHeader; 42 inline bool isServer() const { return (this->type == NET_SERVER)? true:false; } 43 inline bool isActive() const { return this->bActive; } 44 45 virtual void processData(); 46 47 private: 48 NetworkProtocol* networkProtocol; 49 ConnectionMonitor* connectionMonitor; 50 Synchronizeable* synchronizeables; 51 NetworkSocket* networkSocket; 52 int type; 53 int state; 54 Header packetHeader; 55 bool bActive; 51 56 }; 52 57 #endif /* _NETWORK_STREAM */ 53 -
trunk/src/lib/network/synchronizeable.cc
r5822 r5996 18 18 #include "netdefs.h" 19 19 20 21 /** 22 * default constructor 23 */ 24 Synchronizeable::Synchronizeable() 25 {} 26 20 27 /** 21 28 * default constructor … … 25 32 this->setName(name); 26 33 } 34 27 35 28 36 /** … … 41 49 * read data from NetworkStream 42 50 */ 43 int Synchronizeable::readBytes(byte* data) const51 int Synchronizeable::readBytes(byte* data) 44 52 {} 45 53 -
trunk/src/lib/network/synchronizeable.h
r5822 r5996 15 15 16 16 Synchronizeable(const char* name); 17 Synchronizeable(); 17 18 ~Synchronizeable(); 18 19 19 20 virtual void writeBytes(const byte* data, int length); 20 virtual int readBytes(byte* data) const;21 virtual int readBytes(byte* data); 21 22 virtual void writeDebug() const; 22 23 virtual void readDebug() const; -
trunk/src/lib/sound/sound_engine.cc
r5994 r5996 289 289 } 290 290 // INITIALIZING THE DEVICE: 291 291 292 #ifdef AL_VERSION_1_1 292 293 ALubyte deviceName[] = … … 294 295 ALCchar deviceName[] = 295 296 #endif 297 296 298 #ifdef __WIN32__ 297 299 "Direct3D"; … … 304 306 this->context = alcCreateContext(this->device, NULL); 305 307 306 alcMakeContextCurrent(this->context); 308 alcMakeContextCurrent(this->context); 307 309 308 310 if ((result = alGetError()) != AL_NO_ERROR) -
trunk/src/orxonox.cc
r5982 r5996 57 57 #include "load_param_description.h" 58 58 59 #include "network_manager.h" 60 59 61 #include <string.h> 60 62 … … 79 81 this->argc = 0; 80 82 this->argv = NULL; 83 84 /* this way, there is no network enabled: */ 85 this->serverName = NULL; 86 this->port = -1; 81 87 82 88 this->configFileName = NULL; … … 118 124 119 125 PRINT(3) 120 121 122 123 124 125 126 126 ( 127 "===================================================\n" \ 128 "Thanks for playing orxonox.\n" \ 129 "visit: http://www.orxonox.net for new versions.\n" \ 130 "===================================================\n" \ 131 ORXONOX_LICENSE_SHORT 132 ); 127 133 128 134 Orxonox::singletonRef = NULL; … … 137 143 void Orxonox::restart() 138 144 { 139 // int argc = this->argc;140 // char** argv = this->argv;141 //142 // Orxonox *orx = Orxonox::getInstance();143 //144 // delete orx;145 //146 // orx = Orxonox::getInstance();147 //148 // if((*orx).init(argc, argv) == -1)149 // {150 // PRINTF(1)("! Orxonox initialization failed\n");151 // return;152 // }153 //154 // printf("finished inizialisation\n");155 // orx->start();145 // int argc = this->argc; 146 // char** argv = this->argv; 147 // 148 // Orxonox *orx = Orxonox::getInstance(); 149 // 150 // delete orx; 151 // 152 // orx = Orxonox::getInstance(); 153 // 154 // if((*orx).init(argc, argv) == -1) 155 // { 156 // PRINTF(1)("! Orxonox initialization failed\n"); 157 // return; 158 // } 159 // 160 // printf("finished inizialisation\n"); 161 // orx->start(); 156 162 } 157 163 … … 179 185 * initialize Orxonox with command line 180 186 */ 181 int Orxonox::init (int argc, char** argv )187 int Orxonox::init (int argc, char** argv, const char* name, int port) 182 188 { 183 189 this->argc = argc; 184 190 this->argv = argv; 185 // parse command line 186 // config file 191 192 this->serverName = name; 193 this->port = port; 187 194 188 195 // initialize the Config-file 189 196 this->getConfigFile(); 190 197 191 // initialize everything192 SDL_Init(SDL_INIT_TIMER);193 198 // windows must not write into stdout.txt and stderr.txt 194 199 #ifdef __WIN32__ … … 197 202 #endif 198 203 199 if( initResources () == -1) return -1; 200 if( initVideo() == -1) return -1; 201 if( initSound() == -1) return -1; 202 if( initInput() == -1) return -1; 203 if( initNetworking () == -1) return -1; 204 if( initMisc () == -1) return -1; 205 206 return 0; 207 } 204 // initialize everything 205 SDL_Init(SDL_INIT_TIMER); 206 if( initResources () == -1) 207 return -1; 208 if( initVideo() == -1) 209 return -1; 210 if( initSound() == -1) 211 return -1; 212 if( initInput() == -1) 213 return -1; 214 if( initNetworking () == -1) 215 return -1; 216 if( initMisc () == -1) 217 return -1; 218 219 return 0; 220 } 221 208 222 209 223 /** 210 224 * initializes SDL and OpenGL 211 */225 */ 212 226 int Orxonox::initVideo() 213 227 { … … 226 240 return 0; 227 241 } 242 228 243 229 244 /** … … 263 278 PRINT(3)("> Initializing networking\n"); 264 279 265 printf(" ---Not yet implemented-FIXME--\n"); 280 if( this->serverName != NULL) // we are a client 281 NetworkManager::getInstance()->establishConnection(this->serverName, port); 282 else if( this->port > 0) // we are a server 283 NetworkManager::getInstance()->createServer(port); 284 266 285 return 0; 267 286 } … … 282 301 { 283 302 if (!ResourceManager::getInstance()->setDataDir(dataPath) && 284 303 !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE)) 285 304 { 286 305 PRINTF(1)("Data Could not be located in %s\n", dataPath); … … 301 320 exit(-1); 302 321 } 303 322 //! @todo this is a hack and should be loadable 304 323 char* imageDir = ResourceManager::getInstance()->getFullName("maps"); 305 324 ResourceManager::getInstance()->addImageDir(imageDir); … … 332 351 333 352 this->gameLoader = GameLoader::getInstance(); 334 this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc"); 353 354 if( this->port != -1 || this->serverName != NULL) 355 this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc"); /* actualy loadNetworkCampaign*/ 356 else 357 this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc"); 358 335 359 // this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0); 336 360 this->gameLoader->init(); … … 375 399 int main(int argc, char** argv) 376 400 { 377 // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark.378 401 int i; 379 402 for(i = 1; i < argc; ++i) 403 { 404 if( !strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) 405 return showHelp(argc, argv); 406 else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) 407 showGui = true; 408 else if(!strcmp( "--client", argv[i]) || !strcmp("-c", argv[i])) 409 return startNetworkOrxonox(argc, argv); 410 else if(!strcmp( "--server", argv[i]) || !strcmp("-s", argv[i])) 411 return startNetworkOrxonox(argc, argv); 412 else if(!strcmp( "--license", argv[i]) || !strcmp("-s", argv[i])) 413 return PRINT(0)(ORXONOX_LICENSE_SHORT); 414 } 415 416 return startOrxonox(argc, argv, NULL, -1); 417 } 418 419 420 421 int showHelp(int argc, char** argv) 422 { 423 PRINT(0)("Orxonox Version %s\n", PACKAGE_VERSION); 424 PRINT(0)(" Starts Orxonox - The most furious 3D Action Game :)\n"); 425 PRINT(0)("\n"); 426 PRINT(0)("Common options:\n"); 427 PRINT(0)(" -g, --gui starts the orxonox with the configuration GUI \n"); 428 PRINT(0)(" -h, --help shows this help\n"); 429 PRINT(0)("\n"); 430 PRINT(0)("Network options:\n"); 431 PRINT(0)(" -s, --server [port] starts Orxonox and listens on the [port] for players\n"); 432 PRINT(0)(" -c, --client [hostname] [port] starts Orxonox as a Client\n"); 433 PRINT(0)(" -c, --client [ip address] [port] starts Orxonox as a Client\n"); 434 PRINT(0)("\n"); 435 PRINT(0)("Other options:\n"); 436 PRINT(0)(" --license prints the licence and exit\n\n"); 437 PRINT(0)("\n"); 438 439 // { 440 // Gui* gui = new Gui(argc, argv); 441 // gui->printHelp(); 442 // delete gui; 443 // } 444 } 445 446 447 448 449 /** 450 * starts orxonox in network mode 451 * @param argc parameters count given to orxonox 452 * @param argv parameters given to orxonox 453 */ 454 int startNetworkOrxonox(int argc, char** argv) 455 { 456 457 int i; 458 for(i = 0; i < argc; ++i ) 459 { 460 if( !strcmp( "--client", argv[i]) || !strcmp("-c", argv[i])) 380 461 { 381 if(! strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) return startHelp(argc, argv); 382 // else if(!strcmp( "--benchmark", argv[i]) || !strcmp("-b", argv[i])) return startBenchmarks(); 383 else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true; 384 // else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]); 462 if( argc <= (i+2)) 463 { 464 printf(" Wrong arguments try following notations:\n"); 465 printf(" --client [server ip address] [port number]\n"); 466 printf(" --client [dns name] [port number]\n"); 467 return 0; 468 } 469 470 const char* name = argv[i+1]; 471 int port = atoi(argv[i+2]); 472 printf("Starting Orxonox as client: connecting to %s, on port %i\n", name, port); 473 474 startOrxonox(argc, argv, name, port); 385 475 } 386 387 return startOrxonox(argc, argv); 388 } 389 390 391 392 int startHelp(int argc, char** argv) 393 { 394 PRINT(0)("orxonox: starts the orxonox game - rules\n"); 395 PRINT(0)("usage: orxonox [arg [arg...]]\n\n"); 396 PRINT(0)("valid options:\n"); 397 { 398 Gui* gui = new Gui(argc, argv); 399 gui->printHelp(); 400 delete gui; 401 } 402 PRINT(0)(" -b|--benchmark:\t\tstarts the orxonox benchmark\n"); 403 PRINT(0)(" -h|--help:\t\t\tshows this help\n"); 476 else if( !strcmp( "--server", argv[i]) || !strcmp("-s", argv[i])) 477 { 478 if( argc <= (i+1)) 479 { 480 printf(" Wrong arguments try following notations:\n"); 481 printf(" --server [port number]\n"); 482 return 0; 483 } 484 485 int port = atoi(argv[i+1]); 486 printf("Starting Orxonox as server, listening on port %i\n", port); 487 488 startOrxonox(argc, argv, NULL, port); 489 } 490 } 404 491 } 405 492 … … 411 498 * @param argv parameters given to orxonox 412 499 */ 413 int startOrxonox(int argc, char** argv )500 int startOrxonox(int argc, char** argv, const char* name, int port) 414 501 { 415 502 // checking for existence of the configuration-files, or if the lock file is still used 416 503 if (showGui || (!ResourceManager::isFile("./orxonox.conf") && 417 !ResourceManager::isFile(DEFAULT_CONFIG_FILE))504 !ResourceManager::isFile(DEFAULT_CONFIG_FILE)) 418 505 #if DEBUG < 3 // developers do not need to see the GUI, when orxonox fails 419 506 || ResourceManager::isFile(DEFAULT_LOCK_FILE) 420 507 #endif 421 508 ) 422 423 424 425 426 427 428 429 430 431 432 433 434 509 { 510 if (ResourceManager::isFile(DEFAULT_LOCK_FILE)) 511 ResourceManager::deleteFile(DEFAULT_LOCK_FILE); 512 513 // starting the GUI 514 Gui* gui = new Gui(argc, argv); 515 gui->startGui(); 516 517 if (! gui->startOrxonox) 518 return 0; 519 520 delete gui; 521 } 435 522 436 523 PRINT(0)(">>> Starting Orxonox <<<\n"); … … 440 527 Orxonox *orx = Orxonox::getInstance(); 441 528 442 if( orx->init(argc, argv) == -1)443 444 445 446 447 448 529 if( orx->init(argc, argv, name, port) == -1) 530 { 531 PRINTF(1)("! Orxonox initialization failed\n"); 532 return -1; 533 } 534 535 printf("finished inizialisation\n"); 449 536 orx->start(); 450 537 -
trunk/src/orxonox.h
r5207 r5996 23 23 inline static Orxonox* getInstance() { if (!singletonRef) singletonRef = new Orxonox(); return singletonRef; }; 24 24 25 int init (int argc, char** argv);25 int init(int argc, char** argv, const char* name, int port); 26 26 27 27 void restart(); 28 28 29 29 void start(); 30 31 //void graphicsHandler (SDL_Event* event);32 30 33 31 private: … … 43 41 int initMisc (); 44 42 45 46 43 const char* getConfigFile (); 47 44 … … 55 52 unsigned int argc; //!< Count of Arguments of orxonox 56 53 char** argv; //!< Values of th Arguments of orxonox. 54 55 const char* serverName; //!< Name of the Orxonox client if == NULL -> server 56 int port; //!< number of the network port of the server/client if == -1 no network 57 57 }; 58 58 … … 61 61 // Start-up functions // 62 62 //////////////////////// 63 int startHelp(int argc, char** argv); 64 int startOrxonox(int argc, char** argv); 63 int showHelp(int argc, char** argv); 64 int showLicense(); 65 int startNetworkOrxonox(int argc, char** argv); 66 int startOrxonox(int argc, char** argv, const char* clientName, int port); 65 67 66 68 #endif /* _ORXONOX_H */ -
trunk/src/story_entities/world.cc
r5982 r5996 71 71 72 72 #include "playable.h" 73 #include "network_manager.h" 74 #include "playable.h" 75 73 76 74 77 SHELL_COMMAND(speed, World, setSpeed); … … 317 320 while( element != NULL) 318 321 { 319 BaseObject* created = (Factory::fabricate(element));322 BaseObject* created = Factory::fabricate(element); 320 323 if( created != NULL ) 321 324 { 322 325 if(created->isA(CL_WORLD_ENTITY)) 323 326 this->spawn(dynamic_cast<WorldEntity*>(created)); 324 PRINTF(4)("Created a %s: %s\n", created->getClassName(), created->getName());327 printf("Created a %s: %s\n", created->getClassName(), created->getName()); 325 328 } 326 329 … … 659 662 // Get remote input 660 663 // Update synchronizables 664 /* NetworkManager::getInstance()->synchronize();*/ 661 665 } 662 666 -
trunk/src/subprojects/network/Makefile.am
r5822 r5996 15 15 network_SOURCES= network_unit_test.cc \ 16 16 simple_sync.cc \ 17 read_sync.cc \ 18 write_sync.cc \ 17 19 \ 18 20 \ … … 21 23 $(MAINSRCDIR)/util/loading/load_param.cc \ 22 24 $(MAINSRCDIR)/lib/util/substring.cc \ 23 $(MAINSRCDIR)/lib/util/helper_functions.cc 25 $(MAINSRCDIR)/util/loading/load_param_description.cc \ 26 $(MAINSRCDIR)/lib/util/helper_functions.cc \ 27 $(MAINSRCDIR)/lib/util/executor/executor.cc \ 28 $(MAINSRCDIR)/lib/util/multi_type.cc 24 29 25 30 26 31 27 32 noinst_HEADERS = network_unit_test.h \ 28 simple_sync.h 33 simple_sync.h \ 34 read_sync.h \ 35 write_sync.h 29 36 -
trunk/src/subprojects/network/network_unit_test.cc
r5822 r5996 8 8 #include "network_manager.h" 9 9 #include "network_socket.h" 10 #include "server_socket.h" 10 11 #include "network_stream.h" 11 12 #include "synchronizeable.h" 12 13 13 14 #include "simple_sync.h" 15 #include "read_sync.h" 14 16 15 17 int verbose = 4; … … 25 27 printf(" --server [port number] creates a test server\n"); 26 28 printf(" --client [address] [port] connects to a server\n"); 29 printf(" --listen [address] [port] just listens to this connection"); 27 30 printf("\n"); 28 31 } … … 34 37 IPaddress ip; 35 38 SDLNet_ResolveHost(&ip, "127.0.0.1", 9999); 36 NetworkSocket server;39 ServerSocket server; 37 40 server.listen(9999); 38 SDL_Delay(20); 39 40 NetworkSocket client(ip); 41 42 NetworkSocket client1(ip); 43 44 NetworkSocket server1 = server.getNewSocket(); 45 46 NetworkSocket client2(ip); 47 48 NetworkSocket server2 = server.getNewSocket(); 41 49 42 50 char buf[1024]; 43 51 44 printf("read from client before sending data\n");45 printf("result: %d bytes\n", client .readBytes((byte*)buf, 1024));46 47 printf("read from serverbefore sending data\n");48 printf("result: %d bytes\n", server.readBytes((byte*)buf, 1024));52 printf("read from client1 before sending data\n"); 53 printf("result: %d bytes\n", client1.readPacket((byte*)buf, 1024)); 54 55 printf("read from client2 before sending data\n"); 56 printf("result: %d bytes\n", client2.readPacket((byte*)buf, 1024)); 49 57 50 58 int n; 51 char * str1 = "client to server"; 52 char * str2 = "server to client"; 53 n = client.writeBytes((byte*)str1, strlen(str1)+1); 54 printf("%d bytes send from client\n", n); 55 n = server.writeBytes((byte*)str2, strlen(str2)+1); 56 printf("%d bytes send from server\n", n); 59 char * str1 = "client1 to server"; 60 char * str2 = "server1 to client"; 61 char * str3 = "client2 to server"; 62 char * str4 = "server2 to client"; 63 n = client1.writePacket((byte*)str1, strlen(str1)+1); 64 printf("%d bytes send from client1\n", n); 65 n = server1.writePacket((byte*)str2, strlen(str2)+1); 66 printf("%d bytes send from server1\n", n); 67 n = client2.writePacket((byte*)str3, strlen(str3)+1); 68 printf("%d bytes send from client2\n", n); 69 n = server2.writePacket((byte*)str4, strlen(str4)+1); 70 printf("%d bytes send from server2\n", n); 57 71 SDL_Delay(1000); 58 72 59 printf("read from server \n");60 n = server .readBytes((byte*)buf, 1024);73 printf("read from server1\n"); 74 n = server1.readPacket((byte*)buf, 1024); 61 75 printf("read %d bytes\n", n); 62 76 if (n<0) 63 77 return -1; 64 78 65 printf("data: %s\n", buf);66 printf("read from client\n"); 67 n = client.readBytes((byte*)buf, 1024);68 79 printf("data: '%s'\n", buf); 80 81 printf("read from server2\n"); 82 n = server2.readPacket((byte*)buf, 1024); 69 83 printf("read %d bytes\n", n); 70 84 if (n<0) 71 85 return -1; 72 86 73 printf("data: %s\n", buf); 74 75 printf("testing a bigger amount of data\n"); 76 77 #define _N_ELEMENTS 212994 78 char sendbuf[_N_ELEMENTS+1]; 79 char recvbuf[_N_ELEMENTS+1]; 80 sendbuf[_N_ELEMENTS] = '\0'; 81 recvbuf[_N_ELEMENTS] = '\0'; 82 83 for (int i = 0; i<_N_ELEMENTS; i++) 84 sendbuf[i] = i%26 + 65; 85 86 printf("write\n"); 87 printf("result = %d\n", client.writeBytes((byte*)sendbuf, _N_ELEMENTS)); 88 89 SDL_Delay(50); 90 91 printf("read\n"); 92 int nbytes = server.readBytes((byte*)recvbuf, _N_ELEMENTS); 93 int offset = nbytes; 94 95 while (nbytes>0) 96 { 97 SDL_Delay(10); 98 //printf("read\n"); 99 nbytes = server.readBytes((byte*)recvbuf+offset, _N_ELEMENTS-offset); 100 offset += nbytes; 101 //printf("nbytes=%d, offset=%d\n", nbytes, offset); 102 } 103 104 printf("strcmp = %d (0 is good :D not 0 is evil)\noffset = %d\n", strncmp(sendbuf, recvbuf, _N_ELEMENTS), offset); 105 106 //printf("%s\n%s\n", sendbuf, recvbuf); 107 108 for (int i = 0; i<_N_ELEMENTS; i++) 109 { 110 if (sendbuf[i]!=recvbuf[i]) 111 { 112 printf("byte %d is the first difference\n", i+1); 113 break; 114 } 115 } 87 printf("data: '%s'\n", buf); 88 89 printf("read from client1\n"); 90 n = client1.readPacket((byte*)buf, 1024); 91 printf("read %d bytes\n", n); 92 if (n<0) 93 return -1; 94 95 printf("data: '%s'\n", buf); 96 97 printf("read from client2\n"); 98 n = client2.readPacket((byte*)buf, 1024); 99 printf("read %d bytes\n", n); 100 if (n<0) 101 return -1; 102 103 printf("data: '%s'\n", buf); 104 105 //sending bigger packets than 255 is not supported 106 107 printf("try to send more than 255 bytes\n"); 108 printf("result: %d\n", client1.writePacket((byte*)buf, 1000)); 109 110 server1.writePacket((byte*)str1, strlen(str1)+1); 111 SDL_Delay(500); 112 printf("try to read with a too small buffer\n"); 113 printf("result: %d\n", client1.readPacket((byte*)buf, strlen(str1))); 116 114 117 115 return 0; … … 131 129 132 130 /* create the network manager */ 133 NetworkManager* nm = new NetworkManager();131 NetworkManager* nm = NetworkManager::getInstance(); 134 132 135 133 /* initialize the network manager */ … … 143 141 int error = SDLNet_ResolveHost(&ip, "127.0.0.1", port); 144 142 //SDLNet_ResolveHost(&ip, "localhost", port); 145 if(error == -1) printf("\n\nerror on address resolution, program inconsistancy\n\n"); 143 if(error == -1) 144 printf("\n\nerror on address resolution, program inconsistancy\n\n"); 146 145 nm->establishConnection(ip, *clientSync); 147 146 /* adding some break for connection setup */ … … 149 148 150 149 /* synchronize the data 1 time (increment for longer tests) */ 151 for( int i = 0; i < 3; i++) { 150 for( int i = 0; i < 3; i++) 151 { 152 152 nm->synchronize(); 153 153 /* simulate the network delay */ … … 177 177 int startServer(int argc, char** argv) 178 178 { 179 if( argc <= 2) { 179 if( argc <= 2) 180 { 180 181 printf(" Wrong arguments try following notations:\n"); 181 182 printf(" --server [port number]\n"); … … 186 187 printf("Starting Server on port %i\n", port); 187 188 188 NetworkManager* netMan = new NetworkManager();189 NetworkManager* netMan = NetworkManager::getInstance(); 189 190 Synchronizeable* ss = new SimpleSync("Server\0"); 190 191 191 //NetworkStream* server = new NetworkStream(port, ss, NET_SERVER);192 192 netMan->createServer(*ss, port); 193 193 SDL_Delay(20); 194 194 195 for(;;) { 195 for(;;) 196 { 196 197 netMan->synchronize(); 197 198 SDL_Delay(500); 198 199 } 200 201 delete netMan; 202 delete ss; 203 204 199 205 return 0; 200 206 } … … 203 209 int startClient(int argc, char** argv) 204 210 { 205 if( argc < 3) { 211 if( argc < 3) 212 { 206 213 printf(" Wrong arguments try following notations:\n"); 207 214 printf(" --client [server ip] [port number]\n"); 208 printf(" -- server[server name] [port number]\n");215 printf(" --client [server name] [port number]\n"); 209 216 return 0; 210 217 } … … 216 223 IPaddress ip; 217 224 int error = SDLNet_ResolveHost(&ip, name, port); 218 //SDLNet_ResolveHost(&ip, "localhost", port);219 if(error == -1)printf("\n\nerror on address resolution, program inconsistancy\n\n");220 221 NetworkManager* netMan = new NetworkManager();225 if(error == -1) 226 printf("\n\nerror on address resolution, program inconsistancy\n\n"); 227 228 NetworkManager* netMan = NetworkManager::getInstance(); 222 229 Synchronizeable* ss = new SimpleSync("Client\0"); 223 230 224 231 netMan->establishConnection(ip, *ss); 225 232 226 for(;;) { 233 for(;;) 234 { 227 235 netMan->synchronize(); 228 236 SDL_Delay(500); 229 237 } 230 238 231 //NetworkStream* client = new NetworkStream(ip, ss, NET_CLIENT); 239 240 delete netMan; 241 delete ss; 242 243 return 0; 244 } 245 246 247 248 int startListen(int argc, char** argv) 249 { 250 if( argc < 3) 251 { 252 printf(" Wrong arguments try following notations:\n"); 253 printf(" --listen [server ip] [port number]\n"); 254 printf(" --listen [server name] [port number]\n"); 255 return 0; 256 } 257 258 char* name = argv[2]; 259 int port = atoi(argv[3]); 260 printf("Connecting to %s, on port %i\n", name, port); 261 262 IPaddress ip; 263 int error = SDLNet_ResolveHost(&ip, name, port); 264 if(error == -1) 265 printf("\n\nerror on address resolution, program inconsistancy\n\n"); 266 267 NetworkManager* netMan = NetworkManager::getInstance(); 268 Synchronizeable* ss = new ReadSync("WriteSync\0"); 269 270 netMan->establishConnection(ip, *ss); 271 272 for(;;) 273 { 274 netMan->synchronize(); 275 SDL_Delay(10); 276 } 232 277 233 278 … … 253 298 { 254 299 //else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true; 255 if (! strcmp( "--sockettest", argv[i]) || !strcmp("-st", argv[i])) return testSocket(argc, argv); 256 else if (! strcmp( "--frameworktest", argv[i]) || !strcmp("-ft", argv[i])) return testFramework(argc, argv); 257 else if (! strcmp( "--server", argv[i]) || !strcmp("-s", argv[i])) return startServer(argc, argv); 258 else if (! strcmp( "--client", argv[i]) || !strcmp("-c", argv[i])) return startClient(argc, argv); 300 if (! strcmp( "--sockettest", argv[i]) || !strcmp("-st", argv[i])) 301 return testSocket(argc, argv); 302 else if (! strcmp( "--frameworktest", argv[i]) || !strcmp("-ft", argv[i])) 303 return testFramework(argc, argv); 304 else if (! strcmp( "--server", argv[i]) || !strcmp("-s", argv[i])) 305 return startServer(argc, argv); 306 else if (! strcmp( "--client", argv[i]) || !strcmp("-c", argv[i])) 307 return startClient(argc, argv); 308 else if (! strcmp( "--listen", argv[i]) || !strcmp("-l", argv[i])) 309 return startListen(argc, argv); 259 310 } 260 311 … … 270 321 //vprintf(line, arguments); 271 322 printf("%s", line); 272 273 } 323 } -
trunk/src/subprojects/network/simple_sync.cc
r5822 r5996 86 86 * read data from Synchronizeable 87 87 */ 88 int SimpleSync::readBytes(byte* data) const88 int SimpleSync::readBytes(byte* data) 89 89 { 90 90 PRINTF(0)("SimpleSync: sent %i bytes of data\n", this->outLength); -
trunk/src/subprojects/network/simple_sync.h
r5822 r5996 17 17 18 18 virtual void writeBytes(const byte* data, int length); 19 virtual int readBytes(byte* data) const;19 virtual int readBytes(byte* data); 20 20 21 21 -
trunk/src/world_entities/space_ships/space_ship.h
r5978 r5996 1 1 2 /*! 2 3 * @file space_ship.h … … 57 58 bool bRollL; //!< rolling button pressed (left) 58 59 bool bRollR; //!< rolling button pressed (right) 59 60 60 61 float xMouse; //!< mouse moved in x-Direction 61 62 float yMouse; //!< mouse moved in y-Direction -
trunk/src/world_entities/world_entity.cc
r5995 r5996 41 41 */ 42 42 WorldEntity::WorldEntity(const TiXmlElement* root) 43 : Synchronizeable() 43 44 { 44 45 this->setClassID(CL_WORLD_ENTITY, "WorldEntity"); -
trunk/src/world_entities/world_entity.h
r5995 r5996 8 8 9 9 #include "p_node.h" 10 #include "synchronizeable.h" 11 #include "model.h" 10 12 11 13 #include "glincl.h" … … 22 24 23 25 //! Basis-class all interactive stuff in the world is derived from 24 class WorldEntity : public PNode 26 class WorldEntity : public PNode, public Synchronizeable 25 27 { 26 28 public:
Note: See TracChangeset
for help on using the changeset viewer.