48 #include <sys/types.h>
50 #include <sys/socket.h>
51 #include <netinet/in.h>
59 #ifdef HAVE_ARPA_INET_H
60 #include <arpa/inet.h>
147 char *params = NULL, *cp;
161 for (cp = buf; *cp !=
'\0'; cp++)
167 if (!strcmp(buf,
"image_info"))
169 else if (!strcmp(buf,
"image_sums"))
171 else if (!strcmp(buf,
"skill_info"))
173 else if (!strcmp(buf,
"spell_paths"))
175 else if (!strcmp(buf,
"exp_table"))
177 else if (!strcmp(buf,
"race_list"))
179 else if (!strcmp(buf,
"race_info"))
181 else if (!strcmp(buf,
"class_list"))
183 else if (!strcmp(buf,
"class_info"))
216 LOG(
llevDebug,
"handle_client: Read error on connection player %s\n", (pl ? pl->
ob->
name :
"None"));
233 data = (
unsigned char *)strchr((
char *)ns->
inbuf.
buf+2,
' ');
241 for (i = 0; client_commands[i].
cmdname != NULL; i++) {
242 if (strcmp((
char *)ns->
inbuf.
buf+2, client_commands[i].
cmdname) == 0) {
243 client_commands[i].
cmdproc((
char *)data, len, ns);
256 for (i = 0; player_commands[i].
cmdname != NULL; i++) {
257 if (strcmp((
char *)ns->
inbuf.
buf+2, player_commands[i].
cmdname) == 0) {
259 player_commands[i].
cmdproc((
char *)data, len, pl);
289 static struct sockaddr_in insock;
292 struct protoent *protoent;
294 if ((protoent = getprotobyname(
"udp")) == NULL
295 || (fd = socket(PF_INET, SOCK_DGRAM, protoent->p_proto)) == -1) {
298 insock.sin_family = AF_INET;
299 insock.sin_port = htons((
unsigned short)13325);
300 insock.sin_addr.s_addr = inet_addr(
"127.0.0.1");
302 sendto(fd, (
void *)&fd, 1, 0, (
struct sockaddr *)&insock,
sizeof(insock));
310 struct timeval Timeout;
335 if (cycles%120000 == 0) {
340 if (cycles == 720000) {
345 Timeout.tv_usec = 50;
370 return fcntl(fd, F_GETFL) != -1 || errno != EBADF;
385 fd_set tmp_read, tmp_exceptions, tmp_write;
386 struct sockaddr_in addr;
387 socklen_t addrlen =
sizeof(
struct sockaddr);
398 FD_ZERO(&tmp_exceptions);
402 LOG(
llevError,
"do_server: invalid waiting fd %d\n", i);
464 if (pollret && FD_ISSET(
init_sockets[0].fd, &tmp_read)) {
501 ip = ntohl(addr.sin_addr.s_addr);
502 snprintf(buf,
sizeof(buf),
"%ld.%ld.%ld.%ld", (ip>>24)&255, (ip>>16)&255, (ip>>8)&255, ip&255);
505 LOG(
llevInfo,
"Banned host tried to connect: [%s]\n", buf);
540 if (FD_ISSET(pl->
socket.
fd, &tmp_write)) {
553 if (FD_ISSET(pl->
socket.
fd, &tmp_exceptions)) {
596 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));
void leave(player *pl, int draw_exit)
void map_redraw_cmd(char *buf, int len, player *pl)
const func_uint8_int_ns cmdproc
void SockList_Init(SockList *sl)
void(* func_uint8_int_pl)(char *, int, player *)
void set_face_mode_cmd(char *buf, int len, socket_struct *ns)
void SockList_ResetRead(SockList *sl)
void look_at_cmd(char *buf, int len, player *pl)
void version_cmd(char *buf, int len, socket_struct *ns)
void metaserver_update(void)
const func_uint8_int_pl cmdproc
int save_player(object *op, int flag)
void esrv_update_item(int flags, object *pl, object *op)
void send_image_sums(socket_struct *ns, char *params)
void send_image_info(socket_struct *ns, char *params)
int checkbanned(const char *login, const char *host)
void inscribe_scroll_cmd(char *buf, int len, player *pl)
void terminate_all_pets(object *owner)
void send_skill_info(socket_struct *ns, char *params)
socket_struct * init_sockets
void send_class_list(socket_struct *ns, char *params)
void free_newsocket(socket_struct *ns)
unsigned char buf[2+65536UL+1]
void remove_ob(object *op)
void flush_old_maps(void)
static const struct client_cmd_mapping client_commands[]
void new_player_cmd(uint8 *buf, int len, player *pl)
void handle_client(socket_struct *ns, player *pl)
void send_exp_table(socket_struct *ns, char *params)
void SockList_Term(SockList *sl)
void write_socket_buffer(socket_struct *ns)
void SockList_AddString(SockList *sl, const char *data)
void mark_item_cmd(uint8 *data, int len, player *pl)
void send_race_info(socket_struct *ns, char *params)
void tick_the_clock(void)
#define QUERY_FLAG(xyz, p)
static int is_fd_valid(int fd)
void send_class_info(socket_struct *ns, char *params)
void set_sound_cmd(char *buf, int len, socket_struct *ns)
void set_up_cmd(char *buf, int len, socket_struct *ns)
void draw_client_map(object *pl)
void toggle_extended_infos_cmd(char *buf, int len, socket_struct *ns)
int snprintf(char *dest, int max, const char *format,...)
void lock_item_cmd(uint8 *data, int len, player *pl)
void esrv_draw_look(object *pl)
static const struct player_cmd_mapping player_commands[]
void init_connection(socket_struct *ns, const char *from_ip)
void send_tick(player *pl)
void send_spell_paths(socket_struct *ns, char *params)
void request_info_cmd(char *buf, int len, socket_struct *ns)
void write_cs_stats(void)
void(* func_uint8_int_ns)(char *, int, socket_struct *)
void ask_smooth_cmd(char *buf, int len, socket_struct *ns)
void toggle_extended_text_cmd(char *buf, int len, socket_struct *ns)
void examine_cmd(char *buf, int len, player *pl)
void apply_cmd(char *buf, int len, player *pl)
static void block_until_new_connection(void)
EXTERN player * first_player
void final_free_player(player *pl)
void LOG(LogLevel logLevel, const char *format,...)
void add_me_cmd(char *buf, int len, socket_struct *ns)
void send_race_list(socket_struct *ns, char *params)
void reply_cmd(char *buf, int len, player *pl)
char * strerror_local(int errnum, char *buf, size_t size)
void SockList_NullTerminate(SockList *sl)
void esrv_update_stats(player *pl)
int SockList_ReadPacket(int fd, SockList *sl, int len)
void send_face_cmd(char *buff, int len, socket_struct *ns)
void move_cmd(char *buf, int len, player *pl)
void Send_With_Handling(socket_struct *ns, SockList *sl)