Index: .gitignore
===================================================================
--- .gitignore	(revision cdb0e982399ace2b3ddec199a997d4b76be56ae0)
+++ .gitignore	(revision 53643cad0b21a051f5301ad161c43380ff3b29d8)
@@ -8,4 +8,4 @@
 *.log
 gameClient
-server
+gameServer
 graphics_engine
Index: common/Game.cpp
===================================================================
--- common/Game.cpp	(revision cdb0e982399ace2b3ddec199a997d4b76be56ae0)
+++ common/Game.cpp	(revision 53643cad0b21a051f5301ad161c43380ff3b29d8)
@@ -217,6 +217,5 @@
    p->takeDamage(damage);
 
-   if (p->isDead)
-   {
+   if (p->isDead) {
       ObjectType flagType = OBJECT_NONE;
       if (p->hasBlueFlag)
@@ -240,13 +239,10 @@
    bool gameFinished = false;
 
-   for (it = this->getPlayers().begin(); it != this->getPlayers().end(); it++)
-   {
-      gameFinished = gameFinished ||
-         this->handlePlayerEvents(it->second);
+   for (it = this->getPlayers().begin(); it != this->getPlayers().end(); it++) {
+      gameFinished = gameFinished || this->handlePlayerEvents(it->second);
    }
 
    if (gameFinished) {
-      for (it = this->players.begin(); it != this->players.end(); it++)
-      {
+      for (it = this->players.begin(); it != this->players.end(); it++) {
          it->second->currentGame = NULL;
       }
@@ -279,10 +275,8 @@
       bool ownFlagAtBase = false;
 
-      switch(this->worldMap->getStructure(p->pos.x/25, p->pos.y/25))
-      {
+      switch(this->worldMap->getStructure(p->pos.x/25, p->pos.y/25)) {
          case STRUCTURE_BLUE_FLAG:
          {
-            if (p->team == 0 && p->hasRedFlag)
-            {
+            if (p->team == 0 && p->hasRedFlag) {
                // check that your flag is at your base
                pos = this->worldMap->getStructureLocation(STRUCTURE_BLUE_FLAG);
@@ -291,10 +285,7 @@
                vector<WorldMap::Object>::iterator itObjects;
 
-               for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++)
-               {
-                  if (itObjects->type == OBJECT_BLUE_FLAG)
-                  {
-                     if (itObjects->pos.x == pos.x*25+12 && itObjects->pos.y == pos.y*25+12)
-                     {
+               for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++) {
+                  if (itObjects->type == OBJECT_BLUE_FLAG) {
+                     if (itObjects->pos.x == pos.x*25+12 && itObjects->pos.y == pos.y*25+12) {
                         ownFlagAtBase = true;
                         break;
@@ -303,6 +294,5 @@
                }
 
-               if (ownFlagAtBase)
-               {
+               if (ownFlagAtBase) {
                   p->hasRedFlag = false;
                   flagType = OBJECT_RED_FLAG;
@@ -317,6 +307,5 @@
          case STRUCTURE_RED_FLAG:
          {
-            if (p->team == 1 && p->hasBlueFlag)
-            {
+            if (p->team == 1 && p->hasBlueFlag) {
                // check that your flag is at your base
                pos = this->worldMap->getStructureLocation(STRUCTURE_RED_FLAG);
@@ -325,10 +314,7 @@
                vector<WorldMap::Object>::iterator itObjects;
 
-               for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++)
-               {
-                  if (itObjects->type == OBJECT_RED_FLAG)
-                  {
-                     if (itObjects->pos.x == pos.x*25+12 && itObjects->pos.y == pos.y*25+12)
-                     {
+               for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++) {
+                  if (itObjects->type == OBJECT_RED_FLAG) {
+                     if (itObjects->pos.x == pos.x*25+12 && itObjects->pos.y == pos.y*25+12) {
                         ownFlagAtBase = true;
                         break;
@@ -337,6 +323,5 @@
                }
 
-               if (ownFlagAtBase)
-               {
+               if (ownFlagAtBase) {
                   p->hasBlueFlag = false;
                   flagType = OBJECT_BLUE_FLAG;
@@ -355,6 +340,5 @@
       }
 
-      if (flagTurnedIn)
-      {
+      if (flagTurnedIn) {
          unsigned int blueScore = this->blueScore;
          unsigned int redScore = this->redScore;
@@ -399,20 +383,13 @@
       POSITION structPos;
 
-      for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++)
-      {
+      for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++) {
          POSITION pos = itObjects->pos;
 
-         if (posDistance(p->pos, pos.toFloat()) < 10)
-         {
-            if (p->team == 0 && 
-                itObjects->type == OBJECT_BLUE_FLAG)
-            {
+         if (posDistance(p->pos, pos.toFloat()) < 10) {
+            if (p->team == 0 && itObjects->type == OBJECT_BLUE_FLAG) {
                structPos = this->worldMap->getStructureLocation(STRUCTURE_BLUE_FLAG);
                flagReturned = true;
                break;
-            }
-            else if (p->team == 1 &&
-                     itObjects->type == OBJECT_RED_FLAG)
-            {
+            } else if (p->team == 1 && itObjects->type == OBJECT_RED_FLAG) {
                structPos = this->worldMap->getStructureLocation(STRUCTURE_RED_FLAG);
                flagReturned = true;
@@ -422,6 +399,5 @@
       }
 
-      if (flagReturned)
-      {
+      if (flagReturned) {
          itObjects->pos.x = structPos.x*25+12;
          itObjects->pos.y = structPos.y*25+12;
@@ -432,6 +408,5 @@
       }
 
-      if (broadcastMove)
-      {
+      if (broadcastMove) {
          serverMsg.type = MSG_TYPE_PLAYER;
          p->serialize(serverMsg.buffer);
@@ -443,6 +418,5 @@
 
    // check if the player's attack animation is complete
-   if (p->isAttacking && p->timeAttackStarted+p->attackCooldown <= getCurrentMillis())
-   {
+   if (p->isAttacking && p->timeAttackStarted+p->attackCooldown <= getCurrentMillis()) {
       p->isAttacking = false;
       cout << "Attack animation is complete" << endl;
@@ -451,13 +425,10 @@
       cout << "about to broadcast attack" << endl;
 
-      if (p->attackType == Player::ATTACK_MELEE)
-      {
+      if (p->attackType == Player::ATTACK_MELEE) {
          cout << "Melee attack" << endl;
 
          Player* target = players[p->getTargetPlayer()];
          this->dealDamageToPlayer(target, p->damage);
-      }
-      else if (p->attackType == Player::ATTACK_RANGED)
-      {
+      } else if (p->attackType == Player::ATTACK_RANGED) {
          cout << "Ranged attack" << endl;
 
@@ -476,6 +447,5 @@
          memcpy(serverMsg.buffer+12, &targetId, 4);
          msgProcessor->broadcastMessage(serverMsg, players);
-      }
-      else
+      } else
          cout << "Invalid attack type: " << p->attackType << endl;
    }
Index: common/Player.cpp
===================================================================
--- common/Player.cpp	(revision cdb0e982399ace2b3ddec199a997d4b76be56ae0)
+++ common/Player.cpp	(revision 53643cad0b21a051f5301ad161c43380ff3b29d8)
@@ -33,4 +33,10 @@
    this->hasBlueFlag = false;
    this->hasRedFlag = false;
+
+   this->level = 0;
+   this->experience = 0;
+   this->honor = 0;
+   this->wins = 0;
+   this->losses = 0;
 
    this->currentGame = NULL;
@@ -66,4 +72,10 @@
    this->hasRedFlag = p.hasRedFlag;
 
+   this->level = p.level;
+   this->experience = p.experience;
+   this->honor = p.honor;
+   this->wins = p.wins;
+   this->losses = p.losses;
+
    this->currentGame = p.currentGame;
 }
@@ -95,4 +107,10 @@
    this->hasBlueFlag = false;
    this->hasRedFlag = false;
+
+   this->level = 0;
+   this->experience = 0;
+   this->honor = 0;
+   this->wins = 0;
+   this->losses = 0;
 
    this->currentGame = NULL;
Index: common/Player.h
===================================================================
--- common/Player.h	(revision cdb0e982399ace2b3ddec199a997d4b76be56ae0)
+++ common/Player.h	(revision 53643cad0b21a051f5301ad161c43380ff3b29d8)
@@ -88,4 +88,11 @@
    bool hasRedFlag;
 
+   // permanent attributes
+   unsigned int level;
+   unsigned int experience;
+   unsigned int honor;
+   unsigned int wins;
+   unsigned int losses;
+
    Game* currentGame;
 };
Index: server/DataAccess.cpp
===================================================================
--- server/DataAccess.cpp	(revision cdb0e982399ace2b3ddec199a997d4b76be56ae0)
+++ server/DataAccess.cpp	(revision 53643cad0b21a051f5301ad161c43380ff3b29d8)
@@ -6,8 +6,28 @@
 #include <crypt.h>
 
+#include "LuaLoader.h"
+
 using namespace std;
 
 DataAccess::DataAccess()
 {
+   LuaLoader luaLoader;
+
+   string database, username, password;
+
+   if (luaLoader.runScript("db_settings.lua")) {
+       cout << "Loading settings" << endl;
+
+       database = luaLoader.getValue("database");
+       username = luaLoader.getValue("username");
+       password = luaLoader.getValue("password");
+
+       cout << database << endl;
+       cout << username << endl;
+       cout << password << endl;
+   } else {
+       cout << "Failed to load settings from lua script" << endl;
+   }
+
    mysql_init(&mysql);
    connection = mysql_real_connect(&mysql, "localhost", "pythonAdmin", "pyMaster09*", "pythondb", 0, 0, 0);
@@ -52,4 +72,5 @@
 }
 
+// this is no longer used anywhere
 int DataAccess::updatePlayer(string username, string password)
 {
@@ -85,4 +106,5 @@
       cout << "Creating a new player" << endl;
       p = new Player(string(row[1]), string(row[2]));
+      p->setId(atoi(row[0]));
       if (row[3] == NULL) {
          p->setClass(Player::CLASS_NONE);
@@ -93,5 +115,13 @@
       }
       cout << "Player class: " << p->playerClass << endl;
-      cout << "Created new player" << endl;
+      if (row[7] == NULL)
+          cout << "wins: NULL" << endl;
+      else
+          cout << "wins: " << atoi(row[7]) << endl;
+      if (row[8] == NULL)
+          cout << "losses: NULL" << endl;
+      else
+          cout << "losses: " << atoi(row[8]) << endl;
+      cout << "Loaded player from db" << endl;
    }else {
       cout << "Returned no results for some reason" << endl;
@@ -112,5 +142,4 @@
    MYSQL_RES *result;
    MYSQL_ROW row;
-   ostringstream oss;
 
    result = select("users", "");
@@ -139,4 +168,108 @@
 }
 
+int* DataAccess::getPlayerRecord(int playerId) {
+   MYSQL_RES *result;
+   MYSQL_ROW row;
+   ostringstream oss;
+   int* record = new int[5];
+
+   oss << "id=" << playerId;
+   result = select("users", oss.str());
+
+   if ( ( row = mysql_fetch_row(result)) != NULL ) {
+      cout << "Retrieved player record successfully" << endl;
+      record[0] = atoi(row[4]);   // level
+      record[1] = atoi(row[5]);   // experience
+      record[2] = atoi(row[6]);   // honor
+      record[3] = atoi(row[7]);   // wins
+      record[4] = atoi(row[8]);   // losses
+      cout << "record[0]:" << record[0] << endl;
+      cout << "record[1]:" << record[1] << endl;
+      cout << "record[2]:" << record[2] << endl;
+      cout << "record[3]:" << record[3] << endl;
+      cout << "record[4]:" << record[4] << endl;
+   }
+
+   if (result == NULL) {
+      cout << mysql_error(connection) << endl;
+      return NULL;
+   }
+
+   mysql_free_result(result);
+
+   return record;
+}
+
+int** DataAccess::getPlayerGameHistory(int playerId, unsigned int& numGames)
+{
+   // each array is the score for one game
+   // the columns are result, team, blue score, and red score
+   // for result 0 is defeat and 1 is victory
+   // for team, 0 is blue and 1 is red
+
+   MYSQL_RES *result;
+   MYSQL_ROW row;
+   ostringstream oss;
+
+   int** gameHistory;
+
+   oss << "user_id=" << playerId;
+   result = select("gameHistory", oss.str());
+
+   numGames = mysql_num_rows(result);
+   gameHistory = (int**)malloc(sizeof(int*)*numGames);
+   cout << "Result has " << numGames << " rows" << endl;
+
+   int i=0;
+   while ( ( row = mysql_fetch_row(result)) != NULL ) {
+      gameHistory[i] = new int[4];
+
+      int userTeam = atoi(row[2]);
+      int blueScore = atoi(row[4]);
+      int redScore = atoi(row[3]);
+      int gameResult = -1;
+
+      if (blueScore == 3) {
+         if (userTeam == 0)
+            gameResult = 1;
+         else
+            gameResult = 0;
+      }else if (redScore == 3) {
+         if (userTeam == 1)
+            gameResult = 1;
+         else
+            gameResult = 0;
+      }else {
+         cout << "Recorded game has no team with 3 points" << endl;
+      }
+
+      gameHistory[i][0] = gameResult;
+      gameHistory[i][1] = userTeam;
+      gameHistory[i][2] = blueScore;
+      gameHistory[i][3] = redScore;
+
+      i++;
+   }
+
+   if (result == NULL) {
+      cout << mysql_error(connection) << endl;
+      return NULL;
+   }
+
+   mysql_free_result(result);
+
+   return gameHistory;
+}
+
+int DataAccess::saveGameHistory(int playerId, int team, int blueScore, int redScore)
+{
+   ostringstream oss;
+
+   cout << "Saving game to db" << endl;
+   oss << playerId << ", " << team << ", " << blueScore << ", " << redScore;
+
+   return insert("gameHistory", "user_id, user_team, blue_score, red_score", oss.str());
+}
+
 int DataAccess::insert(string table, string columns, string values)
 {
@@ -156,5 +289,5 @@
    if (query_state != 0) {
       cout << mysql_error(connection) << endl;
-      return 1;
+      return -1;
    }
 
@@ -168,5 +301,5 @@
 
    if (connection == NULL) {
-       cout << "Error: non database connection exists" << endl;
+       cout << "Error: no database connection exists" << endl;
        return -1;
    }
@@ -179,5 +312,5 @@
    if (query_state != 0) {
       cout << mysql_error(connection) << endl;
-      return 1;
+      return -1;
    }
 
@@ -198,4 +331,5 @@
    if (!filter.empty())
       oss << " WHERE " << filter;
+   cout << "executing select query: " << oss.str() << endl;
 
    query_state = mysql_query(connection, oss.str().c_str());
Index: server/DataAccess.h
===================================================================
--- server/DataAccess.h	(revision cdb0e982399ace2b3ddec199a997d4b76be56ae0)
+++ server/DataAccess.h	(revision 53643cad0b21a051f5301ad161c43380ff3b29d8)
@@ -1,3 +1,3 @@
-#ifndef _DATA_ACCES_H
+#ifndef _DATA_ACCESS_H
 #define _DATA_ACCESS_H
 
@@ -16,10 +16,16 @@
    ~DataAccess();
 
-   int insertPlayer(string username, string password, Player::PlayerClass playerClass);
-   int updatePlayer(string username, string password);
-
    Player* getPlayer(string username);
    list<Player*>* getPlayers();
    bool verifyPassword(string encrypted, string password);
+   int insertPlayer(string username, string password, Player::PlayerClass playerClass);
+   // this method needs to be more rebust. maybe pass in a player object amd
+   // the method could use the player id to find the player and update any
+   // attributes that changed
+   int updatePlayer(string username, string password);
+
+   int* getPlayerRecord(int playerId);
+   int** getPlayerGameHistory(int playerId, unsigned int& numGames);
+   int saveGameHistory(int playerId, int team, int blueScore, int redScore);
 
    int insert(string table, string rows, string values);
Index: server/LuaLoader.cpp
===================================================================
--- server/LuaLoader.cpp	(revision 53643cad0b21a051f5301ad161c43380ff3b29d8)
+++ server/LuaLoader.cpp	(revision 53643cad0b21a051f5301ad161c43380ff3b29d8)
@@ -0,0 +1,56 @@
+#include "LuaLoader.h"
+
+#include <iostream>
+
+using namespace std;
+
+LuaLoader::LuaLoader()
+{
+   // new Lua state
+   std::cout << "[C++] Starting Lua state" << std::endl;
+   this->lua_state = luaL_newstate();
+
+   // load Lua libraries
+   std::cout << "[C++] Loading Lua libraries" << std::endl;
+   static const luaL_Reg lualibs[] = 
+   {
+      {"base", luaopen_base},
+      {"io", luaopen_io},
+      {NULL, NULL}
+   };
+   const luaL_Reg *lib = lualibs;
+   for(; lib->func != NULL; lib++)
+   {
+      std::cout << " loading '" << lib->name << "'" << std::endl;
+      luaL_requiref(this->lua_state, lib->name, lib->func, 1);
+      lua_settop(this->lua_state, 0);
+   }
+}
+
+LuaLoader::~LuaLoader()
+{
+}
+
+bool LuaLoader::runScript(string filename)
+{
+   // load the script
+   int status = luaL_loadfile(this->lua_state, filename.c_str());
+   cout << " return: " << status << std::endl;
+
+   // run the script with the given arguments
+   cout << "[C++] Running script" << std::endl;
+   if (status == LUA_OK) {
+      lua_pcall(lua_state, 0, LUA_MULTRET, 0);
+      return true;
+   } else {
+      return false;
+   }
+}
+
+string LuaLoader::getValue(string key) 
+{
+   lua_getfield(lua_state, 1, key.c_str());
+   string str(luaL_checkstring(lua_state, -1));
+
+   return str;
+}
Index: server/LuaLoader.h
===================================================================
--- server/LuaLoader.h	(revision 53643cad0b21a051f5301ad161c43380ff3b29d8)
+++ server/LuaLoader.h	(revision 53643cad0b21a051f5301ad161c43380ff3b29d8)
@@ -0,0 +1,26 @@
+#ifndef _LUA_LOADER_H
+#define _LUA_LOADER_H
+
+#include <string>
+
+extern "C" {
+    #include <lua5.2/lua.h>
+    #include <lua5.2/lualib.h>
+    #include <lua5.2/lauxlib.h>
+}
+
+using namespace std;
+
+class LuaLoader {
+public:
+   LuaLoader();
+   ~LuaLoader();
+
+   bool runScript(string filename);
+   string getValue(string key);
+
+private:
+   lua_State* lua_state;
+};
+
+#endif
Index: server/db_settings.lua
===================================================================
--- server/db_settings.lua	(revision 53643cad0b21a051f5301ad161c43380ff3b29d8)
+++ server/db_settings.lua	(revision 53643cad0b21a051f5301ad161c43380ff3b29d8)
@@ -0,0 +1,5 @@
+return {
+    database = 'pythondb',
+    username = 'pythonAdmin',
+    password = 'pyMaster09*'
+}
Index: server/dbmod.txt
===================================================================
--- server/dbmod.txt	(revision 53643cad0b21a051f5301ad161c43380ff3b29d8)
+++ server/dbmod.txt	(revision 53643cad0b21a051f5301ad161c43380ff3b29d8)
@@ -0,0 +1,36 @@
+SQL statements for creating the db tables are stored here
+
+CREATE TABLE users( 
+   id INT NOT NULL AUTO_INCREMENT,
+   wins INT NOT NULL DEFAULT 0,
+   losses INT NOT NULL DEFAULT 0
+);
+
+CREATE TABLE `users` (
+   id INT NOT NULL AUTO_INCREMENT,
+   name varchar(64) NOT NULL,
+   password binary(60) NOT NULL,
+   class INT unsigned DEFAULT NULL,
+   level INT unsigned NOT NULL DEFAULT 0,
+   experience INT unsigned NOT NULL DEFAULT 0,
+   honor INT NOT NULL DEFAULT 0,
+   wins INT NOT NULL DEFAULT 0,
+   losses INT NOT NULL DEFAULT 0,
+   PRIMARY KEY (id),
+   UNIQUE KEY name (name)
+}
+
+
+CREATE TABLE gameHistory (
+   id INT NOT NULL AUTO_INCREMENT,
+   user_id INT NOT NULL,
+   user_team INT NOT NULL,
+   red_score INT NOT NULL,
+   blue_score INT NOT NULL,
+   PRIMARY KEY (id),
+   CONSTRAINT fk_users FOREIGN KEY
+   fki_users (user_id)
+   REFERENCES users (id)
+   ON DELETE CASCADE
+   ON UPDATE CASCADE
+);
Index: server/makefile
===================================================================
--- server/makefile	(revision cdb0e982399ace2b3ddec199a997d4b76be56ae0)
+++ server/makefile	(revision 53643cad0b21a051f5301ad161c43380ff3b29d8)
@@ -1,10 +1,10 @@
 CC = g++
 #LIB_FLAGS = -lssl -lmysqlclient -lcrypt -lrt
-LIB_FLAGS = -lmysqlclient -lcrypt -lrt
+LIB_FLAGS = -lmysqlclient -lcrypt -lrt -llua5.2
 FLAGS = -Wall -g
 COMMON_PATH = ../common
-DEPENDENCIES = Common.o MessageContainer.o MessageProcessor.o Player.o WorldMap.o DataAccess.o Projectile.o Game.o GameSummary.o
+DEPENDENCIES = Common.o MessageContainer.o MessageProcessor.o Player.o WorldMap.o DataAccess.o Projectile.o Game.o GameSummary.o LuaLoader.o
 
-server : server.cpp $(DEPENDENCIES)
+gameServer : server.cpp $(DEPENDENCIES)
 	$(CC) -o $@ $+ $(FLAGS) $(LIB_FLAGS)
 
@@ -38,3 +38,3 @@
 clean:
 	rm *.o
-	rm server
+	rm gameServer
Index: server/server.cpp
===================================================================
--- server/server.cpp	(revision cdb0e982399ace2b3ddec199a997d4b76be56ae0)
+++ server/server.cpp	(revision 53643cad0b21a051f5301ad161c43380ff3b29d8)
@@ -43,7 +43,6 @@
 // from used to be const. Removed that so I could take a reference
 // and use it to send messages
-void processMessage(const NETWORK_MSG& clientMsg, struct sockaddr_in& from, MessageProcessor& msgProcessor, map<unsigned int, Player*>& mapPlayers, map<string, Game*>& mapGames, unsigned int& unusedPlayerId, ofstream& outputLog);
-
-void updateUnusedPlayerId(unsigned int& id, map<unsigned int, Player*>& mapPlayers);
+void processMessage(const NETWORK_MSG& clientMsg, struct sockaddr_in& from, MessageProcessor& msgProcessor, map<unsigned int, Player*>& mapPlayers, map<string, Game*>& mapGames, ofstream& outputLog);
+
 Player *findPlayerByName(map<unsigned int, Player*> &m, string name);
 Player *findPlayerByAddr(map<unsigned int, Player*> &m, const sockaddr_in &addr);
@@ -63,5 +62,4 @@
    map<unsigned int, Projectile> mapProjectiles;
    map<string, Game*> mapGames;
-   unsigned int unusedPlayerId = 1;
    ofstream outputLog;
 
@@ -117,6 +115,4 @@
 
          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)
@@ -179,6 +175,4 @@
          }
 
-         cout << "Processing players in a game" << endl;
-
          // process players currently in a game
          map<string, Game*>::iterator itGames;
@@ -188,4 +182,22 @@
             game = itGames->second;
             if (game->handleGameEvents()) {
+               // save game record
+               int winningTeam = -1;
+               if (game->getBlueScore() == 3)
+                  winningTeam = 0;
+               else if (game->getRedScore() == 3)
+                  winningTeam = 1;
+
+               if (winningTeam == -1)
+                  cout << "Error: Game ended, but neither team has a score of 3" << endl;
+               else {
+                  map<unsigned int, Player*>::iterator it;
+                  DataAccess da;
+
+                  for (it = game->getPlayers().begin(); it != game->getPlayers().end(); it++) {
+                      da.saveGameHistory(it->second->getId(), winningTeam, game->getBlueScore(), game->getRedScore());
+                  }
+               }
+
                // send a GAME_INFO message with 0 players to force clients to delete the game
                int numPlayers = 0;
@@ -200,6 +212,4 @@
                itGames++;
          }
-
-         cout << "Processing projectiles"  << endl;
 
          // move all projectiles
@@ -230,5 +240,5 @@
       if (msgProcessor.receiveMessage(&clientMsg, &from) >= 0)
       {
-         processMessage(clientMsg, from, msgProcessor, mapPlayers, mapGames, unusedPlayerId, outputLog);
+         processMessage(clientMsg, from, msgProcessor, mapPlayers, mapGames, outputLog);
 
          cout << "Finished processing the message" << endl;
@@ -255,5 +265,5 @@
 }
 
-void processMessage(const NETWORK_MSG &clientMsg, struct sockaddr_in &from, MessageProcessor &msgProcessor, map<unsigned int, Player*>& mapPlayers, map<string, Game*>& mapGames, unsigned int& unusedPlayerId, ofstream& outputLog)
+void processMessage(const NETWORK_MSG &clientMsg, struct sockaddr_in &from, MessageProcessor &msgProcessor, map<unsigned int, Player*>& mapPlayers, map<string, Game*>& mapGames, ofstream& outputLog)
 {
    NETWORK_MSG serverMsg;
@@ -331,6 +341,4 @@
          else
          {
-            updateUnusedPlayerId(unusedPlayerId, mapPlayers);
-            p->setId(unusedPlayerId);
             cout << "new player id: " << p->getId() << endl;
             p->setAddr(from);
@@ -369,5 +377,5 @@
             msgProcessor.broadcastMessage(serverMsg, mapPlayers);
 
-            mapPlayers[unusedPlayerId] = p;
+            mapPlayers[p->getId()] = p;
          }
 
@@ -403,7 +411,4 @@
 
             msgProcessor.broadcastMessage(serverMsg, mapPlayers);
-
-            if (p->getId() < unusedPlayerId)
-               unusedPlayerId = p->getId();
 
             mapPlayers.erase(p->getId());
@@ -569,33 +574,36 @@
       case MSG_TYPE_PROFILE:
       {
+         cout << "Received a PROFILE message" << endl;
+
+         unsigned int id;
+
+         memcpy(&id, clientMsg.buffer, 4);
+
+         cout << "Player id: " << id << endl;
+         unsigned int numGames = 0;
+         int** gameHistory = da.getPlayerGameHistory(id, numGames);
+         int* playerRecord = da.getPlayerRecord(id);
+
+         int honorPoints = playerRecord[0];
+         int wins = playerRecord[1];
+         int losses = playerRecord[2];
+
          serverMsg.type = MSG_TYPE_PROFILE;
 
-         // each array is the score for one game
-         // the columns are result, team, blue score, and red score
-         // for result 0 is defeat and 1 is victory
-         // for team, 0 is blue and 1 is red
-         int scores[][4] = {
-            {1, 1, 2, 3},
-            {1, 0, 3, 2},
-            {0, 1, 3, 1},
-            {1, 1, 0, 3},
-            {0, 0, 2, 3},
-            {1, 0, 3, 2},
-            {1, 0, 3, 0},
-            {0, 1, 3, 1},
-            {1, 1, 1, 3},
-            {1, 0, 3, 2}
-         };
-
-         int honorPoints = 1000;
-         int numGames = 10;
          memcpy(serverMsg.buffer, &honorPoints, 4);
-         memcpy(serverMsg.buffer+4, &numGames, 4);
-         for (unsigned int i=0; i<sizeof(scores)/sizeof(scores[0]); i++) {
-            memcpy(serverMsg.buffer+8+i*16, &scores[i][0], 4);
-            memcpy(serverMsg.buffer+12+i*16, &scores[i][1], 4);
-            memcpy(serverMsg.buffer+16+i*16, &scores[i][2], 4);
-            memcpy(serverMsg.buffer+20+i*16, &scores[i][3], 4);
-         }
+         memcpy(serverMsg.buffer+4, &wins, 4);
+         memcpy(serverMsg.buffer+8, &losses, 4);
+         memcpy(serverMsg.buffer+12, &numGames, 4);
+         for (unsigned int i=0; i<numGames; i++) {
+            memcpy(serverMsg.buffer+16+i*16, &gameHistory[i][0], 4);
+            memcpy(serverMsg.buffer+20+i*16, &gameHistory[i][1], 4);
+            memcpy(serverMsg.buffer+24+i*16, &gameHistory[i][2], 4);
+            memcpy(serverMsg.buffer+28+i*16, &gameHistory[i][3], 4);
+            delete[] gameHistory[i];
+         }
+
+         //delete[] gameHistory;
+         free(gameHistory);
+         delete[] playerRecord;
 
          msgProcessor.sendMessage(&serverMsg, &from);
@@ -825,10 +833,4 @@
 }
 
-void updateUnusedPlayerId(unsigned int& id, map<unsigned int, Player*>& mapPlayers)
-{
-   while (mapPlayers.find(id) != mapPlayers.end())
-      id++;
-}
-
 Player *findPlayerByName(map<unsigned int, Player*> &m, string name)
 {
