Index: code/trunk/src/libraries/network/Server.cc
===================================================================
--- code/trunk/src/libraries/network/Server.cc	(revision 7801)
+++ code/trunk/src/libraries/network/Server.cc	(revision 8327)
@@ -57,5 +57,5 @@
 #include "packet/Welcome.h"
 #include "ChatListener.h"
-#include "ClientInformation.h"
+// #include "ClientInformation.h"
 #include "FunctionCallManager.h"
 #include "GamestateManager.h"
@@ -152,13 +152,13 @@
   bool Server::processChat(const std::string& message, unsigned int playerID)
   {
-    ClientInformation *temp = ClientInformation::getBegin();
+//     ClientInformation *temp = ClientInformation::getBegin();
     packet::Chat *chat;
-    while(temp){
-      chat = new packet::Chat(message, playerID);
-      chat->setPeerID(temp->getID());
-      if(!chat->send( static_cast<Host*>(this) ))
-        COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
-      temp = temp->next();
-    }
+//     while(temp){
+    chat = new packet::Chat(message, playerID);
+    chat->setPeerID(NETWORK_PEER_ID_BROADCAST);
+    chat->send( static_cast<Host*>(this) );
+//         COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
+//       temp = temp->next();
+//     }
 //    COUT(1) << "Player " << playerID << ": " << message << std::endl;
     return true;
@@ -207,5 +207,5 @@
     //helper_HandleMasterServerRequests();
 
-    if ( ClientInformation::hasClients() )
+    if ( GamestateManager::hasPeers() )
     {
       // process incoming gamestates
@@ -237,12 +237,14 @@
   unsigned int Server::getRTT(unsigned int clientID)
   {
-    assert(ClientInformation::findClient(clientID));
-    return ClientInformation::findClient(clientID)->getRTT();
+//     assert(ClientInformation::findClient(clientID));
+//     return ClientInformation::findClient(clientID)->getRTT();
+    // TODO: reimplement
+    return 0;
   }
 
   void Server::printRTT()
   {
-    for( ClientInformation* temp=ClientInformation::getBegin(); temp!=0; temp=temp->next() )
-      COUT(0) << "Round trip time to client with ID: " << temp->getID() << " is " << temp->getRTT() << " ms" << endl;
+//     for( ClientInformation* temp=ClientInformation::getBegin(); temp!=0; temp=temp->next() )
+//       COUT(0) << "Round trip time to client with ID: " << temp->getID() << " is " << temp->getRTT() << " ms" << endl;
   }
 
@@ -252,6 +254,7 @@
   double Server::getPacketLoss(unsigned int clientID)
   {
-    assert(ClientInformation::findClient(clientID));
-    return ClientInformation::findClient(clientID)->getPacketLoss();
+//     assert(ClientInformation::findClient(clientID));
+//     return ClientInformation::findClient(clientID)->getPacketLoss();
+    return 0.;
   }
 
@@ -261,5 +264,5 @@
   void Server::updateGamestate()
   {
-    if( ClientInformation::getBegin()==NULL )
+    if( this->clientIDs_.size()==0 )
       //no client connected
       return;
@@ -291,7 +294,8 @@
   bool Server::sendObjectDeletes()
   {
-    ClientInformation *temp = ClientInformation::getBegin();
-    if( temp == NULL )
+//     ClientInformation *temp = ClientInformation::getBegin();
+//     if( temp == NULL )
       //no client connected
+    if( this->clientIDs_.size()==0 )
       return true;
     packet::DeleteObjects *del = new packet::DeleteObjects();
@@ -302,61 +306,72 @@
     }
 //     COUT(3) << "sending DeleteObjects" << std::endl;
-    while(temp != NULL){
-      if( !(temp->getSynched()) )
-      {
-        COUT(5) << "Server: not sending gamestate" << std::endl;
-        temp=temp->next();
-        continue;
-      }
-      int cid = temp->getID(); //get client id
-      packet::DeleteObjects *cd = new packet::DeleteObjects(*del);
-      assert(cd);
-      cd->setPeerID(cid);
-      if ( !cd->send( static_cast<Host*>(this) ) )
-        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended" << std::endl;
-      temp=temp->next();
+//     while(temp != NULL){
+//       if( !(temp->getSynched()) )
+//       {
+//         COUT(5) << "Server: not sending gamestate" << std::endl;
+//         temp=temp->next();
+//         continue;
+//       }
+//       int cid = temp->getID(); //get client id
+//       packet::DeleteObjects *cd = new packet::DeleteObjects(*del);
+//       assert(cd);
+    del->setPeerID(NETWORK_PEER_ID_BROADCAST);
+    if ( !del->send( static_cast<Host*>(this) ) )
+      COUT(3) << "Server: could not broadcast deleteObjects packet" << std::endl;
+//       temp=temp->next();
       // gs gets automatically deleted by enet callback
-    }
-    delete del;
+//     }
+//     delete del;
     return true;
   }
 
 
-  void Server::addPeer(ENetEvent *event)
-  {
-    static unsigned int newid=1;
-
-    COUT(2) << "Server: adding client" << std::endl;
-    ClientInformation *temp = ClientInformation::insertBack(new ClientInformation);
-    if(!temp)
-    {
-      COUT(2) << "Server: could not add client" << std::endl;
-    }
-    temp->setID(newid);
-    temp->setPeer(event->peer);
+  void Server::addPeer(uint32_t peerID)
+  {
+//     static unsigned int newid=1;
+// 
+//     COUT(2) << "Server: adding client" << std::endl;
+//     ClientInformation *temp = ClientInformation::insertBack(new ClientInformation);
+//     if(!temp)
+//     {
+//       COUT(2) << "Server: could not add client" << std::endl;
+//     }
+//     temp->setID(newid);
+//     temp->setPeer(event->peer);
 
     // inform all the listeners
-    ClientConnectionListener::broadcastClientConnected(newid);
-    GamestateManager::addPeer(newid);
-
-    ++newid;
-
-    COUT(3) << "Server: added client id: " << temp->getID() << std::endl;
-    createClient(temp->getID());
+    this->clientIDs_.push_back(peerID);
+    ClientConnectionListener::broadcastClientConnected(peerID);
+    GamestateManager::addPeer(peerID);
+
+//     ++newid;
+
+    COUT(3) << "Server: added client id: " << peerID << std::endl;
+    createClient(peerID);
 }
 
-  void Server::removePeer(ENetEvent *event)
+  void Server::removePeer(uint32_t peerID)
   {
     COUT(4) << "removing client from list" << std::endl;
-    ClientInformation *client = ClientInformation::findClient(&event->peer->address);
-    if(!client)
-      return;
-    else
-    {
-      GamestateManager::removePeer(client->getID());
+//     ClientInformation *client = ClientInformation::findClient(&event->peer->address);
+//     if(!client)
+//       return;
+//     else
+//     {
+  std::vector<uint32_t>::iterator it;
+  for( it=this->clientIDs_.begin(); it!=this->clientIDs_.end(); ++it )
+  {
+    if( *it == peerID )
+    {
+      this->clientIDs_.erase(it);
+      break;
+    }
+  }
+  ClientConnectionListener::broadcastClientDisconnected(peerID);
+  GamestateManager::removePeer(peerID);
       //ServerConnection::disconnectClient( client );
       //ClientConnectionListener::broadcastClientDisconnected( client->getID() ); //this is done in ClientInformation now
-      delete client;
-    }
+//       delete client;
+//     }
   }
   
@@ -365,5 +380,5 @@
     if( packet->isReliable() )
     {
-      if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )
+      if( this->getLastReceivedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )
         packet->process(static_cast<Host*>(this));
       else
@@ -377,14 +392,14 @@
   bool Server::createClient(int clientID)
   {
-    ClientInformation *temp = ClientInformation::findClient(clientID);
-    if(!temp)
-    {
-      COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;
-      return false;
-    }
-    COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
+//     ClientInformation *temp = ClientInformation::findClient(clientID);
+//     if(!temp)
+//     {
+//       COUT(2) << "Server. could not create client with id: " << clientID << std::endl;
+//       return false;
+//     }
+//     COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
 
     // synchronise class ids
-    syncClassid(temp->getID());
+    syncClassid(clientID);
 
     // now synchronise functionIDs
@@ -394,29 +409,29 @@
     assert(b);
 
-    temp->setSynched(true);
+//     temp->setSynched(true);
     GamestateManager::setSynched(clientID);
     
     COUT(4) << "sending welcome" << std::endl;
-    packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID());
-    w->setPeerID(temp->getID());
+    packet::Welcome *w = new packet::Welcome(clientID, OBJECTID_UNKNOWN);
+    w->setPeerID(clientID);
     b = w->send( static_cast<Host*>(this) );
     assert(b);
-    packet::Gamestate *g = new packet::Gamestate();
-    g->setPeerID(temp->getID());
-    b = g->collectData(0,packet::GAMESTATE_MODE_SERVER);
-    assert(b);
-    if(!b)
-      return false; //no data for the client
-//     b = g->compressData();
+//     packet::Gamestate *g = new packet::Gamestate();
+//     g->setPeerID(clientID);
+//     b = g->collectData(0,packet::GAMESTATE_MODE_SERVER);
 //     assert(b);
-    b = g->send( static_cast<Host*>(this) );
-    assert(b);
+//     if(!b)
+//       return false; //no data for the client
+// //     b = g->compressData();
+// //     assert(b);
+//     b = g->send( static_cast<Host*>(this) );
+//     assert(b);
     return true;
   }
 
-  void Server::disconnectClient( ClientInformation *client )
-  {
-    ServerConnection::disconnectClient( client );
-    GamestateManager::removePeer(client->getID());
+  void Server::disconnectClient( uint32_t clientID )
+  {
+    ServerConnection::disconnectClient( clientID );
+    GamestateManager::removePeer( clientID );
     // inform all the listeners
     // ClientConnectionListener::broadcastClientDisconnected(client->getID()); // this is done in ClientInformation now
@@ -430,18 +445,18 @@
   bool Server::broadcast(const std::string& message)
   {
-      return this->sendChat(message, CLIENTID_UNKNOWN);
+      return this->sendChat(message, NETWORK_PEER_ID_BROADCAST);
   }
 
   bool Server::sendChat(const std::string& message, unsigned int clientID)
   {
-    ClientInformation *temp = ClientInformation::getBegin();
+//     ClientInformation *temp = ClientInformation::getBegin();
     packet::Chat *chat;
-    while(temp)
+//     while(temp)
     {
       chat = new packet::Chat(message, clientID);
-      chat->setPeerID(temp->getID());
-      if(!chat->send( static_cast<Host*>(this) ))
-        COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
-      temp = temp->next();
+      chat->setPeerID(NETWORK_PEER_ID_BROADCAST);
+      chat->send( static_cast<Host*>(this) );
+//         COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
+//       temp = temp->next();
     }
 //    COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl;
