Changes in client/Client/main.cpp [ec48e7d:171c4fe] in network-game
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/main.cpp
rec48e7d r171c4fe 51 51 enum STATE { 52 52 STATE_START, 53 STATE_LOGIN, 54 STATE_LOGOUT 53 STATE_LOGIN 55 54 }; 56 55 … … 203 202 switch(state) 204 203 { 205 case STATE_START: 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) 206 212 { 207 msgTo.type = MSG_TYPE_LOGIN; 208 username = input; 209 break; 213 strcpy(msgTo.buffer, username.c_str()); 214 msgTo.type = MSG_TYPE_LOGOUT; 210 215 } 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 } 216 else 217 msgTo.type = MSG_TYPE_CHAT; 218 break; 219 default: 220 cout << "The state has an invalid value: " << state << endl; 221 break; 236 222 } 237 223 … … 243 229 if (n < 0) 244 230 error("receiveMessage"); 245 246 string response = string(msgFrom.buffer);247 231 248 232 switch(state) … … 250 234 case STATE_START: 251 235 { 236 string loginResponse = string(msgFrom.buffer); 252 237 chatConsole.addLine(string(msgFrom.buffer)); 253 238 254 if ( response.compare("Player has already logged in.") == 0)239 if (loginResponse.compare("Player has already logged in.") == 0) 255 240 { 256 241 cout << "User login failed" << endl; … … 267 252 { 268 253 chatConsole.addLine(string(msgFrom.buffer)); 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 254 cout << "Added new line" << endl; 285 255 break; 286 256 } … … 288 258 { 289 259 cout << "The state has an invalid value: " << state << endl; 290 291 260 break; 292 261 }
Note:
See TracChangeset
for help on using the changeset viewer.