- Timestamp:
- Dec 3, 2012, 12:27:01 AM (12 years ago)
- Branches:
- master
- Children:
- cbc595d
- Parents:
- 87b3ee2
- Location:
- server
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
server/DataAccess.cpp
r87b3ee2 r41ad8ed 43 43 result = select("users", oss.str().c_str()); 44 44 45 cout << "Got result" << endl; 46 45 47 if (result == NULL) { 48 cout << "Error occured" << endl; 46 49 cout << mysql_error(connection) << endl; 47 50 return NULL; … … 50 53 if ( ( row = mysql_fetch_row(result)) != NULL ) 51 54 p = new Player(string(row[1]), string(row[2])); 52 else 55 else { 56 cout << "Returned no results for some reason" << endl; 53 57 p = NULL; 58 } 54 59 55 60 mysql_free_result(result); -
server/Player.cpp
r87b3ee2 r41ad8ed 27 27 } 28 28 29 // was meant for the find find function. Currently unused30 bool Player::operator == (const Player &p)31 {32 bool eq = addr.sin_addr.s_addr == p.addr.sin_addr.s_addr;33 34 return eq;35 }36 37 29 void Player::setAddr(sockaddr_in addr) 38 30 { -
server/Player.h
r87b3ee2 r41ad8ed 13 13 ~Player(); 14 14 15 bool operator == (const Player &p);16 17 15 void setAddr(sockaddr_in addr); 18 16 -
server/server.cpp
r87b3ee2 r41ad8ed 25 25 #include "../common/message.h" 26 26 27 /*28 Protocol Design29 30 Client sends a login message31 Server replies with client's position in the world and positions of32 oall other logged in players33 Merver sends player ids along with locations34 This means a newly logged in client will need to know which id is35 assigned to it36 So server needs to send an id message, wait for an ack, and then send37 the location messages38 When a client shuts down, it sends a message to indicate this so the39 server can remove it from the list of connected clients40 Eventually, there'll need to be a way to detect timeouts from clients41 (if they crashed or otherwise failed to send the logout message)42 */43 44 27 using namespace std; 45 28 … … 57 40 vector<Player>::iterator it; 58 41 42 cout << "Entered findPlayerByName" << endl; 43 59 44 for (it = vec.begin(); it != vec.end(); it++) 60 45 { 46 cout << "Comparing name" << endl; 61 47 if ( it->name.compare(name) == 0 ) 62 48 return &(*it); 63 49 } 64 50 51 cout << "About to return" << endl; 65 52 return NULL; 66 53 } … … 110 97 exit(1); 111 98 } 112 113 /* 114 DataAccess da; 115 116 da.printPlayers(); 117 118 da.insertPlayer("playerName3", "playerPass"); 119 cout << endl << "Inserted player" << endl << endl; 120 121 Player* p = da.getPlayer("playerName"); 122 cout << "player name: " << p->name << endl; 123 delete(p); 124 125 p = da.getPlayer("playerName3"); 126 cout << "player name: " << p->name << endl; 127 delete(p); 128 129 da.printPlayers(); 130 cout << endl; 131 */ 132 99 133 100 sock = socket(AF_INET, SOCK_DGRAM, 0); 134 101 if (sock < 0) error("Opening socket"); … … 168 135 void processMessage(const NETWORK_MSG &clientMsg, const struct sockaddr_in &from, vector<Player> &vctPlayers, int &num, NETWORK_MSG &serverMsg) 169 136 { 137 DataAccess da; 138 170 139 cout << "ip address: " << inet_ntoa(from.sin_addr) << endl; 171 140 cout << "port: " << from.sin_port << endl; … … 185 154 cout << "password: " << password << endl; 186 155 187 strcpy(serverMsg.buffer, "Registration test"); 156 da.insertPlayer(username, password); 157 158 strcpy(serverMsg.buffer, "Registration successful"); 188 159 189 160 serverMsg.type = MSG_TYPE_REGISTER; … … 194 165 { 195 166 string username(clientMsg.buffer); 167 string password(strchr(clientMsg.buffer, '\0')+1); 196 168 cout << "Player logging in: " << username << endl; 197 169 198 Player *p = findPlayerByName(vctPlayers, username); 199 200 if (p == NULL) 170 Player* p = da.getPlayer(username); 171 172 if (p == NULL || p->password != password) 173 { 174 if (p != NULL) 175 { 176 cout << "p->password: " << p->password << endl; 177 cout << "password: " << password << endl; 178 } 179 strcpy(serverMsg.buffer, "Incorrect username or password"); 180 } 181 else if(findPlayerByName(vctPlayers, username) != NULL) 182 { 183 strcpy(serverMsg.buffer, "Player has already logged in."); 184 } 185 else 201 186 { 202 187 Player newP(username, ""); … … 206 191 strcpy(serverMsg.buffer, "I'm thinking of a number between 1 and 1000. Guess what it is."); 207 192 } 208 else209 {210 strcpy(serverMsg.buffer, "Player has already logged in.");211 }212 193 213 194 serverMsg.type = MSG_TYPE_LOGIN; 195 196 delete(p); 214 197 215 198 break; … … 234 217 { 235 218 vctPlayers.erase((vector<Player>::iterator)p); 236 strcpy(serverMsg.buffer, "You have successfully logged out. You may quit the game.");219 strcpy(serverMsg.buffer, "You have successfully logged out."); 237 220 } 238 221
Note:
See TracChangeset
for help on using the changeset viewer.