uox3/source/cServerDefinitions.cpp

672 lines
21 KiB
C++
Raw Permalink Normal View History

Added: -JS Get/Set "vulnerable" handlers for character properties (Abaddon) -willHunger with Get/Set HungerStatus() wrappers to CChar class (can now selectively stop a character/creature from continuing to hunger) -JS Get/Set "willhunger" handlers for character properties Changed: Linux compile fixes (thanks Malketh) Hash.h warning fixed (thanks Philantrop) Fixes to getRootPack() and getPackOwner() Removed many #includes from the global scope, including them in the specific files that need them This should greatly reduce compile time and filesize, along with the need to recompile after altering most headers Removed the linux ifdefs around typedefd function declarations, this should work with gcc 3.2 Moved global loading functions into a new cFileIO() class to take them out of global scope Fixed an issue causing items to not be sent to the client (thanks Malketh) Moved some global structs into the CWorldMain class Fixed a bug causing a crash on character / item creation Moved all effects stuff into its own class to take it out of global scope Changed the variable CChar::region to CChar::regionNum to avoid conflicts with the cTownRegion region[] indexes Moved getbestskill(), isHuman(), and inDungeon() into the CChar class to remove them from global scope Took npcSimpleAttackTarget() out of global scope Rewrote restock() to make use of restockNPC() Changed the typedef'd iterator in hash.h to HASHITERATOR to kill a Linux warning Renamed cEffects::soundeffect() to PlaySound() and removed unneeded overloads Fixed a bug causing executebatch to be set with locationcount data Rewrote cEffects::bgsound() Documented sounds.cpp Misc minor cleanups / fixes Removed: sendItemsInRange() (CChar::Teleport() does the same thing) Many #includes that were not being used deathMenu() respawnnow() and moved all of its code into command_respawn() one instance of cEffects::scpSoundEffect() and renamed the other to PlaySound() 3/13/2003 Changed Fixed an issue allowing the server to not have a dictionary.ZRO (which would cause a crash when a dictionary entry was called with no language) Fixed an issue causing the server to puke when it attempted a restart Moved SpawnRandomItem() into cItem class Moved SpawnRandomMonster() into cCharHandle class Broke necro.dfn into fishing.dfn and digging.dfn Made better use of SpawnRandomItem() and SpawnRandomMonster() 3/12/2003 Added: CPOpenGump and CPSpeech packet class to remove some global vars (Note these are pretty basic classes and someone with a better understanding of how we handle sending/recieving packets could probably expand these to make better use of them) Changed: Moved many global vars into the CWorldMain() class Cleaned ResetVars() in uox3.cpp as ResetDefaults() in CWorldMain() now handles much of that Added a check to ensure text wasn't sent twice in talking(), should fix double-speech Cleaned up cmdtable.cpp removing a couple duplicate entries, etc Changed target() to only require 4 values (as the first two were always 0 and 1) Removed many unneeded typedefs and globals Went through cServerData() and noted unused server.ini entries Moved title1(), title2(), and title3() to cClick.cpp since that is their only usage, made use of MAX_TITLE to ensure we wouldn't overrun the buffers, and renamed them matching what title they were 3/11/2003 Changed: Fixed a potentially very serious bugs with how containers were being set upon loading the world Fixed possible re-adding of weight to containers and characters at load Fixed a bug causing equipped items that were not weapons to take damage in combat Minor cleanups / warning fixes / Linux compatability issues (punt) 3/7/2003 Overhauls/Additions/Major Changes Changed: Tweaks/Object Conversions/Misc Small Changes Changed: Changed CItem::Get/SetLayer() to a UI08 Fixed a bug in speech causing you to see your own text twice Fixed a nasty crash bug
2003-03-23 10:18:02 +00:00
#include "uox3.h"
2002-04-07 20:53:41 +00:00
#include "cServerDefinitions.h"
#include "ssection.h"
Added: -JS Get/Set "vulnerable" handlers for character properties (Abaddon) -willHunger with Get/Set HungerStatus() wrappers to CChar class (can now selectively stop a character/creature from continuing to hunger) -JS Get/Set "willhunger" handlers for character properties Changed: Linux compile fixes (thanks Malketh) Hash.h warning fixed (thanks Philantrop) Fixes to getRootPack() and getPackOwner() Removed many #includes from the global scope, including them in the specific files that need them This should greatly reduce compile time and filesize, along with the need to recompile after altering most headers Removed the linux ifdefs around typedefd function declarations, this should work with gcc 3.2 Moved global loading functions into a new cFileIO() class to take them out of global scope Fixed an issue causing items to not be sent to the client (thanks Malketh) Moved some global structs into the CWorldMain class Fixed a bug causing a crash on character / item creation Moved all effects stuff into its own class to take it out of global scope Changed the variable CChar::region to CChar::regionNum to avoid conflicts with the cTownRegion region[] indexes Moved getbestskill(), isHuman(), and inDungeon() into the CChar class to remove them from global scope Took npcSimpleAttackTarget() out of global scope Rewrote restock() to make use of restockNPC() Changed the typedef'd iterator in hash.h to HASHITERATOR to kill a Linux warning Renamed cEffects::soundeffect() to PlaySound() and removed unneeded overloads Fixed a bug causing executebatch to be set with locationcount data Rewrote cEffects::bgsound() Documented sounds.cpp Misc minor cleanups / fixes Removed: sendItemsInRange() (CChar::Teleport() does the same thing) Many #includes that were not being used deathMenu() respawnnow() and moved all of its code into command_respawn() one instance of cEffects::scpSoundEffect() and renamed the other to PlaySound() 3/13/2003 Changed Fixed an issue allowing the server to not have a dictionary.ZRO (which would cause a crash when a dictionary entry was called with no language) Fixed an issue causing the server to puke when it attempted a restart Moved SpawnRandomItem() into cItem class Moved SpawnRandomMonster() into cCharHandle class Broke necro.dfn into fishing.dfn and digging.dfn Made better use of SpawnRandomItem() and SpawnRandomMonster() 3/12/2003 Added: CPOpenGump and CPSpeech packet class to remove some global vars (Note these are pretty basic classes and someone with a better understanding of how we handle sending/recieving packets could probably expand these to make better use of them) Changed: Moved many global vars into the CWorldMain() class Cleaned ResetVars() in uox3.cpp as ResetDefaults() in CWorldMain() now handles much of that Added a check to ensure text wasn't sent twice in talking(), should fix double-speech Cleaned up cmdtable.cpp removing a couple duplicate entries, etc Changed target() to only require 4 values (as the first two were always 0 and 1) Removed many unneeded typedefs and globals Went through cServerData() and noted unused server.ini entries Moved title1(), title2(), and title3() to cClick.cpp since that is their only usage, made use of MAX_TITLE to ensure we wouldn't overrun the buffers, and renamed them matching what title they were 3/11/2003 Changed: Fixed a potentially very serious bugs with how containers were being set upon loading the world Fixed possible re-adding of weight to containers and characters at load Fixed a bug causing equipped items that were not weapons to take damage in combat Minor cleanups / warning fixes / Linux compatability issues (punt) 3/7/2003 Overhauls/Additions/Major Changes Changed: Tweaks/Object Conversions/Misc Small Changes Changed: Changed CItem::Get/SetLayer() to a UI08 Fixed a bug in speech causing you to see your own text twice Fixed a nasty crash bug
2003-03-23 10:18:02 +00:00
#include "scriptc.h"
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt) Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri) Updated SpiderMonkey from v1.6.0 to v1.7.0 Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri) Added StringUtility file with general common string manipulation functions (punt) Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt) Overall code cleanup to remove/replace platform-dependent code (punt) Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt) Replaced usage of char in many places with std::string (punt) Started process of replacing UString usage with functions provided through StringUtility instead (punt) Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt) Replaced platform specific time handling by using cross-platform chrono library (punt) Removed UOX namespace to reduce complexity (punt) Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt) Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt) Removed some platform specific files like uoxlinux.h, which is no longer required (punt) Removed legacy crash protection code, and removed support for cluox (punt) Removed legacy "support" for Borland compiler (punt) Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri) Removed legacy BUILD folder with outdated compilation instructions (Xuri) Removed old Changelog file (merged into Changelog.txt) (Xuri) Fixed a pointer bug for items in multis on world load (punt) Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt) Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt) Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt) Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt) Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt) Added some new commands to js/commands/custom/misc-cmd.js (Xuri) cont // Targeted item will be made a container, set to nondecay and movable 2 endfight // Targeted character (and character being fought) will stop fighting getmulti // Get multiObject for targeted item finditem // Find item at layer X movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen) Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri) Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
#include "StringUtility.hpp"
#include <filesystem>
2022-06-09 08:02:49 -04:00
#include <memory>
2022-06-10 10:49:59 -04:00
#include <array>
using namespace std::string_literals;
CServerDefinitions *FileLookup;
//==================================================================================================
auto CurrentWorkingDir() -> std::string
{
return std::filesystem::current_path().string();
2003-03-04 14:55:47 +00:00
}
Instance-support and misc code cleanup Misc code and documentation cleanup: Updated and standardized function comment blocks throughout entire codebase Grouped getters and setters together in pairs and documented them as one Removed empty and/or non-useful information from comment blocks Removed unused function from cItem.cpp/h - IncID() - formerly used to change IDs for doors Added new feature - Instances Objects (characters, items, multis, spawnregions) can now make use of a 5th parameter to determine their location in the game world. In addition to the traditional X, Y, Z and WORLDNUMBER parameters, a new one has been added - INSTANCEID - that allows objects to exist at the same coordinates in the same world, but in different "dimensions". Code has been updated in multiple places to support this, and a default instanceID of 0 is assumed if nothing else is specified. Added support for new DFN tag in town regions, spawn regions and locations - INSTANCEID (defaults to 0 if not present) Added support for another start location parameter after worldNum in UOX.INI representing instanceID (defaults to 0 if not present) Updated TWEAK menu to include WorldNumber and instanceID Fixed BaseWeight option in TWEAK menu Updated CBase_Teleport - now takes an optional 5th parameter instanceID Updated SE_SpawnNPC now takes an optional 5th parameter - instanceID Updated SE_FindMulti now takes an optional 5th parameter - instanceID Updated SE_GetItem now takes an optional 5th parameter - instanceID Updated SE_FindItem now takes an optional 6th parameter - instanceID Added new JS property for Items, Characters, Regions: .instanceID Added JS property for Regions: .members - returns comma-separated list of town member serials Updated JS scripts making use of the above-mentioned JS Methods/Functions Updated dictionaries with new tweak menu entry texts Exposed SpawnRegions to JS engine, and updated JS docs with details: SpawnRegion JS Functions IterateOverSpawnRegions() GetSpawnRegion( spawnRegNum ) GetSpawnRegionCount() SpawnRegion JS Properties name regionNum itemList npcList item npc maxItems maxNpcs itemCount npcCount onlyOutside prefZ x1 y1 x2 y2 world instanceID minTime maxTime call
2020-08-08 13:57:15 +08:00
//==================================================================================================
auto BuildPath( const std::string &extra ) -> std::string
{
auto temp = std::filesystem::current_path();
temp /= std::filesystem::path( extra );
return temp.string();
2003-03-04 14:55:47 +00:00
}
//==================================================================================================
auto ShortDirectory( std::string sPath ) -> std::string
{
return std::filesystem::path( sPath ).filename().string();
2003-03-04 14:55:47 +00:00
}
//==================================================================================================
const std::array<std::string, NUM_DEFS> dirNames
{
2022-06-10 10:49:59 -04:00
"items"s,
"npc"s,
"create"s,
"regions"s,
"misc"s,
"skills"s,
"location"s,
"menus"s,
"spells"s,
"newbie"s,
"titles"s,
"advance"s,
"house"s,
"colors"s,
"spawn"s,
"html"s,
"race"s,
"weather"s,
"harditems"s,
"command"s,
"msgboard"s,
"carve"s,
"creatures"s,
"maps"s
2002-04-07 20:53:41 +00:00
};
std::multimap<UI32, ADDMENUITEM> g_mmapAddMenuMap;
//==================================================================================================
CServerDefinitions::CServerDefinitions() : defaultPriority( 0 )
{
}
//==================================================================================================
auto CServerDefinitions::Startup() -> void
{
2002-04-07 20:53:41 +00:00
Console.PrintSectionBegin();
Console << "Loading server scripts..." << myendl;
Console << " o Clearing AddMenuMap entries(" << static_cast<UI64>( g_mmapAddMenuMap.size() ) << ")" << myendl;
g_mmapAddMenuMap.clear();
2002-04-07 20:53:41 +00:00
ScriptListings.resize( NUM_DEFS );
ReloadScriptObjects();
Console.PrintSectionBegin();
}
//o------------------------------------------------------------------------------------------------o
//| Function - CServerDefinitions::Reload()
Instance-support and misc code cleanup Misc code and documentation cleanup: Updated and standardized function comment blocks throughout entire codebase Grouped getters and setters together in pairs and documented them as one Removed empty and/or non-useful information from comment blocks Removed unused function from cItem.cpp/h - IncID() - formerly used to change IDs for doors Added new feature - Instances Objects (characters, items, multis, spawnregions) can now make use of a 5th parameter to determine their location in the game world. In addition to the traditional X, Y, Z and WORLDNUMBER parameters, a new one has been added - INSTANCEID - that allows objects to exist at the same coordinates in the same world, but in different "dimensions". Code has been updated in multiple places to support this, and a default instanceID of 0 is assumed if nothing else is specified. Added support for new DFN tag in town regions, spawn regions and locations - INSTANCEID (defaults to 0 if not present) Added support for another start location parameter after worldNum in UOX.INI representing instanceID (defaults to 0 if not present) Updated TWEAK menu to include WorldNumber and instanceID Fixed BaseWeight option in TWEAK menu Updated CBase_Teleport - now takes an optional 5th parameter instanceID Updated SE_SpawnNPC now takes an optional 5th parameter - instanceID Updated SE_FindMulti now takes an optional 5th parameter - instanceID Updated SE_GetItem now takes an optional 5th parameter - instanceID Updated SE_FindItem now takes an optional 6th parameter - instanceID Added new JS property for Items, Characters, Regions: .instanceID Added JS property for Regions: .members - returns comma-separated list of town member serials Updated JS scripts making use of the above-mentioned JS Methods/Functions Updated dictionaries with new tweak menu entry texts Exposed SpawnRegions to JS engine, and updated JS docs with details: SpawnRegion JS Functions IterateOverSpawnRegions() GetSpawnRegion( spawnRegNum ) GetSpawnRegionCount() SpawnRegion JS Properties name regionNum itemList npcList item npc maxItems maxNpcs itemCount npcCount onlyOutside prefZ x1 y1 x2 y2 world instanceID minTime maxTime call
2020-08-08 13:57:15 +08:00
//| Date - 04/17/2002
//o------------------------------------------------------------------------------------------------o
Instance-support and misc code cleanup Misc code and documentation cleanup: Updated and standardized function comment blocks throughout entire codebase Grouped getters and setters together in pairs and documented them as one Removed empty and/or non-useful information from comment blocks Removed unused function from cItem.cpp/h - IncID() - formerly used to change IDs for doors Added new feature - Instances Objects (characters, items, multis, spawnregions) can now make use of a 5th parameter to determine their location in the game world. In addition to the traditional X, Y, Z and WORLDNUMBER parameters, a new one has been added - INSTANCEID - that allows objects to exist at the same coordinates in the same world, but in different "dimensions". Code has been updated in multiple places to support this, and a default instanceID of 0 is assumed if nothing else is specified. Added support for new DFN tag in town regions, spawn regions and locations - INSTANCEID (defaults to 0 if not present) Added support for another start location parameter after worldNum in UOX.INI representing instanceID (defaults to 0 if not present) Updated TWEAK menu to include WorldNumber and instanceID Fixed BaseWeight option in TWEAK menu Updated CBase_Teleport - now takes an optional 5th parameter instanceID Updated SE_SpawnNPC now takes an optional 5th parameter - instanceID Updated SE_FindMulti now takes an optional 5th parameter - instanceID Updated SE_GetItem now takes an optional 5th parameter - instanceID Updated SE_FindItem now takes an optional 6th parameter - instanceID Added new JS property for Items, Characters, Regions: .instanceID Added JS property for Regions: .members - returns comma-separated list of town member serials Updated JS scripts making use of the above-mentioned JS Methods/Functions Updated dictionaries with new tweak menu entry texts Exposed SpawnRegions to JS engine, and updated JS docs with details: SpawnRegion JS Functions IterateOverSpawnRegions() GetSpawnRegion( spawnRegNum ) GetSpawnRegionCount() SpawnRegion JS Properties name regionNum itemList npcList item npc maxItems maxNpcs itemCount npcCount onlyOutside prefZ x1 y1 x2 y2 world instanceID minTime maxTime call
2020-08-08 13:57:15 +08:00
//| Purpose - Reload the dfn files.
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt) Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri) Updated SpiderMonkey from v1.6.0 to v1.7.0 Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri) Added StringUtility file with general common string manipulation functions (punt) Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt) Overall code cleanup to remove/replace platform-dependent code (punt) Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt) Replaced usage of char in many places with std::string (punt) Started process of replacing UString usage with functions provided through StringUtility instead (punt) Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt) Replaced platform specific time handling by using cross-platform chrono library (punt) Removed UOX namespace to reduce complexity (punt) Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt) Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt) Removed some platform specific files like uoxlinux.h, which is no longer required (punt) Removed legacy crash protection code, and removed support for cluox (punt) Removed legacy "support" for Borland compiler (punt) Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri) Removed legacy BUILD folder with outdated compilation instructions (Xuri) Removed old Changelog file (merged into Changelog.txt) (Xuri) Fixed a pointer bug for items in multis on world load (punt) Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt) Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt) Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt) Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt) Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt) Added some new commands to js/commands/custom/misc-cmd.js (Xuri) cont // Targeted item will be made a container, set to nondecay and movable 2 endfight // Targeted character (and character being fought) will stop fighting getmulti // Get multiObject for targeted item finditem // Find item at layer X movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen) Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri) Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
//| Changes - 04042004 - Added the code to clear out the
//| Auto-AddMenu items so there isn't any duplication in the
//| multimap
//o------------------------------------------------------------------------------------------------o
auto CServerDefinitions::Reload() -> bool
{
// We need to clear out the AddMenuItem Map
g_mmapAddMenuMap.clear();
//
Cleanup();
ScriptListings.clear();
ScriptListings.resize( NUM_DEFS );
ReloadScriptObjects();
return true;
}
//o------------------------------------------------------------------------------------------------o
//| Function - CServerDefinitions::Reload( DEFINITIONCATEGORIES toReload )
//o------------------------------------------------------------------------------------------------o
//| Purpose - Reload a specific set of dfn files.
//o------------------------------------------------------------------------------------------------o
auto CServerDefinitions::Reload( DEFINITIONCATEGORIES toReload ) -> bool
{
Dispose( toReload );
LoadDFNCategory( toReload );
return true;
}
//==================================================================================================
auto CServerDefinitions::Cleanup() -> void
{
std::vector<VECSCRIPTLIST>::iterator slIter;
for( slIter = ScriptListings.begin(); slIter != ScriptListings.end(); ++slIter )
{
VECSCRIPTLIST& toDel = ( *slIter );
for( size_t j = 0; j < toDel.size(); ++j )
{
if( toDel[j] )
{
delete toDel[j];
toDel[j] = nullptr;
}
2002-04-07 20:53:41 +00:00
}
}
}
//==================================================================================================
CServerDefinitions::~CServerDefinitions()
{
Cleanup();
}
//==================================================================================================
auto CServerDefinitions::Dispose( DEFINITIONCATEGORIES toDispose ) -> bool
{
bool retVal = false;
if( toDispose != NUM_DEFS )
{
VECSCRIPTLIST& toDel = ScriptListings[toDispose];
for( VECSCRIPTLIST_CITERATOR dIter = toDel.begin(); dIter != toDel.end(); ++dIter )
{
Script *toDelete = ( *dIter );
if( toDelete )
{
retVal = true;
delete toDelete;
}
2002-04-07 20:53:41 +00:00
}
toDel.clear();
2002-04-07 20:53:41 +00:00
}
return retVal;
2002-04-07 20:53:41 +00:00
}
//o------------------------------------------------------------------------------------------------o
//| Function - CServerDefinitions::FindEntry
//o------------------------------------------------------------------------------------------------o
//| Purpose - Find a specific CScriptSection from the DFNs in memory
//o------------------------------------------------------------------------------------------------o
auto CServerDefinitions::FindEntry( const std::string &toFind, DEFINITIONCATEGORIES typeToFind ) ->CScriptSection *
{
CScriptSection *rValue = nullptr;
if( !toFind.empty() && typeToFind != NUM_DEFS )
{
auto tUFind = oldstrutil::upper( toFind );
VECSCRIPTLIST& toDel = ScriptListings[typeToFind];
for( VECSCRIPTLIST_CITERATOR dIter = toDel.begin(); dIter != toDel.end(); ++dIter )
{
Script *toCheck = ( *dIter );
if( toCheck )
{
rValue = toCheck->FindEntry( tUFind );
if( rValue )
{
break;
}
}
2002-04-07 20:53:41 +00:00
}
}
return rValue;
}
//==================================================================================================
auto CServerDefinitions::FindEntrySubStr( const std::string &toFind, DEFINITIONCATEGORIES typeToFind ) ->CScriptSection *
{
CScriptSection *rValue = nullptr;
if( !toFind.empty() && typeToFind != NUM_DEFS )
{
VECSCRIPTLIST& toDel = ScriptListings[typeToFind];
for( VECSCRIPTLIST_CITERATOR dIter = toDel.begin(); dIter != toDel.end(); ++dIter )
{
Script *toCheck = ( *dIter );
if( toCheck )
{
rValue = toCheck->FindEntrySubStr( toFind );
if( rValue )
{
break;
}
}
}
}
return rValue;
2002-04-07 20:53:41 +00:00
}
const std::string defExt = ".dfn";
2002-04-07 20:53:41 +00:00
//==================================================================================================
struct PrioScan_st
{
std::string filename;
2002-04-07 20:53:41 +00:00
SI16 priority;
PrioScan_st() : filename( "" ), priority( 0 )
{
}
PrioScan_st( const char *toUse, SI16 mPrio ) : filename( toUse ), priority( mPrio )
{
}
2002-04-07 20:53:41 +00:00
};
//==================================================================================================
inline auto operator == ( const PrioScan_st& x, const PrioScan_st& y ) -> bool
{
return ( x.priority == y.priority );
2002-04-07 20:53:41 +00:00
}
//==================================================================================================
inline auto operator < ( const PrioScan_st& x, const PrioScan_st& y ) -> bool
{
return ( x.priority < y.priority );
}
//==================================================================================================
inline auto operator > ( const PrioScan_st& x, const PrioScan_st& y ) -> bool
{
return ( x.priority > y.priority );
}
//o------------------------------------------------------------------------------------------------o
//| Function - CServerDefinitions::LoadDFNCategory
//o------------------------------------------------------------------------------------------------o
//| Purpose - Load the files found for each DFN category
//o------------------------------------------------------------------------------------------------o
auto CServerDefinitions::LoadDFNCategory( DEFINITIONCATEGORIES toLoad) -> void
{
CleanPriorityMap();
defaultPriority = 0;
UI08 wasPriod = 2;
BuildPriorityMap( toLoad, wasPriod );
2002-04-07 20:53:41 +00:00
CDirectoryListing fileList( toLoad, defExt );
fileList.Flatten( true );
std::vector<std::string> *shortListing = fileList.FlattenedShortList();
std::vector<std::string> *longListing = fileList.FlattenedList();
std::vector<PrioScan_st> mSort;
for( size_t i = 0; i < shortListing->size(); ++i )
{
mSort.push_back( PrioScan_st(( *longListing )[i].c_str(), GetPriority(( *shortListing )[i].c_str() )));
}
if( !mSort.empty() )
{
std::sort( mSort.begin(), mSort.end() );
Console.Print( oldstrutil::format( "Section %20s : %6i", dirNames[toLoad].c_str(), 0 ));
size_t iTotal = 0;
Console.TurnYellow();
std::vector<PrioScan_st>::const_iterator mIter;
for( mIter = mSort.begin(); mIter != mSort.end(); ++mIter )
{
Console.Print( "\b\b\b\b\b\b" );
ScriptListings[toLoad].push_back( new Script(( *mIter ).filename, toLoad, false ));
iTotal += ScriptListings[toLoad].back()->NumEntries();
Console.Print( oldstrutil::format( "%6i", iTotal ));
2002-04-07 20:53:41 +00:00
}
Console.Print( oldstrutil::format( "\b\b\b\b\b\b%6i", CountOfEntries( toLoad )));
Console.TurnNormal();
Console.Print( " entries" );
switch( wasPriod )
{
case 0:
Console.PrintSpecial( CGREEN, "prioritized" );
break; // prioritized
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt) Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri) Updated SpiderMonkey from v1.6.0 to v1.7.0 Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri) Added StringUtility file with general common string manipulation functions (punt) Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt) Overall code cleanup to remove/replace platform-dependent code (punt) Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt) Replaced usage of char in many places with std::string (punt) Started process of replacing UString usage with functions provided through StringUtility instead (punt) Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt) Replaced platform specific time handling by using cross-platform chrono library (punt) Removed UOX namespace to reduce complexity (punt) Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt) Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt) Removed some platform specific files like uoxlinux.h, which is no longer required (punt) Removed legacy crash protection code, and removed support for cluox (punt) Removed legacy "support" for Borland compiler (punt) Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri) Removed legacy BUILD folder with outdated compilation instructions (Xuri) Removed old Changelog file (merged into Changelog.txt) (Xuri) Fixed a pointer bug for items in multis on world load (punt) Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt) Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt) Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt) Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt) Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt) Added some new commands to js/commands/custom/misc-cmd.js (Xuri) cont // Targeted item will be made a container, set to nondecay and movable 2 endfight // Targeted character (and character being fought) will stop fighting getmulti // Get multiObject for targeted item finditem // Find item at layer X movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen) Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri) Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
case 1:
Console.PrintSpecial( CGREEN, "done" );
break; // file exist, no section
2002-04-07 20:53:41 +00:00
default:
Numerous changes with focus on feature and stability parity across Windows, Linux and MacOS platforms Added new Makefile that handles compiling UOX3 and Spidermonkey on both Linux and MacOS (punt) Added VS solution (SpiderMonkey.sln) and VC++ project files for compiling SpiderMonkey on Windows (Xuri) Updated SpiderMonkey from v1.6.0 to v1.7.0 Added optimization flag -O2 for release build in CMakeLists.txt in project root (Xuri) Added StringUtility file with general common string manipulation functions (punt) Updated RandomNum function to use a "seedless" random number generator from C++11 instead of the old C rand() function. (punt) Overall code cleanup to remove/replace platform-dependent code (punt) Replaced potentially unsafe usage of C string stuff like sprintf, vsprintf, vsnprintf, strncat, strcpy and strlen throughout the code with calls to a format() function containing only a single, safe use of vsnprintf, ensuring there's a single place of failure if there's anything to fix and and making it easy to potentially replace this with std::format from C++20 when the time comes. (punt) Replaced usage of char in many places with std::string (punt) Started process of replacing UString usage with functions provided through StringUtility instead (punt) Replaced platform specific fileIO handling in Windows/Linux with cross-platform C++17 standard std::filesystem (punt) Replaced platform specific time handling by using cross-platform chrono library (punt) Removed UOX namespace to reduce complexity (punt) Elimitated template code approach to singletons for more modern c++ constructs, removing dependices in the process (punt) Removed ODBC support; it hasn't been touched since the initial implementation in 2008, and there is a lack of someone to maintain the code. (punt) Removed some platform specific files like uoxlinux.h, which is no longer required (punt) Removed legacy crash protection code, and removed support for cluox (punt) Removed legacy "support" for Borland compiler (punt) Removed legacy VC++ 6 Workspace/Project files, VS2005 Solution/Project files, as these are no longer supported (Xuri) Removed legacy BUILD folder with outdated compilation instructions (Xuri) Removed old Changelog file (merged into Changelog.txt) (Xuri) Fixed a pointer bug for items in multis on world load (punt) Fixed a dictionary related issue that caused segmentation faults on Linux/MacOS (punt) Fixed an issue with callbacks to JS scripts that caused segmentation faults on Linux/MacOS (punt) Paths in uox.ini should now load properly on all platforms regardless of whether those paths use slashes or backslashes, and whether or not they end in a slash/backslash. (punt) Moved to c++17 style of threading, and got rid of threadsafeobject.cpp/h (punt) Replaced parsing of UOX.INI tags with a system that's more easily maintainable (punt) Added some new commands to js/commands/custom/misc-cmd.js (Xuri) cont // Targeted item will be made a container, set to nondecay and movable 2 endfight // Targeted character (and character being fought) will stop fighting getmulti // Get multiObject for targeted item finditem // Find item at layer X movespeed // Set movement speed of target player (0x0 Normal, 0x1 Mounted, 0x2 Slow (walk only), 0x3 Hybrid ("jog"?), 0x4 Frozen) Added new HTML based documentation in docs folder, and removed many old legacy docs that are either incorporated into this document already or no longer relevant for the current UOX3 version (Xuri) Co-Authored-By: Charles Kerr <punt1959@users.noreply.github.com>
2020-09-07 18:09:55 +08:00
case 2:
Console.PrintSpecial( CBLUE, "done" );
break; // no file
};
}
}
//o------------------------------------------------------------------------------------------------o
//| Function - CServerDefinitions::ReloadScriptObjects()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Reload all the various categories of DFN scripts
//o------------------------------------------------------------------------------------------------o
auto CServerDefinitions::ReloadScriptObjects() -> void
{
Console << myendl;
for( SI32 sCtr = 0; sCtr < NUM_DEFS; ++sCtr )
{
LoadDFNCategory( static_cast<DEFINITIONCATEGORIES>( sCtr ));
2002-04-07 20:53:41 +00:00
}
CleanPriorityMap();
}
//==================================================================================================
auto CServerDefinitions::CountOfEntries( DEFINITIONCATEGORIES typeToFind ) -> size_t
{
size_t sumEntries = 0;
VECSCRIPTLIST *toScan = &( ScriptListings[typeToFind] );
if( toScan )
{
for( auto cIter = toScan->begin(); cIter != toScan->end(); ++cIter )
{
sumEntries += (*cIter)->NumEntries();
}
}
2002-04-07 20:53:41 +00:00
return sumEntries;
}
//==================================================================================================
auto CServerDefinitions::CountOfFiles( DEFINITIONCATEGORIES typeToFind ) -> size_t
{
2002-04-07 20:53:41 +00:00
return ScriptListings[typeToFind].size();
}
//==================================================================================================
auto CServerDefinitions::FirstScript( DEFINITIONCATEGORIES typeToFind ) -> Script *
{
2021-06-12 07:30:23 -04:00
Script *retScript = nullptr;
slIter = ScriptListings[typeToFind].begin();
if( !FinishedScripts( typeToFind ))
{
retScript = ( *slIter );
}
return retScript;
}
//==================================================================================================
auto CServerDefinitions::NextScript( DEFINITIONCATEGORIES typeToFind ) ->Script *
{
2021-06-12 07:30:23 -04:00
Script *retScript = nullptr;
if( !FinishedScripts( typeToFind ))
{
++slIter;
if( !FinishedScripts( typeToFind ))
{
retScript = ( *slIter );
}
}
return retScript;
}
//==================================================================================================
auto CServerDefinitions::FinishedScripts( DEFINITIONCATEGORIES typeToFind ) -> bool
{
return ( slIter == ScriptListings[typeToFind].end() );
2002-04-07 20:53:41 +00:00
}
//==================================================================================================
auto CServerDefinitions::CleanPriorityMap() -> void
{
priorityMap.clear();
2002-04-07 20:53:41 +00:00
}
//o------------------------------------------------------------------------------------------------o
//| Function - CServerDefinitions::BuildPriorityMap()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Build DFN priority map based on entires from priority.nfo
//o------------------------------------------------------------------------------------------------o
auto CServerDefinitions::BuildPriorityMap( DEFINITIONCATEGORIES category, UI08& wasPrioritized ) -> void
{
CDirectoryListing priorityFile( category, "priority.nfo", false );
std::vector<std::string> *longList = priorityFile.List();
if( !longList->empty() )
{
std::string filename = ( *longList )[0];
2003-03-04 14:55:47 +00:00
// Do we have any priority informat?
if( FileExists( filename )) // the file exists, so perhaps we do
{
2022-06-09 08:02:49 -04:00
auto prio = std::make_unique<Script>( filename, category, false ); // generate a script for it
if( prio ) // successfully made a script
{
2022-06-09 08:02:49 -04:00
auto prioInfo = prio->FindEntry( "PRIORITY" ); // find the priority entry
if( prioInfo )
{
for( const auto &sec : prioInfo->collection() )
{
auto tag = sec->tag;
auto data = sec->data;
if( oldstrutil::upper( tag ) == "DEFAULTPRIORITY" )
{
defaultPriority = static_cast<UI16>( std::stoul( data, nullptr, 0 ));
}
else
{
std::string filenametemp = oldstrutil::lower( tag );
priorityMap[filenametemp] =static_cast<SI16>( std::stoi( data, nullptr, 0 ));
2003-03-04 14:55:47 +00:00
}
2002-04-07 20:53:41 +00:00
}
2003-03-04 14:55:47 +00:00
wasPrioritized = 0;
2002-04-07 20:53:41 +00:00
}
else
{
2003-03-04 14:55:47 +00:00
wasPrioritized = 1;
2022-06-09 08:02:49 -04:00
}
2021-06-12 07:30:23 -04:00
prio = nullptr;
2002-04-07 20:53:41 +00:00
}
else
{
2003-03-04 14:55:47 +00:00
wasPrioritized = 2;
2022-06-09 08:02:49 -04:00
}
2003-03-04 14:55:47 +00:00
return;
2002-04-07 20:53:41 +00:00
}
}
#if defined( UOX_DEBUG_MODE )
// Console.Warning( oldstrutil::format( "Failed to open priority.nfo for reading in %s DFN", dirNames[category].c_str() ));
2002-04-07 20:53:41 +00:00
#endif
2003-03-04 14:55:47 +00:00
wasPrioritized = 2;
2002-04-07 20:53:41 +00:00
}
//o------------------------------------------------------------------------------------------------o
//| Function - CServerDefinitions::DisplayPriorityMap()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Dump DFN priority map to console
//o------------------------------------------------------------------------------------------------o
void CServerDefinitions::DisplayPriorityMap()
{
2002-04-07 20:53:41 +00:00
Console << "Dumping map... " << myendl;
for( auto &[name, priority] : priorityMap )
{
Console << name << " : " << priority << myendl;
2002-04-07 20:53:41 +00:00
}
Console << "Dumped" << myendl;
}
//==================================================================================================
2022-10-24 23:42:16 +08:00
auto CServerDefinitions::GetPriority( const char *file ) -> SI16
{
auto retVal = defaultPriority;
auto lowername = oldstrutil::lower( file );
auto p = priorityMap.find( lowername );
if( p != priorityMap.end() )
{
retVal = p->second;
}
return retVal;
2002-04-07 20:53:41 +00:00
}
//==================================================================================================
auto CDirectoryListing::PushDir( DEFINITIONCATEGORIES toMove ) -> bool
{
auto filePath = cwmWorldState->ServerData()->Directory( CSDDP_DEFS );
filePath += dirNames[toMove];
return PushDir( filePath );
2003-03-04 14:55:47 +00:00
}
//==================================================================================================
auto CDirectoryListing::PushDir( std::string toMove ) -> bool
{
2003-03-04 14:55:47 +00:00
std::string cwd = CurrentWorkingDir();
dirs.push( cwd );
auto path = std::filesystem::path( toMove );
auto rValue = true;
if( !std::filesystem::exists( path ))
{
Console.Error( oldstrutil::format( "DFN directory %s does not exist", toMove.c_str() ));
2003-03-04 14:55:47 +00:00
Shutdown( FATAL_UOX3_DIR_NOT_FOUND );
}
std::filesystem::current_path( path );
currentDir = toMove;
toMove = oldstrutil::replaceSlash( toMove );
shortCurrentDir = ShortDirectory( toMove );
return rValue;
}
//==================================================================================================
auto CDirectoryListing::PopDir() -> void
{
if( dirs.empty() )
{
Console.Error( "cServerDefinition::PopDir called, but dirs is empty" );
2003-03-04 14:55:47 +00:00
Shutdown( FATAL_UOX3_DIR_NOT_FOUND );
}
else
{
auto path = std::filesystem::path( dirs.top() );
if( std::filesystem::exists( path ))
{
std::filesystem::current_path( path );
}
2003-03-04 14:55:47 +00:00
dirs.pop();
}
}
//==================================================================================================
CDirectoryListing::CDirectoryListing( bool recurse ) : extension( ".dfn" ), doRecursion( recurse )
{
2003-03-04 14:55:47 +00:00
}
//==================================================================================================
CDirectoryListing::CDirectoryListing( const std::string &dir, const std::string &extent, bool recurse ) : doRecursion( recurse )
{
2003-03-04 14:55:47 +00:00
Extension( extent );
Retrieve( dir );
}
//==================================================================================================
CDirectoryListing::CDirectoryListing( DEFINITIONCATEGORIES dir, const std::string &extent, bool recurse ) : doRecursion( recurse )
{
Extension( extent );
Retrieve( dir );
2003-03-04 14:55:47 +00:00
}
//==================================================================================================
CDirectoryListing::~CDirectoryListing()
{
while( !dirs.empty() )
{
auto path = std::filesystem::path( dirs.top() );
if( std::filesystem::exists( path ))
{
std::filesystem::current_path( path );
}
2003-03-04 14:55:47 +00:00
dirs.pop();
}
}
//==================================================================================================
auto CDirectoryListing::Retrieve( const std::string &dir ) -> void
{
2003-03-04 14:55:47 +00:00
bool dirSet = PushDir( dir );
InternalRetrieve();
if( dirSet )
{
2003-03-04 14:55:47 +00:00
PopDir();
}
2003-03-04 14:55:47 +00:00
}
//==================================================================================================
auto CDirectoryListing::Retrieve( DEFINITIONCATEGORIES dir ) -> void
{
bool dirSet = PushDir( dir );
2003-03-04 14:55:47 +00:00
InternalRetrieve();
if( dirSet )
{
2003-03-04 14:55:47 +00:00
PopDir();
}
2003-03-04 14:55:47 +00:00
}
//==================================================================================================
auto CDirectoryListing::List() -> std::vector<std::string>*
{
2003-03-04 14:55:47 +00:00
return &filenameList;
}
//==================================================================================================
auto CDirectoryListing::ShortList() -> std::vector<std::string>*
{
2003-03-04 14:55:47 +00:00
return &shortList;
}
//==================================================================================================
auto CDirectoryListing::FlattenedList() -> std::vector<std::string>*
{
2003-03-04 14:55:47 +00:00
return &flattenedFull;
}
//==================================================================================================
auto CDirectoryListing::FlattenedShortList() -> std::vector<std::string>*
{
2003-03-04 14:55:47 +00:00
return &flattenedShort;
}
//o------------------------------------------------------------------------------------------------o
//| Function - CDirectoryListing::InternalRetrieve()
//o------------------------------------------------------------------------------------------------o
//| Purpose - ???
//o------------------------------------------------------------------------------------------------o
auto CDirectoryListing::InternalRetrieve() -> void
{
std::string filePath;
auto path = std::filesystem::current_path();
for( const auto& entry : std::filesystem::directory_iterator( path ))
{
auto name = entry.path().filename().string();
filePath = entry.path().string();
auto ext = entry.path().extension();
if( std::filesystem::is_regular_file( entry ))
{
if( !extension.empty() )
{
if( entry.path().extension().string() != extension )
{
name = "";
}
}
if( !name.empty() )
{
shortList.push_back( name );
filenameList.push_back( filePath );
2003-03-04 14:55:47 +00:00
}
}
else if( std::filesystem::is_directory( entry ) && doRecursion )
{
subdirectories.push_back( CDirectoryListing( name, extension, doRecursion ));
2003-03-04 14:55:47 +00:00
}
}
}
//==================================================================================================
auto CDirectoryListing::Extension( const std::string &extent ) -> void
{
2003-03-04 14:55:47 +00:00
extension = extent;
}
//o------------------------------------------------------------------------------------------------o
//| Function - CDirectoryListing::Flatten()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Flatten list of filenames
//o------------------------------------------------------------------------------------------------o
auto CDirectoryListing::Flatten( bool isParent ) -> void
{
2003-03-04 14:55:47 +00:00
ClearFlatten();
std::for_each( filenameList.begin(), filenameList.end(), [isParent, this]( const std::string & entry )
{
flattenedFull.push_back( entry );
auto temp = std::string();
if( !isParent )
{
temp = shortCurrentDir + "/"s;
2003-03-04 14:55:47 +00:00
}
temp += entry;
flattenedShort.push_back( temp );
});
std::string temp;
DIRLIST_ITERATOR dIter;
for( dIter = subdirectories.begin(); dIter != subdirectories.end(); ++dIter )
2003-03-04 14:55:47 +00:00
{
( *dIter ).Flatten( false );
auto shortFlat = ( *dIter ).FlattenedShortList();
auto longFlat = ( *dIter ).FlattenedList();
for( size_t k = 0; k < longFlat->size(); ++k )
2003-03-04 14:55:47 +00:00
{
flattenedFull.push_back(( *longFlat )[k] );
2003-03-04 14:55:47 +00:00
if( isParent )
{
2003-03-04 14:55:47 +00:00
temp = "";
}
2003-03-04 14:55:47 +00:00
else
{
temp = shortCurrentDir;
temp += "/";
}
temp += ( *shortFlat )[k];
2003-03-04 14:55:47 +00:00
flattenedShort.push_back( temp );
}
( *dIter ).ClearFlatten();
2003-03-04 14:55:47 +00:00
}
}
//==================================================================================================
auto CDirectoryListing::ClearFlatten() -> void
{
2003-03-04 14:55:47 +00:00
flattenedFull.clear();
flattenedShort.clear();
2002-04-07 20:53:41 +00:00
}