Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6018 in orxonox.OLD for branches/network


Ignore:
Timestamp:
Dec 10, 2005, 6:48:01 PM (19 years ago)
Author:
rennerc
Message:

NetworkStream should now accept net connections

Location:
branches/network/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/network_manager.h

    r5997 r6018  
    4747    inline int getHostID() { return this->hostID; };
    4848
    49   private:
     49
    5050    void connectSynchronizeable(Synchronizeable& sync);
    5151    void synchronize();
    5252
     53  private:
    5354    NetworkManager();
    5455
  • branches/network/src/lib/network/network_socket.h

    r5996 r6018  
    8787  int readPacket(byte * data, int maxLength);
    8888
     89  inline bool isOk() { return tcpSocket!=NULL; }
     90
    8991};
    9092
  • branches/network/src/lib/network/network_stream.cc

    r6007 r6018  
    6666  this->networkProtocol = new NetworkProtocol();
    6767  this->connectionMonitor = new ConnectionMonitor();
     68  this->networkSockets.push_back( NULL );
     69  this->bActive = true;
    6870}
    6971
     
    111113void NetworkStream::processData()
    112114{
     115  printf("processData()");
     116  if ( this->type == NET_SERVER )
     117    this->updateConnectionList();
     118
    113119#if 0
    114120  int dataLength = 0;
     
    178184#endif
    179185}
     186
     187void NetworkStream::updateConnectionList( )
     188{
     189  //check for new connections
     190  NetworkSocket* tempNetworkSocket = serverSocket->getNewSocket();
     191
     192  if ( tempNetworkSocket )
     193  {
     194    int clientId;
     195    if ( freeSocketSlots.size() >0 )
     196    {
     197      clientId = freeSocketSlots.back();
     198      freeSocketSlots.pop_back();
     199      networkSockets[clientId] = tempNetworkSocket;
     200    } else
     201    {
     202      networkSockets.push_back(tempNetworkSocket);
     203      clientId = networkSockets.size();
     204    }
     205
     206    PRINTF(0)("New Client: %s", clientId);
     207    //TODO: start handshake
     208    //new Handshake(true, clientId);
     209  }
     210
     211
     212  //check if connections are ok else remove them
     213  for ( int i = 1; i<networkSockets.size(); i++)
     214  {
     215    if ( networkSockets[i] && !networkSockets[i]->isOk() )
     216    {
     217      //TODO: tell EntityManager that this player left the game
     218
     219      delete networkSockets[i];
     220      networkSockets[i] = NULL;
     221
     222      if ( i == networkSockets.size()-1 )
     223      {
     224        networkSockets.pop_back();
     225      }
     226      else
     227      {
     228        freeSocketSlots.push_back(i);
     229      }
     230    }
     231  }
     232
     233}
  • branches/network/src/lib/network/network_stream.h

    r6007 r6018  
    5151    Header                 packetHeader;
    5252    bool                   bActive;
     53    std::list<int>         freeSocketSlots;
     54
     55    void updateConnectionList();
    5356};
    5457#endif /* _NETWORK_STREAM */
  • branches/network/src/lib/network/server_socket.cc

    r6007 r6018  
    110110
    111111
    112 NetworkSocket ServerSocket::getNewSocket( )
     112NetworkSocket* ServerSocket::getNewSocket( )
    113113{
    114114  if ( !listenSocket )
     
    127127  else
    128128  {
    129     return NetworkSocket(sock);
     129    return new NetworkSocket(sock);
    130130  }
    131131}
  • branches/network/src/lib/network/server_socket.h

    r6007 r6018  
    3939    ~ServerSocket();
    4040    bool listen( unsigned int port );
    41     NetworkSocket getNewSocket( void );
     41    NetworkSocket* getNewSocket( void );
    4242    void close();
     43    inline bool isOk(){ return listenSocket!=NULL; }
    4344};
    4445
  • branches/network/src/subprojects/network/network_unit_test.cc

    r5996 r6018  
    4242  NetworkSocket client1(ip);
    4343
    44   NetworkSocket server1 = server.getNewSocket();
     44  NetworkSocket* server1 = server.getNewSocket();
    4545
    4646  NetworkSocket client2(ip);
    4747
    48   NetworkSocket server2 = server.getNewSocket();
     48  NetworkSocket* server2 = server.getNewSocket();
    4949
    5050  char buf[1024];
     
    6363  n = client1.writePacket((byte*)str1, strlen(str1)+1);
    6464  printf("%d bytes send from client1\n", n);
    65   n = server1.writePacket((byte*)str2, strlen(str2)+1);
     65  n = server1->writePacket((byte*)str2, strlen(str2)+1);
    6666  printf("%d bytes send from server1\n", n);
    6767  n = client2.writePacket((byte*)str3, strlen(str3)+1);
    6868  printf("%d bytes send from client2\n", n);
    69   n = server2.writePacket((byte*)str4, strlen(str4)+1);
     69  n = server2->writePacket((byte*)str4, strlen(str4)+1);
    7070  printf("%d bytes send from server2\n", n);
    7171  SDL_Delay(1000);
    7272
    7373  printf("read from server1\n");
    74   n = server1.readPacket((byte*)buf, 1024);
     74  n = server1->readPacket((byte*)buf, 1024);
    7575  printf("read %d bytes\n", n);
    7676  if (n<0)
     
    8080
    8181  printf("read from server2\n");
    82   n = server2.readPacket((byte*)buf, 1024);
     82  n = server2->readPacket((byte*)buf, 1024);
    8383  printf("read %d bytes\n", n);
    8484  if (n<0)
     
    108108  printf("result: %d\n", client1.writePacket((byte*)buf, 1000));
    109109
    110   server1.writePacket((byte*)str1, strlen(str1)+1);
     110  server1->writePacket((byte*)str1, strlen(str1)+1);
    111111  SDL_Delay(500);
    112112  printf("try to read with a too small buffer\n");
  • branches/network/src/util/loading/game_loader.h

    r5982 r6018  
    4747  ErrorMessage init();
    4848  ErrorMessage loadCampaign(const char* name);
     49  ErrorMessage loadNetworkCampaign(const char* fileName);
    4950  ErrorMessage start();
    5051  void stop();
     
    6667
    6768  Campaign* fileToCampaign(const char* name);
     69  Campaign* fileToNetworkCampaign(const char* fileName);
    6870
    6971 private:
Note: See TracChangeset for help on using the changeset viewer.