… | |
… | |
38 | #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 */ |
39 | |
39 | |
40 | /** Information about one image */ |
40 | /** Information about one image */ |
41 | typedef struct FaceInfo |
41 | typedef struct FaceInfo |
42 | { |
42 | { |
43 | |
|
|
44 | uint8 *data; /**< image data */ |
43 | uint8 *data; /**< image data */ |
45 | uint16 datalen; /**< length of the xpm data */ |
44 | uint16 datalen; /**< length of the xpm data */ |
46 | uint32 checksum; /**< Checksum of face data */ |
45 | uint32 checksum; /**< Checksum of face data */ |
47 | } FaceInfo; |
46 | } FaceInfo; |
48 | |
47 | |
49 | /** Information about one face set */ |
48 | /** Information about one face set */ |
50 | typedef struct |
49 | typedef struct |
51 | { |
50 | { |
52 | |
|
|
53 | char *prefix; /**< */ |
51 | char *prefix; /**< */ |
54 | char *fullname; |
52 | char *fullname; |
55 | |
53 | |
56 | 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 */ |
57 | char *size; |
55 | char *size; |
… | |
… | |
88 | if (facesets[num].prefix) |
86 | if (facesets[num].prefix) |
89 | { |
87 | { |
90 | for (q = 0; q < nrofpixmaps; q++) |
88 | for (q = 0; q < nrofpixmaps; q++) |
91 | if (facesets[num].faces[q].data) |
89 | if (facesets[num].faces[q].data) |
92 | free (facesets[num].faces[q].data); |
90 | free (facesets[num].faces[q].data); |
|
|
91 | |
93 | free (facesets[num].prefix); |
92 | free (facesets[num].prefix); |
94 | free (facesets[num].fullname); |
93 | free (facesets[num].fullname); |
95 | free (facesets[num].size); |
94 | free (facesets[num].size); |
96 | free (facesets[num].extension); |
95 | free (facesets[num].extension); |
97 | free (facesets[num].comment); |
96 | free (facesets[num].comment); |
… | |
… | |
127 | if (!facesets[faceset].prefix) |
126 | if (!facesets[faceset].prefix) |
128 | { |
127 | { |
129 | 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); |
130 | return 0; /* use default set */ |
129 | return 0; /* use default set */ |
131 | } |
130 | } |
|
|
131 | |
132 | if (facesets[faceset].faces[imageno].data) |
132 | if (facesets[faceset].faces[imageno].data) |
133 | return faceset; |
133 | return faceset; |
|
|
134 | |
134 | return get_face_fallback (facesets[faceset].fallback, imageno); |
135 | return get_face_fallback (facesets[faceset].fallback, imageno); |
135 | } |
136 | } |
136 | |
137 | |
137 | /** |
138 | /** |
138 | * Checks fallback are correctly defined. |
139 | * Checks fallback are correctly defined. |
… | |
… | |
154 | if (!facesets[fallback].prefix) |
155 | if (!facesets[fallback].prefix) |
155 | { |
156 | { |
156 | 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); |
157 | abort (); |
158 | abort (); |
158 | } |
159 | } |
|
|
160 | |
159 | togo--; |
161 | togo--; |
160 | if (togo == 0) |
162 | if (togo == 0) |
161 | { |
163 | { |
162 | LOG (llevError, "Infinite loop found in facesets. aborting.\n"); |
164 | LOG (llevError, "Infinite loop found in facesets. aborting.\n"); |
163 | abort (); |
165 | abort (); |
164 | } |
166 | } |
|
|
167 | |
165 | check_faceset_fallback (fallback, togo); |
168 | check_faceset_fallback (fallback, togo); |
166 | } |
169 | } |
167 | |
170 | |
168 | #define MAX_IMAGE_SIZE 10000 |
171 | #define MAX_IMAGE_SIZE 10000 |
169 | |
172 | |
… | |
… | |
181 | * Function largely rewritten May 2000 to be more general purpose. |
184 | * Function largely rewritten May 2000 to be more general purpose. |
182 | * 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, |
183 | * 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 |
184 | * to do such. |
187 | * to do such. |
185 | */ |
188 | */ |
186 | |
|
|
187 | void |
189 | void |
188 | read_client_images (void) |
190 | read_client_images (void) |
189 | { |
191 | { |
190 | char filename[400]; |
192 | char filename[400]; |
191 | char buf[HUGE_BUF]; |
193 | char buf[HUGE_BUF]; |
… | |
… | |
198 | if ((infile = open_and_uncompress (filename, 0, &compressed)) == NULL) |
200 | if ((infile = open_and_uncompress (filename, 0, &compressed)) == NULL) |
199 | { |
201 | { |
200 | LOG (llevError, "Unable to open %s\n", filename); |
202 | LOG (llevError, "Unable to open %s\n", filename); |
201 | abort (); |
203 | abort (); |
202 | } |
204 | } |
|
|
205 | |
203 | while (fgets (buf, HUGE_BUF - 1, infile) != NULL) |
206 | while (fgets (buf, HUGE_BUF - 1, infile) != NULL) |
204 | { |
207 | { |
205 | badline = 0; |
208 | badline = 0; |
206 | |
209 | |
207 | if (buf[0] == '#') |
210 | if (buf[0] == '#') |
208 | continue; |
211 | continue; |
|
|
212 | |
209 | if (!(cps[0] = strtok (buf, ":"))) |
213 | if (!(cps[0] = strtok (buf, ":"))) |
210 | badline = 1; |
214 | badline = 1; |
|
|
215 | |
211 | for (i = 1; i < 7; i++) |
216 | for (i = 1; i < 7; i++) |
212 | { |
|
|
213 | if (!(cps[i] = strtok (NULL, ":"))) |
217 | if (!(cps[i] = strtok (NULL, ":"))) |
214 | badline = 1; |
218 | badline = 1; |
215 | } |
219 | |
216 | if (badline) |
220 | if (badline) |
217 | { |
|
|
218 | 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); |
219 | } |
|
|
220 | else |
222 | else |
221 | { |
223 | { |
222 | len = atoi (cps[0]); |
224 | len = atoi (cps[0]); |
223 | if (len >= MAX_FACE_SETS) |
225 | if (len >= MAX_FACE_SETS) |
224 | { |
226 | { |
… | |
… | |
231 | facesets[len].size = strdup (cps[4]); |
233 | facesets[len].size = strdup (cps[4]); |
232 | facesets[len].extension = strdup (cps[5]); |
234 | facesets[len].extension = strdup (cps[5]); |
233 | facesets[len].comment = strdup (cps[6]); |
235 | facesets[len].comment = strdup (cps[6]); |
234 | } |
236 | } |
235 | } |
237 | } |
|
|
238 | |
236 | close_and_delete (infile, compressed); |
239 | close_and_delete (infile, compressed); |
|
|
240 | |
237 | for (i = 0; i < MAX_FACE_SETS; i++) |
241 | for (i = 0; i < MAX_FACE_SETS; i++) |
238 | { |
242 | { |
239 | if (facesets[i].prefix) |
243 | if (facesets[i].prefix) |
240 | check_faceset_fallback (i, MAX_FACE_SETS); |
244 | check_faceset_fallback (i, MAX_FACE_SETS); |
241 | } |
245 | } |
|
|
246 | |
242 | /* Loaded the faceset information - now need to load up the |
247 | /* Loaded the faceset information - now need to load up the |
243 | * actual faces. |
248 | * actual faces. |
244 | */ |
249 | */ |
245 | |
250 | |
246 | for (fileno = 0; fileno < MAX_FACE_SETS; fileno++) |
251 | for (fileno = 0; fileno < MAX_FACE_SETS; fileno++) |
247 | { |
252 | { |
248 | /* if prefix is not set, this is not used */ |
253 | /* if prefix is not set, this is not used */ |
249 | if (!facesets[fileno].prefix) |
254 | if (!facesets[fileno].prefix) |
250 | continue; |
255 | continue; |
|
|
256 | |
251 | facesets[fileno].faces = (FaceInfo *) calloc (nrofpixmaps, sizeof (FaceInfo)); |
257 | facesets[fileno].faces = (FaceInfo *) calloc (nrofpixmaps, sizeof (FaceInfo)); |
252 | |
258 | |
253 | sprintf (filename, "%s/crossfire.%d", settings.datadir, fileno); |
259 | sprintf (filename, "%s/crossfire.%d", settings.datadir, fileno); |
254 | LOG (llevDebug, "Loading image file %s\n", filename); |
260 | LOG (llevDebug, "Loading image file %s\n", filename); |
255 | |
261 | |
256 | if ((infile = open_and_uncompress (filename, 0, &compressed)) == NULL) |
262 | if ((infile = open_and_uncompress (filename, 0, &compressed)) == NULL) |
257 | { |
263 | { |
258 | LOG (llevError, "Unable to open %s\n", filename); |
264 | LOG (llevError, "Unable to open %s\n", filename); |
259 | abort (); |
265 | abort (); |
260 | } |
266 | } |
|
|
267 | |
261 | while (fgets (buf, HUGE_BUF - 1, infile) != NULL) |
268 | while (fgets (buf, HUGE_BUF - 1, infile) != NULL) |
262 | { |
269 | { |
263 | if (strncmp (buf, "IMAGE ", 6) != 0) |
270 | if (strncmp (buf, "IMAGE ", 6) != 0) |
264 | { |
271 | { |
265 | 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); |
266 | abort (); |
273 | abort (); |
267 | } |
274 | } |
|
|
275 | |
268 | num = atoi (buf + 6); |
276 | num = atoi (buf + 6); |
269 | if (num < 0 || num >= nrofpixmaps) |
277 | if (num < 0 || num >= nrofpixmaps) |
270 | { |
278 | { |
271 | 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); |
272 | abort (); |
280 | abort (); |
273 | } |
281 | } |
|
|
282 | |
274 | /* Skip accross the number data */ |
283 | /* Skip accross the number data */ |
275 | for (cp = buf + 6; *cp != ' '; cp++); |
284 | for (cp = buf + 6; *cp != ' '; cp++); |
276 | len = atoi (cp); |
285 | len = atoi (cp); |
277 | if (len == 0 || len > MAX_IMAGE_SIZE) |
286 | if (len == 0 || len > MAX_IMAGE_SIZE) |
278 | { |
287 | { |
279 | 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); |
280 | abort (); |
289 | abort (); |
281 | } |
290 | } |
|
|
291 | |
282 | /* We don't actualy care about the name of the image that |
292 | /* We don't actualy care about the name of the image that |
283 | * is embedded in the image file, so just ignore it. |
293 | * is embedded in the image file, so just ignore it. |
284 | */ |
294 | */ |
285 | facesets[fileno].faces[num].datalen = len; |
295 | facesets[fileno].faces[num].datalen = len; |
286 | facesets[fileno].faces[num].data = (uint8 *) malloc (len); |
296 | facesets[fileno].faces[num].data = (uint8 *) malloc (len); |
287 | 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) |
288 | { |
298 | { |
289 | 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); |
290 | abort (); |
300 | abort (); |
291 | } |
301 | } |
|
|
302 | |
292 | facesets[fileno].faces[num].checksum = 0; |
303 | facesets[fileno].faces[num].checksum = 0; |
293 | for (i = 0; i < len; i++) |
304 | for (i = 0; i < len; i++) |
294 | { |
305 | { |
295 | ROTATE_RIGHT (facesets[fileno].faces[num].checksum); |
306 | ROTATE_RIGHT (facesets[fileno].faces[num].checksum); |
296 | facesets[fileno].faces[num].checksum += facesets[fileno].faces[num].data[i]; |
307 | facesets[fileno].faces[num].checksum += facesets[fileno].faces[num].data[i]; |
297 | facesets[fileno].faces[num].checksum &= 0xffffffff; |
308 | facesets[fileno].faces[num].checksum &= 0xffffffff; |
298 | } |
309 | } |
299 | } |
310 | } |
|
|
311 | |
300 | close_and_delete (infile, compressed); |
312 | close_and_delete (infile, compressed); |
301 | } /* For fileno < MAX_FACE_SETS */ |
313 | } /* For fileno < MAX_FACE_SETS */ |
302 | } |
314 | } |
303 | |
315 | |
304 | /** |
316 | /** |
305 | * Client tells us what type of faces it wants. Also sets |
317 | * Client tells us what type of faces it wants. Also sets |
306 | * the caching attribute. |
318 | * the caching attribute. |
307 | * |
319 | * |
308 | */ |
320 | */ |
309 | |
|
|
310 | void |
321 | void |
311 | SetFaceMode (char *buf, int len, client *ns) |
322 | SetFaceMode (char *buf, int len, client *ns) |
312 | { |
323 | { |
313 | 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); |
314 | |
325 | |
… | |
… | |
324 | /** |
335 | /** |
325 | * Client has requested pixmap that it somehow missed getting. |
336 | * Client has requested pixmap that it somehow missed getting. |
326 | * This will be called often if the client is |
337 | * This will be called often if the client is |
327 | * caching images. |
338 | * caching images. |
328 | */ |
339 | */ |
329 | |
|
|
330 | void |
340 | void |
331 | SendFaceCmd (char *buff, int len, client * ns) |
341 | SendFaceCmd (char *buf, int len, client *ns) |
332 | { |
342 | { |
333 | long tmpnum = atoi (buff); |
343 | uint16 facenum = atoi (buf); |
334 | short facenum = tmpnum & 0xffff; |
|
|
335 | |
344 | |
336 | if (facenum != 0) |
345 | if (facenum != 0) |
337 | esrv_send_face (ns, facenum, 1); |
346 | esrv_send_face (ns, facenum, 1); |
338 | } |
347 | } |
339 | |
348 | |
… | |
… | |
343 | * 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 - |
344 | * 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 |
345 | * 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, |
346 | * 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. |
347 | */ |
356 | */ |
348 | |
|
|
349 | void |
357 | void |
350 | esrv_send_face (client *ns, short face_num, int nocache) |
358 | esrv_send_face (client *ns, short face_num, int nocache) |
351 | { |
359 | { |
352 | char fallback; |
360 | char fallback; |
353 | |
361 | |
… | |
… | |
401 | * and the image_info file information. See the doc/Developers/protocol |
409 | * and the image_info file information. See the doc/Developers/protocol |
402 | * if you want further detail. |
410 | * if you want further detail. |
403 | */ |
411 | */ |
404 | |
412 | |
405 | void |
413 | void |
406 | send_image_info (client * ns, char *params) |
414 | send_image_info (client *ns, char *params) |
407 | { |
415 | { |
408 | packet sl; |
416 | packet sl; |
409 | |
417 | |
410 | sl.printf ("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); |
411 | |
419 | |
412 | for (int i = 0; i < MAX_FACE_SETS; i++) |
420 | for (int i = 0; i < MAX_FACE_SETS; i++) |
413 | if (facesets[i].prefix) |
421 | if (facesets[i].prefix) |
414 | sl.printf ("%d:%s:%s:%d:%s:%s:%s", |
422 | sl.printf ("%d:%s:%s:%d:%s:%s:%s", i, |
415 | i, facesets[i].prefix, facesets[i].fullname, facesets[i].fallback, |
423 | facesets[i].prefix, facesets[i].fullname , facesets[i].fallback, |
416 | facesets[i].size, facesets[i].extension, facesets[i].comment); |
424 | facesets[i].size , facesets[i].extension, facesets[i].comment); |
417 | |
425 | |
418 | ns->send_packet (sl); |
426 | ns->send_packet (sl); |
419 | } |
427 | } |
420 | |
428 | |
421 | /** |
429 | /** |
… | |
… | |
426 | * For each image in [start..stop] sends |
434 | * For each image in [start..stop] sends |
427 | * - checksum |
435 | * - checksum |
428 | * - name |
436 | * - name |
429 | */ |
437 | */ |
430 | void |
438 | void |
431 | send_image_sums (client * ns, char *params) |
439 | send_image_sums (client *ns, char *params) |
432 | { |
440 | { |
433 | int start, stop; |
441 | int start, stop; |
434 | char *cp, buf[MAX_BUF]; |
442 | char *cp, buf[MAX_BUF]; |
435 | |
443 | |
436 | packet sl; |
444 | packet sl; |