diff -Nur -Xsnap/diff_ignore snap/server/stdinhand.c snap-team/server/stdinhand.c --- snap/server/stdinhand.c 2003-06-21 22:41:47.000000000 -0500 +++ snap-team/server/stdinhand.c 2003-07-11 17:26:39.000000000 -0500 @@ -1557,6 +1557,41 @@ /************************************************************************** ... **************************************************************************/ +static void cmd_reply_no_such_user(enum command_id cmd, + struct connection *caller, + const char *name, + enum m_pre_result match_result) +{ + switch(match_result) { + case M_PRE_EMPTY: + cmd_reply(cmd, caller, C_SYNTAX, + _("Name is empty, so cannot be a user.")); + break; + case M_PRE_LONG: + cmd_reply(cmd, caller, C_SYNTAX, + _("Name is too long, so cannot be a user.")); + break; + case M_PRE_AMBIGUOUS: + cmd_reply(cmd, caller, C_FAIL, + _("User name prefix '%s' is ambiguous."), name); + break; + case M_PRE_FAIL: + cmd_reply(cmd, caller, C_FAIL, + _("No user by the name of '%s'."), name); + break; + default: + cmd_reply(cmd, caller, C_FAIL, + _("Unexpected match_result %d (%s) for '%s'."), + match_result, _(m_pre_description(match_result)), name); + freelog(LOG_ERROR, + "Unexpected match_result %d (%s) for '%s'.", + match_result, m_pre_description(match_result), name); + } +} + +/************************************************************************** +... +**************************************************************************/ static void open_metaserver_connection(struct connection *caller) { server_open_udp(); @@ -2780,11 +2815,12 @@ ******************************************************************/ static void team_command(struct connection *caller, char *str) { + struct connection *ptarget; struct player *pplayer; enum m_pre_result match_result; char buf[MAX_LEN_CONSOLE_LINE]; char *arg[2]; - int ntokens = 0; + int i, ntokens = 0; if (server_state != PRE_GAME_STATE) { cmd_reply(CMD_TEAM, caller, C_SYNTAX, @@ -2796,16 +2832,26 @@ sz_strlcpy(buf, str); ntokens = get_tokens(buf, arg, 2, TOKEN_DELIMITERS); } - if (ntokens > 2 || ntokens < 1) { + + if (ntokens < 1) { cmd_reply(CMD_TEAM, caller, C_SYNTAX, - _("Undefined argument. Usage: team [team].")); - return; + _("Undefined argument. Usage: team [team].")); + goto end; } - pplayer = find_player_by_name_prefix(arg[0], &match_result); - if (pplayer == NULL) { - cmd_reply_no_such_player(CMD_TEAM, caller, arg[0], match_result); - return; + ptarget = find_conn_by_user_prefix(arg[0], &match_result); + + if (!ptarget) { + cmd_reply_no_such_user(CMD_TEAM, caller, arg[0], match_result); + goto end; + } + + pplayer = ptarget->player; + + if (!pplayer) { + cmd_reply(CMD_TEAM, caller, C_FAIL, _("User %s must first be attached to " + "a player to be made part of a team."), ptarget->username); + goto end; } if (pplayer->team != TEAM_NONE) { @@ -2814,18 +2860,24 @@ if (ntokens == 1) { /* Remove from team */ - cmd_reply(CMD_TEAM, caller, C_OK, _("Player %s is made teamless."), - pplayer->name); - return; + cmd_reply(CMD_TEAM, caller, C_OK, _("%s is made teamless."), + ptarget->username); + goto end; } if (!is_sane_name(arg[1])) { cmd_reply(CMD_TEAM, caller, C_SYNTAX, _("Bad team name.")); - return; + goto end; } team_add_player(pplayer, arg[1]); - cmd_reply(CMD_TEAM, caller, C_OK, _("Player %s set to team %s."), - pplayer->name, team_get_by_id(pplayer->team)->name); + cmd_reply(CMD_TEAM, caller, C_OK, _("%s is set to team %s."), + ptarget->username, team_get_by_id(pplayer->team)->name); + + end:; + /* free our args */ + for (i = 0; i < ntokens; i++) { + free(arg[i]); + } } /******************************************************************