diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 3171e6dd1..89140f3c6 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -68,6 +68,7 @@ static void Got_ExitLevelcmd(UINT8 **cp, INT32 playernum); static void Got_SetupVotecmd(UINT8 **cp, INT32 playernum); static void Got_ModifyVotecmd(UINT8 **cp, INT32 playernum); static void Got_PickVotecmd(UINT8 **cp, INT32 playernum); +static void Got_GiveItemcmd(UINT8 **cp, INT32 playernum); static void Got_RequestAddfilecmd(UINT8 **cp, INT32 playernum); #ifdef DELFILE static void Got_Delfilecmd(UINT8 **cp, INT32 playernum); @@ -190,6 +191,8 @@ static void Command_Archivetest_f(void); #endif #endif +static void Command_KartGiveItem_f(void); + // ========================================================================= // CLIENT VARIABLES // ========================================================================= @@ -388,6 +391,17 @@ static CV_PossibleValue_t kartdebugitem_cons_t[] = consvar_t cv_kartdebugitem = {"kartdebugitem", "0", CV_NETVAR|CV_CHEAT|CV_NOSHOWHELP, kartdebugitem_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t kartdebugamount_cons_t[] = {{1, "MIN"}, {255, "MAX"}, {0, NULL}}; consvar_t cv_kartdebugamount = {"kartdebugamount", "1", CV_NETVAR|CV_CHEAT|CV_NOSHOWHELP, kartdebugamount_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_kartdebug_giveitem = { + "kartdebug_giveitem", + /* :mhm: */ +#ifdef DEVELOP + "Yes", +#else + "No", +#endif + CV_NETVAR|CV_CHEAT|CV_NOSHOWHELP, + CV_YesNo, +}; consvar_t cv_kartdebugshrink = {"kartdebugshrink", "Off", CV_NETVAR|CV_CHEAT|CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_kartdebugdistribution = {"kartdebugdistribution", "Off", CV_NETVAR|CV_CHEAT|CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_kartdebughuddrop = {"kartdebughuddrop", "Off", CV_NETVAR|CV_CHEAT|CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -568,6 +582,8 @@ void D_RegisterServerCommands(void) RegisterNetXCmd(XD_MODIFYVOTE, Got_ModifyVotecmd); RegisterNetXCmd(XD_PICKVOTE, Got_PickVotecmd); + RegisterNetXCmd(XD_GIVEITEM, Got_GiveItemcmd); + // Remote Administration CV_RegisterVar(&cv_dummyjoinpassword); COM_AddCommand("joinpassword", Command_ChangeJoinPassword_f); @@ -626,6 +642,8 @@ void D_RegisterServerCommands(void) #endif #endif + COM_AddCommand("kartgiveitem", Command_KartGiveItem_f); + // for master server connection AddMServCommands(); @@ -5299,6 +5317,41 @@ static void Got_PickVotecmd(UINT8 **cp, INT32 playernum) Y_SetupVoteFinish(pick, level); } +static void Got_GiveItemcmd(UINT8 **cp, INT32 playernum) +{ + int item; + int amt; + + INT32 *kartstuff; + + item = READSINT8 (*cp); + amt = READUINT8 (*cp); + + if ( + ( netgame && ! cv_kartdebug_giveitem.value ) || + ( item < KITEM_SAD || item >= NUMKARTITEMS ) + ) + { + CONS_Alert(CONS_WARNING, + M_GetText ("Illegal give item received from %s\n"), + player_names[playernum]); + if (server) + { + XBOXSTATIC UINT8 buf[2]; + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + return; + } + + kartstuff = players[playernum].kartstuff; + + kartstuff[k_itemtype] = item; + kartstuff[k_itemamount] = amt; +} + /** Prints the number of displayplayers[0]. * * \todo Possibly remove this; it was useful for debugging at one point. @@ -5462,6 +5515,80 @@ static void Command_Archivetest_f(void) #endif #endif +/** Give yourself an, optional quantity or one of, an item. + * + * \sa cv_kartdebug_giveitem +*/ +static void Command_KartGiveItem_f(void) +{ + char buf[2]; + + int ac; + const char *name; + int item; + + const char * str; + + int i; + + /* Allow always in local games. */ + if (! netgame || cv_kartdebug_giveitem.value) + { + ac = COM_Argc(); + if (ac < 2) + { + CONS_Printf( +"kartgiveitem [amount]: Give yourself an item\n" + ); + } + else + { + item = NUMKARTITEMS; + + name = COM_Argv(1); + + if (isdigit(*name) || *name == '-') + { + item = atoi(name); + } + else + { + for (i = 0; ( str = kartdebugitem_cons_t[i].strvalue ); ++i) + { + if (strcasecmp(name, str) == 0) + { + item = kartdebugitem_cons_t[i].value; + break; + } + } + } + + if (item < NUMKARTITEMS) + { + buf[0] = item; + + if (ac > 2) + buf[1] = atoi(COM_Argv(2)); + else + buf[1] = 1;/* default to one quantity */ + + SendNetXCmd(XD_GIVEITEM, buf, 2); + } + else + { + CONS_Alert(CONS_WARNING, + "No item matches '%s'\n", + name); + } + } + } + else + { + CONS_Alert(CONS_NOTICE, + "The server does not allow this.\n"); + } +} + /** Makes a change to ::cv_forceskin take effect immediately. * * \sa Command_SetForcedSkin_f, cv_forceskin, forcedskin diff --git a/src/d_netcmd.h b/src/d_netcmd.h index d1f28665c..1e84c67bb 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -125,7 +125,7 @@ extern consvar_t cv_kartusepwrlv; extern consvar_t cv_votetime; -extern consvar_t cv_kartdebugitem, cv_kartdebugamount, cv_kartdebugshrink, cv_kartdebugdistribution, cv_kartdebughuddrop; +extern consvar_t cv_kartdebugitem, cv_kartdebugamount, cv_kartdebug_giveitem, cv_kartdebugshrink, cv_kartdebugdistribution, cv_kartdebughuddrop; extern consvar_t cv_kartdebugcheckpoint, cv_kartdebugnodes, cv_kartdebugcolorize; extern consvar_t cv_itemfinder; @@ -179,9 +179,10 @@ typedef enum XD_PICKVOTE, // 24 XD_REMOVEPLAYER,// 25 XD_POWERLEVEL, // 26 + XD_GIVEITEM, // 27 #ifdef HAVE_BLUA - XD_LUACMD, // 27 - XD_LUAVAR, // 28 + XD_LUACMD, // 28 + XD_LUAVAR, // 29 #endif MAXNETXCMD } netxcmd_t; diff --git a/src/k_kart.c b/src/k_kart.c index 230662d2a..6eb4b9f9d 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -585,6 +585,7 @@ void K_RegisterKartStuff(void) CV_RegisterVar(&cv_kartdebugitem); CV_RegisterVar(&cv_kartdebugamount); CV_RegisterVar(&cv_kartdebugshrink); + CV_RegisterVar(&cv_kartdebug_giveitem); CV_RegisterVar(&cv_kartdebugdistribution); CV_RegisterVar(&cv_kartdebughuddrop);