… | |
… | |
135 | /* Used in the send_look to put object head into SockList |
135 | /* 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 |
136 | * sl for socket ns. Need socket to know if we need to send |
137 | * animation of face to the client. |
137 | * animation of face to the client. |
138 | */ |
138 | */ |
139 | static void |
139 | static void |
140 | add_object_to_socklist (NewSocket * ns, SockList * sl, object *head) |
140 | add_object_to_socklist (NewSocket &ns, SockList &sl, object *head) |
141 | { |
141 | { |
142 | int flags, len, anim_speed; |
142 | int flags, len, anim_speed; |
143 | char item_n[MAX_BUF]; |
143 | char item_n[MAX_BUF]; |
144 | const char *item_p; |
144 | const char *item_p; |
145 | |
145 | |
146 | flags = query_flags (head); |
146 | flags = query_flags (head); |
147 | if (QUERY_FLAG (head, FLAG_NO_PICK)) |
147 | if (QUERY_FLAG (head, FLAG_NO_PICK)) |
148 | flags |= F_NOPICK; |
148 | flags |= F_NOPICK; |
149 | |
149 | |
150 | if (!(ns->faces_sent[head->face->number] & NS_FACESENT_FACE)) |
150 | if (!(ns.faces_sent[head->face->number] & NS_FACESENT_FACE)) |
151 | esrv_send_face (ns, head->face->number, 0); |
151 | esrv_send_face (&ns, head->face->number, 0); |
152 | |
152 | |
153 | if (QUERY_FLAG (head, FLAG_ANIMATE) && !ns->anims_sent[head->animation_id]) |
153 | if (QUERY_FLAG (head, FLAG_ANIMATE) && !ns.anims_sent[head->animation_id]) |
154 | esrv_send_animation (ns, head->animation_id); |
154 | esrv_send_animation (&ns, head->animation_id); |
155 | |
155 | |
156 | SockList_AddInt (sl, head->count); |
156 | sl << uint32 (head->count) |
157 | SockList_AddInt (sl, flags); |
157 | << uint32 (flags) |
158 | SockList_AddInt (sl, QUERY_FLAG (head, FLAG_NO_PICK) ? -1 : WEIGHT (head)); |
158 | << uint32 (QUERY_FLAG (head, FLAG_NO_PICK) ? -1 : WEIGHT (head)) |
159 | SockList_AddInt (sl, head->face->number); |
159 | << uint32 (head->face->number); |
160 | |
160 | |
161 | if (!head->custom_name) |
161 | if (!head->custom_name) |
162 | { |
162 | { |
163 | strncpy (item_n, query_base_name (head, 0), 127); |
163 | strncpy (item_n, query_base_name (head, 0), 127); |
164 | item_n[127] = 0; |
164 | item_n[127] = 0; |
… | |
… | |
170 | strncpy (item_n, head->custom_name, 127); |
170 | strncpy (item_n, head->custom_name, 127); |
171 | item_n[127] = 0; |
171 | item_n[127] = 0; |
172 | len = strlen (item_n); |
172 | len = strlen (item_n); |
173 | item_p = head->custom_name; |
173 | item_p = head->custom_name; |
174 | } |
174 | } |
|
|
175 | |
175 | strncpy (item_n + len + 1, item_p, 127); |
176 | strncpy (item_n + len + 1, item_p, 127); |
176 | item_n[254] = 0; |
177 | item_n[254] = 0; |
177 | len += strlen (item_n + 1 + len) + 1; |
178 | 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 | |
179 | |
182 | SockList_AddShort (sl, head->animation_id); |
180 | sl << data8 (item_n, len) |
|
|
181 | << uint16 (head->animation_id); |
|
|
182 | |
183 | anim_speed = 0; |
183 | anim_speed = 0; |
184 | if (QUERY_FLAG (head, FLAG_ANIMATE)) |
184 | if (QUERY_FLAG (head, FLAG_ANIMATE)) |
185 | { |
185 | { |
186 | if (head->anim_speed) |
186 | if (head->anim_speed) |
187 | anim_speed = head->anim_speed; |
187 | anim_speed = head->anim_speed; |
… | |
… | |
192 | else if (FABS (head->speed) >= 1.0) |
192 | else if (FABS (head->speed) >= 1.0) |
193 | anim_speed = 1; |
193 | anim_speed = 1; |
194 | else |
194 | else |
195 | anim_speed = (int) (1.0 / FABS (head->speed)); |
195 | anim_speed = (int) (1.0 / FABS (head->speed)); |
196 | } |
196 | } |
|
|
197 | |
197 | if (anim_speed > 255) |
198 | if (anim_speed > 255) |
198 | anim_speed = 255; |
199 | anim_speed = 255; |
199 | } |
200 | } |
200 | SockList_AddChar (sl, (char) anim_speed); |
|
|
201 | SockList_AddInt (sl, head->nrof); |
|
|
202 | |
201 | |
|
|
202 | sl << uint8 (anim_speed) |
|
|
203 | << uint32 (head->nrof); |
|
|
204 | |
203 | if (ns->itemcmd == 2) |
205 | if (ns.itemcmd == 2) |
204 | SockList_AddShort (sl, head->client_type); |
206 | sl << uint16 (head->client_type); |
205 | |
207 | |
206 | SET_FLAG (head, FLAG_CLIENT_SENT); |
208 | SET_FLAG (head, FLAG_CLIENT_SENT); |
207 | } |
209 | } |
208 | |
210 | |
209 | |
211 | |
… | |
… | |
216 | void |
218 | void |
217 | esrv_draw_look (object *pl) |
219 | esrv_draw_look (object *pl) |
218 | { |
220 | { |
219 | object *tmp, *last; |
221 | object *tmp, *last; |
220 | int got_one = 0, start_look = 0, end_look = 0; |
222 | int got_one = 0, start_look = 0, end_look = 0; |
221 | SockList sl; |
|
|
222 | char buf[MAX_BUF]; |
223 | char buf[MAX_BUF]; |
223 | |
224 | |
224 | if (!pl->contr->socket.update_look) |
225 | if (!pl->contr->socket.update_look) |
225 | { |
226 | { |
226 | LOG (llevDebug, "esrv_draw_look called when update_look was not set\n"); |
227 | LOG (llevDebug, "esrv_draw_look called when update_look was not set\n"); |
227 | return; |
228 | return; |
228 | } |
229 | } |
229 | else |
230 | else |
230 | { |
|
|
231 | pl->contr->socket.update_look = 0; |
231 | pl->contr->socket.update_look = 0; |
232 | } |
|
|
233 | |
232 | |
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)) |
233 | if (QUERY_FLAG (pl, FLAG_REMOVED) |
|
|
234 | || !pl->map |
|
|
235 | || pl->map->in_memory != MAP_IN_MEMORY |
|
|
236 | || out_of_map (pl->map, pl->x, pl->y)) |
235 | return; |
237 | return; |
236 | |
238 | |
237 | for (tmp = get_map_ob (pl->map, pl->x, pl->y); tmp && tmp->above; tmp = tmp->above); |
239 | for (tmp = get_map_ob (pl->map, pl->x, pl->y); tmp && tmp->above; tmp = tmp->above); |
238 | |
240 | |
239 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
241 | SockList sl (MAXSOCKBUF); |
240 | |
242 | |
241 | Write_String_To_Socket (&pl->contr->socket, "delinv 0", strlen ("delinv 0")); |
243 | Write_String_To_Socket (&pl->contr->socket, "delinv 0", sizeof ("delinv 0") - 1); |
|
|
244 | |
242 | sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd); |
245 | sl.printf ("item%d ", pl->contr->socket.itemcmd); |
243 | sl.len = strlen ((char *) sl.buf); |
|
|
244 | |
246 | |
245 | SockList_AddInt (&sl, 0); |
247 | sl << uint32 (0); |
246 | |
248 | |
247 | if (!(pl->contr->socket.faces_sent[empty_face->number] & NS_FACESENT_FACE)) |
249 | if (!(pl->contr->socket.faces_sent[empty_face->number] & NS_FACESENT_FACE)) |
248 | esrv_send_face (&pl->contr->socket, empty_face->number, 0); |
250 | esrv_send_face (&pl->contr->socket, empty_face->number, 0); |
249 | |
251 | |
250 | if (pl->contr->socket.look_position) |
252 | if (pl->contr->socket.look_position) |
251 | { |
253 | { |
252 | SockList_AddInt (&sl, 0x80000000 | (pl->contr->socket.look_position - NUM_LOOK_OBJECTS)); |
254 | sl << uint32 (0x80000000 | (pl->contr->socket.look_position - NUM_LOOK_OBJECTS)) |
253 | SockList_AddInt (&sl, 0); |
255 | << uint32 (0) |
254 | SockList_AddInt (&sl, (uint32) - 1); |
256 | << sint32 (-1) |
255 | SockList_AddInt (&sl, empty_face->number); |
257 | << uint32 (empty_face->number); |
|
|
258 | |
256 | sprintf (buf, "Click here to see %d previous items", NUM_LOOK_OBJECTS); |
259 | sl.printf ("Click here to see %d previous items", NUM_LOOK_OBJECTS); |
257 | add_stringlen_to_sockbuf (buf, &sl); |
260 | |
258 | SockList_AddShort (&sl, 0); |
261 | sl << uint16 (0) |
259 | SockList_AddChar (&sl, 0); |
262 | << uint8 (0) |
260 | SockList_AddInt (&sl, 0); |
263 | << uint32 (0); |
|
|
264 | |
261 | if (pl->contr->socket.itemcmd == 2) |
265 | if (pl->contr->socket.itemcmd == 2) |
262 | SockList_AddShort (&sl, 0); |
266 | sl << uint16 (0); |
263 | } |
267 | } |
264 | |
268 | |
265 | for (last = NULL; tmp != last; tmp = tmp->below) |
269 | for (last = NULL; tmp != last; tmp = tmp->below) |
266 | { |
270 | { |
267 | object *head; |
271 | object *head; |
… | |
… | |
270 | { |
274 | { |
271 | last = tmp->below; /* assumes double floor mode */ |
275 | last = tmp->below; /* assumes double floor mode */ |
272 | if (last && QUERY_FLAG (last, FLAG_IS_FLOOR)) |
276 | if (last && QUERY_FLAG (last, FLAG_IS_FLOOR)) |
273 | last = last->below; |
277 | last = last->below; |
274 | } |
278 | } |
|
|
279 | |
275 | if (LOOK_OBJ (tmp)) |
280 | if (LOOK_OBJ (tmp)) |
276 | { |
281 | { |
277 | if (++start_look < pl->contr->socket.look_position) |
282 | if (++start_look < pl->contr->socket.look_position) |
278 | continue; |
283 | continue; |
|
|
284 | |
279 | end_look++; |
285 | end_look++; |
|
|
286 | |
280 | if (end_look > NUM_LOOK_OBJECTS) |
287 | if (end_look > NUM_LOOK_OBJECTS) |
281 | { |
288 | { |
282 | /* What we basically do is make a 'fake' object - when the user applies it, |
289 | /* 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. |
290 | * we notice the special tag the object has, and act accordingly. |
284 | */ |
291 | */ |
… | |
… | |
298 | if (tmp->head) |
305 | if (tmp->head) |
299 | head = tmp->head; |
306 | head = tmp->head; |
300 | else |
307 | else |
301 | head = tmp; |
308 | head = tmp; |
302 | |
309 | |
303 | add_object_to_socklist (&pl->contr->socket, &sl, head); |
310 | add_object_to_socklist (pl->contr->socket, sl, head); |
304 | got_one++; |
311 | got_one++; |
305 | |
312 | |
306 | if (sl.len >= (MAXSOCKBUF - MAXITEMLEN)) |
313 | if (sl.len >= (MAXSOCKBUF - MAXITEMLEN)) |
307 | { |
314 | { |
308 | Send_With_Handling (&pl->contr->socket, &sl); |
315 | Send_With_Handling (&pl->contr->socket, &sl); |
… | |
… | |
311 | SockList_AddInt (&sl, 0); |
318 | SockList_AddInt (&sl, 0); |
312 | got_one = 0; |
319 | got_one = 0; |
313 | } |
320 | } |
314 | } /* If LOOK_OBJ() */ |
321 | } /* If LOOK_OBJ() */ |
315 | } |
322 | } |
|
|
323 | |
316 | if (got_one) |
324 | if (got_one) |
317 | Send_With_Handling (&pl->contr->socket, &sl); |
325 | Send_With_Handling (&pl->contr->socket, &sl); |
318 | |
326 | |
319 | free (sl.buf); |
327 | sl.free (); |
320 | } |
328 | } |
321 | |
329 | |
322 | /** |
330 | /** |
323 | * Sends whole inventory. |
331 | * Sends whole inventory. |
324 | */ |
332 | */ |
… | |
… | |
349 | else |
357 | else |
350 | head = tmp; |
358 | head = tmp; |
351 | |
359 | |
352 | if (LOOK_OBJ (head)) |
360 | if (LOOK_OBJ (head)) |
353 | { |
361 | { |
354 | add_object_to_socklist (&pl->contr->socket, &sl, head); |
362 | add_object_to_socklist (pl->contr->socket, sl, head); |
355 | |
363 | |
356 | got_one++; |
364 | got_one++; |
357 | |
365 | |
358 | /* IT is possible for players to accumulate a huge amount of |
366 | /* IT is possible for players to accumulate a huge amount of |
359 | * items (especially with some of the bags out there) to |
367 | * items (especially with some of the bags out there) to |
… | |
… | |
369 | } |
377 | } |
370 | } /* If LOOK_OBJ() */ |
378 | } /* If LOOK_OBJ() */ |
371 | } |
379 | } |
372 | if (got_one) |
380 | if (got_one) |
373 | Send_With_Handling (&pl->contr->socket, &sl); |
381 | Send_With_Handling (&pl->contr->socket, &sl); |
374 | free (sl.buf); |
382 | sl.free (); |
375 | } |
383 | } |
376 | |
384 | |
377 | /** |
385 | /** |
378 | * Updates object *op for player *pl. |
386 | * Updates object *op for player *pl. |
379 | * |
387 | * |
… | |
… | |
499 | } |
507 | } |
500 | if (flags & UPD_NROF) |
508 | if (flags & UPD_NROF) |
501 | SockList_AddInt (&sl, op->nrof); |
509 | SockList_AddInt (&sl, op->nrof); |
502 | |
510 | |
503 | Send_With_Handling (&pl->contr->socket, &sl); |
511 | Send_With_Handling (&pl->contr->socket, &sl); |
504 | free (sl.buf); |
512 | sl.free (); |
505 | } |
513 | } |
506 | |
514 | |
507 | /** |
515 | /** |
508 | * Sends item's info to player. |
516 | * Sends item's info to player. |
509 | */ |
517 | */ |
… | |
… | |
536 | if (op->head) |
544 | if (op->head) |
537 | op = op->head; |
545 | op = op->head; |
538 | |
546 | |
539 | SockList_AddInt (&sl, op->env ? op->env->count : 0); |
547 | SockList_AddInt (&sl, op->env ? op->env->count : 0); |
540 | |
548 | |
541 | add_object_to_socklist (&pl->contr->socket, &sl, op); |
549 | add_object_to_socklist (pl->contr->socket, sl, op); |
542 | |
550 | |
543 | Send_With_Handling (&pl->contr->socket, &sl); |
551 | Send_With_Handling (&pl->contr->socket, &sl); |
544 | SET_FLAG (op, FLAG_CLIENT_SENT); |
552 | SET_FLAG (op, FLAG_CLIENT_SENT); |
545 | free (sl.buf); |
553 | |
|
|
554 | sl.free (); |
546 | } |
555 | } |
547 | |
556 | |
548 | /** |
557 | /** |
549 | * Tells the client to delete an item. Uses the item |
558 | * Tells the client to delete an item. Uses the item |
550 | * command with a -1 location. |
559 | * command with a -1 location. |
… | |
… | |
560 | strcpy ((char *) sl.buf, "delitem "); |
569 | strcpy ((char *) sl.buf, "delitem "); |
561 | sl.len = strlen ((char *) sl.buf); |
570 | sl.len = strlen ((char *) sl.buf); |
562 | SockList_AddInt (&sl, tag); |
571 | SockList_AddInt (&sl, tag); |
563 | |
572 | |
564 | Send_With_Handling (&pl->socket, &sl); |
573 | Send_With_Handling (&pl->socket, &sl); |
565 | free (sl.buf); |
574 | sl.free (); |
566 | } |
575 | } |
567 | |
576 | |
568 | |
577 | |
569 | /******************************************************************************* |
578 | /******************************************************************************* |
570 | * |
579 | * |