Index: server/server.cpp
===================================================================
--- server/server.cpp	(revision 694c3d24960a9af711962a12d5d064eae0f3762d)
+++ server/server.cpp	(revision 9b5d30bd77df410865678bf12cc80310383b1346)
@@ -29,4 +29,5 @@
 #include "../common/Common.h"
 #include "../common/Message.h"
+#include "../common/MessageProcessor.h"
 #include "../common/WorldMap.h"
 #include "../common/Player.h"
@@ -39,5 +40,5 @@
 // from used to be const. Removed that so I could take a reference
 // and use it to send messages
-bool processMessage(const NETWORK_MSG &clientMsg, struct sockaddr_in &from, map<unsigned int, Player>& mapPlayers, WorldMap* gameMap, unsigned int& unusedPlayerId, NETWORK_MSG &serverMsg, int sock, int &scoreBlue, int &scoreRed);
+bool processMessage(const NETWORK_MSG &clientMsg, struct sockaddr_in &from, MessageProcessor &msgProcessor, map<unsigned int, Player>& mapPlayers, WorldMap* gameMap, unsigned int& unusedPlayerId, NETWORK_MSG &serverMsg, int sock, int &scoreBlue, int &scoreRed);
 
 void updateUnusedPlayerId(unsigned int& id, map<unsigned int, Player>& mapPlayers);
@@ -85,4 +86,5 @@
    struct sockaddr_in from; // info of client sending the message
    NETWORK_MSG clientMsg, serverMsg;
+   MessageProcessor msgProcessor;
    map<unsigned int, Player> mapPlayers;
    map<unsigned int, Projectile> mapProjectiles;
@@ -146,4 +148,6 @@
       if (timeLastUpdated == 0 || (curTime-timeLastUpdated) >= 50) {
          timeLastUpdated = curTime;
+
+         msgProcessor.resendUnackedMessages(sock);
 
          map<unsigned int, Player>::iterator it;
@@ -185,5 +189,5 @@
                   for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
                   {
-                     if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
+                     if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
                         error("sendMessage");
                   }
@@ -200,5 +204,5 @@
                for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
                {
-                  if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
+                  if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
                      error("sendMessage");
                }
@@ -313,5 +317,5 @@
                   for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
                   {
-                     if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
+                     if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
                         error("sendMessage");
                   }
@@ -323,5 +327,5 @@
                   for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
                   {
-                     if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
+                     if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
                         error("sendMessage");
                   }
@@ -364,5 +368,5 @@
                   for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
                   {
-                     if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
+                     if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
                         error("sendMessage");
                   }
@@ -377,5 +381,5 @@
                   for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
                   {
-                     if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
+                     if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
                         error("sendMessage");
                   }
@@ -398,5 +402,5 @@
                for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
                {
-                  if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
+                  if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
                      error("sendMessage");
                }
@@ -434,5 +438,5 @@
                for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
                {
-                  if (sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
+                  if (msgProcessor.sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
                      error("sendMessage");
                }
@@ -456,5 +460,5 @@
                for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
                {
-                  if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
+                  if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
                      error("sendMessage");
                }
@@ -472,5 +476,5 @@
                for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
                {
-                  if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
+                  if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
                      error("sendMessage");
                }
@@ -480,5 +484,5 @@
       }
 
-      n = receiveMessage(&clientMsg, sock, &from);
+      n = msgProcessor.receiveMessage(&clientMsg, sock, &from);
 
       if (n >= 0) {
@@ -493,5 +497,5 @@
             {
                cout << "Sent message back to " << it->second.name << endl;
-               if ( sendMessage(&serverMsg, sock, &(it->second.addr)) < 0 )
+               if ( msgProcessor.sendMessage(&serverMsg, sock, &(it->second.addr)) < 0 )
                   error("sendMessage");
             }
@@ -501,5 +505,5 @@
             cout << "Should be sending back the message" << endl;
 
-            if ( sendMessage(&serverMsg, sock, &from) < 0 )
+            if ( msgProcessor.sendMessage(&serverMsg, sock, &from) < 0 )
                error("sendMessage");
          }
@@ -510,5 +514,5 @@
 }
 
-bool processMessage(const NETWORK_MSG& clientMsg, struct sockaddr_in& from, map<unsigned int, Player>& mapPlayers, WorldMap* gameMap, unsigned int& unusedPlayerId, NETWORK_MSG& serverMsg, int sock, int &scoreBlue, int &scoreRed)
+bool processMessage(const NETWORK_MSG &clientMsg, struct sockaddr_in &from, MessageProcessor &msgProcessor, map<unsigned int, Player>& mapPlayers, WorldMap* gameMap, unsigned int& unusedPlayerId, NETWORK_MSG &serverMsg, int sock, int &scoreBlue, int &scoreRed)
 {
    DataAccess da;
@@ -595,5 +599,5 @@
                cout << "sending info about " << it->second.name  << endl;
                cout << "sending id " << it->second.id  << endl;
-               if ( sendMessage(&serverMsg, sock, &from) < 0 )
+               if ( msgProcessor.sendMessage(&serverMsg, sock, &from) < 0 )
                   error("sendMessage");
             }
@@ -608,5 +612,5 @@
                itObjects->serialize(serverMsg.buffer);
                cout << "sending item id " << itObjects->id  << endl;
-               if ( sendMessage(&serverMsg, sock, &from) < 0 )
+               if ( msgProcessor.sendMessage(&serverMsg, sock, &from) < 0 )
                   error("sendMessage");
             }
@@ -616,5 +620,5 @@
             memcpy(serverMsg.buffer, &scoreBlue, 4);
             memcpy(serverMsg.buffer+4, &scoreRed, 4);
-            if ( sendMessage(&serverMsg, sock, &from) < 0 )
+            if ( msgProcessor.sendMessage(&serverMsg, sock, &from) < 0 )
                error("sendMessage");
 
@@ -626,5 +630,5 @@
             {
                cout << "Sent message back to " << it->second.name << endl;
-               if ( sendMessage(&serverMsg, sock, &(it->second.addr)) < 0 )
+               if ( msgProcessor.sendMessage(&serverMsg, sock, &(it->second.addr)) < 0 )
                   error("sendMessage");
             }
@@ -779,5 +783,5 @@
                   for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
                   {
-                     if ( sendMessage(&serverMsg, sock, &(it->second.addr)) < 0 )
+                     if ( msgProcessor.sendMessage(&serverMsg, sock, &(it->second.addr)) < 0 )
                         error("sendMessage");
                   }
@@ -824,5 +828,5 @@
          for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
          {
-            if ( sendMessage(&serverMsg, sock, &(it->second.addr)) < 0 )
+            if ( msgProcessor.sendMessage(&serverMsg, sock, &(it->second.addr)) < 0 )
                error("sendMessage");
          }
