Added serverGame library

This commit is contained in:
Anonymous
2014-01-15 03:59:18 -07:00
parent 89291fb38c
commit 0196cf51d0
1032 changed files with 256379 additions and 0 deletions
@@ -0,0 +1,291 @@
// CentralCommandParserGame.cpp
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
// Author: Justin Randall
//-----------------------------------------------------------------------
#include "serverGame/FirstServerGame.h"
#include "serverGame/CentralCommandParserGame.h"
#include "serverGame/Chat.h"
#include "serverGame/ConfigServerGame.h"
#include "serverGame/GameServer.h"
#include "serverGame/ObjectTracker.h"
#include "serverGame/ServerMessageForwarding.h"
#include "serverNetworkMessages/ReloadDatatableMessage.h"
#include "serverNetworkMessages/ReloadScriptMessage.h"
#include "serverNetworkMessages/ReloadTemplateMessage.h"
#include "serverNetworkMessages/SetConnectionServerPublic.h"
#include "serverScript/GameScriptObject.h"
#include "serverScript/ScriptParameters.h"
#include "sharedFile/TreeFile.h"
#include "sharedLog/Log.h"
#include "sharedObject/ObjectTemplateList.h"
#include "sharedUtility/DataTableManager.h"
#include "sharedUtility/DataTable.h"
#include "UnicodeUtils.h"
//-----------------------------------------------------------------------
CentralCommandParserGame::CentralCommandParserGame() :
CommandParser ("game", 0, "...", "game commands from the central server", 0)
{
}
//-----------------------------------------------------------------------
CentralCommandParserGame::~CentralCommandParserGame()
{
}
//-----------------------------------------------------------------------
bool CentralCommandParserGame::performParsing (const NetworkId &, const StringVector_t & argv, const String_t & originalMessage, String_t & result, const CommandParser *)
{
LOG("ServerConsole", ("Parsing ServerConsole command."));
bool retval = false;
if(! argv.empty())
{
std::string cmd = Unicode::wideToNarrow(argv[2]);
LOG("ServerConsole", ("Attempting to execute command '%s'.", cmd.c_str()) );
if(cmd == "runScript")
{
// build arguments
if(argv.size() > 4)
{
// get script name
std::string scriptName = Unicode::wideToNarrow(argv[3]);
std::string methodName = Unicode::wideToNarrow(argv[4]);
// determine params
Unicode::String strParam = originalMessage.substr(originalMessage.find(argv[4]) + argv[4].length() + 1);
ScriptParams params;
params.addParam(strParam, "strParam");
std::string scriptResult = GameScriptObject::callScriptConsoleHandler(scriptName, methodName, "u", params);
result += Unicode::narrowToWide(scriptResult);
retval = true;
}
}
else if( cmd == "public" )
{
// LOG("ServerConsole", ("Setting cluster to public."));
SetConnectionServerPublic const p(true);
GameServer::getInstance().sendToCentralServer(p);
result += Unicode::narrowToWide("Cluster set to public.\n");
retval = true;
}
else if( cmd == "private" )
{
// LOG("ServerConsole", ("Setting cluster to private."));
SetConnectionServerPublic const p(false);
GameServer::getInstance().sendToCentralServer(p);
result += Unicode::narrowToWide("Cluster set to private.\n");
retval = true;
}
else if(cmd == "systemMessage")
{
std::string targetId = "SWG." + GameServer::getInstance().getClusterName() + ".SYSTEM";
static const Unicode::String oob;
Unicode::String output = originalMessage.substr(originalMessage.find(argv[2]) + argv[2].length() + 1);
// LOG("ServerConsole", ("Attempting to send system message."));
Chat::sendToRoom("SYSTEM", targetId, output, oob);
result += Unicode::narrowToWide("message \"");
result += output;
result += Unicode::narrowToWide("\" sent to chat system\n");
retval = true;
}
// reloads a script on all game servers
else if(cmd == "reloadScript")
{
std::string scriptName = Unicode::wideToNarrow(argv[3]);
if( GameScriptObject::reloadScript(scriptName) )
{
LOG("ServerConsole", ("Successfully reloaded script '%s'.", scriptName.c_str()));
result += Unicode::narrowToWide("reloadScript '");
result += Unicode::narrowToWide(scriptName);
result += Unicode::narrowToWide("' succeeded\n");
retval = true;
}
else
{
LOG("ServerConsole", ("Failed to reload script '%s'.", scriptName.c_str()));
result += Unicode::narrowToWide("reloadScript '");
result += Unicode::narrowToWide(scriptName);
result += Unicode::narrowToWide("' failed\n");
retval = false;
}
ServerMessageForwarding::beginBroadcast();
ReloadScriptMessage const reloadScriptMessage(scriptName);
ServerMessageForwarding::send(reloadScriptMessage);
ServerMessageForwarding::end();
}
else if( cmd == "reloadServerTemplate" )
{
std::string templateName = Unicode::wideToNarrow(argv[3]);
Iff templateFile;
if( !templateFile.open(templateName.c_str(), true))
{
result += Unicode::narrowToWide("Template '");
result += Unicode::narrowToWide(templateName);
result += Unicode::narrowToWide("' does not exist.\n");
retval = false;
}
else
{
if( !ObjectTemplateList::isLoaded(templateName) )
{
result += Unicode::narrowToWide("Template '");
result += Unicode::narrowToWide(templateName);
result += Unicode::narrowToWide("' can not be reloaded because it is not currently loaded.\n");
retval = false;
}
else
{
if( ObjectTemplateList::reload(templateFile) )
{
result += Unicode::narrowToWide("Template '");
result += Unicode::narrowToWide(templateName);
result += Unicode::narrowToWide("' reloaded.\n");
retval = true;
}
else
{
result += Unicode::narrowToWide("Template '");
result += Unicode::narrowToWide(templateName);
result += Unicode::narrowToWide("' reload failed.\n");
retval = false;
}
}
}
ServerMessageForwarding::beginBroadcast();
ReloadTemplateMessage const reloadTemplateMessage(templateName);
ServerMessageForwarding::send(reloadTemplateMessage);
ServerMessageForwarding::end();
}
else if( cmd == "reloadTable" )
{
std::string tableName = Unicode::wideToNarrow(argv[3]);
if( !TreeFile::exists(tableName.c_str()) )
{
result += Unicode::narrowToWide("Table '");
result += Unicode::narrowToWide(tableName);
result += Unicode::narrowToWide("' does not exist.\n");
retval = false;
}
else
{
if( DataTableManager::reload(tableName) )
{
result += Unicode::narrowToWide("Reload for datatable '");
result += Unicode::narrowToWide(tableName);
result += Unicode::narrowToWide("' succeeded.\n");
retval = true;
}
else
{
result += Unicode::narrowToWide("Reload for datatable '");
result += Unicode::narrowToWide(tableName);
result += Unicode::narrowToWide("' failed.\n");
retval = false;
}
}
ServerMessageForwarding::beginBroadcast();
ReloadDatatableMessage const reloadDatatableMessage(tableName);
ServerMessageForwarding::send(reloadDatatableMessage);
ServerMessageForwarding::end();
}
else if( cmd == "public" )
{
LOG("ServerConsole", ("Setting cluster to public."));
SetConnectionServerPublic const p(true);
GameServer::getInstance().sendToCentralServer(p);
result += Unicode::narrowToWide("Cluster set to public.\n");
retval = true;
}
else if( cmd == "private" )
{
LOG("ServerConsole", ("Setting cluster to private."));
SetConnectionServerPublic const p(false);
GameServer::getInstance().sendToCentralServer(p);
result += Unicode::narrowToWide("Cluster set to private.\n");
retval = true;
}
else if(cmd == "info")
{
char numBuf[64] = {"\0"};
static const Unicode::String unl(Unicode::narrowToWide(std::string("\n")));
result += Unicode::narrowToWide("PID: ");
snprintf(numBuf, sizeof(numBuf), "%lu", GameServer::getInstance().getProcessId());
result += Unicode::narrowToWide(std::string(numBuf)) + unl;
result += Unicode::narrowToWide("Scene: ") + Unicode::narrowToWide(ConfigServerGame::getSceneID()) + unl;
snprintf(numBuf, sizeof(numBuf), "%d", ObjectTracker::getNumObjects());
result += Unicode::narrowToWide(std::string("Number of Objects: ") + std::string(numBuf)) + unl;
snprintf(numBuf, sizeof(numBuf), "%d", ObjectTracker::getNumAI());
result += Unicode::narrowToWide(std::string("Number of AI: ") + std::string(numBuf)) + unl;
snprintf(numBuf, sizeof(numBuf), "%d", ObjectTracker::getNumBuildings());
result += Unicode::narrowToWide(std::string("Number of Buildings: ") + std::string(numBuf)) + unl;
snprintf(numBuf, sizeof(numBuf), "%d", ObjectTracker::getNumCreatures());
result += Unicode::narrowToWide(std::string("Number of Creatures: ") + std::string(numBuf)) + unl;
snprintf(numBuf, sizeof(numBuf), "%d", ObjectTracker::getNumPlayers());
result += Unicode::narrowToWide(std::string("Number of Players: ") + std::string(numBuf)) + unl;
snprintf(numBuf, sizeof(numBuf), "%d", ObjectTracker::getNumTangibles());
result += Unicode::narrowToWide(std::string("Number of Tangibles: ") + std::string(numBuf)) + unl;
snprintf(numBuf, sizeof(numBuf), "%d", ObjectTracker::getNumUniverseObjects());
result += Unicode::narrowToWide(std::string("Number of UniverseObjects: ") + std::string(numBuf)) + unl;
snprintf(numBuf, sizeof(numBuf), "%d", ObjectTracker::getNumDynamicAI());
result += Unicode::narrowToWide(std::string("Number of Dynamic AI: ") + std::string(numBuf)) + unl;
snprintf(numBuf, sizeof(numBuf), "%d", ObjectTracker::getNumStaticAI());
result += Unicode::narrowToWide(std::string("Number of Dynamic AI: ") + std::string(numBuf)) + unl;
snprintf(numBuf, sizeof(numBuf), "%d", ObjectTracker::getNumIntangibles());
result += Unicode::narrowToWide(std::string("Number of Intangibles: ") + std::string(numBuf)) + unl;
snprintf(numBuf, sizeof(numBuf), "%d", ObjectTracker::getNumMissionDatas());
result += Unicode::narrowToWide(std::string("Number of MissionDatas: ") + std::string(numBuf)) + unl;
snprintf(numBuf, sizeof(numBuf), "%d", ObjectTracker::getNumMissionObjects());
result += Unicode::narrowToWide(std::string("Number of MissionObjects: ") + std::string(numBuf)) + unl;
snprintf(numBuf, sizeof(numBuf), "%d", ObjectTracker::getNumRunTimeRules());
result += Unicode::narrowToWide(std::string("Number of Runtime Rules: ") + std::string(numBuf)) + unl;
snprintf(numBuf, sizeof(numBuf), "%d", ObjectTracker::getNumGroupObjects());
result += Unicode::narrowToWide(std::string("Number of GroupObjects: ") + std::string(numBuf)) + unl;
snprintf(numBuf, sizeof(numBuf), "%d", ObjectTracker::getNumMissionListEntries());
result += Unicode::narrowToWide(std::string("Number of MissionListEntries: ") + std::string(numBuf)) + unl;
snprintf(numBuf, sizeof(numBuf), "%d", ObjectTracker::getNumWaypoints());
result += Unicode::narrowToWide(std::string("Number of Waypoints: ") + std::string(numBuf)) + unl;
snprintf(numBuf, sizeof(numBuf), "%d", ObjectTracker::getNumPlayerQuestObjects());
result += Unicode::narrowToWide(std::string("Number of PlayerQuestObjects: ") + std::string(numBuf)) + unl;
}
}
LOG("ServerConsole", ("Command parsing %s.", retval==true?"succeeded":"failed"));
return retval;
}
//-----------------------------------------------------------------------
@@ -0,0 +1,30 @@
// CentralCommandParserGame.h
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
// Author: Justin Randall
#ifndef _INCLUDED_CentralCommandParserGame_H
#define _INCLUDED_CentralCommandParserGame_H
//-----------------------------------------------------------------------
#include "sharedCommandParser/CommandParser.h"
//-----------------------------------------------------------------------
class CentralCommandParserGame : public CommandParser
{
public:
CentralCommandParserGame();
~CentralCommandParserGame();
virtual bool performParsing (const NetworkId & userId, const StringVector_t & argv,const String_t & originalCommand,String_t & result,const CommandParser * node);
private:
CentralCommandParserGame & operator = (const CentralCommandParserGame & rhs);
CentralCommandParserGame(const CentralCommandParserGame & source);
};
//-----------------------------------------------------------------------
#endif // _INCLUDED_CentralCommandParserGame_H
@@ -0,0 +1,676 @@
// ======================================================================
//
// ConsoleCommandParserAi.cpp
// Copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ConsoleCommandParserAi.h"
#include "serverGame/AiCreatureController.h"
#include "serverGame/AiShipController.h"
#include "serverGame/Chat.h"
#include "serverGame/CreatureObject.h"
#include "serverGame/HateList.h"
#include "serverGame/ServerWorld.h"
#include "serverGame/WeaponObject.h"
#include "serverUtility/ServerClock.h"
#include "sharedFile/FileNameUtils.h"
#include "sharedFoundation/FormattedString.h"
#include "sharedFoundation/NetworkId.h"
#include "sharedGame/AiDebugString.h"
#include "sharedNetworkMessages/GenericValueTypeMessage.h"
#include "sharedObject/CellProperty.h"
#include "sharedObject/NetworkIdManager.h"
#include "sharedUtility/DataTable.h"
#include "sharedUtility/DataTableManager.h"
#include "UnicodeUtils.h"
// ======================================================================
static const CommandParser::CmdInfo cmds[] =
{
{"info", 0, "[oid]", "Displays information about the specified AI. Assumes target if no oid specified."},
{"hatelist", 0, "[oid]", "Displays the specified object's hate list. Assumes target if no oid specified."},
{"kill", 0, "[oid]", "Kills the specified AI. Assumes target if no oid specified."},
{"log", 0, "[oid]", "Toggles log file data for the specified AI. Assumes target if no oid specified."},
{"retreat", 0, "[oid]", "Toggles whether the specified AI can auto retreat due to a player running away without attacking. Assumes target if no oid specified."},
{"walkspeed", 1, "<speed | oid speed>", "Displays the current walk speed or sets the walk speed for the specified AI. Assumes target if no oid specified."},
{"runspeed", 1, "<speed | oid speed>", "Displays the current run speed or sets the run speed for the specified AI. Assumes target if no oid specified."},
#ifdef _DEBUG
{"killall", 0, "", "Kills all the AI on the server."},
{"debug", 0, "", "Toggles client AI debugging."},
{"debugText", 0, "", "Toggles the client AI debugging text."},
#endif // _DEBUG
{"", 0, "", ""} // this must be last
};
// ======================================================================
//
// ConsoleCommandParserAiNamespace
//
// ======================================================================
namespace ConsoleCommandParserAiNamespace
{
CreatureObject * const getAiCreatureObject(CreatureObject const & user, std::vector<Unicode::String> const & argv);
}
//-----------------------------------------------------------------
CreatureObject * const ConsoleCommandParserAiNamespace::getAiCreatureObject(CreatureObject const & user, std::vector<Unicode::String> const & argv)
{
NetworkId aiNetworkId;
if (argv.size() > 1)
{
aiNetworkId = NetworkId(Unicode::wideToNarrow(argv[1]));
}
else
{
aiNetworkId = user.getLookAtTarget();
}
CreatureObject * const aiCreatureObject = CreatureObject::getCreatureObject(aiNetworkId);
if ( (aiCreatureObject == NULL)
|| aiCreatureObject->isPlayerControlled())
{
Chat::sendSystemMessage(user, Unicode::narrowToWide(FormattedString<1024>().sprintf("[FAILURE] Unable to resolve %s to an AI", aiNetworkId.getValueString().c_str())), Unicode::emptyString);
}
return aiCreatureObject;
}
using namespace ConsoleCommandParserAiNamespace;
// ======================================================================
//
// ConsoleCommandParserAi
//
// ======================================================================
//-----------------------------------------------------------------
ConsoleCommandParserAi::ConsoleCommandParserAi()
: CommandParser("ai", 0, "...", "Ai related commands.", 0)
{
createDelegateCommands (cmds);
}
//-----------------------------------------------------------------
bool ConsoleCommandParserAi::performParsing(const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node)
{
NOT_NULL (node);
UNREF (userId);
UNREF(originalCommand);
FormattedString<1024> fs;
if (isAbbrev(argv[0], "log"))
{
CreatureObject * const userCreatureObject = CreatureObject::getCreatureObject(userId);
if (userCreatureObject == NULL)
{
result += getErrorMessage(argv[0], ERR_FAIL);
}
else
{
CreatureObject * const aiCreatureObject = getAiCreatureObject(*userCreatureObject, argv);
if (aiCreatureObject == NULL)
{
result += getErrorMessage(argv[0], ERR_FAIL);
}
else
{
AICreatureController * const aiCreatureController = AICreatureController::asAiCreatureController(aiCreatureObject->getController());
if (aiCreatureController == NULL)
{
Chat::sendSystemMessage(*userCreatureObject, Unicode::narrowToWide(fs.sprintf("[FAILURE] Unable to resolve %s to an AI", aiCreatureObject->getNetworkId().getValueString().c_str())), Unicode::emptyString);
result += getErrorMessage(argv[0], ERR_FAIL);
}
else
{
aiCreatureController->setLogging(!aiCreatureController->isLogging());
Chat::sendSystemMessage(*userCreatureObject, Unicode::narrowToWide(fs.sprintf("[%s] Ai logging %s", (aiCreatureController->isLogging() ? "ENABLED" : "DISABLED"), aiCreatureObject->getNetworkId().getValueString().c_str())), Unicode::emptyString);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
}
}
}
else if (isAbbrev(argv[0], "info"))
{
CreatureObject * const userCreatureObject = CreatureObject::getCreatureObject(userId);
if (userCreatureObject == NULL)
{
result += getErrorMessage(argv[0], ERR_FAIL);
}
else
{
NetworkId targetNetworkId;
if (argv.size () > 1)
{
targetNetworkId = NetworkId(Unicode::wideToNarrow(argv[1]));
}
else
{
targetNetworkId = userCreatureObject->getLookAtTarget();
}
AICreatureController * const aiCreatureController = AICreatureController::getAiCreatureController(targetNetworkId);
Unicode::String systemMessage;
if (aiCreatureController == NULL)
{
result = Unicode::narrowToWide(fs.sprintf("[FAILURE] Unable to resolve %s to an AI\n", targetNetworkId.getValueString().c_str()));
result += getErrorMessage(argv[0], ERR_FAIL);
}
else
{
CreatureObject const * const creatureOwner = aiCreatureController->getCreature();
result += Unicode::narrowToWide(fs.sprintf("\nobj_id: %s\n", aiCreatureController->getCreature()->getNetworkId().getValueString().c_str()));
result += Unicode::narrowToWide(fs.sprintf("creatureName: %s\n", aiCreatureController->getCreatureName().getString()));
result += Unicode::narrowToWide(fs.sprintf("level: %i\n", aiCreatureController->getCreature()->getLevel()));
// World position
{
Vector const & position_w = creatureOwner->getPosition_w();
result += Unicode::narrowToWide(fs.sprintf("world position: pos(%.1f, %.1f, %.1f)\n", position_w.x, position_w.y, position_w.z));
}
// Cell position
{
CellProperty const * const cellProperty = creatureOwner->getParentCell();
if (cellProperty != NULL)
{
Vector const & position_p = creatureOwner->getPosition_p();
result += Unicode::narrowToWide(fs.sprintf("cell location: pos(%.1f, %.1f, %.1f) cell(%s:%s)\n", position_p.x, position_p.y, position_p.z, cellProperty->getOwner().getNetworkId().getValueString().c_str(), cellProperty->getCellName()));
}
}
Location const & location = aiCreatureController->getHomeLocation();
result += Unicode::narrowToWide(fs.sprintf("homeLocation: pos(%.1f, %.1f, %.1f) cell(%s:%s) scene(%s)\n", location.getCoordinates().x, location.getCoordinates().y, location.getCoordinates().z, location.getCell().getValueString().c_str(), (location.getCell() == NetworkId::cms_invalid) ? ":world" : "", location.getSceneId()));
result += Unicode::narrowToWide(fs.sprintf("invulnerable: %s\n", aiCreatureController->getCreature()->isInvulnerable() ? "yes" : "no"));
result += Unicode::narrowToWide(fs.sprintf("hibernating: %s\n", aiCreatureController->getHibernate() ? "yes" : "no"));
result += Unicode::narrowToWide(fs.sprintf("movement state: %s\n", AiMovementBase::getMovementString(aiCreatureController->getMovementType())));
result += Unicode::narrowToWide(fs.sprintf("walk speed(%.1f)\n", creatureOwner->getWalkSpeed()));
result += Unicode::narrowToWide(fs.sprintf("run speed(%.1f) modifier(%.2f)\n", creatureOwner->getRunSpeed(), aiCreatureController->getMovementSpeedPercent()));
if (aiCreatureController->isAggressive())
{
result += Unicode::narrowToWide(fs.sprintf("aggressive: yes @ %.1fm\n", aiCreatureController->getAggroRadius()));
}
else
{
result += Unicode::narrowToWide("aggressive: no\n");
}
if (aiCreatureController->isAssist())
{
result += Unicode::narrowToWide(fs.sprintf("assist: yes @ %.1fm\n", aiCreatureController->getAssistRadius()));
}
else
{
result += Unicode::narrowToWide("assist: no\n");
}
result += Unicode::narrowToWide(fs.sprintf("killer: %s\n", aiCreatureController->isKiller() ? "yes" : "no"));
// Hate List
{
HateList::SortedList hateList;
aiCreatureController->getCreature()->getSortedHateList(hateList);
if (hateList.empty())
{
result += Unicode::narrowToWide(fs.sprintf("* NO HATE TARGETS *\n"));
}
else
{
result += Unicode::narrowToWide(fs.sprintf("* HATE LIST *\n"));
HateList::SortedList::const_iterator iterHateList = hateList.begin();
for (; iterHateList != hateList.end(); ++iterHateList)
{
CachedNetworkId const & hateTarget = iterHateList->first;
TangibleObject const * const hateTargetTangibleObject = TangibleObject::asTangibleObject(hateTarget.getObject());
float const hate = iterHateList->second;
std::string hateTargetName;
if (hateTargetTangibleObject != NULL)
{
hateTargetName = Unicode::wideToNarrow(hateTargetTangibleObject->getEncodedObjectName()).c_str();
}
else
{
hateTargetName = "NULL";
}
result += Unicode::narrowToWide(fs.sprintf("%s:%s(%.1f)\n", hateTargetName.c_str(), hateTarget.getValueString().c_str(), hate));
}
}
}
// Hate Over Time List
{
std::map<NetworkId, std::pair<float, std::pair<unsigned long, unsigned long> > > const & hateOverTime = aiCreatureController->getCreature()->getHateOverTime();
if (!hateOverTime.empty())
{
result += Unicode::narrowToWide(fs.sprintf("* HATE OVER TIME LIST currentGameTime=(%lu)*\n", ServerClock::getInstance().getGameTimeSeconds()));
for (std::map<NetworkId, std::pair<float, std::pair<unsigned long, unsigned long> > >::const_iterator iter = hateOverTime.begin(); iter != hateOverTime.end(); ++iter)
{
CachedNetworkId const hateTarget(iter->first);
TangibleObject const * const hateTargetTangibleObject = TangibleObject::asTangibleObject(hateTarget.getObject());
std::string hateTargetName;
if (hateTargetTangibleObject != NULL)
{
hateTargetName = Unicode::wideToNarrow(hateTargetTangibleObject->getEncodedObjectName()).c_str();
}
else
{
hateTargetName = "NULL";
}
result += Unicode::narrowToWide(fs.sprintf("%s:%s (%.2f, %lu, %lu)\n", hateTargetName.c_str(), hateTarget.getValueString().c_str(), iter->second.first, iter->second.second.first, iter->second.second.second));
}
}
}
result += Unicode::narrowToWide(aiCreatureController->getCombatActionsString());
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
}
}
else if (isAbbrev(argv[0], "hatelist"))
{
CreatureObject * const userCreatureObject = CreatureObject::getCreatureObject(userId);
if (userCreatureObject == NULL)
{
result += getErrorMessage(argv[0], ERR_FAIL);
}
else
{
NetworkId targetNetworkId;
if (argv.size () > 1)
{
targetNetworkId = NetworkId(Unicode::wideToNarrow(argv[1]));
}
else
{
targetNetworkId = userCreatureObject->getLookAtTarget();
}
TangibleObject const * const to = TangibleObject::asTangibleObject(NetworkIdManager::getObjectById(targetNetworkId));
if (to == NULL)
{
result += Unicode::narrowToWide(fs.sprintf("Target %s not found or not TangibleObject\n", targetNetworkId.getValueString().c_str()));
}
else
{
result += Unicode::narrowToWide(fs.sprintf("Displaying hate list for %s\n", targetNetworkId.getValueString().c_str()));
// Hate List
{
HateList::SortedList hateList;
to->getSortedHateList(hateList);
if (hateList.empty())
{
result += Unicode::narrowToWide(fs.sprintf("* NO HATE TARGETS *\n"));
}
else
{
result += Unicode::narrowToWide(fs.sprintf("* HATE LIST *\n"));
HateList::SortedList::const_iterator iterHateList = hateList.begin();
for (; iterHateList != hateList.end(); ++iterHateList)
{
CachedNetworkId const & hateTarget = iterHateList->first;
TangibleObject const * const hateTargetTangibleObject = TangibleObject::asTangibleObject(hateTarget.getObject());
float const hate = iterHateList->second;
std::string hateTargetName;
if (hateTargetTangibleObject != NULL)
{
hateTargetName = Unicode::wideToNarrow(hateTargetTangibleObject->getEncodedObjectName()).c_str();
}
else
{
hateTargetName = "NULL";
}
result += Unicode::narrowToWide(fs.sprintf("%s:%s(%.1f)\n", hateTargetName.c_str(), hateTarget.getValueString().c_str(), hate));
}
}
}
// Hate Over Time List
{
std::map<NetworkId, std::pair<float, std::pair<unsigned long, unsigned long> > > const & hateOverTime = to->getHateOverTime();
if (!hateOverTime.empty())
{
result += Unicode::narrowToWide(fs.sprintf("* HATE OVER TIME LIST currentGameTime=(%lu)*\n", ServerClock::getInstance().getGameTimeSeconds()));
for (std::map<NetworkId, std::pair<float, std::pair<unsigned long, unsigned long> > >::const_iterator iter = hateOverTime.begin(); iter != hateOverTime.end(); ++iter)
{
CachedNetworkId const hateTarget(iter->first);
TangibleObject const * const hateTargetTangibleObject = TangibleObject::asTangibleObject(hateTarget.getObject());
std::string hateTargetName;
if (hateTargetTangibleObject != NULL)
{
hateTargetName = Unicode::wideToNarrow(hateTargetTangibleObject->getEncodedObjectName()).c_str();
}
else
{
hateTargetName = "NULL";
}
result += Unicode::narrowToWide(fs.sprintf("%s:%s (%.2f, %lu, %lu)\n", hateTargetName.c_str(), hateTarget.getValueString().c_str(), iter->second.first, iter->second.second.first, iter->second.second.second));
}
}
}
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
}
}
else if (isAbbrev(argv[0], "kill"))
{
CreatureObject * const userCreatureObject = CreatureObject::getCreatureObject(userId);
if (userCreatureObject == NULL)
{
result += getErrorMessage(argv[0], ERR_FAIL);
}
else
{
CreatureObject * const aiCreatureObject = getAiCreatureObject(*userCreatureObject, argv);
if (aiCreatureObject == NULL)
{
result += getErrorMessage(argv[0], ERR_FAIL);
}
else
{
aiCreatureObject->setIncapacitated(true, NetworkId::cms_invalid);
Chat::sendSystemMessage(*userCreatureObject, Unicode::narrowToWide(fs.sprintf("[SUCCESS] AI %s terminated", aiCreatureObject->getNetworkId().getValueString().c_str())), Unicode::emptyString);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
}
}
else if (isAbbrev(argv[0], "retreat"))
{
CreatureObject * const userCreatureObject = CreatureObject::getCreatureObject(userId);
if (userCreatureObject == NULL)
{
result += getErrorMessage(argv[0], ERR_FAIL);
}
else
{
CreatureObject * const aiCreatureObject = getAiCreatureObject(*userCreatureObject, argv);
if (aiCreatureObject == NULL)
{
result += getErrorMessage(argv[0], ERR_FAIL);
}
else
{
aiCreatureObject->setHateListAutoExpireTargetEnabled(!aiCreatureObject->isHateListAutoExpireTargetEnabled());
Chat::sendSystemMessage(*userCreatureObject, Unicode::narrowToWide(fs.sprintf("[SUCCESS] AI %s %s retreat", aiCreatureObject->getNetworkId().getValueString().c_str(), aiCreatureObject->isHateListAutoExpireTargetEnabled() ? "will now" : "will no longer")), Unicode::emptyString);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
}
}
else if (isAbbrev(argv[0], "walkspeed"))
{
CreatureObject * const userCreatureObject = CreatureObject::getCreatureObject(userId);
if (userCreatureObject == NULL)
{
result += getErrorMessage(argv[0], ERR_FAIL);
}
else
{
NetworkId aiNetworkId;
CreatureObject * aiCreatureObject = NULL;
if (argv.size() > 2)
{
// Get the network id and speed
aiNetworkId = NetworkId(Unicode::wideToNarrow(argv[1]));
aiCreatureObject = CreatureObject::getCreatureObject(aiNetworkId);
if ( (aiCreatureObject != NULL)
&& !aiCreatureObject->isPlayerControlled())
{
aiCreatureObject->setBaseWalkSpeed(Unicode::toFloat(argv[2]));
}
}
else if (argv.size() > 1)
{
// Get the look at target and speed
aiNetworkId = userCreatureObject->getLookAtTarget();
aiCreatureObject = CreatureObject::getCreatureObject(aiNetworkId);
if ( (aiCreatureObject != NULL)
&& !aiCreatureObject->isPlayerControlled())
{
aiCreatureObject->setBaseWalkSpeed(Unicode::toFloat(argv[1]));
}
}
if ( (aiCreatureObject == NULL)
|| aiCreatureObject->isPlayerControlled())
{
Chat::sendSystemMessage(*userCreatureObject, Unicode::narrowToWide(fs.sprintf("[FAILURE] Unable to resolve %s to an AI", aiNetworkId.getValueString().c_str())), Unicode::emptyString);
result += getErrorMessage(argv[0], ERR_FAIL);
}
else
{
Chat::sendSystemMessage(*userCreatureObject, Unicode::narrowToWide(fs.sprintf("[SUCCESS] AI %s has a walk speed of %.1fm/s", aiCreatureObject->getNetworkId().getValueString().c_str(), aiCreatureObject->getBaseWalkSpeed())), Unicode::emptyString);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
}
}
else if (isAbbrev(argv[0], "runspeed"))
{
CreatureObject * const userCreatureObject = CreatureObject::getCreatureObject(userId);
if (userCreatureObject == NULL)
{
result += getErrorMessage(argv[0], ERR_FAIL);
}
else
{
NetworkId aiNetworkId;
CreatureObject * aiCreatureObject = NULL;
if (argv.size() > 2)
{
// Get the network id and speed
aiNetworkId = NetworkId(Unicode::wideToNarrow(argv[1]));
aiCreatureObject = CreatureObject::getCreatureObject(aiNetworkId);
if ( (aiCreatureObject != NULL)
&& !aiCreatureObject->isPlayerControlled())
{
aiCreatureObject->setBaseRunSpeed(Unicode::toFloat(argv[2]));
}
}
else if (argv.size() > 1)
{
// Get the look at target and speed
aiNetworkId = userCreatureObject->getLookAtTarget();
aiCreatureObject = CreatureObject::getCreatureObject(aiNetworkId);
if ( (aiCreatureObject != NULL)
&& !aiCreatureObject->isPlayerControlled())
{
aiCreatureObject->setBaseRunSpeed(Unicode::toFloat(argv[1]));
}
}
if ( (aiCreatureObject == NULL)
|| aiCreatureObject->isPlayerControlled())
{
Chat::sendSystemMessage(*userCreatureObject, Unicode::narrowToWide(fs.sprintf("[FAILURE] Unable to resolve %s to an AI", aiNetworkId.getValueString().c_str())), Unicode::emptyString);
result += getErrorMessage(argv[0], ERR_FAIL);
}
else
{
Chat::sendSystemMessage(*userCreatureObject, Unicode::narrowToWide(fs.sprintf("[SUCCESS] AI %s has a run speed of %.1fm/s", aiCreatureObject->getNetworkId().getValueString().c_str(), aiCreatureObject->getBaseRunSpeed())), Unicode::emptyString);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
}
}
#ifdef _DEBUG
else if (isAbbrev(argv[0], "killall"))
{
CreatureObject * const userCreatureObject = CreatureObject::getCreatureObject(userId);
if (userCreatureObject != NULL)
{
NetworkId sparedAiNetworkId;
// See if we need to spare any single AI
{
if (argv.size() > 1)
{
sparedAiNetworkId = NetworkId(Unicode::wideToNarrow(argv[1]));
}
else
{
sparedAiNetworkId = userCreatureObject->getLookAtTarget();
}
}
// Run through all the AI on the server and kill them
int const serverObjectCount = ServerWorld::getNumObjects();
int killCount = 0;
for (int i = 0; i < serverObjectCount; ++i)
{
ServerObject * const serverObject = ServerWorld::getObject(i);
CreatureObject * const creatureObject = (serverObject != NULL) ? serverObject->asCreatureObject() : NULL;
if ( (creatureObject != NULL)
&& !creatureObject->isDead()
&& !creatureObject->isPlayerControlled()
&& (creatureObject->getNetworkId() != sparedAiNetworkId))
{
creatureObject->setIncapacitated(true, NetworkId::cms_invalid);
++killCount;
}
}
Chat::sendSystemMessage(*userCreatureObject, Unicode::narrowToWide(fs.sprintf("[SUCCESS] %d AI terminated.", killCount)), Unicode::emptyString);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else
{
result += getErrorMessage(argv[0], ERR_FAIL);
}
}
else if (isAbbrev(argv[0], "debug"))
{
Object * const object = NetworkIdManager::getObjectById(userId);
ServerObject * const serverObject = (object != NULL) ? object->asServerObject() : NULL;
int temp;
if (serverObject != NULL)
{
if ( serverObject->getObjVars().getItem("ai_debug_string", temp)
&& (temp > 0))
{
if (!AiShipController::isClientDebugEnabled())
{
AiShipController::setClientDebugEnabled(true);
Chat::sendSystemMessage(*serverObject, Unicode::narrowToWide("[ENABLED] Your client is requesting ai debugging."), Unicode::emptyString);
}
else
{
IGNORE_RETURN(serverObject->setObjVarItem("ai_debug_string", 0));
Chat::sendSystemMessage(*serverObject, Unicode::narrowToWide("[DISABLED] Your client is NO LONGER requesting ai debugging."), Unicode::emptyString);
// Tell the client to remove all ai debugging
Client * const client = serverObject->getClient();
if (client != NULL)
{
AiDebugString aiDebugString;
aiDebugString.enableClearClientFlag();
bool const reliable = true;
GenericValueTypeMessage<std::pair<NetworkId, std::string> > message("AiDebugString", std::make_pair(serverObject->getNetworkId(), aiDebugString.toString()));
client->send(message, reliable);
}
}
}
else
{
IGNORE_RETURN(serverObject->setObjVarItem("ai_debug_string", 1));
Chat::sendSystemMessage(*serverObject, Unicode::narrowToWide("[ENABLED] Your client is requesting ai debugging."), Unicode::emptyString);
if (!AiShipController::isClientDebugEnabled())
{
AiShipController::setClientDebugEnabled(true);
}
}
}
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isAbbrev(argv[0], "debugText"))
{
Object * const object = NetworkIdManager::getObjectById(userId);
ServerObject * const serverObject = (object != NULL) ? object->asServerObject() : NULL;
if (serverObject != NULL)
{
AiDebugString::setTextEnabled(!AiDebugString::isTextEnabled());
Unicode::String systemMessage;
systemMessage = Unicode::narrowToWide(AiDebugString::isTextEnabled() ? "[ENABLED] Client-side debug text is enabled." : "[DISABLED] Client-side debug text is disabled.");
Chat::sendSystemMessage(*serverObject, systemMessage, Unicode::emptyString);
}
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
#endif //_DEBUG
else
{
result += getErrorMessage(argv[0], ERR_NO_HANDLER);
}
return true;
}
// ======================================================================
@@ -0,0 +1,38 @@
// ======================================================================
//
// ConsoleCommandParserAi.h
// Copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserAi_H
#define INCLUDED_ConsoleCommandParserAi_H
#include "sharedCommandParser/CommandParser.h"
#include "sharedFoundation/DynamicVariableList.h"
// ======================================================================
/**
* Commands that are related to objvars
*/
class ConsoleCommandParserAi : public CommandParser
{
public:
ConsoleCommandParserAi();
virtual bool performParsing(const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node);
private:
ConsoleCommandParserAi(const ConsoleCommandParserAi & rhs);
ConsoleCommandParserAi & operator =(const ConsoleCommandParserAi & rhs);
int getArgumentType(const Unicode::NarrowString &arg) const;
void listObjvars(const DynamicVariableList::NestedList &objvarList, String_t &result, int tabCount, bool withPackingData);
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserAi_H
@@ -0,0 +1,643 @@
// ======================================================================
//
// ConsoleCommandParserCity.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ConsoleCommandParserCity.h"
#include "UnicodeUtils.h"
#include "serverGame/CitizenInfo.h"
#include "serverGame/CityInfo.h"
#include "serverGame/CityInterface.h"
#include "serverGame/CityStructureInfo.h"
#include "serverGame/GameServer.h"
#include "sharedFoundation/CalendarTime.h"
#include "sharedFoundation/FormattedString.h"
#include "sharedFoundation/NetworkId.h"
#include "sharedGame/PvpData.h"
// ======================================================================
namespace ConsoleCommandParserCityNamespace
{
std::string const getCityPermissionsText(int permissions);
std::string const getStructureTypeText(int type);
std::string const getFactionString(uint32 factionId);
}
using namespace ConsoleCommandParserCityNamespace;
static const CommandParser::CmdInfo cmds[] =
{
{"listById", 0, "", "List all cities by city id."},
{"listByName", 0, "", "List all cities by city name."},
{"listByRank", 0, "", "List all cities by city rank."},
{"listByPlanet", 0, "", "List all cities by planet."},
{"listByCitizenCount", 0, "", "List all cities by citizen count."},
{"listByStructureCount", 0, "", "List all cities by structure count."},
{"listByCreationTime", 0, "", "List all cities by city creation time."},
{"listCitiesWithIllegalShuttleport", 0, "", "List all cities that are not rank 4 or 5 that have a shuttleport."},
{"showCityGcwRegionDefender", 0, "", "Display GCW region defender data for cities."},
{"showCityDetails", 1, "<city id>", "Display city details for a city."},
{"setCityCreationTime", 7, "<city id> <yyyy> <mm> <dd> <h> <m> <s>", "Sets a city's creation time."},
#ifdef _DEBUG
{"showCityRetroactiveCreationTime", 2, "<city id> <cluster>", "Show the retroactive city creation time for the specified city on the specified cluster."},
#else
{"showCityRetroactiveCreationTime", 1, "<city id>", "Show the retroactive city creation time for the specified city."},
#endif
{"", 0, "", ""} // this must be last
};
//-----------------------------------------------------------------
ConsoleCommandParserCity::ConsoleCommandParserCity (void) :
CommandParser ("city", 0, "...", "City related commands.", 0)
{
createDelegateCommands (cmds);
}
//-----------------------------------------------------------------
bool ConsoleCommandParserCity::performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node)
{
NOT_NULL (node);
UNREF (userId);
UNREF(originalCommand);
//-----------------------------------------------------------------
if (isCommand(argv [0], "listById"))
{
std::map<int, CityInfo> const & allCities = CityInterface::getAllCityInfo();
std::multimap<int, std::string> cityInfo;
for (std::map<int, CityInfo>::const_iterator iter = allCities.begin(); iter != allCities.end(); ++iter)
{
CityInfo const & ci = iter->second;
if (ci.getCityName().empty())
continue;
CitizenInfo const * const mayor = CityInterface::getCitizenInfo(iter->first, ci.getLeaderId());
cityInfo.insert(std::make_pair(iter->first, std::string(FormattedString<2048>().sprintf("%d, %s, %s (%s), %s, %s (%d, %d), %dm, %lu (%s), %d, %d, %d (%s)\n", iter->first, ci.getCityName().c_str(), ci.getLeaderId().getValueString().c_str(), (mayor ? mayor->m_citizenName.c_str() : ""), ci.getCityHallId().getValueString().c_str(), ci.getPlanet().c_str(), ci.getX(), ci.getZ(), ci.getRadius(), ci.getFaction(), getFactionString(ci.getFaction()).c_str(), ci.getCitizenCount(), ci.getStructureCount(), ci.getCreationTime(), ((ci.getCreationTime() > 0) ? CalendarTime::convertEpochToTimeStringLocal(ci.getCreationTime()).c_str() : "N/A")))));
}
for (std::multimap<int, std::string>::const_iterator iter2 = cityInfo.begin(); iter2 != cityInfo.end(); ++iter2)
result += Unicode::narrowToWide(iter2->second);
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("%d cities listed\n", cityInfo.size()));
if (!cityInfo.empty())
result += Unicode::narrowToWide("Output format is: \"id, name, mayor, cityHallId, location, radius, faction, number of citizens, number of structures, creationTime\"\n");
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isCommand(argv [0], "listByName"))
{
std::map<int, CityInfo> const & allCities = CityInterface::getAllCityInfo();
std::multimap<std::string, std::string> cityInfo;
for (std::map<int, CityInfo>::const_iterator iter = allCities.begin(); iter != allCities.end(); ++iter)
{
CityInfo const & ci = iter->second;
if (ci.getCityName().empty())
continue;
CitizenInfo const * const mayor = CityInterface::getCitizenInfo(iter->first, ci.getLeaderId());
cityInfo.insert(std::make_pair(ci.getCityName(), std::string(FormattedString<2048>().sprintf("%d, %s, %s (%s), %s, %s (%d, %d), %dm, %lu (%s), %d, %d, %d (%s)\n", iter->first, ci.getCityName().c_str(), ci.getLeaderId().getValueString().c_str(), (mayor ? mayor->m_citizenName.c_str() : ""), ci.getCityHallId().getValueString().c_str(), ci.getPlanet().c_str(), ci.getX(), ci.getZ(), ci.getRadius(), ci.getFaction(), getFactionString(ci.getFaction()).c_str(), ci.getCitizenCount(), ci.getStructureCount(), ci.getCreationTime(), ((ci.getCreationTime() > 0) ? CalendarTime::convertEpochToTimeStringLocal(ci.getCreationTime()).c_str() : "N/A")))));
}
for (std::multimap<std::string, std::string>::const_iterator iter2 = cityInfo.begin(); iter2 != cityInfo.end(); ++iter2)
result += Unicode::narrowToWide(iter2->second);
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("%d cities listed\n", cityInfo.size()));
if (!cityInfo.empty())
result += Unicode::narrowToWide("Output format is: \"id, name, mayor, cityHallId, location, radius, faction, number of citizens, number of structures, creationTime\"\n");
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isCommand(argv [0], "listByRank"))
{
std::map<int, CityInfo> const & allCities = CityInterface::getAllCityInfo();
std::multimap<int, std::string> cityInfo;
for (std::map<int, CityInfo>::const_iterator iter = allCities.begin(); iter != allCities.end(); ++iter)
{
CityInfo const & ci = iter->second;
if (ci.getCityName().empty())
continue;
CitizenInfo const * const mayor = CityInterface::getCitizenInfo(iter->first, ci.getLeaderId());
cityInfo.insert(std::make_pair(-ci.getRadius(), std::string(FormattedString<2048>().sprintf("%d, %s, %s (%s), %s, %s (%d, %d), %dm, %lu (%s), %d, %d, %d (%s)\n", iter->first, ci.getCityName().c_str(), ci.getLeaderId().getValueString().c_str(), (mayor ? mayor->m_citizenName.c_str() : ""), ci.getCityHallId().getValueString().c_str(), ci.getPlanet().c_str(), ci.getX(), ci.getZ(), ci.getRadius(), ci.getFaction(), getFactionString(ci.getFaction()).c_str(), ci.getCitizenCount(), ci.getStructureCount(), ci.getCreationTime(), ((ci.getCreationTime() > 0) ? CalendarTime::convertEpochToTimeStringLocal(ci.getCreationTime()).c_str() : "N/A")))));
}
for (std::multimap<int, std::string>::const_iterator iter2 = cityInfo.begin(); iter2 != cityInfo.end(); ++iter2)
result += Unicode::narrowToWide(iter2->second);
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("%d cities listed\n", cityInfo.size()));
if (!cityInfo.empty())
result += Unicode::narrowToWide("Output format is: \"id, name, mayor, cityHallId, location, radius, faction, number of citizens, number of structures, creationTime\"\n");
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isCommand(argv [0], "listByPlanet"))
{
std::map<int, CityInfo> const & allCities = CityInterface::getAllCityInfo();
std::multimap<std::string, std::string> cityInfo;
for (std::map<int, CityInfo>::const_iterator iter = allCities.begin(); iter != allCities.end(); ++iter)
{
CityInfo const & ci = iter->second;
if (ci.getCityName().empty())
continue;
CitizenInfo const * const mayor = CityInterface::getCitizenInfo(iter->first, ci.getLeaderId());
cityInfo.insert(std::make_pair(ci.getPlanet(), std::string(FormattedString<2048>().sprintf("%d, %s, %s (%s), %s, %s (%d, %d), %dm, %lu (%s), %d, %d, %d (%s)\n", iter->first, ci.getCityName().c_str(), ci.getLeaderId().getValueString().c_str(), (mayor ? mayor->m_citizenName.c_str() : ""), ci.getCityHallId().getValueString().c_str(), ci.getPlanet().c_str(), ci.getX(), ci.getZ(), ci.getRadius(), ci.getFaction(), getFactionString(ci.getFaction()).c_str(), ci.getCitizenCount(), ci.getStructureCount(), ci.getCreationTime(), ((ci.getCreationTime() > 0) ? CalendarTime::convertEpochToTimeStringLocal(ci.getCreationTime()).c_str() : "N/A")))));
}
for (std::multimap<std::string, std::string>::const_iterator iter2 = cityInfo.begin(); iter2 != cityInfo.end(); ++iter2)
result += Unicode::narrowToWide(iter2->second);
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("%d cities listed\n", cityInfo.size()));
if (!cityInfo.empty())
result += Unicode::narrowToWide("Output format is: \"id, name, mayor, cityHallId, location, radius, faction, number of citizens, number of structures, creationTime\"\n");
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isCommand(argv [0], "listByCitizenCount"))
{
std::map<int, CityInfo> const & allCities = CityInterface::getAllCityInfo();
std::multimap<int, std::string> cityInfo;
for (std::map<int, CityInfo>::const_iterator iter = allCities.begin(); iter != allCities.end(); ++iter)
{
CityInfo const & ci = iter->second;
if (ci.getCityName().empty())
continue;
CitizenInfo const * const mayor = CityInterface::getCitizenInfo(iter->first, ci.getLeaderId());
cityInfo.insert(std::make_pair(-ci.getCitizenCount(), std::string(FormattedString<2048>().sprintf("%d, %s, %s (%s), %s, %s (%d, %d), %dm, %lu (%s), %d, %d, %d (%s)\n", iter->first, ci.getCityName().c_str(), ci.getLeaderId().getValueString().c_str(), (mayor ? mayor->m_citizenName.c_str() : ""), ci.getCityHallId().getValueString().c_str(), ci.getPlanet().c_str(), ci.getX(), ci.getZ(), ci.getRadius(), ci.getFaction(), getFactionString(ci.getFaction()).c_str(), ci.getCitizenCount(), ci.getStructureCount(), ci.getCreationTime(), ((ci.getCreationTime() > 0) ? CalendarTime::convertEpochToTimeStringLocal(ci.getCreationTime()).c_str() : "N/A")))));
}
for (std::multimap<int, std::string>::const_iterator iter2 = cityInfo.begin(); iter2 != cityInfo.end(); ++iter2)
result += Unicode::narrowToWide(iter2->second);
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("%d cities listed\n", cityInfo.size()));
if (!cityInfo.empty())
result += Unicode::narrowToWide("Output format is: \"id, name, mayor, cityHallId, location, radius, faction, number of citizens, number of structures, creationTime\"\n");
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isCommand(argv [0], "listByStructureCount"))
{
std::map<int, CityInfo> const & allCities = CityInterface::getAllCityInfo();
std::multimap<int, std::string> cityInfo;
for (std::map<int, CityInfo>::const_iterator iter = allCities.begin(); iter != allCities.end(); ++iter)
{
CityInfo const & ci = iter->second;
if (ci.getCityName().empty())
continue;
CitizenInfo const * const mayor = CityInterface::getCitizenInfo(iter->first, ci.getLeaderId());
cityInfo.insert(std::make_pair(-ci.getStructureCount(), std::string(FormattedString<2048>().sprintf("%d, %s, %s (%s), %s, %s (%d, %d), %dm, %lu (%s), %d, %d, %d (%s)\n", iter->first, ci.getCityName().c_str(), ci.getLeaderId().getValueString().c_str(), (mayor ? mayor->m_citizenName.c_str() : ""), ci.getCityHallId().getValueString().c_str(), ci.getPlanet().c_str(), ci.getX(), ci.getZ(), ci.getRadius(), ci.getFaction(), getFactionString(ci.getFaction()).c_str(), ci.getCitizenCount(), ci.getStructureCount(), ci.getCreationTime(), ((ci.getCreationTime() > 0) ? CalendarTime::convertEpochToTimeStringLocal(ci.getCreationTime()).c_str() : "N/A")))));
}
for (std::multimap<int, std::string>::const_iterator iter2 = cityInfo.begin(); iter2 != cityInfo.end(); ++iter2)
result += Unicode::narrowToWide(iter2->second);
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("%d cities listed\n", cityInfo.size()));
if (!cityInfo.empty())
result += Unicode::narrowToWide("Output format is: \"id, name, mayor, cityHallId, location, radius, faction, number of citizens, number of structures, creationTime\"\n");
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isCommand(argv [0], "listByCreationTime"))
{
std::map<int, CityInfo> const & allCities = CityInterface::getAllCityInfo();
std::multimap<int, std::string> cityInfo;
for (std::map<int, CityInfo>::const_iterator iter = allCities.begin(); iter != allCities.end(); ++iter)
{
CityInfo const & ci = iter->second;
if (ci.getCityName().empty())
continue;
CitizenInfo const * const mayor = CityInterface::getCitizenInfo(iter->first, ci.getLeaderId());
cityInfo.insert(std::make_pair(ci.getCreationTime(), std::string(FormattedString<2048>().sprintf("%d, %s, %s (%s), %s, %s (%d, %d), %dm, %lu (%s), %d, %d, %d (%s)\n", iter->first, ci.getCityName().c_str(), ci.getLeaderId().getValueString().c_str(), (mayor ? mayor->m_citizenName.c_str() : ""), ci.getCityHallId().getValueString().c_str(), ci.getPlanet().c_str(), ci.getX(), ci.getZ(), ci.getRadius(), ci.getFaction(), getFactionString(ci.getFaction()).c_str(), ci.getCitizenCount(), ci.getStructureCount(), ci.getCreationTime(), ((ci.getCreationTime() > 0) ? CalendarTime::convertEpochToTimeStringLocal(ci.getCreationTime()).c_str() : "N/A")))));
}
for (std::multimap<int, std::string>::const_iterator iter2 = cityInfo.begin(); iter2 != cityInfo.end(); ++iter2)
result += Unicode::narrowToWide(iter2->second);
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("%d cities listed\n", cityInfo.size()));
if (!cityInfo.empty())
result += Unicode::narrowToWide("Output format is: \"id, name, mayor, cityHallId, location, radius, faction, number of citizens, number of structures, creationTime\"\n");
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isCommand(argv [0], "listCitiesWithIllegalShuttleport"))
{
std::map<int, CityInfo> const & allCities = CityInterface::getAllCityInfo();
std::multimap<int, std::string> cityInfo;
for (std::map<int, CityInfo>::const_iterator iter = allCities.begin(); iter != allCities.end(); ++iter)
{
CityInfo const & ci = iter->second;
if (ci.getCityName().empty())
continue;
if (ci.getRadius() >= 400)
continue;
if (ci.getTravelCost() > 0)
{
CitizenInfo const * const mayor = CityInterface::getCitizenInfo(iter->first, ci.getLeaderId());
cityInfo.insert(std::make_pair(iter->first, std::string(FormattedString<2048>().sprintf("%d, %s, %s (%s), %s, %s (%d, %d), %dm, %lu (%s), %d, %d, %d (%s)\n", iter->first, ci.getCityName().c_str(), ci.getLeaderId().getValueString().c_str(), (mayor ? mayor->m_citizenName.c_str() : ""), ci.getCityHallId().getValueString().c_str(), ci.getPlanet().c_str(), ci.getX(), ci.getZ(), ci.getRadius(), ci.getFaction(), getFactionString(ci.getFaction()).c_str(), ci.getCitizenCount(), ci.getStructureCount(), ci.getCreationTime(), ((ci.getCreationTime() > 0) ? CalendarTime::convertEpochToTimeStringLocal(ci.getCreationTime()).c_str() : "N/A")))));
}
}
for (std::multimap<int, std::string>::const_iterator iter2 = cityInfo.begin(); iter2 != cityInfo.end(); ++iter2)
result += Unicode::narrowToWide(iter2->second);
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("%d cities with illegal shuttleport listed\n", cityInfo.size()));
if (!cityInfo.empty())
result += Unicode::narrowToWide("Output format is: \"id, name, mayor, cityHallId, location, radius, faction, number of citizens, number of structures, creationTime\"\n");
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isCommand(argv [0], "showCityGcwRegionDefender"))
{
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("Version (%d)\n\n", CityInterface::getGcwRegionDefenderCitiesVersion()));
std::map<std::pair<std::string, int>, uint32> const & gcwRegionDefenderCities = CityInterface::getGcwRegionDefenderCities();
for (std::map<std::pair<std::string, int>, uint32>::const_iterator iterCity = gcwRegionDefenderCities.begin(); iterCity != gcwRegionDefenderCities.end(); ++iterCity)
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("(%s) (%d, %s) (%lu) (%s)\n", iterCity->first.first.c_str(), iterCity->first.second, CityInterface::getCityInfo(iterCity->first.second).getCityName().c_str(), iterCity->second, getFactionString(iterCity->second).c_str()));
result += Unicode::narrowToWide("\n");
std::map<std::string, std::pair<int, int> > const & gcwRegionDefenderCitiesCount = CityInterface::getGcwRegionDefenderCitiesCount();
for (std::map<std::string, std::pair<int, int> >::const_iterator iterCount = gcwRegionDefenderCitiesCount.begin(); iterCount != gcwRegionDefenderCitiesCount.end(); ++iterCount)
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("(%s) (Imperial=%d) (Rebel=%d)\n", iterCount->first.c_str(), iterCount->second.first, iterCount->second.second));
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isCommand(argv [0], "showCityDetails"))
{
int const cityId = atoi(Unicode::wideToNarrow(argv[1]).c_str());
CityInfo const & ci = CityInterface::getCityInfo(cityId);
if (ci.getCityName().empty())
{
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("no city with city id %d\n", cityId));
result += getErrorMessage(argv[0], ERR_FAIL);
}
else
{
// id
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("id: %d\n", cityId));
// name
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("name: %s\n", ci.getCityName().c_str()));
// mayor
CitizenInfo const * const mayor = CityInterface::getCitizenInfo(cityId, ci.getLeaderId());
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("mayor: %s (%s)\n", ci.getLeaderId().getValueString().c_str(), (mayor ? mayor->m_citizenName.c_str() : "")));
// cityHallId
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("city hall id: %s\n", ci.getCityHallId().getValueString().c_str()));
// location
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("location: %s (%d, %d)\n", ci.getPlanet().c_str(), ci.getX(), ci.getZ()));
// radius
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("radius: %dm\n", ci.getRadius()));
// faction
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("faction: %lu (%s)\n", ci.getFaction(), getFactionString(ci.getFaction()).c_str()));
// GCW region defender
if (ci.getGcwDefenderRegion().empty())
result += Unicode::narrowToWide("GCW defender region: (NONE)\n");
else
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("GCW defender region: %s [joined at %d (%s)]\n", ci.getGcwDefenderRegion().c_str(), ci.getTimeJoinedGcwDefenderRegion(), CalendarTime::convertEpochToTimeStringLocal(static_cast<time_t>(ci.getTimeJoinedGcwDefenderRegion())).c_str()));
// creationTime
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("creation time: %d (%s)\n", ci.getCreationTime(), ((ci.getCreationTime() > 0) ? CalendarTime::convertEpochToTimeStringLocal(ci.getCreationTime()).c_str() : "N/A")));
// taxes
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("taxes: income %d, property %d, sales %d\n", ci.getIncomeTax(), ci.getPropertyTax(), ci.getSalesTax()));
// travel
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("travel: location (%.2f, %.2f, %.2f), cost %d, interplanetary %s\n", ci.getTravelLoc().x, ci.getTravelLoc().y, ci.getTravelLoc().z, ci.getTravelCost(), (ci.getTravelInterplanetary() ? "yes" : "no")));
// clone
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("clone: cloner id %s, cloner location (%.2f, %.2f, %.2f), clone respawn location (%.2f, %.2f, %.2f), clone respawn cell %s\n", ci.getCloneId().getValueString().c_str(), ci.getCloneLoc().x, ci.getCloneLoc().y, ci.getCloneLoc().z, ci.getCloneRespawn().x, ci.getCloneRespawn().y, ci.getCloneRespawn().z, ci.getCloneRespawnCell().getValueString().c_str()));
// citizens
result += Unicode::narrowToWide("\nCitizens:\n");
std::map<std::pair<int, NetworkId>, CitizenInfo> const & allCitizens = CityInterface::getAllCitizensInfo();
std::string citizenRankInfo;
int citizenCount = 0;
for (std::map<std::pair<int, NetworkId>, CitizenInfo>::const_iterator iterCitizen = allCitizens.lower_bound(std::make_pair(cityId, NetworkId::cms_invalid)); iterCitizen != allCitizens.end(); ++iterCitizen)
{
if (iterCitizen->first.first != cityId)
break;
++citizenCount;
// citizen rank
iterCitizen->second.m_citizenRank.getAsDbTextString(citizenRankInfo);
citizenRankInfo += " (";
std::vector<std::string> ranks;
CityInterface::getCitizenRank(cityId, iterCitizen->first.second, ranks);
for (std::vector<std::string>::const_iterator iterRank = ranks.begin(); iterRank != ranks.end(); ++iterRank)
{
if (iterRank != ranks.begin())
citizenRankInfo += ", ";
citizenRankInfo += *iterRank;
}
citizenRankInfo += ")";
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("%s, %s, %s, %d, %d (%s), %s, %s, %s\n", iterCitizen->first.second.getValueString().c_str(), iterCitizen->second.m_citizenName.c_str(), iterCitizen->second.m_citizenProfessionSkillTemplate.c_str(), iterCitizen->second.m_citizenLevel, iterCitizen->second.m_citizenPermissions, getCityPermissionsText(iterCitizen->second.m_citizenPermissions).c_str(), citizenRankInfo.c_str(), iterCitizen->second.m_citizenTitle.c_str(), iterCitizen->second.m_citizenAllegiance.getValueString().c_str()));
}
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("%d citizens listed\n", citizenCount));
if (citizenCount > 0)
result += Unicode::narrowToWide("Output format is: \"id, name, profession, level, permissions, rank, title, allegiance\"\n");
// structures
result += Unicode::narrowToWide("\nStructures:\n");
std::map<std::pair<int, NetworkId>, CityStructureInfo> const & allStructures = CityInterface::getAllCityStructuresInfo();
int structureCount = 0;
for (std::map<std::pair<int, NetworkId>, CityStructureInfo>::const_iterator iterStructure = allStructures.lower_bound(std::make_pair(cityId, NetworkId::cms_invalid)); iterStructure != allStructures.end(); ++iterStructure)
{
if (iterStructure->first.first != cityId)
break;
++structureCount;
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("%s, %s, %d (%s)\n", iterStructure->first.second.getValueString().c_str(), (iterStructure->second.getStructureValid() ? "valid" : "no valid"), iterStructure->second.getStructureType(), getStructureTypeText(iterStructure->second.getStructureType()).c_str()));
}
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("%d structures listed\n", structureCount));
if (structureCount > 0)
result += Unicode::narrowToWide("Output format is: \"id, valid, type\"\n");
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
}
else if (isCommand(argv [0], "setCityCreationTime"))
{
int const cityId = atoi(Unicode::wideToNarrow(argv[1]).c_str());
CityInfo const & ci = CityInterface::getCityInfo(cityId);
if (ci.getCityName().empty())
{
result += Unicode::narrowToWide(FormattedString<2048>().sprintf("no city with city id %d\n", cityId));
result += getErrorMessage(argv[0], ERR_FAIL);
}
else
{
time_t const rawtime = ::time(NULL);
struct tm * timeinfo = ::localtime(&rawtime);
timeinfo->tm_year = atoi(Unicode::wideToNarrow(argv[2]).c_str()) - 1900;
timeinfo->tm_mon = atoi(Unicode::wideToNarrow(argv[3]).c_str()) - 1;
timeinfo->tm_mday = atoi(Unicode::wideToNarrow(argv[4]).c_str());
timeinfo->tm_hour = atoi(Unicode::wideToNarrow(argv[5]).c_str());
timeinfo->tm_min = atoi(Unicode::wideToNarrow(argv[6]).c_str());
timeinfo->tm_sec = atoi(Unicode::wideToNarrow(argv[7]).c_str());
time_t const specifiedTime = ::mktime(timeinfo);
if (specifiedTime <= 0)
{
result += Unicode::narrowToWide("specified time is invalid\n");
result += getErrorMessage(argv[0], ERR_FAIL);
}
else
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("setting city creation time for city %d (%s):\n", cityId, ci.getCityName().c_str()));
if (ci.getCreationTime() <= 0)
result += Unicode::narrowToWide(FormattedString<512>().sprintf("***FROM*** %d (N/A)\n", ci.getCreationTime()));
else
result += Unicode::narrowToWide(FormattedString<512>().sprintf("***FROM*** %d (%s, %s)\n", ci.getCreationTime(), CalendarTime::convertEpochToTimeStringLocal(ci.getCreationTime()).c_str(), CalendarTime::convertEpochToTimeStringGMT(ci.getCreationTime()).c_str()));
result += Unicode::narrowToWide(FormattedString<512>().sprintf("****TO**** %ld (%s, %s)\n", static_cast<long>(specifiedTime), CalendarTime::convertEpochToTimeStringLocal(specifiedTime).c_str(), CalendarTime::convertEpochToTimeStringGMT(specifiedTime).c_str()));
CityInterface::setCityCreationTime(cityId, static_cast<int>(specifiedTime));
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
}
}
else if (isCommand(argv [0], "showCityRetroactiveCreationTime"))
{
int const cityId = atoi(Unicode::wideToNarrow(argv[1]).c_str());
#ifdef _DEBUG
std::string const clusterName = Unicode::wideToNarrow(argv[2]);
#else
std::string const clusterName = GameServer::getInstance().getClusterName();
#endif
time_t const retroactiveCreationTime = GameServer::getRetroactivePlayerCityCreationTime(clusterName, cityId);
if (retroactiveCreationTime <= 0)
result += Unicode::narrowToWide(FormattedString<512>().sprintf("no retroactive creation time for player city (%s, %d)\n", clusterName.c_str(), cityId));
else
result += Unicode::narrowToWide(FormattedString<512>().sprintf("retroactive creation time for player city (%s, %d) is %ld, %s\n", clusterName.c_str(), cityId, retroactiveCreationTime, CalendarTime::convertEpochToTimeStringLocal(retroactiveCreationTime).c_str()));
}
return true;
} // ConsoleCommandParserCity::performParsing
// ----------------------------------------------------------------------
std::string const ConsoleCommandParserCityNamespace::getCityPermissionsText(int permissions)
{
std::string result;
if (permissions == static_cast<int>(CitizenPermissions::Citizen))
{
result = "Citizen";
}
else
{
if (permissions & static_cast<int>(CitizenPermissions::Militia))
result += "Militia ";
if (permissions & static_cast<int>(CitizenPermissions::AbsentWeek1))
result += "AbsentWeek1 ";
if (permissions & static_cast<int>(CitizenPermissions::AbsentWeek2))
result += "AbsentWeek2 ";
if (permissions & static_cast<int>(CitizenPermissions::AbsentWeek3))
result += "AbsentWeek3 ";
if (permissions & static_cast<int>(CitizenPermissions::AbsentWeek4))
result += "AbsentWeek4 ";
if (permissions & static_cast<int>(CitizenPermissions::AbsentWeek5))
result += "AbsentWeek5 ";
if (permissions & static_cast<int>(CitizenPermissions::InactiveProtected))
result += "InactiveProtected ";
}
return result;
}
// ----------------------------------------------------------------------
std::string const ConsoleCommandParserCityNamespace::getStructureTypeText(int type)
{
// from city.scriptlib
// Structure Flags
static const int SF_PM_REGISTER = 1;
static const int SF_COST_CITY_HALL = 2; // 5000 (datatable entry 1)
static const int SF_COST_CITY_HI = 4; // 1000
static const int SF_COST_CITY_MED = 8; // 500
static const int SF_COST_CITY_LOW = 16; // 250 (datatable entry 4)
static const int SF_MISSION_TERMINAL = 32;
static const int SF_SKILL_TRAINER = 64;
static const int SF_DECORATION = 128;
// BEGIN: City Hall ONLY flags.
// Must be synchronized with datatables/city/specializations.iff
static const int SF_SPEC_SAMPLE_RICH = 256; /*Sample Rich*/
static const int SF_SPEC_FARMING = 512; /*removed*/
static const int SF_SPEC_INDUSTRY = 1024; /*Manufacturing Center*/
static const int SF_SPEC_RESEARCH = 2048; /*Research Center*/
static const int SF_SPEC_CLONING = 4096; /*Clone Lab*/
static const int SF_SPEC_MISSIONS = 8192; /*Improved Job Market*/
static const int SF_SPEC_ENTERTAINER = 16384; /*Entertainment Districtu*/
static const int SF_SPEC_DOCTOR = 32768; /*removed*/
static const int SF_SPEC_STRONGHOLD = 65536; /*removed*/
static const int SF_SPEC_MASTER_MANUFACTURING = 131072; /*removed*/
static const int SF_SPEC_MASTER_HEALING = 262144; /*removed*/
static const int SF_SPEC_DECOR_INCREASE = 524288; /*Outdoor Enhancements*/
static const int SF_SPEC_STORYTELLER = 1048576; /*Encore Performance*/
static const int SF_SPEC_INCUBATOR = 2097152; /*incubation-BMs*/
static const int SF_SPEC_UNKNOWN_6 = 4194304;
static const int SF_REQUIRE_ZONE_RIGHTS = 8388608;
// END: City Hall ONLY flags.
static const int SF_COST_CITY_GARDEN_SMALL = 16777216;
static const int SF_COST_CITY_GARDEN_LARGE = 33554432;
std::string result;
if (type & SF_PM_REGISTER)
result += "SF_PM_REGISTER ";
if (type & SF_COST_CITY_HALL)
result += "SF_COST_CITY_HALL ";
if (type & SF_COST_CITY_HI)
result += "SF_COST_CITY_HI ";
if (type & SF_COST_CITY_MED)
result += "SF_COST_CITY_MED ";
if (type & SF_COST_CITY_LOW)
result += "SF_COST_CITY_LOW ";
if (type & SF_MISSION_TERMINAL)
result += "SF_MISSION_TERMINAL ";
if (type & SF_SKILL_TRAINER)
result += "SF_SKILL_TRAINER ";
if (type & SF_DECORATION)
result += "SF_DECORATION ";
if (type & SF_SPEC_SAMPLE_RICH)
result += "SF_SPEC_SAMPLE_RICH ";
if (type & SF_SPEC_FARMING)
result += "SF_SPEC_FARMING ";
if (type & SF_SPEC_INDUSTRY)
result += "SF_SPEC_INDUSTRY ";
if (type & SF_SPEC_RESEARCH)
result += "SF_SPEC_RESEARCH ";
if (type & SF_SPEC_CLONING)
result += "SF_SPEC_CLONING ";
if (type & SF_SPEC_MISSIONS)
result += "SF_SPEC_MISSIONS ";
if (type & SF_SPEC_ENTERTAINER)
result += "SF_SPEC_ENTERTAINER ";
if (type & SF_SPEC_DOCTOR)
result += "SF_SPEC_DOCTOR ";
if (type & SF_SPEC_STRONGHOLD)
result += "SF_SPEC_STRONGHOLD ";
if (type & SF_SPEC_MASTER_MANUFACTURING)
result += "SF_SPEC_MASTER_MANUFACTURING ";
if (type & SF_SPEC_MASTER_HEALING)
result += "SF_SPEC_MASTER_HEALING ";
if (type & SF_SPEC_DECOR_INCREASE)
result += "SF_SPEC_DECOR_INCREASE ";
if (type & SF_SPEC_STORYTELLER)
result += "SF_SPEC_STORYTELLER ";
if (type & SF_SPEC_INCUBATOR)
result += "SF_SPEC_INCUBATOR ";
if (type & SF_SPEC_UNKNOWN_6)
result += "SF_SPEC_UNKNOWN_6 ";
if (type & SF_REQUIRE_ZONE_RIGHTS)
result += "SF_REQUIRE_ZONE_RIGHTS ";
if (type & SF_COST_CITY_GARDEN_SMALL)
result += "SF_COST_CITY_GARDEN_SMALL ";
if (type & SF_COST_CITY_GARDEN_LARGE)
result += "SF_COST_CITY_GARDEN_LARGE ";
return result;
}
// ----------------------------------------------------------------------
std::string const ConsoleCommandParserCityNamespace::getFactionString(uint32 factionId)
{
if (PvpData::isNeutralFactionId(factionId))
return "Neutral";
else if (PvpData::isImperialFactionId(factionId))
return "Imperial";
else if (PvpData::isRebelFactionId(factionId))
return "Rebel";
return "Unknown";
}
// ======================================================================
@@ -0,0 +1,32 @@
// ======================================================================
//
// ConsoleCommandParserCity.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserCity_H
#define INCLUDED_ConsoleCommandParserCity_H
#include "sharedCommandParser/CommandParser.h"
// ======================================================================
/**
* Commands that are related to the city system.
*/
class ConsoleCommandParserCity : public CommandParser
{
public:
ConsoleCommandParserCity ();
virtual bool performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node);
private:
ConsoleCommandParserCity (const ConsoleCommandParserCity & rhs);
ConsoleCommandParserCity & operator= (const ConsoleCommandParserCity & rhs);
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserCity_H
@@ -0,0 +1,885 @@
// ======================================================================
//
// ConsoleCommandParserCollection.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ConsoleCommandParserCollection.h"
#include "UnicodeUtils.h"
#include "serverGame/CreatureObject.h"
#include "serverGame/MessageToQueue.h"
#include "serverGame/PlanetObject.h"
#include "serverGame/PlayerCreatureController.h"
#include "serverGame/PlayerObject.h"
#include "serverGame/ServerObject.h"
#include "serverGame/ServerUniverse.h"
#include "serverGame/ServerWorld.h"
#include "sharedFoundation/CalendarTime.h"
#include "sharedFoundation/FormattedString.h"
#include "sharedFoundation/NetworkId.h"
// ======================================================================
static const CommandParser::CmdInfo cmds[] =
{
{"adjustSlotValue", 3, "<oid> <slot name> <adjustment>", "Modify the value of a collection slot by the specified adjustment value"},
{"grantAllSlotsForCollection", 2, "<oid> <collection name>", "Mark all the collection slots in the specified collection as completed"},
{"grantAllSlotsForPage", 2, "<oid> <page name>", "Mark all the collection slots in the specified page as completed"},
{"grantAllSlotsForBook", 2, "<oid> <book name>", "Mark all the collection slots in the specified book as completed"},
{"revokeAllSlotsForCollection", 2, "<oid> <collection name>", "Mark all the collection slots in the specified collection as not completed"},
{"revokeAllSlotsForPage", 2, "<oid> <page name>", "Mark all the collection slots in the specified page as not completed"},
{"revokeAllSlotsForBook", 2, "<oid> <book name>", "Mark all the collection slots in the specified book as not completed"},
{"displayCollections", 1, "<oid>", "Display collections for specified character"},
{"displayServerFirst", 0, "", "Display collections \"server first\" information"},
{"addServerFirst", 2, "<oid> <collection name>", "Make the specified character \"server first\" for the collection"},
{"setServerFirstTime", 7, "<collection name> <yyyy> <mm> <dd> <h> <m> <s>", "Set the \"server first\" completion time for the collection"},
{"removeServerFirst", 1, "<collection name>", "Remove \"server first\" for the collection"},
{"", 0, "", ""} // this must be last
};
//-----------------------------------------------------------------
ConsoleCommandParserCollection::ConsoleCommandParserCollection (void) :
CommandParser ("collection", 0, "...", "Collection related commands.", 0)
{
createDelegateCommands (cmds);
}
//-----------------------------------------------------------------
bool ConsoleCommandParserCollection::performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node)
{
NOT_NULL (node);
UNREF (userId);
UNREF(originalCommand);
// ----------------------------------------------------------------------
if (isCommand (argv [0], "adjustSlotValue"))
{
NetworkId oid(Unicode::wideToNarrow(argv[1]));
ServerObject * o = dynamic_cast<ServerObject *>(ServerWorld::findObjectByNetworkId(oid));
if (o == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
CreatureObject * c = o->asCreatureObject();
if (c == NULL)
{
result += Unicode::narrowToWide("specified object is not a creature object\n");
return true;
}
PlayerObject * p = PlayerCreatureController::getPlayerObject(c);
if (p == NULL)
{
result += Unicode::narrowToWide("specified object is not a character object\n");
return true;
}
CollectionsDataTable::CollectionInfoSlot const * slot = CollectionsDataTable::getSlotByName(Unicode::wideToNarrow(argv[2]));
if (!slot)
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%s is not a valid collection slot name\n", Unicode::wideToNarrow(argv[2]).c_str()));
return true;
}
// quickie way to convert to an int64
NetworkId const adjustment(Unicode::wideToNarrow(argv[3]));
// adjustment value of 0 means leave it alone
if (adjustment.getValue() == 0)
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("adjustment value is 0, so will ***NOT*** adjust collection slot %s/%s/%s/%s for character object %s (%s)\n", slot->collection.page.book.name.c_str(), slot->collection.page.name.c_str(), slot->collection.name.c_str(), Unicode::wideToNarrow(argv[2]).c_str(), oid.getValueString().c_str(), Unicode::wideToNarrow(o->getAssignedObjectName()).c_str()));
return true;
}
// bit-type slot
if (!slot->counterTypeSlot)
{
// set bit-type slot
if (adjustment.getValue() > 0)
{
if (p->hasCompletedCollectionSlot(*slot))
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("character object %s (%s) already has collection slot %s/%s/%s/%s\n", oid.getValueString().c_str(), Unicode::wideToNarrow(o->getAssignedObjectName()).c_str(), slot->collection.page.book.name.c_str(), slot->collection.page.name.c_str(), slot->collection.name.c_str(), Unicode::wideToNarrow(argv[2]).c_str()));
return true;
}
std::vector<CollectionsDataTable::CollectionInfoSlot const *> missingPrereqs;
if (!p->hasCompletedCollectionSlotPrereq(Unicode::wideToNarrow(argv[2]), &missingPrereqs))
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("cannot set collection slot %s/%s/%s/%s for character object %s (%s) because the following prerequisite collection slot(s) are not yet completed:\n", slot->collection.page.book.name.c_str(), slot->collection.page.name.c_str(), slot->collection.name.c_str(), Unicode::wideToNarrow(argv[2]).c_str(), oid.getValueString().c_str(), Unicode::wideToNarrow(o->getAssignedObjectName()).c_str()));
for (std::vector<CollectionsDataTable::CollectionInfoSlot const *>::const_iterator iter = missingPrereqs.begin(); iter != missingPrereqs.end(); ++iter)
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%s/%s/%s/%s\n", (*iter)->collection.page.book.name.c_str(), (*iter)->collection.page.name.c_str(), (*iter)->collection.name.c_str(), (*iter)->name.c_str()));
return true;
}
result += Unicode::narrowToWide(FormattedString<512>().sprintf("setting collection slot %s/%s/%s/%s for character object %s (%s)\n", slot->collection.page.book.name.c_str(), slot->collection.page.name.c_str(), slot->collection.name.c_str(), Unicode::wideToNarrow(argv[2]).c_str(), oid.getValueString().c_str(), Unicode::wideToNarrow(o->getAssignedObjectName()).c_str()));
p->modifyCollectionSlotValue(Unicode::wideToNarrow(argv[2]), 1);
}
// clear bit-type slot
else if (adjustment.getValue() < 0)
{
if (!p->hasCompletedCollectionSlot(*slot))
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("character object %s (%s) doesn't have collection slot %s/%s/%s/%s\n", oid.getValueString().c_str(), Unicode::wideToNarrow(o->getAssignedObjectName()).c_str(), slot->collection.page.book.name.c_str(), slot->collection.page.name.c_str(), slot->collection.name.c_str(), Unicode::wideToNarrow(argv[2]).c_str()));
return true;
}
result += Unicode::narrowToWide(FormattedString<512>().sprintf("removing collection slot %s/%s/%s/%s for character object %s (%s)\n", slot->collection.page.book.name.c_str(), slot->collection.page.name.c_str(), slot->collection.name.c_str(), Unicode::wideToNarrow(argv[2]).c_str(), oid.getValueString().c_str(), Unicode::wideToNarrow(o->getAssignedObjectName()).c_str()));
p->modifyCollectionSlotValue(Unicode::wideToNarrow(argv[2]), -1);
}
}
// counter-type slot
else
{
if (adjustment.getValue() > 0)
{
std::vector<CollectionsDataTable::CollectionInfoSlot const *> missingPrereqs;
if (!p->hasCompletedCollectionSlotPrereq(Unicode::wideToNarrow(argv[2]), &missingPrereqs))
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("cannot modify collection slot %s/%s/%s/%s for character object %s (%s) because the following prerequisite collection slot(s) are not yet completed:\n", slot->collection.page.book.name.c_str(), slot->collection.page.name.c_str(), slot->collection.name.c_str(), Unicode::wideToNarrow(argv[2]).c_str(), oid.getValueString().c_str(), Unicode::wideToNarrow(o->getAssignedObjectName()).c_str()));
for (std::vector<CollectionsDataTable::CollectionInfoSlot const *>::const_iterator iter = missingPrereqs.begin(); iter != missingPrereqs.end(); ++iter)
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%s/%s/%s/%s\n", (*iter)->collection.page.book.name.c_str(), (*iter)->collection.page.name.c_str(), (*iter)->collection.name.c_str(), (*iter)->name.c_str()));
return true;
}
}
unsigned long currentValue;
IGNORE_RETURN(p->getCollectionSlotValue(*slot, currentValue));
result += Unicode::narrowToWide(FormattedString<512>().sprintf("modifying collection slot %s/%s/%s/%s value of %lu by %s for character object %s (%s)\n", slot->collection.page.book.name.c_str(), slot->collection.page.name.c_str(), slot->collection.name.c_str(), Unicode::wideToNarrow(argv[2]).c_str(), currentValue, adjustment.getValueString().c_str(), oid.getValueString().c_str(), Unicode::wideToNarrow(o->getAssignedObjectName()).c_str()));
p->modifyCollectionSlotValue(Unicode::wideToNarrow(argv[2]), adjustment.getValue());
}
return true;
}
// ----------------------------------------------------------------------
else if (isCommand (argv [0], "grantAllSlotsForCollection"))
{
NetworkId oid(Unicode::wideToNarrow(argv[1]));
ServerObject * o = dynamic_cast<ServerObject *>(ServerWorld::findObjectByNetworkId(oid));
if (o == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
CreatureObject * c = o->asCreatureObject();
if (c == NULL)
{
result += Unicode::narrowToWide("specified object is not a creature object\n");
return true;
}
PlayerObject * p = PlayerCreatureController::getPlayerObject(c);
if (p == NULL)
{
result += Unicode::narrowToWide("specified object is not a character object\n");
return true;
}
std::vector<CollectionsDataTable::CollectionInfoSlot const *> const & slots = CollectionsDataTable::getSlotsInCollection(Unicode::wideToNarrow(argv[2]));
if (slots.empty())
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%s is not a valid collection name\n", Unicode::wideToNarrow(argv[2]).c_str()));
return true;
}
result += Unicode::narrowToWide(FormattedString<512>().sprintf("granting collection slot(s) in collection %s which character object %s (%s) hasn't already completed\n", Unicode::wideToNarrow(argv[2]).c_str(), oid.getValueString().c_str(), Unicode::wideToNarrow(o->getAssignedObjectName()).c_str()));
for (std::vector<CollectionsDataTable::CollectionInfoSlot const *>::const_iterator iter = slots.begin(); iter != slots.end(); ++iter)
{
if (!p->hasCompletedCollectionSlot(**iter))
{
// don't do anything for counter-type slot that can never be completed
if ((*iter)->counterTypeSlot && ((*iter)->maxSlotValue == 0))
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("ignoring collection slot %s/%s/%s/%s because it can never be completed\n", (*iter)->collection.page.book.name.c_str(), (*iter)->collection.page.name.c_str(), (*iter)->collection.name.c_str(), (*iter)->name.c_str()));
continue;
}
// don't do anything for slot that haven't met prerequisite
if (!p->hasCompletedCollectionSlotPrereq(**iter))
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("ignoring collection slot %s/%s/%s/%s because its prerequisite collection slot(s) are not yet completed\n", (*iter)->collection.page.book.name.c_str(), (*iter)->collection.page.name.c_str(), (*iter)->collection.name.c_str(), (*iter)->name.c_str()));
continue;
}
if (!(*iter)->counterTypeSlot)
{
// grant bit type slot
result += Unicode::narrowToWide(FormattedString<512>().sprintf("setting collection slot %s/%s/%s/%s\n", (*iter)->collection.page.book.name.c_str(), (*iter)->collection.page.name.c_str(), (*iter)->collection.name.c_str(), (*iter)->name.c_str()));
p->modifyCollectionSlotValue((*iter)->name, 1);
}
else
{
// grant counter-type slot
unsigned long currentValue;
IGNORE_RETURN(p->getCollectionSlotValue(**iter, currentValue));
// quickie way to convert to an int64
NetworkId const adjustment(static_cast<int64>((*iter)->maxSlotValue) - static_cast<int64>(currentValue));
result += Unicode::narrowToWide(FormattedString<512>().sprintf("modifying collection slot %s/%s/%s/%s value of %lu by %s\n", (*iter)->collection.page.book.name.c_str(), (*iter)->collection.page.name.c_str(), (*iter)->collection.name.c_str(), (*iter)->name.c_str(), currentValue, adjustment.getValueString().c_str()));
p->modifyCollectionSlotValue((*iter)->name, adjustment.getValue());
}
}
}
return true;
}
// ----------------------------------------------------------------------
else if (isCommand (argv [0], "grantAllSlotsForPage"))
{
NetworkId oid(Unicode::wideToNarrow(argv[1]));
ServerObject * o = dynamic_cast<ServerObject *>(ServerWorld::findObjectByNetworkId(oid));
if (o == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
CreatureObject * c = o->asCreatureObject();
if (c == NULL)
{
result += Unicode::narrowToWide("specified object is not a creature object\n");
return true;
}
PlayerObject * p = PlayerCreatureController::getPlayerObject(c);
if (p == NULL)
{
result += Unicode::narrowToWide("specified object is not a character object\n");
return true;
}
std::vector<CollectionsDataTable::CollectionInfoSlot const *> const & slots = CollectionsDataTable::getSlotsInPage(Unicode::wideToNarrow(argv[2]));
if (slots.empty())
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%s is not a valid page name\n", Unicode::wideToNarrow(argv[2]).c_str()));
return true;
}
result += Unicode::narrowToWide(FormattedString<512>().sprintf("granting collection slot(s) in page %s which character object %s (%s) hasn't already completed\n", Unicode::wideToNarrow(argv[2]).c_str(), oid.getValueString().c_str(), Unicode::wideToNarrow(o->getAssignedObjectName()).c_str()));
for (std::vector<CollectionsDataTable::CollectionInfoSlot const *>::const_iterator iter = slots.begin(); iter != slots.end(); ++iter)
{
if (!p->hasCompletedCollectionSlot(**iter))
{
// don't do anything for counter-type slot that can never be completed
if ((*iter)->counterTypeSlot && ((*iter)->maxSlotValue == 0))
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("ignoring collection slot %s/%s/%s/%s because it can never be completed\n", (*iter)->collection.page.book.name.c_str(), (*iter)->collection.page.name.c_str(), (*iter)->collection.name.c_str(), (*iter)->name.c_str()));
continue;
}
// don't do anything for slot that haven't met prerequisite
if (!p->hasCompletedCollectionSlotPrereq(**iter))
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("ignoring collection slot %s/%s/%s/%s because its prerequisite collection slot(s) are not yet completed\n", (*iter)->collection.page.book.name.c_str(), (*iter)->collection.page.name.c_str(), (*iter)->collection.name.c_str(), (*iter)->name.c_str()));
continue;
}
if (!(*iter)->counterTypeSlot)
{
// grant bit type slot
result += Unicode::narrowToWide(FormattedString<512>().sprintf("setting collection slot %s/%s/%s/%s\n", (*iter)->collection.page.book.name.c_str(), (*iter)->collection.page.name.c_str(), (*iter)->collection.name.c_str(), (*iter)->name.c_str()));
p->modifyCollectionSlotValue((*iter)->name, 1);
}
else
{
// grant counter-type slot
unsigned long currentValue;
IGNORE_RETURN(p->getCollectionSlotValue(**iter, currentValue));
// quickie way to convert to an int64
NetworkId const adjustment(static_cast<int64>((*iter)->maxSlotValue) - static_cast<int64>(currentValue));
result += Unicode::narrowToWide(FormattedString<512>().sprintf("modifying collection slot %s/%s/%s/%s value of %lu by %s\n", (*iter)->collection.page.book.name.c_str(), (*iter)->collection.page.name.c_str(), (*iter)->collection.name.c_str(), (*iter)->name.c_str(), currentValue, adjustment.getValueString().c_str()));
p->modifyCollectionSlotValue((*iter)->name, adjustment.getValue());
}
}
}
return true;
}
// ----------------------------------------------------------------------
else if (isCommand (argv [0], "grantAllSlotsForBook"))
{
NetworkId oid(Unicode::wideToNarrow(argv[1]));
ServerObject * o = dynamic_cast<ServerObject *>(ServerWorld::findObjectByNetworkId(oid));
if (o == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
CreatureObject * c = o->asCreatureObject();
if (c == NULL)
{
result += Unicode::narrowToWide("specified object is not a creature object\n");
return true;
}
PlayerObject * p = PlayerCreatureController::getPlayerObject(c);
if (p == NULL)
{
result += Unicode::narrowToWide("specified object is not a character object\n");
return true;
}
std::vector<CollectionsDataTable::CollectionInfoSlot const *> const & slots = CollectionsDataTable::getSlotsInBook(Unicode::wideToNarrow(argv[2]));
if (slots.empty())
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%s is not a valid book name\n", Unicode::wideToNarrow(argv[2]).c_str()));
return true;
}
result += Unicode::narrowToWide(FormattedString<512>().sprintf("granting collection slot(s) in book %s which character object %s (%s) hasn't already completed\n", Unicode::wideToNarrow(argv[2]).c_str(), oid.getValueString().c_str(), Unicode::wideToNarrow(o->getAssignedObjectName()).c_str()));
for (std::vector<CollectionsDataTable::CollectionInfoSlot const *>::const_iterator iter = slots.begin(); iter != slots.end(); ++iter)
{
if (!p->hasCompletedCollectionSlot(**iter))
{
// don't do anything for counter-type slot that can never be completed
if ((*iter)->counterTypeSlot && ((*iter)->maxSlotValue == 0))
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("ignoring collection slot %s/%s/%s/%s because it can never be completed\n", (*iter)->collection.page.book.name.c_str(), (*iter)->collection.page.name.c_str(), (*iter)->collection.name.c_str(), (*iter)->name.c_str()));
continue;
}
// don't do anything for slot that haven't met prerequisite
if (!p->hasCompletedCollectionSlotPrereq(**iter))
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("ignoring collection slot %s/%s/%s/%s because its prerequisite collection slot(s) are not yet completed\n", (*iter)->collection.page.book.name.c_str(), (*iter)->collection.page.name.c_str(), (*iter)->collection.name.c_str(), (*iter)->name.c_str()));
continue;
}
if (!(*iter)->counterTypeSlot)
{
// grant bit type slot
result += Unicode::narrowToWide(FormattedString<512>().sprintf("setting collection slot %s/%s/%s/%s\n", (*iter)->collection.page.book.name.c_str(), (*iter)->collection.page.name.c_str(), (*iter)->collection.name.c_str(), (*iter)->name.c_str()));
p->modifyCollectionSlotValue((*iter)->name, 1);
}
else
{
// grant counter-type slot
unsigned long currentValue;
IGNORE_RETURN(p->getCollectionSlotValue(**iter, currentValue));
// quickie way to convert to an int64
NetworkId const adjustment(static_cast<int64>((*iter)->maxSlotValue) - static_cast<int64>(currentValue));
result += Unicode::narrowToWide(FormattedString<512>().sprintf("modifying collection slot %s/%s/%s/%s value of %lu by %s\n", (*iter)->collection.page.book.name.c_str(), (*iter)->collection.page.name.c_str(), (*iter)->collection.name.c_str(), (*iter)->name.c_str(), currentValue, adjustment.getValueString().c_str()));
p->modifyCollectionSlotValue((*iter)->name, adjustment.getValue());
}
}
}
return true;
}
// ----------------------------------------------------------------------
else if (isCommand (argv [0], "revokeAllSlotsForCollection"))
{
NetworkId oid(Unicode::wideToNarrow(argv[1]));
ServerObject * o = dynamic_cast<ServerObject *>(ServerWorld::findObjectByNetworkId(oid));
if (o == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
CreatureObject * c = o->asCreatureObject();
if (c == NULL)
{
result += Unicode::narrowToWide("specified object is not a creature object\n");
return true;
}
PlayerObject * p = PlayerCreatureController::getPlayerObject(c);
if (p == NULL)
{
result += Unicode::narrowToWide("specified object is not a character object\n");
return true;
}
std::vector<CollectionsDataTable::CollectionInfoSlot const *> const & slots = CollectionsDataTable::getSlotsInCollection(Unicode::wideToNarrow(argv[2]));
if (slots.empty())
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%s is not a valid collection name\n", Unicode::wideToNarrow(argv[2]).c_str()));
return true;
}
result += Unicode::narrowToWide(FormattedString<512>().sprintf("revoking collection slot(s) in collection %s which character object %s (%s) has already completed\n", Unicode::wideToNarrow(argv[2]).c_str(), oid.getValueString().c_str(), Unicode::wideToNarrow(o->getAssignedObjectName()).c_str()));
for (std::vector<CollectionsDataTable::CollectionInfoSlot const *>::const_iterator iter = slots.begin(); iter != slots.end(); ++iter)
{
if (p->hasCompletedCollectionSlot(**iter))
{
if (!(*iter)->counterTypeSlot)
{
// revoke bit type slot
result += Unicode::narrowToWide(FormattedString<512>().sprintf("removing collection slot %s/%s/%s/%s\n", (*iter)->collection.page.book.name.c_str(), (*iter)->collection.page.name.c_str(), (*iter)->collection.name.c_str(), (*iter)->name.c_str()));
p->modifyCollectionSlotValue((*iter)->name, -1);
}
else
{
// revoke counter-type slot
unsigned long currentValue;
IGNORE_RETURN(p->getCollectionSlotValue(**iter, currentValue));
// quickie way to convert to an int64
NetworkId const adjustment(-(static_cast<int64>(currentValue)));
result += Unicode::narrowToWide(FormattedString<512>().sprintf("modifying collection slot %s/%s/%s/%s value of %lu by %s\n", (*iter)->collection.page.book.name.c_str(), (*iter)->collection.page.name.c_str(), (*iter)->collection.name.c_str(), (*iter)->name.c_str(), currentValue, adjustment.getValueString().c_str()));
p->modifyCollectionSlotValue((*iter)->name, adjustment.getValue());
}
}
}
return true;
}
// ----------------------------------------------------------------------
else if (isCommand (argv [0], "revokeAllSlotsForPage"))
{
NetworkId oid(Unicode::wideToNarrow(argv[1]));
ServerObject * o = dynamic_cast<ServerObject *>(ServerWorld::findObjectByNetworkId(oid));
if (o == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
CreatureObject * c = o->asCreatureObject();
if (c == NULL)
{
result += Unicode::narrowToWide("specified object is not a creature object\n");
return true;
}
PlayerObject * p = PlayerCreatureController::getPlayerObject(c);
if (p == NULL)
{
result += Unicode::narrowToWide("specified object is not a character object\n");
return true;
}
std::vector<CollectionsDataTable::CollectionInfoSlot const *> const & slots = CollectionsDataTable::getSlotsInPage(Unicode::wideToNarrow(argv[2]));
if (slots.empty())
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%s is not a valid page name\n", Unicode::wideToNarrow(argv[2]).c_str()));
return true;
}
result += Unicode::narrowToWide(FormattedString<512>().sprintf("revoking collection slot(s) in page %s which character object %s (%s) has already completed\n", Unicode::wideToNarrow(argv[2]).c_str(), oid.getValueString().c_str(), Unicode::wideToNarrow(o->getAssignedObjectName()).c_str()));
for (std::vector<CollectionsDataTable::CollectionInfoSlot const *>::const_iterator iter = slots.begin(); iter != slots.end(); ++iter)
{
if (p->hasCompletedCollectionSlot(**iter))
{
if (!(*iter)->counterTypeSlot)
{
// revoke bit type slot
result += Unicode::narrowToWide(FormattedString<512>().sprintf("removing collection slot %s/%s/%s/%s\n", (*iter)->collection.page.book.name.c_str(), (*iter)->collection.page.name.c_str(), (*iter)->collection.name.c_str(), (*iter)->name.c_str()));
p->modifyCollectionSlotValue((*iter)->name, -1);
}
else
{
// revoke counter-type slot
unsigned long currentValue;
IGNORE_RETURN(p->getCollectionSlotValue(**iter, currentValue));
// quickie way to convert to an int64
NetworkId const adjustment(-(static_cast<int64>(currentValue)));
result += Unicode::narrowToWide(FormattedString<512>().sprintf("modifying collection slot %s/%s/%s/%s value of %lu by %s\n", (*iter)->collection.page.book.name.c_str(), (*iter)->collection.page.name.c_str(), (*iter)->collection.name.c_str(), (*iter)->name.c_str(), currentValue, adjustment.getValueString().c_str()));
p->modifyCollectionSlotValue((*iter)->name, adjustment.getValue());
}
}
}
return true;
}
// ----------------------------------------------------------------------
else if (isCommand (argv [0], "revokeAllSlotsForBook"))
{
NetworkId oid(Unicode::wideToNarrow(argv[1]));
ServerObject * o = dynamic_cast<ServerObject *>(ServerWorld::findObjectByNetworkId(oid));
if (o == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
CreatureObject * c = o->asCreatureObject();
if (c == NULL)
{
result += Unicode::narrowToWide("specified object is not a creature object\n");
return true;
}
PlayerObject * p = PlayerCreatureController::getPlayerObject(c);
if (p == NULL)
{
result += Unicode::narrowToWide("specified object is not a character object\n");
return true;
}
std::vector<CollectionsDataTable::CollectionInfoSlot const *> const & slots = CollectionsDataTable::getSlotsInBook(Unicode::wideToNarrow(argv[2]));
if (slots.empty())
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%s is not a valid book name\n", Unicode::wideToNarrow(argv[2]).c_str()));
return true;
}
result += Unicode::narrowToWide(FormattedString<512>().sprintf("revoking collection slot(s) in book %s which character object %s (%s) has already completed\n", Unicode::wideToNarrow(argv[2]).c_str(), oid.getValueString().c_str(), Unicode::wideToNarrow(o->getAssignedObjectName()).c_str()));
for (std::vector<CollectionsDataTable::CollectionInfoSlot const *>::const_iterator iter = slots.begin(); iter != slots.end(); ++iter)
{
if (p->hasCompletedCollectionSlot(**iter))
{
if (!(*iter)->counterTypeSlot)
{
// revoke bit type slot
result += Unicode::narrowToWide(FormattedString<512>().sprintf("removing collection slot %s/%s/%s/%s\n", (*iter)->collection.page.book.name.c_str(), (*iter)->collection.page.name.c_str(), (*iter)->collection.name.c_str(), (*iter)->name.c_str()));
p->modifyCollectionSlotValue((*iter)->name, -1);
}
else
{
// revoke counter-type slot
unsigned long currentValue;
IGNORE_RETURN(p->getCollectionSlotValue(**iter, currentValue));
// quickie way to convert to an int64
NetworkId const adjustment(-(static_cast<int64>(currentValue)));
result += Unicode::narrowToWide(FormattedString<512>().sprintf("modifying collection slot %s/%s/%s/%s value of %lu by %s\n", (*iter)->collection.page.book.name.c_str(), (*iter)->collection.page.name.c_str(), (*iter)->collection.name.c_str(), (*iter)->name.c_str(), currentValue, adjustment.getValueString().c_str()));
p->modifyCollectionSlotValue((*iter)->name, adjustment.getValue());
}
}
}
return true;
}
// ----------------------------------------------------------------------
else if (isCommand (argv [0], "displayCollections"))
{
NetworkId oid(Unicode::wideToNarrow(argv[1]));
ServerObject * o = dynamic_cast<ServerObject *>(ServerWorld::findObjectByNetworkId(oid));
if (o == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
CreatureObject * c = o->asCreatureObject();
if (c == NULL)
{
result += Unicode::narrowToWide("specified object is not a creature object\n");
return true;
}
PlayerObject * p = PlayerCreatureController::getPlayerObject(c);
if (p == NULL)
{
result += Unicode::narrowToWide("specified object is not a character object\n");
return true;
}
result += Unicode::narrowToWide(FormattedString<512>().sprintf("Displaying collections for character object %s (%s)\n", oid.getValueString().c_str(), Unicode::wideToNarrow(o->getAssignedObjectName()).c_str()));
std::string slotInfo;
std::string collectionInfo;
std::string pageInfo;
std::vector<CollectionsDataTable::CollectionInfoBook const *> const & books = CollectionsDataTable::getAllBooks();
for (std::vector<CollectionsDataTable::CollectionInfoBook const *>::const_iterator iterBook = books.begin(); iterBook != books.end(); ++iterBook)
{
std::vector<CollectionsDataTable::CollectionInfoPage const *> const & pages = CollectionsDataTable::getPagesInBook((*iterBook)->name);
pageInfo.clear();
for (std::vector<CollectionsDataTable::CollectionInfoPage const *>::const_iterator iterPage = pages.begin(); iterPage != pages.end(); ++iterPage)
{
std::vector<CollectionsDataTable::CollectionInfoCollection const *> const & collections = CollectionsDataTable::getCollectionsInPage((*iterPage)->name);
collectionInfo.clear();
for (std::vector<CollectionsDataTable::CollectionInfoCollection const *>::const_iterator iterCollection = collections.begin(); iterCollection != collections.end(); ++iterCollection)
{
std::vector<CollectionsDataTable::CollectionInfoSlot const *> const & slots = CollectionsDataTable::getSlotsInCollection((*iterCollection)->name);
slotInfo.clear();
for (std::vector<CollectionsDataTable::CollectionInfoSlot const *>::const_iterator iterSlot = slots.begin(); iterSlot != slots.end(); ++iterSlot)
{
if (!(*iterSlot)->counterTypeSlot)
{
if (p->hasCompletedCollectionSlot(**iterSlot))
slotInfo += FormattedString<512>().sprintf(" %s\n", (*iterSlot)->name.c_str());
}
else
{
unsigned long value;
IGNORE_RETURN(p->getCollectionSlotValue(**iterSlot, value));
if (value == 0)
continue;
if ((*iterSlot)->maxSlotValue == 0)
slotInfo += FormattedString<512>().sprintf(" %s (%lu)\n", (*iterSlot)->name.c_str(), value);
else
slotInfo += FormattedString<512>().sprintf(" %s (%lu/%lu)\n", (*iterSlot)->name.c_str(), value, (*iterSlot)->maxSlotValue);
}
}
if (!slotInfo.empty())
{
if (p->hasCompletedCollection((*iterCollection)->name))
collectionInfo += FormattedString<512>().sprintf(" *%s\n", (*iterCollection)->name.c_str());
else
collectionInfo += FormattedString<512>().sprintf(" %s\n", (*iterCollection)->name.c_str());
collectionInfo += slotInfo;
}
}
if (!collectionInfo.empty())
{
pageInfo += FormattedString<512>().sprintf(" %s\n", (*iterPage)->name.c_str());
pageInfo += collectionInfo;
}
}
if (!pageInfo.empty())
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%s\n", (*iterBook)->name.c_str()));
result += Unicode::narrowToWide(pageInfo);
}
}
return true;
}
// ----------------------------------------------------------------------
else if (isCommand (argv [0], "displayServerFirst"))
{
std::map<std::string, CollectionsDataTable::CollectionInfoCollection const *> const & allServerFirstCollections = CollectionsDataTable::getAllServerFirstCollections();
std::map<std::string, CollectionsDataTable::CollectionInfoCollection const *>::const_iterator iter;
int discovered = 0;
for (iter = allServerFirstCollections.begin(); iter != allServerFirstCollections.end(); ++iter)
{
if (iter->second->serverFirstClaimTime > 0)
++discovered;
}
int const undiscovered = allServerFirstCollections.size() - discovered;
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%d Discovered:\n", discovered));
for (iter = allServerFirstCollections.begin(); iter != allServerFirstCollections.end(); ++iter)
{
if (iter->second->serverFirstClaimTime > 0)
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%s discovered by (%s, %s) at %ld (%s)\n", iter->second->name.c_str(), iter->second->serverFirstClaimantId.getValueString().c_str(), Unicode::wideToNarrow(iter->second->serverFirstClaimantName).c_str(), iter->second->serverFirstClaimTime, CalendarTime::convertEpochToTimeStringLocal(iter->second->serverFirstClaimTime).c_str()));
}
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%d Undiscovered:\n", undiscovered));
for (iter = allServerFirstCollections.begin(); iter != allServerFirstCollections.end(); ++iter)
{
if (iter->second->serverFirstClaimTime <= 0)
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%s\n", iter->second->name.c_str()));
}
return true;
}
// ----------------------------------------------------------------------
else if (isCommand (argv [0], "addServerFirst"))
{
NetworkId oid(Unicode::wideToNarrow(argv[1]));
ServerObject * o = dynamic_cast<ServerObject *>(ServerWorld::findObjectByNetworkId(oid));
if (o == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
CreatureObject * c = o->asCreatureObject();
if (c == NULL)
{
result += Unicode::narrowToWide("specified object is not a creature object\n");
return true;
}
PlayerObject * p = PlayerCreatureController::getPlayerObject(c);
if (p == NULL)
{
result += Unicode::narrowToWide("specified object is not a character object\n");
return true;
}
CollectionsDataTable::CollectionInfoCollection const * const collectionInfo = CollectionsDataTable::getCollectionByName(Unicode::wideToNarrow(argv[2]));
if (!collectionInfo)
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%s is not a valid collection name\n", Unicode::wideToNarrow(argv[2]).c_str()));
return true;
}
if (!collectionInfo->trackServerFirst)
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%s is not a \"server first\" tracked collection\n", Unicode::wideToNarrow(argv[2]).c_str()));
return true;
}
if (collectionInfo->serverFirstClaimTime > 0)
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%s has already been discovered by (%s, %s) at %ld (%s)\n", Unicode::wideToNarrow(argv[2]).c_str(), collectionInfo->serverFirstClaimantId.getValueString().c_str(), Unicode::wideToNarrow(collectionInfo->serverFirstClaimantName).c_str(), collectionInfo->serverFirstClaimTime, CalendarTime::convertEpochToTimeStringLocal(collectionInfo->serverFirstClaimTime).c_str()));
return true;
}
PlanetObject * const planetObject = ServerUniverse::getInstance().getTatooinePlanet();
if (!planetObject)
{
result += Unicode::narrowToWide("could not locate the tatooine PlanetObject\n");
return true;
}
result += Unicode::narrowToWide(FormattedString<512>().sprintf("requesting character object %s (%s) be made \"server first\" for collection %s\n", oid.getValueString().c_str(), Unicode::wideToNarrow(o->getAssignedObjectName()).c_str(), Unicode::wideToNarrow(argv[2]).c_str()));
planetObject->setCollectionServerFirst(*collectionInfo, oid, o->getAssignedObjectName(), p->getAccountDescription());
return true;
}
// ----------------------------------------------------------------------
else if (isCommand (argv [0], "setServerFirstTime"))
{
time_t const rawtime = ::time(NULL);
struct tm * timeinfo = ::localtime(&rawtime);
timeinfo->tm_year = atoi(Unicode::wideToNarrow(argv[2]).c_str()) - 1900;
timeinfo->tm_mon = atoi(Unicode::wideToNarrow(argv[3]).c_str()) - 1;
timeinfo->tm_mday = atoi(Unicode::wideToNarrow(argv[4]).c_str());
timeinfo->tm_hour = atoi(Unicode::wideToNarrow(argv[5]).c_str());
timeinfo->tm_min = atoi(Unicode::wideToNarrow(argv[6]).c_str());
timeinfo->tm_sec = atoi(Unicode::wideToNarrow(argv[7]).c_str());
time_t const specifiedTime = ::mktime(timeinfo);
if (specifiedTime <= 0)
{
result += Unicode::narrowToWide("specified time is invalid\n");
return true;
}
CollectionsDataTable::CollectionInfoCollection const * const collectionInfo = CollectionsDataTable::getCollectionByName(Unicode::wideToNarrow(argv[1]));
if (!collectionInfo)
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%s is not a valid collection name\n", Unicode::wideToNarrow(argv[1]).c_str()));
return true;
}
if (!collectionInfo->trackServerFirst)
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%s is not a \"server first\" tracked collection\n", collectionInfo->name.c_str()));
return true;
}
if (collectionInfo->serverFirstClaimTime <= 0)
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("collection %s has not yet been discovered\n", collectionInfo->name.c_str()));
return true;
}
PlanetObject * const planetObject = ServerUniverse::getInstance().getTatooinePlanet();
if (!planetObject)
{
result += Unicode::narrowToWide("could not locate the tatooine PlanetObject\n");
return true;
}
result += Unicode::narrowToWide(FormattedString<512>().sprintf("setting \"server first\" time for collection %s:\n", collectionInfo->name.c_str()));
result += Unicode::narrowToWide(FormattedString<512>().sprintf("***FROM*** %ld (%s, %s)\n", static_cast<long>(collectionInfo->serverFirstClaimTime), CalendarTime::convertEpochToTimeStringLocal(collectionInfo->serverFirstClaimTime).c_str(), CalendarTime::convertEpochToTimeStringGMT(collectionInfo->serverFirstClaimTime).c_str()));
result += Unicode::narrowToWide(FormattedString<512>().sprintf("****TO**** %ld (%s, %s)\n", static_cast<long>(specifiedTime), CalendarTime::convertEpochToTimeStringLocal(specifiedTime).c_str(), CalendarTime::convertEpochToTimeStringGMT(specifiedTime).c_str()));
char buffer[1024];
snprintf(buffer, sizeof(buffer)-1, "%s|%ld", collectionInfo->name.c_str(), static_cast<long>(specifiedTime));
buffer[sizeof(buffer)-1] = '\0';
MessageToQueue::getInstance().sendMessageToC(planetObject->getNetworkId(),
"C++SetCollectionServerFirstTime",
buffer,
0,
false);
return true;
}
// ----------------------------------------------------------------------
else if (isCommand (argv [0], "removeServerFirst"))
{
CollectionsDataTable::CollectionInfoCollection const * const collectionInfo = CollectionsDataTable::getCollectionByName(Unicode::wideToNarrow(argv[1]));
if (!collectionInfo)
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%s is not a valid collection name\n", Unicode::wideToNarrow(argv[1]).c_str()));
return true;
}
if (!collectionInfo->trackServerFirst)
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%s is not a \"server first\" tracked collection\n", Unicode::wideToNarrow(argv[1]).c_str()));
return true;
}
if (collectionInfo->serverFirstClaimTime <= 0)
{
result += Unicode::narrowToWide(FormattedString<512>().sprintf("%s has not yet been discovered\n", Unicode::wideToNarrow(argv[1]).c_str()));
return true;
}
PlanetObject * const planetObject = ServerUniverse::getInstance().getTatooinePlanet();
if (!planetObject)
{
result += Unicode::narrowToWide("could not locate the tatooine PlanetObject\n");
return true;
}
result += Unicode::narrowToWide(FormattedString<512>().sprintf("requesting clearing of \"server first\" for collection %s [discovered by (%s, %s) at %ld (%s)]\n", Unicode::wideToNarrow(argv[1]).c_str(), collectionInfo->serverFirstClaimantId.getValueString().c_str(), Unicode::wideToNarrow(collectionInfo->serverFirstClaimantName).c_str(), collectionInfo->serverFirstClaimTime, CalendarTime::convertEpochToTimeStringLocal(collectionInfo->serverFirstClaimTime).c_str()));
planetObject->removeCollectionServerFirst(*collectionInfo);
return true;
}
// ----------------------------------------------------------------------
else
{
result += getErrorMessage(argv[0], ERR_NO_HANDLER);
}
return true;
} // ConsoleCommandParserCollection::performParsing
// ======================================================================
@@ -0,0 +1,32 @@
// ======================================================================
//
// ConsoleCommandParserCollection.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserCollection_H
#define INCLUDED_ConsoleCommandParserCollection_H
#include "sharedCommandParser/CommandParser.h"
// ======================================================================
/**
* Commands that are related to the Collection system.
*/
class ConsoleCommandParserCollection : public CommandParser
{
public:
ConsoleCommandParserCollection ();
virtual bool performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node);
private:
ConsoleCommandParserCollection (const ConsoleCommandParserCollection & rhs);
ConsoleCommandParserCollection & operator= (const ConsoleCommandParserCollection & rhs);
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserCollection_H
@@ -0,0 +1,193 @@
// ======================================================================
//
// ConsoleCommandParserCraft.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ConsoleCommandParserCraft.h"
#include "UnicodeUtils.h"
#include "serverGame/ConsoleCommandParserCraftStation.h"
#include "serverGame/CreatureObject.h"
#include "serverGame/GameServer.h"
#include "serverGame/PlayerCreatureController.h"
#include "serverGame/PlayerObject.h"
#include "serverGame/ServerWorld.h"
#include "sharedFoundation/GameControllerMessage.h"
// ======================================================================
static const CommandParser::CmdInfo cmds[] =
{
{"draft", 1, "<number>", "Select a draft schematic to craft with"},
{"fillslot", 3, "<slot #> <slot option #> <ingredient oid>", "Fill a draft schematic slot with an ingredient"},
{"nextstage", 0, "", "Go to the next stage of crafting"},
{"experiment", 3, "<attribute #> <experiment points> <core level>", "Experiment to improve an attribute"},
{"customize", 2, "<custom #> <value>", "Set a customization property"},
{"makeprototype", 1, "<name>", "Create a prototype object"},
{"makeschematic", 1, "<name>", "Create manufacturing schematic"},
{"stop", 0, "", "Stops the current crafting session"},
{"enableSchematicFilter", 0, "", "Enables schematic filtering (god mode only)"},
{"disableSchematicFilter", 0, "", "Disables schematic filtering (god mode only)"},
{"", 0, "", ""} // this must be last
};
//-----------------------------------------------------------------
ConsoleCommandParserCraft::ConsoleCommandParserCraft (void) :
CommandParser ("craft", 0, "...", "Crafting related commands.", 0)
{
createDelegateCommands (cmds);
addSubCommand(new ConsoleCommandParserCraftStation());
}
//-----------------------------------------------------------------
bool ConsoleCommandParserCraft::performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node)
{
NOT_NULL (node);
UNREF(originalCommand);
CreatureObject * creatureObject = safe_cast<CreatureObject *>(ServerWorld::findObjectByNetworkId(userId));
PlayerObject * playerObject = const_cast<PlayerObject *>(PlayerCreatureController::getPlayerObject(creatureObject));
//-----------------------------------------------------------------
if (isAbbrev( argv [0], "draft"))
{
int index = atoi(Unicode::wideToNarrow(argv[1]).c_str()) - 1;
playerObject->selectDraftSchematic(index);
result += getErrorMessage (argv[0], ERR_SUCCESS);
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "fillslot"))
{
int slot(atoi(Unicode::wideToNarrow(argv[1]).c_str()));
int option(atoi(Unicode::wideToNarrow(argv[2]).c_str()));
NetworkId ingredient(Unicode::wideToNarrow(argv[3]));
if (playerObject->fillSlot(slot - 1, option - 1, ingredient))
result += getErrorMessage (argv[0], ERR_SUCCESS);
else
result += getErrorMessage (argv[0], ERR_FILLSLOT_FAIL);
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "nextstage"))
{
if (playerObject->goToNextCraftingStage())
result += getErrorMessage (argv[0], ERR_SUCCESS);
else
result += getErrorMessage (argv[0], ERR_FAIL);
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "experiment"))
{
int attribute(atoi(Unicode::wideToNarrow(argv[1]).c_str()));
int points(atoi(Unicode::wideToNarrow(argv[2]).c_str()));
int core(atoi(Unicode::wideToNarrow(argv[3]).c_str()));
std::vector<MessageQueueCraftExperiment::ExperimentInfo> experiment;
experiment.push_back(MessageQueueCraftExperiment::ExperimentInfo(attribute - 1, points));
if (playerObject->experiment(experiment, points, core))
result += getErrorMessage (argv[0], ERR_SUCCESS);
else
result += getErrorMessage (argv[0], ERR_FILLSLOT_FAIL);
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "customize"))
{
int property(atoi(Unicode::wideToNarrow(argv[1]).c_str()));
int value(atoi(Unicode::wideToNarrow(argv[2]).c_str()));
if (playerObject->customize(property - 1, value))
result += getErrorMessage (argv[0], ERR_SUCCESS);
else
result += getErrorMessage (argv[0], ERR_CUSTOMIZE_FAIL);
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "makeprototype"))
{
std::vector<Crafting::CustomValue> customizations;
if (playerObject->setCustomizationData(argv[1], -1, customizations, 1) ==
Crafting::CE_success && playerObject->createPrototype(true))
{
result += getErrorMessage (argv[0], ERR_SUCCESS);
}
else
result += getErrorMessage (argv[0], ERR_FAIL);
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "makeschematic"))
{
result += getErrorMessage (argv[0], ERR_FAIL);
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "stop"))
{
playerObject->stopCrafting(true);
result += getErrorMessage (argv[0], ERR_SUCCESS);
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "enableSchematicFilter"))
{
if (creatureObject->getClient() == NULL || !creatureObject->getClient()->isGod())
result += getErrorMessage (argv[0], ERR_FAIL);
else
{
creatureObject->enableSchematicFiltering();
result += getErrorMessage (argv[0], ERR_SUCCESS);
}
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "disableSchematicFilter"))
{
if (creatureObject->getClient() == NULL || !creatureObject->getClient()->isGod())
result += getErrorMessage (argv[0], ERR_FAIL);
else
{
creatureObject->disableSchematicFiltering();
result += getErrorMessage (argv[0], ERR_SUCCESS);
}
}
//-----------------------------------------------------------------
else
{
result += getErrorMessage(argv[0], ERR_NO_HANDLER);
}
return true;
}
// ======================================================================
@@ -0,0 +1,48 @@
// ======================================================================
//
// ConsoleCommandParserCraft.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserCraft_H
#define INCLUDED_ConsoleCommandParserCraft_H
#include "sharedCommandParser/CommandParser.h"
// ======================================================================
/**
* Commands that are related to scripts
*/
class ConsoleCommandParserCraft : public CommandParser
{
public:
ConsoleCommandParserCraft ();
virtual bool performParsing (const NetworkId & userId,
const StringVector_t & argv,
const String_t & originalCommand,
String_t & result,
const CommandParser * node);
private:
ConsoleCommandParserCraft (const ConsoleCommandParserCraft & rhs);
ConsoleCommandParserCraft & operator= (const ConsoleCommandParserCraft & rhs);
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserCraft_H
@@ -0,0 +1,184 @@
// ======================================================================
//
// ConsoleCommandParserCraftStation.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ConsoleCommandParserCraftStation.h"
#include "UnicodeUtils.h"
#include "serverGame/CreatureObject.h"
#include "sharedFoundation/GameControllerMessage.h"
#include "serverGame/GameServer.h"
#include "serverGame/ServerWorld.h"
#include "sharedFoundation/DynamicVariable.h"
#include "sharedFoundation/DynamicVariableList.h"
// ======================================================================
static const CommandParser::CmdInfo cmds[] =
{
// {"add", 2, "<station oid> <ingredient oid>", "Add an ingredient to a station"},
// {"remove", 2, "<station oid> <ingredient oid>", "Remove an ingredient from a station"},
// {"list", 1, "<station oid>", "List a station's ingredients"},
{"", 0, "", ""} // this must be last
};
//-----------------------------------------------------------------
ConsoleCommandParserCraftStation::ConsoleCommandParserCraftStation (void) :
CommandParser ("station", 0, "...", "Crafting station related commands.", 0)
{
createDelegateCommands (cmds);
}
//-----------------------------------------------------------------
bool ConsoleCommandParserCraftStation::performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node)
{
NOT_NULL (node);
UNREF(originalCommand);
// CreatureObject * playerObject = safe_cast<CreatureObject *>(ServerWorld::findObjectByNetworkId(userId));
//-----------------------------------------------------------------
if (isAbbrev( argv [0], "add"))
{
/* // get the station
TangibleObject * station = getStation(argv, result);
if (station == NULL)
return true;
// get the ingredient
NetworkId ingredientId(Unicode::wideToNarrow (argv[2]));
ServerObject * object = ServerWorld::findObjectByNetworkId(ingredientId);
if (object == NULL)
{
result += getErrorMessage (argv [0], ERR_INVALID_INGREDIENT);
return true;
}
TangibleObject * ingredient = dynamic_cast<TangibleObject *>(object);
if (ingredient == NULL)
{
result += getErrorMessage (argv [0], ERR_INVALID_INGREDIENT);
return true;
}
station->addIngredientToHopper(*ingredient, playerObject);
result += getErrorMessage (argv[0], ERR_SUCCESS);
*/
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "remove"))
{
/* // get the station
TangibleObject * station = getStation(argv, result);
if (station == NULL)
return true;
// get the ingredient
NetworkId ingredientId(Unicode::wideToNarrow (argv[2]));
ServerObject * object = ServerWorld::findObjectByNetworkId(ingredientId);
if (object == NULL)
{
result += getErrorMessage (argv [0], ERR_INVALID_INGREDIENT);
return true;
}
TangibleObject * ingredient = dynamic_cast<TangibleObject *>(object);
if (ingredient == NULL)
{
result += getErrorMessage (argv [0], ERR_INVALID_INGREDIENT);
return true;
}
station->removeIngredientFromHopper(*ingredient);
result += getErrorMessage (argv[0], ERR_SUCCESS);
*/
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "list"))
{
/* // get the station
NetworkId id(Unicode::wideToNarrow (argv[1]));
ServerObject * object = ServerWorld::findObjectByNetworkId(id);
if (object == NULL)
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
return true;
}
TangibleObject * station = dynamic_cast<TangibleObject *>(object);
if (station == NULL)
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
return true;
}
station->listIngredientsInHopper(*playerObject);
result += getErrorMessage (argv[0], ERR_SUCCESS);
*/
}
//-----------------------------------------------------------------
else
{
result += getErrorMessage(argv[0], ERR_NO_HANDLER);
}
return true;
}
//-----------------------------------------------------------------
/**
* Finds the crafting station for a given id.
*
* @return the station or NULL on error
*/
TangibleObject * ConsoleCommandParserCraftStation::getStation(const StringVector_t & argv, String_t & result)
{
NetworkId id(Unicode::wideToNarrow (argv[1]));
ServerObject * object = ServerWorld::findObjectByNetworkId(id);
if (object == NULL)
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
return NULL;
}
TangibleObject * station = dynamic_cast<TangibleObject *>(object);
if (station == NULL)
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
return NULL;
}
// make sure the station is a atation and that it isn't in use
if (!station->getObjVars().hasItem("crafting.station"))
{
result += getErrorMessage (argv [0], ERR_INVALID_STATION);
return NULL;
}
if (station->getObjVars().hasItem("crafting.crafter"))
{
result += getErrorMessage (argv [0], ERR_STATION_IN_USE);
return NULL;
}
return station;
} // ConsoleCommandParserCraftStation::getStation
// ======================================================================
@@ -0,0 +1,52 @@
// ======================================================================
//
// ConsoleCommandParserCraftStation.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserCraftStation_H
#define INCLUDED_ConsoleCommandParserCraftStation_H
#include "sharedCommandParser/CommandParser.h"
class TangibleObject;
// ======================================================================
/**
* Commands that are related to scripts
*/
class ConsoleCommandParserCraftStation : public CommandParser
{
public:
ConsoleCommandParserCraftStation ();
virtual bool performParsing (const NetworkId & userId,
const StringVector_t & argv,
const String_t & originalCommand,
String_t & result,
const CommandParser * node);
private:
ConsoleCommandParserCraftStation (const ConsoleCommandParserCraftStation & rhs);
ConsoleCommandParserCraftStation & operator= (const ConsoleCommandParserCraftStation & rhs);
TangibleObject * getStation(const StringVector_t & argv, String_t & result);
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserCraftStation_H
@@ -0,0 +1,148 @@
// ======================================================================
//
// ConsoleCommandParserDefault.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ConsoleCommandParserDefault.h"
#include "serverGame/Chat.h"
#include "sharedFoundation/NetworkId.h"
#ifdef __linux__
#define _wcsicmp wcscasecmp
#endif
// ======================================================================
static const CommandParser::CmdInfo cmds[] =
{
{"serverhelp", 0, "", "List serverside commands."},
{"", 0, "", ""} // this must be last
};
//-----------------------------------------------------------------
/**
* Predicate for searching for a command by abbreviation.
*/
struct StrEqualsAbbrevNoCase
{
const CommandParser::String_t & str;
explicit StrEqualsAbbrevNoCase (const CommandParser::String_t & theStr) : str (theStr) {}
bool operator() (const ConsoleCommandParserDefault::AliasMap_t::value_type & t) const
{
return CommandParser::isAbbrev (str, t.first);
}
StrEqualsAbbrevNoCase (const StrEqualsAbbrevNoCase & rhs) : str (rhs.str) {}
private:
StrEqualsAbbrevNoCase & operator= (const StrEqualsAbbrevNoCase & rhs); //lint !e754
StrEqualsAbbrevNoCase ();
};
//-----------------------------------------------------------------
//--
//--
//-----------------------------------------------------------------
ConsoleCommandParserDefault::ConsoleCommandParserDefault (void) :
CommandParser ("", 0, "...", "all server commands", 0),
m_aliases (),
m_aliasGuard (false),
m_aliasGuardSet ()
{
createDelegateCommands (cmds);
}
//-----------------------------------------------------------------
void ConsoleCommandParserDefault::setAlias (const String_t & key, const String_t & value)
{
UNREF (key);
UNREF (value);
const String_t & aliasString = Unicode::narrowToWide ("\\#aaffaaalias\\#ffffff: ");
m_aliases [key] = value;
StringVector_t vec;
vec.push_back (key);
addSubCommand ( new CommandParser (key, 0, String_t (), aliasString + value, this));
}
//-----------------------------------------------------------------
bool ConsoleCommandParserDefault::removeAlias (const String_t & key)
{
//AliasMap_t::iterator iter = std::find_if (m_aliases.begin (), m_aliases.end (), StrEqualsNoCase (key));
AliasMap_t::iterator iter = m_aliases.find (key);
if (iter != m_aliases.end ())
{
m_aliases.erase (iter);
StringVector_t vec;
vec.push_back (key);
CommandParser * parser = findParser (vec, 0);
if (parser != 0)
{
if (removeParser (parser))
delete parser;
}
return true;
}
return false;
}
//-----------------------------------------------------------------
bool ConsoleCommandParserDefault::performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node)
{
NOT_NULL (node);
UNREF (originalCommand);
UNREF (userId);
//-----------------------------------------------------------------
if (isAbbrev( argv [0], "serverhelp"))
{
CommandParser * parser = findParser (argv, 1);
if (parser == 0)
{
String_t str;
for (size_t i = 1; i < argv.size (); ++i)
{
str.append (argv [i]).append (1, ' ');
}
result += getErrorMessage ( str, ERR_CMD_NOT_FOUND);
}
else
parser->showHelp (result);
}
return true;
}
// ======================================================================
@@ -0,0 +1,58 @@
// ======================================================================
//
// ConsoleCommandParserDefault.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserDefault_H
#define INCLUDED_ConsoleCommandParserDefault_H
#include "sharedCommandParser/CommandParser.h"
#include <map>
#include <hash_set>
#include "UnicodeUtils.h"
// ======================================================================
class ConsoleCommandParserDefault : public CommandParser
{
public:
typedef std::map<String_t, String_t> AliasMap_t;
typedef std::hash_set<String_t> AliasGuardSet_t;
explicit ConsoleCommandParserDefault (void);
virtual bool performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node);
private:
ConsoleCommandParserDefault (const ConsoleCommandParserDefault & rhs);
ConsoleCommandParserDefault & operator= (const ConsoleCommandParserDefault & rhs);
void setAlias (const String_t & key, const String_t & value);
/**
* This method should be removed one day when localization rules the earth -- jww
*/
void setAlias (const char * key, const char * value);
bool removeAlias (const String_t & key);
private:
AliasMap_t m_aliases;
bool m_aliasGuard;
AliasGuardSet_t m_aliasGuardSet;
};
// ======================================================================
inline void ConsoleCommandParserDefault::setAlias (const char * const key, const char * const value)
{
NOT_NULL (key);
NOT_NULL (value);
setAlias (Unicode::narrowToWide (key), Unicode::narrowToWide (value));
}
//-----------------------------------------------------------------
#endif // INCLUDED_ConsoleCommandParserDefault_H
@@ -0,0 +1,32 @@
// ======================================================================
//
// ConsoleCommandParserGuild.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserGuild_H
#define INCLUDED_ConsoleCommandParserGuild_H
#include "sharedCommandParser/CommandParser.h"
// ======================================================================
/**
* Commands that are related to the guild system.
*/
class ConsoleCommandParserGuild : public CommandParser
{
public:
ConsoleCommandParserGuild ();
virtual bool performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node);
private:
ConsoleCommandParserGuild (const ConsoleCommandParserGuild & rhs);
ConsoleCommandParserGuild & operator= (const ConsoleCommandParserGuild & rhs);
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserGuild_H
@@ -0,0 +1,484 @@
// ======================================================================
//
// ConsoleCommandParserManufacture.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ConsoleCommandParserManufacture.h"
#include "UnicodeUtils.h"
#include "serverGame/ContainerInterface.h"
#include "serverGame/CreatureObject.h"
#include "serverGame/ManufactureInstallationObject.h"
#include "serverGame/ManufactureSchematicObject.h"
#include "serverGame/ResourceContainerObject.h"
#include "serverGame/ResourceTypeObject.h"
#include "sharedObject/VolumeContainer.h"
#include "serverGame/ServerWorld.h"
// ======================================================================
static const CommandParser::CmdInfo cmds[] =
{
{"addIngredient", 2, "<station oid> <ingredient oid>", "add an ingredient to a station's input hopper"},
{"removeIngredient", 2, "<station oid> <ingredient oid>", "remove an ingredient from a station's input hopper"},
{"listIngredients", 1, "<oid>", "list the ingredients in a station's input hopper"},
{"addSchematic", 2, "<station oid> <schematic oid>", "add a manufacturing schematic to a station"},
{"removeSchematic", 1, "<station oid>", "remove the manufacturing schematic from a station"},
{"listSchematic", 1, "<station oid>", "list the manufacturing schematic of a station"},
{"start", 1, "<oid>", "starts a station manufacturing"},
{"stop", 1, "<oid>", "stops a station manufacturing"},
{"getObjects", 1, "<oid>", "puts all the objects in a station's output hopper in your inventory"},
{"listObjects", 1, "<oid>", "lists all the objects in a station's output hopper"},
{"", 0, "", ""} // this must be last
};
//-----------------------------------------------------------------
ConsoleCommandParserManufacture::ConsoleCommandParserManufacture (void) :
CommandParser ("manf", 0, "...", "Manufacture station commands.", 0)
{
createDelegateCommands (cmds);
}
//-----------------------------------------------------------------
bool ConsoleCommandParserManufacture::performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node)
{
NOT_NULL (node);
UNREF(originalCommand);
CreatureObject * playerObject = safe_cast<CreatureObject *>(ServerWorld::findObjectByNetworkId(userId));
//-----------------------------------------------------------------
if (isAbbrev( argv [0], "addIngredient"))
{
CachedNetworkId stationId(Unicode::wideToNarrow(argv[1]));
CachedNetworkId ingredientId(Unicode::wideToNarrow(argv[2]));
ManufactureInstallationObject * station = dynamic_cast<ManufactureInstallationObject *>(stationId.getObject());
ServerObject * ingredient = safe_cast<ServerObject *>(ingredientId.getObject());
if (station == NULL || ingredient == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
if (station->isActive())
{
result += getErrorMessage(argv[0], ERR_ACTIVE_MANF_STATION);
return true;
}
ServerObject * hopper = station->getInputHopper();
if (hopper == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
Container::ContainerErrorCode tmp = Container::CEC_Success;
if (ContainerInterface::transferItemToVolumeContainer(*hopper, *ingredient, playerObject, tmp))
result += getErrorMessage(argv[0], ERR_SUCCESS);
else
result += getErrorMessage(argv[0], ERR_INVALID_CONTAINER_TRANSFER);
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "removeIngredient"))
{
CachedNetworkId stationId(Unicode::wideToNarrow(argv[1]));
CachedNetworkId ingredientId(Unicode::wideToNarrow(argv[2]));
ManufactureInstallationObject * station = dynamic_cast<ManufactureInstallationObject *>(stationId.getObject());
ServerObject * ingredient = safe_cast<ServerObject *>(ingredientId.getObject());
if (station == NULL || ingredient == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
if (station->isActive())
{
result += getErrorMessage(argv[0], ERR_ACTIVE_MANF_STATION);
return true;
}
ServerObject * hopper = station->getInputHopper();
if (hopper == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
if (hopper != ContainerInterface::getContainedByObject(*ingredient))
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
if (playerObject->getInventory() == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
Container::ContainerErrorCode tmp = Container::CEC_Success;
if (ContainerInterface::transferItemToVolumeContainer(*playerObject->getInventory(), *ingredient, playerObject, tmp))
result += getErrorMessage(argv[0], ERR_SUCCESS);
else
result += getErrorMessage(argv[0], ERR_INVALID_CONTAINER_TRANSFER);
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "listIngredients"))
{
CachedNetworkId stationId(Unicode::wideToNarrow(argv[1]));
ManufactureInstallationObject * station = dynamic_cast<ManufactureInstallationObject *>(stationId.getObject());
if (station == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
if (station->isActive())
{
result += getErrorMessage(argv[0], ERR_ACTIVE_MANF_STATION);
return true;
}
ServerObject * hopper = station->getInputHopper();
if (hopper == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
VolumeContainer * container = ContainerInterface::getVolumeContainer(*hopper);
if (container == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
ContainerIterator iter = container->begin();
while (iter != container->end())
{
const Container::ContainedItem & itemId = *iter;
if (itemId.getObject() != NULL)
{
const ServerObject * item = safe_cast<const ServerObject *>(itemId.getObject());
result += Unicode::narrowToWide("(");
result += Unicode::narrowToWide(itemId.getValueString());
result += Unicode::narrowToWide(") - ");
const ResourceContainerObject * crate = dynamic_cast<
const ResourceContainerObject *>(item);
if (crate != NULL)
{
char buffer[32];
_itoa(crate->getQuantity(), buffer, 10);
result += Unicode::narrowToWide(buffer);
result += Unicode::narrowToWide(" units of resource ");
ResourceTypeObject const * const resourceType = crate->getResourceType();
if (resourceType)
{
result += Unicode::narrowToWide(resourceType->getResourceName());
}
else
{
result += Unicode::narrowToWide("<unknown type>");
}
}
else
{
result += item->getObjectName();
}
result += Unicode::narrowToWide("\n");
}
else
{
result += Unicode::narrowToWide("(");
result += Unicode::narrowToWide(itemId.getValueString());
result += Unicode::narrowToWide(") - unknown name\n");
}
++iter;
}
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "addSchematic"))
{
CachedNetworkId stationId(Unicode::wideToNarrow(argv[1]));
CachedNetworkId schematicId(Unicode::wideToNarrow(argv[2]));
ManufactureInstallationObject * station = dynamic_cast<ManufactureInstallationObject *>(stationId.getObject());
ManufactureSchematicObject * schematic = dynamic_cast<ManufactureSchematicObject *>(schematicId.getObject());
if (station == NULL || schematic == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
if (station->isActive())
{
result += getErrorMessage(argv[0], ERR_ACTIVE_MANF_STATION);
return true;
}
// if (station->addSchematic(*schematic, playerObject))
if (station->addSchematic(*schematic, NULL))
result += getErrorMessage(argv[0], ERR_SUCCESS);
else
result += getErrorMessage(argv[0], ERR_INVALID_CONTAINER_TRANSFER);
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "removeSchematic"))
{
CachedNetworkId stationId(Unicode::wideToNarrow(argv[1]));
ManufactureInstallationObject * station = dynamic_cast<ManufactureInstallationObject *>(stationId.getObject());
if (station == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
if (station->isActive())
{
result += getErrorMessage(argv[0], ERR_ACTIVE_MANF_STATION);
return true;
}
ManufactureSchematicObject * schematic = station->getSchematic();
if (schematic != NULL)
{
if (playerObject->getDatapad() == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
Container::ContainerErrorCode tmp = Container::CEC_Success;
if (ContainerInterface::transferItemToVolumeContainer(*playerObject->getDatapad(), *schematic, playerObject, tmp))
result += getErrorMessage(argv[0], ERR_SUCCESS);
else
result += getErrorMessage(argv[0], ERR_INVALID_CONTAINER_TRANSFER);
}
else
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "listSchematic"))
{
CachedNetworkId stationId(Unicode::wideToNarrow(argv[1]));
ManufactureInstallationObject * station = dynamic_cast<ManufactureInstallationObject *>(stationId.getObject());
if (station == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
if (station->isActive())
{
result += getErrorMessage(argv[0], ERR_ACTIVE_MANF_STATION);
return true;
}
ManufactureSchematicObject * schematic = station->getSchematic();
if (schematic != NULL)
{
result += Unicode::narrowToWide("(");
result += Unicode::narrowToWide(schematic->getNetworkId().getValueString());
result += Unicode::narrowToWide(") - ");
result += schematic->getObjectName();
result += Unicode::narrowToWide("\n");
}
else
result += Unicode::narrowToWide("no schematic in station\n");
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "start"))
{
CachedNetworkId stationId(Unicode::wideToNarrow(argv[1]));
ManufactureInstallationObject * station = dynamic_cast<ManufactureInstallationObject *>(stationId.getObject());
if (station == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
}
else
{
station->activate(NetworkId::cms_invalid);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "stop"))
{
CachedNetworkId stationId(Unicode::wideToNarrow(argv[1]));
ManufactureInstallationObject * station = dynamic_cast<ManufactureInstallationObject *>(stationId.getObject());
if (station == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
}
else
{
station->deactivate();
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "getObjects"))
{
ServerObject * myInventory = playerObject->getInventory();
if (myInventory == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
CachedNetworkId stationId(Unicode::wideToNarrow(argv[1]));
ManufactureInstallationObject * station = dynamic_cast<ManufactureInstallationObject *>(stationId.getObject());
if (station == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
ServerObject * hopper = station->getOutputHopper();
if (hopper == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
VolumeContainer * container = ContainerInterface::getVolumeContainer(*hopper);
if (container == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
Container::ContainerErrorCode tmp = Container::CEC_Success;
ContainerIterator iter = container->begin();
while (iter != container->end())
{
const Container::ContainedItem & itemId = *iter;
if (itemId.getObject() != NULL)
{
ContainerInterface::transferItemToVolumeContainer (*myInventory, *safe_cast<ServerObject *>(itemId.getObject()), playerObject, tmp);
}
else
{
result += Unicode::narrowToWide("No object for id ");
result += Unicode::narrowToWide(itemId.getValueString());
result += Unicode::narrowToWide("!\n");
}
++iter;
}
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "listObjects"))
{
CachedNetworkId stationId(Unicode::wideToNarrow(argv[1]));
ManufactureInstallationObject * station = dynamic_cast<ManufactureInstallationObject *>(stationId.getObject());
if (station == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
ServerObject * hopper = station->getOutputHopper();
if (hopper == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
VolumeContainer * container = ContainerInterface::getVolumeContainer(*hopper);
if (container == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
ContainerIterator iter = container->begin();
while (iter != container->end())
{
const Container::ContainedItem & itemId = *iter;
if (itemId.getObject() != NULL)
{
const ServerObject * item = safe_cast<const ServerObject *>(itemId.getObject());
result += Unicode::narrowToWide("(");
result += Unicode::narrowToWide(itemId.getValueString());
result += Unicode::narrowToWide(") - ");
result += item->getObjectName();
result += Unicode::narrowToWide("\n");
}
else
{
result += Unicode::narrowToWide("(");
result += Unicode::narrowToWide(itemId.getValueString());
result += Unicode::narrowToWide(") - unknown name\n");
}
++iter;
}
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
//-----------------------------------------------------------------
else
{
result += getErrorMessage(argv[0], ERR_NO_HANDLER);
}
return true;
}
// ======================================================================
@@ -0,0 +1,48 @@
// ======================================================================
//
// ConsoleCommandParserManufacture.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserManufacture_H
#define INCLUDED_ConsoleCommandParserManufacture_H
#include "sharedCommandParser/CommandParser.h"
// ======================================================================
/**
* Commands that are related to scripts
*/
class ConsoleCommandParserManufacture : public CommandParser
{
public:
ConsoleCommandParserManufacture ();
virtual bool performParsing (const NetworkId & userId,
const StringVector_t & argv,
const String_t & originalCommand,
String_t & result,
const CommandParser * node);
private:
ConsoleCommandParserManufacture (const ConsoleCommandParserManufacture & rhs);
ConsoleCommandParserManufacture & operator= (const ConsoleCommandParserManufacture & rhs);
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserManufacture_H
@@ -0,0 +1,104 @@
// ======================================================================
//
// ConsoleCommandParserMessageTo.cpp
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ConsoleCommandParserMessageTo.h"
#include "UnicodeUtils.h"
#include "serverGame/MessageToQueue.h"
#include "serverGame/ServerObject.h"
#include "serverUtility/ServerClock.h"
#include "sharedObject/NetworkIdManager.h"
//-----------------------------------------------------------------------
static const CommandParser::CmdInfo cmds[] =
{
{"listMessages", 1,"<object id>","Print a list of all the messages queued for the specified object."},
{"cancelMessage", 2,"<object id> <message name>","Cancel all instances of a specific message pending for a specific object. USE WITH CAUTION."},
{"cancelMessageById", 2,"<object id> <message id>","Cancel a specific message pending for a specific object. USE WITH CAUTION."},
{"viewLastKnownLocations", 0,"","Print a list of the last known locations of objects."},
{"viewScheduler", 0,"","Print the state of the object scheduler in MessageToQueue."},
{"", 0, "", ""} // this must be last
};
ConsoleCommandParserMessageTo::ConsoleCommandParserMessageTo() :
CommandParser ("messageto", 0, "...", "commands for the MessageTo system", 0)
{
createDelegateCommands (cmds);
}
//-----------------------------------------------------------------------
bool ConsoleCommandParserMessageTo::performParsing (const NetworkId & /*userId*/, const StringVector_t & argv, const String_t & /* originalMessage */, String_t & result, const CommandParser *)
{
if (isCommand( argv [0], "viewLastKnownLocations"))
{
result += Unicode::narrowToWide(MessageToQueue::getInstance().debugGetLastKnownLocations());
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
if (isCommand( argv [0], "viewScheduler"))
{
char temp[256];
snprintf(temp,sizeof(temp),"Current time is %li\n",ServerClock::getInstance().getGameTimeSeconds());
result += Unicode::narrowToWide(temp);
result += Unicode::narrowToWide(MessageToQueue::getInstance().debugGetSchedulerData());
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
if (isCommand( argv [0], "listMessages"))
{
NetworkId networkId(Unicode::wideToNarrow (argv[1]));
ServerObject const * const object = safe_cast<ServerObject const *>(NetworkIdManager::getObjectById(networkId));
if (object)
{
char temp[256];
snprintf(temp,sizeof(temp),"Current time is %li\n",ServerClock::getInstance().getGameTimeSeconds());
result += Unicode::narrowToWide(temp);
result += Unicode::narrowToWide(object->debugGetMessageToList());
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else
result += getErrorMessage(argv[0],ERR_INVALID_OBJECT);
}
if (isCommand( argv [0], "cancelMessage"))
{
NetworkId networkId(Unicode::wideToNarrow (argv[1]));
std::string message(Unicode::wideToNarrow (argv[2]));
ServerObject * const object = safe_cast<ServerObject *>(NetworkIdManager::getObjectById(networkId));
if (object)
{
char buffer[255];
snprintf(buffer,sizeof(buffer)-1,"%i messages cancelled\n", object->cancelMessageTo(message));
buffer[sizeof(buffer)-1]='\0';
result += Unicode::narrowToWide(buffer);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else
result += getErrorMessage(argv[0],ERR_INVALID_OBJECT);
}
if (isCommand( argv [0], "cancelMessageById"))
{
NetworkId networkId(Unicode::wideToNarrow (argv[1]));
NetworkId messageId(Unicode::wideToNarrow (argv[2]));
ServerObject * const object = safe_cast<ServerObject *>(NetworkIdManager::getObjectById(networkId));
if (object)
{
char buffer[255];
snprintf(buffer,sizeof(buffer)-1,"%i messages cancelled\n", object->cancelMessageToByMessageId(messageId));
buffer[sizeof(buffer)-1]='\0';
result += Unicode::narrowToWide(buffer);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else
result += getErrorMessage(argv[0],ERR_INVALID_OBJECT);
}
return true;
}
//-----------------------------------------------------------------------
@@ -0,0 +1,32 @@
// ======================================================================
//
// ConsoleCommandParserMessageTo.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserMessageTo_H
#define INCLUDED_ConsoleCommandParserMessageTo_H
#include "sharedCommandParser/CommandParser.h"
// ======================================================================
/**
* Commands that are related to the MessageTo system.
*/
class ConsoleCommandParserMessageTo : public CommandParser
{
public:
ConsoleCommandParserMessageTo ();
virtual bool performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node);
private:
ConsoleCommandParserMessageTo (const ConsoleCommandParserMessageTo & rhs);
ConsoleCommandParserMessageTo & operator= (const ConsoleCommandParserMessageTo & rhs);
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserMessageTo_H
@@ -0,0 +1,236 @@
// ======================================================================
//
// ConsoleCommandParserMoney.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ConsoleCommandParserMoney.h"
#include "serverGame/ConfigServerGame.h"
#include "serverGame/CreatureObject.h"
#include "serverGame/PlayerCreatureController.h"
#include "serverGame/PlayerObject.h"
#include "serverGame/ServerObject.h"
#include "sharedFoundation/FormattedString.h"
#include "sharedObject/NetworkIdManager.h"
#include "UnicodeUtils.h"
#include <stdio.h>
// ======================================================================
static const CommandParser::CmdInfo cmds[] =
{
{"balance",1,"<oid>","Show how much money an object has (cash and bank)."},
{"bankTransfer",3,"<source oid> <target oid> <amount>","Transfers bank credits from one object to another."},
{"cashTransfer",3,"<source oid> <target oid> <amount>","Transfers cash from one object to another."},
{"deposit",2,"<oid> <amount>","Deposit money to the bank."},
{"namedTransfer",3,"<source oid> <target account> <amount>","Transfers bank credits from an object to a named account."},
{"withdraw",2,"<oid> <amount>","Withdraw money from the bank."},
{"setGalacticReserve",2,"<oid> <amount>","Sets the galactic reserve balance (in billion of credits) for the specified player character object."},
{"", 0, "", ""} // this must be last
};
//-----------------------------------------------------------------
ConsoleCommandParserMoney::ConsoleCommandParserMoney (void) :
CommandParser ("money", 0, "...", "Money related commands.", 0)
{
createDelegateCommands (cmds);
}
//-----------------------------------------------------------------
bool ConsoleCommandParserMoney::performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node)
{
NOT_NULL (node);
UNREF (userId);
UNREF(originalCommand);
//-----------------------------------------------------------------
if (isAbbrev( argv [0], "cashTransfer"))
{
NetworkId sourceId(Unicode::wideToNarrow (argv[1]));
NetworkId targetId(Unicode::wideToNarrow (argv[2]));
int amount(strtoul(Unicode::wideToNarrow (argv[3]).c_str (), NULL, 10));
ServerObject* source = dynamic_cast<ServerObject*>(NetworkIdManager::getObjectById(sourceId));
if (!source)
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
return true;
}
if (source->transferCashTo(targetId,amount))
result += getErrorMessage(argv[0], ERR_SUCCESS);
else
result += getErrorMessage(argv[0], ERR_INVALID_CONTAINER_TRANSFER);
}
else if (isAbbrev( argv [0], "bankTransfer"))
{
NetworkId sourceId(Unicode::wideToNarrow (argv[1]));
NetworkId targetId(Unicode::wideToNarrow (argv[2]));
int amount(strtoul(Unicode::wideToNarrow (argv[3]).c_str (), NULL, 10));
ServerObject* source = dynamic_cast<ServerObject*>(NetworkIdManager::getObjectById(sourceId));
if (!source)
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
return true;
}
if (source->transferBankCreditsTo(targetId,amount))
result += getErrorMessage(argv[0], ERR_SUCCESS);
else
result += getErrorMessage(argv[0], ERR_INVALID_CONTAINER_TRANSFER);
}
else if (isAbbrev( argv [0], "namedTransfer"))
{
NetworkId sourceId(Unicode::wideToNarrow (argv[1]));
int amount(strtol(Unicode::wideToNarrow (argv[3]).c_str (), NULL, 10));
ServerObject* source = dynamic_cast<ServerObject*>(NetworkIdManager::getObjectById(sourceId));
if (!source)
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
return true;
}
if (amount > 0)
{
if (source->transferBankCreditsTo(Unicode::wideToNarrow(argv[2]),amount))
result += getErrorMessage(argv[0], ERR_SUCCESS);
else
result += getErrorMessage(argv[0], ERR_INVALID_CONTAINER_TRANSFER);
}
else
{
if (source->transferBankCreditsFrom(Unicode::wideToNarrow(argv[2]),-amount))
result += getErrorMessage(argv[0], ERR_SUCCESS);
else
result += getErrorMessage(argv[0], ERR_INVALID_CONTAINER_TRANSFER);
}
}
else if (isAbbrev( argv [0], "withdraw"))
{
NetworkId sourceId(Unicode::wideToNarrow (argv[1]));
int amount(strtoul(Unicode::wideToNarrow (argv[2]).c_str (), NULL, 10));
ServerObject* source = dynamic_cast<ServerObject*>(NetworkIdManager::getObjectById(sourceId));
if (!source)
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
return true;
}
if (source->withdrawCashFromBank(amount))
result += getErrorMessage(argv[0], ERR_SUCCESS);
else
result += getErrorMessage(argv[0], ERR_INVALID_CONTAINER_TRANSFER);
}
else if (isAbbrev( argv [0], "deposit"))
{
NetworkId sourceId(Unicode::wideToNarrow (argv[1]));
int amount(strtoul(Unicode::wideToNarrow (argv[2]).c_str (), NULL, 10));
ServerObject* source = dynamic_cast<ServerObject*>(NetworkIdManager::getObjectById(sourceId));
if (!source)
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
return true;
}
if (source->depositCashToBank(amount))
result += getErrorMessage(argv[0], ERR_SUCCESS);
else
result += getErrorMessage(argv[0], ERR_INVALID_CONTAINER_TRANSFER);
}
else if (isAbbrev( argv [0], "balance"))
{
NetworkId objectId(Unicode::wideToNarrow (argv[1]));
ServerObject const * const object = dynamic_cast<ServerObject*>(NetworkIdManager::getObjectById(objectId));
if (!object)
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
return true;
}
char buffer[30];
sprintf(buffer,"%i",object->getCashBalance());
result += Unicode::narrowToWide("Cash ") + Unicode::narrowToWide(buffer) + Unicode::narrowToWide("\n");
sprintf(buffer,"%i",object->getBankBalance());
result += Unicode::narrowToWide("Bank ") + Unicode::narrowToWide(buffer) + Unicode::narrowToWide("\n");
sprintf(buffer,"%i",object->getTotalMoney());
result += Unicode::narrowToWide("Total ") + Unicode::narrowToWide(buffer) + Unicode::narrowToWide("\n");
PlayerObject const * const po = PlayerCreatureController::getPlayerObject(object->asCreatureObject());
if (po)
{
sprintf(buffer,"%i",static_cast<int>(po->getGalacticReserveDeposit()));
result += Unicode::narrowToWide("Galactic Reserve ") + Unicode::narrowToWide(buffer) + Unicode::narrowToWide("\n");
}
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isAbbrev( argv [0], "setGalacticReserve"))
{
int const newGalacticReserve(strtoul(Unicode::wideToNarrow (argv[2]).c_str (), NULL, 10));
if ((newGalacticReserve < 0) || (newGalacticReserve > ConfigServerGame::getMaxGalacticReserveDepositBillion()))
{
result += Unicode::narrowToWide(FormattedString<1024>().sprintf("specified galactic reserve balance (%d) must be in the (inclusive) range (0, %d)\n", newGalacticReserve, ConfigServerGame::getMaxGalacticReserveDepositBillion()));
return true;
}
NetworkId const id(Unicode::wideToNarrow (argv[1]));
ServerObject * const so = dynamic_cast<ServerObject*>(NetworkIdManager::getObjectById(id));
if (!so)
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
return true;
}
PlayerObject * const po = PlayerCreatureController::getPlayerObject(so->asCreatureObject());
if (!po)
{
result += Unicode::narrowToWide(FormattedString<1024>().sprintf("object (%s) is not a player character object\n", so->getNetworkId().getValueString().c_str()));
return true;
}
if (!so->isAuthoritative() || !po->isAuthoritative())
{
result += Unicode::narrowToWide(FormattedString<1024>().sprintf("object (%s) is not authoritative\n", so->getNetworkId().getValueString().c_str()));
return true;
}
int currentGalacticReserve = 0;
if (!so->getObjVars().getItem("galactic_reserve", currentGalacticReserve))
{
currentGalacticReserve = 0;
}
if (currentGalacticReserve != newGalacticReserve)
{
result += Unicode::narrowToWide(FormattedString<1024>().sprintf("modifying player character object (%s) galactic reserve balance from (%d) to (%d)\n", so->getNetworkId().getValueString().c_str(), currentGalacticReserve, newGalacticReserve));
if (newGalacticReserve > 0)
so->setObjVarItem("galactic_reserve", newGalacticReserve);
else
so->removeObjVarItem("galactic_reserve");
po->depersistGalacticReserveDeposit();
}
else
{
result += Unicode::narrowToWide(FormattedString<1024>().sprintf("player character object (%s) already has a galactic reserve balance of (%d)\n", so->getNetworkId().getValueString().c_str(), newGalacticReserve));
}
}
else
{
result += getErrorMessage(argv[0], ERR_NO_HANDLER);
}
return true;
} // ConsoleCommandParserMoney::performParsing
// ======================================================================
@@ -0,0 +1,32 @@
// ======================================================================
//
// ConsoleCommandParserMoney.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserMoney_H
#define INCLUDED_ConsoleCommandParserMoney_H
#include "sharedCommandParser/CommandParser.h"
// ======================================================================
/**
* Commands that are related to the resource system.
*/
class ConsoleCommandParserMoney : public CommandParser
{
public:
ConsoleCommandParserMoney ();
virtual bool performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node);
private:
ConsoleCommandParserMoney (const ConsoleCommandParserMoney & rhs);
ConsoleCommandParserMoney & operator= (const ConsoleCommandParserMoney & rhs);
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserMoney_H
@@ -0,0 +1,106 @@
// ======================================================================
//
// ConsoleCommandParserNpc.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ConsoleCommandParserNpc.h"
#include "UnicodeUtils.h"
#include "serverGame/CreatureObject.h"
#include "sharedFoundation/GameControllerMessage.h"
#include "serverGame/GameServer.h"
#include "serverGame/ServerWorld.h"
// ======================================================================
static const CommandParser::CmdInfo cmds[] =
{
{"hail", 1, "<oid>", "Hail an NPC"},
{"goodbye", 0, "", "End the current conversation"},
{"respond", 1, "<response #>", "Select a conversation response"},
{"", 0, "", ""} // this must be last
};
//-----------------------------------------------------------------
ConsoleCommandParserNpc::ConsoleCommandParserNpc (void) :
CommandParser ("npc", 0, "...", "NPC related commands.", 0)
{
createDelegateCommands (cmds);
}
//-----------------------------------------------------------------
bool ConsoleCommandParserNpc::performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node)
{
NOT_NULL (node);
UNREF (userId);
UNREF(originalCommand);
//-----------------------------------------------------------------
if (isAbbrev( argv [0], "hail"))
{
TangibleObject * const playerObject = safe_cast<TangibleObject *>(ServerWorld::findObjectByNetworkId(userId));
NetworkId const oid(Unicode::wideToNarrow(argv[1]));
ServerObject * const object = ServerWorld::findObjectByNetworkId(oid);
if (object == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
TangibleObject * const npc = object->asTangibleObject();
if (npc == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
playerObject->startNpcConversation(*npc, NULL, NpcConversationData::CS_Player, 0);
result += getErrorMessage (argv[0], ERR_SUCCESS);
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "goodbye"))
{
TangibleObject * const playerObject = safe_cast<TangibleObject *>(ServerWorld::findObjectByNetworkId(userId));
playerObject->endNpcConversation();
result += getErrorMessage (argv[0], ERR_SUCCESS);
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "respond"))
{
TangibleObject * const playerObject = safe_cast<TangibleObject *>(ServerWorld::findObjectByNetworkId(userId));
int const response = strtol(Unicode::wideToNarrow(argv[1]).c_str (), NULL, 10);
playerObject->respondToNpc(response);
result += getErrorMessage (argv[0], ERR_SUCCESS);
}
//-----------------------------------------------------------------
else
{
result += getErrorMessage(argv[0], ERR_NO_HANDLER);
}
return true;
}
// ======================================================================
@@ -0,0 +1,48 @@
// ======================================================================
//
// ConsoleCommandParserNpc.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserNpc_H
#define INCLUDED_ConsoleCommandParserNpc_H
#include "sharedCommandParser/CommandParser.h"
// ======================================================================
/**
* Commands that are related to scripts
*/
class ConsoleCommandParserNpc : public CommandParser
{
public:
ConsoleCommandParserNpc ();
virtual bool performParsing (const NetworkId & userId,
const StringVector_t & argv,
const String_t & originalCommand,
String_t & result,
const CommandParser * node);
private:
ConsoleCommandParserNpc (const ConsoleCommandParserNpc & rhs);
ConsoleCommandParserNpc & operator= (const ConsoleCommandParserNpc & rhs);
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserNpc_H
@@ -0,0 +1,66 @@
// ======================================================================
//
// ConsoleCommandParserObject.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserObject_H
#define INCLUDED_ConsoleCommandParserObject_H
#include "sharedCommandParser/CommandParser.h"
#include "sharedMessageDispatch/Emitter.h"
class NetworkId;
class ServerObject;
class Transform;
class Vector;
// ======================================================================
/**
* Commands that are related to scripts
*/
class ConsoleCommandParserObject :
public CommandParser,
public MessageDispatch::Emitter
{
public:
ConsoleCommandParserObject ();
virtual bool performParsing (const NetworkId & userId,
const StringVector_t & argv,
const String_t & originalCommand,
String_t & result,
const CommandParser * node);
private:
ConsoleCommandParserObject (const ConsoleCommandParserObject & rhs);
ConsoleCommandParserObject & operator= (const ConsoleCommandParserObject & rhs);
bool performParsing2 (const NetworkId & userId,
const StringVector_t & argv,
const String_t & originalCommand,
String_t & result,
const CommandParser * node);
bool moveObject (const NetworkId & oid, const Vector & position_w, const NetworkId & targetContainer, const Vector & position_p) const;
bool rotateObject (const NetworkId & oid, real yaw, real pitch, real roll) const;
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserObject_H
@@ -0,0 +1,751 @@
// ======================================================================
//
// ConsoleCommandParserObjvar.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ConsoleCommandParserObjvar.h"
#include "UnicodeUtils.h"
#include "serverGame/CreatureObject.h"
#include "serverGame/ServerObject.h"
#include "serverGame/ServerWorld.h"
#include "sharedFoundation/DynamicVariable.h"
#include "sharedFoundation/DynamicVariableList.h"
#include "sharedFoundation/DynamicVariableListNestedList.h"
#include "sharedFoundation/DynamicVariableLocationData.h"
#include "sharedFoundation/FormattedString.h"
#include "sharedFoundation/NetworkId.h"
#include "sharedGame/GameObjectTypes.h"
#include <cstdio>
// ======================================================================
//TODO: A lot of this file could be replaced by calls to ObjectVariable::debugPrint(), but need to make sure the formatting is consistent whith
// what the god client expects
// value types for set objvar
enum
{
INT_ARGUMENT,
REAL_ARGUMENT,
STRING_ARGUMENT
};
static const CommandParser::CmdInfo cmds[] =
{
{"set", 3, "<oid> <name> <value>", "Sets an objvar for an object."},
{"setlist",2, "<oid> <name>", "Creates a new objvar list."},
{"get", 2, "<oid> <name>", "Prints the value of an objvar."},
{"list", 0, "", "Lists all the objvars on an object."},
{"listWithPacking", 1, "<oid>", "Lists all the objvars on an object, showing which are packed into the OBJECTS table in the database."},
{"remove", 2, "<oid> <name>", "Removes an objvar from an object."},
{"", 0, "", ""} // this must be last
};
//-----------------------------------------------------------------
static std::string getDebugString(Transform const &tr)
{
Vector i(tr.getLocalFrameI_p());
Vector j(tr.getLocalFrameJ_p());
Vector k(tr.getLocalFrameK_p());
Vector p(tr.getPosition_p());
std::string ret("\n");
char buf[256];
snprintf(buf, 256, "[%g %g %g %g]\n", static_cast<double>(i.x), static_cast<double>(j.x), static_cast<double>(k.x), static_cast<double>(p.x));
ret += buf;
snprintf(buf, 256, "[%g %g %g %g]\n", static_cast<double>(i.y), static_cast<double>(j.y), static_cast<double>(k.y), static_cast<double>(p.y));
ret += buf;
snprintf(buf, 256, "[%g %g %g %g]\n", static_cast<double>(i.z), static_cast<double>(j.z), static_cast<double>(k.z), static_cast<double>(p.z));
ret += buf;
return ret;
}
//-----------------------------------------------------------------
static std::string getDebugString(Vector const &v)
{
char buf[256];
snprintf(buf, 256, "[%g %g %g]", static_cast<double>(v.x), static_cast<double>(v.y), static_cast<double>(v.z));
return std::string(buf);
}
//-----------------------------------------------------------------
ConsoleCommandParserObjvar::ConsoleCommandParserObjvar (void) :
CommandParser ("objvar", 0, "...", "Objvar related commands.", 0)
{
createDelegateCommands (cmds);
}
//-----------------------------------------------------------------
bool ConsoleCommandParserObjvar::performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node)
{
NOT_NULL (node);
UNREF (userId);
UNREF(originalCommand);
//-----------------------------------------------------------------
if (isAbbrev( argv [0], "set"))
{
NetworkId oid (Unicode::wideToNarrow (argv[1]));
ServerObject* object = ServerWorld::findObjectByNetworkId(oid);
if (object == NULL)
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
return true;
}
const Unicode::NarrowString &objvarName = Unicode::wideToNarrow(argv[2]);
// can't dork around with the "resourceData" objvar on a resource container
// or a manufacturing schematic or an incubator, since it contains resource
// data for "imported" resources that *MUST* remain the same as the
// corresponding objvar on every other resource container or a manufacturing
// schematic that references that "imported" resource.
if (objvarName == "power.resourceData")
{
const char *objectTemplateName = object->getObjectTemplateName();
if (objectTemplateName && (std::string(objectTemplateName) == "object/tangible/crafting/station/incubator_station.iff"))
{
result += Unicode::narrowToWide("You cannot set the \"resourceData\" objvar on an incubator\n");
return true;
}
}
int const gameObjectType = object->getGameObjectType();
if (GameObjectTypes::isTypeOf(gameObjectType, SharedObjectTemplate::GOT_resource_container) || (gameObjectType == SharedObjectTemplate::GOT_data_manufacturing_schematic))
{
std::string::size_type const pos = objvarName.rfind("resourceData");
if (pos == (objvarName.size() - sizeof("resourceData") + 1))
{
result += Unicode::narrowToWide("You cannot set the \"resourceData\" objvar on a resource crate or a manufacturing schematic\n");
return true;
}
}
if (!object->getObjVars().hasItem(objvarName))
{
// create a new objvar, deduce type from argument string
const Unicode::NarrowString &nString = Unicode::wideToNarrow(argv[3]);
switch (getArgumentType(nString))
{
case INT_ARGUMENT:
object->setObjVarItem(objvarName, atoi(nString.c_str()));
break;
case REAL_ARGUMENT:
object->setObjVarItem(objvarName, static_cast<real>(atof(nString.c_str())));
break;
case STRING_ARGUMENT:
object->setObjVarItem(objvarName, argv[3]);
break;
default:
break;
}
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else
{
// verify that the argument passed in is the same type as the objvar
switch (object->getObjVars().getType(objvarName))
{
case DynamicVariable::INT:
{
const Unicode::NarrowString &nString = Unicode::wideToNarrow(argv[3]);
if (getArgumentType(nString) == INT_ARGUMENT)
{
object->setObjVarItem(objvarName, atoi(nString.c_str()));
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else
result += getErrorMessage(argv[0], ERR_INVALID_INT_OBJVAR);
}
break;
case DynamicVariable::INT_ARRAY:
result += getErrorMessage(argv[0], ERR_CMD_NOT_FOUND);
break;
case DynamicVariable::REAL:
{
const Unicode::NarrowString &nString = Unicode::wideToNarrow(argv[3]);
if (getArgumentType(nString) == REAL_ARGUMENT)
{
object->setObjVarItem(objvarName, static_cast<real>(atof(nString.c_str())));
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else
result += getErrorMessage(argv[0], ERR_INVALID_REAL_OBJVAR);
}
break;
case DynamicVariable::REAL_ARRAY:
result += getErrorMessage(argv[0], ERR_CMD_NOT_FOUND);
break;
case DynamicVariable::STRING:
{
object->setObjVarItem(objvarName, argv[3]);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
break;
case DynamicVariable::STRING_ARRAY:
result += getErrorMessage(argv[0], ERR_CMD_NOT_FOUND);
break;
case DynamicVariable::NETWORK_ID:
case DynamicVariable::NETWORK_ID_ARRAY:
case DynamicVariable::LOCATION:
case DynamicVariable::LOCATION_ARRAY:
case DynamicVariable::STRING_ID:
case DynamicVariable::STRING_ID_ARRAY:
case DynamicVariable::TRANSFORM:
case DynamicVariable::TRANSFORM_ARRAY:
case DynamicVariable::VECTOR:
case DynamicVariable::VECTOR_ARRAY:
result += getErrorMessage(argv[0], ERR_CMD_NOT_FOUND);
break;
case DynamicVariable::LIST:
result += getErrorMessage(argv[0], ERR_LIST_OBJVAR_NOT_SUPPORTED);
break;
}
}
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "setlist"))
{
// This is now a no-op, but left in to avoid breaking the god client
// NetworkId oid (Unicode::wideToNarrow (argv[1]));
// ServerObject* object = ServerWorld::findObjectByNetworkId(oid);
// if (object == NULL)
// {
// result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
// return true;
// }
// const Unicode::NarrowString &listName = Unicode::wideToNarrow(argv[2]);
// object->addNestedObjVarList(listName);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "get"))
{
NetworkId oid (Unicode::wideToNarrow(argv[1]));
ServerObject* object = ServerWorld::findObjectByNetworkId(oid);
if (object == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
std::string objvarName(Unicode::wideToNarrow(argv[2]));
if (object->getObjVars().hasItem(objvarName))
{
char buffer[32];
switch (object->getObjVars().getType(objvarName))
{
case DynamicVariable::INT:
{
int value = 0;
object->getObjVars().getItem(objvarName,value);
IGNORE_RETURN(_itoa(value, buffer, 10));
result += Unicode::narrowToWide(buffer);
}
break;
case DynamicVariable::INT_ARRAY:
result += getErrorMessage(argv[0], ERR_CMD_NOT_FOUND);
break;
case DynamicVariable::REAL:
{
float value = 0;
object->getObjVars().getItem(objvarName,value);
sprintf(buffer, "%f", value);
result += Unicode::narrowToWide(buffer);
}
break;
case DynamicVariable::REAL_ARRAY:
result += getErrorMessage(argv[0], ERR_CMD_NOT_FOUND);
break;
case DynamicVariable::STRING:
{
Unicode::String value;
object->getObjVars().getItem(objvarName,value);
result += value;
}
break;
case DynamicVariable::STRING_ARRAY:
result += getErrorMessage(argv[0], ERR_CMD_NOT_FOUND);
break;
case DynamicVariable::NETWORK_ID:
case DynamicVariable::NETWORK_ID_ARRAY:
case DynamicVariable::LOCATION:
case DynamicVariable::LOCATION_ARRAY:
case DynamicVariable::STRING_ID:
case DynamicVariable::STRING_ID_ARRAY:
case DynamicVariable::TRANSFORM:
case DynamicVariable::TRANSFORM_ARRAY:
case DynamicVariable::VECTOR:
case DynamicVariable::VECTOR_ARRAY:
result += getErrorMessage(argv[0], ERR_CMD_NOT_FOUND);
break;
case DynamicVariable::LIST:
char buf[256];
sprintf (buf, "objvar list\n");
result += Unicode::narrowToWide(buf);
listObjvars(DynamicVariableList::NestedList(object->getObjVars(),objvarName),
result, 0, false);
break;
}
}
else
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJVAR);
}
}
//-----------------------------------------------------------------
else if (isAbbrev(argv[0], "list"))
{
ServerObject * const userServerObject = ServerWorld::findObjectByNetworkId(userId);
if (userServerObject != NULL)
{
NetworkId specifiedNetworkId;
if (argv.size () > 1)
{
specifiedNetworkId = NetworkId(Unicode::wideToNarrow(argv[1]));
}
else
{
CreatureObject * const userCreatureObject = CreatureObject::asCreatureObject(userServerObject);
if (userCreatureObject != NULL)
{
specifiedNetworkId = userCreatureObject->getLookAtTarget();
}
}
ServerObject * const specifiedServerObject = ServerWorld::findObjectByNetworkId(specifiedNetworkId);
if (specifiedServerObject != NULL)
{
DynamicVariableList const & objVarList = specifiedServerObject->getObjVars();
FormattedString<1024> fs;
result += Unicode::narrowToWide(fs.sprintf("objvar list for object %s, num %d\n", specifiedServerObject->getNetworkId().getValueString().c_str(), objVarList.size()));
listObjvars(DynamicVariableList::NestedList(objVarList), result, 0, false);
result += getErrorMessage(argv[0], ERR_SUCCESS);
return true;
}
}
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
}
// ----------------------------------------------------------------------
else if (isAbbrev(argv[0], "listWithPacking"))
{
NetworkId oid = NetworkId(Unicode::wideToNarrow(argv[1]));
ServerObject* object = ServerWorld::findObjectByNetworkId(oid);
if (object == NULL)
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
return true;
}
char buf[256];
sprintf (buf, "objvar list\n");
result += Unicode::narrowToWide(buf);
listObjvars(DynamicVariableList::NestedList(object->getObjVars()), result, 0, true);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
//-----------------------------------------------------------------
else if (isAbbrev(argv[0], "remove"))
{
NetworkId oid = NetworkId(Unicode::wideToNarrow(argv[1]));
ServerObject* object = ServerWorld::findObjectByNetworkId(oid);
if (object == NULL)
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
return true;
}
const Unicode::NarrowString &objvarName = Unicode::wideToNarrow(argv[2]);
// can't dork around with the "resourceData" objvar on a resource container
// or a manufacturing schematic or an incubator, since it contains resource
// data for "imported" resources that *MUST* remain the same as the
// corresponding objvar on every other resource container or a manufacturing
// schematic that references that "imported" resource.
if (objvarName == "power.resourceData")
{
const char *objectTemplateName = object->getObjectTemplateName();
if (objectTemplateName && (std::string(objectTemplateName) == "object/tangible/crafting/station/incubator_station.iff"))
{
result += Unicode::narrowToWide("You cannot remove the \"resourceData\" objvar on an incubator\n");
return true;
}
}
int const gameObjectType = object->getGameObjectType();
if (GameObjectTypes::isTypeOf(gameObjectType, SharedObjectTemplate::GOT_resource_container) || (gameObjectType == SharedObjectTemplate::GOT_data_manufacturing_schematic))
{
std::string::size_type const pos = objvarName.rfind("resourceData");
if (pos == (objvarName.size() - sizeof("resourceData") + 1))
{
result += Unicode::narrowToWide("You cannot remove the \"resourceData\" objvar on a resource crate or a manufacturing schematic\n");
return true;
}
}
object->removeObjVarItem(objvarName);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
//-----------------------------------------------------------------
else
{
result += getErrorMessage(argv[0], ERR_NO_HANDLER);
}
return true;
} // ConsoleCommandParserObjvar::performParsing
//-----------------------------------------------------------------
/**
* Determines the data type of an argument string.
*
* @param arg the string to analize
*
* @return INT_ARGUMENT if the string is all digits,
* REAL_ARGUMENT if the string is all digits plus one '.',
* STRING_ARGUMENT for everthing else
*/
int ConsoleCommandParserObjvar::getArgumentType(const Unicode::NarrowString &arg) const
{
bool foundDecimal = false;
size_t const count = arg.size();
for (size_t i = 0; i < count; ++i)
{
if (!isdigit(arg[i]))
{
if ((i == 0) && (arg[i] == '-') && (count > 1))
continue;
if (arg[i] != '.' || foundDecimal)
return STRING_ARGUMENT;
foundDecimal = true;
}
}
if (foundDecimal)
return REAL_ARGUMENT;
return INT_ARGUMENT;
} // ConsoleCommandParserObjvar::getArgumentType
//-----------------------------------------------------------------
/**
* Prints out to a string all the objvars in an objvar list.
*
* @param objvarList the list to print
* @param result string to print the list to
* @param tabCount how many tabs to print before the data
*/
void ConsoleCommandParserObjvar::listObjvars(const DynamicVariableList::NestedList &objvarList, String_t &result, int tabCount, bool withPackingData)
{
static const String_t space = Unicode::narrowToWide(" ");
static const String_t spaces = Unicode::narrowToWide(" ");
static const String_t newline = Unicode::narrowToWide("\n");
static const String_t tabs = Unicode::narrowToWide("\t");
static const String_t islist = Unicode::narrowToWide("<list>\n");
char buffer[32];
for (DynamicVariableList::NestedList::const_iterator objVar(objvarList.begin()); objVar!=objvarList.end(); ++objVar)
{
// pad the objvar
for (int j = 0; j < tabCount; ++j)
result += spaces;
// print the name
result += Unicode::narrowToWide(objVar.getName());
result += tabs;
if (withPackingData)
{
char buffer[100];
sprintf(buffer,"%i",objVar.getPackedPosition());
result += Unicode::narrowToWide(std::string(buffer));
result += tabs;
}
// print the data
switch (objVar.getType())
{
case DynamicVariable::INT:
{
int value=0;
objVar.getValue(value);
IGNORE_RETURN(_itoa(value, buffer, 10));
result += Unicode::narrowToWide(buffer);
result += newline;
}
break;
case DynamicVariable::INT_ARRAY:
{
std::vector<int> value;
objVar.getValue(value);
std::string text = "[";
size_t count = value.size();
for (size_t j = 0; j < count; ++j)
{
IGNORE_RETURN(_itoa(value[j], buffer, 10));
text += buffer;
if (j + 1 < count)
text += ", ";
}
text += "]\n";
result += Unicode::narrowToWide(text);
}
break;
case DynamicVariable::REAL:
{
real value = 0;
objVar.getValue(value);
sprintf(buffer, "%f\n", value);
result += Unicode::narrowToWide(buffer);
}
break;
case DynamicVariable::REAL_ARRAY:
{
std::vector<real> value;
objVar.getValue(value);
std::string text = "[";
size_t count = value.size();
for (size_t j = 0; j < count; ++j)
{
sprintf(buffer, "%f", value[j]);
text += buffer;
if (j + 1 < count)
text += ", ";
}
text += "]\n";
result += Unicode::narrowToWide(text);
}
break;
case DynamicVariable::STRING:
{
Unicode::String value;
objVar.getValue(value);
result += value;
result += newline;
}
break;
case DynamicVariable::STRING_ARRAY:
{
std::vector<Unicode::String> value;
objVar.getValue(value);
int k;
int nameLength = objVar.getName().size();
result += Unicode::narrowToWide("[\n");
size_t count = value.size();
for (size_t j = 0; j < count; ++j)
{
for (k = 0; k < tabCount; ++k)
result += spaces;
for (k = 0; k < nameLength; ++k)
result += space;
result += tabs;
result += value[j];
result += newline;
}
for (k = 0; k < tabCount; ++k)
result += spaces;
for (k = 0; k < nameLength; ++k)
result += space;
result += tabs;
result += Unicode::narrowToWide("]\n");
}
break;
case DynamicVariable::NETWORK_ID:
{
NetworkId value;
objVar.getValue(value);
result += Unicode::narrowToWide("(NetworkId)");
result += Unicode::narrowToWide(value.getValueString());
result += newline;
}
break;
case DynamicVariable::NETWORK_ID_ARRAY:
{
std::vector<NetworkId> value;
objVar.getValue(value);
std::string text = "(NetworkId)[";
size_t count = value.size();
for (size_t j = 0; j < count; ++j)
{
text += value[j].getValueString();
if (j + 1 < count)
text += ", ";
}
text += "]\n";
result += Unicode::narrowToWide(text);
}
break;
case DynamicVariable::LOCATION:
{
DynamicVariableLocationData value;
objVar.getValue(value);
result += Unicode::narrowToWide("(x=");
sprintf(buffer, "%f", value.pos.x);
result += Unicode::narrowToWide(buffer);
result += Unicode::narrowToWide(", y=");
sprintf(buffer, "%f", value.pos.y);
result += Unicode::narrowToWide(buffer);
result += Unicode::narrowToWide(", z=");
sprintf(buffer, "%f", value.pos.z);
result += Unicode::narrowToWide(buffer);
result += Unicode::narrowToWide(", scene=");
result += Unicode::narrowToWide(value.scene);
result += Unicode::narrowToWide(", cell=");
result += Unicode::narrowToWide(value.cell.getValueString());
result += Unicode::narrowToWide(")\n");
}
break;
case DynamicVariable::LOCATION_ARRAY:
{
std::vector<DynamicVariableLocationData> value;
objVar.getValue(value);
int k;
int nameLength = objVar.getName().size();
result += Unicode::narrowToWide("[\n");
size_t count = value.size();
for (size_t j = 0; j < count; ++j)
{
for (k = 0; k < tabCount; ++k)
result += spaces;
for (k = 0; k < nameLength; ++k)
result += space;
result += tabs;
result += Unicode::narrowToWide("(x=");
sprintf(buffer, "%f", value[j].pos.x);
result += Unicode::narrowToWide(buffer);
result += Unicode::narrowToWide(", y=");
sprintf(buffer, "%f", value[j].pos.y);
result += Unicode::narrowToWide(buffer);
result += Unicode::narrowToWide(", z=");
sprintf(buffer, "%f", value[j].pos.z);
result += Unicode::narrowToWide(buffer);
result += Unicode::narrowToWide(", scene=");
result += Unicode::narrowToWide(value[j].scene);
result += Unicode::narrowToWide(", cell=");
result += Unicode::narrowToWide(value[j].cell.getValueString());
result += Unicode::narrowToWide(")\n");
}
for (k = 0; k < tabCount; ++k)
result += spaces;
for (k = 0; k < nameLength; ++k)
result += space;
result += tabs;
result += Unicode::narrowToWide("]\n");
}
break;
case DynamicVariable::LIST:
result += islist;
listObjvars(objVar.getNestedList(),
result, tabCount + 1, withPackingData);
break;
case DynamicVariable::STRING_ID:
{
StringId value;
objVar.getValue(value);
result += Unicode::narrowToWide("(StringId)");
result += Unicode::narrowToWide(value.getDebugString());
result += newline;
}
break;
case DynamicVariable::STRING_ID_ARRAY:
{
std::vector<StringId> value;
objVar.getValue(value);
std::string text = "(StringId)[";
size_t count = value.size();
for (size_t j = 0; j < count; ++j)
{
text += value[j].getDebugString();
if (j + 1 < count)
text += ", ";
}
text += "]\n";
result += Unicode::narrowToWide(text);
}
break;
case DynamicVariable::TRANSFORM:
{
Transform value;
objVar.getValue(value);
result += Unicode::narrowToWide("(Transform)");
result += Unicode::narrowToWide(getDebugString(value));
result += newline;
}
break;
case DynamicVariable::TRANSFORM_ARRAY:
{
std::vector<Transform> value;
objVar.getValue(value);
std::string text = "(Transform)[";
size_t count = value.size();
for (size_t j = 0; j < count; ++j)
{
text += getDebugString(value[j]);
if (j + 1 < count)
text += ", ";
}
text += "]\n";
result += Unicode::narrowToWide(text);
}
break;
case DynamicVariable::VECTOR:
{
Vector value;
objVar.getValue(value);
result += Unicode::narrowToWide("(Vector)");
result += Unicode::narrowToWide(getDebugString(value));
result += newline;
}
break;
case DynamicVariable::VECTOR_ARRAY:
{
std::vector<Vector> value;
objVar.getValue(value);
std::string text = "(Vector)[";
size_t count = value.size();
for (size_t j = 0; j < count; ++j)
{
text += getDebugString(value[j]);
if (j + 1 < count)
text += ", ";
}
text += "]\n";
result += Unicode::narrowToWide(text);
}
break;
}
}
} // ConsoleCommandParserObjvar::listObjvars
// ======================================================================
@@ -0,0 +1,36 @@
// ======================================================================
//
// ConsoleCommandParserObjvar.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserObjvar_H
#define INCLUDED_ConsoleCommandParserObjvar_H
#include "sharedCommandParser/CommandParser.h"
#include "sharedFoundation/DynamicVariableList.h"
// ======================================================================
/**
* Commands that are related to objvars
*/
class ConsoleCommandParserObjvar : public CommandParser
{
public:
ConsoleCommandParserObjvar ();
virtual bool performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node);
private:
ConsoleCommandParserObjvar (const ConsoleCommandParserObjvar & rhs);
ConsoleCommandParserObjvar & operator= (const ConsoleCommandParserObjvar & rhs);
int getArgumentType(const Unicode::NarrowString &arg) const;
void listObjvars(const DynamicVariableList::NestedList &objvarList, String_t &result, int tabCount, bool withPackingData);
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserObjvar_H
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,32 @@
// ======================================================================
//
// ConsoleCommandParserPvp.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserPvp_H
#define INCLUDED_ConsoleCommandParserPvp_H
#include "sharedCommandParser/CommandParser.h"
// ======================================================================
/**
* Commands that are related to the Pvp system.
*/
class ConsoleCommandParserPvp : public CommandParser
{
public:
ConsoleCommandParserPvp ();
virtual bool performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node);
private:
ConsoleCommandParserPvp (const ConsoleCommandParserPvp & rhs);
ConsoleCommandParserPvp & operator= (const ConsoleCommandParserPvp & rhs);
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserPvp_H
@@ -0,0 +1,335 @@
// ======================================================================
//
// ConsoleCommandParserResource.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ConsoleCommandParserResource.h"
#include "UnicodeUtils.h"
#include "serverGame/HarvesterInstallationObject.h"
#include "serverGame/PlanetObject.h"
#include "serverGame/ResourceContainerObject.h"
#include "serverGame/ResourceTypeObject.h"
#include "serverGame/ServerResourceClassObject.h"
#include "serverGame/ServerUniverse.h"
#include "serverGame/ServerWorld.h"
#include "serverGame/SurveySystem.h"
#include "sharedFoundation/GameControllerMessage.h"
#include "sharedFoundation/NetworkId.h"
#include "sharedObject/Controller.h"
#include "sharedObject/NetworkIdManager.h"
#include "swgServerNetworkMessages/MessageQueueActivateInstallation.h"
#include "swgServerNetworkMessages/MessageQueueDeactivateInstallation.h"
#include "swgServerNetworkMessages/MessageQueueInstallationHarvest.h"
// ======================================================================
static const CommandParser::CmdInfo cmds[] =
{
{"activate", 2,"<harvester oid> <resource name>","Activates a harvester."},
{"addtocontainer", 4,"<container oid> <resource name> <quantity> <source player id>","Add resources to a container."},
{"fillcontainer", 1,"<container oid> [source player id]", "Fills a resource container with its resource."},
{"recycle", 1,"<container oid>", "Convert a container of resource to the recycled version (for debugging)."},
{"deactivate", 1,"<harvester oid>","Deactivates a harvester."},
{"discardHopper", 1,"<harvester>","Empties the contents of a harvester's hopper."},
{"getSurveyList", 2,"<resource class name> <surveytoolId>","For testing surveys, get the resource list for the survey screen."},
{"harvest", 1,"<harvester oid>","Causes a harvester to collect resources."},
{"name", 2,"<resource type oid> <name>","Set the name of a resource."},
{"pools", 1,"<planet>","List all resource pools on a particular planet."},
{"removefromcontainer", 3,"<container oid> <resource name> <quantity>","Remove resources from a container."},
{"survey", 1,"<resource class name> <resource type name> <survey range> <number of points>","For testing surveys, take a survey."},
{"tree", 0,"","List resource hierarchy."},
{"viewcontainer", 1,"<container object id>","View the contents of a resource container."},
{"deplete", 1,"<resource type oid>","Cause a resource type to deplete."},
{"", 0, "", ""} // this must be last
};
//-----------------------------------------------------------------
ConsoleCommandParserResource::ConsoleCommandParserResource (void) :
CommandParser ("resource", 0, "...", "Resource related commands.", 0)
{
createDelegateCommands (cmds);
}
//-----------------------------------------------------------------
bool ConsoleCommandParserResource::performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node)
{
NOT_NULL (node);
UNREF (userId);
UNREF(originalCommand);
//-----------------------------------------------------------------
if (isCommand( argv [0], "activate"))
{
CachedNetworkId harvester(Unicode::wideToNarrow (argv[1]));
ServerObject* harvesterObject = safe_cast<ServerObject*>(harvester.getObject());
if (harvesterObject == NULL)
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
return true;
}
Controller *const controller = harvesterObject->getController();
NOT_NULL(controller);
controller->appendMessage(static_cast<int>(CM_activateInstallation),0.0f,new MessageQueueActivateInstallation(), GameControllerMessageFlags::SEND | GameControllerMessageFlags::RELIABLE | GameControllerMessageFlags::DEST_AUTH_SERVER);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isCommand( argv [0], "harvest"))
{
CachedNetworkId harvester(Unicode::wideToNarrow (argv[1]));
ServerObject* harvesterObject = safe_cast<ServerObject*>(harvester.getObject());
if (harvesterObject == NULL)
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
return true;
}
//TODO: Make all of these into function calls instead of sending messages
Controller *const controller = harvesterObject->getController();
NOT_NULL(controller);
controller->appendMessage(static_cast<int>(CM_installationHarvest),0.0f,new MessageQueueInstallationHarvest(), GameControllerMessageFlags::SEND | GameControllerMessageFlags::RELIABLE | GameControllerMessageFlags::DEST_AUTH_SERVER);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isCommand( argv [0], "discardHopper"))
{
CachedNetworkId harvester(Unicode::wideToNarrow (argv[1]));
HarvesterInstallationObject* harvesterObject = dynamic_cast<HarvesterInstallationObject*>(harvester.getObject());
if (!harvesterObject)
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
return true;
}
harvesterObject->discardAllHopperContents ();
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isCommand( argv [0], "deactivate"))
{
CachedNetworkId harvester(Unicode::wideToNarrow (argv[1]));
ServerObject* harvesterObject = safe_cast<ServerObject*>(harvester.getObject());
if (harvesterObject == NULL)
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
return true;
}
Controller *const controller = harvesterObject->getController();
NOT_NULL(controller);
controller->appendMessage(static_cast<int>(CM_deactivateInstallation),0.0f,new MessageQueueDeactivateInstallation(), GameControllerMessageFlags::SEND | GameControllerMessageFlags::RELIABLE | GameControllerMessageFlags::DEST_AUTH_SERVER);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isCommand( argv [0], "tree"))
{
ServerUniverse & universe = ServerUniverse::getInstance();
ResourceClassObject * root = 0;
if (argv.size () > 1)
root = universe.getResourceClassByName (Unicode::wideToNarrow (argv [1]));
else
root = universe.getResourceTreeRoot();
if (root)
{
std::string temp;
root->debugOutput(temp);
result += Unicode::narrowToWide(temp);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
}
else if (isCommand( argv [0], "pools"))
{
PlanetObject* planet=ServerUniverse::getInstance().getPlanetByName(Unicode::wideToNarrow(argv[1]));
if (planet)
{
std::string temp;
planet->debugOutputPools(temp);
result += Unicode::narrowToWide(temp);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
}
}
else if (isCommand( argv [0], "name"))
{
NetworkId resourceId(Unicode::wideToNarrow (argv[1]));
ResourceTypeObject * const resource = ServerUniverse::getInstance().getResourceTypeById(resourceId);
if (resource)
{
resource->setName(Unicode::wideToNarrow(argv[2]));
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
}
}
else if (isCommand( argv [0], "viewcontainer"))
{
CachedNetworkId contId (Unicode::wideToNarrow (argv[1]));
ResourceContainerObject* container=dynamic_cast<ResourceContainerObject*>(contId.getObject());
if (container)
{
result += Unicode::narrowToWide(container->debugPrint()+'\n');
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
}
}
else if (isCommand( argv [0], "addtocontainer"))
{
NetworkId const contId (Unicode::wideToNarrow (argv[1]));
ResourceContainerObject * const container = dynamic_cast<ResourceContainerObject*>(NetworkIdManager::getObjectById(contId));
std::string const & resourcePath = Unicode::wideToNarrow(argv[2]);
ResourceTypeObject * const resType = ServerUniverse::getInstance().getResourceTypeByName(resourcePath);
int const amount = strtol(Unicode::wideToNarrow (argv[3]).c_str (), NULL, 10);
NetworkId const source(Unicode::wideToNarrow (argv[4]));
if (container && resType)
{
if (container->addResource(CachedNetworkId(resType->getNetworkId()),amount, source))
result += getErrorMessage(argv[0], ERR_SUCCESS);
else
result += getErrorMessage(argv[0], ERR_INVALID_CONTAINER_TRANSFER);
}
else
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
}
}
else if (isCommand( argv [0], "fillcontainer"))
{
NetworkId contId (Unicode::wideToNarrow (argv[1]));
ResourceContainerObject* container=dynamic_cast<ResourceContainerObject*>(NetworkIdManager::getObjectById(contId));
if (container != NULL)
{
NetworkId sourceId;
if (argv.size() >= 3)
sourceId = NetworkId(Unicode::wideToNarrow (argv[2]));
if (container->addResource(container->getResourceType(),
container->getMaxQuantity() - container->getQuantity(),
sourceId))
{
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else
result += getErrorMessage(argv[0], ERR_INVALID_CONTAINER_TRANSFER);
}
else
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
}
else if (isCommand( argv [0], "recycle"))
{
NetworkId contId (Unicode::wideToNarrow (argv[1]));
ResourceContainerObject* container=dynamic_cast<ResourceContainerObject*>(NetworkIdManager::getObjectById(contId));
if (container != NULL)
{
if (container->debugRecycle())
result += getErrorMessage(argv[0], ERR_SUCCESS);
else
result += Unicode::narrowToWide("The resource in the container could not be recycled.\n");
}
else
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
}
else if (isCommand( argv [0], "removefromcontainer"))
{
CachedNetworkId contId (Unicode::wideToNarrow (argv[1]));
ResourceContainerObject* container=dynamic_cast<ResourceContainerObject*>(contId.getObject());
ResourceTypeObject *resType=ServerUniverse::getInstance().getResourceTypeByName(Unicode::wideToNarrow(argv[2]));
int amount=strtol(Unicode::wideToNarrow (argv[3]).c_str (), NULL, 10);
if (container && resType)
{
NetworkId sourcePlayer(NetworkId::cms_invalid);
typedef std::vector<std::pair<NetworkId, int> > SourcesType;
SourcesType sources;
if (container->removeResource(resType->getNetworkId(),amount,&sources))
{
char buffer[50];
for(SourcesType::iterator i=sources.begin(); i!=sources.end(); ++i)
{
IGNORE_RETURN(snprintf(buffer,50,"%i",i->second));
result += Unicode::narrowToWide(std::string("Removed ") + buffer + " resources harvested by player " + i->first.getValueString() + '\n');
}
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else
result += getErrorMessage(argv[0], ERR_INVALID_CONTAINER_TRANSFER);
}
else
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
}
}
else if (isCommand( argv [0], "getSurveyList"))
{
std::string parentResourceClassName(Unicode::wideToNarrow(argv[1]));
CachedNetworkId tool(Unicode::wideToNarrow (argv[2]));
SurveySystem::getInstance().requestResourceListForSurvey(userId, tool, parentResourceClassName);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isCommand( argv [0], "survey"))
{
const std::string parentResourceClassName (Unicode::wideToNarrow(argv[1]));
const std::string resourceTypeName (Unicode::wideToNarrow(argv[2]));
const int surveyRange = strtol(Unicode::wideToNarrow(argv[3]).c_str(),NULL,10);
const int numPoints = strtol(Unicode::wideToNarrow(argv[4]).c_str(),NULL,10);
const Object * player = NetworkIdManager::getObjectById(userId);
if (player)
{
SurveySystem::getInstance().requestSurvey(userId, parentResourceClassName, resourceTypeName, player->getPosition_w(), surveyRange, numPoints);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else
result += getErrorMessage(argv [0], ERR_INVALID_OBJECT);
}
else if (isCommand( argv [0], "deplete"))
{
NetworkId resourceId (Unicode::wideToNarrow (argv[1]));
if (ServerUniverse::getInstance().manualDepleteResource(resourceId))
result += getErrorMessage(argv[0], ERR_SUCCESS);
else
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
}
return true;
} // ConsoleCommandParserResource::performParsing
// ======================================================================
@@ -0,0 +1,32 @@
// ======================================================================
//
// ConsoleCommandParserResource.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserResource_H
#define INCLUDED_ConsoleCommandParserResource_H
#include "sharedCommandParser/CommandParser.h"
// ======================================================================
/**
* Commands that are related to the resource system.
*/
class ConsoleCommandParserResource : public CommandParser
{
public:
ConsoleCommandParserResource ();
virtual bool performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node);
private:
ConsoleCommandParserResource (const ConsoleCommandParserResource & rhs);
ConsoleCommandParserResource & operator= (const ConsoleCommandParserResource & rhs);
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserResource_H
@@ -0,0 +1,324 @@
// ======================================================================
//
// ConsoleCommandParserScript.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ConsoleCommandParserScript.h"
#include "serverGame/CreatureObject.h"
#include "serverGame/GameServer.h"
#include "serverGame/ServerMessageForwarding.h"
#include "serverGame/ServerObject.h"
#include "serverGame/ServerWorld.h"
#include "serverNetworkMessages/ReloadScriptMessage.h"
#include "serverScript/GameScriptObject.h"
#include "sharedFoundation/FormattedString.h"
#include "sharedUtility/DataTableManager.h"
#include "UnicodeUtils.h"
#include <stdio.h>
// ======================================================================
static const CommandParser::CmdInfo cmds[] =
{
{"attach", 2, "<name> <oid>", "Attach a script to an object."},
{"detach", 2, "<name> <oid>", "Detach a script from an object."},
{"list", 0, "", "List the scripts attached to an object."},
{"pause", 1, "<on|off>", "Turn scripting on/off (globally)."},
{"reload", 1, "<name>", "Reload a script that has changed."},
{"triggerAll", 2, "<trigger> <oid> <...>", "Run a trigger on all scripts attached to an object"},
{"triggerOne", 3, "<trigger> <name> <oid> <...>", "Run a trigger on a script attached to an object"},
{"scriptingEnabled", 0, "", "Checks if the scripting system is enabled or not"},
{"enableLogging", 1, "<on|off>", "Turns script logging on or off"},
{"", 0, "", ""} // this must be last
};
//-----------------------------------------------------------------
ConsoleCommandParserScript::ConsoleCommandParserScript (void) :
CommandParser ("script", 0, "...", "Script related commands.", 0)
{
createDelegateCommands (cmds);
}
//-----------------------------------------------------------------
bool ConsoleCommandParserScript::performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node)
{
NOT_NULL (node);
UNREF(originalCommand);
UNREF(userId);
//-----------------------------------------------------------------
if (isAbbrev( argv [0], "attach"))
{
NetworkId oid(Unicode::wideToNarrow (argv[2]));
ServerObject* object = ServerWorld::findObjectByNetworkId(oid);
if (object == NULL)
{
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
return true;
}
if (!object->getScriptObject()->attachScript(Unicode::wideToNarrow(argv[1]), true))
{
result += getErrorMessage (argv[0], ERR_INVALID_SCRIPT);
return true;
}
result += getErrorMessage (argv[0], ERR_SUCCESS);
}
//-----------------------------------------------------------------
else if (isAbbrev( argv [0], "detach"))
{
NetworkId oid(Unicode::wideToNarrow(argv[2]));
ServerObject* object = ServerWorld::findObjectByNetworkId(oid);
if (object == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
if (!object->getScriptObject()->detachScript(Unicode::wideToNarrow(argv[1])))
{
result += getErrorMessage(argv[0], ERR_INVALID_SCRIPT);
return true;
}
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
//-----------------------------------------------------------------
else if (isAbbrev(argv[0], "list"))
{
ServerObject * const userServerObject = ServerWorld::findObjectByNetworkId(userId);
if (userServerObject != NULL)
{
NetworkId specifiedNetworkId;
if (argv.size () > 1)
{
specifiedNetworkId = NetworkId(Unicode::wideToNarrow(argv[1]));
}
else
{
CreatureObject * const userCreatureObject = CreatureObject::asCreatureObject(userServerObject);
if (userCreatureObject != NULL)
{
specifiedNetworkId = userCreatureObject->getLookAtTarget();
}
}
ServerObject * const specifiedServerObject = ServerObject::getServerObject(specifiedNetworkId);
if (specifiedServerObject != NULL)
{
ScriptList const & scripts = specifiedServerObject->getScriptObject()->getScripts();
FormattedString<1024> fs;
result += Unicode::narrowToWide(fs.sprintf("script list for object %s, num %d\n", specifiedServerObject->getNetworkId().getValueString().c_str(), scripts.size()));
if (scripts.size() == 0)
{
result += Unicode::narrowToWide("none\n");
}
else
{
for (ScriptList::const_iterator i = scripts.begin(); i != scripts.end(); ++i)
{
result += Unicode::narrowToWide(fs.sprintf("%s\n", (*i).getScriptName().c_str()));
}
}
result += getErrorMessage(argv[0], ERR_SUCCESS);
return true;
}
}
result += getErrorMessage (argv [0], ERR_INVALID_OBJECT);
}
//-----------------------------------------------------------------
else if (isAbbrev(argv[0], "pause"))
{
bool flag;
if (strcmp(Unicode::wideToNarrow(argv[1]).c_str(), "on") == 0)
flag = true;
else if (strcmp(Unicode::wideToNarrow(argv[1]).c_str(), "off") == 0)
flag = false;
else
{
result += getErrorMessage(argv[0], ERR_INVALID_ARGUMENTS);
return true;
}
GameScriptObject::pauseScripting(flag);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
//-----------------------------------------------------------------
else if (isAbbrev(argv[0], "reload"))
{
std::string script(Unicode::wideToNarrow(argv[1]));
if (GameScriptObject::reloadScript(script))
result += getErrorMessage(argv[0], ERR_SUCCESS);
else
result += getErrorMessage(argv[0], ERR_INVALID_SCRIPT);
ServerMessageForwarding::beginBroadcast();
ReloadScriptMessage const reloadScriptMessage(script);
ServerMessageForwarding::send(reloadScriptMessage);
ServerMessageForwarding::end();
}
//-----------------------------------------------------------------
else if (isAbbrev(argv[0], "triggerAll") || isAbbrev(argv[0], "triggerOne"))
{
int i;
bool all = isAbbrev(argv[0], "triggerAll");
// get the trigger id
int trigger = Scripting::TRIG_LAST_TRIGGER;
std::string triggerName = Unicode::wideToNarrow(argv[1]).c_str();
if (isdigit(triggerName[0]))
trigger = atoi(Unicode::wideToNarrow(argv[1]).c_str());
else
{
Scripting::_ScriptFuncHashMap::const_iterator iter;
for (iter = Scripting::ScriptFuncHashMap->begin();
iter != Scripting::ScriptFuncHashMap->end();
++iter)
{
if (std::string((*iter).second->name) == triggerName)
{
trigger = (*iter).first;
break;
}
}
}
if (trigger < 0 || trigger >= Scripting::TRIG_LAST_TRIGGER)
{
result += getErrorMessage(argv[0], ERR_INVALID_TRIGGER);
return true;
}
int oidIndex = 2;
int paramIndex = 3;
std::string scriptName;
if (!all)
{
oidIndex = 3;
paramIndex = 4;
scriptName = Unicode::wideToNarrow(argv[2]);
}
// get the object id
NetworkId oid(Unicode::wideToNarrow(argv[oidIndex]));
ServerObject* object = ServerWorld::findObjectByNetworkId(oid);
if (object == NULL)
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
return true;
}
// get the parameter template for the trigger
Scripting::_ScriptFuncHashMap::const_iterator funcIter = Scripting::ScriptFuncHashMap->find(trigger);
if (funcIter == Scripting::ScriptFuncHashMap->end())
{
result += getErrorMessage(argv[0], ERR_INVALID_TRIGGER);
return true;
}
const Scripting::ScriptFuncTable *func = (*funcIter).second;
// make sure we have the correct parameter count
int paramCount = argv.size() - paramIndex;
int paramDesired = 0;
for (i = 0; func->argList[i] != 0; ++i)
{
if (func->argList[i] != ']')
++paramDesired;
// don't let a trigger that takes a slotData or attribMod
if (func->argList[i] == 'E' || func->argList[i] == 'A')
{
result += getErrorMessage(argv[0], ERR_UNSUPPORTED_TRIGGER);
return true;
}
}
if (paramCount != paramDesired)
{
char buffer[16];
result += getErrorMessage(argv[0], ERR_INVALID_PARAMETER_COUNT);
_itoa(paramDesired, buffer, 10);
result += Unicode::narrowToWide(buffer);
return true;
}
// copy the parameters
StringVector_t params;
for (i = 0; i < paramCount; ++i)
params.push_back(argv[paramIndex + i]);
// invoke the trigger
int trigResult = object->getScriptObject()->trigScriptFromConsole(
static_cast<Scripting::TrigId>(trigger),
scriptName,
params
);
if (trigResult == SCRIPT_CONTINUE)
result += getErrorMessage(argv[0], ERR_SCRIPT_CONTINUE);
else
result += getErrorMessage(argv[0], ERR_SCRIPT_OVERRIDE);
}
//-----------------------------------------------------------------
else if (isAbbrev(argv[0], "scriptingEnabled"))
{
if (GameScriptObject::isScriptingEnabled())
result += getErrorMessage(argv[0], ERR_SCRIPTING_ENABLED);
else
result += getErrorMessage(argv[0], ERR_SCRIPTING_DISABLED);
}
//-----------------------------------------------------------------
else if (isAbbrev(argv[0], "enableLogging"))
{
bool flag;
if (strcmp(Unicode::wideToNarrow(argv[1]).c_str(), "on") == 0)
flag = true;
else if (strcmp(Unicode::wideToNarrow(argv[1]).c_str(), "off") == 0)
flag = false;
else
{
result += getErrorMessage(argv[0], ERR_INVALID_ARGUMENTS);
return true;
}
GameScriptObject::enableLogging(flag);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
//-----------------------------------------------------------------
else
{
result += getErrorMessage(argv[0], ERR_NO_HANDLER);
}
return true;
}
// ======================================================================
@@ -0,0 +1,32 @@
// ======================================================================
//
// ConsoleCommandParserScript.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserScript_H
#define INCLUDED_ConsoleCommandParserScript_H
#include "sharedCommandParser/CommandParser.h"
// ======================================================================
/**
* Commands that are related to scripts
*/
class ConsoleCommandParserScript : public CommandParser
{
public:
ConsoleCommandParserScript ();
virtual bool performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node);
private:
ConsoleCommandParserScript (const ConsoleCommandParserScript & rhs);
ConsoleCommandParserScript & operator= (const ConsoleCommandParserScript & rhs);
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserScript_H
@@ -0,0 +1,42 @@
// ======================================================================
//
// ConsoleCommandParserServer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserServer_H
#define INCLUDED_ConsoleCommandParserServer_H
#include "sharedCommandParser/CommandParser.h"
// ======================================================================
/**
* Commands that are related to scripts
*/
class ConsoleCommandParserServer : public CommandParser
{
public:
ConsoleCommandParserServer ();
virtual bool performParsing (const NetworkId & userId,
const StringVector_t & argv,
const String_t & originalCommand,
String_t & result,
const CommandParser * node);
private:
ConsoleCommandParserServer (const ConsoleCommandParserServer & rhs);
ConsoleCommandParserServer & operator= (const ConsoleCommandParserServer & rhs);
bool performParsing2 (const NetworkId & userId,
const StringVector_t & argv,
const String_t & originalCommand,
String_t & result,
const CommandParser * node);
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserServer_H
@@ -0,0 +1,569 @@
//======================================================================
//
// ConsoleCommandParserShip.cpp
// copyright (c) 2004 Sony Online Entertainment
//
//======================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ConsoleCommandParserShip.h"
#include "UnicodeUtils.h"
#include "serverGame/CreatureObject.h"
#include "serverGame/ServerWorld.h"
#include "serverGame/ShipComponentDataManager.h"
#include "serverGame/ShipInternalDamageOverTime.h"
#include "serverGame/ShipInternalDamageOverTimeManager.h"
#include "serverGame/ShipObject.h"
#include "sharedFoundation/ConstCharCrcString.h"
#include "sharedFoundation/Crc.h"
#include "sharedFoundation/PersistentCrcString.h"
#include "sharedGame/ShipChassis.h"
#include "sharedGame/ShipChassisSlot.h"
#include "sharedGame/ShipComponentAttachmentManager.h"
#include "sharedGame/ShipComponentData.h"
#include "sharedGame/ShipComponentDescriptor.h"
#include "sharedNetworkMessages/MessageQueueGenericValueType.h"
#include "sharedNetworkMessages/ShipDamageMessage.h"
#include "sharedObject/Controller.h"
#include "sharedObject/NetworkIdManager.h"
#include "sharedObject/ObjectTemplateList.h"
#include <cstdio>
// ======================================================================
//lint -e641
namespace
{
namespace CommandNames
{
#define MAKE_COMMAND(a) const char * const a = #a
MAKE_COMMAND(getSlotList);
MAKE_COMMAND(install);
MAKE_COMMAND(pseudoInstall);
MAKE_COMMAND(uninstall);
MAKE_COMMAND(purge);
MAKE_COMMAND(getComponentDescriptor);
MAKE_COMMAND(pseudoDamageShip);
MAKE_COMMAND(idotList);
MAKE_COMMAND(idotSet);
MAKE_COMMAND(idotRemove);
#undef MAKE_COMMAND
}
const CommandParser::CmdInfo cmds[] =
{
{CommandNames::getSlotList, 0, "[slot name] [ship OID]", "Lists slots on a ship"},
{CommandNames::install, 2, "<component id> <slot> [ship OID]", "Installs a component in a ship."},
{CommandNames::pseudoInstall, 2, "<component name> <slot> [ship OID]", "Installs a psuedo component in a ship."},
{CommandNames::uninstall, 1, "<slot> [target container Id] [ship OID]", "Uninstalls a component from a ship."},
{CommandNames::purge, 1, "<slot> [ship OID]", "Purges a component from a ship."},
{CommandNames::getComponentDescriptor, 0, "[component OID]", "View component descriptor info for a component"},
{CommandNames::pseudoDamageShip, 0, "", "Send a hit message to your piloted ship by the lookAt target."},
{CommandNames::idotList, 0, "[networkId]", "List all active IDOTS."},
{CommandNames::idotSet, 3, "<slot> <damage rate> <damage threshold> [networkId]", "Set an active IDOT."},
{CommandNames::idotRemove, 1, "<slot> [networkId]", "Remove an active IDOT."},
{"", 0, "", ""} // this must be last
};
//----------------------------------------------------------------------
TangibleObject * findTangible (const NetworkId & defaultId, const CommandParser::StringVector_t & argv, int index)
{
if (index < 0)
return 0;
NetworkId oid = defaultId;
if (argv.size () > static_cast<size_t>(index))
oid = NetworkId (Unicode::wideToNarrow (argv [static_cast<size_t>(index)]));
return dynamic_cast<TangibleObject *>(NetworkIdManager::getObjectById(oid));
}
}
//-----------------------------------------------------------------
ConsoleCommandParserShip::ConsoleCommandParserShip (void) :
CommandParser ("ship", 0, "...", "Ship related commands.", 0)
{
createDelegateCommands (cmds);
}
//----------------------------------------------------------------------
bool ConsoleCommandParserShip::performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & , String_t & result, const CommandParser *)
{
CreatureObject const * const user = dynamic_cast<const CreatureObject *>(NetworkIdManager::getObjectById (userId));
if (!user)
return false;
// ----------------------------------------------------------------
if (isCommand (argv[0], CommandNames::getSlotList))
{
ShipObject * const ship = dynamic_cast<ShipObject *>(findTangible (user->getLookAtTarget (), argv, 2));
std::string slotNameToken;
if (argv.size () > 1)
{
slotNameToken = Unicode::wideToNarrow (argv [1]);
if (!slotNameToken.empty () && slotNameToken [0] == '*')
slotNameToken.clear ();
}
if (ship == NULL)
{
result += getErrorMessage (argv[0], ERR_INVALID_OBJECT);
return true;
}
uint32 const chassisType = ship->getChassisType ();
ShipChassis const * const shipChassis = ShipChassis::findShipChassisByCrc (chassisType);
if (shipChassis == NULL)
{
result += Unicode::narrowToWide ("No chassis");
return true;
}
ShipChassis::SlotVector const & slotVector = shipChassis->getSlots ();
char buf [1024];
const size_t buf_size = sizeof (buf);
snprintf (buf, buf_size,
"Chassis type [%s] (%lu)\n"
" Slot count [%d], Hitpoints [%5.2f/%5.2f], Mass [%5.2f/%5.2f]\n",
shipChassis->getName ().getString (), shipChassis->getCrc (),
static_cast<int>(slotVector.size ()),
ship->getCurrentChassisHitPoints(), ship->getMaximumChassisHitPoints(),
ship->getChassisComponentMassCurrent(), ship->getChassisComponentMassMaximum());
result += Unicode::narrowToWide (buf);
for (int chassisSlot = ShipChassisSlotType::SCST_first; chassisSlot < ShipChassisSlotType::SCST_num_types; ++chassisSlot)
{
int effectiveCompatibilitySlot = chassisSlot;
// weapon slots beyond 7 wrap back to slot 0 for the purposes of compatibility checking on captial ships
if (ship->isCapitalShip() && chassisSlot >= ShipChassisSlotType::SCST_num_explicit_types && chassisSlot <= ShipChassisSlotType::SCST_weapon_last)
effectiveCompatibilitySlot = ShipChassisSlotType::SCST_weapon_first+((chassisSlot-ShipChassisSlotType::SCST_weapon_first)&7);
ShipChassisSlot const * const slot = shipChassis->getSlot(static_cast<ShipChassisSlotType::Type>(effectiveCompatibilitySlot));
if (!slot)
continue;
if (!slotNameToken.empty() && ShipChassisSlotType::getNameFromType(slot->getSlotType ()) != slotNameToken)
continue;
snprintf (buf, buf_size,
" \\#pcontrast1 [SLOT %s (%d)]\\#.\n"
" Hitweight [%d], compats: ",
ShipChassisSlotType::getNameFromType(static_cast<ShipChassisSlotType::Type>(chassisSlot)).c_str(),
chassisSlot,
slot->getHitWeight());
result += Unicode::narrowToWide (buf);
result += Unicode::narrowToWide(slot->getCompatibilityString());
result.push_back ('\n');
ShipComponentData * shipComponentData = 0;
if (ship->isSlotInstalled(chassisSlot))
shipComponentData = ship->createShipComponentData(chassisSlot);
if (shipComponentData == NULL)
{
result += Unicode::narrowToWide (" Loaded NONE\n");
}
else
{
result += Unicode::narrowToWide (" Loaded:\n");
shipComponentData->printDebugString (result, Unicode::narrowToWide (" "));
ShipComponentAttachmentManager::TemplateHardpointPairVector const & thpv =
ShipComponentAttachmentManager::getAttachmentsForShip (chassisType, shipComponentData->getDescriptor ().getCrc(), chassisSlot);
if (!thpv.empty ())
{
result += Unicode::narrowToWide (" Attachments: ");
for (ShipComponentAttachmentManager::TemplateHardpointPairVector::const_iterator thpv_it = thpv.begin (); thpv_it != thpv.end (); ++thpv_it)
{
uint32 const objectTemplateCrc = (*thpv_it).first;
CrcString const & hardpointName = (*thpv_it).second;
CrcString const & objectTemplateCrcString = ObjectTemplateList::lookUp(objectTemplateCrc);
result += Unicode::narrowToWide (objectTemplateCrcString.getString ());
result.push_back (':');
result += Unicode::narrowToWide (hardpointName.getString ());
result.push_back (',');
result.push_back (' ');
}
result.push_back ('\n');
}
delete shipComponentData;
}
}
return true;
}
//----------------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::getComponentDescriptor))
{
TangibleObject * const component = findTangible (user->getLookAtTarget (), argv, 1);
if (component == NULL)
{
result += getErrorMessage (argv[0], ERR_INVALID_OBJECT);
return true;
}
ShipComponentData * const shipComponentData = ShipComponentDataManager::create (*component);
if (shipComponentData == NULL)
{
result += Unicode::narrowToWide ("Not a ship component");
return true;
}
shipComponentData->printDebugString (result, Unicode::emptyString);
delete shipComponentData;
return true;
}
//----------------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::install))
{
ShipObject * const ship = dynamic_cast<ShipObject *>(findTangible (user->getLookAtTarget (), argv, 3));
TangibleObject * const component = findTangible (NetworkId::cms_invalid, argv, 1);
std::string const & slotName = Unicode::wideToNarrow (argv [2]);
if (ship == NULL)
{
result += Unicode::narrowToWide ("no ship");
return true;
}
if (component == NULL)
{
result += Unicode::narrowToWide ("no component");
return true;
}
ShipChassisSlotType::Type shipChassisSlotType = ShipChassisSlotType::getTypeFromName (slotName);
if (shipChassisSlotType == ShipChassisSlotType::SCST_num_types)
{
result += Unicode::narrowToWide ("not a valid slot name");
return true;
}
if (ship->isSlotInstalled (shipChassisSlotType))
{
result += Unicode::narrowToWide ("That slot is already filled");
return true;
}
ShipChassis const * const shipChassis = ShipChassis::findShipChassisByCrc (ship->getChassisType ());
if (shipChassis == NULL)
{
result += Unicode::narrowToWide ("Ship chassis invalid");
return true;
}
ShipChassisSlot const * const slot = shipChassis->getSlot (shipChassisSlotType);
if (slot == NULL)
{
result += Unicode::narrowToWide ("Ship chassis does not support that slot");
return true;
}
ShipComponentData * const shipComponentData = ShipComponentDataManager::create (*component);
if (shipComponentData == NULL)
{
result += Unicode::narrowToWide ("Not a ship component");
return true;
}
if (!slot->canAcceptComponent (shipComponentData->getDescriptor ()))
{
result += Unicode::narrowToWide ("Component cannot be installed here, may not be compatible.");
delete shipComponentData;
return true;
}
if (!ship->installComponent (user->getNetworkId(), static_cast<int>(shipChassisSlotType), *component))
result += Unicode::narrowToWide ("Installation failed. Check warnings");
else
result += Unicode::narrowToWide ("Installation Success");
delete shipComponentData;
return true;
}
//----------------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::pseudoInstall))
{
ShipObject * const ship = dynamic_cast<ShipObject *>(findTangible (user->getLookAtTarget (), argv, 3));
std::string const & componentName = Unicode::wideToNarrow (argv [1]);
std::string const & slotName = Unicode::wideToNarrow (argv [2]);
if (ship == NULL)
{
result += Unicode::narrowToWide ("no ship");
return true;
}
uint32 const componentCrc = Crc::normalizeAndCalculate (componentName.c_str ());
ShipComponentDescriptor const * const shipComponentDescriptor = ShipComponentDescriptor::findShipComponentDescriptorByCrc (componentCrc);
if (shipComponentDescriptor == NULL)
{
result += Unicode::narrowToWide ("Invalid component name");
return true;
}
ShipChassisSlotType::Type const shipChassisSlotType = ShipChassisSlotType::getTypeFromName (slotName);
if (shipChassisSlotType == ShipChassisSlotType::SCST_num_types)
{
result += Unicode::narrowToWide ("not a valid slot name");
return true;
}
if (!ship->pseudoInstallComponent (static_cast<int>(shipChassisSlotType), componentCrc))
result += Unicode::narrowToWide ("Installation Failed... check warnings");
else
result += Unicode::narrowToWide ("Installation Success");
return true;
}
//----------------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::uninstall))
{
ShipObject * const ship = dynamic_cast<ShipObject *>(findTangible (user->getLookAtTarget (), argv, 3));
TangibleObject * const targetContainer = findTangible (user->getInventory ()->getNetworkId (), argv, 2);
std::string const & slotName = Unicode::wideToNarrow (argv [1]);
if (ship == NULL)
{
result += Unicode::narrowToWide ("no ship");
return true;
}
if (targetContainer == NULL)
{
result += Unicode::narrowToWide ("no target container");
return true;
}
ShipChassisSlotType::Type shipChassisSlotType = ShipChassisSlotType::getTypeFromName (slotName);
if (shipChassisSlotType == ShipChassisSlotType::SCST_num_types)
{
result += Unicode::narrowToWide ("not a valid slot name");
return true;
}
if (!ship->isSlotInstalled (shipChassisSlotType))
{
result += Unicode::narrowToWide ("That slot is not filled");
return true;
}
if (!ship->uninstallComponent (user->getNetworkId(), static_cast<int>(shipChassisSlotType), *targetContainer))
result += Unicode::narrowToWide ("Uninstallation failed. Check warnings");
else
result += Unicode::narrowToWide ("Uninstallation Success");
return true;
}
//----------------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::purge))
{
ShipObject * const ship = dynamic_cast<ShipObject *>(findTangible (user->getLookAtTarget (), argv, 2));
std::string const & slotName = Unicode::wideToNarrow (argv [1]);
if (ship == NULL)
{
result += Unicode::narrowToWide ("no ship");
return true;
}
ShipChassisSlotType::Type shipChassisSlotType = ShipChassisSlotType::getTypeFromName (slotName);
if (shipChassisSlotType == ShipChassisSlotType::SCST_num_types)
{
result += Unicode::narrowToWide ("not a valid slot name");
return true;
}
if (!ship->isSlotInstalled (shipChassisSlotType))
{
result += Unicode::narrowToWide ("That slot is not filled");
return true;
}
ship->purgeComponent (static_cast<int>(shipChassisSlotType));
result += Unicode::narrowToWide ("Purge Success");
return true;
}
//----------------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::pseudoDamageShip))
{
ShipObject const * const victimShipObject = user->getPilotedShip();
if (victimShipObject == NULL)
{
result += Unicode::narrowToWide ("You are not piloting a ship.");
return true;
}
ShipObject const * const attackerShipObject = dynamic_cast<ShipObject *>(findTangible (user->getLookAtTarget (), argv, 2));
if (attackerShipObject == NULL)
{
result += Unicode::narrowToWide ("You don't have attacker ship targeted.");
return true;
}
Controller * const victimShipController = const_cast<Controller * const>(victimShipObject->getController());
if (victimShipController)
{
ShipDamageMessage shipDamage(attackerShipObject->getNetworkId(),
attackerShipObject->getPosition_w(),
1.0f );
MessageQueueGenericValueType<ShipDamageMessage> * const damageMessage = new MessageQueueGenericValueType<ShipDamageMessage>(shipDamage);
victimShipController->appendMessage(CM_shipDamageMessage, 0.0f, damageMessage,
GameControllerMessageFlags::SEND |
GameControllerMessageFlags::RELIABLE |
GameControllerMessageFlags::DEST_AUTH_CLIENT);
}
return true;
}
//----------------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::idotList))
{
ShipObject * const ship = dynamic_cast<ShipObject *>(findTangible (user->getLookAtTarget (), argv, 1));
ShipInternalDamageOverTimeManager::IdotVector const & idotVector = ShipInternalDamageOverTimeManager::getActiveShipInternalDamageOverTime();
char buf[1024];
size_t const buf_size = sizeof(buf);
int displayCount = 0;
for (ShipInternalDamageOverTimeManager::IdotVector::const_iterator it = idotVector.begin(); it != idotVector.end(); ++it)
{
ShipInternalDamageOverTime const & idot = *it;
ShipObject const * const idotShip = idot.getShipObject();
if (ship != NULL && ship != idotShip)
continue;
uint32 const chassisType = idotShip->getChassisType();
ShipChassis const * const chassis = ShipChassis::findShipChassisByCrc(chassisType);
std::string const chassisTypeName = (chassis != NULL) ? chassis->getName().getString() : "<NO VALID CHASSIS>";
float hpCur = 0.0f;
float hpMax = 0.0f;
IGNORE_RETURN(idot.checkValidity(hpCur, hpMax));
float hpPercent = (hpMax > 0.0f) ? hpCur / hpMax : -1.0f;
snprintf(buf, buf_size,
"[%15s] [%15s]:[%-10s] rate=[%3.1f], threshold=[%3.1f], hp cur/max/pct=[%5.1f/%5.1f/%3.3f\n",
idotShip->getNetworkId().getValueString().c_str(), chassisTypeName.c_str(),
ShipChassisSlotType::getNameFromType(static_cast<ShipChassisSlotType::Type>(idot.getChassisSlot())).c_str(),
idot.getDamageRate(), idot.getDamageThreshold(), hpCur, hpMax, hpPercent);
buf[buf_size-1] = 0;
result += Unicode::narrowToWide(buf);
++displayCount;
}
snprintf(buf, buf_size, "%d/%d displayed", displayCount, idotVector.size());
buf[buf_size-1] = 0;
result += Unicode::narrowToWide(buf);
return true;
}
//----------------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::idotSet))
{
ShipObject * const ship = dynamic_cast<ShipObject *>(findTangible (user->getLookAtTarget (), argv, 4));
if (ship == NULL)
{
result += Unicode::narrowToWide ("no ship");
return true;
}
std::string const & slotName = Unicode::wideToNarrow (argv [1]);
ShipChassisSlotType::Type const shipChassisSlotType = ShipChassisSlotType::getTypeFromName (slotName);
float const damageRate = static_cast<float>(atof(Unicode::wideToNarrow(argv[2]).c_str()));
float const damageThreshold = static_cast<float>(atof(Unicode::wideToNarrow(argv[3]).c_str()));
if (!ShipInternalDamageOverTimeManager::setEntry(*ship, static_cast<int>(shipChassisSlotType), damageRate, damageThreshold))
result += Unicode::narrowToWide("failed to set the IDOT entry");
return true;
}
//----------------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::idotRemove))
{
ShipObject * const ship = dynamic_cast<ShipObject *>(findTangible (user->getLookAtTarget (), argv, 4));
if (ship == NULL)
{
result += Unicode::narrowToWide ("no ship");
return true;
}
std::string const & slotName = Unicode::wideToNarrow (argv [1]);
ShipChassisSlotType::Type const shipChassisSlotType = ShipChassisSlotType::getTypeFromName (slotName);
if (!ShipInternalDamageOverTimeManager::removeEntry(*ship, static_cast<int>(shipChassisSlotType)))
result += Unicode::narrowToWide("failed to remove the IDOT entry");
return true;
}
//----------------------------------------------------------------------
return false;
}
//----------------------------------------------------------------------
@@ -0,0 +1,31 @@
//======================================================================
//
// ConsoleCommandParserShip.h
// copyright (c) 2004 Sony Online Entertainment
//
//======================================================================
#ifndef INCLUDED_ConsoleCommandParserShip_H
#define INCLUDED_ConsoleCommandParserShip_H
//======================================================================
#include "sharedCommandParser/CommandParser.h"
//----------------------------------------------------------------------
class ConsoleCommandParserShip :
public CommandParser
{
public:
ConsoleCommandParserShip ();
virtual bool performParsing (const NetworkId & userId, const StringVector_t & argv,const String_t & originalCommand,String_t & result,const CommandParser * node);
private:
ConsoleCommandParserShip (const ConsoleCommandParserShip & rhs);
ConsoleCommandParserShip & operator= (const ConsoleCommandParserShip & rhs);
};
//======================================================================
#endif
@@ -0,0 +1,470 @@
// ======================================================================
//
// ConsoleCommandParserSkill.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ConsoleCommandParserSkill.h"
#include "UnicodeUtils.h"
#include "serverGame/CreatureObject.h"
#include "serverGame/ServerWorld.h"
#include "sharedFoundation/ConstCharCrcString.h"
#include "sharedLog/Log.h"
#include "sharedObject/ObjectTemplateList.h"
#include "sharedSkillSystem/SkillManager.h"
#include "sharedSkillSystem/SkillObject.h"
#include <cstdio>
// ======================================================================
namespace
{
namespace CommandNames
{
#define MAKE_COMMAND(a) const char * const a = #a
MAKE_COMMAND(getCommandList);
MAKE_COMMAND(getSkillMods);
MAKE_COMMAND(getSkillList);
MAKE_COMMAND(grantExperience);
MAKE_COMMAND(grantSkill);
MAKE_COMMAND(grantSkillMod);
MAKE_COMMAND(grantCommand);
MAKE_COMMAND(revokeSkill);
MAKE_COMMAND(revokeSkillMod);
MAKE_COMMAND(getSchematics);
MAKE_COMMAND(grantSchematicGroup);
MAKE_COMMAND(revokeSchematicGroup);
MAKE_COMMAND(grantSchematic);
MAKE_COMMAND(revokeSchematic);
MAKE_COMMAND(getLevel);
#undef MAKE_COMMAND
}
const CommandParser::CmdInfo cmds[] =
{
{CommandNames::getCommandList, 0, "[creature OID]", "Lists commands on creature."},
{CommandNames::getSkillMods, 0, "[creature OID]", "List all mods on a creature."},
{CommandNames::getSkillList, 0, "[creature OID]", "Lists commands on creature."},
{CommandNames::grantExperience, 3, "[creature OID] [experience type] [amount]", "Grants/remove experience to/from creature"},
{CommandNames::grantSkill, 1, "<skill name> [creature OID]", "Grants skill to creature"},
{CommandNames::grantSkillMod, 2, "<skill mod name> <mod value> [creature OID]", "Grants skill mod to creature"},
{CommandNames::grantCommand, 1, "<command name> [creature OID]", "Grants command to creature"},
{CommandNames::revokeSkill, 1, "<skill name> [creature OID]", "Remove skill from creature"},
{CommandNames::revokeSkillMod, 1, "<skill mod name> [creature OID]", "Remove skill mod from creature"},
{CommandNames::getSchematics, 0, "[creature OID]", "Lists draft schematics owned by a creature"},
{CommandNames::grantSchematicGroup, 1, "<group name> [creature OID]", "Grants a schematic group to a creature"},
{CommandNames::revokeSchematicGroup, 1, "<group name> [creature OID]", "Removes a schematic group from a creature"},
{CommandNames::grantSchematic, 1, "<schematic name> [creature OID]", "Grants a draftt schematic to a creature"},
{CommandNames::revokeSchematic, 1, "<schematic name> [creature OID]", "Removes a draftt schematic from a creature"},
{CommandNames::getLevel, 0, "[creature OID]", "List creature's current level."},
{"", 0, "", ""} // this must be last
};
//----------------------------------------------------------------------
CreatureObject * findCreature (const NetworkId & userId, const CommandParser::StringVector_t & argv, int index)
{
if (index < 0)
return 0;
NetworkId oid = userId;
if (argv.size () > static_cast<size_t>(index))
oid = NetworkId (Unicode::wideToNarrow (argv [index]));
return dynamic_cast<CreatureObject *>(ServerWorld::findObjectByNetworkId(oid));
}
}
//-----------------------------------------------------------------
ConsoleCommandParserSkill::ConsoleCommandParserSkill (void) :
CommandParser ("skill", 0, "...", "Skill related commands.", 0)
{
createDelegateCommands (cmds);
}
//----------------------------------------------------------------------
bool ConsoleCommandParserSkill::performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & , String_t & result, const CommandParser *)
{
// ----------------------------------------------------------------
if (isCommand (argv[0], CommandNames::grantSkill))
{
CreatureObject * const creature = findCreature (userId, argv, 2);
if (creature == NULL)
{
result += getErrorMessage (argv[0], ERR_INVALID_OBJECT);
}
else
{
const std::string skillName = Unicode::wideToNarrow (argv[1]);
const SkillObject * const skill = SkillManager::getInstance ().getSkill (skillName);
if (skill == NULL)
{
result += Unicode::narrowToWide ("unknown skill");
}
else
{
creature->grantSkill (*skill);
result += getErrorMessage (argv[0], ERR_SUCCESS);
}
}
return true;
}
// ----------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::grantSkillMod))
{
CreatureObject * const creature = findCreature (userId, argv, 3);
if (creature == NULL)
{
result += getErrorMessage (argv[0], ERR_INVALID_OBJECT);
}
else
{
const std::string skillModName = Unicode::wideToNarrow (argv[1]);
int value = atoi (Unicode::wideToNarrow (argv [2]).c_str ());
creature->setModValue(skillModName, value);
result += getErrorMessage (argv[0], ERR_SUCCESS);
}
return true;
}
// ----------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::grantCommand))
{
CreatureObject * const creature = findCreature (userId, argv, 2);
if (creature == NULL)
{
result += getErrorMessage (argv[0], ERR_INVALID_OBJECT);
}
else
{
const std::string commandName = Unicode::wideToNarrow (argv[1]);
if (creature->grantCommand (commandName, false))
result += getErrorMessage (argv[0], ERR_SUCCESS);
else
result += getErrorMessage (argv[0], ERR_FAIL);
}
return true;
}
//-----------------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::getSkillMods))
{
const CreatureObject * const creature = findCreature (userId, argv, 2);
if(creature)
{
std::map<std::string, std::pair<int, int> >::const_iterator i;
const std::map<std::string, std::pair<int, int> > & modmap = creature->getModMap();
char valbuf[32] = {"\0"};
int count = 0;
for(i = modmap.begin(); i != modmap.end(); ++i, ++count)
{
snprintf(valbuf, sizeof(valbuf), "%i/%i", (*i).second.first, (*i).second.second);
result += Unicode::narrowToWide((*i).first);
result += Unicode::narrowToWide(std::string(" "));
result += Unicode::narrowToWide(std::string(valbuf));
result += Unicode::narrowToWide(std::string("\n"));
}
snprintf(valbuf, sizeof(valbuf), "%i", count);
result += Unicode::narrowToWide(std::string(valbuf));
result += Unicode::narrowToWide(std::string(" mods returned\n"));
return true;
}
else
{
result += getErrorMessage (argv[0], ERR_INVALID_OBJECT);
}
}
// ----------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::grantExperience))
{
CreatureObject * const creature = findCreature (userId, argv, 1);
if (creature == NULL)
{
result += getErrorMessage (argv[0], ERR_INVALID_OBJECT);
}
else
{
const std::string expType = Unicode::wideToNarrow (argv[2]);
if (argv.size () > 3)
{
const int amount = atoi (Unicode::wideToNarrow (argv [3]).c_str ());
creature->grantExperiencePoints (expType, amount);
result += Unicode::narrowToWide ("granted");
}
else
{
const int amount = creature->getExperiencePoints (expType);
result += Unicode::narrowToWide (expType);
result.append (1, ' ');
result.append (1, ':');
result.append (1, ' ');
char buf[64];
result += Unicode::narrowToWide (_itoa (amount, buf, 10));
}
}
return true;
}
//-----------------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::getSkillList))
{
CreatureObject * const creature = findCreature (userId, argv, 1);
if (creature == NULL)
{
result += getErrorMessage (argv[0], ERR_INVALID_OBJECT);
}
else
{
char buf[1024];
sprintf (buf, "skill list object %s, num %d\n", creature->getNetworkId ().getValueString ().c_str (), creature->getSkillList ().size ());
result += Unicode::narrowToWide (buf);
for (CreatureObject::SkillList::const_iterator i = creature->getSkillList ().begin (); i != creature->getSkillList ().end (); ++i)
{
if (*i)
{
result += Unicode::narrowToWide ( (*i)->getSkillName ());
result += Unicode::narrowToWide ("\n");
}
else
result += Unicode::narrowToWide ("[invalid]\n");
}
}
return true;
}
//-----------------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::getCommandList))
{
CreatureObject * const creature = findCreature (userId, argv, 1);
if (creature == NULL)
{
result += getErrorMessage (argv[0], ERR_INVALID_OBJECT);
}
else
{
char buf[1024];
sprintf (buf, "command list object %s, num %d\n", creature->getNetworkId ().getValueString ().c_str (), creature->getCommandList ().size ());
result += Unicode::narrowToWide (buf);
std::map<std::string, int>::const_iterator i;
for (i = creature->getCommandList ().begin (); i != creature->getCommandList ().end (); ++i)
{
result += Unicode::narrowToWide ((*i).first);
result += Unicode::narrowToWide ("\n");
}
}
return true;
}
// ----------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::revokeSkill))
{
CreatureObject * const creature = findCreature (userId, argv, 2);
if (creature == NULL)
{
result += getErrorMessage (argv[0], ERR_INVALID_OBJECT);
}
else
{
std::string skillName = Unicode::wideToNarrow (argv[1]);
const SkillObject * skill = SkillManager::getInstance ().getSkill (skillName);
if (skill == NULL)
{
result += Unicode::narrowToWide ("unknown skill");
}
else
{
LOG("CustomerService", ("Skill: A GOD has requested the revocation of skill %s from character %s.",
skillName.c_str(), creature->getNetworkId().getValueString().c_str()));
creature->revokeSkill (*skill);
result += getErrorMessage (argv[0], ERR_SUCCESS);
}
}
return true;
}
// ----------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::revokeSkillMod))
{
CreatureObject * const creature = findCreature (userId, argv, 2);
if (creature == NULL)
{
result += getErrorMessage (argv[0], ERR_INVALID_OBJECT);
}
else
{
const std::string skillModName = Unicode::wideToNarrow (argv[1]);
creature->setModValue(skillModName, 0);
result += getErrorMessage (argv[0], ERR_SUCCESS);
}
return true;
}
//-----------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::getSchematics))
{
CreatureObject * const creature = findCreature (userId, argv, 1);
if (creature == NULL)
{
result += getErrorMessage (argv[0], ERR_INVALID_OBJECT);
}
else
{
const std::map<std::pair<uint32, uint32>,int> & schematics = creature->getDraftSchematics();
if (!schematics.empty())
{
std::map<std::pair<uint32, uint32>,int>::const_iterator iter;
for (iter = schematics.begin(); iter != schematics.end(); ++iter)
{
const ConstCharCrcString & crcString = ObjectTemplateList::lookUp((*iter).first.first);
if (!crcString.isEmpty())
{
result += Unicode::narrowToWide(crcString.getString());
result += Unicode::narrowToWide("\n");
}
}
}
else
result += Unicode::narrowToWide("No schematics available");
}
}
//-----------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::grantSchematicGroup))
{
CreatureObject * const creature = findCreature (userId, argv, 2);
if (creature == NULL)
{
result += getErrorMessage (argv[0], ERR_INVALID_OBJECT);
}
else
{
creature->grantSchematicGroup("+" + Unicode::wideToNarrow(argv[1]), false);
result += getErrorMessage (argv[0], ERR_SUCCESS);
}
}
//-----------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::revokeSchematicGroup))
{
CreatureObject * const creature = findCreature (userId, argv, 2);
if (creature == NULL)
{
result += getErrorMessage (argv[0], ERR_INVALID_OBJECT);
}
else
{
creature->grantSchematicGroup("-" + Unicode::wideToNarrow(argv[1]), false);
result += getErrorMessage (argv[0], ERR_SUCCESS);
}
}
//-----------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::grantSchematic))
{
CreatureObject * const creature = findCreature (userId, argv, 2);
if (creature == NULL)
{
result += getErrorMessage (argv[0], ERR_INVALID_OBJECT);
}
else
{
creature->grantSchematic(Unicode::wideToNarrow(argv[1]), false);
result += getErrorMessage (argv[0], ERR_SUCCESS);
}
}
//-----------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::revokeSchematic))
{
CreatureObject * const creature = findCreature (userId, argv, 2);
if (creature == NULL)
{
result += getErrorMessage (argv[0], ERR_INVALID_OBJECT);
}
else
{
creature->revokeSchematic(Unicode::wideToNarrow(argv[1]), false);
result += getErrorMessage (argv[0], ERR_SUCCESS);
}
}
//-----------------------------------------------------------------
else if (isCommand (argv[0], CommandNames::getLevel))
{
CreatureObject * const creature = findCreature (userId, argv, 1);
if (creature == NULL)
{
result += getErrorMessage (argv[0], ERR_INVALID_OBJECT);
}
else
{
char valbuf[32] = {"\0"};
result += Unicode::narrowToWide(std::string("Level "));
snprintf(valbuf, sizeof(valbuf), "%i", creature->getLevel());
result += Unicode::narrowToWide(std::string(valbuf));
result += Unicode::narrowToWide(std::string(" TotalLevelXp "));
snprintf(valbuf, sizeof(valbuf), "%i", creature->getLevelXp());
result += Unicode::narrowToWide(std::string(valbuf));
}
}
//-----------------------------------------------------------------
else
{
result += getErrorMessage (argv[0], ERR_NO_HANDLER);
}
return true;
}
// ======================================================================
@@ -0,0 +1,45 @@
// ======================================================================
//
// ConsoleCommandParserSkill.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserSkill_H
#define INCLUDED_ConsoleCommandParserSkill_H
#include "sharedCommandParser/CommandParser.h"
// ======================================================================
/**
* Commands that are related to skills
*/
class ConsoleCommandParserSkill :
public CommandParser
{
public:
ConsoleCommandParserSkill ();
virtual bool performParsing (const NetworkId & userId, const StringVector_t & argv,const String_t & originalCommand,String_t & result,const CommandParser * node);
private:
ConsoleCommandParserSkill (const ConsoleCommandParserSkill & rhs);
ConsoleCommandParserSkill & operator= (const ConsoleCommandParserSkill & rhs);
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserSkill_H
@@ -0,0 +1,321 @@
// ======================================================================
//
// ConsoleCommandParserSpaceAi.cpp
// Copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ConsoleCommandParserSpaceAi.h"
#include "serverGame/AiServerShipObjectInterface.h"
#include "serverGame/AiShipBehaviorAttackFighter.h"
#include "serverGame/AiShipBehaviorAttackFighter_Maneuver.h"
#include "serverGame/AiShipBehaviorBase.h"
#include "serverGame/AiShipController.h"
#include "serverGame/AiShipPilotData.h"
#include "serverGame/Chat.h"
#include "serverGame/CreatureObject.h"
#include "serverGame/SpacePath.h"
#include "serverGame/SpaceAttackSquad.h"
#include "sharedFoundation/FormattedString.h"
#include "sharedFoundation/NetworkId.h"
#include "sharedGame/AiDebugString.h"
#include "sharedNetworkMessages/GenericValueTypeMessage.h"
#include "sharedObject/NetworkIdManager.h"
#include "UnicodeUtils.h"
// ======================================================================
static const CommandParser::CmdInfo cmds[] =
{
{"war", 0, "", "Sets all AI to resume attacking"},
{"peace", 0, "", "Sets all AI to stop attacking."},
{"path", 1, "", "Sends the pathing points for the specified AI to the client."},
{"reloaddata", 0, "", "Reloads pilottype.tab"},
#ifdef _DEBUG
{"clientDebug", 0, "", "Toggles client AI debugging."},
{"serverDebug", 0, "", "Toggles the server to send AI debugging."},
{"clientDebugText", 0, "", "Toggles the client AI debugging text."},
{"maneuver", 1, "", "Forces the target ship to use evade, leash, or attack maneuvers."},
{"fastAxis", 0, "", "Ships rotate toward the target along the fast axis of rotation."},
//{"logall", 0, "", "Logs all AI to the server output log file."},
//{"log", 0, "", "Logs the specified objectIds to the server output log file."},
#endif // _DEBUG
{"", 0, "", ""} // this must be last
};
//-----------------------------------------------------------------
ConsoleCommandParserSpaceAi::ConsoleCommandParserSpaceAi()
: CommandParser("spaceai", 0, "...", "Space Ai related commands.", 0)
{
createDelegateCommands (cmds);
}
//-----------------------------------------------------------------
bool ConsoleCommandParserSpaceAi::performParsing(const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node)
{
NOT_NULL (node);
UNREF (userId);
UNREF(originalCommand);
if (isAbbrev(argv[0], "war"))
{
AiShipController::setAttackingEnabled(true);
Object * const object = NetworkIdManager::getObjectById(userId);
ServerObject * const serverObject = (object != NULL) ? object->asServerObject() : NULL;
if (serverObject != NULL)
{
Chat::sendSystemMessage(*serverObject, Unicode::narrowToWide("[WAR] AI will now attack."), Unicode::emptyString);
}
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isAbbrev(argv[0], "peace"))
{
AiShipController::setAttackingEnabled(false);
Object * const object = NetworkIdManager::getObjectById(userId);
ServerObject * const serverObject = (object != NULL) ? object->asServerObject() : NULL;
if (serverObject != NULL)
{
Chat::sendSystemMessage(*serverObject, Unicode::narrowToWide("[PEACE] AI will no longer attack."), Unicode::emptyString);
}
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isAbbrev(argv[0], "path"))
{
Object * const object = NetworkIdManager::getObjectById(userId);
ServerObject * const serverObject = (object != NULL) ? object->asServerObject() : NULL;
if ( (serverObject != NULL)
&& (argv.size () > 1))
{
NetworkId networkId(Unicode::wideToNarrow(argv[1]));
AiShipController * const aiShipController = AiShipController::getAiShipController(networkId);
if (aiShipController != NULL)
{
SpacePath * const spacePath = aiShipController->getPath();
if (spacePath != NULL)
{
SpacePath::TransformList const & transformList = spacePath->getTransformList();
SpacePath::TransformList::const_iterator iterTransformList = transformList.begin();
FormattedString<512> formattedString;
int index = 1;
std::string message;
message += formattedString.sprintf("Path of size(%u) for unit(%s)\n", transformList.size(), networkId.getValueString().c_str());
for (; iterTransformList != transformList.end(); ++iterTransformList)
{
Vector const & position_w = iterTransformList->getPosition_p();
message += formattedString.sprintf("[%d] %.2f, %.2f, %.2f%s", index++, position_w.x, position_w.y, position_w.z, (index < static_cast<int>(transformList.size())) ? "\n" : "");
}
Chat::sendSystemMessage(*serverObject, Unicode::narrowToWide(message.c_str()), Unicode::emptyString);
}
else
{
Chat::sendSystemMessage(*serverObject, Unicode::narrowToWide("NULL path"), Unicode::emptyString);
}
}
else
{
Chat::sendSystemMessage(*serverObject, Unicode::narrowToWide("[ERROR] Unable to resolve the obj_id for a path."), Unicode::emptyString);
}
}
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isAbbrev(argv[0], "reloaddata"))
{
Object * const object = NetworkIdManager::getObjectById(userId);
ServerObject * const serverObject = (object != NULL) ? object->asServerObject() : NULL;
if (serverObject != NULL)
{
AiShipPilotData::reload();
Chat::sendSystemMessage(*serverObject, Unicode::narrowToWide("[RELOAD DATA] pilottype.tab was reloaded"), Unicode::emptyString);
}
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
#ifdef _DEBUG
else if (isAbbrev(argv[0], "clientDebug"))
{
Object * const object = NetworkIdManager::getObjectById(userId);
ServerObject * const serverObject = (object != NULL) ? object->asServerObject() : NULL;
int temp;
if (serverObject != NULL)
{
if ( serverObject->getObjVars().getItem("ai_debug_string", temp)
&& (temp > 0))
{
if (!AiShipController::isClientDebugEnabled())
{
AiShipController::setClientDebugEnabled(true);
Chat::sendSystemMessage(*serverObject, Unicode::narrowToWide("[ENABLED] Your client is requesting ai debugging."), Unicode::emptyString);
}
else
{
IGNORE_RETURN(serverObject->setObjVarItem("ai_debug_string", 0));
Chat::sendSystemMessage(*serverObject, Unicode::narrowToWide("[DISABLED] Your client is NO LONGER requesting ai debugging."), Unicode::emptyString);
// Tell the client to remove all ai debugging
Client * const client = serverObject->getClient();
if (client != NULL)
{
AiDebugString aiDebugString;
aiDebugString.enableClearClientFlag();
bool const reliable = true;
GenericValueTypeMessage<std::pair<NetworkId, std::string> > message("AiDebugString", std::make_pair(serverObject->getNetworkId(), aiDebugString.toString()));
client->send(message, reliable);
}
}
}
else
{
IGNORE_RETURN(serverObject->setObjVarItem("ai_debug_string", 1));
Chat::sendSystemMessage(*serverObject, Unicode::narrowToWide("[ENABLED] Your client is requesting ai debugging."), Unicode::emptyString);
if (!AiShipController::isClientDebugEnabled())
{
AiShipController::setClientDebugEnabled(true);
}
}
}
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isAbbrev(argv[0], "serverDebug"))
{
Object * const object = NetworkIdManager::getObjectById(userId);
ServerObject * const serverObject = (object != NULL) ? object->asServerObject() : NULL;
if (serverObject != NULL)
{
AiShipController::setClientDebugEnabled(!AiShipController::isClientDebugEnabled());
Unicode::String systemMessage;
systemMessage = Unicode::narrowToWide(AiShipController::isClientDebugEnabled() ? "[ENABLED] Server is sending debug ai to requesting clients." : "[DISABLED] Server is NO LONGER sending debug ai to requesting clients.");
Chat::sendSystemMessage(*serverObject, systemMessage, Unicode::emptyString);
}
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isAbbrev(argv[0], "clientDebugText"))
{
Object * const object = NetworkIdManager::getObjectById(userId);
ServerObject * const serverObject = (object != NULL) ? object->asServerObject() : NULL;
if (serverObject != NULL)
{
AiDebugString::setTextEnabled(!AiDebugString::isTextEnabled());
Unicode::String systemMessage;
systemMessage = Unicode::narrowToWide(AiDebugString::isTextEnabled() ? "[ENABLED] Client-side debug text is enabled." : "[DISABLED] Client-side debug text is disabled.");
Chat::sendSystemMessage(*serverObject, systemMessage, Unicode::emptyString);
}
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isAbbrev(argv[0], "maneuver"))
{
Object * const object = NetworkIdManager::getObjectById(userId);
ServerObject * const serverObject = (object != NULL) ? object->asServerObject() : NULL;
CreatureObject const * const creatureObject = serverObject ? serverObject->asCreatureObject() : NULL;
if (serverObject)
{
if ((creatureObject != NULL) && (argv.size () > 1))
{
AiShipController const * const lookAtAiShipController = AiShipController::getAiShipController(creatureObject->getLookAtTarget());
if (lookAtAiShipController)
{
SpaceAttackSquad const & attackSquad = lookAtAiShipController->getAttackSquad();
AiShipController * const squadLeaderAiShipController = AiShipController::getAiShipController(attackSquad.getLeader());
bool success = false;
if (isAbbrev(argv[1], "evade"))
{
success = squadLeaderAiShipController->debug_forceFighterAttackManeuver(static_cast<int>(AiShipBehaviorAttackFighter::Maneuver::FM_evade));
}
else if (isAbbrev(argv[1], "chase"))
{
success = squadLeaderAiShipController->debug_forceFighterAttackManeuver(static_cast<int>(AiShipBehaviorAttackFighter::Maneuver::FM_chase));
}
else if (isAbbrev(argv[1], "leash"))
{
success = squadLeaderAiShipController->debug_forceFighterAttackManeuver(static_cast<int>(AiShipBehaviorAttackFighter::Maneuver::FM_leash));
}
else if (isAbbrev(argv[1], "none"))
{
success = squadLeaderAiShipController->debug_forceFighterAttackManeuver(static_cast<int>(AiShipBehaviorAttackFighter::Maneuver::FM_none));
}
else
{
Chat::sendSystemMessage(*serverObject, Unicode::narrowToWide("Valid parameters are: [evade], [attack] or [chase], [leash], and [none]."), Unicode::emptyString);
}
if (!success)
{
Chat::sendSystemMessage(*serverObject, Unicode::narrowToWide("Failed to set the maneuver on the target. The target must be in the AiShipBehaviorAttackFighter state. This fails on a bomber or capship behavior."), Unicode::emptyString);
}
}
else
{
Chat::sendSystemMessage(*serverObject, Unicode::narrowToWide("Incorrect number of arguments."), Unicode::emptyString);
}
}
}
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else if (isAbbrev(argv[0], "fastAxis"))
{
Object * const object = NetworkIdManager::getObjectById(userId);
ServerObject * const serverObject = (object != NULL) ? object->asServerObject() : NULL;
if (serverObject != NULL)
{
Unicode::String systemMessage;
AiServerShipObjectInterface::setFastAxisEnabled(!AiServerShipObjectInterface::isFastAxisEnabled());
systemMessage += Unicode::narrowToWide(AiServerShipObjectInterface::isFastAxisEnabled() ? "[ENABLED] AI ships now use the fast axis." : "[DISABLED] AI ships are no longer using the fast axis.");
Chat::sendSystemMessage(*serverObject, systemMessage, Unicode::emptyString);
}
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
#endif //_DEBUG
else
{
result += getErrorMessage(argv[0], ERR_NO_HANDLER);
}
return true;
}
// ======================================================================
@@ -0,0 +1,38 @@
// ======================================================================
//
// ConsoleCommandParserSpaceAi.h
// Copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserSpaceAi_H
#define INCLUDED_ConsoleCommandParserSpaceAi_H
#include "sharedCommandParser/CommandParser.h"
#include "sharedFoundation/DynamicVariableList.h"
// ======================================================================
/**
* Commands that are related to objvars
*/
class ConsoleCommandParserSpaceAi : public CommandParser
{
public:
ConsoleCommandParserSpaceAi();
virtual bool performParsing(const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node);
private:
ConsoleCommandParserSpaceAi(const ConsoleCommandParserSpaceAi & rhs);
ConsoleCommandParserSpaceAi & operator =(const ConsoleCommandParserSpaceAi & rhs);
int getArgumentType(const Unicode::NarrowString &arg) const;
void listObjvars(const DynamicVariableList::NestedList &objvarList, String_t &result, int tabCount, bool withPackingData);
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserSpaceAi_H
@@ -0,0 +1,130 @@
// ======================================================================
//
// ConsoleCommandParserSpawner.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ConsoleCommandParserSpawner.h"
#include "UnicodeUtils.h"
#include "serverGame/CreatureObject.h"
#include <cstdio>
#include <hash_set>
// ======================================================================
namespace
{
namespace CommandNames
{
#define MAKE_COMMAND(a) const char * const a = #a
MAKE_COMMAND(showQueue);
MAKE_COMMAND(showCreatures);
#undef MAKE_COMMAND
}
const CommandParser::CmdInfo cmds[] =
{
{CommandNames::showQueue, 0, "", "Lists players on the spawn queue."},
{CommandNames::showCreatures, 0, "[pc|npc]", "Lists all creatures on the server."},
{"", 0, "", ""} // this must be last
};
}
//-----------------------------------------------------------------
ConsoleCommandParserSpawner::ConsoleCommandParserSpawner (void) :
CommandParser ("Spawner", 0, "...", "Spawner related commands.", 0)
{
createDelegateCommands (cmds);
}
//----------------------------------------------------------------------
bool ConsoleCommandParserSpawner::performParsing (const NetworkId &, const StringVector_t & argv, const String_t & , String_t & result, const CommandParser *)
{
// ----------------------------------------------------------------
if (isCommand (argv[0], CommandNames::showQueue))
{
CreatureObject::showSpawnQueue(result);
return true;
}
else if(isCommand (argv[0], CommandNames::showCreatures))
{
bool npcOnly = false;
bool pcOnly = false;
if(argv.size() >= 2)
{
std::string arg2 = Unicode::wideToNarrow(argv[1]);
if(arg2 == "npc")
{
npcOnly = true;
}
else if(arg2 == "pc")
{
pcOnly = true;
}
}
static const Unicode::String header(Unicode::narrowToWide(std::string("Creature Listing - ID: POS: Auth Server: Template Name\n")));
result += header;
const CreatureObject::AllCreaturesSet & creatureList = CreatureObject::getAllCreatures();
CreatureObject::AllCreaturesSet::const_iterator i;
int count = 0;
for(i = creatureList.begin(); i != creatureList.end(); ++i)
{
const CreatureObject * creature = (*i);
if(creature)
{
if(pcOnly && (!creature->isPlayerControlled()) )
continue;
if(npcOnly && creature->isPlayerControlled())
continue;
std::string creatureEntry = creature->getNetworkId().getValueString();
creatureEntry += ": ";
char locBuffer[32] = {"\0"};
Vector loc = creature->getTransform_o2w().getPosition_p();
snprintf(locBuffer, sizeof(locBuffer), "%.0f, %.0f: ", loc.x, loc.z);
creatureEntry += locBuffer;
snprintf(locBuffer, sizeof(locBuffer), "%lu: ", creature->getAuthServerProcessId());
creatureEntry += locBuffer;
creatureEntry += creature->getObjectTemplateName();
creatureEntry += "\n";
result += Unicode::narrowToWide(creatureEntry);
count++;
}
}
char countBuffer[32] = {"\0"};
snprintf(countBuffer, sizeof(countBuffer), "%d creatures listed: ", count);
result += Unicode::narrowToWide(std::string(countBuffer));
return true;
}
else
{
result += getErrorMessage (argv[0], ERR_NO_HANDLER);
return false;
}
return true;
}
// ======================================================================
@@ -0,0 +1,45 @@
// ======================================================================
//
// ConsoleCommandParserSpawner.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserSpawner_H
#define INCLUDED_ConsoleCommandParserSpawner_H
#include "sharedCommandParser/CommandParser.h"
// ======================================================================
/**
* Commands that are related to Spawners
*/
class ConsoleCommandParserSpawner :
public CommandParser
{
public:
ConsoleCommandParserSpawner ();
virtual bool performParsing (const NetworkId & userId, const StringVector_t & argv,const String_t & originalCommand,String_t & result,const CommandParser * node);
private:
ConsoleCommandParserSpawner (const ConsoleCommandParserSpawner & rhs);
ConsoleCommandParserSpawner & operator= (const ConsoleCommandParserSpawner & rhs);
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserSpawner_H
@@ -0,0 +1,157 @@
// ======================================================================
//
// ConsoleCommandParserVeteran.cpp
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ConsoleCommandParserVeteran.h"
#include "UnicodeUtils.h"
#include "serverGame/ConfigServerGame.h"
#include "serverGame/GameServer.h"
#include "serverGame/ServerMessageForwarding.h"
#include "serverGame/ServerObject.h"
#include "serverGame/VeteranRewardManager.h"
#include "sharedNetworkMessages/GenericValueTypeMessage.h"
#include "sharedObject/NetworkIdManager.h"
//-----------------------------------------------------------------------
static const CommandParser::CmdInfo cmds[] =
{
{"getRewardInfo", 1,"<player oid>","Get the reward status of a player."},
{"claimReward", 3,"<player oid> <event tag> <reward item tag>","For testing, claim a reward using the specified event."},
{"launchBrowser", 1,"<url>","Test launching a web browser."},
{"setOverrideAccountAge",1,"<age>","For testing, set all accounts as being the speficied age (in days)"},
{"", 0, "", ""} // this must be last
};
ConsoleCommandParserVeteran::ConsoleCommandParserVeteran() :
CommandParser ("veteran", 0, "...", "commands for the veteran reward system", 0)
{
createDelegateCommands (cmds);
}
//-----------------------------------------------------------------------
bool ConsoleCommandParserVeteran::performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & /* originalMessage */, String_t & result, const CommandParser *)
{
if (isCommand( argv [0], "getRewardInfo"))
{
NetworkId targetPlayer(Unicode::wideToNarrow (argv[1]));
ServerObject const * const so = safe_cast<ServerObject const *>(NetworkIdManager::getObjectById(targetPlayer));
Client const * const client = so ? so->getClient() : NULL;
if (client)
{
std::string output;
// Claimed Rewards:
std::vector<std::pair<NetworkId, std::string> > const & accountConsumedRewardEvents = client->getConsumedRewardEvents();
std::vector<std::pair<NetworkId, std::string> > const & accountClaimedRewardItems = client->getClaimedRewardItems();
std::vector<std::string> localConsumedRewardEvents;
VeteranRewardManager::getConsumedEvents(*so, localConsumedRewardEvents);
std::vector<std::string> localClaimedRewardItems;
VeteranRewardManager::getClaimedItems(*so, localClaimedRewardItems);
std::vector<std::pair<NetworkId, std::string> >::const_iterator i;
output += "Consumed reward events (login server db): ";
for (i = accountConsumedRewardEvents.begin(); i != accountConsumedRewardEvents.end(); ++i)
{
if (i != accountConsumedRewardEvents.begin())
output += ", ";
output += '(' + i->first.getValueString() + ") " + i->second;
}
output += "\nClaimed reward items (login server db): ";
for (i = accountClaimedRewardItems.begin(); i != accountClaimedRewardItems.end(); ++i)
{
if (i != accountClaimedRewardItems.begin())
output += ", ";
output += '(' + i->first.getValueString() + ") " + i->second;
}
std::vector<std::string>::const_iterator j;
output += "\nConsumed reward events (cluster db): ";
for (j = localConsumedRewardEvents.begin(); j != localConsumedRewardEvents.end(); ++j)
{
if (j != localConsumedRewardEvents.begin())
output += ", ";
output += *j;
}
output += "\nClaimed reward items (cluster db): ";
for (j = localClaimedRewardItems.begin(); j != localClaimedRewardItems.end(); ++j)
{
if (j != localClaimedRewardItems.begin())
output += ", ";
output += *j;
}
output += "\n";
// Criteria used for granting rewards:
unsigned int const entitledTime = client->getEntitlementEntitledTime();
uint32 const gameFeatures = client->getGameFeatures();
bool const adminLogin = client->isUsingAdminLogin();
char buffer[256];
snprintf(buffer,sizeof(buffer),"Entitled time: %u\nGame features: %lu\nUsing admin login: %s\n",
entitledTime, gameFeatures, adminLogin ? "true" : "false");
buffer[sizeof(buffer)-1]='\0';
output += buffer;
result += Unicode::narrowToWide(output);
}
else
result += getErrorMessage(argv[0],ERR_INVALID_OBJECT);
}
if (isCommand( argv [0], "claimReward"))
{
NetworkId targetPlayer(Unicode::wideToNarrow(argv[1]));
ServerObject const * const so = safe_cast<ServerObject const *>(NetworkIdManager::getObjectById(targetPlayer));
CreatureObject const * const playerCreature = so ? so->asCreatureObject() : NULL;
if (!playerCreature)
result += getErrorMessage(argv[0],ERR_INVALID_OBJECT);
else
{
std::string event(Unicode::wideToNarrow(argv[2]));
std::string item(Unicode::wideToNarrow(argv[3]));
std::string resultMessage;
if (VeteranRewardManager::claimRewards(*playerCreature, event, item, &resultMessage))
result += Unicode::narrowToWide("returned true");
else
result += Unicode::narrowToWide("returned false, message: " + resultMessage);
}
}
if (isCommand( argv [0], "launchBrowser"))
{
std::string url(Unicode::wideToNarrow(argv[1]));
ServerObject const * const so = safe_cast<ServerObject const *>(NetworkIdManager::getObjectById(userId));
Client const * const client = so ? so->getClient() : NULL;
if (client)
{
client->launchWebBrowser(url);
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else
result+=Unicode::narrowToWide("Could not get Client object");
}
if (isCommand( argv [0], "setOverrideAccountAge"))
{
if (ConfigServerGame::getVeteranDebugEnableOverrideAccountAge())
{
int age(atoi(Unicode::wideToNarrow(argv[1]).c_str()));
VeteranRewardManager::setOverrideAccountAge(age);
ServerMessageForwarding::beginBroadcast();
ServerMessageForwarding::send(GenericValueTypeMessage<int>("SetOverrideAccountAgeMessage",age));
ServerMessageForwarding::end();
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
else
result += Unicode::narrowToWide("\"veteranDebugEnableOverrideAccountAge\" must be set to \"true\" in the server config file to use this feature.");
}
return true;
}
//-----------------------------------------------------------------------
@@ -0,0 +1,32 @@
// ======================================================================
//
// ConsoleCommandParserVeteran.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserVeteran_H
#define INCLUDED_ConsoleCommandParserVeteran_H
#include "sharedCommandParser/CommandParser.h"
// ======================================================================
/**
* Commands that are related to the veteran rewards system.
*/
class ConsoleCommandParserVeteran : public CommandParser
{
public:
ConsoleCommandParserVeteran ();
virtual bool performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node);
private:
ConsoleCommandParserVeteran (const ConsoleCommandParserVeteran & rhs);
ConsoleCommandParserVeteran & operator= (const ConsoleCommandParserVeteran & rhs);
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserVeteran_H
@@ -0,0 +1,238 @@
// ======================================================================
//
// ConsoleCommandParserVoice.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
#include "ConsoleCommandParserVoice.h"
#include "UnicodeUtils.h"
#include "serverGame/Chat.h"
#include "sharedLog/Log.h"
//#include "serverGame/PlayerCreatureController.h"
//#include "serverGame/PlayerObject.h"
//#include "serverGame/ServerWorld.h"
#include "sharedNetworkMessages/VoiceChatMiscMessages.h"
// ======================================================================
static const CommandParser::CmdInfo cmds[] =
{
{"channelannounce", 3, "<oid> <channelName> <channelURI>", "Tell a client about a channel without checking if it exitsts."},
{"channeljoin", 4, "<oid> <channelName> <channelURI> <channelPassword>", "Force a client to join a channel"},
{"channelleave", 2, "<oid> <channelName>", "Tell a client to forget about and leave a channel"},
{"channelcreate", 1, "<channelName>", "Create a voice chat room. Give full path ie. SWG.cluster.chanName"},
{"channeldestroy", 1, "<channelName>", "Destroy a voice chat room (name must be fully qualified ie SWG.clustername.channelname)"},
{"addtochannel", 2, "<oid> <channelName>", "Give a client access to a channel. Channel must exist."},
{"removefromchannel", 2, "<oid> <channelName>", "Remove a client's access to a channel"},
{"channelcommand", 3, "<destUser> <channelName> <command> <banTimeout>", "Execute a moderator command in the given channel (fully qualify channel name). Commands are [mute unmute kick hangup invite ban unban chan_lock chan_unlock mute_all unmute_all add_moderator delete_moderator add_acl delete_acl]"},
{"globalchannelmessage", 2, "<channelName> <message> [remove]", "Broadcast a global channel message to everyone on this cluster. Removes if remove != 0."},
{"allclusterglobalchannelmessage", 2, "<channelName> <message> [remove]", "Broadcast a global channel message to everyone on ALL CLUSTERS. Removes if remove != 0."},
{"", 0, "", ""} // this must be last
};
//-----------------------------------------------------------------
ConsoleCommandParserVoice::ConsoleCommandParserVoice (void) :
CommandParser ("voice", 0, "...", "Voice chat related commands.", 0)
{
createDelegateCommands (cmds);
}
//-----------------------------------------------------------------
bool ConsoleCommandParserVoice::performParsing (const NetworkId & userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node)
{
NOT_NULL (node);
UNREF(originalCommand);
UNREF(userId);
//CreatureObject * creatureObject = safe_cast<CreatureObject *>(ServerWorld::findObjectByNetworkId(userId));
//PlayerObject * playerObject = const_cast<PlayerObject *>(PlayerCreatureController::getPlayerObject(creatureObject));
//-----------------------------------------------------------------
static Unicode::String requestSubmittedMessage = Unicode::narrowToWide("request successfully submitted");
if (isAbbrev(argv[0], "channelannounce"))
{
NetworkId oid(Unicode::wideToNarrow(argv[1]));
std::string name = Unicode::wideToNarrow(argv[2]);
std::string uri = Unicode::wideToNarrow(argv[3]);
std::string password = "";
if(Chat::debugTellClientAboutRoom(oid, name, uri, password, false, false))
{
result += requestSubmittedMessage;
}
else
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
}
return true;
}
if (isAbbrev(argv[0], "channeljoin"))
{
NetworkId oid(Unicode::wideToNarrow(argv[1]));
std::string name = Unicode::wideToNarrow(argv[2]);
std::string uri = Unicode::wideToNarrow(argv[3]);
std::string password = Unicode::wideToNarrow(argv[4]);
if(Chat::debugTellClientAboutRoom(oid, name, uri, password, true, false))
{
result += requestSubmittedMessage;
}
else
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
}
return true;
}
if (isAbbrev(argv[0], "channelleave"))
{
NetworkId oid(Unicode::wideToNarrow(argv[1]));
std::string name = Unicode::wideToNarrow(argv[2]);
std::string uri = "";
std::string password = "";
if(Chat::debugTellClientAboutRoom(oid, name, uri, password, false, true))
{
result += requestSubmittedMessage;
}
else
{
result += getErrorMessage(argv[0], ERR_INVALID_OBJECT);
}
return true;
}
if (isAbbrev(argv[0], "addtochannel"))
{
NetworkId oid(Unicode::wideToNarrow(argv[1]));
std::string channelName = Unicode::wideToNarrow(argv[2]);
Chat::requestAddClientToChannel(oid, "", channelName, false);
result += requestSubmittedMessage;
return true;
}
if (isAbbrev(argv[0], "removefromchannel"))
{
NetworkId oid(Unicode::wideToNarrow(argv[1]));
std::string channelName = Unicode::wideToNarrow(argv[2]);
Chat::requestRemoveClientFromChannel(oid, "", channelName);
result += requestSubmittedMessage;
return true;
}
if (isAbbrev(argv[0], "channelcreate"))
{
std::string name = Unicode::wideToNarrow(argv[1]);
Chat::requestGetChannel(name, name,"",false);
result += requestSubmittedMessage;
return true;
}
if (isAbbrev(argv[0], "channeldestroy"))
{
std::string name = Unicode::wideToNarrow(argv[1]);
Chat::requestDestroyChannel(name);
result += requestSubmittedMessage;
return true;
}
if(isAbbrev(argv[0], "channelcommand"))
{
static bool mapInited = false;
static std::map<std::string, uint32> commandTypeLookupMap;
if(!mapInited)
{
commandTypeLookupMap["mute"] = COMMAND_MUTE;
commandTypeLookupMap["unmute"] = COMMAND_UNMUTE;
commandTypeLookupMap["kick"] = COMMAND_KICK;
commandTypeLookupMap["hangup"] = COMMAND_HANGUP;
commandTypeLookupMap["invite"] = COMMAND_INVITE;
commandTypeLookupMap["ban"] = COMMAND_BAN;
commandTypeLookupMap["unban"] = COMMAND_UNBAN;
commandTypeLookupMap["chan_lock"] = COMMAND_CHAN_LOCK;
commandTypeLookupMap["chan_unlock"] = COMMAND_CHAN_UNLOCK;
commandTypeLookupMap["mute_all"] = COMMAND_MUTE_ALL;
commandTypeLookupMap["unmute_all"] = COMMAND_UNMUTE_ALL;
commandTypeLookupMap["add_moderator"] = COMMAND_ADD_MODERATOR;
commandTypeLookupMap["delete_moderaror"] = COMMAND_DELETE_MODERATOR;
commandTypeLookupMap["add_acl"] = COMMAND_ADD_ACL;
commandTypeLookupMap["delete_acl"] = COMMAND_DELETE_ACL;
mapInited = true;
}
std::string destUser = Unicode::wideToNarrow(argv[1]);
std::string destChan = Unicode::wideToNarrow(argv[2]);
std::string strCommandType = Unicode::wideToNarrow(argv[3]);
uint32 banTimeout = argv.size() > 4 ? static_cast<uint32>(atoi(Unicode::wideToNarrow(argv[4]).c_str())) : 0;
std::map<std::string,uint32>::const_iterator i = commandTypeLookupMap.find(strCommandType);
if(i != commandTypeLookupMap.end())
{
//@TODO: send a valid source user that will always have moderator powers
uint32 commandType = i->second;
Chat::requestChannelCommand("",destUser,destChan,commandType,banTimeout);
result += requestSubmittedMessage;
}
else
{
result += Unicode::narrowToWide("Unknown channel command type");
}
return true;
}
if (isAbbrev(argv[0], "globalchannelmessage"))
{
std::string name = Unicode::getTrim(Unicode::wideToNarrow(argv[1]));
std::string message = Unicode::wideToNarrow(argv[2]);
bool isRemove = argv.size() > 3 ? (atoi(Unicode::wideToNarrow(argv[3]).c_str()) != 0) : 0;
LOG("CustomerService", ("BroadcastVoiceChannel: GameServer::globalchannelmessage issued by id(%s) chan(%s) text(%s) remove(%d)",
userId.getValueString().c_str(), name.c_str(), message.c_str(), (isRemove ? 1 : 0)));
Chat::requestBroadcastGlobalChannelMessage(name, message, isRemove, false);
result += requestSubmittedMessage;
return true;
}
if(isAbbrev(argv[0], "allclusterglobalchannelmessage"))
{
std::string name = Unicode::getTrim(Unicode::wideToNarrow(argv[1]));
std::string message = Unicode::wideToNarrow(argv[2]);
bool isRemove = argv.size() > 3 ? (atoi(Unicode::wideToNarrow(argv[3]).c_str()) != 0) : 0;
LOG("CustomerService", ("BroadcastVoiceChannel: GameServer::allclusterglobalchannelmessage issued by id(%s) chan(%s) text(%s) remove(%d)",
userId.getValueString().c_str(), name.c_str(), message.c_str(), (isRemove ? 1 : 0)));
Chat::requestBroadcastGlobalChannelMessage(name, message, isRemove, true);
result += requestSubmittedMessage;
return true;
}
result += getErrorMessage(argv[0], ERR_NO_HANDLER);
return true;
}
// ======================================================================
@@ -0,0 +1,48 @@
// ======================================================================
//
// ConsoleCommandParserVoice.h
// copyright (c) 2008 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ConsoleCommandParserVoice_H
#define INCLUDED_ConsoleCommandParserVoice_H
#include "sharedCommandParser/CommandParser.h"
// ======================================================================
/**
* Commands that are related to voice chat
*/
class ConsoleCommandParserVoice : public CommandParser
{
public:
ConsoleCommandParserVoice ();
virtual bool performParsing (const NetworkId & userId,
const StringVector_t & argv,
const String_t & originalCommand,
String_t & result,
const CommandParser * node);
private:
ConsoleCommandParserVoice (const ConsoleCommandParserVoice & rhs);
ConsoleCommandParserVoice & operator= (const ConsoleCommandParserVoice & rhs);
};
// ======================================================================
#endif // INCLUDED_ConsoleCommandParserVoice_H
@@ -0,0 +1,142 @@
// ConsoleMgr.cpp
// copyright 2000 Verant Interactive
// Author: Chris Mayer
//-----------------------------------------------------------------------
#include "serverGame/FirstServerGame.h"
#include "serverGame/ConsoleManager.h"
#include <cstdio>
#include <cstdlib>
#include "SwgGameServer/ConsoleCommandParserCombatEngine.h"
#include "SwgGameServer/ConsoleCommandParserCombatEngine.h"
#include "serverGame/Client.h"
#include "serverGame/ConsoleCommandParserAi.h"
#include "serverGame/ConsoleCommandParserCity.h"
#include "serverGame/ConsoleCommandParserCollection.h"
#include "serverGame/ConsoleCommandParserCraft.h"
#include "serverGame/ConsoleCommandParserDefault.h"
#include "serverGame/ConsoleCommandParserGuild.h"
#include "serverGame/ConsoleCommandParserManufacture.h"
#include "serverGame/ConsoleCommandParserMessageTo.h"
#include "serverGame/ConsoleCommandParserMoney.h"
#include "serverGame/ConsoleCommandParserNpc.h"
#include "serverGame/ConsoleCommandParserObject.h"
#include "serverGame/ConsoleCommandParserObjvar.h"
#include "serverGame/ConsoleCommandParserPvp.h"
#include "serverGame/ConsoleCommandParserResource.h"
#include "serverGame/ConsoleCommandParserScript.h"
#include "serverGame/ConsoleCommandParserServer.h"
#include "serverGame/ConsoleCommandParserShip.h"
#include "serverGame/ConsoleCommandParserSkill.h"
#include "serverGame/ConsoleCommandParserSpaceAi.h"
#include "serverGame/ConsoleCommandParserSpawner.h"
#include "serverGame/ConsoleCommandParserVeteran.h"
#include "serverGame/ConsoleCommandParserVoice.h"
#include "serverGame/GameServer.h"
#include "serverGame/ServerObject.h"
#include "serverGame/ServerWorld.h"
#include "sharedCommandParser/CommandParser.h"
#include "sharedNetworkMessages/ConsoleChannelMessages.h"
CommandParser * ConsoleMgr::ms_parser = NULL;
//-----------------------------------------------------------------------
void ConsoleMgr::install()
{
if (ms_parser == NULL)
{
ms_parser = new ConsoleCommandParserDefault();
ms_parser->addSubCommand(new ConsoleCommandParserCombatEngine ());
ms_parser->addSubCommand(new ConsoleCommandParserCraft ());
ms_parser->addSubCommand(new ConsoleCommandParserManufacture ());
ms_parser->addSubCommand(new ConsoleCommandParserMoney ());
ms_parser->addSubCommand(new ConsoleCommandParserNpc ());
ms_parser->addSubCommand(new ConsoleCommandParserObject ());
ms_parser->addSubCommand(new ConsoleCommandParserObjvar ());
ms_parser->addSubCommand(new ConsoleCommandParserResource ());
ms_parser->addSubCommand(new ConsoleCommandParserScript ());
ms_parser->addSubCommand(new ConsoleCommandParserServer ());
ms_parser->addSubCommand(new ConsoleCommandParserSkill ());
ms_parser->addSubCommand(new ConsoleCommandParserSpawner ());
ms_parser->addSubCommand(new ConsoleCommandParserShip ());
ms_parser->addSubCommand(new ConsoleCommandParserSpaceAi ());
ms_parser->addSubCommand(new ConsoleCommandParserAi ());
ms_parser->addSubCommand(new ConsoleCommandParserVeteran ());
ms_parser->addSubCommand(new ConsoleCommandParserMessageTo ());
ms_parser->addSubCommand(new ConsoleCommandParserPvp ());
ms_parser->addSubCommand(new ConsoleCommandParserGuild ());
ms_parser->addSubCommand(new ConsoleCommandParserCollection ());
ms_parser->addSubCommand(new ConsoleCommandParserVoice ());
ms_parser->addSubCommand(new ConsoleCommandParserCity ());
}
} // ConsoleMgr::install
//-----------------------------------------------------------------------
void ConsoleMgr::remove()
{
if (ms_parser != NULL)
{
delete ms_parser;
ms_parser = NULL;
}
} // ConsoleMgr::remove
//-----------------------------------------------------------------------
void ConsoleMgr::processString(const std::string & msg, Client *from, uint32 msgId)
{
DEBUG_REPORT_LOG_PRINT(true, ("Console Message Received: %s\n",(msg.c_str())));
if (ms_parser == NULL)
{
DEBUG_WARNING(true, ("Console command parser has not been created!"));
return;
}
CommandParser::String_t wideMsg = Unicode::narrowToWide(msg);
CommandParser::String_t result;
const CommandParser::ErrorType retval = ms_parser->parse(from->getCharacterObjectId (), wideMsg, result);
if (retval == CommandParser::ERR_NO_HANDLER)
{
// @todo: make this message lookup from string table
result += Unicode::narrowToWide("Console Parser Failed!");
}
else if (result.empty())
result += Unicode::narrowToWide("Command [%s%s] succeeded.") + wideMsg.substr(0, 8) + ((wideMsg.size() > 8) ? Unicode::narrowToWide("...") : Unicode::emptyString);
broadcastString(result, from, msgId);
}
//-----------------------------------------------------------------------
void ConsoleMgr::broadcastString(const std::string & msg, Client *to, uint32 msgId)
{
ConGenericMessage m(msg, msgId);
DEBUG_WARNING(! to, ("Do not BROADCAST messages anymore! specify which client to send to or don't send the message\n"));
if (to)
{
to->send(m, true);
}
}
//-----------------------------------------------------------------------
void ConsoleMgr::broadcastString(const std::string & msg, NetworkId to, uint32 msgId)
{
ServerObject * object = ServerWorld::findObjectByNetworkId(to, true);
if (object)
{
if (object->getClient())
broadcastString(msg, object->getClient(), msgId);
}
}
//-----------------------------------------------------------------------
@@ -0,0 +1,41 @@
// ConsoleMgr.h
// copyright 2000 Verant Interactive
// Author: Chris Mayer
#ifndef INCLUDED_ConsoleMgr_H
#define INCLUDED_ConsoleMgr_H
#include "sharedCommandParser/CommandParser.h"
#include "UnicodeUtils.h"
class Client;
class ConsoleMgr
{
public:
static void install();
static void remove();
static void processString(const std::string & msg, Client *from = NULL,uint32 msgId = 0);
static void broadcastString(const std::string & msg, Client *to = NULL, uint32 msgId = 0);
static void broadcastString(const CommandParser::String_t & msg, Client *to = NULL, uint32 msgId = 0);
static void broadcastString(const std::string & msg, NetworkId to, uint32 msgId = 0);
private:
ConsoleMgr();
~ConsoleMgr();
static CommandParser * ms_parser;
};
inline void ConsoleMgr::broadcastString(const CommandParser::String_t & msg, Client *to, uint32 msgId)
{
broadcastString(Unicode::wideToNarrow(msg), to, msgId);
}
#endif // INCLUDED_ConsoleMgr_H
@@ -0,0 +1,58 @@
// ======================================================================
//
// ObjectCommandParserGetAttributes.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ObjectCommandParserGetAttributes.h"
#include "serverScript/GameScriptObject.h"
#include "serverGame/ServerWorld.h"
#include "serverGame/ServerObject.h"
// ======================================================================
static const CommandParser::CmdInfo cmds[] =
{
{"hitpoints", 2, "<oid> <value>", "View an object's hitpoints."},
{"", 0, "", ""} // this must be last
};
//-----------------------------------------------------------------
ObjectCommandParserGetAttributes::ObjectCommandParserGetAttributes (void) :
CommandParser ("getAttribute", 0, "...", "Commands to set attributes on objects", 0)
{
createDelegateCommands (cmds);
}
//-----------------------------------------------------------------
bool ObjectCommandParserGetAttributes::performParsing (NetworkId userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node)
{
NOT_NULL (node);
UNREF(originalCommand);
UNREF (userId);
//-----------------------------------------------------------------
if (isAbbrev( argv [0], "hitpoints"))
{
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
//-----------------------------------------------------------------
else
{
result += getErrorMessage(argv[0], ERR_NO_HANDLER);
}
return true;
}
// ======================================================================
@@ -0,0 +1,32 @@
// ======================================================================
//
// ObjectCommandParserGetAttributes.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ObjectCommandParserGetAttributes_H
#define INCLUDED_ObjectCommandParserGetAttributes_H
#include "sharedCommandParser/CommandParser.h"
// ======================================================================
/**
* Commands that are related to scripts
*/
class ObjectCommandParserGetAttributes : public CommandParser
{
public:
ObjectCommandParserGetAttributes ();
virtual bool performParsing (NetworkId userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node);
private:
ObjectCommandParserGetAttributes (const ObjectCommandParserGetAttributes & rhs);
ObjectCommandParserGetAttributes & operator= (const ObjectCommandParserGetAttributes & rhs);
};
// ======================================================================
#endif // INCLUDED_ObjectCommandParserGetAttributes_H
@@ -0,0 +1,58 @@
// ======================================================================
//
// ObjectCommandParserSetAttributes.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ObjectCommandParserSetAttributes.h"
#include "serverScript/GameScriptObject.h"
#include "serverGame/ServerWorld.h"
#include "serverGame/ServerObject.h"
// ======================================================================
static const CommandParser::CmdInfo cmds[] =
{
{"hitpoints", 2, "<oid> <value>", "Modify an object's hitpoints."},
{"", 0, "", ""} // this must be last
};
//-----------------------------------------------------------------
ObjectCommandParserSetAttributes::ObjectCommandParserSetAttributes (void) :
CommandParser ("setAttribute", 0, "...", "Commands to set attributes on objects", 0)
{
createDelegateCommands (cmds);
}
//-----------------------------------------------------------------
bool ObjectCommandParserSetAttributes::performParsing (NetworkId userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node)
{
NOT_NULL (node);
UNREF(originalCommand);
UNREF (userId);
//-----------------------------------------------------------------
if (isAbbrev( argv [0], "hitpoints"))
{
result += getErrorMessage(argv[0], ERR_SUCCESS);
}
//-----------------------------------------------------------------
else
{
result += getErrorMessage(argv[0], ERR_NO_HANDLER);
}
return true;
}
// ======================================================================
@@ -0,0 +1,32 @@
// ======================================================================
//
// ObjectCommandParserSetAttributes.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ObjectCommandParserSetAttributes_H
#define INCLUDED_ObjectCommandParserSetAttributes_H
#include "sharedCommandParser/CommandParser.h"
// ======================================================================
/**
* Commands that are related to scripts
*/
class ObjectCommandParserSetAttributes : public CommandParser
{
public:
ObjectCommandParserSetAttributes ();
virtual bool performParsing (NetworkId userId, const StringVector_t & argv, const String_t & originalCommand, String_t & result, const CommandParser * node);
private:
ObjectCommandParserSetAttributes (const ObjectCommandParserSetAttributes & rhs);
ObjectCommandParserSetAttributes & operator= (const ObjectCommandParserSetAttributes & rhs);
};
// ======================================================================
#endif // INCLUDED_ObjectCommandParserSetAttributes_H
@@ -0,0 +1,89 @@
// ======================================================================
//
// ServerCommandPermissionManager.cpp
// copyright (c) 2003 Sony Online Entertainment
//
// =====================================================================
#include "serverGame/FirstServerGame.h"
#include "serverGame/ServerCommandPermissionManager.h"
#include "serverGame/Client.h"
#include "serverGame/PlayerObject.h"
#include "serverGame/ServerObject.h"
#include "serverGame/ServerWorld.h"
#include "sharedCommandParser/CommandParser.h"
#include "sharedLog/Log.h"
#include "sharedUtility/DataTable.h"
#include "sharedUtility/DataTableManager.h"
#include "UnicodeUtils.h"
ServerCommandPermissionManager::ServerCommandPermissionManager() :
CommandPermissionManager(),
m_permissionTable(0)
{
m_permissionTable = DataTableManager::getTable("datatables/admin/command_permissions.iff", true);
DEBUG_FATAL(!m_permissionTable, ("Could not open command permissions table"));
CommandParser::setPermissionManager(this);
}
//------------------------------------------------------------------------------------------
ServerCommandPermissionManager::~ServerCommandPermissionManager()
{
DataTableManager::close("command_permissions.iff");
CommandParser::setPermissionManager(0);
}
//------------------------------------------------------------------------------------------
bool ServerCommandPermissionManager::isCommandAllowed (const NetworkId & userId, const Unicode::String & commandPath) const
{
// commands sent from the ServerConsole program don't have a client associated from them
// although it is possible to resolve to a ServerObject
std::string cmd = Unicode::wideToNarrow(commandPath);
if( cmd == "game" )
{
ServerObject * tmpu = ServerWorld::findObjectByNetworkId(userId);
// a ServerConsole command sometimes won't have a ServerObject (first time a cluster receives a command)
// a ServerConsole command will never have a Client associated with it
if( !tmpu || !tmpu->getClient())
{
LOG("ServerCommandPermissionManager", ("Allowing permission to execute ServerConsole command.") );
return true;
}
else
{
LOG("ServerCommandPermissionManager", ("Disallowing permission to execute ServerConsole command because it has a Client associated with it."));
return false;
}
}
ServerObject * user = ServerWorld::findObjectByNetworkId(userId);
if (!user)
return false;
Client* client = user->getClient();
if (!client)
return false;
int clientLevel = client->getGodLevel();
std::string command = Unicode::wideToNarrow(commandPath);
int row = m_permissionTable->searchColumnString( 0, command);
int commandLevel = 5;
if (row != -1)
commandLevel = m_permissionTable->getIntValue(1, row);
bool retval = (commandLevel <= clientLevel);
if (!retval)
{
LOG("CustomerService",("Avatar:%s denied command %s because the command level is %d and they are %d", PlayerObject::getAccountDescription(userId).c_str(), command.c_str(), commandLevel, clientLevel));
}
return retval;
}
//------------------------------------------------------------------------------------------
@@ -0,0 +1,39 @@
// ======================================================================
//
// ServerCommandPermissionManager.h
// copyright (c) 2003 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ServerCommandPermissionManager_H
#define INCLUDED_ServerCommandPermissionManager_H
#include "sharedCommandParser/CommandPermissionManager.h"
class DataTable;
class ServerCommandPermissionManager : public CommandPermissionManager
{
public:
ServerCommandPermissionManager ();
virtual ~ServerCommandPermissionManager ();
/**
* the commandPath is a period-seperated path down through the command tree
*/
virtual bool isCommandAllowed (const NetworkId & userId, const Unicode::String & commandPath) const;
protected:
ServerCommandPermissionManager (const ServerCommandPermissionManager & rhs);
ServerCommandPermissionManager & operator=(const ServerCommandPermissionManager & rhs);
private:
DataTable* m_permissionTable;
};
#endif