… | |
… | |
33 | */ |
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 <newclient.h> |
|
|
39 | #include <newserver.h> |
|
|
40 | #include <sproto.h> |
38 | #include <sproto.h> |
41 | |
39 | |
42 | /** 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 */ |
43 | #define MAXITEMLEN 300 |
41 | #define MAXITEMLEN 300 |
44 | |
42 | |
… | |
… | |
114 | /* Used in the send_look to put object head into packet |
112 | /* Used in the send_look to put object head into packet |
115 | * sl for socket ns. Need socket to know if we need to send |
113 | * sl for socket ns. Need socket to know if we need to send |
116 | * animation of face to the client. |
114 | * animation of face to the client. |
117 | */ |
115 | */ |
118 | static void |
116 | static void |
119 | add_object_to_socklist (client_socket &ns, packet &sl, object *head) |
117 | add_object_to_socklist (client &ns, packet &sl, object *head) |
120 | { |
118 | { |
121 | int flags, len, anim_speed; |
119 | int flags, len, anim_speed; |
122 | char item_n[MAX_BUF]; |
120 | char item_n[MAX_BUF]; |
123 | const char *item_p; |
121 | const char *item_p; |
124 | |
122 | |
… | |
… | |
229 | if (!(pl->contr->socket->faces_sent[empty_face->number] & NS_FACESENT_FACE)) |
227 | if (!(pl->contr->socket->faces_sent[empty_face->number] & NS_FACESENT_FACE)) |
230 | esrv_send_face (pl->contr->socket, empty_face->number, 0); |
228 | esrv_send_face (pl->contr->socket, empty_face->number, 0); |
231 | |
229 | |
232 | if (pl->contr->socket->look_position) |
230 | if (pl->contr->socket->look_position) |
233 | { |
231 | { |
|
|
232 | char buf[80]; |
|
|
233 | snprintf (buf, 80, "Apply this to see %d previous items", NUM_LOOK_OBJECTS); |
|
|
234 | |
234 | sl << uint32 (0x80000000 | (pl->contr->socket->look_position - NUM_LOOK_OBJECTS)) |
235 | sl << uint32 (0x80000000 | (pl->contr->socket->look_position - NUM_LOOK_OBJECTS)) |
235 | << uint32 (0) |
236 | << uint32 (0) |
236 | << sint32 (-1) |
237 | << sint32 (-1) |
237 | << uint32 (empty_face->number); |
238 | << uint32 (empty_face->number) |
238 | |
239 | << data8 (buf) |
239 | sl.printf ("Click here to see %d previous items", NUM_LOOK_OBJECTS); |
|
|
240 | |
|
|
241 | sl << uint16 (0) |
240 | << uint16 (0) |
242 | << uint8 (0) |
241 | << uint8 (0) |
243 | << uint32 (0); |
242 | << uint32 (0); |
244 | |
243 | |
245 | if (pl->contr->socket->itemcmd == 2) |
244 | if (pl->contr->socket->itemcmd == 2) |
246 | sl << uint16 (0); |
245 | sl << uint16 (0); |
… | |
… | |
270 | * we notice the special tag the object has, and act accordingly. |
269 | * we notice the special tag the object has, and act accordingly. |
271 | */ |
270 | */ |
272 | sl << uint32 (0x80000000 | (pl->contr->socket->look_position + NUM_LOOK_OBJECTS)) |
271 | sl << uint32 (0x80000000 | (pl->contr->socket->look_position + NUM_LOOK_OBJECTS)) |
273 | << uint32 (0) |
272 | << uint32 (0) |
274 | << uint32 ((uint32) - 1) |
273 | << uint32 ((uint32) - 1) |
275 | << uint32 (empty_face->number); |
274 | << uint32 (empty_face->number) |
276 | |
275 | << data8 ("Apply this to see next group of items") |
277 | sl.printf ("Click here to see next group of items"); |
|
|
278 | |
|
|
279 | sl << uint16 (0) |
276 | << uint16 (0) |
280 | << uint8 (0) |
277 | << uint8 (0) |
281 | << uint32 (0); |
278 | << uint32 (0); |
282 | |
279 | |
283 | if (pl->contr->socket->itemcmd == 2) |
280 | if (pl->contr->socket->itemcmd == 2) |
284 | sl << uint16 (0); |
281 | sl << uint16 (0); |
… | |
… | |
294 | add_object_to_socklist (*pl->contr->socket, sl, head); |
291 | add_object_to_socklist (*pl->contr->socket, sl, head); |
295 | got_one++; |
292 | got_one++; |
296 | |
293 | |
297 | if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN)) |
294 | if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN)) |
298 | { |
295 | { |
299 | Send_With_Handling (pl->contr->socket, &sl); |
296 | pl->contr->socket->send_packet (sl); |
300 | |
297 | |
301 | sl.reset (); |
298 | sl.reset (); |
302 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
299 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
303 | sl << uint32 (0); |
300 | sl << uint32 (0); |
304 | got_one = 0; |
301 | got_one = 0; |
305 | } |
302 | } |
306 | } /* If LOOK_OBJ() */ |
303 | } /* If LOOK_OBJ() */ |
307 | } |
304 | } |
308 | |
305 | |
309 | if (got_one) |
306 | if (got_one) |
310 | Send_With_Handling (pl->contr->socket, &sl); |
307 | pl->contr->socket->send_packet (sl); |
311 | |
308 | |
312 | } |
309 | } |
313 | |
310 | |
314 | /** |
311 | /** |
315 | * Sends whole inventory. |
312 | * Sends whole inventory. |
… | |
… | |
321 | int got_one = 0; |
318 | int got_one = 0; |
322 | |
319 | |
323 | packet sl; |
320 | packet sl; |
324 | |
321 | |
325 | sl.printf ("delinv %d", op->count); |
322 | sl.printf ("delinv %d", op->count); |
326 | Send_With_Handling (pl->contr->socket, &sl); |
323 | pl->contr->socket->send_packet (sl); |
327 | |
324 | |
328 | sl.reset (); |
325 | sl.reset (); |
329 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
326 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
330 | |
327 | |
331 | sl << uint32 (op->count); |
328 | sl << uint32 (op->count); |
… | |
… | |
349 | * items (especially with some of the bags out there) to |
346 | * items (especially with some of the bags out there) to |
350 | * overflow the buffer. IF so, send multiple item commands. |
347 | * overflow the buffer. IF so, send multiple item commands. |
351 | */ |
348 | */ |
352 | if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN)) |
349 | if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN)) |
353 | { |
350 | { |
354 | Send_With_Handling (pl->contr->socket, &sl); |
351 | pl->contr->socket->send_packet (sl); |
355 | |
352 | |
356 | sl.reset (); |
353 | sl.reset (); |
357 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
354 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
358 | sl << uint32 (op->count); |
355 | sl << uint32 (op->count); |
359 | got_one = 0; |
356 | got_one = 0; |
360 | } |
357 | } |
361 | } /* If LOOK_OBJ() */ |
358 | } /* If LOOK_OBJ() */ |
362 | } |
359 | } |
363 | |
360 | |
364 | if (got_one) |
361 | if (got_one) |
365 | Send_With_Handling (pl->contr->socket, &sl); |
362 | pl->contr->socket->send_packet (sl); |
366 | |
363 | |
367 | } |
364 | } |
368 | |
365 | |
369 | /** |
366 | /** |
370 | * Updates object *op for player *pl. |
367 | * Updates object *op for player *pl. |
… | |
… | |
488 | } |
485 | } |
489 | |
486 | |
490 | if (flags & UPD_NROF) |
487 | if (flags & UPD_NROF) |
491 | sl << uint32 (op->nrof); |
488 | sl << uint32 (op->nrof); |
492 | |
489 | |
493 | Send_With_Handling (pl->contr->socket, &sl); |
490 | pl->contr->socket->send_packet (sl); |
494 | } |
491 | } |
495 | |
492 | |
496 | /** |
493 | /** |
497 | * Sends item's info to player. |
494 | * Sends item's info to player. |
498 | */ |
495 | */ |
… | |
… | |
524 | |
521 | |
525 | sl << uint32 (op->env ? op->env->count : 0); |
522 | sl << uint32 (op->env ? op->env->count : 0); |
526 | |
523 | |
527 | add_object_to_socklist (*pl->contr->socket, sl, op); |
524 | add_object_to_socklist (*pl->contr->socket, sl, op); |
528 | |
525 | |
529 | Send_With_Handling (pl->contr->socket, &sl); |
526 | pl->contr->socket->send_packet (sl); |
530 | SET_FLAG (op, FLAG_CLIENT_SENT); |
527 | SET_FLAG (op, FLAG_CLIENT_SENT); |
531 | |
528 | |
532 | } |
529 | } |
533 | |
530 | |
534 | /** |
531 | /** |
… | |
… | |
542 | packet sl; |
539 | packet sl; |
543 | |
540 | |
544 | sl << "delitem " |
541 | sl << "delitem " |
545 | << uint32 (tag); |
542 | << uint32 (tag); |
546 | |
543 | |
547 | Send_With_Handling (pl->socket, &sl); |
544 | pl->socket->send_packet (sl); |
548 | } |
545 | } |
549 | |
546 | |
550 | |
547 | |
551 | /******************************************************************************* |
548 | /******************************************************************************* |
552 | * |
549 | * |
… | |
… | |
641 | player_apply (pl->ob, op, 0, 0); |
638 | player_apply (pl->ob, op, 0, 0); |
642 | } |
639 | } |
643 | |
640 | |
644 | /** Client wants to apply some object. Lets do so. */ |
641 | /** Client wants to apply some object. Lets do so. */ |
645 | void |
642 | void |
646 | LockItem (uint8 *data, int len, player *pl) |
643 | LockItem (char *data, int len, player *pl) |
647 | { |
644 | { |
648 | int flag = data[0]; |
645 | int flag = data[0]; |
649 | tag_t tag = net_uint32 (data + 1); |
646 | tag_t tag = net_uint32 ((uint8 *)data + 1); |
650 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
647 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
651 | |
648 | |
652 | if (!op) |
649 | if (!op) |
653 | { |
650 | { |
654 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to lock/unlock"); |
651 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to lock/unlock"); |
… | |
… | |
663 | esrv_update_item (UPD_FLAGS, pl->ob, op); |
660 | esrv_update_item (UPD_FLAGS, pl->ob, op); |
664 | } |
661 | } |
665 | |
662 | |
666 | /** Client wants to apply some object. Lets do so. */ |
663 | /** Client wants to apply some object. Lets do so. */ |
667 | void |
664 | void |
668 | MarkItem (uint8 * data, int len, player *pl) |
665 | MarkItem (char *data, int len, player *pl) |
669 | { |
666 | { |
670 | tag_t tag = net_uint32 (data); |
667 | tag_t tag = net_uint32 ((uint8 *)data); |
671 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
668 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
672 | |
669 | |
673 | if (!op) |
670 | if (!op) |
674 | { |
671 | { |
675 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark"); |
672 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark"); |