mirror of
https://github.com/UOX3DevTeam/UOX3
synced 2026-08-13 12:27:04 -04:00
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>
411 lines
16 KiB
C++
411 lines
16 KiB
C++
//o-----------------------------------------------------------------------------------------------o
|
|
//| File - Queue.cpp
|
|
//| Date - March 15th, 2000
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Implementation (vector based) of the GM and counselor queue class
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
|
|
#include "uox3.h"
|
|
#include "PageVector.h"
|
|
#include "gump.h"
|
|
|
|
PageVector *GMQueue;
|
|
PageVector *CounselorQueue;
|
|
|
|
inline bool operator==( const HelpRequest& x, const HelpRequest& y )
|
|
{
|
|
return ( x.Priority() == y.Priority() );
|
|
}
|
|
|
|
inline bool operator<( const HelpRequest& x, const HelpRequest& y )
|
|
{
|
|
return ( x.Priority() < y.Priority() );
|
|
}
|
|
|
|
inline bool operator>( const HelpRequest& x, const HelpRequest& y )
|
|
{
|
|
return ( x.Priority() > y.Priority() );
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - bool AtEnd( void ) const
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Checks whether position has reached end of queue
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
bool PageVector::AtEnd( void ) const
|
|
{
|
|
return ( currentPos == Queue.end() );
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - PageVector()
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Constructor for PageVector class - initializes an empty queue
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
PageVector::PageVector() : maxID( 0 )
|
|
{
|
|
title = "";
|
|
Queue.resize( 0 );
|
|
currentPos = Queue.end();
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - ~PageVector()
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Deconstructor for PageVector class - kills entire queue
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
PageVector::~PageVector()
|
|
{
|
|
KillQueue();
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - SERIAL Add( HelpRequest *toAdd )
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Adds help request from player to page queue
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
SERIAL PageVector::Add( HelpRequest *toAdd )
|
|
{
|
|
HelpRequest *adding = new HelpRequest;
|
|
#if defined( UOX_DEBUG_MODE )
|
|
if( adding == NULL )
|
|
return INVALIDSERIAL;
|
|
#endif
|
|
#pragma note( "Bad idea to use memcpy to copy one class object to another (especially if the class contains an std::string)?" )
|
|
memcpy( adding, toAdd, sizeof( HelpRequest ) );
|
|
//*adding = *toAdd; // Maybe we should do this instead?
|
|
Queue.push_back( adding );
|
|
adding->RequestID( ++maxID );
|
|
std::sort( Queue.begin(), Queue.end() );
|
|
return adding->RequestID();
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - bool Remove( void )
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Removes help request from player from queue
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
bool PageVector::Remove( void )
|
|
{
|
|
if( AtEnd() )
|
|
return false;
|
|
delete (*currentPos);
|
|
Queue.erase( currentPos );
|
|
return true;
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - HelpRequest *First( void )
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Gets first help request in queue, if any exists
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
HelpRequest *PageVector::First( void )
|
|
{
|
|
currentPos = Queue.begin();
|
|
if( AtEnd() )
|
|
return NULL; // empty queue!
|
|
return (*currentPos);
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - HelpRequest *Next( void )
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Gets next help request in queue, if any exists
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
HelpRequest *PageVector::Next( void )
|
|
{
|
|
++currentPos;
|
|
if( AtEnd() )
|
|
return NULL; // at end, return NULL!
|
|
return (*currentPos);
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - size_t NumEntries( void ) const
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Gets number of help requests in queue
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
size_t PageVector::NumEntries( void ) const
|
|
{
|
|
return Queue.size();
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - void KillQueue( void )
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Clears all help requests from queue
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
void PageVector::KillQueue( void )
|
|
{
|
|
for( size_t counter = 0; counter < Queue.size(); ++counter )
|
|
{
|
|
delete Queue[counter];
|
|
}
|
|
Queue.clear();
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - void SendAsGump( CSocket *toSendTo )
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Sends a list of help requests in queue to client and displays it in a Gump
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
void PageVector::SendAsGump( CSocket *toSendTo )
|
|
{
|
|
GumpDisplay GQueue( toSendTo, 320, 340 );
|
|
GQueue.SetTitle( title );
|
|
|
|
std::vector< HelpRequest * >::iterator qIter;
|
|
for( qIter = Queue.begin(); qIter != Queue.end(); ++qIter )
|
|
{
|
|
if( (*qIter) == NULL )
|
|
continue;
|
|
if( !(*qIter)->IsHandled() )
|
|
{
|
|
CChar *mChar = calcCharObjFromSer( (*qIter)->WhoPaging() );
|
|
if( ValidateObject( mChar ) )
|
|
GQueue.AddData( mChar->GetName(), (*qIter)->TimeOfPage() );
|
|
}
|
|
}
|
|
GQueue.Send( 4, false, INVALIDSERIAL );
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - void SetTitle( const std::string &newTitle )
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Sets title displayed for help request queue in client
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
void PageVector::SetTitle( const std::string &newTitle )
|
|
{
|
|
title = newTitle;
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - PageVector( const std::string &newTitle )
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Initializer for PageVector class
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
PageVector::PageVector( const std::string &newTitle )
|
|
{
|
|
SetTitle( newTitle );
|
|
Queue.resize( 0 );
|
|
currentPos = Queue.end();
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - bool GotoPos( SI32 pos )
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Sets queue position to specified value
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
bool PageVector::GotoPos( SI32 pos )
|
|
{
|
|
if( pos < 0 || static_cast<UI32>(pos) >= Queue.size() )
|
|
return false;
|
|
currentPos = (Queue.begin() + pos);
|
|
return true;
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - SI32 CurrentPos( void ) const
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Gets current queue position
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
SI32 PageVector::CurrentPos( void ) const
|
|
{
|
|
return (currentPos - Queue.begin());
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - SERIAL GetCallNum( void ) const
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Gets call number/help request ID for current position in queue
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
SERIAL PageVector::GetCallNum( void ) const
|
|
{
|
|
if( AtEnd() )
|
|
return INVALIDSERIAL;
|
|
return (*currentPos)->RequestID();
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - SI32 FindCallNum( SERIAL callNum )
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Gets position of page with specified call number/help request ID
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
SI32 PageVector::FindCallNum( SERIAL callNum )
|
|
{
|
|
for( size_t counter = 0; counter < Queue.size(); ++counter )
|
|
{
|
|
if( Queue[counter]->RequestID() == callNum )
|
|
return counter;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - HelpRequest *Current( void )
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Gets current position in queue
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
HelpRequest *PageVector::Current( void )
|
|
{
|
|
if( !AtEnd() )
|
|
return (*currentPos);
|
|
else
|
|
return NULL;
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - bool AnswerNextCall( CSocket *mSock, CChar *mChar )
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Marks next help request in queue as handled and sends it to GM/Counselor
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
bool PageVector::AnswerNextCall( CSocket *mSock, CChar *mChar )
|
|
{
|
|
bool retVal = false;
|
|
CChar *isPaging = NULL;
|
|
for( HelpRequest *tempPage = First(); !AtEnd(); tempPage = Next() )
|
|
{
|
|
if( !tempPage->IsHandled() )
|
|
{
|
|
isPaging = calcCharObjFromSer( tempPage->WhoPaging() );
|
|
if( ValidateObject( isPaging ) )
|
|
{
|
|
GumpDisplay QNext( mSock, 300, 200 );
|
|
QNext.AddData( "Pager: ", isPaging->GetName() );
|
|
QNext.AddData( "Problem: ", tempPage->Reason() );
|
|
QNext.AddData( "Serial number ", tempPage->WhoPaging(), 3 );
|
|
QNext.AddData( "Paged at: ", tempPage->TimeOfPage() );
|
|
QNext.Send( 4, false, INVALIDSERIAL );
|
|
tempPage->IsHandled( true );
|
|
mChar->SetLocation( isPaging );
|
|
mChar->SetCallNum( static_cast<SI16>(tempPage->RequestID() ));
|
|
retVal = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return retVal;
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - ~HelpRequest()
|
|
//| Date - 10 September 2001
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Deconstructor for HelpRequest class - cleans up anything allocated
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
HelpRequest::~HelpRequest()
|
|
{
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - SERIAL WhoPaging( void ) const
|
|
//| void WhoPaging( SERIAL pPaging )
|
|
//| Date - 10 September 2001
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Gets/Sets the serial of the player who paged
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
SERIAL HelpRequest::WhoPaging( void ) const
|
|
{
|
|
return playerPaging;
|
|
}
|
|
void HelpRequest::WhoPaging( SERIAL pPaging )
|
|
{
|
|
playerPaging = pPaging;
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - SERIAL WhoHandling( void ) const
|
|
//| void WhoHandling( SERIAL pHandling )
|
|
//| Date - 10 September 2001
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Gets/Sets the serial of the player who is handling the request
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
SERIAL HelpRequest::WhoHandling( void ) const
|
|
{
|
|
return playerHandling;
|
|
}
|
|
void HelpRequest::WhoHandling( SERIAL pHandling )
|
|
{
|
|
playerHandling = pHandling;
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - SI08 Priority( void ) const
|
|
//| void Priority( SI08 pPriority )
|
|
//| Date - 10 September 2001
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Gets/Sets the priority of the request
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
SI08 HelpRequest::Priority( void ) const
|
|
{
|
|
return priority;
|
|
}
|
|
void HelpRequest::Priority( SI08 pPriority )
|
|
{
|
|
priority = pPriority;
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - bool IsHandled( void ) const
|
|
//| void IsHandled( bool pHandled )
|
|
//| Date - 10 September 2001
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Gets/Sets true if the request is being handled
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
bool HelpRequest::IsHandled( void ) const
|
|
{
|
|
return handled;
|
|
}
|
|
void HelpRequest::IsHandled( bool pHandled )
|
|
{
|
|
handled = pHandled;
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - time_t TimeOfPage( void ) const
|
|
//| void TimeOfPage( time_t pTime )
|
|
//| Date - 10 September 2001
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Gets/Sets the number of seconds since Jan 1, 1970 that the
|
|
//| page was recorded
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
time_t HelpRequest::TimeOfPage( void ) const
|
|
{
|
|
return timeOfPage;
|
|
}
|
|
void HelpRequest::TimeOfPage( time_t pTime )
|
|
{
|
|
timeOfPage = pTime;
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - std::string Reason( void )
|
|
//| void Reason( const std::string &pReason )
|
|
//| Date - 10 September 2001
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Gets/Sets the reason that the request was made
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
std::string HelpRequest::Reason( void ) const
|
|
{
|
|
return reason;
|
|
}
|
|
void HelpRequest::Reason( const std::string &pReason )
|
|
{
|
|
reason = pReason;
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - SERIAL RequestID( void ) const
|
|
//| void RequestID( SERIAL hrid )
|
|
//| Date - 10 September 2001
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Gets/Sets the ID # of the request
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
SERIAL HelpRequest::RequestID( void ) const
|
|
{
|
|
return helpReqID;
|
|
}
|
|
void HelpRequest::RequestID( SERIAL hrid )
|
|
{
|
|
helpReqID = hrid;
|
|
}
|