… | |
… | |
109 | flags |= F_LOCKED; |
109 | flags |= F_LOCKED; |
110 | |
110 | |
111 | return flags; |
111 | return flags; |
112 | } |
112 | } |
113 | |
113 | |
114 | /* Used in the send_look to put object head into SockList |
114 | /* 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 |
115 | * sl for socket ns. Need socket to know if we need to send |
116 | * animation of face to the client. |
116 | * animation of face to the client. |
117 | */ |
117 | */ |
118 | static void |
118 | static void |
119 | add_object_to_socklist (NewSocket &ns, SockList &sl, object *head) |
119 | add_object_to_socklist (client_socket &ns, packet &sl, object *head) |
120 | { |
120 | { |
121 | int flags, len, anim_speed; |
121 | int flags, len, anim_speed; |
122 | char item_n[MAX_BUF]; |
122 | char item_n[MAX_BUF]; |
123 | const char *item_p; |
123 | const char *item_p; |
124 | |
124 | |
… | |
… | |
199 | { |
199 | { |
200 | object *tmp, *last; |
200 | object *tmp, *last; |
201 | int got_one = 0, start_look = 0, end_look = 0; |
201 | int got_one = 0, start_look = 0, end_look = 0; |
202 | char buf[MAX_BUF]; |
202 | char buf[MAX_BUF]; |
203 | |
203 | |
204 | if (!pl->contr->socket.update_look) |
204 | if (!pl->contr->socket->update_look) |
205 | { |
205 | { |
206 | LOG (llevDebug, "esrv_draw_look called when update_look was not set\n"); |
206 | LOG (llevDebug, "esrv_draw_look called when update_look was not set\n"); |
207 | return; |
207 | return; |
208 | } |
208 | } |
209 | else |
209 | else |
210 | pl->contr->socket.update_look = 0; |
210 | pl->contr->socket->update_look = 0; |
211 | |
211 | |
212 | if (QUERY_FLAG (pl, FLAG_REMOVED) |
212 | if (QUERY_FLAG (pl, FLAG_REMOVED) |
213 | || !pl->map |
213 | || !pl->map |
214 | || pl->map->in_memory != MAP_IN_MEMORY |
214 | || pl->map->in_memory != MAP_IN_MEMORY |
215 | || out_of_map (pl->map, pl->x, pl->y)) |
215 | || out_of_map (pl->map, pl->x, pl->y)) |
216 | return; |
216 | return; |
217 | |
217 | |
218 | for (tmp = get_map_ob (pl->map, pl->x, pl->y); tmp && tmp->above; tmp = tmp->above) |
218 | for (tmp = get_map_ob (pl->map, pl->x, pl->y); tmp && tmp->above; tmp = tmp->above) |
219 | ; |
219 | ; |
220 | |
220 | |
221 | SockList sl (MAXSOCKBUF); |
221 | packet sl; |
222 | |
222 | |
223 | pl->contr->socket.send_packet ("delinv 0"); |
223 | pl->contr->socket->send_packet ("delinv 0"); |
224 | |
224 | |
225 | sl.printf ("item%d ", pl->contr->socket.itemcmd); |
225 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
226 | |
226 | |
227 | sl << uint32 (0); |
227 | sl << uint32 (0); |
228 | |
228 | |
229 | if (!(pl->contr->socket.faces_sent[empty_face->number] & NS_FACESENT_FACE)) |
229 | if (!(pl->contr->socket->faces_sent[empty_face->number] & NS_FACESENT_FACE)) |
230 | esrv_send_face (&pl->contr->socket, empty_face->number, 0); |
230 | esrv_send_face (pl->contr->socket, empty_face->number, 0); |
231 | |
231 | |
232 | if (pl->contr->socket.look_position) |
232 | if (pl->contr->socket->look_position) |
233 | { |
233 | { |
|
|
234 | char buf[80]; |
|
|
235 | snprintf (buf, 80, "Apply this to see %d previous items", NUM_LOOK_OBJECTS); |
|
|
236 | |
234 | sl << uint32 (0x80000000 | (pl->contr->socket.look_position - NUM_LOOK_OBJECTS)) |
237 | sl << uint32 (0x80000000 | (pl->contr->socket->look_position - NUM_LOOK_OBJECTS)) |
235 | << uint32 (0) |
238 | << uint32 (0) |
236 | << sint32 (-1) |
239 | << sint32 (-1) |
237 | << uint32 (empty_face->number); |
240 | << uint32 (empty_face->number) |
238 | |
241 | << data8 (buf) |
239 | sl.printf ("Click here to see %d previous items", NUM_LOOK_OBJECTS); |
|
|
240 | |
|
|
241 | sl << uint16 (0) |
242 | << uint16 (0) |
242 | << uint8 (0) |
243 | << uint8 (0) |
243 | << uint32 (0); |
244 | << uint32 (0); |
244 | |
245 | |
245 | if (pl->contr->socket.itemcmd == 2) |
246 | if (pl->contr->socket->itemcmd == 2) |
246 | sl << uint16 (0); |
247 | sl << uint16 (0); |
247 | } |
248 | } |
248 | |
249 | |
249 | for (last = NULL; tmp != last; tmp = tmp->below) |
250 | for (last = NULL; tmp != last; tmp = tmp->below) |
250 | { |
251 | { |
… | |
… | |
257 | last = last->below; |
258 | last = last->below; |
258 | } |
259 | } |
259 | |
260 | |
260 | if (LOOK_OBJ (tmp)) |
261 | if (LOOK_OBJ (tmp)) |
261 | { |
262 | { |
262 | if (++start_look < pl->contr->socket.look_position) |
263 | if (++start_look < pl->contr->socket->look_position) |
263 | continue; |
264 | continue; |
264 | |
265 | |
265 | end_look++; |
266 | end_look++; |
266 | |
267 | |
267 | if (end_look > NUM_LOOK_OBJECTS) |
268 | if (end_look > NUM_LOOK_OBJECTS) |
268 | { |
269 | { |
269 | /* What we basically do is make a 'fake' object - when the user applies it, |
270 | /* What we basically do is make a 'fake' object - when the user applies it, |
270 | * we notice the special tag the object has, and act accordingly. |
271 | * we notice the special tag the object has, and act accordingly. |
271 | */ |
272 | */ |
272 | sl << uint32 (0x80000000 | (pl->contr->socket.look_position + NUM_LOOK_OBJECTS)) |
273 | sl << uint32 (0x80000000 | (pl->contr->socket->look_position + NUM_LOOK_OBJECTS)) |
273 | << uint32 (0) |
274 | << uint32 (0) |
274 | << uint32 ((uint32) - 1) |
275 | << uint32 ((uint32) - 1) |
275 | << uint32 (empty_face->number); |
276 | << uint32 (empty_face->number) |
276 | |
277 | << 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) |
278 | << uint16 (0) |
280 | << uint8 (0) |
279 | << uint8 (0) |
281 | << uint32 (0); |
280 | << uint32 (0); |
282 | |
281 | |
283 | if (pl->contr->socket.itemcmd == 2) |
282 | if (pl->contr->socket->itemcmd == 2) |
284 | sl << uint16 (0); |
283 | sl << uint16 (0); |
285 | |
284 | |
286 | break; |
285 | break; |
287 | } |
286 | } |
288 | |
287 | |
289 | if (tmp->head) |
288 | if (tmp->head) |
290 | head = tmp->head; |
289 | head = tmp->head; |
291 | else |
290 | else |
292 | head = tmp; |
291 | head = tmp; |
293 | |
292 | |
294 | add_object_to_socklist (pl->contr->socket, sl, head); |
293 | add_object_to_socklist (*pl->contr->socket, sl, head); |
295 | got_one++; |
294 | got_one++; |
296 | |
295 | |
297 | if (sl.len >= (MAXSOCKBUF - MAXITEMLEN)) |
296 | if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN)) |
298 | { |
297 | { |
299 | Send_With_Handling (&pl->contr->socket, &sl); |
298 | pl->contr->socket->send_packet (sl); |
300 | |
299 | |
301 | sl.reset (); |
300 | sl.reset (); |
302 | sl.printf ("item%d ", pl->contr->socket.itemcmd); |
301 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
303 | sl << uint32 (0); |
302 | sl << uint32 (0); |
304 | got_one = 0; |
303 | got_one = 0; |
305 | } |
304 | } |
306 | } /* If LOOK_OBJ() */ |
305 | } /* If LOOK_OBJ() */ |
307 | } |
306 | } |
308 | |
307 | |
309 | if (got_one) |
308 | if (got_one) |
310 | Send_With_Handling (&pl->contr->socket, &sl); |
309 | pl->contr->socket->send_packet (sl); |
311 | |
310 | |
312 | sl.free (); |
|
|
313 | } |
311 | } |
314 | |
312 | |
315 | /** |
313 | /** |
316 | * Sends whole inventory. |
314 | * Sends whole inventory. |
317 | */ |
315 | */ |
… | |
… | |
319 | esrv_send_inventory (object *pl, object *op) |
317 | esrv_send_inventory (object *pl, object *op) |
320 | { |
318 | { |
321 | object *tmp; |
319 | object *tmp; |
322 | int got_one = 0; |
320 | int got_one = 0; |
323 | |
321 | |
324 | SockList sl (MAXSOCKBUF); |
322 | packet sl; |
325 | |
323 | |
326 | sl.printf ("delinv %d", op->count); |
324 | sl.printf ("delinv %d", op->count); |
327 | Send_With_Handling (&pl->contr->socket, &sl); |
325 | pl->contr->socket->send_packet (sl); |
328 | |
326 | |
329 | sl.reset (); |
327 | sl.reset (); |
330 | sl.printf ("item%d ", pl->contr->socket.itemcmd); |
328 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
331 | |
329 | |
332 | sl << uint32 (op->count); |
330 | sl << uint32 (op->count); |
333 | |
331 | |
334 | for (tmp = op->inv; tmp; tmp = tmp->below) |
332 | for (tmp = op->inv; tmp; tmp = tmp->below) |
335 | { |
333 | { |
… | |
… | |
340 | else |
338 | else |
341 | head = tmp; |
339 | head = tmp; |
342 | |
340 | |
343 | if (LOOK_OBJ (head)) |
341 | if (LOOK_OBJ (head)) |
344 | { |
342 | { |
345 | add_object_to_socklist (pl->contr->socket, sl, head); |
343 | add_object_to_socklist (*pl->contr->socket, sl, head); |
346 | |
344 | |
347 | got_one++; |
345 | got_one++; |
348 | |
346 | |
349 | /* IT is possible for players to accumulate a huge amount of |
347 | /* IT is possible for players to accumulate a huge amount of |
350 | * items (especially with some of the bags out there) to |
348 | * items (especially with some of the bags out there) to |
351 | * overflow the buffer. IF so, send multiple item commands. |
349 | * overflow the buffer. IF so, send multiple item commands. |
352 | */ |
350 | */ |
353 | if (sl.len >= (MAXSOCKBUF - MAXITEMLEN)) |
351 | if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN)) |
354 | { |
352 | { |
355 | Send_With_Handling (&pl->contr->socket, &sl); |
353 | pl->contr->socket->send_packet (sl); |
|
|
354 | |
|
|
355 | sl.reset (); |
356 | sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd); |
356 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
357 | sl.len = strlen ((char *) sl.buf); |
|
|
358 | sl << uint32 (op->count); |
357 | sl << uint32 (op->count); |
359 | got_one = 0; |
358 | got_one = 0; |
360 | } |
359 | } |
361 | } /* If LOOK_OBJ() */ |
360 | } /* If LOOK_OBJ() */ |
362 | } |
361 | } |
363 | |
362 | |
364 | if (got_one) |
363 | if (got_one) |
365 | Send_With_Handling (&pl->contr->socket, &sl); |
364 | pl->contr->socket->send_packet (sl); |
366 | |
365 | |
367 | sl.free (); |
|
|
368 | } |
366 | } |
369 | |
367 | |
370 | /** |
368 | /** |
371 | * Updates object *op for player *pl. |
369 | * Updates object *op for player *pl. |
372 | * |
370 | * |
… | |
… | |
396 | * and track back the call. |
394 | * and track back the call. |
397 | */ |
395 | */ |
398 | LOG (llevDebug, "We have not sent item %s (%d)\n", &op->name, op->count); |
396 | LOG (llevDebug, "We have not sent item %s (%d)\n", &op->name, op->count); |
399 | } |
397 | } |
400 | |
398 | |
401 | SockList sl (MAXSOCKBUF); |
399 | packet sl; |
402 | |
400 | |
403 | sl << "upditem " |
401 | sl << "upditem " |
404 | << uint8 (flags); |
402 | << uint8 (flags); |
405 | |
403 | |
406 | if (op->head) |
404 | if (op->head) |
… | |
… | |
424 | op->contr->last_weight = weight; |
422 | op->contr->last_weight = weight; |
425 | } |
423 | } |
426 | |
424 | |
427 | if (flags & UPD_FACE) |
425 | if (flags & UPD_FACE) |
428 | { |
426 | { |
429 | if (!(pl->contr->socket.faces_sent[op->face->number] & NS_FACESENT_FACE)) |
427 | if (!(pl->contr->socket->faces_sent[op->face->number] & NS_FACESENT_FACE)) |
430 | esrv_send_face (&pl->contr->socket, op->face->number, 0); |
428 | esrv_send_face (pl->contr->socket, op->face->number, 0); |
431 | |
429 | |
432 | sl << uint32 (op->face->number); |
430 | sl << uint32 (op->face->number); |
433 | } |
431 | } |
434 | |
432 | |
435 | if (flags & UPD_NAME) |
433 | if (flags & UPD_NAME) |
… | |
… | |
489 | } |
487 | } |
490 | |
488 | |
491 | if (flags & UPD_NROF) |
489 | if (flags & UPD_NROF) |
492 | sl << uint32 (op->nrof); |
490 | sl << uint32 (op->nrof); |
493 | |
491 | |
494 | Send_With_Handling (&pl->contr->socket, &sl); |
492 | pl->contr->socket->send_packet (sl); |
495 | sl.free (); |
|
|
496 | } |
493 | } |
497 | |
494 | |
498 | /** |
495 | /** |
499 | * Sends item's info to player. |
496 | * Sends item's info to player. |
500 | */ |
497 | */ |
… | |
… | |
510 | /* if the item is on the ground, mark that the look needs to |
507 | /* if the item is on the ground, mark that the look needs to |
511 | * be updated. |
508 | * be updated. |
512 | */ |
509 | */ |
513 | if (!op->env) |
510 | if (!op->env) |
514 | { |
511 | { |
515 | pl->contr->socket.update_look = 1; |
512 | pl->contr->socket->update_look = 1; |
516 | return; |
513 | return; |
517 | } |
514 | } |
518 | } |
515 | } |
519 | |
516 | |
520 | SockList sl (MAXSOCKBUF); |
517 | packet sl; |
521 | |
518 | |
522 | sl.printf ("item%d ", pl->contr->socket.itemcmd); |
519 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
523 | |
520 | |
524 | if (op->head) |
521 | if (op->head) |
525 | op = op->head; |
522 | op = op->head; |
526 | |
523 | |
527 | sl << uint32 (op->env ? op->env->count : 0); |
524 | sl << uint32 (op->env ? op->env->count : 0); |
528 | |
525 | |
529 | add_object_to_socklist (pl->contr->socket, sl, op); |
526 | add_object_to_socklist (*pl->contr->socket, sl, op); |
530 | |
527 | |
531 | Send_With_Handling (&pl->contr->socket, &sl); |
528 | pl->contr->socket->send_packet (sl); |
532 | SET_FLAG (op, FLAG_CLIENT_SENT); |
529 | SET_FLAG (op, FLAG_CLIENT_SENT); |
533 | |
530 | |
534 | sl.free (); |
|
|
535 | } |
531 | } |
536 | |
532 | |
537 | /** |
533 | /** |
538 | * Tells the client to delete an item. Uses the item |
534 | * Tells the client to delete an item. Uses the item |
539 | * command with a -1 location. |
535 | * command with a -1 location. |
540 | */ |
536 | */ |
541 | |
537 | |
542 | void |
538 | void |
543 | esrv_del_item (player *pl, int tag) |
539 | esrv_del_item (player *pl, int tag) |
544 | { |
540 | { |
545 | SockList sl (MAXSOCKBUF); |
541 | packet sl; |
546 | |
542 | |
547 | sl << "delitem " |
543 | sl << "delitem " |
548 | << uint32 (tag); |
544 | << uint32 (tag); |
549 | |
545 | |
550 | Send_With_Handling (&pl->socket, &sl); |
546 | pl->socket->send_packet (sl); |
551 | sl.free (); |
|
|
552 | } |
547 | } |
553 | |
548 | |
554 | |
549 | |
555 | /******************************************************************************* |
550 | /******************************************************************************* |
556 | * |
551 | * |
… | |
… | |
627 | return; |
622 | return; |
628 | |
623 | |
629 | /* If the high bit is set, player applied a pseudo object. */ |
624 | /* If the high bit is set, player applied a pseudo object. */ |
630 | if (tag & 0x80000000) |
625 | if (tag & 0x80000000) |
631 | { |
626 | { |
632 | pl->socket.look_position = tag & 0x7fffffff; |
627 | pl->socket->look_position = tag & 0x7fffffff; |
633 | pl->socket.update_look = 1; |
628 | pl->socket->update_look = 1; |
634 | return; |
629 | return; |
635 | } |
630 | } |
636 | |
631 | |
637 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
632 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
638 | |
633 | |
… | |
… | |
645 | player_apply (pl->ob, op, 0, 0); |
640 | player_apply (pl->ob, op, 0, 0); |
646 | } |
641 | } |
647 | |
642 | |
648 | /** Client wants to apply some object. Lets do so. */ |
643 | /** Client wants to apply some object. Lets do so. */ |
649 | void |
644 | void |
650 | LockItem (uint8 *data, int len, player *pl) |
645 | LockItem (char *data, int len, player *pl) |
651 | { |
646 | { |
652 | int flag = data[0]; |
647 | int flag = data[0]; |
653 | tag_t tag = net_uint32 (data + 1); |
648 | tag_t tag = net_uint32 ((uint8 *)data + 1); |
654 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
649 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
655 | |
650 | |
656 | if (!op) |
651 | if (!op) |
657 | { |
652 | { |
658 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to lock/unlock"); |
653 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to lock/unlock"); |
… | |
… | |
667 | esrv_update_item (UPD_FLAGS, pl->ob, op); |
662 | esrv_update_item (UPD_FLAGS, pl->ob, op); |
668 | } |
663 | } |
669 | |
664 | |
670 | /** Client wants to apply some object. Lets do so. */ |
665 | /** Client wants to apply some object. Lets do so. */ |
671 | void |
666 | void |
672 | MarkItem (uint8 * data, int len, player *pl) |
667 | MarkItem (char *data, int len, player *pl) |
673 | { |
668 | { |
674 | tag_t tag = net_uint32 (data); |
669 | tag_t tag = net_uint32 ((uint8 *)data); |
675 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
670 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
676 | |
671 | |
677 | if (!op) |
672 | if (!op) |
678 | { |
673 | { |
679 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark"); |
674 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark"); |
… | |
… | |
763 | { |
758 | { |
764 | return; |
759 | return; |
765 | } |
760 | } |
766 | dy = atoi (cp); |
761 | dy = atoi (cp); |
767 | |
762 | |
768 | if (FABS (dx) > pl->socket.mapx / 2 || FABS (dy) > pl->socket.mapy / 2) |
763 | if (FABS (dx) > pl->socket->mapx / 2 || FABS (dy) > pl->socket->mapy / 2) |
769 | return; |
764 | return; |
770 | |
765 | |
771 | if (pl->blocked_los[dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2]) |
766 | if (pl->blocked_los[dx + pl->socket->mapx / 2][dy + pl->socket->mapy / 2]) |
772 | return; |
767 | return; |
773 | |
768 | |
774 | look_at (pl->ob, dx, dy); |
769 | look_at (pl->ob, dx, dy); |
775 | } |
770 | } |
776 | |
771 | |