Changes in / [07028b9:b13b001] in network-game
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/main.cpp
r07028b9 rb13b001 51 51 enum STATE { 52 52 STATE_START, 53 STATE_LOGIN 53 STATE_LOGIN, 54 STATE_LOGOUT 54 55 }; 55 56 … … 202 203 switch(state) 203 204 { 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 } 222 236 } 223 237 … … 230 244 error("receiveMessage"); 231 245 246 string response = string(msgFrom.buffer); 247 232 248 switch(state) 233 249 { 234 250 case STATE_START: 235 251 { 236 string loginResponse = string(msgFrom.buffer);237 252 chatConsole.addLine(string(msgFrom.buffer)); 238 253 239 if ( loginResponse.compare("Player has already logged in.") == 0)254 if (response.compare("Player has already logged in.") == 0) 240 255 { 241 256 cout << "User login failed" << endl; … … 252 267 { 253 268 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 255 285 break; 256 286 } … … 258 288 { 259 289 cout << "The state has an invalid value: " << state << endl; 290 260 291 break; 261 292 }
Note:
See TracChangeset
for help on using the changeset viewer.