2021-12-05 17:54:36 +00:00
/*
* Darkflame Universe
* Copyright 2018
*/
# include "SlashCommandHandler.h"
# include <sstream>
# include <iostream>
# include <fstream>
# include <exception>
# include "dZoneManager.h"
# include <stdio.h> /* defines FILENAME_MAX */
# ifdef _WIN32
# include <direct.h>
# define GetCurrentDir _getcwd
# else
# include <unistd.h>
# define GetCurrentDir getcwd
# endif
# include "Metrics.hpp"
# include "User.h"
# include "UserManager.h"
# include "BitStream.h"
# include "dCommonVars.h"
# include "GeneralUtils.h"
# include "Entity.h"
# include "EntityManager.h"
# include "dLogger.h"
# include "WorldPackets.h"
# include "GameMessages.h"
# include "CDClientDatabase.h"
# include "ZoneInstanceManager.h"
# include "ControllablePhysicsComponent.h"
# include "NiPoint3.h"
# include "NiQuaternion.h"
# include "ChatPackets.h"
# include "InventoryComponent.h"
# include "Game.h"
# include "CharacterComponent.h"
# include "Database.h"
# include "DestroyableComponent.h"
# include "dServer.h"
# include "MissionComponent.h"
# include "Mail.h"
# include "dpWorld.h"
# include "Item.h"
# include "PropertyManagementComponent.h"
# include "PacketUtils.h"
# include "Player.h"
# include "PhantomPhysicsComponent.h"
# include "ProximityMonitorComponent.h"
# include "dpShapeSphere.h"
# include "PossessableComponent.h"
# include "PossessorComponent.h"
# include "VehiclePhysicsComponent.h"
# include "BuffComponent.h"
# include "SkillComponent.h"
# include "VanityUtilities.h"
# include "GameConfig.h"
2022-01-01 10:10:12 +00:00
# include "ScriptedActivityComponent.h"
2022-07-24 18:04:02 +00:00
# include "LevelProgressionComponent.h"
2022-11-01 18:21:26 +00:00
# include "AssetManager.h"
2022-11-27 11:59:59 +00:00
# include "BinaryPathFinder.h"
2022-12-04 22:25:58 +00:00
# include "dConfig.h"
2021-12-05 17:54:36 +00:00
void SlashCommandHandler : : HandleChatCommand ( const std : : u16string & command , Entity * entity , const SystemAddress & sysAddr ) {
2022-07-28 13:39:57 +00:00
std : : string chatCommand ;
std : : vector < std : : string > args ;
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
uint32_t breakIndex = 0 ;
for ( uint32_t i = 1 ; i < command . size ( ) ; + + i ) {
if ( command [ i ] = = L ' ' ) {
breakIndex = i ;
break ;
}
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
chatCommand . push_back ( static_cast < unsigned char > ( command [ i ] ) ) ;
breakIndex + + ;
}
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
uint32_t index = + + breakIndex ;
while ( true ) {
std : : string arg ;
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
while ( index < command . size ( ) ) {
if ( command [ index ] = = L ' ' ) {
args . push_back ( arg ) ;
arg = " " ;
index + + ;
continue ;
}
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
arg . push_back ( static_cast < char > ( command [ index ] ) ) ;
index + + ;
}
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
if ( arg ! = " " ) {
args . push_back ( arg ) ;
}
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
break ;
}
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
//Game::logger->Log("SlashCommandHandler", "Received chat command \"%s\"", GeneralUtils::UTF16ToWTF8(command).c_str());
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
User * user = UserManager : : Instance ( ) - > GetUser ( sysAddr ) ;
if ( ( chatCommand = = " setgmlevel " | | chatCommand = = " makegm " | | chatCommand = = " gmlevel " ) & & user - > GetMaxGMLevel ( ) > GAME_MASTER_LEVEL_CIVILIAN ) {
if ( args . size ( ) ! = 1 ) return ;
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
uint32_t level ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , level ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid gm level. " ) ;
return ;
}
# ifndef DEVELOPER_SERVER
2022-07-28 13:39:57 +00:00
if ( user - > GetMaxGMLevel ( ) = = GAME_MASTER_LEVEL_JUNIOR_DEVELOPER ) {
2021-12-05 17:54:36 +00:00
level = GAME_MASTER_LEVEL_CIVILIAN ;
}
# endif
2022-07-28 13:39:57 +00:00
if ( level > user - > GetMaxGMLevel ( ) ) {
2021-12-05 17:54:36 +00:00
level = user - > GetMaxGMLevel ( ) ;
}
2022-07-28 13:39:57 +00:00
if ( level = = entity - > GetGMLevel ( ) ) return ;
bool success = user - > GetMaxGMLevel ( ) > = level ;
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
if ( success ) {
2022-04-12 19:06:03 +00:00
2022-07-28 13:39:57 +00:00
if ( entity - > GetGMLevel ( ) > GAME_MASTER_LEVEL_CIVILIAN & & level = = GAME_MASTER_LEVEL_CIVILIAN ) {
2021-12-05 17:54:36 +00:00
GameMessages : : SendToggleGMInvis ( entity - > GetObjectID ( ) , false , UNASSIGNED_SYSTEM_ADDRESS ) ;
2022-07-28 13:39:57 +00:00
} else if ( entity - > GetGMLevel ( ) = = GAME_MASTER_LEVEL_CIVILIAN & & level > GAME_MASTER_LEVEL_CIVILIAN ) {
2021-12-05 17:54:36 +00:00
GameMessages : : SendToggleGMInvis ( entity - > GetObjectID ( ) , true , UNASSIGNED_SYSTEM_ADDRESS ) ;
}
2022-04-12 23:30:46 +00:00
WorldPackets : : SendGMLevelChange ( sysAddr , success , user - > GetMaxGMLevel ( ) , entity - > GetGMLevel ( ) , level ) ;
GameMessages : : SendChatModeUpdate ( entity - > GetObjectID ( ) , level ) ;
entity - > SetGMLevel ( level ) ;
2022-07-25 02:26:51 +00:00
Game : : logger - > Log ( " SlashCommandHandler " , " User %s (%i) has changed their GM level to %i for charID %llu " , user - > GetUsername ( ) . c_str ( ) , user - > GetAccountID ( ) , level , entity - > GetObjectID ( ) ) ;
2022-04-12 23:30:46 +00:00
}
}
2021-12-05 17:54:36 +00:00
# ifndef DEVELOPER_SERVER
2022-07-28 13:39:57 +00:00
if ( ( entity - > GetGMLevel ( ) > user - > GetMaxGMLevel ( ) ) | | ( entity - > GetGMLevel ( ) > GAME_MASTER_LEVEL_CIVILIAN & & user - > GetMaxGMLevel ( ) = = GAME_MASTER_LEVEL_JUNIOR_DEVELOPER ) ) {
2021-12-05 17:54:36 +00:00
WorldPackets : : SendGMLevelChange ( sysAddr , true , user - > GetMaxGMLevel ( ) , entity - > GetGMLevel ( ) , GAME_MASTER_LEVEL_CIVILIAN ) ;
GameMessages : : SendChatModeUpdate ( entity - > GetObjectID ( ) , GAME_MASTER_LEVEL_CIVILIAN ) ;
entity - > SetGMLevel ( GAME_MASTER_LEVEL_CIVILIAN ) ;
GameMessages : : SendToggleGMInvis ( entity - > GetObjectID ( ) , false , UNASSIGNED_SYSTEM_ADDRESS ) ;
ChatPackets : : SendSystemMessage ( sysAddr , u " Your game master level has been changed, you may not be able to use all commands. " ) ;
}
# endif
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//HANDLE ALL NON GM SLASH COMMANDS RIGHT HERE!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if ( chatCommand = = " pvp " ) {
auto * character = entity - > GetComponent < CharacterComponent > ( ) ;
if ( character = = nullptr ) {
2022-07-25 02:26:51 +00:00
Game : : logger - > Log ( " SlashCommandHandler " , " Failed to find character component! " ) ;
2021-12-05 17:54:36 +00:00
return ;
}
character - > SetPvpEnabled ( ! character - > GetPvpEnabled ( ) ) ;
EntityManager : : Instance ( ) - > SerializeEntity ( entity ) ;
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
std : : stringstream message ;
message < < character - > GetName ( ) < < " changed their PVP flag to " < < std : : to_string ( character - > GetPvpEnabled ( ) ) < < " ! " ;
2022-01-06 02:52:33 +00:00
2022-08-02 13:56:20 +00:00
ChatPackets : : SendSystemMessage ( UNASSIGNED_SYSTEM_ADDRESS , GeneralUtils : : UTF8ToUTF16 ( message . str ( ) ) , true ) ;
2021-12-05 17:54:36 +00:00
return ;
}
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " who " ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage (
sysAddr ,
u " Players in this instance: ( " + GeneralUtils : : to_u16string ( Player : : GetAllPlayers ( ) . size ( ) ) + u " ) "
) ;
2022-07-28 13:39:57 +00:00
for ( auto * player : Player : : GetAllPlayers ( ) ) {
2021-12-05 17:54:36 +00:00
const auto & name = player - > GetCharacter ( ) - > GetName ( ) ;
ChatPackets : : SendSystemMessage (
sysAddr ,
2022-08-02 13:56:20 +00:00
GeneralUtils : : UTF8ToUTF16 ( player = = entity ? name + " (you) " : name )
2021-12-05 17:54:36 +00:00
) ;
}
}
if ( chatCommand = = " ping " ) {
2022-07-28 13:39:57 +00:00
if ( ! args . empty ( ) & & args [ 0 ] = = " -l " ) {
2021-12-05 17:54:36 +00:00
std : : stringstream message ;
message < < " Your latest ping: " < < std : : to_string ( Game : : server - > GetLatestPing ( sysAddr ) ) < < " ms " ;
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , GeneralUtils : : ASCIIToUTF16 ( message . str ( ) ) ) ;
2022-07-28 13:39:57 +00:00
} else {
2021-12-05 17:54:36 +00:00
std : : stringstream message ;
message < < " Your average ping: " < < std : : to_string ( Game : : server - > GetPing ( sysAddr ) ) < < " ms " ;
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , GeneralUtils : : ASCIIToUTF16 ( message . str ( ) ) ) ;
}
return ;
}
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " fix-stats " ) {
2021-12-05 17:54:36 +00:00
// Reset skill component and buff component
auto * skillComponent = entity - > GetComponent < SkillComponent > ( ) ;
auto * buffComponent = entity - > GetComponent < BuffComponent > ( ) ;
auto * destroyableComponent = entity - > GetComponent < DestroyableComponent > ( ) ;
// If any of the components are nullptr, return
2022-07-28 13:39:57 +00:00
if ( skillComponent = = nullptr | | buffComponent = = nullptr | | destroyableComponent = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
// Reset skill component
skillComponent - > Reset ( ) ;
// Reset buff component
buffComponent - > Reset ( ) ;
// Fix the destroyable component
destroyableComponent - > FixStats ( ) ;
}
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " credits " | | chatCommand = = " info " ) {
2022-11-27 11:59:59 +00:00
const auto & customText = chatCommand = = " credits " ? VanityUtilities : : ParseMarkdown ( ( BinaryPathFinder : : GetBinaryDir ( ) / " vanity/CREDITS.md " ) . string ( ) ) : VanityUtilities : : ParseMarkdown ( ( BinaryPathFinder : : GetBinaryDir ( ) / " vanity/INFO.md " ) . string ( ) ) ;
2021-12-05 17:54:36 +00:00
{
AMFArrayValue args ;
auto * state = new AMFStringValue ( ) ;
state - > SetStringValue ( " Story " ) ;
args . InsertValue ( " state " , state ) ;
GameMessages : : SendUIMessageServerToSingleClient ( entity , entity - > GetSystemAddress ( ) , " pushGameState " , & args ) ;
}
2022-07-28 13:39:57 +00:00
entity - > AddCallbackTimer ( 0.5f , [ customText , entity ] ( ) {
2021-12-05 17:54:36 +00:00
AMFArrayValue args ;
auto * text = new AMFStringValue ( ) ;
text - > SetStringValue ( customText ) ;
2022-07-22 05:26:09 +00:00
args . InsertValue ( " visible " , new AMFTrueValue ( ) ) ;
2021-12-05 17:54:36 +00:00
args . InsertValue ( " text " , text ) ;
2022-07-25 02:26:51 +00:00
Game : : logger - > Log ( " SlashCommandHandler " , " Sending %s " , customText . c_str ( ) ) ;
2021-12-05 17:54:36 +00:00
GameMessages : : SendUIMessageServerToSingleClient ( entity , entity - > GetSystemAddress ( ) , " ToggleStoryBox " , & args ) ;
2022-07-28 13:39:57 +00:00
} ) ;
2021-12-05 17:54:36 +00:00
return ;
}
2022-01-06 02:52:33 +00:00
if ( chatCommand = = " leave-zone " ) {
2021-12-05 17:54:36 +00:00
const auto currentZone = dZoneManager : : Instance ( ) - > GetZone ( ) - > GetZoneID ( ) . GetMapID ( ) ;
2022-02-04 06:32:45 +00:00
auto newZone = 0 ;
if ( currentZone % 100 = = 0 ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " You are not in an instanced zone. " ) ;
return ;
2022-02-04 06:32:45 +00:00
} else {
newZone = ( currentZone / 100 ) * 100 ;
2021-12-05 17:54:36 +00:00
}
2022-02-04 06:32:45 +00:00
// If new zone would be inaccessible, then default to Avant Gardens.
if ( ! CheckIfAccessibleZone ( newZone ) ) newZone = 1100 ;
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Leaving zone... " ) ;
const auto objid = entity - > GetObjectID ( ) ;
2022-07-28 13:39:57 +00:00
ZoneInstanceManager : : Instance ( ) - > RequestZoneTransfer ( Game : : server , newZone , 0 , false , [ objid ] ( bool mythranShift , uint32_t zoneID , uint32_t zoneInstance , uint32_t zoneClone , std : : string serverIP , uint16_t serverPort ) {
auto * entity = EntityManager : : Instance ( ) - > GetEntity ( objid ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( entity = = nullptr ) {
return ;
}
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
const auto sysAddr = entity - > GetSystemAddress ( ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
Game : : logger - > Log ( " UserManager " , " Transferring %s to Zone %i (Instance %i | Clone %i | Mythran Shift: %s) with IP %s and Port %i " , entity - > GetCharacter ( ) - > GetName ( ) . c_str ( ) , zoneID , zoneInstance , zoneClone , mythranShift = = true ? " true " : " false " , serverIP . c_str ( ) , serverPort ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( entity - > GetCharacter ( ) ) {
entity - > GetCharacter ( ) - > SetZoneID ( zoneID ) ;
entity - > GetCharacter ( ) - > SetZoneInstance ( zoneInstance ) ;
entity - > GetCharacter ( ) - > SetZoneClone ( zoneClone ) ;
}
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
entity - > GetCharacter ( ) - > SaveXMLToDatabase ( ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
WorldPackets : : SendTransferToWorld ( sysAddr , serverIP , serverPort , mythranShift ) ;
2021-12-05 17:54:36 +00:00
} ) ;
}
2022-01-06 02:52:33 +00:00
if ( chatCommand = = " join " & & ! args . empty ( ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Requesting private map... " ) ;
const auto & password = args [ 0 ] ;
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
ZoneInstanceManager : : Instance ( ) - > RequestPrivateZone ( Game : : server , false , password , [ = ] ( bool mythranShift , uint32_t zoneID , uint32_t zoneInstance , uint32_t zoneClone , std : : string serverIP , uint16_t serverPort ) {
Game : : logger - > Log ( " UserManager " , " Transferring %s to Zone %i (Instance %i | Clone %i | Mythran Shift: %s) with IP %s and Port %i " , sysAddr . ToString ( ) , zoneID , zoneInstance , zoneClone , mythranShift = = true ? " true " : " false " , serverIP . c_str ( ) , serverPort ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( entity - > GetCharacter ( ) ) {
entity - > GetCharacter ( ) - > SetZoneID ( zoneID ) ;
entity - > GetCharacter ( ) - > SetZoneInstance ( zoneInstance ) ;
entity - > GetCharacter ( ) - > SetZoneClone ( zoneClone ) ;
}
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
entity - > GetCharacter ( ) - > SaveXMLToDatabase ( ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
WorldPackets : : SendTransferToWorld ( sysAddr , serverIP , serverPort , mythranShift ) ;
2021-12-05 17:54:36 +00:00
} ) ;
}
2022-04-12 23:30:46 +00:00
if ( user - > GetMaxGMLevel ( ) = = 0 | | entity - > GetGMLevel ( ) > = 0 ) {
2021-12-05 17:54:36 +00:00
if ( chatCommand = = " die " ) {
entity - > Smash ( entity - > GetObjectID ( ) ) ;
}
if ( chatCommand = = " resurrect " ) {
2022-01-01 10:10:12 +00:00
ScriptedActivityComponent * scriptedActivityComponent = dZoneManager : : Instance ( ) - > GetZoneControlObject ( ) - > GetComponent < ScriptedActivityComponent > ( ) ;
2022-01-06 02:52:33 +00:00
2022-01-01 10:10:12 +00:00
if ( scriptedActivityComponent ) { // check if user is in activity world and if so, they can't resurrect
ChatPackets : : SendSystemMessage ( sysAddr , u " You cannot resurrect in an activity world. " ) ;
return ;
}
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
GameMessages : : SendResurrect ( entity ) ;
}
if ( chatCommand = = " requestmailcount " ) {
Mail : : HandleNotificationRequest ( entity - > GetSystemAddress ( ) , entity - > GetObjectID ( ) ) ;
}
if ( chatCommand = = " instanceinfo " ) {
const auto zoneId = dZoneManager : : Instance ( ) - > GetZone ( ) - > GetZoneID ( ) ;
ChatPackets : : SendSystemMessage ( sysAddr , u " Map: " + ( GeneralUtils : : to_u16string ( zoneId . GetMapID ( ) ) ) + u " \n Clone: " + ( GeneralUtils : : to_u16string ( zoneId . GetCloneID ( ) ) ) + u " \n Instance: " + ( GeneralUtils : : to_u16string ( zoneId . GetInstanceID ( ) ) ) ) ;
}
if ( entity - > GetGMLevel ( ) = = 0 ) return ;
2022-04-12 23:30:46 +00:00
}
2021-12-05 17:54:36 +00:00
// Log command to database
2022-04-12 23:30:46 +00:00
auto stmt = Database : : CreatePreppedStmt ( " INSERT INTO command_log (character_id, command) VALUES (?, ?); " ) ;
stmt - > setInt ( 1 , entity - > GetCharacter ( ) - > GetID ( ) ) ;
2021-12-05 17:54:36 +00:00
stmt - > setString ( 2 , GeneralUtils : : UTF16ToWTF8 ( command ) . c_str ( ) ) ;
2022-07-28 13:39:57 +00:00
stmt - > execute ( ) ;
delete stmt ;
2022-01-06 02:52:33 +00:00
2021-12-15 02:51:41 +00:00
if ( chatCommand = = " setminifig " & & args . size ( ) = = 2 & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_FORUM_MODERATOR ) { // could break characters so only allow if GM > 0
2021-12-11 02:02:02 +00:00
int32_t minifigItemId ;
if ( ! GeneralUtils : : TryParse ( args [ 1 ] , minifigItemId ) ) {
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid Minifig Item Id ID. " ) ;
return ;
}
EntityManager : : Instance ( ) - > DestructEntity ( entity , sysAddr ) ;
auto * charComp = entity - > GetComponent < CharacterComponent > ( ) ;
std : : string lowerName = args [ 0 ] ;
if ( lowerName . empty ( ) ) return ;
std : : transform ( lowerName . begin ( ) , lowerName . end ( ) , lowerName . begin ( ) , : : tolower ) ;
if ( lowerName = = " eyebrows " ) {
charComp - > m_Character - > SetEyebrows ( minifigItemId ) ;
} else if ( lowerName = = " eyes " ) {
charComp - > m_Character - > SetEyes ( minifigItemId ) ;
} else if ( lowerName = = " haircolor " ) {
charComp - > m_Character - > SetHairColor ( minifigItemId ) ;
} else if ( lowerName = = " hairstyle " ) {
charComp - > m_Character - > SetHairStyle ( minifigItemId ) ;
} else if ( lowerName = = " pants " ) {
charComp - > m_Character - > SetPantsColor ( minifigItemId ) ;
} else if ( lowerName = = " lefthand " ) {
charComp - > m_Character - > SetLeftHand ( minifigItemId ) ;
} else if ( lowerName = = " mouth " ) {
charComp - > m_Character - > SetMouth ( minifigItemId ) ;
} else if ( lowerName = = " righthand " ) {
charComp - > m_Character - > SetRightHand ( minifigItemId ) ;
2021-12-15 02:55:05 +00:00
} else if ( lowerName = = " shirtcolor " ) {
2021-12-11 02:02:02 +00:00
charComp - > m_Character - > SetShirtColor ( minifigItemId ) ;
} else if ( lowerName = = " hands " ) {
charComp - > m_Character - > SetLeftHand ( minifigItemId ) ;
charComp - > m_Character - > SetRightHand ( minifigItemId ) ;
} else {
EntityManager : : Instance ( ) - > ConstructEntity ( entity ) ;
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid Minifig item to change, try one of the following: Eyebrows, Eyes, HairColor, HairStyle, Pants, LeftHand, Mouth, RightHand, Shirt, Hands " ) ;
return ;
}
2022-01-06 02:52:33 +00:00
2021-12-11 02:02:02 +00:00
EntityManager : : Instance ( ) - > ConstructEntity ( entity ) ;
ChatPackets : : SendSystemMessage ( sysAddr , GeneralUtils : : ASCIIToUTF16 ( lowerName ) + u " set to " + ( GeneralUtils : : to_u16string ( minifigItemId ) ) ) ;
GameMessages : : SendToggleGMInvis ( entity - > GetObjectID ( ) , false , UNASSIGNED_SYSTEM_ADDRESS ) ; // need to retoggle because it gets reenabled on creation of new character
}
2022-03-29 20:06:28 +00:00
if ( ( chatCommand = = " playanimation " | | chatCommand = = " playanim " ) & & args . size ( ) = = 1 & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
std : : u16string anim = GeneralUtils : : ASCIIToUTF16 ( args [ 0 ] , args [ 0 ] . size ( ) ) ;
GameMessages : : SendPlayAnimation ( entity , anim ) ;
2022-09-02 18:49:19 +00:00
auto * possessorComponent = entity - > GetComponent < PossessorComponent > ( ) ;
if ( possessorComponent ) {
auto * possessedComponent = EntityManager : : Instance ( ) - > GetEntity ( possessorComponent - > GetPossessable ( ) ) ;
if ( possessedComponent ) GameMessages : : SendPlayAnimation ( possessedComponent , anim ) ;
}
2022-03-29 20:06:28 +00:00
}
2021-12-11 02:02:02 +00:00
2021-12-05 17:54:36 +00:00
if ( chatCommand = = " list-spawns " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
for ( const auto & pair : EntityManager : : Instance ( ) - > GetSpawnPointEntities ( ) ) {
ChatPackets : : SendSystemMessage ( sysAddr , GeneralUtils : : ASCIIToUTF16 ( pair . first ) ) ;
}
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Current: " + GeneralUtils : : ASCIIToUTF16 ( entity - > GetCharacter ( ) - > GetTargetScene ( ) ) ) ;
return ;
}
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
if ( chatCommand = = " unlock-emote " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
int32_t emoteID ;
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , emoteID ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid emote ID. " ) ;
return ;
}
entity - > GetCharacter ( ) - > UnlockEmote ( emoteID ) ;
}
2021-12-11 02:02:02 +00:00
if ( chatCommand = = " force-save " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
entity - > GetCharacter ( ) - > SaveXMLToDatabase ( ) ;
}
2021-12-05 17:54:36 +00:00
if ( chatCommand = = " kill " & & args . size ( ) = = 1 & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
ChatPackets : : SendSystemMessage ( sysAddr , u " Brutally murdering that player, if online on this server. " ) ;
auto * user = UserManager : : Instance ( ) - > GetUser ( args [ 0 ] ) ;
if ( user ) {
auto * player = EntityManager : : Instance ( ) - > GetEntity ( user - > GetLoggedInChar ( ) ) ;
player - > Smash ( entity - > GetObjectID ( ) ) ;
ChatPackets : : SendSystemMessage ( sysAddr , u " It has been done, do you feel good about yourself now? " ) ;
return ;
}
ChatPackets : : SendSystemMessage ( sysAddr , u " They were saved from your carnage. " ) ;
return ;
}
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " speedboost " & & args . size ( ) = = 1 & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
2021-12-05 17:54:36 +00:00
float boost ;
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , boost ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid boost. " ) ;
return ;
}
auto * controllablePhysicsComponent = entity - > GetComponent < ControllablePhysicsComponent > ( ) ;
2022-09-02 18:49:19 +00:00
if ( ! controllablePhysicsComponent ) return ;
2021-12-05 17:54:36 +00:00
controllablePhysicsComponent - > SetSpeedMultiplier ( boost ) ;
2022-09-02 18:49:19 +00:00
// speedboost possesables
auto possessor = entity - > GetComponent < PossessorComponent > ( ) ;
if ( possessor ) {
auto possessedID = possessor - > GetPossessable ( ) ;
if ( possessedID ! = LWOOBJID_EMPTY ) {
auto possessable = EntityManager : : Instance ( ) - > GetEntity ( possessedID ) ;
if ( possessable ) {
auto * possessControllablePhysicsComponent = possessable - > GetComponent < ControllablePhysicsComponent > ( ) ;
if ( possessControllablePhysicsComponent ) {
possessControllablePhysicsComponent - > SetSpeedMultiplier ( boost ) ;
}
}
}
}
2021-12-05 17:54:36 +00:00
EntityManager : : Instance ( ) - > SerializeEntity ( entity ) ;
}
if ( chatCommand = = " freecam " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
const auto state = ! entity - > GetVar < bool > ( u " freecam " ) ;
entity - > SetVar < bool > ( u " freecam " , state ) ;
GameMessages : : SendSetPlayerControlScheme ( entity , static_cast < eControlSceme > ( state ? 9 : 1 ) ) ;
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Toggled freecam. " ) ;
return ;
}
if ( chatCommand = = " setcontrolscheme " & & args . size ( ) = = 1 & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
uint32_t scheme ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , scheme ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid control scheme. " ) ;
return ;
}
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
GameMessages : : SendSetPlayerControlScheme ( entity , static_cast < eControlSceme > ( scheme ) ) ;
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Switched control scheme. " ) ;
return ;
}
if ( chatCommand = = " approveproperty " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_LEAD_MODERATOR ) {
2022-07-28 13:39:57 +00:00
if ( PropertyManagementComponent : : Instance ( ) ! = nullptr ) {
2021-12-05 17:54:36 +00:00
PropertyManagementComponent : : Instance ( ) - > UpdateApprovedStatus ( true ) ;
}
return ;
}
if ( chatCommand = = " setuistate " & & args . size ( ) = = 1 & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
AMFStringValue * value = new AMFStringValue ( ) ;
value - > SetStringValue ( args [ 0 ] ) ;
AMFArrayValue args ;
args . InsertValue ( " state " , value ) ;
GameMessages : : SendUIMessageServerToSingleClient ( entity , sysAddr , " pushGameState " , & args ) ;
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Switched UI state. " ) ;
return ;
}
if ( chatCommand = = " toggle " & & args . size ( ) = = 1 & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
AMFTrueValue * value = new AMFTrueValue ( ) ;
AMFArrayValue amfArgs ;
amfArgs . InsertValue ( " visible " , value ) ;
GameMessages : : SendUIMessageServerToSingleClient ( entity , sysAddr , args [ 0 ] , & amfArgs ) ;
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Toggled UI state. " ) ;
return ;
}
if ( ( chatCommand = = " setinventorysize " | | chatCommand = = " setinvsize " ) & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
if ( args . size ( ) ! = 1 ) return ;
uint32_t size ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , size ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid size. " ) ;
return ;
}
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
InventoryComponent * inventory = static_cast < InventoryComponent * > ( entity - > GetComponent ( COMPONENT_TYPE_INVENTORY ) ) ;
2022-07-28 13:39:57 +00:00
if ( inventory ) {
2021-12-05 17:54:36 +00:00
auto * items = inventory - > GetInventory ( ITEMS ) ;
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
items - > SetSize ( size ) ;
}
return ;
}
if ( chatCommand = = " runmacro " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
if ( args . size ( ) ! = 1 ) return ;
2022-01-04 05:40:07 +00:00
// Only process if input does not contain separator charaters
if ( args [ 0 ] . find ( " / " ) ! = std : : string : : npos ) return ;
if ( args [ 0 ] . find ( " \\ " ) ! = std : : string : : npos ) return ;
2022-11-01 18:21:26 +00:00
auto buf = Game : : assetManager - > GetFileAsBuffer ( ( " macros/ " + args [ 0 ] + " .scm " ) . c_str ( ) ) ;
2022-11-10 18:59:31 +00:00
if ( ! buf . m_Success ) {
ChatPackets : : SendSystemMessage ( sysAddr , u " Unknown macro! Is the filename right? " ) ;
return ;
}
2022-11-01 18:21:26 +00:00
std : : istream infile ( & buf ) ;
2021-12-05 17:54:36 +00:00
if ( infile . good ( ) ) {
std : : string line ;
while ( std : : getline ( infile , line ) ) {
SlashCommandHandler : : HandleChatCommand ( GeneralUtils : : ASCIIToUTF16 ( line ) , entity , sysAddr ) ;
}
2022-07-28 13:39:57 +00:00
} else {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Unknown macro! Is the filename right? " ) ;
}
2022-01-06 02:52:33 +00:00
2022-11-01 18:21:26 +00:00
buf . close ( ) ;
2021-12-05 17:54:36 +00:00
return ;
}
if ( chatCommand = = " addmission " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
if ( args . size ( ) = = 0 ) return ;
uint32_t missionID ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , missionID ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid mission id. " ) ;
return ;
}
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
auto comp = static_cast < MissionComponent * > ( entity - > GetComponent ( COMPONENT_TYPE_MISSION ) ) ;
if ( comp ) comp - > AcceptMission ( missionID , true ) ;
return ;
}
if ( chatCommand = = " completemission " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
if ( args . size ( ) = = 0 ) return ;
uint32_t missionID ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , missionID ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid mission id. " ) ;
return ;
}
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
auto comp = static_cast < MissionComponent * > ( entity - > GetComponent ( COMPONENT_TYPE_MISSION ) ) ;
if ( comp ) comp - > CompleteMission ( missionID , true ) ;
return ;
}
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " setflag " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER & & args . size ( ) = = 1 ) {
2021-12-05 17:54:36 +00:00
uint32_t flagId ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , flagId ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid flag id. " ) ;
return ;
}
2022-04-12 23:30:46 +00:00
entity - > GetCharacter ( ) - > SetPlayerFlag ( flagId , true ) ;
2021-12-05 17:54:36 +00:00
}
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " setflag " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER & & args . size ( ) = = 2 ) {
2022-01-24 13:57:50 +00:00
uint32_t flagId ;
std : : string onOffFlag = args [ 0 ] ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 1 ] , flagId ) ) {
2022-01-24 13:57:50 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid flag id. " ) ;
return ;
}
if ( onOffFlag ! = " off " & & onOffFlag ! = " on " ) {
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid flag type. " ) ;
return ;
}
2022-04-12 23:30:46 +00:00
entity - > GetCharacter ( ) - > SetPlayerFlag ( flagId , onOffFlag = = " on " ) ;
2022-01-24 13:57:50 +00:00
}
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " clearflag " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER & & args . size ( ) = = 1 ) {
2021-12-05 17:54:36 +00:00
uint32_t flagId ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , flagId ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid flag id. " ) ;
return ;
}
2022-04-12 23:30:46 +00:00
entity - > GetCharacter ( ) - > SetPlayerFlag ( flagId , false ) ;
2021-12-05 17:54:36 +00:00
}
if ( chatCommand = = " resetmission " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
if ( args . size ( ) = = 0 ) return ;
uint32_t missionID ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , missionID ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid mission id. " ) ;
return ;
}
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
auto * comp = static_cast < MissionComponent * > ( entity - > GetComponent ( COMPONENT_TYPE_MISSION ) ) ;
if ( comp = = nullptr ) {
return ;
}
auto * mission = comp - > GetMission ( missionID ) ;
if ( mission = = nullptr ) {
return ;
}
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
mission - > SetMissionState ( MissionState : : MISSION_STATE_ACTIVE ) ;
return ;
}
if ( chatCommand = = " playeffect " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER & & args . size ( ) > = 3 ) {
int32_t effectID = 0 ;
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , effectID ) ) {
return ;
}
2022-08-02 13:56:20 +00:00
// FIXME: use fallible ASCIIToUTF16 conversion, because non-ascii isn't valid anyway
2021-12-05 17:54:36 +00:00
GameMessages : : SendPlayFXEffect ( entity - > GetObjectID ( ) , effectID , GeneralUtils : : ASCIIToUTF16 ( args [ 1 ] ) , args [ 2 ] ) ;
}
if ( chatCommand = = " stopeffect " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER & & args . size ( ) > = 1 ) {
GameMessages : : SendStopFXEffect ( entity , true , args [ 0 ] ) ;
}
if ( chatCommand = = " setanntitle " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
if ( args . size ( ) < 0 ) return ;
std : : stringstream ss ;
for ( auto string : args )
ss < < string < < " " ;
entity - > GetCharacter ( ) - > SetAnnouncementTitle ( ss . str ( ) ) ;
return ;
}
if ( chatCommand = = " setannmsg " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
if ( args . size ( ) < 0 ) return ;
std : : stringstream ss ;
for ( auto string : args )
ss < < string < < " " ;
entity - > GetCharacter ( ) - > SetAnnouncementMessage ( ss . str ( ) ) ;
return ;
}
if ( chatCommand = = " announce " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
if ( entity - > GetCharacter ( ) - > GetAnnouncementTitle ( ) . size ( ) = = 0 | | entity - > GetCharacter ( ) - > GetAnnouncementMessage ( ) . size ( ) = = 0 ) {
ChatPackets : : SendSystemMessage ( sysAddr , u " Use /setanntitle <title> & /setannmsg <msg> first! " ) ;
return ;
}
SendAnnouncement ( entity - > GetCharacter ( ) - > GetAnnouncementTitle ( ) , entity - > GetCharacter ( ) - > GetAnnouncementMessage ( ) ) ;
return ;
}
if ( chatCommand = = " shutdownuniverse " & & entity - > GetGMLevel ( ) = = GAME_MASTER_LEVEL_OPERATOR ) {
//Tell the master server that we're going to be shutting down whole "universe":
CBITSTREAM ;
PacketUtils : : WriteHeader ( bitStream , MASTER , MSG_MASTER_SHUTDOWN_UNIVERSE ) ;
Game : : server - > SendToMaster ( & bitStream ) ;
ChatPackets : : SendSystemMessage ( sysAddr , u " Sent universe shutdown notification to master. " ) ;
//Tell chat to send an announcement to all servers
SendAnnouncement ( " Servers Closing Soon! " , " DLU servers will close for maintenance in 10 minutes from now. " ) ;
return ;
}
if ( chatCommand = = " getnavmeshheight " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
auto control = static_cast < ControllablePhysicsComponent * > ( entity - > GetComponent ( COMPONENT_TYPE_CONTROLLABLE_PHYSICS ) ) ;
if ( ! control ) return ;
2022-08-02 05:30:19 +00:00
float y = dpWorld : : Instance ( ) . GetNavMesh ( ) - > GetHeightAtPoint ( control - > GetPosition ( ) ) ;
2021-12-05 17:54:36 +00:00
std : : u16string msg = u " Navmesh height: " + ( GeneralUtils : : to_u16string ( y ) ) ;
ChatPackets : : SendSystemMessage ( sysAddr , msg ) ;
}
2022-04-12 23:30:46 +00:00
if ( chatCommand = = " gmadditem " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
if ( args . size ( ) = = 1 ) {
2021-12-05 17:54:36 +00:00
uint32_t itemLOT ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , itemLOT ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid item LOT. " ) ;
return ;
}
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
InventoryComponent * inventory = static_cast < InventoryComponent * > ( entity - > GetComponent ( COMPONENT_TYPE_INVENTORY ) ) ;
2021-12-05 17:54:36 +00:00
2022-04-24 03:35:34 +00:00
inventory - > AddItem ( itemLOT , 1 , eLootSourceType : : LOOT_SOURCE_MODERATION ) ;
2022-07-28 13:39:57 +00:00
} else if ( args . size ( ) = = 2 ) {
2021-12-05 17:54:36 +00:00
uint32_t itemLOT ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , itemLOT ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid item LOT. " ) ;
return ;
}
uint32_t count ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 1 ] , count ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid item count. " ) ;
return ;
}
InventoryComponent * inventory = static_cast < InventoryComponent * > ( entity - > GetComponent ( COMPONENT_TYPE_INVENTORY ) ) ;
2022-04-24 03:35:34 +00:00
inventory - > AddItem ( itemLOT , count , eLootSourceType : : LOOT_SOURCE_MODERATION ) ;
2022-07-28 13:39:57 +00:00
} else {
2022-04-12 23:30:46 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Correct usage: /gmadditem <lot> " ) ;
}
}
2021-12-05 17:54:36 +00:00
if ( chatCommand = = " mailitem " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_MODERATOR & & args . size ( ) > = 2 ) {
const auto & playerName = args [ 0 ] ;
sql : : PreparedStatement * stmt = Database : : CreatePreppedStmt ( " SELECT id from charinfo WHERE name=? LIMIT 1; " ) ;
stmt - > setString ( 1 , playerName ) ;
sql : : ResultSet * res = stmt - > executeQuery ( ) ;
uint32_t receiverID = 0 ;
if ( res - > rowsCount ( ) > 0 ) {
while ( res - > next ( ) ) receiverID = res - > getUInt ( 1 ) ;
}
delete stmt ;
delete res ;
2022-07-28 13:39:57 +00:00
if ( receiverID = = 0 ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Failed to find that player " ) ;
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
return ;
}
uint32_t lot ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 1 ] , lot ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid item lot. " ) ;
return ;
}
uint64_t currentTime = time ( NULL ) ;
sql : : PreparedStatement * ins = Database : : CreatePreppedStmt ( " INSERT INTO `mail`(`sender_id`, `sender_name`, `receiver_id`, `receiver_name`, `time_sent`, `subject`, `body`, `attachment_id`, `attachment_lot`, `attachment_subkey`, `attachment_count`, `was_read`) VALUES (?,?,?,?,?,?,?,?,?,?,?,0) " ) ;
ins - > setUInt ( 1 , entity - > GetObjectID ( ) ) ;
ins - > setString ( 2 , " Darkflame Universe " ) ;
ins - > setUInt ( 3 , receiverID ) ;
ins - > setString ( 4 , playerName ) ;
ins - > setUInt64 ( 5 , currentTime ) ;
ins - > setString ( 6 , " Lost item " ) ;
ins - > setString ( 7 , " This is a replacement item for one you lost. " ) ;
ins - > setUInt ( 8 , 0 ) ;
ins - > setInt ( 9 , lot ) ;
ins - > setInt ( 10 , 0 ) ;
ins - > setInt ( 11 , 1 ) ;
ins - > execute ( ) ;
delete ins ;
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Mail sent " ) ;
return ;
}
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " setname " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
2021-12-05 17:54:36 +00:00
std : : string name = " " ;
2022-07-28 13:39:57 +00:00
for ( const auto & arg : args ) {
2021-12-05 17:54:36 +00:00
name + = arg + " " ;
}
2022-08-02 13:56:20 +00:00
GameMessages : : SendSetName ( entity - > GetObjectID ( ) , GeneralUtils : : UTF8ToUTF16 ( name ) , UNASSIGNED_SYSTEM_ADDRESS ) ;
2021-12-05 17:54:36 +00:00
}
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " title " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
2021-12-05 17:54:36 +00:00
std : : string name = entity - > GetCharacter ( ) - > GetName ( ) + " - " ;
2022-07-28 13:39:57 +00:00
for ( const auto & arg : args ) {
2021-12-05 17:54:36 +00:00
name + = arg + " " ;
}
2022-08-02 13:56:20 +00:00
GameMessages : : SendSetName ( entity - > GetObjectID ( ) , GeneralUtils : : UTF8ToUTF16 ( name ) , UNASSIGNED_SYSTEM_ADDRESS ) ;
2021-12-05 17:54:36 +00:00
}
2022-04-12 23:30:46 +00:00
if ( ( chatCommand = = " teleport " | | chatCommand = = " tele " ) & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_JUNIOR_MODERATOR ) {
2022-07-28 13:39:57 +00:00
NiPoint3 pos { } ;
2022-04-12 23:30:46 +00:00
if ( args . size ( ) = = 3 ) {
2021-12-05 17:54:36 +00:00
float x , y , z ;
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , x ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid x. " ) ;
return ;
}
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 1 ] , y ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid y. " ) ;
return ;
}
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 2 ] , z ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid z. " ) ;
return ;
}
2022-07-28 13:39:57 +00:00
pos . SetX ( x ) ;
pos . SetY ( y ) ;
pos . SetZ ( z ) ;
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
Game : : logger - > Log ( " SlashCommandHandler " , " Teleporting objectID: %llu to %f, %f, %f " , entity - > GetObjectID ( ) , pos . x , pos . y , pos . z ) ;
GameMessages : : SendTeleport ( entity - > GetObjectID ( ) , pos , NiQuaternion ( ) , sysAddr ) ;
} else if ( args . size ( ) = = 2 ) {
2022-04-12 19:06:03 +00:00
2021-12-05 17:54:36 +00:00
float x , z ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , x ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid x. " ) ;
return ;
}
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 1 ] , z ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid z. " ) ;
return ;
}
pos . SetX ( x ) ;
pos . SetY ( 0.0f ) ;
pos . SetZ ( z ) ;
2022-07-28 13:39:57 +00:00
Game : : logger - > Log ( " SlashCommandHandler " , " Teleporting objectID: %llu to X: %f, Z: %f " , entity - > GetObjectID ( ) , pos . x , pos . z ) ;
GameMessages : : SendTeleport ( entity - > GetObjectID ( ) , pos , NiQuaternion ( ) , sysAddr ) ;
} else {
ChatPackets : : SendSystemMessage ( sysAddr , u " Correct usage: /teleport <x> (<y>) <z> - if no Y given, will teleport to the height of the terrain (or any physics object). " ) ;
}
2021-12-05 17:54:36 +00:00
2022-09-02 18:49:19 +00:00
auto * possessorComponent = entity - > GetComponent < PossessorComponent > ( ) ;
if ( possessorComponent ) {
2021-12-05 17:54:36 +00:00
auto * possassableEntity = EntityManager : : Instance ( ) - > GetEntity ( possessorComponent - > GetPossessable ( ) ) ;
2022-07-28 13:39:57 +00:00
if ( possassableEntity ! = nullptr ) {
2021-12-05 17:54:36 +00:00
auto * vehiclePhysicsComponent = possassableEntity - > GetComponent < VehiclePhysicsComponent > ( ) ;
2022-09-02 18:49:19 +00:00
if ( vehiclePhysicsComponent ) {
2021-12-05 17:54:36 +00:00
vehiclePhysicsComponent - > SetPosition ( pos ) ;
EntityManager : : Instance ( ) - > SerializeEntity ( possassableEntity ) ;
2022-09-02 18:49:19 +00:00
} else GameMessages : : SendTeleport ( possassableEntity - > GetObjectID ( ) , pos , NiQuaternion ( ) , sysAddr ) ;
2021-12-05 17:54:36 +00:00
}
}
2022-04-12 23:30:46 +00:00
}
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " tpall " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
2021-12-05 17:54:36 +00:00
const auto pos = entity - > GetPosition ( ) ;
const auto characters = EntityManager : : Instance ( ) - > GetEntitiesByComponent ( COMPONENT_TYPE_CHARACTER ) ;
2022-07-28 13:39:57 +00:00
for ( auto * character : characters ) {
2021-12-05 17:54:36 +00:00
GameMessages : : SendTeleport ( character - > GetObjectID ( ) , pos , NiQuaternion ( ) , character - > GetSystemAddress ( ) ) ;
}
return ;
}
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " dismount " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
2022-09-02 18:49:19 +00:00
auto * possessorComponent = entity - > GetComponent < PossessorComponent > ( ) ;
if ( possessorComponent ) {
auto possessableId = possessorComponent - > GetPossessable ( ) ;
if ( possessableId ! = LWOOBJID_EMPTY ) {
auto * possessableEntity = EntityManager : : Instance ( ) - > GetEntity ( possessableId ) ;
if ( possessableEntity ) possessorComponent - > Dismount ( possessableEntity , true ) ;
2021-12-05 17:54:36 +00:00
}
}
}
2022-08-06 08:19:34 +00:00
if ( chatCommand = = " fly " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_JUNIOR_DEVELOPER ) {
auto * character = entity - > GetCharacter ( ) ;
if ( character ) {
bool isFlying = character - > GetIsFlying ( ) ;
if ( isFlying ) {
GameMessages : : SendSetJetPackMode ( entity , false ) ;
character - > SetIsFlying ( false ) ;
} else {
float speedScale = 1.0f ;
if ( args . size ( ) > = 1 ) {
float tempScaleStore ;
if ( GeneralUtils : : TryParse < float > ( args [ 0 ] , tempScaleStore ) ) {
speedScale = tempScaleStore ;
} else {
ChatPackets : : SendSystemMessage ( sysAddr , u " Failed to parse speed scale argument. " ) ;
}
}
float airSpeed = 20 * speedScale ;
float maxAirSpeed = 30 * speedScale ;
float verticalVelocity = 1.5 * speedScale ;
GameMessages : : SendSetJetPackMode ( entity , true , true , false , 167 , airSpeed , maxAirSpeed , verticalVelocity ) ;
character - > SetIsFlying ( true ) ;
}
}
}
2021-12-05 17:54:36 +00:00
//------- GM COMMANDS TO ACTUALLY MODERATE --------
if ( chatCommand = = " mute " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_JUNIOR_DEVELOPER ) {
if ( args . size ( ) > = 1 ) {
auto * player = Player : : GetPlayer ( args [ 0 ] ) ;
uint32_t accountId = 0 ;
LWOOBJID characterId = 0 ;
2022-07-28 13:39:57 +00:00
if ( player = = nullptr ) {
2021-12-05 17:54:36 +00:00
auto * accountQuery = Database : : CreatePreppedStmt ( " SELECT account_id, id FROM charinfo WHERE name=? LIMIT 1; " ) ;
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
accountQuery - > setString ( 1 , args [ 0 ] ) ;
auto result = accountQuery - > executeQuery ( ) ;
2022-07-28 13:39:57 +00:00
if ( result - > rowsCount ( ) > 0 ) {
2021-12-05 17:54:36 +00:00
while ( result - > next ( ) ) {
accountId = result - > getUInt ( 1 ) ;
characterId = result - > getUInt64 ( 2 ) ;
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
characterId = GeneralUtils : : SetBit ( characterId , OBJECT_BIT_CHARACTER ) ;
characterId = GeneralUtils : : SetBit ( characterId , OBJECT_BIT_PERSISTENT ) ;
}
}
delete accountQuery ;
delete result ;
2022-07-28 13:39:57 +00:00
if ( accountId = = 0 ) {
2022-08-02 13:56:20 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Count not find player of name: " + GeneralUtils : : UTF8ToUTF16 ( args [ 0 ] ) ) ;
2021-12-05 17:54:36 +00:00
return ;
}
2022-07-28 13:39:57 +00:00
} else {
2021-12-05 17:54:36 +00:00
accountId = player - > GetParentUser ( ) - > GetAccountID ( ) ;
characterId = player - > GetCharacter ( ) - > GetID ( ) ;
}
auto * userUpdate = Database : : CreatePreppedStmt ( " UPDATE accounts SET mute_expire = ? WHERE id = ?; " ) ;
time_t expire = 1 ; // Default to indefinate mute
2022-07-28 13:39:57 +00:00
if ( args . size ( ) > = 2 ) {
2021-12-05 17:54:36 +00:00
uint32_t days = 0 ;
uint32_t hours = 0 ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 1 ] , days ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid days. " ) ;
return ;
}
2022-07-28 13:39:57 +00:00
if ( args . size ( ) > = 3 ) {
if ( ! GeneralUtils : : TryParse ( args [ 2 ] , hours ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid hours. " ) ;
return ;
}
}
expire = time ( NULL ) ;
expire + = 24 * 60 * 60 * days ;
expire + = 60 * 60 * hours ;
}
userUpdate - > setUInt64 ( 1 , expire ) ;
userUpdate - > setInt ( 2 , accountId ) ;
userUpdate - > executeUpdate ( ) ;
delete userUpdate ;
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
char buffer [ 32 ] = " brought up for review. \0 " ;
2022-07-28 13:39:57 +00:00
if ( expire ! = 1 ) {
std : : tm * ptm = std : : localtime ( & expire ) ;
2021-12-05 17:54:36 +00:00
// Format: Mo, 15.06.2009 20:20:00
std : : strftime ( buffer , 32 , " %a, %d.%m.%Y %H:%M:%S " , ptm ) ;
}
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
const auto timeStr = GeneralUtils : : ASCIIToUTF16 ( std : : string ( buffer ) ) ;
2022-08-02 13:56:20 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Muted: " + GeneralUtils : : UTF8ToUTF16 ( args [ 0 ] ) + u " until " + timeStr ) ;
2021-12-05 17:54:36 +00:00
2022-01-06 02:52:33 +00:00
//Notify chat about it
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
PacketUtils : : WriteHeader ( bitStream , CHAT_INTERNAL , MSG_CHAT_INTERNAL_MUTE_UPDATE ) ;
bitStream . Write ( characterId ) ;
bitStream . Write ( expire ) ;
Game : : chatServer - > Send ( & bitStream , SYSTEM_PRIORITY , RELIABLE , 0 , Game : : chatSysAddr , false ) ;
2022-07-28 13:39:57 +00:00
} else {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Correct usage: /mute <username> <days (optional)> <hours (optional)> " ) ;
}
}
if ( chatCommand = = " kick " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_JUNIOR_MODERATOR ) {
if ( args . size ( ) = = 1 ) {
auto * player = Player : : GetPlayer ( args [ 0 ] ) ;
2022-08-02 13:56:20 +00:00
std : : u16string username = GeneralUtils : : UTF8ToUTF16 ( args [ 0 ] ) ;
2022-07-28 13:39:57 +00:00
if ( player = = nullptr ) {
2022-08-02 13:56:20 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Count not find player of name: " + username ) ;
2021-12-05 17:54:36 +00:00
return ;
}
Game : : server - > Disconnect ( player - > GetSystemAddress ( ) , SERVER_DISCON_KICK ) ;
2022-08-02 13:56:20 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Kicked: " + username ) ;
2022-07-28 13:39:57 +00:00
} else {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Correct usage: /kick <username> " ) ;
}
}
if ( chatCommand = = " ban " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_SENIOR_MODERATOR ) {
if ( args . size ( ) = = 1 ) {
auto * player = Player : : GetPlayer ( args [ 0 ] ) ;
uint32_t accountId = 0 ;
2022-07-28 13:39:57 +00:00
if ( player = = nullptr ) {
2021-12-05 17:54:36 +00:00
auto * accountQuery = Database : : CreatePreppedStmt ( " SELECT account_id FROM charinfo WHERE name=? LIMIT 1; " ) ;
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
accountQuery - > setString ( 1 , args [ 0 ] ) ;
auto result = accountQuery - > executeQuery ( ) ;
2022-07-28 13:39:57 +00:00
if ( result - > rowsCount ( ) > 0 ) {
2021-12-05 17:54:36 +00:00
while ( result - > next ( ) ) accountId = result - > getUInt ( 1 ) ;
}
delete accountQuery ;
delete result ;
2022-07-28 13:39:57 +00:00
if ( accountId = = 0 ) {
2022-08-02 13:56:20 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Count not find player of name: " + GeneralUtils : : UTF8ToUTF16 ( args [ 0 ] ) ) ;
2021-12-05 17:54:36 +00:00
return ;
}
2022-07-28 13:39:57 +00:00
} else {
2021-12-05 17:54:36 +00:00
accountId = player - > GetParentUser ( ) - > GetAccountID ( ) ;
}
auto * userUpdate = Database : : CreatePreppedStmt ( " UPDATE accounts SET banned = true WHERE id = ?; " ) ;
userUpdate - > setInt ( 1 , accountId ) ;
userUpdate - > executeUpdate ( ) ;
delete userUpdate ;
2022-07-28 13:39:57 +00:00
if ( player ! = nullptr ) {
2021-12-05 17:54:36 +00:00
Game : : server - > Disconnect ( player - > GetSystemAddress ( ) , SERVER_DISCON_KICK ) ;
}
ChatPackets : : SendSystemMessage ( sysAddr , u " Banned: " + GeneralUtils : : ASCIIToUTF16 ( args [ 0 ] ) ) ;
2022-07-28 13:39:57 +00:00
} else {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Correct usage: /ban <username> " ) ;
}
}
//-------------------------------------------------
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " buffme " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
2021-12-05 17:54:36 +00:00
auto dest = static_cast < DestroyableComponent * > ( entity - > GetComponent ( COMPONENT_TYPE_DESTROYABLE ) ) ;
if ( dest ) {
dest - > SetHealth ( 999 ) ;
dest - > SetMaxHealth ( 999.0f ) ;
dest - > SetArmor ( 999 ) ;
dest - > SetMaxArmor ( 999.0f ) ;
dest - > SetImagination ( 999 ) ;
dest - > SetMaxImagination ( 999.0f ) ;
}
2022-07-28 13:39:57 +00:00
EntityManager : : Instance ( ) - > SerializeEntity ( entity ) ;
}
2021-12-05 17:54:36 +00:00
if ( chatCommand = = " startcelebration " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER & & args . size ( ) = = 1 ) {
int32_t celebration ;
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , celebration ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid celebration. " ) ;
return ;
}
GameMessages : : SendStartCelebrationEffect ( entity , entity - > GetSystemAddress ( ) , celebration ) ;
}
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " buffmed " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
2021-12-05 17:54:36 +00:00
auto dest = static_cast < DestroyableComponent * > ( entity - > GetComponent ( COMPONENT_TYPE_DESTROYABLE ) ) ;
if ( dest ) {
dest - > SetHealth ( 9 ) ;
dest - > SetMaxHealth ( 9.0f ) ;
dest - > SetArmor ( 9 ) ;
dest - > SetMaxArmor ( 9.0f ) ;
dest - > SetImagination ( 9 ) ;
dest - > SetMaxImagination ( 9.0f ) ;
}
2022-07-28 13:39:57 +00:00
EntityManager : : Instance ( ) - > SerializeEntity ( entity ) ;
}
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " refillstats " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
2022-04-12 19:06:03 +00:00
2021-12-05 17:54:36 +00:00
auto dest = static_cast < DestroyableComponent * > ( entity - > GetComponent ( COMPONENT_TYPE_DESTROYABLE ) ) ;
if ( dest ) {
dest - > SetHealth ( ( int ) dest - > GetMaxHealth ( ) ) ;
dest - > SetArmor ( ( int ) dest - > GetMaxArmor ( ) ) ;
dest - > SetImagination ( ( int ) dest - > GetMaxImagination ( ) ) ;
}
2022-07-28 13:39:57 +00:00
EntityManager : : Instance ( ) - > SerializeEntity ( entity ) ;
}
2022-01-06 02:52:33 +00:00
2022-01-15 19:02:14 +00:00
if ( chatCommand = = " lookup " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER & & args . size ( ) = = 1 ) {
2022-01-13 03:48:27 +00:00
auto query = CDClientDatabase : : CreatePreppedStmt (
2022-01-15 19:02:14 +00:00
" SELECT `id`, `name` FROM `Objects` WHERE `displayName` LIKE ?1 OR `name` LIKE ?1 OR `description` LIKE ?1 LIMIT 50 " ) ;
2022-01-13 03:48:27 +00:00
const std : : string query_text = " % " + args [ 0 ] + " % " ;
2022-01-15 19:02:14 +00:00
query . bind ( 1 , query_text . c_str ( ) ) ;
2022-01-13 03:48:27 +00:00
auto tables = query . execQuery ( ) ;
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
while ( ! tables . eof ( ) ) {
std : : string message = std : : to_string ( tables . getIntField ( 0 ) ) + " - " + tables . getStringField ( 1 ) ;
2022-08-02 13:56:20 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , GeneralUtils : : UTF8ToUTF16 ( message , message . size ( ) ) ) ;
2022-07-28 13:39:57 +00:00
tables . nextRow ( ) ;
}
}
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " spawn " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER & & args . size ( ) > = 1 ) {
ControllablePhysicsComponent * comp = static_cast < ControllablePhysicsComponent * > ( entity - > GetComponent ( COMPONENT_TYPE_CONTROLLABLE_PHYSICS ) ) ;
if ( ! comp ) return ;
2021-12-05 17:54:36 +00:00
uint32_t lot ;
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , lot ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid lot. " ) ;
return ;
}
2022-04-12 23:30:46 +00:00
EntityInfo info ;
info . lot = lot ;
info . pos = comp - > GetPosition ( ) ;
info . rot = comp - > GetRotation ( ) ;
2021-12-05 17:54:36 +00:00
info . spawner = nullptr ;
info . spawnerID = entity - > GetObjectID ( ) ;
info . spawnerNodeID = 0 ;
2022-04-12 23:30:46 +00:00
Entity * newEntity = EntityManager : : Instance ( ) - > CreateEntity ( info , nullptr ) ;
2021-12-05 17:54:36 +00:00
2022-04-12 23:30:46 +00:00
if ( newEntity = = nullptr ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Failed to spawn entity. " ) ;
return ;
2022-04-12 23:30:46 +00:00
}
2021-12-05 17:54:36 +00:00
2022-09-02 18:49:19 +00:00
auto vehiclePhysicsComponent = newEntity - > GetComponent < VehiclePhysicsComponent > ( ) ;
if ( vehiclePhysicsComponent ) {
auto newRot = newEntity - > GetRotation ( ) ;
auto angles = newRot . GetEulerAngles ( ) ;
// make it right side up
angles . x - = PI ;
// make it going in the direction of the player
angles . y - = PI ;
newRot = NiQuaternion : : FromEulerAngles ( angles ) ;
newEntity - > SetRotation ( newRot ) ;
}
2022-04-12 23:30:46 +00:00
EntityManager : : Instance ( ) - > ConstructEntity ( newEntity ) ;
}
2021-12-05 17:54:36 +00:00
2022-12-02 11:47:27 +00:00
if ( chatCommand = = " spawngroup " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER & & args . size ( ) > = 3 ) {
auto controllablePhysicsComponent = entity - > GetComponent < ControllablePhysicsComponent > ( ) ;
if ( ! controllablePhysicsComponent ) return ;
LOT lot { } ;
uint32_t numberToSpawn { } ;
float radiusToSpawnWithin { } ;
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , lot ) ) {
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid lot. " ) ;
return ;
}
if ( ! GeneralUtils : : TryParse ( args [ 1 ] , numberToSpawn ) & & numberToSpawn > 0 ) {
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid number of enemies to spawn. " ) ;
return ;
}
// Must spawn within a radius of at least 0.0f
if ( ! GeneralUtils : : TryParse ( args [ 2 ] , radiusToSpawnWithin ) & & radiusToSpawnWithin < 0.0f ) {
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid radius to spawn within. " ) ;
return ;
}
EntityInfo info ;
info . lot = lot ;
info . spawner = nullptr ;
info . spawnerID = entity - > GetObjectID ( ) ;
info . spawnerNodeID = 0 ;
auto playerPosition = controllablePhysicsComponent - > GetPosition ( ) ;
while ( numberToSpawn > 0 ) {
auto randomAngle = GeneralUtils : : GenerateRandomNumber < float > ( 0.0f , 2 * PI ) ;
auto randomRadius = GeneralUtils : : GenerateRandomNumber < float > ( 0.0f , radiusToSpawnWithin ) ;
// Set the position to the generated random position plus the player position. This will
// spawn the entity in a circle around the player. As you get further from the player, the angle chosen will get less accurate.
info . pos = playerPosition + NiPoint3 ( cos ( randomAngle ) * randomRadius , 0.0f , sin ( randomAngle ) * randomRadius ) ;
info . rot = NiQuaternion ( ) ;
auto newEntity = EntityManager : : Instance ( ) - > CreateEntity ( info ) ;
if ( newEntity = = nullptr ) {
ChatPackets : : SendSystemMessage ( sysAddr , u " Failed to spawn entity. " ) ;
return ;
}
EntityManager : : Instance ( ) - > ConstructEntity ( newEntity ) ;
numberToSpawn - - ;
}
}
2021-12-05 17:54:36 +00:00
if ( ( chatCommand = = " giveuscore " ) & & args . size ( ) = = 1 & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
int32_t uscore ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , uscore ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid uscore. " ) ;
return ;
}
CharacterComponent * character = entity - > GetComponent < CharacterComponent > ( ) ;
if ( character ) character - > SetUScore ( character - > GetUScore ( ) + uscore ) ;
2022-04-12 19:06:03 +00:00
// LOOT_SOURCE_MODERATION should work but it doesn't. Relog to see uscore changes
2022-04-24 03:32:31 +00:00
GameMessages : : SendModifyLEGOScore ( entity , entity - > GetSystemAddress ( ) , uscore , eLootSourceType : : LOOT_SOURCE_MODERATION ) ;
2021-12-05 17:54:36 +00:00
}
2022-07-28 13:39:57 +00:00
if ( ( chatCommand = = " setlevel " ) & & args . size ( ) > = 1 & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
2022-06-13 07:45:17 +00:00
// We may be trying to set a specific players level to a level. If so override the entity with the requested players.
std : : string requestedPlayerToSetLevelOf = " " ;
if ( args . size ( ) > 1 ) {
requestedPlayerToSetLevelOf = args [ 1 ] ;
auto requestedPlayer = Player : : GetPlayer ( requestedPlayerToSetLevelOf ) ;
if ( ! requestedPlayer ) {
2022-08-02 13:56:20 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " No player found with username: ( " + GeneralUtils : : UTF8ToUTF16 ( requestedPlayerToSetLevelOf ) + u " ). " ) ;
2022-06-13 07:45:17 +00:00
return ;
}
if ( ! requestedPlayer - > GetOwner ( ) ) {
2022-08-02 13:56:20 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " No entity found with username: ( " + GeneralUtils : : UTF8ToUTF16 ( requestedPlayerToSetLevelOf ) + u " ). " ) ;
2022-06-13 07:45:17 +00:00
return ;
}
entity = requestedPlayer - > GetOwner ( ) ;
}
uint32_t requestedLevel ;
uint32_t oldLevel ;
// first check the level is valid
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , requestedLevel ) ) {
2022-06-13 07:45:17 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid level. " ) ;
return ;
}
// query to set our uscore to the correct value for this level
auto characterComponent = entity - > GetComponent < CharacterComponent > ( ) ;
2022-07-24 18:04:02 +00:00
if ( ! characterComponent ) return ;
auto levelComponent = entity - > GetComponent < LevelProgressionComponent > ( ) ;
2022-06-13 07:45:17 +00:00
auto query = CDClientDatabase : : CreatePreppedStmt ( " SELECT requiredUScore from LevelProgressionLookup WHERE id = ?; " ) ;
query . bind ( 1 , ( int ) requestedLevel ) ;
auto result = query . execQuery ( ) ;
if ( result . eof ( ) ) return ;
// Set the UScore first
2022-07-24 18:04:02 +00:00
oldLevel = levelComponent - > GetLevel ( ) ;
2022-06-13 07:45:17 +00:00
characterComponent - > SetUScore ( result . getIntField ( 0 , characterComponent - > GetUScore ( ) ) ) ;
// handle level up for each level we have passed if we set our level to be higher than the current one.
if ( oldLevel < requestedLevel ) {
while ( oldLevel < requestedLevel ) {
2022-07-28 13:39:57 +00:00
oldLevel + = 1 ;
2022-07-24 18:04:02 +00:00
levelComponent - > SetLevel ( oldLevel ) ;
levelComponent - > HandleLevelUp ( ) ;
2022-06-13 07:45:17 +00:00
}
} else {
2022-07-24 18:04:02 +00:00
levelComponent - > SetLevel ( requestedLevel ) ;
2022-06-13 07:45:17 +00:00
}
if ( requestedPlayerToSetLevelOf ! = " " ) {
2022-07-28 13:39:57 +00:00
ChatPackets : : SendSystemMessage (
2022-08-02 13:56:20 +00:00
sysAddr , u " Set " + GeneralUtils : : UTF8ToUTF16 ( requestedPlayerToSetLevelOf ) + u " 's level to " + GeneralUtils : : to_u16string ( requestedLevel ) +
2022-07-28 13:39:57 +00:00
u " and UScore to " + GeneralUtils : : to_u16string ( characterComponent - > GetUScore ( ) ) +
u " . Relog to see changes. " ) ;
2022-06-13 07:45:17 +00:00
} else {
2022-07-28 13:39:57 +00:00
ChatPackets : : SendSystemMessage (
sysAddr , u " Set your level to " + GeneralUtils : : to_u16string ( requestedLevel ) +
u " and UScore to " + GeneralUtils : : to_u16string ( characterComponent - > GetUScore ( ) ) +
u " . Relog to see changes. " ) ;
2022-06-13 07:45:17 +00:00
}
return ;
}
2021-12-05 17:54:36 +00:00
if ( chatCommand = = " pos " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
const auto position = entity - > GetPosition ( ) ;
2022-07-28 13:39:57 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " < " + ( GeneralUtils : : to_u16string ( position . x ) ) + u " , " + ( GeneralUtils : : to_u16string ( position . y ) ) + u " , " + ( GeneralUtils : : to_u16string ( position . z ) ) + u " > " ) ;
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
std : : cout < < position . x < < " , " < < position . y < < " , " < < position . z < < std : : endl ;
}
if ( chatCommand = = " rot " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
const auto rotation = entity - > GetRotation ( ) ;
2022-07-28 13:39:57 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " < " + ( GeneralUtils : : to_u16string ( rotation . w ) ) + u " , " + ( GeneralUtils : : to_u16string ( rotation . x ) ) + u " , " + ( GeneralUtils : : to_u16string ( rotation . y ) ) + u " , " + ( GeneralUtils : : to_u16string ( rotation . z ) ) + u " > " ) ;
2021-12-05 17:54:36 +00:00
std : : cout < < rotation . w < < " , " < < rotation . x < < " , " < < rotation . y < < " , " < < rotation . z < < std : : endl ;
}
if ( chatCommand = = " locrow " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
const auto position = entity - > GetPosition ( ) ;
const auto rotation = entity - > GetRotation ( ) ;
std : : cout < < " <location x= \" " < < position . x < < " \" y= \" " < < position . y < < " \" z= \" " < < position . z < < " \" rw= \" " < < rotation . w < < " \" rx= \" " < < rotation . x < < " \" ry= \" " < < rotation . y < < " \" rz= \" " < < rotation . z < < " \" /> " < < std : : endl ;
}
if ( chatCommand = = " playlvlfx " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
GameMessages : : SendPlayFXEffect ( entity , 7074 , u " create " , " 7074 " , LWOOBJID_EMPTY , 1.0f , 1.0f , true ) ;
}
2022-04-12 23:30:46 +00:00
if ( chatCommand = = " playrebuildfx " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
GameMessages : : SendPlayFXEffect ( entity , 230 , u " rebuild " , " 230 " , LWOOBJID_EMPTY , 1.0f , 1.0f , true ) ;
}
2021-12-05 17:54:36 +00:00
if ( ( chatCommand = = " freemoney " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) & & args . size ( ) = = 1 ) {
int32_t money ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , money ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid money. " ) ;
return ;
}
auto * ch = entity - > GetCharacter ( ) ;
2022-04-24 03:32:31 +00:00
ch - > SetCoins ( ch - > GetCoins ( ) + money , eLootSourceType : : LOOT_SOURCE_MODERATION ) ;
2021-12-05 17:54:36 +00:00
}
if ( ( chatCommand = = " setcurrency " ) & & args . size ( ) = = 1 & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
int32_t money ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , money ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid money. " ) ;
return ;
}
auto * ch = entity - > GetCharacter ( ) ;
2022-04-24 03:32:31 +00:00
ch - > SetCoins ( money , eLootSourceType : : LOOT_SOURCE_MODERATION ) ;
2021-12-05 17:54:36 +00:00
}
// Allow for this on even while not a GM, as it sometimes toggles incorrrectly.
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " gminvis " & & entity - > GetParentUser ( ) - > GetMaxGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
2021-12-05 17:54:36 +00:00
GameMessages : : SendToggleGMInvis ( entity - > GetObjectID ( ) , true , UNASSIGNED_SYSTEM_ADDRESS ) ;
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
return ;
}
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " gmimmune " & & args . size ( ) > = 1 & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
2021-12-05 17:54:36 +00:00
auto * destroyableComponent = entity - > GetComponent < DestroyableComponent > ( ) ;
int32_t state = false ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , state ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid state. " ) ;
return ;
}
2022-07-28 13:39:57 +00:00
if ( destroyableComponent ! = nullptr ) {
2021-12-05 17:54:36 +00:00
destroyableComponent - > SetIsGMImmune ( state ) ;
}
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
return ;
}
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " buff " & & args . size ( ) > = 2 & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
2021-12-05 17:54:36 +00:00
auto * buffComponent = entity - > GetComponent < BuffComponent > ( ) ;
int32_t id = 0 ;
int32_t duration = 0 ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , id ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid buff id. " ) ;
return ;
}
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 1 ] , duration ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid buff duration. " ) ;
return ;
}
2022-07-28 13:39:57 +00:00
if ( buffComponent ! = nullptr ) {
2021-12-05 17:54:36 +00:00
buffComponent - > ApplyBuff ( id , duration , entity - > GetObjectID ( ) ) ;
}
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
return ;
}
2022-04-12 23:30:46 +00:00
if ( ( chatCommand = = " testmap " & & args . size ( ) > = 1 ) & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_FORUM_MODERATOR ) {
ChatPackets : : SendSystemMessage ( sysAddr , u " Requesting map change... " ) ;
2021-12-05 17:54:36 +00:00
uint32_t reqZone ;
LWOCLONEID cloneId = 0 ;
bool force = false ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , reqZone ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid zone. " ) ;
return ;
}
2022-07-28 13:39:57 +00:00
if ( args . size ( ) > 1 ) {
2021-12-05 17:54:36 +00:00
auto index = 1 ;
2022-07-28 13:39:57 +00:00
if ( args [ index ] = = " force " ) {
2021-12-05 17:54:36 +00:00
index + + ;
force = true ;
}
2022-07-28 13:39:57 +00:00
if ( args . size ( ) > index & & ! GeneralUtils : : TryParse ( args [ index ] , cloneId ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid clone id. " ) ;
return ;
}
}
const auto objid = entity - > GetObjectID ( ) ;
2022-01-06 02:52:33 +00:00
2022-07-09 03:25:44 +00:00
if ( force | | CheckIfAccessibleZone ( reqZone ) ) { // to prevent tomfoolery
2022-01-06 02:52:33 +00:00
2022-07-09 03:25:44 +00:00
ZoneInstanceManager : : Instance ( ) - > RequestZoneTransfer ( Game : : server , reqZone , cloneId , false , [ objid ] ( bool mythranShift , uint32_t zoneID , uint32_t zoneInstance , uint32_t zoneClone , std : : string serverIP , uint16_t serverPort ) {
2021-12-05 17:54:36 +00:00
auto * entity = EntityManager : : Instance ( ) - > GetEntity ( objid ) ;
2022-07-09 03:25:44 +00:00
if ( ! entity ) return ;
2021-12-05 17:54:36 +00:00
2022-07-09 03:25:44 +00:00
const auto sysAddr = entity - > GetSystemAddress ( ) ;
2021-12-05 17:54:36 +00:00
2022-07-09 03:25:44 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Transfering map... " ) ;
2021-12-05 17:54:36 +00:00
2022-07-25 02:26:51 +00:00
Game : : logger - > Log ( " UserManager " , " Transferring %s to Zone %i (Instance %i | Clone %i | Mythran Shift: %s) with IP %s and Port %i " , sysAddr . ToString ( ) , zoneID , zoneInstance , zoneClone , mythranShift = = true ? " true " : " false " , serverIP . c_str ( ) , serverPort ) ;
2022-07-09 03:25:44 +00:00
if ( entity - > GetCharacter ( ) ) {
entity - > GetCharacter ( ) - > SetZoneID ( zoneID ) ;
entity - > GetCharacter ( ) - > SetZoneInstance ( zoneInstance ) ;
entity - > GetCharacter ( ) - > SetZoneClone ( zoneClone ) ;
entity - > GetComponent < CharacterComponent > ( ) - > SetLastRocketConfig ( u " " ) ;
}
2021-12-05 17:54:36 +00:00
2022-07-09 03:25:44 +00:00
entity - > GetCharacter ( ) - > SaveXMLToDatabase ( ) ;
2021-12-05 17:54:36 +00:00
2022-07-09 03:25:44 +00:00
WorldPackets : : SendTransferToWorld ( sysAddr , serverIP , serverPort , mythranShift ) ;
return ;
2022-07-28 13:39:57 +00:00
} ) ;
2022-07-09 03:25:44 +00:00
} else {
std : : string msg = " ZoneID not found or allowed: " ;
2022-08-02 13:56:20 +00:00
msg . append ( args [ 0 ] ) ; // FIXME: unnecessary utf16 re-encoding just for error
ChatPackets : : SendSystemMessage ( sysAddr , GeneralUtils : : UTF8ToUTF16 ( msg , msg . size ( ) ) ) ;
2022-07-09 03:25:44 +00:00
}
}
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " createprivate " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER & & args . size ( ) > = 3 ) {
2021-12-05 17:54:36 +00:00
uint32_t zone ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , zone ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid zone. " ) ;
return ;
}
uint32_t clone ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 1 ] , clone ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid clone. " ) ;
return ;
}
const auto & password = args [ 2 ] ;
ZoneInstanceManager : : Instance ( ) - > CreatePrivateZone ( Game : : server , zone , clone , password ) ;
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , GeneralUtils : : ASCIIToUTF16 ( " Sent request for private zone with password: " + password ) ) ;
return ;
}
if ( ( chatCommand = = " debugui " ) & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
ChatPackets : : SendSystemMessage ( sysAddr , u " Opening UIDebugger... " ) ;
AMFArrayValue args ;
2022-07-22 05:26:09 +00:00
GameMessages : : SendUIMessageServerToSingleClient ( entity , sysAddr , " ToggleUIDebugger; " , nullptr ) ;
2021-12-05 17:54:36 +00:00
}
if ( ( chatCommand = = " boost " ) & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
auto * possessorComponent = entity - > GetComponent < PossessorComponent > ( ) ;
2022-07-28 13:39:57 +00:00
if ( possessorComponent = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
auto * vehicle = EntityManager : : Instance ( ) - > GetEntity ( possessorComponent - > GetPossessable ( ) ) ;
2022-07-28 13:39:57 +00:00
if ( vehicle = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
2022-09-02 18:49:19 +00:00
if ( args . size ( ) > = 1 ) {
float time ;
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , time ) ) {
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid boost time. " ) ;
return ;
} else {
GameMessages : : SendVehicleAddPassiveBoostAction ( vehicle - > GetObjectID ( ) , UNASSIGNED_SYSTEM_ADDRESS ) ;
entity - > AddCallbackTimer ( time , [ vehicle ] ( ) {
if ( ! vehicle ) return ;
GameMessages : : SendVehicleRemovePassiveBoostAction ( vehicle - > GetObjectID ( ) , UNASSIGNED_SYSTEM_ADDRESS ) ;
} ) ;
}
} else {
GameMessages : : SendVehicleAddPassiveBoostAction ( vehicle - > GetObjectID ( ) , UNASSIGNED_SYSTEM_ADDRESS ) ;
}
}
if ( ( chatCommand = = " unboost " ) & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
auto * possessorComponent = entity - > GetComponent < PossessorComponent > ( ) ;
if ( possessorComponent = = nullptr ) return ;
auto * vehicle = EntityManager : : Instance ( ) - > GetEntity ( possessorComponent - > GetPossessable ( ) ) ;
if ( vehicle = = nullptr ) return ;
GameMessages : : SendVehicleRemovePassiveBoostAction ( vehicle - > GetObjectID ( ) , UNASSIGNED_SYSTEM_ADDRESS ) ;
2021-12-05 17:54:36 +00:00
}
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " activatespawner " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER & & args . size ( ) > = 1 ) {
2021-12-05 17:54:36 +00:00
auto spawners = dZoneManager : : Instance ( ) - > GetSpawnersByName ( args [ 0 ] ) ;
2022-07-28 13:39:57 +00:00
for ( auto * spawner : spawners ) {
2021-12-05 17:54:36 +00:00
spawner - > Activate ( ) ;
}
spawners = dZoneManager : : Instance ( ) - > GetSpawnersInGroup ( args [ 0 ] ) ;
2022-07-28 13:39:57 +00:00
for ( auto * spawner : spawners ) {
2021-12-05 17:54:36 +00:00
spawner - > Activate ( ) ;
}
}
if ( chatCommand = = " spawnphysicsverts " & & entity - > GetGMLevel ( ) > = 6 ) {
//Go tell physics to spawn all the vertices:
auto entities = EntityManager : : Instance ( ) - > GetEntitiesByComponent ( COMPONENT_TYPE_PHANTOM_PHYSICS ) ;
for ( auto en : entities ) {
auto phys = static_cast < PhantomPhysicsComponent * > ( en - > GetComponent ( COMPONENT_TYPE_PHANTOM_PHYSICS ) ) ;
if ( phys )
phys - > SpawnVertices ( ) ;
}
}
if ( chatCommand = = " reportproxphys " & & entity - > GetGMLevel ( ) > = 6 ) {
auto entities = EntityManager : : Instance ( ) - > GetEntitiesByComponent ( COMPONENT_TYPE_PROXIMITY_MONITOR ) ;
for ( auto en : entities ) {
auto phys = static_cast < ProximityMonitorComponent * > ( en - > GetComponent ( COMPONENT_TYPE_PROXIMITY_MONITOR ) ) ;
if ( phys ) {
for ( auto prox : phys - > GetProximitiesData ( ) ) {
if ( ! prox . second ) continue ;
auto sphere = static_cast < dpShapeSphere * > ( prox . second - > GetShape ( ) ) ;
auto pos = prox . second - > GetPosition ( ) ;
std : : cout < < prox . first < < " , r: " < < sphere - > GetRadius ( ) < < " , pos: " < < pos . x < < " , " < < pos . y < < " , " < < pos . z < < std : : endl ;
}
}
}
}
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " triggerspawner " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER & & args . size ( ) > = 1 ) {
2021-12-05 17:54:36 +00:00
auto spawners = dZoneManager : : Instance ( ) - > GetSpawnersByName ( args [ 0 ] ) ;
2022-07-28 13:39:57 +00:00
for ( auto * spawner : spawners ) {
2021-12-05 17:54:36 +00:00
spawner - > Spawn ( ) ;
}
spawners = dZoneManager : : Instance ( ) - > GetSpawnersInGroup ( args [ 0 ] ) ;
2022-07-28 13:39:57 +00:00
for ( auto * spawner : spawners ) {
2021-12-05 17:54:36 +00:00
spawner - > Spawn ( ) ;
}
}
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " reforge " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER & & args . size ( ) > = 2 ) {
2021-12-05 17:54:36 +00:00
LOT baseItem ;
LOT reforgedItem ;
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , baseItem ) ) return ;
if ( ! GeneralUtils : : TryParse ( args [ 1 ] , reforgedItem ) ) return ;
auto * inventoryComponent = entity - > GetComponent < InventoryComponent > ( ) ;
if ( inventoryComponent = = nullptr ) return ;
2022-07-28 13:39:57 +00:00
std : : vector < LDFBaseData * > data { } ;
2021-12-05 17:54:36 +00:00
data . push_back ( new LDFData < int32_t > ( u " reforgedLOT " , reforgedItem ) ) ;
2022-04-24 03:44:08 +00:00
inventoryComponent - > AddItem ( baseItem , 1 , eLootSourceType : : LOOT_SOURCE_MODERATION , eInventoryType : : INVALID , data ) ;
2021-12-05 17:54:36 +00:00
}
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " crash " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_OPERATOR ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Crashing... " ) ;
int * badPtr = nullptr ;
* badPtr = 0 ;
return ;
}
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " config-set " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER & & args . size ( ) > = 2 ) {
2021-12-05 17:54:36 +00:00
GameConfig : : SetValue ( args [ 0 ] , args [ 1 ] ) ;
ChatPackets : : SendSystemMessage (
2022-08-02 13:56:20 +00:00
sysAddr , u " Set config value: " + GeneralUtils : : UTF8ToUTF16 ( args [ 0 ] ) + u " to " + GeneralUtils : : UTF8ToUTF16 ( args [ 1 ] )
2021-12-05 17:54:36 +00:00
) ;
}
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " config-get " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER & & args . size ( ) > = 1 ) {
2021-12-05 17:54:36 +00:00
const auto & value = GameConfig : : GetValue ( args [ 0 ] ) ;
2022-08-02 13:56:20 +00:00
std : : u16string u16key = GeneralUtils : : UTF8ToUTF16 ( args [ 0 ] ) ;
2022-07-28 13:39:57 +00:00
if ( value . empty ( ) ) {
2022-08-02 13:56:20 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " No value found for " + u16key ) ;
2022-07-28 13:39:57 +00:00
} else {
2022-08-02 13:56:20 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Value for " + u16key + u " : " + GeneralUtils : : UTF8ToUTF16 ( value ) ) ;
2021-12-05 17:54:36 +00:00
}
}
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " metrics " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
for ( const auto variable : Metrics : : GetAllMetrics ( ) ) {
2021-12-05 17:54:36 +00:00
auto * metric = Metrics : : GetMetric ( variable ) ;
2022-07-28 13:39:57 +00:00
if ( metric = = nullptr ) {
2021-12-05 17:54:36 +00:00
continue ;
}
ChatPackets : : SendSystemMessage (
sysAddr ,
2022-01-06 02:52:33 +00:00
GeneralUtils : : ASCIIToUTF16 ( Metrics : : MetricVariableToString ( variable ) ) +
u " : " +
GeneralUtils : : to_u16string ( Metrics : : ToMiliseconds ( metric - > average ) ) +
2021-12-05 17:54:36 +00:00
u " ms "
) ;
}
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage (
sysAddr ,
2022-07-28 13:39:57 +00:00
u " Peak RSS: " + GeneralUtils : : to_u16string ( ( float ) ( ( double ) Metrics : : GetPeakRSS ( ) / 1.024e6 ) ) +
2021-12-05 17:54:36 +00:00
u " MB "
) ;
ChatPackets : : SendSystemMessage (
sysAddr ,
2022-07-28 13:39:57 +00:00
u " Current RSS: " + GeneralUtils : : to_u16string ( ( float ) ( ( double ) Metrics : : GetCurrentRSS ( ) / 1.024e6 ) ) +
2021-12-05 17:54:36 +00:00
u " MB "
) ;
ChatPackets : : SendSystemMessage (
sysAddr ,
u " Process ID: " + GeneralUtils : : to_u16string ( Metrics : : GetProcessID ( ) )
) ;
return ;
}
2022-12-04 22:25:58 +00:00
if ( chatCommand = = " reloadconfig " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER ) {
Game : : config - > ReloadConfig ( ) ;
VanityUtilities : : SpawnVanity ( ) ;
dpWorld : : Instance ( ) . Reload ( ) ;
auto entities = EntityManager : : Instance ( ) - > GetEntitiesByComponent ( COMPONENT_TYPE_SCRIPTED_ACTIVITY ) ;
for ( auto entity : entities ) {
auto * scriptedActivityComponent = entity - > GetComponent < ScriptedActivityComponent > ( ) ;
if ( ! scriptedActivityComponent ) continue ;
scriptedActivityComponent - > ReloadConfig ( ) ;
}
2022-12-06 00:08:47 +00:00
Game : : server - > UpdateBandwidthLimit ( ) ;
2022-12-04 22:25:58 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Successfully reloaded config for world! " ) ;
}
2021-12-20 10:25:45 +00:00
if ( chatCommand = = " rollloot " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_OPERATOR & & args . size ( ) > = 3 ) {
uint32_t lootMatrixIndex = 0 ;
uint32_t targetLot = 0 ;
uint32_t loops = 1 ;
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , lootMatrixIndex ) ) return ;
if ( ! GeneralUtils : : TryParse ( args [ 1 ] , targetLot ) ) return ;
if ( ! GeneralUtils : : TryParse ( args [ 2 ] , loops ) ) return ;
uint64_t totalRuns = 0 ;
for ( uint32_t i = 0 ; i < loops ; i + + ) {
while ( true ) {
auto lootRoll = LootGenerator : : Instance ( ) . RollLootMatrix ( lootMatrixIndex ) ;
totalRuns + = 1 ;
bool doBreak = false ;
for ( const auto & kv : lootRoll ) {
if ( ( uint32_t ) kv . first = = targetLot ) {
doBreak = true ;
}
}
if ( doBreak ) break ;
}
}
std : : u16string message = u " Ran loot drops looking for "
2022-01-06 02:52:33 +00:00
+ GeneralUtils : : to_u16string ( targetLot )
+ u " , "
+ GeneralUtils : : to_u16string ( loops )
+ u " times. It ran "
+ GeneralUtils : : to_u16string ( totalRuns )
2021-12-20 10:25:45 +00:00
+ u " times. Averaging out at "
2022-07-28 13:39:57 +00:00
+ GeneralUtils : : to_u16string ( ( float ) totalRuns / loops ) ;
2021-12-20 10:25:45 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , message ) ;
}
2022-12-18 15:46:04 +00:00
if ( chatCommand = = " deleteinven " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER & & args . size ( ) > = 1 ) {
eInventoryType inventoryType = eInventoryType : : INVALID ;
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , inventoryType ) ) {
// In this case, we treat the input as a string and try to find it in the reflection list
std : : transform ( args [ 0 ] . begin ( ) , args [ 0 ] . end ( ) , args [ 0 ] . begin ( ) , : : toupper ) ;
Game : : logger - > Log ( " SlashCommandHandler " , " looking for inventory %s " , args [ 0 ] . c_str ( ) ) ;
for ( uint32_t index = 0 ; index < NUMBER_OF_INVENTORIES ; index + + ) {
if ( std : : string_view ( args [ 0 ] ) = = std : : string_view ( InventoryType : : InventoryTypeToString ( static_cast < eInventoryType > ( index ) ) ) ) inventoryType = static_cast < eInventoryType > ( index ) ;
}
}
if ( inventoryType = = eInventoryType : : INVALID | | inventoryType > = NUMBER_OF_INVENTORIES ) {
ChatPackets : : SendSystemMessage ( sysAddr , u " Invalid inventory provided. " ) ;
return ;
}
auto * inventoryComponent = entity - > GetComponent < InventoryComponent > ( ) ;
if ( ! inventoryComponent ) return ;
auto * inventoryToDelete = inventoryComponent - > GetInventory ( inventoryType ) ;
if ( ! inventoryToDelete ) return ;
inventoryToDelete - > DeleteAllItems ( ) ;
Game : : logger - > Log ( " SlashCommandHandler " , " Deleted inventory %s for user %llu " , args [ 0 ] . c_str ( ) , entity - > GetObjectID ( ) ) ;
ChatPackets : : SendSystemMessage ( sysAddr , u " Deleted inventory " + GeneralUtils : : UTF8ToUTF16 ( args [ 0 ] ) ) ;
}
2022-07-28 13:39:57 +00:00
if ( chatCommand = = " inspect " & & entity - > GetGMLevel ( ) > = GAME_MASTER_LEVEL_DEVELOPER & & args . size ( ) > = 1 ) {
2021-12-05 17:54:36 +00:00
Entity * closest = nullptr ;
int32_t component ;
std : : u16string ldf ;
bool isLDF = false ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 0 ] , component ) ) {
2021-12-05 17:54:36 +00:00
component = - 1 ;
2022-08-02 13:56:20 +00:00
ldf = GeneralUtils : : UTF8ToUTF16 ( args [ 0 ] ) ;
2021-12-05 17:54:36 +00:00
isLDF = true ;
}
auto reference = entity - > GetPosition ( ) ;
auto closestDistance = 0.0f ;
const auto candidates = EntityManager : : Instance ( ) - > GetEntitiesByComponent ( component ) ;
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
for ( auto * candidate : candidates ) {
if ( candidate - > GetLOT ( ) = = 1 | | candidate - > GetLOT ( ) = = 8092 ) {
2021-12-05 17:54:36 +00:00
continue ;
}
2022-07-28 13:39:57 +00:00
if ( isLDF & & ! candidate - > HasVar ( ldf ) ) {
2021-12-05 17:54:36 +00:00
continue ;
}
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
if ( closest = = nullptr ) {
2021-12-05 17:54:36 +00:00
closest = candidate ;
closestDistance = NiPoint3 : : Distance ( candidate - > GetPosition ( ) , reference ) ;
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
continue ;
}
2022-01-06 02:52:33 +00:00
2021-12-05 17:54:36 +00:00
const auto distance = NiPoint3 : : Distance ( candidate - > GetPosition ( ) , reference ) ;
2022-07-28 13:39:57 +00:00
if ( distance < closestDistance ) {
2021-12-05 17:54:36 +00:00
closest = candidate ;
closestDistance = distance ;
}
}
2022-07-28 13:39:57 +00:00
if ( closest = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
EntityManager : : Instance ( ) - > SerializeEntity ( closest ) ;
auto * table = CDClientManager : : Instance ( ) - > GetTable < CDObjectsTable > ( " Objects " ) ;
const auto & info = table - > GetByID ( closest - > GetLOT ( ) ) ;
std : : stringstream header ;
header < < info . name < < " [ " < < std : : to_string ( info . id ) < < " ] " < < " " < < std : : to_string ( closestDistance ) < < " " < < std : : to_string ( closest - > IsSleeping ( ) ) ;
ChatPackets : : SendSystemMessage ( sysAddr , GeneralUtils : : ASCIIToUTF16 ( header . str ( ) ) ) ;
2022-01-06 02:52:33 +00:00
2022-07-28 13:39:57 +00:00
for ( const auto & pair : closest - > GetComponents ( ) ) {
2021-12-05 17:54:36 +00:00
auto id = pair . first ;
std : : stringstream stream ;
stream < < " Component [ " < < std : : to_string ( id ) < < " ] " ;
ChatPackets : : SendSystemMessage ( sysAddr , GeneralUtils : : ASCIIToUTF16 ( stream . str ( ) ) ) ;
}
2022-07-28 13:39:57 +00:00
if ( args . size ( ) > = 2 ) {
if ( args [ 1 ] = = " -m " & & args . size ( ) > = 3 ) {
2021-12-05 17:54:36 +00:00
auto * movingPlatformComponent = closest - > GetComponent < MovingPlatformComponent > ( ) ;
int32_t value = 0 ;
2022-07-28 13:39:57 +00:00
if ( movingPlatformComponent = = nullptr | | ! GeneralUtils : : TryParse ( args [ 2 ] , value ) ) {
2021-12-05 17:54:36 +00:00
return ;
}
movingPlatformComponent - > SetSerialized ( true ) ;
2022-07-28 13:39:57 +00:00
if ( value = = - 1 ) {
2021-12-05 17:54:36 +00:00
movingPlatformComponent - > StopPathing ( ) ;
2022-07-28 13:39:57 +00:00
} else {
2021-12-05 17:54:36 +00:00
movingPlatformComponent - > GotoWaypoint ( value ) ;
}
EntityManager : : Instance ( ) - > SerializeEntity ( closest ) ;
2022-07-28 13:39:57 +00:00
} else if ( args [ 1 ] = = " -a " & & args . size ( ) > = 3 ) {
2022-08-02 13:56:20 +00:00
GameMessages : : SendPlayAnimation ( closest , GeneralUtils : : UTF8ToUTF16 ( args [ 2 ] ) ) ;
2022-07-28 13:39:57 +00:00
} else if ( args [ 1 ] = = " -s " ) {
for ( auto * entry : closest - > GetSettings ( ) ) {
2022-08-02 13:56:20 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , GeneralUtils : : UTF8ToUTF16 ( entry - > GetString ( ) ) ) ;
2021-12-05 17:54:36 +00:00
}
ChatPackets : : SendSystemMessage ( sysAddr , u " ------ " ) ;
ChatPackets : : SendSystemMessage ( sysAddr , u " Spawner ID: " + GeneralUtils : : to_u16string ( closest - > GetSpawnerID ( ) ) ) ;
2022-07-28 13:39:57 +00:00
} else if ( args [ 1 ] = = " -p " ) {
2021-12-05 17:54:36 +00:00
const auto postion = closest - > GetPosition ( ) ;
ChatPackets : : SendSystemMessage (
2022-01-06 02:52:33 +00:00
sysAddr ,
2021-12-05 17:54:36 +00:00
GeneralUtils : : ASCIIToUTF16 ( " < " + std : : to_string ( postion . x ) + " , " + std : : to_string ( postion . y ) + " , " + std : : to_string ( postion . z ) + " > " )
) ;
2022-07-28 13:39:57 +00:00
} else if ( args [ 1 ] = = " -f " ) {
2021-12-05 17:54:36 +00:00
auto * destuctable = closest - > GetComponent < DestroyableComponent > ( ) ;
2022-07-28 13:39:57 +00:00
if ( destuctable = = nullptr ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " No destroyable component on this entity! " ) ;
return ;
}
ChatPackets : : SendSystemMessage ( sysAddr , u " Smashable: " + ( GeneralUtils : : to_u16string ( destuctable - > GetIsSmashable ( ) ) ) ) ;
ChatPackets : : SendSystemMessage ( sysAddr , u " Friendly factions: " ) ;
2022-07-28 13:39:57 +00:00
for ( const auto entry : destuctable - > GetFactionIDs ( ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , ( GeneralUtils : : to_u16string ( entry ) ) ) ;
}
ChatPackets : : SendSystemMessage ( sysAddr , u " Enemy factions: " ) ;
2022-07-28 13:39:57 +00:00
for ( const auto entry : destuctable - > GetEnemyFactionsIDs ( ) ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , ( GeneralUtils : : to_u16string ( entry ) ) ) ;
}
2022-07-28 13:39:57 +00:00
if ( args . size ( ) > = 3 ) {
2021-12-05 17:54:36 +00:00
int32_t faction ;
2022-07-28 13:39:57 +00:00
if ( ! GeneralUtils : : TryParse ( args [ 2 ] , faction ) ) {
2021-12-05 17:54:36 +00:00
return ;
}
destuctable - > SetFaction ( - 1 ) ;
destuctable - > AddFaction ( faction , true ) ;
}
2022-07-28 13:39:57 +00:00
} else if ( args [ 1 ] = = " -t " ) {
2021-12-05 17:54:36 +00:00
auto * phantomPhysicsComponent = closest - > GetComponent < PhantomPhysicsComponent > ( ) ;
2022-07-28 13:39:57 +00:00
if ( phantomPhysicsComponent ! = nullptr ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Type: " + ( GeneralUtils : : to_u16string ( phantomPhysicsComponent - > GetEffectType ( ) ) ) ) ;
const auto dir = phantomPhysicsComponent - > GetDirection ( ) ;
2022-07-28 13:39:57 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Direction: < " + ( GeneralUtils : : to_u16string ( dir . x ) ) + u " , " + ( GeneralUtils : : to_u16string ( dir . y ) ) + u " , " + ( GeneralUtils : : to_u16string ( dir . z ) ) + u " > " ) ;
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Multiplier: " + ( GeneralUtils : : to_u16string ( phantomPhysicsComponent - > GetDirectionalMultiplier ( ) ) ) ) ;
ChatPackets : : SendSystemMessage ( sysAddr , u " Active: " + ( GeneralUtils : : to_u16string ( phantomPhysicsComponent - > GetPhysicsEffectActive ( ) ) ) ) ;
}
2022-07-28 13:39:57 +00:00
if ( closest - > GetTrigger ( ) ! = nullptr ) {
2021-12-05 17:54:36 +00:00
ChatPackets : : SendSystemMessage ( sysAddr , u " Trigger: " + ( GeneralUtils : : to_u16string ( closest - > GetTrigger ( ) - > id ) ) ) ;
}
}
}
}
}
bool SlashCommandHandler : : CheckIfAccessibleZone ( const unsigned int zoneID ) {
2022-04-12 23:05:22 +00:00
//We're gonna go ahead and presume we've got the db loaded already:
2022-07-28 13:39:57 +00:00
CDZoneTableTable * zoneTable = CDClientManager : : Instance ( ) - > GetTable < CDZoneTableTable > ( " ZoneTable " ) ;
2022-04-12 19:06:03 +00:00
const CDZoneTable * zone = zoneTable - > Query ( zoneID ) ;
if ( zone ! = nullptr ) {
2022-11-01 18:21:26 +00:00
return Game : : assetManager - > HasFile ( ( " maps/ " + zone - > zoneName ) . c_str ( ) ) ;
2022-04-12 19:06:03 +00:00
} else {
return false ;
2022-01-18 19:48:56 +00:00
}
2021-12-05 17:54:36 +00:00
}
void SlashCommandHandler : : SendAnnouncement ( const std : : string & title , const std : : string & message ) {
AMFArrayValue args ;
auto * titleValue = new AMFStringValue ( ) ;
titleValue - > SetStringValue ( title ) ;
auto * messageValue = new AMFStringValue ( ) ;
messageValue - > SetStringValue ( message ) ;
args . InsertValue ( " title " , titleValue ) ;
args . InsertValue ( " message " , messageValue ) ;
GameMessages : : SendUIMessageServerToAllClients ( " ToggleAnnounce " , & args ) ;
2022-01-06 02:52:33 +00:00
//Notify chat about it
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
PacketUtils : : WriteHeader ( bitStream , CHAT_INTERNAL , MSG_CHAT_INTERNAL_ANNOUNCEMENT ) ;
2022-07-17 03:40:46 +00:00
bitStream . Write < uint32_t > ( title . size ( ) ) ;
for ( auto character : title ) {
bitStream . Write < char > ( character ) ;
}
2021-12-05 17:54:36 +00:00
2022-07-17 03:40:46 +00:00
bitStream . Write < uint32_t > ( message . size ( ) ) ;
for ( auto character : message ) {
bitStream . Write < char > ( character ) ;
}
2021-12-05 17:54:36 +00:00
Game : : chatServer - > Send ( & bitStream , SYSTEM_PRIORITY , RELIABLE , 0 , Game : : chatSysAddr , false ) ;
}