2023-01-06 18:52:18 +02:00
|
|
|
/*
|
|
|
|
* ClientCommandManager.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2023-01-07 00:37:57 +02:00
|
|
|
#include "StdInc.h"
|
2023-01-06 18:52:18 +02:00
|
|
|
#include "ClientCommandManager.h"
|
|
|
|
|
|
|
|
#include "Client.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "adventureMap/CInGameConsole.h"
|
2023-01-06 18:52:18 +02:00
|
|
|
#include "CPlayerInterface.h"
|
2023-04-17 12:06:58 +02:00
|
|
|
#include "PlayerLocalState.h"
|
2023-01-06 18:52:18 +02:00
|
|
|
#include "CServerHandler.h"
|
|
|
|
#include "gui/CGuiHandler.h"
|
2023-05-16 14:10:26 +02:00
|
|
|
#include "gui/WindowHandler.h"
|
2023-01-06 18:52:18 +02:00
|
|
|
#include "../lib/NetPacks.h"
|
2023-02-12 09:23:39 +02:00
|
|
|
#include "ClientNetPackVisitors.h"
|
2023-01-06 18:52:18 +02:00
|
|
|
#include "../lib/CConfigHandler.h"
|
2023-06-23 17:02:48 +02:00
|
|
|
#include "../lib/gameState/CGameState.h"
|
2023-01-06 18:52:18 +02:00
|
|
|
#include "../lib/CPlayerState.h"
|
|
|
|
#include "../lib/StringConstants.h"
|
2023-06-25 21:28:24 +02:00
|
|
|
#include "../lib/campaign/CampaignHandler.h"
|
2023-03-14 17:54:37 +02:00
|
|
|
#include "../lib/mapping/CMapService.h"
|
|
|
|
#include "../lib/mapping/CMap.h"
|
2023-01-06 18:52:18 +02:00
|
|
|
#include "windows/CCastleInterface.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "render/CAnimation.h"
|
2023-01-06 18:52:18 +02:00
|
|
|
#include "../CCallback.h"
|
|
|
|
#include "../lib/CGeneralTextHandler.h"
|
2023-03-15 21:34:29 +02:00
|
|
|
#include "../lib/filesystem/Filesystem.h"
|
2023-07-30 19:12:25 +02:00
|
|
|
#include "../lib/modding/CModHandler.h"
|
|
|
|
#include "../lib/modding/ContentTypeHandler.h"
|
|
|
|
#include "../lib/modding/ModUtility.h"
|
2023-01-06 18:52:18 +02:00
|
|
|
#include "../lib/CHeroHandler.h"
|
|
|
|
#include "../lib/VCMIDirs.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "CMT.h"
|
2023-01-06 18:52:18 +02:00
|
|
|
|
|
|
|
#ifdef SCRIPTING_ENABLED
|
|
|
|
#include "../lib/ScriptHandler.h"
|
|
|
|
#endif
|
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
void ClientCommandManager::handleQuitCommand()
|
|
|
|
{
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientCommandManager::handleSaveCommand(std::istringstream & singleWordBuffer)
|
|
|
|
{
|
|
|
|
if(!CSH->client)
|
|
|
|
{
|
|
|
|
printCommandMessage("Game is not in playing state");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string saveFilename;
|
|
|
|
singleWordBuffer >> saveFilename;
|
|
|
|
CSH->client->save(saveFilename);
|
|
|
|
printCommandMessage("Game saved as: " + saveFilename);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientCommandManager::handleLoadCommand(std::istringstream& singleWordBuffer)
|
|
|
|
{
|
|
|
|
// TODO: this code should end the running game and manage to call startGame instead
|
|
|
|
//std::string fname;
|
|
|
|
//singleWordBuffer >> fname;
|
|
|
|
//CSH->client->loadGame(fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientCommandManager::handleGoSoloCommand()
|
2023-01-06 18:52:18 +02:00
|
|
|
{
|
|
|
|
Settings session = settings.write["session"];
|
|
|
|
|
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*CPlayerInterface::pim);
|
|
|
|
if(!CSH->client)
|
|
|
|
{
|
2023-01-06 22:01:00 +02:00
|
|
|
printCommandMessage("Game is not in playing state");
|
2023-01-06 18:52:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
PlayerColor color;
|
|
|
|
if(session["aiSolo"].Bool())
|
|
|
|
{
|
|
|
|
for(auto & elem : CSH->client->gameState()->players)
|
|
|
|
{
|
|
|
|
if(elem.second.human)
|
|
|
|
CSH->client->installNewPlayerInterface(std::make_shared<CPlayerInterface>(elem.first), elem.first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
color = LOCPLINT->playerID;
|
2023-01-11 18:11:44 +02:00
|
|
|
CSH->client->removeGUI();
|
2023-01-06 18:52:18 +02:00
|
|
|
for(auto & elem : CSH->client->gameState()->players)
|
|
|
|
{
|
|
|
|
if(elem.second.human)
|
|
|
|
{
|
2023-06-29 18:09:47 +02:00
|
|
|
auto AiToGive = CSH->client->aiNameForPlayer(*CSH->client->getPlayerSettings(elem.first), false, false);
|
2023-01-06 22:01:00 +02:00
|
|
|
printCommandMessage("Player " + elem.first.getStr() + " will be lead by " + AiToGive, ELogLevel::INFO);
|
2023-01-06 18:52:18 +02:00
|
|
|
CSH->client->installNewPlayerInterface(CDynLibHandler::getNewAI(AiToGive), elem.first);
|
|
|
|
}
|
|
|
|
}
|
2023-05-16 14:10:26 +02:00
|
|
|
GH.windows().totalRedraw();
|
2023-01-06 18:52:18 +02:00
|
|
|
giveTurn(color);
|
|
|
|
}
|
|
|
|
session["aiSolo"].Bool() = !session["aiSolo"].Bool();
|
|
|
|
}
|
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
void ClientCommandManager::handleAutoskipCommand()
|
2023-01-06 18:52:18 +02:00
|
|
|
{
|
2023-04-16 18:29:31 +02:00
|
|
|
Settings session = settings.write["session"];
|
|
|
|
session["autoSkip"].Bool() = !session["autoSkip"].Bool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientCommandManager::handleControlaiCommand(std::istringstream& singleWordBuffer)
|
|
|
|
{
|
|
|
|
std::string colorName;
|
|
|
|
singleWordBuffer >> colorName;
|
|
|
|
boost::to_lower(colorName);
|
|
|
|
|
2023-01-06 18:52:18 +02:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*CPlayerInterface::pim);
|
|
|
|
if(!CSH->client)
|
|
|
|
{
|
2023-01-06 22:01:00 +02:00
|
|
|
printCommandMessage("Game is not in playing state");
|
2023-01-06 18:52:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2023-04-16 18:29:31 +02:00
|
|
|
|
2023-01-06 18:52:18 +02:00
|
|
|
PlayerColor color;
|
|
|
|
if(LOCPLINT)
|
|
|
|
color = LOCPLINT->playerID;
|
2023-04-16 18:29:31 +02:00
|
|
|
|
2023-01-06 18:52:18 +02:00
|
|
|
for(auto & elem : CSH->client->gameState()->players)
|
|
|
|
{
|
2023-04-16 18:29:31 +02:00
|
|
|
if(elem.second.human ||
|
|
|
|
(colorName.length() && elem.first.getNum() != vstd::find_pos(GameConstants::PLAYER_COLOR_NAMES, colorName)))
|
2023-01-06 18:52:18 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-01-11 18:11:44 +02:00
|
|
|
CSH->client->removeGUI();
|
2023-01-06 18:52:18 +02:00
|
|
|
CSH->client->installNewPlayerInterface(std::make_shared<CPlayerInterface>(elem.first), elem.first);
|
|
|
|
}
|
2023-04-16 18:29:31 +02:00
|
|
|
|
2023-05-16 14:10:26 +02:00
|
|
|
GH.windows().totalRedraw();
|
2023-01-06 18:52:18 +02:00
|
|
|
if(color != PlayerColor::NEUTRAL)
|
|
|
|
giveTurn(color);
|
|
|
|
}
|
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
void ClientCommandManager::handleSetBattleAICommand(std::istringstream& singleWordBuffer)
|
2023-01-06 18:52:18 +02:00
|
|
|
{
|
2023-04-16 18:29:31 +02:00
|
|
|
std::string aiName;
|
|
|
|
singleWordBuffer >> aiName;
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
printCommandMessage("Will try loading that AI to see if it is correct name...\n");
|
|
|
|
try
|
2023-01-06 18:52:18 +02:00
|
|
|
{
|
2023-04-16 18:29:31 +02:00
|
|
|
if(auto ai = CDynLibHandler::getNewBattleAI(aiName)) //test that given AI is indeed available... heavy but it is easy to make a typo and break the game
|
|
|
|
{
|
|
|
|
Settings neutralAI = settings.write["server"]["neutralAI"];
|
|
|
|
neutralAI->String() = aiName;
|
|
|
|
printCommandMessage("Setting changed, from now the battle ai will be " + aiName + "!\n");
|
|
|
|
}
|
2023-01-06 18:52:18 +02:00
|
|
|
}
|
2023-04-16 18:29:31 +02:00
|
|
|
catch(std::exception &e)
|
2023-01-06 18:52:18 +02:00
|
|
|
{
|
2023-04-16 18:29:31 +02:00
|
|
|
printCommandMessage("Failed opening " + aiName + ": " + e.what(), ELogLevel::WARN);
|
|
|
|
printCommandMessage("Setting not changed, AI not found or invalid!", ELogLevel::WARN);
|
2023-01-06 18:52:18 +02:00
|
|
|
}
|
2023-04-16 18:29:31 +02:00
|
|
|
}
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
void ClientCommandManager::handleRedrawCommand()
|
|
|
|
{
|
2023-05-16 14:10:26 +02:00
|
|
|
GH.windows().totalRedraw();
|
2023-04-16 18:29:31 +02:00
|
|
|
}
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
void ClientCommandManager::handleNotDialogCommand()
|
|
|
|
{
|
|
|
|
LOCPLINT->showingDialog->setn(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientCommandManager::handleConvertTextCommand()
|
|
|
|
{
|
|
|
|
logGlobal->info("Searching for available maps");
|
|
|
|
std::unordered_set<ResourceID> mapList = CResourceHandler::get()->getFilteredFiles([&](const ResourceID & ident)
|
2023-01-06 18:52:18 +02:00
|
|
|
{
|
2023-04-16 18:29:31 +02:00
|
|
|
return ident.getType() == EResType::MAP;
|
|
|
|
});
|
2023-03-14 17:54:37 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
std::unordered_set<ResourceID> campaignList = CResourceHandler::get()->getFilteredFiles([&](const ResourceID & ident)
|
|
|
|
{
|
|
|
|
return ident.getType() == EResType::CAMPAIGN;
|
|
|
|
});
|
2023-03-14 17:54:37 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
CMapService mapService;
|
2023-03-14 17:54:37 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
logGlobal->info("Loading maps for export");
|
|
|
|
for (auto const & mapName : mapList)
|
|
|
|
{
|
|
|
|
try
|
2023-03-14 21:48:39 +02:00
|
|
|
{
|
2023-04-16 18:29:31 +02:00
|
|
|
// load and drop loaded map - we only need loader to run over all maps
|
|
|
|
mapService.loadMap(mapName);
|
2023-03-14 21:48:39 +02:00
|
|
|
}
|
2023-04-16 18:29:31 +02:00
|
|
|
catch(std::exception & e)
|
2023-03-14 19:46:15 +02:00
|
|
|
{
|
2023-04-16 18:29:31 +02:00
|
|
|
logGlobal->error("Map %s is invalid. Message: %s", mapName.getName(), e.what());
|
2023-03-14 19:46:15 +02:00
|
|
|
}
|
2023-01-06 18:52:18 +02:00
|
|
|
}
|
2023-04-16 18:29:31 +02:00
|
|
|
|
|
|
|
logGlobal->info("Loading campaigns for export");
|
|
|
|
for (auto const & campaignName : campaignList)
|
2023-01-06 18:52:18 +02:00
|
|
|
{
|
2023-06-25 20:16:03 +02:00
|
|
|
auto state = CampaignHandler::getCampaign(campaignName.getName());
|
2023-06-25 23:01:25 +02:00
|
|
|
for (auto const & part : state->allScenarios())
|
|
|
|
state->getMap(part);
|
2023-04-16 18:29:31 +02:00
|
|
|
}
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
VLC->generaltexth->dumpAllTexts();
|
|
|
|
}
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
void ClientCommandManager::handleGetConfigCommand()
|
|
|
|
{
|
|
|
|
printCommandMessage("Command accepted.\t");
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
const boost::filesystem::path outPath = VCMIDirs::get().userExtractedPath() / "configuration";
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
boost::filesystem::create_directories(outPath);
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
const std::vector<std::string> contentNames = { "heroClasses", "artifacts", "creatures", "factions", "objects", "heroes", "spells", "skills" };
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
for(auto contentName : contentNames)
|
|
|
|
{
|
2023-07-30 19:12:25 +02:00
|
|
|
auto const & handler = *VLC->modh->content;
|
|
|
|
auto const & content = handler[contentName];
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
auto contentOutPath = outPath / contentName;
|
|
|
|
boost::filesystem::create_directories(contentOutPath);
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
for(auto& iter : content.modData)
|
|
|
|
{
|
|
|
|
const JsonNode& modData = iter.second.modData;
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
for(auto& nameAndObject : modData.Struct())
|
|
|
|
{
|
|
|
|
const JsonNode& object = nameAndObject.second;
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-07-30 19:12:25 +02:00
|
|
|
std::string name = ModUtility::makeFullIdentifier(object.meta, contentName, nameAndObject.first);
|
2023-04-16 18:29:31 +02:00
|
|
|
|
|
|
|
boost::algorithm::replace_all(name, ":", "_");
|
|
|
|
|
|
|
|
const boost::filesystem::path filePath = contentOutPath / (name + ".json");
|
2023-07-28 14:51:14 +02:00
|
|
|
std::ofstream file(filePath.c_str());
|
2023-04-16 18:29:31 +02:00
|
|
|
file << object.toJson();
|
2023-01-06 18:52:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-16 18:29:31 +02:00
|
|
|
|
|
|
|
printCommandMessage("\rExtracting done :)\n");
|
|
|
|
printCommandMessage("Extracted files can be found in " + outPath.string() + " directory\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientCommandManager::handleGetScriptsCommand()
|
|
|
|
{
|
2023-01-06 18:52:18 +02:00
|
|
|
#if SCRIPTING_ENABLED
|
2023-04-16 18:29:31 +02:00
|
|
|
printCommandMessage("Command accepted.\t");
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
const boost::filesystem::path outPath = VCMIDirs::get().userExtractedPath() / "scripts";
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
boost::filesystem::create_directories(outPath);
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
for(auto & kv : VLC->scriptHandler->objects)
|
|
|
|
{
|
|
|
|
std::string name = kv.first;
|
|
|
|
boost::algorithm::replace_all(name,":","_");
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
const scripting::ScriptImpl * script = kv.second.get();
|
|
|
|
boost::filesystem::path filePath = outPath / (name + ".lua");
|
2023-07-28 14:51:14 +02:00
|
|
|
std::ofstream file(filePath.c_str());
|
2023-04-16 18:29:31 +02:00
|
|
|
file << script->getSource();
|
2023-01-06 18:52:18 +02:00
|
|
|
}
|
2023-04-16 18:29:31 +02:00
|
|
|
printCommandMessage("\rExtracting done :)\n");
|
|
|
|
printCommandMessage("Extracted files can be found in " + outPath.string() + " directory\n");
|
2023-01-06 18:52:18 +02:00
|
|
|
#endif
|
2023-04-16 18:29:31 +02:00
|
|
|
}
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
void ClientCommandManager::handleGetTextCommand()
|
|
|
|
{
|
|
|
|
printCommandMessage("Command accepted.\t");
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
const boost::filesystem::path outPath =
|
|
|
|
VCMIDirs::get().userExtractedPath();
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
auto list =
|
|
|
|
CResourceHandler::get()->getFilteredFiles([](const ResourceID & ident)
|
|
|
|
{
|
|
|
|
return ident.getType() == EResType::TEXT && boost::algorithm::starts_with(ident.getName(), "DATA/");
|
|
|
|
});
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
for (auto & filename : list)
|
|
|
|
{
|
|
|
|
const boost::filesystem::path filePath = outPath / (filename.getName() + ".TXT");
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
boost::filesystem::create_directories(filePath.parent_path());
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-07-28 14:51:14 +02:00
|
|
|
std::ofstream file(filePath.c_str());
|
2023-04-16 18:29:31 +02:00
|
|
|
auto text = CResourceHandler::get()->load(filename)->readAll();
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
file.write((char*)text.first.get(), text.second);
|
2023-01-06 18:52:18 +02:00
|
|
|
}
|
2023-04-16 18:29:31 +02:00
|
|
|
|
|
|
|
printCommandMessage("\rExtracting done :)\n");
|
|
|
|
printCommandMessage("Extracted files can be found in " + outPath.string() + " directory\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientCommandManager::handleDef2bmpCommand(std::istringstream& singleWordBuffer)
|
|
|
|
{
|
|
|
|
std::string URI;
|
|
|
|
singleWordBuffer >> URI;
|
|
|
|
std::unique_ptr<CAnimation> anim = std::make_unique<CAnimation>(URI);
|
|
|
|
anim->preload();
|
|
|
|
anim->exportBitmaps(VCMIDirs::get().userExtractedPath());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientCommandManager::handleExtractCommand(std::istringstream& singleWordBuffer)
|
|
|
|
{
|
|
|
|
std::string URI;
|
|
|
|
singleWordBuffer >> URI;
|
|
|
|
|
|
|
|
if(CResourceHandler::get()->existsResource(ResourceID(URI)))
|
2023-01-06 18:52:18 +02:00
|
|
|
{
|
2023-04-16 18:29:31 +02:00
|
|
|
const boost::filesystem::path outPath = VCMIDirs::get().userExtractedPath() / URI;
|
|
|
|
|
|
|
|
auto data = CResourceHandler::get()->load(ResourceID(URI))->readAll();
|
|
|
|
|
|
|
|
boost::filesystem::create_directories(outPath.parent_path());
|
2023-07-28 14:51:14 +02:00
|
|
|
std::ofstream outFile(outPath.c_str(), std::ofstream::binary);
|
2023-04-16 18:29:31 +02:00
|
|
|
outFile.write((char*)data.first.get(), data.second);
|
2023-01-06 18:52:18 +02:00
|
|
|
}
|
2023-04-16 18:29:31 +02:00
|
|
|
else
|
|
|
|
printCommandMessage("File not found!", ELogLevel::ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientCommandManager::handleBonusesCommand(std::istringstream & singleWordBuffer)
|
|
|
|
{
|
|
|
|
if(currentCallFromIngameConsole)
|
2023-01-06 18:52:18 +02:00
|
|
|
{
|
2023-04-16 18:29:31 +02:00
|
|
|
printCommandMessage("Output for this command is too large for ingame chat! Please run it from client console.\n");
|
|
|
|
return;
|
2023-01-06 18:52:18 +02:00
|
|
|
}
|
2023-04-16 18:29:31 +02:00
|
|
|
|
|
|
|
std::string outputFormat;
|
|
|
|
singleWordBuffer >> outputFormat;
|
|
|
|
|
|
|
|
auto format = [outputFormat](const BonusList & b) -> std::string
|
2023-01-06 18:52:18 +02:00
|
|
|
{
|
2023-04-16 18:29:31 +02:00
|
|
|
if(outputFormat == "json")
|
|
|
|
return b.toJsonNode().toJson(true);
|
|
|
|
|
|
|
|
std::ostringstream ss;
|
|
|
|
ss << b;
|
|
|
|
return ss.str();
|
|
|
|
};
|
2023-04-17 12:06:58 +02:00
|
|
|
printCommandMessage("Bonuses of " + LOCPLINT->localState->getCurrentArmy()->getObjectName() + "\n");
|
2023-05-03 15:09:21 +02:00
|
|
|
printCommandMessage(format(*LOCPLINT->localState->getCurrentArmy()->getAllBonuses(Selector::all, Selector::all)) + "\n");
|
2023-04-16 18:29:31 +02:00
|
|
|
|
|
|
|
printCommandMessage("\nInherited bonuses:\n");
|
|
|
|
TCNodes parents;
|
2023-04-17 12:06:58 +02:00
|
|
|
LOCPLINT->localState->getCurrentArmy()->getParents(parents);
|
2023-04-16 18:29:31 +02:00
|
|
|
for(const CBonusSystemNode *parent : parents)
|
2023-01-06 18:52:18 +02:00
|
|
|
{
|
2023-04-16 18:29:31 +02:00
|
|
|
printCommandMessage(std::string("\nBonuses from ") + typeid(*parent).name() + "\n" + format(*parent->getAllBonuses(Selector::all, Selector::all)) + "\n");
|
2023-01-06 18:52:18 +02:00
|
|
|
}
|
2023-04-16 18:29:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientCommandManager::handleTellCommand(std::istringstream& singleWordBuffer)
|
|
|
|
{
|
|
|
|
std::string what;
|
|
|
|
int id1, id2;
|
|
|
|
singleWordBuffer >> what >> id1 >> id2;
|
|
|
|
|
|
|
|
if(what == "hs")
|
2023-01-06 18:52:18 +02:00
|
|
|
{
|
2023-04-16 18:29:31 +02:00
|
|
|
for(const CGHeroInstance* h : LOCPLINT->cb->getHeroesInfo())
|
|
|
|
if(h->type->getIndex() == id1)
|
|
|
|
if(const CArtifactInstance* a = h->getArt(ArtifactPosition(id2)))
|
|
|
|
printCommandMessage(a->nodeName());
|
2023-01-06 18:52:18 +02:00
|
|
|
}
|
2023-04-16 18:29:31 +02:00
|
|
|
}
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
void ClientCommandManager::handleMpCommand()
|
|
|
|
{
|
2023-04-19 16:38:25 +02:00
|
|
|
if(const CGHeroInstance* h = LOCPLINT->localState->getCurrentHero())
|
2023-06-21 19:38:26 +02:00
|
|
|
printCommandMessage(std::to_string(h->movementPointsRemaining()) + "; max: " + std::to_string(h->movementPointsLimit(true)) + "/" + std::to_string(h->movementPointsLimit(false)) + "\n");
|
2023-04-16 18:29:31 +02:00
|
|
|
}
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
void ClientCommandManager::handleSetCommand(std::istringstream& singleWordBuffer)
|
|
|
|
{
|
|
|
|
std::string what, value;
|
|
|
|
singleWordBuffer >> what;
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 18:29:31 +02:00
|
|
|
Settings config = settings.write["session"][what];
|
|
|
|
|
|
|
|
singleWordBuffer >> value;
|
|
|
|
|
|
|
|
if(value == "on")
|
2023-01-06 18:52:18 +02:00
|
|
|
{
|
2023-04-16 18:29:31 +02:00
|
|
|
config->Bool() = true;
|
|
|
|
printCommandMessage("Option " + what + " enabled!", ELogLevel::INFO);
|
2023-01-06 18:52:18 +02:00
|
|
|
}
|
2023-04-16 18:29:31 +02:00
|
|
|
else if(value == "off")
|
2023-01-06 18:52:18 +02:00
|
|
|
{
|
2023-04-16 18:29:31 +02:00
|
|
|
config->Bool() = false;
|
|
|
|
printCommandMessage("Option " + what + " disabled!", ELogLevel::INFO);
|
2023-01-06 18:52:18 +02:00
|
|
|
}
|
2023-04-16 18:29:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientCommandManager::handleUnlockCommand(std::istringstream& singleWordBuffer)
|
|
|
|
{
|
|
|
|
std::string mxname;
|
|
|
|
singleWordBuffer >> mxname;
|
|
|
|
if(mxname == "pim" && LOCPLINT)
|
|
|
|
LOCPLINT->pim->unlock();
|
|
|
|
}
|
2023-01-06 18:52:18 +02:00
|
|
|
|
2023-04-16 22:56:15 +02:00
|
|
|
void ClientCommandManager::handleCrashCommand()
|
2023-01-06 18:52:18 +02:00
|
|
|
{
|
2023-04-16 18:29:31 +02:00
|
|
|
int* ptr = nullptr;
|
|
|
|
*ptr = 666;
|
|
|
|
//disaster!
|
2023-01-06 22:01:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientCommandManager::printCommandMessage(const std::string &commandMessage, ELogLevel::ELogLevel messageType)
|
|
|
|
{
|
|
|
|
switch(messageType)
|
|
|
|
{
|
|
|
|
case ELogLevel::NOT_SET:
|
|
|
|
std::cout << commandMessage;
|
|
|
|
break;
|
|
|
|
case ELogLevel::TRACE:
|
|
|
|
logGlobal->trace(commandMessage);
|
|
|
|
break;
|
|
|
|
case ELogLevel::DEBUG:
|
|
|
|
logGlobal->debug(commandMessage);
|
|
|
|
break;
|
|
|
|
case ELogLevel::INFO:
|
|
|
|
logGlobal->info(commandMessage);
|
|
|
|
break;
|
|
|
|
case ELogLevel::WARN:
|
|
|
|
logGlobal->warn(commandMessage);
|
|
|
|
break;
|
|
|
|
case ELogLevel::ERROR:
|
|
|
|
logGlobal->error(commandMessage);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
std::cout << commandMessage;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(currentCallFromIngameConsole)
|
|
|
|
{
|
2023-01-11 18:14:10 +02:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*CPlayerInterface::pim);
|
2023-01-06 22:01:00 +02:00
|
|
|
if(LOCPLINT && LOCPLINT->cingconsole)
|
|
|
|
{
|
|
|
|
LOCPLINT->cingconsole->print(commandMessage);
|
|
|
|
}
|
|
|
|
}
|
2023-01-02 13:27:03 +02:00
|
|
|
}
|
2023-04-16 18:29:31 +02:00
|
|
|
|
|
|
|
void ClientCommandManager::giveTurn(const PlayerColor &colorIdentifier)
|
|
|
|
{
|
|
|
|
YourTurn yt;
|
|
|
|
yt.player = colorIdentifier;
|
|
|
|
yt.daysWithoutCastle = CSH->client->getPlayerState(colorIdentifier)->daysWithoutCastle;
|
|
|
|
|
|
|
|
ApplyClientNetPackVisitor visitor(*CSH->client, *CSH->client->gameState());
|
|
|
|
yt.visit(visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientCommandManager::processCommand(const std::string & message, bool calledFromIngameConsole)
|
|
|
|
{
|
|
|
|
// split the message into individual words
|
|
|
|
std::istringstream singleWordBuffer;
|
|
|
|
singleWordBuffer.str(message);
|
|
|
|
|
|
|
|
// get command name, to be used for single word commands
|
|
|
|
std::string commandName;
|
|
|
|
singleWordBuffer >> commandName;
|
|
|
|
|
|
|
|
currentCallFromIngameConsole = calledFromIngameConsole;
|
|
|
|
|
|
|
|
if(message == std::string("die, fool"))
|
|
|
|
handleQuitCommand();
|
|
|
|
|
|
|
|
else if(commandName == "save")
|
|
|
|
handleSaveCommand(singleWordBuffer);
|
|
|
|
|
|
|
|
else if(commandName=="load")
|
|
|
|
handleLoadCommand(singleWordBuffer); // not implemented
|
|
|
|
|
|
|
|
else if(commandName == "gosolo")
|
|
|
|
handleGoSoloCommand();
|
|
|
|
|
|
|
|
else if(commandName == "autoskip")
|
|
|
|
handleAutoskipCommand();
|
|
|
|
|
|
|
|
else if(commandName == "controlai")
|
|
|
|
handleControlaiCommand(singleWordBuffer);
|
|
|
|
|
|
|
|
else if(commandName == "setBattleAI")
|
|
|
|
handleSetBattleAICommand(singleWordBuffer);
|
|
|
|
|
|
|
|
else if(commandName == "redraw")
|
|
|
|
handleRedrawCommand();
|
|
|
|
|
|
|
|
else if(commandName == "not dialog")
|
|
|
|
handleNotDialogCommand();
|
|
|
|
|
|
|
|
else if(message=="convert txt")
|
|
|
|
handleConvertTextCommand();
|
|
|
|
|
|
|
|
else if(message=="get config")
|
|
|
|
handleGetConfigCommand();
|
|
|
|
|
|
|
|
else if(message=="get scripts")
|
|
|
|
handleGetScriptsCommand();
|
|
|
|
|
|
|
|
else if(message=="get txt")
|
|
|
|
handleGetTextCommand();
|
|
|
|
|
|
|
|
else if(commandName == "def2bmp")
|
|
|
|
handleDef2bmpCommand(singleWordBuffer);
|
|
|
|
|
|
|
|
else if(commandName == "extract")
|
|
|
|
handleExtractCommand(singleWordBuffer);
|
|
|
|
|
|
|
|
else if(commandName == "bonuses")
|
|
|
|
handleBonusesCommand(singleWordBuffer);
|
|
|
|
|
|
|
|
else if(commandName == "tell")
|
|
|
|
handleTellCommand(singleWordBuffer);
|
|
|
|
|
2023-04-19 16:38:25 +02:00
|
|
|
else if(commandName == "mp" && LOCPLINT)
|
2023-04-16 18:29:31 +02:00
|
|
|
handleMpCommand();
|
|
|
|
|
|
|
|
else if (commandName == "set")
|
|
|
|
handleSetCommand(singleWordBuffer);
|
|
|
|
|
|
|
|
else if(commandName == "unlock")
|
|
|
|
handleUnlockCommand(singleWordBuffer);
|
|
|
|
|
|
|
|
else if(commandName == "crash")
|
|
|
|
handleCrashCommand();
|
|
|
|
|
|
|
|
else
|
2023-04-16 22:56:15 +02:00
|
|
|
{
|
|
|
|
if (!commandName.empty() && !vstd::iswithin(commandName[0], 0, ' ')) // filter-out debugger/IDE noise
|
|
|
|
printCommandMessage("Command not found :(", ELogLevel::ERROR);
|
|
|
|
}
|
2023-04-16 18:29:31 +02:00
|
|
|
}
|