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");
344 sendto(fd, (
void *)&fd, 1, 0, (
struct sockaddr *)&insock,
sizeof(insock));
352 struct timeval Timeout;
380 if (cycles%120000 == 0) {
385 if (cycles == 720000) {
390 Timeout.tv_usec = 50;
415 return fcntl(fd, F_GETFL) != -1 || errno != EBADF;
426 int newsocknum = -1, j;
427 #ifdef HAVE_GETNAMEINFO
428 struct sockaddr_storage addr;
430 struct sockaddr_in addr;
444 if (newsocknum == -1) {
459 if (newsocknum < 0) {
469 #ifndef HAVE_GETNAMEINFO
476 #ifdef HAVE_GETNAMEINFO
477 getnameinfo((
struct sockaddr *) &addr, addrlen,
buf,
sizeof(
buf), NULL, 0, NI_NUMERICHOST);
479 ip = ntohl(addr.sin_addr.s_addr);
480 snprintf(
buf,
sizeof(
buf),
"%ld.%ld.%ld.%ld", (
ip>>24)&255, (
ip>>16)&255, (
ip>>8)&255,
ip&255);
557 fd_set tmp_read, tmp_exceptions;
560 FD_ZERO(&tmp_exceptions);
564 LOG(
llevError,
"do_server: invalid waiting fd %d\n", i);
603 FD_SET((uint32_t)
pl->
socket.
fd, &tmp_exceptions);
612 if (sleep_time < 0) {
613 LOG(
llevInfo,
"skipping time (over by %ld ms)\n", -sleep_time/1000);
617 while (sleep_time > 0) {
623 if (errno != EINTR) {
627 }
else if (!pollret) {
656 if (FD_ISSET(
pl->
socket.
fd, &tmp_exceptions)) {
662 if (!keep_processing) {
static int is_fd_valid(int fd)
SockList ** delayed_buffers
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(* func_uint8_int_pl)(char *, int, player *)
socket_struct * init_sockets
static void send_delayed_buffers(player *pl)
long get_sleep_remaining()
void flush_old_maps(void)
void esrv_send_inventory(object *pl, object *op)
void SockList_AddString(SockList *sl, const char *data)
static void new_connection(int listen_fd)
uint32_t update_inventory
void mark_item_cmd(uint8_t *data, int len, player *pl)
bool connection_alive(socket_struct socket)
void send_new_char_info(socket_struct *ns)
uint8_t delayed_buffers_used
static void block_until_new_connection(void)
void send_map_info(socket_struct *ns)
void send_exp_table(socket_struct *ns)
struct listen_info * listen
unsigned int tick_length(float seconds)
static void send_updates(player *pl)
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)
static const struct player_cmd_mapping player_commands[]
void esrv_update_stats(player *pl)
void fatal(enum fatal_error err)
void request_info_cmd(char *buf, int len, socket_struct *ns)
EXTERN player * first_player
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)
bool handle_client(socket_struct *ns, player *pl)
void create_player_cmd(char *buf, int len, socket_struct *ns)
void new_player_cmd(uint8_t *buf, int len, player *pl)
void account_play_cmd(char *buf, int len, socket_struct *ns)
void SockList_Init(SockList *sl)
void move_cmd(char *buf, int len, player *pl)
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)
void SockList_Term(SockList *sl)
void send_race_list(socket_struct *ns)
void free_newsocket(socket_struct *ns)
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 LOG(LogLevel logLevel, const char *format,...)
void(* func_uint8_int_ns)(char *, int, socket_struct *)
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)
void SockList_ResetRead(SockList *sl)
static const struct client_cmd_mapping client_commands[]
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)
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 SockList_NullTerminate(SockList *sl)
void send_face_cmd(char *buff, int len, socket_struct *ns)
static int handle_cmd(socket_struct *ns, player *pl, char *cmd, char *data, int len)
void init_listening_socket(socket_struct *ns)