Index: server/server.cpp
===================================================================
--- server/server.cpp	(revision 402cf86857bd74889d5f5ddc68a7ee9ebd44c16a)
+++ server/server.cpp	(revision ce2bb8713e893a7b12416d609f4f11969ca936f3)
@@ -153,4 +153,6 @@
 
          map<unsigned int, Player*>::iterator it;
+
+         cout << "Updating player targets and respawning dead players" << endl;
 
          // set targets for all chasing players (or make them attack if they're close enough)
@@ -216,8 +218,14 @@
          }
 
+         cout << "Processing players in a game" << endl;
+
          // process players currently in a game
          FLOAT_POSITION oldPos;
          for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
          {
+            if (it->second->currentGame == NULL)
+               continue;
+
+            cout << "moving player" << endl;
             bool broadcastMove = false;
 
@@ -226,6 +234,8 @@
             if (it->second->move(it->second->currentGame->getMap())) {
 
+               cout << "player moved" << endl;
                if (it->second->currentGame->processPlayerMovement(it->second, oldPos))
                    broadcastMove = true;
+               cout << "player move processed" << endl;
 
                /*
@@ -386,4 +396,5 @@
                if (broadcastMove)
                {
+                  cout << "broadcasting player move" << endl;
                   serverMsg.type = MSG_TYPE_PLAYER;
                   it->second->serialize(serverMsg.buffer);
@@ -394,11 +405,14 @@
                   map<unsigned int, Player*> playersInGame = it->second->currentGame->getPlayers();
                   map<unsigned int, Player*>::iterator it2;
-                  for (it2 = playersInGame.begin(); it2 != playersInGamePlayers.end(); it2++)
+                  for (it2 = playersInGame.begin(); it2 != playersInGame.end(); it2++)
                   {
                      if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 )
                         error("sendMessage");
                   }
-               }
-            }
+                  cout << "done broadcasting player move" << endl;
+               }
+            }
+
+            cout << "processing player attack" << endl;
 
             // check if the player's attack animation is complete
@@ -476,4 +490,6 @@
             }
          }
+
+         cout << "Processing projectiles"  << endl;
 
          // move all projectiles
@@ -540,4 +556,5 @@
             cout << "Should be broadcasting the message" << endl;
 
+            // needs to be updated to use the players from the game
             map<unsigned int, Player*>::iterator it;
             for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
@@ -555,4 +572,6 @@
                error("sendMessage");
          }
+
+         cout << "Finished processing the message" << endl;
       }
    }
@@ -651,4 +670,5 @@
             cout << "new player id: " << p->id << endl;
             p->setAddr(from);
+            p->currentGame = NULL;
 
             // choose a random team (either 0 or 1)
@@ -835,52 +855,21 @@
 
          Player* p = mapPlayers[id];
-
-         vector<WorldMap::Object>* vctObjects = gameMap->getObjects();
-         vector<WorldMap::Object>::iterator itObjects;
-
-         for (itObjects = vctObjects->begin(); itObjects != vctObjects->end();) {
-            POSITION pos = itObjects->pos;
-            bool gotFlag = false;
-
-            if (posDistance(p->pos, pos.toFloat()) < 10) {
-               switch (itObjects->type) {
-                  case WorldMap::OBJECT_BLUE_FLAG:
-                     if (p->team == 1) {
-                        gotFlag = true;
-                        p->hasBlueFlag = true;
-                        broadcastResponse = true;
-                     }
-                     break;
-                  case WorldMap::OBJECT_RED_FLAG:
-                     if (p->team == 0) {
-                        gotFlag = true;
-                        p->hasRedFlag = true;
-                        broadcastResponse = true;
-                     }
-                     break;
-               }
-
-               if (gotFlag) {
-                  serverMsg.type = MSG_TYPE_REMOVE_OBJECT;
-                  memcpy(serverMsg.buffer, &itObjects->id, 4);
-
-                  map<unsigned int, Player*>::iterator it;
-                  for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
-                  {
-                     if ( msgProcessor.sendMessage(&serverMsg, sock, &(it->second->addr), &outputLog) < 0 )
-                        error("sendMessage");
-                  }
-
-                  // remove the object from the server-side map
-                  cout << "size before: " << gameMap->getObjects()->size() << endl;
-                  itObjects = vctObjects->erase(itObjects);
-                  cout << "size after: " << gameMap->getObjects()->size() << endl;
-               }
-            }
-
-            if (!gotFlag)
-               itObjects++;
-         }
-
+         int objectId = p->currentGame->processFlagPickupRequest(p);
+
+         if (objectId >= 0) {
+            serverMsg.type = MSG_TYPE_REMOVE_OBJECT;
+            memcpy(serverMsg.buffer, &objectId, 4);
+
+            map<unsigned int, Player*> players = p->currentGame->getPlayers();
+            map<unsigned int, Player*>::iterator it;
+            for (it = players.begin(); it != players.end(); it++)
+            {
+               if ( msgProcessor.sendMessage(&serverMsg, sock, &(it->second->addr), &outputLog) < 0 )
+                  error("sendMessage");
+            }
+
+         }
+
+         // if there was no flag to pickup, we really don't need to send a message
          serverMsg.type = MSG_TYPE_PLAYER;
          p->serialize(serverMsg.buffer);
