Index: client/Client/main.cpp
===================================================================
--- client/Client/main.cpp	(revision a4db787e5831bbbe5ce409f0af7e57ec3359b651)
+++ client/Client/main.cpp	(revision 8e540f4f076cccb0fd4d74b3fbb0902d34ce5444)
@@ -36,4 +36,6 @@
 void initWinSock();
 void shutdownWinSock();
+void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, string &username);
+
 void error(const char *);
 
@@ -207,4 +209,9 @@
                      msgTo.type = MSG_TYPE_LOGIN;
                      username = input;
+
+                     sendMessage(&msgTo, sock, &server);
+                     receiveMessage(&msgFrom, sock, &from);
+                     processMessage(msgFrom, state, chatConsole, username);
+                     cout << "state: " << state << endl;
 
                      break;
@@ -222,9 +229,16 @@
                         msgTo.type = MSG_TYPE_CHAT;
 
+                     sendMessage(&msgTo, sock, &server);
+                     receiveMessage(&msgFrom, sock, &from);
+                     processMessage(msgFrom, state, chatConsole, username);
+                     cout << "state: " << state << endl;
+
                      break;
                   }
                   case STATE_LOGOUT:
                   {
-                     cout << "Bug: You're logged out, so you shouldn't be receiving any messages." << endl;
+                     chatConsole.addLine("You're logged out, so you can't send any messages to the server.");
+
+                     cout << "You're logged out, so you can't send any messages to the server." << endl;
                   
                      break;
@@ -237,59 +251,4 @@
                   }
                }
-
-               sendMessage(&msgTo, sock, &server);
-
-               receiveMessage(&msgFrom, sock, &from);
-               string response = string(msgFrom.buffer);
-
-               // this whole select block should go in a new function.
-               // Figure out how to pass and return params properly
-               switch(state)
-               {
-                  case STATE_START:
-                  {
-                     chatConsole.addLine(string(msgFrom.buffer));
-
-                     if (response.compare("Player has already logged in.") == 0)
-                     {
-                        cout << "User login failed" << endl;
-                        username.clear();
-                     }
-                     else
-                     {
-                        cout << "User login successful" << endl;
-                        state = STATE_LOGIN;
-                     }
-
-                     break;
-                  }
-                  case STATE_LOGIN:
-                  {
-                     chatConsole.addLine(string(msgFrom.buffer));
-
-                     if (response.compare("You have been successfully logged out. You may quit the game.") == 0)
-                     {
-                        state = STATE_LOGOUT;
-                     }
-                     else
-                     {
-                        cout << "Added new line" << endl;
-                     }
-                     
-                     break;
-                  }
-                  case STATE_LOGOUT:
-                  {
-                     cout << "Bug: You're logged out, so you shouldn't be receiving any messages." << endl;
-                  
-                     break;
-                  }
-                  default:
-                  {
-                     cout << "The state has an invalid value: " << state << endl;
-
-                     break;
-                  }
-               }
             }
          }else {
@@ -364,4 +323,12 @@
  
    return 0;
+}
+
+// need to make a function like this that works on windows
+void error(const char *msg)
+{
+   perror(msg);
+   shutdownWinSock();
+   exit(1);
 }
 
@@ -391,9 +358,57 @@
 }
 
-// need to make a function like this that works on windows
-void error(const char *msg)
+void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, string &username)
 {
-   perror(msg);
-   shutdownWinSock();
-   exit(1);
+   string response = string(msg.buffer);
+
+   // this whole select block should go in a new function.
+   // Figure out how to pass and return params properly
+   switch(state)
+   {
+      case STATE_START:
+      {
+         chatConsole.addLine(response);
+
+         if (response.compare("Player has already logged in.") == 0)
+         {
+            cout << "User login failed" << endl;
+            username.clear();
+         }
+         else
+         {
+            cout << "User login successful" << endl;
+            state = STATE_LOGIN;
+         }
+
+         break;
+      }
+      case STATE_LOGIN:
+      {
+         chatConsole.addLine(response);
+
+         if (response.compare("You have successfully logged out. You may quit the game.") == 0)
+         {
+            cout << "Logged out" << endl;
+            state = STATE_LOGOUT;
+         }
+         else
+         {
+            cout << "Added new line" << endl;
+         }
+                     
+         break;
+      }
+      case STATE_LOGOUT:
+      {
+         cout << "Bug: You're logged out, so you shouldn't be receiving any messages." << endl;
+                  
+         break;
+      }
+      default:
+      {
+         cout << "The state has an invalid value: " << state << endl;
+
+         break;
+      }
+   }
 }
