/* $Id: command.c,v 5.22 2002/06/08 13:39:44 bertg Exp $ * * XPilot, a multiplayer gravity war game. Copyright (C) 1991-2001 by * * Bjørn Stabell * Ken Ronny Schouten * Bert Gijsbers * Dick Balaska * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include #include #ifndef _WINDOWS # include #endif #ifdef _WINDOWS # include "NT/winServer.h" #endif #define SERVER #include "version.h" #include "serverconst.h" #include "global.h" #include "proto.h" #include "error.h" #include "netserver.h" #include "commonproto.h" #include "score.h" char command_version[] = VERSION; static int Get_player_index_by_name(char *name) { int i, j, len; if (!name || !*name) { return -1; } /* Id given directly */ if (isdigit(*name)) { i = atoi(name); if ((i > 0 && i <= NUM_IDS) && (j = GetInd[i]) >= 0 && j < NumPlayers && Players[j]->id == i) { return j; } else { return -1; } } /* look for an exact match on player nickname. */ for (i = 0; i < NumPlayers; i++) { if (strcasecmp(Players[i]->name, name) == 0) { return i; } } /* now look for a partial match on both nick and realname. */ len = strlen(name); for (j = -1, i = 0; i < NumPlayers; i++) { if (strncasecmp(Players[i]->name, name, len) == 0 || strncasecmp(Players[i]->realname, name, len) == 0) { j = (j == -1) ? i : -2; } } return j; } static void Send_info_about_player(player * pl) { int i; for (i = 0; i < NumPlayers; i++) { if (Players[i]->conn != NOT_CONNECTED) { Send_player(Players[i]->conn, pl->id); Send_score(Players[i]->conn, pl->id, pl->score, pl->life, pl->mychar, pl->alliance); Send_base(Players[i]->conn, pl->id, pl->home_base); } } } #define CMD_RESULT_SUCCESS 0 #define CMD_RESULT_ERROR (-1) #define CMD_RESULT_NOT_OPERATOR (-2) #define CMD_RESULT_NO_NAME (-3) static int Cmd_help(char *arg, player *pl, int oper, char *msg); static int Cmd_team(char *arg, player *pl, int oper, char *msg); static int Cmd_ally(char *arg, player *pl, int oper, char *msg); static int Cmd_version(char *arg, player *pl, int oper, char *msg); static int Cmd_lock(char *arg, player *pl, int oper, char *msg); static int Cmd_password(char *arg, player *pl, int oper, char *msg); static int Cmd_pause(char *arg, player *pl, int oper, char *msg); static int Cmd_reset(char *arg, player *pl, int oper, char *msg); static int Cmd_set(char *arg, player *pl, int oper, char *msg); static int Cmd_kick(char *arg, player *pl, int oper, char *msg); static int Cmd_queue(char *arg, player *pl, int oper, char *msg); static int Cmd_advance(char *arg, player *pl, int oper, char *msg); static int Cmd_get(char *arg, player *pl, int oper, char *msg); typedef struct { const char *name; const char *abbrev; const char *help; int oper_only; int (*cmd)(char *arg, player *pl, int oper, char *msg); } Command_info; /* * A list of all the commands sorted alphabetically. */ static Command_info commands[] = { { "advance", "ad", "/advance . " "Move the player to the front of the queue. (operator)", 1, Cmd_advance }, { "ally", "al", "/ally {invite|cancel|refuse|accept|leave|list} []. " "Manages alliances and invitations for them.", 0, Cmd_ally }, { "get", "g", "/get