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.39 by root, Tue Apr 3 00:21:38 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_image (atoi (buf));
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, but always
217 d.chksum [12], d.chksum [13], d.chksum [14], d.chksum [15]); 214// writes a broken checksum to its cache file, so we have to provide
215// gcfclient with the same broken (and useless) checksum just to have it
216// 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)
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); 255 if (faces_sent[facenum])
256 return;
257
258 faces_sent[facenum] = true;
259
260 // if for some reason we let a client without face caching connect,
261 // we better support that decision here and implement it.
262 if (!facecache)
263 return send_image (facenum);
264
265 if (fxix)
266 {
267 fxface.push_back (facenum);
268 return;
269 }
238 270
239 packet sl; 271 packet sl;
240 272
241 if (ns->facecache && !nocache) 273 if (force_face0)
242 { 274 sl << "face " << uint16 (facenum);
243 sl << (ns->image2 ? "face2 " : "face1 ") 275 else if (image2)
244 << uint16 (face_num); 276 sl << "face2 " << uint16 (facenum) << uint8 (0) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0);
245
246 if (ns->image2)
247 sl << uint8 (0);
248
249 sl << uint32 (0);
250
251 // how lame
252 print_facename (sl, *d);
253
254 ns->send_packet (sl);
255 }
256 else 277 else
278 sl << "face1 " << uint16 (facenum) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0);
279
280 // how lame
281 print_facename (sl, *d);
282 send_packet (sl);
283
284 faceinfo *f = face_info (facenum);
285 if (f->smooth && EMI_smooth)
286 {
287 send_face (f->smooth);
288
289 packet sl ("smooth");
290
291 sl << uint16 (facenum)
292 << uint16 (f->smooth);
293
294 send_packet (sl);
257 { 295 }
296}
297
298void client::flush_fx ()
299{
300 while (!fxface.empty ())
301 {
302 packet sl ("fx");
303
304 do
305 {
306 faceidx facenum = fxface.back (); fxface.pop_back ();
307
308 const facedata *d = face_data (facenum, faceset);
309
310 if (d)
311 {
312 sl << ber32 (facenum)
313 << data8 (d->chksum, CHKSUM_SIZE);
314
315 faceinfo *f = face_info (facenum);
316 if (f->smooth && EMI_smooth)
317 sl << ber32 (f->smooth);
318 }
319 }
320 while (!fxface.empty () && sl.room () > CHKSUM_SIZE + 8 + 8);
321
322 send_packet (sl);
323 }
324}
325
326void
327client::send_image (faceidx facenum)
328{
329 // never send face 0. ever. it does not exist.
330 if (!facenum)
331 return;
332
333 const facedata *d = face_data (facenum, faceset);
334
335 if (!d)
336 {
337 LOG (llevError, "client::send_image (%d) out of bounds??\n", facenum);
338 return;
339 }
340
341 faces_sent[facenum] = true;
342
343 if (force_image_newmap)
344 force_newmap = true;
345
346 packet sl;
347
258 sl << (ns->image2 ? "image2 " : "image ") 348 sl << (image2 ? "image2 " : "image ")
259 << uint32 (face_num); 349 << uint32 (facenum);
260 350
261 if (ns->image2) 351 if (image2)
262 sl << uint8 (0); 352 sl << uint8 (0);
263 353
264 sl << uint32 (d->data.size ()) 354 sl << uint32 (d->data.size ())
265 << data (d->data.data (), d->data.size ()); 355 << data (d->data.data (), d->data.size ());
266 356
267 ns->send_packet (sl); 357 send_packet (sl);
358}
359
360// send all faces of this object to the client
361// this uses more bandwidth initially, but makes
362// animations look much smoother, and every client
363// is supposed to do client-side caching anyways.
364void
365client::send_faces (object *ob)
366{
367 send_face (ob->face);
368
369 if (ob->animation_id)
268 } 370 {
371 animation &anim = animations [ob->animation_id];
269 372
270 ns->faces_sent[face_num] |= NS_FACESENT_FACE; 373 for (int i = 0; i < anim.num_animations; i++)
374 send_face (anim.faces [i]);
375 }
376}
377
378/**
379 * Need to send an animation sequence to the client.
380 * We will send appropriate face commands to the client if we haven't
381 * sent them the face yet (this can become quite costly in terms of
382 * how much we are sending - on the other hand, this should only happen
383 * when the player logs in and picks stuff up.
384 */
385void
386client::send_animation (short anim_num)
387{
388 /* Do some checking on the anim_num we got. Note that the animations
389 * are added in contigous order, so if the number is in the valid
390 * range, it must be a valid animation.
391 */
392 if (anim_num < 0 || anim_num > num_animations)
393 {
394 LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num);
395 return;
396 }
397
398 packet sl ("anim");
399
400 sl << uint16 (anim_num)
401 << uint16 (0); /* flags - not used right now */
402
403 /* Build up the list of faces. Also, send any information (ie, the
404 * the face itself) down to the client.
405 */
406 for (int i = 0; i < animations[anim_num].num_animations; i++)
407 {
408 send_face (animations[anim_num].faces[i]);
409 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */
410 }
411
412 send_packet (sl);
413
414 anims_sent[anim_num] = 1;
271} 415}
272 416
273/** 417/**
274 * Sends the number of images, checksum of the face file, 418 * Sends the number of images, checksum of the face file,
275 * and the image_info file information. See the doc/Developers/protocol 419 * and the image_info file information. See the doc/Developers/protocol
276 * if you want further detail. 420 * if you want further detail.
277 */ 421 */
278
279void 422void
280send_image_info (client *ns, char *params) 423send_image_info (client *ns, char *params)
281{ 424{
282 packet sl; 425 packet sl;
283 426
322 465
323 sl.printf ("replyinfo image_sums %d %d ", start, stop); 466 sl.printf ("replyinfo image_sums %d %d ", start, stop);
324 467
325 for (int i = start; i <= stop && i < faces.size (); i++) 468 for (int i = start; i <= stop && i < faces.size (); i++)
326 { 469 {
327 ns->faces_sent[i] |= NS_FACESENT_FACE; 470 ns->faces_sent[i] = true;
328 471
329 const facedata *d = face_data (i, ns->faceset); 472 const facedata *d = face_data (i, ns->faceset);
330 473
331 if (sl.room () < 2 + 4 + 1 + d->data.size () + 1) 474 if (sl.room () < 2 + 4 + 1 + d->data.size () + 1)
332 break; 475 break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines