Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5996 in orxonox.OLD


Ignore:
Timestamp:
Dec 9, 2005, 12:31:01 PM (18 years ago)
Author:
patrick
Message:

orxonox/trunk: merged network branche into trunk with command svn merge -r 5824:HEAD

Location:
trunk/src
Files:
24 edited
6 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r5944 r5996  
    2424                       lib/parser/ini_parser/libIniParser.a \
    2525                       lib/gui/gl_gui/libORXglgui.a \
    26                        lib/shell/libORXshell.a
     26                       lib/shell/libORXshell.a \
     27                       lib/network/libORXnet.a
    2728
    2829orxonox_LDADD = util/libORXutils.a \
     
    4142                lib/gui/gl_gui/libORXglgui.a \
    4243                lib/shell/libORXshell.a \
     44                lib/network/libORXnet.a \
    4345                $(GTK2_LIBS) $(GTHREAD_LIBS) $(CURL_LIBS)
    4446
  • trunk/src/defs/class_id.h

    r5915 r5996  
    224224  CL_NETWORK_PROTOCOL           =    0x00000b02,
    225225  CL_NETWORK_SOCKET             =    0x00000b03,
    226   CL_CONNECTION_MONITOR         =    0x00000b04,
     226  CL_SERVER_SOCKET              =    0X00000b04,
     227  CL_CONNECTION_MONITOR         =    0x00000b05,
    227228
    228229
  • trunk/src/defs/debug.h

    r5944 r5996  
    110110#endif
    111111#ifndef NO_SHELL
    112 #define PRINT_EXEC       ShellBuffer::addBufferLineStatic
     112#define PRINT_EXEC       printf //ShellBuffer::addBufferLineStatic
    113113#else /* NO_SHELL */
    114114#define PRINT_EXEC       printf
  • trunk/src/defs/globals.h

    r5978 r5996  
    9191
    9292#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"
    101110
    102111
  • trunk/src/lib/network/Makefile.am

    r5822 r5996  
    1010                      network_stream.cc \
    1111                      data_stream.cc \
    12                       network_protocol.cc
     12                      network_protocol.cc \
     13                      server_socket.cc
    1314
    1415
     
    2021                 network_stream.h \
    2122                 data_stream.h \
    22                  network_protocol.h
     23                 network_protocol.h \
     24                 server_socket.h
    2325
  • trunk/src/lib/network/network_manager.cc

    r5885 r5996  
    3535
    3636
    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 
     37NetworkManager* NetworkManager::singletonRef = NULL;
    6938
    7039/**
     
    7948  this->netStreamList = NULL;
    8049  this->syncList = NULL;
     50  this->tmpStream = NULL;
    8151
    8252  PRINTF(0)("NetworkManager created\n");
     
    11484 *  creates a connection from one object to a host
    11585 * @param hostName: the name of the destination host
    116  * @param synchronizeable: reference to the sync object
    11786 */
    118 NetworkStream& establishConnection(const char& hostName, const Synchronizeable& sync)
    119 {}
     87int 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 */
     105int NetworkManager::createServer(unsigned int port)
     106{
     107  this->tmpStream = new NetworkStream(port, NET_SERVER);
     108  SDL_Delay(20);
     109  return 1;
     110}
    120111
    121112
     
    127118NetworkStream& NetworkManager::establishConnection(IPaddress& address, Synchronizeable& sync)
    128119{
    129   printf("Establish connection to server %s, on port %u\n", SDLNet_ResolveIP(&address), address.port);
    130120  /* 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);
    132122}
     123
    133124
    134125/**
     
    140131  PRINTF(0)("Create a new server socket\n");
    141132  /* 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);
    143134}
    144135
     
    153144
    154145
     146void NetworkManager::connectSynchronizeable(Synchronizeable& sync)
     147{
     148  this->tmpStream->connectSynchronizeable(sync);
     149}
     150
    155151
    156152/**
     
    163159    std::list<BaseObject*>::const_iterator stream;
    164160    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
    166164  }
    167165
  • trunk/src/lib/network/network_manager.h

    r5885 r5996  
    1919class NetworkStream;
    2020class Synchronizeable;
    21 template<typename> class tList;
     21template<typename>
     22class tList;
    2223
    2324/* and here is the class itsself*/
     
    2526{
    2627
    27 public:
     28  public:
    2829
    29   NetworkManager();
    30   ~NetworkManager();
     30    inline static NetworkManager* getInstance() { if (!NetworkManager::singletonRef) NetworkManager::singletonRef = new NetworkManager();
     31      return NetworkManager::singletonRef; }
     32    ~NetworkManager();
    3133
    32   void initialize();
    33   void shutdown();
     34    void initialize();
     35    void shutdown();
    3436
    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);
    3939
    40   void synchronize();
     40    NetworkStream& establishConnection(IPaddress& address, Synchronizeable& sync);
     41    NetworkStream& createServer(Synchronizeable& sync, unsigned int port);
     42    void shutdownConnection();
     43
    4144
    4245private:
    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
    4559
    4660};
  • trunk/src/lib/network/network_socket.cc

    r5822 r5996  
    4747
    4848
     49NetworkSocket::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
    4958void NetworkSocket::init()
    5059{
     
    7584}
    7685
     86
     87
    7788/**
    7889 * Default destructor
     
    8596  PRINTF(5)("SDL_net shutdown\n");
    8697
    87   _isListening = false;
    88 
    8998  SDL_DestroyMutex(incomingBufferMutex);
    9099  SDL_DestroyMutex(outgoingBufferMutex);
     
    113122  }
    114123
    115   _isListening = false;
    116 
    117124  SDL_CreateThread(thread_read, (void*)this);
    118125  SDL_CreateThread(thread_write, (void*)this);
    119126}
    120127
    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 port
    125  */
    126 void NetworkSocket::listen(unsigned int port)
    127 {
    128   _isListening = true;
    129   //check if not already connected or listening
    130   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 }
    158128
    159129/**
     
    184154  PRINTF(0)("NetworkSocket::writeBytes()\n");
    185155#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 //       else
    205 //       {
    206 //         res += writeBytes(data + i*_OUTGOING_BUFFER_SIZE, _OUTGOING_BUFFER_SIZE);
    207 // //         printf("res = %d\n", res);
    208 //       }
    209 //     }
    210 //     return res;
    211 //   }
    212156
    213157#define min(a,b) (a<b)?a:b
     
    256200int NetworkSocket::readBytes(byte * data, int length)
    257201{
     202  PRINTF(0)("NetworkSocket::readBytes()\n");
    258203  if (data==NULL)
    259204    return 0;
     
    299244}
    300245
    301 /**
    302  * used to create a thread to listen
    303  * will call thrad_read when established connection
    304  * @param data: pointer to NetwortSocket
    305  */
    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 }
    337246
    338247/**
     
    354263
    355264    //if buffer is full
    356     if (nbytestoread<=0 || self->_isListening)
     265    if (nbytestoread<=0)
    357266    {
    358267      SDL_Delay(_MSECONDS_SLEEP_FULL_BUFFER);
     
    405314
    406315    //if buffer is full
    407     if (nbytestowrite<=0 || self->_isListening)
     316    if (nbytestowrite<=0)
    408317    {
    409318      SDL_Delay(_MSECONDS_SLEEP_EMPTY_BUFFER);
     
    442351}
    443352
     353bool 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
     368int 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  
    1818//sleep if outgoing buffer is empty
    1919#define _MSECONDS_SLEEP_EMPTY_BUFFER 10
     20
    2021
    2122/* contains memmove and memcpy */
     
    6263  bool terminateThread;
    6364
    64   static int thread_listen(void * data);
    6565  static int thread_read(void * data);
    6666#ifdef _USE_OUTGOING_BUFFER
     
    6868#endif
    6969
    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();
    7175
    7276public:
     
    7478  NetworkSocket();
    7579  NetworkSocket(IPaddress ip);
     80  NetworkSocket(TCPsocket sock);
    7681  ~NetworkSocket();
    7782
    7883  void connectToServer(IPaddress ip);
    79   void listen(unsigned int port);
    8084  void disconnectServer();
    81   int writeBytes(byte * data, int length);
    82   int readBytes(byte * data, int length);
    83   int readBlock(byte * data, int length);
    8485
    85 private:
    86   void init();
     86  bool writePacket(byte * data, int length);
     87  int readPacket(byte * data, int maxLength);
    8788
    8889};
  • trunk/src/lib/network/network_stream.cc

    r5822 r5996  
    4040
    4141NetworkStream::NetworkStream()
    42   : DataStream()
     42    : DataStream()
    4343{
    4444  this->init();
    4545  /* initialize the references */
     46  this->type = NET_CLIENT;
    4647  this->networkSocket = new NetworkSocket();
    4748  this->networkProtocol = new NetworkProtocol();
     
    5051}
    5152
     53NetworkStream::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
     64NetworkStream::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
    5275
    5376NetworkStream::NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type)
    54   : DataStream()
    55 {
     77    : DataStream()
     78{
     79  this->type = type;
    5680  this->init();
    5781  this->networkSocket = new NetworkSocket(address);
     
    5983  this->synchronizeables = &sync;
    6084  this->connectionMonitor = new ConnectionMonitor();
     85  this->bActive = true;
    6186}
    6287
    6388
    6489NetworkStream::NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type)
    65   : DataStream()
    66 {
     90    : DataStream()
     91{
     92  this->type = type;
    6793  this->init();
    6894  this->networkSocket = new NetworkSocket();
    69   this->networkSocket->listen(port);
     95//  this->networkSocket->listen(port);
    7096  this->networkProtocol = new NetworkProtocol();
    7197  this->synchronizeables = &sync;
    7298  this->connectionMonitor = new ConnectionMonitor();
     99  this->bActive = true;
    73100}
    74101
     
    79106  this->setClassID(CL_NETWORK_STREAM, "NetworkStream");
    80107  this->state = NET_REC_HEADER;
     108  this->bActive = false;
    81109}
    82110
     
    85113{
    86114
    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
     125void NetworkStream::connectSynchronizeable(Synchronizeable& sync)
     126{
     127  this->synchronizeables = &sync;
     128  if( this->networkSocket != NULL)
     129    this->bActive = true;
     130}
     131
    95132
    96133void NetworkStream::processData()
     
    102139  PRINT(0)("============= DOWNSTREAM:===============\n");
    103140  /* 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  }
    117160
    118161
     
    124167  if( this->state == NET_REC_HEADER)
    125168  {
    126     dataLength = this->networkSocket->readBlock((byte*)upBuffer, sizeof(Header));
     169//    dataLength = this->networkSocket->readBlock((byte*)upBuffer, sizeof(Header));
    127170    if( dataLength == sizeof(Header))
    128171    {
     
    139182  {
    140183    /* now read the data */
    141     dataLength = this->networkSocket->readBlock((byte*)upBuffer, this->packetHeader.length);
     184//    dataLength = this->networkSocket->readBlock((byte*)upBuffer, this->packetHeader.length);
    142185    /* check if the data is available and process it if so */
    143186    if( dataLength == this->packetHeader.length)
    144187    {
    145       printf("NetworkStream::processData() - Got Data: \n");
     188      printf("NetworkStream::processData() - Got Data: %i bytes\n", dataLength);
    146189      /* send the received data to connectionMonitor */
    147190      this->connectionMonitor->processPacket((byte*)upBuffer, this->packetHeader.length);
    148191      /* 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);
    150194
    151195      this->state = NET_REC_HEADER;
  • trunk/src/lib/network/network_stream.h

    r5822 r5996  
    2828{
    2929
    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);
    3534
    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();
    3739
    38   inline bool isServer() { return (this->type == NET_SERVER)? true:false; }
    39   virtual void processData();
     40    void connectSynchronizeable(Synchronizeable& sync);
    4041
    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;
    5156};
    5257#endif /* _NETWORK_STREAM */
    53 
  • trunk/src/lib/network/synchronizeable.cc

    r5822 r5996  
    1818#include "netdefs.h"
    1919
     20
     21/**
     22 *  default constructor
     23 */
     24Synchronizeable::Synchronizeable()
     25{}
     26
    2027/**
    2128 *  default constructor
     
    2532  this->setName(name);
    2633}
     34
    2735
    2836/**
     
    4149 *  read data from NetworkStream
    4250 */
    43 int Synchronizeable::readBytes(byte* data) const
     51int Synchronizeable::readBytes(byte* data)
    4452{}
    4553
  • trunk/src/lib/network/synchronizeable.h

    r5822 r5996  
    1515
    1616    Synchronizeable(const char* name);
     17    Synchronizeable();
    1718    ~Synchronizeable();
    1819
    1920    virtual void      writeBytes(const byte* data, int length);
    20     virtual int       readBytes(byte* data) const;
     21    virtual int       readBytes(byte* data);
    2122    virtual void      writeDebug() const;
    2223    virtual void      readDebug() const;
  • trunk/src/lib/sound/sound_engine.cc

    r5994 r5996  
    289289  }
    290290  // INITIALIZING THE DEVICE:
     291
    291292#ifdef AL_VERSION_1_1
    292293  ALubyte deviceName[] =
     
    294295  ALCchar deviceName[] =
    295296#endif
     297
    296298#ifdef __WIN32__
    297299      "Direct3D";
     
    304306  this->context = alcCreateContext(this->device, NULL);
    305307
    306   alcMakeContextCurrent(this->context); 
     308  alcMakeContextCurrent(this->context);
    307309
    308310  if ((result = alGetError()) != AL_NO_ERROR)
  • trunk/src/orxonox.cc

    r5982 r5996  
    5757#include "load_param_description.h"
    5858
     59#include "network_manager.h"
     60
    5961#include <string.h>
    6062
     
    7981  this->argc = 0;
    8082  this->argv = NULL;
     83
     84  /* this way, there is no network enabled: */
     85  this->serverName = NULL;
     86  this->port = -1;
    8187
    8288  this->configFileName = NULL;
     
    118124
    119125  PRINT(3)
    120       (
    121       "===================================================\n" \
    122       "Thanks for playing orxonox.\n" \
    123       "visit: http://www.orxonox.net for new versions.\n" \
    124       "===================================================\n" \
    125       ORXONOX_LICENSE_SHORT
    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  );
    127133
    128134  Orxonox::singletonRef = NULL;
     
    137143void Orxonox::restart()
    138144{
    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();
    156162}
    157163
     
    179185 * initialize Orxonox with command line
    180186 */
    181 int Orxonox::init (int argc, char** argv)
     187int Orxonox::init (int argc, char** argv, const char* name, int port)
    182188{
    183189  this->argc = argc;
    184190  this->argv = argv;
    185   // parse command line
    186   // config file
     191
     192  this->serverName = name;
     193  this->port = port;
    187194
    188195  // initialize the Config-file
    189196  this->getConfigFile();
    190197
    191   // initialize everything
    192   SDL_Init(SDL_INIT_TIMER);
    193198  // windows must not write into stdout.txt and stderr.txt
    194199#ifdef __WIN32__
     
    197202#endif
    198203
    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
    208222
    209223/**
    210224 * initializes SDL and OpenGL
    211 */
     225 */
    212226int Orxonox::initVideo()
    213227{
     
    226240  return 0;
    227241}
     242
    228243
    229244/**
     
    263278  PRINT(3)("> Initializing networking\n");
    264279
    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
    266285  return 0;
    267286}
     
    282301  {
    283302    if (!ResourceManager::getInstance()->setDataDir(dataPath) &&
    284          !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE))
     303        !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE))
    285304    {
    286305      PRINTF(1)("Data Could not be located in %s\n", dataPath);
     
    301320    exit(-1);
    302321  }
    303    //! @todo this is a hack and should be loadable
     322  //! @todo this is a hack and should be loadable
    304323  char* imageDir = ResourceManager::getInstance()->getFullName("maps");
    305324  ResourceManager::getInstance()->addImageDir(imageDir);
     
    332351
    333352  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
    335359  //  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0);
    336360  this->gameLoader->init();
     
    375399int main(int argc, char** argv)
    376400{
    377   // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark.
    378401  int i;
    379402  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
     421int 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 */
     454int 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]))
    380461    {
    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);
    385475    }
    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  }
    404491}
    405492
     
    411498 * @param argv parameters given to orxonox
    412499 */
    413 int startOrxonox(int argc, char** argv)
     500int startOrxonox(int argc, char** argv, const char* name, int port)
    414501{
    415502  // checking for existence of the configuration-files, or if the lock file is still used
    416503  if (showGui || (!ResourceManager::isFile("./orxonox.conf") &&
    417       !ResourceManager::isFile(DEFAULT_CONFIG_FILE))
     504                  !ResourceManager::isFile(DEFAULT_CONFIG_FILE))
    418505#if DEBUG < 3 // developers do not need to see the GUI, when orxonox fails
    419        || ResourceManager::isFile(DEFAULT_LOCK_FILE)
     506      || ResourceManager::isFile(DEFAULT_LOCK_FILE)
    420507#endif
    421508     )
    422     {
    423       if (ResourceManager::isFile(DEFAULT_LOCK_FILE))
    424         ResourceManager::deleteFile(DEFAULT_LOCK_FILE);
    425 
    426       // starting the GUI
    427       Gui* gui = new Gui(argc, argv);
    428       gui->startGui();
    429 
    430       if (! gui->startOrxonox)
    431         return 0;
    432 
    433       delete gui;
    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  }
    435522
    436523  PRINT(0)(">>> Starting Orxonox <<<\n");
     
    440527  Orxonox *orx = Orxonox::getInstance();
    441528
    442   if(orx->init(argc, argv) == -1)
    443     {
    444       PRINTF(1)("! Orxonox initialization failed\n");
    445       return -1;
    446     }
    447 
    448     printf("finished inizialisation\n");
     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");
    449536  orx->start();
    450537
  • trunk/src/orxonox.h

    r5207 r5996  
    2323  inline static Orxonox* getInstance() { if (!singletonRef) singletonRef = new Orxonox();  return singletonRef; };
    2424
    25   int init (int argc, char** argv);
     25  int init(int argc, char** argv, const char* name, int port);
    2626
    2727  void restart();
    2828
    2929  void start();
    30 
    31   //void graphicsHandler (SDL_Event* event);
    3230
    3331 private:
     
    4341  int initMisc ();
    4442
    45 
    4643  const char* getConfigFile ();
    4744
     
    5552  unsigned int      argc;                    //!< Count of Arguments of orxonox
    5653  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
    5757};
    5858
     
    6161// Start-up functions //
    6262////////////////////////
    63 int startHelp(int argc, char** argv);
    64 int startOrxonox(int argc, char** argv);
     63int showHelp(int argc, char** argv);
     64int showLicense();
     65int startNetworkOrxonox(int argc, char** argv);
     66int startOrxonox(int argc, char** argv, const char* clientName, int port);
    6567
    6668#endif /* _ORXONOX_H */
  • trunk/src/story_entities/world.cc

    r5982 r5996  
    7171
    7272#include "playable.h"
     73#include "network_manager.h"
     74#include "playable.h"
     75
    7376
    7477SHELL_COMMAND(speed, World, setSpeed);
     
    317320      while( element != NULL)
    318321        {
    319           BaseObject* created = (Factory::fabricate(element));
     322          BaseObject* created = Factory::fabricate(element);
    320323          if( created != NULL )
    321324          {
    322325            if(created->isA(CL_WORLD_ENTITY))
    323326              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());
    325328          }
    326329
     
    659662  // Get remote input
    660663  // Update synchronizables
     664/*  NetworkManager::getInstance()->synchronize();*/
    661665}
    662666
  • trunk/src/subprojects/network/Makefile.am

    r5822 r5996  
    1515network_SOURCES=  network_unit_test.cc \
    1616                  simple_sync.cc \
     17                  read_sync.cc \
     18                  write_sync.cc \
    1719                  \
    1820                  \
     
    2123                  $(MAINSRCDIR)/util/loading/load_param.cc \
    2224                  $(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
    2429
    2530
    2631
    2732noinst_HEADERS  =  network_unit_test.h \
    28                    simple_sync.h
     33                   simple_sync.h \
     34                   read_sync.h \
     35                   write_sync.h
    2936
  • trunk/src/subprojects/network/network_unit_test.cc

    r5822 r5996  
    88#include "network_manager.h"
    99#include "network_socket.h"
     10#include "server_socket.h"
    1011#include "network_stream.h"
    1112#include "synchronizeable.h"
    1213
    1314#include "simple_sync.h"
     15#include "read_sync.h"
    1416
    1517int verbose = 4;
     
    2527  printf(" --server [port number]     creates a test server\n");
    2628  printf(" --client [address] [port]  connects to a server\n");
     29  printf(" --listen [address] [port]  just listens to this connection");
    2730  printf("\n");
    2831}
     
    3437  IPaddress ip;
    3538  SDLNet_ResolveHost(&ip, "127.0.0.1", 9999);
    36   NetworkSocket server;
     39  ServerSocket server;
    3740  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();
    4149
    4250  char buf[1024];
    4351
    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 server before 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));
    4957
    5058  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);
    5771  SDL_Delay(1000);
    5872
    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);
    6175  printf("read %d bytes\n", n);
    6276  if (n<0)
    6377    return -1;
    6478
    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);
    6983  printf("read %d bytes\n", n);
    7084  if (n<0)
    7185    return -1;
    7286
    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)));
    116114
    117115  return 0;
     
    131129
    132130  /* create the network manager */
    133   NetworkManager* nm = new NetworkManager();
     131  NetworkManager* nm = NetworkManager::getInstance();
    134132
    135133  /* initialize the network manager */
     
    143141  int error = SDLNet_ResolveHost(&ip, "127.0.0.1", port);
    144142  //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");
    146145  nm->establishConnection(ip, *clientSync);
    147146  /* adding some break for connection setup */
     
    149148
    150149  /* 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  {
    152152    nm->synchronize();
    153153    /* simulate the network delay */
     
    177177int startServer(int argc, char** argv)
    178178{
    179   if( argc <= 2) {
     179  if( argc <= 2)
     180  {
    180181    printf(" Wrong arguments try following notations:\n");
    181182    printf("   --server [port number]\n");
     
    186187  printf("Starting Server on port %i\n", port);
    187188
    188   NetworkManager* netMan = new NetworkManager();
     189  NetworkManager* netMan = NetworkManager::getInstance();
    189190  Synchronizeable* ss = new SimpleSync("Server\0");
    190191
    191   //NetworkStream* server = new NetworkStream(port, ss, NET_SERVER);
    192192  netMan->createServer(*ss, port);
    193193  SDL_Delay(20);
    194194
    195   for(;;) {
     195  for(;;)
     196  {
    196197    netMan->synchronize();
    197198    SDL_Delay(500);
    198199  }
     200
     201  delete netMan;
     202  delete ss;
     203
     204
    199205  return 0;
    200206}
     
    203209int startClient(int argc, char** argv)
    204210{
    205   if( argc < 3) {
     211  if( argc < 3)
     212  {
    206213    printf(" Wrong arguments try following notations:\n");
    207214    printf("   --client [server ip] [port number]\n");
    208     printf("   --server [server name] [port number]\n");
     215    printf("   --client [server name] [port number]\n");
    209216    return 0;
    210217  }
     
    216223  IPaddress ip;
    217224  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();
    222229  Synchronizeable* ss = new SimpleSync("Client\0");
    223230
    224231  netMan->establishConnection(ip, *ss);
    225232
    226   for(;;) {
     233  for(;;)
     234  {
    227235    netMan->synchronize();
    228236    SDL_Delay(500);
    229237  }
    230238
    231   //NetworkStream* client = new NetworkStream(ip, ss, NET_CLIENT);
     239
     240  delete netMan;
     241  delete ss;
     242
     243  return 0;
     244}
     245
     246
     247
     248int 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  }
    232277
    233278
     
    253298  {
    254299    //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);
    259310  }
    260311
     
    270321  //vprintf(line, arguments);
    271322  printf("%s", line);
    272 
    273 }
     323}
  • trunk/src/subprojects/network/simple_sync.cc

    r5822 r5996  
    8686 *  read data from Synchronizeable
    8787 */
    88 int SimpleSync::readBytes(byte* data) const
     88int SimpleSync::readBytes(byte* data)
    8989{
    9090  PRINTF(0)("SimpleSync: sent %i bytes of data\n", this->outLength);
  • trunk/src/subprojects/network/simple_sync.h

    r5822 r5996  
    1717
    1818    virtual void writeBytes(const byte* data, int length);
    19     virtual int readBytes(byte* data) const;
     19    virtual int readBytes(byte* data);
    2020
    2121
  • trunk/src/world_entities/space_ships/space_ship.h

    r5978 r5996  
     1
    12/*!
    23 * @file space_ship.h
     
    5758    bool                  bRollL;             //!< rolling button pressed (left)
    5859    bool                  bRollR;             //!< rolling button pressed (right)
    59    
     60
    6061    float                 xMouse;             //!< mouse moved in x-Direction
    6162    float                 yMouse;             //!< mouse moved in y-Direction
  • trunk/src/world_entities/world_entity.cc

    r5995 r5996  
    4141 */
    4242WorldEntity::WorldEntity(const TiXmlElement* root)
     43  : Synchronizeable()
    4344{
    4445  this->setClassID(CL_WORLD_ENTITY, "WorldEntity");
  • trunk/src/world_entities/world_entity.h

    r5995 r5996  
    88
    99#include "p_node.h"
     10#include "synchronizeable.h"
     11#include "model.h"
    1012
    1113#include "glincl.h"
     
    2224
    2325//! Basis-class all interactive stuff in the world is derived from
    24 class WorldEntity : public PNode
     26class WorldEntity : public PNode, public Synchronizeable
    2527{
    2628 public:
Note: See TracChangeset for help on using the changeset viewer.