Crossfire Server, Trunk
loop.c
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, "spell_paths"))
167  send_spell_paths(ns);
168  else if (!strcmp(buf, "exp_table"))
169  send_exp_table(ns);
170  else if (!strcmp(buf, "race_list"))
171  send_race_list(ns);
172  else if (!strcmp(buf, "race_info"))
173  send_race_info(ns, params);
174  else if (!strcmp(buf, "class_list"))
175  send_class_list(ns);
176  else if (!strcmp(buf, "class_info"))
177  send_class_info(ns, params);
178  else if (!strcmp(buf, "rules"))
179  send_file(ns, "rules");
180  else if (!strcmp(buf, "motd"))
181  send_file(ns, "motd");
182  else if (!strcmp(buf, "news"))
183  send_file(ns, "news");
184  else if (!strcmp(buf,"newcharinfo"))
185  send_new_char_info(ns);
186  else if (!strcmp(buf,"startingmap"))
187  send_map_info(ns);
188  else if (!strcmp(buf, "knowledge_info"))
190  else
191  Send_With_Handling(ns, &sl);
192  SockList_Term(&sl);
193 }
194 
204 static int
205 handle_cmd(socket_struct *ns, player *pl, char *cmd, char *data, int len) {
206  /* Fuzz testing indicated a way to get a null command here
207  * --> make an empty command, but have a length.
208  * So, if we get here with a null command, log it and exit the function.
209  * Daniel Hawkins 2020-01-16
210  */
211  if (cmd == NULL) {
212  LOG(llevDebug, "%s: missing command. Sending garbage?\n", ns->host);
213  return 0;
214  }
215  for (int i = 0; client_commands[i].cmdname != NULL; i++) {
216  if (strcmp(cmd, client_commands[i].cmdname) == 0) {
217  if (client_commands[i].cmdproc != NULL) {
218  client_commands[i].cmdproc(data, len, ns);
219  }
220  return 0;
221  }
222  }
223  /* Player must be in the playing state or the flag on the
224  * the command must be zero for the user to use the command -
225  * otherwise, a player cam save, be in the play_again state, and
226  * the map they were on getsswapped out, yet things that try to look
227  * at the map causes a crash. If the command is valid, but
228  * one they can't use, we still swallow it up.
229  */
230  if (pl) {
231  for (int i = 0; player_commands[i].cmdname != NULL; i++) {
232  if (strcmp(cmd, player_commands[i].cmdname) == 0) {
233  if (pl->state == ST_PLAYING || player_commands[i].flag == 0) {
234  player_commands[i].cmdproc(data, len, pl);
235  }
236  return 1;
237  }
238  }
239  }
240  LOG(llevDebug, "%s: invalid command '%s'\n", ns->host, cmd);
241  return 0;
242 }
243 
254  /* Loop through this - maybe we have several complete packets here. */
255  /* Command_count is used to limit the number of requests from
256  * clients that have not logged in - we do not want an unauthenticated
257  * connection to spew us with hundreds of requests. As such,
258  * this counter is only increased in the case of socket level commands.
259  * Note that this also has the effect of throttling down face and other
260  * socket commands from the client. As such, if we have a player attached,
261  * we will process more of these, as getting a fair number when entering
262  * a map may not be uncommon.
263  */
264  int command_count = 0;
265  while (command_count < 5 || (pl && command_count < 25)) {
266  if (pl && pl->state == ST_PLAYING && pl->ob != NULL && pl->ob->speed_left < 0) {
267  // Skip processing players with no turns left.
268  return false;
269  }
270 
271  int status = SockList_ReadPacket(ns->fd, &ns->inbuf, sizeof(ns->inbuf.buf)-1);
272  if (status != 1) {
273  if (status < 0) {
274  ns->status = Ns_Dead;
275  }
276  return false;
277  }
278 
279  /* Since we have a full packet, reset last tick time. */
280  ns->last_tick = 0;
281 
283  assert(ns->inbuf.len >= 2);
284  char *data;
285  char *cmd = strtok_r((char *)ns->inbuf.buf + 2, " ", &data);
286 
287  int got_player_cmd;
288  if (data != NULL) {
289  int rem = ns->inbuf.len - ((unsigned char *)data - ns->inbuf.buf);
290  got_player_cmd = handle_cmd(ns, pl, cmd, data, rem);
291  } else {
292  got_player_cmd = handle_cmd(ns, pl, cmd, NULL, 0);
293  }
294 
296  if (got_player_cmd) {
297  return true;
298  }
299 
300  command_count += 1;
301  /* Evil case, and not a nice workaround, but well...
302  * If we receive eg an accountplay command, the socket is copied
303  * to the player structure, and its faces_sent is set to NULL.
304  * This leads to issues when processing the next commands in the queue,
305  * especially if related to faces...
306  * So get out of here in this case, which we detect because faces_sent is NULL.
307  */
308  if (ns->faces_sent == NULL) {
309  command_count = 6;
310  }
311  }
312  return false;
313 }
314 
315 /*****************************************************************************
316  *
317  * Low level socket looping - select calls and watchdog udp packet
318  * sending.
319  *
320  ******************************************************************************/
321 
322 #ifdef WATCHDOG
323 
329 void watchdog(void) {
330  static int fd = -1;
331  static struct sockaddr_in insock;
332 
333  if (fd == -1) {
334  struct protoent *protoent;
335 
336  if ((protoent = getprotobyname("udp")) == NULL
337  || (fd = socket(PF_INET, SOCK_DGRAM, protoent->p_proto)) == -1) {
338  return;
339  }
340  insock.sin_family = AF_INET;
341  insock.sin_port = htons((unsigned short)13325);
342  insock.sin_addr.s_addr = inet_addr("127.0.0.1");
343  }
344  sendto(fd, (void *)&fd, 1, 0, (struct sockaddr *)&insock, sizeof(insock));
345 }
346 #endif
347 
348 extern unsigned long todtick;
349 
353 static void block_until_new_connection(void) {
354  struct timeval Timeout;
355  fd_set readfs;
356  int cycles;
357  int i;
358 
359  LOG(llevInfo, "Waiting for connections...\n");
360 
361  cycles = 1;
362  do {
363  /* Every minutes is a bit often for updates - especially if nothing is going
364  * on. This slows it down to every 6 minutes.
365  */
366  cycles++;
367  if (cycles%2 == 0)
368  tick_the_clock();
369 
370  FD_ZERO(&readfs);
371  for (i = 0; i < socket_info.allocated_sockets && init_sockets[i].listen; i++)
372  if (init_sockets[i].status == Ns_Add)
373  FD_SET((uint32_t)init_sockets[i].fd, &readfs);
374 
375  /* If fastclock is set, we need to seriously slow down the updates
376  * to the metaserver as well as watchdog. Do same for flush_old_maps() -
377  * that is time sensitive, so there is no good reason to call it 2000 times
378  * a second.
379  */
380  if (settings.fastclock > 0) {
381 #ifdef WATCHDOG
382  if (cycles%120000 == 0) {
383  watchdog();
384  flush_old_maps();
385  }
386 #endif
387  if (cycles == 720000) {
389  cycles = 1;
390  }
391  Timeout.tv_sec = 0;
392  Timeout.tv_usec = 50;
393  } else {
394  Timeout.tv_sec = 60;
395  Timeout.tv_usec = 0;
396  if (cycles == 7) {
398  cycles = 1;
399  }
400  flush_old_maps();
401  }
402  } while (select(socket_info.max_filedescriptor, &readfs, NULL, NULL, &Timeout) == 0);
403 
404  reset_sleep(); /* Or the game would go too fast */
405 }
406 
415 static int is_fd_valid(int fd) {
416 #ifndef WIN32
417  return fcntl(fd, F_GETFL) != -1 || errno != EBADF;
418 #else
419  return 1;
420 #endif
421 }
422 
427 static void new_connection(int listen_fd) {
428  int newsocknum = -1, j;
429 #ifdef HAVE_GETNAMEINFO
430  struct sockaddr_storage addr;
431 #else
432  struct sockaddr_in addr;
433 #endif
434  socklen_t addrlen = sizeof(addr);
435 
436 #ifdef ESRV_DEBUG
437  LOG(llevDebug, "do_server: New Connection\n");
438 #endif
439 
440  for (j = 0; j < socket_info.allocated_sockets; j++)
441  if (init_sockets[j].status == Ns_Avail) {
442  newsocknum = j;
443  break;
444  }
445 
446  if (newsocknum == -1) {
447  /* If this is the case, all sockets currently in used */
449  if (!init_sockets)
451  newsocknum = socket_info.allocated_sockets;
453  init_sockets[newsocknum].listen = NULL;
455  init_sockets[newsocknum].faces_sent = calloc(get_faces_count(), sizeof(*init_sockets[newsocknum].faces_sent));
456  if (!init_sockets[newsocknum].faces_sent)
458  init_sockets[newsocknum].status = Ns_Avail;
459  }
460 
461  if (newsocknum < 0) {
462  LOG(llevError, "FATAL: didn't allocate a newsocket?? alloc = %d, newsocknum = %d", socket_info.allocated_sockets, newsocknum);
464  }
465 
466  init_sockets[newsocknum].fd = accept(listen_fd, (struct sockaddr *)&addr, &addrlen);
467  if (init_sockets[newsocknum].fd == -1) {
468  LOG(llevError, "accept failed: %s\n", strerror(errno));
469  } else {
470  char buf[MAX_BUF];
471 #ifndef HAVE_GETNAMEINFO
472  long ip;
473 #endif
474  socket_struct *ns;
475 
476  ns = &init_sockets[newsocknum];
477 
478 #ifdef HAVE_GETNAMEINFO
479  getnameinfo((struct sockaddr *) &addr, addrlen, buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
480 #else
481  ip = ntohl(addr.sin_addr.s_addr);
482  snprintf(buf, sizeof(buf), "%ld.%ld.%ld.%ld", (ip>>24)&255, (ip>>16)&255, (ip>>8)&255, ip&255);
483 #endif
484 
485  if (checkbanned(NULL, buf)) {
486  LOG(llevInfo, "Banned host tried to connect: [%s]\n", buf);
487  close(init_sockets[newsocknum].fd);
488  init_sockets[newsocknum].fd = -1;
489  } else {
490  init_connection(ns, buf);
491  }
492  }
493 }
494 
501  // If the client doesn't send heartbeats, assume it's connected.
502  if (!socket.heartbeat) {
503  return true;
504  }
505 
506  // If a client message was received recently, it's connected.
507  if (socket.last_tick < tick_length(BEAT_INTERVAL + 1)) {
508  return true;
509  }
510 
511  return false;
512 }
513 
519  for (uint8_t buf = 0; buf < pl->delayed_buffers_used; buf++) {
521  }
523 }
524 
528 static void send_updates(player *pl) {
529  /* Update the players stats once per tick. More efficient than
530  * sending them whenever they change, and probably just as useful
531  */
533  if (pl->last_weight != -1 && pl->last_weight != WEIGHT(pl->ob)) {
535  if (pl->last_weight != WEIGHT(pl->ob))
536  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));
537  }
538  /* draw_client_map does sanity checking that map is
539  * valid, so don't do it here.
540  */
542  if (pl->socket.update_look)
543  esrv_draw_look(pl->ob);
544  if (pl->socket.update_inventory) {
545  if (pl->ob->container != NULL)
548  }
549 }
550 
558 void do_server(void) {
559  fd_set tmp_read, tmp_exceptions;
560  int active = 0;
561  FD_ZERO(&tmp_read);
562  FD_ZERO(&tmp_exceptions);
563 
564  for (int i = 0; i < socket_info.allocated_sockets; i++) {
565  if (init_sockets[i].status == Ns_Add && !is_fd_valid(init_sockets[i].fd)) {
566  LOG(llevError, "do_server: invalid waiting fd %d\n", i);
568  }
569  if (init_sockets[i].status == Ns_Dead) {
570  LOG(llevInfo, "Disconnected from %s\n", init_sockets[i].host);
571  if (init_sockets[i].listen) {
572  /* try to reopen the listening socket */
574  } else {
577  }
578  } else if (init_sockets[i].status != Ns_Avail) {
579  FD_SET((uint32_t)init_sockets[i].fd, &tmp_read);
580  FD_SET((uint32_t)init_sockets[i].fd, &tmp_exceptions);
581  active++;
582  }
583  }
584 
585  /* Go through the players. Let the loop set the next pl value,
586  * since we may remove some
587  */
588  player *pl, *next;
589  for (pl = first_player; pl != NULL; ) {
590  if (pl->socket.status != Ns_Dead && !is_fd_valid(pl->socket.fd)) {
591  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);
592  pl->socket.status = Ns_Dead;
593  }
594 
595  if (pl->socket.status == Ns_Dead) {
596  player *npl = pl->next;
597 
598  save_player(pl->ob, 0);
599  leave(pl, 1);
601  pl = npl;
602  } else {
603  FD_SET((uint32_t)pl->socket.fd, &tmp_read);
604  FD_SET((uint32_t)pl->socket.fd, &tmp_exceptions);
605  pl = pl->next;
606  }
607  }
608 
609  if (active == 1 && first_player == NULL)
611 
612  long sleep_time = get_sleep_remaining();
613  if (sleep_time < 0) {
614  LOG(llevInfo, "skipping time (over by %ld ms)\n", -sleep_time/1000);
615  jump_time();
616  }
617 
618  while (sleep_time > 0) {
619  socket_info.timeout.tv_sec = 0;
620  socket_info.timeout.tv_usec = sleep_time;
621  int pollret = select(socket_info.max_filedescriptor, &tmp_read, NULL,
622  &tmp_exceptions, &socket_info.timeout);
623  if (pollret == -1) {
624  if (errno != EINTR) {
625  LOG(llevError, "select failed: %s\n", strerror(errno));
626  }
627  return;
628  } else if (!pollret) {
629  return;
630  }
631 
632  /* Check for any exceptions/input on the sockets */
633  for (int i = 0; i < socket_info.allocated_sockets; i++) {
634  /* listen sockets can stay in status Ns_Dead */
635  if (init_sockets[i].status != Ns_Add) {
636  continue;
637  }
638  if (FD_ISSET(init_sockets[i].fd, &tmp_exceptions)) {
641  continue;
642  }
643  if (FD_ISSET(init_sockets[i].fd, &tmp_read)) {
644  if (init_sockets[i].listen)
646  else
647  handle_client(&init_sockets[i], NULL);
648  }
649  }
650 
651  /* This does roughly the same thing, but for the players now */
652  for (pl = first_player; pl != NULL; pl = next) {
653  next = pl->next;
654  if (pl->socket.status == Ns_Dead)
655  continue;
656 
657  if (FD_ISSET(pl->socket.fd, &tmp_exceptions)) {
658  save_player(pl->ob, 0);
659  leave(pl, 1);
661  } else {
662  bool keep_processing = handle_client(&pl->socket, pl);
663  if (!keep_processing) {
664  FD_CLR(pl->socket.fd, &tmp_read);
665  }
666 
667  /* There seems to be rare cases where next points to a removed/freed player.
668  * My belief is that this player does something (shout, move, whatever)
669  * that causes data to be sent to the next player on the list, but
670  * that player is defunct, so the socket codes removes that player.
671  * End result is that next now points at the removed player, and
672  * that has garbage data so we crash. So update the next pointer
673  * while pl is still valid. MSW 2007-04-21
674  */
675  next = pl->next;
676 
677 
678  /* If the player has left the game, then the socket status
679  * will be set to this be the leave function. We don't
680  * need to call leave again, as it has already been called
681  * once.
682  */
683  if (pl->socket.status == Ns_Dead) {
684  save_player(pl->ob, 0);
685  leave(pl, 1);
687  } else {
689  send_updates(pl);
690  }
691  }
692  }
693  sleep_time = get_sleep_remaining();
694  }
695 }
696 
701  player *pl, *next;
702  for (pl = first_player; pl != NULL; pl = next) {
703  next = pl->next;
704  send_updates(pl);
705  /* Increment time since last contact only if logged in. */
706  if (pl->state == ST_PLAYING) {
707  pl->socket.last_tick++;
708 
709  if (!connection_alive(pl->socket)) {
710  // TODO: Handle a lost client connection.
711  LOG(llevDebug, "Lost client connection!\n");
712  }
713 
714  if (pl->socket.tick)
715  send_tick(pl);
716  }
717  }
718 }
give.next
def next
Definition: give.py:44
todtick
unsigned long todtick
Definition: init.c:398
is_fd_valid
static int is_fd_valid(int fd)
Definition: loop.c:415
pl::delayed_buffers
SockList ** delayed_buffers
Definition: player.h:211
socket_struct::tick
uint32_t tick
Definition: newserver.h:106
send_image_info
void send_image_info(socket_struct *ns)
Definition: image.c:121
global.h
player_cmd_mapping::cmdname
const char * cmdname
Definition: loop.c:75
send_image_sums
void send_image_sums(socket_struct *ns, char *params)
Definition: image.c:142
reply_cmd
void reply_cmd(char *buf, int len, player *pl)
Definition: request.c:522
tick_the_clock
void tick_the_clock(void)
Definition: weather.c:96
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.c:85
func_uint8_int_pl
void(* func_uint8_int_pl)(char *, int, player *)
Definition: loop.c:72
init_sockets
socket_struct * init_sockets
Definition: init.c:58
send_delayed_buffers
static void send_delayed_buffers(player *pl)
Definition: loop.c:518
sockproto.h
socket_struct
Definition: newserver.h:89
Socket_Info::allocated_sockets
int allocated_sockets
Definition: newserver.h:144
get_sleep_remaining
long get_sleep_remaining()
Definition: time.c:184
flush_old_maps
void flush_old_maps(void)
Definition: swap.c:247
esrv_send_inventory
void esrv_send_inventory(object *pl, object *op)
Definition: item.c:312
manor.params
params
Definition: manor.py:295
UPD_WEIGHT
#define UPD_WEIGHT
Definition: newclient.h:316
SockList_AddString
void SockList_AddString(SockList *sl, const char *data)
Definition: lowlevel.c:154
pl::socket
socket_struct socket
Definition: player.h:94
pl
Definition: player.h:92
socket_info
Socket_Info socket_info
Definition: init.c:49
new_connection
static void new_connection(int listen_fd)
Definition: loop.c:427
socket_struct::update_inventory
uint32_t update_inventory
Definition: newserver.h:105
mark_item_cmd
void mark_item_cmd(uint8_t *data, int len, player *pl)
Definition: item.c:737
connection_alive
bool connection_alive(socket_struct socket)
Definition: loop.c:500
Socket_Info::max_filedescriptor
int max_filedescriptor
Definition: newserver.h:143
pl::ob
object * ob
Definition: player.h:162
send_new_char_info
void send_new_char_info(socket_struct *ns)
Definition: requestinfo.c:503
pl::delayed_buffers_used
uint8_t delayed_buffers_used
Definition: player.h:210
block_until_new_connection
static void block_until_new_connection(void)
Definition: loop.c:353
send_map_info
void send_map_info(socket_struct *ns)
Definition: requestinfo.c:439
send_exp_table
void send_exp_table(socket_struct *ns)
Definition: requestinfo.c:127
socket_struct::listen
struct listen_info * listen
Definition: newserver.h:92
tick_length
unsigned int tick_length(float seconds)
Definition: time.c:378
SEE_LAST_ERROR
@ SEE_LAST_ERROR
Definition: define.h:52
socket_struct::inbuf
SockList inbuf
Definition: newserver.h:99
reset_sleep
void reset_sleep(void)
Definition: time.c:130
send_updates
static void send_updates(player *pl)
Definition: loop.c:528
settings
struct Settings settings
Definition: init.c:39
socket_struct::update_look
uint32_t update_look
Definition: newserver.h:104
Ns_Dead
@ Ns_Dead
Definition: newserver.h:67
account_password
void account_password(char *buf, int len, socket_struct *ns)
Definition: request.c:2994
send_skill_info
void send_skill_info(socket_struct *ns, char *params)
Definition: requestinfo.c:70
account_login_cmd
void account_login_cmd(char *buf, int len, socket_struct *ns)
Definition: request.c:2110
look_at_cmd
void look_at_cmd(char *buf, int len, player *pl)
Definition: item.c:833
knowledge_send_info
void knowledge_send_info(socket_struct *ns)
Definition: knowledge.c:1368
Ns_Avail
@ Ns_Avail
Definition: newserver.h:65
pl::next
struct pl * next
Definition: player.h:93
final_free_player
void final_free_player(player *pl)
Definition: init.c:444
obj::name
sstring name
Definition: object.h:312
pl::state
uint8_t state
Definition: player.h:118
socklen_t
#define socklen_t
Definition: win32.h:17
player_cmd_mapping::flag
const uint8_t flag
Definition: loop.c:77
player_commands
static const struct player_cmd_mapping player_commands[]
Definition: loop.c:95
esrv_update_stats
void esrv_update_stats(player *pl)
Definition: request.c:800
fatal
void fatal(enum fatal_error err)
Definition: utils.c:597
request_info_cmd
void request_info_cmd(char *buf, int len, socket_struct *ns)
Definition: loop.c:134
obj::speed_left
float speed_left
Definition: object.h:331
socket_struct::host
char * host
Definition: newserver.h:100
first_player
EXTERN player * first_player
Definition: global.h:115
obj::container
struct obj * container
Definition: object.h:292
client_cmd_mapping
Definition: loop.c:66
send_tick
void send_tick(player *pl)
Definition: request.c:1913
navar-midane_time.data
data
Definition: navar-midane_time.py:11
leave
void leave(player *pl, int draw_exit)
Definition: server.c:1275
ask_smooth_cmd
void ask_smooth_cmd(char *buf, int len, socket_struct *ns)
Definition: request.c:437
account_add_player_cmd
void account_add_player_cmd(char *buf, int len, socket_struct *ns)
Definition: request.c:2351
handle_client
bool handle_client(socket_struct *ns, player *pl)
Definition: loop.c:253
sproto.h
create_player_cmd
void create_player_cmd(char *buf, int len, socket_struct *ns)
Definition: request.c:2574
new_player_cmd
void new_player_cmd(uint8_t *buf, int len, player *pl)
Definition: request.c:461
account_play_cmd
void account_play_cmd(char *buf, int len, socket_struct *ns)
Definition: request.c:2480
SockList_Init
void SockList_Init(SockList *sl)
Definition: lowlevel.c:52
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
SockList::len
size_t len
Definition: newclient.h:686
image.h
client_cmd_mapping::cmdname
const char * cmdname
Definition: loop.c:67
move_cmd
void move_cmd(char *buf, int len, player *pl)
Definition: request.c:641
send_class_info
void send_class_info(socket_struct *ns, char *params)
Definition: requestinfo.c:392
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.c:32
pl::last_weight
int32_t last_weight
Definition: player.h:144
version_cmd
void version_cmd(char *buf, int len, socket_struct *ns)
Definition: request.c:584
SockList_Term
void SockList_Term(SockList *sl)
Definition: lowlevel.c:62
send_race_list
void send_race_list(socket_struct *ns)
Definition: requestinfo.c:305
ST_PLAYING
#define ST_PLAYING
Definition: define.h:541
free_newsocket
void free_newsocket(socket_struct *ns)
Definition: init.c:412
llevInfo
@ llevInfo
Definition: logger.h:12
inscribe_scroll_cmd
void inscribe_scroll_cmd(char *buf, int len, player *pl)
Definition: item.c:928
send_class_list
void send_class_list(socket_struct *ns)
Definition: requestinfo.c:371
socket_struct::last_tick
uint32_t last_tick
Definition: newserver.h:130
Socket_Info::timeout
struct timeval timeout
Definition: newserver.h:142
metaserver_update
void metaserver_update(void)
Definition: metaserver.c:78
Settings::fastclock
uint8_t fastclock
Definition: global.h:293
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
newserver.h
BEAT_INTERVAL
#define BEAT_INTERVAL
Definition: config.h:628
func_uint8_int_ns
void(* func_uint8_int_ns)(char *, int, socket_struct *)
Definition: loop.c:63
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.c:360
esrv_draw_look
void esrv_draw_look(object *pl)
Definition: item.c:192
send_file
void send_file(socket_struct *ns, const char *file)
Definition: requestinfo.c:462
examine_cmd
void examine_cmd(char *buf, int len, player *pl)
Definition: item.c:619
socket_struct::faces_sent_len
size_t faces_sent_len
Definition: newserver.h:95
WEIGHT
#define WEIGHT(op)
Definition: define.h:649
buf
StringBuffer * buf
Definition: readable.c:1606
SockList_ResetRead
void SockList_ResetRead(SockList *sl)
Definition: lowlevel.c:80
client_commands
static const struct client_cmd_mapping client_commands[]
Definition: loop.c:109
send_spell_paths
void send_spell_paths(socket_struct *ns)
Definition: requestinfo.c:101
account_new_cmd
void account_new_cmd(char *buf, int len, socket_struct *ns)
Definition: request.c:2237
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:26
lock_item_cmd
void lock_item_cmd(uint8_t *data, int len, player *pl)
Definition: item.c:678
save_player
int save_player(object *op, int flag)
Definition: login.c:230
socket_struct::fd
int fd
Definition: newserver.h:91
jump_time
void jump_time()
Definition: time.c:192
update_players
void update_players()
Definition: loop.c:700
player_cmd_mapping
Definition: loop.c:74
do_server
void do_server(void)
Definition: loop.c:558
get_faces_count
size_t get_faces_count()
Definition: assets.cpp:313
SockList_ReadPacket
int SockList_ReadPacket(int fd, SockList *sl, int len)
Definition: lowlevel.c:272
set_up_cmd
void set_up_cmd(char *buf, int len, socket_struct *ns)
Definition: request.c:95
SockList::buf
unsigned char buf[MAXSOCKBUF]
Definition: newclient.h:687
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.c:326
client_cmd_mapping::cmdproc
const func_uint8_int_ns cmdproc
Definition: loop.c:68
OUT_OF_MEMORY
@ OUT_OF_MEMORY
Definition: define.h:48
player_cmd_mapping::cmdproc
const func_uint8_int_pl cmdproc
Definition: loop.c:76
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.c:349
draw_client_map
void draw_client_map(object *pl)
Definition: request.c:1552
Send_With_Handling
void Send_With_Handling(socket_struct *ns, SockList *sl)
Definition: lowlevel.c:440
SockList
Definition: newclient.h:681
apply_cmd
void apply_cmd(char *buf, int len, player *pl)
Definition: item.c:638
takeitem.status
status
Definition: takeitem.py:35
SockList_NullTerminate
void SockList_NullTerminate(SockList *sl)
Definition: lowlevel.c:234
send_face_cmd
void send_face_cmd(char *buff, int len, socket_struct *ns)
Definition: image.c:44
llevDebug
@ llevDebug
Definition: logger.h:13
handle_cmd
static int handle_cmd(socket_struct *ns, player *pl, char *cmd, char *data, int len)
Definition: loop.c:205
init_listening_socket
void init_listening_socket(socket_struct *ns)
Definition: init.c:173