- Timestamp:
- Nov 26, 2012, 8:02:56 PM (12 years ago)
- Branches:
- master
- Children:
- 07028b9, ec48e7d
- Parents:
- d2b411a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/main.cpp
rd2b411a r171c4fe 140 140 struct sockaddr_in server, from; 141 141 struct hostent *hp; 142 //char buffer[256];143 142 NETWORK_MSG msgTo, msgFrom; 143 string username; 144 144 145 145 if (argc != 3) { … … 162 162 server.sin_port = htons(atoi(argv[2])); 163 163 164 strcpy(msgTo.buffer, "Hello");165 n=sendMessage(&msgTo, sock, &server);166 if (n < 0)167 error("sendMessage");168 169 n = receiveMessage(&msgFrom, sock, &from);170 if (n < 0)171 error("receiveMessage");172 173 chatConsole.addLine(msgFrom.buffer);174 175 164 al_start_timer(timer); 176 165 … … 215 204 case STATE_START: 216 205 msgTo.type = MSG_TYPE_LOGIN; 206 username = input; 217 207 break; 218 208 case STATE_LOGIN: 219 msgTo.type = MSG_TYPE_CHAT; 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; 220 218 break; 221 219 default: … … 234 232 switch(state) 235 233 { 236 case STATE_START: 237 state = STATE_LOGIN; 238 break; 239 case STATE_LOGIN: 240 chatConsole.addLine(string(msgFrom.buffer)); 241 cout << "Added new line" << endl; 242 break; 243 default: 244 cout << "The state has an invalid value: " << state << endl; 245 break; 234 case STATE_START: 235 { 236 string loginResponse = string(msgFrom.buffer); 237 chatConsole.addLine(string(msgFrom.buffer)); 238 239 if (loginResponse.compare("Player has already logged in.") == 0) 240 { 241 cout << "User login failed" << endl; 242 username.clear(); 243 } 244 else 245 { 246 cout << "User login successful" << endl; 247 state = STATE_LOGIN; 248 } 249 break; 250 } 251 case STATE_LOGIN: 252 { 253 chatConsole.addLine(string(msgFrom.buffer)); 254 cout << "Added new line" << endl; 255 break; 256 } 257 default: 258 { 259 cout << "The state has an invalid value: " << state << endl; 260 break; 261 } 246 262 } 247 263 }
Note:
See TracChangeset
for help on using the changeset viewer.