| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
#include "global.h" |
| 43 |
|
| 44 |
#include <assert.h> |
| 45 |
#include <stdlib.h> |
| 46 |
#include <string.h> |
| 47 |
#include <sys/time.h> |
| 48 |
#include <unistd.h> |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
#ifndef WIN32 |
| 54 |
#include <sys/types.h> |
| 55 |
#include <netinet/in.h> |
| 56 |
#include <netinet/tcp.h> |
| 57 |
#include <netdb.h> |
| 58 |
#endif |
| 59 |
|
| 60 |
#include "commands.h" |
| 61 |
#include "living.h" |
| 62 |
#include "newserver.h" |
| 63 |
#include "shared/newclient.h" |
| 64 |
#include "sounds.h" |
| 65 |
#include "sproto.h" |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
static const short atnr_cs_stat[NROFATTACKS] = { |
| 74 |
CS_STAT_RES_PHYS, CS_STAT_RES_MAG, |
| 75 |
CS_STAT_RES_FIRE, CS_STAT_RES_ELEC, |
| 76 |
CS_STAT_RES_COLD, CS_STAT_RES_CONF, |
| 77 |
CS_STAT_RES_ACID, |
| 78 |
CS_STAT_RES_DRAIN, -1 , |
| 79 |
CS_STAT_RES_GHOSTHIT, CS_STAT_RES_POISON, |
| 80 |
CS_STAT_RES_SLOW, CS_STAT_RES_PARA, |
| 81 |
CS_STAT_TURN_UNDEAD, |
| 82 |
CS_STAT_RES_FEAR, -1 , |
| 83 |
CS_STAT_RES_DEPLETE, CS_STAT_RES_DEATH, |
| 84 |
-1 , -1 , |
| 85 |
-1 , CS_STAT_RES_HOLYWORD, |
| 86 |
CS_STAT_RES_BLIND, |
| 87 |
-1, |
| 88 |
-1, |
| 89 |
-1 |
| 90 |
}; |
| 91 |
|
| 92 |
|
| 93 |
void set_up_cmd(char *buf, int len, socket_struct *ns) { |
| 94 |
int s = 0; |
| 95 |
char *cmd, *param; |
| 96 |
SockList sl; |
| 97 |
|
| 98 |
if (len <= 0 || !buf) { |
| 99 |
LOG(llevDebug, "IP '%s' sent bogus set_up_cmd information\n", ns->host); |
| 100 |
return; |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
LOG(llevDebug, "setup: %s\n", buf); |
| 112 |
SockList_Init(&sl); |
| 113 |
SockList_AddString(&sl, "setup"); |
| 114 |
while (s < len) { |
| 115 |
cmd = &buf[s]; |
| 116 |
|
| 117 |
|
| 118 |
for (; buf[s] && buf[s] != ' '; s++) |
| 119 |
; |
| 120 |
if (s >= len) |
| 121 |
break; |
| 122 |
buf[s++] = 0; |
| 123 |
|
| 124 |
while (buf[s] == ' ') |
| 125 |
s++; |
| 126 |
if (s >= len) |
| 127 |
break; |
| 128 |
param = &buf[s]; |
| 129 |
|
| 130 |
for (; buf[s] && buf[s] != ' '; s++) |
| 131 |
; |
| 132 |
buf[s++] = 0; |
| 133 |
|
| 134 |
while (s < len && buf[s] == ' ') |
| 135 |
s++; |
| 136 |
|
| 137 |
SockList_AddPrintf(&sl, " %s ", cmd); |
| 138 |
|
| 139 |
if (!strcmp(cmd, "sound2")) { |
| 140 |
ns->sound = atoi(param)&(SND_EFFECTS|SND_MUSIC|SND_MUTE); |
| 141 |
SockList_AddString(&sl, param); |
| 142 |
} else if (!strcmp(cmd, "spellmon")) { |
| 143 |
int monitor_spells; |
| 144 |
|
| 145 |
monitor_spells = atoi(param); |
| 146 |
if (monitor_spells < 0 || monitor_spells > 2) { |
| 147 |
SockList_AddString(&sl, "FALSE"); |
| 148 |
} else { |
| 149 |
ns->monitor_spells = monitor_spells; |
| 150 |
SockList_AddPrintf(&sl, "%d", monitor_spells); |
| 151 |
} |
| 152 |
} else if (!strcmp(cmd, "darkness")) { |
| 153 |
int darkness; |
| 154 |
|
| 155 |
darkness = atoi(param); |
| 156 |
if (darkness != 0 && darkness != 1) { |
| 157 |
SockList_AddString(&sl, "FALSE"); |
| 158 |
} else { |
| 159 |
ns->darkness = darkness; |
| 160 |
SockList_AddPrintf(&sl, "%d", darkness); |
| 161 |
} |
| 162 |
} else if (!strcmp(cmd, "map2cmd")) { |
| 163 |
int map2cmd; |
| 164 |
|
| 165 |
map2cmd = atoi(param); |
| 166 |
if (map2cmd != 1) { |
| 167 |
SockList_AddString(&sl, "FALSE"); |
| 168 |
} else { |
| 169 |
SockList_AddString(&sl, "1"); |
| 170 |
} |
| 171 |
} else if (!strcmp(cmd, "facecache")) { |
| 172 |
int facecache; |
| 173 |
|
| 174 |
facecache = atoi(param); |
| 175 |
if (facecache != 0 && facecache != 1) { |
| 176 |
SockList_AddString(&sl, "FALSE"); |
| 177 |
} else { |
| 178 |
ns->facecache = facecache; |
| 179 |
SockList_AddPrintf(&sl, "%d", facecache); |
| 180 |
} |
| 181 |
} else if (!strcmp(cmd, "faceset")) { |
| 182 |
int q = atoi(param); |
| 183 |
|
| 184 |
if (is_valid_faceset(q)) |
| 185 |
ns->faceset = q; |
| 186 |
SockList_AddPrintf(&sl, "%d", ns->faceset); |
| 187 |
} else if (!strcmp(cmd, "mapsize")) { |
| 188 |
int x, y, n; |
| 189 |
|
| 190 |
if (sscanf(param, "%dx%d%n", &x, &y, &n) != 2 || n != (int)strlen(param)) { |
| 191 |
x = 0; |
| 192 |
y = 0; |
| 193 |
} |
| 194 |
if (x < 9 || y < 9 || x > MAP_CLIENT_X || y > MAP_CLIENT_Y) { |
| 195 |
SockList_AddPrintf(&sl, "%dx%d", MAP_CLIENT_X, MAP_CLIENT_Y); |
| 196 |
} else { |
| 197 |
player *pl; |
| 198 |
ns->mapx = x; |
| 199 |
ns->mapy = y; |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
SockList_AddPrintf(&sl, "%dx%d", x, y); |
| 204 |
|
| 205 |
pl = find_player_socket(ns); |
| 206 |
if (pl) |
| 207 |
update_los(pl->ob); |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
map_newmap_cmd(ns); |
| 213 |
} |
| 214 |
} else if (!strcmp(cmd, "tick")) { |
| 215 |
int tick; |
| 216 |
|
| 217 |
tick = atoi(param); |
| 218 |
if (tick != 0 && tick != 1) { |
| 219 |
SockList_AddString(&sl, "FALSE"); |
| 220 |
} else { |
| 221 |
ns->tick = tick; |
| 222 |
SockList_AddPrintf(&sl, "%d", tick); |
| 223 |
} |
| 224 |
} else if (!strcmp(cmd, "bot")) { |
| 225 |
int is_bot; |
| 226 |
|
| 227 |
is_bot = atoi(param); |
| 228 |
if (is_bot != 0 && is_bot != 1) { |
| 229 |
SockList_AddString(&sl, "FALSE"); |
| 230 |
} else { |
| 231 |
ns->is_bot = is_bot; |
| 232 |
SockList_AddPrintf(&sl, "%d", is_bot); |
| 233 |
} |
| 234 |
} else if (!strcmp(cmd, "want_pickup")) { |
| 235 |
int want_pickup; |
| 236 |
|
| 237 |
want_pickup = atoi(param); |
| 238 |
if (want_pickup != 0 && want_pickup != 1) { |
| 239 |
SockList_AddString(&sl, "FALSE"); |
| 240 |
} else { |
| 241 |
ns->want_pickup = want_pickup; |
| 242 |
SockList_AddPrintf(&sl, "%d", want_pickup); |
| 243 |
} |
| 244 |
} else if (!strcmp(cmd, "num_look_objects")) { |
| 245 |
int tmp; |
| 246 |
player *pl; |
| 247 |
|
| 248 |
tmp = atoi(param); |
| 249 |
if (tmp < MIN_NUM_LOOK_OBJECTS) { |
| 250 |
tmp = MIN_NUM_LOOK_OBJECTS; |
| 251 |
} else if (tmp > MAX_NUM_LOOK_OBJECTS) { |
| 252 |
tmp = MAX_NUM_LOOK_OBJECTS; |
| 253 |
} |
| 254 |
ns->num_look_objects = (uint8_t)tmp; |
| 255 |
SockList_AddPrintf(&sl, "%d", tmp); |
| 256 |
|
| 257 |
pl = find_player_socket(ns); |
| 258 |
if (pl && pl->ob) { |
| 259 |
ns->update_look = 1; |
| 260 |
esrv_draw_look(pl->ob); |
| 261 |
} |
| 262 |
} else if (!strcmp(cmd, "extended_stats")) { |
| 263 |
int extended_stats; |
| 264 |
|
| 265 |
extended_stats = atoi(param); |
| 266 |
if (extended_stats != 0 && extended_stats != 1) { |
| 267 |
SockList_AddString(&sl, "FALSE"); |
| 268 |
} else { |
| 269 |
ns->extended_stats = extended_stats; |
| 270 |
SockList_AddPrintf(&sl, "%d", extended_stats); |
| 271 |
} |
| 272 |
} else if (!strcmp(cmd, "beat")) { |
| 273 |
int use_beat = atoi(param); |
| 274 |
|
| 275 |
if (use_beat != 0 && use_beat != 1) { |
| 276 |
SockList_AddString(&sl, "FALSE"); |
| 277 |
} else { |
| 278 |
ns->heartbeat = use_beat ? true : false; |
| 279 |
|
| 280 |
|
| 281 |
SockList_AddPrintf(&sl, "%d", BEAT_INTERVAL); |
| 282 |
} |
| 283 |
} else if (!strcmp(cmd, "loginmethod")) { |
| 284 |
int loginmethod; |
| 285 |
|
| 286 |
loginmethod = atoi(param); |
| 287 |
|
| 288 |
|
| 289 |
if (loginmethod > 2) loginmethod=2; |
| 290 |
|
| 291 |
ns->login_method = loginmethod; |
| 292 |
SockList_AddPrintf(&sl, "%d", loginmethod); |
| 293 |
|
| 294 |
} else if (!strcmp(cmd, "notifications")) { |
| 295 |
int notifications; |
| 296 |
|
| 297 |
notifications = atoi(param); |
| 298 |
|
| 299 |
ns->notifications = notifications; |
| 300 |
SockList_AddPrintf(&sl, "%d", notifications); |
| 301 |
|
| 302 |
} else if (!strcmp(cmd, "newmapcmd")) { |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
SockList_AddString(&sl, "1"); |
| 310 |
} else if (!strcmp(cmd, "extendedTextInfos")) { |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
SockList_AddString(&sl, "1"); |
| 316 |
} else if (!strcmp(cmd, "itemcmd")) { |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
SockList_AddString(&sl, "2"); |
| 322 |
} else if (!strcmp(cmd, "exp64")) { |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
SockList_AddString(&sl, "1"); |
| 328 |
} else { |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
SockList_AddString(&sl, "FALSE"); |
| 333 |
} |
| 334 |
} |
| 335 |
Send_With_Handling(ns, &sl); |
| 336 |
SockList_Term(&sl); |
| 337 |
} |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
void add_me_cmd(char *buf, int len, socket_struct *ns) { |
| 348 |
Settings oldsettings; |
| 349 |
SockList sl; |
| 350 |
|
| 351 |
oldsettings = settings; |
| 352 |
if (ns->status != Ns_Add) { |
| 353 |
SockList_Init(&sl); |
| 354 |
SockList_AddString(&sl, "addme_failed"); |
| 355 |
Send_With_Handling(ns, &sl); |
| 356 |
SockList_Term(&sl); |
| 357 |
} else if (find_player_socket(ns) == NULL) { |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
add_player(ns, 0); |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
SockList_Init(&sl); |
| 368 |
SockList_AddString(&sl, "addme_success"); |
| 369 |
Send_With_Handling(ns, &sl); |
| 370 |
SockList_Term(&sl); |
| 371 |
if (ns->sc_version < 1027 || ns->cs_version < 1023) { |
| 372 |
print_ext_msg(ns, NDI_RED, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_VERSION, |
| 373 |
"Warning: Your client is too old to receive map data. Please update to a new client at: " |
| 374 |
"https://sourceforge.net/projects/crossfire/"); |
| 375 |
} |
| 376 |
} |
| 377 |
settings = oldsettings; |
| 378 |
} |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
static void send_smooth(socket_struct *ns, const Face *face) { |
| 390 |
const Face *smoothface; |
| 391 |
SockList sl; |
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
if (!find_smooth(face, &smoothface) |
| 399 |
&& !find_smooth(smooth_face, &smoothface)) { |
| 400 |
LOG(llevDebug, |
| 401 |
"Could not smooth face %d\n" |
| 402 |
"Check that this face has a smoothing pixmap, or remove its smoothlevel.\n", |
| 403 |
face); |
| 404 |
ns->faces_sent[face->number] |= NS_FACESENT_SMOOTH; |
| 405 |
return; |
| 406 |
} |
| 407 |
|
| 408 |
if (!(ns->faces_sent[smoothface->number]&NS_FACESENT_FACE)) |
| 409 |
esrv_send_face(ns, smoothface, 0); |
| 410 |
|
| 411 |
ns->faces_sent[face->number] |= NS_FACESENT_SMOOTH; |
| 412 |
|
| 413 |
SockList_Init(&sl); |
| 414 |
SockList_AddString(&sl, "smooth "); |
| 415 |
SockList_AddShort(&sl, face->number); |
| 416 |
SockList_AddShort(&sl, smoothface->number); |
| 417 |
Send_With_Handling(ns, &sl); |
| 418 |
SockList_Term(&sl); |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
void ask_smooth_cmd(char *buf, int len, socket_struct *ns) { |
| 426 |
uint16_t facenid; |
| 427 |
|
| 428 |
if (len <= 0 || !buf) { |
| 429 |
LOG(llevDebug, "IP '%s' sent bogus ask_smooth_cmd information\n", ns->host); |
| 430 |
return; |
| 431 |
} |
| 432 |
|
| 433 |
facenid = atoi(buf); |
| 434 |
send_smooth(ns, get_face_by_id(facenid)); |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
void new_player_cmd(uint8_t *buf, int len, player *pl) { |
| 450 |
int time, repeat; |
| 451 |
short packet; |
| 452 |
char command[MAX_BUF]; |
| 453 |
SockList sl; |
| 454 |
|
| 455 |
if (len < 7) { |
| 456 |
LOG(llevDebug, "Corrupt ncom command - not long enough - discarding\n"); |
| 457 |
return; |
| 458 |
} |
| 459 |
|
| 460 |
packet = GetShort_String(buf); |
| 461 |
repeat = GetInt_String(buf+2); |
| 462 |
|
| 463 |
if (repeat != -1) { |
| 464 |
pl->count = repeat; |
| 465 |
} |
| 466 |
if (len-4 >= MAX_BUF) |
| 467 |
len = MAX_BUF-5; |
| 468 |
|
| 469 |
strncpy(command, (char *)buf+6, len-4); |
| 470 |
command[len-4] = '\0'; |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
if (pl->state != ST_PLAYING) { |
| 478 |
draw_ext_info_format(NDI_UNIQUE, 0, pl->ob, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR, |
| 479 |
"You can not issue commands - state is not ST_PLAYING (%s)", |
| 480 |
buf); |
| 481 |
return; |
| 482 |
} |
| 483 |
|
| 484 |
|
| 485 |
if (pl->ob->speed_left < 0) { |
| 486 |
LOG(llevError, "Player has negative time - shouldn't do command.\n"); |
| 487 |
} |
| 488 |
|
| 489 |
execute_newserver_command(pl->ob, command); |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
pl->count = 0; |
| 496 |
|
| 497 |
|
| 498 |
SockList_Init(&sl); |
| 499 |
SockList_AddString(&sl, "comc "); |
| 500 |
SockList_AddShort(&sl, packet); |
| 501 |
if (FABS(pl->ob->speed) < 0.001) |
| 502 |
time = MAX_TIME*100; |
| 503 |
else |
| 504 |
time = (int)(MAX_TIME/FABS(pl->ob->speed)); |
| 505 |
SockList_AddInt(&sl, time); |
| 506 |
Send_With_Handling(&pl->socket, &sl); |
| 507 |
SockList_Term(&sl); |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
void reply_cmd(char *buf, int len, player *pl) { |
| 512 |
|
| 513 |
if (len <= 0 || !buf) { |
| 514 |
LOG(llevDebug, "Player '%s' sent bogus reply_cmd information\n", pl->ob->name); |
| 515 |
return; |
| 516 |
} |
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
snprintf(pl->write_buf, sizeof(pl->write_buf), ":%s", buf); |
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
switch (pl->state) { |
| 531 |
case ST_PLAYING: |
| 532 |
LOG(llevError, "Got reply message with ST_PLAYING input state\n"); |
| 533 |
break; |
| 534 |
|
| 535 |
case ST_PLAY_AGAIN: |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
receive_play_again(pl->ob, buf[0]); |
| 540 |
break; |
| 541 |
|
| 542 |
case ST_ROLL_STAT: |
| 543 |
key_roll_stat(pl->ob, buf[0]); |
| 544 |
break; |
| 545 |
|
| 546 |
case ST_CHANGE_CLASS: |
| 547 |
|
| 548 |
key_change_class(pl->ob, buf[0]); |
| 549 |
break; |
| 550 |
|
| 551 |
case ST_CONFIRM_QUIT: |
| 552 |
key_confirm_quit(pl->ob, buf[0]); |
| 553 |
break; |
| 554 |
|
| 555 |
case ST_GET_NAME: |
| 556 |
receive_player_name(pl->ob); |
| 557 |
break; |
| 558 |
|
| 559 |
case ST_GET_PASSWORD: |
| 560 |
case ST_CONFIRM_PASSWORD: |
| 561 |
case ST_CHANGE_PASSWORD_OLD: |
| 562 |
case ST_CHANGE_PASSWORD_NEW: |
| 563 |
case ST_CHANGE_PASSWORD_CONFIRM: |
| 564 |
receive_player_password(pl->ob); |
| 565 |
break; |
| 566 |
|
| 567 |
case ST_GET_PARTY_PASSWORD: |
| 568 |
receive_party_password(pl->ob); |
| 569 |
break; |
| 570 |
|
| 571 |
default: |
| 572 |
LOG(llevError, "Unknown input state: %d\n", pl->state); |
| 573 |
} |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
void version_cmd(char *buf, int len, socket_struct *ns) { |
| 584 |
char *rest; |
| 585 |
char *cs_str = strtok_r(buf, " ", &rest); |
| 586 |
char *sc_str = strtok_r(NULL, " ", &rest); |
| 587 |
|
| 588 |
if (cs_str == NULL || sc_str == NULL) { |
| 589 |
LOG(llevError, "%s: sent invalid version string\n", ns->host); |
| 590 |
return; |
| 591 |
} else { |
| 592 |
ns->cs_version = atoi(cs_str); |
| 593 |
ns->sc_version = atoi(sc_str); |
| 594 |
} |
| 595 |
|
| 596 |
#ifdef ESRV_DEBUG |
| 597 |
if (VERSION_CS != ns->cs_version) { |
| 598 |
LOG(llevDebug, "CS: csversion mismatch (%d,%d)\n", VERSION_CS, ns->cs_version); |
| 599 |
} |
| 600 |
|
| 601 |
if (VERSION_SC != ns->sc_version) { |
| 602 |
LOG(llevDebug, "CS: scversion mismatch (%d,%d)\n", VERSION_SC, ns->sc_version); |
| 603 |
} |
| 604 |
#endif |
| 605 |
|
| 606 |
if (rest != NULL) { |
| 607 |
LOG(llevInfo, "Connection from %s (%s), CS %d, SC %d\n", |
| 608 |
ns->host, rest, ns->cs_version, ns->sc_version); |
| 609 |
} |
| 610 |
} |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
void map_newmap_cmd(socket_struct *ns) { |
| 619 |
SockList sl; |
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
ns->map_scroll_x = 0; |
| 625 |
ns->map_scroll_y = 0; |
| 626 |
|
| 627 |
|
| 628 |
memset(&ns->lastmap, 0, sizeof(ns->lastmap)); |
| 629 |
SockList_Init(&sl); |
| 630 |
SockList_AddString(&sl, "newmap"); |
| 631 |
Send_With_Handling(ns, &sl); |
| 632 |
SockList_Term(&sl); |
| 633 |
} |
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
void move_cmd(char *buf, int len, player *pl) { |
| 640 |
int vals[3], i; |
| 641 |
|
| 642 |
if (len <= 0 || !buf) { |
| 643 |
LOG(llevDebug, "Player '%s' sent bogus move_cmd information\n", pl->ob->name); |
| 644 |
return; |
| 645 |
} |
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
for (i = 0; i < 2; i++) { |
| 653 |
vals[i] = atoi(buf); |
| 654 |
if (!(buf = strchr(buf, ' '))) { |
| 655 |
LOG(llevError, "Incomplete move command: %s\n", buf); |
| 656 |
return; |
| 657 |
} |
| 658 |
buf++; |
| 659 |
} |
| 660 |
vals[2] = atoi(buf); |
| 661 |
|
| 662 |
|
| 663 |
esrv_move_object(pl->ob, vals[0], vals[1], vals[2]); |
| 664 |
} |
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
void send_query(socket_struct *ns, uint8_t flags, const char *text) { |
| 678 |
SockList sl; |
| 679 |
|
| 680 |
SockList_Init(&sl); |
| 681 |
SockList_AddPrintf(&sl, "query %d %s", flags, text ? text : ""); |
| 682 |
Send_With_Handling(ns, &sl); |
| 683 |
SockList_Term(&sl); |
| 684 |
} |
| 685 |
|
| 686 |
#define AddIfInt64(Old, New, Type) \ |
| 687 |
if (Old != New) { \ |
| 688 |
Old = New; \ |
| 689 |
SockList_AddChar(&sl, Type); \ |
| 690 |
SockList_AddInt64(&sl, New); \ |
| 691 |
} |
| 692 |
|
| 693 |
#define AddIfInt(Old, New, Type) \ |
| 694 |
if (Old != New) { \ |
| 695 |
Old = New; \ |
| 696 |
SockList_AddChar(&sl, Type); \ |
| 697 |
SockList_AddInt(&sl, New); \ |
| 698 |
} |
| 699 |
|
| 700 |
#define AddIfShort(Old, New, Type) \ |
| 701 |
if (Old != New) { \ |
| 702 |
Old = New; \ |
| 703 |
SockList_AddChar(&sl, Type); \ |
| 704 |
SockList_AddShort(&sl, New); \ |
| 705 |
} |
| 706 |
|
| 707 |
#define AddIfFloat(Old, New, Type) \ |
| 708 |
if (Old != New) { \ |
| 709 |
Old = New; \ |
| 710 |
SockList_AddChar(&sl, Type); \ |
| 711 |
SockList_AddInt(&sl, (long)(New*FLOAT_MULTI));\ |
| 712 |
} |
| 713 |
|
| 714 |
#define AddIfString(Old, New, Type) \ |
| 715 |
if (Old == NULL || strcmp(Old, New)) { \ |
| 716 |
free(Old); \ |
| 717 |
Old = strdup_local(New); \ |
| 718 |
SockList_AddChar(&sl, Type); \ |
| 719 |
SockList_AddLen8Data(&sl, New, strlen(New));\ |
| 720 |
} |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
void esrv_update_stats(player *pl) { |
| 729 |
SockList sl; |
| 730 |
char buf[MAX_BUF]; |
| 731 |
uint16_t flags; |
| 732 |
uint8_t s; |
| 733 |
|
| 734 |
SockList_Init(&sl); |
| 735 |
SockList_AddString(&sl, "stats "); |
| 736 |
|
| 737 |
if (pl->ob != NULL) { |
| 738 |
AddIfShort(pl->last_stats.hp, pl->ob->stats.hp, CS_STAT_HP); |
| 739 |
AddIfShort(pl->last_stats.maxhp, pl->ob->stats.maxhp, CS_STAT_MAXHP); |
| 740 |
AddIfShort(pl->last_stats.sp, pl->ob->stats.sp, CS_STAT_SP); |
| 741 |
AddIfShort(pl->last_stats.maxsp, pl->ob->stats.maxsp, CS_STAT_MAXSP); |
| 742 |
AddIfShort(pl->last_stats.grace, pl->ob->stats.grace, CS_STAT_GRACE); |
| 743 |
AddIfShort(pl->last_stats.maxgrace, pl->ob->stats.maxgrace, CS_STAT_MAXGRACE); |
| 744 |
AddIfShort(pl->last_stats.Str, pl->ob->stats.Str, CS_STAT_STR); |
| 745 |
AddIfShort(pl->last_stats.Int, pl->ob->stats.Int, CS_STAT_INT); |
| 746 |
AddIfShort(pl->last_stats.Pow, pl->ob->stats.Pow, CS_STAT_POW); |
| 747 |
AddIfShort(pl->last_stats.Wis, pl->ob->stats.Wis, CS_STAT_WIS); |
| 748 |
AddIfShort(pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); |
| 749 |
AddIfShort(pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON); |
| 750 |
AddIfShort(pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA); |
| 751 |
} |
| 752 |
if (pl->socket.extended_stats) { |
| 753 |
int16_t golem_hp, golem_maxhp; |
| 754 |
AddIfShort(pl->last_orig_stats.Str, pl->orig_stats.Str, CS_STAT_BASE_STR); |
| 755 |
AddIfShort(pl->last_orig_stats.Int, pl->orig_stats.Int, CS_STAT_BASE_INT); |
| 756 |
AddIfShort(pl->last_orig_stats.Pow, pl->orig_stats.Pow, CS_STAT_BASE_POW); |
| 757 |
AddIfShort(pl->last_orig_stats.Wis, pl->orig_stats.Wis, CS_STAT_BASE_WIS); |
| 758 |
AddIfShort(pl->last_orig_stats.Dex, pl->orig_stats.Dex, CS_STAT_BASE_DEX); |
| 759 |
AddIfShort(pl->last_orig_stats.Con, pl->orig_stats.Con, CS_STAT_BASE_CON); |
| 760 |
AddIfShort(pl->last_orig_stats.Cha, pl->orig_stats.Cha, CS_STAT_BASE_CHA); |
| 761 |
if (pl->ob != NULL) { |
| 762 |
AddIfShort(pl->last_race_stats.Str, 20 + pl->ob->arch->clone.stats.Str, CS_STAT_RACE_STR); |
| 763 |
AddIfShort(pl->last_race_stats.Int, 20 + pl->ob->arch->clone.stats.Int, CS_STAT_RACE_INT); |
| 764 |
AddIfShort(pl->last_race_stats.Pow, 20 + pl->ob->arch->clone.stats.Pow, CS_STAT_RACE_POW); |
| 765 |
AddIfShort(pl->last_race_stats.Wis, 20 + pl->ob->arch->clone.stats.Wis, CS_STAT_RACE_WIS); |
| 766 |
AddIfShort(pl->last_race_stats.Dex, 20 + pl->ob->arch->clone.stats.Dex, CS_STAT_RACE_DEX); |
| 767 |
AddIfShort(pl->last_race_stats.Con, 20 + pl->ob->arch->clone.stats.Con, CS_STAT_RACE_CON); |
| 768 |
AddIfShort(pl->last_race_stats.Cha, 20 + pl->ob->arch->clone.stats.Cha, CS_STAT_RACE_CHA); |
| 769 |
AddIfShort(pl->last_applied_stats.Str, pl->applied_stats.Str, CS_STAT_APPLIED_STR); |
| 770 |
AddIfShort(pl->last_applied_stats.Int, pl->applied_stats.Int, CS_STAT_APPLIED_INT); |
| 771 |
AddIfShort(pl->last_applied_stats.Pow, pl->applied_stats.Pow, CS_STAT_APPLIED_POW); |
| 772 |
AddIfShort(pl->last_applied_stats.Wis, pl->applied_stats.Wis, CS_STAT_APPLIED_WIS); |
| 773 |
AddIfShort(pl->last_applied_stats.Dex, pl->applied_stats.Dex, CS_STAT_APPLIED_DEX); |
| 774 |
AddIfShort(pl->last_applied_stats.Con, pl->applied_stats.Con, CS_STAT_APPLIED_CON); |
| 775 |
AddIfShort(pl->last_applied_stats.Cha, pl->applied_stats.Cha, CS_STAT_APPLIED_CHA); |
| 776 |
} |
| 777 |
if (pl->ranges[range_golem]) { |
| 778 |
object *golem = pl->ranges[range_golem]; |
| 779 |
if (QUERY_FLAG(golem, FLAG_REMOVED) || golem->count != pl->golem_count || QUERY_FLAG(golem, FLAG_FREED)) { |
| 780 |
golem_hp = 0; |
| 781 |
golem_maxhp = 0; |
| 782 |
} else { |
| 783 |
golem_hp = golem->stats.hp; |
| 784 |
golem_maxhp = golem->stats.maxhp; |
| 785 |
} |
| 786 |
} else { |
| 787 |
golem_hp = 0; |
| 788 |
golem_maxhp = 0; |
| 789 |
} |
| 790 |
|
| 791 |
AddIfShort(pl->last_golem_maxhp, golem_maxhp, CS_STAT_GOLEM_MAXHP); |
| 792 |
AddIfShort(pl->last_golem_hp, golem_hp, CS_STAT_GOLEM_HP); |
| 793 |
} |
| 794 |
|
| 795 |
for (s = 0; s < MAX_SKILLS; s++) { |
| 796 |
if (pl->last_skill_ob[s]) { |
| 797 |
|
| 798 |
|
| 799 |
if (QUERY_FLAG(pl->last_skill_ob[s], FLAG_REMOVED)) { |
| 800 |
LOG(llevDebug, "pruning removed object from last_skill_ob\n"); |
| 801 |
pl->last_skill_ob[s] = NULL; |
| 802 |
continue; |
| 803 |
} |
| 804 |
|
| 805 |
if (pl->last_skill_exp[s] != pl->last_skill_ob[s]->stats.exp) { |
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
SockList_AddChar(&sl, (char)(get_skill_client_code(pl->last_skill_ob[s]->name) + CS_STAT_SKILLINFO)); |
| 810 |
SockList_AddChar(&sl, (char)pl->last_skill_ob[s]->level); |
| 811 |
SockList_AddInt64(&sl, pl->last_skill_ob[s]->stats.exp); |
| 812 |
pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
| 813 |
} |
| 814 |
} |
| 815 |
} |
| 816 |
AddIfInt64(pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64); |
| 817 |
AddIfShort(pl->last_level, (char)pl->ob->level, CS_STAT_LEVEL); |
| 818 |
AddIfShort(pl->last_stats.wc, pl->ob->stats.wc, CS_STAT_WC); |
| 819 |
AddIfShort(pl->last_stats.ac, pl->ob->stats.ac, CS_STAT_AC); |
| 820 |
AddIfShort(pl->last_stats.dam, pl->ob->stats.dam, CS_STAT_DAM); |
| 821 |
AddIfFloat(pl->last_speed, pl->ob->speed, CS_STAT_SPEED); |
| 822 |
AddIfShort(pl->last_stats.food, pl->ob->stats.food, CS_STAT_FOOD); |
| 823 |
AddIfFloat(pl->last_weapon_sp, pl->ob->weapon_speed, CS_STAT_WEAP_SP); |
| 824 |
AddIfInt(pl->last_weight_limit, (int32_t)get_weight_limit(pl->ob->stats.Str), CS_STAT_WEIGHT_LIM); |
| 825 |
flags = 0; |
| 826 |
if (pl->fire_on) |
| 827 |
flags |= SF_FIREON; |
| 828 |
if (pl->run_on) |
| 829 |
flags |= SF_RUNON; |
| 830 |
|
| 831 |
AddIfShort(pl->last_flags, flags, CS_STAT_FLAGS); |
| 832 |
if (pl->socket.sc_version < 1025) { |
| 833 |
AddIfShort(pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR); |
| 834 |
} else { |
| 835 |
int i; |
| 836 |
|
| 837 |
for (i = 0; i < NROFATTACKS; i++) { |
| 838 |
|
| 839 |
if (atnr_cs_stat[i] == -1) |
| 840 |
continue; |
| 841 |
AddIfShort(pl->last_resist[i], pl->ob->resist[i], (char)atnr_cs_stat[i]); |
| 842 |
} |
| 843 |
} |
| 844 |
if (pl->socket.monitor_spells) { |
| 845 |
AddIfInt(pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
| 846 |
AddIfInt(pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL); |
| 847 |
AddIfInt(pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY); |
| 848 |
} |
| 849 |
|
| 850 |
rangetostring(pl->ob, buf, sizeof(buf)); |
| 851 |
AddIfString(pl->socket.stats.range, buf, CS_STAT_RANGE); |
| 852 |
set_title(pl->ob, buf, sizeof(buf)); |
| 853 |
AddIfString(pl->socket.stats.title, buf, CS_STAT_TITLE); |
| 854 |
|
| 855 |
|
| 856 |
if (sl.len > 8) { |
| 857 |
#ifdef ESRV_DEBUG |
| 858 |
LOG(llevDebug, "Sending stats command, %d bytes long.\n", sl.len); |
| 859 |
#endif |
| 860 |
Send_With_Handling(&pl->socket, &sl); |
| 861 |
} |
| 862 |
SockList_Term(&sl); |
| 863 |
} |
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
void esrv_new_player(player *pl, uint32_t weight) { |
| 869 |
SockList sl; |
| 870 |
|
| 871 |
pl->last_weight = weight; |
| 872 |
|
| 873 |
if (!(pl->socket.faces_sent[pl->ob->face->number]&NS_FACESENT_FACE)) |
| 874 |
esrv_send_face(&pl->socket, pl->ob->face, 0); |
| 875 |
|
| 876 |
SockList_Init(&sl); |
| 877 |
SockList_AddString(&sl, "player "); |
| 878 |
SockList_AddInt(&sl, pl->ob->count); |
| 879 |
SockList_AddInt(&sl, weight); |
| 880 |
SockList_AddInt(&sl, pl->ob->face->number); |
| 881 |
SockList_AddLen8Data(&sl, pl->ob->name, strlen(pl->ob->name)); |
| 882 |
|
| 883 |
Send_With_Handling(&pl->socket, &sl); |
| 884 |
SockList_Term(&sl); |
| 885 |
SET_FLAG(pl->ob, FLAG_CLIENT_SENT); |
| 886 |
} |
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
void esrv_send_animation(socket_struct *ns, const Animations *anim) { |
| 899 |
SockList sl; |
| 900 |
int i; |
| 901 |
|
| 902 |
if (anim == NULL) { |
| 903 |
LOG(llevError, "esrv_send_anim NULL??\n"); |
| 904 |
return; |
| 905 |
} |
| 906 |
|
| 907 |
SockList_Init(&sl); |
| 908 |
SockList_AddString(&sl, "anim "); |
| 909 |
SockList_AddShort(&sl, anim->num); |
| 910 |
SockList_AddShort(&sl, 0); |
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
for (i = 0; i < anim->num_animations; i++) { |
| 915 |
if (!(ns->faces_sent[anim->faces[i]->number]&NS_FACESENT_FACE)) |
| 916 |
esrv_send_face(ns, anim->faces[i], 0); |
| 917 |
|
| 918 |
SockList_AddShort(&sl, anim->faces[i]->number); |
| 919 |
} |
| 920 |
Send_With_Handling(ns, &sl); |
| 921 |
SockList_Term(&sl); |
| 922 |
ns->anims_sent[anim->num] = 1; |
| 923 |
} |
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
static void map_clearcell(struct map_cell_struct *cell, int face, int count) { |
| 933 |
cell->darkness = count; |
| 934 |
memset(cell->faces, face, sizeof(cell->faces)); |
| 935 |
} |
| 936 |
|
| 937 |
#define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) |
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
static const object *heads[MAX_HEAD_POS][MAX_HEAD_POS][MAP_LAYERS]; |
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
static int map2_add_ob(int ax, int ay, int layer, const object *ob, SockList *sl, socket_struct *ns, int *has_obj, int is_head) { |
| 974 |
uint8_t nlayer, smoothlevel = 0; |
| 975 |
const object *head; |
| 976 |
|
| 977 |
assert(ob != NULL); |
| 978 |
|
| 979 |
head = HEAD(ob); |
| 980 |
const Face *face = ob->face; |
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
if (!is_head && (head->arch->tail_x || head->arch->tail_y) |
| 986 |
&& (head->arch->tail_x != ob->arch->clone.x || head->arch->tail_y != ob->arch->clone.y)) { |
| 987 |
int bx, by, l; |
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
bx = ax+head->arch->tail_x-ob->arch->clone.x; |
| 999 |
by = ay+head->arch->tail_y-ob->arch->clone.y; |
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
if (bx < ax || by < ay) { |
| 1005 |
LOG(llevError, "map2_add_ob: bx (%d) or by (%d) is less than ax (%d) or ay (%d)\n", bx, by, ax, ay); |
| 1006 |
face = NULL; |
| 1007 |
} |
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
for (l = layer-1; l <= layer+1; l++) { |
| 1013 |
if (l < 0 || l >= MAP_LAYERS) |
| 1014 |
continue; |
| 1015 |
if (heads[by][bx][l] == head) |
| 1016 |
break; |
| 1017 |
} |
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
if (l == layer+2) { |
| 1022 |
if (!heads[by][bx][layer]) |
| 1023 |
heads[by][bx][layer] = head; |
| 1024 |
else if (layer+1 < MAP_LAYERS && !heads[by][bx][layer+1]) |
| 1025 |
heads[by][bx][layer+1] = head; |
| 1026 |
} |
| 1027 |
return 0; |
| 1028 |
|
| 1029 |
} else { |
| 1030 |
uint16_t face_num = face ? face->number : 0; |
| 1031 |
(*has_obj)++; |
| 1032 |
if (QUERY_FLAG(ob, FLAG_CLIENT_ANIM_SYNC) |
| 1033 |
|| QUERY_FLAG(ob, FLAG_CLIENT_ANIM_RANDOM)) { |
| 1034 |
face_num = (ob->animation ? ob->animation->num : 0)|(1<<15); |
| 1035 |
if (QUERY_FLAG(ob, FLAG_CLIENT_ANIM_SYNC)) |
| 1036 |
face_num |= ANIM_SYNC; |
| 1037 |
else if (QUERY_FLAG(ob, FLAG_CLIENT_ANIM_RANDOM)) |
| 1038 |
face_num |= ANIM_RANDOM; |
| 1039 |
} |
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
if (ns->lastmap.cells[ax][ay].faces[layer] != face_num) { |
| 1046 |
uint8_t len, anim_speed = 0, i; |
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
ns->lastmap.cells[ax][ay].faces[layer] = face_num; |
| 1051 |
|
| 1052 |
|
| 1053 |
nlayer = MAP2_LAYER_START+layer; |
| 1054 |
|
| 1055 |
len = 2; |
| 1056 |
|
| 1057 |
if (ob->map && !MAP_NOSMOOTH(ob->map)) { |
| 1058 |
smoothlevel = ob->smoothlevel; |
| 1059 |
if (smoothlevel) |
| 1060 |
len++; |
| 1061 |
} |
| 1062 |
|
| 1063 |
if (QUERY_FLAG(ob, FLAG_CLIENT_ANIM_SYNC) |
| 1064 |
|| QUERY_FLAG(ob, FLAG_CLIENT_ANIM_RANDOM)) { |
| 1065 |
len++; |
| 1066 |
|
| 1067 |
|
| 1068 |
if (ob->anim_speed) |
| 1069 |
anim_speed = ob->anim_speed; |
| 1070 |
else if (FABS(ob->speed) < 0.004) |
| 1071 |
anim_speed = 255; |
| 1072 |
else if (FABS(ob->speed) >= 1.0) |
| 1073 |
anim_speed = 1; |
| 1074 |
else |
| 1075 |
anim_speed = (int)(1.0/FABS(ob->speed)); |
| 1076 |
|
| 1077 |
if (ob->animation && !ns->anims_sent[ob->animation->num]) |
| 1078 |
esrv_send_animation(ns, ob->animation); |
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
if (smoothlevel) { |
| 1086 |
for (i = 0; i < NUM_ANIMATIONS(ob); i++) { |
| 1087 |
if (!(ns->faces_sent[ob->animation->faces[i]->number]&NS_FACESENT_SMOOTH)) |
| 1088 |
send_smooth(ns, ob->animation->faces[i]); |
| 1089 |
} |
| 1090 |
} |
| 1091 |
} else if (!(ns->faces_sent[face_num]&NS_FACESENT_FACE)) { |
| 1092 |
esrv_send_face(ns, face, 0); |
| 1093 |
} |
| 1094 |
|
| 1095 |
if (smoothlevel |
| 1096 |
&& !(ns->faces_sent[ob->face->number]&NS_FACESENT_SMOOTH)) |
| 1097 |
send_smooth(ns, ob->face); |
| 1098 |
|
| 1099 |
|
| 1100 |
nlayer |= len<<5; |
| 1101 |
|
| 1102 |
SockList_AddChar(sl, nlayer); |
| 1103 |
SockList_AddShort(sl, face_num); |
| 1104 |
if (anim_speed) |
| 1105 |
SockList_AddChar(sl, anim_speed); |
| 1106 |
if (smoothlevel) |
| 1107 |
SockList_AddChar(sl, smoothlevel); |
| 1108 |
return 1; |
| 1109 |
} |
| 1110 |
} |
| 1111 |
return 0; |
| 1112 |
} |
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
static int map2_delete_layer(int ax, int ay, int layer, SockList *sl, socket_struct *ns) { |
| 1119 |
int nlayer; |
| 1120 |
|
| 1121 |
if (ns->lastmap.cells[ax][ay].faces[layer] != 0) { |
| 1122 |
|
| 1123 |
nlayer = 0x10+layer+(2<<5); |
| 1124 |
SockList_AddChar(sl, nlayer); |
| 1125 |
SockList_AddShort(sl, 0); |
| 1126 |
ns->lastmap.cells[ax][ay].faces[layer] = 0; |
| 1127 |
return 1; |
| 1128 |
} |
| 1129 |
return 0; |
| 1130 |
} |
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
static int check_probe(int ax, int ay, const object *ob, SockList *sl, socket_struct *ns, int *has_obj, int *alive_layer) { |
| 1144 |
int got_one = 0, poisoned = 0, diseased = 0; |
| 1145 |
char name[60]; |
| 1146 |
int value, granularity; |
| 1147 |
const object *probe; |
| 1148 |
|
| 1149 |
|
| 1150 |
if ((*alive_layer) != -1 || ob->head || !CAN_PROBE(ob)) |
| 1151 |
return 0; |
| 1152 |
|
| 1153 |
if (settings.always_show_hp == 2) { |
| 1154 |
|
| 1155 |
granularity = 30; |
| 1156 |
} else if (settings.always_show_hp == 1 && ob->stats.hp < ob->stats.maxhp) { |
| 1157 |
granularity = 30; |
| 1158 |
} else { |
| 1159 |
|
| 1160 |
if (!QUERY_FLAG(ob, FLAG_PROBE)) { |
| 1161 |
return 0; |
| 1162 |
} |
| 1163 |
probe = object_find_by_type_and_name(ob, FORCE, "probe_force"); |
| 1164 |
if (probe == NULL || probe->level < 15) { |
| 1165 |
|
| 1166 |
return 0; |
| 1167 |
} |
| 1168 |
|
| 1169 |
granularity = (probe->level - 14) / 3; |
| 1170 |
if (granularity <= 0) |
| 1171 |
granularity = 1; |
| 1172 |
else if (granularity > 30) |
| 1173 |
granularity = 30; |
| 1174 |
} |
| 1175 |
|
| 1176 |
if (ob->stats.maxhp > 0) { |
| 1177 |
value = (ob->stats.hp * granularity) / (ob->stats.maxhp); |
| 1178 |
|
| 1179 |
if (value < 0) |
| 1180 |
value = 0; |
| 1181 |
else if (value > granularity) |
| 1182 |
value = granularity; |
| 1183 |
} else |
| 1184 |
value = 30; |
| 1185 |
|
| 1186 |
value = (value * 30) / granularity; |
| 1187 |
|
| 1188 |
if (object_present_in_ob(POISONING, ob) != NULL) |
| 1189 |
poisoned = 1; |
| 1190 |
if (object_present_in_ob(DISEASE, ob) != NULL) |
| 1191 |
diseased = 1; |
| 1192 |
|
| 1193 |
if (value > 0) { |
| 1194 |
archetype *dummy; |
| 1195 |
|
| 1196 |
snprintf(name, sizeof(name), "hpbar%s%s%s_%d", |
| 1197 |
poisoned ? "_poisoned" : "", |
| 1198 |
diseased ? "_diseased" : "", |
| 1199 |
(!poisoned && !diseased) ? "_standard" : "", |
| 1200 |
value); |
| 1201 |
dummy = try_find_archetype(name); |
| 1202 |
if (dummy != NULL) { |
| 1203 |
got_one += map2_add_ob(ax, ay, MAP_LAYER_FLY2, &dummy->clone, sl, ns, has_obj, 0); |
| 1204 |
(*alive_layer) = MAP_LAYER_FLY2; |
| 1205 |
} |
| 1206 |
} |
| 1207 |
|
| 1208 |
return got_one; |
| 1209 |
} |
| 1210 |
|
| 1211 |
static int annotate_ob(int ax, int ay, const object *ob, SockList *sl, socket_struct *ns, int *has_obj, int *alive_layer) { |
| 1212 |
int got_one = check_probe(ax, ay, ob, sl, ns, has_obj, alive_layer); |
| 1213 |
if (QUERY_FLAG(ob, FLAG_ALIVE) && (QUERY_FLAG(ob, FLAG_UNAGGRESSIVE) || QUERY_FLAG(ob, FLAG_FRIENDLY)) && ob->msg != NULL && ob->type != PLAYER) { |
| 1214 |
archetype *dummy = try_find_archetype("speechbubble"); |
| 1215 |
if (dummy != NULL) { |
| 1216 |
got_one += map2_add_ob(ax, ay, MAP_LAYER_FLY2, &dummy->clone, sl, ns, has_obj, 0); |
| 1217 |
(*alive_layer) = MAP_LAYER_FLY2; |
| 1218 |
} |
| 1219 |
} |
| 1220 |
return got_one; |
| 1221 |
} |
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
static void check_space_for_heads(int ax, int ay, SockList *sl, socket_struct *ns) { |
| 1239 |
int layer, got_one = 0, del_one = 0, oldlen, has_obj = 0; |
| 1240 |
uint16_t coord; |
| 1241 |
|
| 1242 |
coord = MAP2_COORD_ENCODE(ax, ay, 0); |
| 1243 |
oldlen = sl->len; |
| 1244 |
SockList_AddShort(sl, coord); |
| 1245 |
|
| 1246 |
for (layer = 0; layer < MAP_LAYERS; layer++) { |
| 1247 |
const object *head; |
| 1248 |
|
| 1249 |
head = heads[ay][ax][layer]; |
| 1250 |
if (head) { |
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
got_one += map2_add_ob(ax, ay, layer, head, sl, ns, &has_obj, 1); |
| 1255 |
} else { |
| 1256 |
del_one += map2_delete_layer(ax, ay, layer, sl, ns); |
| 1257 |
} |
| 1258 |
} |
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
if (!del_one && !got_one) { |
| 1268 |
sl->len = oldlen; |
| 1269 |
} else if (del_one && !has_obj) { |
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
sl->len = oldlen+2; |
| 1276 |
SockList_AddChar(sl, 0); |
| 1277 |
SockList_AddChar(sl, 255); |
| 1278 |
|
| 1279 |
map_clearcell(ns->lastmap.cells[ax] + ay, 0, 0); |
| 1280 |
} else { |
| 1281 |
SockList_AddChar(sl, 255); |
| 1282 |
} |
| 1283 |
} |
| 1284 |
|
| 1285 |
static void draw_client_map2(object *pl) { |
| 1286 |
int x, y, ax, ay, d, min_x, max_x, min_y, max_y, oldlen, layer; |
| 1287 |
size_t startlen; |
| 1288 |
int16_t nx, ny; |
| 1289 |
SockList sl; |
| 1290 |
uint16_t coord; |
| 1291 |
mapstruct *m; |
| 1292 |
|
| 1293 |
player *plyr = pl->contr; |
| 1294 |
|
| 1295 |
SockList_Init(&sl); |
| 1296 |
SockList_AddString(&sl, "map2 "); |
| 1297 |
startlen = sl.len; |
| 1298 |
|
| 1299 |
|
| 1300 |
if (plyr->socket.map_scroll_x || plyr->socket.map_scroll_y) { |
| 1301 |
coord = MAP2_COORD_ENCODE(plyr->socket.map_scroll_x, plyr->socket.map_scroll_y, 1); |
| 1302 |
plyr->socket.map_scroll_x = 0; |
| 1303 |
plyr->socket.map_scroll_y = 0; |
| 1304 |
SockList_AddShort(&sl, coord); |
| 1305 |
} |
| 1306 |
|
| 1307 |
|
| 1308 |
memset(heads, 0, sizeof(heads)); |
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
min_x = pl->x-plyr->socket.mapx/2; |
| 1314 |
min_y = pl->y-plyr->socket.mapy/2; |
| 1315 |
max_x = pl->x+(plyr->socket.mapx+1)/2+MAX_HEAD_OFFSET; |
| 1316 |
max_y = pl->y+(plyr->socket.mapy+1)/2+MAX_HEAD_OFFSET; |
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
ay = 0; |
| 1322 |
for (y = min_y; y < max_y; y++, ay++) { |
| 1323 |
ax = 0; |
| 1324 |
for (x = min_x; x < max_x; x++, ax++) { |
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
if (ax >= plyr->socket.mapx || ay >= plyr->socket.mapy) { |
| 1331 |
check_space_for_heads(ax, ay, &sl, &plyr->socket); |
| 1332 |
} else { |
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
d = plyr->blocked_los[ax][ay]; |
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
nx = x; |
| 1350 |
ny = y; |
| 1351 |
m = get_map_from_coord(pl->map, &nx, &ny); |
| 1352 |
coord = MAP2_COORD_ENCODE(ax, ay, 0); |
| 1353 |
|
| 1354 |
if (!m) { |
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
if (plyr->socket.lastmap.cells[ax][ay].darkness != 0) { |
| 1361 |
SockList_AddShort(&sl, coord); |
| 1362 |
SockList_AddChar(&sl, MAP2_TYPE_CLEAR); |
| 1363 |
SockList_AddChar(&sl, 255); |
| 1364 |
|
| 1365 |
map_clearcell(plyr->socket.lastmap.cells[ax] + ay, 0, 0); |
| 1366 |
} |
| 1367 |
} else if (d >= MAX_LIGHT_RADII) { |
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
check_space_for_heads(ax, ay, &sl, &plyr->socket); |
| 1373 |
} else { |
| 1374 |
int have_darkness = 0, has_obj = 0, got_one = 0, del_one = 0, g1, alive_layer = -1, old_got; |
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
oldlen = sl.len; |
| 1392 |
SockList_AddShort(&sl, coord); |
| 1393 |
|
| 1394 |
|
| 1395 |
if (plyr->socket.lastmap.cells[ax][ay].darkness != d |
| 1396 |
&& plyr->socket.darkness) { |
| 1397 |
plyr->socket.lastmap.cells[ax][ay].darkness = d; |
| 1398 |
|
| 1399 |
SockList_AddChar(&sl, MAP2_TYPE_DARKNESS|1<<5); |
| 1400 |
SockList_AddChar(&sl, 255-d*(256/MAX_LIGHT_RADII)); |
| 1401 |
have_darkness = 1; |
| 1402 |
} |
| 1403 |
|
| 1404 |
for (layer = 0; layer < MAP_LAYERS; layer++) { |
| 1405 |
const object *ob = GET_MAP_FACE_OBJ(m, nx, ny, layer); |
| 1406 |
|
| 1407 |
|
| 1408 |
if (!ob |
| 1409 |
&& x == pl->x |
| 1410 |
&& y == pl->y |
| 1411 |
&& (pl->invisible&(pl->invisible < 50 ? 4 : 1)) |
| 1412 |
&& (layer == MAP_LAYER_LIVING1 || layer == MAP_LAYER_LIVING2)) |
| 1413 |
ob = pl; |
| 1414 |
|
| 1415 |
if (ob) { |
| 1416 |
g1 = has_obj; |
| 1417 |
old_got = got_one; |
| 1418 |
got_one += map2_add_ob(ax, ay, layer, ob, &sl, &plyr->socket, &has_obj, 0); |
| 1419 |
|
| 1420 |
|
| 1421 |
if (got_one != old_got || (ob->head == NULL && ob->more)) |
| 1422 |
got_one += annotate_ob(ax, ay, ob, &sl, &plyr->socket, &has_obj, &alive_layer); |
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
if (g1 == has_obj) { |
| 1430 |
del_one += map2_delete_layer(ax, ay, layer, &sl, &plyr->socket); |
| 1431 |
} else if (ob->head == NULL) { |
| 1432 |
|
| 1433 |
got_one += annotate_ob(ax, ay, ob, &sl, &plyr->socket, &has_obj, &alive_layer); |
| 1434 |
} |
| 1435 |
} else { |
| 1436 |
if (layer != alive_layer) |
| 1437 |
del_one += map2_delete_layer(ax, ay, layer, &sl, &plyr->socket); |
| 1438 |
} |
| 1439 |
} |
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
if (!del_one && !got_one && !have_darkness) { |
| 1444 |
sl.len = oldlen; |
| 1445 |
} else if (del_one && !has_obj) { |
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
sl.len = oldlen+2; |
| 1454 |
SockList_AddChar(&sl, MAP2_TYPE_CLEAR); |
| 1455 |
SockList_AddChar(&sl, 255); |
| 1456 |
|
| 1457 |
map_clearcell(plyr->socket.lastmap.cells[ax] + ay, 0, 0); |
| 1458 |
} else { |
| 1459 |
SockList_AddChar(&sl, 255); |
| 1460 |
} |
| 1461 |
} |
| 1462 |
} |
| 1463 |
} |
| 1464 |
} |
| 1465 |
|
| 1466 |
|
| 1467 |
if (sl.len > startlen) { |
| 1468 |
Send_With_Handling(&plyr->socket, &sl); |
| 1469 |
} |
| 1470 |
SockList_Term(&sl); |
| 1471 |
} |
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
void draw_client_map(object *pl) { |
| 1477 |
int i, j; |
| 1478 |
int16_t ax, ay; |
| 1479 |
int mflags; |
| 1480 |
mapstruct *m, *pm; |
| 1481 |
int min_x, min_y, max_x, max_y; |
| 1482 |
|
| 1483 |
if (pl->type != PLAYER) { |
| 1484 |
LOG(llevError, "draw_client_map called with non player/non eric-server\n"); |
| 1485 |
return; |
| 1486 |
} |
| 1487 |
|
| 1488 |
if (pl->contr->transport) { |
| 1489 |
pm = pl->contr->transport->map; |
| 1490 |
} else |
| 1491 |
pm = pl->map; |
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
if (pm == NULL || pm->in_memory != MAP_IN_MEMORY) |
| 1498 |
return; |
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
min_x = pl->x-pl->contr->socket.mapx/2; |
| 1505 |
min_y = pl->y-pl->contr->socket.mapy/2; |
| 1506 |
max_x = pl->x+(pl->contr->socket.mapx+1)/2; |
| 1507 |
max_y = pl->y+(pl->contr->socket.mapy+1)/2; |
| 1508 |
for (j = min_y; j < max_y; j++) { |
| 1509 |
for (i = min_x; i < max_x; i++) { |
| 1510 |
ax = i; |
| 1511 |
ay = j; |
| 1512 |
m = pm; |
| 1513 |
mflags = get_map_flags(m, &m, ax, ay, &ax, &ay); |
| 1514 |
if (mflags&P_OUT_OF_MAP) |
| 1515 |
continue; |
| 1516 |
if (mflags&P_NEED_UPDATE) |
| 1517 |
update_position(m, ax, ay); |
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
if (mflags&P_NEW_MAP) |
| 1524 |
m->timeout = 50; |
| 1525 |
} |
| 1526 |
} |
| 1527 |
|
| 1528 |
|
| 1529 |
if (pl->contr->do_los) { |
| 1530 |
update_los(pl); |
| 1531 |
pl->contr->do_los = 0; |
| 1532 |
} |
| 1533 |
|
| 1534 |
draw_client_map2(pl); |
| 1535 |
} |
| 1536 |
|
| 1537 |
void esrv_map_scroll(socket_struct *ns, int dx, int dy) { |
| 1538 |
struct Map newmap; |
| 1539 |
int x, y, mx, my; |
| 1540 |
|
| 1541 |
ns->map_scroll_x += dx; |
| 1542 |
ns->map_scroll_y += dy; |
| 1543 |
|
| 1544 |
mx = ns->mapx+MAX_HEAD_OFFSET; |
| 1545 |
my = ns->mapy+MAX_HEAD_OFFSET; |
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
for (x = 0; x < mx; x++) { |
| 1554 |
for (y = 0; y < my; y++) { |
| 1555 |
if (x >= ns->mapx || y >= ns->mapy) { |
| 1556 |
|
| 1557 |
memset(&newmap.cells[x][y], 0, sizeof(newmap.cells[x][y])); |
| 1558 |
} else if (x+dx < 0 || x+dx >= ns->mapx || y+dy < 0 || y+dy >= ns->mapy) { |
| 1559 |
|
| 1560 |
memset(&newmap.cells[x][y], 0, sizeof(newmap.cells[x][y])); |
| 1561 |
} else { |
| 1562 |
memcpy(&newmap.cells[x][y], &ns->lastmap.cells[x+dx][y+dy], sizeof(newmap.cells[x][y])); |
| 1563 |
} |
| 1564 |
} |
| 1565 |
} |
| 1566 |
|
| 1567 |
memcpy(&ns->lastmap, &newmap, sizeof(ns->lastmap)); |
| 1568 |
} |
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
void send_plugin_custom_message(object *pl, char *buf) { |
| 1576 |
SockList sl; |
| 1577 |
|
| 1578 |
SockList_Init(&sl); |
| 1579 |
SockList_AddString(&sl, buf); |
| 1580 |
Send_With_Handling(&pl->contr->socket, &sl); |
| 1581 |
SockList_Term(&sl); |
| 1582 |
} |
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
void esrv_update_spells(player *pl) { |
| 1590 |
SockList sl; |
| 1591 |
int flags = 0; |
| 1592 |
client_spell *spell_info; |
| 1593 |
|
| 1594 |
if (!pl->socket.monitor_spells) |
| 1595 |
return; |
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
if (!pl->spell_state) |
| 1604 |
return; |
| 1605 |
|
| 1606 |
FOR_INV_PREPARE(pl->ob, spell) { |
| 1607 |
if (spell->type == SPELL) { |
| 1608 |
spell_info = get_client_spell_state(pl, spell); |
| 1609 |
|
| 1610 |
if (spell_info->last_sp != SP_level_spellpoint_cost(pl->ob, spell, SPELL_MANA)) { |
| 1611 |
spell_info->last_sp = SP_level_spellpoint_cost(pl->ob, spell, SPELL_MANA); |
| 1612 |
flags |= UPD_SP_MANA; |
| 1613 |
} |
| 1614 |
if (spell_info->last_grace != SP_level_spellpoint_cost(pl->ob, spell, SPELL_GRACE)) { |
| 1615 |
spell_info->last_grace = SP_level_spellpoint_cost(pl->ob, spell, SPELL_GRACE); |
| 1616 |
flags |= UPD_SP_GRACE; |
| 1617 |
} |
| 1618 |
if (spell_info->last_dam != spell->stats.dam+SP_level_dam_adjust(pl->ob, spell)) { |
| 1619 |
spell_info->last_dam = spell->stats.dam+SP_level_dam_adjust(pl->ob, spell); |
| 1620 |
flags |= UPD_SP_DAMAGE; |
| 1621 |
} |
| 1622 |
if (flags != 0) { |
| 1623 |
SockList_Init(&sl); |
| 1624 |
SockList_AddString(&sl, "updspell "); |
| 1625 |
SockList_AddChar(&sl, flags); |
| 1626 |
SockList_AddInt(&sl, spell->count); |
| 1627 |
if (flags&UPD_SP_MANA) |
| 1628 |
SockList_AddShort(&sl, spell_info->last_sp); |
| 1629 |
if (flags&UPD_SP_GRACE) |
| 1630 |
SockList_AddShort(&sl, spell_info->last_grace); |
| 1631 |
if (flags&UPD_SP_DAMAGE) |
| 1632 |
SockList_AddShort(&sl, spell_info->last_dam); |
| 1633 |
flags = 0; |
| 1634 |
Send_With_Handling(&pl->socket, &sl); |
| 1635 |
SockList_Term(&sl); |
| 1636 |
} |
| 1637 |
} |
| 1638 |
} FOR_INV_FINISH(); |
| 1639 |
} |
| 1640 |
|
| 1641 |
void esrv_remove_spell(player *pl, object *spell) { |
| 1642 |
SockList sl; |
| 1643 |
|
| 1644 |
if (!pl || !spell || spell->env != pl->ob) { |
| 1645 |
LOG(llevError, "Invalid call to esrv_remove_spell\n"); |
| 1646 |
return; |
| 1647 |
} |
| 1648 |
if (!pl->socket.monitor_spells) |
| 1649 |
return; |
| 1650 |
|
| 1651 |
SockList_Init(&sl); |
| 1652 |
SockList_AddString(&sl, "delspell "); |
| 1653 |
SockList_AddInt(&sl, spell->count); |
| 1654 |
Send_With_Handling(&pl->socket, &sl); |
| 1655 |
SockList_Term(&sl); |
| 1656 |
} |
| 1657 |
|
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
void esrv_send_pickup(player *pl) { |
| 1665 |
SockList sl; |
| 1666 |
|
| 1667 |
if (!pl->socket.want_pickup) |
| 1668 |
return; |
| 1669 |
SockList_Init(&sl); |
| 1670 |
SockList_AddString(&sl, "pickup "); |
| 1671 |
SockList_AddInt(&sl, pl->mode); |
| 1672 |
Send_With_Handling(&pl->socket, &sl); |
| 1673 |
SockList_Term(&sl); |
| 1674 |
} |
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
static int spell_client_use(const object *spell) { |
| 1685 |
switch (spell->type) |
| 1686 |
{ |
| 1687 |
case SP_RAISE_DEAD: |
| 1688 |
case SP_MAKE_MARK: |
| 1689 |
return 3; |
| 1690 |
case SP_RUNE: |
| 1691 |
if (!spell->other_arch) |
| 1692 |
return 1; |
| 1693 |
break; |
| 1694 |
case SP_CREATE_FOOD: |
| 1695 |
case SP_CREATE_MISSILE: |
| 1696 |
return 2; |
| 1697 |
case SP_SUMMON_MONSTER: |
| 1698 |
if (spell->randomitems != NULL) |
| 1699 |
return 2; |
| 1700 |
|
| 1701 |
} |
| 1702 |
|
| 1703 |
|
| 1704 |
return 0; |
| 1705 |
} |
| 1706 |
|
| 1707 |
|
| 1708 |
static void append_spell(player *pl, SockList *sl, object *spell) { |
| 1709 |
client_spell *spell_info; |
| 1710 |
int len, i, skill = 0; |
| 1711 |
|
| 1712 |
if (!spell->name) { |
| 1713 |
LOG(llevError, "item number %d is a spell with no name.\n", spell->count); |
| 1714 |
return; |
| 1715 |
} |
| 1716 |
|
| 1717 |
if (spell->face && !(pl->socket.faces_sent[spell->face->number]&NS_FACESENT_FACE)) |
| 1718 |
esrv_send_face(&pl->socket, spell->face, 0); |
| 1719 |
|
| 1720 |
spell_info = get_client_spell_state(pl, spell); |
| 1721 |
SockList_AddInt(sl, spell->count); |
| 1722 |
SockList_AddShort(sl, spell->level); |
| 1723 |
SockList_AddShort(sl, spell->casting_time); |
| 1724 |
|
| 1725 |
spell_info->last_sp = SP_level_spellpoint_cost(pl->ob, spell, SPELL_MANA); |
| 1726 |
spell_info->last_grace = SP_level_spellpoint_cost(pl->ob, spell, SPELL_GRACE); |
| 1727 |
spell_info->last_dam = spell->stats.dam+SP_level_dam_adjust(pl->ob, spell); |
| 1728 |
|
| 1729 |
SockList_AddShort(sl, spell_info->last_sp); |
| 1730 |
SockList_AddShort(sl, spell_info->last_grace); |
| 1731 |
SockList_AddShort(sl, spell_info->last_dam); |
| 1732 |
|
| 1733 |
|
| 1734 |
if (spell->skill) { |
| 1735 |
for (i = 0; i < MAX_SKILLS && skill_names[i]; i++) |
| 1736 |
if (!strcmp(spell->skill, skill_names[i])) { |
| 1737 |
skill = i+CS_STAT_SKILLINFO; |
| 1738 |
break; |
| 1739 |
} |
| 1740 |
} |
| 1741 |
SockList_AddChar(sl, skill); |
| 1742 |
|
| 1743 |
SockList_AddInt(sl, spell->path_attuned); |
| 1744 |
SockList_AddInt(sl, spell->face ? spell->face->number : 0); |
| 1745 |
SockList_AddLen8Data(sl, spell->name, strlen(spell->name)); |
| 1746 |
|
| 1747 |
if (!spell->msg) { |
| 1748 |
SockList_AddShort(sl, 0); |
| 1749 |
} else { |
| 1750 |
len = strlen(spell->msg); |
| 1751 |
SockList_AddShort(sl, len); |
| 1752 |
SockList_AddData(sl, spell->msg, len); |
| 1753 |
} |
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
if (pl->socket.monitor_spells >= 2) { |
| 1758 |
|
| 1759 |
|
| 1760 |
sstring req = object_get_value(spell, "casting_requirements"); |
| 1761 |
|
| 1762 |
SockList_AddChar(sl, spell_client_use(spell)); |
| 1763 |
|
| 1764 |
if (req) { |
| 1765 |
SockList_AddLen8Data(sl, req, strlen(req)); |
| 1766 |
} else { |
| 1767 |
SockList_AddChar(sl, 0); |
| 1768 |
} |
| 1769 |
|
| 1770 |
|
| 1771 |
} |
| 1772 |
} |
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
void esrv_add_spells(player *pl, object *spell) { |
| 1779 |
SockList sl; |
| 1780 |
size_t size; |
| 1781 |
sstring value; |
| 1782 |
|
| 1783 |
if (!pl) { |
| 1784 |
LOG(llevError, "esrv_add_spells, tried to add a spell to a NULL player\n"); |
| 1785 |
return; |
| 1786 |
} |
| 1787 |
|
| 1788 |
if (!pl->socket.monitor_spells) |
| 1789 |
return; |
| 1790 |
|
| 1791 |
SockList_Init(&sl); |
| 1792 |
SockList_AddString(&sl, "addspell "); |
| 1793 |
if (!spell) { |
| 1794 |
FOR_INV_PREPARE(pl->ob, spell) { |
| 1795 |
if (spell->type != SPELL) |
| 1796 |
continue; |
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
size = 26+strlen(spell->name)+(spell->msg ? strlen(spell->msg) : 0); |
| 1808 |
if (pl->socket.monitor_spells >= 2) { |
| 1809 |
|
| 1810 |
value = object_get_value(spell, "casting_requirements"); |
| 1811 |
size += 2 + (value ? strlen(value) : 0); |
| 1812 |
} |
| 1813 |
if (SockList_Avail(&sl) < size) { |
| 1814 |
Send_With_Handling(&pl->socket, &sl); |
| 1815 |
SockList_Reset(&sl); |
| 1816 |
SockList_AddString(&sl, "addspell "); |
| 1817 |
} |
| 1818 |
append_spell(pl, &sl, spell); |
| 1819 |
} FOR_INV_FINISH(); |
| 1820 |
} else if (spell->type != SPELL) { |
| 1821 |
LOG(llevError, "Asked to send a non-spell object as a spell\n"); |
| 1822 |
return; |
| 1823 |
} else |
| 1824 |
append_spell(pl, &sl, spell); |
| 1825 |
|
| 1826 |
Send_With_Handling(&pl->socket, &sl); |
| 1827 |
SockList_Term(&sl); |
| 1828 |
} |
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
void send_tick(player *pl) { |
| 1838 |
SockList sl; |
| 1839 |
int tmp; |
| 1840 |
|
| 1841 |
SockList_Init(&sl); |
| 1842 |
SockList_AddString(&sl, "tick "); |
| 1843 |
SockList_AddInt(&sl, pticks); |
| 1844 |
tmp = 1; |
| 1845 |
if (setsockopt(pl->socket.fd, IPPROTO_TCP, TCP_NODELAY, &tmp, sizeof(tmp))) |
| 1846 |
LOG(llevError, "send_tick: Unable to turn on TCP_NODELAY\n"); |
| 1847 |
|
| 1848 |
Send_With_Handling(&pl->socket, &sl); |
| 1849 |
tmp = 0; |
| 1850 |
if (setsockopt(pl->socket.fd, IPPROTO_TCP, TCP_NODELAY, &tmp, sizeof(tmp))) |
| 1851 |
LOG(llevError, "send_tick: Unable to turn off TCP_NODELAY\n"); |
| 1852 |
SockList_Term(&sl); |
| 1853 |
} |
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
|
| 1863 |
|
| 1864 |
|
| 1865 |
|
| 1866 |
|
| 1867 |
static void add_char_field(SockList *sl, int type, const char *data) |
| 1868 |
{ |
| 1869 |
int len; |
| 1870 |
|
| 1871 |
len = strlen(data); |
| 1872 |
|
| 1873 |
if (len) { |
| 1874 |
|
| 1875 |
SockList_AddChar(sl, len+1); |
| 1876 |
SockList_AddChar(sl, type); |
| 1877 |
SockList_AddString(sl, data); |
| 1878 |
} |
| 1879 |
} |
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
|
| 1886 |
|
| 1887 |
|
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
void send_account_players(socket_struct *ns) |
| 1902 |
{ |
| 1903 |
SockList sl; |
| 1904 |
Account_Char *acn; |
| 1905 |
int i, num_chars, need_send[MAX_CHARACTERS_PER_ACCOUNT]; |
| 1906 |
char **chars; |
| 1907 |
|
| 1908 |
ns->account_chars = account_char_load(ns->account_name); |
| 1909 |
|
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
chars = account_get_players_for_account(ns->account_name); |
| 1926 |
|
| 1927 |
SockList_Init(&sl); |
| 1928 |
SockList_AddString(&sl, "accountplayers "); |
| 1929 |
num_chars=0; |
| 1930 |
|
| 1931 |
|
| 1932 |
|
| 1933 |
|
| 1934 |
|
| 1935 |
for (i=0; i<MAX_CHARACTERS_PER_ACCOUNT; i++) { |
| 1936 |
if (chars[i]) |
| 1937 |
need_send[i] = 1; |
| 1938 |
else break; |
| 1939 |
} |
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
for (acn = ns->account_chars; acn; acn = acn->next) { |
| 1945 |
num_chars++; |
| 1946 |
for (i=0; i<MAX_CHARACTERS_PER_ACCOUNT; i++) { |
| 1947 |
|
| 1948 |
|
| 1949 |
|
| 1950 |
if (!chars[i]) break; |
| 1951 |
|
| 1952 |
if (!strcmp(chars[i], acn->name)) { |
| 1953 |
need_send[i] = 0; |
| 1954 |
break; |
| 1955 |
} |
| 1956 |
} |
| 1957 |
} |
| 1958 |
|
| 1959 |
|
| 1960 |
for (i=0; i< MAX_CHARACTERS_PER_ACCOUNT; i++) { |
| 1961 |
if (!chars[i]) break; |
| 1962 |
|
| 1963 |
if (need_send[i]) |
| 1964 |
num_chars++; |
| 1965 |
} |
| 1966 |
|
| 1967 |
SockList_AddChar(&sl, num_chars); |
| 1968 |
|
| 1969 |
|
| 1970 |
for (acn = ns->account_chars; acn; acn = acn->next) { |
| 1971 |
uint16_t faceno = 0; |
| 1972 |
|
| 1973 |
|
| 1974 |
if (acn->isDead) { |
| 1975 |
continue; |
| 1976 |
} |
| 1977 |
|
| 1978 |
add_char_field(&sl, ACL_NAME, acn->name); |
| 1979 |
add_char_field(&sl, ACL_CLASS, acn->character_class); |
| 1980 |
add_char_field(&sl, ACL_RACE, acn->race); |
| 1981 |
add_char_field(&sl, ACL_FACE, acn->face); |
| 1982 |
if (acn->face[0] != 0 ) { |
| 1983 |
const Face *face = find_face(acn->face, 0); |
| 1984 |
|
| 1985 |
if (face != NULL) { |
| 1986 |
if (!(ns->faces_sent[face->number]&NS_FACESENT_FACE)) { |
| 1987 |
esrv_send_face(ns, face, 0); |
| 1988 |
} |
| 1989 |
faceno = face->number; |
| 1990 |
} |
| 1991 |
} |
| 1992 |
|
| 1993 |
add_char_field(&sl, ACL_PARTY, acn->party); |
| 1994 |
add_char_field(&sl, ACL_MAP, acn->map); |
| 1995 |
SockList_AddChar(&sl, 3); |
| 1996 |
SockList_AddChar(&sl, ACL_LEVEL); |
| 1997 |
SockList_AddShort(&sl, acn->level); |
| 1998 |
if (faceno) { |
| 1999 |
SockList_AddChar(&sl, 3); |
| 2000 |
SockList_AddChar(&sl, ACL_FACE_NUM); |
| 2001 |
SockList_AddShort(&sl, faceno); |
| 2002 |
} |
| 2003 |
|
| 2004 |
SockList_AddChar(&sl, 0); |
| 2005 |
} |
| 2006 |
|
| 2007 |
for (i=0; i< MAX_CHARACTERS_PER_ACCOUNT; i++) { |
| 2008 |
if (!chars[i]) break; |
| 2009 |
|
| 2010 |
if (need_send[i]) { |
| 2011 |
add_char_field(&sl, ACL_NAME, chars[i]); |
| 2012 |
SockList_AddChar(&sl, 0); |
| 2013 |
} |
| 2014 |
} |
| 2015 |
|
| 2016 |
Send_With_Handling(ns, &sl); |
| 2017 |
SockList_Term(&sl); |
| 2018 |
} |
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
|
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
|
| 2034 |
|
| 2035 |
|
| 2036 |
|
| 2037 |
|
| 2038 |
|
| 2039 |
|
| 2040 |
|
| 2041 |
static int decode_name_password(const char *buf, int *len, char *name, char *password) |
| 2042 |
{ |
| 2043 |
int nlen, plen; |
| 2044 |
|
| 2045 |
if (*len < 2) { |
| 2046 |
return 1; |
| 2047 |
} |
| 2048 |
|
| 2049 |
nlen = (unsigned char)buf[0]; |
| 2050 |
if (nlen >= MAX_BUF || nlen > *len-2) { |
| 2051 |
return 1; |
| 2052 |
} |
| 2053 |
memcpy(name, buf+1, nlen); |
| 2054 |
name[nlen] = 0; |
| 2055 |
|
| 2056 |
plen = (unsigned char)buf[nlen+1]; |
| 2057 |
if (plen >= MAX_BUF || plen > *len-2-nlen) { |
| 2058 |
return 2; |
| 2059 |
} |
| 2060 |
memcpy(password, buf+2+nlen, plen); |
| 2061 |
password[plen] = 0; |
| 2062 |
|
| 2063 |
*len = nlen+plen+2; |
| 2064 |
|
| 2065 |
return 0; |
| 2066 |
} |
| 2067 |
|
| 2068 |
|
| 2069 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
void account_login_cmd(char *buf, int len, socket_struct *ns) { |
| 2078 |
char name[MAX_BUF], password[MAX_BUF]; |
| 2079 |
int status; |
| 2080 |
SockList sl; |
| 2081 |
|
| 2082 |
if (len <= 0 || !buf) { |
| 2083 |
LOG(llevDebug, "IP '%s' sent bogus add_player_cmd information\n", ns->host); |
| 2084 |
return; |
| 2085 |
} |
| 2086 |
|
| 2087 |
SockList_Init(&sl); |
| 2088 |
|
| 2089 |
status = decode_name_password(buf, &len, name, password); |
| 2090 |
|
| 2091 |
if (status == 1) { |
| 2092 |
SockList_AddString(&sl, "failure accountlogin Name is too long"); |
| 2093 |
Send_With_Handling(ns, &sl); |
| 2094 |
SockList_Term(&sl); |
| 2095 |
return; |
| 2096 |
} |
| 2097 |
if (status == 2) { |
| 2098 |
SockList_AddString(&sl, "failure accountlogin Password is too long"); |
| 2099 |
Send_With_Handling(ns, &sl); |
| 2100 |
SockList_Term(&sl); |
| 2101 |
return; |
| 2102 |
} |
| 2103 |
|
| 2104 |
if (!account_exists(name)) { |
| 2105 |
SockList_AddString(&sl, "failure accountlogin No such account name exists on this server"); |
| 2106 |
Send_With_Handling(ns, &sl); |
| 2107 |
SockList_Term(&sl); |
| 2108 |
return; |
| 2109 |
} |
| 2110 |
|
| 2111 |
if (account_login(name, password)) { |
| 2112 |
LOG(llevInfo, "Account login for '%s' from %s\n", name, ns->host); |
| 2113 |
player *pl; |
| 2114 |
socket_struct *tns; |
| 2115 |
|
| 2116 |
|
| 2117 |
|
| 2118 |
|
| 2119 |
|
| 2120 |
|
| 2121 |
tns = account_get_logged_in_init_socket(name); |
| 2122 |
|
| 2123 |
|
| 2124 |
|
| 2125 |
|
| 2126 |
|
| 2127 |
|
| 2128 |
|
| 2129 |
if (tns && tns != ns) |
| 2130 |
tns->status = Ns_Dead; |
| 2131 |
|
| 2132 |
|
| 2133 |
|
| 2134 |
|
| 2135 |
|
| 2136 |
|
| 2137 |
pl = account_get_logged_in_player(name); |
| 2138 |
if (pl) |
| 2139 |
pl->socket.status = Ns_Dead; |
| 2140 |
|
| 2141 |
|
| 2142 |
if (ns->account_name) free(ns->account_name); |
| 2143 |
|
| 2144 |
|
| 2145 |
|
| 2146 |
|
| 2147 |
|
| 2148 |
|
| 2149 |
ns->account_name = strdup_local(account_exists(name)); |
| 2150 |
|
| 2151 |
send_account_players(ns); |
| 2152 |
} else { |
| 2153 |
LOG(llevInfo, "Failed account login for '%s' from %s\n", name, ns->host); |
| 2154 |
SockList_AddString(&sl, "failure accountlogin Incorrect password for account"); |
| 2155 |
Send_With_Handling(ns, &sl); |
| 2156 |
SockList_Term(&sl); |
| 2157 |
} |
| 2158 |
} |
| 2159 |
|
| 2160 |
|
| 2161 |
|
| 2162 |
|
| 2163 |
|
| 2164 |
|
| 2165 |
|
| 2166 |
|
| 2167 |
|
| 2168 |
static int account_block_create(const socket_struct *ns) { |
| 2169 |
|
| 2170 |
if(!settings.account_block_create) { |
| 2171 |
|
| 2172 |
return 0; |
| 2173 |
} |
| 2174 |
|
| 2175 |
|
| 2176 |
if(settings.account_trusted_host == NULL) { |
| 2177 |
|
| 2178 |
settings.account_trusted_host = strdup_local("127.0.0.1"); |
| 2179 |
} |
| 2180 |
|
| 2181 |
|
| 2182 |
if(strcmp(ns->host, settings.account_trusted_host) == 0){ |
| 2183 |
return 0; |
| 2184 |
} |
| 2185 |
|
| 2186 |
|
| 2187 |
|
| 2188 |
|
| 2189 |
|
| 2190 |
return 1; |
| 2191 |
} |
| 2192 |
|
| 2193 |
|
| 2194 |
|
| 2195 |
|
| 2196 |
|
| 2197 |
|
| 2198 |
|
| 2199 |
|
| 2200 |
|
| 2201 |
|
| 2202 |
|
| 2203 |
|
| 2204 |
void account_new_cmd(char *buf, int len, socket_struct *ns) { |
| 2205 |
char name[MAX_BUF], password[MAX_BUF]; |
| 2206 |
int status; |
| 2207 |
SockList sl; |
| 2208 |
|
| 2209 |
if (len <= 0 || !buf) { |
| 2210 |
LOG(llevDebug, "IP '%s' sent bogus add_player_cmd information\n", ns->host); |
| 2211 |
return; |
| 2212 |
} |
| 2213 |
|
| 2214 |
SockList_Init(&sl); |
| 2215 |
|
| 2216 |
status = decode_name_password(buf, &len, name, password); |
| 2217 |
|
| 2218 |
if (account_block_create(ns)) { |
| 2219 |
LOG(llevInfo, "Account create blocked from %s\n", ns->host); |
| 2220 |
SockList_AddString(&sl, "failure accountnew Account creation is disabled"); |
| 2221 |
Send_With_Handling(ns, &sl); |
| 2222 |
SockList_Term(&sl); |
| 2223 |
return; |
| 2224 |
} |
| 2225 |
|
| 2226 |
if (status == 1) { |
| 2227 |
SockList_AddString(&sl, "failure accountnew Name is too long"); |
| 2228 |
Send_With_Handling(ns, &sl); |
| 2229 |
SockList_Term(&sl); |
| 2230 |
return; |
| 2231 |
} |
| 2232 |
if (status == 2) { |
| 2233 |
SockList_AddString(&sl, "failure accountnew Password is too long"); |
| 2234 |
Send_With_Handling(ns, &sl); |
| 2235 |
SockList_Term(&sl); |
| 2236 |
return; |
| 2237 |
} |
| 2238 |
|
| 2239 |
|
| 2240 |
|
| 2241 |
|
| 2242 |
if (strlen(name)<settings.min_name) { |
| 2243 |
SockList_AddString(&sl, "failure accountnew Name is too short"); |
| 2244 |
Send_With_Handling(ns, &sl); |
| 2245 |
SockList_Term(&sl); |
| 2246 |
return; |
| 2247 |
} |
| 2248 |
if (strlen(password)<2) { |
| 2249 |
SockList_AddString(&sl, "failure accountnew Password is too short"); |
| 2250 |
Send_With_Handling(ns, &sl); |
| 2251 |
SockList_Term(&sl); |
| 2252 |
return; |
| 2253 |
} |
| 2254 |
|
| 2255 |
if (account_exists(name)) { |
| 2256 |
SockList_AddString(&sl, "failure accountnew That account already exists on this server"); |
| 2257 |
Send_With_Handling(ns, &sl); |
| 2258 |
SockList_Term(&sl); |
| 2259 |
return; |
| 2260 |
} |
| 2261 |
|
| 2262 |
status = account_check_string(name); |
| 2263 |
if (status == 1) { |
| 2264 |
SockList_AddString(&sl, |
| 2265 |
"failure accountnew That account name contains invalid characters."); |
| 2266 |
Send_With_Handling(ns, &sl); |
| 2267 |
SockList_Term(&sl); |
| 2268 |
return; |
| 2269 |
} |
| 2270 |
|
| 2271 |
if (status == 2) { |
| 2272 |
SockList_AddString(&sl, |
| 2273 |
"failure accountnew That account name is too long"); |
| 2274 |
Send_With_Handling(ns, &sl); |
| 2275 |
SockList_Term(&sl); |
| 2276 |
return; |
| 2277 |
} |
| 2278 |
|
| 2279 |
status = account_check_string(password); |
| 2280 |
if (status == 1) { |
| 2281 |
SockList_AddString(&sl, |
| 2282 |
"failure accountnew That password contains invalid characters."); |
| 2283 |
Send_With_Handling(ns, &sl); |
| 2284 |
SockList_Term(&sl); |
| 2285 |
return; |
| 2286 |
} |
| 2287 |
|
| 2288 |
if (status == 2) { |
| 2289 |
SockList_AddString(&sl, |
| 2290 |
"failure accountnew That password is too long"); |
| 2291 |
Send_With_Handling(ns, &sl); |
| 2292 |
SockList_Term(&sl); |
| 2293 |
return; |
| 2294 |
} |
| 2295 |
|
| 2296 |
|
| 2297 |
if (ns->account_name) free(ns->account_name); |
| 2298 |
ns->account_name = strdup_local(name); |
| 2299 |
account_new(name, password); |
| 2300 |
|
| 2301 |
accounts_save(); |
| 2302 |
send_account_players(ns); |
| 2303 |
} |
| 2304 |
|
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
|
| 2313 |
|
| 2314 |
|
| 2315 |
|
| 2316 |
|
| 2317 |
|
| 2318 |
void account_add_player_cmd(char *buf, int len, socket_struct *ns) { |
| 2319 |
char name[MAX_BUF], password[MAX_BUF]; |
| 2320 |
int status, force, nlen; |
| 2321 |
SockList sl; |
| 2322 |
const char *cp; |
| 2323 |
|
| 2324 |
if (len <= 0 || !buf) { |
| 2325 |
LOG(llevDebug, "IP '%s' sent bogus add_player_cmd information\n", ns->host); |
| 2326 |
return; |
| 2327 |
} |
| 2328 |
|
| 2329 |
SockList_Init(&sl); |
| 2330 |
|
| 2331 |
if (ns->account_name == NULL) { |
| 2332 |
SockList_AddString(&sl, "failure accountaddplayer Not logged in"); |
| 2333 |
Send_With_Handling(ns, &sl); |
| 2334 |
SockList_Term(&sl); |
| 2335 |
return; |
| 2336 |
} |
| 2337 |
|
| 2338 |
force = buf[0]; |
| 2339 |
nlen = len - 1; |
| 2340 |
status = decode_name_password(buf+1, &nlen, name, password); |
| 2341 |
if (status == 1) { |
| 2342 |
SockList_AddString(&sl, "failure accountaddplayer Name is too long"); |
| 2343 |
Send_With_Handling(ns, &sl); |
| 2344 |
SockList_Term(&sl); |
| 2345 |
return; |
| 2346 |
} |
| 2347 |
if (status == 2) { |
| 2348 |
SockList_AddString(&sl, "failure accountaddplayer Password is too long"); |
| 2349 |
Send_With_Handling(ns, &sl); |
| 2350 |
SockList_Term(&sl); |
| 2351 |
return; |
| 2352 |
} |
| 2353 |
|
| 2354 |
status = verify_player(name, password); |
| 2355 |
if (status) { |
| 2356 |
|
| 2357 |
|
| 2358 |
|
| 2359 |
|
| 2360 |
|
| 2361 |
|
| 2362 |
|
| 2363 |
if (status == 1) |
| 2364 |
SockList_AddString(&sl, "failure accountaddplayer 0 The character does not exist."); |
| 2365 |
else |
| 2366 |
SockList_AddString(&sl, "failure accountaddplayer 0 That password is incorrect."); |
| 2367 |
|
| 2368 |
Send_With_Handling(ns, &sl); |
| 2369 |
SockList_Term(&sl); |
| 2370 |
return; |
| 2371 |
} |
| 2372 |
|
| 2373 |
|
| 2374 |
cp = account_get_account_for_char(name); |
| 2375 |
if (cp) { |
| 2376 |
if (!strcmp(cp, ns->account_name)) { |
| 2377 |
SockList_AddString(&sl, "failure accountaddplayer 0 That character is already connected to this account."); |
| 2378 |
Send_With_Handling(ns, &sl); |
| 2379 |
SockList_Term(&sl); |
| 2380 |
return; |
| 2381 |
} else { |
| 2382 |
if (!force) { |
| 2383 |
SockList_AddString(&sl, "failure accountaddplayer 1 That character is already connected to a different account."); |
| 2384 |
Send_With_Handling(ns, &sl); |
| 2385 |
SockList_Term(&sl); |
| 2386 |
return; |
| 2387 |
} else if (account_is_logged_in(cp)) { |
| 2388 |
|
| 2389 |
|
| 2390 |
|
| 2391 |
|
| 2392 |
|
| 2393 |
|
| 2394 |
|
| 2395 |
SockList_AddString(&sl, "failure accountaddplayer 0 That character is already connected to a different account which is currently logged in."); |
| 2396 |
Send_With_Handling(ns, &sl); |
| 2397 |
SockList_Term(&sl); |
| 2398 |
return; |
| 2399 |
} |
| 2400 |
} |
| 2401 |
} |
| 2402 |
|
| 2403 |
|
| 2404 |
|
| 2405 |
|
| 2406 |
status = account_link(ns->account_name, name); |
| 2407 |
|
| 2408 |
|
| 2409 |
|
| 2410 |
|
| 2411 |
|
| 2412 |
if (status==1) { |
| 2413 |
SockList_AddString(&sl, "failure accountaddplayer 0 Could not find your account."); |
| 2414 |
Send_With_Handling(ns, &sl); |
| 2415 |
SockList_Term(&sl); |
| 2416 |
return; |
| 2417 |
} else if (status == 2) { |
| 2418 |
SockList_AddString(&sl, "failure accountaddplayer 0 You have reached the maximum number of characters allowed per account."); |
| 2419 |
Send_With_Handling(ns, &sl); |
| 2420 |
SockList_Term(&sl); |
| 2421 |
return; |
| 2422 |
} |
| 2423 |
|
| 2424 |
|
| 2425 |
|
| 2426 |
|
| 2427 |
if (cp) { |
| 2428 |
Account_Char *chars; |
| 2429 |
|
| 2430 |
account_remove_player(cp, name); |
| 2431 |
chars = account_char_load(cp); |
| 2432 |
chars=account_char_remove(chars, name); |
| 2433 |
account_char_save(cp, chars); |
| 2434 |
account_char_free(chars); |
| 2435 |
} |
| 2436 |
|
| 2437 |
send_account_players(ns); |
| 2438 |
|
| 2439 |
|
| 2440 |
account_char_save(ns->account_name, ns->account_chars); |
| 2441 |
} |
| 2442 |
|
| 2443 |
|
| 2444 |
|
| 2445 |
|
| 2446 |
|
| 2447 |
void account_play_cmd(char *buf, int len, socket_struct *ns) |
| 2448 |
{ |
| 2449 |
char **chars; |
| 2450 |
int i; |
| 2451 |
SockList sl; |
| 2452 |
player *pl; |
| 2453 |
|
| 2454 |
if (len <= 0 || !buf) { |
| 2455 |
LOG(llevDebug, "IP '%s' sent bogus account_play_cmd information\n", ns->host); |
| 2456 |
return; |
| 2457 |
} |
| 2458 |
|
| 2459 |
SockList_Init(&sl); |
| 2460 |
|
| 2461 |
if (ns->status != Ns_Add) { |
| 2462 |
SockList_AddString(&sl, "failure accountplay Not allowed right now"); |
| 2463 |
Send_With_Handling(ns, &sl); |
| 2464 |
SockList_Term(&sl); |
| 2465 |
return; |
| 2466 |
} |
| 2467 |
|
| 2468 |
if (!buf[0]) { |
| 2469 |
SockList_AddString(&sl, "failure accountplay Malformed character name"); |
| 2470 |
Send_With_Handling(ns, &sl); |
| 2471 |
SockList_Term(&sl); |
| 2472 |
return; |
| 2473 |
} |
| 2474 |
|
| 2475 |
if (ns->account_name == NULL) { |
| 2476 |
SockList_AddString(&sl, "failure accountplay Not logged in"); |
| 2477 |
Send_With_Handling(ns, &sl); |
| 2478 |
SockList_Term(&sl); |
| 2479 |
return; |
| 2480 |
} |
| 2481 |
|
| 2482 |
chars = account_get_players_for_account(ns->account_name); |
| 2483 |
|
| 2484 |
for (i=0; i<MAX_CHARACTERS_PER_ACCOUNT; i++) { |
| 2485 |
if (!chars[i] || !strcmp(chars[i], buf)) break; |
| 2486 |
} |
| 2487 |
|
| 2488 |
if (i == MAX_CHARACTERS_PER_ACCOUNT || !chars[i]) { |
| 2489 |
SockList_AddPrintf(&sl, |
| 2490 |
"failure accountplay Character %s is not associated with account %s", |
| 2491 |
buf, ns->account_name); |
| 2492 |
Send_With_Handling(ns, &sl); |
| 2493 |
SockList_Term(&sl); |
| 2494 |
return; |
| 2495 |
} |
| 2496 |
|
| 2497 |
|
| 2498 |
|
| 2499 |
|
| 2500 |
|
| 2501 |
|
| 2502 |
|
| 2503 |
for (pl=first_player; pl; pl=pl->next) { |
| 2504 |
if (&pl->socket == ns) { |
| 2505 |
|
| 2506 |
save_player(pl->ob, 0); |
| 2507 |
break; |
| 2508 |
} |
| 2509 |
} |
| 2510 |
|
| 2511 |
|
| 2512 |
|
| 2513 |
|
| 2514 |
|
| 2515 |
if (!pl) { |
| 2516 |
pl = get_player(NULL); |
| 2517 |
ns->status = Ns_Avail; |
| 2518 |
memcpy(&pl->socket, ns, sizeof(socket_struct)); |
| 2519 |
ns->faces_sent = NULL; |
| 2520 |
SockList_ResetRead(&pl->socket.inbuf); |
| 2521 |
} else { |
| 2522 |
pl->state = ST_PLAYING; |
| 2523 |
} |
| 2524 |
|
| 2525 |
pl->ob->name = add_string(buf); |
| 2526 |
check_login(pl->ob, 0); |
| 2527 |
|
| 2528 |
SockList_AddString(&sl, "addme_success"); |
| 2529 |
Send_With_Handling(ns, &sl); |
| 2530 |
SockList_Term(&sl); |
| 2531 |
} |
| 2532 |
|
| 2533 |
#define MAX_CHOICES 100 |
| 2534 |
|
| 2535 |
|
| 2536 |
|
| 2537 |
|
| 2538 |
|
| 2539 |
|
| 2540 |
void create_player_cmd(char *buf, int len, socket_struct *ns) |
| 2541 |
{ |
| 2542 |
char name[MAX_BUF], password[MAX_BUF], *choices[MAX_CHOICES]; |
| 2543 |
int status, nlen, choice_num=0, i; |
| 2544 |
SockList sl; |
| 2545 |
player *pl; |
| 2546 |
archetype *map=NULL, *race_a=NULL, *class_a=NULL; |
| 2547 |
living new_stats; |
| 2548 |
|
| 2549 |
if (len <= 0 || !buf) { |
| 2550 |
LOG(llevDebug, "IP '%s' sent bogus create_player_cmd information\n", ns->host); |
| 2551 |
return; |
| 2552 |
} |
| 2553 |
|
| 2554 |
SockList_Init(&sl); |
| 2555 |
|
| 2556 |
if (ns->status != Ns_Add) { |
| 2557 |
SockList_AddString(&sl, "failure createplayer Not allowed right now"); |
| 2558 |
Send_With_Handling(ns, &sl); |
| 2559 |
SockList_Term(&sl); |
| 2560 |
return; |
| 2561 |
} |
| 2562 |
|
| 2563 |
nlen = len; |
| 2564 |
status = decode_name_password(buf, &nlen, name, password); |
| 2565 |
if (status == 1) { |
| 2566 |
SockList_AddString(&sl, "failure createplayer Name is too long"); |
| 2567 |
Send_With_Handling(ns, &sl); |
| 2568 |
SockList_Term(&sl); |
| 2569 |
return; |
| 2570 |
} |
| 2571 |
|
| 2572 |
|
| 2573 |
if (strlen(name)<settings.min_name) { |
| 2574 |
SockList_AddString(&sl, "failure createplayer Name is too short"); |
| 2575 |
Send_With_Handling(ns, &sl); |
| 2576 |
SockList_Term(&sl); |
| 2577 |
return; |
| 2578 |
} |
| 2579 |
|
| 2580 |
|
| 2581 |
if (strlen(password)<2) { |
| 2582 |
SockList_AddString(&sl, "failure createplayer Password is too short"); |
| 2583 |
Send_With_Handling(ns, &sl); |
| 2584 |
SockList_Term(&sl); |
| 2585 |
return; |
| 2586 |
} |
| 2587 |
|
| 2588 |
|
| 2589 |
if (status == 2) { |
| 2590 |
SockList_AddString(&sl, "failure createplayer Password is too long"); |
| 2591 |
Send_With_Handling(ns, &sl); |
| 2592 |
SockList_Term(&sl); |
| 2593 |
return; |
| 2594 |
} |
| 2595 |
|
| 2596 |
|
| 2597 |
|
| 2598 |
|
| 2599 |
|
| 2600 |
|
| 2601 |
|
| 2602 |
|
| 2603 |
|
| 2604 |
if (strlen(password)>17) |
| 2605 |
password[16] = 0; |
| 2606 |
|
| 2607 |
|
| 2608 |
|
| 2609 |
|
| 2610 |
|
| 2611 |
|
| 2612 |
if (account_check_string(name)) { |
| 2613 |
SockList_AddString(&sl, "failure createplayer The name contains illegal characters"); |
| 2614 |
Send_With_Handling(ns, &sl); |
| 2615 |
SockList_Term(&sl); |
| 2616 |
return; |
| 2617 |
} |
| 2618 |
|
| 2619 |
|
| 2620 |
|
| 2621 |
|
| 2622 |
|
| 2623 |
if (verify_player(name, password) != 1) { |
| 2624 |
SockList_AddString(&sl, "failure createplayer That name is already in use"); |
| 2625 |
Send_With_Handling(ns, &sl); |
| 2626 |
SockList_Term(&sl); |
| 2627 |
return; |
| 2628 |
} |
| 2629 |
|
| 2630 |
|
| 2631 |
|
| 2632 |
|
| 2633 |
|
| 2634 |
|
| 2635 |
|
| 2636 |
for (pl=first_player; pl; pl=pl->next) |
| 2637 |
if (&pl->socket == ns) { |
| 2638 |
if (pl->ob->name) { |
| 2639 |
if (!strcmp(pl->ob->name, name)) { |
| 2640 |
|
| 2641 |
|
| 2642 |
|
| 2643 |
|
| 2644 |
|
| 2645 |
|
| 2646 |
if (!QUERY_FLAG(pl->ob, FLAG_REMOVED)) |
| 2647 |
object_remove(pl->ob); |
| 2648 |
} |
| 2649 |
else { |
| 2650 |
|
| 2651 |
|
| 2652 |
|
| 2653 |
|
| 2654 |
|
| 2655 |
|
| 2656 |
|
| 2657 |
if (pl->ob->contr == pl) { |
| 2658 |
if (!QUERY_FLAG(pl->ob, FLAG_REMOVED)) |
| 2659 |
object_remove(pl->ob); |
| 2660 |
} |
| 2661 |
} |
| 2662 |
} |
| 2663 |
break; |
| 2664 |
} |
| 2665 |
|
| 2666 |
|
| 2667 |
|
| 2668 |
|
| 2669 |
|
| 2670 |
|
| 2671 |
|
| 2672 |
|
| 2673 |
|
| 2674 |
if (ns->login_method >= 2) { |
| 2675 |
int i, j, stat_total=0; |
| 2676 |
char *key, *value, *race=NULL, *class=NULL; |
| 2677 |
|
| 2678 |
|
| 2679 |
|
| 2680 |
|
| 2681 |
memset(&new_stats, 0, sizeof(living)); |
| 2682 |
|
| 2683 |
while (nlen < len) { |
| 2684 |
i = buf[nlen]; |
| 2685 |
|
| 2686 |
|
| 2687 |
|
| 2688 |
|
| 2689 |
|
| 2690 |
|
| 2691 |
|
| 2692 |
if ((i == 0) || (nlen + i > len)) break; |
| 2693 |
buf[nlen + i] = 0; |
| 2694 |
|
| 2695 |
|
| 2696 |
|
| 2697 |
|
| 2698 |
|
| 2699 |
|
| 2700 |
key = buf + nlen + 1; |
| 2701 |
value = strchr(key, ' '); |
| 2702 |
if (!value) break; |
| 2703 |
*value = 0; |
| 2704 |
value++; |
| 2705 |
|
| 2706 |
if (!strcasecmp(key,"race")) race = value; |
| 2707 |
else if (!strcasecmp(key,"class")) class = value; |
| 2708 |
else if (!strcasecmp(key,"starting_map")) { |
| 2709 |
map = try_find_archetype(value); |
| 2710 |
if (!map || map->clone.type != MAP || map->clone.subtype !=MAP_TYPE_CHOICE) { |
| 2711 |
SockList_AddString(&sl, |
| 2712 |
"failure createplayer Invalid or map"); |
| 2713 |
Send_With_Handling(ns, &sl); |
| 2714 |
SockList_Term(&sl); |
| 2715 |
return; |
| 2716 |
} |
| 2717 |
} |
| 2718 |
else if (!strcasecmp(key,"choice")) { |
| 2719 |
|
| 2720 |
|
| 2721 |
|
| 2722 |
|
| 2723 |
|
| 2724 |
if (choice_num == MAX_CHOICES) { |
| 2725 |
LOG(llevError, |
| 2726 |
"Number of choices receive exceed max value: %d>%d\n", |
| 2727 |
choice_num, MAX_CHOICES); |
| 2728 |
} else { |
| 2729 |
choices[choice_num] = value; |
| 2730 |
choice_num++; |
| 2731 |
} |
| 2732 |
} |
| 2733 |
else { |
| 2734 |
|
| 2735 |
for (j=0; j < NUM_STATS; j++) { |
| 2736 |
if (!strcasecmp(key,short_stat_name[j])) { |
| 2737 |
int val = atoi(value); |
| 2738 |
|
| 2739 |
set_attr_value(&new_stats, j, val); |
| 2740 |
break; |
| 2741 |
} |
| 2742 |
} |
| 2743 |
if (j >= NUM_STATS) { |
| 2744 |
|
| 2745 |
|
| 2746 |
|
| 2747 |
LOG(llevError, "Got unknown key/value from client: %s %s\n", key, value); |
| 2748 |
} |
| 2749 |
} |
| 2750 |
nlen += i + 1; |
| 2751 |
} |
| 2752 |
|
| 2753 |
|
| 2754 |
|
| 2755 |
|
| 2756 |
|
| 2757 |
|
| 2758 |
for (j=0; j<NUM_STATS; j++) { |
| 2759 |
int val = get_attr_value(&new_stats, j); |
| 2760 |
|
| 2761 |
stat_total += val; |
| 2762 |
if (val > settings.starting_stat_max || |
| 2763 |
val < settings.starting_stat_min) { |
| 2764 |
SockList_AddPrintf(&sl, |
| 2765 |
"failure createplayer Stat value is out of range - %d must be between %d and %d", |
| 2766 |
val, settings.starting_stat_min, settings.starting_stat_max); |
| 2767 |
Send_With_Handling(ns, &sl); |
| 2768 |
SockList_Term(&sl); |
| 2769 |
return; |
| 2770 |
} |
| 2771 |
} |
| 2772 |
if (stat_total > settings.starting_stat_points) { |
| 2773 |
SockList_AddPrintf(&sl, |
| 2774 |
"failure createplayer Total allocated statistics is higher than allowed (%d>%d)", |
| 2775 |
stat_total, settings.starting_stat_points); |
| 2776 |
Send_With_Handling(ns, &sl); |
| 2777 |
SockList_Term(&sl); |
| 2778 |
return; |
| 2779 |
} |
| 2780 |
|
| 2781 |
if (race) |
| 2782 |
race_a = try_find_archetype(race); |
| 2783 |
|
| 2784 |
if (class) |
| 2785 |
class_a = try_find_archetype(class); |
| 2786 |
|
| 2787 |
|
| 2788 |
|
| 2789 |
|
| 2790 |
if (!race_a || race_a->clone.type != PLAYER || !class_a || class_a->clone.type != CLASS) { |
| 2791 |
SockList_AddString(&sl, |
| 2792 |
"failure createplayer Invalid or unknown race or class"); |
| 2793 |
Send_With_Handling(ns, &sl); |
| 2794 |
SockList_Term(&sl); |
| 2795 |
return; |
| 2796 |
} |
| 2797 |
|
| 2798 |
|
| 2799 |
|
| 2800 |
|
| 2801 |
if (check_race_and_class(&new_stats, race_a, class_a)) { |
| 2802 |
SockList_AddString(&sl, |
| 2803 |
"failure createplayer Unable to apply race or class - statistic is out of bounds"); |
| 2804 |
Send_With_Handling(ns, &sl); |
| 2805 |
SockList_Term(&sl); |
| 2806 |
return; |
| 2807 |
} |
| 2808 |
|
| 2809 |
if (!pl) |
| 2810 |
pl = add_player(ns, ADD_PLAYER_NEW | ADD_PLAYER_NO_MAP | ADD_PLAYER_NO_STATS_ROLL); |
| 2811 |
|
| 2812 |
|
| 2813 |
else |
| 2814 |
ns->status = Ns_Avail; |
| 2815 |
|
| 2816 |
apply_race_and_class(pl->ob, race_a, class_a, &new_stats); |
| 2817 |
|
| 2818 |
} else { |
| 2819 |
|
| 2820 |
if (!pl) |
| 2821 |
pl = add_player(ns, ADD_PLAYER_NEW); |
| 2822 |
|
| 2823 |
|
| 2824 |
else |
| 2825 |
ns->status = Ns_Avail; |
| 2826 |
|
| 2827 |
|
| 2828 |
|
| 2829 |
|
| 2830 |
} |
| 2831 |
|
| 2832 |
|
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
|
| 2837 |
|
| 2838 |
|
| 2839 |
|
| 2840 |
FREE_AND_COPY(pl->ob->name, name); |
| 2841 |
FREE_AND_COPY(pl->ob->name_pl, name); |
| 2842 |
pl->name_changed = 1; |
| 2843 |
safe_strncpy(pl->password, newhash(password), sizeof(pl->password)); |
| 2844 |
|
| 2845 |
SockList_AddString(&sl, "addme_success"); |
| 2846 |
Send_With_Handling(ns, &sl); |
| 2847 |
SockList_Term(&sl); |
| 2848 |
|
| 2849 |
if (ns->login_method >= 2) { |
| 2850 |
|
| 2851 |
|
| 2852 |
|
| 2853 |
if (!map) |
| 2854 |
map = get_archetype_by_type_subtype(MAP, MAP_TYPE_DEFAULT); |
| 2855 |
|
| 2856 |
if (!map) { |
| 2857 |
|
| 2858 |
|
| 2859 |
|
| 2860 |
|
| 2861 |
LOG(llevError, "Can not find object of type MAP subtype MAP_TYPE_DEFAULT.\n"); |
| 2862 |
LOG(llevError, "Are the archetype files up to date? Can not continue.\n"); |
| 2863 |
abort(); |
| 2864 |
} |
| 2865 |
|
| 2866 |
enter_exit(pl->ob, &map->clone); |
| 2867 |
|
| 2868 |
if (pl->ob->map == NULL) { |
| 2869 |
LOG(llevError, "Couldn't put player %s on start map %s!", pl->ob->name, map->name); |
| 2870 |
abort(); |
| 2871 |
} |
| 2872 |
|
| 2873 |
|
| 2874 |
safe_strncpy(pl->savebed_map, pl->ob->map->path, sizeof(pl->savebed_map)); |
| 2875 |
pl->bed_x = pl->ob->x; |
| 2876 |
pl->bed_y = pl->ob->y; |
| 2877 |
|
| 2878 |
player_set_state(pl, ST_PLAYING); |
| 2879 |
} |
| 2880 |
|
| 2881 |
|
| 2882 |
|
| 2883 |
|
| 2884 |
|
| 2885 |
|
| 2886 |
|
| 2887 |
|
| 2888 |
for (i=0; i < choice_num; i++) { |
| 2889 |
char *choiceval, *cp; |
| 2890 |
const char *value; |
| 2891 |
archetype *arch; |
| 2892 |
object *op; |
| 2893 |
|
| 2894 |
choiceval = strchr(choices[i], ' '); |
| 2895 |
if (!choiceval) { |
| 2896 |
LOG(llevError, "Choice does not specify value: %s\n", choices[i]); |
| 2897 |
continue; |
| 2898 |
} |
| 2899 |
*choiceval=0; |
| 2900 |
choiceval++; |
| 2901 |
value = object_get_value(&race_a->clone, choices[i]); |
| 2902 |
if (!value) |
| 2903 |
value = object_get_value(&class_a->clone, choices[i]); |
| 2904 |
|
| 2905 |
if (!value) { |
| 2906 |
LOG(llevError, "Choice not found in archetype: %s\n", choices[i]); |
| 2907 |
continue; |
| 2908 |
} |
| 2909 |
cp = strstr(value, choiceval); |
| 2910 |
if (!cp) { |
| 2911 |
LOG(llevError, "Choice value not found in archetype: %s %s\n", |
| 2912 |
choices[i], choiceval); |
| 2913 |
continue; |
| 2914 |
} |
| 2915 |
|
| 2916 |
|
| 2917 |
|
| 2918 |
|
| 2919 |
|
| 2920 |
|
| 2921 |
|
| 2922 |
if ((cp[strlen(choiceval)] != ' ') && (cp[strlen(choiceval)] != 0) && |
| 2923 |
(cp != value) && (*(cp-1) != ' ')) { |
| 2924 |
|
| 2925 |
LOG(llevError, "Choice value matches substring but not entire word: %s substring %s\n", |
| 2926 |
choiceval, value); |
| 2927 |
continue; |
| 2928 |
} |
| 2929 |
arch = try_find_archetype(choiceval); |
| 2930 |
if (!arch) { |
| 2931 |
LOG(llevError, "Choice value can not find archetype %s\n", choiceval); |
| 2932 |
continue; |
| 2933 |
} |
| 2934 |
op = arch_to_object(arch); |
| 2935 |
op = object_insert_in_ob(op, pl->ob); |
| 2936 |
if (QUERY_FLAG(op, FLAG_AUTO_APPLY)) |
| 2937 |
ob_apply(op, pl->ob, 0); |
| 2938 |
} |
| 2939 |
|
| 2940 |
LOG(llevInfo, "new character %s from %s\n", pl->ob->name, pl->ob->contr->socket.host); |
| 2941 |
draw_ext_info_format(NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, |
| 2942 |
MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_PLAYER, |
| 2943 |
"%s has entered the game.", pl->ob->name); |
| 2944 |
} |
| 2945 |
|
| 2946 |
|
| 2947 |
|
| 2948 |
|
| 2949 |
|
| 2950 |
|
| 2951 |
|
| 2952 |
|
| 2953 |
|
| 2954 |
|
| 2955 |
|
| 2956 |
void account_password(char *buf, int len, socket_struct *ns) { |
| 2957 |
char old[MAX_BUF], change[MAX_BUF]; |
| 2958 |
int status; |
| 2959 |
SockList sl; |
| 2960 |
|
| 2961 |
if (len <= 0 || !buf) { |
| 2962 |
LOG(llevDebug, "IP '%s' sent bogus account_password_cmd information\n", ns->host); |
| 2963 |
return; |
| 2964 |
} |
| 2965 |
|
| 2966 |
SockList_Init(&sl); |
| 2967 |
|
| 2968 |
if (ns->account_name == NULL) { |
| 2969 |
SockList_AddString(&sl, "failure accountpw Not logged in"); |
| 2970 |
Send_With_Handling(ns, &sl); |
| 2971 |
SockList_Term(&sl); |
| 2972 |
return; |
| 2973 |
} |
| 2974 |
|
| 2975 |
status = decode_name_password(buf, &len, old, change); |
| 2976 |
if (status == 1) { |
| 2977 |
SockList_AddString(&sl, "failure accountpw Old password is too long"); |
| 2978 |
Send_With_Handling(ns, &sl); |
| 2979 |
SockList_Term(&sl); |
| 2980 |
return; |
| 2981 |
} |
| 2982 |
if (status == 2) { |
| 2983 |
SockList_AddString(&sl, "failure accountpw New password is too long"); |
| 2984 |
Send_With_Handling(ns, &sl); |
| 2985 |
SockList_Term(&sl); |
| 2986 |
return; |
| 2987 |
} |
| 2988 |
|
| 2989 |
|
| 2990 |
|
| 2991 |
|
| 2992 |
if (strlen(change)<2) { |
| 2993 |
SockList_AddString(&sl, "failure accountpw New password is too short"); |
| 2994 |
Send_With_Handling(ns, &sl); |
| 2995 |
SockList_Term(&sl); |
| 2996 |
return; |
| 2997 |
} |
| 2998 |
|
| 2999 |
status = account_check_string(change); |
| 3000 |
if (status == 1) { |
| 3001 |
SockList_AddString(&sl, |
| 3002 |
"failure accountpw That password contains invalid characters."); |
| 3003 |
Send_With_Handling(ns, &sl); |
| 3004 |
SockList_Term(&sl); |
| 3005 |
return; |
| 3006 |
} |
| 3007 |
|
| 3008 |
if (status == 2) { |
| 3009 |
SockList_AddString(&sl, |
| 3010 |
"failure accountpw That password is too long"); |
| 3011 |
Send_With_Handling(ns, &sl); |
| 3012 |
SockList_Term(&sl); |
| 3013 |
return; |
| 3014 |
} |
| 3015 |
|
| 3016 |
status = account_change_password(ns->account_name, old, change); |
| 3017 |
if (status != 0) { |
| 3018 |
const char *error; |
| 3019 |
|
| 3020 |
if (status == 1) { |
| 3021 |
error = "failure accountpw Illegal characters present"; |
| 3022 |
} else if (status == 2) { |
| 3023 |
error = "failure accountpw Invalid account"; |
| 3024 |
} else { |
| 3025 |
error = "failure accountpw Incorrect current password"; |
| 3026 |
} |
| 3027 |
|
| 3028 |
SockList_AddString(&sl, error); |
| 3029 |
Send_With_Handling(ns, &sl); |
| 3030 |
SockList_Term(&sl); |
| 3031 |
return; |
| 3032 |
} |
| 3033 |
|
| 3034 |
|
| 3035 |
send_account_players(ns); |
| 3036 |
} |