--- deliantra/server/socket/image.C 2007/03/12 23:45:10 1.26 +++ deliantra/server/socket/image.C 2007/05/28 21:22:26 1.42 @@ -1,25 +1,25 @@ /* - * CrossFire, A Multiplayer game - * - * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team - * Copyright (C) 2001 Mark Wedel - * 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 + * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. + * + * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team + * Copyright (©) 2001,2007 Mark Wedel + * Copyright (©) 1992,2007 Frank Tore Johansen + * + * Crossfire TRT 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 Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * The authors can be reached via e-mail to */ /** \file @@ -200,10 +200,7 @@ void SendFaceCmd (char *buf, int len, client *ns) { - uint16 facenum = atoi (buf); - - if (facenum != 0) - esrv_send_face (ns, facenum, 1); + ns->send_image (atoi (buf)); } // how lame @@ -213,10 +210,10 @@ sl.printf ("%02x", d.chksum [i]); } -// gcfclient uses the server-provided checksum for comparison, -// but always wrotes a broken checksum to its cache file, so we -// have to provide gcfclient with a useless checksum just to -// have to cache the image despite its bugs. +// gcfclient uses the server-provided checksum for comparison, but always +// writes a broken checksum to its cache file, so we have to provide +// gcfclient with the same broken (and useless) checksum just to have it +// cache the image despite its bugs. static uint32 gcfclient_checksum (const facedata *d) { uint32 csum = 0; @@ -241,48 +238,197 @@ * we look at the facecache, and if set, send the image name. */ void -esrv_send_face (client *ns, short face_num, int nocache) +client::send_face (faceidx facenum) { - if (face_num <= 0 || face_num >= faces.size ()) + // never send face 0. ever. it does not exist. + if (!facenum) + return; + + const facedata *d = face_data (facenum, faceset); + + if (!d) { - LOG (llevError, "esrv_send_face (%d) out of bounds??\n", face_num); + LOG (llevError, "client::send_face (%d) out of bounds??\n", facenum); return; } - const facedata *d = face_data (face_num, ns->faceset); + if (faces_sent[facenum]) + return; + + faces_sent[facenum] = true; + + // if for some reason we let a client without face caching connect, + // we better support that decision here and implement it. + if (!facecache) + return send_image (facenum); + + if (fxix) + { + fxface.push_back (facenum); + return; + } packet sl; - if (ns->facecache && !nocache) + if (force_face0) + sl << "face " << uint16 (facenum); + else if (image2) + sl << "face2 " << uint16 (facenum) << uint8 (0) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0); + else + sl << "face1 " << uint16 (facenum) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0); + + // how lame + print_facename (sl, *d); + send_packet (sl); + + if (EMI_smooth) { - if (ns->force_face0) - sl << "face " << uint16 (face_num); - else if (ns->image2) - sl << "face2 " << uint16 (face_num) << uint8 (0) << uint32 (ns->force_bad_checksum ? gcfclient_checksum (d) : 0); - else - sl << "face1 " << uint16 (face_num) << uint32 (ns->force_bad_checksum ? gcfclient_checksum (d) : 0); + faceinfo *f = face_info (facenum); - // how lame - print_facename (sl, *d); + if (f->smooth) + { + send_face (f->smooth); - ns->send_packet (sl); + packet sl ("smooth"); + + sl << uint16 (facenum) + << uint16 (f->smooth); + + send_packet (sl); + } } - else +} + +void client::flush_fx () +{ + while (!fxface.empty ()) { - fprintf (stderr, "image %s %d\n", &faces [face_num].name, nocache);//D - sl << (ns->image2 ? "image2 " : "image ") - << uint32 (face_num); + packet fx ("fx"); + packet sx ("sx"); - if (ns->image2) - sl << uint8 (0); + do + { + faceidx facenum = fxface.back (); fxface.pop_back (); - sl << uint32 (d->data.size ()) - << data (d->data.data (), d->data.size ()); + const facedata *d = face_data (facenum, faceset); - ns->send_packet (sl); + if (d) + { + fx << ber32 (facenum) + << data8 (d->chksum, CHKSUM_SIZE); + + if (smoothing) + { + faceinfo *f = face_info (facenum); + + if (f->smooth) + { + send_face (f->smooth); + sx << ber32 (facenum) + << ber32 (f->smooth) + << ber32 (f->smoothlevel); + } + } + } + } + while (!fxface.empty () + && fx.room () > ber32::size + CHKSUM_SIZE + 1 + && sx.room () > ber32::size * 3); + + send_packet (fx); + if (sx.length () > 3) send_packet (sx); + } +} + +void +client::send_image (faceidx facenum) +{ + // never send face 0. ever. it does not exist. + if (!facenum) + return; + + const facedata *d = face_data (facenum, faceset); + + if (!d) + { + LOG (llevError, "client::send_image (%d) out of bounds??\n", facenum); + return; + } + + faces_sent[facenum] = true; + + if (force_image_newmap) + force_newmap = true; + + packet sl; + + sl << (image2 ? "image2 " : "image ") + << uint32 (facenum); + + if (image2) + sl << uint8 (0); + + sl << uint32 (d->data.size ()) + << data (d->data.data (), d->data.size ()); + + send_packet (sl); +} + +// send all faces of this object to the client +// this uses more bandwidth initially, but makes +// animations look much smoother, and every client +// is supposed to do client-side caching anyways. +void +client::send_faces (object *ob) +{ + send_face (ob->face); + + if (ob->animation_id) + { + animation &anim = animations [ob->animation_id]; + + for (int i = 0; i < anim.num_animations; i++) + send_face (anim.faces [i]); } +} - ns->faces_sent[face_num] |= NS_FACESENT_FACE; +/** + * Need to send an animation sequence to the client. + * We will send appropriate face commands to the client if we haven't + * sent them the face yet (this can become quite costly in terms of + * how much we are sending - on the other hand, this should only happen + * when the player logs in and picks stuff up. + */ +void +client::send_animation (short anim_num) +{ + /* Do some checking on the anim_num we got. Note that the animations + * are added in contigous order, so if the number is in the valid + * range, it must be a valid animation. + */ + if (anim_num < 0 || anim_num >= animations.size ()) + { + LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num); + return; + } + + packet sl ("anim"); + + sl << uint16 (anim_num) + << uint16 (0); /* flags - not used right now */ + + /* Build up the list of faces. Also, send any information (ie, the + * the face itself) down to the client. + */ + for (int i = 0; i < animations[anim_num].num_animations; i++) + { + send_face (animations[anim_num].faces[i]); + sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ + } + + send_packet (sl); + + anims_sent[anim_num] = 1; } /** @@ -290,7 +436,6 @@ * and the image_info file information. See the doc/Developers/protocol * if you want further detail. */ - void send_image_info (client *ns, char *params) { @@ -339,7 +484,7 @@ for (int i = start; i <= stop && i < faces.size (); i++) { - ns->faces_sent[i] |= NS_FACESENT_FACE; + ns->faces_sent[i] = true; const facedata *d = face_data (i, ns->faceset);