Crossfire Server, Trunk
request.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
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 /* This block is basically taken from socket.c - I assume if it works there,
51  * it should work here.
52  */
53 #ifndef WIN32 /* ---win32 exclude unix headers */
54 #include <sys/types.h>
55 #include <netinet/in.h>
56 #include <netinet/tcp.h>
57 #include <netdb.h>
58 #else
59 #include <winsock2.h>
60 #endif /* win32 */
61 
62 #include "commands.h"
63 #include "living.h"
64 #include "newserver.h"
65 #include "shared/newclient.h"
66 #include "sounds.h"
67 #include "sproto.h"
68 
75 static const short atnr_cs_stat[NROFATTACKS] = {
80  CS_STAT_RES_DRAIN, -1 /* weaponmagic */,
84  CS_STAT_RES_FEAR, -1 /* Cancellation */,
86  -1 /* Chaos */, -1 /* Counterspell */,
87  -1 /* Godpower */, CS_STAT_RES_HOLYWORD,
89  -1, /* Internal */
90  -1, /* life stealing */
91  -1 /* Disease - not fully done yet */
92 };
93 
95 void set_up_cmd(char *buf, int len, socket_struct *ns) {
96  int s = 0;
97  char *cmd, *param;
98  SockList sl;
99 
100  if (len <= 0 || !buf) {
101  LOG(llevDebug, "IP '%s' sent bogus set_up_cmd information\n", ns->host);
102  return;
103  }
104 
105  /* run through the cmds of setup
106  * syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ...
107  *
108  * we send the status of the cmd back, or a FALSE is the cmd
109  * is the server unknown
110  * The client then must sort this out
111  */
112 
113  LOG(llevDebug, "setup: %s\n", buf);
114  SockList_Init(&sl);
115  SockList_AddString(&sl, "setup");
116  while (s < len) {
117  cmd = &buf[s];
118 
119  /* find the next space, and put a null there */
120  for (; buf[s] && buf[s] != ' '; s++)
121  ;
122  if (s >= len)
123  break;
124  buf[s++] = 0;
125 
126  while (buf[s] == ' ')
127  s++;
128  if (s >= len)
129  break;
130  param = &buf[s];
131 
132  for (; buf[s] && buf[s] != ' '; s++)
133  ;
134  buf[s++] = 0;
135 
136  while (s < len && buf[s] == ' ')
137  s++;
138 
139  SockList_AddPrintf(&sl, " %s ", cmd);
140 
141  if (!strcmp(cmd, "sound2")) {
142  ns->sound = atoi(param)&(SND_EFFECTS|SND_MUSIC|SND_MUTE);
143  SockList_AddString(&sl, param);
144  } else if (!strcmp(cmd, "spellmon")) {
145  int monitor_spells;
146 
147  monitor_spells = atoi(param);
148  if (monitor_spells < 0 || monitor_spells > 2) {
149  SockList_AddString(&sl, "FALSE");
150  } else {
151  ns->monitor_spells = monitor_spells;
152  SockList_AddPrintf(&sl, "%d", monitor_spells);
153  }
154  } else if (!strcmp(cmd, "darkness")) {
155  int darkness;
156 
157  darkness = atoi(param);
158  if (darkness != 0 && darkness != 1) {
159  SockList_AddString(&sl, "FALSE");
160  } else {
161  ns->darkness = darkness;
162  SockList_AddPrintf(&sl, "%d", darkness);
163  }
164  } else if (!strcmp(cmd, "map2cmd")) {
165  int map2cmd;
166 
167  map2cmd = atoi(param);
168  if (map2cmd != 1) {
169  SockList_AddString(&sl, "FALSE");
170  } else {
171  SockList_AddString(&sl, "1");
172  }
173  } else if (!strcmp(cmd, "facecache")) {
174  int facecache;
175 
176  facecache = atoi(param);
177  if (facecache != 0 && facecache != 1) {
178  SockList_AddString(&sl, "FALSE");
179  } else {
180  ns->facecache = facecache;
181  SockList_AddPrintf(&sl, "%d", facecache);
182  }
183  } else if (!strcmp(cmd, "faceset")) {
184  int q = atoi(param);
185 
186  if (is_valid_faceset(q))
187  ns->faceset = q;
188  SockList_AddPrintf(&sl, "%d", ns->faceset);
189  } else if (!strcmp(cmd, "mapsize")) {
190  int x, y, n;
191 
192  if (sscanf(param, "%dx%d%n", &x, &y, &n) != 2 || n != (int)strlen(param)) {
193  x = 0;
194  y = 0;
195  }
196  if (x < 9 || y < 9 || x > MAP_CLIENT_X || y > MAP_CLIENT_Y) {
198  } else {
199  player *pl;
200  ns->mapx = x;
201  ns->mapy = y;
202  /* better to send back what we are really using and not the
203  * param as given to us in case it gets parsed differently.
204  */
205  SockList_AddPrintf(&sl, "%dx%d", x, y);
206  /* need to update the los, else the view jumps */
207  pl = find_player_socket(ns);
208  if (pl)
209  update_los(pl->ob);
210 
211  /* Client and server need to resynchronize on data - treating it as
212  * a new map is best way to go.
213  */
214  map_newmap_cmd(ns);
215  }
216  } else if (!strcmp(cmd, "tick")) {
217  int tick;
218 
219  tick = atoi(param);
220  if (tick != 0 && tick != 1) {
221  SockList_AddString(&sl, "FALSE");
222  } else {
223  ns->tick = tick;
224  SockList_AddPrintf(&sl, "%d", tick);
225  }
226  } else if (!strcmp(cmd, "bot")) {
227  int is_bot;
228 
229  is_bot = atoi(param);
230  if (is_bot != 0 && is_bot != 1) {
231  SockList_AddString(&sl, "FALSE");
232  } else {
233  ns->is_bot = is_bot;
234  SockList_AddPrintf(&sl, "%d", is_bot);
235  }
236  } else if (!strcmp(cmd, "want_pickup")) {
237  int want_pickup;
238 
239  want_pickup = atoi(param);
240  if (want_pickup != 0 && want_pickup != 1) {
241  SockList_AddString(&sl, "FALSE");
242  } else {
243  ns->want_pickup = want_pickup;
244  SockList_AddPrintf(&sl, "%d", want_pickup);
245  }
246  } else if (!strcmp(cmd, "num_look_objects")) {
247  int tmp;
248  player *pl;
249 
250  tmp = atoi(param);
251  if (tmp < MIN_NUM_LOOK_OBJECTS) {
253  } else if (tmp > MAX_NUM_LOOK_OBJECTS) {
255  }
256  ns->num_look_objects = (uint8_t)tmp;
257  SockList_AddPrintf(&sl, "%d", tmp);
258 
259  pl = find_player_socket(ns);
260  if (pl && pl->ob) {
261  ns->update_look = 1;
262  esrv_draw_look(pl->ob);
263  }
264  } else if (!strcmp(cmd, "extended_stats")) {
265  int extended_stats;
266 
267  extended_stats = atoi(param);
268  if (extended_stats != 0 && extended_stats != 1) {
269  SockList_AddString(&sl, "FALSE");
270  } else {
271  ns->extended_stats = extended_stats;
272  SockList_AddPrintf(&sl, "%d", extended_stats);
273  }
274  } else if (!strcmp(cmd, "beat")) {
275  int use_beat = atoi(param);
276 
277  if (use_beat != 0 && use_beat != 1) {
278  SockList_AddString(&sl, "FALSE");
279  } else {
280  ns->heartbeat = use_beat ? true : false;
281 
282  // Send setup command with standard beat interval.
283  SockList_AddPrintf(&sl, "%d", BEAT_INTERVAL);
284  }
285  } else if (!strcmp(cmd, "loginmethod")) {
286  int loginmethod;
287 
288  loginmethod = atoi(param);
289 
290  /* Only support basic login right now */
291  if (loginmethod > 2) loginmethod=2;
292 
293  ns->login_method = loginmethod;
294  SockList_AddPrintf(&sl, "%d", loginmethod);
295 
296  } else if (!strcmp(cmd, "notifications")) {
297  int notifications;
298 
299  notifications = atoi(param);
300 
301  ns->notifications = MIN(notifications, 3);
302  SockList_AddPrintf(&sl, "%d", ns->notifications);
303 
304  } else if (!strcmp(cmd, "newmapcmd")) {
305  /* newmapcmd is deprecated (now standard part), but some
306  * clients still use this setup option, and if the server
307  * doesn't respond, erroneously report that the client is
308  * too old. Since it is always on, regardless of what is
309  * request, send back one.
310  */
311  SockList_AddString(&sl, "1");
312  } else if (!strcmp(cmd, "extendedTextInfos")) {
313  /* like newmapcmd above, extendedTextInfos is
314  * obsolete, but we respond for the same reason as we do
315  * in newmapcmd
316  */
317  SockList_AddString(&sl, "1");
318  } else if (!strcmp(cmd, "itemcmd")) {
319  /* like newmapcmd above, itemcmd is
320  * obsolete, but we respond for the same reason as we do
321  * in newmapcmd
322  */
323  SockList_AddString(&sl, "2");
324  } else if (!strcmp(cmd, "exp64")) {
325  /* like newmapcmd above, exp64 is
326  * obsolete, but we respond for the same reason as we do
327  * in newmapcmd
328  */
329  SockList_AddString(&sl, "1");
330  } else {
331  /* Didn't get a setup command we understood -
332  * report a failure to the client.
333  */
334  SockList_AddString(&sl, "FALSE");
335  }
336  } /* for processing all the setup commands */
337  Send_With_Handling(ns, &sl);
338  SockList_Term(&sl);
339 }
340 
349 void add_me_cmd(char *buf, int len, socket_struct *ns) {
350  Settings oldsettings;
351  SockList sl;
352  (void)buf;
353  (void)len;
354 
355  oldsettings = settings;
356  if (ns->status != Ns_Add) {
357  SockList_Init(&sl);
358  SockList_AddString(&sl, "addme_failed");
359  Send_With_Handling(ns, &sl);
360  SockList_Term(&sl);
361  } else if (find_player_socket(ns) == NULL) {
362  /* if there is already a player for this socket (add_me was already called),
363  * just ignore, else weird issues. */
364 
365  add_player(ns, 0);
366  /* Basically, the add_player copies the socket structure into
367  * the player structure, so this one (which is from init_sockets)
368  * is not needed anymore. The write below should still work,
369  * as the stuff in ns is still relevant.
370  */
371  SockList_Init(&sl);
372  SockList_AddString(&sl, "addme_success");
373  Send_With_Handling(ns, &sl);
374  SockList_Term(&sl);
375  if (ns->sc_version < 1027 || ns->cs_version < 1023) {
377  "Warning: Your client is too old to receive map data. Please update to a new client at: "
378  "https://sourceforge.net/projects/crossfire/");
379  }
380  }
381  settings = oldsettings;
382 }
383 
393 static void send_smooth(socket_struct *ns, const Face *face) {
394  const Face *smoothface;
395  SockList sl;
396 
397  // A malicious client can send bogus asksmooth commands that don't
398  // translate to any face. Catch those here before the message below
399  // in order to avoid a segfault.
400  if (!face) {
401  LOG(llevError, "Tried to smooth null face.\n");
402  return;
403  }
404 
405  // Try to find a smoothing face, or the default smoothing face. If this
406  // fails, set NS_FACESENT_SMOOTH so we don't try to send it again.
407  //
408  // Failures are usually due to map makers changing the face of a ground
409  // tile, but forgetting to unset smoothlevel.
410  if (!find_smooth(face, &smoothface)
411  && !find_smooth(smooth_face, &smoothface)) {
412  LOG(llevInfo,
413  "Could not smooth face %s. "
414  "Check that this face has a smoothing pixmap, or remove its smoothlevel.\n",
415  face->name);
416  ns->faces_sent[face->number] |= NS_FACESENT_SMOOTH;
417  return;
418  }
419 
420  if (!(ns->faces_sent[smoothface->number]&NS_FACESENT_FACE))
421  esrv_send_face(ns, smoothface, 0);
422 
423  ns->faces_sent[face->number] |= NS_FACESENT_SMOOTH;
424 
425  SockList_Init(&sl);
426  SockList_AddString(&sl, "smooth ");
427  SockList_AddShort(&sl, face->number);
428  SockList_AddShort(&sl, smoothface->number);
429  Send_With_Handling(ns, &sl);
430  SockList_Term(&sl);
431 }
432 
437 void ask_smooth_cmd(char *buf, int len, socket_struct *ns) {
438  uint16_t facenid;
439 
440  if (len <= 0 || !buf) {
441  LOG(llevDebug, "IP '%s' sent bogus ask_smooth_cmd information\n", ns->host);
442  return;
443  }
444 
445  facenid = atoi(buf);
446  send_smooth(ns, get_face_by_id(facenid));
447 }
448 
461 void new_player_cmd(uint8_t *buf, int len, player *pl) {
462  int time, repeat;
463  short packet;
464  char command[MAX_BUF];
465  SockList sl;
466 
467  if (len < 7) {
468  LOG(llevDebug, "Corrupt ncom command - not long enough - discarding\n");
469  return;
470  }
471 
472  packet = GetShort_String(buf);
473  repeat = GetInt_String(buf+2);
474  /* -1 is special - no repeat, but don't update */
475  if (repeat != -1) {
476  pl->count = repeat;
477  }
478  if (len-4 >= MAX_BUF)
479  len = MAX_BUF-5;
480 
481  strncpy(command, (char *)buf+6, len-4);
482  command[len-4] = '\0';
483 
484  /* The following should never happen with a proper or honest client.
485  * Therefore, the error message doesn't have to be too clear - if
486  * someone is playing with a hacked/non working client, this gives them
487  * an idea of the problem, but they deserve what they get
488  */
489  if (pl->state != ST_PLAYING) {
491  "You can not issue commands - state is not ST_PLAYING (%s)",
492  buf);
493  return;
494  }
495 
496  /* This should not happen anymore. */
497  if (pl->ob->speed_left < 0) {
498  LOG(llevError, "Player %s (%s) has negative time - shouldn't do command.\n",
499  pl->ob->name ? pl->ob->name : "(unnamed)", pl->socket->account_name ? pl->socket->account_name : "(no account)");
500  }
501  command_execute(pl->ob, command);
502  /* Perhaps something better should be done with a left over count.
503  * Cleaning up the input should probably be done first - all actions
504  * for the command that issued the count should be done before
505  * any other commands.
506  */
507  pl->count = 0;
508 
509  /* Send confirmation of command execution now */
510  SockList_Init(&sl);
511  SockList_AddString(&sl, "comc ");
512  SockList_AddShort(&sl, packet);
513  if (FABS(pl->ob->speed) < 0.001)
514  time = MAX_TIME*100;
515  else
516  time = (int)(MAX_TIME/FABS(pl->ob->speed));
517  SockList_AddInt(&sl, time);
518  Send_With_Handling(pl->socket, &sl);
519  SockList_Term(&sl);
520 }
521 
523 void reply_cmd(char *buf, int len, player *pl) {
524 
525  if (len <= 0 || !buf) {
526  LOG(llevDebug, "Player '%s' sent bogus reply_cmd information\n", pl->ob->name);
527  return;
528  }
529 
530  /* this avoids any hacking here */
531 
532  switch (pl->state) {
533  case ST_PLAYING:
534  LOG(llevError, "Got reply message with ST_PLAYING input state\n");
535  break;
536 
537  case ST_PLAY_AGAIN:
538  /* We can check this for return value (2==quit). Maybe we
539  * should, and do something appropriate?
540  */
541  receive_play_again(pl->ob, buf[0]);
542  break;
543 
544  case ST_ROLL_STAT:
545  key_roll_stat(pl->ob, buf[0]);
546  break;
547 
548  case ST_CHANGE_CLASS:
549 
550  key_change_class(pl->ob, buf[0]);
551  break;
552 
553  case ST_CONFIRM_QUIT:
554  key_confirm_quit(pl->ob, buf[0]);
555  break;
556 
557  case ST_GET_NAME:
558  receive_player_name(pl->ob, buf);
559  break;
560 
561  case ST_GET_PASSWORD:
562  case ST_CONFIRM_PASSWORD:
567  break;
568 
569  case ST_GET_PARTY_PASSWORD: /* Get password for party */
571  break;
572 
573  default:
574  LOG(llevError, "Unknown input state: %d\n", pl->state);
575  }
576 }
577 
585 void version_cmd(char *buf, int len, socket_struct *ns) {
586  char *rest = NULL;
587  char *cs_str = strtok_r(buf, " ", &rest);
588  char *sc_str = strtok_r(NULL, " ", &rest);
589  (void)len;
590 
591  if (cs_str == NULL || sc_str == NULL) {
592  LOG(llevError, "%s: sent invalid version string\n", ns->host);
593  return;
594  } else {
595  ns->cs_version = atoi(cs_str);
596  ns->sc_version = atoi(sc_str);
597  }
598 
599 #ifdef ESRV_DEBUG
600  if (VERSION_CS != ns->cs_version) {
601  LOG(llevDebug, "CS: csversion mismatch (%d,%d)\n", VERSION_CS, ns->cs_version);
602  }
603 
604  if (VERSION_SC != ns->sc_version) {
605  LOG(llevDebug, "CS: scversion mismatch (%d,%d)\n", VERSION_SC, ns->sc_version);
606  }
607 #endif
608 
609  if (rest != NULL) {
610  LOG(llevInfo, "Connection from %s (%s), CS %d, SC %d\n",
611  ns->host, rest, ns->cs_version, ns->sc_version);
612  }
613 }
614 
622  SockList sl;
623 
624  /* If getting a newmap command, this scroll information
625  * is no longer relevant.
626  */
627  ns->map_scroll_x = 0;
628  ns->map_scroll_y = 0;
629 
630 
631  memset(&ns->lastmap, 0, sizeof(ns->lastmap));
632  SockList_Init(&sl);
633  SockList_AddString(&sl, "newmap");
634  Send_With_Handling(ns, &sl);
635  SockList_Term(&sl);
636 }
637 
642 void move_cmd(char *buf, int len, player *pl) {
643  int vals[3], i;
644 
645  if (len <= 0 || !buf) {
646  LOG(llevDebug, "Player '%s' sent bogus move_cmd information\n", pl->ob->name);
647  return;
648  }
649 
650  /* A little funky here. We only cycle for 2 records, because
651  * we obviously am not going to find a space after the third
652  * record. Perhaps we should just replace this with a
653  * sscanf?
654  */
655  for (i = 0; i < 2; i++) {
656  vals[i] = atoi(buf);
657  if (!(buf = strchr(buf, ' '))) {
658  LOG(llevError, "Incomplete move command: %s\n", buf);
659  return;
660  }
661  buf++;
662  }
663  vals[2] = atoi(buf);
664 
665 /* LOG(llevDebug, "Move item %d (nrof=%d) to %d.\n", vals[1], vals[2], vals[0]);*/
666  esrv_move_object(pl->ob, vals[0], vals[1], vals[2]);
667 }
668 
669 /***************************************************************************
670  *
671  * Start of commands the server sends to the client.
672  *
673  ***************************************************************************
674  */
675 
680 void send_query(socket_struct *ns, uint8_t flags, const char *text) {
681  SockList sl;
682 
683  SockList_Init(&sl);
684  SockList_AddPrintf(&sl, "query %d %s", flags, text ? text : "");
685  Send_With_Handling(ns, &sl);
686  SockList_Term(&sl);
687 }
688 
689 #define AddIfInt64(Old, New, sl, Type) \
690  if (Old != New) { \
691  Old = New; \
692  SockList_AddChar(sl, Type); \
693  SockList_AddInt64(sl, New); \
694  }
695 
696 #define AddIfInt(Old, New, sl, Type) \
697  if (Old != New) { \
698  Old = New; \
699  SockList_AddChar(sl, Type); \
700  SockList_AddInt(sl, New); \
701  }
702 
703 #define AddIfShort(Old, New, sl, Type) \
704  if (Old != New) { \
705  Old = New; \
706  SockList_AddChar(sl, Type); \
707  SockList_AddShort(sl, New); \
708  }
709 
710 #define AddIfFloat(Old, New, sl, Type) \
711  if (Old != New) { \
712  Old = New; \
713  SockList_AddChar(sl, Type); \
714  SockList_AddInt(sl, (long)(New*FLOAT_MULTI));\
715  }
716 
717 #define AddIfString(Old, New, sl, Type) \
718  if (Old == NULL || strcmp(Old, New)) { \
719  free(Old); \
720  Old = strdup_local(New); \
721  SockList_AddChar(sl, Type); \
722  SockList_AddLen8Data(sl, New, strlen(New)); \
723  }
724 
730 static uint8_t is_perfect(const player *pl) {
731  const int16_t until = MIN(11, pl->ob->level);
732  for (int16_t i = 1; i < until; i++) {
733  if (pl->levhp[i] < 9 || pl->levsp[i] < 6 || pl->levgrace[i] < 3) {
734  return 0;
735  }
736  }
737  return 1;
738 }
739 
745 static void send_extra_stats(SockList *sl, player *pl) {
746  uint32_t uflags = 0;
747  const char *god = "none";
748 
749  if (pl->socket->notifications < 3) {
750  return;
751  }
752 
753  if (!pl->peaceful) {
754  uflags |= CF_HOSTILE;
755  }
756  if (!is_perfect(pl)) {
757  uflags |= CF_NOT_PERFECT;
758  }
759 
760 #define FIF(F, C) \
761  if (QUERY_FLAG(pl->ob, F)) { \
762  uflags |= C; \
763  }
765  FIF(FLAG_CONFUSED, CF_CONFUSED); // If confused by an item
769 
770  FOR_INV_PREPARE(pl->ob, item) {
771  if (item->type == DISEASE && !QUERY_FLAG(item, FLAG_STARTEQUIP)) {
772  uflags |= CF_DISEASED;
773  }
774  if (strcmp(item->arch->name, "poisoning") == 0) {
775  uflags |= CF_POISONED;
776  }
777  if (strcmp(item->arch->name, "blindness") == 0) {
778  uflags |= CF_BLIND;
779  }
780  if (item->type == FORCE && strcmp(item->name, "confusion") == 0) {
781  uflags |= CF_CONFUSED;
782  }
783  if (item->type == SKILL && item->subtype == SK_PRAYING && item->title) {
784  god = item->title;
785  }
786  }
787  FOR_INV_FINISH();
788 
789  AddIfInt(pl->last_character_flags, uflags, sl, CS_STAT_CHARACTER_FLAGS);
790  AddIfFloat(pl->last_character_load, pl->character_load, sl, CS_STAT_OVERLOAD);
791  AddIfString(pl->socket->stats.god, god, sl, CS_STAT_GOD_NAME);
792  AddIfShort(pl->last_item_power, pl->item_power, sl, CS_STAT_ITEM_POWER);
793 }
794 
802  SockList sl;
803  char buf[MAX_BUF];
804  uint16_t flags;
805  uint8_t s;
806 
807  SockList_Init(&sl);
808  SockList_AddString(&sl, "stats ");
809 
810  if (pl->ob != NULL) {
811  AddIfShort(pl->last_stats.hp, pl->ob->stats.hp, &sl, CS_STAT_HP);
812  AddIfShort(pl->last_stats.maxhp, pl->ob->stats.maxhp, &sl, CS_STAT_MAXHP);
813  AddIfShort(pl->last_stats.sp, pl->ob->stats.sp, &sl, CS_STAT_SP);
814  AddIfShort(pl->last_stats.maxsp, pl->ob->stats.maxsp, &sl, CS_STAT_MAXSP);
815  AddIfShort(pl->last_stats.grace, pl->ob->stats.grace, &sl, CS_STAT_GRACE);
816  AddIfShort(pl->last_stats.maxgrace, pl->ob->stats.maxgrace, &sl, CS_STAT_MAXGRACE);
817  AddIfShort(pl->last_stats.Str, pl->ob->stats.Str, &sl, CS_STAT_STR);
818  AddIfShort(pl->last_stats.Int, pl->ob->stats.Int, &sl, CS_STAT_INT);
819  AddIfShort(pl->last_stats.Pow, pl->ob->stats.Pow, &sl, CS_STAT_POW);
820  AddIfShort(pl->last_stats.Wis, pl->ob->stats.Wis, &sl, CS_STAT_WIS);
821  AddIfShort(pl->last_stats.Dex, pl->ob->stats.Dex, &sl, CS_STAT_DEX);
822  AddIfShort(pl->last_stats.Con, pl->ob->stats.Con, &sl, CS_STAT_CON);
823  AddIfShort(pl->last_stats.Cha, pl->ob->stats.Cha, &sl, CS_STAT_CHA);
824  }
825  if (pl->socket->extended_stats) {
826  int16_t golem_hp, golem_maxhp;
827  AddIfShort(pl->last_orig_stats.Str, pl->orig_stats.Str, &sl, CS_STAT_BASE_STR);
828  AddIfShort(pl->last_orig_stats.Int, pl->orig_stats.Int, &sl, CS_STAT_BASE_INT);
829  AddIfShort(pl->last_orig_stats.Pow, pl->orig_stats.Pow, &sl, CS_STAT_BASE_POW);
830  AddIfShort(pl->last_orig_stats.Wis, pl->orig_stats.Wis, &sl, CS_STAT_BASE_WIS);
831  AddIfShort(pl->last_orig_stats.Dex, pl->orig_stats.Dex, &sl, CS_STAT_BASE_DEX);
832  AddIfShort(pl->last_orig_stats.Con, pl->orig_stats.Con, &sl, CS_STAT_BASE_CON);
833  AddIfShort(pl->last_orig_stats.Cha, pl->orig_stats.Cha, &sl, CS_STAT_BASE_CHA);
834  if (pl->ob != NULL) {
835  AddIfShort(pl->last_race_stats.Str, 20 + pl->ob->arch->clone.stats.Str, &sl, CS_STAT_RACE_STR);
836  AddIfShort(pl->last_race_stats.Int, 20 + pl->ob->arch->clone.stats.Int, &sl, CS_STAT_RACE_INT);
837  AddIfShort(pl->last_race_stats.Pow, 20 + pl->ob->arch->clone.stats.Pow, &sl, CS_STAT_RACE_POW);
838  AddIfShort(pl->last_race_stats.Wis, 20 + pl->ob->arch->clone.stats.Wis, &sl, CS_STAT_RACE_WIS);
839  AddIfShort(pl->last_race_stats.Dex, 20 + pl->ob->arch->clone.stats.Dex, &sl, CS_STAT_RACE_DEX);
840  AddIfShort(pl->last_race_stats.Con, 20 + pl->ob->arch->clone.stats.Con, &sl, CS_STAT_RACE_CON);
841  AddIfShort(pl->last_race_stats.Cha, 20 + pl->ob->arch->clone.stats.Cha, &sl, CS_STAT_RACE_CHA);
842  AddIfShort(pl->last_applied_stats.Str, pl->applied_stats.Str, &sl, CS_STAT_APPLIED_STR);
843  AddIfShort(pl->last_applied_stats.Int, pl->applied_stats.Int, &sl, CS_STAT_APPLIED_INT);
844  AddIfShort(pl->last_applied_stats.Pow, pl->applied_stats.Pow, &sl, CS_STAT_APPLIED_POW);
845  AddIfShort(pl->last_applied_stats.Wis, pl->applied_stats.Wis, &sl, CS_STAT_APPLIED_WIS);
846  AddIfShort(pl->last_applied_stats.Dex, pl->applied_stats.Dex, &sl, CS_STAT_APPLIED_DEX);
847  AddIfShort(pl->last_applied_stats.Con, pl->applied_stats.Con, &sl, CS_STAT_APPLIED_CON);
848  AddIfShort(pl->last_applied_stats.Cha, pl->applied_stats.Cha, &sl, CS_STAT_APPLIED_CHA);
849  }
850  if (pl->ranges[range_golem]) {
851  object *golem = pl->ranges[range_golem];
852  if (QUERY_FLAG(golem, FLAG_REMOVED) || golem->count != pl->golem_count || QUERY_FLAG(golem, FLAG_FREED)) {
853  golem_hp = 0;
854  golem_maxhp = 0;
855  } else {
856  golem_hp = golem->stats.hp;
857  golem_maxhp = golem->stats.maxhp;
858  }
859  } else {
860  golem_hp = 0;
861  golem_maxhp = 0;
862  }
863  /* send first the maxhp, so the client can set up the display */
864  AddIfShort(pl->last_golem_maxhp, golem_maxhp, &sl, CS_STAT_GOLEM_MAXHP);
865  AddIfShort(pl->last_golem_hp, golem_hp, &sl, CS_STAT_GOLEM_HP);
866  }
867 
868  for (s = 0; s < MAX_SKILLS; s++) {
869  if (pl->last_skill_ob[s]) {
870  // Skill objects can be removed without updating last_skill_ob.
871  // Clean them up here if that's the case.
872  if (QUERY_FLAG(pl->last_skill_ob[s], FLAG_REMOVED)) {
873  LOG(llevDebug, "pruning removed object from last_skill_ob\n");
874  pl->last_skill_ob[s] = NULL;
875  continue;
876  }
877 
878  if (pl->last_skill_exp[s] != pl->last_skill_ob[s]->stats.exp) {
879  /* Always send along the level if exp changes. This
880  * is only 1 extra byte, but keeps processing simpler.
881  */
882  SockList_AddChar(&sl, (char)(get_skill_client_code(pl->last_skill_ob[s]->name) + CS_STAT_SKILLINFO));
883  SockList_AddChar(&sl, (char)pl->last_skill_ob[s]->level);
884  SockList_AddInt64(&sl, pl->last_skill_ob[s]->stats.exp);
885  pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp;
886  }
887  }
888  }
889  AddIfInt64(pl->last_stats.exp, pl->ob->stats.exp, &sl, CS_STAT_EXP64);
890  AddIfShort(pl->last_level, (char)pl->ob->level, &sl, CS_STAT_LEVEL);
891  AddIfShort(pl->last_stats.wc, pl->ob->stats.wc, &sl, CS_STAT_WC);
892  AddIfShort(pl->last_stats.ac, pl->ob->stats.ac, &sl, CS_STAT_AC);
893  AddIfShort(pl->last_stats.dam, pl->ob->stats.dam, &sl, CS_STAT_DAM);
894  AddIfFloat(pl->last_speed, pl->ob->speed, &sl, CS_STAT_SPEED);
895  AddIfShort(pl->last_stats.food, pl->ob->stats.food, &sl, CS_STAT_FOOD);
896  AddIfFloat(pl->last_weapon_sp, pl->ob->weapon_speed, &sl, CS_STAT_WEAP_SP);
897  AddIfInt(pl->last_weight_limit, (int32_t)get_weight_limit(pl->ob->stats.Str), &sl, CS_STAT_WEIGHT_LIM);
898  flags = 0;
899  if (pl->fire_on)
900  flags |= SF_FIREON;
901  if (pl->run_on)
902  flags |= SF_RUNON;
903 
904  AddIfShort(pl->last_flags, flags, &sl, CS_STAT_FLAGS);
905  if (pl->socket->sc_version < 1025) {
906  AddIfShort(pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], &sl, CS_STAT_ARMOUR);
907  } else {
908  int i;
909 
910  for (i = 0; i < NROFATTACKS; i++) {
911  /* Skip ones we won't send */
912  if (atnr_cs_stat[i] == -1)
913  continue;
914  AddIfShort(pl->last_resist[i], pl->ob->resist[i], &sl, (char)atnr_cs_stat[i]);
915  }
916  }
917  if (pl->socket->monitor_spells) {
918  AddIfInt(pl->last_path_attuned, pl->ob->path_attuned, &sl, CS_STAT_SPELL_ATTUNE);
919  AddIfInt(pl->last_path_repelled, pl->ob->path_repelled, &sl, CS_STAT_SPELL_REPEL);
920  AddIfInt(pl->last_path_denied, pl->ob->path_denied, &sl, CS_STAT_SPELL_DENY);
921  }
922  /* we want to use the new fire & run system in new client */
923  rangetostring(pl->ob, buf, sizeof(buf));
924  AddIfString(pl->socket->stats.range, buf, &sl, CS_STAT_RANGE);
925  set_title(pl->ob, buf, sizeof(buf));
926  AddIfString(pl->socket->stats.title, buf, &sl, CS_STAT_TITLE);
927 
928  send_extra_stats(&sl, pl);
929 
930  /* Only send it away if we have some actual data - 2 bytes for length, 6 for "stats ". */
931  if (sl.len > 8) {
932 #ifdef ESRV_DEBUG
933  LOG(llevDebug, "Sending stats command, %d bytes long.\n", sl.len);
934 #endif
935  Send_With_Handling(pl->socket, &sl);
936  }
937  SockList_Term(&sl);
938 }
939 
943 void esrv_new_player(player *pl, uint32_t weight) {
944  SockList sl;
945 
946  pl->last_weight = weight;
947 
948  if (!(pl->socket->faces_sent[pl->ob->face->number]&NS_FACESENT_FACE))
949  esrv_send_face(pl->socket, pl->ob->face, 0);
950 
951  SockList_Init(&sl);
952  SockList_AddString(&sl, "player ");
953  SockList_AddInt(&sl, pl->ob->count);
954  SockList_AddInt(&sl, weight);
955  SockList_AddInt(&sl, pl->ob->face->number);
956  SockList_AddLen8Data(&sl, pl->ob->name, strlen(pl->ob->name));
957 
958  Send_With_Handling(pl->socket, &sl);
959  SockList_Term(&sl);
961 }
962 
974  SockList sl;
975  int i;
976 
977  if (anim == NULL) {
978  LOG(llevError, "esrv_send_anim NULL??\n");
979  return;
980  }
981 
982  SockList_Init(&sl);
983  SockList_AddString(&sl, "anim ");
984  SockList_AddShort(&sl, anim->num);
985  SockList_AddShort(&sl, 0); /* flags - not used right now */
986  /* Build up the list of faces. Also, send any information (ie, the
987  * the face itself) down to the client.
988  */
989  for (i = 0; i < anim->num_animations; i++) {
990  if (!(ns->faces_sent[anim->faces[i]->number]&NS_FACESENT_FACE))
991  esrv_send_face(ns, anim->faces[i], 0);
992  /* flags - not used right now */
993  SockList_AddShort(&sl, anim->faces[i]->number);
994  }
995  Send_With_Handling(ns, &sl);
996  SockList_Term(&sl);
997  ns->anims_sent[anim->num] = 1;
998 }
999 
1000 /****************************************************************************
1001  *
1002  * Start of map related commands.
1003  *
1004  ****************************************************************************/
1005 
1007 static void map_clearcell(struct map_cell_struct *cell, int face, int count) {
1008  cell->darkness = count;
1009  memset(cell->faces, face, sizeof(cell->faces));
1010 }
1011 
1012 #define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y)
1013 
1021 static const object *heads[MAX_HEAD_POS][MAX_HEAD_POS][MAP_LAYERS];
1022 
1023 /****************************************************************************
1024  * This block is for map2 drawing related commands.
1025  * Note that the map2 still uses other functions.
1026  *
1027  ***************************************************************************/
1028 
1048 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) {
1049  uint8_t nlayer, smoothlevel = 0;
1050  const object *head;
1051 
1052  assert(ob != NULL);
1053 
1054  head = HEAD(ob);
1055  const Face *face = ob->face;
1056 
1057  /* This is a multipart object, and we are not at the lower
1058  * right corner. So we need to store away the lower right corner.
1059  */
1060  if (!is_head && (head->arch->tail_x || head->arch->tail_y)
1061  && (head->arch->tail_x != ob->arch->clone.x || head->arch->tail_y != ob->arch->clone.y)) {
1062  int bx, by, l;
1063 
1064  /* Basically figure out where the offset is from where we
1065  * are right now. the ob->arch->clone.{x,y} values hold
1066  * the offset that this current piece is from the head,
1067  * and the tail is where the tail is from the head.
1068  * Note that bx and by will equal sx and sy if we are
1069  * already working on the bottom right corner. If ob is
1070  * the head, the clone values will be zero, so the right
1071  * thing will still happen.
1072  */
1073  bx = ax+head->arch->tail_x-ob->arch->clone.x;
1074  by = ay+head->arch->tail_y-ob->arch->clone.y;
1075 
1076  /* I don't think this can ever happen, but better to check
1077  * for it just in case.
1078  */
1079  if (bx < ax || by < ay) {
1080  LOG(llevError, "map2_add_ob: bx (%d) or by (%d) is less than ax (%d) or ay (%d)\n", bx, by, ax, ay);
1081  face = NULL;
1082  }
1083  /* the target position must be within +/-1 of our current
1084  * layer as the layers are defined. We are basically checking
1085  * to see if we have already stored this object away.
1086  */
1087  for (l = layer-1; l <= layer+1; l++) {
1088  if (l < 0 || l >= MAP_LAYERS)
1089  continue;
1090  if (heads[by][bx][l] == head)
1091  break;
1092  }
1093  /* Didn't find it. So we need to store it away. Try to store it
1094  * on our original layer, and then move up a layer.
1095  */
1096  if (l == layer+2) {
1097  if (!heads[by][bx][layer])
1098  heads[by][bx][layer] = head;
1099  else if (layer+1 < MAP_LAYERS && !heads[by][bx][layer+1])
1100  heads[by][bx][layer+1] = head;
1101  }
1102  return 0;
1103  /* Ok - All done storing away the head for future use */
1104  } else {
1105  uint16_t face_num = face ? face->number : 0;
1106  (*has_obj)++;
1109  face_num = (ob->animation ? ob->animation->num : 0)|(1<<15);
1111  face_num |= ANIM_SYNC;
1113  face_num |= ANIM_RANDOM;
1114  }
1115  /* Since face_num includes the bits for the animation tag,
1116  * and we will store that away in the faces[] array, below
1117  * check works fine _except_ for the case where animation
1118  * speed chances.
1119  */
1120  if (ns->lastmap.cells[ax][ay].faces[layer] != face_num) {
1121  uint8_t len, anim_speed = 0, i;
1122 
1123  /* This block takes care of sending the actual face
1124  * to the client. */
1125  ns->lastmap.cells[ax][ay].faces[layer] = face_num;
1126 
1127  /* Now form the data packet */
1128  nlayer = MAP2_LAYER_START+layer;
1129 
1130  len = 2;
1131 
1132  if (ob->map && !MAP_NOSMOOTH(ob->map)) {
1133  smoothlevel = ob->smoothlevel;
1134  if (smoothlevel)
1135  len++;
1136  }
1137 
1140  len++;
1141  /* 1/0.004 == 250, so this is a good cap for an
1142  * upper limit */
1143  if (ob->anim_speed)
1144  anim_speed = ob->anim_speed;
1145  else if (FABS(ob->speed) < 0.004)
1146  anim_speed = 255;
1147  else if (FABS(ob->speed) >= 1.0)
1148  anim_speed = 1;
1149  else
1150  anim_speed = (int)(1.0/FABS(ob->speed));
1151 
1152  if (ob->animation && !ns->anims_sent[ob->animation->num])
1153  esrv_send_animation(ns, ob->animation);
1154 
1155  /* If smoothing, need to send smoothing information
1156  * for all faces in the animation sequence. Since
1157  * smoothlevel is an object attribute,
1158  * it applies to all faces.
1159  */
1160  if (smoothlevel) {
1161  for (i = 0; i < NUM_ANIMATIONS(ob); i++) {
1162  if (!(ns->faces_sent[ob->animation->faces[i]->number]&NS_FACESENT_SMOOTH))
1163  send_smooth(ns, ob->animation->faces[i]);
1164  }
1165  }
1166  } else if (!(ns->faces_sent[face_num]&NS_FACESENT_FACE)) {
1167  esrv_send_face(ns, face, 0);
1168  }
1169 
1170  if (smoothlevel
1171  && !(ns->faces_sent[ob->face->number]&NS_FACESENT_SMOOTH))
1172  send_smooth(ns, ob->face);
1173 
1174  /* Length of packet */
1175  nlayer |= len<<5;
1176 
1177  SockList_AddChar(sl, nlayer);
1178  SockList_AddShort(sl, face_num);
1179  if (anim_speed)
1180  SockList_AddChar(sl, anim_speed);
1181  if (smoothlevel)
1182  SockList_AddChar(sl, smoothlevel);
1183  return 1;
1184  } /* Face is different */
1185  }
1186  return 0;
1187 }
1188 
1189 /* This function is used see if a layer needs to be cleared.
1190  * It updates the socklist, and returns 1 if the update is
1191  * needed, 0 otherwise.
1192  */
1193 static int map2_delete_layer(int ax, int ay, int layer, SockList *sl, socket_struct *ns) {
1194  int nlayer;
1195 
1196  if (ns->lastmap.cells[ax][ay].faces[layer] != 0) {
1197  /* Now form the data packet */
1198  nlayer = 0x10+layer+(2<<5);
1199  SockList_AddChar(sl, nlayer);
1200  SockList_AddShort(sl, 0);
1201  ns->lastmap.cells[ax][ay].faces[layer] = 0;
1202  return 1;
1203  }
1204  return 0;
1205 }
1206 
1218 static int check_probe(int ax, int ay, const object *ob, SockList *sl, socket_struct *ns, int *has_obj, int *alive_layer) {
1219  int got_one = 0, poisoned = 0, diseased = 0;
1220  char name[60];
1221  int value, granularity;
1222  const object *probe;
1223 
1224  /* send hp bar if needed */
1225  if ((*alive_layer) != -1 || ob->head || !CAN_PROBE(ob))
1226  return 0;
1227 
1228  if (settings.always_show_hp == 2) {
1229  /* global hp bars are enabled */
1230  granularity = 30;
1231  } else if (settings.always_show_hp == 1 && ob->stats.hp < ob->stats.maxhp) {
1232  granularity = 30;
1233  } else {
1234  /* only give hp bars to monsters that have been probed */
1235  if (!QUERY_FLAG(ob, FLAG_PROBE)) {
1236  return 0;
1237  }
1238  probe = object_find_by_type_and_name(ob, FORCE, "probe_force");
1239  if (probe == NULL || probe->level < 15) {
1240  /* if probe is not null, this is an error, but well */
1241  return 0;
1242  }
1243 
1244  granularity = (probe->level - 14) / 3;
1245  if (granularity <= 0)
1246  granularity = 1;
1247  else if (granularity > 30)
1248  granularity = 30;
1249  }
1250 
1251  if (ob->stats.maxhp > 0) {
1252  value = (ob->stats.hp * granularity) / (ob->stats.maxhp);
1253 
1254  if (value < 0)
1255  value = 0;
1256  else if (value > granularity)
1257  value = granularity;
1258  } else
1259  value = 30;
1260 
1261  value = (value * 30) / granularity;
1262 
1263  if (object_present_in_ob(POISONING, ob) != NULL)
1264  poisoned = 1;
1265  if (object_present_in_ob(DISEASE, ob) != NULL)
1266  diseased = 1;
1267 
1268  if (value > 0) {
1269  archetype *dummy;
1270 
1271  snprintf(name, sizeof(name), "hpbar%s%s%s_%d",
1272  poisoned ? "_poisoned" : "",
1273  diseased ? "_diseased" : "",
1274  (!poisoned && !diseased) ? "_standard" : "",
1275  value);
1276  dummy = try_find_archetype(name);
1277  if (dummy != NULL) {
1278  got_one += map2_add_ob(ax, ay, MAP_LAYER_FLY2, &dummy->clone, sl, ns, has_obj, 0);
1279  (*alive_layer) = MAP_LAYER_FLY2;
1280  }
1281  }
1282 
1283  return got_one;
1284 }
1285 
1286 static int annotate_ob(int ax, int ay, const object *ob, SockList *sl, socket_struct *ns, int *has_obj, int *alive_layer) {
1287  int got_one = check_probe(ax, ay, ob, sl, ns, has_obj, alive_layer);
1289  if (ob->msg != NULL || object_find_by_arch_name(ob, "npc_dialog")) {
1290  archetype *dummy = try_find_archetype("speechbubble");
1291  if (dummy != NULL) {
1292  got_one += map2_add_ob(ax, ay, MAP_LAYER_FLY2, &dummy->clone, sl, ns, has_obj, 0);
1293  (*alive_layer) = MAP_LAYER_FLY2;
1294  }
1295  }
1296  }
1297  return got_one;
1298 }
1299 
1300 /*
1301  * This function is used to check a space (ax, ay) whose only
1302  * data we may care about are any heads. Basically, this
1303  * space is out of direct view. This is only used with the
1304  * Map2 protocol.
1305  *
1306  * @param ax
1307  * viewport relative x-coordinate
1308  * @param ay
1309  * viewport relative y-coordinate
1310  * @param sl
1311  * the reply to append to
1312  * @param ns
1313  * the client socket
1314  */
1315 static void check_space_for_heads(int ax, int ay, SockList *sl, socket_struct *ns) {
1316  int layer, got_one = 0, del_one = 0, oldlen, has_obj = 0;
1317  uint16_t coord;
1318 
1319  coord = MAP2_COORD_ENCODE(ax, ay, 0);
1320  oldlen = sl->len;
1321  SockList_AddShort(sl, coord);
1322 
1323  for (layer = 0; layer < MAP_LAYERS; layer++) {
1324  const object *head;
1325 
1326  head = heads[ay][ax][layer];
1327  if (head) {
1328  /* in this context, got_one should always increase
1329  * because heads should always point to data to really send.
1330  */
1331  got_one += map2_add_ob(ax, ay, layer, head, sl, ns, &has_obj, 1);
1332  } else {
1333  del_one += map2_delete_layer(ax, ay, layer, sl, ns);
1334  }
1335  }
1336  /* Note - if/when lighting information is added, some code is
1337  * needed here - lighting sources that are out of sight may still
1338  * extend into the viewable area.
1339  */
1340 
1341  /* If nothing to do for this space, we
1342  * can erase the coordinate bytes
1343  */
1344  if (!del_one && !got_one) {
1345  sl->len = oldlen;
1346  } else if (del_one && !has_obj) {
1347  /* If we're only deleting faces and not adding, and there
1348  * are not any faces on the space we care about,
1349  * more efficient
1350  * to send 0 as the type/len field.
1351  */
1352  sl->len = oldlen+2; /* 2 bytes for coordinate */
1353  SockList_AddChar(sl, 0); /* Clear byte */
1354  SockList_AddChar(sl, 255); /* Termination byte */
1355  // Reduce defreferences by passing the inner array offset instead of address of value
1356  map_clearcell(ns->lastmap.cells[ax] + ay, 0, 0);
1357  } else {
1358  SockList_AddChar(sl, 255); /* Termination byte */
1359  }
1360 }
1361 
1362 static void draw_client_map2(object *pl) {
1363  int x, y, ax, ay, d, min_x, max_x, min_y, max_y, oldlen, layer;
1364  size_t startlen;
1365  int16_t nx, ny;
1366  SockList sl;
1367  uint16_t coord;
1368  mapstruct *m;
1369  // Dereference once. It should not change in the middle of processing.
1370  player *plyr = pl->contr;
1371 
1372  SockList_Init(&sl);
1373  SockList_AddString(&sl, "map2 ");
1374  startlen = sl.len;
1375 
1376  /* Handle map scroll */
1377  if (plyr->socket->map_scroll_x || plyr->socket->map_scroll_y) {
1379  plyr->socket->map_scroll_x = 0;
1380  plyr->socket->map_scroll_y = 0;
1381  SockList_AddShort(&sl, coord);
1382  }
1383 
1384  /* Init data to zero */
1385  memset(heads, 0, sizeof(heads));
1386 
1387  /* We could do this logic as conditionals in the if statement,
1388  * but that started to get a bit messy to look at.
1389  */
1390  min_x = pl->x-plyr->socket->mapx/2;
1391  min_y = pl->y-plyr->socket->mapy/2;
1392  max_x = pl->x+(plyr->socket->mapx+1)/2+MAX_HEAD_OFFSET;
1393  max_y = pl->y+(plyr->socket->mapy+1)/2+MAX_HEAD_OFFSET;
1394 
1395  /* x, y are the real map locations. ax, ay are viewport relative
1396  * locations.
1397  */
1398  ay = 0;
1399  for (y = min_y; y < max_y; y++, ay++) {
1400  ax = 0;
1401  for (x = min_x; x < max_x; x++, ax++) {
1402  /* If this space is out of the normal viewable area,
1403  * we only check the heads value. This is used to
1404  * handle big images - if they extend to a viewable
1405  * portion, we need to send just the lower right corner.
1406  */
1407  if (ax >= plyr->socket->mapx || ay >= plyr->socket->mapy) {
1408  check_space_for_heads(ax, ay, &sl, plyr->socket);
1409  } else {
1410  /* This space is within the viewport of the client. Due
1411  * to walls or darkness, it may still not be visible.
1412  */
1413 
1414  /* Meaning of d:
1415  * 0 - object is in plain sight, full brightness.
1416  * 1 - MAX_DARKNESS - how dark the space is - higher
1417  * value is darker space. If level is at max darkness,
1418  * you can't see the space (too dark)
1419  * 100 - space is blocked from sight.
1420  */
1421  d = plyr->blocked_los[ax][ay];
1422 
1423  /* If the coordinates are not valid, or it is too
1424  * dark to see, we tell the client as such
1425  */
1426  nx = x;
1427  ny = y;
1428  m = get_map_from_coord(pl->map, &nx, &ny);
1429  coord = MAP2_COORD_ENCODE(ax, ay, 0);
1430 
1431  if (!m) {
1432  /* space is out of map. Update space and clear
1433  * values if this hasn't already been done.
1434  * If the space is out of the map, it shouldn't
1435  * have a head.
1436  */
1437  if (plyr->socket->lastmap.cells[ax][ay].darkness != 0) {
1438  SockList_AddShort(&sl, coord);
1440  SockList_AddChar(&sl, 255); /* Termination byte */
1441  // Reduce dereferences by passing the inner array offset instead of address of value
1442  map_clearcell(plyr->socket->lastmap.cells[ax] + ay, 0, 0);
1443  }
1444  } else if (d >= MAX_LIGHT_RADII) {
1445  /* This block deals with spaces that are not
1446  * visible due to darkness or walls. Still
1447  * need to send the heads for this space.
1448  */
1449  check_space_for_heads(ax, ay, &sl, plyr->socket);
1450  } else {
1451  int have_darkness = 0, has_obj = 0, got_one = 0, del_one = 0, g1, alive_layer = -1, old_got;
1452 
1453  /* In this block, the space is visible. */
1454 
1455  /* Rather than try to figure out what everything
1456  * that we might need to send is, then form the
1457  * packet after that, we presume that we will in
1458  * fact form a packet, and update the bits by what
1459  * we do actually send. If we send nothing, we
1460  * just back out sl.len to the old value, and no
1461  * harm is done.
1462  * I think this is simpler than doing a bunch of
1463  * checks to see what if anything we need to send,
1464  * setting the bits, then doing those checks again
1465  * to add the real data.
1466  */
1467 
1468  oldlen = sl.len;
1469  SockList_AddShort(&sl, coord);
1470 
1471  /* Darkness changed */
1472  if (plyr->socket->lastmap.cells[ax][ay].darkness != d
1473  && plyr->socket->darkness) {
1474  plyr->socket->lastmap.cells[ax][ay].darkness = d;
1475  /* Darkness tag & length*/
1477  SockList_AddChar(&sl, 255-d*(256/MAX_LIGHT_RADII));
1478  have_darkness = 1;
1479  }
1480 
1481  for (layer = 0; layer < MAP_LAYERS; layer++) {
1482  const object *ob = GET_MAP_FACE_OBJ(m, nx, ny, layer);
1483 
1484  /* Special case: send player itself if invisible */
1485  if (!ob
1486  && x == pl->x
1487  && y == pl->y
1488  && (pl->invisible&(pl->invisible < 50 ? 4 : 1))
1489  && (layer == MAP_LAYER_LIVING1 || layer == MAP_LAYER_LIVING2))
1490  ob = pl;
1491 
1492  if (ob) {
1493  g1 = has_obj;
1494  old_got = got_one;
1495  got_one += map2_add_ob(ax, ay, layer, ob, &sl, plyr->socket, &has_obj, 0);
1496 
1497  /* if we added the face, or it is a monster's head, check probe spell */
1498  if (got_one != old_got || (ob->head == NULL && ob->more))
1499  got_one += annotate_ob(ax, ay, ob, &sl, plyr->socket, &has_obj, &alive_layer);
1500 
1501  /* If we are just storing away the head
1502  * for future use, then effectively this
1503  * space/layer is blank, and we should clear
1504  * it if needed.
1505  */
1506  if (g1 == has_obj) {
1507  del_one += map2_delete_layer(ax, ay, layer, &sl, plyr->socket);
1508  } else if (ob->head == NULL) {
1509  /* for single-part items */
1510  got_one += annotate_ob(ax, ay, ob, &sl, plyr->socket, &has_obj, &alive_layer);
1511  }
1512  } else {
1513  if (layer != alive_layer)
1514  del_one += map2_delete_layer(ax, ay, layer, &sl, plyr->socket);
1515  }
1516  }
1517  /* If nothing to do for this space, we
1518  * can erase the coordinate bytes
1519  */
1520  if (!del_one && !got_one && !have_darkness) {
1521  sl.len = oldlen;
1522  } else if (del_one && !has_obj) {
1523  /* If we're only deleting faces and don't
1524  * have any objs we care about, just clear
1525  * space. Note it is possible we may have
1526  * darkness, but if there is nothing on the
1527  * space, darkness isn't all that interesting
1528  * - we can send it when an object shows up.
1529  */
1530  sl.len = oldlen+2; /* 2 bytes for coordinate */
1532  SockList_AddChar(&sl, 255); /* Termination byte */
1533  // Reduce dereferences by passing the inner array offset instead of address of value
1534  map_clearcell(plyr->socket->lastmap.cells[ax] + ay, 0, 0);
1535  } else {
1536  SockList_AddChar(&sl, 255); /* Termination byte */
1537  }
1538  }
1539  } /* else this is a viewable space */
1540  } /* for x loop */
1541  } /* for y loop */
1542 
1543  /* Only send this if there are in fact some differences. */
1544  if (sl.len > startlen) {
1545  Send_With_Handling(plyr->socket, &sl);
1546  }
1547  SockList_Term(&sl);
1548 }
1549 
1553 void draw_client_map(object *pl) {
1554  int i, j;
1555  int16_t ax, ay;
1556  int mflags;
1557  mapstruct *m, *pm;
1558  int min_x, min_y, max_x, max_y;
1559 
1560  if (pl->type != PLAYER) {
1561  LOG(llevError, "draw_client_map called with non player/non eric-server\n");
1562  return;
1563  }
1564 
1565  if (pl->contr->transport) {
1566  pm = pl->contr->transport->map;
1567  } else
1568  pm = pl->map;
1569 
1570  /* If player is just joining the game, he isn't here yet, so
1571  * the map can get swapped out. If so, don't try to send them
1572  * a map. All will be OK once they really log in.
1573  */
1574  if (pm == NULL || pm->in_memory != MAP_IN_MEMORY)
1575  return;
1576 
1577  /*
1578  * This block just makes sure all the spaces are properly
1579  * updated in terms of what they look like.
1580  */
1581  min_x = pl->x-pl->contr->socket->mapx/2;
1582  min_y = pl->y-pl->contr->socket->mapy/2;
1583  max_x = pl->x+(pl->contr->socket->mapx+1)/2;
1584  max_y = pl->y+(pl->contr->socket->mapy+1)/2;
1585  for (j = min_y; j < max_y; j++) {
1586  for (i = min_x; i < max_x; i++) {
1587  ax = i;
1588  ay = j;
1589  m = pm;
1590  mflags = get_map_flags(m, &m, ax, ay, &ax, &ay);
1591  if (mflags&P_OUT_OF_MAP)
1592  continue;
1593  if (mflags&P_NEED_UPDATE)
1594  update_position(m, ax, ay);
1595  /* If a map is visible to the player, we don't want
1596  * to swap it out just to reload it. This should
1597  * really call something like swap_map, but this is
1598  * much more efficient and 'good enough'
1599  */
1600  if (mflags&P_NEW_MAP)
1601  m->timeout = 50;
1602  }
1603  }
1604 
1605  /* do LOS after calls to update_position */
1606  if (pl->contr->do_los) {
1607  update_los(pl);
1608  pl->contr->do_los = 0;
1609  }
1610 
1612 }
1613 
1614 void esrv_map_scroll(socket_struct *ns, int dx, int dy) {
1615  struct Map newmap;
1616  int x, y, mx, my;
1617 
1618  ns->map_scroll_x += dx;
1619  ns->map_scroll_y += dy;
1620 
1621  mx = ns->mapx+MAX_HEAD_OFFSET;
1622  my = ns->mapy+MAX_HEAD_OFFSET;
1623 
1624  /* the x and y here are coordinates for the new map, i.e. if we moved
1625  * (dx,dy), newmap[x][y] = oldmap[x-dx][y-dy]. For this reason,
1626  * if the destination x or y coordinate is outside the viewable
1627  * area, we clear the values - otherwise, the old values
1628  * are preserved, and the check_head thinks it needs to clear them.
1629  */
1630  for (x = 0; x < mx; x++) {
1631  for (y = 0; y < my; y++) {
1632  if (x >= ns->mapx || y >= ns->mapy) {
1633  /* clear cells outside the viewable area */
1634  memset(&newmap.cells[x][y], 0, sizeof(newmap.cells[x][y]));
1635  } else if (x+dx < 0 || x+dx >= ns->mapx || y+dy < 0 || y+dy >= ns->mapy) {
1636  /* clear newly visible tiles within the viewable area */
1637  memset(&newmap.cells[x][y], 0, sizeof(newmap.cells[x][y]));
1638  } else {
1639  memcpy(&newmap.cells[x][y], &ns->lastmap.cells[x+dx][y+dy], sizeof(newmap.cells[x][y]));
1640  }
1641  }
1642  }
1643 
1644  memcpy(&ns->lastmap, &newmap, sizeof(ns->lastmap));
1645 }
1646 
1652 void send_plugin_custom_message(object *pl, char *buf) {
1653  SockList sl;
1654 
1655  SockList_Init(&sl);
1656  SockList_AddString(&sl, buf);
1657  Send_With_Handling(pl->contr->socket, &sl);
1658  SockList_Term(&sl);
1659 }
1660 
1667  SockList sl;
1668  int flags = 0;
1669  client_spell *spell_info;
1670 
1671  if (!pl->socket || !pl->socket->monitor_spells)
1672  return;
1673 
1674  /* Handles problem at login, where this is called from fix_object
1675  * before we have had a chance to send spells to the player. It does seem
1676  * to me that there should never be a case where update_spells is called
1677  * before add_spells has been called. Add_spells() will update the
1678  * spell_state to non null.
1679  */
1680  if (!pl->spell_state)
1681  return;
1682 
1683  FOR_INV_PREPARE(pl->ob, spell) {
1684  if (spell->type == SPELL) {
1685  spell_info = get_client_spell_state(pl, spell);
1686  /* check if we need to update it*/
1687  if (spell_info->last_sp != SP_level_spellpoint_cost(pl->ob, spell, SPELL_MANA)) {
1688  spell_info->last_sp = SP_level_spellpoint_cost(pl->ob, spell, SPELL_MANA);
1689  flags |= UPD_SP_MANA;
1690  }
1691  if (spell_info->last_grace != SP_level_spellpoint_cost(pl->ob, spell, SPELL_GRACE)) {
1692  spell_info->last_grace = SP_level_spellpoint_cost(pl->ob, spell, SPELL_GRACE);
1693  flags |= UPD_SP_GRACE;
1694  }
1695  if (spell_info->last_dam != spell->stats.dam+SP_level_dam_adjust(pl->ob, spell)) {
1696  spell_info->last_dam = spell->stats.dam+SP_level_dam_adjust(pl->ob, spell);
1697  flags |= UPD_SP_DAMAGE;
1698  }
1699  if (flags != 0) {
1700  SockList_Init(&sl);
1701  SockList_AddString(&sl, "updspell ");
1702  SockList_AddChar(&sl, flags);
1703  SockList_AddInt(&sl, spell->count);
1704  if (flags&UPD_SP_MANA)
1705  SockList_AddShort(&sl, spell_info->last_sp);
1706  if (flags&UPD_SP_GRACE)
1707  SockList_AddShort(&sl, spell_info->last_grace);
1708  if (flags&UPD_SP_DAMAGE)
1709  SockList_AddShort(&sl, spell_info->last_dam);
1710  flags = 0;
1711  Send_With_Handling(pl->socket, &sl);
1712  SockList_Term(&sl);
1713  }
1714  }
1715  } FOR_INV_FINISH();
1716 }
1717 
1718 void esrv_remove_spell(player *pl, object *spell) {
1719  SockList sl;
1720 
1721  if (!pl || !spell || spell->env != pl->ob) {
1722  LOG(llevError, "Invalid call to esrv_remove_spell\n");
1723  return;
1724  }
1725  if (!pl->socket->monitor_spells)
1726  return;
1727 
1728  SockList_Init(&sl);
1729  SockList_AddString(&sl, "delspell ");
1730  SockList_AddInt(&sl, spell->count);
1731  Send_With_Handling(pl->socket, &sl);
1732  SockList_Term(&sl);
1733 }
1734 
1742  SockList sl;
1743 
1744  if (!pl->socket->want_pickup)
1745  return;
1746  SockList_Init(&sl);
1747  SockList_AddString(&sl, "pickup ");
1748  SockList_AddInt(&sl, pl->mode);
1749  Send_With_Handling(pl->socket, &sl);
1750  SockList_Term(&sl);
1751 }
1752 
1761 static int spell_client_use(const object *spell) {
1762  switch (spell->type)
1763  {
1764  case SP_RAISE_DEAD:
1765  case SP_MAKE_MARK:
1766  return 3;
1767  case SP_RUNE:
1768  if (!spell->other_arch)
1769  return 1;
1770  break;
1771  case SP_CREATE_FOOD:
1772  case SP_CREATE_MISSILE:
1773  return 2;
1774  case SP_SUMMON_MONSTER:
1775  if (spell->randomitems != NULL)
1776  return 2;
1777  /* break; */// If add conditins below, use this break statement
1778  }
1779  // This is not in the switch statement so that it supports fallthrough logic
1780  // on the few spell types that have additional conditions attached.
1781  return 0;
1782 }
1783 
1785 static void append_spell(player *pl, SockList *sl, object *spell) {
1786  client_spell *spell_info;
1787  int len, i, skill = 0;
1788 
1789  if (!spell->name) {
1790  LOG(llevError, "item number %d is a spell with no name.\n", spell->count);
1791  return;
1792  }
1793 
1794  if (spell->face && !(pl->socket->faces_sent[spell->face->number]&NS_FACESENT_FACE))
1795  esrv_send_face(pl->socket, spell->face, 0);
1796 
1797  spell_info = get_client_spell_state(pl, spell);
1798  SockList_AddInt(sl, spell->count);
1799  SockList_AddShort(sl, spell->level);
1800  SockList_AddShort(sl, spell->casting_time);
1801  /* store costs and damage in the object struct, to compare to later */
1802  spell_info->last_sp = SP_level_spellpoint_cost(pl->ob, spell, SPELL_MANA);
1803  spell_info->last_grace = SP_level_spellpoint_cost(pl->ob, spell, SPELL_GRACE);
1804  spell_info->last_dam = spell->stats.dam+SP_level_dam_adjust(pl->ob, spell);
1805  /* send the current values */
1806  SockList_AddShort(sl, spell_info->last_sp);
1807  SockList_AddShort(sl, spell_info->last_grace);
1808  SockList_AddShort(sl, spell_info->last_dam);
1809 
1810  /* figure out which skill it uses, if it uses one */
1811  if (spell->skill) {
1812  for (i = 0; i < MAX_SKILLS && skill_names[i]; i++)
1813  if (!strcmp(spell->skill, skill_names[i])) {
1814  skill = i+CS_STAT_SKILLINFO;
1815  break;
1816  }
1817  }
1818  SockList_AddChar(sl, skill);
1819 
1820  SockList_AddInt(sl, spell->path_attuned);
1821  SockList_AddInt(sl, spell->face ? spell->face->number : 0);
1822  SockList_AddLen8Data(sl, spell->name, strlen(spell->name));
1823 
1824  if (!spell->msg) {
1825  SockList_AddShort(sl, 0);
1826  } else {
1827  len = strlen(spell->msg);
1828  SockList_AddShort(sl, len);
1829  SockList_AddData(sl, spell->msg, len);
1830  }
1831 
1832  /* Extended spell information available if the client wants it.
1833  */
1834  if (pl->socket->monitor_spells >= 2) {
1835  /* spellmon 2
1836  */
1837  sstring req = object_get_value(spell, "casting_requirements");
1838 
1839  SockList_AddChar(sl, spell_client_use(spell)); /* Usage code */
1840 
1841  if (req) { /* Requirements */
1842  SockList_AddLen8Data(sl, req, strlen(req));
1843  } else {
1844  SockList_AddChar(sl, 0);
1845  }
1846  /* end spellmon 2
1847  */
1848  }
1849 }
1850 
1855 void esrv_add_spells(player *pl, object *spell) {
1856  SockList sl;
1857  size_t size;
1858  sstring value;
1859 
1860  if (!pl) {
1861  LOG(llevError, "esrv_add_spells, tried to add a spell to a NULL player\n");
1862  return;
1863  }
1864 
1865  if (!pl->socket->monitor_spells)
1866  return;
1867 
1868  SockList_Init(&sl);
1869  SockList_AddString(&sl, "addspell ");
1870  if (!spell) {
1871  FOR_INV_PREPARE(pl->ob, spell) {
1872  if (spell->type != SPELL)
1873  continue;
1874  /* Were we to simply keep appending data here, we could
1875  * exceed the SockList buffer if the player has enough spells
1876  * to add. We know that append_spell will always append
1877  * 23 data bytes, plus 3 length bytes and 2 strings
1878  * (because that is the spec) so we need to check that
1879  * the length of those 2 strings, plus the 26 bytes,
1880  * won't take us over the length limit for the socket.
1881  * If it does, we need to send what we already have,
1882  * and restart packet formation.
1883  */
1884  size = 26+strlen(spell->name)+(spell->msg ? strlen(spell->msg) : 0);
1885  if (pl->socket->monitor_spells >= 2) {
1887  value = object_get_value(spell, "casting_requirements");
1888  size += 2 + (value ? strlen(value) : 0);
1889  }
1890  if (SockList_Avail(&sl) < size) {
1891  Send_With_Handling(pl->socket, &sl);
1892  SockList_Reset(&sl);
1893  SockList_AddString(&sl, "addspell ");
1894  }
1895  append_spell(pl, &sl, spell);
1896  } FOR_INV_FINISH();
1897  } else if (spell->type != SPELL) {
1898  LOG(llevError, "Asked to send a non-spell object as a spell\n");
1899  return;
1900  } else
1901  append_spell(pl, &sl, spell);
1902  /* finally, we can send the packet */
1903  Send_With_Handling(pl->socket, &sl);
1904  SockList_Term(&sl);
1905 }
1906 
1907 /* sends a 'tick' information to the client.
1908  * We also take the opportunity to toggle TCP_NODELAY -
1909  * this forces the data in the socket to be flushed sooner to the
1910  * client - otherwise, the OS tries to wait for full packets
1911  * and will this hold sending the data for some amount of time,
1912  * which thus adds some additional latency.
1913  */
1915  SockList sl;
1916 #ifdef WIN32
1917  char tmp;
1918 #else
1919  int tmp;
1920 #endif
1921 
1922  SockList_Init(&sl);
1923  SockList_AddString(&sl, "tick ");
1924  SockList_AddInt(&sl, pticks);
1925  tmp = 1;
1926  if (setsockopt(pl->socket->fd, IPPROTO_TCP, TCP_NODELAY, &tmp, sizeof(tmp)))
1927  LOG(llevError, "send_tick: Unable to turn on TCP_NODELAY\n");
1928 
1929  Send_With_Handling(pl->socket, &sl);
1930  tmp = 0;
1931  if (setsockopt(pl->socket->fd, IPPROTO_TCP, TCP_NODELAY, &tmp, sizeof(tmp)))
1932  LOG(llevError, "send_tick: Unable to turn off TCP_NODELAY\n");
1933  SockList_Term(&sl);
1934 }
1935 
1948 static void add_char_field(SockList *sl, int type, const char *data)
1949 {
1950  int len;
1951 
1952  len = strlen(data);
1953 
1954  if (len) {
1955  /* one extra for length for the type byte */
1956  SockList_AddChar(sl, len+1);
1957  SockList_AddChar(sl, type);
1958  SockList_AddString(sl, data);
1959  }
1960 }
1961 
1983 {
1984  SockList sl;
1985  int num_chars;
1986  linked_char *extra;
1987 
1988  if (ns->account_chars) {
1990  }
1992 
1993  num_chars = 0;
1994  extra = account_get_additional_chars(ns->account_name, ns->account_chars, &num_chars);
1995 
1996  SockList_Init(&sl);
1997  SockList_AddString(&sl, "accountplayers ");
1998 
1999  SockList_AddChar(&sl, static_cast<char>(ns->account_chars->chars.size() + num_chars));
2000 
2001  /* Now add real character data */
2002  for (auto acn : ns->account_chars->chars) {
2003  uint16_t faceno = 0;
2004 
2005  /* Ignore a dead character. They don't need to show up. */
2006  if (acn->isDead) {
2007  continue;
2008  }
2009 
2010  add_char_field(&sl, ACL_NAME, acn->name);
2011  add_char_field(&sl, ACL_CLASS, acn->character_class);
2012  add_char_field(&sl, ACL_RACE, acn->race);
2013  add_char_field(&sl, ACL_FACE, acn->face);
2014  if (acn->face[0] != 0 ) {
2015  const Face *face = try_find_face(acn->face, NULL);
2016 
2017  if (face != NULL) {
2018  if (!(ns->faces_sent[face->number]&NS_FACESENT_FACE)) {
2019  esrv_send_face(ns, face, 0);
2020  }
2021  faceno = face->number;
2022  }
2023  }
2024 
2025  add_char_field(&sl, ACL_PARTY, acn->party);
2026  add_char_field(&sl, ACL_MAP, acn->map);
2027  SockList_AddChar(&sl, 3);
2029  SockList_AddShort(&sl, acn->level);
2030  if (faceno) {
2031  SockList_AddChar(&sl, 3);
2033  SockList_AddShort(&sl, faceno);
2034  }
2035 
2036  SockList_AddChar(&sl, 0);
2037  }
2038  /* Now for any characters where we just have the name */
2039  for (linked_char *e = extra; e != NULL; e = e->next) {
2040  add_char_field(&sl, ACL_NAME, e->name);
2041  SockList_AddChar(&sl, 0);
2042  }
2043 
2044  Send_With_Handling(ns, &sl);
2045  SockList_Term(&sl);
2046 
2047  if (extra) {
2048  free_charlinks(extra);
2049  }
2050 }
2051 
2073 static int decode_name_password(const char *buf, int *len, char *name, char *password)
2074 {
2075  int nlen, plen;
2076 
2077  if (*len < 2) {
2078  return 1;
2079  }
2080 
2081  nlen = (unsigned char)buf[0];
2082  if (nlen >= MAX_BUF || nlen > *len-2) {
2083  return 1;
2084  }
2085  memcpy(name, buf+1, nlen);
2086  name[nlen] = 0;
2087 
2088  plen = (unsigned char)buf[nlen+1];
2089  if (plen >= MAX_BUF || plen > *len-2-nlen) {
2090  return 2;
2091  }
2092  memcpy(password, buf+2+nlen, plen);
2093  password[plen] = 0;
2094 
2095  *len = nlen+plen+2;
2096 
2097  return 0;
2098 }
2109 void account_login_cmd(char *buf, int len, socket_struct *ns) {
2110  char name[MAX_BUF], password[MAX_BUF];
2111  int status;
2112  SockList sl;
2113 
2114  if (len <= 0 || !buf) {
2115  LOG(llevDebug, "IP '%s' sent bogus add_player_cmd information\n", ns->host);
2116  return;
2117  }
2118 
2119  SockList_Init(&sl);
2120 
2121  status = decode_name_password(buf, &len, name, password);
2122 
2123  if (status == 1) {
2124  SockList_AddString(&sl, "failure accountlogin Name is too long");
2125  Send_With_Handling(ns, &sl);
2126  SockList_Term(&sl);
2127  return;
2128  }
2129  if (status == 2) {
2130  SockList_AddString(&sl, "failure accountlogin Password is too long");
2131  Send_With_Handling(ns, &sl);
2132  SockList_Term(&sl);
2133  return;
2134  }
2135 
2136  if (!account_exists(name)) {
2137  SockList_AddString(&sl, "failure accountlogin No such account name exists on this server");
2138  Send_With_Handling(ns, &sl);
2139  SockList_Term(&sl);
2140  return;
2141  }
2142 
2143  if (account_login(name, password)) {
2144  LOG(llevInfo, "Account login for '%s' from %s\n", name, ns->host);
2145 
2146  if (ns->account_name) free(ns->account_name);
2147  /* We want to store away official name so we do not
2148  * have any case sensitivity issues on the files.
2149  * because we have already checked password, we
2150  * know that account_exists should never return NULL in
2151  * this case.
2152  */
2154 
2156  } else {
2157  LOG(llevInfo, "Failed account login for '%s' from %s\n", name, ns->host);
2158  SockList_AddString(&sl, "failure accountlogin Incorrect password for account");
2159  Send_With_Handling(ns, &sl);
2160  SockList_Term(&sl);
2161  }
2162 }
2163 
2172 static int account_block_create(const socket_struct *ns) {
2173  /* Check if account creation is blocked. */
2175  /* Account creation is allowed for everyone. */
2176  return 0;
2177  }
2178 
2179  /* Has the trusted host been defined? */
2180  if(settings.account_trusted_host == NULL) {
2181  /* No, allocate it and set it to localhost now. */
2183  }
2184 
2185  /* Return false if the client connected from the trusted host. */
2186  if(strcmp(ns->host, settings.account_trusted_host) == 0){
2187  return 0;
2188  }
2189 
2190  /*
2191  * If we are here, then we are blocking account create and we do
2192  * not trust this client's IP address.
2193  */
2194  return 1;
2195 }
2196 
2208 void account_new_cmd(char *buf, int len, socket_struct *ns) {
2209  char name[MAX_BUF], password[MAX_BUF];
2210  int status;
2211  SockList sl;
2212 
2213  if (len <= 0 || !buf) {
2214  LOG(llevDebug, "IP '%s' sent bogus add_player_cmd information\n", ns->host);
2215  return;
2216  }
2217 
2218  SockList_Init(&sl);
2219 
2220  status = decode_name_password(buf, &len, name, password);
2221 
2222  if (account_block_create(ns)) {
2223  LOG(llevInfo, "Account create blocked from %s\n", ns->host);
2224  SockList_AddString(&sl, "failure accountnew Account creation is disabled");
2225  Send_With_Handling(ns, &sl);
2226  SockList_Term(&sl);
2227  return;
2228  }
2229 
2230  if (status == 1) {
2231  SockList_AddString(&sl, "failure accountnew Name is too long");
2232  Send_With_Handling(ns, &sl);
2233  SockList_Term(&sl);
2234  return;
2235  }
2236  if (status == 2) {
2237  SockList_AddString(&sl, "failure accountnew Password is too long");
2238  Send_With_Handling(ns, &sl);
2239  SockList_Term(&sl);
2240  return;
2241  }
2242  /*The minimum length isn't exactly required, but in the current implementation,
2243  * client will send the same password for character for which there is a
2244  * 2 character minimum size. Thus an account with a one character password
2245  * won't be able to create a character. */
2246  if (strlen(name)<settings.min_name) {
2247  SockList_AddString(&sl, "failure accountnew Name is too short");
2248  Send_With_Handling(ns, &sl);
2249  SockList_Term(&sl);
2250  return;
2251  }
2252  if (strlen(password)<2) {
2253  SockList_AddString(&sl, "failure accountnew Password is too short");
2254  Send_With_Handling(ns, &sl);
2255  SockList_Term(&sl);
2256  return;
2257  }
2258 
2259  if (account_exists(name)) {
2260  SockList_AddString(&sl, "failure accountnew That account already exists on this server");
2261  Send_With_Handling(ns, &sl);
2262  SockList_Term(&sl);
2263  return;
2264  }
2265 
2267  if (status == 1) {
2268  SockList_AddString(&sl,
2269  "failure accountnew That account name contains invalid characters.");
2270  Send_With_Handling(ns, &sl);
2271  SockList_Term(&sl);
2272  return;
2273  }
2274 
2275  if (status == 2) {
2276  SockList_AddString(&sl,
2277  "failure accountnew That account name is too long");
2278  Send_With_Handling(ns, &sl);
2279  SockList_Term(&sl);
2280  return;
2281  }
2282 
2283  status = account_check_string(password);
2284  if (status == 1) {
2285  SockList_AddString(&sl,
2286  "failure accountnew That password contains invalid characters.");
2287  Send_With_Handling(ns, &sl);
2288  SockList_Term(&sl);
2289  return;
2290  }
2291 
2292  if (status == 2) {
2293  SockList_AddString(&sl,
2294  "failure accountnew That password is too long");
2295  Send_With_Handling(ns, &sl);
2296  SockList_Term(&sl);
2297  return;
2298  }
2299 
2300  /* If we got here, we passed all checks - so now add it */
2301  if (ns->account_name) free(ns->account_name);
2303  account_new(name, password);
2304  /* save account information */
2305  accounts_save();
2307 }
2308 
2322 void account_add_player_cmd(char *buf, int len, socket_struct *ns) {
2323  char name[MAX_BUF], password[MAX_BUF];
2324  int status, force, nlen;
2325  SockList sl;
2326  const char *cp;
2327 
2328  if (len <= 0 || !buf) {
2329  LOG(llevDebug, "IP '%s' sent bogus add_player_cmd information\n", ns->host);
2330  return;
2331  }
2332 
2333  SockList_Init(&sl);
2334 
2335  if (ns->account_name == NULL) {
2336  SockList_AddString(&sl, "failure accountaddplayer Not logged in");
2337  Send_With_Handling(ns, &sl);
2338  SockList_Term(&sl);
2339  return;
2340  }
2341 
2342  force = buf[0];
2343  nlen = len - 1;
2344  status = decode_name_password(buf+1, &nlen, name, password);
2345  if (status == 1) {
2346  SockList_AddString(&sl, "failure accountaddplayer Name is too long");
2347  Send_With_Handling(ns, &sl);
2348  SockList_Term(&sl);
2349  return;
2350  }
2351  if (status == 2) {
2352  SockList_AddString(&sl, "failure accountaddplayer Password is too long");
2353  Send_With_Handling(ns, &sl);
2354  SockList_Term(&sl);
2355  return;
2356  }
2357 
2358  status = verify_player(name, password);
2359  if (status) {
2360  /* From a security standpoint, telling random folks if it
2361  * it as wrong password makes it easier to hack. However,
2362  * it is fairly easy to determine what characters exist on a server
2363  * (either by trying to create a new one and see if the name is in
2364  * in use, or just looking at the high score file), so this
2365  * really does not make things much less secure
2366  */
2367  if (status == 1)
2368  SockList_AddString(&sl, "failure accountaddplayer 0 The character does not exist.");
2369  else
2370  SockList_AddString(&sl, "failure accountaddplayer 0 That password is incorrect.");
2371 
2372  Send_With_Handling(ns, &sl);
2373  SockList_Term(&sl);
2374  return;
2375  }
2376  /* Check to see if this character is associated with an account.
2377  */
2379  if (cp) {
2380  if (!strcmp(cp, ns->account_name)) {
2381  SockList_AddString(&sl, "failure accountaddplayer 0 That character is already connected to this account.");
2382  Send_With_Handling(ns, &sl);
2383  SockList_Term(&sl);
2384  return;
2385  } else {
2386  if (!force) {
2387  SockList_AddString(&sl, "failure accountaddplayer 1 That character is already connected to a different account.");
2388  Send_With_Handling(ns, &sl);
2389  SockList_Term(&sl);
2390  return;
2391  } else if (account_is_logged_in(cp)) {
2392  /* We could be clever and try to handle this case, but it is
2393  * trickier. If the character is logged in, it has to
2394  * be logged out. And the socket holds some data which
2395  * needs to be cleaned up. Since it should be fairly
2396  * uncommon that users need to do this, just disallowing
2397  * it makes things a lot simpler.
2398  */
2399  SockList_AddString(&sl, "failure accountaddplayer 0 That character is already connected to a different account which is currently logged in.");
2400  Send_With_Handling(ns, &sl);
2401  SockList_Term(&sl);
2402  return;
2403  }
2404  }
2405  }
2406  /* If we have gotten this far, the name/password provided is OK,
2407  * and the character is not associated with a different account (or
2408  * force is true). Now try to add the character to this account.
2409  */
2411 
2412  /* This should never happen, but check for it just in case -
2413  * if we were able to log in, the account should exist. but
2414  * if this fails, need to give the user some clue.
2415  */
2416  if (status==1) {
2417  SockList_AddString(&sl, "failure accountaddplayer 0 Could not find your account.");
2418  Send_With_Handling(ns, &sl);
2419  SockList_Term(&sl);
2420  return;
2421  } else if (status == 2) {
2422  SockList_AddString(&sl, "failure accountaddplayer 0 You have reached the maximum number of characters allowed per account.");
2423  Send_With_Handling(ns, &sl);
2424  SockList_Term(&sl);
2425  return;
2426  }
2427 
2428  /* If cp is set, then this character used to belong to a different
2429  * account. Remove it now.
2430  */
2431  if (cp) {
2432  Account_Chars *chars;
2433 
2435  chars = account_char_load(cp);
2436  account_char_remove(chars, name);
2437  account_char_save(chars);
2438  account_char_free(chars);
2439  }
2440 
2442 
2443  /* store data so nothing is lost in case of crash */
2445 }
2446 
2451 void account_play_cmd(char *buf, int len, socket_struct *ns)
2452 {
2453  char **chars;
2454  int i;
2455  SockList sl;
2456  player *pl;
2457 
2458  if (len <= 0 || !buf) {
2459  LOG(llevDebug, "IP '%s' sent bogus account_play_cmd information\n", ns->host);
2460  return;
2461  }
2462 
2463  SockList_Init(&sl);
2464 
2465  if (ns->status != Ns_Add) {
2466  SockList_AddString(&sl, "failure accountplay Not allowed right now");
2467  Send_With_Handling(ns, &sl);
2468  SockList_Term(&sl);
2469  return;
2470  }
2471 
2472  if (!buf[0]) {
2473  SockList_AddString(&sl, "failure accountplay Malformed character name");
2474  Send_With_Handling(ns, &sl);
2475  SockList_Term(&sl);
2476  return;
2477  }
2478 
2479  if (ns->account_name == NULL) {
2480  SockList_AddString(&sl, "failure accountplay Not logged in");
2481  Send_With_Handling(ns, &sl);
2482  SockList_Term(&sl);
2483  return;
2484  }
2485 
2486  /* Make sure a client is not trying to spoof us here */
2488 
2489  for (i=0; chars[i]; i++) {
2490  if (strcmp(chars[i], buf) == 0)
2491  break;
2492  }
2493  if (!chars[i]) {
2494  SockList_AddPrintf(&sl,
2495  "failure accountplay Character %s is not associated with account %s",
2496  buf, ns->account_name);
2497  Send_With_Handling(ns, &sl);
2498  SockList_Term(&sl);
2499  return;
2500  }
2501 
2502  for (pl = first_player; pl; pl = pl->next) {
2503  if (pl->ob && pl->socket != ns && strcmp(buf, pl->ob->name) == 0 && pl->state != ST_PLAY_AGAIN && pl->state != ST_GET_NAME) {
2504  SockList_AddPrintf(&sl,
2505  "failure accountplay Character %s is already playing",
2506  buf);
2507  Send_With_Handling(ns, &sl);
2508  SockList_Term(&sl);
2509  return;
2510  }
2511  }
2512 
2513  /* from a protocol standpoint, accountplay can be used
2514  * before there is a player structure (first login) or after
2515  * (character has logged in and is changing characters).
2516  * Checkthe sockets for that second case - if so,
2517  * we don't need to make a new player object, etc.
2518  */
2519  for (pl=first_player; pl; pl=pl->next) {
2520  if (pl->socket == ns) {
2521  /* The player still in the socket must be saved first. */
2522  save_player(pl->ob, 0);
2523  break;
2524  }
2525  }
2526 
2527  /* Some of this logic is from add_player()
2528  * we just don't use add_player() as it does some other work
2529  * we don't really want to do.
2530  */
2531  if (!pl) {
2532  pl = get_player(NULL);
2533  set_player_socket(pl, ns);
2534  ns->status = Ns_Avail;
2535  ns->account_chars = NULL;
2536  SockList_ResetRead(&pl->socket->inbuf);
2537  } else {
2538  pl->state = ST_PLAYING;
2539  }
2540 
2541  pl->ob->name = add_string(buf);
2542  check_login(pl->ob, NULL);
2543 
2544  SockList_AddString(&sl, "addme_success");
2545  Send_With_Handling(ns, &sl);
2546  SockList_Term(&sl);
2547 }
2548 
2549 #define MAX_CHOICES 100
2550 
2556 void create_player_cmd(char *buf, int len, socket_struct *ns)
2557 {
2558  char name[MAX_BUF], password[MAX_BUF], *choices[MAX_CHOICES];
2559  int status, nlen, choice_num=0, i;
2560  SockList sl;
2561  player *pl;
2562  archetype *map=NULL, *race_a=NULL, *class_a=NULL;
2563  living new_stats;
2564 
2565  if (len <= 0 || !buf) {
2566  LOG(llevDebug, "IP '%s' sent bogus create_player_cmd information\n", ns->host);
2567  return;
2568  }
2569 
2570  SockList_Init(&sl);
2571 
2572  if (ns->status != Ns_Add) {
2573  SockList_AddString(&sl, "failure createplayer Not allowed right now");
2574  Send_With_Handling(ns, &sl);
2575  SockList_Term(&sl);
2576  return;
2577  }
2578 
2579  nlen = len;
2580  status = decode_name_password(buf, &nlen, name, password);
2581  if (status == 1) {
2582  SockList_AddString(&sl, "failure createplayer Name is too long");
2583  Send_With_Handling(ns, &sl);
2584  SockList_Term(&sl);
2585  return;
2586  }
2587 
2588  /* Minimum character name limit (if set) */
2589  if (strlen(name)<settings.min_name) {
2590  SockList_AddString(&sl, "failure createplayer Name is too short");
2591  Send_With_Handling(ns, &sl);
2592  SockList_Term(&sl);
2593  return;
2594  }
2595 
2596  if (playername_ok(name) == 0) {
2597  SockList_AddString(&sl, "failure createplayer Player name contains invalid characters");
2598  Send_With_Handling(ns, &sl);
2599  SockList_Term(&sl);
2600  return;
2601  }
2602 
2603  /* 2 characters minimum for password */
2604  if (strlen(password)<2) {
2605  SockList_AddString(&sl, "failure createplayer Password is too short");
2606  Send_With_Handling(ns, &sl);
2607  SockList_Term(&sl);
2608  return;
2609  }
2610 
2612  if (status == 2) {
2613  SockList_AddString(&sl, "failure createplayer Password is too long");
2614  Send_With_Handling(ns, &sl);
2615  SockList_Term(&sl);
2616  return;
2617  }
2618 
2619  /* This is a fairly ugly solution - we're truncating the password.
2620  * however, the password information for characters is really
2621  * a legacy issue - when every character is associated with
2622  * an account, legacy login (character name/password) will get
2623  * removed, at which point the only use for password might be
2624  * to move characters from one account to another, but not sure
2625  * if that is something we want to allow.
2626  */
2627  if (strlen(password)>17)
2628  password[16] = 0;
2629 
2630  /* We just can't call check_name(), since that uses draw_info() to
2631  * report status. We are also more permissive on names, so we use
2632  * account_check_string() - if that is safe for account, also safe
2633  * for player names.
2634  */
2635  if (account_check_string(name)) {
2636  SockList_AddString(&sl, "failure createplayer The name contains illegal characters");
2637  Send_With_Handling(ns, &sl);
2638  SockList_Term(&sl);
2639  return;
2640  }
2641 
2642  /* 1 means no such player, 0 is correct name/password (which in this
2643  * case, is an error), and 2 is incorrect password. Only way we
2644  * go onward is if there is no such player.
2645  */
2646  if (verify_player(name, password) != 1) {
2647  SockList_AddString(&sl, "failure createplayer That name is already in use");
2648  Send_With_Handling(ns, &sl);
2649  SockList_Term(&sl);
2650  return;
2651  }
2652 
2653  /* from a protocol standpoint, accountplay can be used
2654  * before there is a player structure (first login) or after
2655  * (character has logged in and is changing characters).
2656  * Check the sockets for that second case - if so,
2657  * we don't need to make a new player object, etc.
2658  */
2659  for (pl=first_player; pl; pl=pl->next)
2660  if (pl->socket == ns) {
2661  if (pl->ob->name) {
2662  if (!strcmp(pl->ob->name, name)) {
2663  /* For some reason not only the socket is the same but also
2664  * the player is already playing. If this happens at this
2665  * point let's assume the character never was able to apply
2666  * a bet of reality to make a correct first-time save.
2667  * So, for safety remove it and start over.
2668  */
2669  if (!QUERY_FLAG(pl->ob, FLAG_REMOVED))
2670  object_remove(pl->ob);
2671  }
2672  else {
2673  /* If this is a different player on the same socket, then we
2674  * need to make sure that the old one is not connected to the player
2675  *
2676  * This prevents bizarre scenarios where the player is on the map
2677  * multiple times (from multiple createplayer commands), and
2678  * only one of them is controlled by the player.
2679  */
2680  if (pl->ob->contr == pl) {
2681  if (!QUERY_FLAG(pl->ob, FLAG_REMOVED))
2682  object_remove(pl->ob);
2683  }
2684  }
2685  }
2686  break;
2687  }
2688 
2689  /* In this mode, we have additional data
2690  * Note that because there are a lot of failure cases in here
2691  * (where we end up not creating the new player), the code
2692  * to create the new player is done within this routine
2693  * after all checks pass. Note that all of the checks
2694  * done are done without using the player structure,
2695  * as pl may be null right now.
2696  */
2697  if (ns->login_method >= 2) {
2698  int i, j, stat_total=0;
2699  char *key, *value, *race=NULL, *class_name=NULL;
2700 
2701  /* By setting this to zero, then we can easily
2702  * check to see if all stats have been set.
2703  */
2704  memset(&new_stats, 0, sizeof(living));
2705 
2706  while (nlen < len) {
2707  i = buf[nlen]; /* Length of this line */
2708  /* Sanity check from client - don't want to loop
2709  * forever if there is a 0 length, and don't
2710  * want to read beyond size of packet.
2711  * Likewise, client should have sent
2712  * the string to us already null terminated,
2713  * but we will just make sure.
2714  */
2715  if ((i == 0) || (nlen + i > len)) break;
2716  buf[nlen + i] = 0;
2717 
2718  /* What we have are a series of lines -
2719  * 'key value' format. Find that space,
2720  * and null it out so we can do strcasecmp.
2721  * If no space, abort processing
2722  */
2723  key = buf + nlen + 1;
2724  value = strchr(key, ' ');
2725  if (!value) break;
2726  *value = 0;
2727  value++;
2728 
2729  if (!strcasecmp(key,"race")) race = value;
2730  else if (!strcasecmp(key,"class")) class_name = value;
2731  else if (!strcasecmp(key,"starting_map")) {
2733  if (!map || map->clone.type != MAP || map->clone.subtype !=MAP_TYPE_CHOICE) {
2734  SockList_AddString(&sl,
2735  "failure createplayer Invalid starting map");
2736  Send_With_Handling(ns, &sl);
2737  SockList_Term(&sl);
2738  return;
2739  }
2740  }
2741  else if (!strcasecmp(key,"choice")) {
2742  /* In general, MAX_CHOICES should be large enough
2743  * to always handle the choices from the client - of
2744  * course, the client could be broken and send us many
2745  * more choices than we should have, so handle that.
2746  */
2747  if (choice_num == MAX_CHOICES) {
2748  LOG(llevError,
2749  "Number of choices receive exceed max value: %d>%d\n",
2750  choice_num, MAX_CHOICES);
2751  } else {
2752  choices[choice_num] = value;
2753  choice_num++;
2754  }
2755  }
2756  else {
2757  /* Do stat processing here */
2758  for (j=0; j < NUM_STATS; j++) {
2759  if (!strcasecmp(key,short_stat_name[j])) {
2760  int val = atoi(value);
2761 
2762  set_attr_value(&new_stats, j, val);
2763  break;
2764  }
2765  }
2766  if (j >= NUM_STATS) {
2767  /* Bad clients could do this - we should at least report
2768  * it, and useful when trying to add new parameters.
2769  */
2770  LOG(llevError, "Got unknown key/value from client: %s %s\n", key, value);
2771  }
2772  }
2773  nlen += i + 1;
2774  }
2775  /* Do some sanity checking now. But checking the stat
2776  * values here, we will catch any 0 values since we do
2777  * a memset above. A properly behaving client should
2778  * never do any of these things, but we do not presume
2779  * clients will behave properly.
2780  */
2781  for (j=0; j<NUM_STATS; j++) {
2782  int val = get_attr_value(&new_stats, j);
2783 
2784  stat_total += val;
2785  if (val > settings.starting_stat_max ||
2786  val < settings.starting_stat_min) {
2787  SockList_AddPrintf(&sl,
2788  "failure createplayer Stat value is out of range - %d must be between %d and %d",
2790  Send_With_Handling(ns, &sl);
2791  SockList_Term(&sl);
2792  return;
2793  }
2794  }
2795  if (stat_total > settings.starting_stat_points) {
2796  SockList_AddPrintf(&sl,
2797  "failure createplayer Total allocated statistics is higher than allowed (%d>%d)",
2798  stat_total, settings.starting_stat_points);
2799  Send_With_Handling(ns, &sl);
2800  SockList_Term(&sl);
2801  return;
2802  }
2803 
2804  if (race)
2805  race_a = try_find_archetype(race);
2806 
2807  if (class_name)
2808  class_a = try_find_archetype(class_name);
2809 
2810  /* This should never happen with a properly behaving client, so the error message
2811  * doesn't have to be that great.
2812  */
2813  if (!race_a || race_a->clone.type != PLAYER || !class_a || class_a->clone.type != CLASS) {
2814  SockList_AddString(&sl,
2815  "failure createplayer Invalid or unknown race or class");
2816  Send_With_Handling(ns, &sl);
2817  SockList_Term(&sl);
2818  return;
2819  }
2820 
2821  /* At current time, only way this can fail is if the adjusted
2822  * stat is less than 1.
2823  */
2824  if (check_race_and_class(&new_stats, race_a, class_a)) {
2825  SockList_AddString(&sl,
2826  "failure createplayer Unable to apply race or class - statistic is out of bounds");
2827  Send_With_Handling(ns, &sl);
2828  SockList_Term(&sl);
2829  return;
2830  }
2831 
2832  if (!pl)
2834  // If we already have a player, we a replaying on the same connection.
2835  // Since add_player normally sets ns->status, we still need that to happen.
2836  else
2837  ns->status = Ns_Avail;
2838 
2839  // We need to copy the name in before apply_race_and_class() because it
2840  // tells the client our character name. If we don't update it, they get the old one.
2841  FREE_AND_COPY(pl->ob->name, name);
2842 
2843  apply_race_and_class(pl->ob, race_a, class_a, &new_stats);
2844 
2845  } else {
2846  /* In thise case, old login method */
2847  if (!pl)
2848  pl = add_player(ns, ADD_PLAYER_NEW);
2849  // If we already have a player, we a replaying on the same connection.
2850  // Since add_player normally sets ns->status, we still need that to happen.
2851  else
2852  ns->status = Ns_Avail;
2853 
2854  // Make sure to do this on both code branches.
2855  FREE_AND_COPY(pl->ob->name, name);
2856 /* already done by add_player
2857  roll_again(pl->ob);
2858  pl->state = ST_ROLL_STAT;
2859  set_first_map(pl->ob);*/
2860  }
2861 
2862  /* add_player does a lot of the work, but there are a few
2863  * things we need to update, like starting name and
2864  * password.
2865  * This is done before processing in login_method>2.
2866  * The character creation process it does when
2867  * applying the race/class will use this
2868  * name information.
2869  */
2870  FREE_AND_COPY(pl->ob->name_pl, name);
2871  pl->name_changed = 1;
2872  safe_strncpy(pl->password, newhash(password), sizeof(pl->password));
2873 
2874  SockList_AddString(&sl, "addme_success");
2875  Send_With_Handling(ns, &sl);
2876  SockList_Term(&sl);
2877 
2878  if (ns->login_method >= 2) {
2879  /* The client could have provided us a map - if so, map will be set
2880  * and we don't want to overwrite it
2881  */
2882  if (!map)
2884  assert(map); // Existence checked in init_dynamic()
2885 
2886  enter_exit(pl->ob, &map->clone);
2887 
2888  if (pl->ob->map == NULL) {
2889  LOG(llevError, "Couldn't put player %s on start map %s!", pl->ob->name, map->name);
2890  abort();
2891  }
2892 
2893  /* copy information to bed of reality information, in case the player dies */
2894  safe_strncpy(pl->savebed_map, pl->ob->map->path, sizeof(pl->savebed_map));
2895  pl->bed_x = pl->ob->x;
2896  pl->bed_y = pl->ob->y;
2897 
2899  }
2900 
2901  /* We insert any objects after we have put the player on the map -
2902  * this makes things safer, as certain objects may expect a normal
2903  * environment. Note that choice_num will only be set in the
2904  * loginmethod > 2, which also checks (and errors out) if the
2905  * race/class is not set, which is why explicit checking for
2906  * those is not need.
2907  */
2908  for (i=0; i < choice_num; i++) {
2909  char *choiceval;
2910  const char *value, *cp;
2911  archetype *arch;
2912  object *op;
2913 
2914  choiceval = strchr(choices[i], ' ');
2915  if (!choiceval) {
2916  LOG(llevError, "Choice does not specify value: %s\n", choices[i]);
2917  continue;
2918  }
2919  *choiceval=0;
2920  choiceval++;
2921  value = object_get_value(&race_a->clone, choices[i]);
2922  if (!value)
2923  value = object_get_value(&class_a->clone, choices[i]);
2924 
2925  if (!value) {
2926  LOG(llevError, "Choice not found in archetype: %s\n", choices[i]);
2927  continue;
2928  }
2929  cp = strstr(value, choiceval);
2930  if (!cp) {
2931  LOG(llevError, "Choice value not found in archetype: %s %s\n",
2932  choices[i], choiceval);
2933  continue;
2934  }
2935 
2936  /* Check to make sure that the matched string is an entire word,
2937  * and not a substring (eg, valid choice being great_sword but
2938  * we just get sword) - the space after the match should either be a
2939  * space or null, and space before match should also be a space
2940  * or the start of the string.
2941  */
2942  if ((cp[strlen(choiceval)] != ' ') && (cp[strlen(choiceval)] != 0) &&
2943  (cp != value) && (*(cp-1) != ' ')) {
2944 
2945  LOG(llevError, "Choice value matches substring but not entire word: %s substring %s\n",
2946  choiceval, value);
2947  continue;
2948  }
2949  arch = try_find_archetype(choiceval);
2950  if (!arch) {
2951  LOG(llevError, "Choice value can not find archetype %s\n", choiceval);
2952  continue;
2953  }
2954  op = arch_to_object(arch);
2955  op = object_insert_in_ob(op, pl->ob);
2957  ob_apply(op, pl->ob, 0);
2958  }
2959 
2960  LOG(llevInfo, "new character %s from %s\n", pl->ob->name, pl->ob->contr->socket->host);
2963  "%s has entered the game.", pl->ob->name);
2964 }
2965 
2976 void account_password(char *buf, int len, socket_struct *ns) {
2977  char old[MAX_BUF], change[MAX_BUF];
2978  int status;
2979  SockList sl;
2980 
2981  if (len <= 0 || !buf) {
2982  LOG(llevDebug, "IP '%s' sent bogus account_password_cmd information\n", ns->host);
2983  return;
2984  }
2985 
2986  SockList_Init(&sl);
2987 
2988  if (ns->account_name == NULL) {
2989  SockList_AddString(&sl, "failure accountpw Not logged in");
2990  Send_With_Handling(ns, &sl);
2991  SockList_Term(&sl);
2992  return;
2993  }
2994 
2995  status = decode_name_password(buf, &len, old, change);
2996  if (status == 1) {
2997  SockList_AddString(&sl, "failure accountpw Old password is too long");
2998  Send_With_Handling(ns, &sl);
2999  SockList_Term(&sl);
3000  return;
3001  }
3002  if (status == 2) {
3003  SockList_AddString(&sl, "failure accountpw New password is too long");
3004  Send_With_Handling(ns, &sl);
3005  SockList_Term(&sl);
3006  return;
3007  }
3008  /*The minimum length isn't exactly required, but in the current implementation,
3009  * client will send the same password for character for which there is a
3010  * 2 character minimum size. Thus an account with a one character password
3011  * won't be able to create a character. */
3012  if (strlen(change)<2) {
3013  SockList_AddString(&sl, "failure accountpw New password is too short");
3014  Send_With_Handling(ns, &sl);
3015  SockList_Term(&sl);
3016  return;
3017  }
3018 
3019  status = account_check_string(change);
3020  if (status == 1) {
3021  SockList_AddString(&sl,
3022  "failure accountpw That password contains invalid characters.");
3023  Send_With_Handling(ns, &sl);
3024  SockList_Term(&sl);
3025  return;
3026  }
3027 
3028  if (status == 2) {
3029  SockList_AddString(&sl,
3030  "failure accountpw That password is too long");
3031  Send_With_Handling(ns, &sl);
3032  SockList_Term(&sl);
3033  return;
3034  }
3035 
3036  status = account_change_password(ns->account_name, old, change);
3037  if (status != 0) {
3038  const char *error;
3039 
3040  if (status == 1) {
3041  error = "failure accountpw Illegal characters present";
3042  } else if (status == 2) {
3043  error = "failure accountpw Invalid account";
3044  } else {
3045  error = "failure accountpw Incorrect current password";
3046  }
3047 
3048  SockList_AddString(&sl, error);
3049  Send_With_Handling(ns, &sl);
3050  SockList_Term(&sl);
3051  return;
3052  }
3053 
3054  /* If we got here, we passed all checks, and password was changed */
3056 }
find_player_socket
player * find_player_socket(const socket_struct *ns)
Definition: player.cpp:123
ADD_PLAYER_NO_STATS_ROLL
#define ADD_PLAYER_NO_STATS_ROLL
Definition: player.h:246
SF_FIREON
#define SF_FIREON
Definition: newclient.h:189
CF_BLIND
#define CF_BLIND
Definition: newclient.h:200
Face::name
sstring name
Definition: face.h:19
account_add_player_cmd
void account_add_player_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:2322
CLASS
@ CLASS
Definition: object.h:141
CS_STAT_RES_DEPLETE
#define CS_STAT_RES_DEPLETE
Definition: newclient.h:162
Face
Definition: face.h:14
MAP_CLIENT_X
#define MAP_CLIENT_X
Definition: config.h:237
CF_STEALTHY
#define CF_STEALTHY
Definition: newclient.h:205
socket_struct::tick
uint32_t tick
Definition: newserver.h:106
atnr_cs_stat
static const short atnr_cs_stat[NROFATTACKS]
Definition: request.cpp:75
PLAYER
@ PLAYER
Definition: object.h:110
SockList_AddInt
void SockList_AddInt(SockList *sl, uint32_t data)
Definition: lowlevel.cpp:124
global.h
ANIM_SYNC
#define ANIM_SYNC
Definition: newclient.h:348
NS_FACESENT_FACE
#define NS_FACESENT_FACE
Definition: newserver.h:137
socket_struct::sc_version
uint32_t sc_version
Definition: newserver.h:113
first_player
player * first_player
Definition: init.cpp:106
ST_CHANGE_PASSWORD_OLD
#define ST_CHANGE_PASSWORD_OLD
Definition: define.h:550
settings
struct Settings settings
Definition: init.cpp:138
CS_STAT_RACE_CON
#define CS_STAT_RACE_CON
Definition: newclient.h:121
print_ext_msg
void print_ext_msg(socket_struct *ns, int color, uint8_t type, uint8_t subtype, const char *message)
Definition: info.cpp:62
banquet.l
l
Definition: banquet.py:164
CS_STAT_GRACE
#define CS_STAT_GRACE
Definition: newclient.h:109
safe_strncpy
#define safe_strncpy
Definition: compat.h:27
find_smooth
int find_smooth(const Face *face, const Face **smoothed)
Definition: image.cpp:102
annotate_ob
static int annotate_ob(int ax, int ay, const object *ob, SockList *sl, socket_struct *ns, int *has_obj, int *alive_layer)
Definition: request.cpp:1286
MAP
@ MAP
Definition: object.h:128
living::maxhp
int16_t maxhp
Definition: living.h:41
socket_struct::heartbeat
bool heartbeat
Definition: newserver.h:112
SockList_AddInt64
void SockList_AddInt64(SockList *sl, uint64_t data)
Definition: lowlevel.cpp:137
ST_GET_PASSWORD
#define ST_GET_PASSWORD
Definition: define.h:547
ACL_FACE_NUM
#define ACL_FACE_NUM
Definition: newclient.h:224
FLAG_CONFUSED
#define FLAG_CONFUSED
Definition: define.h:311
CAN_PROBE
static bool CAN_PROBE(const object *ob)
Definition: object.h:605
llevError
@ llevError
Definition: logger.h:11
FABS
#define FABS(x)
Definition: define.h:22
FLAG_CLIENT_ANIM_RANDOM
#define FLAG_CLIENT_ANIM_RANDOM
Definition: define.h:241
send_account_players
void send_account_players(socket_struct *ns)
Definition: request.cpp:1982
object::path_attuned
uint32_t path_attuned
Definition: object.h:351
CS_STAT_APPLIED_WIS
#define CS_STAT_APPLIED_WIS
Definition: newclient.h:133
MSG_TYPE_ADMIN_PLAYER
#define MSG_TYPE_ADMIN_PLAYER
Definition: newclient.h:496
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.cpp:51
send_query
void send_query(socket_struct *ns, uint8_t flags, const char *text)
Definition: request.cpp:680
Map
Definition: newserver.h:48
account_play_cmd
void account_play_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:2451
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
new_player_cmd
void new_player_cmd(uint8_t *buf, int len, player *pl)
Definition: request.cpp:461
client_spell
Definition: player.h:87
CS_STAT_RES_FEAR
#define CS_STAT_RES_FEAR
Definition: newclient.h:161
player
Definition: player.h:105
CS_STAT_DAM
#define CS_STAT_DAM
Definition: newclient.h:101
strdup_local
#define strdup_local
Definition: compat.h:29
ACL_RACE
#define ACL_RACE
Definition: newclient.h:219
diamondslots.x
x
Definition: diamondslots.py:15
FLAG_STARTEQUIP
#define FLAG_STARTEQUIP
Definition: define.h:268
CS_STAT_RES_FIRE
#define CS_STAT_RES_FIRE
Definition: newclient.h:150
ask_smooth_cmd
void ask_smooth_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:437
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
newhash
char const * newhash(char const *password)
Definition: server.cpp:101
archininventory.arch
arch
DIALOGCHECK MINARGS 1 MAXARGS 1
Definition: archininventory.py:16
socket_struct::sound
uint32_t sound
Definition: newserver.h:111
account_get_additional_chars
linked_char * account_get_additional_chars(const char *account_name, const Account_Chars *chars, int *count)
Definition: account.cpp:551
CS_STAT_APPLIED_POW
#define CS_STAT_APPLIED_POW
Definition: newclient.h:137
CS_STAT_HP
#define CS_STAT_HP
Definition: newclient.h:87
socket_struct
Definition: newserver.h:89
socket_struct::mapx
uint8_t mapx
Definition: newserver.h:116
get_skill_client_code
int get_skill_client_code(const char *skill_name)
Definition: skill_util.cpp:107
ST_GET_NAME
#define ST_GET_NAME
Definition: define.h:546
map2_delete_layer
static int map2_delete_layer(int ax, int ay, int layer, SockList *sl, socket_struct *ns)
Definition: request.cpp:1193
update_position
void update_position(mapstruct *m, int x, int y)
Definition: map.cpp:2141
MAX_NUM_LOOK_OBJECTS
#define MAX_NUM_LOOK_OBJECTS
Definition: newserver.h:28
socket_struct::num_look_objects
uint8_t num_look_objects
Definition: newserver.h:122
object::arch
struct archetype * arch
Definition: object.h:420
command_execute
void command_execute(object *pl, char *command)
Definition: commands.cpp:455
AddIfInt64
#define AddIfInt64(Old, New, sl, Type)
Definition: request.cpp:689
SockList_AddString
void SockList_AddString(SockList *sl, const char *data)
Definition: lowlevel.cpp:154
ring_occidental_mages.rest
rest
Definition: ring_occidental_mages.py:16
MAX_TIME
#define MAX_TIME
Definition: config.h:246
CS_STAT_SPELL_DENY
#define CS_STAT_SPELL_DENY
Definition: newclient.h:116
account_get_players_for_account
char ** account_get_players_for_account(const char *account_name)
Definition: account.cpp:520
accounts_save
void accounts_save(void)
Definition: account.cpp:256
CS_STAT_WIS
#define CS_STAT_WIS
Definition: newclient.h:93
reply_cmd
void reply_cmd(char *buf, int len, player *pl)
Definition: request.cpp:523
CS_STAT_SPEED
#define CS_STAT_SPEED
Definition: newclient.h:103
socket_struct::extended_stats
uint32_t extended_stats
Definition: newserver.h:109
CS_STAT_INT
#define CS_STAT_INT
Definition: newclient.h:92
append_spell
static void append_spell(player *pl, SockList *sl, object *spell)
Definition: request.cpp:1785
guildjoin.ob
ob
Definition: guildjoin.py:42
Settings::min_name
uint8_t min_name
Definition: global.h:331
SK_PRAYING
@ SK_PRAYING
Definition: skills.h:49
CS_STAT_MAXSP
#define CS_STAT_MAXSP
Definition: newclient.h:90
draw_ext_info_format
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...) PRINTF_ARGS(6
MIN
#define MIN(x, y)
Definition: compat.h:21
CS_STAT_BASE_DEX
#define CS_STAT_BASE_DEX
Definition: newclient.h:127
CS_STAT_RES_MAG
#define CS_STAT_RES_MAG
Definition: newclient.h:149
FIF
#define FIF(F, C)
MAP_LAYERS
#define MAP_LAYERS
Definition: map.h:32
Settings::starting_stat_min
uint8_t starting_stat_min
Definition: global.h:320
SKILL
@ SKILL
Definition: object.h:146
client_spell::last_sp
int16_t last_sp
Definition: player.h:89
socket_struct::is_bot
uint32_t is_bot
Definition: newserver.h:107
get_player
player * get_player(player *p)
Definition: player.cpp:285
send_extra_stats
static void send_extra_stats(SockList *sl, player *pl)
Definition: request.cpp:745
object::count
tag_t count
Definition: object.h:305
flags
static const flag_definition flags[]
Definition: gridarta-types-convert.cpp:101
CS_STAT_SP
#define CS_STAT_SP
Definition: newclient.h:89
SP_CREATE_FOOD
#define SP_CREATE_FOOD
Definition: spells.h:96
ACL_NAME
#define ACL_NAME
Definition: newclient.h:217
CS_STAT_RES_HOLYWORD
#define CS_STAT_RES_HOLYWORD
Definition: newclient.h:164
Ice.tmp
int tmp
Definition: Ice.py:207
CS_STAT_GOLEM_HP
#define CS_STAT_GOLEM_HP
Definition: newclient.h:138
CS_STAT_RES_CONF
#define CS_STAT_RES_CONF
Definition: newclient.h:153
NDI_RED
#define NDI_RED
Definition: newclient.h:245
MAX_HEAD_OFFSET
#define MAX_HEAD_OFFSET
Definition: newserver.h:42
account_link
int account_link(const char *account_name, const char *player_name)
Definition: account.cpp:445
ATNR_PHYSICAL
#define ATNR_PHYSICAL
Definition: attack.h:49
CS_STAT_TURN_UNDEAD
#define CS_STAT_TURN_UNDEAD
Definition: newclient.h:160
ACL_CLASS
#define ACL_CLASS
Definition: newclient.h:218
SP_CREATE_MISSILE
#define SP_CREATE_MISSILE
Definition: spells.h:113
CF_NOT_PERFECT
#define CF_NOT_PERFECT
Definition: newclient.h:203
NROFATTACKS
#define NROFATTACKS
Definition: attack.h:17
receive_play_again
void receive_play_again(object *op, char key)
Definition: player.cpp:956
set_player_socket
void set_player_socket(player *p, socket_struct *ns)
Definition: player.cpp:413
MSG_TYPE_COMMAND_ERROR
#define MSG_TYPE_COMMAND_ERROR
Definition: newclient.h:529
CS_STAT_EXP64
#define CS_STAT_EXP64
Definition: newclient.h:113
FLAG_PROBE
#define FLAG_PROBE
Definition: define.h:257
range_golem
@ range_golem
Definition: player.h:34
send_plugin_custom_message
void send_plugin_custom_message(object *pl, char *buf)
Definition: request.cpp:1652
SockList_Reset
void SockList_Reset(SockList *sl)
Definition: lowlevel.cpp:71
CS_STAT_CHARACTER_FLAGS
#define CS_STAT_CHARACTER_FLAGS
Definition: newclient.h:140
socket_struct::map_scroll_x
int8_t map_scroll_x
Definition: newserver.h:94
object_get_value
const char * object_get_value(const object *op, const char *const key)
Definition: object.cpp:4339
set_up_cmd
void set_up_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:95
UPD_SP_MANA
#define UPD_SP_MANA
Definition: newclient.h:324
object::level
int16_t level
Definition: object.h:359
FLAG_STEALTH
#define FLAG_STEALTH
Definition: define.h:312
heads
static const object * heads[MAX_HEAD_POS][MAX_HEAD_POS][MAP_LAYERS]
Definition: request.cpp:1021
pticks
uint32_t pticks
Definition: time.cpp:47
buf
StringBuffer * buf
Definition: readable.cpp:1551
key_confirm_quit
void key_confirm_quit(object *op, char key)
Definition: player.cpp:1592
CS_STAT_APPLIED_DEX
#define CS_STAT_APPLIED_DEX
Definition: newclient.h:134
add_player
player * add_player(socket_struct *ns, int flags)
Definition: player.cpp:460
object_insert_in_ob
object * object_insert_in_ob(object *op, object *where)
Definition: object.cpp:2851
POISONING
@ POISONING
Definition: object.h:221
MSG_TYPE_COMMAND
#define MSG_TYPE_COMMAND
Definition: newclient.h:404
CS_STAT_RACE_STR
#define CS_STAT_RACE_STR
Definition: newclient.h:117
CS_STAT_GOLEM_MAXHP
#define CS_STAT_GOLEM_MAXHP
Definition: newclient.h:139
SND_EFFECTS
#define SND_EFFECTS
Definition: sounds.h:12
ACL_MAP
#define ACL_MAP
Definition: newclient.h:223
linked_char
Definition: global.h:96
Account_Chars::chars
std::vector< Account_Char * > chars
Definition: account_char.h:30
FLAG_ALIVE
#define FLAG_ALIVE
Definition: define.h:230
socket_struct::update_look
uint32_t update_look
Definition: newserver.h:104
SockList_Avail
size_t SockList_Avail(const SockList *sl)
Definition: lowlevel.cpp:243
GetShort_String
short GetShort_String(const unsigned char *data)
Definition: lowlevel.cpp:255
short_stat_name
const char *const short_stat_name[NUM_STATS]
Definition: living.cpp:194
SP_SUMMON_MONSTER
#define SP_SUMMON_MONSTER
Definition: spells.h:101
UPD_SP_DAMAGE
#define UPD_SP_DAMAGE
Definition: newclient.h:326
m
static event_registration m
Definition: citylife.cpp:425
AddIfShort
#define AddIfShort(Old, New, sl, Type)
Definition: request.cpp:703
socket_struct::account_chars
Account_Chars * account_chars
Definition: newserver.h:127
esrv_send_animation
void esrv_send_animation(socket_struct *ns, const Animations *anim)
Definition: request.cpp:973
socket_struct::mapy
uint8_t mapy
Definition: newserver.h:116
MAP_IN_MEMORY
#define MAP_IN_MEMORY
Definition: map.h:131
Ns_Avail
@ Ns_Avail
Definition: newserver.h:65
CS_STAT_RACE_DEX
#define CS_STAT_RACE_DEX
Definition: newclient.h:120
CS_STAT_ARMOUR
#define CS_STAT_ARMOUR
Definition: newclient.h:102
positioning_system.coord
coord
Definition: positioning_system.py:26
item.q
q
Definition: item.py:32
set_title
void set_title(const object *pl, char *buf, size_t len)
Definition: info.cpp:334
map_cell_struct
Definition: newserver.h:31
MAP_CLIENT_Y
#define MAP_CLIENT_Y
Definition: config.h:238
CS_STAT_SPELL_REPEL
#define CS_STAT_SPELL_REPEL
Definition: newclient.h:115
disinfect.map
map
Definition: disinfect.py:4
CS_STAT_RACE_CHA
#define CS_STAT_RACE_CHA
Definition: newclient.h:122
P_NEW_MAP
#define P_NEW_MAP
Definition: map.h:251
CS_STAT_LEVEL
#define CS_STAT_LEVEL
Definition: newclient.h:98
CS_STAT_CON
#define CS_STAT_CON
Definition: newclient.h:95
account_new_cmd
void account_new_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:2208
account_login_cmd
void account_login_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:2109
playername_ok
int playername_ok(const char *cp)
Definition: player.cpp:257
esrv_send_face
void esrv_send_face(socket_struct *ns, const Face *face, int nocache)
Definition: image.cpp:72
client_spell::last_dam
int16_t last_dam
Definition: player.h:91
ACL_PARTY
#define ACL_PARTY
Definition: newclient.h:222
CS_STAT_CHA
#define CS_STAT_CHA
Definition: newclient.h:96
CS_STAT_APPLIED_CHA
#define CS_STAT_APPLIED_CHA
Definition: newclient.h:136
ST_CHANGE_PASSWORD_CONFIRM
#define ST_CHANGE_PASSWORD_CONFIRM
Definition: define.h:552
CS_STAT_RES_SLOW
#define CS_STAT_RES_SLOW
Definition: newclient.h:158
socket_struct::facecache
uint32_t facecache
Definition: newserver.h:102
check_race_and_class
int check_race_and_class(living *stats, archetype *race, archetype *opclass)
Definition: player.cpp:1429
player::blocked_los
int8_t blocked_los[MAP_CLIENT_X][MAP_CLIENT_Y]
Definition: player.h:177
check_login
void check_login(object *op, const char *password)
Definition: login.cpp:511
CS_STAT_BASE_POW
#define CS_STAT_BASE_POW
Definition: newclient.h:130
account_get_account_for_char
const char * account_get_account_for_char(const char *charname)
Definition: account.cpp:580
CS_STAT_RES_PHYS
#define CS_STAT_RES_PHYS
Definition: newclient.h:148
Settings::account_block_create
uint8_t account_block_create
Definition: global.h:328
ST_PLAY_AGAIN
#define ST_PLAY_AGAIN
Definition: define.h:542
CS_STAT_GOD_NAME
#define CS_STAT_GOD_NAME
Definition: newclient.h:141
Face::number
uint16_t number
Definition: face.h:15
ADD_PLAYER_NO_MAP
#define ADD_PLAYER_NO_MAP
Definition: player.h:245
map_cell_struct::darkness
int darkness
Definition: newserver.h:33
account_char_free
void account_char_free(Account_Chars *chars)
Definition: account_char.cpp:345
archetype::clone
object clone
Definition: object.h:476
send_smooth
static void send_smooth(socket_struct *ns, const Face *face)
Definition: request.cpp:393
add_string
sstring add_string(const char *str)
Definition: shstr.cpp:124
draw_client_map
void draw_client_map(object *pl)
Definition: request.cpp:1553
account_remove_player
int account_remove_player(const char *account_name, const char *player_name)
Definition: account.cpp:475
HEAD
#define HEAD(op)
Definition: object.h:596
MAX_HEAD_POS
#define MAX_HEAD_POS
Definition: request.cpp:1012
SockList_AddShort
void SockList_AddShort(SockList *sl, uint16_t data)
Definition: lowlevel.cpp:113
object::casting_time
int16_t casting_time
Definition: object.h:410
ANIM_RANDOM
#define ANIM_RANDOM
Definition: newclient.h:347
CS_STAT_BASE_CHA
#define CS_STAT_BASE_CHA
Definition: newclient.h:129
object_find_by_type_and_name
object * object_find_by_type_and_name(const object *who, int type, const char *name)
Definition: object.cpp:4101
SockList_AddChar
void SockList_AddChar(SockList *sl, unsigned char c)
Definition: lowlevel.cpp:103
set_attr_value
void set_attr_value(living *stats, int attr, int8_t value)
Definition: living.cpp:218
FLAG_FREED
#define FLAG_FREED
Definition: define.h:233
socket_struct::lastmap
struct Map lastmap
Definition: newserver.h:93
CF_POISONED
#define CF_POISONED
Definition: newclient.h:199
MAP2_LAYER_START
#define MAP2_LAYER_START
Definition: newclient.h:53
SPELL_GRACE
#define SPELL_GRACE
Definition: spells.h:59
object::face
const Face * face
Definition: object.h:339
CS_STAT_APPLIED_STR
#define CS_STAT_APPLIED_STR
Definition: newclient.h:131
socket_struct::host
char * host
Definition: newserver.h:100
CS_STAT_RACE_POW
#define CS_STAT_RACE_POW
Definition: newclient.h:123
account_password
void account_password(char *buf, int len, socket_struct *ns)
Definition: request.cpp:2976
esrv_map_scroll
void esrv_map_scroll(socket_struct *ns, int dx, int dy)
Definition: request.cpp:1614
GET_MAP_FACE_OBJ
#define GET_MAP_FACE_OBJ(M, X, Y, L)
Definition: map.h:185
socket_struct::account_name
char * account_name
Definition: newserver.h:126
CS_STAT_AC
#define CS_STAT_AC
Definition: newclient.h:100
FREE_AND_COPY
#define FREE_AND_COPY(sv, nv)
Definition: global.h:204
client_spell::last_grace
int16_t last_grace
Definition: player.h:90
check_space_for_heads
static void check_space_for_heads(int ax, int ay, SockList *sl, socket_struct *ns)
Definition: request.cpp:1315
CS_STAT_OVERLOAD
#define CS_STAT_OVERLOAD
Definition: newclient.h:142
object::type
uint8_t type
Definition: object.h:346
living::dam
int16_t dam
Definition: living.h:46
CS_STAT_WEAP_SP
#define CS_STAT_WEAP_SP
Definition: newclient.h:105
socket_struct::monitor_spells
uint32_t monitor_spells
Definition: newserver.h:110
FLAG_PARALYZED
#define FLAG_PARALYZED
Definition: define.h:371
CS_STAT_APPLIED_CON
#define CS_STAT_APPLIED_CON
Definition: newclient.h:135
MAP_LAYER_LIVING1
#define MAP_LAYER_LIVING1
Definition: map.h:46
navar-midane_time.data
data
Definition: navar-midane_time.py:11
esrv_update_spells
void esrv_update_spells(player *pl)
Definition: request.cpp:1666
skill_names
const char * skill_names[MAX_SKILLS]
Definition: skill_util.cpp:59
map_cell_struct::faces
uint16_t faces[MAP_LAYERS]
Definition: newserver.h:32
socket_struct::faceset
uint8_t faceset
Definition: newserver.h:117
CS_STAT_RES_GHOSTHIT
#define CS_STAT_RES_GHOSTHIT
Definition: newclient.h:156
linked_char::next
struct linked_char * next
Definition: global.h:98
CS_STAT_SKILLINFO
#define CS_STAT_SKILLINFO
Definition: newclient.h:172
FOR_INV_FINISH
#define FOR_INV_FINISH()
Definition: define.h:677
account_new
int account_new(const char *account_name, const char *account_password)
Definition: account.cpp:400
ST_CHANGE_PASSWORD_NEW
#define ST_CHANGE_PASSWORD_NEW
Definition: define.h:551
CS_STAT_RES_BLIND
#define CS_STAT_RES_BLIND
Definition: newclient.h:165
sstring
const typedef char * sstring
Definition: global.h:47
FLAG_UNAGGRESSIVE
#define FLAG_UNAGGRESSIVE
Definition: define.h:272
disinfect.count
int count
Definition: disinfect.py:7
CF_DISEASED
#define CF_DISEASED
Definition: newclient.h:202
MAP2_TYPE_DARKNESS
#define MAP2_TYPE_DARKNESS
Definition: newclient.h:43
socket_struct::map_scroll_y
int8_t map_scroll_y
Definition: newserver.h:94
archetype
Definition: object.h:472
sproto.h
CS_STAT_RACE_INT
#define CS_STAT_RACE_INT
Definition: newclient.h:118
SND_MUTE
#define SND_MUTE
Definition: sounds.h:14
MAX_SKILLS
#define MAX_SKILLS
Definition: skills.h:70
get_map_from_coord
mapstruct * get_map_from_coord(mapstruct *m, int16_t *x, int16_t *y)
Definition: map.cpp:2393
VERSION_SC
#define VERSION_SC
Definition: newserver.h:150
animate.anim
string anim
Definition: animate.py:20
get_face_by_id
const Face * get_face_by_id(uint16_t id)
Definition: assets.cpp:315
devourers.command
command
Definition: devourers.py:16
SP_level_spellpoint_cost
int16_t SP_level_spellpoint_cost(object *caster, object *spell, int flags)
Definition: spell_util.cpp:236
account_is_logged_in
int account_is_logged_in(const char *name)
Definition: account.cpp:605
MAP_TYPE_CHOICE
#define MAP_TYPE_CHOICE
Definition: map.h:59
SockList_Init
void SockList_Init(SockList *sl)
Definition: lowlevel.cpp:52
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
SockList::len
size_t len
Definition: newclient.h:686
CS_STAT_BASE_WIS
#define CS_STAT_BASE_WIS
Definition: newclient.h:126
is_perfect
static uint8_t is_perfect(const player *pl)
Definition: request.cpp:730
CS_STAT_FOOD
#define CS_STAT_FOOD
Definition: newclient.h:104
socket_struct::cs_version
uint32_t cs_version
Definition: newserver.h:113
object::other_arch
struct archetype * other_arch
Definition: object.h:421
living
Definition: living.h:35
guild_entry.text
text
Definition: guild_entry.py:44
P_OUT_OF_MAP
#define P_OUT_OF_MAP
Definition: map.h:250
CS_STAT_WEIGHT_LIM
#define CS_STAT_WEIGHT_LIM
Definition: newclient.h:112
MAX_BUF
#define MAX_BUF
Definition: define.h:35
Ns_Add
@ Ns_Add
Definition: newserver.h:66
CS_STAT_ITEM_POWER
#define CS_STAT_ITEM_POWER
Definition: newclient.h:143
CS_STAT_RES_POISON
#define CS_STAT_RES_POISON
Definition: newclient.h:157
receive_player_name
void receive_player_name(object *op, const char *name)
Definition: c_misc.cpp:1935
is_valid_faceset
int is_valid_faceset(int fsn)
Definition: image.cpp:117
CS_STAT_WC
#define CS_STAT_WC
Definition: newclient.h:99
ADD_PLAYER_NEW
#define ADD_PLAYER_NEW
Definition: player.h:244
object_present_in_ob
object * object_present_in_ob(uint8_t type, const object *op)
Definition: object.cpp:3161
get_weight_limit
uint32_t get_weight_limit(int stat)
Definition: living.cpp:2360
SockList_Term
void SockList_Term(SockList *sl)
Definition: lowlevel.cpp:62
AddIfInt
#define AddIfInt(Old, New, sl, Type)
Definition: request.cpp:696
probe
int probe(object *op, object *caster, object *spell_ob, int dir, int level)
Definition: spell_effect.cpp:695
FLAG_CLIENT_SENT
#define FLAG_CLIENT_SENT
Definition: define.h:346
CS_STAT_MAXGRACE
#define CS_STAT_MAXGRACE
Definition: newclient.h:110
key_roll_stat
void key_roll_stat(object *op, char key)
Definition: player.cpp:1213
MAP2_TYPE_CLEAR
#define MAP2_TYPE_CLEAR
Definition: newclient.h:42
FLAG_CLIENT_ANIM_SYNC
#define FLAG_CLIENT_ANIM_SYNC
Definition: define.h:240
Settings::starting_stat_points
uint8_t starting_stat_points
Definition: global.h:322
ST_PLAYING
#define ST_PLAYING
Definition: define.h:541
MAP2_COORD_ENCODE
#define MAP2_COORD_ENCODE(x, y, flags)
Definition: newclient.h:64
Settings
Definition: global.h:240
create_player_cmd
void create_player_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:2556
CS_STAT_STR
#define CS_STAT_STR
Definition: newclient.h:91
apply_race_and_class
int apply_race_and_class(object *op, archetype *race, archetype *opclass, living *stats)
Definition: player.cpp:1479
CS_STAT_BASE_INT
#define CS_STAT_BASE_INT
Definition: newclient.h:125
sounds.h
FLAG_REMOVED
#define FLAG_REMOVED
Definition: define.h:232
ST_CHANGE_CLASS
#define ST_CHANGE_CLASS
Definition: define.h:544
CS_STAT_SPELL_ATTUNE
#define CS_STAT_SPELL_ATTUNE
Definition: newclient.h:114
FLAG_WIZ
#define FLAG_WIZ
Definition: define.h:231
llevInfo
@ llevInfo
Definition: logger.h:12
SockList_AddData
void SockList_AddData(SockList *sl, const void *data, size_t len)
Definition: lowlevel.cpp:164
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:262
esrv_move_object
void esrv_move_object(object *pl, tag_t to, tag_t tag, long nrof)
Definition: item.cpp:890
FLAG_FRIENDLY
#define FLAG_FRIENDLY
Definition: define.h:246
get_client_spell_state
client_spell * get_client_spell_state(player *pl, object *spell)
Definition: player.cpp:144
archetype::tail_x
int8_t tail_x
Definition: object.h:477
object::name
sstring name
Definition: object.h:317
SP_level_dam_adjust
int SP_level_dam_adjust(const object *caster, const object *spob)
Definition: spell_util.cpp:287
socket_struct::want_pickup
uint32_t want_pickup
Definition: newserver.h:108
object_find_by_arch_name
object * object_find_by_arch_name(const object *who, const char *name)
Definition: object.cpp:4245
AddIfFloat
#define AddIfFloat(Old, New, sl, Type)
Definition: request.cpp:710
ST_CONFIRM_PASSWORD
#define ST_CONFIRM_PASSWORD
Definition: define.h:548
send_tick
void send_tick(player *pl)
Definition: request.cpp:1914
map2_add_ob
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)
Definition: request.cpp:1048
get_map_flags
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny)
Definition: map.cpp:301
account_block_create
static int account_block_create(const socket_struct *ns)
Definition: request.cpp:2172
item
Definition: item.py:1
DISEASE
@ DISEASE
Definition: object.h:247
P_NEED_UPDATE
#define P_NEED_UPDATE
Definition: map.h:240
newserver.h
mapstruct
Definition: map.h:316
enter_exit
void enter_exit(object *op, object *exit_ob)
Definition: server.cpp:732
SP_RUNE
#define SP_RUNE
Definition: spells.h:76
BEAT_INTERVAL
#define BEAT_INTERVAL
Definition: config.h:628
object::env
object * env
Definition: object.h:299
map_newmap_cmd
void map_newmap_cmd(socket_struct *ns)
Definition: request.cpp:621
esrv_add_spells
void esrv_add_spells(player *pl, object *spell)
Definition: request.cpp:1855
SND_MUSIC
#define SND_MUSIC
Definition: sounds.h:13
give.op
op
Definition: give.py:33
NDI_ALL
#define NDI_ALL
Definition: newclient.h:263
socket_struct::status
enum Sock_Status status
Definition: newserver.h:90
Animations
Definition: face.h:25
autojail.value
value
Definition: autojail.py:6
CS_STAT_RES_COLD
#define CS_STAT_RES_COLD
Definition: newclient.h:152
FLAG_AUTO_APPLY
#define FLAG_AUTO_APPLY
Definition: define.h:250
object::skill
sstring skill
Definition: object.h:327
esrv_remove_spell
void esrv_remove_spell(player *pl, object *spell)
Definition: request.cpp:1718
SockList_AddLen8Data
void SockList_AddLen8Data(SockList *sl, const void *data, size_t len)
Definition: lowlevel.cpp:176
receive_player_password
void receive_player_password(object *op, const char *password)
Definition: c_misc.cpp:1955
mapstruct::in_memory
uint32_t in_memory
Definition: map.h:337
add_me_cmd
void add_me_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:349
esrv_draw_look
void esrv_draw_look(object *pl)
Definition: item.cpp:193
object::msg
sstring msg
Definition: object.h:328
version_cmd
void version_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:585
diamondslots.y
y
Definition: diamondslots.py:16
Map::cells
struct map_cell_struct cells[MAX_CLIENT_X][MAX_CLIENT_Y]
Definition: newserver.h:49
CF_CONFUSED
#define CF_CONFUSED
Definition: newclient.h:198
ob_apply
method_ret ob_apply(object *op, object *applier, int aflags)
Definition: ob_methods.cpp:44
map_clearcell
static void map_clearcell(struct map_cell_struct *cell, int face, int count)
Definition: request.cpp:1007
NUM_ANIMATIONS
#define NUM_ANIMATIONS(ob)
Definition: global.h:171
SockList_ResetRead
void SockList_ResetRead(SockList *sl)
Definition: lowlevel.cpp:80
NDI_DK_ORANGE
#define NDI_DK_ORANGE
Definition: newclient.h:248
socket_struct::anims_sent
uint8_t anims_sent[MAXANIMNUM]
Definition: newserver.h:97
account_change_password
int account_change_password(const char *account_name, const char *current_password, const char *new_password)
Definition: account.cpp:628
socket_struct::faces_sent
uint8_t * faces_sent
Definition: newserver.h:96
CS_STAT_RES_DEATH
#define CS_STAT_RES_DEATH
Definition: newclient.h:163
arch_to_object
object * arch_to_object(archetype *at)
Definition: arch.cpp:229
GetInt_String
int GetInt_String(const unsigned char *data)
Definition: lowlevel.cpp:251
draw_client_map2
static void draw_client_map2(object *pl)
Definition: request.cpp:1362
strcasecmp
int strcasecmp(const char *s1, const char *s2)
castle_read.key
key
Definition: castle_read.py:64
make_face_from_files.int
int
Definition: make_face_from_files.py:26
ACL_LEVEL
#define ACL_LEVEL
Definition: newclient.h:220
MAP_LAYER_FLY2
#define MAP_LAYER_FLY2
Definition: map.h:49
CS_STAT_TITLE
#define CS_STAT_TITLE
Definition: newclient.h:107
MAP_TYPE_DEFAULT
#define MAP_TYPE_DEFAULT
Definition: map.h:58
object::randomitems
struct treasurelist * randomitems
Definition: object.h:393
newclient.h
save_player
int save_player(object *op, int flag)
Definition: login.cpp:230
ST_GET_PARTY_PASSWORD
#define ST_GET_PARTY_PASSWORD
Definition: define.h:549
VERSION_CS
#define VERSION_CS
Definition: newserver.h:149
Account_Chars
Definition: account_char.h:27
UPD_SP_GRACE
#define UPD_SP_GRACE
Definition: newclient.h:325
get_archetype_by_type_subtype
archetype * get_archetype_by_type_subtype(int type, int subtype)
Definition: arch.cpp:99
CS_STAT_POW
#define CS_STAT_POW
Definition: newclient.h:108
CF_WIZARD
#define CF_WIZARD
Definition: newclient.h:207
esrv_send_pickup
void esrv_send_pickup(player *pl)
Definition: request.cpp:1741
object_remove
void object_remove(object *op)
Definition: object.cpp:1833
player_set_state
void player_set_state(player *pl, uint8_t state)
Definition: player.cpp:4452
free_charlinks
void free_charlinks(linked_char *lc)
Definition: utils.cpp:596
try_find_archetype
archetype * try_find_archetype(const char *name)
Definition: assets.cpp:270
CS_STAT_RACE_WIS
#define CS_STAT_RACE_WIS
Definition: newclient.h:119
AddIfString
#define AddIfString(Old, New, sl, Type)
Definition: request.cpp:717
MAX_CHOICES
#define MAX_CHOICES
Definition: request.cpp:2549
try_find_face
const Face * try_find_face(const char *name, const Face *error)
Definition: assets.cpp:286
SP_RAISE_DEAD
#define SP_RAISE_DEAD
Definition: spells.h:75
MIN_NUM_LOOK_OBJECTS
#define MIN_NUM_LOOK_OBJECTS
Definition: newserver.h:16
SP_MAKE_MARK
#define SP_MAKE_MARK
Definition: spells.h:77
MAP_LAYER_LIVING2
#define MAP_LAYER_LIVING2
Definition: map.h:47
socket_struct::login_method
uint8_t login_method
Definition: newserver.h:128
archetype::tail_y
int8_t tail_y
Definition: object.h:477
check_probe
static int check_probe(int ax, int ay, const object *ob, SockList *sl, socket_struct *ns, int *has_obj, int *alive_layer)
Definition: request.cpp:1218
commands.h
ST_CONFIRM_QUIT
#define ST_CONFIRM_QUIT
Definition: define.h:545
CS_STAT_MAXHP
#define CS_STAT_MAXHP
Definition: newclient.h:88
move_cmd
void move_cmd(char *buf, int len, player *pl)
Definition: request.cpp:642
account_char_load
Account_Chars * account_char_load(const char *account_name)
Definition: account_char.cpp:135
key_change_class
void key_change_class(object *op, char key)
Definition: player.cpp:1289
receive_party_password
void receive_party_password(object *op, const char *password)
Definition: c_party.cpp:53
spell_client_use
static int spell_client_use(const object *spell)
Definition: request.cpp:1761
account_check_string
int account_check_string(const char *str)
Definition: account.cpp:361
esrv_update_stats
void esrv_update_stats(player *pl)
Definition: request.cpp:801
socket_struct::darkness
uint32_t darkness
Definition: newserver.h:103
FLAG_XRAYS
#define FLAG_XRAYS
Definition: define.h:300
player::socket
socket_struct * socket
Definition: player.h:107
socket_struct::notifications
uint16_t notifications
Definition: newserver.h:129
SF_RUNON
#define SF_RUNON
Definition: newclient.h:190
CS_STAT_RANGE
#define CS_STAT_RANGE
Definition: newclient.h:106
Settings::account_trusted_host
char * account_trusted_host
Definition: global.h:329
report.error
def error(pl)
Definition: report.py:43
object::stats
living stats
Definition: object.h:376
MSG_TYPE_ADMIN_VERSION
#define MSG_TYPE_ADMIN_VERSION
Definition: newclient.h:501
get_attr_value
int8_t get_attr_value(const living *stats, int attr)
Definition: living.cpp:313
update_los
void update_los(object *op)
Definition: los.cpp:459
CS_STAT_BASE_CON
#define CS_STAT_BASE_CON
Definition: newclient.h:128
add_char_field
static void add_char_field(SockList *sl, int type, const char *data)
Definition: request.cpp:1948
CS_STAT_DEX
#define CS_STAT_DEX
Definition: newclient.h:94
account_login
int account_login(const char *account_name, const char *account_password)
Definition: account.cpp:319
Settings::always_show_hp
uint8_t always_show_hp
Definition: global.h:273
verify_player
int verify_player(const char *name, char *password)
Definition: login.cpp:111
ST_ROLL_STAT
#define ST_ROLL_STAT
Definition: define.h:543
SPELL
@ SPELL
Definition: object.h:217
CS_STAT_BASE_STR
#define CS_STAT_BASE_STR
Definition: newclient.h:124
smooth_face
const Face * smooth_face
Definition: image.cpp:36
esrv_new_player
void esrv_new_player(player *pl, uint32_t weight)
Definition: request.cpp:943
decode_name_password
static int decode_name_password(const char *buf, int *len, char *name, char *password)
Definition: request.cpp:2073
account_char_save
void account_char_save(Account_Chars *chars)
Definition: account_char.cpp:158
CS_STAT_RES_DRAIN
#define CS_STAT_RES_DRAIN
Definition: newclient.h:155
altar_valkyrie.pl
pl
Definition: altar_valkyrie.py:28
MAP_NOSMOOTH
#define MAP_NOSMOOTH(m)
Definition: map.h:89
living.h
Send_With_Handling
void Send_With_Handling(socket_struct *ns, SockList *sl)
Definition: lowlevel.cpp:444
MSG_TYPE_ADMIN
#define MSG_TYPE_ADMIN
Definition: newclient.h:402
CF_HOSTILE
#define CF_HOSTILE
Definition: newclient.h:204
SockList
Definition: newclient.h:681
CF_PARALYZED
#define CF_PARALYZED
Definition: newclient.h:206
NUM_STATS
@ NUM_STATS
Definition: living.h:18
FOR_INV_PREPARE
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:670
living::hp
int16_t hp
Definition: living.h:40
takeitem.status
status
Definition: takeitem.py:38
FORCE
@ FORCE
Definition: object.h:227
account_char_remove
void account_char_remove(Account_Chars *chars, const char *pl_name)
Definition: account_char.cpp:313
CS_STAT_APPLIED_INT
#define CS_STAT_APPLIED_INT
Definition: newclient.h:132
MAX_LIGHT_RADII
#define MAX_LIGHT_RADII
Definition: define.h:450
ACL_FACE
#define ACL_FACE
Definition: newclient.h:221
CF_XRAY
#define CF_XRAY
Definition: newclient.h:201
rangetostring
void rangetostring(const object *pl, char *obuf, size_t len)
Definition: info.cpp:264
llevDebug
@ llevDebug
Definition: logger.h:13
NS_FACESENT_SMOOTH
#define NS_FACESENT_SMOOTH
Definition: newserver.h:138
is_valid_types_gen.type
list type
Definition: is_valid_types_gen.py:25
SockList_AddPrintf
void SockList_AddPrintf(SockList *sl, const char *format,...)
Definition: lowlevel.cpp:199
account_exists
const char * account_exists(const char *account_name)
Definition: account.cpp:297
give.name
name
Definition: give.py:27
CS_STAT_RES_PARA
#define CS_STAT_RES_PARA
Definition: newclient.h:159
Settings::starting_stat_max
uint8_t starting_stat_max
Definition: global.h:321
CS_STAT_RES_ACID
#define CS_STAT_RES_ACID
Definition: newclient.h:154
SPELL_MANA
#define SPELL_MANA
Definition: spells.h:58
dragon_attune.force
force
Definition: dragon_attune.py:45
CS_STAT_RES_ELEC
#define CS_STAT_RES_ELEC
Definition: newclient.h:151
CS_STAT_FLAGS
#define CS_STAT_FLAGS
Definition: newclient.h:111