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-09-04 17:01:44 +02:00
|
|
|
#include "render/IRenderHandler.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"
|
2023-08-19 23:22:31 +02:00
|
|
|
#include "../lib/constants/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-10-23 12:59:15 +02:00
|
|
|
#include "../lib/mapObjects/CGHeroInstance.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"];
|
|
|
|
|
2023-09-27 17:33:52 +02:00
|
|
|
boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
|
|
|
|
|
2023-01-06 18:52:18 +02:00
|
|
|
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-09-04 21:21:02 +02:00
|
|
|
printCommandMessage("Player " + elem.first.toString() + " 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-09-27 17:33:52 +02:00
|
|
|
boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
|
|
|
|
|
2023-01-06 18:52:18 +02:00
|
|
|
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");
|
2023-08-23 14:07:50 +02:00
|
|
|
std::unordered_set<ResourcePath> mapList = CResourceHandler::get()->getFilteredFiles([&](const ResourcePath & 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-08-23 14:07:50 +02:00
|
|
|
std::unordered_set<ResourcePath> campaignList = CResourceHandler::get()->getFilteredFiles([&](const ResourcePath & ident)
|
2023-04-16 18:29:31 +02:00
|
|
|
{
|
|
|
|
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
|
2024-01-01 16:37:48 +02:00
|
|
|
mapService.loadMap(mapName, nullptr);
|
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())
|
2024-01-01 16:37:48 +02:00
|
|
|
state->getMap(part, nullptr);
|
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
|
|
|
|
2024-01-19 15:12:35 +02:00
|
|
|
for(const auto & kv : VLC->scriptHandler->objects)
|
2023-04-16 18:29:31 +02:00
|
|
|
{
|
|
|
|
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 =
|
2023-08-23 14:07:50 +02:00
|
|
|
CResourceHandler::get()->getFilteredFiles([](const ResourcePath & ident)
|
2023-04-16 18:29:31 +02:00
|
|
|
{
|
|
|
|
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;
|
2023-09-04 17:01:44 +02:00
|
|
|
auto anim = GH.renderHandler().loadAnimation(AnimationPath::builtin(URI));
|
2023-04-16 18:29:31 +02:00
|
|
|
anim->preload();
|
|
|
|
anim->exportBitmaps(VCMIDirs::get().userExtractedPath());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientCommandManager::handleExtractCommand(std::istringstream& singleWordBuffer)
|
|
|
|
{
|
|
|
|
std::string URI;
|
|
|
|
singleWordBuffer >> URI;
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
if(CResourceHandler::get()->existsResource(ResourcePath(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;
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
auto data = CResourceHandler::get()->load(ResourcePath(URI))->readAll();
|
2023-04-16 18:29:31 +02:00
|
|
|
|
|
|
|
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;
|
2024-01-10 00:38:54 +02:00
|
|
|
int id1;
|
|
|
|
int id2;
|
2023-04-16 18:29:31 +02:00
|
|
|
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)
|
|
|
|
{
|
2024-01-10 00:38:54 +02:00
|
|
|
std::string what;
|
|
|
|
std::string value;
|
2023-04-16 18:29:31 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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-09-27 17:33:52 +02:00
|
|
|
boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
|
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)
|
|
|
|
{
|
2023-09-17 00:13:58 +02:00
|
|
|
PlayerStartsTurn yt;
|
2023-04-16 18:29:31 +02:00
|
|
|
yt.player = colorIdentifier;
|
2023-09-28 18:43:04 +02:00
|
|
|
yt.queryID = QueryID::NONE;
|
2023-04-16 18:29:31 +02:00
|
|
|
|
|
|
|
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 == "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
|
|
|
}
|