| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 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 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
void send_face_cmd(char *buff, int len, socket_struct *ns) { |
| 44 |
long tmpnum; |
| 45 |
uint16_t faceid; |
| 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 |
faceid = tmpnum&0xffff; |
| 54 |
|
| 55 |
if (faceid != 0) |
| 56 |
esrv_send_face(ns, get_face_by_id(faceid), 1); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
void esrv_send_face(socket_struct *ns, const Face *face, int nocache) { |
| 71 |
SockList sl; |
| 72 |
int fallback; |
| 73 |
|
| 74 |
if (face == NULL) { |
| 75 |
LOG(llevError, "esrv_send_face NULL??\n"); |
| 76 |
return; |
| 77 |
} |
| 78 |
|
| 79 |
SockList_Init(&sl); |
| 80 |
fallback = get_face_fallback(ns->faceset, face->number); |
| 81 |
|
| 82 |
if (facesets[fallback].faces[face->number].data == NULL) { |
| 83 |
LOG(llevError, "esrv_send_face: faces[%d].data == NULL\n", face->number); |
| 84 |
return; |
| 85 |
} |
| 86 |
|
| 87 |
if (ns->facecache && !nocache) { |
| 88 |
SockList_AddString(&sl, "face2 "); |
| 89 |
SockList_AddShort(&sl, face->number); |
| 90 |
SockList_AddChar(&sl, fallback); |
| 91 |
SockList_AddInt(&sl, facesets[fallback].faces[face->number].checksum); |
| 92 |
SockList_AddString(&sl, face->name); |
| 93 |
Send_With_Handling(ns, &sl); |
| 94 |
} else { |
| 95 |
SockList_AddString(&sl, "image2 "); |
| 96 |
SockList_AddInt(&sl, face->number); |
| 97 |
SockList_AddChar(&sl, fallback); |
| 98 |
SockList_AddInt(&sl, facesets[fallback].faces[face->number].datalen); |
| 99 |
SockList_AddData(&sl, facesets[fallback].faces[face->number].data, facesets[fallback].faces[face->number].datalen); |
| 100 |
Send_With_Handling(ns, &sl); |
| 101 |
} |
| 102 |
ns->faces_sent[face->number] |= NS_FACESENT_FACE; |
| 103 |
SockList_Term(&sl); |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
void send_image_info(socket_struct *ns) { |
| 113 |
SockList sl; |
| 114 |
int i; |
| 115 |
|
| 116 |
SockList_Init(&sl); |
| 117 |
SockList_AddPrintf(&sl, "replyinfo image_info\n%d\n%d\n", get_faces_count()-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 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
void send_image_sums(socket_struct *ns, char *params) { |
| 140 |
unsigned int start, stop; |
| 141 |
unsigned 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 >= get_faces_count()) { |
| 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 |
const Face *face = get_face_by_index(i); |
| 167 |
|
| 168 |
if (SockList_Avail(&sl) < 2+4+1+1+strlen(face->name)+1) { |
| 169 |
LOG(llevError, "send_image_sums: buffer overflow, rejecting range %d..%d\n", start, stop); |
| 170 |
SockList_Reset(&sl); |
| 171 |
SockList_AddPrintf(&sl, "replyinfo image_sums %d %d", start, stop); |
| 172 |
Send_With_Handling(ns, &sl); |
| 173 |
SockList_Term(&sl); |
| 174 |
return; |
| 175 |
} |
| 176 |
|
| 177 |
SockList_AddShort(&sl, i); |
| 178 |
ns->faces_sent[face->number] |= NS_FACESENT_FACE; |
| 179 |
|
| 180 |
faceset = get_face_fallback(ns->faceset, i); |
| 181 |
SockList_AddInt(&sl, facesets[faceset].faces[i].checksum); |
| 182 |
SockList_AddChar(&sl, faceset); |
| 183 |
SockList_AddLen8Data(&sl, face->name, strlen(face->name)+1); |
| 184 |
} |
| 185 |
Send_With_Handling(ns, &sl); |
| 186 |
SockList_Term(&sl); |
| 187 |
} |