Esempio n. 1
0
/*
 * Get a command from the current player into COMBUFP[1024], in UTF-8.
 * This may block for input, yielding the processor.  Flush buffered
 * output when blocking, to make sure player sees the prompt.
 * Return command's byte length on success, -1 on error.
 */
int
getcommand(char *combufp)
{
    char buf[1024];		/* user text */

    if (recvclient(buf, sizeof(buf)) < 0)
	return -1;

    if (++player_commands_index >= KEEP_COMMANDS)
	player_commands_index = 0;
    sprintf(player_commands[player_commands_index], "%3d %3d %s",
	    player_commands_index, player->cnum, buf);

    if (player->flags & PF_UTF8)
	return copy_utf8_no_funny(combufp, buf);
    return copy_ascii_no_funny(combufp, buf);
}
Esempio n. 2
0
/*
 * 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
 * '?'.  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,
 * or -1 on error.
 */
int
uprmptrd(char *prompt, char *buf, int size)
{
    int r;

    if (CANT_HAPPEN(!prompt))
	prompt = "? ";

    pr_id(player, C_FLUSH, "%s\n", prompt);
    if ((r = recvclient(buf, size)) < 0)
	return r;
    time(&player->curup);
    if (*buf == 0)
	return 1;
    if (player->flags & PF_UTF8)
	return copy_utf8_no_funny(buf, buf);
    return copy_ascii_no_funny(buf, buf);
}