/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure, Markus Armbruster
*
* Empire is free software: you can redistribute it and/or modify
* Dave Pare, 1986, 1989
* Steve McClure, 1998-2000
* Ron Koenderink, 2005
- * Markus Armbruster, 2005-2011
+ * Markus Armbruster, 2005-2012
*/
/*
* without yielding the processor.
*
* Each line of output starts with an identification character
- * encoding the output id, followed by space. Ids less than 10 are
- * encoded as decimal digits, and larger ids as lower case letters,
- * starting with 'a'. Symbolic names for ids are defined in proto.h.
+ * encoding the output ID, followed by space. Ids less than 10 are
+ * encoded as decimal digits, and larger IDs as lower case letters,
+ * starting with 'a'. Symbolic names for IDs are defined in proto.h.
*/
#include <config.h>
#include <stdarg.h>
#include <stdlib.h>
-#include "com.h"
#include "empio.h"
-#include "file.h"
#include "journal.h"
#include "misc.h"
#include "nat.h"
#include "player.h"
#include "proto.h"
#include "prototypes.h"
-#include "server.h"
-#include "tel.h"
+#include "update.h"
#include "xy.h"
static void pr_player(struct player *pl, int id, char *buf);
static void upr_player(struct player *pl, int id, char *buf);
static void outid(struct player *pl, int n);
+static void player_output_some(void);
/*
* Print to current player similar to printf().
- * Use printf-style FORMAT with the optional arguments.
+ * Use printf-style @format with the optional arguments.
* Note: `to print' without further qualifications means sending
* C_DATA text.
*/
}
/*
- * Print UTF-8 text BUF to current player.
+ * Print UTF-8 text @buf to current player.
*/
void
uprnf(char *buf)
}
/*
- * Send some text to P with id ID, line-buffered.
- * Format text to send using printf-style FORMAT and optional
+ * Send some text to @p with ID @id, line-buffered.
+ * Format text to send using printf-style @format and optional
* arguments. It is assumed to be already user text. Plain ASCII and
* text received from the same player are fine, for anything else the
* caller has to deal with output filtering.
}
/*
- * Send C_FLASH text to PL.
- * Format text to send using printf-style FORMAT and optional
+ * Send C_FLASH text to @pl.
+ * Format text to send using printf-style @format and optional
* arguments. It is assumed to be UTF-8.
* Initiate an output queue flush, but do not wait for it to complete.
*/
}
/*
- * Send C_INFORM text to PL.
- * Format text to send using printf-style FORMAT and optional
+ * Send C_INFORM text to @pl.
+ * Format text to send using printf-style @format and optional
* arguments. It is assumed to be plain ASCII.
* Initiate an output queue flush, but do not wait for it to complete.
*/
/*
* Send C_FLASH text to everyone.
- * Format text to send using printf-style FORMAT and optional
+ * Format text to send using printf-style @format and optional
* arguments. It is assumed to be plain ASCII.
* Prefix text it with a header suitable for broadcast from deity.
* Initiate an output queue flush, but do not wait for it to complete.
}
/*
- * Send ID text BUF to PL, line-buffered.
- * BUF is user text.
- * If a partial line with different id is buffered, terminate it with
+ * Send @id text @buf to @pl, line-buffered.
+ * @buf is user text.
+ * If a partial line with different ID is buffered, terminate it with
* a newline first.
*/
static void
}
}
- if (player == pl) {
- while (io_output_if_queue_long(pl->iop,
- pl->may_sleep == PLAYER_SLEEP_FREELY) > 0)
- ;
- }
+ if (player == pl)
+ player_output_some();
}
/*
- * Send ID text BUF to PL, line-buffered.
+ * Send @id text @buf to @pl, line-buffered.
* This function translates from normal text to user text.
- * If a partial line with different id is buffered, terminate it with
+ * If a partial line with different ID is buffered, terminate it with
* a newline first.
*/
static void
}
}
- if (player == pl) {
- while (io_output_if_queue_long(pl->iop,
- pl->may_sleep == PLAYER_SLEEP_FREELY) > 0)
- ;
- }
+ if (player == pl)
+ player_output_some();
}
/*
- * Send id N to PL.
+ * Send ID @n to @pl.
* This runs always at the beginning of a line.
*/
static void
pl->curid = n;
}
+static void
+player_output_some(void)
+{
+ time_t deadline = player_io_deadline(player, 1);
+
+ while (io_output_if_queue_long(player->iop, deadline) > 0)
+ ;
+}
+
/*
- * Send redirection request REDIR to the current player.
- * REDIR is UTF-8, but non-ASCII characters can occur only if the
+ * Send redirection request @redir to the current player.
+ * @redir is UTF-8, but non-ASCII characters can occur only if the
* player sent them. Therefore, it is also user text.
*/
void
}
/*
- * Send script execute request FILE to the current player.
- * REDIR is UTF-8, but non-ASCII characters can occur only if the
+ * Send script execute request @file to the current player.
+ * @file is UTF-8, but non-ASCII characters can occur only if the
* player sent them. Therefore, it is also user text.
*/
void
/*
* Prompt for a line of non-command input.
- * Send C_FLUSH prompt PROMPT to the current player.
- * Read a line of input into BUF[SIZE] and convert it to ASCII.
+ * Send C_FLUSH prompt @prompt to the current player.
+ * Read a line of input into @buf[@size] and convert it to ASCII.
* This may block for input, yielding the processor. Flush buffered
* output when blocking, to make sure player sees the prompt.
- * Return number of bytes in BUF[], not counting the terminating 0,
+ * Return number of bytes in @buf[], not counting the terminating 0,
* or -1 on error.
*/
int
/*
* Prompt for a line of non-command, UTF-8 input.
- * Send C_FLUSH prompt PROMPT to the current player.
- * Read a line of input into BUF[SIZE], replacing funny characters by
+ * Send C_FLUSH prompt @prompt to the current player.
+ * Read a line of input into @buf[@size], replacing funny characters by
* '?'. The result is UTF-8.
* This may block for input, yielding the processor. Flush buffered
* output when blocking, to make sure player sees the prompt.
- * Return number of bytes in BUF[], not counting the terminating 0,
+ * Return number of bytes in @buf[], not counting the terminating 0,
* or -1 on error.
*/
int
time_t now;
(void)time(&now);
- pr(ctime(&now));
+ pr("%s", ctime(&now));
}
/*
- * Print coordinates X, Y.
- * FORMAT must be a printf-style format string that converts exactly
+ * Print coordinates @x,@y.
+ * @format must be a printf-style format string that converts exactly
* two int values.
*/
void
}
/*
- * Print complete lines to country CN similar to printf().
- * Use printf-style FORMAT with the optional arguments. FORMAT must
+ * Print complete lines to country @cn similar to printf().
+ * Use printf-style @format with the optional arguments. @format must
* end with '\n'.
- * If CN is zero, don't print anything.
- * Else, if CN is the current player and we're not in the update,
+ * If @cn is zero, don't print anything.
+ * Else, if @cn is the current player and we're not in the update,
* print just like pr(). Else print into a bulletin.
* Because printing like pr() requires normal text, and bulletins
* require user text, only plain ASCII is allowed.
(void)vsprintf(buf, format, ap);
va_end(ap);
if (update_running || cn != player->cnum)
- typed_wu(0, cn, buf, TEL_BULLETIN);
+ wu(0, cn, "%s", buf);
else
pr_player(player, C_DATA, buf);
}
/*
- * Copy SRC without funny characters to DST.
+ * Copy @src without funny characters to @dst.
* Drop control characters, except for '\t'.
* Replace non-ASCII characters by '?'.
- * Return length of DST.
- * DST must have space. If it overlaps SRC, then DST <= SRC must
+ * Return length of @dst.
+ * @dst must have space. If it overlaps @src, then @dst <= @src must
* hold.
*/
size_t
}
/*
- * Copy UTF-8 SRC without funny characters to DST.
+ * Copy UTF-8 @src without funny characters to @dst.
* Drop control characters, except for '\t'.
* FIXME Replace malformed UTF-8 sequences by '?'.
- * Return byte length of DST.
- * DST must have space. If it overlaps SRC, then DST <= SRC must
+ * Return byte length of @dst.
+ * @dst must have space. If it overlaps @src, then @dst <= @src must
* hold.
*/
size_t
}
/*
- * Copy UTF-8 SRC without funny characters to ASCII DST.
+ * Copy UTF-8 @src without funny characters to ASCII @dst.
* Drop control characters, except for '\t'.
* Replace non-ASCII characters by '?'.
- * Return length of DST.
- * DST must have space. If it overlaps SRC, then DST <= SRC must
+ * Return length of @dst.
+ * @dst must have space. If it overlaps @src, then @dst <= @src must
* hold.
*/
size_t
; /* ignore funny control */
else if (ch > 0x7f) {
*p++ = '?'; /* replace non-ASCII */
- while ((*src++ & 0xc0) == 0x80) ;
+ while ((*src & 0xc0) == 0x80)
+ src++;
} else
*p++ = ch;
}
}
/*
- * Return byte-index of the N-th UTF-8 character in UTF-8 string S.
- * If S doesn't have that many characters, return its length instead.
+ * Return byte-index of the @n-th UTF-8 character in UTF-8 string @s.
+ * If @s doesn't have that many characters, return its length instead.
*/
int
ufindpfx(char *s, int n)