1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
|
|
4 | * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
8 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
12 | * option) any later version. |
12 | * |
13 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * GNU General Public License for more details. |
17 | * |
18 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * You should have received a copy of the Affero GNU General Public License |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
21 | * <http://www.gnu.org/licenses/>. |
21 | * |
22 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
24 | */ |
24 | |
25 | |
25 | /** |
26 | /** |
26 | * \file |
27 | * \file |
… | |
… | |
39 | #include <skills.h> |
40 | #include <skills.h> |
40 | |
41 | |
41 | #include <cstring> |
42 | #include <cstring> |
42 | |
43 | |
43 | /** |
44 | /** |
44 | * Draws a normal message on the client. It is pretty |
45 | * Draws a normal message on the client. It is pretty |
45 | * much the same thing as the draw_info above, but takes a color |
46 | * much the same thing as the draw_info above, but takes a color |
46 | * parameter. the esrv_drawinfo functions should probably be |
47 | * parameter. the esrv_drawinfo functions should probably be |
47 | * replaced with this, just using black as the color. |
48 | * replaced with this, just using black as the color. |
48 | */ |
49 | */ |
49 | static void |
50 | static void |
50 | esrv_print_msg (client *ns, int color, const char *str) |
51 | esrv_print_msg (client *ns, int color, const char *str) |
51 | { |
52 | { |
52 | ns->send_msg (color, "info", str); |
53 | ns->send_msg (color, "info", str); |
53 | } |
|
|
54 | |
|
|
55 | /** |
|
|
56 | * Draws an extended message on the client. |
|
|
57 | * ns the socket to send message to |
|
|
58 | * color color informations (used mainly if client does not support message type) |
|
|
59 | * type, |
|
|
60 | * subtype type and subtype of text message |
|
|
61 | * intro Intro message to send with main message if client does not support the message type |
|
|
62 | * message The main message |
|
|
63 | */ |
|
|
64 | static void |
|
|
65 | esrv_print_ext_msg (client *ns, int color, uint8 type, uint8 subtype, const char *message) |
|
|
66 | { |
|
|
67 | ns->send_packet_printf ("drawextinfo %d %u %u %s", color, type, subtype, message); |
|
|
68 | } |
54 | } |
69 | |
55 | |
70 | /** |
56 | /** |
71 | * Frontend for esrv_print_msg |
57 | * Frontend for esrv_print_msg |
72 | * \param colr message color |
58 | * \param colr message color |
… | |
… | |
108 | for (msg_buf *buf = msgbuf; buf < msgbuf + MSG_BUF_COUNT; ++buf) |
94 | for (msg_buf *buf = msgbuf; buf < msgbuf + MSG_BUF_COUNT; ++buf) |
109 | { |
95 | { |
110 | if (len == buf->len && !memcmp (msg, buf->msg, len)) |
96 | if (len == buf->len && !memcmp (msg, buf->msg, len)) |
111 | { |
97 | { |
112 | // found matching buf, see if expired |
98 | // found matching buf, see if expired |
113 | if (buf->expire <= pticks || !buf->count) |
99 | if (buf->expire <= server_tick || !buf->count) |
114 | { |
100 | { |
115 | // yes, take over matching buffer, print |
101 | // yes, take over matching buffer, print |
116 | buf->expire = pticks + pl->outputs_sync; |
102 | buf->expire = server_tick + pl->outputs_sync; |
117 | buf->count = pl->outputs_count; |
103 | buf->count = pl->outputs_count; |
118 | |
104 | |
119 | return false; |
105 | return false; |
120 | } |
106 | } |
121 | |
107 | |
… | |
… | |
127 | if (lru->expire > buf->expire) |
113 | if (lru->expire > buf->expire) |
128 | lru = buf; |
114 | lru = buf; |
129 | } |
115 | } |
130 | |
116 | |
131 | // new message, evoke oldest buffer |
117 | // new message, evoke oldest buffer |
132 | lru->expire = pticks + pl->outputs_sync; |
118 | lru->expire = server_tick + pl->outputs_sync; |
133 | lru->count = pl->outputs_count; |
119 | lru->count = pl->outputs_count; |
134 | lru->len = len; |
120 | lru->len = len; |
135 | memcpy (lru->msg, msg, len); |
121 | memcpy (lru->msg, msg, len); |
136 | |
122 | |
137 | return false; |
123 | return false; |
… | |
… | |
184 | va_start (ap, format); |
170 | va_start (ap, format); |
185 | new_draw_info (flags, pri, pl, vformat (format, ap)); |
171 | new_draw_info (flags, pri, pl, vformat (format, ap)); |
186 | va_end (ap); |
172 | va_end (ap); |
187 | } |
173 | } |
188 | |
174 | |
189 | void |
|
|
190 | draw_ext_info (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage) |
|
|
191 | { |
|
|
192 | if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) |
|
|
193 | return; |
|
|
194 | |
|
|
195 | if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type)) |
|
|
196 | { |
|
|
197 | char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1); |
|
|
198 | |
|
|
199 | if (buf == NULL) |
|
|
200 | LOG (llevError, "info::draw_ext_info -> Out of memory!"); |
|
|
201 | else |
|
|
202 | { |
|
|
203 | strcpy (buf, oldmessage == NULL ? message : oldmessage); |
|
|
204 | strip_media_tag (buf); |
|
|
205 | new_draw_info (flags, pri, pl, buf); |
|
|
206 | free (buf); |
|
|
207 | } |
|
|
208 | } |
|
|
209 | else |
|
|
210 | esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, message); |
|
|
211 | } |
|
|
212 | |
|
|
213 | void |
|
|
214 | draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...) |
|
|
215 | { |
|
|
216 | va_list ap; |
|
|
217 | va_start (ap, new_format); |
|
|
218 | |
|
|
219 | if (!pl || !pl->is_player ()) |
|
|
220 | return; |
|
|
221 | |
|
|
222 | // TODO: just assume, and rip out? |
|
|
223 | if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type)) |
|
|
224 | { |
|
|
225 | LOG (llevDebug, "Non supported extension text type for client.\n"); |
|
|
226 | new_draw_info (flags, pri, pl, vformat (old_format, ap)); |
|
|
227 | } |
|
|
228 | else |
|
|
229 | { |
|
|
230 | char *buf = vformat (new_format, ap); |
|
|
231 | strip_media_tag (buf); |
|
|
232 | esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, buf); |
|
|
233 | } |
|
|
234 | |
|
|
235 | va_end (ap); |
|
|
236 | } |
|
|
237 | |
|
|
238 | /** |
175 | /** |
239 | * Writes to everyone on the map *except* op. This is useful for emotions. |
176 | * Writes to everyone on the map *except* op. This is useful for emotions. |
240 | */ |
177 | */ |
241 | void |
178 | void |
242 | new_info_map_except (int color, maptile * map, object *op, const char *str) |
179 | new_info_map_except (int color, maptile * map, object *op, const char *str) |
243 | { |
180 | { |
244 | for_all_players (pl) |
181 | for_all_players (pl) |
245 | if (pl->ob->map == map && pl->ob != op) |
182 | if (pl->ob->map == map && pl->ob != op) |
246 | new_draw_info (color, 0, pl->ob, str); |
|
|
247 | } |
|
|
248 | |
|
|
249 | /** |
|
|
250 | * Writes to everyone on the map except op1 and op2 |
|
|
251 | */ |
|
|
252 | static void |
|
|
253 | new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str) |
|
|
254 | { |
|
|
255 | for_all_players (pl) |
|
|
256 | if (pl->ob->map == map && pl->ob != op1 && pl->ob != op2) |
|
|
257 | new_draw_info (color, 0, pl->ob, str); |
183 | new_draw_info (color, 0, pl->ob, str); |
258 | } |
184 | } |
259 | |
185 | |
260 | /** |
186 | /** |
261 | * Writes to everyone on the specified map |
187 | * Writes to everyone on the specified map |
… | |
… | |
414 | * Mark Wedel |
340 | * Mark Wedel |
415 | */ |
341 | */ |
416 | void |
342 | void |
417 | draw_magic_map (object *pl) |
343 | draw_magic_map (object *pl) |
418 | { |
344 | { |
419 | char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
|
|
420 | int xmin, xmax, ymin, ymax; |
345 | int xmin, xmax, ymin, ymax; |
421 | |
346 | |
422 | if (pl->type != PLAYER) |
347 | if (pl->type != PLAYER) |
423 | { |
348 | { |
424 | LOG (llevError, "Non player object called draw_map.\n"); |
349 | LOG (llevError, "Non player object called draw_map.\n"); |
425 | return; |
350 | return; |
426 | } |
351 | } |
|
|
352 | |
|
|
353 | char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
|
|
354 | assert(("Out of memory!", map_mark != NULL)); |
427 | |
355 | |
428 | /* First, we figure out what spaces are 'reachable' by the player */ |
356 | /* First, we figure out what spaces are 'reachable' by the player */ |
429 | magic_mapping_mark (pl, map_mark, 3); |
357 | magic_mapping_mark (pl, map_mark, 3); |
430 | |
358 | |
431 | /* We now go through and figure out what spaces have been |
359 | /* We now go through and figure out what spaces have been |