27 #include <arpa/inet.h> 36 #include <sys/types.h> 38 #include <netinet/in.h> 133 char *params = NULL, *cp;
137 if (len <= 0 || !buf) {
138 LOG(
llevDebug,
"IP '%s' sent bogus request_info_cmd information\n", ns->
host);
152 for (cp = buf; *cp !=
'\0'; cp++)
158 if (!strcmp(buf,
"image_info"))
160 else if (!strcmp(buf,
"image_sums"))
162 else if (!strcmp(buf,
"skill_info"))
164 else if (!strcmp(buf,
"spell_paths"))
166 else if (!strcmp(buf,
"exp_table"))
168 else if (!strcmp(buf,
"race_list"))
170 else if (!strcmp(buf,
"race_info"))
172 else if (!strcmp(buf,
"class_list"))
174 else if (!strcmp(buf,
"class_info"))
176 else if (!strcmp(buf,
"rules"))
178 else if (!strcmp(buf,
"motd"))
180 else if (!strcmp(buf,
"news"))
182 else if (!strcmp(buf,
"newcharinfo"))
184 else if (!strcmp(buf,
"startingmap"))
186 else if (!strcmp(buf,
"knowledge_info"))
204 for (
int i = 0; client_commands[i].
cmdname != NULL; i++) {
205 if (strcmp(cmd, client_commands[i].
cmdname) == 0) {
206 if (client_commands[i].
cmdproc != NULL) {
207 client_commands[i].
cmdproc(data, len, ns);
220 for (
int i = 0; player_commands[i].
cmdname != NULL; i++) {
221 if (strcmp(cmd, player_commands[i].
cmdname) == 0) {
223 player_commands[i].
cmdproc(data, len, pl);
253 int command_count = 0;
254 while (command_count < 5 || (pl && command_count < 25)) {
279 got_player_cmd =
handle_cmd(ns, pl, cmd, data, rem);
281 got_player_cmd =
handle_cmd(ns, pl, cmd, NULL, 0);
285 if (got_player_cmd) {
320 static struct sockaddr_in insock;
323 struct protoent *protoent;
325 if ((protoent = getprotobyname(
"udp")) == NULL
326 || (fd = socket(PF_INET, SOCK_DGRAM, protoent->p_proto)) == -1) {
329 insock.sin_family = AF_INET;
330 insock.sin_port = htons((
unsigned short)13325);
331 insock.sin_addr.s_addr = inet_addr(
"127.0.0.1");
333 sendto(fd, (
void *)&fd, 1, 0, (
struct sockaddr *)&insock,
sizeof(insock));
343 struct timeval Timeout;
371 if (cycles%120000 == 0) {
376 if (cycles == 720000) {
381 Timeout.tv_usec = 50;
406 return fcntl(fd, F_GETFL) != -1 || errno != EBADF;
417 int newsocknum = -1, j;
418 #ifdef HAVE_GETNAMEINFO 419 struct sockaddr_storage addr;
421 struct sockaddr_in addr;
435 if (newsocknum == -1) {
450 if (newsocknum < 0) {
455 init_sockets[newsocknum].
fd = accept(listen_fd, (
struct sockaddr *)&addr, &addrlen);
460 #ifndef HAVE_GETNAMEINFO 467 #ifdef HAVE_GETNAMEINFO 468 getnameinfo((
struct sockaddr *) &addr, addrlen, buf,
sizeof(buf), NULL, 0, NI_NUMERICHOST);
470 ip = ntohl(addr.sin_addr.s_addr);
471 snprintf(buf,
sizeof(buf),
"%ld.%ld.%ld.%ld", (ip>>24)&255, (ip>>16)&255, (ip>>8)&255, ip&255);
475 LOG(
llevInfo,
"Banned host tried to connect: [%s]\n", buf);
514 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 fd_set tmp_read, tmp_exceptions;
540 FD_ZERO(&tmp_exceptions);
544 LOG(
llevError,
"do_server: invalid waiting fd %d\n", i);
591 if (sleep_time < 0) {
592 LOG(
llevInfo,
"skipping time (over by %ld ms)\n", -sleep_time/1000);
596 while (sleep_time > 0) {
602 if (errno != EINTR) {
606 }
else if (!pollret) {
635 if (FD_ISSET(pl->
socket.
fd, &tmp_exceptions)) {
641 if (!keep_processing) {
static void send_updates(player *pl)
void leave(player *pl, int draw_exit)
const func_uint8_int_ns cmdproc
void SockList_Init(SockList *sl)
unsigned char buf[MAXSOCKBUF]
void account_login_cmd(char *buf, int len, socket_struct *ns)
void SockList_ResetRead(SockList *sl)
void mark_item_cmd(uint8_t *data, int len, player *pl)
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
void fatal(enum fatal_error err)
int save_player(object *op, int flag)
void esrv_update_item(int flags, object *pl, object *op)
void send_map_info(socket_struct *ns)
void send_image_sums(socket_struct *ns, char *params)
void esrv_send_inventory(object *pl, object *op)
void new_player_cmd(uint8_t *buf, int len, player *pl)
int checkbanned(const char *login, const char *host)
void inscribe_scroll_cmd(char *buf, int len, player *pl)
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)
static int handle_cmd(socket_struct *ns, player *pl, char *cmd, char *data, int len)
void flush_old_maps(void)
static const struct client_cmd_mapping client_commands[]
#define strtok_r(x, y, z)
void send_exp_table(socket_struct *ns, char *params)
void SockList_Term(SockList *sl)
long get_sleep_remaining()
void(* func_uint8_int_ns)(char *, int, socket_struct *)
void account_password(char *buf, int len, socket_struct *ns)
bool connection_alive(socket_struct socket)
void init_listening_socket(socket_struct *ns)
void SockList_AddString(SockList *sl, const char *data)
void account_new_cmd(char *buf, int len, socket_struct *ns)
uint32_t update_inventory
void send_race_info(socket_struct *ns, char *params)
void tick_the_clock(void)
unsigned int get_faces_count()
void send_image_info(socket_struct *ns)
static int is_fd_valid(int fd)
void send_class_info(socket_struct *ns, char *params)
void set_up_cmd(char *buf, int len, socket_struct *ns)
void draw_client_map(object *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 lock_item_cmd(uint8_t *data, int len, player *pl)
void ask_smooth_cmd(char *buf, int len, socket_struct *ns)
void(* func_uint8_int_pl)(char *, int, player *)
void send_file(socket_struct *ns, const char *file)
bool handle_client(socket_struct *ns, player *pl)
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 account_add_player_cmd(char *buf, int len, socket_struct *ns)
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)
void send_new_char_info(socket_struct *ns)
static void new_connection(int listen_fd)
void knowledge_send_info(socket_struct *ns)
unsigned int tick_length(float seconds)
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)
struct listen_info * listen
void move_cmd(char *buf, int len, player *pl)
void create_player_cmd(char *buf, int len, socket_struct *ns)
void Send_With_Handling(socket_struct *ns, SockList *sl)
void account_play_cmd(char *buf, int len, socket_struct *ns)