1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
3 | |
3 | |
|
|
4 | Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | |
7 | This program is free software; you can redistribute it and/or modify |
8 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | it under the terms of the GNU General Public License as published by |
… | |
… | |
30 | * This containes item logic for client/server. It doesn't contain |
31 | * This containes item logic for client/server. It doesn't contain |
31 | * the actual commands that send the data, but does contain |
32 | * the actual commands that send the data, but does contain |
32 | * the logic for what items should be sent. |
33 | * the logic for what items should be sent. |
33 | */ |
34 | */ |
34 | |
35 | |
35 | |
|
|
36 | #include <global.h> |
36 | #include <global.h> |
37 | #include <object.h> /* LOOK_OBJ */ |
37 | #include <object.h> /* LOOK_OBJ */ |
38 | #include <sproto.h> |
38 | #include <sproto.h> |
39 | |
39 | |
40 | /** This is the maximum number of bytes we expect any one item to take up */ |
40 | /** This is the maximum number of bytes we expect any one item to take up */ |
41 | #define MAXITEMLEN 300 |
41 | #define MAXITEMLEN 300 |
|
|
42 | |
|
|
43 | #if 0 |
|
|
44 | tag_t |
|
|
45 | client_container::tag () const |
|
|
46 | { |
|
|
47 | switch (type) |
|
|
48 | { |
|
|
49 | case CC_INVENTORY: |
|
|
50 | return ns->pl->count; |
|
|
51 | case CC_MAPSPACE: |
|
|
52 | return 0; |
|
|
53 | case CC_CONTAINER: |
|
|
54 | return env->count; |
|
|
55 | } |
|
|
56 | |
|
|
57 | abort (); |
|
|
58 | } |
|
|
59 | |
|
|
60 | void |
|
|
61 | client_container::clear () |
|
|
62 | { |
|
|
63 | switch (type) |
|
|
64 | { |
|
|
65 | case CC_INVENTORY: |
|
|
66 | abort (); |
|
|
67 | |
|
|
68 | case CC_MAPSPACE: |
|
|
69 | case CC_CONTAINER: |
|
|
70 | ns->send_packet_printf ("delinv %d", tag ()); |
|
|
71 | break; |
|
|
72 | } |
|
|
73 | |
|
|
74 | for (iterator i = begin (); i != end (); ++i) |
|
|
75 | i->op->seen_by = 0; |
|
|
76 | |
|
|
77 | vector< refitem, slice_allocator<refitem> >::clear (); |
|
|
78 | } |
|
|
79 | |
|
|
80 | inline iterator |
|
|
81 | client_container::merge_item (iterator i, object *op) |
|
|
82 | { |
|
|
83 | if (i != end () && i->op == op) |
|
|
84 | return ++i; |
|
|
85 | |
|
|
86 | if (op->seen_by) |
|
|
87 | return; // seen by another entity already |
|
|
88 | |
|
|
89 | op->seen_by = this; |
|
|
90 | |
|
|
91 | refitem ref; |
|
|
92 | ref.op = op; |
|
|
93 | |
|
|
94 | return insert (i, ref); |
|
|
95 | } |
|
|
96 | |
|
|
97 | void |
|
|
98 | client_container::update (int offset) |
|
|
99 | { |
|
|
100 | iterator i = begin (); |
|
|
101 | |
|
|
102 | switch (type) |
|
|
103 | { |
|
|
104 | case CC_INVENTORY: |
|
|
105 | case CC_CONTAINER: |
|
|
106 | { |
|
|
107 | object *env = type == CC_INVENTORY |
|
|
108 | ? ns->pl->ob |
|
|
109 | : this->env; |
|
|
110 | |
|
|
111 | // pass 1, erase all objects no longer in container |
|
|
112 | for (iterator j = begin (); j != end (); ++j) |
|
|
113 | if (j->op->env != env) |
|
|
114 | { |
|
|
115 | j->op->seen_by = 0; |
|
|
116 | erase (j); |
|
|
117 | } |
|
|
118 | |
|
|
119 | // pass 2 merge items |
|
|
120 | for (object *op = env->inv; op; op = op->below) |
|
|
121 | { |
|
|
122 | if (--offset < 0) |
|
|
123 | i = merge_item (i, op); |
|
|
124 | else if (offset < -FLOORBOX_PAGESIZE) |
|
|
125 | break; |
|
|
126 | } |
|
|
127 | } |
|
|
128 | break; |
|
|
129 | |
|
|
130 | case CC_MAPSPACE: |
|
|
131 | { |
|
|
132 | // pass 1, erase all objects no longer on space |
|
|
133 | for (iterator j = begin (); j != end (); ++j) |
|
|
134 | if (j->op->x != x || j->op->y != y || j->op->map != map) |
|
|
135 | { |
|
|
136 | j->op->seen_by = 0; |
|
|
137 | erase (j); |
|
|
138 | } |
|
|
139 | |
|
|
140 | // pass 2 merge items |
|
|
141 | for (object *op = GET_MAP_OB (map, x, y); op; op = op->above) |
|
|
142 | { |
|
|
143 | if (--offset < 0) |
|
|
144 | i = merge_item (i, op); |
|
|
145 | else if (offset < -FLOORBOX_PAGESIZE) |
|
|
146 | break; |
|
|
147 | } |
|
|
148 | } |
|
|
149 | break; |
|
|
150 | } |
|
|
151 | |
|
|
152 | // pass 3, erase all extra items |
|
|
153 | for (iterator j = i; j != end (); ++j) |
|
|
154 | j->op->seen_by = 0; |
|
|
155 | |
|
|
156 | if (i != end ()) |
|
|
157 | erase (i, end ()); |
|
|
158 | } |
|
|
159 | |
|
|
160 | void |
|
|
161 | client_container::set_mapspace (maptile *map, int x, int y) |
|
|
162 | { |
|
|
163 | if (type == CC_MAPSPACE |
|
|
164 | && this->map == map |
|
|
165 | && this->x == x |
|
|
166 | && this->y == y) |
|
|
167 | return; |
|
|
168 | |
|
|
169 | clear (); |
|
|
170 | |
|
|
171 | type = CC_MAPSPACE; |
|
|
172 | this->map = map; |
|
|
173 | this->x = x; |
|
|
174 | this->y = y; |
|
|
175 | } |
|
|
176 | |
|
|
177 | void |
|
|
178 | client_container::set_container (object *env) |
|
|
179 | { |
|
|
180 | } |
|
|
181 | #endif |
42 | |
182 | |
43 | /******************************************************************************* |
183 | /******************************************************************************* |
44 | * |
184 | * |
45 | * Functions related to sending object data to the client. |
185 | * Functions related to sending object data to the client. |
46 | * |
186 | * |
47 | ******************************************************************************/ |
187 | ******************************************************************************/ |
48 | |
188 | |
49 | /** |
189 | /** |
50 | * This is a similar to query_name, but returns flags |
190 | * This is a similar to query_name, but returns flags |
51 | * to be sended to client. |
191 | * to be sent to client. |
52 | */ |
192 | */ |
53 | unsigned int |
193 | unsigned int |
54 | query_flags (object *op) |
194 | query_flags (object *op) |
55 | { |
195 | { |
56 | unsigned int flags = 0; |
196 | unsigned int flags = 0; |
57 | |
197 | |
58 | if (QUERY_FLAG (op, FLAG_APPLIED)) |
198 | if (QUERY_FLAG (op, FLAG_APPLIED)) |
59 | { |
199 | { |
60 | switch (op->type) |
200 | switch (op->type) |
61 | { |
201 | { |
62 | case BOW: |
202 | case BOW: |
63 | case WAND: |
203 | case WAND: |
64 | case ROD: |
204 | case ROD: |
65 | case HORN: |
205 | case HORN: |
66 | flags = a_readied; |
206 | flags = a_readied; |
67 | break; |
207 | break; |
68 | case WEAPON: |
208 | case WEAPON: |
69 | flags = a_wielded; |
209 | flags = a_wielded; |
70 | break; |
210 | break; |
71 | case SKILL: |
211 | case SKILL: |
72 | case ARMOUR: |
212 | case ARMOUR: |
73 | case HELMET: |
213 | case HELMET: |
74 | case SHIELD: |
214 | case SHIELD: |
75 | case RING: |
215 | case RING: |
76 | case BOOTS: |
216 | case BOOTS: |
77 | case GLOVES: |
217 | case GLOVES: |
78 | case AMULET: |
218 | case AMULET: |
79 | case GIRDLE: |
219 | case GIRDLE: |
80 | case BRACERS: |
220 | case BRACERS: |
81 | case CLOAK: |
221 | case CLOAK: |
82 | flags = a_worn; |
222 | flags = a_worn; |
83 | break; |
223 | break; |
84 | case CONTAINER: |
224 | case CONTAINER: |
85 | flags = a_active; |
225 | flags = a_active; |
86 | break; |
226 | break; |
87 | default: |
227 | default: |
88 | flags = a_applied; |
228 | flags = a_applied; |
89 | break; |
229 | break; |
90 | } |
230 | } |
91 | } |
231 | } |
|
|
232 | |
92 | if (op->type == CONTAINER && ((op->env && op->env->container == op) || (!op->env && QUERY_FLAG (op, FLAG_APPLIED)))) |
233 | if (op->type == CONTAINER && ((op->env && op->env->container == op) || (!op->env && QUERY_FLAG (op, FLAG_APPLIED)))) |
93 | flags |= F_OPEN; |
234 | flags |= F_OPEN; |
94 | |
235 | |
95 | if (QUERY_FLAG (op, FLAG_KNOWN_CURSED)) |
236 | if (QUERY_FLAG (op, FLAG_KNOWN_CURSED)) |
96 | { |
237 | { |
97 | if (QUERY_FLAG (op, FLAG_DAMNED)) |
238 | if (QUERY_FLAG (op, FLAG_DAMNED)) |
98 | flags |= F_DAMNED; |
239 | flags |= F_DAMNED; |
99 | else if (QUERY_FLAG (op, FLAG_CURSED)) |
240 | else if (QUERY_FLAG (op, FLAG_CURSED)) |
100 | flags |= F_CURSED; |
241 | flags |= F_CURSED; |
101 | } |
242 | } |
|
|
243 | |
102 | if (QUERY_FLAG (op, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (op, FLAG_IDENTIFIED)) |
244 | if (QUERY_FLAG (op, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (op, FLAG_IDENTIFIED)) |
103 | flags |= F_MAGIC; |
245 | flags |= F_MAGIC; |
104 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
246 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
105 | flags |= F_UNPAID; |
247 | flags |= F_UNPAID; |
106 | if (QUERY_FLAG (op, FLAG_INV_LOCKED)) |
248 | if (QUERY_FLAG (op, FLAG_INV_LOCKED)) |
… | |
… | |
185 | SET_FLAG (head, FLAG_CLIENT_SENT); |
327 | SET_FLAG (head, FLAG_CLIENT_SENT); |
186 | } |
328 | } |
187 | |
329 | |
188 | |
330 | |
189 | /** |
331 | /** |
190 | * Send the look window. Don't need to do animations here |
332 | * Send the look window. Don't need to do animations here |
191 | * This sends all the faces to the client, not just updates. This is |
333 | * This sends all the faces to the client, not just updates. This is |
192 | * because object ordering would otherwise be inconsistent |
334 | * because object ordering would otherwise be inconsistent. |
193 | */ |
335 | */ |
194 | |
|
|
195 | void |
336 | void |
196 | esrv_draw_look (object *pl) |
337 | esrv_draw_look (object *pl) |
197 | { |
338 | { |
198 | object *tmp, *last; |
339 | object *tmp, *last; |
199 | int got_one = 0, start_look = 0, end_look = 0; |
340 | int got_one = 0, start_look = 0, end_look = 0; |
200 | char buf[MAX_BUF]; |
341 | char buf[MAX_BUF]; |
201 | |
342 | |
202 | if (!pl->contr->socket->update_look) |
343 | if (!pl->contr->ns->update_look) |
203 | { |
344 | { |
204 | LOG (llevDebug, "esrv_draw_look called when update_look was not set\n"); |
345 | LOG (llevDebug, "esrv_draw_look called when update_look was not set\n"); |
205 | return; |
346 | return; |
206 | } |
347 | } |
207 | else |
348 | else |
208 | pl->contr->socket->update_look = 0; |
349 | pl->contr->ns->update_look = 0; |
209 | |
350 | |
210 | if (QUERY_FLAG (pl, FLAG_REMOVED) |
351 | if (QUERY_FLAG (pl, FLAG_REMOVED) |
211 | || !pl->map |
352 | || !pl->map |
212 | || pl->map->in_memory != MAP_IN_MEMORY |
353 | || pl->map->in_memory != MAP_IN_MEMORY |
213 | || out_of_map (pl->map, pl->x, pl->y)) |
354 | || out_of_map (pl->map, pl->x, pl->y)) |
214 | return; |
355 | return; |
215 | |
356 | |
216 | for (tmp = get_map_ob (pl->map, pl->x, pl->y); tmp && tmp->above; tmp = tmp->above) |
357 | for (tmp = GET_MAP_OB (pl->map, pl->x, pl->y); tmp && tmp->above; tmp = tmp->above) |
217 | ; |
358 | ; |
218 | |
359 | |
|
|
360 | pl->contr->ns->send_packet ("delinv 0"); |
|
|
361 | |
219 | packet sl; |
362 | packet sl; |
220 | |
|
|
221 | pl->contr->socket->send_packet ("delinv 0"); |
|
|
222 | |
|
|
223 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
363 | sl.printf ("item%d ", pl->contr->ns->itemcmd); |
224 | |
364 | |
225 | sl << uint32 (0); |
365 | sl << uint32 (0); |
226 | |
366 | |
227 | if (!(pl->contr->socket->faces_sent[empty_face->number] & NS_FACESENT_FACE)) |
367 | if (!(pl->contr->ns->faces_sent[empty_face->number] & NS_FACESENT_FACE)) |
228 | esrv_send_face (pl->contr->socket, empty_face->number, 0); |
368 | esrv_send_face (pl->contr->ns, empty_face->number, 0); |
229 | |
369 | |
230 | if (pl->contr->socket->look_position) |
370 | if (pl->contr->ns->look_position) |
231 | { |
371 | { |
232 | char buf[80]; |
372 | char buf[80]; |
233 | snprintf (buf, 80, "Apply this to see %d previous items", NUM_LOOK_OBJECTS); |
373 | snprintf (buf, 80, "Apply this to see %d previous items", FLOORBOX_PAGESIZE); |
234 | |
374 | |
235 | sl << uint32 (0x80000000 | (pl->contr->socket->look_position - NUM_LOOK_OBJECTS)) |
375 | sl << uint32 (0x80000000 | (pl->contr->ns->look_position - FLOORBOX_PAGESIZE)) |
236 | << uint32 (0) |
376 | << uint32 (0) |
237 | << sint32 (-1) |
377 | << sint32 (-1) |
238 | << uint32 (empty_face->number) |
378 | << uint32 (empty_face->number) |
239 | << data8 (buf) |
379 | << data8 (buf) |
240 | << uint16 (0) |
380 | << uint16 (0) |
241 | << uint8 (0) |
381 | << uint8 (0) |
242 | << uint32 (0); |
382 | << uint32 (0); |
243 | |
383 | |
244 | if (pl->contr->socket->itemcmd == 2) |
384 | if (pl->contr->ns->itemcmd == 2) |
245 | sl << uint16 (0); |
385 | sl << uint16 (0); |
246 | } |
386 | } |
247 | |
387 | |
248 | for (last = NULL; tmp != last; tmp = tmp->below) |
388 | for (last = NULL; tmp != last; tmp = tmp->below) |
249 | { |
389 | { |
… | |
… | |
256 | last = last->below; |
396 | last = last->below; |
257 | } |
397 | } |
258 | |
398 | |
259 | if (LOOK_OBJ (tmp)) |
399 | if (LOOK_OBJ (tmp)) |
260 | { |
400 | { |
261 | if (++start_look < pl->contr->socket->look_position) |
401 | if (++start_look < pl->contr->ns->look_position) |
262 | continue; |
402 | continue; |
263 | |
403 | |
264 | end_look++; |
404 | end_look++; |
265 | |
405 | |
266 | if (end_look > NUM_LOOK_OBJECTS) |
406 | if (end_look > FLOORBOX_PAGESIZE) |
267 | { |
407 | { |
268 | /* What we basically do is make a 'fake' object - when the user applies it, |
408 | /* What we basically do is make a 'fake' object - when the user applies it, |
269 | * we notice the special tag the object has, and act accordingly. |
409 | * we notice the special tag the object has, and act accordingly. |
270 | */ |
410 | */ |
271 | sl << uint32 (0x80000000 | (pl->contr->socket->look_position + NUM_LOOK_OBJECTS)) |
411 | sl << uint32 (0x80000000 | (pl->contr->ns->look_position + FLOORBOX_PAGESIZE)) |
272 | << uint32 (0) |
412 | << uint32 (0) |
273 | << uint32 ((uint32) - 1) |
413 | << uint32 ((uint32) - 1) |
274 | << uint32 (empty_face->number) |
414 | << uint32 (empty_face->number) |
275 | << data8 ("Apply this to see next group of items") |
415 | << data8 ("Apply this to see next group of items") |
276 | << uint16 (0) |
416 | << uint16 (0) |
277 | << uint8 (0) |
417 | << uint8 (0) |
278 | << uint32 (0); |
418 | << uint32 (0); |
279 | |
419 | |
280 | if (pl->contr->socket->itemcmd == 2) |
420 | if (pl->contr->ns->itemcmd == 2) |
281 | sl << uint16 (0); |
421 | sl << uint16 (0); |
282 | |
422 | |
283 | break; |
423 | break; |
284 | } |
424 | } |
285 | |
425 | |
286 | if (tmp->head) |
426 | if (tmp->head) |
287 | head = tmp->head; |
427 | head = tmp->head; |
288 | else |
428 | else |
289 | head = tmp; |
429 | head = tmp; |
290 | |
430 | |
291 | add_object_to_socklist (*pl->contr->socket, sl, head); |
431 | add_object_to_socklist (*pl->contr->ns, sl, head); |
292 | got_one++; |
432 | got_one++; |
293 | |
433 | |
294 | if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN)) |
434 | if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN)) |
295 | { |
435 | { |
296 | pl->contr->socket->send_packet (sl); |
436 | pl->contr->ns->send_packet (sl); |
297 | |
437 | |
298 | sl.reset (); |
438 | sl.reset (); |
299 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
439 | sl.printf ("item%d ", pl->contr->ns->itemcmd); |
300 | sl << uint32 (0); |
440 | sl << uint32 (0); |
301 | got_one = 0; |
441 | got_one = 0; |
302 | } |
442 | } |
303 | } /* If LOOK_OBJ() */ |
443 | } |
304 | } |
444 | } |
305 | |
445 | |
306 | if (got_one) |
446 | if (got_one) |
307 | pl->contr->socket->send_packet (sl); |
447 | pl->contr->ns->send_packet (sl); |
308 | |
448 | |
309 | } |
449 | } |
310 | |
450 | |
311 | /** |
451 | /** |
312 | * Sends whole inventory. |
452 | * Sends whole inventory. |
… | |
… | |
315 | esrv_send_inventory (object *pl, object *op) |
455 | esrv_send_inventory (object *pl, object *op) |
316 | { |
456 | { |
317 | object *tmp; |
457 | object *tmp; |
318 | int got_one = 0; |
458 | int got_one = 0; |
319 | |
459 | |
|
|
460 | |
|
|
461 | pl->contr->ns->send_packet_printf ("delinv %d", op->count); |
|
|
462 | |
320 | packet sl; |
463 | packet sl; |
321 | |
|
|
322 | sl.printf ("delinv %d", op->count); |
|
|
323 | pl->contr->socket->send_packet (sl); |
|
|
324 | |
|
|
325 | sl.reset (); |
|
|
326 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
464 | sl.printf ("item%d ", pl->contr->ns->itemcmd); |
327 | |
465 | |
328 | sl << uint32 (op->count); |
466 | sl << uint32 (op->count); |
329 | |
467 | |
330 | for (tmp = op->inv; tmp; tmp = tmp->below) |
468 | for (tmp = op->inv; tmp; tmp = tmp->below) |
331 | { |
469 | { |
… | |
… | |
336 | else |
474 | else |
337 | head = tmp; |
475 | head = tmp; |
338 | |
476 | |
339 | if (LOOK_OBJ (head)) |
477 | if (LOOK_OBJ (head)) |
340 | { |
478 | { |
341 | add_object_to_socklist (*pl->contr->socket, sl, head); |
479 | add_object_to_socklist (*pl->contr->ns, sl, head); |
342 | |
480 | |
343 | got_one++; |
481 | got_one++; |
344 | |
482 | |
345 | /* IT is possible for players to accumulate a huge amount of |
483 | /* IT is possible for players to accumulate a huge amount of |
346 | * items (especially with some of the bags out there) to |
484 | * items (especially with some of the bags out there) to |
347 | * overflow the buffer. IF so, send multiple item commands. |
485 | * overflow the buffer. IF so, send multiple item commands. |
348 | */ |
486 | */ |
349 | if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN)) |
487 | if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN)) |
350 | { |
488 | { |
351 | pl->contr->socket->send_packet (sl); |
489 | pl->contr->ns->send_packet (sl); |
352 | |
490 | |
353 | sl.reset (); |
491 | sl.reset (); |
354 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
492 | sl.printf ("item%d ", pl->contr->ns->itemcmd); |
355 | sl << uint32 (op->count); |
493 | sl << uint32 (op->count); |
356 | got_one = 0; |
494 | got_one = 0; |
357 | } |
495 | } |
358 | } /* If LOOK_OBJ() */ |
496 | } /* If LOOK_OBJ() */ |
359 | } |
497 | } |
360 | |
498 | |
361 | if (got_one) |
499 | if (got_one) |
362 | pl->contr->socket->send_packet (sl); |
500 | pl->contr->ns->send_packet (sl); |
363 | |
|
|
364 | } |
501 | } |
365 | |
502 | |
366 | /** |
503 | /** |
367 | * Updates object *op for player *pl. |
504 | * Updates object *op for player *pl. |
368 | * |
505 | * |
… | |
… | |
383 | * is hopefully in the same place, so the client should preserve |
520 | * is hopefully in the same place, so the client should preserve |
384 | * order. |
521 | * order. |
385 | */ |
522 | */ |
386 | } |
523 | } |
387 | |
524 | |
|
|
525 | client *ns = pl->contr->ns; |
|
|
526 | if (!ns) |
|
|
527 | return; |
|
|
528 | |
388 | if (!QUERY_FLAG (op, FLAG_CLIENT_SENT)) |
529 | if (!QUERY_FLAG (op, FLAG_CLIENT_SENT)) |
389 | { |
530 | { |
390 | /* FLAG_CLIENT_SENT is debug only. We are using it to see where |
531 | /* FLAG_CLIENT_SENT is debug only. We are using it to see where |
391 | * this is happening - we can set a breakpoint here in the debugger |
532 | * this is happening - we can set a breakpoint here in the debugger |
392 | * and track back the call. |
533 | * and track back the call. |
393 | */ |
534 | */ |
394 | LOG (llevDebug, "We have not sent item %s (%d)\n", &op->name, op->count); |
535 | LOG (llevDebug, "We have not sent item %s (%d)\n", &op->name, op->count); |
395 | } |
536 | } |
396 | |
537 | |
397 | packet sl; |
538 | packet sl ("upditem"); |
398 | |
539 | |
399 | sl << "upditem " |
|
|
400 | << uint8 (flags); |
540 | sl << uint8 (flags); |
401 | |
541 | |
402 | if (op->head) |
542 | if (op->head) |
403 | op = op->head; |
543 | op = op->head; |
404 | |
544 | |
405 | sl << uint32 (op->count); |
545 | sl << uint32 (op->count); |
… | |
… | |
415 | sint32 weight = WEIGHT (op); |
555 | sint32 weight = WEIGHT (op); |
416 | |
556 | |
417 | sl << uint32 (QUERY_FLAG (op, FLAG_NO_PICK) ? -1 : weight); |
557 | sl << uint32 (QUERY_FLAG (op, FLAG_NO_PICK) ? -1 : weight); |
418 | |
558 | |
419 | if (pl == op) |
559 | if (pl == op) |
420 | op->contr->last_weight = weight; |
560 | ns->last_weight = weight; |
421 | } |
561 | } |
422 | |
562 | |
423 | if (flags & UPD_FACE) |
563 | if (flags & UPD_FACE) |
424 | { |
564 | { |
425 | if (!(pl->contr->socket->faces_sent[op->face->number] & NS_FACESENT_FACE)) |
565 | if (!(ns->faces_sent[op->face->number] & NS_FACESENT_FACE)) |
426 | esrv_send_face (pl->contr->socket, op->face->number, 0); |
566 | esrv_send_face (ns, op->face->number, 0); |
427 | |
567 | |
428 | sl << uint32 (op->face->number); |
568 | sl << uint32 (op->face->number); |
429 | } |
569 | } |
430 | |
570 | |
431 | if (flags & UPD_NAME) |
571 | if (flags & UPD_NAME) |
… | |
… | |
485 | } |
625 | } |
486 | |
626 | |
487 | if (flags & UPD_NROF) |
627 | if (flags & UPD_NROF) |
488 | sl << uint32 (op->nrof); |
628 | sl << uint32 (op->nrof); |
489 | |
629 | |
490 | pl->contr->socket->send_packet (sl); |
630 | pl->contr->ns->send_packet (sl); |
491 | } |
631 | } |
492 | |
632 | |
493 | /** |
633 | /** |
494 | * Sends item's info to player. |
634 | * Sends item's info to player. |
495 | */ |
635 | */ |
… | |
… | |
505 | /* if the item is on the ground, mark that the look needs to |
645 | /* if the item is on the ground, mark that the look needs to |
506 | * be updated. |
646 | * be updated. |
507 | */ |
647 | */ |
508 | if (!op->env) |
648 | if (!op->env) |
509 | { |
649 | { |
510 | pl->contr->socket->update_look = 1; |
650 | pl->contr->ns->floorbox_update (); |
511 | return; |
651 | return; |
512 | } |
652 | } |
513 | } |
653 | } |
514 | |
654 | |
515 | packet sl; |
655 | packet sl; |
516 | |
656 | |
517 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
657 | sl.printf ("item%d ", pl->contr->ns->itemcmd); |
518 | |
658 | |
519 | if (op->head) |
659 | if (op->head) |
520 | op = op->head; |
660 | op = op->head; |
521 | |
661 | |
522 | sl << uint32 (op->env ? op->env->count : 0); |
662 | sl << uint32 (op->env ? op->env->count : 0); |
523 | |
663 | |
524 | add_object_to_socklist (*pl->contr->socket, sl, op); |
664 | add_object_to_socklist (*pl->contr->ns, sl, op); |
525 | |
665 | |
526 | pl->contr->socket->send_packet (sl); |
666 | pl->contr->ns->send_packet (sl); |
527 | SET_FLAG (op, FLAG_CLIENT_SENT); |
667 | SET_FLAG (op, FLAG_CLIENT_SENT); |
528 | |
|
|
529 | } |
668 | } |
530 | |
669 | |
531 | /** |
670 | /** |
532 | * Tells the client to delete an item. Uses the item |
671 | * Tells the client to delete an item. Uses the item |
533 | * command with a -1 location. |
672 | * command with a -1 location. |
534 | */ |
673 | */ |
535 | |
674 | |
536 | void |
675 | void |
537 | esrv_del_item (player *pl, int tag) |
676 | esrv_del_item (player *pl, int tag) |
538 | { |
677 | { |
539 | packet sl; |
678 | packet sl ("delitem"); |
540 | |
679 | |
541 | sl << "delitem " |
|
|
542 | << uint32 (tag); |
680 | sl << uint32 (tag); |
543 | |
681 | |
544 | pl->socket->send_packet (sl); |
682 | pl->ns->send_packet (sl); |
545 | } |
683 | } |
546 | |
684 | |
547 | |
685 | |
548 | /******************************************************************************* |
686 | /******************************************************************************* |
549 | * |
687 | * |
… | |
… | |
570 | else if (op->type == CONTAINER && pl->container == op) |
708 | else if (op->type == CONTAINER && pl->container == op) |
571 | for (tmp = op->inv; tmp; tmp = tmp->below) |
709 | for (tmp = op->inv; tmp; tmp = tmp->below) |
572 | if (tmp->count == count) |
710 | if (tmp->count == count) |
573 | return tmp; |
711 | return tmp; |
574 | |
712 | |
575 | for (op = get_map_ob (pl->map, pl->x, pl->y); op; op = op->above) |
713 | for (op = GET_MAP_OB (pl->map, pl->x, pl->y); op; op = op->above) |
576 | if (op->head != NULL && op->head->count == count) |
714 | if (op->head && op->head->count == count) |
577 | return op; |
715 | return op; |
578 | else if (op->count == count) |
716 | else if (op->count == count) |
579 | return op; |
717 | return op; |
580 | else if (op->type == CONTAINER && pl->container == op) |
718 | else if (op->type == CONTAINER && pl->container == op) |
581 | for (tmp = op->inv; tmp; tmp = tmp->below) |
719 | for (tmp = op->inv; tmp; tmp = tmp->below) |
582 | if (tmp->count == count) |
720 | if (tmp->count == count) |
583 | return tmp; |
721 | return tmp; |
584 | |
722 | |
585 | return NULL; |
723 | return 0; |
586 | } |
724 | } |
587 | |
725 | |
588 | |
726 | |
589 | /** Client wants to examine some object. So lets do so. */ |
727 | /** Client wants to examine some object. So lets do so. */ |
590 | void |
728 | void |
… | |
… | |
605 | } |
743 | } |
606 | |
744 | |
607 | examine (pl->ob, op); |
745 | examine (pl->ob, op); |
608 | } |
746 | } |
609 | |
747 | |
610 | /** Client wants to apply some object. Lets do so. */ |
748 | /** Client wants to apply some object. Lets do so. */ |
611 | void |
749 | void |
612 | ApplyCmd (char *buf, int len, player *pl) |
750 | ApplyCmd (char *buf, int len, player *pl) |
613 | { |
751 | { |
614 | tag_t tag = atoi (buf); |
752 | tag_t tag = atoi (buf); |
615 | |
753 | |
… | |
… | |
620 | return; |
758 | return; |
621 | |
759 | |
622 | /* If the high bit is set, player applied a pseudo object. */ |
760 | /* If the high bit is set, player applied a pseudo object. */ |
623 | if (tag & 0x80000000) |
761 | if (tag & 0x80000000) |
624 | { |
762 | { |
625 | pl->socket->look_position = tag & 0x7fffffff; |
763 | pl->ns->look_position = tag & 0x7fffffff; |
626 | pl->socket->update_look = 1; |
764 | pl->ns->floorbox_update (); |
627 | return; |
765 | return; |
628 | } |
766 | } |
629 | |
767 | |
630 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
768 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
631 | |
769 | |
… | |
… | |
636 | } |
774 | } |
637 | |
775 | |
638 | player_apply (pl->ob, op, 0, 0); |
776 | player_apply (pl->ob, op, 0, 0); |
639 | } |
777 | } |
640 | |
778 | |
641 | /** Client wants to apply some object. Lets do so. */ |
779 | /** Client wants to lock some object. Lets do so. */ |
642 | void |
780 | void |
643 | LockItem (char *data, int len, player *pl) |
781 | LockItem (char *data, int len, player *pl) |
644 | { |
782 | { |
645 | int flag = data[0]; |
783 | int flag = data[0]; |
646 | tag_t tag = net_uint32 ((uint8 *)data + 1); |
784 | tag_t tag = net_uint32 ((uint8 *)data + 1); |
… | |
… | |
658 | SET_FLAG (op, FLAG_INV_LOCKED); |
796 | SET_FLAG (op, FLAG_INV_LOCKED); |
659 | |
797 | |
660 | esrv_update_item (UPD_FLAGS, pl->ob, op); |
798 | esrv_update_item (UPD_FLAGS, pl->ob, op); |
661 | } |
799 | } |
662 | |
800 | |
663 | /** Client wants to apply some object. Lets do so. */ |
801 | /** Client wants to mark some object. Lets do so. */ |
664 | void |
802 | void |
665 | MarkItem (char *data, int len, player *pl) |
803 | MarkItem (char *data, int len, player *pl) |
666 | { |
804 | { |
667 | tag_t tag = net_uint32 ((uint8 *)data); |
805 | tag_t tag = net_uint32 ((uint8 *)data); |
668 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
806 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
… | |
… | |
699 | |
837 | |
700 | m = get_map_from_coord (op->map, &x, &y); |
838 | m = get_map_from_coord (op->map, &x, &y); |
701 | if (!m) |
839 | if (!m) |
702 | return; |
840 | return; |
703 | |
841 | |
704 | for (tmp = get_map_ob (m, x, y); tmp != NULL && tmp->above != NULL; tmp = tmp->above); |
842 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL && tmp->above != NULL; tmp = tmp->above); |
705 | |
843 | |
706 | for (; tmp != NULL; tmp = tmp->below) |
844 | for (; tmp != NULL; tmp = tmp->below) |
707 | { |
845 | { |
708 | if (tmp->invisible && !QUERY_FLAG (op, FLAG_WIZ)) |
846 | if (tmp->invisible && !QUERY_FLAG (op, FLAG_WIZ)) |
709 | continue; |
847 | continue; |
… | |
… | |
756 | { |
894 | { |
757 | return; |
895 | return; |
758 | } |
896 | } |
759 | dy = atoi (cp); |
897 | dy = atoi (cp); |
760 | |
898 | |
761 | if (FABS (dx) > pl->socket->mapx / 2 || FABS (dy) > pl->socket->mapy / 2) |
899 | if (FABS (dx) > pl->ns->mapx / 2 || FABS (dy) > pl->ns->mapy / 2) |
762 | return; |
900 | return; |
763 | |
901 | |
764 | if (pl->blocked_los[dx + pl->socket->mapx / 2][dy + pl->socket->mapy / 2]) |
902 | if (pl->blocked_los[dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2]) |
765 | return; |
903 | return; |
766 | |
904 | |
767 | look_at (pl->ob, dx, dy); |
905 | look_at (pl->ob, dx, dy); |
768 | } |
906 | } |
769 | |
907 | |
… | |
… | |
799 | } |
937 | } |
800 | |
938 | |
801 | esrv_update_item (UPD_WEIGHT, pl, op); |
939 | esrv_update_item (UPD_WEIGHT, pl, op); |
802 | } |
940 | } |
803 | else |
941 | else |
804 | { |
|
|
805 | drop_object (pl, op, nrof); |
942 | drop_object (pl, op, nrof); |
806 | } |
943 | |
807 | return; |
944 | return; |
808 | } |
945 | } |
809 | else if (to == pl->count) |
946 | else if (to == pl->count) |
810 | { /* pick it up to the inventory */ |
947 | { /* pick it up to the inventory */ |
811 | /* return if player has already picked it up */ |
948 | /* return if player has already picked it up */ |
… | |
… | |
828 | * has already been done (eg, it can be picked up and fits in |
965 | * has already been done (eg, it can be picked up and fits in |
829 | * in a sack, so check for those things. We should also check |
966 | * in a sack, so check for those things. We should also check |
830 | * an make sure env is in fact a container for that matter. |
967 | * an make sure env is in fact a container for that matter. |
831 | */ |
968 | */ |
832 | if (env->type == CONTAINER && can_pick (pl, op) && sack_can_hold (pl, env, op, nrof)) |
969 | if (env->type == CONTAINER && can_pick (pl, op) && sack_can_hold (pl, env, op, nrof)) |
833 | { |
|
|
834 | put_object_in_sack (pl, env, op, nrof); |
970 | put_object_in_sack (pl, env, op, nrof); |
835 | } |
|
|
836 | } |
971 | } |
837 | |
972 | |