Crossfire Server, Trunk
loop.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 
25 #include "global.h"
26 
27 #include <assert.h>
28 #include <errno.h>
29 #include <fcntl.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <unistd.h>
33 
34 #ifndef WIN32 /* ---win32 exclude unix headers */
35 #include <arpa/inet.h>
36 #include <sys/types.h>
37 #include <sys/time.h>
38 #include <netinet/in.h>
39 #include <netdb.h>
40 #else
41 #include <winsock2.h>
42 #endif /* end win32 */
43 
44 #include "image.h"
45 #include "newserver.h"
46 #include "sockproto.h"
47 #include "sproto.h"
48 
49 /*****************************************************************************
50  * Start of command dispatch area.
51  * The commands here are protocol commands.
52  ****************************************************************************/
53 
54 /* Either keep this near the start or end of the file so it is
55  * at least reasonablye easy to find.
56  * There are really 2 commands - those which are sent/received
57  * before player joins, and those happen after the player has joined.
58  * As such, we have function types that might be called, so
59  * we end up having 2 tables.
60  */
61 
63 typedef void (*func_uint8_int_ns)(char *, int, socket_struct *);
64 
67  const char *cmdname;
69 };
70 
72 typedef void (*func_uint8_int_pl)(char *, int, player *);
75  const char *cmdname;
77  const uint8_t flag;
78 };
79 
95 static const struct player_cmd_mapping player_commands[] = {
96  { "examine", examine_cmd, 1 },
97  { "apply", apply_cmd, 1 },
98  { "move", move_cmd, 1 },
99  { "reply", reply_cmd, 0 },
100  { "ncom", (func_uint8_int_pl)new_player_cmd, 1 },
101  { "lookat", look_at_cmd, 1 },
102  { "lock", (func_uint8_int_pl)lock_item_cmd, 1 },
103  { "mark", (func_uint8_int_pl)mark_item_cmd, 1 },
104  { "inscribe", inscribe_scroll_cmd, 0 },
105  { NULL, NULL, 0 } /* terminator */
106 };
107 
109 static const struct client_cmd_mapping client_commands[] = {
110  { "addme", add_me_cmd },
111  { "askface", send_face_cmd }, /* Added: phil */
112  { "beat", NULL },
113  { "requestinfo", request_info_cmd },
114  { "setup", set_up_cmd },
115  { "version", version_cmd },
116  { "asksmooth", ask_smooth_cmd }, /*Added: tchize (smoothing technologies)*/
117  { "accountlogin", account_login_cmd },
118  { "accountnew", account_new_cmd },
119  { "accountaddplayer", account_add_player_cmd },
120  { "accountplay", account_play_cmd },
121  { "accountpw", account_password },
122  { "createplayer", create_player_cmd },
123  { NULL, NULL } /* terminator (I, II & III)*/
124 };
125 
134 void request_info_cmd(char *buf, int len, socket_struct *ns) {
135  char *params = NULL, *cp;
136  /* No match */
137  SockList sl;
138 
139  if (len <= 0 || !buf) {
140  LOG(llevDebug, "IP '%s' sent bogus request_info_cmd information\n", ns->host);
141  return;
142  }
143 
144  /* Set up replyinfo before we modify any of the buffers - this is used
145  * if we don't find a match.
146  */
147  SockList_Init(&sl);
148  SockList_AddString(&sl, "replyinfo ");
149  SockList_AddString(&sl, buf);
150 
151  /* find the first space, make it null, and update the
152  * params pointer.
153  */
154  for (cp = buf; *cp != '\0'; cp++)
155  if (*cp == ' ') {
156  *cp = '\0';
157  params = cp+1;
158  break;
159  }
160  if (!strcmp(buf, "image_info"))
161  send_image_info(ns);
162  else if (!strcmp(buf, "image_sums"))
163  send_image_sums(ns, params);
164  else if (!strcmp(buf, "skill_info"))
165  send_skill_info(ns, params);
166  else if (!strcmp(buf, "skill_extra"))
168  else if (!strcmp(buf, "spell_paths"))
169  send_spell_paths(ns);
170  else if (!strcmp(buf, "exp_table"))
171  send_exp_table(ns);
172  else if (!strcmp(buf, "race_list"))
173  send_race_list(ns);
174  else if (!strcmp(buf, "race_info"))
175  send_race_info(ns, params);
176  else if (!strcmp(buf, "class_list"))
177  send_class_list(ns);
178  else if (!strcmp(buf, "class_info"))
179  send_class_info(ns, params);
180  else if (!strcmp(buf, "rules"))
181  send_file(ns, "rules");
182  else if (!strcmp(buf, "motd"))
183  send_file(ns, "motd");
184  else if (!strcmp(buf, "news"))
185  send_file(ns, "news");
186  else if (!strcmp(buf,"newcharinfo"))
187  send_new_char_info(ns);
188  else if (!strcmp(buf,"startingmap"))
189  send_map_info(ns);
190  else if (!strcmp(buf, "knowledge_info"))
192  else
193  Send_With_Handling(ns, &sl);
194  SockList_Term(&sl);
195 }
196 
206 static int
207 handle_cmd(socket_struct *ns, player *pl, char *cmd, char *data, int len) {
208  /* Fuzz testing indicated a way to get a null command here
209  * --> make an empty command, but have a length.
210  * So, if we get here with a null command, log it and exit the function.
211  * Daniel Hawkins 2020-01-16
212  */
213  if (cmd == NULL) {
214  LOG(llevDebug, "%s: missing command. Sending garbage?\n", ns->host);
215  return 0;
216  }
217  for (int i = 0; client_commands[i].cmdname != NULL; i++) {
218  if (strcmp(cmd, client_commands[i].cmdname) == 0) {
219  if (client_commands[i].cmdproc != NULL) {
220  client_commands[i].cmdproc(data, len, ns);
221  }
222  return 0;
223  }
224  }
225  /* Player must be in the playing state or the flag on the
226  * the command must be zero for the user to use the command -
227  * otherwise, a player cam save, be in the play_again state, and
228  * the map they were on getsswapped out, yet things that try to look
229  * at the map causes a crash. If the command is valid, but
230  * one they can't use, we still swallow it up.
231  */
232  if (pl) {
233  for (int i = 0; player_commands[i].cmdname != NULL; i++) {
234  if (strcmp(cmd, player_commands[i].cmdname) == 0) {
235  if (pl->state == ST_PLAYING || player_commands[i].flag == 0) {
236  player_commands[i].cmdproc(data, len, pl);
237  }
238  return 1;
239  }
240  }
241  }
242  LOG(llevDebug, "%s: invalid command '%s'\n", ns->host, cmd);
243  return 0;
244 }
245 
256  /* Loop through this - maybe we have several complete packets here. */
257  /* Command_count is used to limit the number of requests from
258  * clients that have not logged in - we do not want an unauthenticated
259  * connection to spew us with hundreds of requests. As such,
260  * this counter is only increased in the case of socket level commands.
261  * Note that this also has the effect of throttling down face and other
262  * socket commands from the client. As such, if we have a player attached,
263  * we will process more of these, as getting a fair number when entering
264  * a map may not be uncommon.
265  */
266  int command_count = 0;
267  while (command_count < 5 || (pl && command_count < 25)) {
268  if (pl && pl->state == ST_PLAYING && pl->ob != NULL && pl->ob->speed_left < 0) {
269  // Skip processing players with no turns left.
270  return false;
271  }
272 
273  int status = SockList_ReadPacket(ns->fd, &ns->inbuf, sizeof(ns->inbuf.buf)-1);
274  if (status != 1) {
275  if (status < 0) {
276  ns->status = Ns_Dead;
277  }
278  return false;
279  }
280 
281  /* Since we have a full packet, reset last tick time. */
282  ns->last_tick = 0;
283 
285  assert(ns->inbuf.len >= 2);
286  char *data;
287  char *cmd = strtok_r((char *)ns->inbuf.buf + 2, " ", &data);
288 
289  int got_player_cmd;
290  if (data != NULL) {
291  int rem = ns->inbuf.len - ((unsigned char *)data - ns->inbuf.buf);
292  got_player_cmd = handle_cmd(ns, pl, cmd, data, rem);
293  } else {
294  got_player_cmd = handle_cmd(ns, pl, cmd, NULL, 0);
295  }
296 
298  if (got_player_cmd) {
299  return true;
300  }
301 
302  command_count += 1;
303  /* Evil case, and not a nice workaround, but well...
304  * If we receive eg an accountplay command, the socket is copied
305  * to the player structure, and its faces_sent is set to NULL.
306  * This leads to issues when processing the next commands in the queue,
307  * especially if related to faces...
308  * So get out of here in this case, which we detect because faces_sent is NULL.
309  */
310  if (ns->faces_sent == NULL) {
311  command_count = 6;
312  }
313  }
314  return false;
315 }
316 
317 /*****************************************************************************
318  *
319  * Low level socket looping - select calls and watchdog udp packet
320  * sending.
321  *
322  ******************************************************************************/
323 
324 #ifdef WATCHDOG
325 
331 void watchdog(void) {
332  static int fd = -1;
333  static struct sockaddr_in insock;
334 
335  if (fd == -1) {
336  struct protoent *protoent;
337 
338  if ((protoent = getprotobyname("udp")) == NULL
339  || (fd = socket(PF_INET, SOCK_DGRAM, protoent->p_proto)) == -1) {
340  return;
341  }
342  insock.sin_family = AF_INET;
343  insock.sin_port = htons((unsigned short)13325);
344  insock.sin_addr.s_addr = inet_addr("127.0.0.1");
345  }
346  char buf[MAX_BUF];
347  snprintf(buf, sizeof(buf), "%d\n", pticks);
348  sendto(fd, buf, strlen(buf), 0, (struct sockaddr *)&insock, sizeof(insock));
349 }
350 #endif
351 
355 static void block_until_new_connection(void) {
356  struct timeval Timeout;
357  fd_set readfs;
358  int cycles;
359  int i;
360 
361  LOG(llevInfo, "Waiting for connections...\n");
362 
363  cycles = 1;
364  do {
365  /* Every minutes is a bit often for updates - especially if nothing is going
366  * on. This slows it down to every 6 minutes.
367  */
368  cycles++;
369  if (cycles%2 == 0)
370  tick_the_clock();
371 
372  FD_ZERO(&readfs);
373  for (i = 0; i < socket_info.allocated_sockets && init_sockets[i].listen; i++)
374  if (init_sockets[i].status == Ns_Add)
375  FD_SET((uint32_t)init_sockets[i].fd, &readfs);
376 
377  /* If fastclock is set, we need to seriously slow down the updates
378  * to the metaserver as well as watchdog. Do same for flush_old_maps() -
379  * that is time sensitive, so there is no good reason to call it 2000 times
380  * a second.
381  */
382  if (settings.fastclock > 0) {
383  if (cycles%120000 == 0) {
384 #ifdef WATCHDOG
385  watchdog();
386 #endif
387  flush_old_maps();
388  }
389  if (cycles == 720000) {
391  cycles = 1;
392  }
393  Timeout.tv_sec = 0;
394  Timeout.tv_usec = 50;
395  } else {
396  Timeout.tv_sec = 60;
397  Timeout.tv_usec = 0;
398  if (cycles == 7) {
400  cycles = 1;
401  }
402 #ifdef WATCHDOG
403  watchdog();
404 #endif
405  flush_old_maps();
406  }
407  } while (select(socket_info.max_filedescriptor, &readfs, NULL, NULL, &Timeout) == 0);
408 
409  reset_sleep(); /* Or the game would go too fast */
410 }
411 
420 static int is_fd_valid(int fd) {
421 #ifndef WIN32
422  return fcntl(fd, F_GETFL) != -1 || errno != EBADF;
423 #else
424  return 1;
425 #endif
426 }
427 
432 static void new_connection(int listen_fd) {
433  int newsocknum = -1, j;
434 #ifdef HAVE_GETNAMEINFO
435  struct sockaddr_storage addr;
436 #else
437  struct sockaddr_in addr;
438 #endif
439  socklen_t addrlen = sizeof(addr);
440 
441 #ifdef ESRV_DEBUG
442  LOG(llevDebug, "do_server: New Connection\n");
443 #endif
444 
445  for (j = 0; j < socket_info.allocated_sockets; j++)
446  if (init_sockets[j].status == Ns_Avail) {
447  newsocknum = j;
448  break;
449  }
450 
451  if (newsocknum == -1) {
452  /* If this is the case, all sockets currently in used */
453  init_sockets = static_cast<socket_struct *>(realloc(init_sockets, sizeof(socket_struct)*(socket_info.allocated_sockets+1)));
454  if (!init_sockets)
456  newsocknum = socket_info.allocated_sockets;
458  memset(&init_sockets[newsocknum], 0, sizeof(*init_sockets));
459  init_sockets[newsocknum].listen = NULL;
461  init_sockets[newsocknum].faces_sent = static_cast<uint8_t *>(calloc(get_faces_count(), sizeof(*init_sockets[newsocknum].faces_sent)));
462  if (!init_sockets[newsocknum].faces_sent)
464  init_sockets[newsocknum].status = Ns_Avail;
465  }
466 
467  if (newsocknum < 0) {
468  LOG(llevError, "FATAL: didn't allocate a newsocket?? alloc = %d, newsocknum = %d", socket_info.allocated_sockets, newsocknum);
470  }
471 
472  init_sockets[newsocknum].fd = accept(listen_fd, (struct sockaddr *)&addr, &addrlen);
473  if (init_sockets[newsocknum].fd == -1) {
474  LOG(llevError, "accept failed: %s\n", strerror(errno));
475  } else {
476  char buf[MAX_BUF];
477 #ifndef HAVE_GETNAMEINFO
478  long ip;
479 #endif
480  socket_struct *ns;
481 
482  ns = &init_sockets[newsocknum];
483 
484 #ifdef HAVE_GETNAMEINFO
485  getnameinfo((struct sockaddr *) &addr, addrlen, buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
486 #else
487  ip = ntohl(addr.sin_addr.s_addr);
488  snprintf(buf, sizeof(buf), "%ld.%ld.%ld.%ld", (ip>>24)&255, (ip>>16)&255, (ip>>8)&255, ip&255);
489 #endif
490 
491  if (checkbanned(NULL, buf)) {
492  LOG(llevInfo, "Banned host tried to connect: [%s]\n", buf);
493  close(init_sockets[newsocknum].fd);
494  init_sockets[newsocknum].fd = -1;
495  } else {
496  init_connection(ns, buf);
497  }
498  }
499 }
500 
506 bool connection_alive(const socket_struct *socket) {
507  // If the client doesn't send heartbeats, assume it's connected.
508  if (!socket->heartbeat) {
509  return true;
510  }
511 
512  // If a client message was received recently, it's connected.
513  if (socket->last_tick < tick_length(BEAT_INTERVAL + 1)) {
514  return true;
515  }
516 
517  return false;
518 }
519 
525  for (uint8_t buf = 0; buf < pl->delayed_buffers_used; buf++) {
526  Send_With_Handling(pl->socket, pl->delayed_buffers[buf]);
527  }
528  pl->delayed_buffers_used = 0;
529 }
530 
534 static void send_updates(player *pl) {
535  /* Update the players stats once per tick. More efficient than
536  * sending them whenever they change, and probably just as useful
537  */
539  if (pl->last_weight != -1 && pl->last_weight != WEIGHT(pl->ob)) {
540  esrv_update_item(UPD_WEIGHT, pl->ob, pl->ob);
541  if (pl->last_weight != WEIGHT(pl->ob))
542  LOG(llevError, "esrv_update_item(UPD_WEIGHT) did not set player weight: is %lu, should be %lu\n", (unsigned long)pl->last_weight, (unsigned long)WEIGHT(pl->ob));
543  }
544  /* draw_client_map does sanity checking that map is
545  * valid, so don't do it here.
546  */
547  draw_client_map(pl->ob);
548  if (pl->socket->update_look)
549  esrv_draw_look(pl->ob);
550  if (pl->socket->update_inventory) {
551  if (pl->ob->container != NULL)
552  esrv_send_inventory(pl->ob, pl->ob->container);
553  pl->socket->update_inventory = 0;
554  }
555 }
556 
564 void do_server(void) {
565  fd_set tmp_read, tmp_exceptions;
566  int active = 0;
567  FD_ZERO(&tmp_read);
568  FD_ZERO(&tmp_exceptions);
569 
570  for (int i = 0; i < socket_info.allocated_sockets; i++) {
571  if (init_sockets[i].status == Ns_Add && !is_fd_valid(init_sockets[i].fd)) {
572  LOG(llevError, "do_server: invalid waiting fd %d\n", i);
574  FREE_AND_CLEAR(init_sockets[i].faces_sent);
575  }
576  if (init_sockets[i].status == Ns_Dead) {
577  LOG(llevInfo, "Disconnected from %s\n", init_sockets[i].host);
578  if (init_sockets[i].listen) {
579  /* try to reopen the listening socket */
581  } else {
584  }
585  } else if (init_sockets[i].status != Ns_Avail) {
586  FD_SET((uint32_t)init_sockets[i].fd, &tmp_read);
587  FD_SET((uint32_t)init_sockets[i].fd, &tmp_exceptions);
588  active++;
589  }
590  }
591 
592  /* Go through the players. Let the loop set the next pl value,
593  * since we may remove some
594  */
595  player *pl, *next;
596  for (pl = first_player; pl != NULL; ) {
597  if (pl->socket->status != Ns_Dead && !is_fd_valid(pl->socket->fd)) {
598  LOG(llevError, "do_server: invalid file descriptor for player %s [%s]: %d\n", (pl->ob && pl->ob->name) ? pl->ob->name : "(unnamed player?)", (pl->socket->host) ? pl->socket->host : "(unknown ip?)", pl->socket->fd);
599  pl->socket->status = Ns_Dead;
600  }
601 
602  if (pl->socket->status == Ns_Dead) {
603  player *npl = pl->next;
604 
605  save_player(pl->ob, 0);
606  leave(pl, 1);
608  pl = npl;
609  } else {
610  FD_SET((uint32_t)pl->socket->fd, &tmp_read);
611  FD_SET((uint32_t)pl->socket->fd, &tmp_exceptions);
612  pl = pl->next;
613  }
614  }
615 
616  if (active == 1 && first_player == NULL)
618 
619  long sleep_time = get_sleep_remaining();
620  if (sleep_time < 0) {
621  LOG(llevInfo, "skipping time (over by %ld ms)\n", -sleep_time/1000);
622  jump_time();
623  }
624 
625  while (sleep_time > 0) {
626  socket_info.timeout.tv_sec = 0;
627  socket_info.timeout.tv_usec = sleep_time;
628  int pollret = select(socket_info.max_filedescriptor, &tmp_read, NULL,
629  &tmp_exceptions, &socket_info.timeout);
630  if (pollret == -1) {
631  if (errno != EINTR) {
632  LOG(llevError, "select failed: %s\n", strerror(errno));
633  }
634  return;
635  } else if (!pollret) {
636  return;
637  }
638 
639  /* Check for any exceptions/input on the sockets */
640  for (int i = 0; i < socket_info.allocated_sockets; i++) {
641  /* listen sockets can stay in status Ns_Dead */
642  if (init_sockets[i].status != Ns_Add) {
643  continue;
644  }
645  if (FD_ISSET(init_sockets[i].fd, &tmp_exceptions)) {
648  continue;
649  }
650  if (FD_ISSET(init_sockets[i].fd, &tmp_read)) {
651  if (init_sockets[i].listen)
653  else
654  handle_client(&init_sockets[i], NULL);
655  }
656  }
657 
658  /* This does roughly the same thing, but for the players now */
659  for (pl = first_player; pl != NULL; pl = next) {
660  next = pl->next;
661  if (pl->socket->status == Ns_Dead)
662  continue;
663 
664  if (FD_ISSET(pl->socket->fd, &tmp_exceptions)) {
665  save_player(pl->ob, 0);
666  leave(pl, 1);
668  } else {
669  bool keep_processing = handle_client(pl->socket, pl);
670  if (!keep_processing) {
671  FD_CLR(pl->socket->fd, &tmp_read);
672  }
673 
674  /* There seems to be rare cases where next points to a removed/freed player.
675  * My belief is that this player does something (shout, move, whatever)
676  * that causes data to be sent to the next player on the list, but
677  * that player is defunct, so the socket codes removes that player.
678  * End result is that next now points at the removed player, and
679  * that has garbage data so we crash. So update the next pointer
680  * while pl is still valid. MSW 2007-04-21
681  */
682  next = pl->next;
683 
684 
685  /* If the player has left the game, then the socket status
686  * will be set to this be the leave function. We don't
687  * need to call leave again, as it has already been called
688  * once.
689  */
690  if (pl->socket->status == Ns_Dead) {
691  save_player(pl->ob, 0);
692  leave(pl, 1);
694  } else {
696  send_updates(pl);
697  }
698  }
699  }
700  sleep_time = get_sleep_remaining();
701  }
702 }
703 
708  player *pl, *next;
709  for (pl = first_player; pl != NULL; pl = next) {
710  next = pl->next;
711  send_updates(pl);
712  /* Increment time since last contact only if logged in. */
713  if (pl->state == ST_PLAYING) {
714  pl->socket->last_tick++;
715 
716  if (!connection_alive(pl->socket)) {
717  // TODO: Handle a lost client connection.
718  LOG(llevDebug, "Lost client connection!\n");
719  }
720 
721  if (pl->socket->tick)
722  send_tick(pl);
723  }
724  }
725 }
give.next
def next
Definition: give.py:44
request_info_cmd
void request_info_cmd(char *buf, int len, socket_struct *ns)
Definition: loop.cpp:134
send_image_info
void send_image_info(socket_struct *ns)
Definition: image.cpp:113
global.h
player_cmd_mapping::cmdname
const char * cmdname
Definition: loop.cpp:75
send_image_sums
void send_image_sums(socket_struct *ns, char *params)
Definition: image.cpp:138
first_player
player * first_player
Definition: init.cpp:106
reply_cmd
void reply_cmd(char *buf, int len, player *pl)
Definition: request.cpp:571
settings
struct Settings settings
Definition: init.cpp:139
tick_the_clock
void tick_the_clock(void)
Definition: weather.cpp:94
socket_struct::heartbeat
bool heartbeat
Definition: newserver.h:112
llevError
@ llevError
Definition: logger.h:11
init_connection
void init_connection(socket_struct *ns, const char *from_ip)
Definition: init.cpp:85
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.cpp:51
init_sockets
socket_struct * init_sockets
Definition: init.cpp:58
player
Definition: player.h:105
sockproto.h
client_commands
static const struct client_cmd_mapping client_commands[]
Definition: loop.cpp:109
socket_struct
Definition: newserver.h:89
flush_old_maps
void flush_old_maps(void)
Definition: swap.cpp:289
esrv_send_inventory
void esrv_send_inventory(object *pl, object *op)
Definition: item.cpp:316
UPD_WEIGHT
#define UPD_WEIGHT
Definition: newclient.h:305
SockList_AddString
void SockList_AddString(SockList *sl, const char *data)
Definition: lowlevel.cpp:154
SockList::len
size_t len
Definition: newclient.h:675
socket_info
Socket_Info socket_info
Definition: init.cpp:49
mark_item_cmd
void mark_item_cmd(uint8_t *data, int len, player *pl)
Definition: item.cpp:764
Socket_Info::max_filedescriptor
int max_filedescriptor
Definition: newserver.h:143
send_updates
static void send_updates(player *pl)
Definition: loop.cpp:534
send_new_char_info
void send_new_char_info(socket_struct *ns)
Definition: requestinfo.cpp:520
send_map_info
void send_map_info(socket_struct *ns)
Definition: requestinfo.cpp:441
send_exp_table
void send_exp_table(socket_struct *ns)
Definition: requestinfo.cpp:158
socket_struct::listen
struct listen_info * listen
Definition: newserver.h:92
is_fd_valid
static int is_fd_valid(int fd)
Definition: loop.cpp:420
SEE_LAST_ERROR
@ SEE_LAST_ERROR
Definition: define.h:52
socket_struct::inbuf
SockList inbuf
Definition: newserver.h:99
pticks
uint32_t pticks
Definition: time.cpp:47
buf
StringBuffer * buf
Definition: readable.cpp:1552
SockList
Definition: newclient.h:670
Ns_Dead
@ Ns_Dead
Definition: newserver.h:67
account_password
void account_password(char *buf, int len, socket_struct *ns)
Definition: request.cpp:3026
send_skill_info
void send_skill_info(socket_struct *ns, char *params)
Definition: requestinfo.cpp:71
account_login_cmd
void account_login_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:2159
look_at_cmd
void look_at_cmd(char *buf, int len, player *pl)
Definition: item.cpp:860
knowledge_send_info
void knowledge_send_info(socket_struct *ns)
Definition: knowledge.cpp:1371
Ns_Avail
@ Ns_Avail
Definition: newserver.h:65
final_free_player
void final_free_player(player *pl)
Definition: init.cpp:455
socklen_t
#define socklen_t
Definition: win32.h:17
player_cmd_mapping::flag
const uint8_t flag
Definition: loop.cpp:77
update_players
void update_players()
Definition: loop.cpp:707
func_uint8_int_ns
void(* func_uint8_int_ns)(char *, int, socket_struct *)
Definition: loop.cpp:63
esrv_update_stats
void esrv_update_stats(player *pl)
Definition: request.cpp:849
SockList::buf
unsigned char buf[MAXSOCKBUF]
Definition: newclient.h:676
jump_time
void jump_time()
Definition: time.cpp:194
socket_struct::host
char * host
Definition: newserver.h:100
client_cmd_mapping
Definition: loop.cpp:66
send_tick
void send_tick(player *pl)
Definition: request.cpp:1968
navar-midane_time.data
data
Definition: navar-midane_time.py:11
leave
void leave(player *pl, int draw_exit)
Definition: server.cpp:1305
ask_smooth_cmd
void ask_smooth_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:479
account_add_player_cmd
void account_add_player_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:2372
sproto.h
create_player_cmd
void create_player_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:2606
new_player_cmd
void new_player_cmd(uint8_t *buf, int len, player *pl)
Definition: request.cpp:503
get_sleep_remaining
long get_sleep_remaining()
Definition: time.cpp:186
account_play_cmd
void account_play_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:2501
SockList_Init
void SockList_Init(SockList *sl)
Definition: lowlevel.cpp:52
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
do_server
void do_server(void)
Definition: loop.cpp:564
send_delayed_buffers
static void send_delayed_buffers(player *pl)
Definition: loop.cpp:524
image.h
client_cmd_mapping::cmdname
const char * cmdname
Definition: loop.cpp:67
move_cmd
void move_cmd(char *buf, int len, player *pl)
Definition: request.cpp:690
send_class_info
void send_class_info(socket_struct *ns, char *params)
Definition: requestinfo.cpp:413
log_login.ip
ip
Definition: log_login.py:6
MAX_BUF
#define MAX_BUF
Definition: define.h:35
Ns_Add
@ Ns_Add
Definition: newserver.h:66
checkbanned
int checkbanned(const char *login, const char *host)
Definition: ban.cpp:32
version_cmd
void version_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:633
tick_length
unsigned int tick_length(float seconds)
Definition: time.cpp:378
new_connection
static void new_connection(int listen_fd)
Definition: loop.cpp:432
SockList_Term
void SockList_Term(SockList *sl)
Definition: lowlevel.cpp:62
send_race_list
void send_race_list(socket_struct *ns)
Definition: requestinfo.cpp:326
handle_client
bool handle_client(socket_struct *ns, player *pl)
Definition: loop.cpp:255
Socket_Info::timeout
struct timeval timeout
Definition: newserver.h:142
ST_PLAYING
#define ST_PLAYING
Definition: define.h:541
free_newsocket
void free_newsocket(socket_struct *ns)
Definition: init.cpp:420
block_until_new_connection
static void block_until_new_connection(void)
Definition: loop.cpp:355
llevInfo
@ llevInfo
Definition: logger.h:12
inscribe_scroll_cmd
void inscribe_scroll_cmd(char *buf, int len, player *pl)
Definition: item.cpp:955
fatal
void fatal(enum fatal_error err)
Definition: utils.cpp:570
send_class_list
void send_class_list(socket_struct *ns)
Definition: requestinfo.cpp:392
FREE_AND_CLEAR
#define FREE_AND_CLEAR(xyz)
Definition: global.h:193
socket_struct::last_tick
uint32_t last_tick
Definition: newserver.h:130
metaserver_update
void metaserver_update(void)
Definition: metaserver.cpp:80
newserver.h
BEAT_INTERVAL
#define BEAT_INTERVAL
Definition: config.h:636
socket_struct::status
enum Sock_Status status
Definition: newserver.h:90
esrv_update_item
void esrv_update_item(int flags, object *pl, object *op)
Definition: main.cpp:359
esrv_draw_look
void esrv_draw_look(object *pl)
Definition: item.cpp:193
send_file
void send_file(socket_struct *ns, const char *file)
Definition: requestinfo.cpp:479
roll-o-matic.params
params
Definition: roll-o-matic.py:193
examine_cmd
void examine_cmd(char *buf, int len, player *pl)
Definition: item.cpp:643
reset_sleep
void reset_sleep(void)
Definition: time.cpp:132
socket_struct::faces_sent_len
size_t faces_sent_len
Definition: newserver.h:95
WEIGHT
#define WEIGHT(op)
Definition: define.h:651
handle_cmd
static int handle_cmd(socket_struct *ns, player *pl, char *cmd, char *data, int len)
Definition: loop.cpp:207
Socket_Info::allocated_sockets
int allocated_sockets
Definition: newserver.h:144
SockList_ResetRead
void SockList_ResetRead(SockList *sl)
Definition: lowlevel.cpp:80
send_skill_extra
void send_skill_extra(socket_struct *ns, char *params)
Definition: requestinfo.cpp:102
send_spell_paths
void send_spell_paths(socket_struct *ns)
Definition: requestinfo.cpp:132
account_new_cmd
void account_new_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:2258
watchdog
void watchdog(void)
socket_struct::faces_sent
uint8_t * faces_sent
Definition: newserver.h:96
make_face_from_files.int
int
Definition: make_face_from_files.py:32
lock_item_cmd
void lock_item_cmd(uint8_t *data, int len, player *pl)
Definition: item.cpp:705
save_player
int save_player(object *op, int flag)
Definition: login.cpp:230
socket_struct::fd
int fd
Definition: newserver.h:91
player_cmd_mapping
Definition: loop.cpp:74
player_commands
static const struct player_cmd_mapping player_commands[]
Definition: loop.cpp:95
get_faces_count
size_t get_faces_count()
Definition: assets.cpp:293
SockList_ReadPacket
int SockList_ReadPacket(int fd, SockList *sl, int len)
Definition: lowlevel.cpp:272
set_up_cmd
void set_up_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:119
altar_valkyrie.accept
def accept(description)
Definition: altar_valkyrie.py:22
send_race_info
void send_race_info(socket_struct *ns, char *params)
Definition: requestinfo.cpp:347
client_cmd_mapping::cmdproc
const func_uint8_int_ns cmdproc
Definition: loop.cpp:68
OUT_OF_MEMORY
@ OUT_OF_MEMORY
Definition: define.h:48
player_cmd_mapping::cmdproc
const func_uint8_int_pl cmdproc
Definition: loop.cpp:76
Settings::fastclock
uint8_t fastclock
Definition: global.h:297
altar_valkyrie.pl
pl
Definition: altar_valkyrie.py:28
add_me_cmd
void add_me_cmd(char *buf, int len, socket_struct *ns)
Definition: request.cpp:391
draw_client_map
void draw_client_map(object *pl)
Definition: request.cpp:1607
Send_With_Handling
void Send_With_Handling(socket_struct *ns, SockList *sl)
Definition: lowlevel.cpp:444
apply_cmd
void apply_cmd(char *buf, int len, player *pl)
Definition: item.cpp:665
takeitem.status
status
Definition: takeitem.py:38
func_uint8_int_pl
void(* func_uint8_int_pl)(char *, int, player *)
Definition: loop.cpp:72
SockList_NullTerminate
void SockList_NullTerminate(SockList *sl)
Definition: lowlevel.cpp:234
send_face_cmd
void send_face_cmd(char *buff, int len, socket_struct *ns)
Definition: image.cpp:45
llevDebug
@ llevDebug
Definition: logger.h:13
init_listening_socket
void init_listening_socket(socket_struct *ns)
Definition: init.cpp:181
connection_alive
bool connection_alive(const socket_struct *socket)
Definition: loop.cpp:506