--- deliantra/server/socket/loop.C 2006/12/11 19:46:47 1.8 +++ deliantra/server/socket/loop.C 2006/12/13 02:55:51 1.10 @@ -34,10 +34,8 @@ #include -#ifndef __CEXTRACT__ -# include -# include -#endif +#include +#include #include #include @@ -160,6 +158,7 @@ params = cp + 1; break; } + if (!strcmp (buf, "image_info")) send_image_info (ns, params); else if (!strcmp (buf, "image_sums")) @@ -326,7 +325,7 @@ } /** - * This checks the sockets for input and exceptions, does the right thing. + * This checks the sockets for input, does the right thing. * * A bit of this code is grabbed out of socket.c * There are 2 lists we need to look through - init_sockets is a list @@ -336,7 +335,7 @@ doeric_server (void) { int i, pollret; - fd_set tmp_read, tmp_exceptions, tmp_write; + fd_set tmp_read, tmp_write; struct sockaddr_in addr; socklen_t addrlen = sizeof (struct sockaddr); player *pl, *next; @@ -348,7 +347,6 @@ FD_ZERO (&tmp_read); FD_ZERO (&tmp_write); - FD_ZERO (&tmp_exceptions); for (i = 0; i < socket_info.allocated_sockets; i++) { @@ -360,9 +358,8 @@ } else if (init_sockets[i].status != Ns_Avail) { - FD_SET ((uint32) init_sockets[i].fd, &tmp_read); - FD_SET ((uint32) init_sockets[i].fd, &tmp_write); - FD_SET ((uint32) init_sockets[i].fd, &tmp_exceptions); + FD_SET (init_sockets[i].fd, &tmp_read); + FD_SET (init_sockets[i].fd, &tmp_write); } } @@ -376,11 +373,13 @@ player *npl = pl->next; save_player (pl->ob, 0); + if (!QUERY_FLAG (pl->ob, FLAG_REMOVED)) { terminate_all_pets (pl->ob); - remove_ob (pl->ob); + pl->ob->remove (); } + leave (pl, 1); final_free_player (pl); pl = npl; @@ -389,7 +388,6 @@ { FD_SET ((uint32) pl->socket.fd, &tmp_read); FD_SET ((uint32) pl->socket.fd, &tmp_write); - FD_SET ((uint32) pl->socket.fd, &tmp_exceptions); pl = pl->next; } } @@ -397,10 +395,12 @@ /* Reset timeout each time, since some OS's will change the values on * the return from select. */ - socket_info.timeout.tv_sec = 0; + socket_info.timeout.tv_sec = 0; socket_info.timeout.tv_usec = 0; - pollret = select (socket_info.max_filedescriptor, &tmp_read, &tmp_write, &tmp_exceptions, &socket_info.timeout); + pollret = select (socket_info.max_filedescriptor, + &tmp_read, &tmp_write, 0, + &socket_info.timeout); if (pollret == -1) { @@ -445,11 +445,11 @@ break; } } + init_sockets[newsocknum].fd = accept (init_sockets[0].fd, (struct sockaddr *) &addr, &addrlen); + if (init_sockets[newsocknum].fd == -1) - { - LOG (llevError, "accept failed: %s\n", strerror (errno)); - } + LOG (llevError, "accept failed: %s\n", strerror (errno)); else { char buf[MAX_BUF]; @@ -475,27 +475,18 @@ } } - /* Check for any exceptions/input on the sockets */ + /* Check for any input on the sockets */ if (pollret) for (i = 1; i < socket_info.allocated_sockets; i++) { if (init_sockets[i].status == Ns_Avail) continue; - if (FD_ISSET (init_sockets[i].fd, &tmp_exceptions)) - { - free_newsocket (&init_sockets[i]); - init_sockets[i].status = Ns_Avail; - socket_info.nconns--; - continue; - } + if (FD_ISSET (init_sockets[i].fd, &tmp_read)) - { - HandleClient (&init_sockets[i], NULL); - } + HandleClient (&init_sockets[i], NULL); + if (FD_ISSET (init_sockets[i].fd, &tmp_write)) - { - init_sockets[i].can_write = 1; - } + init_sockets[i].can_write = 1; } /* This does roughly the same thing, but for the players now */ @@ -516,6 +507,7 @@ pl->socket.can_write = 1; write_socket_buffer (&pl->socket); } + /* if we get an error on the write_socket buffer, no reason to * continue on this socket. */ @@ -525,57 +517,46 @@ else pl->socket.can_write = 0; - if (FD_ISSET (pl->socket.fd, &tmp_exceptions)) + HandleClient (&pl->socket, pl); + /* If the player has left the game, then the socket status + * will be set to this be the leave function. We don't + * need to call leave again, as it has already been called + * once. + */ + if (pl->socket.status == Ns_Dead) { save_player (pl->ob, 0); + if (!QUERY_FLAG (pl->ob, FLAG_REMOVED)) { terminate_all_pets (pl->ob); - remove_ob (pl->ob); + pl->ob->remove (); } + leave (pl, 1); final_free_player (pl); } else { - HandleClient (&pl->socket, pl); - /* If the player has left the game, then the socket status - * will be set to this be the leave function. We don't - * need to call leave again, as it has already been called - * once. + /* Update the players stats once per tick. More efficient than + * sending them whenever they change, and probably just as useful */ - if (pl->socket.status == Ns_Dead) + esrv_update_stats (pl); + if (pl->last_weight != -1 && pl->last_weight != WEIGHT (pl->ob)) { - save_player (pl->ob, 0); - if (!QUERY_FLAG (pl->ob, FLAG_REMOVED)) - { - terminate_all_pets (pl->ob); - remove_ob (pl->ob); - } - leave (pl, 1); - final_free_player (pl); + esrv_update_item (UPD_WEIGHT, pl->ob, pl->ob); + if (pl->last_weight != WEIGHT (pl->ob)) + LOG (llevError, "esrv_update_item(UPD_WEIGHT) did not set player weight: is %lu, should be %lu\n", + (unsigned long) pl->last_weight, WEIGHT (pl->ob)); } - else - { - /* Update the players stats once per tick. More efficient than - * sending them whenever they change, and probably just as useful - */ - esrv_update_stats (pl); - if (pl->last_weight != -1 && pl->last_weight != WEIGHT (pl->ob)) - { - esrv_update_item (UPD_WEIGHT, pl->ob, pl->ob); - if (pl->last_weight != WEIGHT (pl->ob)) - LOG (llevError, "esrv_update_item(UPD_WEIGHT) did not set player weight: is %lu, should be %lu\n", - (unsigned long) pl->last_weight, WEIGHT (pl->ob)); - } - /* draw_client_map does sanity checking that map is - * valid, so don't do it here. - */ - draw_client_map (pl->ob); - if (pl->socket.update_look) - esrv_draw_look (pl->ob); - } + /* draw_client_map does sanity checking that map is + * valid, so don't do it here. + */ + draw_client_map (pl->ob); + if (pl->socket.update_look) + esrv_draw_look (pl->ob); } } } +