[1] | 1 | #include "../common/cbasetypes.h" |
---|
| 2 | #include "../common/mmo.h" |
---|
| 3 | #include "../common/core.h" |
---|
| 4 | #include "../common/socket.h" |
---|
| 5 | #include "../common/db.h" |
---|
| 6 | #include "../common/timer.h" |
---|
| 7 | #include "../common/malloc.h" |
---|
| 8 | #include "../common/strlib.h" |
---|
| 9 | #include "../common/showmsg.h" |
---|
| 10 | #include "../common/version.h" |
---|
| 11 | #include "../common/md5calc.h" |
---|
| 12 | #include "../common/lock.h" |
---|
| 13 | #include "login.h" |
---|
| 14 | |
---|
| 15 | #include <stdio.h> |
---|
| 16 | #include <stdlib.h> |
---|
| 17 | #include <string.h> |
---|
| 18 | #include <sys/stat.h> // for stat/lstat/fstat |
---|
| 19 | |
---|
| 20 | extern struct Login_Config login_config; |
---|
| 21 | |
---|
| 22 | #define MAX_SERVERS 30 |
---|
| 23 | extern struct mmo_char_server server[MAX_SERVERS]; |
---|
| 24 | extern struct mmo_account* auth_dat; |
---|
| 25 | extern uint32 auth_num; |
---|
| 26 | extern int account_id_count; |
---|
| 27 | extern char GM_account_filename[1024]; |
---|
| 28 | |
---|
| 29 | int charif_sendallwos(int sfd, unsigned char *buf, unsigned int len); |
---|
| 30 | int search_account_index(char* account_name); |
---|
| 31 | int mmo_auth_new(struct mmo_account* account); |
---|
| 32 | void mmo_auth_sync(void); |
---|
| 33 | int mmo_auth_tostr(char* str, struct mmo_account* p); |
---|
| 34 | int read_gm_account(void); |
---|
| 35 | void send_GM_accounts(int fd); |
---|
| 36 | int isGM(int account_id); |
---|
| 37 | |
---|
| 38 | //--------------------------------------- |
---|
| 39 | // Packet parsing for administation login |
---|
| 40 | //--------------------------------------- |
---|
| 41 | int parse_admin(int fd) |
---|
| 42 | { |
---|
| 43 | unsigned int i, j; |
---|
| 44 | char* account_name; |
---|
| 45 | |
---|
| 46 | uint32 ipl = session[fd]->client_addr; |
---|
| 47 | char ip[16]; |
---|
| 48 | ip2str(ipl, ip); |
---|
| 49 | |
---|
| 50 | if( session[fd]->flag.eof ) |
---|
| 51 | { |
---|
| 52 | do_close(fd); |
---|
| 53 | ShowInfo("Remote administration has disconnected (session #%d).\n", fd); |
---|
| 54 | return 0; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | while( RFIFOREST(fd) >= 2 ) |
---|
| 58 | { |
---|
| 59 | uint16 command = RFIFOW(fd,0); |
---|
| 60 | |
---|
| 61 | switch( command ) |
---|
| 62 | { |
---|
| 63 | |
---|
| 64 | case 0x7530: // Request of the server version |
---|
| 65 | ShowStatus("'ladmin': Sending of the server version (ip: %s)\n", ip); |
---|
| 66 | WFIFOHEAD(fd,10); |
---|
| 67 | WFIFOW(fd,0) = 0x7531; |
---|
| 68 | WFIFOB(fd,2) = ATHENA_MAJOR_VERSION; |
---|
| 69 | WFIFOB(fd,3) = ATHENA_MINOR_VERSION; |
---|
| 70 | WFIFOB(fd,4) = ATHENA_REVISION; |
---|
| 71 | WFIFOB(fd,5) = ATHENA_RELEASE_FLAG; |
---|
| 72 | WFIFOB(fd,6) = ATHENA_OFFICIAL_FLAG; |
---|
| 73 | WFIFOB(fd,7) = ATHENA_SERVER_LOGIN; |
---|
| 74 | WFIFOW(fd,8) = ATHENA_MOD_VERSION; |
---|
| 75 | WFIFOSET(fd,10); |
---|
| 76 | RFIFOSKIP(fd,2); |
---|
| 77 | break; |
---|
| 78 | |
---|
| 79 | case 0x7920: // Request of an accounts list |
---|
| 80 | if (RFIFOREST(fd) < 10) |
---|
| 81 | return 0; |
---|
| 82 | { |
---|
| 83 | int st, ed; |
---|
| 84 | uint16 len; |
---|
| 85 | CREATE_BUFFER(id, int, auth_num); |
---|
| 86 | st = RFIFOL(fd,2); |
---|
| 87 | ed = RFIFOL(fd,6); |
---|
| 88 | RFIFOSKIP(fd,10); |
---|
| 89 | WFIFOW(fd,0) = 0x7921; |
---|
| 90 | if (st < 0) |
---|
| 91 | st = 0; |
---|
| 92 | if (ed > END_ACCOUNT_NUM || ed < st || ed <= 0) |
---|
| 93 | ed = END_ACCOUNT_NUM; |
---|
| 94 | ShowStatus("'ladmin': Sending an accounts list (ask: from %d to %d, ip: %s)\n", st, ed, ip); |
---|
| 95 | // Sort before send |
---|
| 96 | for(i = 0; i < auth_num; i++) { |
---|
| 97 | unsigned int k; |
---|
| 98 | id[i] = i; |
---|
| 99 | for(j = 0; j < i; j++) { |
---|
| 100 | if (auth_dat[id[i]].account_id < auth_dat[id[j]].account_id) { |
---|
| 101 | for(k = i; k > j; k--) { |
---|
| 102 | id[k] = id[k-1]; |
---|
| 103 | } |
---|
| 104 | id[j] = i; // id[i] |
---|
| 105 | break; |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | // Sending accounts information |
---|
| 110 | len = 4; |
---|
| 111 | for(i = 0; i < auth_num && len < 30000; i++) { |
---|
| 112 | int account_id = auth_dat[id[i]].account_id; // use sorted index |
---|
| 113 | if (account_id >= st && account_id <= ed) { |
---|
| 114 | j = id[i]; |
---|
| 115 | WFIFOL(fd,len) = account_id; |
---|
| 116 | WFIFOB(fd,len+4) = (unsigned char)isGM(account_id); |
---|
| 117 | memcpy(WFIFOP(fd,len+5), auth_dat[j].userid, 24); |
---|
| 118 | WFIFOB(fd,len+29) = auth_dat[j].sex; |
---|
| 119 | WFIFOL(fd,len+30) = auth_dat[j].logincount; |
---|
| 120 | if (auth_dat[j].state == 0 && auth_dat[j].unban_time != 0) // if no state and banished |
---|
| 121 | WFIFOL(fd,len+34) = 7; // 6 = Your are Prohibited to log in until %s |
---|
| 122 | else |
---|
| 123 | WFIFOL(fd,len+34) = auth_dat[j].state; |
---|
| 124 | len += 38; |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | WFIFOW(fd,2) = len; |
---|
| 128 | WFIFOSET(fd,len); |
---|
| 129 | //if (id) free(id); |
---|
| 130 | DELETE_BUFFER(id); |
---|
| 131 | } |
---|
| 132 | break; |
---|
| 133 | |
---|
| 134 | case 0x7930: // Request for an account creation |
---|
| 135 | if (RFIFOREST(fd) < 91) |
---|
| 136 | return 0; |
---|
| 137 | { |
---|
| 138 | struct mmo_account ma; |
---|
| 139 | safestrncpy(ma.userid, (char*)RFIFOP(fd, 2), NAME_LENGTH); |
---|
| 140 | safestrncpy(ma.pass, (char*)RFIFOP(fd,26), NAME_LENGTH); |
---|
| 141 | safestrncpy(ma.email, (char*)RFIFOP(fd,51), 40); |
---|
| 142 | memcpy(ma.lastlogin, "-", 2); |
---|
| 143 | ma.sex = RFIFOB(fd,50); |
---|
| 144 | RFIFOSKIP(fd,91); |
---|
| 145 | |
---|
| 146 | WFIFOW(fd,0) = 0x7931; |
---|
| 147 | WFIFOL(fd,2) = 0xffffffff; // invalid account id |
---|
| 148 | safestrncpy((char*)WFIFOP(fd,6), ma.userid, 24); |
---|
| 149 | if (strlen(ma.userid) < 4 || strlen(ma.pass) < 4) { |
---|
| 150 | ShowNotice("'ladmin': Attempt to create an invalid account (account or pass is too short, ip: %s)\n", ip); |
---|
| 151 | } else if (ma.sex != 'F' && ma.sex != 'M') { |
---|
| 152 | ShowNotice("'ladmin': Attempt to create an invalid account (account: %s, received pass: %s, invalid sex, ip: %s)\n", ma.userid, ma.pass, ip); |
---|
| 153 | } else if (account_id_count > END_ACCOUNT_NUM) { |
---|
| 154 | ShowNotice("'ladmin': Attempt to create an account, but there is no more available id number (account: %s, pass: %s, sex: %c, ip: %s)\n", ma.userid, ma.pass, ma.sex, ip); |
---|
| 155 | } else { |
---|
| 156 | remove_control_chars(ma.userid); |
---|
| 157 | remove_control_chars(ma.pass); |
---|
| 158 | remove_control_chars(ma.email); |
---|
| 159 | ARR_FIND( 0, auth_num, i, strncmp(auth_dat[i].userid, ma.userid, 24) == 0 ); |
---|
| 160 | if( i < auth_num ) |
---|
| 161 | ShowNotice("'ladmin': Attempt to create an already existing account (account: %s, pass: %s, received pass: %s, ip: %s)\n", auth_dat[i].userid, auth_dat[i].pass, ma.pass, ip); |
---|
| 162 | else |
---|
| 163 | { |
---|
| 164 | int new_id; |
---|
| 165 | new_id = mmo_auth_new(&ma); |
---|
| 166 | ShowNotice("'ladmin': Account creation (account: %s (id: %d), pass: %s, sex: %c, email: %s, ip: %s)\n", ma.userid, new_id, ma.pass, ma.sex, auth_dat[i].email, ip); |
---|
| 167 | WFIFOL(fd,2) = new_id; |
---|
| 168 | mmo_auth_sync(); |
---|
| 169 | } |
---|
| 170 | } |
---|
| 171 | WFIFOSET(fd,30); |
---|
| 172 | } |
---|
| 173 | break; |
---|
| 174 | |
---|
| 175 | case 0x7932: // Request for an account deletion |
---|
| 176 | if (RFIFOREST(fd) < 26) |
---|
| 177 | return 0; |
---|
| 178 | WFIFOW(fd,0) = 0x7933; |
---|
| 179 | WFIFOL(fd,2) = 0xFFFFFFFF; |
---|
| 180 | account_name = (char*)RFIFOP(fd,2); |
---|
| 181 | account_name[23] = '\0'; |
---|
| 182 | remove_control_chars(account_name); |
---|
| 183 | i = search_account_index(account_name); |
---|
| 184 | if (i != -1) { |
---|
| 185 | // Char-server is notified of deletion (for characters deletion). |
---|
| 186 | unsigned char buf[65535]; |
---|
| 187 | WBUFW(buf,0) = 0x2730; |
---|
| 188 | WBUFL(buf,2) = auth_dat[i].account_id; |
---|
| 189 | charif_sendallwos(-1, buf, 6); |
---|
| 190 | // send answer |
---|
| 191 | memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); |
---|
| 192 | WFIFOL(fd,2) = auth_dat[i].account_id; |
---|
| 193 | // save deleted account in log file |
---|
| 194 | ShowNotice("'ladmin': Account deletion (account: %s, id: %d, ip: %s) - saved in next line:\n", auth_dat[i].userid, auth_dat[i].account_id, ip); |
---|
| 195 | mmo_auth_tostr((char*)buf, &auth_dat[i]); |
---|
| 196 | ShowNotice("%s\n", buf); |
---|
| 197 | // delete account |
---|
| 198 | memset(auth_dat[i].userid, '\0', sizeof(auth_dat[i].userid)); |
---|
| 199 | auth_dat[i].account_id = -1; |
---|
| 200 | mmo_auth_sync(); |
---|
| 201 | } else { |
---|
| 202 | memcpy(WFIFOP(fd,6), account_name, 24); |
---|
| 203 | ShowNotice("'ladmin': Attempt to delete an unknown account (account: %s, ip: %s)\n", account_name, ip); |
---|
| 204 | } |
---|
| 205 | WFIFOSET(fd,30); |
---|
| 206 | RFIFOSKIP(fd,26); |
---|
| 207 | break; |
---|
| 208 | |
---|
| 209 | case 0x7934: // Request to change a password |
---|
| 210 | if (RFIFOREST(fd) < 50) |
---|
| 211 | return 0; |
---|
| 212 | WFIFOW(fd,0) = 0x7935; |
---|
| 213 | WFIFOL(fd,2) = 0xFFFFFFFF; /// WTF??? an unsigned being set to a -1 |
---|
| 214 | account_name = (char*)RFIFOP(fd,2); |
---|
| 215 | account_name[23] = '\0'; |
---|
| 216 | remove_control_chars(account_name); |
---|
| 217 | i = search_account_index(account_name); |
---|
| 218 | if (i != -1) { |
---|
| 219 | memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); |
---|
| 220 | memcpy(auth_dat[i].pass, RFIFOP(fd,26), 24); |
---|
| 221 | auth_dat[i].pass[23] = '\0'; |
---|
| 222 | remove_control_chars(auth_dat[i].pass); |
---|
| 223 | WFIFOL(fd,2) = auth_dat[i].account_id; |
---|
| 224 | ShowNotice("'ladmin': Modification of a password (account: %s, new password: %s, ip: %s)\n", auth_dat[i].userid, auth_dat[i].pass, ip); |
---|
| 225 | mmo_auth_sync(); |
---|
| 226 | } else { |
---|
| 227 | memcpy(WFIFOP(fd,6), account_name, 24); |
---|
| 228 | ShowNotice("'ladmin': Attempt to modify the password of an unknown account (account: %s, ip: %s)\n", account_name, ip); |
---|
| 229 | } |
---|
| 230 | WFIFOSET(fd,30); |
---|
| 231 | RFIFOSKIP(fd,50); |
---|
| 232 | break; |
---|
| 233 | |
---|
| 234 | case 0x7936: // Request to modify a state |
---|
| 235 | if (RFIFOREST(fd) < 50) |
---|
| 236 | return 0; |
---|
| 237 | { |
---|
| 238 | char error_message[20]; |
---|
| 239 | uint32 statut; |
---|
| 240 | WFIFOW(fd,0) = 0x7937; |
---|
| 241 | WFIFOL(fd,2) = 0xFFFFFFFF; // WTF??? |
---|
| 242 | account_name = (char*)RFIFOP(fd,2); |
---|
| 243 | account_name[23] = '\0'; |
---|
| 244 | remove_control_chars(account_name); |
---|
| 245 | statut = RFIFOL(fd,26); |
---|
| 246 | memcpy(error_message, RFIFOP(fd,30), 20); |
---|
| 247 | error_message[19] = '\0'; |
---|
| 248 | remove_control_chars(error_message); |
---|
| 249 | if (statut != 7 || error_message[0] == '\0') { // 7: // 6 = Your are Prohibited to log in until %s |
---|
| 250 | strcpy(error_message, "-"); |
---|
| 251 | } |
---|
| 252 | i = search_account_index(account_name); |
---|
| 253 | if (i != -1) { |
---|
| 254 | memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); |
---|
| 255 | WFIFOL(fd,2) = auth_dat[i].account_id; |
---|
| 256 | if (auth_dat[i].state == statut && strcmp(auth_dat[i].error_message, error_message) == 0) |
---|
| 257 | ShowNotice("'ladmin': Modification of a state, but the state of the account is already the good state (account: %s, received state: %d, ip: %s)\n", account_name, statut, ip); |
---|
| 258 | else { |
---|
| 259 | if (statut == 7) |
---|
| 260 | ShowNotice("'ladmin': Modification of a state (account: %s, new state: %d - prohibited to login until '%s', ip: %s)\n", auth_dat[i].userid, statut, error_message, ip); |
---|
| 261 | else |
---|
| 262 | ShowNotice("'ladmin': Modification of a state (account: %s, new state: %d, ip: %s)\n", auth_dat[i].userid, statut, ip); |
---|
| 263 | if (auth_dat[i].state == 0) { |
---|
| 264 | unsigned char buf[16]; |
---|
| 265 | WBUFW(buf,0) = 0x2731; |
---|
| 266 | WBUFL(buf,2) = auth_dat[i].account_id; |
---|
| 267 | WBUFB(buf,6) = 0; // 0: change of statut, 1: ban |
---|
| 268 | WBUFL(buf,7) = statut; // status or final date of a banishment |
---|
| 269 | charif_sendallwos(-1, buf, 11); |
---|
| 270 | } |
---|
| 271 | auth_dat[i].state = statut; |
---|
| 272 | memcpy(auth_dat[i].error_message, error_message, 20); |
---|
| 273 | mmo_auth_sync(); |
---|
| 274 | } |
---|
| 275 | } else { |
---|
| 276 | memcpy(WFIFOP(fd,6), account_name, 24); |
---|
| 277 | ShowNotice("'ladmin': Attempt to modify the state of an unknown account (account: %s, received state: %d, ip: %s)\n", account_name, statut, ip); |
---|
| 278 | } |
---|
| 279 | WFIFOL(fd,30) = statut; |
---|
| 280 | } |
---|
| 281 | WFIFOSET(fd,34); |
---|
| 282 | RFIFOSKIP(fd,50); |
---|
| 283 | break; |
---|
| 284 | |
---|
| 285 | case 0x7938: // Request for servers list and # of online players |
---|
| 286 | { |
---|
| 287 | uint8 server_num = 0; |
---|
| 288 | ShowStatus("'ladmin': Sending of servers list (ip: %s)\n", ip); |
---|
| 289 | for(i = 0; i < MAX_SERVERS; i++) { |
---|
| 290 | if (server[i].fd >= 0) { |
---|
| 291 | WFIFOL(fd,4+server_num*32) = htonl(server[i].ip); |
---|
| 292 | WFIFOW(fd,4+server_num*32+4) = htons(server[i].port); |
---|
| 293 | memcpy(WFIFOP(fd,4+server_num*32+6), server[i].name, 20); |
---|
| 294 | WFIFOW(fd,4+server_num*32+26) = server[i].users; |
---|
| 295 | WFIFOW(fd,4+server_num*32+28) = server[i].maintenance; |
---|
| 296 | WFIFOW(fd,4+server_num*32+30) = server[i].new_; |
---|
| 297 | server_num++; |
---|
| 298 | } |
---|
| 299 | } |
---|
| 300 | WFIFOW(fd,0) = 0x7939; |
---|
| 301 | WFIFOW(fd,2) = 4 + 32 * server_num; |
---|
| 302 | WFIFOSET(fd,4+32*server_num); |
---|
| 303 | RFIFOSKIP(fd,2); |
---|
| 304 | break; |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | case 0x793a: // Request to password check |
---|
| 308 | if (RFIFOREST(fd) < 50) |
---|
| 309 | return 0; |
---|
| 310 | WFIFOW(fd,0) = 0x793b; |
---|
| 311 | WFIFOL(fd,2) = 0xFFFFFFFF; // WTF??? |
---|
| 312 | account_name = (char*)RFIFOP(fd,2); |
---|
| 313 | account_name[23] = '\0'; |
---|
| 314 | remove_control_chars(account_name); |
---|
| 315 | i = search_account_index(account_name); |
---|
| 316 | if (i != -1) { |
---|
| 317 | char pass[25]; |
---|
| 318 | memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); |
---|
| 319 | memcpy(pass, RFIFOP(fd,26), 24); |
---|
| 320 | pass[24] = '\0'; |
---|
| 321 | remove_control_chars(pass); |
---|
| 322 | if (strcmp(auth_dat[i].pass, pass) == 0) { |
---|
| 323 | WFIFOL(fd,2) = auth_dat[i].account_id; |
---|
| 324 | ShowNotice("'ladmin': Check of password OK (account: %s, password: %s, ip: %s)\n", auth_dat[i].userid, auth_dat[i].pass, ip); |
---|
| 325 | } else { |
---|
| 326 | ShowNotice("'ladmin': Failure of password check (account: %s, proposed pass: %s, ip: %s)\n", auth_dat[i].userid, pass, ip); |
---|
| 327 | } |
---|
| 328 | } else { |
---|
| 329 | memcpy(WFIFOP(fd,6), account_name, 24); |
---|
| 330 | ShowNotice("'ladmin': Attempt to check the password of an unknown account (account: %s, ip: %s)\n", account_name, ip); |
---|
| 331 | } |
---|
| 332 | WFIFOSET(fd,30); |
---|
| 333 | RFIFOSKIP(fd,50); |
---|
| 334 | break; |
---|
| 335 | |
---|
| 336 | case 0x793c: // Request to modify sex |
---|
| 337 | if (RFIFOREST(fd) < 27) |
---|
| 338 | return 0; |
---|
| 339 | WFIFOW(fd,0) = 0x793d; |
---|
| 340 | WFIFOL(fd,2) = 0xFFFFFFFF; // WTF??? |
---|
| 341 | account_name = (char*)RFIFOP(fd,2); |
---|
| 342 | account_name[23] = '\0'; |
---|
| 343 | remove_control_chars(account_name); |
---|
| 344 | memcpy(WFIFOP(fd,6), account_name, 24); |
---|
| 345 | { |
---|
| 346 | char sex; |
---|
| 347 | sex = RFIFOB(fd,26); |
---|
| 348 | if (sex != 'F' && sex != 'M') { |
---|
| 349 | if (sex > 31) |
---|
| 350 | ShowNotice("'ladmin': Attempt to give an invalid sex (account: %s, received sex: %c, ip: %s)\n", account_name, sex, ip); |
---|
| 351 | else |
---|
| 352 | ShowNotice("'ladmin': Attempt to give an invalid sex (account: %s, received sex: 'control char', ip: %s)\n", account_name, ip); |
---|
| 353 | } else { |
---|
| 354 | i = search_account_index(account_name); |
---|
| 355 | if (i != -1) { |
---|
| 356 | memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); |
---|
| 357 | if (auth_dat[i].sex != ((sex == 'S' || sex == 's') ? 2 : (sex == 'M' || sex == 'm'))) { |
---|
| 358 | unsigned char buf[16]; |
---|
| 359 | WFIFOL(fd,2) = auth_dat[i].account_id; |
---|
| 360 | auth_dat[i].sex = (sex == 'S' || sex == 's') ? 2 : (sex == 'M' || sex == 'm'); |
---|
| 361 | ShowNotice("'ladmin': Modification of a sex (account: %s, new sex: %c, ip: %s)\n", auth_dat[i].userid, sex, ip); |
---|
| 362 | mmo_auth_sync(); |
---|
| 363 | // send to all char-server the change |
---|
| 364 | WBUFW(buf,0) = 0x2723; |
---|
| 365 | WBUFL(buf,2) = auth_dat[i].account_id; |
---|
| 366 | WBUFB(buf,6) = auth_dat[i].sex; |
---|
| 367 | charif_sendallwos(-1, buf, 7); |
---|
| 368 | } else { |
---|
| 369 | ShowNotice("'ladmin': Modification of a sex, but the sex is already the good sex (account: %s, sex: %c, ip: %s)\n", auth_dat[i].userid, sex, ip); |
---|
| 370 | } |
---|
| 371 | } else { |
---|
| 372 | ShowNotice("'ladmin': Attempt to modify the sex of an unknown account (account: %s, received sex: %c, ip: %s)\n", account_name, sex, ip); |
---|
| 373 | } |
---|
| 374 | } |
---|
| 375 | } |
---|
| 376 | WFIFOSET(fd,30); |
---|
| 377 | RFIFOSKIP(fd,27); |
---|
| 378 | break; |
---|
| 379 | |
---|
| 380 | case 0x793e: // Request to modify GM level |
---|
| 381 | if (RFIFOREST(fd) < 27) |
---|
| 382 | return 0; |
---|
| 383 | WFIFOW(fd,0) = 0x793f; |
---|
| 384 | WFIFOL(fd,2) = 0xFFFFFFFF; // WTF??? |
---|
| 385 | account_name = (char*)RFIFOP(fd,2); |
---|
| 386 | account_name[23] = '\0'; |
---|
| 387 | remove_control_chars(account_name); |
---|
| 388 | memcpy(WFIFOP(fd,6), account_name, 24); |
---|
| 389 | { |
---|
| 390 | char new_gm_level; |
---|
| 391 | new_gm_level = RFIFOB(fd,26); |
---|
| 392 | if (new_gm_level < 0 || new_gm_level > 99) { |
---|
| 393 | ShowNotice("'ladmin': Attempt to give an invalid GM level (account: %s, received GM level: %d, ip: %s)\n", account_name, (int)new_gm_level, ip); |
---|
| 394 | } else { |
---|
| 395 | i = search_account_index(account_name); |
---|
| 396 | if (i != -1) { |
---|
| 397 | int acc = auth_dat[i].account_id; |
---|
| 398 | memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); |
---|
| 399 | if (isGM(acc) != new_gm_level) { |
---|
| 400 | // modification of the file |
---|
| 401 | FILE *fp, *fp2; |
---|
| 402 | int lock; |
---|
| 403 | char line[512]; |
---|
| 404 | int GM_account, GM_level; |
---|
| 405 | int modify_flag; |
---|
| 406 | char tmpstr[24]; |
---|
| 407 | time_t raw_time; |
---|
| 408 | if ((fp2 = lock_fopen(GM_account_filename, &lock)) != NULL) { |
---|
| 409 | if ((fp = fopen(GM_account_filename, "r")) != NULL) { |
---|
| 410 | time(&raw_time); |
---|
| 411 | strftime(tmpstr, 23, login_config.date_format, localtime(&raw_time)); |
---|
| 412 | modify_flag = 0; |
---|
| 413 | // read/write GM file |
---|
| 414 | while(fgets(line, sizeof(line), fp)) |
---|
| 415 | { |
---|
| 416 | while(line[0] != '\0' && (line[strlen(line)-1] == '\n' || line[strlen(line)-1] == '\r')) |
---|
| 417 | line[strlen(line)-1] = '\0'; // TODO: remove this |
---|
| 418 | if ((line[0] == '/' && line[1] == '/') || line[0] == '\0') |
---|
| 419 | fprintf(fp2, "%s\n", line); |
---|
| 420 | else { |
---|
| 421 | if (sscanf(line, "%d %d", &GM_account, &GM_level) != 2 && sscanf(line, "%d: %d", &GM_account, &GM_level) != 2) |
---|
| 422 | fprintf(fp2, "%s\n", line); |
---|
| 423 | else if (GM_account != acc) |
---|
| 424 | fprintf(fp2, "%s\n", line); |
---|
| 425 | else if (new_gm_level < 1) { |
---|
| 426 | fprintf(fp2, "// %s: 'ladmin' GM level removed on account %d '%s' (previous level: %d)\n//%d %d\n", tmpstr, acc, auth_dat[i].userid, GM_level, acc, new_gm_level); |
---|
| 427 | modify_flag = 1; |
---|
| 428 | } else { |
---|
| 429 | fprintf(fp2, "// %s: 'ladmin' GM level on account %d '%s' (previous level: %d)\n%d %d\n", tmpstr, acc, auth_dat[i].userid, GM_level, acc, new_gm_level); |
---|
| 430 | modify_flag = 1; |
---|
| 431 | } |
---|
| 432 | } |
---|
| 433 | } |
---|
| 434 | if (modify_flag == 0) |
---|
| 435 | fprintf(fp2, "// %s: 'ladmin' GM level on account %d '%s' (previous level: 0)\n%d %d\n", tmpstr, acc, auth_dat[i].userid, acc, new_gm_level); |
---|
| 436 | fclose(fp); |
---|
| 437 | } else { |
---|
| 438 | ShowNotice("'ladmin': Attempt to modify of a GM level - impossible to read GM accounts file (account: %s (%d), received GM level: %d, ip: %s)\n", auth_dat[i].userid, acc, (int)new_gm_level, ip); |
---|
| 439 | } |
---|
| 440 | if (lock_fclose(fp2, GM_account_filename, &lock) == 0) { |
---|
| 441 | WFIFOL(fd,2) = acc; |
---|
| 442 | ShowNotice("'ladmin': Modification of a GM level (account: %s (%d), new GM level: %d, ip: %s)\n", auth_dat[i].userid, acc, (int)new_gm_level, ip); |
---|
| 443 | // read and send new GM informations |
---|
| 444 | read_gm_account(); |
---|
| 445 | send_GM_accounts(-1); |
---|
| 446 | } else { |
---|
| 447 | ShowNotice("'ladmin': Attempt to modify of a GM level - impossible to write GM accounts file (account: %s (%d), received GM level: %d, ip: %s)\n", auth_dat[i].userid, acc, (int)new_gm_level, ip); |
---|
| 448 | } |
---|
| 449 | } else { |
---|
| 450 | ShowNotice("'ladmin': Attempt to modify of a GM level - impossible to write GM accounts file (account: %s (%d), received GM level: %d, ip: %s)\n", auth_dat[i].userid, acc, (int)new_gm_level, ip); |
---|
| 451 | } |
---|
| 452 | } else { |
---|
| 453 | ShowNotice("'ladmin': Attempt to modify of a GM level, but the GM level is already the good GM level (account: %s (%d), GM level: %d, ip: %s)\n", auth_dat[i].userid, acc, (int)new_gm_level, ip); |
---|
| 454 | } |
---|
| 455 | } else { |
---|
| 456 | ShowNotice("'ladmin': Attempt to modify the GM level of an unknown account (account: %s, received GM level: %d, ip: %s)\n", account_name, (int)new_gm_level, ip); |
---|
| 457 | } |
---|
| 458 | } |
---|
| 459 | } |
---|
| 460 | WFIFOSET(fd,30); |
---|
| 461 | RFIFOSKIP(fd,27); |
---|
| 462 | break; |
---|
| 463 | |
---|
| 464 | case 0x7940: // Request to modify e-mail |
---|
| 465 | if (RFIFOREST(fd) < 66) |
---|
| 466 | return 0; |
---|
| 467 | WFIFOW(fd,0) = 0x7941; |
---|
| 468 | WFIFOL(fd,2) = 0xFFFFFFFF; // WTF??? |
---|
| 469 | account_name = (char*)RFIFOP(fd,2); |
---|
| 470 | account_name[23] = '\0'; |
---|
| 471 | remove_control_chars(account_name); |
---|
| 472 | memcpy(WFIFOP(fd,6), account_name, 24); |
---|
| 473 | { |
---|
| 474 | char email[40]; |
---|
| 475 | memcpy(email, RFIFOP(fd,26), 40); |
---|
| 476 | if (e_mail_check(email) == 0) { |
---|
| 477 | ShowNotice("'ladmin': Attempt to give an invalid e-mail (account: %s, ip: %s)\n", account_name, ip); |
---|
| 478 | } else { |
---|
| 479 | remove_control_chars(email); |
---|
| 480 | i = search_account_index(account_name); |
---|
| 481 | if (i != -1) { |
---|
| 482 | memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); |
---|
| 483 | memcpy(auth_dat[i].email, email, 40); |
---|
| 484 | WFIFOL(fd,2) = auth_dat[i].account_id; |
---|
| 485 | ShowNotice("'ladmin': Modification of an email (account: %s, new e-mail: %s, ip: %s)\n", auth_dat[i].userid, email, ip); |
---|
| 486 | mmo_auth_sync(); |
---|
| 487 | } else { |
---|
| 488 | ShowNotice("'ladmin': Attempt to modify the e-mail of an unknown account (account: %s, received e-mail: %s, ip: %s)\n", account_name, email, ip); |
---|
| 489 | } |
---|
| 490 | } |
---|
| 491 | } |
---|
| 492 | WFIFOSET(fd,30); |
---|
| 493 | RFIFOSKIP(fd,66); |
---|
| 494 | break; |
---|
| 495 | |
---|
| 496 | case 0x7942: // Request to modify memo field |
---|
| 497 | if ((int)RFIFOREST(fd) < 28 || (int)RFIFOREST(fd) < (28 + RFIFOW(fd,26))) |
---|
| 498 | return 0; |
---|
| 499 | WFIFOW(fd,0) = 0x7943; |
---|
| 500 | WFIFOL(fd,2) = 0xFFFFFFFF; // WTF??? |
---|
| 501 | account_name = (char*)RFIFOP(fd,2); |
---|
| 502 | account_name[23] = '\0'; |
---|
| 503 | remove_control_chars(account_name); |
---|
| 504 | i = search_account_index(account_name); |
---|
| 505 | if (i != -1) { |
---|
| 506 | int size_of_memo = sizeof(auth_dat[i].memo); |
---|
| 507 | memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); |
---|
| 508 | memset(auth_dat[i].memo, '\0', size_of_memo); |
---|
| 509 | if (RFIFOW(fd,26) == 0) { |
---|
| 510 | strncpy(auth_dat[i].memo, "-", size_of_memo); |
---|
| 511 | } else if (RFIFOW(fd,26) > size_of_memo - 1) { |
---|
| 512 | memcpy(auth_dat[i].memo, RFIFOP(fd,28), size_of_memo - 1); |
---|
| 513 | } else { |
---|
| 514 | memcpy(auth_dat[i].memo, RFIFOP(fd,28), RFIFOW(fd,26)); |
---|
| 515 | } |
---|
| 516 | auth_dat[i].memo[size_of_memo - 1] = '\0'; |
---|
| 517 | remove_control_chars(auth_dat[i].memo); |
---|
| 518 | WFIFOL(fd,2) = auth_dat[i].account_id; |
---|
| 519 | ShowNotice("'ladmin': Modification of a memo field (account: %s, new memo: %s, ip: %s)\n", auth_dat[i].userid, auth_dat[i].memo, ip); |
---|
| 520 | mmo_auth_sync(); |
---|
| 521 | } else { |
---|
| 522 | memcpy(WFIFOP(fd,6), account_name, 24); |
---|
| 523 | ShowNotice("'ladmin': Attempt to modify the memo field of an unknown account (account: %s, ip: %s)\n", account_name, ip); |
---|
| 524 | } |
---|
| 525 | WFIFOSET(fd,30); |
---|
| 526 | RFIFOSKIP(fd,28 + RFIFOW(fd,26)); |
---|
| 527 | break; |
---|
| 528 | |
---|
| 529 | case 0x7944: // Request to found an account id |
---|
| 530 | if (RFIFOREST(fd) < 26) |
---|
| 531 | return 0; |
---|
| 532 | WFIFOW(fd,0) = 0x7945; |
---|
| 533 | WFIFOL(fd,2) = 0xFFFFFFFF; // WTF??? |
---|
| 534 | account_name = (char*)RFIFOP(fd,2); |
---|
| 535 | account_name[23] = '\0'; |
---|
| 536 | remove_control_chars(account_name); |
---|
| 537 | i = search_account_index(account_name); |
---|
| 538 | if (i != -1) { |
---|
| 539 | memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); |
---|
| 540 | WFIFOL(fd,2) = auth_dat[i].account_id; |
---|
| 541 | ShowNotice("'ladmin': Request (by the name) of an account id (account: %s, id: %d, ip: %s)\n", auth_dat[i].userid, auth_dat[i].account_id, ip); |
---|
| 542 | } else { |
---|
| 543 | memcpy(WFIFOP(fd,6), account_name, 24); |
---|
| 544 | ShowNotice("'ladmin': ID request (by the name) of an unknown account (account: %s, ip: %s)\n", account_name, ip); |
---|
| 545 | } |
---|
| 546 | WFIFOSET(fd,30); |
---|
| 547 | RFIFOSKIP(fd,26); |
---|
| 548 | break; |
---|
| 549 | |
---|
| 550 | case 0x7946: // Request to found an account name |
---|
| 551 | if (RFIFOREST(fd) < 6) |
---|
| 552 | return 0; |
---|
| 553 | WFIFOW(fd,0) = 0x7947; |
---|
| 554 | WFIFOL(fd,2) = RFIFOL(fd,2); |
---|
| 555 | memset(WFIFOP(fd,6), '\0', 24); |
---|
| 556 | for(i = 0; i < auth_num; i++) { |
---|
| 557 | if (auth_dat[i].account_id == (int)RFIFOL(fd,2)) { |
---|
| 558 | strncpy((char*)WFIFOP(fd,6), auth_dat[i].userid, 24); |
---|
| 559 | ShowNotice("'ladmin': Request (by id) of an account name (account: %s, id: %d, ip: %s)\n", auth_dat[i].userid, RFIFOL(fd,2), ip); |
---|
| 560 | break; |
---|
| 561 | } |
---|
| 562 | } |
---|
| 563 | if (i == auth_num) { |
---|
| 564 | ShowNotice("'ladmin': Name request (by id) of an unknown account (id: %d, ip: %s)\n", RFIFOL(fd,2), ip); |
---|
| 565 | strncpy((char*)WFIFOP(fd,6), "", 24); |
---|
| 566 | } |
---|
| 567 | WFIFOSET(fd,30); |
---|
| 568 | RFIFOSKIP(fd,6); |
---|
| 569 | break; |
---|
| 570 | |
---|
| 571 | case 0x7948: // Request to change the validity limit (timestamp) (absolute value) |
---|
| 572 | if (RFIFOREST(fd) < 30) |
---|
| 573 | return 0; |
---|
| 574 | { |
---|
| 575 | time_t timestamp; |
---|
| 576 | char tmpstr[2048]; |
---|
| 577 | WFIFOW(fd,0) = 0x7949; |
---|
| 578 | WFIFOL(fd,2) = 0xFFFFFFFF; // WTF??? |
---|
| 579 | account_name = (char*)RFIFOP(fd,2); |
---|
| 580 | account_name[23] = '\0'; |
---|
| 581 | remove_control_chars(account_name); |
---|
| 582 | timestamp = (time_t)RFIFOL(fd,26); |
---|
| 583 | strftime(tmpstr, 24, login_config.date_format, localtime(×tamp)); |
---|
| 584 | i = search_account_index(account_name); |
---|
| 585 | if (i != -1) { |
---|
| 586 | memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); |
---|
| 587 | ShowNotice("'ladmin': Change of a validity limit (account: %s, new validity: %d (%s), ip: %s)\n", auth_dat[i].userid, timestamp, (timestamp == 0 ? "unlimited" : tmpstr), ip); |
---|
| 588 | auth_dat[i].expiration_time = timestamp; |
---|
| 589 | WFIFOL(fd,2) = auth_dat[i].account_id; |
---|
| 590 | mmo_auth_sync(); |
---|
| 591 | } else { |
---|
| 592 | memcpy(WFIFOP(fd,6), account_name, 24); |
---|
| 593 | ShowNotice("'ladmin': Attempt to change the validity limit of an unknown account (account: %s, received validity: %d (%s), ip: %s)\n", account_name, timestamp, (timestamp == 0 ? "unlimited" : tmpstr), ip); |
---|
| 594 | } |
---|
| 595 | WFIFOL(fd,30) = (unsigned int)timestamp; |
---|
| 596 | } |
---|
| 597 | WFIFOSET(fd,34); |
---|
| 598 | RFIFOSKIP(fd,30); |
---|
| 599 | break; |
---|
| 600 | |
---|
| 601 | case 0x794a: // Request to change the final date of a banishment (timestamp) (absolute value) |
---|
| 602 | if (RFIFOREST(fd) < 30) |
---|
| 603 | return 0; |
---|
| 604 | { |
---|
| 605 | time_t timestamp; |
---|
| 606 | char tmpstr[2048]; |
---|
| 607 | WFIFOW(fd,0) = 0x794b; |
---|
| 608 | WFIFOL(fd,2) = 0xFFFFFFFF; // WTF??? |
---|
| 609 | account_name = (char*)RFIFOP(fd,2); |
---|
| 610 | account_name[23] = '\0'; |
---|
| 611 | remove_control_chars(account_name); |
---|
| 612 | timestamp = (time_t)RFIFOL(fd,26); |
---|
| 613 | if (timestamp <= time(NULL)) |
---|
| 614 | timestamp = 0; |
---|
| 615 | strftime(tmpstr, 24, login_config.date_format, localtime(×tamp)); |
---|
| 616 | i = search_account_index(account_name); |
---|
| 617 | if (i != -1) { |
---|
| 618 | memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); |
---|
| 619 | WFIFOL(fd,2) = auth_dat[i].account_id; |
---|
| 620 | ShowNotice("'ladmin': Change of the final date of a banishment (account: %s, new final date of banishment: %d (%s), ip: %s)\n", auth_dat[i].userid, timestamp, (timestamp == 0 ? "no banishment" : tmpstr), ip); |
---|
| 621 | if (auth_dat[i].unban_time != timestamp) { |
---|
| 622 | if (timestamp != 0) { |
---|
| 623 | unsigned char buf[16]; |
---|
| 624 | WBUFW(buf,0) = 0x2731; |
---|
| 625 | WBUFL(buf,2) = auth_dat[i].account_id; |
---|
| 626 | WBUFB(buf,6) = 1; // 0: change of statut, 1: ban |
---|
| 627 | WBUFL(buf,7) = (unsigned int)timestamp; // status or final date of a banishment |
---|
| 628 | charif_sendallwos(-1, buf, 11); |
---|
| 629 | } |
---|
| 630 | auth_dat[i].unban_time = timestamp; |
---|
| 631 | mmo_auth_sync(); |
---|
| 632 | } |
---|
| 633 | } else { |
---|
| 634 | memcpy(WFIFOP(fd,6), account_name, 24); |
---|
| 635 | ShowNotice("'ladmin': Attempt to change the final date of a banishment of an unknown account (account: %s, received final date of banishment: %d (%s), ip: %s)\n", account_name, timestamp, (timestamp == 0 ? "no banishment" : tmpstr), ip); |
---|
| 636 | } |
---|
| 637 | WFIFOL(fd,30) = (unsigned int)timestamp; |
---|
| 638 | } |
---|
| 639 | WFIFOSET(fd,34); |
---|
| 640 | RFIFOSKIP(fd,30); |
---|
| 641 | break; |
---|
| 642 | |
---|
| 643 | case 0x794c: // Request to change the final date of a banishment (timestamp) (relative change) |
---|
| 644 | if (RFIFOREST(fd) < 38) |
---|
| 645 | return 0; |
---|
| 646 | { |
---|
| 647 | time_t timestamp; |
---|
| 648 | struct tm *tmtime; |
---|
| 649 | char tmpstr[2048]; |
---|
| 650 | WFIFOW(fd,0) = 0x794d; |
---|
| 651 | WFIFOL(fd,2) = 0xFFFFFFFF; // WTF??? |
---|
| 652 | account_name = (char*)RFIFOP(fd,2); |
---|
| 653 | account_name[23] = '\0'; |
---|
| 654 | remove_control_chars(account_name); |
---|
| 655 | i = search_account_index(account_name); |
---|
| 656 | if (i != -1) { |
---|
| 657 | WFIFOL(fd,2) = auth_dat[i].account_id; |
---|
| 658 | memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); |
---|
| 659 | if (auth_dat[i].unban_time == 0 || auth_dat[i].unban_time < time(NULL)) |
---|
| 660 | timestamp = time(NULL); |
---|
| 661 | else |
---|
| 662 | timestamp = auth_dat[i].unban_time; |
---|
| 663 | tmtime = localtime(×tamp); |
---|
| 664 | tmtime->tm_year = tmtime->tm_year + (short)RFIFOW(fd,26); |
---|
| 665 | tmtime->tm_mon = tmtime->tm_mon + (short)RFIFOW(fd,28); |
---|
| 666 | tmtime->tm_mday = tmtime->tm_mday + (short)RFIFOW(fd,30); |
---|
| 667 | tmtime->tm_hour = tmtime->tm_hour + (short)RFIFOW(fd,32); |
---|
| 668 | tmtime->tm_min = tmtime->tm_min + (short)RFIFOW(fd,34); |
---|
| 669 | tmtime->tm_sec = tmtime->tm_sec + (short)RFIFOW(fd,36); |
---|
| 670 | timestamp = mktime(tmtime); |
---|
| 671 | if (timestamp != -1) { |
---|
| 672 | if (timestamp <= time(NULL)) |
---|
| 673 | timestamp = 0; |
---|
| 674 | strftime(tmpstr, 24, login_config.date_format, localtime(×tamp)); |
---|
| 675 | ShowNotice("'ladmin': Adjustment of a final date of a banishment (account: %s, (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %d (%s), ip: %s)\n", auth_dat[i].userid, (short)RFIFOW(fd,26), (short)RFIFOW(fd,28), (short)RFIFOW(fd,30), (short)RFIFOW(fd,32), (short)RFIFOW(fd,34), (short)RFIFOW(fd,36), timestamp, (timestamp == 0 ? "no banishment" : tmpstr), ip); |
---|
| 676 | if (auth_dat[i].unban_time != timestamp) { |
---|
| 677 | if (timestamp != 0) { |
---|
| 678 | unsigned char buf[16]; |
---|
| 679 | WBUFW(buf,0) = 0x2731; |
---|
| 680 | WBUFL(buf,2) = auth_dat[i].account_id; |
---|
| 681 | WBUFB(buf,6) = 1; // 0: change of statut, 1: ban |
---|
| 682 | WBUFL(buf,7) = (unsigned int)timestamp; // status or final date of a banishment |
---|
| 683 | charif_sendallwos(-1, buf, 11); |
---|
| 684 | } |
---|
| 685 | auth_dat[i].unban_time = timestamp; |
---|
| 686 | mmo_auth_sync(); |
---|
| 687 | } |
---|
| 688 | } else { |
---|
| 689 | strftime(tmpstr, 24, login_config.date_format, localtime(&auth_dat[i].unban_time)); |
---|
| 690 | ShowNotice("'ladmin': Impossible to adjust the final date of a banishment (account: %s, %d (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> ???, ip: %s)\n", auth_dat[i].userid, auth_dat[i].unban_time, (auth_dat[i].unban_time == 0 ? "no banishment" : tmpstr), (short)RFIFOW(fd,26), (short)RFIFOW(fd,28), (short)RFIFOW(fd,30), (short)RFIFOW(fd,32), (short)RFIFOW(fd,34), (short)RFIFOW(fd,36), ip); |
---|
| 691 | } |
---|
| 692 | WFIFOL(fd,30) = (unsigned long)auth_dat[i].unban_time; |
---|
| 693 | } else { |
---|
| 694 | memcpy(WFIFOP(fd,6), account_name, 24); |
---|
| 695 | ShowNotice("'ladmin': Attempt to adjust the final date of a banishment of an unknown account (account: %s, ip: %s)\n", account_name, ip); |
---|
| 696 | WFIFOL(fd,30) = 0; |
---|
| 697 | } |
---|
| 698 | } |
---|
| 699 | WFIFOSET(fd,34); |
---|
| 700 | RFIFOSKIP(fd,38); |
---|
| 701 | break; |
---|
| 702 | |
---|
| 703 | case 0x794e: // Request to send a broadcast message |
---|
| 704 | if (RFIFOREST(fd) < 8 || RFIFOREST(fd) < (8 + RFIFOL(fd,4))) |
---|
| 705 | return 0; |
---|
| 706 | WFIFOW(fd,0) = 0x794f; |
---|
| 707 | WFIFOW(fd,2) = 0xFFFF; // WTF??? |
---|
| 708 | if (RFIFOL(fd,4) < 1) { |
---|
| 709 | ShowNotice("'ladmin': Receiving a message for broadcast, but message is void (ip: %s)\n", ip); |
---|
| 710 | } else { |
---|
| 711 | // at least 1 char-server |
---|
| 712 | for(i = 0; i < MAX_SERVERS; i++) |
---|
| 713 | if (server[i].fd >= 0) |
---|
| 714 | break; |
---|
| 715 | if (i == MAX_SERVERS) { |
---|
| 716 | ShowNotice("'ladmin': Receiving a message for broadcast, but no char-server is online (ip: %s)\n", ip); |
---|
| 717 | } else { |
---|
| 718 | unsigned char buf[32000]; |
---|
| 719 | char message[32000]; |
---|
| 720 | WFIFOW(fd,2) = 0; |
---|
| 721 | memset(message, '\0', sizeof(message)); |
---|
| 722 | memcpy(message, RFIFOP(fd,8), RFIFOL(fd,4)); |
---|
| 723 | message[sizeof(message)-1] = '\0'; |
---|
| 724 | remove_control_chars(message); |
---|
| 725 | if (RFIFOW(fd,2) == 0) |
---|
| 726 | ShowNotice("'ladmin': Receiving a message for broadcast (message (in yellow): %s, ip: %s)\n", message, ip); |
---|
| 727 | else |
---|
| 728 | ShowNotice("'ladmin': Receiving a message for broadcast (message (in blue): %s, ip: %s)\n", message, ip); |
---|
| 729 | // send same message to all char-servers (no answer) |
---|
| 730 | memcpy(WBUFP(buf,0), RFIFOP(fd,0), 8 + RFIFOL(fd,4)); |
---|
| 731 | WBUFW(buf,0) = 0x2726; |
---|
| 732 | charif_sendallwos(-1, buf, 8 + RFIFOL(fd,4)); |
---|
| 733 | } |
---|
| 734 | } |
---|
| 735 | WFIFOSET(fd,4); |
---|
| 736 | RFIFOSKIP(fd,8 + RFIFOL(fd,4)); |
---|
| 737 | break; |
---|
| 738 | |
---|
| 739 | case 0x7950: // Request to change the validity limite (timestamp) (relative change) |
---|
| 740 | if (RFIFOREST(fd) < 38) |
---|
| 741 | return 0; |
---|
| 742 | { |
---|
| 743 | time_t timestamp; |
---|
| 744 | struct tm *tmtime; |
---|
| 745 | char tmpstr[2048]; |
---|
| 746 | char tmpstr2[2048]; |
---|
| 747 | WFIFOW(fd,0) = 0x7951; |
---|
| 748 | WFIFOL(fd,2) = 0xFFFFFFFF; // WTF??? |
---|
| 749 | account_name = (char*)RFIFOP(fd,2); |
---|
| 750 | account_name[23] = '\0'; |
---|
| 751 | remove_control_chars(account_name); |
---|
| 752 | i = search_account_index(account_name); |
---|
| 753 | if (i != -1) { |
---|
| 754 | WFIFOL(fd,2) = auth_dat[i].account_id; |
---|
| 755 | memcpy(WFIFOP(fd,6), auth_dat[i].userid, 24); |
---|
| 756 | timestamp = auth_dat[i].expiration_time; |
---|
| 757 | if (timestamp == 0 || timestamp < time(NULL)) |
---|
| 758 | timestamp = time(NULL); |
---|
| 759 | tmtime = localtime(×tamp); |
---|
| 760 | tmtime->tm_year = tmtime->tm_year + (short)RFIFOW(fd,26); |
---|
| 761 | tmtime->tm_mon = tmtime->tm_mon + (short)RFIFOW(fd,28); |
---|
| 762 | tmtime->tm_mday = tmtime->tm_mday + (short)RFIFOW(fd,30); |
---|
| 763 | tmtime->tm_hour = tmtime->tm_hour + (short)RFIFOW(fd,32); |
---|
| 764 | tmtime->tm_min = tmtime->tm_min + (short)RFIFOW(fd,34); |
---|
| 765 | tmtime->tm_sec = tmtime->tm_sec + (short)RFIFOW(fd,36); |
---|
| 766 | timestamp = mktime(tmtime); |
---|
| 767 | if (timestamp != -1) { |
---|
| 768 | strftime(tmpstr, 24, login_config.date_format, localtime(&auth_dat[i].expiration_time)); |
---|
| 769 | strftime(tmpstr2, 24, login_config.date_format, localtime(×tamp)); |
---|
| 770 | ShowNotice("'ladmin': Adjustment of a validity limit (account: %s, %d (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %d (%s), ip: %s)\n", auth_dat[i].userid, auth_dat[i].expiration_time, (auth_dat[i].expiration_time == 0 ? "unlimited" : tmpstr), (short)RFIFOW(fd,26), (short)RFIFOW(fd,28), (short)RFIFOW(fd,30), (short)RFIFOW(fd,32), (short)RFIFOW(fd,34), (short)RFIFOW(fd,36), timestamp, (timestamp == 0 ? "unlimited" : tmpstr2), ip); |
---|
| 771 | auth_dat[i].expiration_time = timestamp; |
---|
| 772 | mmo_auth_sync(); |
---|
| 773 | WFIFOL(fd,30) = (unsigned long)auth_dat[i].expiration_time; |
---|
| 774 | } else { |
---|
| 775 | strftime(tmpstr, 24, login_config.date_format, localtime(&auth_dat[i].expiration_time)); |
---|
| 776 | ShowNotice("'ladmin': Impossible to adjust a validity limit (account: %s, %d (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> ???, ip: %s)\n", auth_dat[i].userid, auth_dat[i].expiration_time, (auth_dat[i].expiration_time == 0 ? "unlimited" : tmpstr), (short)RFIFOW(fd,26), (short)RFIFOW(fd,28), (short)RFIFOW(fd,30), (short)RFIFOW(fd,32), (short)RFIFOW(fd,34), (short)RFIFOW(fd,36), ip); |
---|
| 777 | WFIFOL(fd,30) = 0; |
---|
| 778 | } |
---|
| 779 | } else { |
---|
| 780 | memcpy(WFIFOP(fd,6), account_name, 24); |
---|
| 781 | ShowNotice("'ladmin': Attempt to adjust the validity limit of an unknown account (account: %s, ip: %s)\n", account_name, ip); |
---|
| 782 | WFIFOL(fd,30) = 0; |
---|
| 783 | } |
---|
| 784 | } |
---|
| 785 | WFIFOSET(fd,34); |
---|
| 786 | RFIFOSKIP(fd,38); |
---|
| 787 | break; |
---|
| 788 | |
---|
| 789 | case 0x7952: // Request about informations of an account (by account name) |
---|
| 790 | if (RFIFOREST(fd) < 26) |
---|
| 791 | return 0; |
---|
| 792 | WFIFOW(fd,0) = 0x7953; |
---|
| 793 | WFIFOL(fd,2) = 0xFFFFFFFF; // WTF??? |
---|
| 794 | account_name = (char*)RFIFOP(fd,2); |
---|
| 795 | account_name[23] = '\0'; |
---|
| 796 | remove_control_chars(account_name); |
---|
| 797 | i = search_account_index(account_name); |
---|
| 798 | if (i != -1) { |
---|
| 799 | WFIFOL(fd,2) = auth_dat[i].account_id; |
---|
| 800 | WFIFOB(fd,6) = (unsigned char)isGM(auth_dat[i].account_id); |
---|
| 801 | memcpy(WFIFOP(fd,7), auth_dat[i].userid, 24); |
---|
| 802 | WFIFOB(fd,31) = auth_dat[i].sex; |
---|
| 803 | WFIFOL(fd,32) = auth_dat[i].logincount; |
---|
| 804 | WFIFOL(fd,36) = auth_dat[i].state; |
---|
| 805 | memcpy(WFIFOP(fd,40), auth_dat[i].error_message, 20); |
---|
| 806 | memcpy(WFIFOP(fd,60), auth_dat[i].lastlogin, 24); |
---|
| 807 | memcpy(WFIFOP(fd,84), auth_dat[i].last_ip, 16); |
---|
| 808 | memcpy(WFIFOP(fd,100), auth_dat[i].email, 40); |
---|
| 809 | WFIFOL(fd,140) = (unsigned long)auth_dat[i].expiration_time; |
---|
| 810 | WFIFOL(fd,144) = (unsigned long)auth_dat[i].unban_time; |
---|
| 811 | WFIFOW(fd,148) = (uint16)strlen(auth_dat[i].memo); |
---|
| 812 | if (auth_dat[i].memo[0]) { |
---|
| 813 | memcpy(WFIFOP(fd,150), auth_dat[i].memo, strlen(auth_dat[i].memo)); |
---|
| 814 | } |
---|
| 815 | ShowNotice("'ladmin': Sending information of an account (request by the name; account: %s, id: %d, ip: %s)\n", auth_dat[i].userid, auth_dat[i].account_id, ip); |
---|
| 816 | WFIFOSET(fd,150+strlen(auth_dat[i].memo)); |
---|
| 817 | } else { |
---|
| 818 | memcpy(WFIFOP(fd,7), account_name, 24); |
---|
| 819 | WFIFOW(fd,148) = 0; |
---|
| 820 | ShowNotice("'ladmin': Attempt to obtain information (by the name) of an unknown account (account: %s, ip: %s)\n", account_name, ip); |
---|
| 821 | WFIFOSET(fd,150); |
---|
| 822 | } |
---|
| 823 | RFIFOSKIP(fd,26); |
---|
| 824 | break; |
---|
| 825 | |
---|
| 826 | case 0x7954: // Request about information of an account (by account id) |
---|
| 827 | if (RFIFOREST(fd) < 6) |
---|
| 828 | return 0; |
---|
| 829 | WFIFOW(fd,0) = 0x7953; |
---|
| 830 | WFIFOL(fd,2) = RFIFOL(fd,2); |
---|
| 831 | memset(WFIFOP(fd,7), '\0', 24); |
---|
| 832 | for(i = 0; i < auth_num; i++) { |
---|
| 833 | if (auth_dat[i].account_id == (int)RFIFOL(fd,2)) { |
---|
| 834 | ShowNotice("'ladmin': Sending information of an account (request by the id; account: %s, id: %d, ip: %s)\n", auth_dat[i].userid, RFIFOL(fd,2), ip); |
---|
| 835 | WFIFOB(fd,6) = (unsigned char)isGM(auth_dat[i].account_id); |
---|
| 836 | memcpy(WFIFOP(fd,7), auth_dat[i].userid, 24); |
---|
| 837 | WFIFOB(fd,31) = auth_dat[i].sex; |
---|
| 838 | WFIFOL(fd,32) = auth_dat[i].logincount; |
---|
| 839 | WFIFOL(fd,36) = auth_dat[i].state; |
---|
| 840 | memcpy(WFIFOP(fd,40), auth_dat[i].error_message, 20); |
---|
| 841 | memcpy(WFIFOP(fd,60), auth_dat[i].lastlogin, 24); |
---|
| 842 | memcpy(WFIFOP(fd,84), auth_dat[i].last_ip, 16); |
---|
| 843 | memcpy(WFIFOP(fd,100), auth_dat[i].email, 40); |
---|
| 844 | WFIFOL(fd,140) = (unsigned long)auth_dat[i].expiration_time; |
---|
| 845 | WFIFOL(fd,144) = (unsigned long)auth_dat[i].unban_time; |
---|
| 846 | WFIFOW(fd,148) = (uint16)strlen(auth_dat[i].memo); |
---|
| 847 | if (auth_dat[i].memo[0]) { |
---|
| 848 | memcpy(WFIFOP(fd,150), auth_dat[i].memo, strlen(auth_dat[i].memo)); |
---|
| 849 | } |
---|
| 850 | WFIFOSET(fd,150+strlen(auth_dat[i].memo)); |
---|
| 851 | break; |
---|
| 852 | } |
---|
| 853 | } |
---|
| 854 | if (i == auth_num) { |
---|
| 855 | ShowNotice("'ladmin': Attempt to obtain information (by the id) of an unknown account (id: %d, ip: %s)\n", RFIFOL(fd,2), ip); |
---|
| 856 | strncpy((char*)WFIFOP(fd,7), "", 24); |
---|
| 857 | WFIFOW(fd,148) = 0; |
---|
| 858 | WFIFOSET(fd,150); |
---|
| 859 | } |
---|
| 860 | RFIFOSKIP(fd,6); |
---|
| 861 | break; |
---|
| 862 | |
---|
| 863 | case 0x7955: // Request to reload GM file (no answer) |
---|
| 864 | ShowStatus("'ladmin': Request to re-load GM configuration file (ip: %s).\n", ip); |
---|
| 865 | read_gm_account(); |
---|
| 866 | // send GM accounts to all char-servers |
---|
| 867 | send_GM_accounts(-1); |
---|
| 868 | RFIFOSKIP(fd,2); |
---|
| 869 | break; |
---|
| 870 | |
---|
| 871 | default: |
---|
| 872 | ShowStatus("'ladmin': End of connection, unknown packet (ip: %s)\n", ip); |
---|
| 873 | set_eof(fd); |
---|
| 874 | return 0; |
---|
| 875 | } |
---|
| 876 | } |
---|
| 877 | RFIFOSKIP(fd,RFIFOREST(fd)); |
---|
| 878 | return 0; |
---|
| 879 | } |
---|