ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/image.C
(Generate patch)

Comparing deliantra/server/socket/image.C (file contents):
Revision 1.24 by root, Sun Mar 11 02:12:45 2007 UTC vs.
Revision 1.30 by root, Wed Mar 14 01:19:10 2007 UTC

198 * caching images. 198 * caching images.
199 */ 199 */
200void 200void
201SendFaceCmd (char *buf, int len, client *ns) 201SendFaceCmd (char *buf, int len, client *ns)
202{ 202{
203 uint16 facenum = atoi (buf); 203 ns->send_face (atoi (buf), 1);
204
205 if (facenum != 0)
206 esrv_send_face (ns, facenum, 1);
207} 204}
208 205
209// how lame 206// how lame
210static void print_facename (packet &sl, const facedata &d) 207static void print_facename (packet &sl, const facedata &d)
211{ 208{
212 sl.printf ("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" 209 for (int i = 0; i < CHKSUM_SIZE; ++i)
213 "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", 210 sl.printf ("%02x", d.chksum [i]);
214 d.chksum [ 0], d.chksum [ 1], d.chksum [ 2], d.chksum [ 3], 211}
215 d.chksum [ 4], d.chksum [ 5], d.chksum [ 6], d.chksum [ 7], 212
216 d.chksum [ 8], d.chksum [ 9], d.chksum [10], d.chksum [11], 213// gcfclient uses the server-provided checksum for comparison,
217 d.chksum [12], d.chksum [13], d.chksum [14], d.chksum [15]); 214// but always wrotes a broken checksum to its cache file, so we
215// have to provide gcfclient with a useless checksum just to
216// have to cache the image despite its bugs.
217static uint32 gcfclient_checksum (const facedata *d)
218{
219 uint32 csum = 0;
220
221 for (std::string::const_iterator i = d->data.begin ();
222 i != d->data.end ();
223 ++i)
224 {
225 csum = rotate_right (csum);
226 csum += *(uint8 *)&*i;
227 }
228
229 return csum;
218} 230}
219 231
220/** 232/**
221 * Sends a face to a client if they are in pixmap mode 233 * Sends a face to a client if they are in pixmap mode
222 * nothing gets sent in bitmap mode. 234 * nothing gets sent in bitmap mode.
224 * this is needed for the askface, in which we really do want to send the 236 * this is needed for the askface, in which we really do want to send the
225 * face (and askface is the only place that should be setting it). Otherwise, 237 * face (and askface is the only place that should be setting it). Otherwise,
226 * we look at the facecache, and if set, send the image name. 238 * we look at the facecache, and if set, send the image name.
227 */ 239 */
228void 240void
229esrv_send_face (client *ns, short face_num, int nocache) 241client::send_face (faceidx facenum, bool forced)
230{ 242{
231 if (face_num <= 0 || face_num >= faces.size ()) 243 // never send face 0. ever. it does not exist.
244 if (!facenum)
245 return;
246
247 const facedata *d = face_data (facenum, faceset);
248
249 if (!d)
232 { 250 {
233 LOG (llevError, "esrv_send_face (%d) out of bounds??\n", face_num); 251 LOG (llevError, "client::send_face (%d) out of bounds??\n", facenum);
234 return; 252 return;
235 } 253 }
236 254
237 const facedata *d = face_data (face_num, ns->faceset);
238
239 packet sl; 255 packet sl;
240 256
241 if (ns->facecache && !nocache) 257 if (facecache && !forced)
242 { 258 {
243 sl << (ns->image2 ? "face2 " : "face1 ") 259 if (faces_sent[facenum])
260 return;
261
262 faces_sent[facenum] = true;
263
264 faceinfo *f = face_info (facenum);
265 if (f->smooth && EMI_smooth)
266 {
267 send_face (f->smooth);
268
269 packet sl ("smooth");
270
244 << uint16 (face_num); 271 sl << uint16 (facenum)
272 << uint16 (f->smooth);
245 273
274 send_packet (sl);
275 }
276
277 if (force_face0)
278 sl << "face " << uint16 (facenum);
246 if (ns->image2) 279 else if (image2)
247 sl << uint8 (0); 280 sl << "face2 " << uint16 (facenum) << uint8 (0) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0);
248 281 else
249 sl << uint32 (0); 282 sl << "face1 " << uint16 (facenum) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0);
250 283
251 // how lame 284 // how lame
252 print_facename (sl, *d); 285 print_facename (sl, *d);
253
254 ns->send_packet (sl);
255 } 286 }
256 else 287 else
257 { 288 {
258 sl << (ns->image2 ? "image2 " : "image ") 289 sl << (image2 ? "image2 " : "image ")
259 << uint32 (face_num); 290 << uint32 (facenum);
260 291
261 if (ns->image2) 292 if (image2)
262 sl << uint8 (0); 293 sl << uint8 (0);
263 294
264 sl << uint32 (d->data.size ()) 295 sl << uint32 (d->data.size ())
265 << data (d->data.data (), d->data.size ()); 296 << data (d->data.data (), d->data.size ());
297 }
266 298
267 ns->send_packet (sl); 299 send_packet (sl);
300}
301
302// send all faces of this object to the client
303// this uses more bandwidth initially, but makes
304// animations look much smoother, and every client
305// is supposed to do client-side caching anyways.
306void
307client::send_faces (object *ob)
308{
309 send_face (ob->face);
310
311 if (ob->animation_id)
268 } 312 {
313 animation &anim = animations [ob->animation_id];
269 314
270 ns->faces_sent[face_num] |= NS_FACESENT_FACE; 315 for (int i = 0; i < anim.num_animations; i++)
316 send_face (anim.faces [i]);
317 }
318}
319
320/**
321 * Need to send an animation sequence to the client.
322 * We will send appropriate face commands to the client if we haven't
323 * sent them the face yet (this can become quite costly in terms of
324 * how much we are sending - on the other hand, this should only happen
325 * when the player logs in and picks stuff up.
326 */
327void
328client::send_animation (short anim_num)
329{
330 /* Do some checking on the anim_num we got. Note that the animations
331 * are added in contigous order, so if the number is in the valid
332 * range, it must be a valid animation.
333 */
334 if (anim_num < 0 || anim_num > num_animations)
335 {
336 LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num);
337 return;
338 }
339
340 packet sl ("anim");
341
342 sl << uint16 (anim_num)
343 << uint16 (0); /* flags - not used right now */
344
345 /* Build up the list of faces. Also, send any information (ie, the
346 * the face itself) down to the client.
347 */
348 for (int i = 0; i < animations[anim_num].num_animations; i++)
349 {
350 send_face (animations[anim_num].faces[i]);
351 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */
352 }
353
354 send_packet (sl);
355
356 anims_sent[anim_num] = 1;
271} 357}
272 358
273/** 359/**
274 * Sends the number of images, checksum of the face file, 360 * Sends the number of images, checksum of the face file,
275 * and the image_info file information. See the doc/Developers/protocol 361 * and the image_info file information. See the doc/Developers/protocol
276 * if you want further detail. 362 * if you want further detail.
277 */ 363 */
278
279void 364void
280send_image_info (client *ns, char *params) 365send_image_info (client *ns, char *params)
281{ 366{
282 packet sl; 367 packet sl;
283 368
322 407
323 sl.printf ("replyinfo image_sums %d %d ", start, stop); 408 sl.printf ("replyinfo image_sums %d %d ", start, stop);
324 409
325 for (int i = start; i <= stop && i < faces.size (); i++) 410 for (int i = start; i <= stop && i < faces.size (); i++)
326 { 411 {
327 ns->faces_sent[i] |= NS_FACESENT_FACE; 412 ns->faces_sent[i] = true;
328 413
329 const facedata *d = face_data (i, ns->faceset); 414 const facedata *d = face_data (i, ns->faceset);
330 415
331 if (sl.room () < 2 + 4 + 1 + d->data.size () + 1) 416 if (sl.room () < 2 + 4 + 1 + d->data.size () + 1)
332 break; 417 break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines