--- deliantra/server/socket/item.C 2006/12/21 23:37:06 1.29 +++ deliantra/server/socket/item.C 2007/01/21 21:28:27 1.35 @@ -1,25 +1,26 @@ /* - CrossFire, A Multiplayer game for X-windows - - Copyright (C) 2002 Mark Wedel & Crossfire Development Team - Copyright (C) 1992 Frank Tore Johansen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - The author can be reached via e-mail to -*/ + * CrossFire, A Multiplayer game for X-windows + * + * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team + * Copyright (C) 2002 Mark Wedel & Crossfire Development Team + * Copyright (C) 1992 Frank Tore Johansen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * The author can be reached via e-mail to + */ /** * \file @@ -27,13 +28,13 @@ * * \date 2003-12-02 * - * This containes item logic for client/server. It doesn't contain + * This contains item logic for client/server. It doesn't contain * the actual commands that send the data, but does contain * the logic for what items should be sent. */ #include -#include /* LOOK_OBJ */ +#include #include /** This is the maximum number of bytes we expect any one item to take up */ @@ -305,12 +306,12 @@ anim_speed = head->anim_speed; else { - if (FABS (head->speed) < 0.001) + if (fabs (head->speed) < 0.001) anim_speed = 255; - else if (FABS (head->speed) >= 1.0) + else if (fabs (head->speed) >= 1.0) anim_speed = 1; else - anim_speed = (int) (1.0 / FABS (head->speed)); + anim_speed = (int) (1.0 / fabs (head->speed)); } if (anim_speed > 255) @@ -326,7 +327,6 @@ SET_FLAG (head, FLAG_CLIENT_SENT); } - /** * Send the look window. Don't need to do animations here * This sends all the faces to the client, not just updates. This is @@ -335,7 +335,6 @@ void esrv_draw_look (object *pl) { - object *tmp, *last; int got_one = 0, start_look = 0, end_look = 0; char buf[MAX_BUF]; @@ -353,9 +352,6 @@ || out_of_map (pl->map, pl->x, pl->y)) return; - for (tmp = GET_MAP_OB (pl->map, pl->x, pl->y); tmp && tmp->above; tmp = tmp->above) - ; - pl->contr->ns->send_packet ("delinv 0"); packet sl; @@ -384,7 +380,8 @@ sl << uint16 (0); } - for (last = NULL; tmp != last; tmp = tmp->below) + object *tmp = pl->ms ().top; + for (object *last = 0; tmp != last; tmp = tmp->below) { object *head; @@ -395,7 +392,7 @@ last = last->below; } - if (LOOK_OBJ (tmp)) + if (tmp->client_visible ()) { if (++start_look < pl->contr->ns->look_position) continue; @@ -453,9 +450,10 @@ void esrv_send_inventory (object *pl, object *op) { - object *tmp; - int got_one = 0; + if (!pl->contr->ns)//D + return; + int got_one = 0; pl->contr->ns->send_packet_printf ("delinv %d", op->count); @@ -464,7 +462,7 @@ sl << uint32 (op->count); - for (tmp = op->inv; tmp; tmp = tmp->below) + for (object *tmp = op->inv; tmp; tmp = tmp->below) { object *head; @@ -473,7 +471,7 @@ else head = tmp; - if (LOOK_OBJ (head)) + if (head->client_visible ()) { add_object_to_socklist (*pl->contr->ns, sl, head); @@ -492,7 +490,7 @@ sl << uint32 (op->count); got_one = 0; } - } /* If LOOK_OBJ() */ + } } if (got_one) @@ -513,7 +511,7 @@ /* If we have a request to send the player item, skip a few checks. */ if (op != pl) { - if (!LOOK_OBJ (op)) + if (!op->client_visible ()) return; /* we remove the check for op->env, because in theory, the object * is hopefully in the same place, so the client should preserve @@ -521,6 +519,10 @@ */ } + client *ns = pl->contr->ns; + if (!ns) + return; + if (!QUERY_FLAG (op, FLAG_CLIENT_SENT)) { /* FLAG_CLIENT_SENT is debug only. We are using it to see where @@ -552,13 +554,13 @@ sl << uint32 (QUERY_FLAG (op, FLAG_NO_PICK) ? -1 : weight); if (pl == op) - op->contr->last_weight = weight; + ns->last_weight = weight; } if (flags & UPD_FACE) { - if (!(pl->contr->ns->faces_sent[op->face->number] & NS_FACESENT_FACE)) - esrv_send_face (pl->contr->ns, op->face->number, 0); + if (!(ns->faces_sent[op->face->number] & NS_FACESENT_FACE)) + esrv_send_face (ns, op->face->number, 0); sl << uint32 (op->face->number); } @@ -604,12 +606,12 @@ anim_speed = op->anim_speed; else { - if (FABS (op->speed) < 0.001) + if (fabs (op->speed) < 0.001) anim_speed = 255; - else if (FABS (op->speed) >= 1.0) + else if (fabs (op->speed) >= 1.0) anim_speed = 1; else - anim_speed = (int) (1.0 / FABS (op->speed)); + anim_speed = (int) (1.0 / fabs (op->speed)); } if (anim_speed > 255) @@ -631,12 +633,16 @@ void esrv_send_item (object *pl, object *op) { + if (!pl->contr->ns) + return; + /* If this is not the player object, do some more checks */ if (op != pl) { /* We only send 'visibile' objects to the client */ - if (!LOOK_OBJ (op)) + if (!op->client_visible ()) return; + /* if the item is on the ground, mark that the look needs to * be updated. */ @@ -891,7 +897,7 @@ } dy = atoi (cp); - if (FABS (dx) > pl->ns->mapx / 2 || FABS (dy) > pl->ns->mapy / 2) + if (fabs (dx) > pl->ns->mapx / 2 || fabs (dy) > pl->ns->mapy / 2) return; if (pl->blocked_los[dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2])