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