Changeset ec48e7d in network-game for client/Client/main.cpp


Ignore:
Timestamp:
Nov 26, 2012, 8:31:36 PM (12 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
b13b001
Parents:
171c4fe
Message:

Added a logout state where no messages can be sent. Once the client logs out, the only available option is to close the client and then restart it to login again.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    r171c4fe rec48e7d  
    5151enum STATE {
    5252   STATE_START,
    53    STATE_LOGIN
     53   STATE_LOGIN,
     54   STATE_LOGOUT
    5455};
    5556 
     
    202203               switch(state)
    203204               {
    204                case STATE_START:
    205                   msgTo.type = MSG_TYPE_LOGIN;
    206                   username = input;
    207                   break;
    208                case STATE_LOGIN:
    209                   if (input.compare("quit") == 0 ||
    210                       input.compare("exit") == 0 ||
    211                       input.compare("logout") == 0)
    212                   {
    213                      strcpy(msgTo.buffer, username.c_str());
    214                      msgTo.type = MSG_TYPE_LOGOUT;
    215                   }
    216                   else
    217                      msgTo.type = MSG_TYPE_CHAT;
    218                   break;
    219                default:
    220                   cout << "The state has an invalid value: " << state << endl;
    221                   break;
     205                  case STATE_START:
     206                  {
     207                     msgTo.type = MSG_TYPE_LOGIN;
     208                     username = input;
     209                     break;
     210                  }
     211                  case STATE_LOGIN:
     212                  {
     213                     if (input.compare("quit") == 0 ||
     214                         input.compare("exit") == 0 ||
     215                         input.compare("logout") == 0)
     216                     {
     217                        strcpy(msgTo.buffer, username.c_str());
     218                        msgTo.type = MSG_TYPE_LOGOUT;
     219                     }
     220                     else
     221                        msgTo.type = MSG_TYPE_CHAT;
     222                     break;
     223                  }
     224                  case STATE_LOGOUT:
     225                  {
     226                     cout << "Bug: You're logged out, so you shouldn't be receiving any messages." << endl;
     227                 
     228                     break;
     229                  }
     230                  default:
     231                  {
     232                     cout << "The state has an invalid value: " << state << endl;
     233                 
     234                     break;
     235                  }
    222236               }
    223237
     
    230244                  error("receiveMessage");
    231245
     246               string response = string(msgFrom.buffer);
     247
    232248               switch(state)
    233249               {
    234250                  case STATE_START:
    235251                  {
    236                      string loginResponse = string(msgFrom.buffer);
    237252                     chatConsole.addLine(string(msgFrom.buffer));
    238253
    239                      if (loginResponse.compare("Player has already logged in.") == 0)
     254                     if (response.compare("Player has already logged in.") == 0)
    240255                     {
    241256                        cout << "User login failed" << endl;
     
    252267                  {
    253268                     chatConsole.addLine(string(msgFrom.buffer));
    254                      cout << "Added new line" << endl;
     269
     270                     if (response.compare("You have been successfully logged out. You may quit the game.") == 0)
     271                     {
     272                        state = STATE_LOGOUT;
     273                     }
     274                     else
     275                     {
     276                        cout << "Added new line" << endl;
     277                     }
     278                     
     279                     break;
     280                  }
     281                  case STATE_LOGOUT:
     282                  {
     283                     cout << "Bug: You're logged out, so you shouldn't be receiving any messages." << endl;
     284                 
    255285                     break;
    256286                  }
     
    258288                  {
    259289                     cout << "The state has an invalid value: " << state << endl;
     290
    260291                     break;
    261292                  }
Note: See TracChangeset for help on using the changeset viewer.