2020-08-18 20:42:30 +00:00
# include "CNShardServer.hpp"
# include "CNStructs.hpp"
# include "ChatManager.hpp"
2021-01-19 02:44:02 +00:00
# include "Database.hpp"
2020-08-18 20:42:30 +00:00
# include "PlayerManager.hpp"
2020-10-03 15:21:36 +00:00
# include "TransportManager.hpp"
2020-10-03 02:05:20 +00:00
# include "TableData.hpp"
2020-10-07 17:29:59 +00:00
# include "NPCManager.hpp"
# include "MobManager.hpp"
2020-10-18 21:02:51 +00:00
# include "MissionManager.hpp"
2020-11-22 21:29:22 +00:00
# include "ChunkManager.hpp"
2020-12-17 00:03:38 +00:00
# include "ItemManager.hpp"
2020-08-18 20:42:30 +00:00
2020-10-02 23:50:47 +00:00
# include <sstream>
# include <iterator>
2020-12-06 01:45:20 +00:00
# include <math.h>
2020-10-02 23:50:47 +00:00
std : : map < std : : string , ChatCommand > ChatManager : : commands ;
2020-12-15 14:58:11 +00:00
std : : vector < std : : string > ChatManager : : dump ;
2020-10-02 23:50:47 +00:00
std : : vector < std : : string > parseArgs ( std : : string full ) {
std : : stringstream ss ( full ) ;
std : : istream_iterator < std : : string > begin ( ss ) ;
std : : istream_iterator < std : : string > end ;
return std : : vector < std : : string > ( begin , end ) ;
}
2020-12-31 01:13:43 +00:00
bool ChatManager : : runCmd ( std : : string full , CNSocket * sock ) {
2020-10-03 00:20:59 +00:00
std : : vector < std : : string > args = parseArgs ( full ) ;
2020-10-02 23:50:47 +00:00
std : : string cmd = args [ 0 ] . substr ( 1 , args [ 0 ] . size ( ) - 1 ) ;
2020-10-05 00:03:13 +00:00
2020-10-02 23:59:07 +00:00
// check if the command exists
2020-10-02 23:50:47 +00:00
if ( ChatManager : : commands . find ( cmd ) ! = ChatManager : : commands . end ( ) ) {
Player * plr = PlayerManager : : getPlayer ( sock ) ;
ChatCommand command = ChatManager : : commands [ cmd ] ;
2020-10-05 00:03:13 +00:00
2020-10-02 23:59:07 +00:00
// sanity check + does the player have the required account level to use the command?
2020-10-02 23:50:47 +00:00
if ( plr ! = nullptr & & plr - > accountLevel < = command . requiredAccLevel ) {
command . handlr ( full , args , sock ) ;
return true ;
} else {
ChatManager : : sendServerMessage ( sock , " You don't have access to that command! " ) ;
return false ;
}
}
ChatManager : : sendServerMessage ( sock , " Unknown command! " ) ;
return false ;
}
2020-10-12 07:08:10 +00:00
void helpCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
2020-10-18 20:43:22 +00:00
ChatManager : : sendServerMessage ( sock , " Commands available to you: " ) ;
2020-10-12 07:08:10 +00:00
Player * plr = PlayerManager : : getPlayer ( sock ) ;
for ( auto & cmd : ChatManager : : commands ) {
2020-11-26 13:30:19 +00:00
if ( cmd . second . requiredAccLevel > = plr - > accountLevel )
2020-10-12 07:08:10 +00:00
ChatManager : : sendServerMessage ( sock , " / " + cmd . first + ( cmd . second . help . length ( ) > 0 ? " - " + cmd . second . help : " " ) ) ;
}
}
2020-10-03 00:20:59 +00:00
void accessCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
2020-10-02 23:50:47 +00:00
ChatManager : : sendServerMessage ( sock , " Your access level is " + std : : to_string ( PlayerManager : : getPlayer ( sock ) - > accountLevel ) ) ;
}
2020-10-05 00:33:30 +00:00
void populationCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
ChatManager : : sendServerMessage ( sock , std : : to_string ( PlayerManager : : players . size ( ) ) + " players online " ) ;
}
void levelCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
2020-10-08 18:20:12 +00:00
if ( args . size ( ) < 2 ) {
ChatManager : : sendServerMessage ( sock , " /level: no level specified " ) ;
return ;
}
2020-10-05 00:33:30 +00:00
Player * plr = PlayerManager : : getPlayer ( sock ) ;
char * tmp ;
int level = std : : strtol ( args [ 1 ] . c_str ( ) , & tmp , 10 ) ;
if ( * tmp )
return ;
if ( ( level < 1 | | level > 36 ) & & plr - > accountLevel > 30 )
return ;
if ( ! ( level < 1 | | level > 36 ) )
plr - > level = level ;
INITSTRUCT ( sP_FE2CL_REP_PC_CHANGE_LEVEL , resp ) ;
resp . iPC_ID = plr - > iID ;
resp . iPC_Level = level ;
sock - > sendPacket ( ( void * ) & resp , P_FE2CL_REP_PC_CHANGE_LEVEL , sizeof ( sP_FE2CL_REP_PC_CHANGE_LEVEL ) ) ;
PlayerManager : : sendToViewable ( sock , ( void * ) & resp , P_FE2CL_REP_PC_CHANGE_LEVEL , sizeof ( sP_FE2CL_REP_PC_CHANGE_LEVEL ) ) ;
}
2020-10-03 02:05:20 +00:00
void mssCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
if ( args . size ( ) < 2 ) {
ChatManager : : sendServerMessage ( sock , " [MSS] Too few arguments " ) ;
2020-10-03 15:21:36 +00:00
ChatManager : : sendServerMessage ( sock , " [MSS] Usage: /mss <route> <add/remove/goto/clear/test/export> <<height>> " ) ;
2020-10-03 02:05:20 +00:00
return ;
}
// Validate route number
char * routeNumC ;
int routeNum = std : : strtol ( args [ 1 ] . c_str ( ) , & routeNumC , 10 ) ;
if ( * routeNumC ) {
// not an integer
ChatManager : : sendServerMessage ( sock , " [MSS] Invalid route number ' " + args [ 1 ] + " ' " ) ;
return ;
}
if ( args . size ( ) < 3 ) {
ChatManager : : sendServerMessage ( sock , " [MSS] Too few arguments " ) ;
2020-10-06 19:53:21 +00:00
ChatManager : : sendServerMessage ( sock , " [MSS] Usage: /mss <route> <add/remove/goto/clear/test> <<height>> " ) ;
2020-10-03 02:05:20 +00:00
return ;
}
// get the route (if it doesn't exist yet, this will also make it)
2020-10-03 15:21:36 +00:00
std : : vector < WarpLocation > * route = & TableData : : RunningSkywayRoutes [ routeNum ] ;
2020-10-03 02:05:20 +00:00
// mss <route> add <height>
if ( args [ 2 ] = = " add " ) {
// make sure height token exists
if ( args . size ( ) < 4 ) {
ChatManager : : sendServerMessage ( sock , " [MSS] Point height must be specified " ) ;
ChatManager : : sendServerMessage ( sock , " [MSS] Usage: /mss <route> add <height> " ) ;
return ;
}
// validate height token
char * heightC ;
int height = std : : strtol ( args [ 3 ] . c_str ( ) , & heightC , 10 ) ;
if ( * heightC ) {
ChatManager : : sendServerMessage ( sock , " [MSS] Invalid height " + args [ 3 ] ) ;
return ;
}
Player * plr = PlayerManager : : getPlayer ( sock ) ;
2020-10-03 15:21:36 +00:00
route - > push_back ( { plr - > x , plr - > y , height } ) ; // add point
2020-10-03 02:05:20 +00:00
ChatManager : : sendServerMessage ( sock , " [MSS] Added point ( " + std : : to_string ( plr - > x ) + " , " + std : : to_string ( plr - > y ) + " , " + std : : to_string ( height ) + " ) to route " + std : : to_string ( routeNum ) ) ;
return ;
}
// mss <route> remove
if ( args [ 2 ] = = " remove " ) {
if ( route - > empty ( ) ) {
ChatManager : : sendServerMessage ( sock , " [MSS] Route " + std : : to_string ( routeNum ) + " is empty " ) ;
return ;
}
2020-10-03 15:21:36 +00:00
WarpLocation pulled = route - > back ( ) ;
route - > pop_back ( ) ; // remove point at top of stack
2020-10-03 02:05:20 +00:00
ChatManager : : sendServerMessage ( sock , " [MSS] Removed point ( " + std : : to_string ( pulled . x ) + " , " + std : : to_string ( pulled . y ) + " , " + std : : to_string ( pulled . z ) + " ) from route " + std : : to_string ( routeNum ) ) ;
return ;
}
// mss <route> goto
if ( args [ 2 ] = = " goto " ) {
if ( route - > empty ( ) ) {
ChatManager : : sendServerMessage ( sock , " [MSS] Route " + std : : to_string ( routeNum ) + " is empty " ) ;
return ;
}
2020-10-03 15:21:36 +00:00
WarpLocation pulled = route - > back ( ) ;
PlayerManager : : sendPlayerTo ( sock , pulled . x , pulled . y , pulled . z ) ;
2020-10-03 02:05:20 +00:00
return ;
}
// mss <route> clear
if ( args [ 2 ] = = " clear " ) {
2020-10-03 15:21:36 +00:00
route - > clear ( ) ;
2020-10-03 02:05:20 +00:00
ChatManager : : sendServerMessage ( sock , " [MSS] Cleared route " + std : : to_string ( routeNum ) ) ;
return ;
}
2020-10-06 21:59:33 +00:00
// mss <route> test
2020-10-03 15:21:36 +00:00
if ( args [ 2 ] = = " test " ) {
if ( route - > empty ( ) ) {
ChatManager : : sendServerMessage ( sock , " [MSS] Route " + std : : to_string ( routeNum ) + " is empty " ) ;
return ;
}
2020-10-06 19:53:21 +00:00
WarpLocation pulled = route - > front ( ) ;
PlayerManager : : sendPlayerTo ( sock , pulled . x , pulled . y , pulled . z ) ;
TransportManager : : testMssRoute ( sock , route ) ;
2020-10-03 02:05:20 +00:00
return ;
}
2020-10-06 19:53:21 +00:00
// for compatibility: mss <route> export
2020-10-03 02:05:20 +00:00
if ( args [ 2 ] = = " export " ) {
2020-10-06 21:59:33 +00:00
ChatManager : : sendServerMessage ( sock , " Wrote gruntwork to " + settings : : GRUNTWORKJSON ) ;
2020-10-06 19:53:21 +00:00
TableData : : flush ( ) ;
2020-10-03 02:05:20 +00:00
return ;
}
// mss ????
ChatManager : : sendServerMessage ( sock , " [MSS] Unknown command ' " + args [ 2 ] + " ' " ) ;
2020-10-07 17:29:59 +00:00
}
void summonWCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
2020-10-08 18:20:12 +00:00
if ( args . size ( ) < 2 ) {
2020-10-18 02:13:33 +00:00
ChatManager : : sendServerMessage ( sock , " /summonW: no mob type specified " ) ;
2020-10-08 18:20:12 +00:00
return ;
}
2020-10-07 17:29:59 +00:00
Player * plr = PlayerManager : : getPlayer ( sock ) ;
char * rest ;
int type = std : : strtol ( args [ 1 ] . c_str ( ) , & rest , 10 ) ;
if ( * rest ) {
ChatManager : : sendServerMessage ( sock , " Invalid NPC number: " + args [ 1 ] ) ;
return ;
}
2020-12-21 00:57:56 +00:00
int limit = NPCManager : : NPCData . back ( ) [ " m_iNpcNumber " ] ;
2020-10-07 17:29:59 +00:00
// permission & sanity check
2020-12-21 00:57:56 +00:00
if ( type > limit )
2020-10-07 17:29:59 +00:00
return ;
2020-12-15 22:15:39 +00:00
BaseNPC * npc = NPCManager : : summonNPC ( plr - > x , plr - > y , plr - > z , plr - > instanceID , type , true ) ;
2020-10-07 17:29:59 +00:00
2020-12-15 22:15:39 +00:00
// update angle
2020-10-19 01:45:58 +00:00
npc - > appearanceData . iAngle = ( plr - > angle + 180 ) % 360 ;
2020-11-18 00:07:04 +00:00
NPCManager : : updateNPCPosition ( npc - > appearanceData . iNPC_ID , plr - > x , plr - > y , plr - > z , plr - > instanceID , npc - > appearanceData . iAngle ) ;
2020-10-07 17:29:59 +00:00
2020-10-19 01:45:58 +00:00
// if we're in a lair, we need to spawn the NPC in both the private instance and the template
2020-10-18 20:43:22 +00:00
if ( PLAYERID ( plr - > instanceID ) ! = 0 ) {
2020-12-15 22:15:39 +00:00
npc = NPCManager : : summonNPC ( plr - > x , plr - > y , plr - > z , plr - > instanceID , type , true , true ) ;
2020-10-19 01:45:58 +00:00
npc - > appearanceData . iAngle = ( plr - > angle + 180 ) % 360 ;
2020-11-18 00:07:04 +00:00
NPCManager : : updateNPCPosition ( npc - > appearanceData . iNPC_ID , plr - > x , plr - > y , plr - > z , npc - > instanceID , npc - > appearanceData . iAngle ) ;
2020-10-18 02:13:33 +00:00
}
2020-10-07 17:29:59 +00:00
ChatManager : : sendServerMessage ( sock , " /summonW: placed mob with type: " + std : : to_string ( type ) +
" , id: " + std : : to_string ( npc - > appearanceData . iNPC_ID ) ) ;
2020-10-18 02:13:33 +00:00
TableData : : RunningMobs [ npc - > appearanceData . iNPC_ID ] = npc ; // only record the one in the template
2020-10-03 02:05:20 +00:00
}
2020-10-07 17:29:59 +00:00
void unsummonWCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
2020-11-17 23:16:16 +00:00
Player * plr = PlayerManager : : getPlayer ( sock ) ;
2020-10-06 22:34:11 +00:00
2020-11-23 00:14:46 +00:00
BaseNPC * npc = NPCManager : : getNearestNPC ( plr - > viewableChunks , plr - > x , plr - > y , plr - > z ) ;
2020-10-07 17:29:59 +00:00
if ( npc = = nullptr ) {
ChatManager : : sendServerMessage ( sock , " /unsummonW: No NPCs found nearby " ) ;
return ;
}
2020-11-08 08:42:49 +00:00
if ( TableData : : RunningEggs . find ( npc - > appearanceData . iNPC_ID ) ! = TableData : : RunningEggs . end ( ) ) {
ChatManager : : sendServerMessage ( sock , " /unsummonW: removed egg with type: " + std : : to_string ( npc - > appearanceData . iNPCType ) +
" , id: " + std : : to_string ( npc - > appearanceData . iNPC_ID ) ) ;
TableData : : RunningEggs . erase ( npc - > appearanceData . iNPC_ID ) ;
NPCManager : : destroyNPC ( npc - > appearanceData . iNPC_ID ) ;
return ;
}
2020-11-25 16:45:34 +00:00
if ( TableData : : RunningMobs . find ( npc - > appearanceData . iNPC_ID ) = = TableData : : RunningMobs . end ( )
& & TableData : : RunningGroups . find ( npc - > appearanceData . iNPC_ID ) = = TableData : : RunningGroups . end ( ) ) {
2020-10-07 17:29:59 +00:00
ChatManager : : sendServerMessage ( sock , " /unsummonW: Closest NPC is not a gruntwork mob. " ) ;
return ;
}
2020-11-30 15:53:34 +00:00
if ( MobManager : : Mobs . find ( npc - > appearanceData . iNPC_ID ) ! = MobManager : : Mobs . end ( ) ) {
int leadId = ( ( Mob * ) npc ) - > groupLeader ;
if ( leadId ! = 0 ) {
if ( MobManager : : Mobs . find ( leadId ) = = MobManager : : Mobs . end ( ) ) {
std : : cout < < " [WARN] unsummonW: leader not found! " < < std : : endl ;
2020-11-23 00:14:46 +00:00
}
2020-11-30 15:53:34 +00:00
Mob * leadNpc = MobManager : : Mobs [ leadId ] ;
for ( int i = 0 ; i < 4 ; i + + ) {
if ( leadNpc - > groupMember [ i ] = = 0 )
break ;
if ( MobManager : : Mobs . find ( leadNpc - > groupMember [ i ] ) = = MobManager : : Mobs . end ( ) ) {
std : : cout < < " [WARN] unsommonW: leader can't find a group member! " < < std : : endl ;
continue ;
}
2020-11-23 00:14:46 +00:00
2020-11-30 15:53:34 +00:00
NPCManager : : destroyNPC ( leadNpc - > groupMember [ i ] ) ;
}
TableData : : RunningGroups . erase ( leadId ) ;
NPCManager : : destroyNPC ( leadId ) ;
ChatManager : : sendServerMessage ( sock , " /unsummonW: Mob group destroyed. " ) ;
return ;
2020-11-16 03:13:40 +00:00
}
}
2020-10-07 17:29:59 +00:00
ChatManager : : sendServerMessage ( sock , " /unsummonW: removed mob with type: " + std : : to_string ( npc - > appearanceData . iNPCType ) +
" , id: " + std : : to_string ( npc - > appearanceData . iNPC_ID ) ) ;
TableData : : RunningMobs . erase ( npc - > appearanceData . iNPC_ID ) ;
NPCManager : : destroyNPC ( npc - > appearanceData . iNPC_ID ) ;
}
2020-10-07 18:38:32 +00:00
void toggleAiCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
MobManager : : simulateMobs = ! MobManager : : simulateMobs ;
if ( MobManager : : simulateMobs )
return ;
// return all mobs to their spawn points
for ( auto & pair : MobManager : : Mobs ) {
pair . second - > state = MobState : : RETREAT ;
pair . second - > target = nullptr ;
2020-10-14 21:15:02 +00:00
pair . second - > nextMovement = getTime ( ) ;
2020-10-13 19:44:43 +00:00
2020-10-14 21:15:02 +00:00
// mobs with static paths can chill where they are
if ( pair . second - > staticPath ) {
pair . second - > roamX = pair . second - > appearanceData . iX ;
pair . second - > roamY = pair . second - > appearanceData . iY ;
pair . second - > roamZ = pair . second - > appearanceData . iZ ;
} else {
pair . second - > roamX = pair . second - > spawnX ;
pair . second - > roamY = pair . second - > spawnY ;
pair . second - > roamZ = pair . second - > spawnZ ;
}
2020-10-07 18:38:32 +00:00
}
}
2020-10-07 17:29:59 +00:00
void npcRotateCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
2020-11-17 23:16:16 +00:00
Player * plr = PlayerManager : : getPlayer ( sock ) ;
2020-10-19 17:26:14 +00:00
2020-11-23 00:14:46 +00:00
BaseNPC * npc = NPCManager : : getNearestNPC ( plr - > viewableChunks , plr - > x , plr - > y , plr - > z ) ;
2020-10-06 21:59:33 +00:00
2020-10-06 22:34:11 +00:00
if ( npc = = nullptr ) {
ChatManager : : sendServerMessage ( sock , " [NPCR] No NPCs found nearby " ) ;
2020-10-06 21:59:33 +00:00
return ;
}
2020-10-06 22:34:11 +00:00
int angle = ( plr - > angle + 180 ) % 360 ;
2020-11-18 00:07:04 +00:00
NPCManager : : updateNPCPosition ( npc - > appearanceData . iNPC_ID , npc - > appearanceData . iX , npc - > appearanceData . iY , npc - > appearanceData . iZ , npc - > instanceID , angle ) ;
2020-10-19 01:45:58 +00:00
// if it's a gruntwork NPC, rotate in-place
if ( TableData : : RunningMobs . find ( npc - > appearanceData . iNPC_ID ) ! = TableData : : RunningMobs . end ( ) ) {
2020-11-18 00:07:04 +00:00
NPCManager : : updateNPCPosition ( npc - > appearanceData . iNPC_ID , npc - > appearanceData . iX , npc - > appearanceData . iY , npc - > appearanceData . iZ , npc - > instanceID , angle ) ;
2020-10-19 01:45:58 +00:00
ChatManager : : sendServerMessage ( sock , " [NPCR] Successfully set angle to " + std : : to_string ( angle ) + " for gruntwork NPC "
+ std : : to_string ( npc - > appearanceData . iNPC_ID ) ) ;
} else {
TableData : : RunningNPCRotations [ npc - > appearanceData . iNPC_ID ] = angle ;
ChatManager : : sendServerMessage ( sock , " [NPCR] Successfully set angle to " + std : : to_string ( angle ) + " for NPC "
+ std : : to_string ( npc - > appearanceData . iNPC_ID ) ) ;
}
2020-10-06 22:34:11 +00:00
// update rotation clientside
INITSTRUCT ( sP_FE2CL_NPC_ENTER , pkt ) ;
pkt . NPCAppearanceData = npc - > appearanceData ;
sock - > sendPacket ( ( void * ) & pkt , P_FE2CL_NPC_ENTER , sizeof ( sP_FE2CL_NPC_ENTER ) ) ;
2020-10-06 21:59:33 +00:00
}
2020-10-06 22:00:17 +00:00
void refreshCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
Player * plr = PlayerManager : : getPlayer ( sock ) ;
2020-11-22 21:29:22 +00:00
ChunkPos currentChunk = plr - > chunkPos ;
ChunkPos nullChunk = std : : make_tuple ( 0 , 0 , 0 ) ;
ChunkManager : : updatePlayerChunk ( sock , currentChunk , nullChunk ) ;
ChunkManager : : updatePlayerChunk ( sock , nullChunk , currentChunk ) ;
2020-10-06 22:00:17 +00:00
}
2020-10-12 01:53:01 +00:00
void instanceCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
Player * plr = PlayerManager : : getPlayer ( sock ) ;
// no additional arguments: report current instance ID
if ( args . size ( ) < 2 ) {
ChatManager : : sendServerMessage ( sock , " [INST] Current instance ID: " + std : : to_string ( plr - > instanceID ) ) ;
2020-10-18 20:43:22 +00:00
ChatManager : : sendServerMessage ( sock , " [INST] (Map " + std : : to_string ( MAPNUM ( plr - > instanceID ) ) + " , instance " + std : : to_string ( PLAYERID ( plr - > instanceID ) ) + " ) " ) ;
2020-10-12 01:53:01 +00:00
return ;
}
// move player to specified instance
// validate instance ID
char * instanceS ;
2020-12-28 15:12:57 +00:00
uint64_t instance = std : : strtoll ( args [ 1 ] . c_str ( ) , & instanceS , 10 ) ;
2020-10-12 01:53:01 +00:00
if ( * instanceS ) {
ChatManager : : sendServerMessage ( sock , " [INST] Invalid instance ID: " + args [ 1 ] ) ;
return ;
}
2020-12-28 15:12:57 +00:00
if ( args . size ( ) > = 3 ) {
char * playeridS ;
uint64_t playerid = std : : strtoll ( args [ 2 ] . c_str ( ) , & playeridS , 10 ) ;
if ( playerid ! = 0 ) {
instance | = playerid < < 32ULL ;
ChunkManager : : createInstance ( instance ) ;
// a precaution
plr - > recallInstance = 0 ;
}
}
2020-10-12 01:53:01 +00:00
PlayerManager : : sendPlayerTo ( sock , plr - > x , plr - > y , plr - > z , instance ) ;
ChatManager : : sendServerMessage ( sock , " [INST] Switched to instance with ID " + std : : to_string ( instance ) ) ;
}
void npcInstanceCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
2020-11-17 23:16:16 +00:00
Player * plr = PlayerManager : : getPlayer ( sock ) ;
2020-10-12 01:53:01 +00:00
if ( args . size ( ) < 2 ) {
ChatManager : : sendServerMessage ( sock , " [NPCI] Instance ID must be specified " ) ;
ChatManager : : sendServerMessage ( sock , " [NPCI] Usage: /npci <instance ID> " ) ;
return ;
}
2020-11-23 00:14:46 +00:00
BaseNPC * npc = NPCManager : : getNearestNPC ( plr - > viewableChunks , plr - > x , plr - > y , plr - > z ) ;
2020-10-12 01:53:01 +00:00
if ( npc = = nullptr ) {
ChatManager : : sendServerMessage ( sock , " [NPCI] No NPCs found nearby " ) ;
return ;
}
// validate instance ID
char * instanceS ;
int instance = std : : strtol ( args [ 1 ] . c_str ( ) , & instanceS , 10 ) ;
if ( * instanceS ) {
ChatManager : : sendServerMessage ( sock , " [NPCI] Invalid instance ID: " + args [ 1 ] ) ;
return ;
}
ChatManager : : sendServerMessage ( sock , " [NPCI] Moving NPC with ID " + std : : to_string ( npc - > appearanceData . iNPC_ID ) + " to instance " + std : : to_string ( instance ) ) ;
TableData : : RunningNPCMapNumbers [ npc - > appearanceData . iNPC_ID ] = instance ;
2020-11-18 00:07:04 +00:00
NPCManager : : updateNPCPosition ( npc - > appearanceData . iNPC_ID , npc - > appearanceData . iX , npc - > appearanceData . iY , npc - > appearanceData . iZ , instance , npc - > appearanceData . iAngle ) ;
2020-10-12 01:53:01 +00:00
}
2020-10-18 21:02:51 +00:00
void minfoCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
Player * plr = PlayerManager : : getPlayer ( sock ) ;
ChatManager : : sendServerMessage ( sock , " [MINFO] Current mission ID: " + std : : to_string ( plr - > CurrentMissionID ) ) ;
for ( int i = 0 ; i < ACTIVE_MISSION_COUNT ; i + + ) {
if ( plr - > tasks [ i ] ! = 0 ) {
TaskData & task = * MissionManager : : Tasks [ plr - > tasks [ i ] ] ;
if ( ( int ) ( task [ " m_iHMissionID " ] ) = = plr - > CurrentMissionID ) {
ChatManager : : sendServerMessage ( sock , " [MINFO] Current task ID: " + std : : to_string ( plr - > tasks [ i ] ) ) ;
ChatManager : : sendServerMessage ( sock , " [MINFO] Current task type: " + std : : to_string ( ( int ) ( task [ " m_iHTaskType " ] ) ) ) ;
ChatManager : : sendServerMessage ( sock , " [MINFO] Current waypoint NPC ID: " + std : : to_string ( ( int ) ( task [ " m_iSTGrantWayPoint " ] ) ) ) ;
2020-10-21 05:24:51 +00:00
ChatManager : : sendServerMessage ( sock , " [MINFO] Current terminator NPC ID: " + std : : to_string ( ( int ) ( task [ " m_iHTerminatorNPCID " ] ) ) ) ;
2020-10-18 21:02:51 +00:00
2020-11-29 01:43:42 +00:00
if ( ( int ) ( task [ " m_iSTGrantTimer " ] ) ! = 0 )
ChatManager : : sendServerMessage ( sock , " [MINFO] Current task timer: " + std : : to_string ( ( int ) ( task [ " m_iSTGrantTimer " ] ) ) ) ;
2020-10-18 21:02:51 +00:00
for ( int j = 0 ; j < 3 ; j + + )
if ( ( int ) ( task [ " m_iCSUEnemyID " ] [ j ] ) ! = 0 )
ChatManager : : sendServerMessage ( sock , " [MINFO] Current task mob # " + std : : to_string ( j + 1 ) + " : " + std : : to_string ( ( int ) ( task [ " m_iCSUEnemyID " ] [ j ] ) ) ) ;
return ;
}
}
}
}
void tasksCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
Player * plr = PlayerManager : : getPlayer ( sock ) ;
for ( int i = 0 ; i < ACTIVE_MISSION_COUNT ; i + + ) {
if ( plr - > tasks [ i ] ! = 0 ) {
TaskData & task = * MissionManager : : Tasks [ plr - > tasks [ i ] ] ;
ChatManager : : sendServerMessage ( sock , " [TASK- " + std : : to_string ( i ) + " ] mission ID: " + std : : to_string ( ( int ) ( task [ " m_iHMissionID " ] ) ) ) ;
ChatManager : : sendServerMessage ( sock , " [TASK- " + std : : to_string ( i ) + " ] task ID: " + std : : to_string ( plr - > tasks [ i ] ) ) ;
}
}
}
2020-10-22 08:23:12 +00:00
void buffCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
if ( args . size ( ) < 3 ) {
ChatManager : : sendServerMessage ( sock , " /buff: no skill Id and duration time specified " ) ;
return ;
}
char * tmp ;
int skillId = std : : strtol ( args [ 1 ] . c_str ( ) , & tmp , 10 ) ;
if ( * tmp )
return ;
int duration = std : : strtol ( args [ 2 ] . c_str ( ) , & tmp , 10 ) ;
if ( * tmp )
return ;
2021-01-06 11:55:55 +00:00
if ( NPCManager : : eggBuffPlayer ( sock , skillId , 0 , duration ) < 0 )
2020-10-22 08:23:12 +00:00
ChatManager : : sendServerMessage ( sock , " /buff: unknown skill Id " ) ;
}
2020-11-09 10:04:30 +00:00
void eggCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
if ( args . size ( ) < 2 ) {
ChatManager : : sendServerMessage ( sock , " /egg: no egg type specified " ) ;
return ;
}
char * tmp ;
int eggType = std : : strtol ( args [ 1 ] . c_str ( ) , & tmp , 10 ) ;
if ( * tmp )
return ;
if ( NPCManager : : EggTypes . find ( eggType ) = = NPCManager : : EggTypes . end ( ) ) {
ChatManager : : sendServerMessage ( sock , " /egg: Unknown egg type " ) ;
return ;
}
assert ( NPCManager : : nextId < INT32_MAX ) ;
int id = NPCManager : : nextId + + ;
Player * plr = PlayerManager : : getPlayer ( sock ) ;
// some math to place egg nicely in front of the player
// temporarly disabled for sake of gruntwork
int addX = 0 ; //-500.0f * sin(plr->angle / 180.0f * M_PI);
int addY = 0 ; //-500.0f * cos(plr->angle / 180.0f * M_PI);
Egg * egg = new Egg ( plr - > x + addX , plr - > y + addY , plr - > z , plr - > instanceID , eggType , id , false ) ; // change last arg to true after gruntwork
NPCManager : : NPCs [ id ] = egg ;
NPCManager : : Eggs [ id ] = egg ;
2020-11-18 00:07:04 +00:00
NPCManager : : updateNPCPosition ( id , plr - > x + addX , plr - > y + addY , plr - > z , plr - > instanceID , plr - > angle ) ;
2020-11-09 10:04:30 +00:00
// add to template
TableData : : RunningEggs [ id ] = egg ;
}
2020-10-31 17:12:13 +00:00
void notifyCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
Player * plr = PlayerManager : : getPlayer ( sock ) ;
if ( plr - > notify ) {
2020-11-16 03:13:40 +00:00
plr - > notify = false ;
ChatManager : : sendServerMessage ( sock , " [ADMIN] No longer receiving join notifications " ) ;
2020-10-31 17:12:13 +00:00
} else {
2020-11-16 03:13:40 +00:00
plr - > notify = true ;
ChatManager : : sendServerMessage ( sock , " [ADMIN] Receiving join notifications " ) ;
2020-10-31 17:12:13 +00:00
}
}
void playersCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
ChatManager : : sendServerMessage ( sock , " [ADMIN] Players on the server: " ) ;
for ( auto pair : PlayerManager : : players )
2020-11-17 23:16:16 +00:00
ChatManager : : sendServerMessage ( sock , PlayerManager : : getPlayerName ( pair . second ) ) ;
2020-10-31 17:12:13 +00:00
}
2020-11-16 03:13:40 +00:00
void summonGroupCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
2020-11-15 18:19:34 +00:00
if ( args . size ( ) < 4 ) {
2020-11-16 03:13:40 +00:00
ChatManager : : sendServerMessage ( sock , " /summonGroup(W) <leadermob> <mob> <number> [distance] " ) ;
2020-11-15 18:19:34 +00:00
return ;
}
Player * plr = PlayerManager : : getPlayer ( sock ) ;
char * rest ;
2020-11-16 03:13:40 +00:00
bool wCommand = ( args [ 0 ] = = " /summonGroupW " ) ;
2020-11-15 18:19:34 +00:00
int type = std : : strtol ( args [ 1 ] . c_str ( ) , & rest , 10 ) ;
int type2 = std : : strtol ( args [ 2 ] . c_str ( ) , & rest , 10 ) ;
int count = std : : strtol ( args [ 3 ] . c_str ( ) , & rest , 10 ) ;
int distance = 150 ;
if ( args . size ( ) > 4 )
distance = std : : strtol ( args [ 4 ] . c_str ( ) , & rest , 10 ) ;
if ( * rest ) {
ChatManager : : sendServerMessage ( sock , " Invalid NPC number: " + args [ 1 ] ) ;
return ;
}
2020-12-21 00:57:56 +00:00
int limit = NPCManager : : NPCData . back ( ) [ " m_iNpcNumber " ] ;
2020-11-15 18:19:34 +00:00
// permission & sanity check
2020-12-21 00:57:56 +00:00
if ( type > limit | | type2 > limit | | count > 5 ) {
2020-11-23 00:14:46 +00:00
ChatManager : : sendServerMessage ( sock , " Invalid parameters; double check types and count " ) ;
2020-11-15 18:19:34 +00:00
return ;
2020-11-23 00:14:46 +00:00
}
2020-11-15 18:19:34 +00:00
Mob * leadNpc = nullptr ;
for ( int i = 0 ; i < count ; i + + ) {
int team = NPCManager : : NPCData [ type ] [ " m_iTeam " ] ;
int x = plr - > x ;
int y = plr - > y ;
int z = plr - > z ;
2020-12-15 22:15:39 +00:00
2020-11-15 18:19:34 +00:00
if ( i > 0 ) {
int angle = 360.0f / ( count - 1 ) * ( i - 1 ) ;
if ( count = = 3 )
angle = 90 + 60 * i ;
angle + = ( plr - > angle + 180 ) % 360 ;
x + = - 1.0f * sin ( angle / 180.0f * M_PI ) * distance ;
y + = - 1.0f * cos ( angle / 180.0f * M_PI ) * distance ;
z = plr - > z ;
}
2020-12-15 22:15:39 +00:00
BaseNPC * npc = NPCManager : : summonNPC ( x , y , z , plr - > instanceID , type , wCommand ) ;
if ( team = = 2 & & i > 0 ) {
leadNpc - > groupMember [ i - 1 ] = npc - > appearanceData . iNPC_ID ;
Mob * mob = MobManager : : Mobs [ npc - > appearanceData . iNPC_ID ] ;
mob - > groupLeader = leadNpc - > appearanceData . iNPC_ID ;
mob - > offsetX = x - plr - > x ;
mob - > offsetY = y - plr - > y ;
2020-11-15 18:19:34 +00:00
}
npc - > appearanceData . iAngle = ( plr - > angle + 180 ) % 360 ;
2020-11-23 00:14:46 +00:00
NPCManager : : updateNPCPosition ( npc - > appearanceData . iNPC_ID , x , y , z , plr - > instanceID , npc - > appearanceData . iAngle ) ;
2020-11-15 18:19:34 +00:00
// if we're in a lair, we need to spawn the NPC in both the private instance and the template
if ( PLAYERID ( plr - > instanceID ) ! = 0 ) {
2020-12-15 22:15:39 +00:00
npc = NPCManager : : summonNPC ( plr - > x , plr - > y , plr - > z , plr - > instanceID , type , wCommand , true ) ;
2020-11-15 18:19:34 +00:00
2020-12-15 22:15:39 +00:00
if ( team = = 2 & & i > 0 ) {
leadNpc - > groupMember [ i - 1 ] = npc - > appearanceData . iNPC_ID ;
Mob * mob = MobManager : : Mobs [ npc - > appearanceData . iNPC_ID ] ;
mob - > groupLeader = leadNpc - > appearanceData . iNPC_ID ;
mob - > offsetX = x - plr - > x ;
mob - > offsetY = y - plr - > y ;
2020-11-15 18:19:34 +00:00
}
npc - > appearanceData . iAngle = ( plr - > angle + 180 ) % 360 ;
2020-11-23 00:14:46 +00:00
NPCManager : : updateNPCPosition ( npc - > appearanceData . iNPC_ID , x , y , z , plr - > instanceID , npc - > appearanceData . iAngle ) ;
2020-11-15 18:19:34 +00:00
}
2020-11-16 03:13:40 +00:00
ChatManager : : sendServerMessage ( sock , " /summonGroup(W): placed mob with type: " + std : : to_string ( type ) +
2020-11-15 18:19:34 +00:00
" , id: " + std : : to_string ( npc - > appearanceData . iNPC_ID ) ) ;
if ( i = = 0 & & team = = 2 ) {
type = type2 ;
leadNpc = MobManager : : Mobs [ npc - > appearanceData . iNPC_ID ] ;
leadNpc - > groupLeader = leadNpc - > appearanceData . iNPC_ID ;
}
}
2020-11-25 15:41:10 +00:00
if ( ! wCommand )
return ; // not writing; don't add to running mobs
if ( leadNpc = = nullptr ) {
std : : cout < < " /summonGroupW: can't find group leader! Won't be saved! \n " ;
return ;
}
TableData : : RunningGroups [ leadNpc - > appearanceData . iNPC_ID ] = leadNpc ; // only record the leader
2020-11-15 18:19:34 +00:00
}
2020-10-06 19:53:21 +00:00
void flushCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
TableData : : flush ( ) ;
2020-10-07 17:29:59 +00:00
ChatManager : : sendServerMessage ( sock , " Wrote gruntwork to " + settings : : GRUNTWORKJSON ) ;
2020-10-06 19:53:21 +00:00
}
2020-11-26 13:59:16 +00:00
void whoisCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
Player * plr = PlayerManager : : getPlayer ( sock ) ;
BaseNPC * npc = NPCManager : : getNearestNPC ( plr - > viewableChunks , plr - > x , plr - > y , plr - > z ) ;
if ( npc = = nullptr ) {
ChatManager : : sendServerMessage ( sock , " [WHOIS] No NPCs found nearby " ) ;
return ;
}
ChatManager : : sendServerMessage ( sock , " [WHOIS] ID: " + std : : to_string ( npc - > appearanceData . iNPC_ID ) ) ;
ChatManager : : sendServerMessage ( sock , " [WHOIS] Type: " + std : : to_string ( npc - > appearanceData . iNPCType ) ) ;
ChatManager : : sendServerMessage ( sock , " [WHOIS] HP: " + std : : to_string ( npc - > appearanceData . iHP ) ) ;
ChatManager : : sendServerMessage ( sock , " [WHOIS] CBF: " + std : : to_string ( npc - > appearanceData . iConditionBitFlag ) ) ;
ChatManager : : sendServerMessage ( sock , " [WHOIS] Class: " + std : : to_string ( npc - > npcClass ) ) ;
ChatManager : : sendServerMessage ( sock , " [WHOIS] X: " + std : : to_string ( npc - > appearanceData . iX ) ) ;
ChatManager : : sendServerMessage ( sock , " [WHOIS] Y: " + std : : to_string ( npc - > appearanceData . iY ) ) ;
ChatManager : : sendServerMessage ( sock , " [WHOIS] Z: " + std : : to_string ( npc - > appearanceData . iZ ) ) ;
ChatManager : : sendServerMessage ( sock , " [WHOIS] Angle: " + std : : to_string ( npc - > appearanceData . iAngle ) ) ;
std : : string chunkPosition = std : : to_string ( std : : get < 0 > ( npc - > chunkPos ) ) + " , " + std : : to_string ( std : : get < 1 > ( npc - > chunkPos ) ) + " , " + std : : to_string ( std : : get < 2 > ( npc - > chunkPos ) ) ;
ChatManager : : sendServerMessage ( sock , " [WHOIS] Chunk: { " + chunkPosition + " } " ) ;
ChatManager : : sendServerMessage ( sock , " [WHOIS] MapNum: " + std : : to_string ( MAPNUM ( npc - > instanceID ) ) ) ;
ChatManager : : sendServerMessage ( sock , " [WHOIS] Instance: " + std : : to_string ( PLAYERID ( npc - > instanceID ) ) ) ;
}
2020-12-02 23:29:21 +00:00
void lairUnlockCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
2020-11-30 16:59:39 +00:00
Player * plr = PlayerManager : : getPlayer ( sock ) ;
if ( ! ChunkManager : : chunkExists ( plr - > chunkPos ) )
return ;
Chunk * chnk = ChunkManager : : chunks [ plr - > chunkPos ] ;
int taskID = - 1 ;
int missionID = - 1 ;
int found = 0 ;
for ( int32_t id : chnk - > NPCs ) {
if ( NPCManager : : NPCs . find ( id ) = = NPCManager : : NPCs . end ( ) )
continue ;
BaseNPC * npc = NPCManager : : NPCs [ id ] ;
for ( auto it = NPCManager : : Warps . begin ( ) ; it ! = NPCManager : : Warps . end ( ) ; it + + ) {
if ( ( * it ) . second . npcID = = npc - > appearanceData . iNPCType ) {
taskID = ( * it ) . second . limitTaskID ;
missionID = MissionManager : : Tasks [ taskID ] - > task [ " m_iHMissionID " ] ;
found + + ;
break ;
}
}
}
if ( missionID = = - 1 | | taskID = = - 1 ) {
ChatManager : : sendServerMessage ( sock , " You are NOT standing near a lair portal; move around and try again! " ) ;
return ;
}
if ( found > 1 ) {
ChatManager : : sendServerMessage ( sock , " More than one lair found; decrease chunk size and try again! " ) ;
return ;
}
INITSTRUCT ( sP_FE2CL_REP_PC_TASK_START_SUCC , taskResp ) ;
2020-12-22 21:18:46 +00:00
MissionManager : : startTask ( plr , taskID ) ;
2020-11-30 16:59:39 +00:00
taskResp . iTaskNum = taskID ;
taskResp . iRemainTime = 0 ;
sock - > sendPacket ( ( void * ) & taskResp , P_FE2CL_REP_PC_TASK_START_SUCC , sizeof ( sP_FE2CL_REP_PC_TASK_START_SUCC ) ) ;
INITSTRUCT ( sP_FE2CL_REP_PC_SET_CURRENT_MISSION_ID , missionResp ) ;
missionResp . iCurrentMissionID = missionID ;
plr - > CurrentMissionID = missionID ;
sock - > sendPacket ( ( void * ) & missionResp , P_FE2CL_REP_PC_SET_CURRENT_MISSION_ID , sizeof ( sP_FE2CL_REP_PC_SET_CURRENT_MISSION_ID ) ) ;
}
2020-12-04 12:04:59 +00:00
void hideCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
Player * plr = PlayerManager : : getPlayer ( sock ) ;
if ( plr - > hidden ) {
ChatManager : : sendServerMessage ( sock , " [HIDE] You're already hidden from the map. " ) ;
return ;
}
plr - > hidden = true ;
ChatManager : : sendServerMessage ( sock , " [HIDE] Successfully hidden from the map. " ) ;
}
void unhideCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
Player * plr = PlayerManager : : getPlayer ( sock ) ;
if ( ! plr - > hidden ) {
ChatManager : : sendServerMessage ( sock , " [HIDE] You're already visible from the map. " ) ;
return ;
}
plr - > hidden = false ;
ChatManager : : sendServerMessage ( sock , " [HIDE] Successfully un-hidden from the map. " ) ;
}
2020-12-17 00:03:38 +00:00
void redeemCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
if ( args . size ( ) < 2 ) {
2020-12-21 22:01:21 +00:00
ChatManager : : sendServerMessage ( sock , " /redeem: No code specified " ) ;
2020-12-17 00:03:38 +00:00
return ;
}
2020-12-23 05:34:42 +00:00
// convert string to all lowercase
const char * codeRaw = args [ 1 ] . c_str ( ) ;
if ( args [ 1 ] . size ( ) > 256 ) { // prevent overflow
ChatManager : : sendServerMessage ( sock , " /redeem: Code too long " ) ;
return ;
}
char buf [ 256 ] ;
for ( int i = 0 ; i < args [ 1 ] . size ( ) ; i + + )
buf [ i ] = std : : tolower ( codeRaw [ i ] ) ;
std : : string code ( buf , args [ 1 ] . size ( ) ) ;
2020-12-17 00:03:38 +00:00
if ( ItemManager : : CodeItems . find ( code ) = = ItemManager : : CodeItems . end ( ) ) {
ChatManager : : sendServerMessage ( sock , " /redeem: Unknown code " ) ;
return ;
}
Player * plr = PlayerManager : : getPlayer ( sock ) ;
2021-01-19 02:44:02 +00:00
if ( Database : : isCodeRedeemed ( plr - > iID , code ) ) {
ChatManager : : sendServerMessage ( sock , " /redeem: You have already redeemed this code item " ) ;
return ;
}
2020-12-21 22:01:21 +00:00
int itemCount = ItemManager : : CodeItems [ code ] . size ( ) ;
2021-03-06 01:09:21 +00:00
std : : vector < int > slots ;
2020-12-17 00:03:38 +00:00
2020-12-21 22:01:21 +00:00
for ( int i = 0 ; i < itemCount ; i + + ) {
2021-03-06 01:09:21 +00:00
slots . push_back ( ItemManager : : findFreeSlot ( plr ) ) ;
2020-12-21 22:01:21 +00:00
if ( slots [ i ] = = - 1 ) {
ChatManager : : sendServerMessage ( sock , " /redeem: Not enough space in inventory " ) ;
2020-12-17 00:03:38 +00:00
2020-12-21 22:01:21 +00:00
// delete any temp items we might have set
for ( int j = 0 ; j < i ; j + + ) {
plr - > Inven [ slots [ j ] ] = { 0 , 0 , 0 , 0 } ; // empty
}
return ;
}
2020-12-17 00:03:38 +00:00
2020-12-21 22:01:21 +00:00
plr - > Inven [ slots [ i ] ] = { 999 , 999 , 999 , 0 } ; // temp item; overwritten later
2020-12-17 00:03:38 +00:00
}
2020-12-21 22:01:21 +00:00
2021-01-19 02:44:02 +00:00
Database : : recordCodeRedemption ( plr - > iID , code ) ;
2020-12-21 22:01:21 +00:00
for ( int i = 0 ; i < itemCount ; i + + ) {
std : : pair < int32_t , int32_t > item = ItemManager : : CodeItems [ code ] [ i ] ;
INITSTRUCT ( sP_FE2CL_REP_PC_GIVE_ITEM_SUCC , resp ) ;
2020-12-17 00:03:38 +00:00
2020-12-21 22:01:21 +00:00
resp . eIL = 1 ;
resp . iSlotNum = slots [ i ] ;
resp . Item . iID = item . first ;
resp . Item . iType = item . second ;
// I think it is safe? :eyes
resp . Item . iOpt = 1 ;
2020-12-17 00:03:38 +00:00
2020-12-21 22:01:21 +00:00
// save serverside
plr - > Inven [ resp . iSlotNum ] = resp . Item ;
sock - > sendPacket ( ( void * ) & resp , P_FE2CL_REP_PC_GIVE_ITEM_SUCC , sizeof ( sP_FE2CL_REP_PC_GIVE_ITEM_SUCC ) ) ;
}
std : : string msg = itemCount = = 1 ? " You have redeemed a code item " : " You have redeemed code items " ;
ChatManager : : sendServerMessage ( sock , msg ) ;
2020-12-17 00:03:38 +00:00
}
2020-12-28 15:24:24 +00:00
void unwarpableCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
Player * plr = PlayerManager : : getPlayer ( sock ) ;
plr - > unwarpable = true ;
}
void warpableCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
Player * plr = PlayerManager : : getPlayer ( sock ) ;
plr - > unwarpable = false ;
}
2021-01-05 11:43:11 +00:00
void registerallCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
Player * plr = PlayerManager : : getPlayer ( sock ) ;
plr - > iWarpLocationFlag = UINT32_MAX ;
plr - > aSkywayLocationFlag [ 0 ] = UINT64_MAX ;
plr - > aSkywayLocationFlag [ 1 ] = UINT64_MAX ;
// update the client
INITSTRUCT ( sP_FE2CL_REP_PC_REGIST_TRANSPORTATION_LOCATION_SUCC , resp ) ;
resp . iWarpLocationFlag = plr - > iWarpLocationFlag ;
resp . aWyvernLocationFlag [ 0 ] = plr - > aSkywayLocationFlag [ 0 ] ;
resp . aWyvernLocationFlag [ 1 ] = plr - > aSkywayLocationFlag [ 1 ] ;
sock - > sendPacket ( ( void * ) & resp , P_FE2CL_REP_PC_REGIST_TRANSPORTATION_LOCATION_SUCC , sizeof ( sP_FE2CL_REP_PC_REGIST_TRANSPORTATION_LOCATION_SUCC ) ) ;
}
void unregisterallCommand ( std : : string full , std : : vector < std : : string > & args , CNSocket * sock ) {
Player * plr = PlayerManager : : getPlayer ( sock ) ;
plr - > iWarpLocationFlag = 0 ;
plr - > aSkywayLocationFlag [ 0 ] = 0 ;
plr - > aSkywayLocationFlag [ 1 ] = 0 ;
// update the client
INITSTRUCT ( sP_FE2CL_REP_PC_REGIST_TRANSPORTATION_LOCATION_SUCC , resp ) ;
resp . iWarpLocationFlag = plr - > iWarpLocationFlag ;
resp . aWyvernLocationFlag [ 0 ] = plr - > aSkywayLocationFlag [ 0 ] ;
resp . aWyvernLocationFlag [ 1 ] = plr - > aSkywayLocationFlag [ 1 ] ;
sock - > sendPacket ( ( void * ) & resp , P_FE2CL_REP_PC_REGIST_TRANSPORTATION_LOCATION_SUCC , sizeof ( sP_FE2CL_REP_PC_REGIST_TRANSPORTATION_LOCATION_SUCC ) ) ;
}
2020-08-18 20:42:30 +00:00
void ChatManager : : init ( ) {
REGISTER_SHARD_PACKET ( P_CL2FE_REQ_SEND_FREECHAT_MESSAGE , chatHandler ) ;
REGISTER_SHARD_PACKET ( P_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT , emoteHandler ) ;
2020-08-22 18:11:47 +00:00
REGISTER_SHARD_PACKET ( P_CL2FE_REQ_SEND_MENUCHAT_MESSAGE , menuChatHandler ) ;
2020-11-19 16:19:22 +00:00
REGISTER_SHARD_PACKET ( P_CL2FE_GM_REQ_PC_ANNOUNCE , announcementHandler ) ;
2020-10-02 23:50:47 +00:00
2020-10-18 20:43:22 +00:00
registerCommand ( " help " , 100 , helpCommand , " list all unlocked server-side commands " ) ;
registerCommand ( " access " , 100 , accessCommand , " print your access level " ) ;
registerCommand ( " instance " , 30 , instanceCommand , " print or change your current instance " ) ;
registerCommand ( " mss " , 30 , mssCommand , " edit Monkey Skyway routes " ) ;
registerCommand ( " npcr " , 30 , npcRotateCommand , " rotate NPCs " ) ;
registerCommand ( " npci " , 30 , npcInstanceCommand , " move NPCs across instances " ) ;
registerCommand ( " summonW " , 30 , summonWCommand , " permanently summon NPCs " ) ;
registerCommand ( " unsummonW " , 30 , unsummonWCommand , " delete permanently summoned NPCs " ) ;
registerCommand ( " toggleai " , 30 , toggleAiCommand , " enable/disable mob AI " ) ;
registerCommand ( " flush " , 30 , flushCommand , " save gruntwork to file " ) ;
registerCommand ( " level " , 50 , levelCommand , " change your character's level " ) ;
2020-11-25 22:36:30 +00:00
registerCommand ( " levelx " , 50 , levelCommand , " change your character's level " ) ; // for Academy
2020-10-18 20:43:22 +00:00
registerCommand ( " population " , 100 , populationCommand , " check how many players are online " ) ;
registerCommand ( " refresh " , 100 , refreshCommand , " teleport yourself to your current location " ) ;
2020-10-18 21:02:51 +00:00
registerCommand ( " minfo " , 30 , minfoCommand , " show details of the current mission and task. " ) ;
2020-10-22 08:23:12 +00:00
registerCommand ( " buff " , 50 , buffCommand , " give yourself a buff effect " ) ;
2020-11-09 10:04:30 +00:00
registerCommand ( " egg " , 30 , eggCommand , " summon a coco egg " ) ;
2020-10-18 21:02:51 +00:00
registerCommand ( " tasks " , 30 , tasksCommand , " list all active missions and their respective task ids. " ) ;
2020-10-31 17:12:13 +00:00
registerCommand ( " notify " , 30 , notifyCommand , " receive a message whenever a player joins the server " ) ;
registerCommand ( " players " , 30 , playersCommand , " print all players on the server " ) ;
2020-11-16 03:13:40 +00:00
registerCommand ( " summonGroup " , 30 , summonGroupCommand , " summon group NPCs " ) ;
registerCommand ( " summonGroupW " , 30 , summonGroupCommand , " permanently summon group NPCs " ) ;
2020-11-26 13:59:16 +00:00
registerCommand ( " whois " , 50 , whoisCommand , " describe nearest NPC " ) ;
2020-12-02 23:29:21 +00:00
registerCommand ( " lair " , 50 , lairUnlockCommand , " get the required mission for the nearest fusion lair " ) ;
2020-12-04 12:04:59 +00:00
registerCommand ( " hide " , 100 , hideCommand , " hide yourself from the global player map " ) ;
registerCommand ( " unhide " , 100 , unhideCommand , " un-hide yourself from the global player map " ) ;
2020-12-28 15:24:24 +00:00
registerCommand ( " unwarpable " , 100 , unwarpableCommand , " prevent buddies from warping to you " ) ;
registerCommand ( " warpable " , 100 , warpableCommand , " re-allow buddies to warp to you " ) ;
2021-01-05 11:43:11 +00:00
registerCommand ( " registerall " , 50 , registerallCommand , " register all SCAMPER and MSS destinations " ) ;
registerCommand ( " unregisterall " , 50 , unregisterallCommand , " clear all SCAMPER and MSS destinations " ) ;
2020-12-17 00:03:38 +00:00
registerCommand ( " redeem " , 100 , redeemCommand , " redeem a code item " ) ;
2020-10-02 23:50:47 +00:00
}
2020-10-12 07:08:10 +00:00
void ChatManager : : registerCommand ( std : : string cmd , int requiredLevel , CommandHandler handlr , std : : string help ) {
commands [ cmd ] = ChatCommand ( requiredLevel , handlr , help ) ;
2020-08-18 20:42:30 +00:00
}
void ChatManager : : chatHandler ( CNSocket * sock , CNPacketData * data ) {
2020-08-20 23:50:30 +00:00
if ( data - > size ! = sizeof ( sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE ) )
return ; // malformed packet
2020-10-05 00:03:13 +00:00
2020-08-18 20:42:30 +00:00
sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE * chat = ( sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE * ) data - > buf ;
2020-10-02 23:50:47 +00:00
Player * plr = PlayerManager : : getPlayer ( sock ) ;
2020-10-31 20:31:25 +00:00
std : : string fullChat = sanitizeText ( U16toU8 ( chat - > szFreeChat ) ) ;
2020-10-03 00:20:59 +00:00
if ( fullChat . length ( ) > 1 & & fullChat [ 0 ] = = CMD_PREFIX ) { // PREFIX
runCmd ( fullChat , sock ) ;
2020-10-02 23:50:47 +00:00
return ;
}
2020-08-19 18:22:51 +00:00
2020-12-31 01:13:43 +00:00
if ( plr - > iSpecialState & CN_SPECIAL_STATE_FLAG__MUTE_FREECHAT )
return ;
std : : string logLine = " [FreeChat] " + PlayerManager : : getPlayerName ( plr , true ) + " : " + fullChat ;
std : : cout < < logLine < < std : : endl ;
dump . push_back ( logLine ) ;
2020-08-19 18:25:54 +00:00
// send to client
2020-08-23 00:26:18 +00:00
INITSTRUCT ( sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC , resp ) ;
2020-10-31 20:31:25 +00:00
U8toU16 ( fullChat , ( char16_t * ) & resp . szFreeChat , sizeof ( resp . szFreeChat ) ) ;
2020-10-02 23:50:47 +00:00
resp . iPC_ID = plr - > iID ;
2020-08-22 23:31:09 +00:00
resp . iEmoteCode = chat - > iEmoteCode ;
2020-10-31 20:31:25 +00:00
2020-08-22 23:31:09 +00:00
sock - > sendPacket ( ( void * ) & resp , P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC , sizeof ( sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC ) ) ;
2020-08-19 18:22:51 +00:00
2020-08-19 18:25:54 +00:00
// send to visible players
2020-09-17 22:45:43 +00:00
PlayerManager : : sendToViewable ( sock , ( void * ) & resp , P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC , sizeof ( sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC ) ) ;
2020-08-18 20:42:30 +00:00
}
2020-09-16 19:46:15 +00:00
2020-08-22 18:11:47 +00:00
void ChatManager : : menuChatHandler ( CNSocket * sock , CNPacketData * data ) {
if ( data - > size ! = sizeof ( sP_CL2FE_REQ_SEND_MENUCHAT_MESSAGE ) )
return ; // malformed packet
2020-10-31 20:31:25 +00:00
2020-08-22 18:11:47 +00:00
sP_CL2FE_REQ_SEND_MENUCHAT_MESSAGE * chat = ( sP_CL2FE_REQ_SEND_MENUCHAT_MESSAGE * ) data - > buf ;
2020-10-31 20:31:25 +00:00
Player * plr = PlayerManager : : getPlayer ( sock ) ;
std : : string fullChat = sanitizeText ( U16toU8 ( chat - > szFreeChat ) ) ;
2020-12-31 01:13:43 +00:00
std : : string logLine = " [MenuChat] " + PlayerManager : : getPlayerName ( plr , true ) + " : " + fullChat ;
2020-10-31 20:31:25 +00:00
2020-12-31 01:13:43 +00:00
std : : cout < < logLine < < std : : endl ;
dump . push_back ( logLine ) ;
2020-08-22 18:11:47 +00:00
// send to client
2020-08-23 00:26:18 +00:00
INITSTRUCT ( sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC , resp ) ;
2020-10-31 20:31:25 +00:00
U8toU16 ( fullChat , ( char16_t * ) & resp . szFreeChat , sizeof ( resp . szFreeChat ) ) ;
2020-11-17 23:16:16 +00:00
resp . iPC_ID = PlayerManager : : getPlayer ( sock ) - > iID ;
2020-08-22 23:31:09 +00:00
resp . iEmoteCode = chat - > iEmoteCode ;
2020-10-31 20:31:25 +00:00
2020-08-22 23:31:09 +00:00
sock - > sendPacket ( ( void * ) & resp , P_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC , sizeof ( sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC ) ) ;
2020-08-18 20:42:30 +00:00
2020-08-22 18:11:47 +00:00
// send to visible players
2020-09-17 22:45:43 +00:00
PlayerManager : : sendToViewable ( sock , ( void * ) & resp , P_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC , sizeof ( sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC ) ) ;
2020-08-22 18:11:47 +00:00
}
2020-09-16 19:46:15 +00:00
2020-08-18 20:42:30 +00:00
void ChatManager : : emoteHandler ( CNSocket * sock , CNPacketData * data ) {
2020-08-19 00:11:31 +00:00
if ( data - > size ! = sizeof ( sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT ) )
return ; // ignore the malformed packet
2020-08-18 20:42:30 +00:00
// you can dance with friends!!!!!!!!
sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT * emote = ( sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT * ) data - > buf ;
2020-10-02 23:50:47 +00:00
Player * plr = PlayerManager : : getPlayer ( sock ) ;
2020-09-14 13:53:48 +00:00
2020-08-18 20:42:30 +00:00
// send to client
2020-08-23 00:26:18 +00:00
INITSTRUCT ( sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT , resp ) ;
2020-08-22 23:31:09 +00:00
resp . iEmoteCode = emote - > iEmoteCode ;
2020-10-02 23:50:47 +00:00
resp . iID_From = plr - > iID ;
2020-08-22 23:31:09 +00:00
sock - > sendPacket ( ( void * ) & resp , P_FE2CL_REP_PC_AVATAR_EMOTES_CHAT , sizeof ( sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT ) ) ;
2020-08-18 20:42:30 +00:00
// send to visible players (players within render distance)
2020-09-17 22:45:43 +00:00
PlayerManager : : sendToViewable ( sock , ( void * ) & resp , P_FE2CL_REP_PC_AVATAR_EMOTES_CHAT , sizeof ( sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT ) ) ;
2020-08-18 20:42:30 +00:00
}
2020-10-02 23:50:47 +00:00
void ChatManager : : sendServerMessage ( CNSocket * sock , std : : string msg ) {
INITSTRUCT ( sP_FE2CL_PC_MOTD_LOGIN , motd ) ;
motd . iType = 1 ;
2020-10-04 17:52:16 +00:00
// convert string to u16 and write it to the buffer
2020-10-04 17:50:58 +00:00
U8toU16 ( msg , ( char16_t * ) motd . szSystemMsg , sizeof ( motd . szSystemMsg ) ) ;
2020-10-02 23:50:47 +00:00
// send the packet :)
sock - > sendPacket ( ( void * ) & motd , P_FE2CL_PC_MOTD_LOGIN , sizeof ( sP_FE2CL_PC_MOTD_LOGIN ) ) ;
}
2020-10-31 20:31:25 +00:00
2020-11-19 16:19:22 +00:00
void ChatManager : : announcementHandler ( CNSocket * sock , CNPacketData * data ) {
if ( data - > size ! = sizeof ( sP_CL2FE_GM_REQ_PC_ANNOUNCE ) )
return ; // ignore malformed packet
2020-11-17 23:16:16 +00:00
Player * plr = PlayerManager : : getPlayer ( sock ) ;
if ( plr - > accountLevel > 30 )
2020-11-19 16:19:22 +00:00
return ; // only players with account level less than 30 (GM) are allowed to use this command
sP_CL2FE_GM_REQ_PC_ANNOUNCE * announcement = ( sP_CL2FE_GM_REQ_PC_ANNOUNCE * ) data - > buf ;
INITSTRUCT ( sP_FE2CL_GM_REP_PC_ANNOUNCE , msg ) ;
msg . iAnnounceType = announcement - > iAnnounceType ;
msg . iDuringTime = announcement - > iDuringTime ;
memcpy ( msg . szAnnounceMsg , announcement - > szAnnounceMsg , sizeof ( msg . szAnnounceMsg ) ) ;
2020-11-17 23:16:16 +00:00
std : : map < CNSocket * , Player * > : : iterator it ;
2020-11-19 16:19:22 +00:00
switch ( announcement - > iAreaType ) {
2020-11-17 23:16:16 +00:00
case 0 : // area (all players in viewable chunks)
2020-12-01 22:32:45 +00:00
sock - > sendPacket ( ( void * ) & msg , P_FE2CL_GM_REP_PC_ANNOUNCE , sizeof ( sP_FE2CL_GM_REP_PC_ANNOUNCE ) ) ;
2020-11-17 23:16:16 +00:00
PlayerManager : : sendToViewable ( sock , ( void * ) & msg , P_FE2CL_GM_REP_PC_ANNOUNCE , sizeof ( sP_FE2CL_GM_REP_PC_ANNOUNCE ) ) ;
break ;
2020-11-19 16:19:22 +00:00
case 1 : // shard
case 2 : // world
2020-12-01 22:32:45 +00:00
break ; // not applicable to OpenFusion
2020-11-17 23:16:16 +00:00
case 3 : // global (all players)
2020-11-19 16:19:22 +00:00
for ( it = PlayerManager : : players . begin ( ) ; it ! = PlayerManager : : players . end ( ) ; it + + ) {
CNSocket * allSock = it - > first ;
allSock - > sendPacket ( ( void * ) & msg , P_FE2CL_GM_REP_PC_ANNOUNCE , sizeof ( sP_FE2CL_GM_REP_PC_ANNOUNCE ) ) ;
}
default :
break ;
}
2020-12-31 01:13:43 +00:00
std : : string logLine = " [Bcast " + std : : to_string ( announcement - > iAreaType ) + " ] " + PlayerManager : : getPlayerName ( plr , false ) + " : " + U16toU8 ( msg . szAnnounceMsg ) ;
std : : cout < < logLine < < std : : endl ;
dump . push_back ( " ** " + logLine + " ** " ) ;
2020-11-19 16:19:22 +00:00
}
2020-10-31 20:31:25 +00:00
// we only allow plain ascii, at least for now
2020-11-29 20:31:54 +00:00
std : : string ChatManager : : sanitizeText ( std : : string text , bool allowNewlines ) {
2020-10-31 20:31:25 +00:00
int i ;
2020-12-19 04:46:38 +00:00
const int BUFSIZE = 512 ;
char buf [ BUFSIZE ] ;
assert ( text . size ( ) < BUFSIZE ) ;
2020-10-31 20:31:25 +00:00
i = 0 ;
for ( char c : text ) {
2020-12-19 04:46:38 +00:00
if ( i > = BUFSIZE - 1 )
2020-10-31 20:31:25 +00:00
break ;
2020-11-29 20:31:54 +00:00
if ( ! allowNewlines & & c = = ' \n ' )
continue ;
2020-12-14 01:52:59 +00:00
if ( ( c > = ' ' & & c < = ' ~ ' ) | | c = = ' \n ' )
2020-10-31 20:31:25 +00:00
buf [ i + + ] = c ;
}
buf [ i ] = 0 ;
return std : : string ( buf ) ;
}