Changeset b128109 in network-game for server/server.cpp
- Timestamp:
- Jan 29, 2013, 7:34:29 PM (12 years ago)
- Branches:
- master
- Children:
- 60b77d2
- Parents:
- 5806dc2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/server.cpp
r5806dc2 rb128109 14 14 #include <netinet/in.h> 15 15 #include <arpa/inet.h> 16 17 #include <crypt.h> 16 18 17 19 /* … … 129 131 broadcastResponse = processMessage(clientMsg, from, mapPlayers, unusedId, serverMsg); 130 132 133 // probably replace this with a function that prints based on the 134 // message type 131 135 cout << "msg: " << serverMsg.buffer << endl; 132 136 cout << "broadcastResponse: " << broadcastResponse << endl; 133 137 if (broadcastResponse) 134 138 { … … 197 201 string username(clientMsg.buffer); 198 202 string password(strchr(clientMsg.buffer, '\0')+1); 199 cout << "Player logging in: " << username << endl;200 203 201 204 Player* p = da.getPlayer(username); 202 205 203 if (p == NULL || p->password != password)206 if (p == NULL || !da.verifyPassword(password, p->password)) 204 207 { 205 208 strcpy(serverMsg.buffer, "Incorrect username or password"); … … 272 275 broadcastResponse = true; 273 276 274 stringstreamss;275 ss << p->name << ": " << clientMsg.buffer;276 277 strcpy(serverMsg.buffer, ss.str().c_str());277 ostringstream oss; 278 oss << p->name << ": " << clientMsg.buffer; 279 280 strcpy(serverMsg.buffer, oss.str().c_str()); 278 281 } 279 282 280 283 serverMsg.type = MSG_TYPE_CHAT; 284 285 break; 286 } 287 case MSG_TYPE_PLAYER_MOVE: 288 { 289 istringstream iss; 290 iss.str(clientMsg.buffer); 291 292 cout << "PLAYER_MOVE" << endl; 293 294 int id, x, y; 295 296 memcpy(&id, clientMsg.buffer, 4); 297 memcpy(&x, clientMsg.buffer+4, 4); 298 memcpy(&y, clientMsg.buffer+8, 4); 299 300 cout << "x: " << x << endl; 301 cout << "y: " << y << endl; 302 cout << "id: " << id << endl; 303 304 if ( mapPlayers[id].addr.sin_addr.s_addr == from.sin_addr.s_addr && 305 mapPlayers[id].addr.sin_port == from.sin_port ) 306 { 307 memcpy(&mapPlayers[id].pos.x, clientMsg.buffer+4, 4); 308 memcpy(&mapPlayers[id].pos.y, clientMsg.buffer+8, 4); 309 310 serverMsg.type = MSG_TYPE_PLAYER_MOVE; 311 memcpy(serverMsg.buffer, clientMsg.buffer, 12); 312 313 broadcastResponse = true; 314 } 315 else // nned to send back a message indicating failure 316 cout << "Player id (" << id << ") doesn't match sender" << endl; 281 317 282 318 break;
Note:
See TracChangeset
for help on using the changeset viewer.