Go to the documentation of this file.
35 #include <arpa/inet.h>
36 #include <sys/types.h>
38 #include <netinet/in.h>
139 if (len <= 0 || !
buf) {
140 LOG(
llevDebug,
"IP '%s' sent bogus request_info_cmd information\n", ns->
host);
154 for (cp =
buf; *cp !=
'\0'; cp++)
160 if (!strcmp(
buf,
"image_info"))
162 else if (!strcmp(
buf,
"image_sums"))
164 else if (!strcmp(
buf,
"skill_info"))
166 else if (!strcmp(
buf,
"spell_paths"))
168 else if (!strcmp(
buf,
"exp_table"))
170 else if (!strcmp(
buf,
"race_list"))
172 else if (!strcmp(
buf,
"race_info"))
174 else if (!strcmp(
buf,
"class_list"))
176 else if (!strcmp(
buf,
"class_info"))
178 else if (!strcmp(
buf,
"rules"))
180 else if (!strcmp(
buf,
"motd"))
182 else if (!strcmp(
buf,
"news"))
184 else if (!strcmp(
buf,
"newcharinfo"))
186 else if (!strcmp(
buf,
"startingmap"))
188 else if (!strcmp(
buf,
"knowledge_info"))
264 int command_count = 0;
265 while (command_count < 5 || (
pl && command_count < 25)) {
285 char *cmd = strtok_r((
char *)ns->
inbuf.
buf + 2,
" ", &
data);
296 if (got_player_cmd) {
331 static struct sockaddr_in insock;
334 struct protoent *protoent;
336 if ((protoent = getprotobyname(
"udp")) == NULL
337 || (fd = socket(PF_INET, SOCK_DGRAM, protoent->p_proto)) == -1) {
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");
346 sendto(fd,
buf, strlen(
buf), 0, (
struct sockaddr *)&insock,
sizeof(insock));
354 struct timeval Timeout;
381 if (cycles%120000 == 0) {
387 if (cycles == 720000) {
392 Timeout.tv_usec = 50;
420 return fcntl(fd, F_GETFL) != -1 || errno != EBADF;
431 int newsocknum = -1, j;
432 #ifdef HAVE_GETNAMEINFO
433 struct sockaddr_storage addr;
435 struct sockaddr_in addr;
449 if (newsocknum == -1) {
465 if (newsocknum < 0) {
475 #ifndef HAVE_GETNAMEINFO
482 #ifdef HAVE_GETNAMEINFO
483 getnameinfo((
struct sockaddr *) &addr, addrlen,
buf,
sizeof(
buf), NULL, 0, NI_NUMERICHOST);
485 ip = ntohl(addr.sin_addr.s_addr);
486 snprintf(
buf,
sizeof(
buf),
"%ld.%ld.%ld.%ld", (
ip>>24)&255, (
ip>>16)&255, (
ip>>8)&255,
ip&255);
523 for (uint8_t
buf = 0;
buf <
pl->delayed_buffers_used;
buf++) {
526 pl->delayed_buffers_used = 0;
537 if (
pl->last_weight != -1 &&
pl->last_weight !=
WEIGHT(
pl->ob)) {
540 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));
546 if (
pl->socket->update_look)
548 if (
pl->socket->update_inventory) {
549 if (
pl->ob->container != NULL)
551 pl->socket->update_inventory = 0;
563 fd_set tmp_read, tmp_exceptions;
566 FD_ZERO(&tmp_exceptions);
570 LOG(
llevError,
"do_server: invalid waiting fd %d\n", i);
596 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);
608 FD_SET((uint32_t)
pl->socket->fd, &tmp_read);
609 FD_SET((uint32_t)
pl->socket->fd, &tmp_exceptions);
618 if (sleep_time < 0) {
619 LOG(
llevInfo,
"skipping time (over by %ld ms)\n", -sleep_time/1000);
623 while (sleep_time > 0) {
629 if (errno != EINTR) {
633 }
else if (!pollret) {
662 if (FD_ISSET(
pl->socket->fd, &tmp_exceptions)) {
668 if (!keep_processing) {
669 FD_CLR(
pl->socket->fd, &tmp_read);
712 pl->socket->last_tick++;
719 if (
pl->socket->tick)
void request_info_cmd(char *buf, int len, socket_struct *ns)
void send_image_info(socket_struct *ns)
void send_image_sums(socket_struct *ns, char *params)
void reply_cmd(char *buf, int len, player *pl)
void tick_the_clock(void)
void init_connection(socket_struct *ns, const char *from_ip)
void LOG(LogLevel logLevel, const char *format,...)
socket_struct * init_sockets
static const struct client_cmd_mapping client_commands[]
void flush_old_maps(void)
void esrv_send_inventory(object *pl, object *op)
void SockList_AddString(SockList *sl, const char *data)
void mark_item_cmd(uint8_t *data, int len, player *pl)
static void send_updates(player *pl)
void send_new_char_info(socket_struct *ns)
void send_map_info(socket_struct *ns)
void send_exp_table(socket_struct *ns)
struct listen_info * listen
static int is_fd_valid(int fd)
void account_password(char *buf, int len, socket_struct *ns)
void send_skill_info(socket_struct *ns, char *params)
void account_login_cmd(char *buf, int len, socket_struct *ns)
void look_at_cmd(char *buf, int len, player *pl)
void knowledge_send_info(socket_struct *ns)
void final_free_player(player *pl)
void(* func_uint8_int_ns)(char *, int, socket_struct *)
void esrv_update_stats(player *pl)
void send_tick(player *pl)
void leave(player *pl, int draw_exit)
void ask_smooth_cmd(char *buf, int len, socket_struct *ns)
void account_add_player_cmd(char *buf, int len, socket_struct *ns)
void create_player_cmd(char *buf, int len, socket_struct *ns)
void new_player_cmd(uint8_t *buf, int len, player *pl)
long get_sleep_remaining()
void account_play_cmd(char *buf, int len, socket_struct *ns)
void SockList_Init(SockList *sl)
static void send_delayed_buffers(player *pl)
void move_cmd(char *buf, int len, player *pl)
void fatal(enum fatal_error err)
void send_class_info(socket_struct *ns, char *params)
int checkbanned(const char *login, const char *host)
void version_cmd(char *buf, int len, socket_struct *ns)
unsigned int tick_length(float seconds)
static void new_connection(int listen_fd)
void SockList_Term(SockList *sl)
void send_race_list(socket_struct *ns)
bool handle_client(socket_struct *ns, player *pl)
void free_newsocket(socket_struct *ns)
static void block_until_new_connection(void)
void inscribe_scroll_cmd(char *buf, int len, player *pl)
void send_class_list(socket_struct *ns)
#define FREE_AND_CLEAR(xyz)
void metaserver_update(void)
void esrv_update_item(int flags, object *pl, object *op)
void esrv_draw_look(object *pl)
void send_file(socket_struct *ns, const char *file)
void examine_cmd(char *buf, int len, player *pl)
static int handle_cmd(socket_struct *ns, player *pl, char *cmd, char *data, int len)
void SockList_ResetRead(SockList *sl)
void send_spell_paths(socket_struct *ns)
void account_new_cmd(char *buf, int len, socket_struct *ns)
void lock_item_cmd(uint8_t *data, int len, player *pl)
int save_player(object *op, int flag)
static const struct player_cmd_mapping player_commands[]
int SockList_ReadPacket(int fd, SockList *sl, int len)
void set_up_cmd(char *buf, int len, socket_struct *ns)
unsigned char buf[MAXSOCKBUF]
void send_race_info(socket_struct *ns, char *params)
const func_uint8_int_ns cmdproc
const func_uint8_int_pl cmdproc
void add_me_cmd(char *buf, int len, socket_struct *ns)
void draw_client_map(object *pl)
void Send_With_Handling(socket_struct *ns, SockList *sl)
void apply_cmd(char *buf, int len, player *pl)
void(* func_uint8_int_pl)(char *, int, player *)
void SockList_NullTerminate(SockList *sl)
void send_face_cmd(char *buff, int len, socket_struct *ns)
void init_listening_socket(socket_struct *ns)
bool connection_alive(const socket_struct *socket)