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

Comparing deliantra/server/socket/item.C (file contents):
Revision 1.11 by root, Wed Dec 13 21:27:09 2006 UTC vs.
Revision 1.15 by root, Thu Dec 14 01:12:35 2006 UTC

45/******************************************************************************* 45/*******************************************************************************
46 * 46 *
47 * Functions related to sending object data to the client. 47 * Functions related to sending object data to the client.
48 * 48 *
49 ******************************************************************************/ 49 ******************************************************************************/
50
51/**
52 * Adds string to socklist.
53 *
54 * This is a simple function that we use a lot here. It basically
55 * adds the specified buffer into the socklist, but prepends a
56 * single byte in length. If the data is longer than that byte, it is
57 * truncated approprately.
58 */
59inline void
60add_stringlen_to_sockbuf (const char *buf, SockList * sl)
61{
62 int len;
63
64 len = strlen (buf);
65 if (len > 255)
66 len = 255;
67 SockList_AddChar (sl, (char) len);
68 strncpy ((char *) sl->buf + sl->len, buf, len);
69 sl->len += len;
70}
71 50
72/** 51/**
73 * This is a similar to query_name, but returns flags 52 * This is a similar to query_name, but returns flags
74 * to be sended to client. 53 * to be sended to client.
75 */ 54 */
135/* Used in the send_look to put object head into SockList 114/* Used in the send_look to put object head into SockList
136 * 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
137 * animation of face to the client. 116 * animation of face to the client.
138 */ 117 */
139static void 118static void
140add_object_to_socklist (NewSocket * ns, SockList * sl, object *head) 119add_object_to_socklist (NewSocket &ns, SockList &sl, object *head)
141{ 120{
142 int flags, len, anim_speed; 121 int flags, len, anim_speed;
143 char item_n[MAX_BUF]; 122 char item_n[MAX_BUF];
144 const char *item_p; 123 const char *item_p;
145 124
146 flags = query_flags (head); 125 flags = query_flags (head);
147 if (QUERY_FLAG (head, FLAG_NO_PICK)) 126 if (QUERY_FLAG (head, FLAG_NO_PICK))
148 flags |= F_NOPICK; 127 flags |= F_NOPICK;
149 128
150 if (!(ns->faces_sent[head->face->number] & NS_FACESENT_FACE)) 129 if (!(ns.faces_sent[head->face->number] & NS_FACESENT_FACE))
151 esrv_send_face (ns, head->face->number, 0); 130 esrv_send_face (&ns, head->face->number, 0);
152 131
153 if (QUERY_FLAG (head, FLAG_ANIMATE) && !ns->anims_sent[head->animation_id]) 132 if (QUERY_FLAG (head, FLAG_ANIMATE) && !ns.anims_sent[head->animation_id])
154 esrv_send_animation (ns, head->animation_id); 133 esrv_send_animation (&ns, head->animation_id);
155 134
156 SockList_AddInt (sl, head->count); 135 sl << uint32 (head->count)
157 SockList_AddInt (sl, flags); 136 << uint32 (flags)
158 SockList_AddInt (sl, QUERY_FLAG (head, FLAG_NO_PICK) ? -1 : WEIGHT (head)); 137 << uint32 (QUERY_FLAG (head, FLAG_NO_PICK) ? -1 : WEIGHT (head))
159 SockList_AddInt (sl, head->face->number); 138 << uint32 (head->face->number);
160 139
161 if (!head->custom_name) 140 if (!head->custom_name)
162 { 141 {
163 strncpy (item_n, query_base_name (head, 0), 127); 142 strncpy (item_n, query_base_name (head, 0), 127);
164 item_n[127] = 0; 143 item_n[127] = 0;
170 strncpy (item_n, head->custom_name, 127); 149 strncpy (item_n, head->custom_name, 127);
171 item_n[127] = 0; 150 item_n[127] = 0;
172 len = strlen (item_n); 151 len = strlen (item_n);
173 item_p = head->custom_name; 152 item_p = head->custom_name;
174 } 153 }
154
175 strncpy (item_n + len + 1, item_p, 127); 155 strncpy (item_n + len + 1, item_p, 127);
176 item_n[254] = 0; 156 item_n[254] = 0;
177 len += strlen (item_n + 1 + len) + 1; 157 len += strlen (item_n + 1 + len) + 1;
178 SockList_AddChar (sl, (char) len);
179 memcpy (sl->buf + sl->len, item_n, len);
180 sl->len += len;
181 158
182 SockList_AddShort (sl, head->animation_id); 159 sl << data8 (item_n, len)
160 << uint16 (head->animation_id);
161
183 anim_speed = 0; 162 anim_speed = 0;
184 if (QUERY_FLAG (head, FLAG_ANIMATE)) 163 if (QUERY_FLAG (head, FLAG_ANIMATE))
185 { 164 {
186 if (head->anim_speed) 165 if (head->anim_speed)
187 anim_speed = head->anim_speed; 166 anim_speed = head->anim_speed;
192 else if (FABS (head->speed) >= 1.0) 171 else if (FABS (head->speed) >= 1.0)
193 anim_speed = 1; 172 anim_speed = 1;
194 else 173 else
195 anim_speed = (int) (1.0 / FABS (head->speed)); 174 anim_speed = (int) (1.0 / FABS (head->speed));
196 } 175 }
176
197 if (anim_speed > 255) 177 if (anim_speed > 255)
198 anim_speed = 255; 178 anim_speed = 255;
199 } 179 }
200 SockList_AddChar (sl, (char) anim_speed);
201 SockList_AddInt (sl, head->nrof);
202 180
181 sl << uint8 (anim_speed)
182 << uint32 (head->nrof);
183
203 if (ns->itemcmd == 2) 184 if (ns.itemcmd == 2)
204 SockList_AddShort (sl, head->client_type); 185 sl << uint16 (head->client_type);
205 186
206 SET_FLAG (head, FLAG_CLIENT_SENT); 187 SET_FLAG (head, FLAG_CLIENT_SENT);
207} 188}
208 189
209 190
216void 197void
217esrv_draw_look (object *pl) 198esrv_draw_look (object *pl)
218{ 199{
219 object *tmp, *last; 200 object *tmp, *last;
220 int got_one = 0, start_look = 0, end_look = 0; 201 int got_one = 0, start_look = 0, end_look = 0;
221 SockList sl;
222 char buf[MAX_BUF]; 202 char buf[MAX_BUF];
223 203
224 if (!pl->contr->socket.update_look) 204 if (!pl->contr->socket.update_look)
225 { 205 {
226 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");
227 return; 207 return;
228 } 208 }
229 else 209 else
230 {
231 pl->contr->socket.update_look = 0; 210 pl->contr->socket.update_look = 0;
232 }
233 211
234 if (QUERY_FLAG (pl, FLAG_REMOVED) || pl->map == NULL || pl->map->in_memory != MAP_IN_MEMORY || out_of_map (pl->map, pl->x, pl->y)) 212 if (QUERY_FLAG (pl, FLAG_REMOVED)
213 || !pl->map
214 || pl->map->in_memory != MAP_IN_MEMORY
215 || out_of_map (pl->map, pl->x, pl->y))
235 return; 216 return;
236 217
237 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 ;
238 220
239 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 221 SockList sl (MAXSOCKBUF);
240 222
241 Write_String_To_Socket (&pl->contr->socket, "delinv 0", strlen ("delinv 0")); 223 pl->contr->socket.send_packet ("delinv 0");
224
242 sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd); 225 sl.printf ("item%d ", pl->contr->socket.itemcmd);
243 sl.len = strlen ((char *) sl.buf);
244 226
245 SockList_AddInt (&sl, 0); 227 sl << uint32 (0);
246 228
247 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))
248 esrv_send_face (&pl->contr->socket, empty_face->number, 0); 230 esrv_send_face (&pl->contr->socket, empty_face->number, 0);
249 231
250 if (pl->contr->socket.look_position) 232 if (pl->contr->socket.look_position)
251 { 233 {
252 SockList_AddInt (&sl, 0x80000000 | (pl->contr->socket.look_position - NUM_LOOK_OBJECTS)); 234 sl << uint32 (0x80000000 | (pl->contr->socket.look_position - NUM_LOOK_OBJECTS))
253 SockList_AddInt (&sl, 0); 235 << uint32 (0)
254 SockList_AddInt (&sl, (uint32) - 1); 236 << sint32 (-1)
255 SockList_AddInt (&sl, empty_face->number); 237 << uint32 (empty_face->number);
238
256 sprintf (buf, "Click here to see %d previous items", NUM_LOOK_OBJECTS); 239 sl.printf ("Click here to see %d previous items", NUM_LOOK_OBJECTS);
257 add_stringlen_to_sockbuf (buf, &sl); 240
258 SockList_AddShort (&sl, 0); 241 sl << uint16 (0)
259 SockList_AddChar (&sl, 0); 242 << uint8 (0)
260 SockList_AddInt (&sl, 0); 243 << uint32 (0);
244
261 if (pl->contr->socket.itemcmd == 2) 245 if (pl->contr->socket.itemcmd == 2)
262 SockList_AddShort (&sl, 0); 246 sl << uint16 (0);
263 } 247 }
264 248
265 for (last = NULL; tmp != last; tmp = tmp->below) 249 for (last = NULL; tmp != last; tmp = tmp->below)
266 { 250 {
267 object *head; 251 object *head;
270 { 254 {
271 last = tmp->below; /* assumes double floor mode */ 255 last = tmp->below; /* assumes double floor mode */
272 if (last && QUERY_FLAG (last, FLAG_IS_FLOOR)) 256 if (last && QUERY_FLAG (last, FLAG_IS_FLOOR))
273 last = last->below; 257 last = last->below;
274 } 258 }
259
275 if (LOOK_OBJ (tmp)) 260 if (LOOK_OBJ (tmp))
276 { 261 {
277 if (++start_look < pl->contr->socket.look_position) 262 if (++start_look < pl->contr->socket.look_position)
278 continue; 263 continue;
264
279 end_look++; 265 end_look++;
266
280 if (end_look > NUM_LOOK_OBJECTS) 267 if (end_look > NUM_LOOK_OBJECTS)
281 { 268 {
282 /* What we basically do is make a 'fake' object - when the user applies it, 269 /* What we basically do is make a 'fake' object - when the user applies it,
283 * we notice the special tag the object has, and act accordingly. 270 * we notice the special tag the object has, and act accordingly.
284 */ 271 */
285 SockList_AddInt (&sl, 0x80000000 | (pl->contr->socket.look_position + NUM_LOOK_OBJECTS)); 272 sl << uint32 (0x80000000 | (pl->contr->socket.look_position + NUM_LOOK_OBJECTS))
286 SockList_AddInt (&sl, 0); 273 << uint32 (0)
287 SockList_AddInt (&sl, (uint32) - 1); 274 << uint32 ((uint32) - 1)
288 SockList_AddInt (&sl, empty_face->number); 275 << uint32 (empty_face->number);
276
289 sprintf (buf, "Click here to see next group of items"); 277 sl.printf ("Click here to see next group of items");
290 add_stringlen_to_sockbuf (buf, &sl); 278
291 SockList_AddShort (&sl, 0); 279 sl << uint16 (0)
292 SockList_AddChar (&sl, 0); 280 << uint8 (0)
293 SockList_AddInt (&sl, 0); 281 << uint32 (0);
282
294 if (pl->contr->socket.itemcmd == 2) 283 if (pl->contr->socket.itemcmd == 2)
295 SockList_AddShort (&sl, 0); 284 sl << uint16 (0);
285
296 break; 286 break;
297 } 287 }
288
298 if (tmp->head) 289 if (tmp->head)
299 head = tmp->head; 290 head = tmp->head;
300 else 291 else
301 head = tmp; 292 head = tmp;
302 293
303 add_object_to_socklist (&pl->contr->socket, &sl, head); 294 add_object_to_socklist (pl->contr->socket, sl, head);
304 got_one++; 295 got_one++;
305 296
306 if (sl.len >= (MAXSOCKBUF - MAXITEMLEN)) 297 if (sl.len >= (MAXSOCKBUF - MAXITEMLEN))
307 { 298 {
308 Send_With_Handling (&pl->contr->socket, &sl); 299 Send_With_Handling (&pl->contr->socket, &sl);
300
301 sl.reset ();
309 sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd); 302 sl.printf ("item%d ", pl->contr->socket.itemcmd);
310 sl.len = strlen ((char *) sl.buf); 303 sl << uint32 (0);
311 SockList_AddInt (&sl, 0);
312 got_one = 0; 304 got_one = 0;
313 } 305 }
314 } /* If LOOK_OBJ() */ 306 } /* If LOOK_OBJ() */
315 } 307 }
308
316 if (got_one) 309 if (got_one)
317 Send_With_Handling (&pl->contr->socket, &sl); 310 Send_With_Handling (&pl->contr->socket, &sl);
318 311
319 free (sl.buf); 312 sl.free ();
320} 313}
321 314
322/** 315/**
323 * Sends whole inventory. 316 * Sends whole inventory.
324 */ 317 */
325void 318void
326esrv_send_inventory (object *pl, object *op) 319esrv_send_inventory (object *pl, object *op)
327{ 320{
328 object *tmp; 321 object *tmp;
329 int got_one = 0; 322 int got_one = 0;
330 SockList sl;
331 323
332 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 324 SockList sl (MAXSOCKBUF);
333 325
334 sprintf ((char *) sl.buf, "delinv %d", op->count); 326 sl.printf ("delinv %d", op->count);
335 sl.len = strlen ((char *) sl.buf);
336 Send_With_Handling (&pl->contr->socket, &sl); 327 Send_With_Handling (&pl->contr->socket, &sl);
337 328
329 sl.reset ();
338 sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd); 330 sl.printf ("item%d ", pl->contr->socket.itemcmd);
339 sl.len = strlen ((char *) sl.buf);
340 331
341 SockList_AddInt (&sl, op->count); 332 sl << uint32 (op->count);
342 333
343 for (tmp = op->inv; tmp; tmp = tmp->below) 334 for (tmp = op->inv; tmp; tmp = tmp->below)
344 { 335 {
345 object *head; 336 object *head;
346 337
349 else 340 else
350 head = tmp; 341 head = tmp;
351 342
352 if (LOOK_OBJ (head)) 343 if (LOOK_OBJ (head))
353 { 344 {
354 add_object_to_socklist (&pl->contr->socket, &sl, head); 345 add_object_to_socklist (pl->contr->socket, sl, head);
355 346
356 got_one++; 347 got_one++;
357 348
358 /* IT is possible for players to accumulate a huge amount of 349 /* IT is possible for players to accumulate a huge amount of
359 * items (especially with some of the bags out there) to 350 * items (especially with some of the bags out there) to
362 if (sl.len >= (MAXSOCKBUF - MAXITEMLEN)) 353 if (sl.len >= (MAXSOCKBUF - MAXITEMLEN))
363 { 354 {
364 Send_With_Handling (&pl->contr->socket, &sl); 355 Send_With_Handling (&pl->contr->socket, &sl);
365 sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd); 356 sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd);
366 sl.len = strlen ((char *) sl.buf); 357 sl.len = strlen ((char *) sl.buf);
367 SockList_AddInt (&sl, op->count); 358 sl << uint32 (op->count);
368 got_one = 0; 359 got_one = 0;
369 } 360 }
370 } /* If LOOK_OBJ() */ 361 } /* If LOOK_OBJ() */
371 } 362 }
363
372 if (got_one) 364 if (got_one)
373 Send_With_Handling (&pl->contr->socket, &sl); 365 Send_With_Handling (&pl->contr->socket, &sl);
374 free (sl.buf); 366
367 sl.free ();
375} 368}
376 369
377/** 370/**
378 * Updates object *op for player *pl. 371 * Updates object *op for player *pl.
379 * 372 *
383 */ 376 */
384 377
385void 378void
386esrv_update_item (int flags, object *pl, object *op) 379esrv_update_item (int flags, object *pl, object *op)
387{ 380{
388 SockList sl;
389
390 /* If we have a request to send the player item, skip a few checks. */ 381 /* If we have a request to send the player item, skip a few checks. */
391 if (op != pl) 382 if (op != pl)
392 { 383 {
393 if (!LOOK_OBJ (op)) 384 if (!LOOK_OBJ (op))
394 return; 385 return;
405 * and track back the call. 396 * and track back the call.
406 */ 397 */
407 LOG (llevDebug, "We have not sent item %s (%d)\n", &op->name, op->count); 398 LOG (llevDebug, "We have not sent item %s (%d)\n", &op->name, op->count);
408 } 399 }
409 400
410 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 401 SockList sl (MAXSOCKBUF);
411 402
412 strcpy ((char *) sl.buf, "upditem "); 403 sl << "upditem "
413 sl.len = strlen ((char *) sl.buf); 404 << uint8 (flags);
414
415 SockList_AddChar (&sl, (char) flags);
416 405
417 if (op->head) 406 if (op->head)
418 op = op->head; 407 op = op->head;
419 408
420 SockList_AddInt (&sl, op->count); 409 sl << uint32 (op->count);
421 410
422 if (flags & UPD_LOCATION) 411 if (flags & UPD_LOCATION)
423 SockList_AddInt (&sl, op->env ? op->env->count : 0); 412 sl << uint32 (op->env ? op->env->count : 0);
424 413
425 if (flags & UPD_FLAGS) 414 if (flags & UPD_FLAGS)
426 SockList_AddInt (&sl, query_flags (op)); 415 sl << uint32 (query_flags (op));
427 416
428 if (flags & UPD_WEIGHT) 417 if (flags & UPD_WEIGHT)
429 { 418 {
430 sint32 weight = WEIGHT (op); 419 sint32 weight = WEIGHT (op);
431 420
432 SockList_AddInt (&sl, QUERY_FLAG (op, FLAG_NO_PICK) ? -1 : weight); 421 sl << uint32 (QUERY_FLAG (op, FLAG_NO_PICK) ? -1 : weight);
422
433 if (pl == op) 423 if (pl == op)
434 {
435 op->contr->last_weight = weight; 424 op->contr->last_weight = weight;
436 }
437 } 425 }
438 426
439 if (flags & UPD_FACE) 427 if (flags & UPD_FACE)
440 { 428 {
441 if (!(pl->contr->socket.faces_sent[op->face->number] & NS_FACESENT_FACE)) 429 if (!(pl->contr->socket.faces_sent[op->face->number] & NS_FACESENT_FACE))
442 esrv_send_face (&pl->contr->socket, op->face->number, 0); 430 esrv_send_face (&pl->contr->socket, op->face->number, 0);
443 SockList_AddInt (&sl, op->face->number); 431
432 sl << uint32 (op->face->number);
444 } 433 }
445 434
446 if (flags & UPD_NAME) 435 if (flags & UPD_NAME)
447 { 436 {
448 int len; 437 int len;
465 } 454 }
466 455
467 strncpy (item_n + len + 1, item_p, 127); 456 strncpy (item_n + len + 1, item_p, 127);
468 item_n[254] = 0; 457 item_n[254] = 0;
469 len += strlen (item_n + 1 + len) + 1; 458 len += strlen (item_n + 1 + len) + 1;
470 SockList_AddChar (&sl, (char) len); 459
471 memcpy (sl.buf + sl.len, item_n, len); 460 sl << data8 (item_n, len);
472 sl.len += len;
473 } 461 }
474 462
475 if (flags & UPD_ANIM) 463 if (flags & UPD_ANIM)
476 SockList_AddShort (&sl, op->animation_id); 464 sl << uint16 (op->animation_id);
477 465
478 if (flags & UPD_ANIMSPEED) 466 if (flags & UPD_ANIMSPEED)
479 { 467 {
480 int anim_speed = 0; 468 int anim_speed = 0;
481 469
490 else if (FABS (op->speed) >= 1.0) 478 else if (FABS (op->speed) >= 1.0)
491 anim_speed = 1; 479 anim_speed = 1;
492 else 480 else
493 anim_speed = (int) (1.0 / FABS (op->speed)); 481 anim_speed = (int) (1.0 / FABS (op->speed));
494 } 482 }
483
495 if (anim_speed > 255) 484 if (anim_speed > 255)
496 anim_speed = 255; 485 anim_speed = 255;
497 } 486 }
498 SockList_AddChar (&sl, (char) anim_speed); 487
488 sl << uint8 (anim_speed);
499 } 489 }
490
500 if (flags & UPD_NROF) 491 if (flags & UPD_NROF)
501 SockList_AddInt (&sl, op->nrof); 492 sl << uint32 (op->nrof);
502 493
503 Send_With_Handling (&pl->contr->socket, &sl); 494 Send_With_Handling (&pl->contr->socket, &sl);
504 free (sl.buf); 495 sl.free ();
505} 496}
506 497
507/** 498/**
508 * Sends item's info to player. 499 * Sends item's info to player.
509 */ 500 */
510void 501void
511esrv_send_item (object *pl, object *op) 502esrv_send_item (object *pl, object *op)
512{ 503{
513 SockList sl;
514
515 /* If this is not the player object, do some more checks */ 504 /* If this is not the player object, do some more checks */
516 if (op != pl) 505 if (op != pl)
517 { 506 {
518 /* We only send 'visibile' objects to the client */ 507 /* We only send 'visibile' objects to the client */
519 if (!LOOK_OBJ (op)) 508 if (!LOOK_OBJ (op))
526 pl->contr->socket.update_look = 1; 515 pl->contr->socket.update_look = 1;
527 return; 516 return;
528 } 517 }
529 } 518 }
530 519
531 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 520 SockList sl (MAXSOCKBUF);
532 521
533 sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd); 522 sl.printf ("item%d ", pl->contr->socket.itemcmd);
534 sl.len = strlen ((char *) sl.buf);
535 523
536 if (op->head) 524 if (op->head)
537 op = op->head; 525 op = op->head;
538 526
539 SockList_AddInt (&sl, op->env ? op->env->count : 0); 527 sl << uint32 (op->env ? op->env->count : 0);
540 528
541 add_object_to_socklist (&pl->contr->socket, &sl, op); 529 add_object_to_socklist (pl->contr->socket, sl, op);
542 530
543 Send_With_Handling (&pl->contr->socket, &sl); 531 Send_With_Handling (&pl->contr->socket, &sl);
544 SET_FLAG (op, FLAG_CLIENT_SENT); 532 SET_FLAG (op, FLAG_CLIENT_SENT);
545 free (sl.buf); 533
534 sl.free ();
546} 535}
547 536
548/** 537/**
549 * Tells the client to delete an item. Uses the item 538 * Tells the client to delete an item. Uses the item
550 * command with a -1 location. 539 * command with a -1 location.
551 */ 540 */
552 541
553void 542void
554esrv_del_item (player *pl, int tag) 543esrv_del_item (player *pl, int tag)
555{ 544{
556 SockList sl; 545 SockList sl (MAXSOCKBUF);
557 546
558 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 547 sl << "delitem "
559 548 << uint32 (tag);
560 strcpy ((char *) sl.buf, "delitem ");
561 sl.len = strlen ((char *) sl.buf);
562 SockList_AddInt (&sl, tag);
563 549
564 Send_With_Handling (&pl->socket, &sl); 550 Send_With_Handling (&pl->socket, &sl);
565 free (sl.buf); 551 sl.free ();
566} 552}
567 553
568 554
569/******************************************************************************* 555/*******************************************************************************
570 * 556 *
659 player_apply (pl->ob, op, 0, 0); 645 player_apply (pl->ob, op, 0, 0);
660} 646}
661 647
662/** Client wants to apply some object. Lets do so. */ 648/** Client wants to apply some object. Lets do so. */
663void 649void
664LockItem (uint8 * data, int len, player *pl) 650LockItem (uint8 *data, int len, player *pl)
665{ 651{
666 int flag, tag;
667 object *op;
668
669 flag = data[0]; 652 int flag = data[0];
670 tag = GetInt_String (data + 1); 653 tag_t tag = net_uint32 (data + 1);
671 op = esrv_get_ob_from_count (pl->ob, tag); 654 object *op = esrv_get_ob_from_count (pl->ob, tag);
672 655
673 if (!op) 656 if (!op)
674 { 657 {
675 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to lock/unlock"); 658 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to lock/unlock");
676 return; 659 return;
677 } 660 }
661
678 if (!flag) 662 if (!flag)
679 CLEAR_FLAG (op, FLAG_INV_LOCKED); 663 CLEAR_FLAG (op, FLAG_INV_LOCKED);
680 else 664 else
681 SET_FLAG (op, FLAG_INV_LOCKED); 665 SET_FLAG (op, FLAG_INV_LOCKED);
666
682 esrv_update_item (UPD_FLAGS, pl->ob, op); 667 esrv_update_item (UPD_FLAGS, pl->ob, op);
683} 668}
684 669
685/** Client wants to apply some object. Lets do so. */ 670/** Client wants to apply some object. Lets do so. */
686void 671void
687MarkItem (uint8 * data, int len, player *pl) 672MarkItem (uint8 * data, int len, player *pl)
688{ 673{
689 int tag; 674 tag_t tag = net_uint32 (data);
690 object *op;
691
692 tag = GetInt_String (data);
693 op = esrv_get_ob_from_count (pl->ob, tag); 675 object *op = esrv_get_ob_from_count (pl->ob, tag);
694 676
695 if (!op) 677 if (!op)
696 { 678 {
697 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark"); 679 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark");
698 return; 680 return;
699 } 681 }
700 682
701 pl->mark = op; 683 pl->mark = op;
702 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Marked item %s", query_name (op)); 684 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Marked item %s", query_name (op));
703} 685}
704
705 686
706/** 687/**
707 * look_at prints items on the specified square. 688 * look_at prints items on the specified square.
708 * 689 *
709 * [ removed EARTHWALL check and added check for containers inventory. 690 * [ removed EARTHWALL check and added check for containers inventory.
806 return; 787 return;
807 } 788 }
808 789
809 if (!to) 790 if (!to)
810 { /* drop it to the ground */ 791 { /* drop it to the ground */
811
812/* LOG(llevDebug, "Drop it on the ground.\n");*/
813
814 if (op->map && !op->env) 792 if (op->map && !op->env)
815 {
816
817/* LOG(llevDebug,"Dropping object to ground that is already on ground\n");*/
818 return; 793 return;
819 } 794
820 /* If it is an active container, then we should drop all objects 795 /* If it is an active container, then we should drop all objects
821 * in the container and not the container itself. 796 * in the container and not the container itself.
822 */ 797 */
823 if (op->inv && QUERY_FLAG (op, FLAG_APPLIED)) 798 if (op->inv && QUERY_FLAG (op, FLAG_APPLIED))
824 { 799 {
827 for (current = op->inv; current != NULL; current = next) 802 for (current = op->inv; current != NULL; current = next)
828 { 803 {
829 next = current->below; 804 next = current->below;
830 drop_object (pl, current, 0); 805 drop_object (pl, current, 0);
831 } 806 }
807
832 esrv_update_item (UPD_WEIGHT, pl, op); 808 esrv_update_item (UPD_WEIGHT, pl, op);
833 } 809 }
834 else 810 else
835 { 811 {
836 drop_object (pl, op, nrof); 812 drop_object (pl, op, nrof);
845 821
846 pl->contr->count = nrof; 822 pl->contr->count = nrof;
847 pick_up (pl, op); 823 pick_up (pl, op);
848 return; 824 return;
849 } 825 }
826
850 env = esrv_get_ob_from_count (pl, to); 827 env = esrv_get_ob_from_count (pl, to);
851 if (!env) 828 if (!env)
852 { 829 {
853 LOG (llevDebug, "Player '%s' tried to move object to the unknown location (%d)\n", &pl->name, to); 830 LOG (llevDebug, "Player '%s' tried to move object to the unknown location (%d)\n", &pl->name, to);
854 return; 831 return;
855 } 832 }
833
856 /* put_object_in_sack presumes that necessary sanity checking 834 /* put_object_in_sack presumes that necessary sanity checking
857 * has already been done (eg, it can be picked up and fits in 835 * has already been done (eg, it can be picked up and fits in
858 * in a sack, so check for those things. We should also check 836 * in a sack, so check for those things. We should also check
859 * an make sure env is in fact a container for that matter. 837 * an make sure env is in fact a container for that matter.
860 */ 838 */
861 if (env->type == CONTAINER && can_pick (pl, op) && sack_can_hold (pl, env, op, nrof)) 839 if (env->type == CONTAINER && can_pick (pl, op) && sack_can_hold (pl, env, op, nrof))
862 { 840 {
863 put_object_in_sack (pl, env, op, nrof); 841 put_object_in_sack (pl, env, op, nrof);
864 } 842 }
865} 843}
844

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines