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.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 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 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);
253 { 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
254 sl << (ns->image2 ? "image2 " : "image ") 348 sl << (image2 ? "image2 " : "image ")
255 << uint32 (face_num); 349 << uint32 (facenum);
256 350
257 if (ns->image2) 351 if (image2)
258 sl << uint8 (0); 352 sl << uint8 (0);
259 353
260 sl << uint32 (d->data.size ()) 354 sl << uint32 (d->data.size ())
261 << data (d->data.data (), d->data.size ()); 355 << data (d->data.data (), d->data.size ());
262 356
263 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)
264 } 370 {
371 animation &anim = animations [ob->animation_id];
265 372
266 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;
267} 415}
268 416
269/** 417/**
270 * Sends the number of images, checksum of the face file, 418 * Sends the number of images, checksum of the face file,
271 * and the image_info file information. See the doc/Developers/protocol 419 * and the image_info file information. See the doc/Developers/protocol
272 * if you want further detail. 420 * if you want further detail.
273 */ 421 */
274
275void 422void
276send_image_info (client *ns, char *params) 423send_image_info (client *ns, char *params)
277{ 424{
278 packet sl; 425 packet sl;
279 426
318 465
319 sl.printf ("replyinfo image_sums %d %d ", start, stop); 466 sl.printf ("replyinfo image_sums %d %d ", start, stop);
320 467
321 for (int i = start; i <= stop && i < faces.size (); i++) 468 for (int i = start; i <= stop && i < faces.size (); i++)
322 { 469 {
323 ns->faces_sent[i] |= NS_FACESENT_FACE; 470 ns->faces_sent[i] = true;
324 471
325 const facedata *d = face_data (i, ns->faceset); 472 const facedata *d = face_data (i, ns->faceset);
326 473
327 if (sl.room () < 2 + 4 + 1 + d->data.size () + 1) 474 if (sl.room () < 2 + 4 + 1 + d->data.size () + 1)
328 break; 475 break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines