… | |
… | |
33 | */ |
33 | */ |
34 | |
34 | |
35 | #include <global.h> |
35 | #include <global.h> |
36 | #include <sproto.h> |
36 | #include <sproto.h> |
37 | |
37 | |
38 | #include <newclient.h> |
|
|
39 | #include <newserver.h> |
|
|
40 | #include <loader.h> |
|
|
41 | |
|
|
42 | #define MAX_FACE_SETS 20 /**< Maximum number of image sets the program will handle */ |
38 | #define MAX_FACE_SETS 20 /**< Maximum number of image sets the program will handle */ |
43 | |
39 | |
44 | /** Information about one image */ |
40 | /** Information about one image */ |
45 | typedef struct FaceInfo |
41 | typedef struct FaceInfo |
46 | { |
42 | { |
47 | |
|
|
48 | uint8 *data; /**< image data */ |
43 | uint8 *data; /**< image data */ |
49 | |
|
|
50 | uint16 datalen; /**< length of the xpm data */ |
44 | uint16 datalen; /**< length of the xpm data */ |
51 | |
|
|
52 | uint32 checksum; /**< Checksum of face data */ |
45 | uint32 checksum; /**< Checksum of face data */ |
53 | } FaceInfo; |
46 | } FaceInfo; |
54 | |
47 | |
55 | /** Information about one face set */ |
48 | /** Information about one face set */ |
56 | typedef struct |
49 | typedef struct |
57 | { |
50 | { |
58 | |
|
|
59 | char *prefix; /**< */ |
51 | char *prefix; /**< */ |
60 | char *fullname; |
52 | char *fullname; |
61 | |
53 | |
62 | uint8 fallback; /**< faceset to use when an image is not found in this faceset */ |
54 | uint8 fallback; /**< faceset to use when an image is not found in this faceset */ |
63 | char *size; |
55 | char *size; |
… | |
… | |
94 | if (facesets[num].prefix) |
86 | if (facesets[num].prefix) |
95 | { |
87 | { |
96 | for (q = 0; q < nrofpixmaps; q++) |
88 | for (q = 0; q < nrofpixmaps; q++) |
97 | if (facesets[num].faces[q].data) |
89 | if (facesets[num].faces[q].data) |
98 | free (facesets[num].faces[q].data); |
90 | free (facesets[num].faces[q].data); |
|
|
91 | |
99 | free (facesets[num].prefix); |
92 | free (facesets[num].prefix); |
100 | free (facesets[num].fullname); |
93 | free (facesets[num].fullname); |
101 | free (facesets[num].size); |
94 | free (facesets[num].size); |
102 | free (facesets[num].extension); |
95 | free (facesets[num].extension); |
103 | free (facesets[num].comment); |
96 | free (facesets[num].comment); |
… | |
… | |
133 | if (!facesets[faceset].prefix) |
126 | if (!facesets[faceset].prefix) |
134 | { |
127 | { |
135 | LOG (llevError, "get_face_fallback called with unused set (%d)?\n", faceset); |
128 | LOG (llevError, "get_face_fallback called with unused set (%d)?\n", faceset); |
136 | return 0; /* use default set */ |
129 | return 0; /* use default set */ |
137 | } |
130 | } |
|
|
131 | |
138 | if (facesets[faceset].faces[imageno].data) |
132 | if (facesets[faceset].faces[imageno].data) |
139 | return faceset; |
133 | return faceset; |
|
|
134 | |
140 | return get_face_fallback (facesets[faceset].fallback, imageno); |
135 | return get_face_fallback (facesets[faceset].fallback, imageno); |
141 | } |
136 | } |
142 | |
137 | |
143 | /** |
138 | /** |
144 | * Checks fallback are correctly defined. |
139 | * Checks fallback are correctly defined. |
… | |
… | |
160 | if (!facesets[fallback].prefix) |
155 | if (!facesets[fallback].prefix) |
161 | { |
156 | { |
162 | LOG (llevError, "Face set %d falls to non set faceset %d\n", faceset, fallback); |
157 | LOG (llevError, "Face set %d falls to non set faceset %d\n", faceset, fallback); |
163 | abort (); |
158 | abort (); |
164 | } |
159 | } |
|
|
160 | |
165 | togo--; |
161 | togo--; |
166 | if (togo == 0) |
162 | if (togo == 0) |
167 | { |
163 | { |
168 | LOG (llevError, "Infinite loop found in facesets. aborting.\n"); |
164 | LOG (llevError, "Infinite loop found in facesets. aborting.\n"); |
169 | abort (); |
165 | abort (); |
170 | } |
166 | } |
|
|
167 | |
171 | check_faceset_fallback (fallback, togo); |
168 | check_faceset_fallback (fallback, togo); |
172 | } |
169 | } |
173 | |
170 | |
174 | #define MAX_IMAGE_SIZE 10000 |
171 | #define MAX_IMAGE_SIZE 10000 |
175 | |
172 | |
… | |
… | |
187 | * Function largely rewritten May 2000 to be more general purpose. |
184 | * Function largely rewritten May 2000 to be more general purpose. |
188 | * The server itself does not care what the image data is - to the server, |
185 | * The server itself does not care what the image data is - to the server, |
189 | * it is just data it needs to allocate. As such, the code is written |
186 | * it is just data it needs to allocate. As such, the code is written |
190 | * to do such. |
187 | * to do such. |
191 | */ |
188 | */ |
192 | |
|
|
193 | void |
189 | void |
194 | read_client_images (void) |
190 | read_client_images (void) |
195 | { |
191 | { |
196 | char filename[400]; |
192 | char filename[400]; |
197 | char buf[HUGE_BUF]; |
193 | char buf[HUGE_BUF]; |
… | |
… | |
204 | if ((infile = open_and_uncompress (filename, 0, &compressed)) == NULL) |
200 | if ((infile = open_and_uncompress (filename, 0, &compressed)) == NULL) |
205 | { |
201 | { |
206 | LOG (llevError, "Unable to open %s\n", filename); |
202 | LOG (llevError, "Unable to open %s\n", filename); |
207 | abort (); |
203 | abort (); |
208 | } |
204 | } |
|
|
205 | |
209 | while (fgets (buf, HUGE_BUF - 1, infile) != NULL) |
206 | while (fgets (buf, HUGE_BUF - 1, infile) != NULL) |
210 | { |
207 | { |
211 | badline = 0; |
208 | badline = 0; |
212 | |
209 | |
213 | if (buf[0] == '#') |
210 | if (buf[0] == '#') |
214 | continue; |
211 | continue; |
|
|
212 | |
215 | if (!(cps[0] = strtok (buf, ":"))) |
213 | if (!(cps[0] = strtok (buf, ":"))) |
216 | badline = 1; |
214 | badline = 1; |
|
|
215 | |
217 | for (i = 1; i < 7; i++) |
216 | for (i = 1; i < 7; i++) |
218 | { |
|
|
219 | if (!(cps[i] = strtok (NULL, ":"))) |
217 | if (!(cps[i] = strtok (NULL, ":"))) |
220 | badline = 1; |
218 | badline = 1; |
221 | } |
219 | |
222 | if (badline) |
220 | if (badline) |
223 | { |
|
|
224 | LOG (llevError, "Bad line in image_info file, ignoring line:\n %s", buf); |
221 | LOG (llevError, "Bad line in image_info file, ignoring line:\n %s", buf); |
225 | } |
|
|
226 | else |
222 | else |
227 | { |
223 | { |
228 | len = atoi (cps[0]); |
224 | len = atoi (cps[0]); |
229 | if (len >= MAX_FACE_SETS) |
225 | if (len >= MAX_FACE_SETS) |
230 | { |
226 | { |
231 | LOG (llevError, "To high a setnum in image_info file: %d > %d\n", len, MAX_FACE_SETS); |
227 | LOG (llevError, "To high a setnum in image_info file: %d > %d\n", len, MAX_FACE_SETS); |
232 | abort (); |
228 | abort (); |
233 | } |
229 | } |
234 | facesets[len].prefix = strdup_local (cps[1]); |
230 | facesets[len].prefix = strdup (cps[1]); |
235 | facesets[len].fullname = strdup_local (cps[2]); |
231 | facesets[len].fullname = strdup (cps[2]); |
236 | facesets[len].fallback = atoi (cps[3]); |
232 | facesets[len].fallback = atoi (cps[3]); |
237 | facesets[len].size = strdup_local (cps[4]); |
233 | facesets[len].size = strdup (cps[4]); |
238 | facesets[len].extension = strdup_local (cps[5]); |
234 | facesets[len].extension = strdup (cps[5]); |
239 | facesets[len].comment = strdup_local (cps[6]); |
235 | facesets[len].comment = strdup (cps[6]); |
240 | } |
236 | } |
241 | } |
237 | } |
|
|
238 | |
242 | close_and_delete (infile, compressed); |
239 | close_and_delete (infile, compressed); |
|
|
240 | |
243 | for (i = 0; i < MAX_FACE_SETS; i++) |
241 | for (i = 0; i < MAX_FACE_SETS; i++) |
244 | { |
242 | { |
245 | if (facesets[i].prefix) |
243 | if (facesets[i].prefix) |
246 | check_faceset_fallback (i, MAX_FACE_SETS); |
244 | check_faceset_fallback (i, MAX_FACE_SETS); |
247 | } |
245 | } |
|
|
246 | |
248 | /* Loaded the faceset information - now need to load up the |
247 | /* Loaded the faceset information - now need to load up the |
249 | * actual faces. |
248 | * actual faces. |
250 | */ |
249 | */ |
251 | |
250 | |
252 | for (fileno = 0; fileno < MAX_FACE_SETS; fileno++) |
251 | for (fileno = 0; fileno < MAX_FACE_SETS; fileno++) |
253 | { |
252 | { |
254 | /* if prefix is not set, this is not used */ |
253 | /* if prefix is not set, this is not used */ |
255 | if (!facesets[fileno].prefix) |
254 | if (!facesets[fileno].prefix) |
256 | continue; |
255 | continue; |
|
|
256 | |
257 | facesets[fileno].faces = (FaceInfo *) calloc (nrofpixmaps, sizeof (FaceInfo)); |
257 | facesets[fileno].faces = (FaceInfo *) calloc (nrofpixmaps, sizeof (FaceInfo)); |
258 | |
258 | |
259 | sprintf (filename, "%s/crossfire.%d", settings.datadir, fileno); |
259 | sprintf (filename, "%s/crossfire.%d", settings.datadir, fileno); |
260 | LOG (llevDebug, "Loading image file %s\n", filename); |
260 | LOG (llevDebug, "Loading image file %s\n", filename); |
261 | |
261 | |
262 | if ((infile = open_and_uncompress (filename, 0, &compressed)) == NULL) |
262 | if ((infile = open_and_uncompress (filename, 0, &compressed)) == NULL) |
263 | { |
263 | { |
264 | LOG (llevError, "Unable to open %s\n", filename); |
264 | LOG (llevError, "Unable to open %s\n", filename); |
265 | abort (); |
265 | abort (); |
266 | } |
266 | } |
|
|
267 | |
267 | while (fgets (buf, HUGE_BUF - 1, infile) != NULL) |
268 | while (fgets (buf, HUGE_BUF - 1, infile) != NULL) |
268 | { |
269 | { |
269 | if (strncmp (buf, "IMAGE ", 6) != 0) |
270 | if (strncmp (buf, "IMAGE ", 6) != 0) |
270 | { |
271 | { |
271 | LOG (llevError, "read_client_images:Bad image line - not IMAGE, instead\n%s", buf); |
272 | LOG (llevError, "read_client_images:Bad image line - not IMAGE, instead\n%s", buf); |
272 | abort (); |
273 | abort (); |
273 | } |
274 | } |
|
|
275 | |
274 | num = atoi (buf + 6); |
276 | num = atoi (buf + 6); |
275 | if (num < 0 || num >= nrofpixmaps) |
277 | if (num < 0 || num >= nrofpixmaps) |
276 | { |
278 | { |
277 | LOG (llevError, "read_client_images: Image num %d not in 0..%d\n%s", num, nrofpixmaps, buf); |
279 | LOG (llevError, "read_client_images: Image num %d not in 0..%d\n%s", num, nrofpixmaps, buf); |
278 | abort (); |
280 | abort (); |
279 | } |
281 | } |
|
|
282 | |
280 | /* Skip accross the number data */ |
283 | /* Skip accross the number data */ |
281 | for (cp = buf + 6; *cp != ' '; cp++); |
284 | for (cp = buf + 6; *cp != ' '; cp++); |
282 | len = atoi (cp); |
285 | len = atoi (cp); |
283 | if (len == 0 || len > MAX_IMAGE_SIZE) |
286 | if (len == 0 || len > MAX_IMAGE_SIZE) |
284 | { |
287 | { |
285 | LOG (llevError, "read_client_images: length not valid: %d > %d \n%s", len, MAX_IMAGE_SIZE, buf); |
288 | LOG (llevError, "read_client_images: length not valid: %d > %d \n%s", len, MAX_IMAGE_SIZE, buf); |
286 | abort (); |
289 | abort (); |
287 | } |
290 | } |
|
|
291 | |
288 | /* We don't actualy care about the name if the image that |
292 | /* We don't actualy care about the name of the image that |
289 | * is embedded in the image file, so just ignore it. |
293 | * is embedded in the image file, so just ignore it. |
290 | */ |
294 | */ |
291 | facesets[fileno].faces[num].datalen = len; |
295 | facesets[fileno].faces[num].datalen = len; |
292 | facesets[fileno].faces[num].data = (uint8 *) malloc (len); |
296 | facesets[fileno].faces[num].data = (uint8 *) malloc (len); |
293 | if ((i = fread (facesets[fileno].faces[num].data, len, 1, infile)) != 1) |
297 | if ((i = fread (facesets[fileno].faces[num].data, len, 1, infile)) != 1) |
294 | { |
298 | { |
295 | LOG (llevError, "read_client_images: Did not read desired amount of data, wanted %d, got %d\n%s", len, i, buf); |
299 | LOG (llevError, "read_client_images: Did not read desired amount of data, wanted %d, got %d\n%s", len, i, buf); |
296 | abort (); |
300 | abort (); |
297 | } |
301 | } |
|
|
302 | |
298 | facesets[fileno].faces[num].checksum = 0; |
303 | facesets[fileno].faces[num].checksum = 0; |
299 | for (i = 0; i < len; i++) |
304 | for (i = 0; i < len; i++) |
300 | { |
305 | { |
301 | ROTATE_RIGHT (facesets[fileno].faces[num].checksum); |
306 | ROTATE_RIGHT (facesets[fileno].faces[num].checksum); |
302 | facesets[fileno].faces[num].checksum += facesets[fileno].faces[num].data[i]; |
307 | facesets[fileno].faces[num].checksum += facesets[fileno].faces[num].data[i]; |
303 | facesets[fileno].faces[num].checksum &= 0xffffffff; |
308 | facesets[fileno].faces[num].checksum &= 0xffffffff; |
304 | } |
309 | } |
305 | } |
310 | } |
|
|
311 | |
306 | close_and_delete (infile, compressed); |
312 | close_and_delete (infile, compressed); |
307 | } /* For fileno < MAX_FACE_SETS */ |
313 | } /* For fileno < MAX_FACE_SETS */ |
308 | } |
314 | } |
309 | |
315 | |
310 | /** |
316 | /** |
311 | * Client tells us what type of faces it wants. Also sets |
317 | * Client tells us what type of faces it wants. Also sets |
312 | * the caching attribute. |
318 | * the caching attribute. |
313 | * |
319 | * |
314 | */ |
320 | */ |
315 | |
|
|
316 | void |
321 | void |
317 | SetFaceMode (char *buf, int len, NewSocket * ns) |
322 | SetFaceMode (char *buf, int len, client *ns) |
318 | { |
323 | { |
319 | char tmp[256]; |
|
|
320 | |
|
|
321 | int mask = (atoi (buf) & CF_FACE_CACHE), mode = (atoi (buf) & ~CF_FACE_CACHE); |
324 | int mask = (atoi (buf) & CF_FACE_CACHE), mode = (atoi (buf) & ~CF_FACE_CACHE); |
322 | |
325 | |
323 | if (mode == CF_FACE_NONE) |
326 | if (mode == CF_FACE_NONE) |
324 | { |
|
|
325 | ns->facecache = 1; |
327 | ns->facecache = 1; |
326 | } |
|
|
327 | else if (mode != CF_FACE_PNG) |
328 | else if (mode != CF_FACE_PNG) |
328 | { |
|
|
329 | sprintf (tmp, "drawinfo %d %s", NDI_RED, "Warning - send unsupported face mode. Will use Png"); |
329 | ns->send_packet_printf ("drawinfo %d %s", NDI_RED, "Warning - send unsupported face mode. Will use Png"); |
330 | Write_String_To_Socket (ns, tmp, strlen (tmp)); |
330 | |
331 | #ifdef ESRV_DEBUG |
|
|
332 | LOG (llevDebug, "SetFaceMode: Invalid mode from client: %d\n", mode); |
|
|
333 | #endif |
|
|
334 | } |
|
|
335 | if (mask) |
331 | if (mask) |
336 | { |
|
|
337 | ns->facecache = 1; |
332 | ns->facecache = 1; |
338 | } |
|
|
339 | } |
333 | } |
340 | |
334 | |
341 | /** |
335 | /** |
342 | * Client has requested pixmap that it somehow missed getting. |
336 | * Client has requested pixmap that it somehow missed getting. |
343 | * This will be called often if the client is |
337 | * This will be called often if the client is |
344 | * caching images. |
338 | * caching images. |
345 | */ |
339 | */ |
346 | |
|
|
347 | void |
340 | void |
348 | SendFaceCmd (char *buff, int len, NewSocket * ns) |
341 | SendFaceCmd (char *buf, int len, client *ns) |
349 | { |
342 | { |
350 | long tmpnum = atoi (buff); |
343 | uint16 facenum = atoi (buf); |
351 | short facenum = tmpnum & 0xffff; |
|
|
352 | |
344 | |
353 | if (facenum != 0) |
345 | if (facenum != 0) |
354 | esrv_send_face (ns, facenum, 1); |
346 | esrv_send_face (ns, facenum, 1); |
355 | } |
347 | } |
356 | |
348 | |
… | |
… | |
360 | * If nocache is true (nonzero), ignore the cache setting from the client - |
352 | * If nocache is true (nonzero), ignore the cache setting from the client - |
361 | * this is needed for the askface, in which we really do want to send the |
353 | * this is needed for the askface, in which we really do want to send the |
362 | * face (and askface is the only place that should be setting it). Otherwise, |
354 | * face (and askface is the only place that should be setting it). Otherwise, |
363 | * we look at the facecache, and if set, send the image name. |
355 | * we look at the facecache, and if set, send the image name. |
364 | */ |
356 | */ |
365 | |
|
|
366 | void |
357 | void |
367 | esrv_send_face (NewSocket * ns, short face_num, int nocache) |
358 | esrv_send_face (client *ns, short face_num, int nocache) |
368 | { |
359 | { |
369 | SockList sl; |
|
|
370 | char fallback; |
360 | char fallback; |
371 | |
361 | |
372 | if (face_num <= 0 || face_num >= nrofpixmaps) |
362 | if (face_num <= 0 || face_num >= nrofpixmaps) |
373 | { |
363 | { |
374 | LOG (llevError, "esrv_send_face (%d) out of bounds??\n", face_num); |
364 | LOG (llevError, "esrv_send_face (%d) out of bounds??\n", face_num); |
375 | return; |
365 | return; |
376 | } |
366 | } |
377 | |
367 | |
378 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
368 | packet sl; |
379 | fallback = get_face_fallback (ns->faceset, face_num); |
369 | fallback = get_face_fallback (ns->faceset, face_num); |
380 | |
370 | |
381 | if (facesets[fallback].faces[face_num].data == NULL) |
371 | if (facesets[fallback].faces[face_num].data == NULL) |
382 | { |
372 | { |
383 | LOG (llevError, "esrv_send_face: faces[%d].data == NULL\n", face_num); |
373 | LOG (llevError, "esrv_send_face: faces[%d].data == NULL\n", face_num); |
384 | return; |
374 | return; |
385 | } |
375 | } |
386 | |
376 | |
387 | if (ns->facecache && !nocache) |
377 | if (ns->facecache && !nocache) |
388 | { |
378 | { |
|
|
379 | sl << (ns->image2 ? "face2 " : "face1 ") |
|
|
380 | << uint16 (face_num); |
|
|
381 | |
389 | if (ns->image2) |
382 | if (ns->image2) |
390 | strcpy ((char *) sl.buf, "face2 "); |
383 | sl << uint8 (fallback); |
391 | else if (ns->sc_version >= 1026) |
384 | |
392 | strcpy ((char *) sl.buf, "face1 "); |
385 | sl << uint32 (facesets[fallback].faces[face_num].checksum) |
|
|
386 | << new_faces[face_num].name; |
|
|
387 | |
|
|
388 | ns->send_packet (sl); |
|
|
389 | } |
393 | else |
390 | else |
394 | strcpy ((char *) sl.buf, "face "); |
391 | { |
|
|
392 | sl << (ns->image2 ? "image2 " : "image ") |
|
|
393 | << uint32 (face_num); |
395 | |
394 | |
396 | sl.len = strlen ((const char *) sl.buf); |
|
|
397 | SockList_AddShort (&sl, face_num); |
|
|
398 | if (ns->image2) |
395 | if (ns->image2) |
399 | SockList_AddChar (&sl, fallback); |
396 | sl << uint8 (fallback); |
400 | if (ns->sc_version >= 1026) |
397 | |
401 | SockList_AddInt (&sl, facesets[fallback].faces[face_num].checksum); |
|
|
402 | strcpy ((char *) sl.buf + sl.len, new_faces[face_num].name); |
|
|
403 | sl.len += strlen (new_faces[face_num].name); |
|
|
404 | Send_With_Handling (ns, &sl); |
|
|
405 | } |
|
|
406 | else |
|
|
407 | { |
|
|
408 | if (ns->image2) |
|
|
409 | strcpy ((char *) sl.buf, "image2 "); |
|
|
410 | else |
|
|
411 | strcpy ((char *) sl.buf, "image "); |
|
|
412 | sl.len = strlen ((char *) sl.buf); |
|
|
413 | SockList_AddInt (&sl, face_num); |
|
|
414 | if (ns->image2) |
|
|
415 | SockList_AddChar (&sl, fallback); |
|
|
416 | SockList_AddInt (&sl, facesets[fallback].faces[face_num].datalen); |
398 | sl << uint32 (facesets[fallback].faces[face_num].datalen) |
417 | memcpy (sl.buf + sl.len, facesets[fallback].faces[face_num].data, facesets[fallback].faces[face_num].datalen); |
399 | << data (facesets[fallback].faces[face_num].data, facesets[fallback].faces[face_num].datalen); |
418 | sl.len += facesets[fallback].faces[face_num].datalen; |
400 | |
419 | Send_With_Handling (ns, &sl); |
401 | ns->send_packet (sl); |
420 | } |
402 | } |
|
|
403 | |
421 | ns->faces_sent[face_num] |= NS_FACESENT_FACE; |
404 | ns->faces_sent[face_num] |= NS_FACESENT_FACE; |
422 | free (sl.buf); |
|
|
423 | } |
405 | } |
424 | |
406 | |
425 | /** |
407 | /** |
426 | * Sends the number of images, checksum of the face file, |
408 | * Sends the number of images, checksum of the face file, |
427 | * and the image_info file information. See the doc/Developers/protocol |
409 | * and the image_info file information. See the doc/Developers/protocol |
428 | * if you want further detail. |
410 | * if you want further detail. |
429 | */ |
411 | */ |
430 | |
412 | |
431 | void |
413 | void |
432 | send_image_info (NewSocket * ns, char *params) |
414 | send_image_info (client *ns, char *params) |
433 | { |
415 | { |
434 | SockList sl; |
416 | packet sl; |
435 | int i; |
|
|
436 | |
417 | |
437 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
|
|
438 | |
|
|
439 | sprintf ((char *) sl.buf, "replyinfo image_info\n%d\n%d\n", nrofpixmaps - 1, bmaps_checksum); |
418 | sl.printf ("replyinfo image_info\n%d\n%d\n", nrofpixmaps - 1, bmaps_checksum); |
|
|
419 | |
440 | for (i = 0; i < MAX_FACE_SETS; i++) |
420 | for (int i = 0; i < MAX_FACE_SETS; i++) |
441 | { |
|
|
442 | if (facesets[i].prefix) |
421 | if (facesets[i].prefix) |
443 | { |
422 | sl.printf ("%d:%s:%s:%d:%s:%s:%s", i, |
444 | sprintf ((char *) sl.buf + strlen ((const char *) sl.buf), "%d:%s:%s:%d:%s:%s:%s", |
|
|
445 | i, facesets[i].prefix, facesets[i].fullname, facesets[i].fallback, |
423 | facesets[i].prefix, facesets[i].fullname , facesets[i].fallback, |
446 | facesets[i].size, facesets[i].extension, facesets[i].comment); |
424 | facesets[i].size , facesets[i].extension, facesets[i].comment); |
447 | } |
425 | |
448 | } |
426 | ns->send_packet (sl); |
449 | sl.len = strlen ((const char *) sl.buf); |
|
|
450 | Send_With_Handling (ns, &sl); |
|
|
451 | free (sl.buf); |
|
|
452 | } |
427 | } |
453 | |
428 | |
454 | /** |
429 | /** |
455 | * Sends requested face information. |
430 | * Sends requested face information. |
456 | * \param ns socket to send to |
431 | * \param ns socket to send to |
… | |
… | |
459 | * For each image in [start..stop] sends |
434 | * For each image in [start..stop] sends |
460 | * - checksum |
435 | * - checksum |
461 | * - name |
436 | * - name |
462 | */ |
437 | */ |
463 | void |
438 | void |
464 | send_image_sums (NewSocket * ns, char *params) |
439 | send_image_sums (client *ns, char *params) |
465 | { |
440 | { |
466 | int start, stop; |
441 | int start, stop; |
467 | short i; |
|
|
468 | char qq; |
|
|
469 | char *cp, buf[MAX_BUF]; |
442 | char *cp, buf[MAX_BUF]; |
470 | SockList sl; |
|
|
471 | |
443 | |
472 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
444 | packet sl; |
473 | |
445 | |
474 | start = atoi (params); |
446 | start = atoi (params); |
475 | for (cp = params; *cp != '\0'; cp++) |
447 | for (cp = params; *cp != '\0'; cp++) |
476 | if (*cp == ' ') |
448 | if (*cp == ' ') |
477 | break; |
449 | break; |
478 | |
450 | |
479 | stop = atoi (cp); |
451 | stop = atoi (cp); |
480 | if (stop < start || *cp == '\0' || (stop - start) > 1000 || stop >= nrofpixmaps) |
452 | if (stop < start || *cp == '\0' || (stop - start) > 1000 || stop >= nrofpixmaps) |
481 | { |
453 | { |
482 | sprintf (buf, "replyinfo image_sums %d %d", start, stop); |
454 | sl.printf ("replyinfo image_sums %d %d", start, stop); |
483 | cs_write_string (ns, buf, strlen (buf)); |
455 | ns->send_packet (sl); |
|
|
456 | sl.reset (); |
484 | return; |
457 | return; |
485 | } |
458 | } |
|
|
459 | |
486 | sprintf ((char *) sl.buf, "replyinfo image_sums %d %d ", start, stop); |
460 | sl.printf ("replyinfo image_sums %d %d ", start, stop); |
487 | |
461 | |
488 | sl.len = strlen ((const char *) sl.buf); |
|
|
489 | |
|
|
490 | for (i = start; i <= stop; i++) |
462 | for (int i = start; i <= stop; i++) |
491 | { |
463 | { |
492 | SockList_AddShort (&sl, i); |
|
|
493 | ns->faces_sent[i] |= NS_FACESENT_FACE; |
464 | ns->faces_sent[i] |= NS_FACESENT_FACE; |
494 | |
465 | |
495 | qq = get_face_fallback (ns->faceset, i); |
466 | int qq = get_face_fallback (ns->faceset, i); |
|
|
467 | |
|
|
468 | sl << uint16 (i) |
496 | SockList_AddInt (&sl, facesets[qq].faces[i].checksum); |
469 | << uint32 (facesets[qq].faces[i].checksum) |
497 | SockList_AddChar (&sl, qq); |
470 | << uint8 (qq) |
498 | |
471 | << data8 (&new_faces[i].name, new_faces[i].name.length () + 1); |
499 | qq = strlen (new_faces[i].name); |
|
|
500 | SockList_AddChar (&sl, (char) (qq + 1)); |
|
|
501 | strcpy ((char *) sl.buf + sl.len, new_faces[i].name); |
|
|
502 | sl.len += qq; |
|
|
503 | SockList_AddChar (&sl, 0); |
|
|
504 | } |
472 | } |
|
|
473 | |
505 | /* It would make more sense to catch this pre-emptively in the code above. |
474 | /* It would make more sense to catch this pre-emptively in the code above. |
506 | * however, if this really happens, we probably just want to cut down the |
475 | * however, if this really happens, we probably just want to cut down the |
507 | * size to less than 1000, since that is what we claim the protocol would |
476 | * size to less than 1000, since that is what we claim the protocol would |
508 | * support. |
477 | * support. |
509 | */ |
478 | */ |
510 | if (sl.len >= MAXSOCKBUF) |
479 | if (sl.length () >= MAXSOCKBUF) |
511 | { |
480 | { |
512 | LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.len, MAXSOCKBUF); |
481 | LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.length (), MAXSOCKBUF); |
513 | abort (); |
482 | abort (); |
514 | } |
483 | } |
515 | Send_With_Handling (ns, &sl); |
484 | |
516 | free (sl.buf); |
485 | ns->send_packet (sl); |
517 | } |
486 | } |
|
|
487 | |