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  }
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);
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:
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 
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 
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) {
824  }
825  if (pl->socket->extended_stats) {
826  int16_t golem_hp, golem_maxhp;
834  if (pl->ob != NULL) {
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.
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  */
883  SockList_AddChar(&sl, (char)pl->last_skill_ob[s]->level);
886  }
887  }
888  }
890  AddIfShort(pl->last_level, (char)pl->ob->level, &sl, CS_STAT_LEVEL);
898  flags = 0;
899  if (pl->fire_on)
900  flags |= SF_FIREON;
901  if (pl->run_on)
902  flags |= SF_RUNON;
903 
905  if (pl->socket->sc_version < 1025) {
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) {
921  }
922  /* we want to use the new fire & run system in new client */
923  rangetostring(pl->ob, buf, sizeof(buf));
925  set_title(pl->ob, buf, sizeof(buf));
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
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 
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 
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  Account_Char *acn;
1986  int num_chars;
1987  linked_char *extra;
1988 
1989  if (ns->account_chars) {
1991  }
1993 
1994  num_chars = 0;
1995  extra = account_get_additional_chars(ns->account_name, ns->account_chars, &num_chars);
1996 
1997  SockList_Init(&sl);
1998  SockList_AddString(&sl, "accountplayers ");
1999 
2000  for (acn = ns->account_chars->chars; acn; acn = acn->next) {
2001  num_chars++;
2002  }
2003 
2004  SockList_AddChar(&sl, num_chars);
2005 
2006  /* Now add real character data */
2007  for (acn = ns->account_chars->chars; acn; acn = acn->next) {
2008  uint16_t faceno = 0;
2009 
2010  /* Ignore a dead character. They don't need to show up. */
2011  if (acn->isDead) {
2012  continue;
2013  }
2014 
2015  add_char_field(&sl, ACL_NAME, acn->name);
2017  add_char_field(&sl, ACL_RACE, acn->race);
2018  add_char_field(&sl, ACL_FACE, acn->face);
2019  if (acn->face[0] != 0 ) {
2020  const Face *face = try_find_face(acn->face, NULL);
2021 
2022  if (face != NULL) {
2023  if (!(ns->faces_sent[face->number]&NS_FACESENT_FACE)) {
2024  esrv_send_face(ns, face, 0);
2025  }
2026  faceno = face->number;
2027  }
2028  }
2029 
2030  add_char_field(&sl, ACL_PARTY, acn->party);
2031  add_char_field(&sl, ACL_MAP, acn->map);
2032  SockList_AddChar(&sl, 3);
2034  SockList_AddShort(&sl, acn->level);
2035  if (faceno) {
2036  SockList_AddChar(&sl, 3);
2038  SockList_AddShort(&sl, faceno);
2039  }
2040 
2041  SockList_AddChar(&sl, 0);
2042  }
2043  /* Now for any characters where we just have the name */
2044  for (linked_char *e = extra; e != NULL; e = e->next) {
2045  add_char_field(&sl, ACL_NAME, e->name);
2046  SockList_AddChar(&sl, 0);
2047  }
2048 
2049  Send_With_Handling(ns, &sl);
2050  SockList_Term(&sl);
2051 
2052  if (extra) {
2053  free_charlinks(extra);
2054  }
2055 }
2056 
2078 static int decode_name_password(const char *buf, int *len, char *name, char *password)
2079 {
2080  int nlen, plen;
2081 
2082  if (*len < 2) {
2083  return 1;
2084  }
2085 
2086  nlen = (unsigned char)buf[0];
2087  if (nlen >= MAX_BUF || nlen > *len-2) {
2088  return 1;
2089  }
2090  memcpy(name, buf+1, nlen);
2091  name[nlen] = 0;
2092 
2093  plen = (unsigned char)buf[nlen+1];
2094  if (plen >= MAX_BUF || plen > *len-2-nlen) {
2095  return 2;
2096  }
2097  memcpy(password, buf+2+nlen, plen);
2098  password[plen] = 0;
2099 
2100  *len = nlen+plen+2;
2101 
2102  return 0;
2103 }
2114 void account_login_cmd(char *buf, int len, socket_struct *ns) {
2115  char name[MAX_BUF], password[MAX_BUF];
2116  int status;
2117  SockList sl;
2118 
2119  if (len <= 0 || !buf) {
2120  LOG(llevDebug, "IP '%s' sent bogus add_player_cmd information\n", ns->host);
2121  return;
2122  }
2123 
2124  SockList_Init(&sl);
2125 
2126  status = decode_name_password(buf, &len, name, password);
2127 
2128  if (status == 1) {
2129  SockList_AddString(&sl, "failure accountlogin Name is too long");
2130  Send_With_Handling(ns, &sl);
2131  SockList_Term(&sl);
2132  return;
2133  }
2134  if (status == 2) {
2135  SockList_AddString(&sl, "failure accountlogin Password is too long");
2136  Send_With_Handling(ns, &sl);
2137  SockList_Term(&sl);
2138  return;
2139  }
2140 
2141  if (!account_exists(name)) {
2142  SockList_AddString(&sl, "failure accountlogin No such account name exists on this server");
2143  Send_With_Handling(ns, &sl);
2144  SockList_Term(&sl);
2145  return;
2146  }
2147 
2148  if (account_login(name, password)) {
2149  LOG(llevInfo, "Account login for '%s' from %s\n", name, ns->host);
2150 
2151  if (ns->account_name) free(ns->account_name);
2152  /* We want to store away official name so we do not
2153  * have any case sensitivity issues on the files.
2154  * because we have already checked password, we
2155  * know that account_exists should never return NULL in
2156  * this case.
2157  */
2159 
2161  } else {
2162  LOG(llevInfo, "Failed account login for '%s' from %s\n", name, ns->host);
2163  SockList_AddString(&sl, "failure accountlogin Incorrect password for account");
2164  Send_With_Handling(ns, &sl);
2165  SockList_Term(&sl);
2166  }
2167 }
2168 
2177 static int account_block_create(const socket_struct *ns) {
2178  /* Check if account creation is blocked. */
2180  /* Account creation is allowed for everyone. */
2181  return 0;
2182  }
2183 
2184  /* Has the trusted host been defined? */
2185  if(settings.account_trusted_host == NULL) {
2186  /* No, allocate it and set it to localhost now. */
2188  }
2189 
2190  /* Return false if the client connected from the trusted host. */
2191  if(strcmp(ns->host, settings.account_trusted_host) == 0){
2192  return 0;
2193  }
2194 
2195  /*
2196  * If we are here, then we are blocking account create and we do
2197  * not trust this client's IP address.
2198  */
2199  return 1;
2200 }
2201 
2213 void account_new_cmd(char *buf, int len, socket_struct *ns) {
2214  char name[MAX_BUF], password[MAX_BUF];
2215  int status;
2216  SockList sl;
2217 
2218  if (len <= 0 || !buf) {
2219  LOG(llevDebug, "IP '%s' sent bogus add_player_cmd information\n", ns->host);
2220  return;
2221  }
2222 
2223  SockList_Init(&sl);
2224 
2225  status = decode_name_password(buf, &len, name, password);
2226 
2227  if (account_block_create(ns)) {
2228  LOG(llevInfo, "Account create blocked from %s\n", ns->host);
2229  SockList_AddString(&sl, "failure accountnew Account creation is disabled");
2230  Send_With_Handling(ns, &sl);
2231  SockList_Term(&sl);
2232  return;
2233  }
2234 
2235  if (status == 1) {
2236  SockList_AddString(&sl, "failure accountnew Name is too long");
2237  Send_With_Handling(ns, &sl);
2238  SockList_Term(&sl);
2239  return;
2240  }
2241  if (status == 2) {
2242  SockList_AddString(&sl, "failure accountnew Password is too long");
2243  Send_With_Handling(ns, &sl);
2244  SockList_Term(&sl);
2245  return;
2246  }
2247  /*The minimum length isn't exactly required, but in the current implementation,
2248  * client will send the same password for character for which there is a
2249  * 2 character minimum size. Thus an account with a one character password
2250  * won't be able to create a character. */
2251  if (strlen(name)<settings.min_name) {
2252  SockList_AddString(&sl, "failure accountnew Name is too short");
2253  Send_With_Handling(ns, &sl);
2254  SockList_Term(&sl);
2255  return;
2256  }
2257  if (strlen(password)<2) {
2258  SockList_AddString(&sl, "failure accountnew Password is too short");
2259  Send_With_Handling(ns, &sl);
2260  SockList_Term(&sl);
2261  return;
2262  }
2263 
2264  if (account_exists(name)) {
2265  SockList_AddString(&sl, "failure accountnew That account already exists on this server");
2266  Send_With_Handling(ns, &sl);
2267  SockList_Term(&sl);
2268  return;
2269  }
2270 
2272  if (status == 1) {
2273  SockList_AddString(&sl,
2274  "failure accountnew That account name contains invalid characters.");
2275  Send_With_Handling(ns, &sl);
2276  SockList_Term(&sl);
2277  return;
2278  }
2279 
2280  if (status == 2) {
2281  SockList_AddString(&sl,
2282  "failure accountnew That account name is too long");
2283  Send_With_Handling(ns, &sl);
2284  SockList_Term(&sl);
2285  return;
2286  }
2287 
2288  status = account_check_string(password);
2289  if (status == 1) {
2290  SockList_AddString(&sl,
2291  "failure accountnew That password contains invalid characters.");
2292  Send_With_Handling(ns, &sl);
2293  SockList_Term(&sl);
2294  return;
2295  }
2296 
2297  if (status == 2) {
2298  SockList_AddString(&sl,
2299  "failure accountnew That password is too long");
2300  Send_With_Handling(ns, &sl);
2301  SockList_Term(&sl);
2302  return;
2303  }
2304 
2305  /* If we got here, we passed all checks - so now add it */
2306  if (ns->account_name) free(ns->account_name);
2308  account_new(name, password);
2309  /* save account information */
2310  accounts_save();
2312 }
2313 
2327 void account_add_player_cmd(char *buf, int len, socket_struct *ns) {
2328  char name[MAX_BUF], password[MAX_BUF];
2329  int status, force, nlen;
2330  SockList sl;
2331  const char *cp;
2332 
2333  if (len <= 0 || !buf) {
2334  LOG(llevDebug, "IP '%s' sent bogus add_player_cmd information\n", ns->host);
2335  return;
2336  }
2337 
2338  SockList_Init(&sl);
2339 
2340  if (ns->account_name == NULL) {
2341  SockList_AddString(&sl, "failure accountaddplayer Not logged in");
2342  Send_With_Handling(ns, &sl);
2343  SockList_Term(&sl);
2344  return;
2345  }
2346 
2347  force = buf[0];
2348  nlen = len - 1;
2349  status = decode_name_password(buf+1, &nlen, name, password);
2350  if (status == 1) {
2351  SockList_AddString(&sl, "failure accountaddplayer Name is too long");
2352  Send_With_Handling(ns, &sl);
2353  SockList_Term(&sl);
2354  return;
2355  }
2356  if (status == 2) {
2357  SockList_AddString(&sl, "failure accountaddplayer Password is too long");
2358  Send_With_Handling(ns, &sl);
2359  SockList_Term(&sl);
2360  return;
2361  }
2362 
2363  status = verify_player(name, password);
2364  if (status) {
2365  /* From a security standpoint, telling random folks if it
2366  * it as wrong password makes it easier to hack. However,
2367  * it is fairly easy to determine what characters exist on a server
2368  * (either by trying to create a new one and see if the name is in
2369  * in use, or just looking at the high score file), so this
2370  * really does not make things much less secure
2371  */
2372  if (status == 1)
2373  SockList_AddString(&sl, "failure accountaddplayer 0 The character does not exist.");
2374  else
2375  SockList_AddString(&sl, "failure accountaddplayer 0 That password is incorrect.");
2376 
2377  Send_With_Handling(ns, &sl);
2378  SockList_Term(&sl);
2379  return;
2380  }
2381  /* Check to see if this character is associated with an account.
2382  */
2384  if (cp) {
2385  if (!strcmp(cp, ns->account_name)) {
2386  SockList_AddString(&sl, "failure accountaddplayer 0 That character is already connected to this account.");
2387  Send_With_Handling(ns, &sl);
2388  SockList_Term(&sl);
2389  return;
2390  } else {
2391  if (!force) {
2392  SockList_AddString(&sl, "failure accountaddplayer 1 That character is already connected to a different account.");
2393  Send_With_Handling(ns, &sl);
2394  SockList_Term(&sl);
2395  return;
2396  } else if (account_is_logged_in(cp)) {
2397  /* We could be clever and try to handle this case, but it is
2398  * trickier. If the character is logged in, it has to
2399  * be logged out. And the socket holds some data which
2400  * needs to be cleaned up. Since it should be fairly
2401  * uncommon that users need to do this, just disallowing
2402  * it makes things a lot simpler.
2403  */
2404  SockList_AddString(&sl, "failure accountaddplayer 0 That character is already connected to a different account which is currently logged in.");
2405  Send_With_Handling(ns, &sl);
2406  SockList_Term(&sl);
2407  return;
2408  }
2409  }
2410  }
2411  /* If we have gotten this far, the name/password provided is OK,
2412  * and the character is not associated with a different account (or
2413  * force is true). Now try to add the character to this account.
2414  */
2416 
2417  /* This should never happen, but check for it just in case -
2418  * if we were able to log in, the account should exist. but
2419  * if this fails, need to give the user some clue.
2420  */
2421  if (status==1) {
2422  SockList_AddString(&sl, "failure accountaddplayer 0 Could not find your account.");
2423  Send_With_Handling(ns, &sl);
2424  SockList_Term(&sl);
2425  return;
2426  } else if (status == 2) {
2427  SockList_AddString(&sl, "failure accountaddplayer 0 You have reached the maximum number of characters allowed per account.");
2428  Send_With_Handling(ns, &sl);
2429  SockList_Term(&sl);
2430  return;
2431  }
2432 
2433  /* If cp is set, then this character used to belong to a different
2434  * account. Remove it now.
2435  */
2436  if (cp) {
2437  Account_Chars *chars;
2438 
2440  chars = account_char_load(cp);
2441  account_char_remove(chars, name);
2442  account_char_save(chars);
2443  account_char_free(chars);
2444  }
2445 
2447 
2448  /* store data so nothing is lost in case of crash */
2450 }
2451 
2456 void account_play_cmd(char *buf, int len, socket_struct *ns)
2457 {
2458  char **chars;
2459  int i;
2460  SockList sl;
2461  player *pl;
2462 
2463  if (len <= 0 || !buf) {
2464  LOG(llevDebug, "IP '%s' sent bogus account_play_cmd information\n", ns->host);
2465  return;
2466  }
2467 
2468  SockList_Init(&sl);
2469 
2470  if (ns->status != Ns_Add) {
2471  SockList_AddString(&sl, "failure accountplay Not allowed right now");
2472  Send_With_Handling(ns, &sl);
2473  SockList_Term(&sl);
2474  return;
2475  }
2476 
2477  if (!buf[0]) {
2478  SockList_AddString(&sl, "failure accountplay Malformed character name");
2479  Send_With_Handling(ns, &sl);
2480  SockList_Term(&sl);
2481  return;
2482  }
2483 
2484  if (ns->account_name == NULL) {
2485  SockList_AddString(&sl, "failure accountplay Not logged in");
2486  Send_With_Handling(ns, &sl);
2487  SockList_Term(&sl);
2488  return;
2489  }
2490 
2491  /* Make sure a client is not trying to spoof us here */
2493 
2494  for (i=0; chars[i]; i++) {
2495  if (strcmp(chars[i], buf) == 0)
2496  break;
2497  }
2498  if (!chars[i]) {
2499  SockList_AddPrintf(&sl,
2500  "failure accountplay Character %s is not associated with account %s",
2501  buf, ns->account_name);
2502  Send_With_Handling(ns, &sl);
2503  SockList_Term(&sl);
2504  return;
2505  }
2506 
2507  for (pl = first_player; pl; pl = pl->next) {
2508  if (pl->ob && pl->socket != ns && strcmp(buf, pl->ob->name) == 0 && pl->state != ST_PLAY_AGAIN && pl->state != ST_GET_NAME) {
2509  SockList_AddPrintf(&sl,
2510  "failure accountplay Character %s is already playing",
2511  buf);
2512  Send_With_Handling(ns, &sl);
2513  SockList_Term(&sl);
2514  return;
2515  }
2516  }
2517 
2518  /* from a protocol standpoint, accountplay can be used
2519  * before there is a player structure (first login) or after
2520  * (character has logged in and is changing characters).
2521  * Checkthe sockets for that second case - if so,
2522  * we don't need to make a new player object, etc.
2523  */
2524  for (pl=first_player; pl; pl=pl->next) {
2525  if (pl->socket == ns) {
2526  /* The player still in the socket must be saved first. */
2527  save_player(pl->ob, 0);
2528  break;
2529  }
2530  }
2531 
2532  /* Some of this logic is from add_player()
2533  * we just don't use add_player() as it does some other work
2534  * we don't really want to do.
2535  */
2536  if (!pl) {
2537  pl = get_player(NULL);
2538  set_player_socket(pl, ns);
2539  ns->status = Ns_Avail;
2540  ns->account_chars = NULL;
2542  } else {
2543  pl->state = ST_PLAYING;
2544  }
2545 
2546  pl->ob->name = add_string(buf);
2547  check_login(pl->ob, NULL);
2548 
2549  SockList_AddString(&sl, "addme_success");
2550  Send_With_Handling(ns, &sl);
2551  SockList_Term(&sl);
2552 }
2553 
2554 #define MAX_CHOICES 100
2555 
2561 void create_player_cmd(char *buf, int len, socket_struct *ns)
2562 {
2563  char name[MAX_BUF], password[MAX_BUF], *choices[MAX_CHOICES];
2564  int status, nlen, choice_num=0, i;
2565  SockList sl;
2566  player *pl;
2567  archetype *map=NULL, *race_a=NULL, *class_a=NULL;
2568  living new_stats;
2569 
2570  if (len <= 0 || !buf) {
2571  LOG(llevDebug, "IP '%s' sent bogus create_player_cmd information\n", ns->host);
2572  return;
2573  }
2574 
2575  SockList_Init(&sl);
2576 
2577  if (ns->status != Ns_Add) {
2578  SockList_AddString(&sl, "failure createplayer Not allowed right now");
2579  Send_With_Handling(ns, &sl);
2580  SockList_Term(&sl);
2581  return;
2582  }
2583 
2584  nlen = len;
2585  status = decode_name_password(buf, &nlen, name, password);
2586  if (status == 1) {
2587  SockList_AddString(&sl, "failure createplayer Name is too long");
2588  Send_With_Handling(ns, &sl);
2589  SockList_Term(&sl);
2590  return;
2591  }
2592 
2593  /* Minimum character name limit (if set) */
2594  if (strlen(name)<settings.min_name) {
2595  SockList_AddString(&sl, "failure createplayer Name is too short");
2596  Send_With_Handling(ns, &sl);
2597  SockList_Term(&sl);
2598  return;
2599  }
2600 
2601  if (playername_ok(name) == 0) {
2602  SockList_AddString(&sl, "failure createplayer Player name contains invalid characters");
2603  Send_With_Handling(ns, &sl);
2604  SockList_Term(&sl);
2605  return;
2606  }
2607 
2608  /* 2 characters minimum for password */
2609  if (strlen(password)<2) {
2610  SockList_AddString(&sl, "failure createplayer Password is too short");
2611  Send_With_Handling(ns, &sl);
2612  SockList_Term(&sl);
2613  return;
2614  }
2615 
2617  if (status == 2) {
2618  SockList_AddString(&sl, "failure createplayer Password is too long");
2619  Send_With_Handling(ns, &sl);
2620  SockList_Term(&sl);
2621  return;
2622  }
2623 
2624  /* This is a fairly ugly solution - we're truncating the password.
2625  * however, the password information for characters is really
2626  * a legacy issue - when every character is associated with
2627  * an account, legacy login (character name/password) will get
2628  * removed, at which point the only use for password might be
2629  * to move characters from one account to another, but not sure
2630  * if that is something we want to allow.
2631  */
2632  if (strlen(password)>17)
2633  password[16] = 0;
2634 
2635  /* We just can't call check_name(), since that uses draw_info() to
2636  * report status. We are also more permissive on names, so we use
2637  * account_check_string() - if that is safe for account, also safe
2638  * for player names.
2639  */
2640  if (account_check_string(name)) {
2641  SockList_AddString(&sl, "failure createplayer The name contains illegal characters");
2642  Send_With_Handling(ns, &sl);
2643  SockList_Term(&sl);
2644  return;
2645  }
2646 
2647  /* 1 means no such player, 0 is correct name/password (which in this
2648  * case, is an error), and 2 is incorrect password. Only way we
2649  * go onward is if there is no such player.
2650  */
2651  if (verify_player(name, password) != 1) {
2652  SockList_AddString(&sl, "failure createplayer That name is already in use");
2653  Send_With_Handling(ns, &sl);
2654  SockList_Term(&sl);
2655  return;
2656  }
2657 
2658  /* from a protocol standpoint, accountplay can be used
2659  * before there is a player structure (first login) or after
2660  * (character has logged in and is changing characters).
2661  * Check the sockets for that second case - if so,
2662  * we don't need to make a new player object, etc.
2663  */
2664  for (pl=first_player; pl; pl=pl->next)
2665  if (pl->socket == ns) {
2666  if (pl->ob->name) {
2667  if (!strcmp(pl->ob->name, name)) {
2668  /* For some reason not only the socket is the same but also
2669  * the player is already playing. If this happens at this
2670  * point let's assume the character never was able to apply
2671  * a bet of reality to make a correct first-time save.
2672  * So, for safety remove it and start over.
2673  */
2674  if (!QUERY_FLAG(pl->ob, FLAG_REMOVED))
2675  object_remove(pl->ob);
2676  }
2677  else {
2678  /* If this is a different player on the same socket, then we
2679  * need to make sure that the old one is not connected to the player
2680  *
2681  * This prevents bizarre scenarios where the player is on the map
2682  * multiple times (from multiple createplayer commands), and
2683  * only one of them is controlled by the player.
2684  */
2685  if (pl->ob->contr == pl) {
2686  if (!QUERY_FLAG(pl->ob, FLAG_REMOVED))
2687  object_remove(pl->ob);
2688  }
2689  }
2690  }
2691  break;
2692  }
2693 
2694  /* In this mode, we have additional data
2695  * Note that because there are a lot of failure cases in here
2696  * (where we end up not creating the new player), the code
2697  * to create the new player is done within this routine
2698  * after all checks pass. Note that all of the checks
2699  * done are done without using the player structure,
2700  * as pl may be null right now.
2701  */
2702  if (ns->login_method >= 2) {
2703  int i, j, stat_total=0;
2704  char *key, *value, *race=NULL, *class_name=NULL;
2705 
2706  /* By setting this to zero, then we can easily
2707  * check to see if all stats have been set.
2708  */
2709  memset(&new_stats, 0, sizeof(living));
2710 
2711  while (nlen < len) {
2712  i = buf[nlen]; /* Length of this line */
2713  /* Sanity check from client - don't want to loop
2714  * forever if there is a 0 length, and don't
2715  * want to read beyond size of packet.
2716  * Likewise, client should have sent
2717  * the string to us already null terminated,
2718  * but we will just make sure.
2719  */
2720  if ((i == 0) || (nlen + i > len)) break;
2721  buf[nlen + i] = 0;
2722 
2723  /* What we have are a series of lines -
2724  * 'key value' format. Find that space,
2725  * and null it out so we can do strcasecmp.
2726  * If no space, abort processing
2727  */
2728  key = buf + nlen + 1;
2729  value = strchr(key, ' ');
2730  if (!value) break;
2731  *value = 0;
2732  value++;
2733 
2734  if (!strcasecmp(key,"race")) race = value;
2735  else if (!strcasecmp(key,"class")) class_name = value;
2736  else if (!strcasecmp(key,"starting_map")) {
2738  if (!map || map->clone.type != MAP || map->clone.subtype !=MAP_TYPE_CHOICE) {
2739  SockList_AddString(&sl,
2740  "failure createplayer Invalid starting map");
2741  Send_With_Handling(ns, &sl);
2742  SockList_Term(&sl);
2743  return;
2744  }
2745  }
2746  else if (!strcasecmp(key,"choice")) {
2747  /* In general, MAX_CHOICES should be large enough
2748  * to always handle the choices from the client - of
2749  * course, the client could be broken and send us many
2750  * more choices than we should have, so handle that.
2751  */
2752  if (choice_num == MAX_CHOICES) {
2753  LOG(llevError,
2754  "Number of choices receive exceed max value: %d>%d\n",
2755  choice_num, MAX_CHOICES);
2756  } else {
2757  choices[choice_num] = value;
2758  choice_num++;
2759  }
2760  }
2761  else {
2762  /* Do stat processing here */
2763  for (j=0; j < NUM_STATS; j++) {
2764  if (!strcasecmp(key,short_stat_name[j])) {
2765  int val = atoi(value);
2766 
2767  set_attr_value(&new_stats, j, val);
2768  break;
2769  }
2770  }
2771  if (j >= NUM_STATS) {
2772  /* Bad clients could do this - we should at least report
2773  * it, and useful when trying to add new parameters.
2774  */
2775  LOG(llevError, "Got unknown key/value from client: %s %s\n", key, value);
2776  }
2777  }
2778  nlen += i + 1;
2779  }
2780  /* Do some sanity checking now. But checking the stat
2781  * values here, we will catch any 0 values since we do
2782  * a memset above. A properly behaving client should
2783  * never do any of these things, but we do not presume
2784  * clients will behave properly.
2785  */
2786  for (j=0; j<NUM_STATS; j++) {
2787  int val = get_attr_value(&new_stats, j);
2788 
2789  stat_total += val;
2790  if (val > settings.starting_stat_max ||
2791  val < settings.starting_stat_min) {
2792  SockList_AddPrintf(&sl,
2793  "failure createplayer Stat value is out of range - %d must be between %d and %d",
2795  Send_With_Handling(ns, &sl);
2796  SockList_Term(&sl);
2797  return;
2798  }
2799  }
2800  if (stat_total > settings.starting_stat_points) {
2801  SockList_AddPrintf(&sl,
2802  "failure createplayer Total allocated statistics is higher than allowed (%d>%d)",
2803  stat_total, settings.starting_stat_points);
2804  Send_With_Handling(ns, &sl);
2805  SockList_Term(&sl);
2806  return;
2807  }
2808 
2809  if (race)
2810  race_a = try_find_archetype(race);
2811 
2812  if (class_name)
2813  class_a = try_find_archetype(class_name);
2814 
2815  /* This should never happen with a properly behaving client, so the error message
2816  * doesn't have to be that great.
2817  */
2818  if (!race_a || race_a->clone.type != PLAYER || !class_a || class_a->clone.type != CLASS) {
2819  SockList_AddString(&sl,
2820  "failure createplayer Invalid or unknown race or class");
2821  Send_With_Handling(ns, &sl);
2822  SockList_Term(&sl);
2823  return;
2824  }
2825 
2826  /* At current time, only way this can fail is if the adjusted
2827  * stat is less than 1.
2828  */
2829  if (check_race_and_class(&new_stats, race_a, class_a)) {
2830  SockList_AddString(&sl,
2831  "failure createplayer Unable to apply race or class - statistic is out of bounds");
2832  Send_With_Handling(ns, &sl);
2833  SockList_Term(&sl);
2834  return;
2835  }
2836 
2837  if (!pl)
2839  // If we already have a player, we a replaying on the same connection.
2840  // Since add_player normally sets ns->status, we still need that to happen.
2841  else
2842  ns->status = Ns_Avail;
2843 
2844  // We need to copy the name in before apply_race_and_class() because it
2845  // tells the client our character name. If we don't update it, they get the old one.
2846  FREE_AND_COPY(pl->ob->name, name);
2847 
2848  apply_race_and_class(pl->ob, race_a, class_a, &new_stats);
2849 
2850  } else {
2851  /* In thise case, old login method */
2852  if (!pl)
2853  pl = add_player(ns, ADD_PLAYER_NEW);
2854  // If we already have a player, we a replaying on the same connection.
2855  // Since add_player normally sets ns->status, we still need that to happen.
2856  else
2857  ns->status = Ns_Avail;
2858 
2859  // Make sure to do this on both code branches.
2860  FREE_AND_COPY(pl->ob->name, name);
2861 /* already done by add_player
2862  roll_again(pl->ob);
2863  pl->state = ST_ROLL_STAT;
2864  set_first_map(pl->ob);*/
2865  }
2866 
2867  /* add_player does a lot of the work, but there are a few
2868  * things we need to update, like starting name and
2869  * password.
2870  * This is done before processing in login_method>2.
2871  * The character creation process it does when
2872  * applying the race/class will use this
2873  * name information.
2874  */
2876  pl->name_changed = 1;
2877  safe_strncpy(pl->password, newhash(password), sizeof(pl->password));
2878 
2879  SockList_AddString(&sl, "addme_success");
2880  Send_With_Handling(ns, &sl);
2881  SockList_Term(&sl);
2882 
2883  if (ns->login_method >= 2) {
2884  /* The client could have provided us a map - if so, map will be set
2885  * and we don't want to overwrite it
2886  */
2887  if (!map)
2889  assert(map); // Existence checked in init_dynamic()
2890 
2891  enter_exit(pl->ob, &map->clone);
2892 
2893  if (pl->ob->map == NULL) {
2894  LOG(llevError, "Couldn't put player %s on start map %s!", pl->ob->name, map->name);
2895  abort();
2896  }
2897 
2898  /* copy information to bed of reality information, in case the player dies */
2899  safe_strncpy(pl->savebed_map, pl->ob->map->path, sizeof(pl->savebed_map));
2900  pl->bed_x = pl->ob->x;
2901  pl->bed_y = pl->ob->y;
2902 
2904  }
2905 
2906  /* We insert any objects after we have put the player on the map -
2907  * this makes things safer, as certain objects may expect a normal
2908  * environment. Note that choice_num will only be set in the
2909  * loginmethod > 2, which also checks (and errors out) if the
2910  * race/class is not set, which is why explicit checking for
2911  * those is not need.
2912  */
2913  for (i=0; i < choice_num; i++) {
2914  char *choiceval;
2915  const char *value, *cp;
2916  archetype *arch;
2917  object *op;
2918 
2919  choiceval = strchr(choices[i], ' ');
2920  if (!choiceval) {
2921  LOG(llevError, "Choice does not specify value: %s\n", choices[i]);
2922  continue;
2923  }
2924  *choiceval=0;
2925  choiceval++;
2926  value = object_get_value(&race_a->clone, choices[i]);
2927  if (!value)
2928  value = object_get_value(&class_a->clone, choices[i]);
2929 
2930  if (!value) {
2931  LOG(llevError, "Choice not found in archetype: %s\n", choices[i]);
2932  continue;
2933  }
2934  cp = strstr(value, choiceval);
2935  if (!cp) {
2936  LOG(llevError, "Choice value not found in archetype: %s %s\n",
2937  choices[i], choiceval);
2938  continue;
2939  }
2940 
2941  /* Check to make sure that the matched string is an entire word,
2942  * and not a substring (eg, valid choice being great_sword but
2943  * we just get sword) - the space after the match should either be a
2944  * space or null, and space before match should also be a space
2945  * or the start of the string.
2946  */
2947  if ((cp[strlen(choiceval)] != ' ') && (cp[strlen(choiceval)] != 0) &&
2948  (cp != value) && (*(cp-1) != ' ')) {
2949 
2950  LOG(llevError, "Choice value matches substring but not entire word: %s substring %s\n",
2951  choiceval, value);
2952  continue;
2953  }
2954  arch = try_find_archetype(choiceval);
2955  if (!arch) {
2956  LOG(llevError, "Choice value can not find archetype %s\n", choiceval);
2957  continue;
2958  }
2959  op = arch_to_object(arch);
2960  op = object_insert_in_ob(op, pl->ob);
2962  ob_apply(op, pl->ob, 0);
2963  }
2964 
2965  LOG(llevInfo, "new character %s from %s\n", pl->ob->name, pl->ob->contr->socket->host);
2968  "%s has entered the game.", pl->ob->name);
2969 }
2970 
2981 void account_password(char *buf, int len, socket_struct *ns) {
2982  char old[MAX_BUF], change[MAX_BUF];
2983  int status;
2984  SockList sl;
2985 
2986  if (len <= 0 || !buf) {
2987  LOG(llevDebug, "IP '%s' sent bogus account_password_cmd information\n", ns->host);
2988  return;
2989  }
2990 
2991  SockList_Init(&sl);
2992 
2993  if (ns->account_name == NULL) {
2994  SockList_AddString(&sl, "failure accountpw Not logged in");
2995  Send_With_Handling(ns, &sl);
2996  SockList_Term(&sl);
2997  return;
2998  }
2999 
3000  status = decode_name_password(buf, &len, old, change);
3001  if (status == 1) {
3002  SockList_AddString(&sl, "failure accountpw Old password is too long");
3003  Send_With_Handling(ns, &sl);
3004  SockList_Term(&sl);
3005  return;
3006  }
3007  if (status == 2) {
3008  SockList_AddString(&sl, "failure accountpw New password is too long");
3009  Send_With_Handling(ns, &sl);
3010  SockList_Term(&sl);
3011  return;
3012  }
3013  /*The minimum length isn't exactly required, but in the current implementation,
3014  * client will send the same password for character for which there is a
3015  * 2 character minimum size. Thus an account with a one character password
3016  * won't be able to create a character. */
3017  if (strlen(change)<2) {
3018  SockList_AddString(&sl, "failure accountpw New password is too short");
3019  Send_With_Handling(ns, &sl);
3020  SockList_Term(&sl);
3021  return;
3022  }
3023 
3024  status = account_check_string(change);
3025  if (status == 1) {
3026  SockList_AddString(&sl,
3027  "failure accountpw That password contains invalid characters.");
3028  Send_With_Handling(ns, &sl);
3029  SockList_Term(&sl);
3030  return;
3031  }
3032 
3033  if (status == 2) {
3034  SockList_AddString(&sl,
3035  "failure accountpw That password is too long");
3036  Send_With_Handling(ns, &sl);
3037  SockList_Term(&sl);
3038  return;
3039  }
3040 
3041  status = account_change_password(ns->account_name, old, change);
3042  if (status != 0) {
3043  const char *error;
3044 
3045  if (status == 1) {
3046  error = "failure accountpw Illegal characters present";
3047  } else if (status == 2) {
3048  error = "failure accountpw Invalid account";
3049  } else {
3050  error = "failure accountpw Incorrect current password";
3051  }
3052 
3053  SockList_AddString(&sl, error);
3054  Send_With_Handling(ns, &sl);
3055  SockList_Term(&sl);
3056  return;
3057  }
3058 
3059  /* If we got here, we passed all checks, and password was changed */
3061 }
find_player_socket
player * find_player_socket(const socket_struct *ns)
Definition: player.cpp:121
ADD_PLAYER_NO_STATS_ROLL
#define ADD_PLAYER_NO_STATS_ROLL
Definition: player.h:246
obj::weapon_speed
float weapon_speed
Definition: object.h:337
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:2327
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:139
liv::dam
int16_t dam
Definition: living.h:46
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
pl::count
uint32_t count
Definition: player.h:122
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
pl::golem_count
uint32_t golem_count
Definition: player.h:119
socket_struct::heartbeat
bool heartbeat
Definition: newserver.h:112
SockList_AddInt64
void SockList_AddInt64(SockList *sl, uint64_t data)
Definition: lowlevel.cpp:137
pl::transport
object * transport
Definition: player.h:213
account_char_struct::isDead
uint8_t isDead
Definition: account_char.h:20
obj::face
const Face * face
Definition: object.h:339
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
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:2456
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
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
obj::count
tag_t count
Definition: object.h:305
ask_smooth_cmd
void ask_smooth_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:437
obj::map
struct mapdef * map
Definition: object.h:303
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
archt::tail_x
int8_t tail_x
Definition: object.h:477
liv::maxgrace
int16_t maxgrace
Definition: living.h:45
socket_struct::sound
uint32_t sound
Definition: newserver.h:111
pl::peaceful
uint32_t peaceful
Definition: player.h:146
account_get_additional_chars
linked_char * account_get_additional_chars(const char *account_name, const Account_Chars *chars, int *count)
Definition: account.cpp:573
pl::last_race_stats
living last_race_stats
Definition: player.h:169
CS_STAT_APPLIED_POW
#define CS_STAT_APPLIED_POW
Definition: newclient.h:137
liv::wc
int8_t wc
Definition: living.h:37
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
account_char_struct::level
uint8_t level
Definition: account_char.h:16
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
liv::Str
int8_t Str
Definition: living.h:36
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
account_char_struct::map
sstring map
Definition: account_char.h:19
command_execute
void command_execute(object *pl, char *command)
Definition: commands.cpp:457
obj::path_attuned
uint32_t path_attuned
Definition: object.h:351
AddIfInt64
#define AddIfInt64(Old, New, sl, Type)
Definition: request.cpp:689
liv::maxhp
int16_t maxhp
Definition: living.h:41
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:539
pl
Definition: player.h:105
accounts_save
void accounts_save(void)
Definition: account.cpp:266
CS_STAT_WIS
#define CS_STAT_WIS
Definition: newclient.h:93
pl::blocked_los
int8_t blocked_los[MAP_CLIENT_X][MAP_CLIENT_Y]
Definition: player.h:177
pl::name_changed
uint32_t name_changed
Definition: player.h:145
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
liv::hp
int16_t hp
Definition: living.h:40
pl::last_golem_hp
int16_t last_golem_hp
Definition: player.h:174
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
pl::mode
uint32_t mode
Definition: player.h:123
mapdef::in_memory
uint32_t in_memory
Definition: map.h:338
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
pl::ob
object * ob
Definition: player.h:176
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
archt::tail_y
int8_t tail_y
Definition: object.h:477
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:283
send_extra_stats
static void send_extra_stats(SockList *sl, player *pl)
Definition: request.cpp:745
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
account_char_struct::name
sstring name
Definition: account_char.h:13
obj::path_denied
uint32_t path_denied
Definition: object.h:353
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:461
ATNR_PHYSICAL
#define ATNR_PHYSICAL
Definition: attack.h:49
socket_struct::inbuf
SockList inbuf
Definition: newserver.h:99
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
flags
static const flag_definition flags[]
Definition: gridarta-types-convert.c:101
CF_NOT_PERFECT
#define CF_NOT_PERFECT
Definition: newclient.h:203
NROFATTACKS
#define NROFATTACKS
Definition: attack.h:17
obj::msg
sstring msg
Definition: object.h:328
receive_play_again
void receive_play_again(object *op, char key)
Definition: player.cpp:936
pl::last_resist
int16_t last_resist[NROFATTACKS]
Definition: player.h:173
set_player_socket
void set_player_socket(player *p, socket_struct *ns)
Definition: player.cpp:405
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
pl::last_weapon_sp
float last_weapon_sp
Definition: player.h:156
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
account_chars_struct
Definition: account_char.h:28
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
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
account_char_struct
Definition: account_char.h:12
pticks
uint32_t pticks
Definition: time.cpp:47
pl::last_speed
float last_speed
Definition: player.h:172
buf
StringBuffer * buf
Definition: readable.cpp:1611
obj::randomitems
struct treasureliststruct * randomitems
Definition: object.h:393
key_confirm_quit
void key_confirm_quit(object *op, char key)
Definition: player.cpp:1572
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:452
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:89
archt
Definition: object.h:472
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
pl::levsp
int8_t levsp[11]
Definition: player.h:186
SP_SUMMON_MONSTER
#define SP_SUMMON_MONSTER
Definition: spells.h:101
UPD_SP_DAMAGE
#define UPD_SP_DAMAGE
Definition: newclient.h:326
pl::item_power
int16_t item_power
Definition: player.h:130
m
static event_registration m
Definition: citylife.cpp:425
liv::maxsp
int16_t maxsp
Definition: living.h:43
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
pl::savebed_map
char savebed_map[MAX_BUF]
Definition: player.h:110
MAP_IN_MEMORY
#define MAP_IN_MEMORY
Definition: map.h:131
liv::exp
int64_t exp
Definition: living.h:47
socket_struct::stats
struct statsinfo stats
Definition: newserver.h:98
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
pl::next
struct pl * next
Definition: player.h:106
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
obj::name
sstring name
Definition: object.h:317
CS_STAT_LEVEL
#define CS_STAT_LEVEL
Definition: newclient.h:98
pl::state
uint8_t state
Definition: player.h:131
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:2213
account_login_cmd
void account_login_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:2114
playername_ok
int playername_ok(const char *cp)
Definition: player.cpp:255
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:1409
check_login
void check_login(object *op, const char *password)
Definition: login.cpp:511
pl::last_orig_stats
living last_orig_stats
Definition: player.h:168
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:603
obj::path_repelled
uint32_t path_repelled
Definition: object.h:352
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:374
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
liv::Cha
int8_t Cha
Definition: living.h:36
account_remove_player
int account_remove_player(const char *account_name, const char *player_name)
Definition: account.cpp:493
obj::name_pl
sstring name_pl
Definition: object.h:321
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
ANIM_RANDOM
#define ANIM_RANDOM
Definition: newclient.h:347
obj::speed_left
float speed_left
Definition: object.h:336
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
CS_STAT_APPLIED_STR
#define CS_STAT_APPLIED_STR
Definition: newclient.h:131
socket_struct::host
char * host
Definition: newserver.h:100
pl::last_path_attuned
uint32_t last_path_attuned
Definition: player.h:160
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:2981
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
pl::last_character_flags
uint32_t last_character_flags
Definition: player.h:163
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
obj::x
int16_t x
Definition: object.h:333
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
pl::levgrace
int8_t levgrace[11]
Definition: player.h:187
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:91
CS_STAT_SKILLINFO
#define CS_STAT_SKILLINFO
Definition: newclient.h:172
obj::other_arch
struct archt * other_arch
Definition: object.h:421
FOR_INV_FINISH
#define FOR_INV_FINISH()
Definition: define.h:677
account_char_struct::race
sstring race
Definition: account_char.h:15
account_new
int account_new(const char *account_name, const char *account_password)
Definition: account.cpp:415
ST_CHANGE_PASSWORD_NEW
#define ST_CHANGE_PASSWORD_NEW
Definition: define.h:551
pl::last_character_load
float last_character_load
Definition: player.h:136
CS_STAT_RES_BLIND
#define CS_STAT_RES_BLIND
Definition: newclient.h:165
sstring
const typedef char * sstring
Definition: global.h:43
FLAG_UNAGGRESSIVE
#define FLAG_UNAGGRESSIVE
Definition: define.h:272
disinfect.count
int count
Definition: disinfect.py:7
obj::speed
float speed
Definition: object.h:335
CF_DISEASED
#define CF_DISEASED
Definition: newclient.h:202
pl::run_on
uint32_t run_on
Definition: player.h:143
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
obj::env
struct obj * env
Definition: object.h:299
account_char_struct::next
struct account_char_struct * next
Definition: account_char.h:21
liv::Con
int8_t Con
Definition: living.h:36
statsinfo::title
char * title
Definition: newserver.h:57
sproto.h
liv::food
int32_t food
Definition: living.h:48
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
pl::last_golem_maxhp
int16_t last_golem_maxhp
Definition: player.h:175
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:319
devourers.command
command
Definition: devourers.py:16
pl::last_path_denied
uint32_t last_path_denied
Definition: player.h:162
mapdef
Definition: map.h:317
SP_level_spellpoint_cost
int16_t SP_level_spellpoint_cost(object *caster, object *spell, int flags)
Definition: spell_util.cpp:235
account_is_logged_in
int account_is_logged_in(const char *name)
Definition: account.cpp:629
liv::Int
int8_t Int
Definition: living.h:36
MAP_TYPE_CHOICE
#define MAP_TYPE_CHOICE
Definition: map.h:59
liv
Definition: living.h:35
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
pl::bed_x
int16_t bed_x
Definition: player.h:111
socket_struct::cs_version
uint32_t cs_version
Definition: newserver.h:113
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:1936
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
pl::levhp
int8_t levhp[11]
Definition: player.h:185
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
pl::last_weight
int32_t last_weight
Definition: player.h:158
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:710
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:1193
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
pl::spell_state
client_spell * spell_state
Definition: player.h:214
obj::y
int16_t y
Definition: object.h:333
ST_PLAYING
#define ST_PLAYING
Definition: define.h:541
obj::arch
struct archt * arch
Definition: object.h:420
MAP2_COORD_ENCODE
#define MAP2_COORD_ENCODE(x, y, flags)
Definition: newclient.h:64
Settings
Definition: global.h:240
pl::bed_y
int16_t bed_y
Definition: player.h:111
create_player_cmd
void create_player_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:2561
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:1459
CS_STAT_BASE_INT
#define CS_STAT_BASE_INT
Definition: newclient.h:125
animations_struct
Definition: face.h:25
sounds.h
FLAG_REMOVED
#define FLAG_REMOVED
Definition: define.h:232
pl::last_applied_stats
living last_applied_stats
Definition: player.h:171
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
obj::type
uint8_t type
Definition: object.h:346
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
obj::stats
living stats
Definition: object.h:376
SP_level_dam_adjust
int SP_level_dam_adjust(const object *caster, const object *spob)
Definition: spell_util.cpp:286
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
archt::clone
object clone
Definition: object.h:476
obj::contr
struct pl * contr
Definition: object.h:282
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
liv::Dex
int8_t Dex
Definition: living.h:36
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:2177
pl::fire_on
uint32_t fire_on
Definition: player.h:142
item
Definition: item.py:1
DISEASE
@ DISEASE
Definition: object.h:247
pl::password
char password[16]
Definition: player.h:192
pl::last_skill_exp
int64_t last_skill_exp[MAX_SKILLS]
Definition: player.h:154
P_NEED_UPDATE
#define P_NEED_UPDATE
Definition: map.h:240
newserver.h
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
map_newmap_cmd
void map_newmap_cmd(socket_struct *ns)
Definition: request.cpp:621
liv::Wis
int8_t Wis
Definition: living.h:36
esrv_add_spells
void esrv_add_spells(player *pl, object *spell)
Definition: request.cpp:1855
SND_MUSIC
#define SND_MUSIC
Definition: sounds.h:13
liv::grace
int16_t grace
Definition: living.h:44
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
autojail.value
value
Definition: autojail.py:6
account_char_struct::party
sstring party
Definition: account_char.h:18
CS_STAT_RES_COLD
#define CS_STAT_RES_COLD
Definition: newclient.h:152
FLAG_AUTO_APPLY
#define FLAG_AUTO_APPLY
Definition: define.h:250
account_char_struct::character_class
sstring character_class
Definition: account_char.h:14
pl::do_los
uint32_t do_los
Definition: player.h:141
pl::last_weight_limit
int32_t last_weight_limit
Definition: player.h:159
pl::last_skill_ob
object * last_skill_ob[MAX_SKILLS]
Definition: player.h:153
statsinfo::god
char * god
Definition: newserver.h:57
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:1956
account_chars_struct::chars
Account_Char * chars
Definition: account_char.h:31
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
version_cmd
void version_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:585
obj::casting_time
int16_t casting_time
Definition: object.h:410
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
pl::last_stats
living last_stats
Definition: player.h:167
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:652
socket_struct::faces_sent
uint8_t * faces_sent
Definition: newserver.h:96
account_char_struct::face
sstring face
Definition: account_char.h:17
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:230
pl::ranges
object * ranges[range_size]
Definition: player.h:116
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
liv::ac
int8_t ac
Definition: living.h:38
obj::skill
sstring skill
Definition: object.h:327
CS_STAT_TITLE
#define CS_STAT_TITLE
Definition: newclient.h:107
MAP_TYPE_DEFAULT
#define MAP_TYPE_DEFAULT
Definition: map.h:58
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
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:4432
free_charlinks
void free_charlinks(linked_char *lc)
Definition: utils.cpp:606
try_find_archetype
archetype * try_find_archetype(const char *name)
Definition: assets.cpp:274
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:2554
try_find_face
const Face * try_find_face(const char *name, const Face *error)
Definition: assets.cpp:290
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
socket_struct::fd
int fd
Definition: newserver.h:91
MAP_LAYER_LIVING2
#define MAP_LAYER_LIVING2
Definition: map.h:47
socket_struct::login_method
uint8_t login_method
Definition: newserver.h:128
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
statsinfo::range
char * range
Definition: newserver.h:57
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:147
key_change_class
void key_change_class(object *op, char key)
Definition: player.cpp:1269
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:376
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
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
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
mapdef::path
char path[HUGE_BUF]
Definition: map.h:358
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:332
pl::character_load
float character_load
Definition: player.h:135
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
liv::sp
int16_t sp
Definition: living.h:42
decode_name_password
static int decode_name_password(const char *buf, int *len, char *name, char *password)
Definition: request.cpp:2078
account_char_save
void account_char_save(Account_Chars *chars)
Definition: account_char.cpp:179
CS_STAT_RES_DRAIN
#define CS_STAT_RES_DRAIN
Definition: newclient.h:155
pl::socket
socket_struct * socket
Definition: player.h:107
altar_valkyrie.pl
pl
Definition: altar_valkyrie.py:28
MAP_NOSMOOTH
#define MAP_NOSMOOTH(m)
Definition: map.h:89
living.h
obj::resist
int16_t resist[NROFATTACKS]
Definition: object.h:349
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
pl::applied_stats
living applied_stats
Definition: player.h:170
FOR_INV_PREPARE
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:670
takeitem.status
status
Definition: takeitem.py:35
FORCE
@ FORCE
Definition: object.h:227
pl::last_level
int8_t last_level
Definition: player.h:134
account_char_remove
void account_char_remove(Account_Chars *chars, const char *pl_name)
Definition: account_char.cpp:336
CS_STAT_APPLIED_INT
#define CS_STAT_APPLIED_INT
Definition: newclient.h:132
MAX_LIGHT_RADII
#define MAX_LIGHT_RADII
Definition: define.h:450
liv::Pow
int8_t Pow
Definition: living.h:36
pl::last_flags
uint16_t last_flags
Definition: player.h:157
obj::level
int16_t level
Definition: object.h:359
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
pl::orig_stats
living orig_stats
Definition: player.h:166
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:308
pl::last_item_power
uint16_t last_item_power
Definition: player.h:164
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
pl::last_path_repelled
uint32_t last_path_repelled
Definition: player.h:161
CS_STAT_RES_ELEC
#define CS_STAT_RES_ELEC
Definition: newclient.h:151
CS_STAT_FLAGS
#define CS_STAT_FLAGS
Definition: newclient.h:111