Index: code/branches/network/src/network/Server.cc
===================================================================
--- code/branches/network/src/network/Server.cc	(revision 1699)
+++ code/branches/network/src/network/Server.cc	(revision 1705)
@@ -45,6 +45,5 @@
 
 #include "ConnectionManager.h"
-#include "PacketTypes.h"
-#include "GameStateManager.h"
+#include "GamestateManager.h"
 #include "ClientInformation.h"
 #include "util/Sleep.h"
@@ -53,4 +52,5 @@
 #include "packet/Chat.h"
 #include "packet/Packet.h"
+#include "packet/Welcome.h"
 
 namespace network
@@ -65,14 +65,12 @@
   Server::Server() {
     timeSinceLastUpdate_=0;
-    packet_gen = PacketGenerator();
     connection = new ConnectionManager();
-    gamestates = new GameStateManager();
+    gamestates_ = new GamestateManager();
   }
   
   Server::Server(int port){
     timeSinceLastUpdate_=0;
-    packet_gen = PacketGenerator();
     connection = new ConnectionManager(port);
-    gamestates = new GameStateManager();
+    gamestates_ = new GamestateManager();
   }
 
@@ -84,7 +82,6 @@
   Server::Server(int port, std::string bindAddress) {
     timeSinceLastUpdate_=0;
-    packet_gen = PacketGenerator();
     connection = new ConnectionManager(port, bindAddress);
-    gamestates = new GameStateManager();
+    gamestates_ = new GamestateManager();
   }
 
@@ -96,7 +93,6 @@
   Server::Server(int port, const char *bindAddress) {
     timeSinceLastUpdate_=0;
-    packet_gen = PacketGenerator();
     connection = new ConnectionManager(port, bindAddress);
-    gamestates = new GameStateManager();
+    gamestates_ = new GamestateManager();
   }
 
@@ -173,5 +169,5 @@
       timeSinceLastUpdate_=(float)((int)(timeSinceLastUpdate_*NETWORK_FREQUENCY))/timeSinceLastUpdate_;
 //      timeSinceLastUpdate_-=1./NETWORK_FREQUENCY;
-      gamestates->processGameStates();
+      gamestates_->processGamestates();
       updateGamestate();
     }
@@ -191,5 +187,4 @@
   void Server::processQueue() {
     ENetEvent *event;
-    int clientID=-1;
     while(!connection->queueEmpty()){
       //std::cout << "Client " << clientID << " sent: " << std::endl;
@@ -209,9 +204,6 @@
         break;
       case ENET_EVENT_TYPE_RECEIVE:
-        if(ClientInformation::findClient(&event->peer->address)){
-          clientID = ClientInformation::findClient(&event->peer->address)->getID();
-          if( !elaborate(event->packet, clientID) ) 
-            COUT(3) << "Server: could not elaborate" << std::endl;
-        }
+        if(!processPacket(event->packet, event->peer))
+          COUT(3) << "processing incoming packet failed" << std::endl;
         break;
       default:
@@ -227,5 +219,5 @@
   */
   void Server::updateGamestate() {
-    gamestates->update();
+    gamestates_->update();
     COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
     //std::cout << "updated gamestate, sending it" << std::endl;
@@ -236,4 +228,9 @@
   }
 
+  bool Server::processPacket( ENetPacket *packet, ENetPeer *peer ){
+    packet::Packet p = packet::Packet(packet, peer);
+    return p.getPacketContent()->process();
+  }
+  
   /**
   * sends the gamestate
@@ -257,5 +254,5 @@
       int cid = temp->getID(); //get client id
       COUT(5) << "Server: got acked (gamestate) ID from clientlist: " << gid << std::endl;
-      GameStateCompressed *gs = gamestates->popGameState(cid);
+      packet::Gamestate *gs = gamestates_->popGameState(cid);
       if(gs==NULL){
         COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl;
@@ -263,8 +260,7 @@
       }
       //std::cout << "adding gamestate" << std::endl;
-      ENetPacket *packet = packet_gen.gstate(gs);
-      if(!packet)
-	continue;
-      if ( !(connection->addPacket(packet, cid)) ){
+      packet::Packet packet(gs);
+      packet.setClientID(cid);
+      if ( !packet.send() ){
         COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 
         temp->addFailure();
@@ -277,5 +273,4 @@
       temp=temp->next();
       // now delete gamestate
-      delete[] gs->data;
       delete gs;
     }
@@ -286,32 +281,4 @@
     //COUT(5) << "Server: had no gamestates to send" << std::endl;
     return true;
-  }
-
-  void Server::processAck( ack *data, int clientID) {
-    COUT(4) << "Server: processing ack from client: " << clientID << "; ack-id: " << data->a << std::endl;
-    gamestates->ackGameState(clientID, data->a);
-    delete data;
-  }
-  
-  bool Server::processConnectRequest( connectRequest *con, int clientID ){
-    //(COUT(3) << "processing connectRequest " << std::endl;
-    //connection->addPacket(packet_gen.gstate(gamestates->popGameState(clientID)) , clientID);
-    //createClient(clientID);
-    delete con;
-    return true;
-  }
-  
-  bool Server::ackGamestateID(int gamestateID, int clientID){
-    gamestates->ackGameState(clientID, gamestateID);
-    return true;
-  }
-  
-  void Server::processGamestate( GameStateCompressed *data, int clientID){
-    COUT(4) << "processing partial gamestate from client " << clientID << std::endl;
-    gamestates->addGameState(data, clientID);
-        /*COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl;
-    else
-      if(clients->findClient(clientID))
-        clients->findClient(clientID)->resetFailures();*/
   }
   
@@ -359,5 +326,6 @@
     temp->setSynched(true);
     COUT(3) << "sending welcome" << std::endl;
-    connection->sendWelcome(temp->getID(), temp->getShipID(), true);
+    packet::Packet packet(new packet::Welcome(temp->getID(), temp->getShipID()));
+    assert(packet.send());
     return true;
   }
@@ -421,5 +389,5 @@
   void Server::disconnectClient( ClientInformation *client){
     connection->disconnectClient(client);
-    gamestates->removeClient(client);
+    gamestates_->removeClient(client);
   }
   
