Crossfire Client, Trunk  R20693
commands.c
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2013 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 
55 int mapupdatesent = 0;
56 
57 #include "client.h"
58 
59 #include <assert.h>
60 #include <ctype.h>
61 #include <errno.h>
62 
63 #include "external.h"
64 #include "mapdata.h"
65 
66 /* In general, the data from the server should not do bad
67  * things like this, but checking for it makes it easier
68  * to find bugs. Often this is called within a loop
69  * that of iterating over the length of the buffer, hence
70  * the break. Note that this may not prevent crashes,
71  * but at least we generate a message.
72  * Note that curpos & buflen may be string pointers or
73  * may be integers - as long as both are the same
74  * (both integers or both char *) it will work.
75  */
76 #define ASSERT_LEN(function, curpos, buflen) \
77  if (curpos > buflen) { \
78  LOG(LOG_WARNING, function, "Data goes beyond length of buffer (%d>%d)", curpos, buflen); \
79  break; \
80 }
81 
82 char *news=NULL, *motd=NULL, *rules=NULL;
83 
85 static int spellmon_level = 0;
86 
87 int num_races = 0; /* Number of different races server has */
88 int used_races = 0; /* How many races we have filled in */
89 
90 int num_classes = 0; /* Same as race data above, but for classes */
91 int used_classes = 0;
92 
93 int stat_points; /* Number of stat points for new characters */
94 int stat_min; /* Minimum stat for new characters */
95 int stat_maximum; /* Maximum stat for new characters */
96 int starting_map_number = 0; /* Number of starting maps */
97 
100 
101 /* Best I can tell, none of this stat information is stored anyplace
102  * else in the server - MSW 2010-07-28
103  */
104 
105 #define NUM_STATS 7
106 
107 static const char *const short_stat_name[NUM_STATS] = {
108  "Str", "Dex", "Con",
109  "Wis", "Cha", "Int",
110  "Pow"
111 };
112 
113 /* Note that the label_cs and label_rs will be in this same
114  * order, eg, label_cs[0] will be strength, label_cs[1] will
115  * be con. However, this order can be changed, so it should
116  * not be assumed that label_cs[1] will always be con.
117  */
119  {"str", CS_STAT_STR, 0},
120  {"con", CS_STAT_CON, 1},
121  {"dex", CS_STAT_DEX, 2},
122  {"int", CS_STAT_INT, 3},
123  {"wis", CS_STAT_WIS, 4},
124  {"pow", CS_STAT_POW, 5},
125  {"cha", CS_STAT_CHA, 6}
126 };
127 
135 {
136  int i;
137 
138  if (!starting_map_info) {
139  return;
140  }
141 
142  /* Because we are going free the array storage itself, there is no reason
143  * to clear the data[i].. values.
144  */
145  for (i=0; i<starting_map_number; i++) {
146  if (starting_map_info[i].arch_name) {
147  free(starting_map_info[i].arch_name);
148  }
149  if (starting_map_info[i].public_name) {
150  free(starting_map_info[i].public_name);
151  }
152  if (starting_map_info[i].description) {
153  free(starting_map_info[i].description);
154  }
155  }
156 
157  free(starting_map_info);
158  starting_map_info=NULL;
159  starting_map_number = 0;
160 }
161 
172 static void get_starting_map_info(unsigned char *data, int len) {
173  int pos, type, length, map_entry=-1;
174  char *cp;
175 
176  pos = 0;
177  while (pos < len) {
178  type = data[pos];
179  pos++;
180 
181  /* Right now, all the data is length prefixed strings, so
182  * the only real difference is where we store the data
183  */
184 
185  length = GetShort_String(data + pos);
186  pos += 2;
187 
188  if ((length+pos) > len) {
189  LOG(LOG_WARNING, "common::get_starting_map_info",
190  "Length of data is greater than buffer (%d>%d)", length + pos, len);
191  return;
192  }
193 
194  cp = g_malloc(length+1);
195  strncpy(cp, (char *)data + pos, length);
196  cp[length] = 0;
197 
198  pos += length;
199 
200  /* If it is the arch name, it is a new entry, so we allocate
201  * space and clear it. This isn't most efficient, but at
202  * the same time, I don't see there being many maps.
203  * Note: If g_realloc is given a null pointer (which starting_map_info
204  * will be after free or first load), g_realloc just acts as g_malloc.
205  */
206  if (type == INFO_MAP_ARCH_NAME) {
207  map_entry++;
208  starting_map_info = g_realloc(starting_map_info,
209  (map_entry + 1) * sizeof(Starting_Map_Info));
210 
211  if (starting_map_info == NULL) {
212  LOG(LOG_ERROR, "get_starting_map_info",
213  "Could not allocate memory: %s", strerror(errno));
214  exit(EXIT_FAILURE);
215  }
216 
217  memset(&starting_map_info[map_entry], 0, sizeof(Starting_Map_Info));
218  starting_map_info[map_entry].arch_name = cp;
219  } else if (type == INFO_MAP_NAME) {
220  starting_map_info[map_entry].public_name = cp;
221  } else if (type == INFO_MAP_DESCRIPTION) {
222  starting_map_info[map_entry].description = cp;
223  } else {
224  /* Could be this is old client - but we can skip over
225  * this bad data so long as the length byte is valid.
226  */
227  LOG(LOG_WARNING, "common::get_starting_map_info",
228  "Unknown type: %d\n", type);
229  }
230  }
231  starting_map_number = map_entry;
233 }
234 
247 static void get_new_char_info(unsigned char *data, int len) {
248  int olen=0, llen;
249 
250  /* We reset these values - if the user is switching between
251  * servers before restarting the client, these may have
252  * different values.
253  */
254  stat_points = 0;
255  stat_min = 0;
256  stat_maximum = 0;
257 
258  while (olen < len) {
259  char datatype, *cp;
260 
261  /* Where this line ends in the total buffer */
262  llen = olen + GetChar_String(data + olen);
263 
264  /* By protocol convention, this should already be NULL,
265  * but we ensure it is. If the server has not included the
266  * null byte, we are overwriting some real data here, but
267  * the client will probably get an error at that point -
268  * if the server is not following the protocol, we really
269  * can't trust any of the data we get from it.
270  */
271  data[llen] = 0;
272 
273  if (llen > len) {
274  LOG(LOG_WARNING, "common::get_new_char_info",
275  "Length of line is greater than buffer (%d>%d)", llen, len);
276  return;
277  }
278  olen++;
279  datatype = GetChar_String(data+olen); /* Type value */
280  olen++;
281  /* First skip all the spaces */
282  while (olen <= len) {
283  if (!isspace(data[olen])) {
284  break;
285  }
286  olen++;
287  }
288  if (olen > len) {
289  LOG(LOG_WARNING, "common::get_new_char_info",
290  "Overran length of buffer (%d>%d)", olen, len);
291  return;
292  }
293 
294  cp = (char *)data + olen;
295  /* Go until we find another space */
296  while (olen <= len) {
297  if (isspace(data[olen])) {
298  break;
299  }
300  olen++;
301  }
302  data[olen] = 0; /* Null terminate the string */
303  olen++;
304  if (olen > len) {
305  LOG(LOG_WARNING, "common::get_new_char_info",
306  "Overran length of buffer (%d>%d)", olen, len);
307  return;
308  }
309  /* At this point, cp points to the string portion (variable name)
310  * of the line, with data+olen is the start of the next string
311  * (variable value).
312  */
313  if (!g_ascii_strcasecmp(cp,"points")) {
314  stat_points = atoi((char *)data + olen);
315  olen = llen + 1;
316  continue;
317  } else if (!g_ascii_strcasecmp(cp,"statrange")) {
318  if (sscanf((char *)data + olen, "%d %d", &stat_min, &stat_maximum) != 2) {
319  LOG(LOG_WARNING, "common::get_new_char_info",
320  "Unable to process statrange line (%s)", data + olen);
321  }
322  /* Either way, we go onto the next line */
323  olen = llen + 1;
324  continue;
325  } else if (!g_ascii_strcasecmp(cp,"statname")) {
326  /* The checking we do here is somewhat basic:
327  * 1) That we understand all the stat names that the server sends us
328  * 2) That we get the correct number of stats.
329  * Note that if the server sends us the same stat name twice, eg
330  * Str Str Dex Con ..., that will screw up this logic, but to a
331  * great extent, we have to trust that server is sending us correct
332  * information - sending the same stat twice does not follow that.
333  */
334  int i, matches=0;
335 
336  while (olen < llen) {
337  for (i=0; i < NUM_STATS; i++) {
338  if (!g_ascii_strncasecmp((char *)data + olen,
339  short_stat_name[i], strlen(short_stat_name[i]))) {
340  matches++;
341  olen += strlen(short_stat_name[i]) + 1;
342  break;
343  }
344  }
345  if (i == NUM_STATS) {
346  LOG(LOG_WARNING, "common::get_new_char_info",
347  "Unable to find matching stat name (%s)", data + olen);
348  break;
349  }
350  }
351  if (matches != NUM_STATS) {
352  LOG(LOG_WARNING, "common::get_new_char_info",
353  "Did not get correct number of stats (%d!=%d)", matches, NUM_STATS);
354  }
355  olen = llen + 1;
356  continue;
357  } else if (!g_ascii_strcasecmp(cp,"race") || !g_ascii_strcasecmp(cp,"class")) {
358  if (g_ascii_strcasecmp((char *)data + olen, "requestinfo")) {
359  LOG(LOG_WARNING, "common::get_new_char_info",
360  "Got unexpected value for %s: %s", cp, data+olen);
361  }
362  olen = llen + 1;
363  continue;
364  } else if (!g_ascii_strcasecmp(cp,"startingmap")) {
365  if (g_ascii_strcasecmp((char *)data + olen, "requestinfo")) {
366  LOG(LOG_WARNING, "common::get_new_char_info",
367  "Got unexpected value for %s: %s", cp, data+olen);
368  } else {
369  cs_print_string(csocket.fd, "requestinfo startingmap");
371  }
372  olen = llen + 1;
373  continue;
374  } else {
375  if (datatype == 'V' || datatype == 'R') {
376  LOG(LOG_WARNING, "common::get_new_char_info",
377  "Got unsupported string from server, type %c, value %s", datatype, cp);
378  /* pop up error here */
379  } else {
380  /* pop up warning here */
381  }
382  olen = llen + 1;
383  }
384  }
385  if (stat_min == 0 || stat_maximum == 0 || stat_points == 0) {
386  /* this needs to be handled better, but I'm not sure how -
387  * we could fall back to legacy character creation mode,
388  * but that will go away at some point - in a sense, if the
389  * server is not sending us values, that is a broken/non comformant
390  * server - best we could perhaps do is throw up a window saying
391  * this client is not compatible with the server.
392  */
393  LOG(LOG_ERROR, "common::get_new_char_info",
394  "Processed all newcharinfo yet have 0 value: stat_min=%d, stat_maximum=%d, stat_points=%d",
396  } else {
398  }
399 }
400 
401 
405 static int rc_compar(const Race_Class_Info *a, const Race_Class_Info *b)
406 {
407  return g_ascii_strcasecmp(a->public_name, b->public_name);
408 }
409 
420 void free_all_race_class_info(Race_Class_Info *data, int num_entries)
421 {
422  int i;
423 
424  /* Because we are going free the array storage itself, there is no reason
425  * to clear the data[i].. values.
426  */
427  for (i=0; i<num_entries; i++) {
428  int j;
429 
430  if (data[i].arch_name) {
431  free(data[i].arch_name);
432  }
433  if (data[i].public_name) {
434  free(data[i].public_name);
435  }
436  if (data[i].description) {
437  free(data[i].description);
438  }
439 
440  for (j=0; j<data[i].num_rc_choice; j++) {
441  int k;
442 
443  for (k=0; k<data[i].rc_choice[j].num_values; k++) {
444  free(data[i].rc_choice[j].value_arch[k]);
445  free(data[i].rc_choice[j].value_desc[k]);
446  }
447  free(data[i].rc_choice[j].value_arch);
448  free(data[i].rc_choice[j].value_desc);
449  free(data[i].rc_choice[j].choice_name);
450  free(data[i].rc_choice[j].choice_desc);
451  }
452  }
453 
454  free(data);
455  data=NULL;
456 }
457 
469 static void process_race_class_info(unsigned char *data, int len, Race_Class_Info *rci) {
470  char *cp = (char *)data, *nl;
471 
472  /* First thing is to process the remaining bit of the requestinfo line,
473  * which is the archetype name for this race/class
474  */
475  nl = strchr(cp, '\n');
476  if (nl) {
477  *nl=0;
478  rci->arch_name = g_strdup(cp);
479  cp = nl+1;
480  } else {
481  LOG(LOG_WARNING, "common::process_race_class_info", "Did not find archetype name");
482  return;
483  }
484 
485  /* Now we process the rest of the data - we look for a word the describes
486  * the data to follow. cp is a pointer to the data we are processing. nl
487  * is used to store temporary values.
488  */
489  do {
490  nl = strchr(cp, ' ');
491  /* If we did not find a space, may just mean we have reached the end
492  * of the data - could be a stray character, etc
493  */
494  if (!nl) {
495  break;
496  }
497 
498  if (nl) {
499  *nl = 0;
500  nl++;
501  }
502  if (!strcmp(cp, "name")) {
503  /* We get a name. The string is not NULL terminated, but the
504  * length is transmitted. So get the length, allocate a string
505  * large enough for that + NULL terminator, and copy string in,
506  * making sure to put terminator in place. also make sure we
507  * update cp beyond this block of data.
508  */
509  int namelen;
510 
511  namelen = GetChar_String((unsigned char *)nl);
512  ASSERT_LEN("common::process_race_class_info",
513  (unsigned char *)nl + namelen, data + len);
514  nl++;
515  rci->public_name = g_malloc(namelen+1);
516  strncpy(rci->public_name, nl, namelen);
517  rci->public_name[namelen] = 0;
518  cp = nl + namelen;
519  } else if (!strcmp(cp, "stats")) {
520  cp = nl;
521  /* This loop goes through the stat values - *cp points to the stat
522  * value - if 0, no more stats, hence the check here.
523  */
524  while (cp < (char *)data + len && *cp != 0) {
525  int i;
526 
527  for (i=0; i < NUM_NEW_CHAR_STATS; i++)
528  if (stat_mapping[i].cs_value == *cp) {
529  break;
530  }
531 
532  if (i == NUM_NEW_CHAR_STATS) {
533  /* Just return with what we have */
534  LOG(LOG_WARNING, "common::process_race_class_info",
535  "Unknown stat value: %d", cp);
536  return;
537  }
538  rci->stat_adj[stat_mapping[i].rc_offset] =
539  GetShort_String((unsigned char *)cp + 1);
540  cp += 3;
541  }
542  cp++; /* Skip over 0 terminator */
543  } else if (!strcmp(cp, "msg")) {
544  /* This is really exactly same as name processing above, except
545  * length is 2 bytes in this case.
546  */
547  int msglen;
548 
549  msglen = GetShort_String((unsigned char *)nl);
550  ASSERT_LEN("common::process_race_class_info",
551  (unsigned char *)nl + msglen, data + len);
552  nl+=2;
553  rci->description = g_malloc(msglen+1);
554  strncpy(rci->description, nl, msglen);
555  rci->description[msglen] = 0;
556  cp = nl + msglen;
557  } else if (!strcmp(cp, "choice")) {
558  int oc = rci->num_rc_choice, clen;
559 
560  rci->num_rc_choice++;
561  /* rc_choice may be null, but g_realloc still works there */
562  rci->rc_choice = g_realloc(rci->rc_choice, sizeof(struct RC_Choice) * rci->num_rc_choice);
563  memset(&rci->rc_choice[oc], 0, sizeof(struct RC_Choice));
564 
565  cp = nl;
566 
567  /* First is the coice string we return */
568  clen = GetChar_String((unsigned char *)cp);
569  cp++;
570  ASSERT_LEN("common::process_race_class_info",
571  (unsigned char *)cp + clen, data + len);
572  rci->rc_choice[oc].choice_name = g_malloc(clen+1);
573  strncpy(rci->rc_choice[oc].choice_name, cp, clen);
574  rci->rc_choice[oc].choice_name[clen] = 0;
575  cp += clen;
576 
577  /* Next is the description */
578  clen = GetChar_String((unsigned char *)cp);
579  cp++;
580  ASSERT_LEN("common::process_race_class_info",
581  (unsigned char *)cp + clen, data + len);
582  rci->rc_choice[oc].choice_desc = g_malloc(clen+1);
583  strncpy(rci->rc_choice[oc].choice_desc, cp, clen);
584  rci->rc_choice[oc].choice_desc[clen] = 0;
585  cp += clen;
586 
587  /* Now is a series of archetype/description pairs */
588  while (1) {
589  int vn;
590 
591  clen = GetChar_String((unsigned char *)cp);
592  cp++;
593  if (!clen) {
594  break; /* 0 length is end of data */
595  }
596  vn = rci->rc_choice[oc].num_values;
597  rci->rc_choice[oc].num_values++;
598  rci->rc_choice[oc].value_arch = g_realloc(rci->rc_choice[oc].value_arch,
599  sizeof(char*) * rci->rc_choice[oc].num_values);
600  rci->rc_choice[oc].value_desc = g_realloc(rci->rc_choice[oc].value_desc,
601  sizeof(char*) * rci->rc_choice[oc].num_values);
602 
603  ASSERT_LEN("common::process_race_class_info",
604  (unsigned char *)cp + clen, data + len);
605  rci->rc_choice[oc].value_arch[vn] = g_malloc(clen+1);
606  strncpy(rci->rc_choice[oc].value_arch[vn], cp, clen);
607  rci->rc_choice[oc].value_arch[vn][clen] = 0;
608  cp += clen;
609 
610  clen = GetChar_String((unsigned char *)cp);
611  cp++;
612  ASSERT_LEN("common::process_race_class_info",
613  (unsigned char *)cp + clen, data + len);
614  rci->rc_choice[oc].value_desc[vn] = g_malloc(clen+1);
615  strncpy(rci->rc_choice[oc].value_desc[vn], cp, clen);
616  rci->rc_choice[oc].value_desc[vn][clen] = 0;
617  cp += clen;
618  }
619  } else {
620  /* Got some keyword we did not understand. Because we do not know
621  * about it, we do not know how to skip it over - the data could
622  * very well contain spaces or other markers we look for.
623  */
624  LOG(LOG_WARNING, "common::process_race_class_info", "Got unknown keyword: %s", cp);
625  break;
626  }
627  } while ((unsigned char *)cp < data + len);
628 
629  /* The display code expects all of these to have a description -
630  * rather than add checks there for NULL values, simpler to
631  * just set things to an empty value.
632  */
633  if (!rci->description) {
634  rci->description = g_strdup("");
635  }
636 
637 }
638 
648 static void get_race_info(unsigned char *data, int len) {
649  /* This should not happen - the client is only requesting race info for
650  * races it has received - and it knows how many of those it has.
651  */
652  if (used_races >= num_races) {
653  LOG(LOG_ERROR, "common::get_race_info",
654  "used races exceed num races, %d>=%d", used_races, num_races);
655  return;
656  }
657 
658  process_race_class_info(data, len, &races[used_races]);
659  used_races++;
660 
661  if (used_races == num_races) {
662  qsort(races, used_races, sizeof(Race_Class_Info),
663  (int (*)(const void *, const void *))rc_compar);
664 
666  }
667 }
668 
679 static void get_class_info(unsigned char *data, int len) {
680  /* This should not happen - the client is only requesting race info for
681  * classes it has received - and it knows how many of those it has.
682  */
683  if (used_classes >= num_classes) {
684  LOG(LOG_ERROR, "common::get_race_info",
685  "used classes exceed num classes, %d>=%d", used_classes, num_classes);
686  return;
687  }
688 
690  used_classes++;
691 
692  if (used_classes == num_classes) {
693  qsort(classes, used_classes, sizeof(Race_Class_Info),
694  (int (*)(const void *, const void *))rc_compar);
695 
697  }
698 }
699 
705 static void get_exp_info(const unsigned char *data, int len)
706 {
707  int pos, level;
708 
709  if (len < 2) {
710  LOG(LOG_ERROR, "common::get_exp_info", "no max level info from server provided");
711  return;
712  }
713 
715  pos = 2;
716  exp_table = calloc(exp_table_max, sizeof(guint64));
717  for (level = 1; level <= exp_table_max && pos < len; level++) {
718  exp_table[level] = GetInt64_String(data+pos);
719  pos += 8;
720  }
721  if (level != exp_table_max) {
722  LOG(LOG_ERROR, "common::get_exp_info",
723  "Incomplete table sent - got %d entries, wanted %d", level, exp_table_max);
724  }
725 }
726 
732 static void get_skill_info(char *data, int len)
733 {
734  char *cp, *nl, *sn;
735  int val;
736 
737  cp = data;
738  do {
739  nl = strchr(cp, '\n');
740  if (nl) {
741  *nl = 0;
742  nl++;
743  }
744  sn = strchr(cp, ':');
745  if (!sn) {
746  LOG(LOG_WARNING, "common::get_skill_info", "corrupt line: /%s/", cp);
747  return;
748  }
749 
750  *sn = 0;
751  sn++;
752  val = atoi(cp);
753  val -= CS_STAT_SKILLINFO;
754 
755  /* skill_names[MAX_SKILL] is the declaration, so check against that */
756  if (val < 0 || val >= MAX_SKILL) {
757  LOG(LOG_WARNING, "common::get_skill_info", "invalid skill number %d", val);
758  return;
759  }
760 
761  free(skill_names[val]);
762  skill_names[val] = g_strdup(sn);
763  cp = nl;
764  } while (cp < data+len);
765 }
766 
774 void ReplyInfoCmd(unsigned char *buf, int len) {
775  unsigned char *cp;
776  int i;
777 
778  /* Covers a bug in the server in that it could send a replyinfo with no
779  * parameters
780  */
781  if (!buf) {
782  return;
783  }
784 
785  for (i = 0; i < len; i++) {
786  /* Either a space or newline represents a break */
787  if (*(buf+i) == ' ' || *(buf+i) == '\n') {
788  break;
789  }
790  }
791  if (i >= len) {
792  /* Don't print buf, as it may contain binary data */
793  /* Downgrade this to DEBUG - if the client issued an unsupported
794  * requestinfo info to the server, we'll end up here - this could be
795  * normal behaviour
796  */
797  LOG(LOG_DEBUG, "common::ReplyInfoCmd", "Never found a space in the replyinfo");
798  return;
799  }
800 
801  /* Null out the space and put cp beyond it */
802  cp = buf+i;
803  *cp++ = '\0';
804  if (!strcmp((char*)buf, "image_info")) {
805  get_image_info(cp, len-i-1); /* Located in common/image.c */
806  } else if (!strcmp((char*)buf, "image_sums")) {
807  get_image_sums((char*)cp, len-i-1); /* Located in common/image.c */
808  } else if (!strcmp((char*)buf, "skill_info")) {
809  get_skill_info((char*)cp, len-i-1); /* Located in common/commands.c */
810  } else if (!strcmp((char*)buf, "exp_table")) {
811  get_exp_info(cp, len-i-1); /* Located in common/commands.c */
812  } else if (!strcmp((char*)buf, "motd")) {
813  if (motd) {
814  free((char*)motd);
815  }
816  motd = g_strdup((char *)cp);
818  } else if (!strcmp((char*)buf, "news")) {
819  if (news) {
820  free((char*)news);
821  }
822  news = g_strdup((char *)cp);
824  } else if (!strcmp((char*)buf, "rules")) {
825  if (rules) {
826  free((char*)rules);
827  }
828  rules = g_strdup((char *)cp);
830  } else if (!strcmp((char*)buf, "race_list")) {
831  unsigned char *cp1;
832  for (cp1=cp; *cp !=0; cp++) {
833  if (*cp == '|') {
834  *cp++ = '\0';
835  /* The first separator has no data, so only send request to
836  * server if this is not null.
837  */
838  if (*cp1!='\0') {
839  cs_print_string(csocket.fd, "requestinfo race_info %s", cp1);
840  num_races++;
841  }
842  cp1 = cp;
843  }
844  }
845  if (*cp1!='\0') {
846  cs_print_string(csocket.fd, "requestinfo race_info %s", cp1);
847  num_races++;
848  }
849  if (races) {
851  num_races=0;
852  used_races=0;
853  }
854  races = calloc(num_races, sizeof(Race_Class_Info));
855 
856  } else if (!strcmp((char*)buf, "class_list")) {
857  unsigned char *cp1;
858  for (cp1=cp; *cp !=0; cp++) {
859  if (*cp == '|') {
860  *cp++ = '\0';
861  /* The first separator has no data, so only send request to
862  * server if this is not null.
863  */
864  if (*cp1!='\0') {
865  cs_print_string(csocket.fd, "requestinfo class_info %s", cp1);
866  num_classes++;
867  }
868  cp1 = cp;
869  }
870  }
871  /* last race isn't followed by a | */
872  if (*cp1 != '\0') {
873  cs_print_string(csocket.fd, "requestinfo class_info %s", cp1);
874  num_classes++;
875  }
876  if (classes) {
878  num_classes=0;
879  used_classes=0;
880  }
881  classes = calloc(num_classes, sizeof(Race_Class_Info));
882  } else if (!strcmp((char*)buf, "race_info")) {
883  get_race_info(cp, len -i -1);
884  } else if (!strcmp((char*)buf, "class_info")) {
885  get_class_info(cp, len -i -1);
886  } else if (!strcmp((char*)buf, "newcharinfo")) {
887  get_new_char_info(cp, len -i -1);
888  } else if (!strcmp((char*)buf, "startingmap")) {
889  get_starting_map_info(cp, len -i -1);
890  }
891 }
892 
901 void SetupCmd(char *buf, int len)
902 {
903  int s;
904  char *cmd, *param;
905 
906  /* Process the setup commands.
907  * Syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ...
908  *
909  * The server sends the status of the cmd back, or a FALSE if the cmd is
910  * unknown. The client then must sort this out.
911  */
912 
913  LOG(LOG_DEBUG, "common::SetupCmd", "%s", buf);
914  for (s = 0; ; ) {
915  if (s >= len) { /* Ugly, but for secure...*/
916  break;
917  }
918 
919  cmd = &buf[s];
920 
921  /* Find the next space, and put a null there */
922  for (; buf[s] && buf[s] != ' '; s++)
923  ;
924  buf[s++] = 0;
925  while (buf[s] == ' ') {
926  s++;
927  }
928  if (s >= len) {
929  break;
930  }
931 
932  param = &buf[s];
933 
934  for (; buf[s] && buf[s] != ' '; s++)
935  ;
936  buf[s++] = 0;
937  while (s < len && buf[s] == ' ') {
938  s++;
939  }
940 
941  /* What is done with the returned data depends on what the server
942  * returns. In some cases the client may fall back to other methods,
943  * report an error, or try another setup command.
944  */
945  if (!strcmp(cmd, "sound2")) {
946  /* No parsing needed, but we don't want a warning about unknown
947  * setup option below.
948  */
949  } else if (!strcmp(cmd, "sound")) {
950  /* No, this should not be !strcmp()... */
951  } else if (!strcmp(cmd, "mapsize")) {
952  int x, y = 0;
953  char *cp, tmpbuf[MAX_BUF];
954 
955  if (!g_ascii_strcasecmp(param, "false")) {
957  "Server only supports standard sized maps (11x11)");
958  /* Do this because we may have been playing on a big server
959  * before */
963  resize_map_window(use_config[CONFIG_MAPWIDTH], use_config[CONFIG_MAPHEIGHT]);
964  continue;
965  }
966  x = atoi(param);
967  for (cp = param; *cp != 0; cp++) {
968  if (*cp == 'x' || *cp == 'X') {
969  y = atoi(cp+1);
970  break;
971  }
972  }
973  /* A size larger than what the server supports was requested.
974  * Reduce the size to server maximum, and re-send the setup
975  * command. Update our want sizes, and tell the player what is
976  * going on.
977  */
979  if (use_config[CONFIG_MAPWIDTH] > x) {
981  }
982  if (use_config[CONFIG_MAPHEIGHT] > y) {
984  }
987  "setup mapsize %dx%d", use_config[CONFIG_MAPWIDTH], use_config[CONFIG_MAPHEIGHT]);
988  snprintf(tmpbuf, sizeof(tmpbuf), "Server supports a max mapsize of %d x %d - requesting a %d x %d mapsize",
989  x, y, use_config[CONFIG_MAPWIDTH], use_config[CONFIG_MAPHEIGHT]);
991  tmpbuf);
992  } else if (use_config[CONFIG_MAPWIDTH] == x && use_config[CONFIG_MAPHEIGHT] == y) {
994  resize_map_window(use_config[CONFIG_MAPWIDTH], use_config[CONFIG_MAPHEIGHT]);
995  } else {
996  /* The request was not bigger than what server supports, and
997  * not the same size, so what is the problem? Tell the user
998  * that something is wrong.
999  */
1000  snprintf(tmpbuf, sizeof(tmpbuf), "Unable to set mapsize on server - we wanted %d x %d, server returned %d x %d",
1002  draw_ext_info(
1004  }
1005  } else if (!strcmp(cmd, "darkness")) {
1006  /* Older servers might not support this setup command.
1007  */
1008  if (!strcmp(param, "FALSE")) {
1009  LOG(LOG_WARNING, "common::SetupCmd", "Server returned FALSE for setup command %s", cmd);
1010  }
1011  } else if (!strcmp(cmd, "spellmon")) {
1012 
1013  /* Older servers might not support this setup command or all of
1014  * the extensions.
1015  *
1016  * Spellmon 2 was added to the protocol in January 2010 to send an
1017  * additional spell information string with casting requirements
1018  * including required items, if the spell needs arguments passed
1019  * (like text for rune of marking), etc.
1020  *
1021  * To use the new feature, "setup spellmon 1 spellmon 2" is sent,
1022  * and if "spellmon 1 spellmon FALSE" is returned then the server
1023  * doesn't accept 2 - sending spellmon 2 to a server that does not
1024  * support it is not problematic, so the spellmon 1 command will
1025  * still be handled correctly by the server. If the server sends
1026  * "spellmon 1 spellmon 2" then the extended mode is in effect.
1027  *
1028  * It is not particularly important for the player to know what
1029  * level of command is accepted by the server. The extra features
1030  * will simply not be functionally available.
1031  */
1032  if (!strcmp(param, "FALSE")) {
1033  LOG(LOG_INFO, "common::SetupCmd", "Server returned FALSE for a %s setup command", cmd);
1034  } else {
1035  spellmon_level = atoi(param);
1036  }
1037  } else if (!strcmp(cmd, "facecache")) {
1038  use_config[CONFIG_CACHE] = atoi(param);
1039  } else if (!strcmp(cmd, "faceset")) {
1040  if (!strcmp(param, "FALSE")) {
1042  "Server does not support other image sets, will use default");
1043  face_info.faceset = 0;
1044  }
1045  } else if (!strcmp(cmd, "map2cmd")) {
1046  if (!strcmp(param, "FALSE")) {
1048  "Server does not support map2cmd!");
1050  "This server is too old to support this client!");
1052  }
1053  } else if (!strcmp(cmd, "want_pickup")) {
1054  /* Nothing special to do as this is info pushed from server and
1055  * not having it isn't that bad.
1056  */
1057  } else if (!strcmp(cmd, "loginmethod")) {
1058  int method = atoi(param);
1059 
1060  /* If the server supports new login, start the process. Pass what
1061  * version the server supports so client can do appropriate
1062  * work
1063  */
1064  if (method) {
1065  start_login(method);
1066  }
1067  } else {
1068  LOG(LOG_INFO, "common::SetupCmd",
1069  "Got setup for a command we don't understand: %s %s",
1070  cmd, param);
1071  }
1072  }
1073 }
1074 
1083 void AddMeFail(char *data, int len)
1084 {
1085  (void)data; /* __UNUSED__ */
1086  (void)len; /* __UNUSED__ */
1087 
1088  LOG(LOG_INFO, "common::AddMeFail", "addme_failed received.");
1089  return;
1090 }
1091 
1099 void AddMeSuccess(char *data, int len)
1100 {
1101  (void)data; /* __UNUSED__ */
1102  (void)len; /* __UNUSED__ */
1103 
1105  show_main_client();
1106  LOG(LOG_DEBUG, "common::AddMeSuccess", "addme_success received.");
1107  return;
1108 }
1109 
1115 void GoodbyeCmd(char *data, int len)
1116 {
1117  (void)data; /* __UNUSED__ */
1118  (void)len; /* __UNUSED__ */
1119 
1120  /* This could probably be greatly improved - I am not sure if anything
1121  * needs to be saved here, but it should be possible to reconnect to the
1122  * server or a different server without having to rerun the client.
1123  */
1124  LOG(LOG_WARNING, "common::GoodbyeCmd", "Received goodbye command from server - exiting");
1125  exit(0);
1126 }
1127 
1129 
1135 void AnimCmd(unsigned char *data, int len)
1136 {
1137  short anum;
1138  int i, j;
1139 
1140  anum = GetShort_String(data);
1141  if (anum < 0 || anum > MAXANIM) {
1142  LOG(LOG_WARNING, "common::AnimCmd", "animation number invalid: %d", anum);
1143  return;
1144  }
1145 
1146  animations[anum].flags = GetShort_String(data+2);
1147  animations[anum].num_animations = (len-4)/2;
1148  if (animations[anum].num_animations < 1) {
1149  LOG(LOG_WARNING, "common::AnimCmd", "num animations invalid: %d",
1150  animations[anum].num_animations);
1151  return;
1152  }
1153  animations[anum].faces = g_malloc(sizeof(guint16)*animations[anum].num_animations);
1154  for (i = 4, j = 0; i < len; i += 2, j++) {
1155  animations[anum].faces[j] = GetShort_String(data+i);
1156  }
1157 
1158  if (j != animations[anum].num_animations) {
1159  LOG(LOG_WARNING, "common::AnimCmd",
1160  "Calculated animations does not equal stored animations? (%d!=%d)",
1161  j, animations[anum].num_animations);
1162  }
1163 
1164  animations[anum].speed = 0;
1165  animations[anum].speed_left = 0;
1166  animations[anum].phase = 0;
1167 
1168  LOG(LOG_DEBUG, "common::AnimCmd", "Received animation %d, %d faces", anum, animations[anum].num_animations);
1169 }
1170 
1180 void SmoothCmd(unsigned char *data, int len)
1181 {
1182  guint16 faceid;
1183  guint16 smoothing;
1184 
1185  /* len is unused. We should check that we don't have an invalid short
1186  * command. Hence, the compiler warning is valid.
1187  */
1188 
1189  faceid = GetShort_String(data);
1190  smoothing = GetShort_String(data+2);
1191  addsmooth(faceid, smoothing);
1192 }
1193 
1200 void DrawInfoCmd(char *data, int len)
1201 {
1202  int color = atoi(data);
1203  char *buf;
1204 
1205  (void)len; /* __UNUSED__ */
1206 
1207  buf = strchr(data, ' ');
1208  if (!buf) {
1209  LOG(LOG_WARNING, "common::DrawInfoCmd", "got no data");
1210  buf = "";
1211  } else {
1212  buf++;
1213  }
1215 }
1216 
1218 
1224 void setTextManager(int type, ExtTextManager callback)
1225 {
1226  TextManager *current = firstTextManager;
1227 
1228  while (current != NULL) {
1229  if (current->type == type) {
1230  current->callback = callback;
1231  return;
1232  }
1233  current = current->next;
1234  }
1235  current = g_malloc(sizeof(TextManager));
1236  current->type = type;
1237  current->callback = callback;
1238  current->next = firstTextManager;
1239  firstTextManager = current;
1240 }
1241 
1247 {
1248  TextManager *current = firstTextManager;
1249  while (current != NULL) {
1250  if (current->type == type) {
1251  return current->callback;
1252  }
1253  current = current->next;
1254  }
1255  return NULL;
1256 }
1257 
1264 void DrawExtInfoCmd(char *data, int len)
1265 {
1266  int color;
1267  int type, subtype;
1268  char *buf = data;
1269  int wordCount = 3;
1270  ExtTextManager fnct;
1271 
1272  while (wordCount > 0) {
1273  while (buf[0] == ' ') {
1274  buf++;
1275  }
1276  wordCount--;
1277  while (buf[0] != ' ') {
1278  if (buf[0] == '\0') {
1279  LOG(LOG_WARNING,
1280  "common::DrawExtInfoCmd", "Data is missing %d parameters %s",
1281  wordCount,
1282  data);
1283  return;
1284  } else {
1285  buf++;
1286  }
1287  }
1288  if (buf[0] == ' ') {
1289  buf++; /*remove trailing space to send clean data to callback */
1290  }
1291  }
1292  wordCount = sscanf(data, "%d %d %d", &color, &type, &subtype);
1293  if (wordCount != 3) {
1294  LOG(LOG_WARNING,
1295  "common::DrawExtInfoCmd", "Wrong parameters received. Could only parse %d out of 3 int in %s",
1296  wordCount,
1297  data);
1298  return;
1299  }
1300  fnct = getTextManager(type);
1301  if (fnct == NULL) {
1302  LOG(LOG_WARNING,
1303  "common::DrawExtInfoCmd", "Server send us a type %d but i can't find any callback for it",
1304  type);
1305  return;
1306  }
1307  fnct(color, type, subtype, buf);
1308 }
1309 
1316 void use_skill(int skill_id)
1317 {
1318  int i = 0;
1319  int next;
1320  int prev = last_used_skills[0];
1321 
1322  if(last_used_skills[0] == skill_id) {
1323  return;
1324  }
1325 
1326  do {
1327  next = last_used_skills[i+1];
1328  last_used_skills[i+1] = prev;
1329  prev = next;
1330  ++i;
1331  } while(next != skill_id && next >= 0);
1332  last_used_skills[0] = skill_id;
1333 }
1334 
1341 void StatsCmd(unsigned char *data, int len)
1342 {
1343  int i = 0, c, redraw = 0;
1344  gint64 last_exp;
1345 
1346  while (i < len) {
1347  c = data[i++];
1348  if (c >= CS_STAT_RESIST_START && c <= CS_STAT_RESIST_END) {
1350  i += 2;
1351  cpl.stats.resist_change = 1;
1352  } else if (c >= CS_STAT_SKILLINFO && c < (CS_STAT_SKILLINFO+CS_NUM_SKILLS)) {
1353  /* We track to see if the exp has gone from 0 to some total value
1354  * - we do this because the draw logic currently only draws skills
1355  * where the player has exp. We need to communicate to the draw
1356  * function that it should draw all the players skills. Using
1357  * redraw is a little overkill, because a lot of the data may not
1358  * be changing. OTOH, such a transition should only happen
1359  * rarely, not not be a very big deal.
1360  */
1361  cpl.stats.skill_level[c-CS_STAT_SKILLINFO] = data[i++];
1362  last_exp = cpl.stats.skill_exp[c-CS_STAT_SKILLINFO];
1365  if (last_exp == 0 && cpl.stats.skill_exp[c-CS_STAT_SKILLINFO]) {
1366  redraw = 1;
1367  }
1368  i += 8;
1369  } else {
1370  switch (c) {
1371  case CS_STAT_HP:
1372  cpl.stats.hp = GetShort_String(data+i);
1373  i += 2;
1374  break;
1375  case CS_STAT_MAXHP:
1376  cpl.stats.maxhp = GetShort_String(data+i);
1377  i += 2;
1378  break;
1379  case CS_STAT_SP:
1380  cpl.stats.sp = GetShort_String(data+i);
1381  i += 2;
1382  break;
1383  case CS_STAT_MAXSP:
1384  cpl.stats.maxsp = GetShort_String(data+i);
1385  i += 2;
1386  break;
1387  case CS_STAT_GRACE:
1388  cpl.stats.grace = GetShort_String(data+i);
1389  i += 2;
1390  break;
1391  case CS_STAT_MAXGRACE:
1392  cpl.stats.maxgrace = GetShort_String(data+i);
1393  i += 2;
1394  break;
1395  case CS_STAT_STR:
1396  cpl.stats.Str = GetShort_String(data+i);
1397  i += 2;
1398  break;
1399  case CS_STAT_INT:
1400  cpl.stats.Int = GetShort_String(data+i);
1401  i += 2;
1402  break;
1403  case CS_STAT_POW:
1404  cpl.stats.Pow = GetShort_String(data+i);
1405  i += 2;
1406  break;
1407  case CS_STAT_WIS:
1408  cpl.stats.Wis = GetShort_String(data+i);
1409  i += 2;
1410  break;
1411  case CS_STAT_DEX:
1412  cpl.stats.Dex = GetShort_String(data+i);
1413  i += 2;
1414  break;
1415  case CS_STAT_CON:
1416  cpl.stats.Con = GetShort_String(data+i);
1417  i += 2;
1418  break;
1419  case CS_STAT_CHA:
1420  cpl.stats.Cha = GetShort_String(data+i);
1421  i += 2;
1422  break;
1423  case CS_STAT_EXP:
1424  cpl.stats.exp = GetInt_String(data+i);
1425  i += 4;
1426  break;
1427  case CS_STAT_EXP64:
1428  cpl.stats.exp = GetInt64_String(data+i);
1429  i += 8;
1430  break;
1431  case CS_STAT_LEVEL:
1432  cpl.stats.level = GetShort_String(data+i);
1433  i += 2;
1434  break;
1435  case CS_STAT_WC:
1436  cpl.stats.wc = GetShort_String(data+i);
1437  i += 2;
1438  break;
1439  case CS_STAT_AC:
1440  cpl.stats.ac = GetShort_String(data+i);
1441  i += 2;
1442  break;
1443  case CS_STAT_DAM:
1444  cpl.stats.dam = GetShort_String(data+i);
1445  i += 2;
1446  break;
1447  case CS_STAT_ARMOUR:
1448  cpl.stats.resists[0] = GetShort_String(data+i);
1449  i += 2;
1450  break;
1451  case CS_STAT_SPEED:
1452  cpl.stats.speed = GetInt_String(data+i);
1453  i += 4;
1454  break;
1455  case CS_STAT_FOOD:
1456  cpl.stats.food = GetShort_String(data+i);
1457  i += 2;
1458  break;
1459  case CS_STAT_WEAP_SP:
1460  cpl.stats.weapon_sp = GetInt_String(data+i);
1461  i += 4;
1462  break;
1463  case CS_STAT_SPELL_ATTUNE:
1464  cpl.stats.attuned = GetInt_String(data+i);
1465  i += 4;
1466  cpl.spells_updated = 1;
1467  break;
1468  case CS_STAT_SPELL_REPEL:
1469  cpl.stats.repelled = GetInt_String(data+i);
1470  i += 4;
1471  cpl.spells_updated = 1;
1472  break;
1473  case CS_STAT_SPELL_DENY:
1474  cpl.stats.denied = GetInt_String(data+i);
1475  i += 4;
1476  cpl.spells_updated = 1;
1477  break;
1478 
1479  case CS_STAT_FLAGS:
1480  cpl.stats.flags = GetShort_String(data+i);
1481  i += 2;
1482  break;
1483  case CS_STAT_WEIGHT_LIM:
1485  i += 4;
1486  /* Mark weight limit changes to update the client inventory window */
1487  cpl.ob->inv_updated = 1;
1488  break;
1489 
1490  case CS_STAT_RANGE: {
1491  int rlen = data[i++];
1492  strncpy(cpl.range, (const char*)data+i, rlen);
1493  cpl.range[rlen] = '\0';
1494  i += rlen;
1495  break;
1496  }
1497 
1498  case CS_STAT_TITLE: {
1499  int rlen = data[i++];
1500  strncpy(cpl.title, (const char*)data+i, rlen);
1501  cpl.title[rlen] = '\0';
1502  i += rlen;
1503  break;
1504  }
1505 
1506  default:
1507  LOG(LOG_WARNING, "common::StatsCmd", "Unknown stat number %d", c);
1508  break;
1509  }
1510  }
1511  }
1512 
1513  if (i > len) {
1514  LOG(LOG_WARNING, "common::StatsCmd", "got stats overflow, processed %d bytes out of %d", i, len);
1515  }
1516  draw_stats(redraw);
1518 #ifdef HAVE_LUA
1519  script_lua_stats();
1520 #endif
1521 }
1522 
1529 void handle_query(char *data, int len)
1530 {
1531  char *buf, *cp;
1532  guint8 flags = atoi(data);
1533 
1534  (void)len; /* __UNUSED__ */
1535 
1536  if (flags&CS_QUERY_HIDEINPUT) { /* No echo */
1537  cpl.no_echo = 1;
1538  } else {
1539  cpl.no_echo = 0;
1540  }
1541 
1542  /* Let the window system know this may have changed */
1543  x_set_echo();
1544 
1545  /* The actual text is optional */
1546  buf = strchr(data, ' ');
1547  if (buf) {
1548  buf++;
1549  }
1550 
1551  /* If we just get passed an empty string, why draw this? */
1552  if (buf) {
1553  cp = buf;
1554  while ((buf = strchr(buf, '\n')) != NULL) {
1555  *buf++ = '\0';
1556  draw_ext_info(
1558  cp = buf;
1559  }
1560  /* Yes/no - don't do anything with it now */
1561  if (flags&CS_QUERY_YESNO) {
1562  }
1563 
1564  /* One character response expected */
1565  if (flags&CS_QUERY_SINGLECHAR) {
1567  } else {
1569  }
1570 
1571  if (cp) {
1572  draw_prompt(cp);
1573  }
1574  }
1575 
1576  LOG(LOG_DEBUG, "common::handle_query", "Received query. Input state now %d", cpl.input_state);
1577 }
1578 
1585 void send_reply(const char *text)
1586 {
1587  cs_print_string(csocket.fd, "reply %s", text);
1588 
1589  /* Let the window system know that the (possibly hidden) query is over. */
1590  cpl.no_echo = 0;
1591  x_set_echo();
1592 }
1593 
1602 void PlayerCmd(unsigned char *data, int len)
1603 {
1604  char name[MAX_BUF];
1605  int tag, weight, face, i = 0, nlen;
1606 
1608  tag = GetInt_String(data);
1609  i += 4;
1610  weight = GetInt_String(data+i);
1611  i += 4;
1612  face = GetInt_String(data+i);
1613  i += 4;
1614  nlen = data[i++];
1615  memcpy(name, (const char*)data+i, nlen);
1616  name[nlen] = '\0';
1617  i += nlen;
1618 
1619  if (i != len) {
1620  LOG(LOG_WARNING, "common::PlayerCmd", "lengths do not match (%d!=%d)", len, i);
1621  }
1622  new_player(tag, name, weight, face);
1623 }
1624 
1630 {
1631  if (!op) {
1632  return;
1633  }
1634 
1635  if (op->open) {
1636  open_container(op);
1637  cpl.container = op;
1638  } else if (op->was_open) {
1639  close_container(op);
1640  cpl.container = NULL;
1641  }
1642 }
1643 
1651 static void common_item_command(guint8 *data, int len)
1652 {
1653 
1654  int weight, loc, tag, face, flags, pos = 0, nlen, anim, nrof, type;
1655  guint8 animspeed;
1656  char name[MAX_BUF];
1657 
1658  loc = GetInt_String(data);
1659  pos += 4;
1660 
1661  if (pos == len) {
1662  LOG(LOG_WARNING, "common::common_item_command", "Got location with no other data");
1663  return;
1664  } else if (loc < 0) { /* Delete following items */
1665  LOG(LOG_WARNING, "common::common_item_command", "Got location with negative value (%d)", loc);
1666  return;
1667  } else {
1668  while (pos < len) {
1669  tag = GetInt_String(data+pos);
1670  pos += 4;
1671  flags = GetInt_String(data+pos);
1672  pos += 4;
1673  weight = GetInt_String(data+pos);
1674  pos += 4;
1675  face = GetInt_String(data+pos);
1676  pos += 4;
1677  nlen = data[pos++];
1678  memcpy(name, (char*)data+pos, nlen);
1679  pos += nlen;
1680  name[nlen] = '\0';
1681  anim = GetShort_String(data+pos);
1682  pos += 2;
1683  animspeed = data[pos++];
1684  nrof = GetInt_String(data+pos);
1685  pos += 4;
1686  type = GetShort_String(data+pos);
1687  pos += 2;
1688  update_item(tag, loc, name, weight, face, flags, anim, animspeed, nrof, type);
1689  item_actions(locate_item(tag));
1690  }
1691  if (pos > len) {
1692  LOG(LOG_WARNING, "common::common_item_cmd", "Overread buffer: %d > %d", pos, len);
1693  }
1694  }
1695 }
1696 
1702 void Item2Cmd(unsigned char *data, int len)
1703 {
1704  common_item_command(data, len);
1705 }
1706 
1713 void UpdateItemCmd(unsigned char *data, int len)
1714 {
1715  int weight, loc, tag, face, sendflags, flags, pos = 0, nlen, anim;
1716  guint32 nrof;
1717  char name[MAX_BUF];
1718  item *ip;
1719  guint8 animspeed;
1720 
1721  sendflags = data[0];
1722  pos += 1;
1723  tag = GetInt_String(data+pos);
1724  pos += 4;
1725  ip = locate_item(tag);
1726  if (!ip) {
1727  /*
1728  fprintf(stderr, "Got update_item command for item we don't have (%d)\n", tag);
1729  */
1730  return;
1731  }
1732 
1733  /* Copy all of these so we can pass the values to update_item and don't
1734  * need to figure out which ones were modified by this function.
1735  */
1736  *name = '\0';
1737  loc = ip->env ? ip->env->tag : 0;
1738  weight = ip->weight*1000;
1739  face = ip->face;
1740  flags = ip->flagsval;
1741  anim = ip->animation_id;
1742  animspeed = ip->anim_speed;
1743  nrof = ip->nrof;
1744 
1745  if (sendflags&UPD_LOCATION) {
1746  loc = GetInt_String(data+pos);
1747  LOG(LOG_WARNING, "common::UpdateItemCmd", "Got tag of unknown object (%d) for new location", loc);
1748  pos += 4;
1749  }
1750  if (sendflags&UPD_FLAGS) {
1751  flags = GetInt_String(data+pos);
1752  pos += 4;
1753  }
1754  if (sendflags&UPD_WEIGHT) {
1755  weight = GetInt_String(data+pos);
1756  pos += 4;
1757  }
1758  if (sendflags&UPD_FACE) {
1759  face = GetInt_String(data+pos);
1760  pos += 4;
1761  }
1762  if (sendflags&UPD_NAME) {
1763  nlen = data[pos++];
1764  memcpy(name, (char*)data+pos, nlen);
1765  pos += nlen;
1766  name[nlen] = '\0';
1767  }
1768  if (pos > len) {
1769  LOG(LOG_WARNING, "common::UpdateItemCmd", "Overread buffer: %d > %d", pos, len);
1770  return; /* We have bad data, probably don't want to store it then */
1771  }
1772  if (sendflags&UPD_ANIM) {
1773  anim = GetShort_String(data+pos);
1774  pos += 2;
1775  }
1776  if (sendflags&UPD_ANIMSPEED) {
1777  animspeed = data[pos++];
1778  }
1779  if (sendflags&UPD_NROF) {
1780  nrof = (guint32)GetInt_String(data+pos);
1781  pos += 4;
1782  }
1783  /* update_item calls set_item_values which will then set the list redraw
1784  * flag, so we don't need to do an explicit redraw here. Actually,
1785  * calling update_item is a little bit of overkill, since we already
1786  * determined some of the values in this function.
1787  */
1788  update_item(tag, loc, name, weight, face, flags, anim, animspeed, nrof, ip->type);
1789  item_actions(locate_item(tag));
1790 }
1791 
1797 void DeleteItem(unsigned char *data, int len)
1798 {
1799  int pos = 0, tag;
1800 
1801  while (pos < len) {
1802  item *op;
1803 
1804  tag = GetInt_String(data+pos);
1805  pos += 4;
1806  op = locate_item(tag);
1807  if (op != NULL) {
1808  remove_item(op);
1809  } else {
1810  LOG(LOG_WARNING, "common::DeleteItem", "Cannot find tag %d", tag);
1811  }
1812  }
1813  if (pos > len) {
1814  LOG(LOG_WARNING, "common::DeleteItem", "Overread buffer: %d > %d", pos, len);
1815  }
1816 }
1817 
1823 void DeleteInventory(unsigned char *data, int len)
1824 {
1825  int tag;
1826  item *op;
1827 
1828  (void)len; /* __UNUSED__ */
1829 
1830  tag = atoi((const char*)data);
1831  op = locate_item(tag);
1832  if (op != NULL) {
1834  } else {
1835  LOG(LOG_WARNING, "common::DeleteInventory", "Invalid tag: %d", tag);
1836  }
1837 }
1838 
1839 /****************************************************************************/
1840 
1851 void AddspellCmd(unsigned char *data, int len)
1852 {
1853  guint8 nlen;
1854  guint16 mlen, pos = 0;
1855  Spell *newspell, *tmp;
1856 
1857  while (pos < len) {
1858  newspell = calloc(1, sizeof(Spell));
1859 
1860  /* Get standard spell information (spellmon 1)
1861  */
1862  newspell->tag = GetInt_String(data+pos);
1863  pos += 4;
1864  newspell->level = GetShort_String(data+pos);
1865  pos += 2;
1866  newspell->time = GetShort_String(data+pos);
1867  pos += 2;
1868  newspell->sp = GetShort_String(data+pos);
1869  pos += 2;
1870  newspell->grace = GetShort_String(data+pos);
1871  pos += 2;
1872  newspell->dam = GetShort_String(data+pos);
1873  pos += 2;
1874  newspell->skill_number = GetChar_String(data+pos);
1875  pos += 1;
1876  newspell->path = GetInt_String(data+pos);
1877  pos += 4;
1878  newspell->face = GetInt_String(data+pos);
1879  pos += 4;
1880  nlen = GetChar_String(data+pos);
1881  pos += 1;
1882  strncpy(newspell->name, (char*)data+pos, nlen);
1883  pos += nlen;
1884  newspell->name[nlen] = '\0'; /* To ensure we are null terminated */
1885  mlen = GetShort_String(data+pos);
1886  pos += 2;
1887  strncpy(newspell->message, (char*)data+pos, mlen);
1888  pos += mlen;
1889  newspell->message[mlen] = '\0'; /* To ensure we are null terminated */
1890 
1891  if (spellmon_level < 2) {
1892 
1893  /* The server is not sending spellmon 2 extended information, so
1894  * initialize the spell data fields as unused/empty.
1895  */
1896  newspell->usage = 0;
1897  newspell->requirements[0] = '\0';
1898 
1899  } else if (pos < len) {
1900 
1901  /* The server is sending extended spell information (spellmon 2) so
1902  * process it.
1903  */
1904  newspell->usage = GetChar_String(data+pos);
1905  pos += 1;
1906  nlen = GetChar_String(data+pos);
1907  pos += 1;
1908  strncpy(newspell->requirements, (char*) data+pos, nlen);
1909  pos += nlen;
1910  newspell->requirements[nlen] = '\0'; /* Ensure null-termination */
1911  }
1912 
1913  /* Compute the derived spell information.
1914  */
1915  newspell->skill = skill_names[newspell->skill_number-CS_STAT_SKILLINFO];
1916 
1917  /* Add the spell to the player struct.
1918  */
1919  if (!cpl.spelldata) {
1920  cpl.spelldata = newspell;
1921  } else {
1922  for (tmp = cpl.spelldata; tmp->next; tmp = tmp->next)
1923  ;
1924  tmp->next = newspell;
1925  }
1926  /* Check to see if there are more spells to add.
1927  */
1928  }
1929  if (pos > len) {
1930  LOG(LOG_WARNING, "common::AddspellCmd", "Overread buffer: %d > %d", pos, len);
1931  }
1932  cpl.spells_updated = 1;
1933 }
1934 
1935 void UpdspellCmd(unsigned char *data, int len) {
1936  int flags, pos = 0;
1937  guint32 tag;
1938  Spell *tmp;
1939 
1940  if (!cpl.spelldata) {
1941  LOG(LOG_WARNING, "common::UpdspellCmd", "I know no spells to update");
1942  return;
1943  }
1944 
1945  flags = GetChar_String(data+pos);
1946  pos += 1;
1947  tag = GetInt_String(data+pos);
1948  pos += 4;
1949  for (tmp = cpl.spelldata; tmp && tmp->tag != tag; tmp = tmp->next)
1950  ;
1951  if (!tmp) {
1952  LOG(LOG_WARNING, "common::UpdspellCmd", "Invalid tag: %d", tag);
1953  return;
1954  }
1955  if (flags&UPD_SP_MANA) {
1956  tmp->sp = GetShort_String(data+pos);
1957  pos += 2;
1958  }
1959  if (flags&UPD_SP_GRACE) {
1960  tmp->grace = GetShort_String(data+pos);
1961  pos += 2;
1962  }
1963  if (flags&UPD_SP_DAMAGE) {
1964  tmp->dam = GetShort_String(data+pos);
1965  pos += 2;
1966  }
1967  if (pos > len) {
1968  LOG(LOG_WARNING, "common::UpdspellCmd", "Overread buffer: %d > %d", pos, len);
1969  }
1970  cpl.spells_updated = 1;
1971 }
1972 
1973 void DeleteSpell(unsigned char *data, int len) {
1974  guint32 tag;
1975  Spell *tmp, *target;
1976 
1977  if (!cpl.spelldata) {
1978  LOG(LOG_WARNING, "common::DeleteSpell", "I know no spells to delete");
1979  return;
1980  }
1981 
1982  tag = GetInt_String(data);
1983  /* Special case: the first spell is the one removed */
1984  if (cpl.spelldata->tag == tag) {
1985  target = cpl.spelldata;
1986  if (target->next) {
1987  cpl.spelldata = target->next;
1988  } else {
1989  cpl.spelldata = NULL;
1990  }
1991  free(target);
1992  return;
1993  }
1994 
1995  for (tmp = cpl.spelldata; tmp->next && tmp->next->tag != tag; tmp = tmp->next)
1996  ;
1997  if (!tmp->next) {
1998  LOG(LOG_WARNING, "common::DeleteSpell", "Invalid tag: %d", tag);
1999  return;
2000  }
2001  target = tmp->next;
2002  if (target->next) {
2003  tmp->next = target->next;
2004  } else {
2005  tmp->next = NULL;
2006  }
2007  free(target);
2008  cpl.spells_updated = 1;
2009 }
2010 
2011 /****************************************************************************/
2012  /* EndOf SCSpellCommands
2015  */
2016 
2027 void NewmapCmd(unsigned char *data, int len)
2028 {
2029  (void)data; /* __UNUSED__ */
2030  (void)len; /* __UNUSED__ */
2031 
2032  mapdata_newmap();
2033 }
2034 
2035 /* This is the common processing block for the map1 and map1a protocol
2036  * commands. The map1a mieks minor extensions and are easy to deal with
2037  * inline (in fact, this code doesn't even care what rev is - just certain
2038  * bits will only bet set when using the map1a command. rev is 0 for map1, 1
2039  * for map1a. It conceivable that there could be future revisions.
2040  */
2041 
2042 /* NUM_LAYERS should only be used for the map1{a} which only has a few layers.
2043  * Map2 has 10 layers. However, some of the map1 logic requires this to be
2044  * set right.
2045  */
2046 #define NUM_LAYERS (MAP1_LAYERS-1)
2047 
2053 void Map2Cmd(unsigned char *data, int len)
2054 {
2055  int mask, x, y, pos = 0, space_len, value;
2056  guint8 type;
2057 
2058  /* Not really using map1 protocol, but some draw logic differs from the
2059  * original draw logic, and map2 is closest.
2060  */
2061  while (pos < len) {
2062  mask = GetShort_String(data+pos);
2063  pos += 2;
2064  x = ((mask>>10)&0x3f)-MAP2_COORD_OFFSET;
2065  y = ((mask>>4)&0x3f)-MAP2_COORD_OFFSET;
2066 
2067  /* This is a scroll then. Go back and fetch another coordinate */
2068  if (mask&0x1) {
2069  mapdata_scroll(x, y);
2070  continue;
2071  }
2072 
2073  if (x<0) {
2074  LOG(LOG_WARNING, "commands.c::Map2Cmd", "got negative x!");
2075  x = 0;
2076  } else if (x >= MAX_VIEW) {
2077  LOG(LOG_WARNING, "commands.c::Map2Cmd", "got x >= MAX_VIEW!");
2078  x = MAX_VIEW - 1;
2079  }
2080 
2081  if (y<0) {
2082  LOG(LOG_WARNING, "commands.c::Map2Cmd", "got negative y!");
2083  y = 0;
2084  } else if (y >= MAX_VIEW) {
2085  LOG(LOG_WARNING, "commands.c::Map2Cmd", "got y >= MAX_VIEW!");
2086  y = MAX_VIEW - 1;
2087  }
2088 
2089  assert(0 <= x && x < MAX_VIEW);
2090  assert(0 <= y && y < MAX_VIEW);
2091  /* Clearing old cell data as needed (was in mapdata_set_face_layer()
2092  * before however that caused darkness to only work if sent after the
2093  * layers).
2094  */
2095  mapdata_clear_old(x, y);
2096 
2097  /* Inner loop is for the data on the space itself */
2098  while (pos < len) {
2099  type = data[pos++];
2100  /* type == 255 means nothing more for this space */
2101  if (type == 255) {
2103  break;
2104  }
2105  space_len = type>>5;
2106  type &= 0x1f;
2107  /* Clear the space */
2108  if (type == MAP2_TYPE_CLEAR) {
2109  mapdata_clear_space(x, y);
2110  continue;
2111  } else if (type == MAP2_TYPE_DARKNESS) {
2112  value = data[pos++];
2113  mapdata_set_darkness(x, y, value);
2114  continue;
2115  } else if (type >= MAP2_LAYER_START && type < MAP2_LAYER_START+MAXLAYERS) {
2116  int layer, opt;
2117 
2118  /* This is face information for a layer. */
2119  layer = type&0xf;
2120 
2121  if (layer < 0) {
2122  LOG(LOG_WARNING, "commands.c::Map2Cmd", "got negative layer!");
2123  layer = 0;
2124  } else if (layer >= MAXLAYERS) {
2125  LOG(LOG_WARNING, "commands.c::Map2Cmd", "got layer >= MAXLAYERS!");
2126  layer = MAXLAYERS - 1;
2127  }
2128  assert(0 <= layer && layer < MAXLAYERS);
2129 
2130  /* This is the face */
2131  value = GetShort_String(data+pos);
2132  pos += 2;
2133  if (!(value&FACE_IS_ANIM)) {
2134  mapdata_set_face_layer(x, y, value, layer);
2135  }
2136 
2137  if (space_len > 2) {
2138  opt = data[pos++];
2139  if (value&FACE_IS_ANIM) {
2140  /* Animation speed */
2141  mapdata_set_anim_layer(x, y, value, opt, layer);
2142  } else {
2143  /* Smooth info */
2144  mapdata_set_smooth(x, y, opt, layer);
2145  }
2146  }
2147  /* Currently, if 4 bytes, must be a smooth byte */
2148  if (space_len > 3) {
2149  opt = data[pos++];
2150  mapdata_set_smooth(x, y, opt, layer);
2151  }
2152  continue;
2153  } /* if image layer */
2154  } /* while pos<len inner loop for space */
2155  } /* While pos<len outer loop */
2156  mapupdatesent = 0;
2157  display_map_doneupdate(FALSE, FALSE);
2158 }
2159 
2166 void map_scrollCmd(char *data, int len)
2167 {
2168  int dx, dy;
2169  char *buf;
2170 
2171  (void)len; /* __UNUSED__ */
2172 
2173  dx = atoi(data);
2174  buf = strchr(data, ' ');
2175  if (!buf) {
2176  LOG(LOG_WARNING, "common::map_scrollCmd", "Got short packet.");
2177  return;
2178  }
2179  buf++;
2180  dy = atoi(buf);
2181 
2182  mapdata_scroll(dx, dy);
2183  display_map_doneupdate(FALSE, TRUE);
2184 }
2185 
2196 int ExtSmooth(unsigned char *data, int len, int x, int y, int layer)
2197 {
2198  static int dx[8] = { 0, 1, 1, 1, 0, -1, -1, -1, };
2199  static int dy[8] = { -1, -1, 0, 1, 1, 1, 0, -1, };
2200  int i, rx, ry;
2201  int newsm;
2202 
2203  if (len < 1) {
2204  return 0;
2205  }
2206 
2207  x += pl_pos.x;
2208  y += pl_pos.y;
2209  newsm = GetChar_String(data);
2210 
2211  if (mapdata_cell(x, y)->smooth[layer] != newsm) {
2212  for (i = 0; i < 8; i++) {
2213  rx = x+dx[i];
2214  ry = y+dy[i];
2215  if (!mapdata_contains(rx, ry)) {
2216  continue;
2217  }
2218  mapdata_cell(x, y)->need_resmooth = 1;
2219  }
2220  }
2221  mapdata_cell(x, y)->smooth[layer] = newsm;
2222  return 1;/*Cause smooth infos only use 1 byte*/
2223 }
2224 
2234 void MapExtendedCmd(unsigned char *data, int len)
2235 {
2236  int mask, x, y, pos = 0, layer;
2237  int noredraw = 0;
2238  int hassmooth = 0;
2239  int entrysize;
2240  int startpackentry;
2241 
2242  mapupdatesent = 1;
2243  mask = GetChar_String(data+pos);
2244  pos += 1;
2245  if (mask&EMI_NOREDRAW) {
2246  noredraw = 1;
2247  }
2248  if (mask&EMI_SMOOTH) {
2249  hassmooth = 1;
2250  }
2251  while (mask&EMI_HASMOREBITS) {
2252  /*There may be bits we ignore about*/
2253  mask = GetChar_String(data+pos);
2254  pos += 1;
2255  }
2256  entrysize = GetChar_String(data+pos);
2257  pos = pos+1;
2258 
2259  while (pos+entrysize+2 <= len) {
2260  mask = GetShort_String(data+pos);
2261  pos += 2;
2262  x = (mask>>10)&0x3f;
2263  y = (mask>>4)&0x3f;
2264  for (layer = NUM_LAYERS; layer >= 0; layer--) {
2265  if (mask&(1<<layer)) {
2266  /*handle an entry*/
2267  if (pos+entrysize > len) { /*erroneous packet*/
2268  break;
2269  }
2270  startpackentry = pos;
2271  /* If you had extended infos to the server, this is where, in
2272  * the client, you may add your code
2273  */
2274  if (hassmooth) {
2275  pos = pos+ExtSmooth(data+pos, len-pos, x, y, NUM_LAYERS-layer);
2276  }
2277  /* Continue with other if you add new extended infos to server
2278  *
2279  * Now point to the next data
2280  */
2281  pos = startpackentry+entrysize;
2282  }
2283  }
2284  }
2285  if (!noredraw) {
2286  display_map_doneupdate(FALSE, FALSE);
2287  mapupdatesent = 0;
2288  }
2289 }
2290 
2296 void MagicMapCmd(unsigned char *data, int len)
2297 {
2298  unsigned char *cp;
2299  int i;
2300 
2301  /* First, extract the size/position information. */
2302  if (sscanf((const char*)data, "%hd %hd %hd %hd", &cpl.mmapx, &cpl.mmapy, &cpl.pmapx, &cpl.pmapy) != 4) {
2303  LOG(LOG_WARNING, "common::MagicMapCmd", "Was not able to properly extract magic map size, pos");
2304  return;
2305  }
2306 
2307  if (cpl.mmapx == 0 || cpl.mmapy == 0) {
2308  LOG(LOG_WARNING, "common::MagicMapCmd", "empty map");
2309  return;
2310  }
2311 
2312  /* Now we need to find the start of the actual data. There are 4 space
2313  * characters we need to skip over.
2314  */
2315  for (cp = data, i = 0; i < 4 && cp < data+len; cp++) {
2316  if (*cp == ' ') {
2317  i++;
2318  }
2319  }
2320  if (i != 4) {
2321  LOG(LOG_WARNING, "common::MagicMapCmd", "Was unable to find start of magic map data");
2322  return;
2323  }
2324  i = len-(cp-data); /* This should be the number of bytes left */
2325  if (i != cpl.mmapx*cpl.mmapy) {
2326  LOG(LOG_WARNING, "common::MagicMapCmd", "Magic map size mismatch. Have %d bytes, should have %d",
2327  i, cpl.mmapx*cpl.mmapy);
2328  return;
2329  }
2330  free(cpl.magicmap);
2331  cpl.magicmap = g_malloc(cpl.mmapx*cpl.mmapy);
2332  /* Order the server puts it in should be just fine. Note that the only
2333  * requirement that this works is that magicmap by 8 bits, being that is
2334  * the size specified in the protocol and what the server sends us.
2335  */
2336  memcpy(cpl.magicmap, cp, cpl.mmapx*cpl.mmapy);
2337  draw_magic_map();
2338 }
2339  /* EndOf SCMapCommands
2342  */
2343 
2349 void SinkCmd(unsigned char *data, int len)
2350 {
2351 }
2352 
2360 void TickCmd(guint8 *data, int len)
2361 {
2362 
2363  tick = GetInt_String(data);
2364 
2365  /* Up to the specific client to decide what to do */
2366  client_tick(tick);
2367 }
2368 
2377 void PickupCmd(guint8 *data, int len)
2378 {
2379  guint32 pickup = GetInt_String(data);
2380  client_pickup(pickup);
2381 }
2382 
2391 void FailureCmd(char *buf, int len)
2392 {
2393  char *cp;
2394 
2395  /* The format of the buffer is 'command error message'. We need to
2396  * extract the failed command, and then pass in the error message to the
2397  * appropriate handler. So find the space, set it to null. in that way,
2398  * buf is now just the failure command, and cp is the message.
2399  */
2400  cp = strchr(buf,' ');
2401  if (!cp) {
2402  return;
2403  }
2404 
2405  *cp = 0;
2406  cp++;
2407 
2408  if (!strcmp(buf,"accountlogin")) {
2410  } else if (!strcmp(buf,"accountnew")) {
2412  } else if (!strcmp(buf,"accountaddplayer")) {
2414  } else if (!strcmp(buf,"createplayer")) {
2416  } else if (!strcmp(buf, "accountpw")) {
2418  } else
2419  /* This really is an error - if this happens it menas the server
2420  * failed to process a request that the client made - the client
2421  * should be able to handle failures for all request types it makes.
2422  * But this is also a problem in that it means that the server is
2423  * waiting for a correct response, and if we do not display anything,
2424  * the player is unlikely to know this.
2425  */
2426  LOG(LOG_ERROR, "common::FailureCmd", "Got a failure response we can not handle: %s:%s",
2427  buf, cp);
2428 }
2429 
2433 void AccountPlayersCmd(char *buf, int len) {
2434  int level, pos, flen, faceno;
2435  char name[MAX_BUF], class[MAX_BUF], race[MAX_BUF],
2436  face[MAX_BUF], party[MAX_BUF], map[MAX_BUF];
2437 
2438  /* This is called first so it can clear out the existing data store.
2439  */
2441 
2442  level=0;
2443  name[0]=0;
2444  class[0]=0;
2445  race[0]=0;
2446  face[0]=0;
2447  party[0]=0;
2448  map[0]=0;
2449  faceno=0;
2450 
2451  pos=1;
2452  while (pos < len) {
2453  flen = buf[pos];
2454  /* flen == 0 is to note that we got end of character data */
2455  if (flen == 0) {
2456  update_character_choose(name, class, race, face, party, map, level, faceno);
2457  /* Blank all the values - it is no sure thing that the next
2458  * character will fill all these in.
2459  */
2460  level=0;
2461  name[0]=0;
2462  class[0]=0;
2463  race[0]=0;
2464  face[0]=0;
2465  party[0]=0;
2466  map[0]=0;
2467  faceno=0;
2468  pos++;
2469  continue;
2470  }
2471  pos++;
2472  if ((pos +flen) > len || flen>=MAX_BUF) {
2473  LOG(LOG_ERROR,"commands.c:AccountPlayerCmd", "data overran buffer");
2474  return;
2475  }
2476  switch (buf[pos]) {
2477  case ACL_NAME:
2478  strncpy(name, buf + pos +1, flen-1);
2479  name[flen-1] = 0;
2480  break;
2481 
2482  case ACL_CLASS:
2483  strncpy(class, buf + pos +1, flen-1);
2484  class[flen-1] = 0;
2485  break;
2486 
2487  case ACL_RACE:
2488  strncpy(race, buf + pos +1, flen-1);
2489  race[flen-1] = 0;
2490  break;
2491 
2492  case ACL_FACE:
2493  strncpy(face, buf + pos +1, flen-1);
2494  face[flen-1] = 0;
2495  break;
2496 
2497  case ACL_PARTY:
2498  strncpy(party, buf + pos +1, flen-1);
2499  party[flen-1] = 0;
2500  break;
2501 
2502  case ACL_MAP:
2503  strncpy(map, buf + pos +1, flen-1);
2504  map[flen-1] = 0;
2505  break;
2506 
2507  case ACL_LEVEL:
2508  level = GetShort_String((unsigned char *)buf + pos + 1);
2509  break;
2510  case ACL_FACE_NUM:
2511  faceno = GetShort_String((unsigned char *)buf + pos + 1);
2512  break;
2513  }
2514  pos += flen;
2515  }
2516 }
2517 
float weight
Definition: item.h:61
void PickupCmd(guint8 *data, int len)
Definition: commands.c:2377
#define CS_STAT_AC
Definition: newclient.h:100
gint16 grace
Definition: client.h:266
void free_all_race_class_info(Race_Class_Info *data, int num_entries)
Definition: commands.c:420
#define ACL_CLASS
Definition: newclient.h:197
void DeleteItem(unsigned char *data, int len)
Definition: commands.c:1797
gint8 wc
Definition: client.h:259
void handle_query(char *data, int len)
Definition: commands.c:1529
int num_races
Definition: commands.c:87
char * news
Definition: commands.c:82
void SetupCmd(char *buf, int len)
Definition: commands.c:901
struct Stat_Mapping stat_mapping[NUM_NEW_CHAR_STATS]
Definition: commands.c:118
#define INFO_MAP_ARCH_NAME
Definition: newclient.h:673
gint32 weapon_sp
Definition: client.h:276
GSocketConnection * fd
Definition: client.h:120
int stat_maximum
Definition: commands.c:95
char ** value_arch
Definition: client.h:598
char * choice_desc
Definition: client.h:596
guint32 tick
Definition: client.c:61
guint16 level
Definition: client.h:301
int num_values
Definition: client.h:597
gint16 use_config[CONFIG_NUMS]
Definition: init.c:40
#define CS_STAT_INT
Definition: newclient.h:92
void create_new_character_failure(char *message)
Definition: account.c:152
char * description
Definition: client.h:614
item * locate_item(gint32 tag)
Definition: item.c:300
#define UPD_ANIM
Definition: newclient.h:294
void DrawInfoCmd(char *data, int len)
Definition: commands.c:1200
void TickCmd(guint8 *data, int len)
Definition: commands.c:2360
void mapdata_set_check_space(int x, int y)
Definition: mapdata.c:675
void mapdata_clear_space(int x, int y)
Definition: mapdata.c:633
void set_weight_limit(guint32 wlim)
Definition: inventory.c:622
#define ACL_FACE_NUM
Definition: newclient.h:203
gint64 skill_exp[MAX_SKILL]
Definition: client.h:290
guint8 num_animations
Definition: client.h:100
char * motd
Definition: commands.c:82
void account_add_character_failure(char *message)
Definition: account.c:291
void choose_character_init(void)
Definition: account.c:439
#define UPD_SP_GRACE
Definition: newclient.h:300
#define EMI_SMOOTH
Definition: newclient.h:352
void reset_player_data()
Definition: init.c:226
guint16 inv_updated
Definition: item.h:76
#define ACL_LEVEL
Definition: newclient.h:199
void setTextManager(int type, ExtTextManager callback)
Definition: commands.c:1224
#define MAX_SKILL
Definition: client.h:84
void AddMeFail(char *data, int len)
Definition: commands.c:1083
gint16 maxsp
Definition: client.h:265
item * ob
Definition: client.h:336
short GetShort_String(const unsigned char *data)
Definition: newsocket.c:172
int stat_min
Definition: commands.c:94
Animations animations[MAXANIM]
Definition: commands.c:1128
struct item_struct * env
Definition: item.h:53
guint16 dam
Definition: client.h:305
#define NUM_STATS
Definition: commands.c:105
#define CS_STAT_SPEED
Definition: newclient.h:103
void account_change_password_failure(char *message)
Definition: account.c:1181
Warning that something might not work.
Definition: client.h:443
guint16 sp
Definition: client.h:303
struct MapCell * mapdata_cell(int x, int y)
Definition: mapdata.c:119
gint32 speed
Definition: client.h:275
#define MAP2_TYPE_CLEAR
Definition: newclient.h:42
void mapdata_set_face_layer(int x, int y, gint16 face, int layer)
Definition: mapdata.c:815
guint16 mmapy
Definition: client.h:360
#define MSG_TYPE_CLIENT_QUERY
Definition: newclient.h:662
void ReplyInfoCmd(unsigned char *buf, int len)
Definition: commands.c:774
char * rules
Definition: commands.c:82
char GetChar_String(const unsigned char *data)
Definition: newsocket.c:130
void close_container(item *op)
Definition: inventory.c:574
#define CS_STAT_DEX
Definition: newclient.h:94
guint16 smooth[MAXLAYERS]
Definition: mapdata.h:53
ClientSocket csocket
Definition: client.c:69
#define INFO_MAP_NAME
Definition: newclient.h:674
char * description
Definition: client.h:605
Face_Information face_info
Definition: image.c:169
static void get_starting_map_info(unsigned char *data, int len)
Definition: commands.c:172
#define MSG_TYPE_CLIENT
Definition: newclient.h:395
guint16 time
Definition: client.h:302
void MapExtendedCmd(unsigned char *data, int len)
Definition: commands.c:2234
Stats stats
Definition: client.h:349
#define NUM_NEW_CHAR_STATS
Definition: client.h:569
static int spellmon_level
Definition: commands.c:85
#define ACL_FACE
Definition: newclient.h:200
int mapupdatesent
Definition: commands.c:55
guint16 pmapx
Definition: client.h:361
#define CS_STAT_MAXSP
Definition: newclient.h:90
#define CS_STAT_WIS
Definition: newclient.h:93
#define INFO_MAP_DESCRIPTION
Definition: newclient.h:675
char ** value_desc
Definition: client.h:599
#define NDI_BLACK
Definition: newclient.h:221
guint8 usage
Definition: client.h:322
gint8 Con
Definition: client.h:254
void DeleteInventory(unsigned char *data, int len)
Definition: commands.c:1823
int type
Definition: client.h:48
#define CS_STAT_FLAGS
Definition: newclient.h:111
#define ACL_MAP
Definition: newclient.h:202
gint32 tag
Definition: item.h:59
guint8 * magicmap
Definition: client.h:363
guint32 nrof
Definition: item.h:60
char * skill_names[MAX_SKILL]
Definition: client.c:50
void mapdata_newmap(void)
Definition: mapdata.c:981
void FailureCmd(char *buf, int len)
Definition: commands.c:2391
#define MSG_TYPE_CLIENT_SERVER
Definition: newclient.h:660
void Item2Cmd(unsigned char *data, int len)
Definition: commands.c:1702
int stat_points
Definition: commands.c:93
#define CS_STAT_WEIGHT_LIM
Definition: newclient.h:112
guint64 * exp_table
Definition: client.c:64
static void common_item_command(guint8 *data, int len)
Definition: commands.c:1651
#define EMI_HASMOREBITS
Definition: newclient.h:358
void addsmooth(guint16 face, guint16 smooth_face)
Definition: image.c:403
guint32 path
Definition: client.h:315
#define CS_STAT_EXP64
Definition: newclient.h:113
void map_scrollCmd(char *data, int len)
Definition: commands.c:2166
static int rc_compar(const Race_Class_Info *a, const Race_Class_Info *b)
Definition: commands.c:405
guint16 type
Definition: item.h:81
void mapdata_set_anim_layer(int x, int y, guint16 anim, guint8 anim_speed, int layer)
Definition: mapdata.c:846
void draw_stats(int redraw)
Definition: stats.c:554
#define CS_STAT_WC
Definition: newclient.h:99
void AccountPlayersCmd(char *buf, int len)
Definition: commands.c:2433
void LOG(LogLevel level, const char *origin, const char *format,...)
Definition: misc.c:109
void client_disconnect()
Definition: client.c:180
#define NDI_RED
Definition: newclient.h:224
char * public_name
Definition: client.h:613
guint32 resist_change
Definition: client.h:288
guint32 repelled
Definition: client.h:282
int ExtSmooth(unsigned char *data, int len, int x, int y, int layer)
Definition: commands.c:2196
void Map2Cmd(unsigned char *data, int len)
Definition: commands.c:2053
guint16 grace
Definition: client.h:304
void UpdspellCmd(unsigned char *data, int len)
Definition: commands.c:1935
void update_login_info(int type)
Definition: account.c:1240
gint8 ac
Definition: client.h:260
void SinkCmd(unsigned char *data, int len)
Definition: commands.c:2349
#define INFO_NEWS
Definition: client.h:633
void x_set_echo(void)
Definition: keys.c:1686
guint8 cs_value
Definition: client.h:579
#define CS_QUERY_YESNO
Definition: newclient.h:66
int num_classes
Definition: commands.c:90
TextManager * firstTextManager
Definition: commands.c:1217
static gboolean redraw(gpointer data)
Definition: main.c:128
void display_map_doneupdate(int redraw, int notice)
Definition: map.c:488
void NewmapCmd(unsigned char *data, int len)
Definition: commands.c:2027
void update_character_choose(const char *name, const char *class, const char *race, const char *face, const char *party, const char *map, int level, int faceno)
Definition: account.c:571
ExtTextManager callback
Definition: client.h:49
void new_char_window_update_info()
Definition: create_char.c:633
gint8 Str
Definition: client.h:252
guint8 speed
Definition: client.h:104
void SmoothCmd(unsigned char *data, int len)
Definition: commands.c:1180
int num_rc_choice
Definition: client.h:607
void get_image_info(guint8 *data, int len)
Definition: image.c:706
#define ASSERT_LEN(function, curpos, buflen)
Definition: commands.c:76
void draw_message_window(int redraw)
Definition: stats.c:459
#define CS_STAT_RESIST_END
Definition: newclient.h:142
#define CS_STAT_LEVEL
Definition: newclient.h:98
guint8 rc_offset
Definition: client.h:580
#define UPD_SP_DAMAGE
Definition: newclient.h:301
void use_skill(int skill_id)
Definition: commands.c:1316
gint8 Wis
Definition: client.h:255
#define CS_STAT_WEAP_SP
Definition: newclient.h:105
guint16 mmapx
Definition: client.h:360
void item_actions(item *op)
Definition: commands.c:1629
gint8 level
Definition: client.h:261
void UpdateItemCmd(unsigned char *data, int len)
Definition: commands.c:1713
void mapdata_clear_old(int x, int y)
Definition: mapdata.c:787
Client_Player cpl
Definition: client.c:68
item * container
Definition: client.h:339
static const char *const short_stat_name[NUM_STATS]
Definition: commands.c:107
Race_Class_Info * races
Definition: commands.c:98
char * choice_name
Definition: client.h:595
guint16 was_open
Definition: item.h:75
static void get_new_char_info(unsigned char *data, int len)
Definition: commands.c:247
#define CONFIG_MAPHEIGHT
Definition: client.h:204
void(* ExtTextManager)(int flag, int type, int subtype, char *message)
Definition: client.h:45
guint8 need_resmooth
Definition: mapdata.h:57
static void get_skill_info(char *data, int len)
Definition: commands.c:732
void StatsCmd(unsigned char *data, int len)
Definition: commands.c:1341
#define CS_QUERY_SINGLECHAR
Definition: newclient.h:67
guint32 flagsval
Definition: item.h:80
gint8 Pow
Definition: client.h:258
char message[10000]
Definition: client.h:297
void update_item(int tag, int loc, char *name, int weight, int face, int flags, int anim, int animspeed, guint32 nrof, int type)
Definition: item.c:645
#define MAX_BUF
Definition: client.h:40
guint8 skill_number
Definition: client.h:309
void get_image_sums(char *data, int len)
Definition: image.c:802
#define INFO_MOTD
Definition: client.h:634
void AddspellCmd(unsigned char *data, int len)
Definition: commands.c:1851
#define CONFIG_CACHE
Definition: client.h:189
gint16 food
Definition: client.h:269
#define UPD_FLAGS
Definition: newclient.h:290
void free_all_starting_map_info()
Definition: commands.c:134
#define CS_STAT_CHA
Definition: newclient.h:96
gint8 Dex
Definition: client.h:253
guint32 tag
Definition: client.h:299
guint16 animation_id
Definition: item.h:63
void new_player(long tag, char *name, long weight, long face)
Definition: player.c:41
void account_creation_failure(char *message)
Definition: account.c:724
#define UPD_SP_MANA
Definition: newclient.h:299
gint64 GetInt64_String(const unsigned char *data)
Definition: newsocket.c:154
void client_tick(guint32 tick)
Definition: main.c:156
#define UPD_WEIGHT
Definition: newclient.h:291
guint16 pmapy
Definition: client.h:361
void send_reply(const char *text)
Definition: commands.c:1585
#define CS_STAT_SPELL_REPEL
Definition: newclient.h:115
#define CS_STAT_STR
Definition: newclient.h:91
static void get_race_info(unsigned char *data, int len)
Definition: commands.c:648
struct RC_Choice * rc_choice
Definition: client.h:608
guint8 anim_speed
Definition: item.h:64
#define CS_STAT_FOOD
Definition: newclient.h:104
char * arch_name
Definition: client.h:603
gint16 resists[30]
Definition: client.h:287
#define CS_STAT_EXP
Definition: newclient.h:97
#define FACE_IS_ANIM
Definition: newclient.h:321
bool mapdata_contains(int x, int y)
Definition: mapdata.c:126
int last_used_skills[MAX_SKILL+1]
Definition: client.c:55
void GoodbyeCmd(char *data, int len)
Definition: commands.c:1115
struct Spell_struct * next
Definition: client.h:295
int starting_map_number
Definition: commands.c:96
guint16 flags
Definition: client.h:286
#define UPD_ANIMSPEED
Definition: newclient.h:295
gint64 exp
Definition: client.h:268
gint32 face
Definition: client.h:319
static void get_class_info(unsigned char *data, int len)
Definition: commands.c:679
gint16 skill_level[MAX_SKILL]
Definition: client.h:289
void starting_map_update_info()
Definition: create_char.c:753
Warning that something definitely didn't work.
Definition: client.h:444
guint32 weight_limit
Definition: client.h:291
void script_lua_stats(void)
void AddMeSuccess(char *data, int len)
Definition: commands.c:1099
void client_pickup(guint32 pickup)
Definition: pickup.c:630
guint16 open
Definition: item.h:74
Spell * spelldata
Definition: client.h:350
gint16 dam
Definition: client.h:272
guint32 spells_updated
Definition: client.h:353
#define MAXLAYERS
Definition: mapdata.h:6
#define INFO_RULES
Definition: client.h:635
#define EMI_NOREDRAW
Definition: newclient.h:348
#define MAP2_TYPE_DARKNESS
Definition: newclient.h:43
void AnimCmd(unsigned char *data, int len)
Definition: commands.c:1135
char name[256]
Definition: client.h:296
void mapdata_scroll(int dx, int dy)
Definition: mapdata.c:908
guint16 flags
Definition: client.h:99
static void get_exp_info(const unsigned char *data, int len)
Definition: commands.c:705
#define UPD_NROF
Definition: newclient.h:296
#define CS_STAT_SP
Definition: newclient.h:89
void DrawExtInfoCmd(char *data, int len)
Definition: commands.c:1264
#define NUM_LAYERS
Definition: commands.c:2046
gint8 stat_adj[NUM_NEW_CHAR_STATS]
Definition: client.h:606
static ExtTextManager getTextManager(int type)
Definition: commands.c:1246
void start_login(int method)
Definition: account.c:1329
#define UPD_FACE
Definition: newclient.h:292
gint8 Int
Definition: client.h:257
struct TextManager * next
Definition: client.h:50
void hide_all_login_windows(void)
Definition: account.c:102
void PlayerCmd(unsigned char *data, int len)
Definition: commands.c:1602
gint16 sp
Definition: client.h:264
char * arch_name
Definition: client.h:612
void draw_ext_info(int orig_color, int type, int subtype, const char *message)
Definition: info.c:932
void remove_item_inventory(item *op)
Definition: item.c:393
#define MAP2_COORD_OFFSET
Definition: newclient.h:32
void DeleteSpell(unsigned char *data, int len)
Definition: commands.c:1973
static void process_race_class_info(unsigned char *data, int len, Race_Class_Info *rci)
Definition: commands.c:469
guint16 * faces
Definition: client.h:107
#define UPD_LOCATION
Definition: newclient.h:289
#define ACL_PARTY
Definition: newclient.h:201
#define CS_STAT_ARMOUR
Definition: newclient.h:102
guint8 speed_left
Definition: client.h:105
#define UPD_NAME
Definition: newclient.h:293
#define CS_STAT_DAM
Definition: newclient.h:101
#define CS_NUM_SKILLS
Definition: newclient.h:175
char * public_name
Definition: client.h:604
#define CS_STAT_TITLE
Definition: newclient.h:107
int used_classes
Definition: commands.c:91
Input_State input_state
Definition: client.h:341
char range[MAX_BUF]
Definition: client.h:352
Race_Class_Info * classes
Definition: commands.c:98
#define ACL_RACE
Definition: newclient.h:198
#define CS_STAT_SPELL_DENY
Definition: newclient.h:116
#define CS_STAT_HP
Definition: newclient.h:87
void draw_magic_map(void)
Definition: magicmap.c:24
gint16 maxhp
Definition: client.h:263
char title[MAX_BUF]
Definition: client.h:351
void resize_map_window(int x, int y)
Definition: map.c:371
int cs_print_string(GSocketConnection *fd, const char *str,...)
Definition: newsocket.c:245
int used_races
Definition: commands.c:88
char * name
Definition: image.c:39
#define MSG_TYPE_CLIENT_COMMAND
Definition: newclient.h:661
void open_container(item *op)
Definition: inventory.c:582
#define CS_STAT_RESIST_START
Definition: newclient.h:141
#define MAX_VIEW
Definition: mapdata.h:11
#define CS_QUERY_HIDEINPUT
Definition: newclient.h:68
gint16 hp
Definition: client.h:262
#define CS_STAT_POW
Definition: newclient.h:108
gint16 face
Definition: item.h:62
char requirements[256]
Definition: client.h:327
guint32 no_echo
Definition: client.h:358
#define CS_STAT_RANGE
Definition: newclient.h:106
#define MAXANIM
Definition: client.h:86
#define CS_STAT_MAXHP
Definition: newclient.h:88
void draw_prompt(const char *str)
Definition: keys.c:1695
void MagicMapCmd(unsigned char *data, int len)
Definition: commands.c:2296
Useful debugging information.
Definition: client.h:441
gint8 Cha
Definition: client.h:256
#define CS_STAT_CON
Definition: newclient.h:95
#define CS_STAT_SPELL_ATTUNE
Definition: newclient.h:114
int GetInt_String(const unsigned char *data)
Definition: newsocket.c:142
#define ACL_NAME
Definition: newclient.h:196
#define CS_STAT_MAXGRACE
Definition: newclient.h:110
void mapdata_set_size(int viewx, int viewy)
Definition: mapdata.c:614
guint16 exp_table_max
Definition: client.c:63
#define MAP2_LAYER_START
Definition: newclient.h:53
void account_login_failure(char *message)
Definition: account.c:909
Minor, non-harmful issues.
Definition: client.h:442
void show_main_client(void)
Definition: main.c:410
#define CS_STAT_SKILLINFO
Definition: newclient.h:168
void remove_item(item *op)
Definition: item.c:331
void mapdata_set_darkness(int x, int y, int darkness)
Definition: mapdata.c:730
PlayerPosition pl_pos
Definition: map.c:37
guint32 attuned
Definition: client.h:279
#define CS_STAT_GRACE
Definition: newclient.h:109
guint8 phase
Definition: client.h:106
#define CONFIG_MAPWIDTH
Definition: client.h:203
static item * map
Definition: item.c:28
Starting_Map_Info * starting_map_info
Definition: commands.c:99
char * skill
Definition: client.h:313
gint16 maxgrace
Definition: client.h:267
guint32 denied
Definition: client.h:285
void mapdata_set_smooth(int x, int y, int smooth, int layer)
Definition: mapdata.c:753