Crossfire Server, Branch 1.12
R12190
|
00001 /* 00002 * static char *rcsid_init_c = 00003 * "$Id: image.c 11578 2009-02-23 22:02:27Z lalo $"; 00004 */ 00005 00006 /* 00007 CrossFire, A Multiplayer game for X-windows 00008 00009 Copyright (C) 2006 Mark Wedel & Crossfire Development Team 00010 Copyright (C) 1992 Frank Tore Johansen 00011 00012 This program is free software; you can redistribute it and/or modify 00013 it under the terms of the GNU General Public License as published by 00014 the Free Software Foundation; either version 2 of the License, or 00015 (at your option) any later version. 00016 00017 This program is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 GNU General Public License for more details. 00021 00022 You should have received a copy of the GNU General Public License 00023 along with this program; if not, write to the Free Software 00024 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00025 00026 The author can be reached via e-mail to crossfire-devel@real-time.com 00027 */ 00028 00040 #include <global.h> 00041 #include <sproto.h> 00042 00043 #include <newclient.h> 00044 #include <newserver.h> 00045 #include <loader.h> 00046 #include <image.h> 00047 00053 void set_face_mode_cmd(char *buf, int len, socket_struct *ns) { 00054 int mask = (atoi(buf)&CF_FACE_CACHE), mode = (atoi(buf)&~CF_FACE_CACHE); 00055 00056 if (mode == CF_FACE_NONE) { 00057 ns->facecache = 1; 00058 } else if (mode != CF_FACE_PNG) { 00059 SockList sl; 00060 00061 SockList_Init(&sl); 00062 SockList_AddPrintf(&sl, "drawinfo %d %s", NDI_RED, "Warning - send unsupported face mode. Will use Png"); 00063 Send_With_Handling(ns, &sl); 00064 SockList_Term(&sl); 00065 #ifdef ESRV_DEBUG 00066 LOG(llevDebug, "set_face_mode_cmd: Invalid mode from client: %d\n", mode); 00067 #endif 00068 } 00069 if (mask) { 00070 ns->facecache = 1; 00071 } 00072 } 00073 00080 void send_face_cmd(char *buff, int len, socket_struct *ns) { 00081 long tmpnum = atoi(buff); 00082 short facenum = tmpnum&0xffff; 00083 00084 if (facenum != 0) 00085 esrv_send_face(ns, facenum, 1); 00086 } 00087 00096 void esrv_send_face(socket_struct *ns, short face_num, int nocache) { 00097 SockList sl; 00098 int fallback; 00099 00100 if (face_num <= 0 || face_num >= nrofpixmaps) { 00101 LOG(llevError, "esrv_send_face (%d) out of bounds??\n", face_num); 00102 return; 00103 } 00104 00105 SockList_Init(&sl); 00106 fallback = get_face_fallback(ns->faceset, face_num); 00107 00108 if (facesets[fallback].faces[face_num].data == NULL) { 00109 LOG(llevError, "esrv_send_face: faces[%d].data == NULL\n", face_num); 00110 return; 00111 } 00112 00113 if (ns->facecache && !nocache) { 00114 SockList_AddString(&sl, "face2 "); 00115 SockList_AddShort(&sl, face_num); 00116 SockList_AddChar(&sl, fallback); 00117 SockList_AddInt(&sl, facesets[fallback].faces[face_num].checksum); 00118 SockList_AddString(&sl, new_faces[face_num].name); 00119 Send_With_Handling(ns, &sl); 00120 } else { 00121 SockList_AddString(&sl, "image2 "); 00122 SockList_AddInt(&sl, face_num); 00123 SockList_AddChar(&sl, fallback); 00124 SockList_AddInt(&sl, facesets[fallback].faces[face_num].datalen); 00125 SockList_AddData(&sl, facesets[fallback].faces[face_num].data, facesets[fallback].faces[face_num].datalen); 00126 Send_With_Handling(ns, &sl); 00127 } 00128 ns->faces_sent[face_num] |= NS_FACESENT_FACE; 00129 SockList_Term(&sl); 00130 } 00131 00138 void send_image_info(socket_struct *ns, char *params) { 00139 SockList sl; 00140 int i; 00141 00142 SockList_Init(&sl); 00143 SockList_AddPrintf(&sl, "replyinfo image_info\n%d\n%d\n", nrofpixmaps-1, bmaps_checksum); 00144 for (i = 0; i < MAX_FACE_SETS; i++) { 00145 if (facesets[i].prefix) { 00146 SockList_AddPrintf(&sl, "%d:%s:%s:%d:%s:%s:%s", 00147 i, facesets[i].prefix, facesets[i].fullname, 00148 facesets[i].fallback, facesets[i].size, 00149 facesets[i].extension, facesets[i].comment); 00150 } 00151 } 00152 Send_With_Handling(ns, &sl); 00153 SockList_Term(&sl); 00154 } 00155 00165 void send_image_sums(socket_struct *ns, char *params) { 00166 int start, stop; 00167 short i; 00168 char *cp; 00169 SockList sl; 00170 00171 SockList_Init(&sl); 00172 00173 start = atoi(params); 00174 for (cp = params; *cp != '\0'; cp++) 00175 if (*cp == ' ') 00176 break; 00177 00178 stop = atoi(cp); 00179 if (stop < start 00180 || *cp == '\0' 00181 || (stop-start) > 1000 00182 || stop >= nrofpixmaps) { 00183 SockList_AddPrintf(&sl, "replyinfo image_sums %d %d", start, stop); 00184 Send_With_Handling(ns, &sl); 00185 SockList_Term(&sl); 00186 return; 00187 } 00188 SockList_AddPrintf(&sl, "replyinfo image_sums %d %d ", start, stop); 00189 00190 for (i = start; i <= stop; i++) { 00191 int faceset; 00192 00193 if (SockList_Avail(&sl) < 2+4+1+1+strlen(new_faces[i].name)+1) { 00194 LOG(llevError, "send_image_sums: buffer overflow, rejecting range %d..%d\n", start, stop); 00195 SockList_Reset(&sl); 00196 SockList_AddPrintf(&sl, "replyinfo image_sums %d %d", start, stop); 00197 Send_With_Handling(ns, &sl); 00198 SockList_Term(&sl); 00199 return; 00200 } 00201 00202 SockList_AddShort(&sl, i); 00203 ns->faces_sent[i] |= NS_FACESENT_FACE; 00204 00205 faceset = get_face_fallback(ns->faceset, i); 00206 SockList_AddInt(&sl, facesets[faceset].faces[i].checksum); 00207 SockList_AddChar(&sl, faceset); 00208 SockList_AddLen8Data(&sl, new_faces[i].name, strlen(new_faces[i].name)+1); 00209 } 00210 Send_With_Handling(ns, &sl); 00211 SockList_Term(&sl); 00212 }