| 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 |
#include "global.h" |
| 27 |
|
| 28 |
#include <assert.h> |
| 29 |
#include <fcntl.h> |
| 30 |
#include <stdlib.h> |
| 31 |
#include <string.h> |
| 32 |
#include <sys/time.h> |
| 33 |
#include <unistd.h> |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
#ifndef WIN32 |
| 39 |
#include <sys/types.h> |
| 40 |
#include <sys/time.h> |
| 41 |
#include <netinet/in.h> |
| 42 |
#include <netinet/tcp.h> |
| 43 |
#include <netdb.h> |
| 44 |
#endif |
| 45 |
|
| 46 |
#include "commands.h" |
| 47 |
#include "living.h" |
| 48 |
#include "newserver.h" |
| 49 |
#include "shared/newclient.h" |
| 50 |
#include "sounds.h" |
| 51 |
#include "sproto.h" |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
void send_skill_info(socket_struct *ns, char *params) { |
| 68 |
SockList sl; |
| 69 |
int i; |
| 70 |
|
| 71 |
SockList_Init(&sl); |
| 72 |
SockList_AddString(&sl, "replyinfo skill_info\n"); |
| 73 |
for (i = 0; i < MAX_SKILLS && skill_names[i]; i++) { |
| 74 |
size_t len; |
| 75 |
|
| 76 |
len = 16+strlen(skill_names[i]); |
| 77 |
if (SockList_Avail(&sl) < len) { |
| 78 |
LOG(llevError, "Buffer overflow in send_skill_info, not sending all skill information\n"); |
| 79 |
break; |
| 80 |
} |
| 81 |
|
| 82 |
if (params != NULL && *params == '1') { |
| 83 |
if ((skill_faces[i] != NULL) && !(ns->faces_sent[skill_faces[i]->number]&NS_FACESENT_FACE)) |
| 84 |
esrv_send_face(ns, skill_faces[i], 0); |
| 85 |
SockList_AddPrintf(&sl, "%d:%s:%d\n", i+CS_STAT_SKILLINFO, skill_names[i], skill_faces[i] ? skill_faces[i]->number : 0); |
| 86 |
} else |
| 87 |
SockList_AddPrintf(&sl, "%d:%s\n", i+CS_STAT_SKILLINFO, skill_names[i]); |
| 88 |
} |
| 89 |
Send_With_Handling(ns, &sl); |
| 90 |
SockList_Term(&sl); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
void send_spell_paths(socket_struct *ns, char *params) { |
| 98 |
SockList sl; |
| 99 |
int i; |
| 100 |
|
| 101 |
SockList_Init(&sl); |
| 102 |
SockList_AddString(&sl, "replyinfo spell_paths\n"); |
| 103 |
for (i = 0; i < NRSPELLPATHS; i++) { |
| 104 |
size_t len; |
| 105 |
|
| 106 |
len = 16+strlen(spellpathnames[i]); |
| 107 |
if (SockList_Avail(&sl) < len) { |
| 108 |
LOG(llevError, "Buffer overflow in send_spell_paths, not sending all spell information\n"); |
| 109 |
break; |
| 110 |
} |
| 111 |
|
| 112 |
SockList_AddPrintf(&sl, "%d:%s\n", 1<<i, spellpathnames[i]); |
| 113 |
} |
| 114 |
Send_With_Handling(ns, &sl); |
| 115 |
SockList_Term(&sl); |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
void send_exp_table(socket_struct *ns, char *params) { |
| 122 |
SockList sl; |
| 123 |
int i; |
| 124 |
extern int64_t *levels; |
| 125 |
|
| 126 |
SockList_Init(&sl); |
| 127 |
SockList_AddString(&sl, "replyinfo exp_table\n"); |
| 128 |
SockList_AddShort(&sl, settings.max_level+1); |
| 129 |
for (i = 1; i <= settings.max_level; i++) { |
| 130 |
if (SockList_Avail(&sl) < 8) { |
| 131 |
LOG(llevError, "Buffer overflow in send_exp_table, not sending all information\n"); |
| 132 |
break; |
| 133 |
} |
| 134 |
SockList_AddInt64(&sl, levels[i]); |
| 135 |
} |
| 136 |
Send_With_Handling(ns, &sl); |
| 137 |
SockList_Term(&sl); |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
#define AddShortAttr(New, Type) \ |
| 145 |
if (New) { \ |
| 146 |
SockList_AddChar(sl, Type); \ |
| 147 |
SockList_AddShort(sl, New); \ |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
static void send_arch_info(SockList *sl, const object *op) |
| 161 |
{ |
| 162 |
if (op->name) { |
| 163 |
SockList_AddString(sl, "name "); |
| 164 |
SockList_AddLen8Data(sl, op->name, strlen(op->name)); |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
if (op->msg) { |
| 169 |
SockList_AddString(sl, "msg "); |
| 170 |
SockList_AddShort(sl, strlen(op->msg)); |
| 171 |
SockList_AddData(sl, op->msg, strlen(op->msg)); |
| 172 |
} |
| 173 |
|
| 174 |
SockList_AddString(sl, "stats "); |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
AddShortAttr(op->stats.Str, CS_STAT_STR); |
| 182 |
AddShortAttr(op->stats.Int, CS_STAT_INT); |
| 183 |
AddShortAttr(op->stats.Pow, CS_STAT_POW); |
| 184 |
AddShortAttr(op->stats.Wis, CS_STAT_WIS); |
| 185 |
AddShortAttr(op->stats.Dex, CS_STAT_DEX); |
| 186 |
AddShortAttr(op->stats.Con, CS_STAT_CON); |
| 187 |
AddShortAttr(op->stats.Cha, CS_STAT_CHA); |
| 188 |
|
| 189 |
|
| 190 |
SockList_AddChar(sl, 0); |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
if (op->type == CLASS || op->type == PLAYER) { |
| 197 |
int i=1; |
| 198 |
char buf[MAX_BUF]; |
| 199 |
const char *value, *value1; |
| 200 |
char *lasts, *mychoices, *token; |
| 201 |
|
| 202 |
while (1) { |
| 203 |
if (op->type == PLAYER) { |
| 204 |
snprintf(buf, MAX_BUF, "race_choice_description_%d", i); |
| 205 |
value = object_get_value(op, buf); |
| 206 |
snprintf(buf, MAX_BUF, "race_choice_%d", i); |
| 207 |
value1 = object_get_value(op, buf); |
| 208 |
} else { |
| 209 |
snprintf(buf, MAX_BUF, "class_choice_description_%d", i); |
| 210 |
value = object_get_value(op, buf); |
| 211 |
snprintf(buf, MAX_BUF, "class_choice_%d", i); |
| 212 |
value1 = object_get_value(op, buf); |
| 213 |
} |
| 214 |
|
| 215 |
if (value && value1) { |
| 216 |
SockList_AddString(sl, "choice "); |
| 217 |
SockList_AddLen8Data(sl, buf, strlen(buf)); |
| 218 |
SockList_AddLen8Data(sl, value, strlen(value)); |
| 219 |
i++; |
| 220 |
|
| 221 |
|
| 222 |
mychoices = strdup_local(value1); |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
token = strtok_r(mychoices, " ", &lasts); |
| 231 |
while (token) { |
| 232 |
archetype *arch; |
| 233 |
|
| 234 |
arch = try_find_archetype(token); |
| 235 |
if (arch) { |
| 236 |
SockList_AddLen8Data(sl, token, strlen(token)); |
| 237 |
SockList_AddLen8Data(sl, arch->clone.name, |
| 238 |
strlen(arch->clone.name)); |
| 239 |
} else { |
| 240 |
LOG(llevError, "send_arch_info: Unable to find archetype %s\n", token); |
| 241 |
} |
| 242 |
token = strtok_r(NULL, " ", &lasts); |
| 243 |
} |
| 244 |
free(mychoices); |
| 245 |
|
| 246 |
SockList_AddChar(sl, 0); |
| 247 |
} else { |
| 248 |
break; |
| 249 |
} |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
static void build_race_list_reply(SockList *sl) { |
| 272 |
archetype *race; |
| 273 |
|
| 274 |
SockList_AddString(sl, "replyinfo race_list "); |
| 275 |
|
| 276 |
for (race = first_archetype; race; race = race->next) { |
| 277 |
if (race->clone.type == PLAYER) { |
| 278 |
SockList_AddPrintf(sl, "|%s", race->name); |
| 279 |
} |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
void send_race_list(socket_struct *ns, char *params) { |
| 293 |
static SockList sl; |
| 294 |
static int sl_initialized = 0; |
| 295 |
|
| 296 |
if (!sl_initialized) { |
| 297 |
sl_initialized = 1; |
| 298 |
SockList_Init(&sl); |
| 299 |
build_race_list_reply(&sl); |
| 300 |
} |
| 301 |
|
| 302 |
Send_With_Handling(ns, &sl); |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
void send_race_info(socket_struct *ns, char *params) { |
| 314 |
archetype *race = try_find_archetype(params); |
| 315 |
SockList sl; |
| 316 |
|
| 317 |
SockList_Init(&sl); |
| 318 |
SockList_AddPrintf(&sl, "replyinfo race_info %s\n", params); |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
if (race && race->clone.type == PLAYER) { |
| 324 |
send_arch_info(&sl, &race->clone); |
| 325 |
} |
| 326 |
|
| 327 |
Send_With_Handling(ns, &sl); |
| 328 |
SockList_Term(&sl); |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
static void build_class_list_reply(SockList *sl) { |
| 338 |
archetype *cl; |
| 339 |
|
| 340 |
SockList_Reset(sl); |
| 341 |
SockList_AddString(sl, "replyinfo class_list "); |
| 342 |
|
| 343 |
for (cl = first_archetype; cl; cl = cl->next) { |
| 344 |
if (cl->clone.type == CLASS) { |
| 345 |
SockList_AddPrintf(sl, "|%s", cl->name); |
| 346 |
} |
| 347 |
} |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
void send_class_list(socket_struct *ns, char *params) { |
| 360 |
static SockList sl; |
| 361 |
static int sl_initialized = 0; |
| 362 |
|
| 363 |
if (!sl_initialized) { |
| 364 |
sl_initialized = 1; |
| 365 |
SockList_Init(&sl); |
| 366 |
build_class_list_reply(&sl); |
| 367 |
} |
| 368 |
|
| 369 |
Send_With_Handling(ns, &sl); |
| 370 |
} |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
void send_class_info(socket_struct *ns, char *params) { |
| 381 |
archetype *class = try_find_archetype(params); |
| 382 |
SockList sl; |
| 383 |
|
| 384 |
SockList_Init(&sl); |
| 385 |
SockList_AddPrintf(&sl, "replyinfo class_info %s\n", params); |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
if (class && class->clone.type == CLASS) { |
| 391 |
send_arch_info(&sl, &class->clone); |
| 392 |
} |
| 393 |
|
| 394 |
Send_With_Handling(ns, &sl); |
| 395 |
SockList_Term(&sl); |
| 396 |
} |
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
void send_map_info(socket_struct *ns) { |
| 405 |
archetype *m; |
| 406 |
SockList sl; |
| 407 |
|
| 408 |
SockList_Init(&sl); |
| 409 |
SockList_AddPrintf(&sl, "replyinfo startingmap\n"); |
| 410 |
|
| 411 |
for (m = first_archetype; m; m = m->next) { |
| 412 |
if (m->clone.type == MAP && m->clone.subtype == MAP_TYPE_CHOICE) { |
| 413 |
SockList_AddChar(&sl, INFO_MAP_ARCH_NAME); |
| 414 |
SockList_AddLen16Data(&sl, m->name, strlen(m->name)); |
| 415 |
|
| 416 |
SockList_AddChar(&sl, INFO_MAP_NAME); |
| 417 |
SockList_AddLen16Data(&sl, m->clone.name, strlen(m->clone.name)); |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
if (m->clone.msg) { |
| 423 |
SockList_AddChar(&sl, INFO_MAP_DESCRIPTION); |
| 424 |
SockList_AddLen16Data(&sl, m->clone.msg, strlen(m->clone.msg)); |
| 425 |
} |
| 426 |
} |
| 427 |
} |
| 428 |
|
| 429 |
Send_With_Handling(ns, &sl); |
| 430 |
SockList_Term(&sl); |
| 431 |
} |
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
void send_file(socket_struct *ns, const char *file) { |
| 444 |
char buf[MAX_BUF]; |
| 445 |
FILE *fp; |
| 446 |
SockList sl; |
| 447 |
|
| 448 |
if (!strcmp(file,"motd")) |
| 449 |
snprintf(buf, sizeof(buf), "%s/%s", settings.confdir, settings.motd); |
| 450 |
else if (!strcmp(file,"rules")) |
| 451 |
snprintf(buf, sizeof(buf), "%s/%s", settings.confdir, settings.rules); |
| 452 |
else if (!strcmp(file,"news")) |
| 453 |
snprintf(buf, sizeof(buf), "%s/%s", settings.confdir, settings.news); |
| 454 |
else { |
| 455 |
LOG(llevError,"send_file requested to send unknown file: %s\n", file); |
| 456 |
return; |
| 457 |
} |
| 458 |
fp = fopen(buf, "r"); |
| 459 |
if (fp == NULL) |
| 460 |
return; |
| 461 |
SockList_Init(&sl); |
| 462 |
SockList_AddString(&sl, "replyinfo "); |
| 463 |
SockList_AddString(&sl, file); |
| 464 |
SockList_AddString(&sl, "\n"); |
| 465 |
|
| 466 |
while (fgets(buf, MAX_BUF, fp) != NULL) { |
| 467 |
if (*buf == '#') |
| 468 |
continue; |
| 469 |
SockList_AddString(&sl, buf); |
| 470 |
} |
| 471 |
fclose(fp); |
| 472 |
SockList_AddChar(&sl, 0); |
| 473 |
Send_With_Handling(ns, &sl); |
| 474 |
SockList_Term(&sl); |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
void send_new_char_info(socket_struct *ns) { |
| 485 |
char buf[MAX_BUF]; |
| 486 |
int i; |
| 487 |
size_t len; |
| 488 |
SockList sl; |
| 489 |
|
| 490 |
SockList_Init(&sl); |
| 491 |
|
| 492 |
SockList_AddString(&sl, "replyinfo newcharinfo\n"); |
| 493 |
snprintf(buf, MAX_BUF, "V points %d", settings.starting_stat_points); |
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
SockList_AddLen8Data(&sl, buf, strlen(buf) + 1); |
| 498 |
|
| 499 |
snprintf(buf, MAX_BUF, "V statrange %d %d", |
| 500 |
settings.starting_stat_min, settings.starting_stat_max); |
| 501 |
SockList_AddLen8Data(&sl, buf, strlen(buf) + 1); |
| 502 |
|
| 503 |
snprintf(buf, MAX_BUF, "V statname"); |
| 504 |
len = strlen(buf); |
| 505 |
for (i=0; i<NUM_STATS; i++) { |
| 506 |
safe_strcat(buf, " ", &len, MAX_BUF); |
| 507 |
safe_strcat(buf, short_stat_name[i], &len, MAX_BUF); |
| 508 |
} |
| 509 |
|
| 510 |
SockList_AddLen8Data(&sl, buf, strlen(buf) + 1); |
| 511 |
|
| 512 |
snprintf(buf, MAX_BUF, "R race requestinfo"); |
| 513 |
SockList_AddLen8Data(&sl, buf, strlen(buf) + 1); |
| 514 |
|
| 515 |
snprintf(buf, MAX_BUF, "R class requestinfo"); |
| 516 |
SockList_AddLen8Data(&sl, buf, strlen(buf) + 1); |
| 517 |
|
| 518 |
snprintf(buf, MAX_BUF, "O startingmap requestinfo"); |
| 519 |
SockList_AddLen8Data(&sl, buf, strlen(buf) + 1); |
| 520 |
|
| 521 |
Send_With_Handling(ns, &sl); |
| 522 |
SockList_Term(&sl); |
| 523 |
} |