Changeset 4da5aa3 in network-game
- Timestamp:
- Nov 26, 2012, 10:18:25 PM (12 years ago)
- Branches:
- master
- Children:
- 73f75c1
- Parents:
- a4db787
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/main.cpp
ra4db787 r4da5aa3 36 36 void initWinSock(); 37 37 void shutdownWinSock(); 38 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, string &username); 39 38 40 void error(const char *); 39 41 … … 207 209 msgTo.type = MSG_TYPE_LOGIN; 208 210 username = input; 211 212 sendMessage(&msgTo, sock, &server); 213 receiveMessage(&msgFrom, sock, &from); 214 processMessage(msgFrom, state, chatConsole, username); 215 cout << "state: " << state << endl; 209 216 210 217 break; … … 222 229 msgTo.type = MSG_TYPE_CHAT; 223 230 231 sendMessage(&msgTo, sock, &server); 232 receiveMessage(&msgFrom, sock, &from); 233 processMessage(msgFrom, state, chatConsole, username); 234 cout << "state: " << state << endl; 235 224 236 break; 225 237 } 226 238 case STATE_LOGOUT: 227 239 { 228 cout << "Bug: You're logged out, so you shouldn't be receiving any messages." << endl; 240 chatConsole.addLine("You're logged out, so you can't send any messages to the server."); 241 242 cout << "You're logged out, so you can't send any messages to the server." << endl; 229 243 230 244 break; … … 237 251 } 238 252 } 239 240 sendMessage(&msgTo, sock, &server);241 242 receiveMessage(&msgFrom, sock, &from);243 string response = string(msgFrom.buffer);244 245 // this whole select block should go in a new function.246 // Figure out how to pass and return params properly247 switch(state)248 {249 case STATE_START:250 {251 chatConsole.addLine(string(msgFrom.buffer));252 253 if (response.compare("Player has already logged in.") == 0)254 {255 cout << "User login failed" << endl;256 username.clear();257 }258 else259 {260 cout << "User login successful" << endl;261 state = STATE_LOGIN;262 }263 264 break;265 }266 case STATE_LOGIN:267 {268 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 else275 {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 285 break;286 }287 default:288 {289 cout << "The state has an invalid value: " << state << endl;290 291 break;292 }293 }294 253 } 295 254 }else { … … 364 323 365 324 return 0; 325 } 326 327 // need to make a function like this that works on windows 328 void error(const char *msg) 329 { 330 perror(msg); 331 shutdownWinSock(); 332 exit(1); 366 333 } 367 334 … … 391 358 } 392 359 393 // need to make a function like this that works on windows 394 void error(const char *msg) 360 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, string &username) 395 361 { 396 perror(msg); 397 shutdownWinSock(); 398 exit(1); 362 string response = string(msg.buffer); 363 364 // this whole select block should go in a new function. 365 // Figure out how to pass and return params properly 366 switch(state) 367 { 368 case STATE_START: 369 { 370 chatConsole.addLine(response); 371 372 if (response.compare("Player has already logged in.") == 0) 373 { 374 cout << "User login failed" << endl; 375 username.clear(); 376 } 377 else 378 { 379 cout << "User login successful" << endl; 380 state = STATE_LOGIN; 381 } 382 383 break; 384 } 385 case STATE_LOGIN: 386 { 387 chatConsole.addLine(response); 388 389 if (response.compare("You have successfully logged out. You may quit the game.") == 0) 390 { 391 cout << "Logged out" << endl; 392 state = STATE_LOGOUT; 393 } 394 else 395 { 396 cout << "Added new line" << endl; 397 } 398 399 break; 400 } 401 case STATE_LOGOUT: 402 { 403 cout << "Bug: You're logged out, so you shouldn't be receiving any messages." << endl; 404 405 break; 406 } 407 default: 408 { 409 cout << "The state has an invalid value: " << state << endl; 410 411 break; 412 } 413 } 399 414 }
Note:
See TracChangeset
for help on using the changeset viewer.