From 7b99967bc0be8ab84e7226ffb6cf190567aa4ec6 Mon Sep 17 00:00:00 2001 From: allejo Date: Fri, 22 Jan 2016 01:39:13 -0800 Subject: [PATCH 1/4] Start adding world sanity checks for inputted values - Starts implementing #1 - Waiting on new API function: https://github.com/BZFlag-Dev/bzflag/pull/38 --- matchTrainerAssistant.cpp | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/matchTrainerAssistant.cpp b/matchTrainerAssistant.cpp index 6ff6387..afae0c3 100644 --- a/matchTrainerAssistant.cpp +++ b/matchTrainerAssistant.cpp @@ -20,6 +20,7 @@ THE SOFTWARE. */ +#include #include #include "bzfsAPI.h" @@ -31,8 +32,8 @@ const std::string PLUGIN_NAME = "Match Trainer Assistant"; // Define plug-in version numbering const int MAJOR = 1; const int MINOR = 0; -const int REV = 0; -const int BUILD = 4; +const int REV = 1; +const int BUILD = 5; class MatchTrainerAssistant : public bz_Plugin, public bz_CustomSlashCommandHandler { @@ -178,6 +179,8 @@ bool MatchTrainerAssistant::SlashCommand(int playerID, bz_ApiString command, bz_ if (command == "spawn") { + int maxXY = bz_getBZDBInt("_worldSize") / 2; + if (params->size() > 0) { if (params->size() != 1 && params->size() != 4) @@ -197,12 +200,6 @@ bool MatchTrainerAssistant::SlashCommand(int playerID, bz_ApiString command, bz_ { std::unique_ptr target(bz_getPlayerBySlotOrCallsign(params->get(0).c_str())); - if (target == NULL) - { - bz_sendTextMessagef(BZ_SERVER, playerID, "player %s not found", params->get(0).c_str()); - return true; - } - lastDeaths[playerID][0] = target->lastKnownState.pos[0]; lastDeaths[playerID][1] = target->lastKnownState.pos[1]; lastDeaths[playerID][2] = target->lastKnownState.pos[2]; @@ -210,6 +207,28 @@ bool MatchTrainerAssistant::SlashCommand(int playerID, bz_ApiString command, bz_ } else { + float posX = std::atof(params->get(0).c_str()); + float posY = std::atof(params->get(1).c_str()); + float posZ = std::atof(params->get(2).c_str()); + + if (abs(posX) > maxXY || abs(posY) > maxXY) + { + bz_sendTextMessagef(BZ_SERVER, playerID, "The following %s value (%.2f) is outside of this world", + (abs(posX) > maxXY) ? "X" : "Y", + (abs(posX) > maxXY) ? posX : posY); + + return true; + } + + float maxZ = bz_getWorldMaxHeight(); + + if (maxZ > 0 && posZ > maxZ) + { + bz_sendTextMessagef(BZ_SERVER, playerID, "The following Z value (%.2f) is outside of this world", posZ); + + return true; + } + lastDeaths[playerID][0] = std::atof(params->get(0).c_str()); lastDeaths[playerID][1] = std::atof(params->get(1).c_str()); lastDeaths[playerID][2] = std::atof(params->get(2).c_str()); @@ -217,15 +236,13 @@ bool MatchTrainerAssistant::SlashCommand(int playerID, bz_ApiString command, bz_ } } - protectedPos[playerID] = true; - handleSpawn[playerID] = true; - if (pr->spawned) { bz_killPlayer(playerID, BZ_SERVER); } bztk_forcePlayerSpawn(playerID); + handleSpawn[playerID] = true; return true; } From 3859e6e8441368cc877c141fa93eb39f880b245e Mon Sep 17 00:00:00 2001 From: allejo Date: Tue, 8 Mar 2016 21:37:18 -0800 Subject: [PATCH 2/4] Re-added player not found check --- matchTrainerAssistant.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/matchTrainerAssistant.cpp b/matchTrainerAssistant.cpp index afae0c3..9d4b84d 100644 --- a/matchTrainerAssistant.cpp +++ b/matchTrainerAssistant.cpp @@ -200,6 +200,12 @@ bool MatchTrainerAssistant::SlashCommand(int playerID, bz_ApiString command, bz_ { std::unique_ptr target(bz_getPlayerBySlotOrCallsign(params->get(0).c_str())); + if (target == NULL) + { + bz_sendTextMessagef(BZ_SERVER, playerID, "player %s not found", params->get(0).c_str()); + return true; + } + lastDeaths[playerID][0] = target->lastKnownState.pos[0]; lastDeaths[playerID][1] = target->lastKnownState.pos[1]; lastDeaths[playerID][2] = target->lastKnownState.pos[2]; From fd614030b083ee19857f7a6aad4a65215d5675f8 Mon Sep 17 00:00:00 2001 From: allejo Date: Fri, 25 Mar 2016 13:55:08 -0700 Subject: [PATCH 3/4] Make use of new bzToolkit function --- bztoolkit | 2 +- matchTrainerAssistant.cpp | 31 ++++++++----------------------- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/bztoolkit b/bztoolkit index 05d31db..dea5bad 160000 --- a/bztoolkit +++ b/bztoolkit @@ -1 +1 @@ -Subproject commit 05d31dbff734ceec97986788576ee0db4f28d7fd +Subproject commit dea5bad13e36c6d886c33622e71c4974de9f3840 diff --git a/matchTrainerAssistant.cpp b/matchTrainerAssistant.cpp index 9d4b84d..399aa40 100644 --- a/matchTrainerAssistant.cpp +++ b/matchTrainerAssistant.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 Vladimir "allejo" Jimenez + Copyright (C) 2016 Vladimir "allejo" Jimenez Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -27,18 +27,18 @@ #include "bztoolkit/bzToolkitAPI.h" // Define plug-in name -const std::string PLUGIN_NAME = "Match Trainer Assistant"; +std::string PLUGIN_NAME = "Match Trainer Assistant"; // Define plug-in version numbering -const int MAJOR = 1; -const int MINOR = 0; -const int REV = 1; -const int BUILD = 5; +int MAJOR = 1; +int MINOR = 0; +int REV = 1; +int BUILD = 5; class MatchTrainerAssistant : public bz_Plugin, public bz_CustomSlashCommandHandler { public: - virtual const char* Name (); + virtual const char* Name () { return bztk_PluginName(); } virtual void Init (const char* config); virtual void Event (bz_EventData *eventData); virtual void Cleanup (void); @@ -52,21 +52,6 @@ class MatchTrainerAssistant : public bz_Plugin, public bz_CustomSlashCommandHand BZ_PLUGIN(MatchTrainerAssistant) -const char* MatchTrainerAssistant::Name (void) -{ - static std::string pluginBuild = ""; - - if (!pluginBuild.size()) - { - std::ostringstream pluginBuildStream; - - pluginBuildStream << PLUGIN_NAME << " " << MAJOR << "." << MINOR << "." << REV << " (" << BUILD << ")"; - pluginBuild = pluginBuildStream.str(); - } - - return pluginBuild.c_str(); -} - void MatchTrainerAssistant::Init (const char* /*commandLine*/) { // Register our events with Register() @@ -228,7 +213,7 @@ bool MatchTrainerAssistant::SlashCommand(int playerID, bz_ApiString command, bz_ float maxZ = bz_getWorldMaxHeight(); - if (maxZ > 0 && posZ > maxZ) + if (posZ < 0 || (maxZ > 0 && posZ > maxZ)) { bz_sendTextMessagef(BZ_SERVER, playerID, "The following Z value (%.2f) is outside of this world", posZ); From 6f0406b96520ca83302d37c4067b1fe69f056068 Mon Sep 17 00:00:00 2001 From: allejo Date: Fri, 25 Mar 2016 14:44:11 -0700 Subject: [PATCH 4/4] Fix bugs with inconsistent spawning --- matchTrainerAssistant.cpp | 71 +++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/matchTrainerAssistant.cpp b/matchTrainerAssistant.cpp index 399aa40..d745442 100644 --- a/matchTrainerAssistant.cpp +++ b/matchTrainerAssistant.cpp @@ -38,16 +38,15 @@ int BUILD = 5; class MatchTrainerAssistant : public bz_Plugin, public bz_CustomSlashCommandHandler { public: - virtual const char* Name () { return bztk_PluginName(); } + virtual const char* Name () { return bztk_pluginName(); } virtual void Init (const char* config); virtual void Event (bz_EventData *eventData); virtual void Cleanup (void); virtual bool SlashCommand (int playerID, bz_ApiString, bz_ApiString, bz_APIStringList*); - bool protectedPos[256]; bool handleSpawn[256]; - float lastDeaths[256][4]; + float nextSpawnLocation[256][4]; }; BZ_PLUGIN(MatchTrainerAssistant) @@ -95,7 +94,7 @@ void MatchTrainerAssistant::Event (bz_EventData *eventData) for (int i = 0; i < 4; i++) { - if (isnan(lastDeaths[spawnData->playerID][i])) + if (isnan(nextSpawnLocation[spawnData->playerID][i])) { return; } @@ -103,13 +102,12 @@ void MatchTrainerAssistant::Event (bz_EventData *eventData) if (handleSpawn[spawnData->playerID]) { - spawnData->handled = handleSpawn[spawnData->playerID]; - spawnData->pos[0] = lastDeaths[spawnData->playerID][0]; - spawnData->pos[1] = lastDeaths[spawnData->playerID][1]; - spawnData->pos[2] = lastDeaths[spawnData->playerID][2]; - spawnData->rot = lastDeaths[spawnData->playerID][3]; + spawnData->handled = true; + spawnData->pos[0] = nextSpawnLocation[spawnData->playerID][0]; + spawnData->pos[1] = nextSpawnLocation[spawnData->playerID][1]; + spawnData->pos[2] = nextSpawnLocation[spawnData->playerID][2]; + spawnData->rot = nextSpawnLocation[spawnData->playerID][3]; - protectedPos[spawnData->playerID] = false; handleSpawn[spawnData->playerID] = false; } } @@ -119,15 +117,15 @@ void MatchTrainerAssistant::Event (bz_EventData *eventData) { bz_PlayerDieEventData_V1* dieData = (bz_PlayerDieEventData_V1*)eventData; - if (!protectedPos[dieData->playerID]) + // If they aren't killed by the server, save their last position. This is done because whenever someone does a /spawn, they are killed in order to + // be respawned elsewhere + if (dieData->killerID != ServerPlayer) { - lastDeaths[dieData->playerID][0] = dieData->state.pos[0]; - lastDeaths[dieData->playerID][1] = dieData->state.pos[1]; - lastDeaths[dieData->playerID][2] = dieData->state.pos[2]; - lastDeaths[dieData->playerID][3] = dieData->state.rotation; + nextSpawnLocation[dieData->playerID][0] = dieData->state.pos[0]; + nextSpawnLocation[dieData->playerID][1] = dieData->state.pos[1]; + nextSpawnLocation[dieData->playerID][2] = dieData->state.pos[2]; + nextSpawnLocation[dieData->playerID][3] = dieData->state.rotation; } - - protectedPos[dieData->playerID] = false; } break; @@ -136,13 +134,12 @@ void MatchTrainerAssistant::Event (bz_EventData *eventData) { bz_PlayerJoinPartEventData_V1* joinPartData = (bz_PlayerJoinPartEventData_V1*)eventData; - protectedPos[joinPartData->playerID] = false; handleSpawn[joinPartData->playerID] = false; - lastDeaths[joinPartData->playerID][0] = NAN; - lastDeaths[joinPartData->playerID][1] = NAN; - lastDeaths[joinPartData->playerID][2] = NAN; - lastDeaths[joinPartData->playerID][3] = NAN; + nextSpawnLocation[joinPartData->playerID][0] = NAN; + nextSpawnLocation[joinPartData->playerID][1] = NAN; + nextSpawnLocation[joinPartData->playerID][2] = NAN; + nextSpawnLocation[joinPartData->playerID][3] = NAN; } break; @@ -191,22 +188,23 @@ bool MatchTrainerAssistant::SlashCommand(int playerID, bz_ApiString command, bz_ return true; } - lastDeaths[playerID][0] = target->lastKnownState.pos[0]; - lastDeaths[playerID][1] = target->lastKnownState.pos[1]; - lastDeaths[playerID][2] = target->lastKnownState.pos[2]; - lastDeaths[playerID][3] = target->lastKnownState.rotation; + nextSpawnLocation[playerID][0] = target->lastKnownState.pos[0]; + nextSpawnLocation[playerID][1] = target->lastKnownState.pos[1]; + nextSpawnLocation[playerID][2] = target->lastKnownState.pos[2]; + nextSpawnLocation[playerID][3] = target->lastKnownState.rotation; } else { float posX = std::atof(params->get(0).c_str()); float posY = std::atof(params->get(1).c_str()); float posZ = std::atof(params->get(2).c_str()); + float rot = std::atof(params->get(3).c_str()); - if (abs(posX) > maxXY || abs(posY) > maxXY) + if (std::abs(posX) > maxXY || std::abs(posY) > maxXY) { bz_sendTextMessagef(BZ_SERVER, playerID, "The following %s value (%.2f) is outside of this world", - (abs(posX) > maxXY) ? "X" : "Y", - (abs(posX) > maxXY) ? posX : posY); + (std::abs(posX) > maxXY) ? "X" : "Y", + (std::abs(posX) > maxXY) ? posX : posY); return true; } @@ -220,20 +218,20 @@ bool MatchTrainerAssistant::SlashCommand(int playerID, bz_ApiString command, bz_ return true; } - lastDeaths[playerID][0] = std::atof(params->get(0).c_str()); - lastDeaths[playerID][1] = std::atof(params->get(1).c_str()); - lastDeaths[playerID][2] = std::atof(params->get(2).c_str()); - lastDeaths[playerID][3] = std::atof(params->get(3).c_str()); + nextSpawnLocation[playerID][0] = posX; + nextSpawnLocation[playerID][1] = posY; + nextSpawnLocation[playerID][2] = posZ; + nextSpawnLocation[playerID][3] = rot; } } if (pr->spawned) { - bz_killPlayer(playerID, BZ_SERVER); + bz_killPlayer(playerID, ServerPlayer); } - bztk_forcePlayerSpawn(playerID); handleSpawn[playerID] = true; + bztk_forcePlayerSpawn(playerID); return true; } @@ -250,8 +248,7 @@ bool MatchTrainerAssistant::SlashCommand(int playerID, bz_ApiString command, bz_ } else if (command == "die") { - protectedPos[playerID] = true; - bz_killPlayer(playerID, BZ_SERVER); + bz_killPlayer(playerID, false, playerID); return true; }