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

Comparing deliantra/server/socket/info.C (file contents):
Revision 1.47 by root, Thu Nov 8 19:43:29 2007 UTC vs.
Revision 1.53 by root, Thu Oct 15 21:09:32 2009 UTC

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 (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24/** 25/**
139/** 140/**
140 * Sends message to player(s). 141 * Sends message to player(s).
141 * 142 *
142 * flags is various flags - mostly color, plus a few specials. 143 * flags is various flags - mostly color, plus a few specials.
143 * 144 *
144 * pri is priority. It is a little odd - the lower the value, the more 145 * pri is unused.
145 * important it is. Thus, 0 gets sent no matter what. Otherwise, the
146 * value must be less than the listening level that the player has set.
147 * Unfortunately, there is no clear guideline on what each level does what.
148 * 146 *
149 * pl can be passed as NULL - in fact, this will be done if NDI_ALL is set 147 * pl can be passed as NULL - in fact, this will be done if NDI_ALL is set
150 * in the flags. 148 * in the flags.
151 * 149 *
152 * If message is black, and not NDI_UNIQUE, gets sent through output buffers. 150 * If message is black, and not NDI_UNIQUE, gets sent through output buffers.
156new_draw_info (int flags, int pri, const object *op, const char *buf) 154new_draw_info (int flags, int pri, const object *op, const char *buf)
157{ 155{
158 if (flags & NDI_ALL) 156 if (flags & NDI_ALL)
159 { 157 {
160 for_all_players (pl) 158 for_all_players (pl)
161 new_draw_info (flags & ~NDI_ALL, pri, pl->ob, buf); 159 new_draw_info (flags & ~NDI_ALL, 0, pl->ob, buf);
162 } 160 }
163 else 161 else
164 { 162 {
165 if (!op || !op->contr || !op->contr->ns) 163 if (!op || !op->contr || !op->contr->ns)
166 return;
167
168 if (pri >= op->contr->listening)
169 return; 164 return;
170 165
171 if ((flags & (NDI_COLOR_MASK | NDI_UNIQUE)) != NDI_BLACK 166 if ((flags & (NDI_COLOR_MASK | NDI_UNIQUE)) != NDI_BLACK
172 || !op->contr->ns->msg_suppressed (buf)) 167 || !op->contr->ns->msg_suppressed (buf))
173 print_message (flags & NDI_COLOR_MASK, op, buf); 168 print_message (flags & NDI_COLOR_MASK, op, buf);
183 * client/server bandwidth (client could keep track of various strings 178 * client/server bandwidth (client could keep track of various strings
184 */ 179 */
185void 180void
186new_draw_info_format (int flags, int pri, const object *pl, const char *format, ...) 181new_draw_info_format (int flags, int pri, const object *pl, const char *format, ...)
187{ 182{
188 char buf[HUGE_BUF];
189
190 va_list ap; 183 va_list ap;
191 va_start (ap, format); 184 va_start (ap, format);
192 vsnprintf (buf, HUGE_BUF, format, ap); 185 new_draw_info (flags, pri, pl, vformat (format, ap));
193 va_end (ap); 186 va_end (ap);
194
195 new_draw_info (flags, pri, pl, buf);
196} 187}
197 188
198void 189void
199draw_ext_info (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage) 190draw_ext_info (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage)
200{ 191{
201 192
202 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) 193 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL))
203 return;
204
205 if (pri >= pl->contr->listening)
206 return; 194 return;
207 195
208 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type)) 196 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type))
209 { 197 {
210 char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1); 198 char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1);
224} 212}
225 213
226void 214void
227draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...) 215draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...)
228{ 216{
229 char buf[HUGE_BUF]; 217 va_list ap;
218 va_start (ap, new_format);
230 219
231 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) 220 if (!pl || !pl->is_player ())
232 return; 221 return;
233 222
234 if (pri >= pl->contr->listening) 223 // TODO: just assume, and rip out?
235 return;
236
237 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type)) 224 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type))
238 { 225 {
239 va_list ap;
240
241 LOG (llevDebug, "Non supported extension text type for client.\n"); 226 LOG (llevDebug, "Non supported extension text type for client.\n");
242 va_start (ap, new_format);
243 vsnprintf (buf, HUGE_BUF, old_format, ap);
244 va_end (ap);
245 new_draw_info (flags, pri, pl, buf); 227 new_draw_info (flags, pri, pl, vformat (old_format, ap));
246 return;
247 } 228 }
248 else 229 else
249 { 230 {
250 va_list ap; 231 char *buf = vformat (new_format, ap);
251
252 va_start (ap, new_format);
253 vsnprintf (buf, HUGE_BUF, new_format, ap);
254 va_end (ap);
255 strip_media_tag (buf); 232 strip_media_tag (buf);
256 esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, buf); 233 esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, buf);
257 } 234 }
235
236 va_end (ap);
258} 237}
259 238
260/** 239/**
261 * Writes to everyone on the map *except* op. This is useful for emotions. 240 * Writes to everyone on the map *except* op. This is useful for emotions.
262 */ 241 */
263 242
264void 243void
265new_info_map_except (int color, maptile * map, object *op, const char *str) 244new_info_map_except (int color, maptile * map, object *op, const char *str)
266{ 245{
267 for_all_players (pl) 246 for_all_players (pl)
268 if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) 247 if (pl->ob->map == map && pl->ob != op)
269 new_draw_info (color, 0, pl->ob, str); 248 new_draw_info (color, 0, pl->ob, str);
270} 249}
271 250
272/** 251/**
273 * Writes to everyone on the map except op1 and op2 252 * Writes to everyone on the map except op1 and op2
274 */ 253 */
275void 254void
276new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str) 255new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str)
277{ 256{
278 for_all_players (pl) 257 for_all_players (pl)
279 if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2) 258 if (pl->ob->map == map && pl->ob != op1 && pl->ob != op2)
280 new_draw_info (color, 0, pl->ob, str); 259 new_draw_info (color, 0, pl->ob, str);
281} 260}
282 261
283/** 262/**
284 * Writes to everyone on the specified map 263 * Writes to everyone on the specified map
285 */ 264 */
286void 265void
287new_info_map (int color, maptile * map, const char *str) 266new_info_map (int color, maptile * map, const char *str)
288{ 267{
289 for_all_players (pl) 268 for_all_players (pl)
290 if (pl->ob != NULL && pl->ob->map == map) 269 if (pl->ob->map == map)
291 new_draw_info (color, 0, pl->ob, str); 270 new_draw_info (color, 0, pl->ob, str);
292} 271}
293 272
294/** 273/**
295 * Sets player title. 274 * Sets player title.
486 pl->contr->ns->send_packet (sl); 465 pl->contr->ns->send_packet (sl);
487 466
488 free (map_mark); 467 free (map_mark);
489} 468}
490 469
491/**
492 * Send a kill log record to sockets
493 */
494void
495Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType)
496{
497 size_t len;
498 char buf[MAX_BUF];
499
500 if (With != NULL)
501 snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType);
502 else
503 snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType);
504
505 len = strlen (buf);
506}
507

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines