Crossfire Server, Trunk  R20513
image.c
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
25 #include "global.h"
26 
27 #include <stdlib.h>
28 #include <string.h>
29 
30 #include "image.h"
31 #include "newserver.h"
32 #include "shared/newclient.h"
33 #include "sproto.h"
34 
43 void send_face_cmd(char *buff, int len, socket_struct *ns) {
44  long tmpnum;
45  uint16_t facenum;
46 
47  if (len <= 0 || !buff) {
48  LOG(llevDebug, "IP '%s' sent bogus send_face_cmd information\n", ns->host);
49  return;
50  }
51 
52  tmpnum = atoi(buff);
53  facenum = tmpnum&0xffff;
54 
55  if (facenum != 0)
56  esrv_send_face(ns, facenum, 1);
57 }
58 
70 void esrv_send_face(socket_struct *ns, uint16_t face_num, int nocache) {
71  SockList sl;
72  int fallback;
73 
74  if (face_num == 0 || face_num >= nrofpixmaps) {
75  LOG(llevError, "esrv_send_face (%d) out of bounds??\n", face_num);
76  return;
77  }
78 
79  SockList_Init(&sl);
80  fallback = get_face_fallback(ns->faceset, face_num);
81 
82  if (facesets[fallback].faces[face_num].data == NULL) {
83  LOG(llevError, "esrv_send_face: faces[%d].data == NULL\n", face_num);
84  return;
85  }
86 
87  if (ns->facecache && !nocache) {
88  SockList_AddString(&sl, "face2 ");
89  SockList_AddShort(&sl, face_num);
90  SockList_AddChar(&sl, fallback);
91  SockList_AddInt(&sl, facesets[fallback].faces[face_num].checksum);
92  SockList_AddString(&sl, new_faces[face_num].name);
93  Send_With_Handling(ns, &sl);
94  } else {
95  SockList_AddString(&sl, "image2 ");
96  SockList_AddInt(&sl, face_num);
97  SockList_AddChar(&sl, fallback);
98  SockList_AddInt(&sl, facesets[fallback].faces[face_num].datalen);
99  SockList_AddData(&sl, facesets[fallback].faces[face_num].data, facesets[fallback].faces[face_num].datalen);
100  Send_With_Handling(ns, &sl);
101  }
102  ns->faces_sent[face_num] |= NS_FACESENT_FACE;
103  SockList_Term(&sl);
104 }
105 
113  SockList sl;
114  int i;
115 
116  SockList_Init(&sl);
117  SockList_AddPrintf(&sl, "replyinfo image_info\n%d\n%d\n", nrofpixmaps-1, bmaps_checksum);
118  for (i = 0; i < MAX_FACE_SETS; i++) {
119  if (facesets[i].prefix) {
120  SockList_AddPrintf(&sl, "%d:%s:%s:%d:%s:%s:%s",
121  i, facesets[i].prefix, facesets[i].fullname,
122  facesets[i].fallback, facesets[i].size,
123  facesets[i].extension, facesets[i].comment);
124  }
125  }
126  Send_With_Handling(ns, &sl);
127  SockList_Term(&sl);
128 }
129 
139 void send_image_sums(socket_struct *ns, char *params) {
140  int start, stop;
141  short i;
142  char *cp;
143  SockList sl;
144 
145  SockList_Init(&sl);
146 
147  start = atoi(params);
148  for (cp = params; *cp != '\0'; cp++)
149  if (*cp == ' ')
150  break;
151 
152  stop = atoi(cp);
153  if (stop < start
154  || *cp == '\0'
155  || (stop-start) > 1000
156  || stop >= nrofpixmaps) {
157  SockList_AddPrintf(&sl, "replyinfo image_sums %d %d", start, stop);
158  Send_With_Handling(ns, &sl);
159  SockList_Term(&sl);
160  return;
161  }
162  SockList_AddPrintf(&sl, "replyinfo image_sums %d %d ", start, stop);
163 
164  for (i = start; i <= stop; i++) {
165  int faceset;
166 
167  if (SockList_Avail(&sl) < 2+4+1+1+strlen(new_faces[i].name)+1) {
168  LOG(llevError, "send_image_sums: buffer overflow, rejecting range %d..%d\n", start, stop);
169  SockList_Reset(&sl);
170  SockList_AddPrintf(&sl, "replyinfo image_sums %d %d", start, stop);
171  Send_With_Handling(ns, &sl);
172  SockList_Term(&sl);
173  return;
174  }
175 
176  SockList_AddShort(&sl, i);
177  ns->faces_sent[i] |= NS_FACESENT_FACE;
178 
179  faceset = get_face_fallback(ns->faceset, i);
180  SockList_AddInt(&sl, facesets[faceset].faces[i].checksum);
181  SockList_AddChar(&sl, faceset);
182  SockList_AddLen8Data(&sl, new_faces[i].name, strlen(new_faces[i].name)+1);
183  }
184  Send_With_Handling(ns, &sl);
185  SockList_Term(&sl);
186 }
Error, serious thing.
Definition: logger.h:11
void SockList_AddPrintf(SockList *sl, const char *format,...)
Adds a printf like formatted string.
Definition: lowlevel.c:194
uint8_t faceset
Set the client is using, default 0.
Definition: newserver.h:129
void SockList_Reset(SockList *sl)
Resets the length of the stored data for writing.
Definition: lowlevel.c:66
#define NS_FACESENT_FACE
Bitmask for the faces_sent[] array - what portion of the face have we sent?
Definition: newserver.h:149
void SockList_Init(SockList *sl)
Initializes the SockList instance.
Definition: lowlevel.c:48
New_Face * new_faces
Contains face information, with names, numbers, magicmap color and such.
Definition: image.c:33
Defines various flags that both the new client and new server use.
void SockList_AddShort(SockList *sl, uint16_t data)
Adds a 16 bit value.
Definition: lowlevel.c:108
Socket structure, represents a client-server connection.
Definition: newserver.h:99
void SockList_AddInt(SockList *sl, uint32_t data)
Adds a 32 bit value.
Definition: lowlevel.c:119
Global type definitions and header inclusions.
char * host
Which host it is connected from (ip address).
Definition: newserver.h:110
unsigned int nrofpixmaps
Number of bitmaps loaded from the "bmaps" file.
Definition: image.c:45
uint32_t facecache
If true, client is caching images.
Definition: newserver.h:113
void SockList_AddData(SockList *sl, const void *data, size_t len)
Adds a data block.
Definition: lowlevel.c:159
Image-related structures.
void SockList_Term(SockList *sl)
Frees all resources allocated by a SockList instance.
Definition: lowlevel.c:58
void SockList_AddString(SockList *sl, const char *data)
Adds a string without length.
Definition: lowlevel.c:149
Defines various structures and values that are used for the new client server communication method...
size_t SockList_Avail(const SockList *sl)
Returns the available bytes in a SockList instance.
Definition: lowlevel.c:238
unsigned short uint16_t
Definition: win32.h:163
void SockList_AddChar(SockList *sl, char c)
Adds an 8 bit value.
Definition: lowlevel.c:98
void send_image_info(socket_struct *ns)
Sends the number of images, checksum of the face file, and the image_info file information.
Definition: image.c:112
void send_image_sums(socket_struct *ns, char *params)
Sends requested face information.
Definition: image.c:139
#define MAX_FACE_SETS
Maximum number of image sets the program will handle.
Definition: image.h:26
face_sets facesets[MAX_FACE_SETS]
All facesets.
Definition: image.c:47
Only for debugging purposes.
Definition: logger.h:13
EXTERN int bmaps_checksum
Definition: global.h:166
void SockList_AddLen8Data(SockList *sl, const void *data, size_t len)
Adds a data block prepended with an 8 bit length field.
Definition: lowlevel.c:171
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
Definition: logger.c:51
int get_face_fallback(int faceset, int imageno)
This returns the set we will actually use when sending a face.
Definition: image.c:602
void esrv_send_face(socket_struct *ns, uint16_t face_num, int nocache)
Sends a face to a client if they are in pixmap mode, nothing gets sent in bitmap mode.
Definition: image.c:70
Contains the base information we use to make up a packet we want to send.
Definition: newclient.h:680
uint8_t * faces_sent
This is a bitmap on sent face status.
Definition: newserver.h:106
void send_face_cmd(char *buff, int len, socket_struct *ns)
Client has requested pixmap that it somehow missed getting.
Definition: image.c:43
void Send_With_Handling(socket_struct *ns, SockList *sl)
Calls Write_To_Socket to send data to the client.
Definition: lowlevel.c:542