… | |
… | |
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 | */ |
|
|
59 | inline void |
|
|
60 | add_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 | */ |
… | |
… | |
130 | flags |= F_LOCKED; |
109 | flags |= F_LOCKED; |
131 | |
110 | |
132 | return flags; |
111 | return flags; |
133 | } |
112 | } |
134 | |
113 | |
135 | /* Used in the send_look to put object head into SockList |
114 | /* Used in the send_look to put object head into packet |
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 | */ |
139 | static void |
118 | static void |
140 | add_object_to_socklist (NewSocket * ns, SockList * sl, object *head) |
119 | add_object_to_socklist (client_socket &ns, packet &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 | |
… | |
… | |
216 | void |
197 | void |
217 | esrv_draw_look (object *pl) |
198 | esrv_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 | packet sl; |
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.length () >= (MAXSOCKBUF - MAXITEMLEN)) |
307 | { |
298 | { |
308 | Send_With_Handling (&pl->contr->socket, &sl); |
299 | pl->contr->socket->send_packet (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 | pl->contr->socket->send_packet (sl); |
318 | |
311 | |
319 | free (sl.buf); |
|
|
320 | } |
312 | } |
321 | |
313 | |
322 | /** |
314 | /** |
323 | * Sends whole inventory. |
315 | * Sends whole inventory. |
324 | */ |
316 | */ |
325 | void |
317 | void |
326 | esrv_send_inventory (object *pl, object *op) |
318 | esrv_send_inventory (object *pl, object *op) |
327 | { |
319 | { |
328 | object *tmp; |
320 | object *tmp; |
329 | int got_one = 0; |
321 | int got_one = 0; |
330 | SockList sl; |
|
|
331 | |
322 | |
332 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
323 | packet sl; |
333 | |
324 | |
334 | sprintf ((char *) sl.buf, "delinv %d", op->count); |
325 | sl.printf ("delinv %d", op->count); |
335 | sl.len = strlen ((char *) sl.buf); |
326 | pl->contr->socket->send_packet (sl); |
336 | Send_With_Handling (&pl->contr->socket, &sl); |
|
|
337 | |
327 | |
|
|
328 | sl.reset (); |
338 | sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd); |
329 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
339 | sl.len = strlen ((char *) sl.buf); |
|
|
340 | |
330 | |
341 | SockList_AddInt (&sl, op->count); |
331 | sl << uint32 (op->count); |
342 | |
332 | |
343 | for (tmp = op->inv; tmp; tmp = tmp->below) |
333 | for (tmp = op->inv; tmp; tmp = tmp->below) |
344 | { |
334 | { |
345 | object *head; |
335 | object *head; |
346 | |
336 | |
… | |
… | |
349 | else |
339 | else |
350 | head = tmp; |
340 | head = tmp; |
351 | |
341 | |
352 | if (LOOK_OBJ (head)) |
342 | if (LOOK_OBJ (head)) |
353 | { |
343 | { |
354 | add_object_to_socklist (&pl->contr->socket, &sl, head); |
344 | add_object_to_socklist (*pl->contr->socket, sl, head); |
355 | |
345 | |
356 | got_one++; |
346 | got_one++; |
357 | |
347 | |
358 | /* IT is possible for players to accumulate a huge amount of |
348 | /* IT is possible for players to accumulate a huge amount of |
359 | * items (especially with some of the bags out there) to |
349 | * items (especially with some of the bags out there) to |
360 | * overflow the buffer. IF so, send multiple item commands. |
350 | * overflow the buffer. IF so, send multiple item commands. |
361 | */ |
351 | */ |
362 | if (sl.len >= (MAXSOCKBUF - MAXITEMLEN)) |
352 | if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN)) |
363 | { |
353 | { |
364 | Send_With_Handling (&pl->contr->socket, &sl); |
354 | pl->contr->socket->send_packet (sl); |
|
|
355 | |
|
|
356 | sl.reset (); |
365 | sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd); |
357 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
366 | sl.len = strlen ((char *) sl.buf); |
358 | sl << uint32 (op->count); |
367 | SockList_AddInt (&sl, 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 | pl->contr->socket->send_packet (sl); |
374 | free (sl.buf); |
366 | |
375 | } |
367 | } |
376 | |
368 | |
377 | /** |
369 | /** |
378 | * Updates object *op for player *pl. |
370 | * Updates object *op for player *pl. |
379 | * |
371 | * |
… | |
… | |
383 | */ |
375 | */ |
384 | |
376 | |
385 | void |
377 | void |
386 | esrv_update_item (int flags, object *pl, object *op) |
378 | esrv_update_item (int flags, object *pl, object *op) |
387 | { |
379 | { |
388 | SockList sl; |
|
|
389 | |
|
|
390 | /* If we have a request to send the player item, skip a few checks. */ |
380 | /* If we have a request to send the player item, skip a few checks. */ |
391 | if (op != pl) |
381 | if (op != pl) |
392 | { |
382 | { |
393 | if (!LOOK_OBJ (op)) |
383 | if (!LOOK_OBJ (op)) |
394 | return; |
384 | return; |
395 | /* we remove the check for op->env, because in theory, the object |
385 | /* we remove the check for op->env, because in theory, the object |
396 | * is hopefully in the same place, so the client should preserve |
386 | * is hopefully in the same place, so the client should preserve |
397 | * order. |
387 | * order. |
398 | */ |
388 | */ |
399 | } |
389 | } |
|
|
390 | |
400 | if (!QUERY_FLAG (op, FLAG_CLIENT_SENT)) |
391 | if (!QUERY_FLAG (op, FLAG_CLIENT_SENT)) |
401 | { |
392 | { |
402 | /* FLAG_CLIENT_SENT is debug only. We are using it to see where |
393 | /* FLAG_CLIENT_SENT is debug only. We are using it to see where |
403 | * this is happening - we can set a breakpoint here in the debugger |
394 | * this is happening - we can set a breakpoint here in the debugger |
404 | * and track back the call. |
395 | * and track back the call. |
405 | */ |
396 | */ |
406 | LOG (llevDebug, "We have not sent item %s (%d)\n", &op->name, op->count); |
397 | LOG (llevDebug, "We have not sent item %s (%d)\n", &op->name, op->count); |
407 | } |
398 | } |
408 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
|
|
409 | |
399 | |
410 | strcpy ((char *) sl.buf, "upditem "); |
400 | packet sl; |
411 | sl.len = strlen ((char *) sl.buf); |
|
|
412 | |
401 | |
413 | SockList_AddChar (&sl, (char) flags); |
402 | sl << "upditem " |
|
|
403 | << uint8 (flags); |
414 | |
404 | |
415 | if (op->head) |
405 | if (op->head) |
416 | op = op->head; |
406 | op = op->head; |
417 | |
407 | |
418 | SockList_AddInt (&sl, op->count); |
408 | sl << uint32 (op->count); |
419 | |
409 | |
420 | if (flags & UPD_LOCATION) |
410 | if (flags & UPD_LOCATION) |
421 | SockList_AddInt (&sl, op->env ? op->env->count : 0); |
411 | sl << uint32 (op->env ? op->env->count : 0); |
422 | |
412 | |
423 | if (flags & UPD_FLAGS) |
413 | if (flags & UPD_FLAGS) |
424 | SockList_AddInt (&sl, query_flags (op)); |
414 | sl << uint32 (query_flags (op)); |
425 | |
415 | |
426 | if (flags & UPD_WEIGHT) |
416 | if (flags & UPD_WEIGHT) |
427 | { |
417 | { |
428 | sint32 weight = WEIGHT (op); |
418 | sint32 weight = WEIGHT (op); |
429 | |
419 | |
430 | SockList_AddInt (&sl, QUERY_FLAG (op, FLAG_NO_PICK) ? -1 : weight); |
420 | sl << uint32 (QUERY_FLAG (op, FLAG_NO_PICK) ? -1 : weight); |
|
|
421 | |
431 | if (pl == op) |
422 | if (pl == op) |
432 | { |
|
|
433 | op->contr->last_weight = weight; |
423 | op->contr->last_weight = weight; |
434 | } |
|
|
435 | } |
424 | } |
436 | |
425 | |
437 | if (flags & UPD_FACE) |
426 | if (flags & UPD_FACE) |
438 | { |
427 | { |
439 | if (!(pl->contr->socket.faces_sent[op->face->number] & NS_FACESENT_FACE)) |
428 | if (!(pl->contr->socket->faces_sent[op->face->number] & NS_FACESENT_FACE)) |
440 | esrv_send_face (&pl->contr->socket, op->face->number, 0); |
429 | esrv_send_face (pl->contr->socket, op->face->number, 0); |
441 | SockList_AddInt (&sl, op->face->number); |
430 | |
|
|
431 | sl << uint32 (op->face->number); |
442 | } |
432 | } |
|
|
433 | |
443 | if (flags & UPD_NAME) |
434 | if (flags & UPD_NAME) |
444 | { |
435 | { |
445 | int len; |
436 | int len; |
446 | const char *item_p; |
437 | const char *item_p; |
447 | char item_n[MAX_BUF]; |
438 | char item_n[MAX_BUF]; |
… | |
… | |
462 | } |
453 | } |
463 | |
454 | |
464 | strncpy (item_n + len + 1, item_p, 127); |
455 | strncpy (item_n + len + 1, item_p, 127); |
465 | item_n[254] = 0; |
456 | item_n[254] = 0; |
466 | len += strlen (item_n + 1 + len) + 1; |
457 | len += strlen (item_n + 1 + len) + 1; |
467 | SockList_AddChar (&sl, (char) len); |
458 | |
468 | memcpy (sl.buf + sl.len, item_n, len); |
459 | sl << data8 (item_n, len); |
469 | sl.len += len; |
|
|
470 | } |
460 | } |
|
|
461 | |
471 | if (flags & UPD_ANIM) |
462 | if (flags & UPD_ANIM) |
472 | SockList_AddShort (&sl, op->animation_id); |
463 | sl << uint16 (op->animation_id); |
473 | |
464 | |
474 | if (flags & UPD_ANIMSPEED) |
465 | if (flags & UPD_ANIMSPEED) |
475 | { |
466 | { |
476 | int anim_speed = 0; |
467 | int anim_speed = 0; |
477 | |
468 | |
… | |
… | |
486 | else if (FABS (op->speed) >= 1.0) |
477 | else if (FABS (op->speed) >= 1.0) |
487 | anim_speed = 1; |
478 | anim_speed = 1; |
488 | else |
479 | else |
489 | anim_speed = (int) (1.0 / FABS (op->speed)); |
480 | anim_speed = (int) (1.0 / FABS (op->speed)); |
490 | } |
481 | } |
|
|
482 | |
491 | if (anim_speed > 255) |
483 | if (anim_speed > 255) |
492 | anim_speed = 255; |
484 | anim_speed = 255; |
493 | } |
485 | } |
494 | SockList_AddChar (&sl, (char) anim_speed); |
486 | |
|
|
487 | sl << uint8 (anim_speed); |
495 | } |
488 | } |
|
|
489 | |
496 | if (flags & UPD_NROF) |
490 | if (flags & UPD_NROF) |
497 | SockList_AddInt (&sl, op->nrof); |
491 | sl << uint32 (op->nrof); |
498 | |
492 | |
499 | Send_With_Handling (&pl->contr->socket, &sl); |
493 | pl->contr->socket->send_packet (sl); |
500 | free (sl.buf); |
|
|
501 | } |
494 | } |
502 | |
495 | |
503 | /** |
496 | /** |
504 | * Sends item's info to player. |
497 | * Sends item's info to player. |
505 | */ |
498 | */ |
506 | void |
499 | void |
507 | esrv_send_item (object *pl, object *op) |
500 | esrv_send_item (object *pl, object *op) |
508 | { |
501 | { |
509 | SockList sl; |
|
|
510 | |
|
|
511 | /* If this is not the player object, do some more checks */ |
502 | /* If this is not the player object, do some more checks */ |
512 | if (op != pl) |
503 | if (op != pl) |
513 | { |
504 | { |
514 | /* We only send 'visibile' objects to the client */ |
505 | /* We only send 'visibile' objects to the client */ |
515 | if (!LOOK_OBJ (op)) |
506 | if (!LOOK_OBJ (op)) |
… | |
… | |
517 | /* if the item is on the ground, mark that the look needs to |
508 | /* if the item is on the ground, mark that the look needs to |
518 | * be updated. |
509 | * be updated. |
519 | */ |
510 | */ |
520 | if (!op->env) |
511 | if (!op->env) |
521 | { |
512 | { |
522 | pl->contr->socket.update_look = 1; |
513 | pl->contr->socket->update_look = 1; |
523 | return; |
514 | return; |
524 | } |
515 | } |
525 | } |
516 | } |
526 | |
517 | |
527 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
518 | packet sl; |
528 | |
519 | |
529 | sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd); |
520 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
530 | sl.len = strlen ((char *) sl.buf); |
|
|
531 | |
521 | |
532 | if (op->head) |
522 | if (op->head) |
533 | op = op->head; |
523 | op = op->head; |
534 | |
524 | |
535 | SockList_AddInt (&sl, op->env ? op->env->count : 0); |
525 | sl << uint32 (op->env ? op->env->count : 0); |
536 | |
526 | |
537 | add_object_to_socklist (&pl->contr->socket, &sl, op); |
527 | add_object_to_socklist (*pl->contr->socket, sl, op); |
538 | |
528 | |
539 | Send_With_Handling (&pl->contr->socket, &sl); |
529 | pl->contr->socket->send_packet (sl); |
540 | SET_FLAG (op, FLAG_CLIENT_SENT); |
530 | SET_FLAG (op, FLAG_CLIENT_SENT); |
541 | free (sl.buf); |
531 | |
542 | } |
532 | } |
543 | |
533 | |
544 | /** |
534 | /** |
545 | * Tells the client to delete an item. Uses the item |
535 | * Tells the client to delete an item. Uses the item |
546 | * command with a -1 location. |
536 | * command with a -1 location. |
547 | */ |
537 | */ |
548 | |
538 | |
549 | void |
539 | void |
550 | esrv_del_item (player *pl, int tag) |
540 | esrv_del_item (player *pl, int tag) |
551 | { |
541 | { |
552 | SockList sl; |
542 | packet sl; |
553 | |
543 | |
554 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
544 | sl << "delitem " |
|
|
545 | << uint32 (tag); |
555 | |
546 | |
556 | strcpy ((char *) sl.buf, "delitem "); |
547 | pl->socket->send_packet (sl); |
557 | sl.len = strlen ((char *) sl.buf); |
|
|
558 | SockList_AddInt (&sl, tag); |
|
|
559 | |
|
|
560 | Send_With_Handling (&pl->socket, &sl); |
|
|
561 | free (sl.buf); |
|
|
562 | } |
548 | } |
563 | |
549 | |
564 | |
550 | |
565 | /******************************************************************************* |
551 | /******************************************************************************* |
566 | * |
552 | * |
… | |
… | |
605 | |
591 | |
606 | /** Client wants to examine some object. So lets do so. */ |
592 | /** Client wants to examine some object. So lets do so. */ |
607 | void |
593 | void |
608 | ExamineCmd (char *buf, int len, player *pl) |
594 | ExamineCmd (char *buf, int len, player *pl) |
609 | { |
595 | { |
610 | long tag = atoi (buf); |
596 | tag_t tag = atoi (buf); |
|
|
597 | |
|
|
598 | /* If the high bit is set, player examined a pseudo object. */ |
|
|
599 | if (tag & 0x80000000) |
|
|
600 | return; |
|
|
601 | |
611 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
602 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
612 | |
603 | |
613 | if (!op) |
604 | if (!op) |
614 | { |
605 | { |
615 | LOG (llevDebug, "Player '%s' tried to examine the unknown object (%ld)\n", &pl->ob->name, tag); |
606 | LOG (llevDebug, "Player '%s' tried to examine the unknown object (%ld)\n", &pl->ob->name, tag); |
616 | return; |
607 | return; |
617 | } |
608 | } |
|
|
609 | |
618 | examine (pl->ob, op); |
610 | examine (pl->ob, op); |
619 | } |
611 | } |
620 | |
612 | |
621 | /** Client wants to apply some object. Lets do so. */ |
613 | /** Client wants to apply some object. Lets do so. */ |
622 | void |
614 | void |
623 | ApplyCmd (char *buf, int len, player *pl) |
615 | ApplyCmd (char *buf, int len, player *pl) |
624 | { |
616 | { |
625 | uint32 tag = atoi (buf); |
617 | tag_t tag = atoi (buf); |
626 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
|
|
627 | |
618 | |
628 | /* sort of a hack, but if the player saves and the player then manually |
619 | /* sort of a hack, but if the player saves and the player then manually |
629 | * applies a savebed (or otherwise tries to do stuff), we run into trouble. |
620 | * applies a savebed (or otherwise tries to do stuff), we run into trouble. |
630 | */ |
621 | */ |
631 | if (QUERY_FLAG (pl->ob, FLAG_REMOVED)) |
622 | if (QUERY_FLAG (pl->ob, FLAG_REMOVED)) |
632 | return; |
623 | return; |
633 | |
624 | |
634 | /* If the high bit is set, player applied a pseudo object. */ |
625 | /* If the high bit is set, player applied a pseudo object. */ |
635 | if (tag & 0x80000000) |
626 | if (tag & 0x80000000) |
636 | { |
627 | { |
637 | pl->socket.look_position = tag & 0x7fffffff; |
628 | pl->socket->look_position = tag & 0x7fffffff; |
638 | pl->socket.update_look = 1; |
629 | pl->socket->update_look = 1; |
639 | return; |
630 | return; |
640 | } |
631 | } |
|
|
632 | |
|
|
633 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
641 | |
634 | |
642 | if (!op) |
635 | if (!op) |
643 | { |
636 | { |
644 | LOG (llevDebug, "Player '%s' tried to apply the unknown object (%d)\n", &pl->ob->name, tag); |
637 | LOG (llevDebug, "Player '%s' tried to apply the unknown object (%d)\n", &pl->ob->name, tag); |
645 | return; |
638 | return; |
646 | } |
639 | } |
|
|
640 | |
647 | player_apply (pl->ob, op, 0, 0); |
641 | player_apply (pl->ob, op, 0, 0); |
648 | } |
642 | } |
649 | |
643 | |
650 | /** Client wants to apply some object. Lets do so. */ |
644 | /** Client wants to apply some object. Lets do so. */ |
651 | void |
645 | void |
652 | LockItem (uint8 * data, int len, player *pl) |
646 | LockItem (uint8 *data, int len, player *pl) |
653 | { |
647 | { |
654 | int flag, tag; |
|
|
655 | object *op; |
|
|
656 | |
|
|
657 | flag = data[0]; |
648 | int flag = data[0]; |
658 | tag = GetInt_String (data + 1); |
649 | tag_t tag = net_uint32 (data + 1); |
659 | op = esrv_get_ob_from_count (pl->ob, tag); |
650 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
660 | |
651 | |
661 | if (!op) |
652 | if (!op) |
662 | { |
653 | { |
663 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to lock/unlock"); |
654 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to lock/unlock"); |
664 | return; |
655 | return; |
665 | } |
656 | } |
|
|
657 | |
666 | if (!flag) |
658 | if (!flag) |
667 | CLEAR_FLAG (op, FLAG_INV_LOCKED); |
659 | CLEAR_FLAG (op, FLAG_INV_LOCKED); |
668 | else |
660 | else |
669 | SET_FLAG (op, FLAG_INV_LOCKED); |
661 | SET_FLAG (op, FLAG_INV_LOCKED); |
|
|
662 | |
670 | esrv_update_item (UPD_FLAGS, pl->ob, op); |
663 | esrv_update_item (UPD_FLAGS, pl->ob, op); |
671 | } |
664 | } |
672 | |
665 | |
673 | /** Client wants to apply some object. Lets do so. */ |
666 | /** Client wants to apply some object. Lets do so. */ |
674 | void |
667 | void |
675 | MarkItem (uint8 * data, int len, player *pl) |
668 | MarkItem (uint8 * data, int len, player *pl) |
676 | { |
669 | { |
677 | int tag; |
670 | tag_t tag = net_uint32 (data); |
678 | object *op; |
|
|
679 | |
|
|
680 | tag = GetInt_String (data); |
|
|
681 | op = esrv_get_ob_from_count (pl->ob, tag); |
671 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
|
|
672 | |
682 | if (!op) |
673 | if (!op) |
683 | { |
674 | { |
684 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark"); |
675 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark"); |
685 | return; |
676 | return; |
686 | } |
677 | } |
|
|
678 | |
687 | pl->mark = op; |
679 | pl->mark = op; |
688 | pl->mark_count = op->count; |
|
|
689 | new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Marked item %s", query_name (op)); |
680 | new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Marked item %s", query_name (op)); |
690 | } |
681 | } |
691 | |
|
|
692 | |
682 | |
693 | /** |
683 | /** |
694 | * look_at prints items on the specified square. |
684 | * look_at prints items on the specified square. |
695 | * |
685 | * |
696 | * [ removed EARTHWALL check and added check for containers inventory. |
686 | * [ removed EARTHWALL check and added check for containers inventory. |
… | |
… | |
769 | { |
759 | { |
770 | return; |
760 | return; |
771 | } |
761 | } |
772 | dy = atoi (cp); |
762 | dy = atoi (cp); |
773 | |
763 | |
774 | if (FABS (dx) > pl->socket.mapx / 2 || FABS (dy) > pl->socket.mapy / 2) |
764 | if (FABS (dx) > pl->socket->mapx / 2 || FABS (dy) > pl->socket->mapy / 2) |
775 | return; |
765 | return; |
776 | |
766 | |
777 | if (pl->blocked_los[dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2]) |
767 | if (pl->blocked_los[dx + pl->socket->mapx / 2][dy + pl->socket->mapy / 2]) |
778 | return; |
768 | return; |
779 | |
769 | |
780 | look_at (pl->ob, dx, dy); |
770 | look_at (pl->ob, dx, dy); |
781 | } |
771 | } |
782 | |
772 | |
… | |
… | |
793 | return; |
783 | return; |
794 | } |
784 | } |
795 | |
785 | |
796 | if (!to) |
786 | if (!to) |
797 | { /* drop it to the ground */ |
787 | { /* drop it to the ground */ |
798 | |
|
|
799 | /* LOG(llevDebug, "Drop it on the ground.\n");*/ |
|
|
800 | |
|
|
801 | if (op->map && !op->env) |
788 | if (op->map && !op->env) |
802 | { |
|
|
803 | |
|
|
804 | /* LOG(llevDebug,"Dropping object to ground that is already on ground\n");*/ |
|
|
805 | return; |
789 | return; |
806 | } |
790 | |
807 | /* If it is an active container, then we should drop all objects |
791 | /* If it is an active container, then we should drop all objects |
808 | * in the container and not the container itself. |
792 | * in the container and not the container itself. |
809 | */ |
793 | */ |
810 | if (op->inv && QUERY_FLAG (op, FLAG_APPLIED)) |
794 | if (op->inv && QUERY_FLAG (op, FLAG_APPLIED)) |
811 | { |
795 | { |
… | |
… | |
814 | for (current = op->inv; current != NULL; current = next) |
798 | for (current = op->inv; current != NULL; current = next) |
815 | { |
799 | { |
816 | next = current->below; |
800 | next = current->below; |
817 | drop_object (pl, current, 0); |
801 | drop_object (pl, current, 0); |
818 | } |
802 | } |
|
|
803 | |
819 | esrv_update_item (UPD_WEIGHT, pl, op); |
804 | esrv_update_item (UPD_WEIGHT, pl, op); |
820 | } |
805 | } |
821 | else |
806 | else |
822 | { |
807 | { |
823 | drop_object (pl, op, nrof); |
808 | drop_object (pl, op, nrof); |
… | |
… | |
832 | |
817 | |
833 | pl->contr->count = nrof; |
818 | pl->contr->count = nrof; |
834 | pick_up (pl, op); |
819 | pick_up (pl, op); |
835 | return; |
820 | return; |
836 | } |
821 | } |
|
|
822 | |
837 | env = esrv_get_ob_from_count (pl, to); |
823 | env = esrv_get_ob_from_count (pl, to); |
838 | if (!env) |
824 | if (!env) |
839 | { |
825 | { |
840 | LOG (llevDebug, "Player '%s' tried to move object to the unknown location (%d)\n", &pl->name, to); |
826 | LOG (llevDebug, "Player '%s' tried to move object to the unknown location (%d)\n", &pl->name, to); |
841 | return; |
827 | return; |
842 | } |
828 | } |
|
|
829 | |
843 | /* put_object_in_sack presumes that necessary sanity checking |
830 | /* put_object_in_sack presumes that necessary sanity checking |
844 | * has already been done (eg, it can be picked up and fits in |
831 | * has already been done (eg, it can be picked up and fits in |
845 | * in a sack, so check for those things. We should also check |
832 | * in a sack, so check for those things. We should also check |
846 | * an make sure env is in fact a container for that matter. |
833 | * an make sure env is in fact a container for that matter. |
847 | */ |
834 | */ |
848 | if (env->type == CONTAINER && can_pick (pl, op) && sack_can_hold (pl, env, op, nrof)) |
835 | if (env->type == CONTAINER && can_pick (pl, op) && sack_can_hold (pl, env, op, nrof)) |
849 | { |
836 | { |
850 | put_object_in_sack (pl, env, op, nrof); |
837 | put_object_in_sack (pl, env, op, nrof); |
851 | } |
838 | } |
852 | } |
839 | } |
|
|
840 | |