Пример #1
0
/*ARGSUSED*/
void
player_login(void *ud)
{
    time_t deadline;
    char buf[128];
    char space[128];
    int res, ac, cmd, prev_state;

    player->proc = empth_self();

    pr_id(player, C_INIT, "Empire server ready\n");

    for (;;) {
        deadline = player_io_deadline(player, 0);
        if (io_outputwaiting(player->iop)) {
            if (io_output(player->iop, deadline) <= 0)
                break;
            continue;
        }
        if (io_gets(player->iop, buf, sizeof(buf)) < 0) {
            res = io_input(player->iop, deadline);
            if (res <= 0)
                break;
            continue;
        }
        journal_input(buf);
        ac = parse(buf, space, player->argp, NULL, NULL, NULL);
        if (ac <= 0) {
            pr_id(player, C_BADCMD, "Can't parse command\n");
            continue;
        }
        cmd = comtch(player->argp[0], login_coms, 0);
        if (cmd < 0) {
            pr_id(player, C_BADCMD, "Command %s not found\n", player->argp[0]);
            continue;
        }
        switch (login_coms[cmd].c_addr()) {
        case RET_OK:
            break;
        case RET_FAIL:
            break;
        case RET_SYN:
            pr_id(player, C_BADCMD, "Usage %s\n", login_coms[cmd].c_form);
            break;
        default:
            break;
        }
    }
    prev_state = player->state;
    player->state = PS_SHUTDOWN;
    if (prev_state == PS_PLAYING)
        empth_rwlock_unlock(shutdown_lock);
    pr_id(player, C_EXIT, "so long...\n");
    player_delete(player);
    empth_exit();
    /*NOTREACHED*/
}
Пример #2
0
static void
disable_coms(void)
{
    char *tmp = strdup(disabled_commands);
    char *name;
    int cmd;

    for (name = strtok(tmp, " \t"); name; name = strtok(NULL, " \t")) {
	cmd = comtch(name, player_coms, -1);
	if (cmd < 0) {
	    logerror("Warning: not disabling %s command %s\n",
		     cmd == M_NOTUNIQUE ? "ambiguous" : "unknown", name);
	    continue;
	}
	player_coms[cmd].c_permit |= GOD;
    }

    free(tmp);
}
Пример #3
0
/*
 * Execute command named by player->argp[0].
 * BUF is the raw UTF-8 command line.  It should have been passed to
 * parse() to set up player->argp.
 * If REDIR is not null, it's the command's redirection, in UTF-8.
 * Return -1 if the command is not unique or doesn't exist, else 0.
 */
int
dispatch(char *buf, char *redir)
{
    struct natstr *np;
    struct cmndstr *command;
    int cmd;

    cmd = comtch(player->argp[0], player_coms, player->nstat);
    if (cmd < 0) {
	if (cmd == M_NOTUNIQUE)
	    pr("Command \"%s\" is ambiguous -- ", player->argp[0]);
	else if (cmd == M_IGNORE)
	    return 0;
	else
	    pr("\"%s\" is not a legal command\n", player->argp[0]);
	return -1;
    }
    command = &player_coms[cmd];
    np = getnatp(player->cnum);
    if (np->nat_btu < command->c_cost && command->c_cost > 0) {
	if (player->god || opt_BLITZ)
	    np->nat_btu = max_btus;
	else {
	    pr("You don't have the BTU's, bozo\n");
	    return 0;
	}
    }
    if (!command->c_addr) {
	pr("Command not implemented\n");
	return 0;
    }
    player->may_sleep = command->c_flags & C_MOD
	? PLAYER_SLEEP_ON_INPUT : PLAYER_SLEEP_FREELY;
    player->command = command;
    empth_rwlock_rdlock(update_lock);
    if (redir) {
	prredir(redir);
	uprnf(buf);
	pr("\n");
    }
    journal_command(command->c_form);
    switch (command->c_addr()) {
    case RET_OK:
	player->btused += command->c_cost;
	break;
    case RET_FAIL:
	pr("command failed\n");
	player->btused += command->c_cost;
	break;
    case RET_SYN:
	pr("Usage: %s\n", command->c_form);
	break;
    default:
	CANT_REACH();
	break;
    }
    empth_rwlock_unlock(update_lock);
    player->command = NULL;
    if (player->may_sleep != PLAYER_SLEEP_NEVER || !io_eof(player->iop))
	player->may_sleep = PLAYER_SLEEP_FREELY;
    /* else we're being kicked out */
    return 0;
}