… | |
… | |
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 | { |
… | |
… | |
237 | facesets[len].size = strdup (cps[4]); |
233 | facesets[len].size = strdup (cps[4]); |
238 | facesets[len].extension = strdup (cps[5]); |
234 | facesets[len].extension = strdup (cps[5]); |
239 | facesets[len].comment = strdup (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 of 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, client_socket *ns) |
322 | SetFaceMode (char *buf, int len, client *ns) |
318 | { |
323 | { |
319 | 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); |
320 | |
325 | |
321 | if (mode == CF_FACE_NONE) |
326 | if (mode == CF_FACE_NONE) |
322 | ns->facecache = 1; |
327 | ns->facecache = 1; |
323 | else if (mode != CF_FACE_PNG) |
328 | else if (mode != CF_FACE_PNG) |
324 | { |
|
|
325 | packet sl; |
|
|
326 | sl.printf ("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"); |
327 | ns->send_packet (sl); |
|
|
328 | } |
|
|
329 | |
330 | |
330 | if (mask) |
331 | if (mask) |
331 | ns->facecache = 1; |
332 | ns->facecache = 1; |
332 | } |
333 | } |
333 | |
334 | |
334 | /** |
335 | /** |
335 | * Client has requested pixmap that it somehow missed getting. |
336 | * Client has requested pixmap that it somehow missed getting. |
336 | * This will be called often if the client is |
337 | * This will be called often if the client is |
337 | * caching images. |
338 | * caching images. |
338 | */ |
339 | */ |
339 | |
|
|
340 | void |
340 | void |
341 | SendFaceCmd (char *buff, int len, client_socket * ns) |
341 | SendFaceCmd (char *buf, int len, client *ns) |
342 | { |
342 | { |
343 | long tmpnum = atoi (buff); |
343 | uint16 facenum = atoi (buf); |
344 | short facenum = tmpnum & 0xffff; |
|
|
345 | |
344 | |
346 | if (facenum != 0) |
345 | if (facenum != 0) |
347 | esrv_send_face (ns, facenum, 1); |
346 | esrv_send_face (ns, facenum, 1); |
348 | } |
347 | } |
349 | |
348 | |
… | |
… | |
353 | * 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 - |
354 | * 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 |
355 | * 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, |
356 | * 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. |
357 | */ |
356 | */ |
358 | |
|
|
359 | void |
357 | void |
360 | esrv_send_face (client_socket *ns, short face_num, int nocache) |
358 | esrv_send_face (client *ns, short face_num, int nocache) |
361 | { |
359 | { |
362 | char fallback; |
360 | char fallback; |
363 | |
361 | |
364 | if (face_num <= 0 || face_num >= nrofpixmaps) |
362 | if (face_num <= 0 || face_num >= nrofpixmaps) |
365 | { |
363 | { |
… | |
… | |
411 | * and the image_info file information. See the doc/Developers/protocol |
409 | * and the image_info file information. See the doc/Developers/protocol |
412 | * if you want further detail. |
410 | * if you want further detail. |
413 | */ |
411 | */ |
414 | |
412 | |
415 | void |
413 | void |
416 | send_image_info (client_socket * ns, char *params) |
414 | send_image_info (client *ns, char *params) |
417 | { |
415 | { |
418 | packet sl; |
416 | packet sl; |
419 | |
417 | |
420 | 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); |
421 | |
419 | |
422 | for (int i = 0; i < MAX_FACE_SETS; i++) |
420 | for (int i = 0; i < MAX_FACE_SETS; i++) |
423 | if (facesets[i].prefix) |
421 | if (facesets[i].prefix) |
424 | sl.printf ("%d:%s:%s:%d:%s:%s:%s", |
422 | sl.printf ("%d:%s:%s:%d:%s:%s:%s", i, |
425 | i, facesets[i].prefix, facesets[i].fullname, facesets[i].fallback, |
423 | facesets[i].prefix, facesets[i].fullname , facesets[i].fallback, |
426 | facesets[i].size, facesets[i].extension, facesets[i].comment); |
424 | facesets[i].size , facesets[i].extension, facesets[i].comment); |
427 | |
425 | |
428 | ns->send_packet (sl); |
426 | ns->send_packet (sl); |
429 | } |
427 | } |
430 | |
428 | |
431 | /** |
429 | /** |
… | |
… | |
436 | * For each image in [start..stop] sends |
434 | * For each image in [start..stop] sends |
437 | * - checksum |
435 | * - checksum |
438 | * - name |
436 | * - name |
439 | */ |
437 | */ |
440 | void |
438 | void |
441 | send_image_sums (client_socket * ns, char *params) |
439 | send_image_sums (client *ns, char *params) |
442 | { |
440 | { |
443 | int start, stop; |
441 | int start, stop; |
444 | char *cp, buf[MAX_BUF]; |
442 | char *cp, buf[MAX_BUF]; |
445 | |
443 | |
446 | packet sl; |
444 | packet sl; |