ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/image.C
(Generate patch)

Comparing deliantra/server/socket/image.C (file contents):
Revision 1.59 by root, Thu Sep 17 01:57:31 2009 UTC vs.
Revision 1.74 by root, Sun Nov 11 18:21:21 2012 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001,2007 Mark Wedel 5 * Copyright (©) 2001 Mark Wedel
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24/** \file 25/*
25 * Image related communication 26 * Image related communication
26 *
27 * \date 2003-12-02
28 * 27 *
29 * This file deals with the image related communication to the 28 * This file deals with the image related communication to the
30 * client. I've located all the functions in this file - this 29 * client. I've located all the functions in this file - this
31 * localizes it more, and means that we don't need to declare 30 * localizes it more, and means that we don't need to declare
32 * things like all the structures as globals. 31 * things like all the structures as globals.
50 49
51 sscanf (buf, "%d %d", &idx, &pri); 50 sscanf (buf, "%d %d", &idx, &pri);
52 51
53 //TODO: somehow fetch default priority from send_fx here 52 //TODO: somehow fetch default priority from send_fx here
54 53
55 const facedata *d = face_data (idx, ns->faceset); 54 const faceinfo *f = face_info (idx);
56 55
57 if (!d) 56 if (!f)
58 return; // doh 57 return; // doh
59 58
59 int set = ns->tileset;
60
61 if (!f->face [set].chksum_len)
62 set = 0;
63
64 /* cfperl_ix calls cf::face::ix which loads the data */
65 /* and then calls cf::client::send_ix to actually queue the ix */
66 cfperl_ix (ns, set, idx, pri);
67}
68
69void
70client::ix_send (faceidx idx, sint16 pri, SV *data_sv)
71{
72 STRLEN size;
73 char *data = SvPVbyte (data_sv, size);
60 client::ixsend ix; 74 ixsend ix;
61 75
62 ix.pri = pri; 76 ix.pri = pri;
63 ix.idx = idx; 77 ix.idx = idx;
64 ix.ofs = d->data.size (); 78 ix.ofs = size;
79 ix.data = (uint8 *)data;
80 ix.data_sv = SvREFCNT_inc (data_sv);
65 81
66 auto (pos, ns->ixface.end ()); 82 auto (pos, ixface.end ());
67 83
68 // the by far most common case will be to insert 84 // the by far most common case will be to insert
69 // near the end, so little looping. 85 // near the end, so little looping.
70 while (pos != ns->ixface.begin ()) 86 while (pos != ixface.begin ())
71 { 87 {
72 --pos; 88 --pos;
73 89
74 // sort within 2k bins, to slightly prefer smaller images 90 // sort within 2k bins, to slightly prefer smaller images
75 if (pri > pos->pri || (pri == pos->pri && (ix.ofs >> 11) <= (pos->ofs >> 11))) 91 if (pri > pos->pri || (pri == pos->pri && (ix.ofs >> 11) <= (pos->ofs >> 11)))
77 ++pos; 93 ++pos;
78 break; 94 break;
79 } 95 }
80 } 96 }
81 97
82 ns->ixface.insert (pos, ix); 98 ixface.insert (pos, ix);
83 99
84#if 0 100#if 0
85 for (auto (i, ns->ixface.begin ()); i != ns->ixface.end (); ++i) 101 for (auto (i, ixface.begin ()); i != ixface.end (); ++i)
86 fprintf (stderr, "<%d,%d> ", i->pri, i->ofs); 102 fprintf (stderr, "<%d,%d> ", i->pri, i->ofs);
87 fprintf (stderr, "\n"); 103 fprintf (stderr, "\n");
88#endif 104#endif
89} 105}
90 106
107void
108client::ix_pop ()
109{
110 ixsend &ix = ixface.back ();
111
112 SvREFCNT_dec (ix.data_sv);
113
114 ixface.pop_back ();
115}
116
91/** 117/**
92 * Sends a face to a client if they are in pixmap mode 118 * Sends a face offer (fx) to a client.
93 * nothing gets sent in bitmap mode.
94 * If nocache is true (nonzero), ignore the cache setting from the client - 119 * If nocache is true (nonzero), ignore the cache setting from the client -
95 * this is needed for the askface, in which we really do want to send the 120 * this is needed for the askface, in which we really do want to send the
96 * face (and askface is the only place that should be setting it). Otherwise, 121 * face (and askface is the only place that should be setting it). Otherwise,
97 * we look at the facecache, and if set, send the image name. 122 * we look at the facecache, and if set, send the image name.
98 */ 123 */
109 { 134 {
110 LOG (llevError | logBacktrace, "client::send_face (%d) out of bounds??\n", facenum); 135 LOG (llevError | logBacktrace, "client::send_face (%d) out of bounds??\n", facenum);
111 return; 136 return;
112 } 137 }
113 138
114 // refuse to send non-image faces 139 // refuse to send non-image faces unless requested
115 if (!fx_want [f->type]) 140 if (!fx_want [f->type])
116 return; 141 return;
117 142
118 if (faces_sent [facenum]) 143 if (faces_sent [facenum])
119 return; 144 return;
120 145
121 faces_sent[facenum] = true; 146 faces_sent [facenum] = true;
122 147
123 fxface.push_back (facenum); 148 fxface.push_back (facenum);
124} 149}
125 150
126void client::flush_fx () 151void client::flush_fx ()
143 168
144 fx << ber32 (0) 169 fx << ber32 (0)
145 << uint8 (1) << uint8 (type); 170 << uint8 (1) << uint8 (type);
146 } 171 }
147 172
148 const facedata *d = f->data (faceset); 173 const facedata *d = f->data (tileset);
149 174
150 fx << ber32 (facenum) 175 fx << ber32 (facenum)
151 << data8 (d->chksum, CHKSUM_SIZE); 176 << data8 (d->chksum, d->chksum_len);
152 177
153 if (smoothing) 178 if (smoothing)
154 { 179 {
155 faceinfo *f = face_info (facenum); 180 faceinfo *f = face_info (facenum);
156 181
164 } 189 }
165 } 190 }
166 } 191 }
167 } 192 }
168 while (!fxface.empty () 193 while (!fxface.empty ()
169 && fx.room () > ber32::size + CHKSUM_SIZE + 1 + 3 /* type switch */ 194 && fx.room () > ber32::size + CHKSUM_MAXLEN + 1 + 3 /* type switch */
170 && sx.room () > ber32::size * 3); 195 && sx.room () > ber32::size * 3);
171 196
172 send_packet (fx); 197 send_packet (fx);
173 if (sx.length () > 3) send_packet (sx); 198 if (sx.length () > 3) send_packet (sx);
174 } 199 }
201 */ 226 */
202void 227void
203client::send_animation (short anim_num) 228client::send_animation (short anim_num)
204{ 229{
205 /* Do some checking on the anim_num we got. Note that the animations 230 /* Do some checking on the anim_num we got. Note that the animations
206 * are added in contigous order, so if the number is in the valid 231 * are added in contiguous order, so if the number is in the valid
207 * range, it must be a valid animation. 232 * range, it must be a valid animation.
208 */ 233 */
209 if (anim_num < 0 || anim_num >= animations.size ()) 234 if (anim_num < 0 || anim_num >= animations.size ())
210 { 235 {
211 LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num); 236 LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num);
221 * the face itself) down to the client. 246 * the face itself) down to the client.
222 */ 247 */
223 for (int i = 0; i < animations[anim_num].num_animations; i++) 248 for (int i = 0; i < animations[anim_num].num_animations; i++)
224 { 249 {
225 send_face (animations[anim_num].faces[i], -20); 250 send_face (animations[anim_num].faces[i], -20);
226 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ 251 sl << uint16 (animations[anim_num].faces[i]);
227 } 252 }
228 253
229 send_packet (sl); 254 send_packet (sl);
230 255
231 anims_sent[anim_num] = 1; 256 anims_sent[anim_num] = 1;
232} 257}
233 258
234/**
235 * Sends the number of images, checksum of the face file,
236 * and the image_info file information. See the doc/Developers/protocol
237 * if you want further detail.
238 */
239void 259void
240send_image_info (client *ns, char *params) 260client::invalidate_face (faceidx idx)
241{ 261{
242 packet sl; 262 faces_sent [idx] = false;
243 263 force_newmap = true;
244 //TODO: second parameter is a checksum, but it makes no sense in this current framework
245 sl.printf ("replyinfo image_info\n%d\n%u\n", MAX_FACES, 0);
246
247 sl << "0:base:standard:0:32x32:none:The old 32x32 faceset.\n";
248
249 ns->send_packet (sl);
250} 264}
251 265
252/**
253 * Sends requested face information.
254 * \param ns socket to send to
255 * \param params contains first and last index of face
256 *
257 * For each image in [start..stop] sends
258 * - checksum
259 * - name
260 */
261void 266void
262send_image_sums (client *ns, char *params) 267client::invalidate_all_faces ()
263{ 268{
264 int start, stop; 269 faces_sent.reset ();
265 char *cp; 270 force_newmap = true;
266
267 packet sl;
268
269 start = atoi (params);
270 for (cp = params; *cp != '\0'; cp++)
271 if (*cp == ' ')
272 break;
273
274 stop = atoi (cp);
275 if (stop < start || *cp == '\0' || (stop - start) > 1000 || stop >= MAX_FACES)
276 {
277 sl.printf ("replyinfo image_sums %d %d", start, stop);
278 ns->send_packet (sl);
279 sl.reset ();
280 return;
281 }
282
283 sl.printf ("replyinfo image_sums %d %d ", start, stop);
284
285 for (int i = start; i <= stop && i < faces.size (); i++)
286 if (const faceinfo *f = face_info (i))
287 if (ns->fx_want [f->type])
288 {
289 ns->faces_sent[i] = true;
290
291 const facedata *d = f->data (ns->faceset);
292
293 if (sl.room () < 2 + 4 + 1 + d->data.size () + 1)
294 break;
295
296 sl << uint16 (i)
297 << uint32 (0) // checksum
298 << uint8 (ns->faceset);
299
300 for (int i = 0; i < CHKSUM_SIZE; ++i)
301 sl.printf ("%02x", d->chksum [i]);
302
303 sl << uint8 (0);
304 }
305
306 /* It would make more sense to catch this pre-emptively in the code above.
307 * however, if this really happens, we probably just want to cut down the
308 * size to less than 1000, since that is what we claim the protocol would
309 * support.
310 */
311 //TODO: taken care of above, should simply abort or make sure the above code is correct
312 if (sl.length () > MAXSOCKBUF)
313 {
314 LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.length (), MAXSOCKBUF);
315 abort ();
316 }
317
318 ns->send_packet (sl);
319} 271}
320 272

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines