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.25 by root, Sun Mar 11 20:25:37 2007 UTC vs.
Revision 1.41 by root, Thu Apr 12 14:18:06 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 for (int i = 0; i < CHKSUM_SIZE; ++i) 209 for (int i = 0; i < CHKSUM_SIZE; ++i)
213 sl.printf ("%02x", d.chksum [i]); 210 sl.printf ("%02x", d.chksum [i]);
211}
212
213// gcfclient uses the server-provided checksum for comparison, but always
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;
214} 230}
215 231
216/** 232/**
217 * 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
218 * nothing gets sent in bitmap mode. 234 * nothing gets sent in bitmap mode.
220 * 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
221 * 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,
222 * 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.
223 */ 239 */
224void 240void
225esrv_send_face (client *ns, short face_num, int nocache) 241client::send_face (faceidx facenum)
226{ 242{
227 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)
228 { 250 {
229 LOG (llevError, "esrv_send_face (%d) out of bounds??\n", face_num); 251 LOG (llevError, "client::send_face (%d) out of bounds??\n", facenum);
230 return; 252 return;
231 } 253 }
232 254
233 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 }
234 270
235 packet sl; 271 packet sl;
236 272
237 if (ns->facecache && !nocache) 273 if (force_face0)
238 { 274 sl << "face " << uint16 (facenum);
239 sl << (ns->image2 ? "face2 " : "face1 ") 275 else if (image2)
240 << uint16 (face_num); 276 sl << "face2 " << uint16 (facenum) << uint8 (0) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0);
241
242 if (ns->image2)
243 sl << uint8 (0);
244
245 sl << uint32 (0);
246
247 // how lame
248 print_facename (sl, *d);
249
250 ns->send_packet (sl);
251 }
252 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 if (EMI_smooth)
285 {
286 faceinfo *f = face_info (facenum);
287
288 if (f->smooth)
289 {
290 send_face (f->smooth);
291
292 packet sl ("smooth");
293
294 sl << uint16 (facenum)
295 << uint16 (f->smooth);
296
297 send_packet (sl);
298 }
253 { 299 }
300}
301
302void client::flush_fx ()
303{
304 while (!fxface.empty ())
305 {
306 packet fx ("fx");
307 packet sx ("sx");
308
309 do
310 {
311 faceidx facenum = fxface.back (); fxface.pop_back ();
312
313 const facedata *d = face_data (facenum, faceset);
314
315 if (d)
316 {
317 fx << ber32 (facenum)
318 << data8 (d->chksum, CHKSUM_SIZE);
319
320 if (smoothing)
321 {
322 faceinfo *f = face_info (facenum);
323
324 if (f->smooth)
325 {
326 send_face (f->smooth);
327 sx << ber32 (facenum)
328 << ber32 (f->smooth)
329 << ber32 (f->smoothlevel);
330 }
331 }
332 }
333 }
334 while (!fxface.empty ()
335 && fx.room () > ber32::size + CHKSUM_SIZE + 1
336 && sx.room () > ber32::size * 3);
337
338 send_packet (fx);
339 if (sx.length () > 3) send_packet (sx);
340 }
341}
342
343void
344client::send_image (faceidx facenum)
345{
346 // never send face 0. ever. it does not exist.
347 if (!facenum)
348 return;
349
350 const facedata *d = face_data (facenum, faceset);
351
352 if (!d)
353 {
354 LOG (llevError, "client::send_image (%d) out of bounds??\n", facenum);
355 return;
356 }
357
358 faces_sent[facenum] = true;
359
360 if (force_image_newmap)
361 force_newmap = true;
362
363 packet sl;
364
254 sl << (ns->image2 ? "image2 " : "image ") 365 sl << (image2 ? "image2 " : "image ")
255 << uint32 (face_num); 366 << uint32 (facenum);
256 367
257 if (ns->image2) 368 if (image2)
258 sl << uint8 (0); 369 sl << uint8 (0);
259 370
260 sl << uint32 (d->data.size ()) 371 sl << uint32 (d->data.size ())
261 << data (d->data.data (), d->data.size ()); 372 << data (d->data.data (), d->data.size ());
262 373
263 ns->send_packet (sl); 374 send_packet (sl);
375}
376
377// send all faces of this object to the client
378// this uses more bandwidth initially, but makes
379// animations look much smoother, and every client
380// is supposed to do client-side caching anyways.
381void
382client::send_faces (object *ob)
383{
384 send_face (ob->face);
385
386 if (ob->animation_id)
264 } 387 {
388 animation &anim = animations [ob->animation_id];
265 389
266 ns->faces_sent[face_num] |= NS_FACESENT_FACE; 390 for (int i = 0; i < anim.num_animations; i++)
391 send_face (anim.faces [i]);
392 }
393}
394
395/**
396 * Need to send an animation sequence to the client.
397 * We will send appropriate face commands to the client if we haven't
398 * sent them the face yet (this can become quite costly in terms of
399 * how much we are sending - on the other hand, this should only happen
400 * when the player logs in and picks stuff up.
401 */
402void
403client::send_animation (short anim_num)
404{
405 /* Do some checking on the anim_num we got. Note that the animations
406 * are added in contigous order, so if the number is in the valid
407 * range, it must be a valid animation.
408 */
409 if (anim_num < 0 || anim_num >= animations.size ())
410 {
411 LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num);
412 return;
413 }
414
415 packet sl ("anim");
416
417 sl << uint16 (anim_num)
418 << uint16 (0); /* flags - not used right now */
419
420 /* Build up the list of faces. Also, send any information (ie, the
421 * the face itself) down to the client.
422 */
423 for (int i = 0; i < animations[anim_num].num_animations; i++)
424 {
425 send_face (animations[anim_num].faces[i]);
426 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */
427 }
428
429 send_packet (sl);
430
431 anims_sent[anim_num] = 1;
267} 432}
268 433
269/** 434/**
270 * Sends the number of images, checksum of the face file, 435 * Sends the number of images, checksum of the face file,
271 * and the image_info file information. See the doc/Developers/protocol 436 * and the image_info file information. See the doc/Developers/protocol
272 * if you want further detail. 437 * if you want further detail.
273 */ 438 */
274
275void 439void
276send_image_info (client *ns, char *params) 440send_image_info (client *ns, char *params)
277{ 441{
278 packet sl; 442 packet sl;
279 443
318 482
319 sl.printf ("replyinfo image_sums %d %d ", start, stop); 483 sl.printf ("replyinfo image_sums %d %d ", start, stop);
320 484
321 for (int i = start; i <= stop && i < faces.size (); i++) 485 for (int i = start; i <= stop && i < faces.size (); i++)
322 { 486 {
323 ns->faces_sent[i] |= NS_FACESENT_FACE; 487 ns->faces_sent[i] = true;
324 488
325 const facedata *d = face_data (i, ns->faceset); 489 const facedata *d = face_data (i, ns->faceset);
326 490
327 if (sl.room () < 2 + 4 + 1 + d->data.size () + 1) 491 if (sl.room () < 2 + 4 + 1 + d->data.size () + 1)
328 break; 492 break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines