 |
Crossfire Client, Trunk
|
Go to the documentation of this file.
23 #include <glib/gstdio.h>
33 #define ROTATE_RIGHT(c) if ((c) & 01) (c) = ((c) >>1) + 0x80000000; else (c) >>= 1;
55 static int load_image(
char *filename, guint8 *data,
int *len, guint32 *csum) {
65 if ((cp = strchr(filename,
'@')) != NULL) {
67 int offset, last = -1;
73 offset = atoi(cp + 1);
77 "Corrupt filename - has '@' but no ':' ?(%s)", filename);
81 length = atoi(lp + 1);
85 if (!strcmp(
fd_cache[i].name, filename)) {
88 if (last == -1 &&
fd_cache[i].fd == -1) {
96 "fd_cache filled up? unable to load matching cache entry");
101 if ((
fd_cache[last].fd = open(filename, O_RDONLY | O_BINARY)) == -1)
103 if ((
fd_cache[last].fd = open(filename, O_RDONLY)) == -1)
106 LOG(
LOG_WARNING,
"common::load_image",
"unable to load listed cache file %s",
111 strcpy(
fd_cache[last].name, filename);
114 lseek(
fd_cache[i].fd, offset, SEEK_SET);
116 *len = read(
fd_cache[i].fd, data, length);
118 *len = read(
fd_cache[i].fd, data, 65535);
124 if ((fd = open(filename, O_RDONLY | O_BINARY)) == -1) {
127 length = lseek(fd, 0, SEEK_END);
128 lseek(fd, 0, SEEK_SET);
129 *len = read(fd, data, length);
131 if ((fd = open(filename, O_RDONLY)) == -1) {
134 *len = read(fd, data, 65535);
146 for (i = 0; i < *len; i++) {
167 #define IMAGE_HASH 8192
193 for (p = str; *p !=
'\0' && *p !=
'.'; p++) {
201 return hash % tablesize;
217 if (!strcmp(
image_cache[newhash].image_name, str)) {
224 }
while (newhash != hash);
230 "Hash table is full, increase IMAGE_CACHE size");
242 if (hash_entry == -1) {
244 "Unable to find cache entry for %s, %s", imagename, ce->
filename);
254 while (last->
next && last->
next != ce) {
259 "Unable to find cache entry for %s, %s", imagename, ce->
filename);
278 if (hash_entry == -1) {
303 strcmp(
image_cache[newhash].image_name, imagename)) {
309 if (newhash == hash) {
311 "Hash table is full, increase IMAGE_CACHE size");
344 if (line[0] ==
'#') {
352 "Did not parse line %s properly?", line);
375 snprintf(bmaps,
sizeof(bmaps),
"%s/bmaps.client", CF_DATADIR);
376 if ((fp = fopen(bmaps,
"r")) != NULL) {
377 while (fgets(inbuf,
MAX_BUF - 1, fp) != NULL) {
382 snprintf(inbuf,
sizeof(inbuf),
383 "Unable to open %s. You may wish to download and install the image file to improve performance.\n",
388 snprintf(bmaps,
sizeof(bmaps),
"%s/image-cache/bmaps.client",
cache_dir);
389 if ((fp = fopen(bmaps,
"r")) != NULL) {
390 while (fgets(inbuf,
MAX_BUF - 1, fp) != NULL) {
433 guint8 data[65536], *png_tmp;
439 fprintf(stderr,
"finish_face_cmd, pnum=%d, checksum=%d, face=%s\n",
469 "file %s listed in cache file, but unable to load",
filename);
477 if (!(png_tmp =
png_to_data(data, len, &nx, &ny))) {
480 "Got error on png_to_data, image=%s", face);
496 "Got error on create_and_rescale_image_from_data, file=%s",
filename);
537 "Received a 'face' command when we are not caching");
543 face = (
char *)data + 7;
559 if (len < 9 || (len - 9) != plen) {
560 LOG(
LOG_WARNING,
"common::Image2Cmd",
"Lengths don't compare (%d,%d)",
570 static void cache_newpng(
int face, guint8 *buf,
int buflen,
int setnum,
578 "Caching images, but name for %ld not set", face);
584 if (g_access(
filename, R_OK | W_OK | X_OK) == -1) {
590 if (access(
filename, R_OK | W_OK | X_OK) == -1) {
604 snprintf(basename,
sizeof(basename),
"%s.%s",
facetoname[face],
618 }
while (g_access(
filename, F_OK) == -0);
621 if ((tmpfile = fopen(
filename,
"wb")) == NULL)
623 if ((tmpfile = fopen(
filename,
"w")) == NULL)
626 LOG(
LOG_WARNING,
"common::display_newpng",
"Can not open %s for writing",
631 fwrite(buf, buflen, 1, tmpfile);
634 for (i = 0; (int)i < buflen; i++) {
651 if ((tmpfile = fopen(
filename,
"a")) == NULL) {
652 LOG(
LOG_WARNING,
"common::display_newpng",
"Can not open %s for appending",
655 fprintf(tmpfile,
"%s %u %c%c/%s.%d\n",
680 LOG(
LOG_ERROR,
"display_newpng",
"error in PNG data; discarding");
686 "create_and_rescale_image_from_data failed for face %ld", face);
707 char *cp, *lp, *cps[7], buf[
MAX_BUF];
708 int onset = 0, badline = 0, i;
713 cp = strchr(lp,
'\n');
714 if (!cp || (cp - lp) > len) {
720 cp = strchr(lp,
'\n');
721 if (!cp || (cp - lp) > len) {
728 cp = strchr(lp,
'\n');
729 while (cp && (cp - lp) <= len) {
735 if (!(cps[0] = strtok(lp,
":"))) {
738 for (i = 1; i < 7; i++) {
739 if (!(cps[i] = strtok(NULL,
":"))) {
744 LOG(
LOG_WARNING,
"common::get_image_info",
"bad data, ignoring line:/%s/", lp);
746 onset = atoi(cps[0]);
748 LOG(
LOG_WARNING,
"common::get_image_info",
"setnum is too high: %d > %d",
759 cp = strchr(lp,
'\n');
781 snprintf(buf,
sizeof(buf),
"Unable to find match for faceset %s on the server",
803 int stop, imagenum, slen, faceset;
807 cp = strchr((
char *)data,
' ');
808 if (!cp || (cp - data) > len) {
812 while (isspace(*cp)) {
816 cp = strchr(lp,
' ');
817 if (!cp || (cp - data) > len) {
833 while ((cp - data) < len) {
851 if (imagenum > stop) {
853 "Received an image beyond our range? %d > %d", imagenum, stop);
int create_and_rescale_image_from_data(Cache_Entry *ce, int pixmap_num, guint8 *rgba_data, int width, int height)
Takes the pixmap to put the data into, as well as the rgba data (ie, already loaded with png_to_data)...
#define MSG_TYPE_CLIENT
Client originated Messages.
short GetShort_String(const unsigned char *data)
@ LOG_WARNING
Warning that something might not work.
char facecachedir[MAX_BUF]
static int load_image(char *filename, guint8 *data, int *len, guint32 *csum)
Given a filename, this tries to load the data.
struct Image_Cache image_cache[IMAGE_HASH]
Used mostly in the cache.c file, however, it can be returned to the graphic side of things so that th...
guint8 * png_to_data(guint8 *data, int len, guint32 *width, guint32 *height)
static void cache_newpng(int face, guint8 *buf, int buflen, int setnum, Cache_Entry **ce)
Helper for display_newpng, implements the caching of the image to disk.
struct FD_Cache fd_cache[MAX_FACE_SETS]
int GetInt_String(const unsigned char *data)
The reverse of SockList_AddInt, but on strings instead.
static Cache_Entry * image_add_hash(char *imagename, char *filename, guint32 checksum, guint32 ispublic)
Add a hash entry.
void get_image_info(guint8 *data, int len)
Takes the data from a replyinfo image_info and breaks it down.
void display_newpng(int face, guint8 *buf, int buflen, int setnum)
This function is called when the server has sent us the actual png data for an image.
void finish_face_cmd(int pnum, guint32 checksum, int has_sum, char *face, int faceset)
This is common for all the face commands (face2, face1, face).
void reset_image_cache_data(void)
We can now connect to different servers, so we need to clear out any old images.
int associate_cache_entry(Cache_Entry *ce, int pixnum)
This functions associates image_data in the cache entry with the specific pixmap number.
void get_image_sums(char *data, int len)
This gets a block of checksums from the server.
void LOG(LogLevel level, const char *origin, const char *format,...)
Log messages of a certain importance to stderr.
int cs_print_string(GSocketConnection *fd, const char *str,...)
Send a printf-formatted packet to the socket.
gint16 want_config[CONFIG_NUMS]
void draw_ext_info(int orig_color, int type, int subtype, const char *message)
A message processor that accepts messages along with meta information color and type.
void Face2Cmd(guint8 *data, int len)
We only get here if the server believes we are caching images.
static void image_remove_hash(char *imagename, Cache_Entry *ce)
static void image_process_line(char *line, guint32 ispublic)
Process a line from the bmaps.client file.
@ LOG_ERROR
Warning that something definitely didn't work.
void Image2Cmd(guint8 *data, int len)
#define MSG_TYPE_CLIENT_CONFIG
Local configuration issues.
static guint32 image_hash_name(char *str, int tablesize)
This function is basically hasharch from the server, common/arch.c a few changes - first,...
static gint32 image_find_hash(char *str)
This function returns an index into the image_cache for a matching entry, -1 if no match is found.
struct Cache_Entry * cache_entry
void requestface(int pnum, char *facename)
void init_common_cache_data(void)
#define MSG_TYPE_CLIENT_NOTICE
Non-critical note to player.
Face_Information face_info
gint16 use_config[CONFIG_NUMS]
static Cache_Entry * image_find_cache_entry(char *imagename, guint32 checksum, int has_sum)
This finds and returns the Cache_Entry of the image that matches name and checksum if has_sum is set.
static char * facetoname[MAXPIXMAPNUM]
This holds the name we recieve with the 'face' command so we know what to save it as when we actually...
struct Cache_Entry * next