… | |
… | |
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]) |
|
|
260 | return; |
|
|
261 | |
|
|
262 | faces_sent[facenum] = true; |
|
|
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); |
273 | send_packet (sl); |
|
|
274 | |
|
|
275 | faceinfo *f = face_info (facenum); |
|
|
276 | if (f->smooth && EMI_smooth) |
|
|
277 | { |
|
|
278 | send_face (f->smooth); |
|
|
279 | |
|
|
280 | packet sl ("smooth"); |
|
|
281 | |
|
|
282 | sl << uint16 (facenum) |
|
|
283 | << uint16 (f->smooth); |
|
|
284 | |
|
|
285 | send_packet (sl); |
|
|
286 | } |
251 | } |
287 | } |
252 | else |
288 | else |
253 | { |
289 | { |
254 | sl << (ns->image2 ? "image2 " : "image ") |
290 | sl << (image2 ? "image2 " : "image ") |
255 | << uint32 (face_num); |
291 | << uint32 (facenum); |
256 | |
292 | |
257 | if (ns->image2) |
293 | if (image2) |
258 | sl << uint8 (0); |
294 | sl << uint8 (0); |
259 | |
295 | |
260 | sl << uint32 (d->data.size ()) |
296 | sl << uint32 (d->data.size ()) |
261 | << data (d->data.data (), d->data.size ()); |
297 | << data (d->data.data (), d->data.size ()); |
262 | |
298 | |
263 | ns->send_packet (sl); |
299 | send_packet (sl); |
|
|
300 | } |
|
|
301 | } |
|
|
302 | |
|
|
303 | // send all faces of this object to the client |
|
|
304 | // this uses more bandwidth initially, but makes |
|
|
305 | // animations look much smoother, and every client |
|
|
306 | // is supposed to do client-side caching anyways. |
|
|
307 | void |
|
|
308 | client::send_faces (object *ob) |
|
|
309 | { |
|
|
310 | send_face (ob->face); |
|
|
311 | |
|
|
312 | if (ob->animation_id) |
264 | } |
313 | { |
|
|
314 | animation &anim = animations [ob->animation_id]; |
265 | |
315 | |
266 | ns->faces_sent[face_num] |= NS_FACESENT_FACE; |
316 | for (int i = 0; i < anim.num_animations; i++) |
|
|
317 | send_face (anim.faces [i]); |
|
|
318 | } |
|
|
319 | } |
|
|
320 | |
|
|
321 | /** |
|
|
322 | * Need to send an animation sequence to the client. |
|
|
323 | * We will send appropriate face commands to the client if we haven't |
|
|
324 | * sent them the face yet (this can become quite costly in terms of |
|
|
325 | * how much we are sending - on the other hand, this should only happen |
|
|
326 | * when the player logs in and picks stuff up. |
|
|
327 | */ |
|
|
328 | void |
|
|
329 | client::send_animation (short anim_num) |
|
|
330 | { |
|
|
331 | /* Do some checking on the anim_num we got. Note that the animations |
|
|
332 | * are added in contigous order, so if the number is in the valid |
|
|
333 | * range, it must be a valid animation. |
|
|
334 | */ |
|
|
335 | if (anim_num < 0 || anim_num > num_animations) |
|
|
336 | { |
|
|
337 | LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num); |
|
|
338 | return; |
|
|
339 | } |
|
|
340 | |
|
|
341 | packet sl ("anim"); |
|
|
342 | |
|
|
343 | sl << uint16 (anim_num) |
|
|
344 | << uint16 (0); /* flags - not used right now */ |
|
|
345 | |
|
|
346 | /* Build up the list of faces. Also, send any information (ie, the |
|
|
347 | * the face itself) down to the client. |
|
|
348 | */ |
|
|
349 | for (int i = 0; i < animations[anim_num].num_animations; i++) |
|
|
350 | { |
|
|
351 | send_face (animations[anim_num].faces[i]); |
|
|
352 | sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ |
|
|
353 | } |
|
|
354 | |
|
|
355 | send_packet (sl); |
|
|
356 | |
|
|
357 | anims_sent[anim_num] = 1; |
267 | } |
358 | } |
268 | |
359 | |
269 | /** |
360 | /** |
270 | * Sends the number of images, checksum of the face file, |
361 | * Sends the number of images, checksum of the face file, |
271 | * and the image_info file information. See the doc/Developers/protocol |
362 | * and the image_info file information. See the doc/Developers/protocol |
272 | * if you want further detail. |
363 | * if you want further detail. |
273 | */ |
364 | */ |
274 | |
|
|
275 | void |
365 | void |
276 | send_image_info (client *ns, char *params) |
366 | send_image_info (client *ns, char *params) |
277 | { |
367 | { |
278 | packet sl; |
368 | packet sl; |
279 | |
369 | |
… | |
… | |
318 | |
408 | |
319 | sl.printf ("replyinfo image_sums %d %d ", start, stop); |
409 | sl.printf ("replyinfo image_sums %d %d ", start, stop); |
320 | |
410 | |
321 | for (int i = start; i <= stop && i < faces.size (); i++) |
411 | for (int i = start; i <= stop && i < faces.size (); i++) |
322 | { |
412 | { |
323 | ns->faces_sent[i] |= NS_FACESENT_FACE; |
413 | ns->faces_sent[i] = true; |
324 | |
414 | |
325 | const facedata *d = face_data (i, ns->faceset); |
415 | const facedata *d = face_data (i, ns->faceset); |
326 | |
416 | |
327 | if (sl.room () < 2 + 4 + 1 + d->data.size () + 1) |
417 | if (sl.room () < 2 + 4 + 1 + d->data.size () + 1) |
328 | break; |
418 | break; |