… | |
… | |
198 | * caching images. |
198 | * caching images. |
199 | */ |
199 | */ |
200 | void |
200 | void |
201 | SendFaceCmd (char *buf, int len, client *ns) |
201 | SendFaceCmd (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 |
210 | static void print_facename (packet &sl, const facedata &d) |
207 | static 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. |
|
|
217 | static 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 | */ |
228 | void |
240 | void |
229 | esrv_send_face (client *ns, short face_num, int nocache) |
241 | client::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] & NS_FACESENT_FACE) |
|
|
260 | return; |
|
|
261 | |
|
|
262 | faces_sent[facenum] |= NS_FACESENT_FACE; |
|
|
263 | |
|
|
264 | if (force_face0) |
244 | << uint16 (face_num); |
265 | sl << "face " << uint16 (facenum); |
245 | |
|
|
246 | if (ns->image2) |
266 | else if (image2) |
247 | sl << uint8 (0); |
267 | sl << "face2 " << uint16 (facenum) << uint8 (0) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0); |
248 | |
268 | else |
249 | sl << uint32 (0); |
269 | sl << "face1 " << uint16 (facenum) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0); |
250 | |
270 | |
251 | // how lame |
271 | // how lame |
252 | print_facename (sl, *d); |
272 | print_facename (sl, *d); |
253 | |
|
|
254 | ns->send_packet (sl); |
|
|
255 | } |
273 | } |
256 | else |
274 | else |
257 | { |
275 | { |
|
|
276 | fprintf (stderr, "image %d\n", facenum);//D |
258 | sl << (ns->image2 ? "image2 " : "image ") |
277 | sl << (image2 ? "image2 " : "image ") |
259 | << uint32 (face_num); |
278 | << uint32 (facenum); |
260 | |
279 | |
261 | if (ns->image2) |
280 | if (image2) |
262 | sl << uint8 (0); |
281 | sl << uint8 (0); |
263 | |
282 | |
264 | sl << uint32 (d->data.size ()) |
283 | sl << uint32 (d->data.size ()) |
265 | << data (d->data.data (), d->data.size ()); |
284 | << data (d->data.data (), d->data.size ()); |
|
|
285 | } |
266 | |
286 | |
267 | ns->send_packet (sl); |
287 | send_packet (sl); |
|
|
288 | } |
|
|
289 | |
|
|
290 | // send all faces of this object to the client |
|
|
291 | // this uses more bandwidth initially, but makes |
|
|
292 | // animations look much smoother, and every client |
|
|
293 | // is supposed to do client-side caching anyways. |
|
|
294 | void |
|
|
295 | client::send_faces (object *ob) |
|
|
296 | { |
|
|
297 | send_face (ob->face); |
|
|
298 | |
|
|
299 | if (ob->animation_id) |
268 | } |
300 | { |
|
|
301 | animation &anim = animations [ob->animation_id]; |
269 | |
302 | |
|
|
303 | for (int i = 0; i < anim.num_animations; i++) |
|
|
304 | send_face (anim.faces [i]); |
|
|
305 | } |
|
|
306 | } |
|
|
307 | |
|
|
308 | /** |
|
|
309 | * A lot like the old AskSmooth (in fact, now called by AskSmooth). |
|
|
310 | * Basically, it makes no sense to wait for the client to request a |
|
|
311 | * a piece of data from us that we know the client wants. So |
|
|
312 | * if we know the client wants it, might as well push it to the |
|
|
313 | * client. |
|
|
314 | */ |
|
|
315 | void |
|
|
316 | client::send_smooth (faceidx face) |
|
|
317 | { |
|
|
318 | faceinfo *f = face_info (face); |
|
|
319 | |
|
|
320 | if (!f) |
|
|
321 | return; |
|
|
322 | |
|
|
323 | if (faces_sent[face] & NS_FACESENT_SMOOTH) |
|
|
324 | return; |
|
|
325 | |
270 | ns->faces_sent[face_num] |= NS_FACESENT_FACE; |
326 | faces_sent[face] |= NS_FACESENT_SMOOTH; |
|
|
327 | |
|
|
328 | /* If we can't find a face, return and set it so we won't try to send this |
|
|
329 | * again. |
|
|
330 | */ |
|
|
331 | if (!f->smooth) |
|
|
332 | { |
|
|
333 | LOG (llevError, "could not findsmooth for %d.\n", face); |
|
|
334 | return; |
|
|
335 | } |
|
|
336 | |
|
|
337 | send_face (f->smooth); |
|
|
338 | |
|
|
339 | packet sl ("smooth"); |
|
|
340 | |
|
|
341 | sl << uint16 (face) |
|
|
342 | << uint16 (f->smooth); |
|
|
343 | |
|
|
344 | send_packet (sl); |
|
|
345 | } |
|
|
346 | |
|
|
347 | /** |
|
|
348 | * Need to send an animation sequence to the client. |
|
|
349 | * We will send appropriate face commands to the client if we haven't |
|
|
350 | * sent them the face yet (this can become quite costly in terms of |
|
|
351 | * how much we are sending - on the other hand, this should only happen |
|
|
352 | * when the player logs in and picks stuff up. |
|
|
353 | */ |
|
|
354 | void |
|
|
355 | client::send_animation (short anim_num) |
|
|
356 | { |
|
|
357 | /* Do some checking on the anim_num we got. Note that the animations |
|
|
358 | * are added in contigous order, so if the number is in the valid |
|
|
359 | * range, it must be a valid animation. |
|
|
360 | */ |
|
|
361 | if (anim_num < 0 || anim_num > num_animations) |
|
|
362 | { |
|
|
363 | LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num); |
|
|
364 | return; |
|
|
365 | } |
|
|
366 | |
|
|
367 | packet sl ("anim"); |
|
|
368 | |
|
|
369 | sl << uint16 (anim_num) |
|
|
370 | << uint16 (0); /* flags - not used right now */ |
|
|
371 | |
|
|
372 | /* Build up the list of faces. Also, send any information (ie, the |
|
|
373 | * the face itself) down to the client. |
|
|
374 | */ |
|
|
375 | for (int i = 0; i < animations[anim_num].num_animations; i++) |
|
|
376 | { |
|
|
377 | send_face (animations[anim_num].faces[i]); |
|
|
378 | sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ |
|
|
379 | } |
|
|
380 | |
|
|
381 | send_packet (sl); |
|
|
382 | |
|
|
383 | anims_sent[anim_num] = 1; |
271 | } |
384 | } |
272 | |
385 | |
273 | /** |
386 | /** |
274 | * Sends the number of images, checksum of the face file, |
387 | * Sends the number of images, checksum of the face file, |
275 | * and the image_info file information. See the doc/Developers/protocol |
388 | * and the image_info file information. See the doc/Developers/protocol |
276 | * if you want further detail. |
389 | * if you want further detail. |
277 | */ |
390 | */ |
278 | |
|
|
279 | void |
391 | void |
280 | send_image_info (client *ns, char *params) |
392 | send_image_info (client *ns, char *params) |
281 | { |
393 | { |
282 | packet sl; |
394 | packet sl; |
283 | |
395 | |