Go to the documentation of this file.
35 #include <arpa/inet.h>
36 #include <sys/types.h>
38 #include <netinet/in.h>
141 if (len <= 0 || !
buf) {
142 LOG(
llevDebug,
"IP '%s' sent bogus request_info_cmd information\n", ns->
host);
156 for (cp =
buf; *cp !=
'\0'; cp++)
162 if (!strcmp(
buf,
"image_info"))
164 else if (!strcmp(
buf,
"image_sums"))
166 else if (!strcmp(
buf,
"skill_info"))
168 else if (!strcmp(
buf,
"skill_extra"))
170 else if (!strcmp(
buf,
"spell_paths"))
172 else if (!strcmp(
buf,
"exp_table"))
174 else if (!strcmp(
buf,
"race_list"))
176 else if (!strcmp(
buf,
"race_info"))
178 else if (!strcmp(
buf,
"class_list"))
180 else if (!strcmp(
buf,
"class_info"))
182 else if (!strcmp(
buf,
"rules"))
184 else if (!strcmp(
buf,
"motd"))
186 else if (!strcmp(
buf,
"news"))
188 else if (!strcmp(
buf,
"newcharinfo"))
190 else if (!strcmp(
buf,
"startingmap"))
192 else if (!strcmp(
buf,
"knowledge_info"))
268 int command_count = 0;
269 while (command_count < 5 || (
pl && command_count < 25)) {
289 char *cmd = strtok_r((
char *)ns->
inbuf.
buf + 2,
" ", &
data);
300 if (got_player_cmd) {
335 static struct sockaddr_in insock;
338 struct protoent *protoent;
340 if ((protoent = getprotobyname(
"udp")) == NULL
341 || (fd = socket(PF_INET, SOCK_DGRAM, protoent->p_proto)) == -1) {
344 insock.sin_family = AF_INET;
345 insock.sin_port = htons((
unsigned short)13325);
346 insock.sin_addr.s_addr = inet_addr(
"127.0.0.1");
350 sendto(fd,
buf, strlen(
buf), 0, (
struct sockaddr *)&insock,
sizeof(insock));
364 return fcntl(fd, F_GETFL) != -1 || errno != EBADF;
375 int newsocknum = -1, j;
376 #ifdef HAVE_GETNAMEINFO
377 struct sockaddr_storage addr;
379 struct sockaddr_in addr;
393 if (newsocknum == -1) {
409 if (newsocknum < 0) {
419 #ifndef HAVE_GETNAMEINFO
426 #ifdef HAVE_GETNAMEINFO
427 getnameinfo((
struct sockaddr *) &addr, addrlen,
buf,
sizeof(
buf), NULL, 0, NI_NUMERICHOST);
429 ip = ntohl(addr.sin_addr.s_addr);
430 snprintf(
buf,
sizeof(
buf),
"%ld.%ld.%ld.%ld", (
ip>>24)&255, (
ip>>16)&255, (
ip>>8)&255,
ip&255);
467 for (uint8_t
buf = 0;
buf <
pl->delayed_buffers_used;
buf++) {
470 pl->delayed_buffers_used = 0;
481 if (
pl->last_weight != -1 &&
pl->last_weight !=
WEIGHT(
pl->ob)) {
484 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));
490 if (
pl->socket->update_look)
492 if (
pl->socket->update_inventory) {
493 if (
pl->ob->container != NULL)
495 pl->socket->update_inventory = 0;
536 fd_set tmp_read, tmp_exceptions;
538 FD_ZERO(&tmp_exceptions);
568 FD_SET((uint32_t)
pl->socket->fd, &tmp_read);
569 FD_SET((uint32_t)
pl->socket->fd, &tmp_exceptions);
575 if (sleep_time < 0) {
576 LOG(
llevInfo,
"skipping time (over by %ld ms)\n", -sleep_time/1000);
595 while (sleep_time > 0) {
601 if (errno == EINTR) {
604 }
else if (errno == EBADF) {
609 }
else if (!pollret) {
638 if (FD_ISSET(
pl->socket->fd, &tmp_exceptions)) {
644 if (!keep_processing) {
645 FD_CLR(
pl->socket->fd, &tmp_read);
688 pl->socket->last_tick++;
695 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)
unsigned long total_ticktime
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 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)
void inscribe_scroll_cmd(char *buf, int len, player *pl)
unsigned long max_ticktime
void send_class_list(socket_struct *ns)
#define FREE_AND_CLEAR(xyz)
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_skill_extra(socket_struct *ns, char *params)
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[]
unsigned long ticks_overtime
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)