--- deliantra/server/socket/image.C 2007/03/14 01:19:10 1.30 +++ deliantra/server/socket/image.C 2007/07/01 04:08:14 1.43 @@ -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 @@ -193,14 +193,46 @@ } /** - * Client has requested pixmap that it somehow missed getting. - * This will be called often if the client is - * caching images. + * client requested an image. send it rate-limited + * before flushing. + */ +void +AskFaceCmd (char *buf, int len, client *ns) +{ + int idx = 0, pri = 0; + + sscanf (buf, "%d %d", &idx, &pri); + + const facedata *d = face_data (idx, ns->faceset); + + if (!d) + return; // doh + + client::ixsend ix; + + ix.pri = pri; + ix.idx = idx; + ix.ofs = d->data.size (); + + // the by far most common case will be to insert + // right at the end, so no looping. + auto (i, ns->ixface.end ()); + for (; i != ns->ixface.begin (); ) + if (pri >= (--i)->pri) + break; + + ns->ixface.insert (i, ix); +} + +/** + * Tells client the picture it has to use + * to smooth a picture number given as argument. */ void -SendFaceCmd (char *buf, int len, client *ns) +AskSmooth (char *buf, int len, client *ns) { - ns->send_face (atoi (buf), 1); + ns->send_face (atoi (buf)); + ns->flush_fx (); } // how lame @@ -210,10 +242,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; @@ -238,7 +270,7 @@ * we look at the facecache, and if set, send the image name. */ void -client::send_face (faceidx facenum, bool forced) +client::send_face (faceidx facenum) { // never send face 0. ever. it does not exist. if (!facenum) @@ -252,17 +284,40 @@ return; } - packet sl; + if (faces_sent[facenum]) + return; + + faces_sent[facenum] = true; - if (facecache && !forced) + // 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) { - if (faces_sent[facenum]) - return; + fxface.push_back (facenum); + return; + } + + packet sl; - faces_sent[facenum] = true; + 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) + { faceinfo *f = face_info (facenum); - if (f->smooth && EMI_smooth) + + if (f->smooth) { send_face (f->smooth); @@ -273,28 +328,82 @@ send_packet (sl); } + } +} + +void client::flush_fx () +{ + while (!fxface.empty ()) + { + packet fx ("fx"); + packet sx ("sx"); + + do + { + faceidx facenum = fxface.back (); fxface.pop_back (); - 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); + const facedata *d = face_data (facenum, faceset); - // how lame - print_facename (sl, *d); + 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); } - else - { - sl << (image2 ? "image2 " : "image ") - << uint32 (facenum); +} + +void +client::send_image (faceidx facenum) +{ + // never send face 0. ever. it does not exist. + if (!facenum) + return; - if (image2) - sl << uint8 (0); + const facedata *d = face_data (facenum, faceset); + + faces_sent[facenum] = true; - sl << uint32 (d->data.size ()) - << data (d->data.data (), d->data.size ()); + if (!d) + { + LOG (llevError, "client::send_image (%d) out of bounds??\n", facenum); + return; } + + //TODO: check type here? + + 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); } @@ -331,7 +440,7 @@ * 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 > num_animations) + if (anim_num < 0 || anim_num >= animations.size ()) { LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num); return;