- Timestamp:
- Nov 26, 2012, 8:02:25 PM (12 years ago)
- Branches:
- master
- Children:
- b13b001
- Parents:
- 171c4fe
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/server.cpp
r171c4fe r07028b9 102 102 switch(clientMsg.type) 103 103 { 104 { 105 case MSG_TYPE_LOGIN: 106 string name(clientMsg.buffer); 107 cout << "Player logging in: " << name << endl; 108 109 player *p = findPlayerByName(vctPlayers, name); 110 111 if (p == NULL) 112 { 113 vctPlayers.push_back(player(name, from)); 114 strcpy(serverMsg.buffer, "I'm thinking of a number between 1 and 1000. Guess what it is."); 115 } 116 else 117 { 118 strcpy(serverMsg.buffer, "Player has already logged in."); 119 } 120 121 serverMsg.type = MSG_TYPE_LOGIN; 122 123 break; 104 case MSG_TYPE_LOGIN: 105 { 106 string name(clientMsg.buffer); 107 cout << "Player logging in: " << name << endl; 108 109 player *p = findPlayerByName(vctPlayers, name); 110 111 if (p == NULL) 112 { 113 vctPlayers.push_back(player(name, from)); 114 strcpy(serverMsg.buffer, "I'm thinking of a number between 1 and 1000. Guess what it is."); 115 } 116 else 117 { 118 strcpy(serverMsg.buffer, "Player has already logged in."); 119 } 120 121 serverMsg.type = MSG_TYPE_LOGIN; 122 123 break; 124 } 125 case MSG_TYPE_LOGOUT: 126 { 127 string name(clientMsg.buffer); 128 cout << "Player logging out: " << name << endl; 129 130 player *p = findPlayerByName(vctPlayers, name); 131 132 if (p == NULL) 133 { 134 strcpy(serverMsg.buffer, "That player is not logged in. This is either a bug, or you're trying to hack the server."); 135 } 136 else 137 { 138 vctPlayers.erase(p); 139 strcpy(serverMsg.buffer, "You have successfully logged out. You may quit the game."); 140 } 141 } 142 case MSG_TYPE_CHAT: 143 { 144 int guess = atoi(clientMsg.buffer); 145 146 cout << "guess: " << guess << endl; 147 148 if (guess < 1 || guess > 1000) { 149 strcpy(serverMsg.buffer, "You must guess a number between 1 and 1000"); 150 }else if(guess > num) 151 strcpy(serverMsg.buffer, "The number I'm thinking of is less than that."); 152 else if(guess < num) 153 strcpy(serverMsg.buffer, "The number I'm thinking of is greater than that."); 154 else if(guess == num) { 155 strcpy(serverMsg.buffer, "Congratulations! I will now think of a new number."); 156 num = (rand() % 1000) + 1; 157 } 158 159 serverMsg.type = MSG_TYPE_CHAT; 160 161 break; 162 } 163 default: 164 { 165 strcpy(serverMsg.buffer, "Server error occured. Report this please."); 166 167 serverMsg.type = MSG_TYPE_CHAT; 168 169 break; 170 } 124 171 } 125 case MSG_TYPE_CHAT:126 {127 int guess = atoi(clientMsg.buffer);128 129 cout << "guess: " << guess << endl;130 131 if (guess < 1 || guess > 1000) {132 strcpy(serverMsg.buffer, "You must guess a number between 1 and 1000");133 }else if(guess > num)134 strcpy(serverMsg.buffer, "The number I'm thinking of is less than that.");135 else if(guess < num)136 strcpy(serverMsg.buffer, "The number I'm thinking of is greater than that.");137 else if(guess == num) {138 strcpy(serverMsg.buffer, "Congratulations! I will now think of a new number.");139 num = (rand() % 1000) + 1;140 }141 142 serverMsg.type = MSG_TYPE_CHAT;143 144 break;145 }146 default:147 {148 strcpy(serverMsg.buffer, "Server error occured. Report this please.");149 150 serverMsg.type = MSG_TYPE_CHAT;151 152 break;153 }154 }155 156 /*157 if (strcmp(clientMsg.buffer, "Hello") == 0)158 {159 player *p = findPlayerByName(vctPlayers, "Boberty");160 161 if (p == NULL)162 {163 vctPlayers.push_back(player("Boberty", from));164 strcpy(serverMsg.buffer, "I'm thinking of a number between 1 and 1000. Guess what it is.");165 }166 else167 {168 strcpy(serverMsg.buffer, "Player has already logged in.");169 }170 }else {171 int guess = atoi(clientMsg.buffer);172 173 cout << "guess: " << guess << endl;174 175 if (guess < 1 || guess > 1000) {176 strcpy(serverMsg.buffer, "You must guess a number between 1 and 1000");177 }else if(guess > num)178 strcpy(serverMsg.buffer, "The number I'm thinking of is less than that.");179 else if(guess < num)180 strcpy(serverMsg.buffer, "The number I'm thinking of is greater than that.");181 else if(guess == num) {182 strcpy(serverMsg.buffer, "Congratulations! I will now think of a new number.");183 num = (rand() % 1000) + 1;184 }185 }186 */187 172 188 173 cout << "msg: " << serverMsg.buffer << endl;
Note:
See TracChangeset
for help on using the changeset viewer.