*/
/** Static members **/
-RegEx* PAccount::mUsernameRegexFilter = NULL;
-RegEx* PAccount::mPasswordRegexFilter = NULL;
+RegEx* PAccount::mUsernameRegexFilter = nullptr;
+RegEx* PAccount::mPasswordRegexFilter = nullptr;
bool PAccount::SetUsernameRegexFilter(const char* RegexStr)
{
if(mUsernameRegexFilter)
{
delete mUsernameRegexFilter;
- mUsernameRegexFilter = NULL;
+ mUsernameRegexFilter = nullptr;
}
if(RegexStr)
if(mPasswordRegexFilter)
{
delete mPasswordRegexFilter;
- mPasswordRegexFilter = NULL;
+ mPasswordRegexFilter = nullptr;
}
if(RegexStr)
bool FinalResult = false;
result = MySQL->InfoResQuery(query);
- if(result == NULL)
+ if(result == nullptr)
{
Console->Print(RED, BLACK, "Failed to load AccountData from SQL");
MySQL->ShowInfoSQLError();
mPassword = row[a_password];
mBannedUntil = atoi(row[a_bandate]);
- if(mBannedUntil > time(NULL))
+ if(mBannedUntil > Time::nowTimeT())
{
mStatus = PAS_BANNED;
mLevel = PAL_BANNED;
return true;
}
-bool PAccount::SetBannedUntilTime(std::time_t BannedUntil)
+bool PAccount::SetBannedUntilTime(time_t BannedUntil)
{
- if ((BannedUntil == 0) || (BannedUntil > std::time(NULL)))
+ if ((BannedUntil == 0) || (BannedUntil > Time::nowTimeT()))
{
mBannedUntil = BannedUntil;
return true;
}
}
+bool PAccount::IsBanned() const
+{
+ return (mBannedUntil > Time::nowTimeT());
+}
+
bool PAccount::DecodePassword(const uint8_t* PasswordData, int PassLen, const uint8_t *Key, char* ClearPassword)
{
ClearPassword[0] = 0;
snprintf(query, 256, "SELECT c_id FROM characters WHERE a_id = %d AND c_slot = %d LIMIT 1;", mID, SlotId);
result = MySQL->GameResQuery(query);
- if(result == NULL)
+ if (result == nullptr)
{
Console->Print(RED, BLACK, "Failed to load CharacterData from SQL");
MySQL->ShowGameSQLError();
snprintf(query, 256, "SELECT c_id FROM characters WHERE a_id = %d ORDER BY c_slot ASC, c_id ASC LIMIT %d, 1;", mID, SlotId);
result = MySQL->GameResQuery(query);
- if(result == NULL)
+ if (result == nullptr)
{
Console->Print(RED, BLACK, "Failed to load CharacterData from SQL");
MySQL->ShowGameSQLError();
{
const char* unit[5] = {"seconds", "minutes", "hours", "days", "weeks"};
- std::time_t timediff = mBannedUntil - std::time(NULL);
+ time_t timediff = mBannedUntil - Time::nowTimeT();
if(timediff <=0)
{
return "0 more seconds. Please relog";
bool SetStatus(PAccountStatus Status);
inline PAccountStatus GetStatus() const { return mStatus; }
bool SetBannedUntilTime(time_t BannedUntil);
- inline bool IsBanned() const { return (mBannedUntil > std::time(NULL)); }
+ bool IsBanned() const;
std::string GetBannedTime() const;
bool Authenticate(const uint8_t* PasswordData, int PassLen, const uint8_t *Key);
{
mOwnerCharID = nOwnerCharID;
mListMaxSize = mListSize = 0;
- mCharIDList = NULL;
+ mCharIDList = nullptr;
}
PBuddyList::~PBuddyList()
snprintf(query, 256, "SELECT * FROM buddy_list WHERE (bud_charid='%u')", mOwnerCharID);
result = MySQL->GameResQuery(query);
- if(result == NULL)
+ if (result == nullptr)
{
Console->Print(RED, BLACK, "PBuddyList::SQLLoad could not load buddylist entry from the database");
Console->Print("Query was:");
ADD_EXECUTABLE (GameServer
Accounts.cxx Appartements.cxx BuddyList.cxx Chars.cxx Chat.cxx Client.cxx ClientManager.cxx
- Commands.cxx Container.cxx DoorTemplate.cxx FurnitureTemplate.cxx GameScript.cxx
+ Commands.cxx Container.cxx DoorTemplate.cxx FurnitureTemplate.cxx
GameServer.cxx GenrepList.cxx Includes.cxx Isc.cxx Inventory.cxx Item.cxx LuaEngine.cxx
Main.cxx MessageBuilder.cxx MultiPart.cxx Npc.cxx NpcAi.cxx NpcConversation.cxx NpcTemplate.cxx
Outpost.cxx RemoteConsole.cxx Server.cxx Skill.cxx Sql.cxx Subway.cxx Terminal.cxx
c_soullight
};
-RegEx* PChar::mCharnameRegexFilter = NULL;
+RegEx* PChar::mCharnameRegexFilter = nullptr;
PChar::PChar()
{
mSeatInUseType = seat_none;
mSeatInUseObjectId = 0;
mSeatInUseSeatId = 0;
- mVhcAccessRequestList = NULL;
+ mVhcAccessRequestList = nullptr;
- mContainerInExclusiveUse = NULL;
+ mContainerInExclusiveUse = nullptr;
mIsOnline = false;
mDirtyFlag = false;
mCurrentDialogNode = 0;
Skill = new PSkillHandler();
- mBuddyList = NULL;
- mGenrepList = NULL;
+ mBuddyList = nullptr;
+ mGenrepList = nullptr;
// Required for initial OOC Broadcast welcome message.
//Gets overwritten as soon as the first PingPacket arrives
if ( mCharnameRegexFilter )
{
delete mCharnameRegexFilter;
- mCharnameRegexFilter = NULL;
+ mCharnameRegexFilter = nullptr;
}
if ( RegexStr )
void PChar::SetProfession( uint32_t Profession )
{
const PDefCharKind *def = GameDefs->CharKinds()->GetDef( Profession );
- if ( def == NULL )
+ if (def == nullptr)
{
Console->Print( RED, BLACK, "Char %d: Invalid profession %d", mID, Profession );
mProfession = 10;
{
const PDefCharKind *def = GameDefs->CharKinds()->GetDef( mProfession );
//Console->Print(YELLOW, BLACK, "PChar::SetBaseSkills() Profession: %d",def->GetIndex());
- if ( def == NULL )
+ if (def == nullptr)
{
Console->Print( RED, BLACK, "PChar::SetBaseSkills: GetCharKindDef=NULL" );
return;
snprintf(query, 200, "SELECT cll_level FROM clanlevels WHERE cll_charid = %d AND cll_clanid = %d", mID, mClanID);
result = MySQL->GameResQuery( query );
- if ( result == NULL )
+ if (result == nullptr)
{
mClanID = 0;
Console->Print( RED, BLACK, "PChar::GetClanLevel could not load ClanLevel from the database" );
snprintf( query, 1024, "SELECT * FROM characters WHERE c_id = %d LIMIT 1", CharID );
result = MySQL->GameResQuery( query );
- if ( result == NULL )
+ if (result == nullptr)
{
Console->Print( RED, BLACK, "PChar::SQLLoad could not load Chardata from the database" );
Console->Print( "Query was:" );
void PChar::SetLookingAt( uint16_t nLocalCharID )
{
mLookingAt = nLocalCharID;
- mLookAtTimestamp = std::time( NULL );
+ mLookAtTimestamp = Time::nowTimeT();
}
uint16_t PChar::GetLookingAt( uint16_t nMaxDelaySec )
{
- return ((( mLookAtTimestamp + nMaxDelaySec ) >= std::time( NULL ) ) ? mLookingAt : 0 );
+ return ((( mLookAtTimestamp + nMaxDelaySec ) >= Time::nowTimeT() ) ? mLookingAt : 0 );
}
// ===================================
PChars::PChars()
{
mLastID = 0;
- mLastSave = std::time( NULL );
+ mLastSave = Time::nowTimeT();
mAutoSavePeriod = Config->GetOptionInt( "auto_save_period" );
if ( mAutoSavePeriod < 0 )
PChar* PChars::RemoveChar( uint32_t CharID )
{
- PChar* Result = NULL;
+ PChar* Result = nullptr;
CharMap::iterator i = mChars.find( CharID );
if ( i != mChars.end() )
snprintf( query, 256, "SELECT 1 FROM characters WHERE c_name = '%s' LIMIT 1;", escUsername );
result = MySQL->GameResQuery( query );
- if ( result == NULL )
+ if (result == nullptr)
{
Console->Print( RED, BLACK, "[ERROR] Failed to get CharacterData from SQL" );
MySQL->ShowGameSQLError();
void PChars::Update()
{
- std::time_t t = std::time( NULL ); // changed to time() to have real time instead of cpu used time
+ time_t t = Time::nowTimeT(); // changed to time() to have real time instead of cpu used time
if ( mAutoSavePeriod && (( t - mLastSave ) >= mAutoSavePeriod ) )
{
snprintf( query, 256, "SELECT * FROM characters WHERE a_id = %d ORDER BY c_slot ASC", AccountID );
result = MySQL->GameResQuery( query );
- if ( result == NULL )
+ if (result == nullptr)
{
Console->Print( RED, BLACK, "[ERROR] Failed to load CharacterData from SQL" );
MySQL->ShowGameSQLError();
uint8_t mQuickBeltActiveSlot; // QB SlotID of item "in hand", or INV_WORN_QB_HAND or INV_WORN_QB_NONE
uint16_t mLookingAt; // Zone charID of currently targeted player
- std::time_t mLookAtTimestamp; // Lifetimer of lookat var
+ time_t mLookAtTimestamp; // Lifetimer of lookat var
uint32_t mLastUsedWorldObjectId; // Last world object clicked on
uint8_t mClanLevel; // 1-15
inline void SetLocationLeased( bool nState = true ) { mLocationLeased = nState; }
inline bool GetLocationLeased() { return mLocationLeased; }
- PSeatType GetSeatInUse( uint32_t* nObjectId = NULL, uint8_t* nSeatId = NULL );
- void SetSeatInUse( PSeatType nSeatType, uint32_t nObjectId = 0, uint8_t nSeatId = 0 );
+ PSeatType GetSeatInUse(uint32_t* nObjectId = nullptr, uint8_t* nSeatId = nullptr);
+ void SetSeatInUse(PSeatType nSeatType, uint32_t nObjectId = 0, uint8_t nSeatId = 0);
PVhcAccessRequestList* GetVhcAccessRequestList();
CharMap mChars;
uint32_t mLastID;
- std::time_t mAutoSavePeriod;
- std::time_t mLastSave;
+ time_t mAutoSavePeriod;
+ time_t mLastSave;
public :
PChars();
mCharID = 0;
mConnection = PCC_NONE;
mRemotePort = 0;
- m_TCPConnection = NULL;
- m_UDPConnection = NULL;
+ m_TCPConnection = nullptr;
+ m_UDPConnection = nullptr;
for ( int i = 0; i < DEBUG_MODES ; i++ )
mDebugMode[i] = false;
if ( m_TCPConnection )
{
delete m_TCPConnection;
- m_TCPConnection = NULL;
+ m_TCPConnection = nullptr;
}
if ( m_UDPConnection )
{
delete m_UDPConnection;
- m_UDPConnection = NULL;
+ m_UDPConnection = nullptr;
}
}
/// ******************************************************
for ( uint16_t ChunkID = 0; ChunkID < ChunksNum; ChunkID++ )
{
ChunkBuffer = nMessage->GetChunk( IncludedHeaderSize, ChunkSize, ChunkID );
- if ( ChunkBuffer == NULL )
+ if (ChunkBuffer == nullptr)
{
Console->Print( RED, BLACK, "[Error] PClient::FragmentAndSendUDPMessage: Bad chunk number: %d for size %d", ChunksNum, nMessage->GetSize() );
break;
if ( m_TCPConnection )
{
delete m_TCPConnection;
- m_TCPConnection = NULL;
+ m_TCPConnection = nullptr;
}
if ( m_UDPConnection )
{
delete m_UDPConnection;
- m_UDPConnection = NULL;
+ m_UDPConnection = nullptr;
}
/**** Will be better to put that char-saving-at-disconnect in Char destructor, when only used Chars will be loaded ****/
{
//if(gDevDebug)
Console->Print( "%s Trying to get leaving char out of her seat", Console->ColorText( CYAN, BLACK, "[DEBUG]" ) );
- PUdpCharExitChair::DoLeaveChair( tChar, this, NULL, true );
+ PUdpCharExitChair::DoLeaveChair(tChar, this, nullptr, true);
}
/* // replaced by the lines above
PSeatType cSeatType;
{
//Console->Print(YELLOW, BLACK, "GameDisconnect: Client %i had no char online.", mIndex);
}
- /**********************************/
- //mConnection &= ~PCC_GAME;
mConnection = PCC_NONE;
}
}
else
{
- return NULL;
+ return nullptr;
}
}
*PosZ = mTargetZ;
return mAwaitingWarpto;
- /*
- if(mAwaitingWarpto == true)
- {
-
- // Position update doesnt work. Uncomment&Change function if ever required again
- mAwaitingWarpto = false;
- (GetChar()->Coords).mX = mTargetX;
- (GetChar()->Coords).mY = mTargetY;
- (GetChar()->Coords).mZ = mTargetZ;
- return true;
- // PMessage* tmpMsg_posupdate;
- //
- // tmpMsg_posupdate = MsgBuilder->BuildCharPosMoveMsg(this, mTargetX, mTargetY, mTargetZ);
- // ClientManager->UDPBroadcast(tmpMsg_posupdate, this);
- // tmpMsg_posupdate = NULL;
- }
- return false;
- */
}
void PClient::InitWarpCircle()
//inline int* getIP() const { return (int*) m_IP; }
void SetAwaitingWarpto(bool yesno, uint16_t NewX, uint16_t NewY, uint16_t NewZ);
- bool GetCharAwaitingWarpto(uint16_t* PosX = NULL, uint16_t* PosY = NULL, uint16_t* PosZ = NULL);
+ bool GetCharAwaitingWarpto(uint16_t* PosX = nullptr, uint16_t* PosY = nullptr, uint16_t* PosZ = nullptr);
// Char broadcasted effects
void InitWarpCircle();
}
}
-/* bool PClientManager::deleteClientFromList(PClient* delClient)
-{
- for(PClientMap::iterator it=mClientList.begin(); it!=mClientList.end(); it++)
- {
- if(delClient == it->second)
- {
- // if(it->second)
- // {
- // delete delClient;
- mClientList.erase( it );
- return true;
- // }
- }
- }
- return false;
-} */
-
PClient* PClientManager::getClientByID( uint32_t id ) const
{
PClientMap::const_iterator it = mClientList.find( id );
- return (( it != mClientList.end() ) ? ( PClient* )( it->second ) : NULL );
+ return (( it != mClientList.end() ) ? ( PClient* )( it->second ) : nullptr);
}
PClient* PClientManager::getClientByChar( uint32_t CharID ) const
return it->second;
}
}
- return NULL;
+ return nullptr;
}
PClient* PClientManager::getClientByChar( const std::string &Name ) const
return it->second;
}
}
- return NULL;
+ return nullptr;
}
-/* uint32_t PClientManager::getClientID(PClient* _client)
-{
- for(PClientMap::iterator it=mClientList.begin(); it!=mClientList<p align="center"></p>.end(); it++)
- {
- if(_client == it->second)
- {
- return it->first;
- }
- }
-
- return -1;
-} */
-
// Distance checking doesn't care for Z axis ATM
int PClientManager::UDPBroadcast( PMessage* nMessage, uint32_t nZoneID, uint16_t nX, uint16_t nY, uint16_t nZ, uint16_t nMaxDist, uint32_t nSkipCharId, bool nNPCPing )
{
{
doCmdrawf();
}
- /* Not required anymore, TinNS gets is worlditemdata from .dat files now
- else if(strcmp(Command, "delworlditem") == 0)
- {
- doCmddelworlditem();
- }
- else if(strcmp(Command, "addworlditem") == 0)
- {
- doCmdaddworlditem();
- }
- else if(strcmp(Command, "adddoor") == 0)
- {
- doCmdadddor();
- }
- */
else if ( (strcmp(Command, "online") == 0) || (strcmp(Command, "who") == 0) ) // Was: connectedList
{
doCmdconlist();
target = GetClientByNick(tmp);
}
- if (target == NULL)
+ if (target == nullptr)
return false;
else
return true;
ArgC = 0;
DumbMade = false;
- source = NULL;
- target = NULL;
+ source = nullptr;
+ target = nullptr;
}
{
return ClientManager->getClientByChar( charid );
}
-/*
-PClient* PCommands::GetClientByID(int charid)
-{
- for(PClientMap::iterator it=ClientManager->getClientListBegin(); it!=ClientManager->getClientListEnd(); it++)
- {
- if(it->second)
- {
- PClient* target = it->second;
- if((int)target->GetCharID() == charid)
- return it->second;
- }
- }
- return NULL;
-}
-*/
PClient* PCommands::GetClientByNick(const char *nick)
{
return ClientManager->getClientByChar( (std::string) nick );
}
-/*
-PClient* PCommands::GetClientByNick(const char *nick)
-{
- for(PClientMap::iterator it=ClientManager->getClientListBegin(); it!=ClientManager->getClientListEnd(); it++)
- {
- if(it->second)
- {
- PClient* target = it->second;
- if(!strcasecmp(Chars->GetChar(target->GetCharID())->GetName().c_str(), nick))
- return it->second;
- }
- }
- return NULL;
-}
-*/
bool PCommands::RequirePacketDumb()
{
PContainerEntry::PContainerEntry( MYSQL_ROW row )
{
- mItem = NULL;
+ mItem = nullptr;
mInvID = atoi( row[i_invid] );
mPosX = atoi( row[i_x] );
mPosY = atoi( row[i_y] );
Console->Print( GREEN, BLACK, "Item %d deleted from container DB", mInvID );
mInvID = 0;
delete mItem;
- mItem = NULL;
+ mItem = nullptr;
mDirtyFlag = false;
return true;
{
mMaxSlots = ( nMaxSlots > CONTAINER_MAX_SIZE ? CONTAINER_MAX_SIZE : nMaxSlots ) ;
if ( mMaxSlots )
- mContContent = new std::vector< PContainerEntry* >( mMaxSlots, NULL );
+ mContContent = new std::vector<PContainerEntry *>(mMaxSlots, nullptr);
else
- mContContent = new std::vector< PContainerEntry* >;
+ mContContent = new std::vector<PContainerEntry *>;
mCharID = 0;
mInvLoc = 0;
mExclusiveUseCharID = 0;
if ( IsSlotAllowed( nSlotId ) )
{
for ( uint8_t i = mContContent->size(); i <= nSlotId; ++i ) // Extend as needed
- mContContent->push_back( static_cast<PContainerEntry*>(NULL) );
+ mContContent->push_back( static_cast<PContainerEntry *>(nullptr));
if ( mContContent->at( nSlotId ) )
{
Console->Print( RED, BLACK, "[Warning] PContainer::AddEntry: Target entry already %d in use !!!", nSlotId );
PContainerEntry* PContainer::RemoveEntry( uint8_t nSlotId )
{
- PContainerEntry* tEntry = NULL;
+ PContainerEntry *tEntry = nullptr;
if ( nSlotId < mContContent->size() )
{
tEntry = mContContent->at( nSlotId );
- mContContent->at( nSlotId ) = NULL;
+ mContContent->at(nSlotId) = nullptr;
}
return tEntry;
}
{
mContContent->at( j ) = tEntry = mContContent->at( i );
this->SetEntryPosXY( tEntry, j, tEntry->mPosX, tEntry->mPosX );
- mContContent->at( i ) = NULL;
+ mContContent->at(i) = nullptr;
mDirtyFlag = true;
}
++j;
snprintf( query, 1024, "SELECT * FROM inventory WHERE inv_charid='%d' AND inv_loc='%d' ORDER BY inv_x ASC", mCharID, mInvLoc );
result = MySQL->GameResQuery( query );
- if ( result == NULL )
+ if (result == nullptr)
{
Console->Print( RED, BLACK, "[Warning] PContainer::SQLLoad could not load inventory from the database" );
Console->Print( "Query was:" );
tEntry->mPosX = dstSlotId;
tEntry->mPosY = 0;
tEntry->mDirtyFlag = true;
- mContContent->at( srcSlotId ) = NULL;
+ mContContent->at(srcSlotId) = nullptr;
mDirtyFlag = true;
return true;
}
PContainerEntry* PContainer::GetEntry( uint8_t nSlotId )
{
if ( nSlotId >= mContContent->size() )
- return NULL;
+ return nullptr;
return mContContent->at( nSlotId );
}
PItem* PContainer::GetItem( uint8_t nSlotId )
{
PContainerEntry* tEntry = this->GetEntry( nSlotId );
- return ( tEntry ? tEntry->mItem : NULL );
+ return (tEntry ? tEntry->mItem : nullptr);
}
uint8_t PContainer::RandomFill( uint8_t nItemCount, int nItemContainerDefIndex )
{
- PItem* nItem = NULL;
+ PItem* nItem = nullptr;
const PDefItems* nItemDef;
uint32_t nItemSeqId;
uint8_t CreatedCount = 0;
/* --- PContainerAutoCompact --- */
PContainerEntry* PContainerAutoCompact::RemoveEntry( uint8_t nSlotId )
{
- PContainerEntry* tEntry = NULL;
+ PContainerEntry* tEntry = nullptr;
if ( nSlotId < mContContent->size() )
{
tEntry = mContContent->at( nSlotId );
- mContContent->at( nSlotId ) = NULL;
+ mContContent->at( nSlotId ) = nullptr;
if ( nSlotId == ( mContContent->size() - 1 ) )
mContContent->pop_back();
else
if ( FindValid2DPos( tEntry ) )
{
for ( uint8_t i = mContContent->size(); i <= nSlotId; ++i ) // Extend as needed
- mContContent->push_back( static_cast<PContainerEntry *>(NULL) );
+ mContContent->push_back( static_cast<PContainerEntry *>(nullptr));
if ( mContContent->at( nSlotId ) )
{
Console->Print( RED, BLACK, "[Warning] PContainer2DWorkaround::AddEntry: Target entry already %d in use !!!", nSlotId );
PContainerEntry* PContainer2DWorkaround::RemoveEntry( uint8_t nSlotId )
{
- PContainerEntry* tEntry = NULL;
+ PContainerEntry* tEntry = nullptr;
if ( nSlotId < mContContent->size() )
{
tEntry = mContContent->at( nSlotId );
- mContContent->at( nSlotId ) = NULL;
+ mContContent->at( nSlotId ) = nullptr;
//Console->Print(YELLOW, BLACK, "Cleaning (%d,%d) (%d x %d)", tEntry->mPosX, tEntry->mPosY, tEntry->mItem->GetSizeX(), tEntry->mItem->GetSizeY());
SetUsed( tEntry, false );
}
PUdpMsgAnalyser* PUdp0x13::Analyse()
{
PMessage* TmpMsg = mDecodeData->mMessage;
- PUdpMsgAnalyser* nextAnalyser = NULL;
+ PUdpMsgAnalyser* nextAnalyser = nullptr;
if ( ! mDecodeData->mHandling0x13Sub ) // First decoding pass
{
PUdpMsgAnalyser* PUdp0x1f::Analyse()
{
- PUdpMsgAnalyser* nextAnalyser = NULL;
+ PUdpMsgAnalyser* nextAnalyser = nullptr;
mDecodeData->mState = DECODE_MORE;
uint8_t MsgType = mDecodeData->mMessage->U8Data( mDecodeData->Sub0x13Start + 7 );
uint8_t MsgSubType = mDecodeData->mMessage->U8Data( mDecodeData->Sub0x13Start + 8 );
PUdpMsgAnalyser* PUdp0x22::Analyse()
{
- PUdpMsgAnalyser* nextAnalyser = NULL;
+ PUdpMsgAnalyser* nextAnalyser = nullptr;
mDecodeData->mState = DECODE_MORE;
uint8_t MsgType = mDecodeData->mMessage->U8Data(mDecodeData->Sub0x13Start + 5);
switch(MsgType) // MsgType is probably uint16_t rather than uint8_t
PClient* nClient = mDecodeData->mClient;
PChar* tChar = nClient->GetChar();
PWorld* CurrentWorld = Worlds->GetWorld(tChar->GetLocation());
- const PFurnitureItemTemplate* tFurnitureTemplate = NULL;
- const PDefWorldModel* tFurnitureModel = NULL;
+ const PFurnitureItemTemplate* tFurnitureTemplate = nullptr;
+ const PDefWorldModel* tFurnitureModel = nullptr;
uint32_t mRawItemID = mDecodeData->mMessage->U32Data(mDecodeData->Sub0x13Start+8);
if(gDevDebug) Console->Print("DEBUG: Client %d successfully hacked object %d", mDecodeData->mClient->GetID(), mRawItemID);
}
- if(tHandleDynamicActor == false && tFurnitureTemplate != NULL)
+ if(tHandleDynamicActor == false && tFurnitureTemplate != nullptr)
{
if (tFurnitureTemplate->GetLinkedObjectID())
{
PClient* nClient = mDecodeData->mClient;
PChar* tChar = nClient->GetChar();
PWorld* CurrentWorld = Worlds->GetWorld( tChar->GetLocation() );
- const PFurnitureItemTemplate* tFurnitureTemplate = NULL;
- const PDefWorldModel* tFurnitureModel = NULL;
+ const PFurnitureItemTemplate* tFurnitureTemplate = nullptr;
+ const PDefWorldModel* tFurnitureModel = nullptr;
uint32_t mRawItemID = mDecodeData->mMessage->U32Data( mDecodeData->Sub0x13Start + 24 );
//if(gDevDebug) Console->Print("Client %d wants to hack itemID %d ***not managed yet***", mDecodeData->mClient->GetID(), mRawItemID);
PMessage* tmpMsg = MsgBuilder->BuildStartHackGameMsg( nClient, mRawItemID, tHackDifficult );
nClient->SendUDPMessage( tmpMsg );
- tmpMsg = NULL;
+ tmpMsg = nullptr;
}
}
uint8_t origDstY = mDstY;
PContainerEntry* tEntry;
- PItem* tItem = NULL;
+ PItem* tItem = nullptr;
PContainer* SrcContainer = GetContainerByLoc( tChar, mSrcLoc );
if ( SrcContainer )
PContainer* PUdpItemMove::GetContainerByLoc( PChar* nChar, uint8_t nLoc )
{
- PContainer* tContainer = NULL;
+ PContainer* tContainer = nullptr;
switch ( nLoc )
{
//SrcContainer->Dump();
// No answer to confirm ?
-//tmpMsg = NULL;
+//tmpMsg = nullptr;
mDecodeData->mState = DECODE_ACTION_DONE | DECODE_FINISHED;
return true;
PUdpMsgAnalyser* PUdpPopupResponse::Analyse()
{
- PUdpMsgAnalyser* nextAnalyser = NULL;
+ PUdpMsgAnalyser* nextAnalyser = nullptr;
mDecodeData->mState = DECODE_MORE;
uint8_t MsgType = mDecodeData->mMessage->U8Data( mDecodeData->Sub0x13Start + 12 ); //uint32_t but only uint8_t used
uint32_t vehicleId = 0;
nAccessRequests->GetInfo( mVhcAccessRequestId, &requesterCharId, &vehicleId );
PClient* requesterClient = ClientManager->getClientByChar( requesterCharId );
- PChar* requesterChar = ( requesterClient ? requesterClient->GetChar() : NULL );
+ PChar* requesterChar = (requesterClient ? requesterClient->GetChar() : nullptr);
if ( requesterChar && nAccessRequests->Check( mVhcAccessRequestId ) )
{
{
PClient* nClient = mDecodeData->mClient;
PChar* tChar = nClient->GetChar();
- PItem* targetItem = NULL;
+ PItem* targetItem = nullptr;
bool tUsable = false;
bool tUsableInHand = false;
uint16_t nWeaponId = 0;
bool PUdpReqInfo::DoAction()
{
- MYSQL_RES* result = NULL;
+ MYSQL_RES* result = nullptr;
MYSQL_ROW row;
char query[255];
char txtmsg[32];
- void* Answer = NULL;
+ void* Answer = nullptr;
int len;
query[0]='\0';
if(mRequestType == 3)
{
uint32_t tFileLen = 0;
- PFile* fLua = NULL;
+ PFile* fLua = nullptr;
fLua = Filesystem->Open( "", (char*)Answer, Config->GetOption( "nc_data_path" ) );
std::string tLUAScript = "";
if(fLua)
memset(t_content, '\0', tFileLen+1);
fLua->Read( t_content, tFileLen );
- fLua = NULL;
+ fLua = nullptr;
Filesystem->Close( fLua );
tLUAScript = t_content; // APPEND the script to our existing lua headerfile
{
if (( tChar = Chars->GetChar( tCharId ) ) )
{
- PUdpCharExitChair::DoLeaveChair( tChar, NULL, tVhc );
+ PUdpCharExitChair::DoLeaveChair(tChar, nullptr, tVhc);
}
}
}
}
else // furniture objects
{
- const PFurnitureItemTemplate* tFurnitureTemplate = NULL;
- const PDefWorldModel* tFurnitureModel = NULL;
+ const PFurnitureItemTemplate* tFurnitureTemplate = nullptr;
+ const PDefWorldModel* tFurnitureModel = nullptr;
if ( tHandleDynamicActor == false )
{
// We have an STATIC ACTOR, which means we DONT KNOW the FUNCTION VALUE from pak_worldmodel.def yet
CurrentWorld->CharLeaveChair( nClient->GetLocalID(), cSeatObjectId );
}
nChar->SetSeatInUse( seat_chair, ItemID );
- if ( tHandleDynamicActor == false && tFurnitureTemplate != NULL )
+ if (tHandleDynamicActor == false && tFurnitureTemplate != nullptr)
{
tFurnitureTemplate->GetFrontPos( &( nChar->Coords.mX ), &( nChar->Coords.mY ), &( nChar->Coords.mZ ) );
//(nChar->Coords).mLR = tFurnitureTemplate->GetFrontLR();
//nEntity = MySQL->GetWorldItemOption(mRawItemID/256, nLocation, 1);
// This is a kind of nearly-not-hardcoded-hack ...
int nEntityInt = 0;
- if ( tHandleDynamicActor == false && tFurnitureTemplate != NULL )
+ if (tHandleDynamicActor == false && tFurnitureTemplate != nullptr)
{
nEntityInt = GameDefs->Respawns()->GetRespawnEntity( nChar->GetLocation(), tFurnitureTemplate->GetLinkedObjectID() );
}
{
if ( Appartements->CanFreelyEnter( nChar, nChar->GetLocation() ) )
{
- if ( tHandleDynamicActor == false && tFurnitureTemplate != NULL )
+ if (tHandleDynamicActor == false && tFurnitureTemplate != nullptr)
{
if ( tFurnitureTemplate->GetLinkedObjectID() )
{
case 12: //Standard Button
{
- if ( tHandleDynamicActor == false && tFurnitureTemplate != NULL )
+ if (tHandleDynamicActor == false && tFurnitureTemplate != nullptr)
{
if ( tFurnitureTemplate->GetLinkedObjectID() )
{
}
case 13: //Hack Button
{
- if ( tHandleDynamicActor == false && tFurnitureTemplate != NULL )
+ if (tHandleDynamicActor == false && tFurnitureTemplate != nullptr)
{
if ( tFurnitureTemplate->GetLinkedObjectID() )
{
case 23: //EINTRITTSGELD BUTTON
{
- if ( tHandleDynamicActor == false && tFurnitureTemplate != NULL )
+ if (tHandleDynamicActor == false && tFurnitureTemplate != nullptr)
{
if ( tFurnitureTemplate->GetLinkedObjectID() )
{
uint32_t NewCash = nChar->SetCash( OldCash - DoorFee );
PMessage* tmpMsg_cash = MsgBuilder->BuildCharMoneyUpdateMsg( nClient, NewCash );
nClient->SendUDPMessage( tmpMsg_cash );
- tmpMsg_cash = NULL;
+ tmpMsg_cash = nullptr;
tmpMsg = MsgBuilder->BuildDoorOpenMsg( 0x80 + tFurnitureTemplate->GetLinkedObjectID(), CurrentWorld->GetDoor( tFurnitureTemplate->GetLinkedObjectID() )->IsDoubleDoor() );
ClientManager->UDPBroadcast( tmpMsg, nClient );
}
uint32_t NewCash = nChar->SetCash( OldCash - DoorFee );
PMessage* tmpMsg_cash = MsgBuilder->BuildCharMoneyUpdateMsg( nClient, NewCash );
nClient->SendUDPMessage( tmpMsg_cash );
- tmpMsg_cash = NULL;
+ tmpMsg_cash = nullptr;
tmpMsg = MsgBuilder->BuildDoorOpenMsg( 0x80 + linkobjID, CurrentWorld->GetDoor( linkobjID )->IsDoubleDoor() );
ClientManager->UDPBroadcast( tmpMsg, nClient );
}
PContainer* tContainer = nChar->GetContainerInExclusiveUse();
if ( tContainer )
{
- nChar->SetContainerInExclusiveUse( NULL );
+ nChar->SetContainerInExclusiveUse(nullptr);
tContainer->EndUse( nChar->GetID() );
if ( ! tContainer->GetOwnerId() )
{
bool PWorldIDInfoReq::DoAction()
{
- PNPC* targetNPC = NULL;
+ PNPC* targetNPC = nullptr;
PNPCWorld* currentNPCWorld = NPCManager->GetWorld( mDecodeData->mClient->GetChar()->GetLocation() );
if ( currentNPCWorld )
tmpMsg = MsgBuilder->BuildAptLiftFailedMsg( nClient );
}
else
- tmpMsg = NULL;
+ tmpMsg = nullptr;
mDecodeData->mTraceDump = true;
}
PDefItemsMap::PDefItemsMap()
{
- mMapItCache = NULL;
+ mMapItCache = nullptr;
mMapItCacheCount = 0;
mMaxItemGroupId = -1;
}
mMaxItemGroupId = i->first;
//Console->Print("Item group %d : %d items", i->first, i->second);
}
-
+
// Effective groups building
for ( std::map<int, PDefItems*>::const_iterator i = mDefs.begin(); i != mDefs.end(); i++ )
mItemGroups[ i->second->GetItemGroupID() ].push_back(i->first); // i->first is ItemIndex
{
int CacheEntryIdx = nSeqIndex / GAMEDEFS_DEFITEMSMAXSEQ;
if ( CacheEntryIdx >= mMapItCacheCount )
- return NULL;
+ return nullptr;
std::map<int, PDefItems*>::const_iterator It = mMapItCache[CacheEntryIdx];
int EntrySeqIdx = CacheEntryIdx * GAMEDEFS_DEFITEMSMAXSEQ;
return It->second;
}
else
- return NULL;
+ return nullptr;
}
int PDefItemsMap::GetRandomItemIdFromGroup( int nGroupId ) const
PWorldDatParser::PWorldDatParser()
{
- f = NULL;
+ f = nullptr;
}
PWorldDatParser::~PWorldDatParser()
else
{
nName = "PASSIVE";
- nWorldModel = NULL;
+ nWorldModel = nullptr;
}
/* if (gDevDebug) {
else
{
nName = "PASSIVE";
- nWorldModel = NULL;
+ nWorldModel = nullptr;
}
StringData[Data.mActorStringSize - 1] = 0;
{
mDoorID = 0;
mWorldmodelID = 0;
- mDefWorldModel = NULL;
+ mDefWorldModel = nullptr;
mIsDoubleDoor = false;
mIsTriggeredDoor = false;
}
mObjectID = 0;
mModelID = 0;
mWorldmodelID = 0;
- mDefWorldModel = NULL;
+ mDefWorldModel = nullptr;
mLinkedObjectID = 0;
}
GetArgText(2, tmp_destNick, 50);
target = GetClientByNick(tmp_destNick);
}
- if(target == NULL)
+ if (target == nullptr)
{
Chat->send(source, CHAT_DIRECT, "System", "No such player");
return;
PMessage* tmpMsg_cash = MsgBuilder->BuildCharMoneyUpdateMsg(target, newcashvalue);
target->SendUDPMessage(tmpMsg_cash);
- tmpMsg_cash = NULL;
+ tmpMsg_cash = nullptr;
char tmpMsg_success[200];
snprintf(tmpMsg_success, 199, "Added %d NC to %s's wallet (Has now %d NC)", diffcash, target->GetChar()->GetName().c_str(), newcashvalue);
PMessage* tmpMsg_cash = MsgBuilder->BuildCharMoneyUpdateMsg(source, newcashvalue);
source->SendUDPMessage(tmpMsg_cash);
- tmpMsg_cash = NULL;
+ tmpMsg_cash = nullptr;
//Console->Print("oldcashval: %d newcashvalue: %d", oldcashval, newcashvalue);
}
}
target = GetClientByNick(tmp_destNick);
}
- if(target == NULL) // If victim isnt found, return error
+ if (target == nullptr) // If victim isnt found, return error
{
Chat->send(source, CHAT_DIRECT, "System", "No such player");
return;
target = GetClientByNick( tmp_destNick );
}
- if ( target == NULL ) // If victim isnt found, return error
+ if (target == nullptr) // If victim isnt found, return error
{
Chat->send( source, CHAT_DIRECT, "System", "No such player" );
return;
{
PMessage* tmpMsg_zone = MsgBuilder->BuildAptLiftUseMsg( target, destZone, 0 );
target->SendUDPMessage( tmpMsg_zone );
- tmpMsg_zone = NULL;
+ tmpMsg_zone = nullptr;
char tmpMsg_success[81];
snprintf( tmpMsg_success, 80, "Successfully jailed %s", target->GetChar()->GetName().c_str() );
target = GetClientByNick(tmp_destNick);
}
- if(target == NULL) // If victim isnt found, return error
+ if (target == nullptr) // If victim isnt found, return error
{
Chat->send(source, CHAT_DIRECT, "System", "No such player");
return;
}
// *************** Checks done, proceed with command
- int final_bantime = std::time(NULL) + 60; // Ban 60 seconds (Anti-Rejoin)
+ int final_bantime = Time::nowTimeT() + 60; // Ban 60 seconds (Anti-Rejoin)
PAccount Acc(target->GetAccountID());
Acc.SetBannedUntilTime(final_bantime);
Acc.Save();
GetArgText(1, tmp_npccommand, 50);
// Dont search for NPC ID when commands HELP and SPAWN are used
- PNPC* targetNPC = NULL;
- PNPCWorld* currentNPCWorld = NULL;
+ PNPC* targetNPC = nullptr;
+ PNPCWorld* currentNPCWorld = nullptr;
if(strncmp(tmp_npccommand, "spawn", 5) != 0 && strncmp(tmp_npccommand, "help", 4) != 0)
{
currentNPCWorld = NPCManager->GetWorld( source->GetChar()->GetLocation() );
/*-------------------------------------------------------*/
// Get the highest NPC Id for current zone
/*-------------------------------------------------------*/
- MYSQL_RES *result = NULL;
+ MYSQL_RES *result = nullptr;
char tSql[100];
snprintf(tSql, 100, "SELECT IFNULL(MAX(npc_worldid)+1,0) FROM npc_spawns WHERE npc_location = %d", tLocation);
result = MySQL->GameResQuery(tSql);
return;
}
- PNPC* targetNPC = NULL;
+ PNPC* targetNPC = nullptr;
PNPCWorld* currentNPCWorld = NPCManager->GetWorld( source->GetChar()->GetLocation() );
if ( currentNPCWorld )
{
target = GetClientByNick( tmp_destNick );
}
- if ( target == NULL ) // If victim isnt found, return error
+ if (target == nullptr) // If victim isnt found, return error
{
Chat->send( source, CHAT_DIRECT, "System", "No such player" );
return;
{
PMessage* tmpMsg_zone = MsgBuilder->BuildAptLiftUseMsg( target, destZone, 0 );
target->SendUDPMessage( tmpMsg_zone );
- tmpMsg_zone = NULL;
+ tmpMsg_zone = nullptr;
uint16_t nNewX, nNewY, nNewZ;
nNewX = source->GetChar()->Coords.mX;
target = GetClientByNick(tmp_destNick);
}
- if (target == NULL) // If victim isnt found, return error
+ if (target == nullptr) // If victim isnt found, return error
{
Chat->send(source, CHAT_DIRECT, "System", "No such player");
return;
return;
}
- PClient *temp_target = NULL;
+ PClient *temp_target = nullptr;
if ( ArgC == 3 )
{
if (IsArgNumeric(3) == true)
GetArgText(3, tmp_destNick, 50);
temp_target = GetClientByNick(tmp_destNick);
}
- if (temp_target == NULL)
+ if (temp_target == nullptr)
{
Chat->send(source, CHAT_DIRECT, "System", "No such player");
return;
//PMessage* PMsgBuilder::BuildLevelUpMessage( PClient* nClient, uint8_t nMainSkill, uint8_t nNewLevel, uint16_t nFreeSkillPoints)
PMessage* tmpMsg_setLv = MsgBuilder->BuildLevelUpMessage(temp_target, tMainSkill, tNewLevel, tNewSkillPoints);
temp_target->SendUDPMessage(tmpMsg_setLv);
- tmpMsg_setLv = NULL;
- temp_target = NULL;
+ tmpMsg_setLv = nullptr;
+ temp_target = nullptr;
}
return;
}
- PClient *temp_target = NULL;
+ PClient *temp_target = nullptr;
if ( ArgC == 3 )
{
if (IsArgNumeric(3) == true)
GetArgText(3, tmp_destNick, 50);
temp_target = GetClientByNick(tmp_destNick);
}
- if (temp_target == NULL)
+ if (temp_target == nullptr)
{
Chat->send(source, CHAT_DIRECT, "System", "No such player");
return;
MAIN_SKILLS tMainSkill = temp_target->GetChar()->Skill->GetMSfromSS(tSubSkill);
PMessage* tmpMsg_setSLv = MsgBuilder->BuildSubskillIncMsg(temp_target, tSubSkill, temp_target->GetChar()->Skill->GetSP(tMainSkill));
temp_target->SendUDPMessage(tmpMsg_setSLv);
- tmpMsg_setSLv = NULL;
- temp_target = NULL;
+ tmpMsg_setSLv = nullptr;
+ temp_target = nullptr;
}
target = GetClientByNick(tmp_destNick);
}
- if(target == NULL) // If victim isnt found, return error
+ if (target == nullptr) // If victim isnt found, return error
{
Chat->send(source, CHAT_DIRECT, "System", "No such player");
return;
}
//PMessage* tmpMsg = MsgBuilder->BuiltSpawnObjectMsg(source, tmpActorID, tmpFunctionID, mWOID++);
//ClientManager->UDPBroadcast(tmpMsg, source);
- //tmpMsg = NULL;
+ //tmpMsg = nullptr;
}
const char* usage = "Usage: @t r <rawid> (to remove object) | @t d <rawid> [<v1=74> [<v2=29>]] (to send death packet to object with args v1 v2)";
char tmpStr[128];
const char* textMsg = usage;
- PMessage* tmpMsg = NULL;
+ PMessage* tmpMsg = nullptr;
char Arg1[30];
if ( IsAdmin() == false )
//sleep(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
}
- tmpMsg = NULL;
+ tmpMsg = nullptr;
}
else if ( Arg1[0] == 'd' )
{
textMsg = tmpStr;
source->SendUDPMessage( tmpMsg );
- tmpMsg = NULL;
+ tmpMsg = nullptr;
}
else if ( Arg1[0] == 'e' )
{
textMsg = tmpStr;
source->SendUDPMessage( tmpMsg );
- tmpMsg = NULL;
+ tmpMsg = nullptr;
}
else if ( Arg1[0] == 'w' )
{
textMsg = tmpStr;
source->SendUDPMessage( tmpMsg );
- tmpMsg = NULL;
+ tmpMsg = nullptr;
}
else if ( Arg1[0] == 'x' )
{
textMsg = tmpStr;
source->SendUDPMessage( tmpMsg );
- tmpMsg = NULL;
+ tmpMsg = nullptr;
}
}
uint32_t val1;
uint8_t val2;
char tmpStr[128];
- static PMessage* tmpMsg = NULL;
+ static PMessage* tmpMsg = nullptr;
bool SetUDP_IDNeeded = true;
PChar* nChar = source->GetChar();
(nChar->Coords).mY += 20;
GetArgText(2, tmp_destNick, 50);
target = GetClientByNick(tmp_destNick);
}
- if(target == NULL)
+ if (target == nullptr)
{
Chat->send(source, CHAT_DIRECT, "System", "No such player");
return;
PMessage* tmpMsg_cash = MsgBuilder->BuildCharMoneyUpdateMsg(target, newcashvalue);
target->SendUDPMessage(tmpMsg_cash);
- tmpMsg_cash = NULL;
+ tmpMsg_cash = nullptr;
char tmpMsg_success[200];
snprintf(tmpMsg_success, 199, "Stole %d NC from %s's wallet (Has now %d NC)", diffcash, target->GetChar()->GetName().c_str(), newcashvalue);
PMessage* tmpMsg_cash = MsgBuilder->BuildCharMoneyUpdateMsg(source, newcashvalue);
source->SendUDPMessage(tmpMsg_cash);
- tmpMsg_cash = NULL;
+ tmpMsg_cash = nullptr;
}
}
target = GetClientByNick(tmp_destNick);
}
- if(target == NULL) // If victim isnt found, return error
+ if (target == nullptr) // If victim isnt found, return error
{
Chat->send(source, CHAT_DIRECT, "System", "No such player");
return;
PMessage* tmpMsg_zone = MsgBuilder->BuildAptLiftUseMsg (target, destZone, 0);
target->SendUDPMessage(tmpMsg_zone);
- tmpMsg_zone = NULL;
+ tmpMsg_zone = nullptr;
char tmpMsg_success[81];
snprintf(tmpMsg_success, 80, "Successfully teleported %s to World %d", target->GetChar()->GetName().c_str(), destZone);
if(ArgC < 5)
return;
- PNPC* targetNPC = NULL;
- PNPCWorld* currentNPCWorld = NULL;
+ PNPC* targetNPC = nullptr;
+ PNPCWorld* currentNPCWorld = nullptr;
currentNPCWorld = NPCManager->GetWorld( source->GetChar()->GetLocation() );
if ( currentNPCWorld )
{
int tF1 = GetArgInt(2);
int tF2 = GetArgInt(3);
- const PDefFaction* tFactionA = NULL;
- const PDefFaction* tFactionB = NULL;
+ const PDefFaction* tFactionA = nullptr;
+ const PDefFaction* tFactionB = nullptr;
if(tF1 > tF2)
{
else
Chat->send(source, CHAT_DIRECT, "Relations", "Invalid faction");
}
-
-
-
-
-
-
- /*
- uint8_t val1 = 0;
- uint8_t val2 = 0;
- uint8_t val3 = 0;
- uint16_t val4 = 0;
- uint16_t val5 = 0;
- // uint16_t val6 = 0;
- // uint8_t val7 = 0;
-
- bool SyntaxError = false;
- if(ArgC < 5)
- {
- SyntaxError = true;
- }
-
- if(IsArgNumeric(1) == false)
- SyntaxError = true;
- if(IsArgNumeric(2) == false)
- SyntaxError = true;
- if(IsArgNumeric(3) == false)
- SyntaxError = true;
- if(IsArgNumeric(4) == false)
- SyntaxError = true;
- if(IsArgNumeric(5) == false)
- SyntaxError = true;
- // if(IsArgNumeric(6) == false)
- // SyntaxError = true;
- // if(IsArgNumeric(7) == false)
- // SyntaxError = true;
-
- if(SyntaxError == true)
- {
- PMessage* tmpMsg1 = new PMessage(14);
-
- *tmpMsg1 << (uint8_t)0x13;
- *tmpMsg1 << (uint16_t)0x0000; // UDP ID placeholder
- *tmpMsg1 << (uint16_t)0x0000; // SessionID placeholder
- *tmpMsg1 << (uint8_t)0x08; // Len (static, always 0x08
- *tmpMsg1 << (uint8_t)0x03;
- *tmpMsg1 << (uint16_t)0x0000; // Sub UDP ID placeholder
- *tmpMsg1 << (uint8_t)0x26; // Command FADE AWAY CHAR (kinda ^^)
- *tmpMsg1 << (uint8_t)0x00;
- *tmpMsg1 << (uint8_t)0x10;
- *tmpMsg1 << (uint8_t)0x00;
- *tmpMsg1 << (uint8_t)0x80;
- ClientManager->UDPBroadcast(tmpMsg1, source);
- }
-
- val1 = (uint8_t)GetArgInt(1);
- val2 = (uint8_t)GetArgInt(2);
- val3 = (uint8_t)GetArgInt(3);
- val4 = (uint16_t)GetArgInt(4);
- val5 = (uint16_t)GetArgInt(5);
- // val7 = (uint16_t)GetArgInt(7);
-
- //tmpMsg = MsgBuilder->BuildCharUseQBSlotMsg1(source, 59);
- //source->SendUDPMessage(tmpMsg);
- //tmpMsg = NULL;
-
- PMessage* tmpMsg = new PMessage(29);
- *tmpMsg << (uint8_t)0x13;
- *tmpMsg << (uint16_t)0x0000;
- *tmpMsg << (uint16_t)0x0000;
- *tmpMsg << (uint8_t)0x16; // Message length
- *tmpMsg << (uint8_t)0x03;
- *tmpMsg << (uint16_t)0x0000;
- *tmpMsg << (uint8_t)0x1b;
- *tmpMsg << (uint8_t)0x00;
- *tmpMsg << (uint8_t)0x10;
- *tmpMsg << (uint8_t)0x00;
- *tmpMsg << (uint8_t)0x80;
- *tmpMsg << (uint8_t)0x19;
- *tmpMsg << (uint8_t)0x55;
- *tmpMsg << (uint8_t)0x74;
- *tmpMsg << (uint8_t)0x80;
- *tmpMsg << (uint8_t)0x82;
- *tmpMsg << (uint8_t)0xc2;
- *tmpMsg << (uint8_t)0x84;
- *tmpMsg << (uint8_t)val1;
- *tmpMsg << (uint8_t)val2;
- *tmpMsg << (uint8_t)val3;
- *tmpMsg << (uint16_t)val4;
- *tmpMsg << (uint16_t)val5;
- // *tmpMsg << (uint8_t)0x69;
- // *tmpMsg << (uint8_t)0x00;
-
- ClientManager->UDPBroadcast(tmpMsg, source);
-
- // ***************************
- bool SyntaxError = false;
- if(ArgC < 1)
- {
- SyntaxError = true;
- }
-
- if(IsArgNumeric(1) == false)
- SyntaxError = true;
-
- if(SyntaxError == true)
- {
- Chat->send(source, CHAT_DIRECT, "Usage", "@test <id>");
- return;
- }
-
- uint16_t itemID;
- char effStr[128];
- PMessage* tmpMsg;
-
- itemID = (uint16_t)GetArgInt(1);
-
- source->GetChar()->SetItemInHand(itemID);
-
- tmpMsg = MsgBuilder->BuildCharHelloMsg(source);
- ClientManager->UDPBroadcast(tmpMsg, source);
- snprintf(effStr, 127, "Item in hand changes to value %d", itemID);
- effStr[127] = '\0';
- Chat->send(source, CHAT_DIRECT, "System", effStr);
- ===========================================================================
- uint16_t ItemToSpawn = 0;
- uint8_t Quality = 0;
- uint8_t Stack = 0;
-
- bool SyntaxError = false;
- if(ArgC < 3)
- {
- SyntaxError = true;
- }
- else
- {
- if(IsArgNumeric(1) == true)
- {
- ItemToSpawn = (uint16_t)GetArgInt(1);
- if(ItemToSpawn == 0)
- {
- SyntaxError = true;
- }
- }
- else
- {
- SyntaxError = true;
- }
-
- if(IsArgNumeric(2) == true)
- {
- Quality = (uint8_t)GetArgInt(2);
- if(Quality == 0)
- {
- SyntaxError = true;
- }
- }
- else
- {
- SyntaxError = true;
- }
-
- if(IsArgNumeric(3) == true)
- {
- Stack = (uint8_t)GetArgInt(3);
- if(Stack == 0)
- {
- SyntaxError = true;
- }
- }
- else
- {
- SyntaxError = true;
- }
- }
- if(SyntaxError == true)
- {
- Chat->send(source, CHAT_DIRECT, "Usage", "@test <itemID> <quality> <itemID>");
- return;
- }
- PMessage* tmpMsg = new PMessage(29);
- source->IncreaseUDP_ID();
- source->IncreaseTransactionID();
-
- *tmpMsg << (uint8_t)0x13;
- *tmpMsg << (uint16_t)source->GetUDP_ID();
- *tmpMsg << (uint16_t)source->GetSessionID();
- *tmpMsg << (uint8_t)0x16; // Message length
- *tmpMsg << (uint8_t)0x03;
- *tmpMsg << (uint16_t)source->GetUDP_ID();
- *tmpMsg << (uint8_t)0x1f;
- *tmpMsg << (uint16_t)source->GetLocalID();
- *tmpMsg << (uint8_t)0x25; // ??
- *tmpMsg << (uint8_t)0x13; // ??
- *tmpMsg << (uint16_t)source->GetTransactionID();
- *tmpMsg << (uint8_t)0x18; // ??
- *tmpMsg << (uint8_t)0x03; // ??
- *tmpMsg << (uint8_t)0x01; // ??
- *tmpMsg << (uint8_t)0x00; // ??
- *tmpMsg << (uint8_t)0x05; // ??
- *tmpMsg << (uint8_t)0x00; // ??
- *tmpMsg << ItemToSpawn;
- *tmpMsg << (uint8_t)0x02; // ??
- *tmpMsg << (uint8_t)0x01; // ??
- *tmpMsg << Quality;
- *tmpMsg << Stack;
-
-
- source->SendUDPMessage(tmpMsg);
- */
}
target = GetClientByNick( tmp_destNick );
}
- if ( target == NULL ) // If victim isnt found, return error
+ if (target == nullptr) // If victim isnt found, return error
{
Chat->send( source, CHAT_DIRECT, "System", "No such player" );
return;
{
PMessage* tmpMsg_zone = MsgBuilder->BuildAptLiftUseMsg( target, destZone, 0 );
target->SendUDPMessage( tmpMsg_zone );
- tmpMsg_zone = NULL;
+ tmpMsg_zone = nullptr;
char tmpMsg_success[81];
snprintf( tmpMsg_success, 80, "Successfully unjailed %s", target->GetChar()->GetName().c_str() );
target = GetClientByNick(tmp_destNick);
}
- if(target == NULL) // If victim isnt found, return error
+ if (target == nullptr) // If victim isnt found, return error
{
Chat->send(source, CHAT_DIRECT, "System", "No such player");
return;
#include "GameServer/Includes.hxx"
+#include "Common/Includes.hxx"
void PCommands::doCmduptime()
{
// get difference between var uptime and current time
time_t Uptime = GameServer->GetStartTime();
- uint32_t TimeDiff = std::time(NULL) - Uptime;
+ uint32_t TimeDiff = Time::nowTimeT() - Uptime;
uint32_t UpYears = 0, UpMonths = 0, UpWeeks = 0, UpDays = 0, UpHours = 0, UpMinutes = 0, UpSeconds = 0;
char tmpY[21], tmpM[21], tmpW[21], tmpD[21], tmpH[21], tmpMi[21], tmpS[21];
target = GetClientByNick( tmp_destNick );
}
- if ( target == NULL ) // If victim isnt found, return error
+ if (target == nullptr) // If victim isnt found, return error
{
Chat->send( source, CHAT_DIRECT, "System", "No such player" );
return;
+++ /dev/null
-#include "GameServer/Includes.hxx"
-#include "Common/Includes.hxx"
-
-#if 0
-PGameScript::PGameScript()
-{
-}
-
-PGameScript::~PGameScript()
-{
- for(HookMap::iterator it = mHooks.begin(); it != mHooks.end(); it++)
- delete it->second;
-}
-
-bool PGameScript::LoadScripts()
-{
-}
-
-bool PGameScript::Rehash()
-{
- Console->LPrint("Rehashing GameMonkey Scripts...");
- for(HookMap::iterator it = mHooks.end(); it != mHooks.begin(); it--)
- mHooks.erase(it);
-
- if(LoadScripts() == true)
- {
- Console->LPrint(GREEN, BLACK, "Done");
- Console->LClose();
- return true;
- }
- else
- {
- Console->LPrint(RED, BLACK, "Failed");
- Console->LClose();
- return false;
- }
-}
-
-void PGameScript::TriggerHook(PHookTypes hook)
-{
-}
-
-
-bool PGameScript::ExecuteFile(const char* a_fileName)
-{
- FILE* scriptFile = NULL;
- char* fileString = NULL;
- int fileSize = 0;
-
- GM_ASSERT(m_machine);
-
- if( !(scriptFile = fopen(a_fileName, "rb")) )
- {
- return false;
- }
-
- fseek(scriptFile, 0, SEEK_END);
- fileSize = ftell(scriptFile);
- fseek(scriptFile, 0, SEEK_SET);
- fileString = new char [fileSize+1];
- fread(fileString, fileSize, 1, scriptFile);
- fileString[fileSize] = 0; // Terminating null
- fclose(scriptFile);
-
- int threadId = GM_INVALID_THREAD;
- int errors = m_machine->ExecuteString(fileString, &threadId, true, a_fileName);
- if(errors)
- {
- LogAnyMachineErrorMessages();
- }
-
- delete [] fileString;
-
- return true;
-}
-
-
-int GM_CDECL PGameScript::AddHook(gmThread *a_thread)
-{
- GM_CHECK_NUM_PARAMS(2);
- GM_CHECK_STRING_PARAM(tmphooktype, 0);
- GM_CHECK_STRING_PARAM(tmpfunction, 1);
-
- mHooks.insert(std::make_pair(tmphooktype, tmpfunction));
-
- return GM_OK;
-}
-
-int PGameScript::AddTwoIntegers(int valueA, int valueB)
-{
- int resultInt = 0;
-
- gmCall call;
-
- if(call.BeginGlobalFunction(&machine, "Add"))
- {
- call.AddParamInt(valueA);
- call.AddParamInt(valueB);
- call.End();
- call.GetReturnedInt(resultInt);
- }
-
- return resultInt;
-}
-#endif
+++ /dev/null
-#pragma once
-
-#if 0
-#include <map>
-#include <string>
-
-enum PHookTypes {
- HOOK_CHAT,
- HOOK_TRADE,
- HOOK_ZONE
-};
-
-class PGameScript {
-private:
- typedef std::map<PHookTypes, std::string> HookMap;
- HookMap mHooks;
-
-public:
- PGameScript();
- ~PGameScript();
-
- bool LoadScripts();
- bool Rehash();
- void TriggerHook(PHookTypes hook);
- bool ExecuteFile(const char* a_fileName);
-};
-#endif
PGameServer::PGameServer()
{
- mServerStartupTime = std::time( NULL );
+ mServerStartupTime = Time::nowTimeT();
mNumClients = 0;
MsgDecoder = new PUdpMsgDecoder();
}
uint32_t CharID = Acc.GetCharIdBySlot( Num );
// Also check that char is out of game
- if (( CharID != 0 ) && ( Chars->GetChar( CharID ) == NULL ) )
+ if ((CharID != 0) && (Chars->GetChar(CharID) == nullptr))
{
char query[100];
snprintf( query, 100, "DELETE FROM characters WHERE c_id = %d LIMIT 1", CharID );
GameStateMap::iterator node = ClientStates.find( nClient );
if ( node == ClientStates.end() )
- return NULL;
+ return nullptr;
else
return node->second;
}
{
mOwnerCharID = nOwnerCharID;
mListMaxSize = mListSize = 0;
- mGenrepList = NULL;
+ mGenrepList = nullptr;
}
PGenrepList::~PGenrepList()
snprintf(query, 256, "SELECT * FROM genrep WHERE (g_charid='%u')", mOwnerCharID);
result = MySQL->GameResQuery(query);
- if(result == NULL)
+ if (result == nullptr)
{
Console->Print(RED, BLACK, "PGenrepList::SQLLoad could not load genreplist from the database");
Console->Print("Query was:");
#include "GameServer/Container.hxx"
#include "GameServer/DoorTemplate.hxx"
#include "GameServer/FurnitureTemplate.hxx"
-#include "GameServer/GameScript.hxx"
#include "GameServer/GameServer.hxx"
#include "GameServer/GenrepList.hxx"
#include "GameServer/Inventory.hxx"
tContainer = mGogo;
break;
default:
- tContainer = NULL;
+ tContainer = nullptr;
}
return tContainer;
}
void PISC::Update_mysql()
{
bool do_update = false;
- std::time_t t = std::time(NULL);
+ time_t t = Time::nowTimeT();
int client_count = Server->GetNumClients();
if (((t - mysql_last_update_time) >= mysql_update_intervall) || (client_count > mysql_last_client_count))
do_mysql_db_update(client_count);
mysql_last_client_count = client_count;
mysql_last_count_decrease_time = 0;
- mysql_last_update_time = std::time(NULL);
+ mysql_last_update_time = Time::nowTimeT();
}
}
int npcscript_callback(lua_State *nLua)
{
PClient* tClient = LuaEngine->GetBoundClient();
- if(tClient == NULL)
+ if (tClient == nullptr)
{
Console->Print("%s [npcscript_callback] No client is set, unable to process actions!", Console->ColorText(RED, BLACK, "[Error]"));
return 0;
}
// Cleanup everything
- mTargetClient = NULL;
+ mTargetClient = nullptr;
CleanUp();
}
bool PLuaEngine::ExecuteScript(std::string nLUAScript, int nNode, int nDialogClass)
{
// Make sure we have an bound client to work with
- if(mTargetClient == NULL)
+ if (mTargetClient == nullptr)
{
Console->Print("%s [PLuaEngine::ExecuteScript] No Client has been bound. Cannot run lua script", Console->ColorText(RED, BLACK, "[Error]"));
return false;
}
// Check if sequence is timed out
- if(i->second.smTimeStamp + MAX_SEQUENCE_LIFE < time(NULL))
+ if(i->second.smTimeStamp + MAX_SEQUENCE_LIFE < Time::nowTimeT())
{
if (gDevDebug) Console->Print("[PMultiPart::Update] Sequence number %d timed out. Deleting...", i->first);
MsgMap.erase(i);
// And push it into the vector
it->second.smvChunk.push_back(tChunk);
// Update lifetimer
- it->second.smTimeStamp = time(NULL);
+ it->second.smTimeStamp = Time::nowTimeT();
}
else
{
// Push our temp chunk into the vector
tSeq.smvChunk.push_back(tChunk);
// Add current timestamp
- tSeq.smTimeStamp = time(NULL);
+ tSeq.smTimeStamp = Time::nowTimeT();
// Set chunktotal
tSeq.smChunkTotal = nChunkTotal;
// Store client
void PNPC::PushUpdateTimer()
{
- mNextUpdate = std::time(nullptr) + GetRandom(NPC_HEARTBEAT_MAX, NPC_HEARTBEAT_MIN);
+ mNextUpdate = Time::nowTimeT() + GetRandom(NPC_HEARTBEAT_MAX, NPC_HEARTBEAT_MIN);
};
// Reload LUA script while running, in case we modified it and dont want to restart the entire server
bool PNPC::SQL_Load()
{
if ( gDevDebug ) Console->Print( "[DEBUG] Now loading NPC data for NPC id %d from SQL", mID );
- MYSQL_RES *result = NULL;
+ MYSQL_RES *result = nullptr;
MYSQL_ROW row;
char query[100];
snprintf( query, 100, "SELECT * FROM `npc_spawns` WHERE `npc_id` = %d", mID );
if ( gDevDebug ) Console->Print( "[DEBUG] Executing query %s", query );
result = MySQL->GameResQuery( query );
- if ( result == NULL )
+ if (result == nullptr)
{
Console->Print( RED, BLACK, "PNPC::SQL_Load could not load NPC definition" );
Console->Print( "Query was:" );
else
mScripting = false;
- if ( row[npc_name] != NULL )
+ if (row[npc_name] != nullptr)
mName = row[npc_name];
- if ( row[npc_customname] != NULL )
+ if (row[npc_customname] != nullptr)
mCustomName = row[npc_customname];
- if ( row[npc_customscript] != NULL )
+ if (row[npc_customscript] != nullptr)
mCustomLua = row[npc_customscript];
// Now make sure we have an valid NPC here. Besides we need some more information
bool PNPC::LoadLUAScript()
{
uint32_t tFileLen = 0;
- PFile* fLua = NULL;
+ PFile* fLua = nullptr;
std::string tLuaFile = "";
std::string tHDRFile = "";
if(mDialogScript.length() > 1)
{
// Get LUA filename from defs
- const PDefScripts* tDefScripts = NULL;
+ const PDefScripts* tDefScripts = nullptr;
std::map<int, PDefScripts*>::const_iterator itScrStart = GameDefs->Scripts()->ConstIteratorBegin();
std::map<int, PDefScripts*>::const_iterator itScrEnd = GameDefs->Scripts()->ConstIteratorEnd();
for ( std::map<int, PDefScripts*>::const_iterator i = itScrStart; i != itScrEnd; i++ )
// Reset vars
tFileLen = 0;
- fLua = NULL;
+ fLua = nullptr;
fLua = Filesystem->Open( "", tLuaFile.c_str(), Config->GetOption( "nc_data_path" ) );
if(fLua)
if ( gDevDebug ) Console->Print( "[DEBUG] NPC dying now" );
mHealth = 0;
mAction = NPC_ACTIONSTATE_DEATH;
- mRespawn = std::time( NULL ) + NPC_RESPAWN_AFTER;
+ mRespawn = Time::nowTimeT() + NPC_RESPAWN_AFTER;
mDirty = true;
}
void PNPC::Update()
{
// Has to be changed for mobs later
- if ( std::time( NULL ) >= mRespawn && (mAction&NPC_ACTIONSTATE_DEATH) )
+ if (Time::nowTimeT() >= mRespawn && (mAction&NPC_ACTIONSTATE_DEATH))
{
if ( gDevDebug ) Console->Print( "[DEBUG] NPC Update: Respawn timer triggered! Setting NPC back to life" );
mHealth = mMaxHealth;
// Set next update timer for this NPC to 10 - 30 seconds
// Note: this is for regular heartbeats only. If npc is dirty,
// an update is sent anyway
- mNextUpdate = std::time(NULL) + GetRandom(30, 10);
+ mNextUpdate = Time::nowTimeT() + GetRandom(30, 10);
}
void PNPC::Attack( uint32_t nWorldID, uint8_t nType, uint8_t nUnknown )
// Now broadcast the new NPC to all clients
BroadcastNewNPC(tmpNpc);
mNPCs.insert( std::make_pair( nRaw_ID, tmpNpc ) );
- tmpNpc = NULL;
+ tmpNpc = nullptr;
if ( gDevDebug ) Console->Print( "[PNPCWorld::AddNPC] Custom NPC added" );
}
else
void PNPCWorld::MSG_SendNPCs( PClient* nClient )
{
- PNPC* nNpc = NULL;
+ PNPC* nNpc = nullptr;
for ( PNPCMap::iterator it = mNPCs.begin(); it != mNPCs.end(); it++ )
{
nNpc = it->second;
bool PNPCWorld::LoadNPCfromSQL()
{
// Load NPC defs from MySQL
- MYSQL_RES *result = NULL;
+ MYSQL_RES *result = nullptr;
MYSQL_ROW row;
char query[100];
snprintf( query, 100, "SELECT * FROM `npc_spawns` WHERE `npc_location` = %d", mWorldID );
//if(gDevDebug) Console->Print("[DEBUG] Query is: %s", query);
result = MySQL->GameResQuery( query );
- if ( result == NULL )
+ if (result == nullptr)
{
Console->Print( RED, BLACK, "PNPCWorld::PNPCWorld could not load NPC definition" );
Console->Print( "Query was:" );
return true;
}
//if(gDevDebug) Console->Print("[DEBUG] Found NPCs, now adding!");
- PNPC* tmpNpc = NULL;
+ PNPC* tmpNpc = nullptr;
uint32_t tRawID = 0;
int tSQLID = 0;
while (( row = mysql_fetch_row( result ) ) )
{
//if(gDevDebug) Console->Print("[DEBUG] NPC init successfull, adding to list");
mNPCs.insert( std::make_pair( tRawID, tmpNpc ) );
- tmpNpc = NULL;
+ tmpNpc = nullptr;
}
else
{
{
const PNPCsMap* tNPCmap = Worlds->GetWorld(mWorldID)->GetNPCMap(); // Get the NPC Map for this world
- PNPC* tmpNpc = NULL;
+ PNPC* tmpNpc = nullptr;
uint32_t tDEFID = 0;
for ( PNPCsMap::const_iterator i = tNPCmap->begin(); i != tNPCmap->end(); i++ )
if ( tmpNpc->mSuccess == true )
{
mNPCs.insert( std::make_pair( tDEFID, tmpNpc ) );
- tmpNpc = NULL;
+ tmpNpc = nullptr;
}
else
{
//if(gDevDebug) Console->Print("[DEBUG] New world got initialized! Now starting to add NPCs. (WorldID %d)", nWorldID);
// Assign WorldValues now
- mCreation = std::time( NULL );
+ mCreation = Time::nowTimeT();
mWorldID = nWorldID;
mLastAliveMsg = 0;
LoadNPCfromSQL();
// Updates NPC in a World.
// If NPC is dirty, send "large" update. Else
// send small "i'm alive" message
- std::time_t tNow = std::time(NULL);
- PNPC* tNPC = NULL;
+ time_t tNow = Time::nowTimeT();
+ PNPC* tNPC = nullptr;
for ( PNPCMap::iterator it = mNPCs.begin(); it != mNPCs.end(); it++ )
{
if ( it->second )
return;
}
-/*
-void PNPCWorld::Update()
-{
- // Updates NPC in a World.
- // If NPC is dirty, send "large" update. Else
- // send small "i'm alive" message
- std::time_t tNow = std::time(NULL);
- PNPC* tNPC = NULL;
- for ( PNPCMap::iterator it = mNPCs.begin(); it != mNPCs.end(); it++ )
- {
- if ( it->second )
- {
- tNPC = it->second;
- // Check for enemies nearby
- CheckForEnemies(tNPC);
- // Let NPC make themselfs "dirty"
- tNPC->Update();
- // Only update dirty npcs
- if ( tNPC->mDirty == true )
- {
- PMessage* tmpMsg = MsgBuilder->BuildNPCMassUpdateMsg( tNPC->GetRealWorldID(), tNPC->mPosX, tNPC->mPosY,
- tNPC->mPosZ, tNPC->GetActionStatus(), tNPC->mHealth, tNPC->mTarget, tNPC->mAction);
-
- ClientManager->UDPBroadcast( tmpMsg, mWorldID );
- tNPC->mDirty = false;
- // Large update also counts as small one, inc update counter
- tNPC->PushUpdateTimer();
- }
- else if(tNPC->mNextUpdate <= tNow)
- {
- PMessage* tmpMsg = MsgBuilder->BuildNPCMassAliveMsg( tNPC->GetRealWorldID(), tNPC->mPosX, tNPC->mPosY,
- tNPC->mPosZ, tNPC->GetActionStatus(), tNPC->mHealth, tNPC->mAction);
-
- ClientManager->UDPBroadcast( tmpMsg, mWorldID );
- tNPC->PushUpdateTimer();
- }
- }
- }
-
- return;
-}
-*/
PNPC* PNPCWorld::GetNPC( uint32_t nNPCID )
{
if ( gDevDebug ) Console->Print( "[DEBUG] Searching for NPC %d in list", nNPCID );
PNPCMap::const_iterator it = mNPCs.find( nNPCID );
if ( it == mNPCs.end() ) // only if client not found in list
- return NULL;
+ return nullptr;
else
return it->second;
}
// Search worldmanager for this zone
PNPCWorld* tmpWorld = GetWorld( nZone );
- if ( tmpWorld != NULL )
+ if (tmpWorld != nullptr)
{
if ( gDevDebug ) Console->Print( "[DEBUG] World found, poking MSG_SendNPCs" );
// World found? Fine. Then poke the class to send its content to the client
if ( gDevDebug ) Console->Print( "[DEBUG] World not found, creating...." );
// World not found! OMG! Create it!
tmpWorld = InitWorld( nZone );
- if ( tmpWorld == NULL )
+ if (tmpWorld == nullptr)
{
Console->Print( "%s Unable to init NPCs for world %d", Console->ColorText( RED, BLACK, "[ERROR]" ), nZone );
return;
PNPCWorld* PNPCManager::InitWorld( uint32_t nWorldID )
{
if ( gDevDebug ) Console->Print( "[DEBUG] InitWorld triggered: ID %d", nWorldID );
- PNPCWorld* tmpWorld = NULL;
+ PNPCWorld* tmpWorld = nullptr;
tmpWorld = new PNPCWorld( nWorldID );
- if ( tmpWorld != NULL )
+ if (tmpWorld != nullptr)
{
if ( gDevDebug ) Console->Print( "[DEBUG] World created. Adding to list..." );
mWorlds.insert( std::make_pair( nWorldID, tmpWorld ) );
else
{
if ( gDevDebug ) Console->Print( "[DEBUG] Failed to init world. Returning NULL" );
- return NULL;
+ return nullptr;
}
}
void PNPCManager::Update()
{
- static std::time_t lastdebug = std::time( NULL );
+ static time_t lastdebug = Time::nowTimeT();
// Loop all worlds
- // if(lastdebug < std::time(NULL))
+ // if(lastdebug < Time::nowTimeT())
// if(gDevDebug) Console->Print("[DEBUG] WorldLoop still running...");
for ( PNPCWorldMap::iterator it = mWorlds.begin(); it != mWorlds.end(); it++ )
PNPCWorld* tWorld = it->second;
if ( ClientManager->IsWorldInUse( tWorld->mWorldID ) == true )
{
- //if(lastdebug < std::time(NULL))
+ //if(lastdebug < Time::nowTimeT())
// if(gDevDebug) Console->Print("[DEBUG] World is in use, poking management class to update itself");
// World is in use. Now send "dirty" npcs or alive messages
tWorld->Update();
}
else
{
- //if(lastdebug < std::time(NULL))
+ //if(lastdebug < Time::nowTimeT())
// if(gDevDebug) Console->Print("[DEBUG] World not in use. Checking lifetimer...");
- if (( tWorld->mCreation + ZONE_RESET_AFTER ) <= std::time( NULL ) )
- //if(tWorld->mCreation <= std::time(NULL))
+ if ((tWorld->mCreation + ZONE_RESET_AFTER ) <= Time::nowTimeT())
+ //if(tWorld->mCreation <= Time::nowTimeT())
{
if ( gDevDebug ) Console->Print( "[DEBUG] World reached ZONE_RESET timeout. Erasing..." );
// World is unused sine ZONE_RESET_AFTER minutes, deleting now
else
{
// Keep LastAliveMessage up to date until someone enters zone
- tWorld->mLastAliveMsg = std::time( NULL );
- // if(lastdebug < std::time(NULL))
+ tWorld->mLastAliveMsg = Time::nowTimeT();
+ // if(lastdebug < Time::nowTimeT())
// if(gDevDebug) Console->Print("[DEBUG] World still within ZONE_RESET timeout");
}
}
}
}
- if ( lastdebug < std::time( NULL ) )
+ if (lastdebug < Time::nowTimeT())
{
- lastdebug = std::time( NULL ) + 3;
+ lastdebug = Time::nowTimeT() + 3;
//if(gDevDebug) Console->Print("[DEBUG] next updateloopmsg in 3 seconds");
}
}
if ( it == mWorlds.end() )
{
if ( gDevDebug ) Console->Print( "[DEBUG] Not found, returning NULL" );
- return NULL;
+ return nullptr;
}
else
{
// Healthfactor for NPCs (see old npc.def)
#define NPC_HEALTHFACTOR 15
-
+
// Minimum time in seconds that has to pass before an NPC
// gets his heartbeat send
#define NPC_HEARTBEAT_MIN 5
// Maximum time in seconds that is allowed to pass without
// an NPC heartbeat
#define NPC_HEARTBEAT_MAX 20
-
+
// If no custom NPC is set in this Zone, what ID to start with?
#define NEW_NPC_ZONEID_START 1000
// How many seconds have to pass until we need an NPC "keepalive" packet?
#define NPC_ALIVE_MSG 15
-
+
// How often a NPC should check if an enemy is nearby?
#define NPC_ENEMYCHECK 5
-
+
#define NPC_ACTIONSTATE_SITGND 0x00
#define NPC_ACTIONSTATE_ATTACK 0x01
//#define NPC_ACTIONSTATE_? 0x02
#define NPC_ACTIONSTATE_PASSIVE 0x20
#define NPC_ACTIONSTATE_IDLE 0x40
#define NPC_ACTIONSTATE_DEATH 0x80
-
+
#define NPC_SHOOT_IDLE 15
#define NPC_SHOOT_SINGLE 16
#define NPC_SHOOT_AUTO1 17
#define NPC_SHOOT_AUTO2 18
-
+
class PNPC;
class PNPCWorld;
typedef std::map<uint32_t, PNPC*> PNPCMap;
typedef std::map<uint32_t, PNPCWorld*> PNPCWorldMap;
-
+
typedef struct
{
uint16_t ItemID;
uint32_t Price;
} stShopListEntry;
-
+
class PNPC
{
private:
npc_shop_quality,
npc_scripting
};
-
+
time_t mNextUpdate; // Timestamp for next heartbeat
time_t mNextEnemyCheck; // Timestamp for next enemycheck
void PushUpdateTimer();
uint16_t mTrader;
uint8_t mItemQuality; // Used for Shopping stuff
uint8_t mUnknown;
-
+
std::string mDialogScript;
std::string mLUAFile; // Load File; Preloaded uppon NPC creation
-
+
std::vector<stShopListEntry> mVectItemsInShop; // We need to keep track of the itemorder for shopping
void AddToVectorList(uint16_t nItemID, uint32_t nPrice);
- inline const stShopListEntry* GetItemNum(uint32_t nIdx) const { if(nIdx > mVectItemsInShop.size()) { return NULL; } else { return &mVectItemsInShop[nIdx]; }};
-
+ inline const stShopListEntry* GetItemNum(uint32_t nIdx) const { if(nIdx > mVectItemsInShop.size()) { return nullptr; } else { return &mVectItemsInShop[nIdx]; }};
+
bool mScripting; // Manual override to disable scripting for an NPC TRUE: Scripts will be executed FALSE: Scripts will be ignored
std::string mName;
// WorldID Fix 10.10.2009
bool mFromDEF; // to differ DEF NPCs from SQL NPCs
bool mSuccess; // NPC load successfull?
-
+
uint8_t mAction; // Current action
inline uint8_t GetActionStatus() const { return mAction; };
// 00100000 ( 32) 0x20: Passive-Mode (Depends on WeaponStatus. Difference between 0x01: NPC does NOT open fire)
// 01000000 ( 64) 0x40: Idle
// 10000000 (128) 0x80: Die
-
+
uint8_t mWeaponStatus;
inline uint8_t GetWeaponStatus() const { return mWeaponStatus; };
// 00001111 (15) 0x0F: Follow given target with eyes / Put weapon away if pulled
// 00010000 (16) 0x10: Pull weapon if not pulled / If pulled, attack
// 00010001 (17) 0x11: Pull weapon and attack
-
+
bool SQL_Load();
bool DEF_Load(uint32_t nWorldID);
-
+
PNPC( int nSQLID );
PNPC( int nDEFID, uint32_t nWorldID );
~PNPC();
-
+
void InitVars();
void ContentListAddItem(PMessage* nContentList, uint16_t nItemID, uint32_t nBasePrice = 0, bool nAddToList = true);
void ContentListAddItemGroup(PMessage* nContentList, uint32_t nItemGroupID);
void StartDialog( PClient* nClient/*, string &nDialogscript */);
-
+
bool DoSQLShoppingList( PClient* nClient, PMessage* nContentList );
bool HasSQLShoppingList( PClient* nClient );
bool IsAllbuyer( PClient* nClient );
bool LoadLUAScript();
-
+
inline uint32_t GetRealWorldID() { if(mFromDEF == true) return mWorldID+255; else return mWorldID; };
public:
friend class PNPCWorld;
-
+
inline void StopAttack() { mDirty = true; mAction = NPC_ACTIONSTATE_IDLE; mWeaponStatus = NPC_SHOOT_IDLE; };
inline void Attack( PClient* nClient, uint8_t nType = NPC_SHOOT_SINGLE, uint8_t nUnknown = 90 ) { Attack(nClient->GetChar()->GetID(), nType, nUnknown); };
void Attack( uint32_t nWorldID, uint8_t nType = NPC_SHOOT_SINGLE, uint8_t nUnknown = 90 );
-
+
inline void Move( uint16_t nNewX, uint16_t nNewY, uint16_t nNewZ )
{
mPosX = nNewX;
void Update(); // Check respawn timer
void StartConversation( PClient* nClient );
void DoConversation( PClient* nClient, uint8_t nAnswer ) ;
-
+
// GameCommands
bool ReloadLUAScript();
bool ReloadShopList();
bool LoadNPCfromSQL();
bool LoadNPCfromDEF();
-
+
void BroadcastNewNPC(PNPC* nNpc);
void CheckForEnemies(PNPC* nNPC);
public:
friend class PNPCManager;
PNPC* GetNPC( uint32_t nNPCID );
-
+
// Functions to add/remove an NPC while server is running
void SendSingleNPCInfo( PClient* nClient, PNPC* nNpc ); // Send
bool AddNPC(uint32_t nSQL_ID, uint32_t nRaw_ID); // Load single SQL NPC from given SQL ID
void PNPCWorld::CheckForEnemies(PNPC* nNPC)
{
//return;
- time_t tNow = time(NULL);
+ time_t tNow = Time::nowTimeT();
// Is it time for next enemy check?
// Temp: Skip that for IDs below 1000
if(tNow > nNPC->mNextEnemyCheck)
{
//Console->Print("[NPC AI] Checking enemy status for NPC %d", nNPC->GetRealWorldID());
- nNPC->mNextEnemyCheck = time(NULL) + NPC_ENEMYCHECK;
+ nNPC->mNextEnemyCheck = Time::nowTimeT() + NPC_ENEMYCHECK;
// Loop all NPCs in my world
// tNearestEnemy[0] = WorldID | tNearestEnemy[1] = Distance to us
if(tFactionMe == tFactionHim)
continue;
- const PDefFaction* tFaction = NULL;
+ const PDefFaction* tFaction = nullptr;
int tStanding = 0;
// Always check higher faction against lower faction
if(tFactionMe > tFactionHim)
void PNPC::ContentListAddItemGroup(PMessage* nContentList, uint32_t nItemGroupID)
{
- const PDefItems* tDefItems = NULL;
+ const PDefItems* tDefItems = nullptr;
std::map<int, PDefItems*>::const_iterator itStart = GameDefs->Items()->ConstIteratorBegin();
std::map<int, PDefItems*>::const_iterator itEnd = GameDefs->Items()->ConstIteratorEnd();
for ( std::map<int, PDefItems*>::const_iterator i = itStart; i != itEnd; i++ )
bool PNPC::DoSQLShoppingList( PClient* nClient, PMessage* nContentList )
{
- MYSQL_RES *result = NULL;
+ MYSQL_RES *result = nullptr;
MYSQL_ROW row;
char query[100];
snprintf( query, 100, "SELECT * FROM `npc_shop` WHERE `c_npc_id` = %d AND `c_zoneid` = %d", mWorldID, nClient->GetChar()->GetLocation());
if (gDevDebug) Console->Print( "[PNPC::DoSQLShoppingList] Executing query %s", query );
result = MySQL->GameResQuery( query );
- if ( result == NULL )
+ if (result == nullptr)
{
Console->Print( YELLOW, BLACK, "[PNPC::DoSQLShoppingList] could not load shoplist from SQL" );
Console->Print( "Query was:" );
bool PNPC::IsAllbuyer( PClient* nClient )
{
- MYSQL_RES *result = NULL;
+ MYSQL_RES *result = nullptr;
char query[100];
snprintf( query, 100, "SELECT * FROM `npc_shop` WHERE `c_npc_id` = %d AND `c_zoneid` = %d and `c_itemid` = -1", mWorldID, nClient->GetChar()->GetLocation());
Console->Print( "[PNPC::IsAllbuyer] Executing query %s", query );
result = MySQL->GameResQuery( query );
- if ( result == NULL )
+ if (result == nullptr)
{
Console->Print( YELLOW, BLACK, "[PNPC::IsAllbuyer] could not check if npc is allbuyer" );
Console->Print( "Query was:" );
bool PNPC::HasSQLShoppingList( PClient* nClient )
{
- MYSQL_RES *result = NULL;
+ MYSQL_RES *result = nullptr;
char query[100];
snprintf( query, 100, "SELECT * FROM `npc_shop` WHERE `c_npc_id` = %d AND `c_zoneid` = %d", mWorldID, nClient->GetChar()->GetLocation());
Console->Print( "[PNPC::HasSQLShoppingList] Executing query %s", query );
result = MySQL->GameResQuery( query );
- if ( result == NULL )
+ if (result == nullptr)
{
Console->Print( YELLOW, BLACK, "[PNPC::HasSQLShoppingList] could not load shoplist from SQL" );
Console->Print( "Query was:" );
uint32_t POutpost::GetCurrentClan(uint32_t nOutpostID)
{
- MYSQL_RES *result = NULL;
+ MYSQL_RES *result = nullptr;
char tQuery[200];
snprintf(tQuery, 200, "SELECT o_clan FROM outposts WHERE o_outnum = %d", nOutpostID);
if(!nClient)
return;
- MYSQL_RES *result = NULL;
- MYSQL_ROW row = NULL;
+ MYSQL_RES *result = nullptr;
+ MYSQL_ROW row = nullptr;
char tQuery[200];
int nZoneID = nClient->GetChar()->GetLocation();
strncpy(game_password, Config->GetOption("game_sql_password").c_str(), 100);
strncpy(game_database, Config->GetOption("game_sql_database").c_str(), 100);
- mKeepaliveDelay = (std::time_t) (Config->GetOptionInt("mysql_wait_timeout") * 0.9) ; // we take 90% of the wait_timeout to trigger keepalive
+ mKeepaliveDelay = (time_t) (Config->GetOptionInt("mysql_wait_timeout") * 0.9) ; // we take 90% of the wait_timeout to trigger keepalive
if (mKeepaliveDelay == 0)
{
Console->Print("%s MySQL keepalive disabled by config", Console->ColorText(GREEN, BLACK, "[Info]"));
CheckResCount(); // Check for MYSQL_RES mem leak
// MySQL keepalive
- std::time_t t = std::time(NULL);
+ time_t t = Time::nowTimeT();
if ((mKeepaliveDelay > 0) && ((t - mLastKeepaliveSent) > mKeepaliveDelay))
{
MYSQL_RES *result;
else
FreeInfoSQLResult(result);
- mLastKeepaliveSent = std::time(NULL);
+ mLastKeepaliveSent = Time::nowTimeT();
if (gDevDebug) Console->Print("%s MySQL keepalive sent", Console->ColorText(GREEN, BLACK, "[Debug]"));
}
}
{
Console->LPrint("Establishing link to Infoserver Database...");
- info_dbHandle = mysql_init(NULL);
+ info_dbHandle = mysql_init(nullptr);
if(!info_dbHandle)
{
exit(0);
}
- if(!mysql_real_connect(info_dbHandle, info_host, info_userName, info_password, info_database, info_port, NULL, 0))
+ if(!mysql_real_connect(info_dbHandle, info_host, info_userName, info_password, info_database, info_port, nullptr, 0))
{
Console->LPrint(RED, BLACK, "[ERROR]");
Console->LClose();
// <><><><><><><><> Gameserver DB <><><><><><><><>
Console->LPrint("Establishing link to Gameserver Database...");
- game_dbHandle = mysql_init(NULL);
+ game_dbHandle = mysql_init(nullptr);
if(!game_dbHandle)
{
exit(0);
}
- if(!mysql_real_connect(game_dbHandle, game_host, game_userName, game_password, game_database, game_port, NULL, 0))
+ if(!mysql_real_connect(game_dbHandle, game_host, game_userName, game_password, game_database, game_port, nullptr, 0))
{
Console->LPrint(RED, BLACK, "[ERROR]");
Console->LClose();
MYSQL_RES *result;
sql_result = mysql_real_query(info_dbHandle, query, strlen(query));
- if(sql_result)
- {
- return NULL;
- }
+ if (sql_result)
+ return nullptr;
+
result = mysql_store_result(info_dbHandle);
- if(!result)
- {
- return NULL;
- }
+ if (!result)
+ return nullptr;
//if(InfoDBInuse == true)
/*if(InfoDBInuse > 0)
{
MYSQL_RES *result;
sql_result = mysql_real_query(game_dbHandle, query, strlen(query));
- if(sql_result)
- {
- return NULL;
- }
+ if (sql_result)
+ return nullptr;
+
result = mysql_store_result(game_dbHandle);
- if(!result)
- {
- return NULL;
- }
+ if (!result)
+ return nullptr;
+
/*if(GameDBInuse > 0)
{
Console->Print("%s another (%d) game_dbHandle result is still in use", Console->ColorText(YELLOW, BLACK, "[Warning]"), GameDBInuse);
return mysql_real_escape_string(game_dbHandle, dText, nText, nLength);
}
-
-// ----------------------------------------------------
-/*
-int PMySQL::GetWorldItemType(unsigned short ID, int Location)
-{
- char query[2048];
- MYSQL_RES *result;
- MYSQL_ROW row;
-
- if (Location > 100000)
- {
- //int nAppLoc = GetAptLocation(Location);
- int nAppLoc = Location - 100000; // temp as DB doesn't link with App world ID, but with app ID
- if (nAppLoc)
- snprintf(query, 2048, "SELECT ai_type FROM apt_items WHERE ai_apt_id = %d AND ai_apt_map = %d", ID, nAppLoc);
- else
- return 0;
- }
- else
- snprintf(query, 2048, "SELECT wi_type FROM world_items WHERE wi_worlditem_id = %d AND wi_worlditem_map = %d", ID, Location);
-
- result = GameResQuery(query);
- if(!result)
- {
- Console->Print("%s Cannot get WorldItemType; MySQL returned", Console->ColorText(RED, BLACK, "[Error]"));
- ShowGameSQLError();
- return 0;
- }
- else
- {
- if(mysql_num_rows(result) > 1)
- {
- FreeGameSQLResult(result);
- return -2;
- }
- else
- {
- row = mysql_fetch_row(result);
- if(row == NULL)
- {
- FreeGameSQLResult(result);
- return -1;
- }
- int ret_val = std::atoi(row[0]);
- FreeGameSQLResult(result);
- return ret_val;
- }
- }
-// else
-// {
-// FreeGameSQLResult(result);
-// return -1;
-// }
-//
- return -1;
-}
-
-int PMySQL::GetWorldItemOption(unsigned short ID, int Location, int option)
-{
- char query[2048];
- MYSQL_RES *result;
- MYSQL_ROW row;
- if(option != 1 && option != 2 && option != 3)
- {
- return -1;
- }
-
- if (Location > 100000)
- {
- //int nAppLoc = GetAptLocation(Location);
- int nAppLoc = Location - 100000; // temp as DB doesn't link with App world ID, but with app ID
- if (nAppLoc)
- snprintf(query, 2048, "SELECT ai_option%d FROM apt_items WHERE ai_apt_id = %d AND ai_apt_map = %d", option, ID, nAppLoc);
- else
- return 0;
- }
- else
- snprintf(query, 2048, "SELECT wi_option%d FROM world_items WHERE wi_worlditem_id = %d AND wi_worlditem_map = %d", option, ID, Location);
-
- result = GameResQuery(query);
- if(!result)
- {
- Console->Print("%s Cannot get WorldItemOption; MySQL returned", Console->ColorText(RED, BLACK, "[Error]"));
- ShowGameSQLError();
- return 0;
- }
- else
- {
- if(mysql_num_rows(result) > 1)
- {
- FreeGameSQLResult(result);
- return -2;
- }
- else
- {
- row = mysql_fetch_row(result);
- if(row == NULL)
- {
- FreeGameSQLResult(result);
- return -1;
- }
- int ret_val = std::atoi(row[0]);
- FreeGameSQLResult(result);
- return ret_val;
- }
- }
-//
-// else
-// {
-// FreeGameSQLResult(result);
-// return -1;
-// }
-
- return -1;
-}
-
-int PMySQL::GetWorldDoorType(unsigned int ID, int Location) // To be removed
-{
- char query[2048];
- MYSQL_RES *result;
- MYSQL_ROW row;
-
-Console->Print(RED, BLACK, "PMySQL::GetWorldDoorType: DATABASE MUST NOT BE USED ANYMORE FOR DOORS INFO !!!");
- if (Location > 100000)
- {
- //int nAppLoc = GetAptLocation(Location);
- int nAppLoc = Location - 100000; // temp as DB doesn't link with App world ID, but with app ID
- if (nAppLoc)
- snprintf(query, 2048, "SELECT ad_type FROM apt_doors, apartments WHERE apt_doors.ad_apt_map = apartments.apt_type AND apt_doors.ad_apt_id = %i AND apartments.apt_id = %i", ID, nAppLoc);
- else
- return 0;
- }
- else
- {
- snprintf(query, 2048, "SELECT wd_type FROM world_doors WHERE wd_world_id = %d AND wd_world_map = %d", ID, Location);
- }
- result = GameResQuery(query);
-
- if(!result)
- {
- Console->Print("%s Cannot get WorldDoorType; MySQL returned", Console->ColorText(RED, BLACK, "[Error]"));
- ShowGameSQLError();
- return 0;
- } else {
- if(mysql_num_rows(result) > 1)
- {
- FreeGameSQLResult(result);
- return -2;
- }
- else
- {
- row = mysql_fetch_row(result);
- if(row == NULL)
- {
- FreeGameSQLResult(result);
- return -1;
- }
- int ret_val = std::atoi(row[0]);
- FreeGameSQLResult(result);
- return ret_val;
- }
- }
-//
-// else
-// {
-// FreeGameSQLResult(result);
-// return -1;
-// }
-//
- return -1;
-}*/
char info_password[100];
char info_database[100];
MYSQL *info_dbHandle;
- std::time_t mKeepaliveDelay;
- std::time_t mLastKeepaliveSent;
+ time_t mKeepaliveDelay;
+ time_t mLastKeepaliveSent;
int game_port;
char game_host[100];
PSubwayInfo mSubways[mCabsNumber];
public:
- bool GetInfoIndex(uint32_t nVhcId, uint8_t *Index = NULL);
+ bool GetInfoIndex(uint32_t nVhcId, uint8_t *Index = nullptr);
public:
PSubway();
uint16_t GetPosition(uint32_t nVhcId);
uint32_t GetTimeOffset(uint32_t nVhcId, uint32_t nTime);
- uint8_t GetStation(uint32_t nVhcId, uint32_t nTime, uint32_t* TimeOffset = NULL);
+ uint8_t GetStation(uint32_t nVhcId, uint32_t nTime, uint32_t* TimeOffset = nullptr);
bool IsDoorOpen(uint32_t nVhcId, uint32_t nTime);
std::string* GetStationName(uint8_t nStationId);
bool GetStationExitPosition(PCharCoordinates* nPosition, uint8_t nStationId, float nCoef = 0.5);
uint8_t PTerminal::GetNewEmailCount(PClient* nClient, bool nNoticeClient)
{
- MYSQL_RES *result = NULL;
+ MYSQL_RES *result = nullptr;
MYSQL_ROW row;
char query[100];
snprintf(query, 100, "SELECT count(*) FROM emails WHERE e_toid = %d AND e_new = 1", nClient->GetCharID());
if(gDevDebug) Console->Print("[DEBUG] Query is: %s", query);
result = MySQL->GameResQuery(query);
- if(result == NULL)
+ if(result == nullptr)
{
Console->Print(RED, BLACK, "PTerminal::GetNewEmailCount could not get emailcount");
Console->Print("Query was:");
if(strlen(mSQLQuery) == 0)
return false;
// ---------------
- MYSQL_RES *result = NULL;
+ MYSQL_RES *result = nullptr;
MYSQL_ROW row;
int tNumRows = 0;
bool PTerminal::DoStockXCheck(PClient* nClient, int nAmountEntered, int nNewAmount)
{
- MYSQL_RES *result = NULL;
+ MYSQL_RES *result = nullptr;
char qry[100];
int tDepotAmount = 0;
// ----------------
if(tGetResultFromSQL == true)
{
- MYSQL_RES *result = NULL;
+ MYSQL_RES *result = nullptr;
//MYSQL_ROW row;
int tNumRows = 0;
}
else
{
- return NULL;
+ return nullptr;
}
}
PSpawnedVehicle* PVehicles::SpawnVehicle( uint32_t nVehicleId, uint32_t nLocation, PVhcCoordinates const* nVhcPos )
{
- PSpawnedVehicle* newVhc = NULL;
+ PSpawnedVehicle* newVhc = nullptr;
PWorld* cWorld;
PVehicleInformation nVhcInfo;
PSpawnedVehicle* PSpawnedVehicles::SpawnVehicle( PVehicleInformation const* nVhcInfo, PVhcCoordinates const* nVhcPos )
{
- PSpawnedVehicle* newVhc = NULL;
+ PSpawnedVehicle* newVhc = nullptr;
uint32_t nSize;
if ( nVhcInfo->GetStatus() == 0 ) // only if in garage
}
if ( mNextFreeHint == nSize )
{
- mSpawnedVehicles.push_back( static_cast<PSpawnedVehicle *>(NULL) );
+ mSpawnedVehicles.push_back( static_cast<PSpawnedVehicle *>(nullptr));
}
if ( mNextFreeHint < mMaxLocalVhc )
}
else
{
- return NULL;
+ return nullptr;
}
}
}
}
- return NULL;
+ return nullptr;
}
bool PSpawnedVehicles::UnspawnVehicle( uint32_t nLocalId )
tVhc->SetStatus( 0 );
}
delete tVhc;
- mSpawnedVehicles[Index] = NULL;
+ mSpawnedVehicles[Index] = nullptr;
if ( mNextFreeHint > Index )
{
mNextFreeHint = Index;
mCharId = nRequesterCharId;
mVhcGlobalId = nVhcGlobalId;
mStatus = 0;
- mTimestamp = std::time( NULL );
+ mTimestamp = Time::nowTimeT();
}
/*
PVhcAccessRequestMap mActiveRequests;
uint32_t mNextRequestId;
-std::time_t mResponseWaitTime; // How long do we wait for owner answer
-std::time_t mCheckWaitTime; // How long do we wait for user access check (0: remaining time from mResponseWaitTime)
-std::time_t mReuseWaitTime; // How long do we allow user to re-use the autorization after first check
+time_t mResponseWaitTime; // How long do we wait for owner answer
+time_t mCheckWaitTime; // How long do we wait for user access check (0: remaining time from mResponseWaitTime)
+time_t mReuseWaitTime; // How long do we allow user to re-use the autorization after first check
*/
void PVhcAccessRequestList::DropTimedOut()
{
{
}
-void PVhcAccessRequestList::SetParameters( std::time_t nResponseWaitTime, std::time_t nCheckWaitTime, std::time_t nReuseWaitTime )
+void PVhcAccessRequestList::SetParameters(time_t nResponseWaitTime, time_t nCheckWaitTime, time_t nReuseWaitTime)
{
mResponseWaitTime = nResponseWaitTime;
mCheckWaitTime = nCheckWaitTime;
it->second.mStatus = 1;
if ( mCheckWaitTime )
{
- it->second.mTimestamp = std::time( NULL );
+ it->second.mTimestamp = Time::nowTimeT();
}
return true;
}
if ( mReuseWaitTime && ( it->second.mStatus == 1 ) )
{
it->second.mStatus = 2;
- it->second.mTimestamp = std::time( NULL );
+ it->second.mTimestamp = Time::nowTimeT();
}
else
{
uint32_t PWorldActors::GetNextFreeWAID()
{
if (gDevDebug) Console->Print("DEBUG: Getting next free worldactor ID...");
- MYSQL_RES *result = NULL;
+ MYSQL_RES *result = nullptr;
MYSQL_ROW row;
char query[100];
if (gDevDebug) Console->Print("DEBUG: Executing query %s", query);
result = MySQL->GameResQuery(query);
- if(result == NULL)
+ if (result == nullptr)
{
Console->Print(RED, BLACK, "PWorldActors::GetNextFreeWAID could not get next free WorldActorID");
Console->Print("Query was:");
DoActorCheck();
if (gDevDebug) Console->Print("DEBUG: Initializing WorldActors for client...");
uint32_t tZone = nClient->GetChar()->GetLocation();
- MYSQL_RES *result = NULL;
+ MYSQL_RES *result = nullptr;
MYSQL_ROW row;
char query[100];
snprintf(query, 100, "SELECT * FROM `world_actors` WHERE `wa_actor_map` = %d", tZone);
//if (gDevDebug) Console->Print("DEBUG: Executing query: %s", query);
result = MySQL->GameResQuery(query);
- if(result == NULL)
+ if (result == nullptr)
{
Console->Print(RED, BLACK, "PWorldActors::InitWorld could not load WorldActor definition");
Console->Print("Query was:");
tmpActorSpawn->U16Data(0x01) = nClient->GetUDP_ID(); // Set final UDP ID
tmpActorSpawn->U16Data(0x03) = nClient->GetSessionID(); // Set final SessionID
nClient->SendUDPMessage(tmpActorSpawn);
- tmpActorSpawn = NULL;
+ tmpActorSpawn = nullptr;
// ReInit message
tmpActorSpawn = new PMessage(256);
void PWorldActors::GetWAoption(uint32_t nWAid, uint16_t nWorld, uint16_t &nValue1, uint16_t &nValue2, uint16_t &nValue3)
{
- MYSQL_RES *result = NULL;
+ MYSQL_RES *result = nullptr;
MYSQL_ROW row;
char query[100];
snprintf(query, 100, "SELECT * FROM `world_actors` WHERE `wa_actor_map` = %d AND `wa_actor_id` = %d", nWorld, nWAid);
result = MySQL->GameResQuery(query);
- if(result == NULL)
+ if (result == nullptr)
{
Console->Print(RED, BLACK, "PWorldActors::GetWAoption could not get WorldActor options");
Console->Print("Query was:");
int PWorldActors::GetWASQLID(uint32_t nWAid, uint32_t nWorld)
{
- MYSQL_RES *result = NULL;
+ MYSQL_RES *result = nullptr;
MYSQL_ROW row;
char query[100];
snprintf(query, 100, "SELECT * FROM `world_actors` WHERE `wa_actor_map` = %d AND `wa_actor_id` = %d", nWorld, nWAid);
result = MySQL->GameResQuery(query);
- if(result == NULL)
+ if (result == nullptr)
{
Console->Print(RED, BLACK, "PWorldActors::GetWASQLID could not get WorldActor SQL ID");
Console->Print("Query was:");
bool PWorldActors::IsDynamicActor(uint32_t nWAid)
{
- MYSQL_RES *result = NULL;
+ MYSQL_RES *result = nullptr;
char query[100];
snprintf(query, 100, "SELECT * FROM `world_actors` WHERE `wa_actor_id` = %d", nWAid);
result = MySQL->GameResQuery(query);
- if(result == NULL)
+ if (result == nullptr)
{
Console->Print(RED, BLACK, "PWorldActors::IsDynamicActor could not check if worldactor is dynamic");
Console->Print("Query was:");
MySQL->FreeGameSQLResult(result);
return false;
}
-/* Not needed. Better re-spawn the actor
-bool PWorldActors::EditWorldActor(uint32_t nWorldID, int nOption1, int nOption2, int nOption3)
-{
- if(IsDynamicActor(nWorldID) == false) // Make sure we really have this actor in DB
- return false;
-
- std::string query;
- query = "UPDATE `world_actors` SET wa_option1 = ";
- if(nOption1 > -1)
- query += Ssprintf("%d,", nOption1);
- else
- query += "wa_option1,";
-
- query += " wa_option2 = ";
- if(nOption2 > -1)
- query += Ssprintf("%d,", nOption2);
- else
- query += "wa_option1,";
-
- query += " wa_option3 = ";
- if(nOption3 > -1)
- query += Ssprintf("%d", nOption3);
- else
- query += "wa_option1";
- query += "WHERE wa_actor_id = ";
- query += Ssprintf("%d", nWorldID);
-
- if(MySQL->GameQuery(query.c_str()))
- {
- Console->Print(RED, BLACK, "PWorldActors::EditWorldActor could not update recordset for worldactor id %d", nWorldID);
- Console->Print("Query was:");
- Console->Print("%s", query.c_str());
- MySQL->ShowGameSQLError();
- return false;
- }
- return true;
-}
-*/
int PWorldActors::GetWorldActorFunctionID(uint32_t nWAid)
{
- MYSQL_RES *result = NULL;
+ MYSQL_RES *result = nullptr;
MYSQL_ROW row;
char query[100];
snprintf(query, 100, "SELECT * FROM `world_actors` WHERE `wa_actor_id` = %d", nWAid);
result = MySQL->GameResQuery(query);
- if(result == NULL)
+ if (result == nullptr)
{
Console->Print(RED, BLACK, "PWorldActors::GetWorldActorFunctionID could not get WorldActor Function ID");
Console->Print("Query was:");
void PWorldActors::GetFrontPos(uint32_t nWAID, uint16_t* mX, uint16_t* mY, uint16_t* mZ)
{
- MYSQL_RES *result = NULL;
+ MYSQL_RES *result = nullptr;
MYSQL_ROW row;
char query[100];
snprintf(query, 100, "SELECT * FROM `world_actors` WHERE `wa_actor_id` = %d", nWAID);
result = MySQL->GameResQuery(query);
- if(result == NULL)
+ if (result == nullptr)
{
Console->Print(RED, BLACK, "PWorldActors::GetFrontPos could not get X/Y/Z values for worldactor");
Console->Print("Query was:");
int PWorldActors::GetLinkedObjectID(uint32_t nWAID)
{
- MYSQL_RES *result = NULL;
+ MYSQL_RES *result = nullptr;
MYSQL_ROW row;
char query[100];
snprintf(query, 100, "SELECT * FROM `world_actors` WHERE `wa_actor_id` = %d", nWAID);
result = MySQL->GameResQuery(query);
- if(result == NULL)
+ if (result == nullptr)
{
Console->Print(RED, BLACK, "PWorldActors::GetLinkedObjectID could not get Linked object ID");
Console->Print("Query was:");
// Check if given WO function is a valid one
const PDefWorldModel* tFurnitureModel = GameDefs->WorldModels()->GetDef(nFunctionID);
- if(tFurnitureModel == NULL)
+ if (tFurnitureModel == nullptr)
return false;
else
return true;
void PWorldActors::DoActorCheck()
{
- MYSQL_RES *result = NULL;
+ MYSQL_RES *result = nullptr;
MYSQL_ROW row;
char query[200];
char query2[100];
snprintf(query, 200, "SELECT COUNT(`wa_actor_id`),`wa_actor_id` FROM `world_actors` GROUP BY `wa_actor_id` HAVING COUNT(`wa_actor_id`)>1");
result = MySQL->GameResQuery(query);
- if(result == NULL)
+ if (result == nullptr)
{
Console->Print(RED, BLACK, "PWorldActors::DoActorCheck unable to check for double actorIDs");
Console->Print("Query was:");
mUseCount = 0;
for ( int i = 0; i < WORLDDATATEMPLATE_MAXPOSITEMS; ++i )
{
- mPositionItems[i] = NULL;
+ mPositionItems[i] = nullptr;
}
}
{
PFurnitureItemsMap::const_iterator it = mFurnitureItems.find( ItemID );
if ( it == mFurnitureItems.end() )
- return NULL;
+ return nullptr;
else
return it->second;
}
{
PDoorsMap::const_iterator it = mDoors.find( DoorID );
if ( it == mDoors.end() )
- return NULL;
+ return nullptr;
else
return it->second;
}
{
PNPCsMap::const_iterator it = mNPCs.find( NPCID );
if ( it == mNPCs.end() )
- return NULL;
+ return nullptr;
else
return it->second;
}
{
mID = 0;
mUseCount = 0;
- mWorldDataTemplate = NULL;
+ mWorldDataTemplate = nullptr;
}
PWorld::~PWorld()
if (( nWorldID > 90000 ) && ( nWorldID < 90017 ) ) // hardcoded holomatch hack
{
- nWorldFileDef = NULL;
+ nWorldFileDef = nullptr;
char worldName[19];
int MatchID = nWorldID - 90000;
if ( MatchID > 8 ) // to care for Neofrag 1 & 2
const PFurnitureItemTemplate *PWorld::GetFurnitureItemTemplate( uint32_t nItemID )
{
- return ( mWorldDataTemplate ? mWorldDataTemplate->GetFurnitureItem( nItemID ) : NULL ) ;
+ return ( mWorldDataTemplate ? mWorldDataTemplate->GetFurnitureItem( nItemID ) : nullptr);
}
const PDefWorldModel *PWorld::GetFurnitureItemModel(uint32_t nItemID)
}
else
{
- mWorldDataTemplatesMap.insert( std::make_pair( nFileName, ( PWorldDataTemplate* )NULL ) ); // NULL means file access OK but not preloaded yet
+ mWorldDataTemplatesMap.insert(std::make_pair(nFileName, (PWorldDataTemplate *)nullptr)); // NULL means file access OK but not preloaded yet
delete tWorldDataTemplate;
}
//return true;
Console->Print( "%s PWorlds::UnloadWorldDataTemplate : attempt to unload template %s when use count not null ou preload set", Console->ColorText( RED, BLACK, "[Warning]" ), nFileName.c_str() );
else
{
- it->second = ( PWorldDataTemplate* )NULL;
+ it->second = (PWorldDataTemplate *)nullptr;
delete tWorldDataTemplate;
}
}
if ( it != mWorldDataTemplatesMap.end() )
return it->second;
else
- return NULL;
+ return nullptr;
}
bool PWorlds::LoadWorlds() // once Load is done, only WorldDataTemplate registred in mWorldDataTemplatesMap
}
else
{
- mStaticWorldsMap.insert( std::make_pair( tDefWorldFile->GetIndex(), ( PWorld* )NULL ) );
+ mStaticWorldsMap.insert(std::make_pair( tDefWorldFile->GetIndex(), (PWorld *)nullptr));
}
if ( gDevDebug )
Console->Print( GREEN, BLACK, "Template file %s for world %d (%s) loaded", tFileName.c_str(), i->second->GetIndex(), i->second->GetName().c_str() );
}
else
{
- mStaticWorldsMap.insert( std::make_pair( 90000 + i, ( PWorld* )NULL ) );
+ mStaticWorldsMap.insert(std::make_pair(90000 + i, (PWorld *)nullptr));
}
if ( gDevDebug )
Console->Print( GREEN, BLACK, "Template file %s for world %d (%s) loaded", tFileName.c_str(), 90000 + i, worldName );
{
delete nWorld;
Console->Print( "% Could not load world %d - World now set as invalid", Console->ColorText( RED, BLACK, "[Warning]" ), nWorldID );
- return NULL;
+ return nullptr;
}
else
{
it = mStaticWorldsMap.find( nWorldID ); // Check if already loaded
if (( it == mStaticWorldsMap.end() ) && nPreloadPhase )
{
- mStaticWorldsMap.insert( std::make_pair( nWorldID, ( PWorld* )NULL ) );
+ mStaticWorldsMap.insert(std::make_pair(nWorldID, (PWorld *)nullptr));
it = mStaticWorldsMap.find( nWorldID );
}
if ( it != mStaticWorldsMap.end() )
delete it->second;
Console->Print( "%s Could not load world %d - World now set as invalid", Console->ColorText( RED, BLACK, "[Warning]" ), nWorldID );
mStaticWorldsMap.erase( it ); // remove from valid worlds map
- return NULL;
+ return nullptr;
}
}
it->second->IncreaseUseCount();
}
else // invalid worldID
{
- return NULL;
+ return nullptr;
}
}
}
else
{
Console->Print( "%s PWorlds::GetWorld : Trying to get world %d without lease !", Console->ColorText( RED, BLACK, "[Warning]" ), nWorldID );
- return NULL;
+ return nullptr;
}
}
if(mUsernameRegexFilter)
{
delete mUsernameRegexFilter;
- mUsernameRegexFilter = NULL;
+ mUsernameRegexFilter = nullptr;
}
if(RegexStr)
if(mPasswordRegexFilter)
{
delete mPasswordRegexFilter;
- mPasswordRegexFilter = NULL;
+ mPasswordRegexFilter = nullptr;
}
if(RegexStr)
//result = MySQL->InfoResQuery(query);
result = MySQL->ResQuery(query);
- if(result == NULL)
+ if(result == nullptr)
{
Console->Print(RED, BLACK, "Failed to load AccountData from SQL");
//MySQL->ShowInfoSQLError();
mPassword = row[a_password];
mBannedUntil = atoi(row[a_bandate]);
- if(mBannedUntil > std::time(NULL))
+ if(mBannedUntil > Time::nowTimeT())
{
mStatus = PAS_BANNED;
mLevel = PAL_BANNED;
return mStatus;
}
-bool PAccount::SetBannedUntilTime(std::time_t BannedUntil)
+bool PAccount::SetBannedUntilTime(time_t BannedUntil)
{
- if ((BannedUntil == 0) || (BannedUntil > std::time(NULL)))
+ if ((BannedUntil == 0) || (BannedUntil > Time::nowTimeT()))
{
mBannedUntil = BannedUntil;
return true;
bool PAccount::IsBanned() const
{
- return (mBannedUntil > std::time(nullptr));
+ return (mBannedUntil > Time::nowTimeT());
}
bool PAccount::DecodePassword(const uint8_t* PasswordData, int PassLen, const uint8_t *Key, char* ClearPassword)
{
const char* unit[5] = {"seconds", "minutes", "hours", "days", "weeks"};
- std::time_t timediff = mBannedUntil - std::time(NULL);
- if(timediff <=0)
- {
+ time_t timediff = mBannedUntil - Time::nowTimeT();
+ if (timediff <=0)
return "0 more seconds. Please relog";
- }
long counter;
int type;
#pragma once
#include <cstdint>
-#include <ctime>
#include <string>
class RegEx;
std::string mPassword;
int32_t mLevel;
PAccountStatus mStatus;
- std::time_t mBannedUntil;
+ time_t mBannedUntil;
bool LoadFromQuery(char *query);
bool DecodePassword(const uint8_t *PasswordData, int32_t PassLen, const uint8_t *Key, char *ClearPassword);
std::string GetLevelString() const;
bool SetStatus(PAccountStatus Status);
PAccountStatus GetStatus() const;
- bool SetBannedUntilTime(std::time_t BannedUntil);
+ bool SetBannedUntilTime(time_t BannedUntil);
bool IsBanned() const;
std::string GetBannedTime() const;
bool Authenticate(const uint8_t *PasswordData, int32_t PassLen, const uint8_t *Key);
// -12: Account is not yet activated (accesslevel = 0)
// -99: General fault. Contact admin
ConnectionTCP *Socket = Client->getTCPConn();
- PAccount* currentAccount = NULL;
+ PAccount* currentAccount = nullptr;
if (PacketSize > 20 && *(uint16_t *)&Packet[3] == 0x8084)
{
void PMySQL::Update()
{
// MySQL keepalive
- time_t t = std::time(NULL);
+ time_t t = Time::nowTimeT();
if ((mKeepaliveDelay > 0) && ((t - mLastKeepaliveSent) > mKeepaliveDelay))
{
MYSQL_RES *result;
else
FreeSQLResult(result);
- mLastKeepaliveSent = std::time(NULL);
+ mLastKeepaliveSent = Time::nowTimeT();
//Console->Print("%s MySQL keepalive sent", Console->ColorText(GREEN, BLACK, "[Debug]"));
}
}
{
Console->LPrint("Establishing link to MySQL Database...");
- dbHandle = mysql_init(NULL);
+ dbHandle = mysql_init(nullptr);
if(dbHandle)
{
exit(0);
}
- if(!mysql_real_connect(dbHandle, host, userName, password, database, port, NULL, 0))
+ if (!mysql_real_connect(dbHandle, host, userName, password, database, port, nullptr, 0))
{
Console->LPrint(RED, BLACK, "[ERROR]");
Console->LClose();
MYSQL_RES *result;
sql_result = mysql_real_query(dbHandle, query, strlen(query));
- if(sql_result)
- {
- return NULL;
- }
+ if (sql_result)
+ return nullptr;
+
result = mysql_store_result(dbHandle);
- if(!result)
- {
- return NULL;
- }
+ if (!result)
+ return nullptr;
return result;
}