diff --git a/config.ini b/config.ini index 65173ca..a74402a 100644 --- a/config.ini +++ b/config.ini @@ -25,6 +25,8 @@ motd=Welcome to OpenFusion! npcdata=NPCs.json # warp target json data warpdata=warps.json +# is everyone a GM? +gm=true # spawn coordinates (Z is height) # the supplied defaults are at City Hall diff --git a/src/CNLoginServer.cpp b/src/CNLoginServer.cpp index 15a14ce..1570ebc 100644 --- a/src/CNLoginServer.cpp +++ b/src/CNLoginServer.cpp @@ -92,7 +92,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { loginSessions[sock].characters[UID].z = charInfo.iZ; loginSessions[sock].characters[UID].PCStyle = charInfo.sPC_Style; loginSessions[sock].characters[UID].PCStyle2 = charInfo.sPC_Style2; - loginSessions[sock].characters[UID].IsGM = false; + loginSessions[sock].characters[UID].IsGM = settings::GM; for (int i = 0; i < AEQUIP_COUNT; i++) { // setup equips @@ -227,7 +227,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { loginSessions[sock].characters[UID].Equip[2].iType = 2; loginSessions[sock].characters[UID].Equip[3].iID = character->sOn_Item.iEquipFootID; // foot! loginSessions[sock].characters[UID].Equip[3].iType = 3; - loginSessions[sock].characters[UID].IsGM = false; + loginSessions[sock].characters[UID].IsGM = settings::GM; sock->sendPacket((void*)&resp, P_LS2CL_REP_CHAR_CREATE_SUCC, sizeof(sP_LS2CL_REP_CHAR_CREATE_SUCC)); break; diff --git a/src/NPCManager.cpp b/src/NPCManager.cpp index 1cbf973..7685d3e 100644 --- a/src/NPCManager.cpp +++ b/src/NPCManager.cpp @@ -55,7 +55,8 @@ void NPCManager::init() { } - REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_WARP_USE_NPC, npcWarpManager); + REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_WARP_USE_NPC, npcWarpHandler); + REGISTER_SHARD_PACKET(P_CL2FE_REQ_NPC_SUMMON, npcSummonHandler); } void NPCManager::updatePlayerNPCS(CNSocket* sock, PlayerView& view) { @@ -107,8 +108,7 @@ void NPCManager::updatePlayerNPCS(CNSocket* sock, PlayerView& view) { PlayerManager::players[sock].viewableNPCs = view.viewableNPCs; } -void NPCManager::npcWarpManager(CNSocket* sock, CNPacketData* data) -{ +void NPCManager::npcWarpHandler(CNSocket* sock, CNPacketData* data) { if (data->size != sizeof(sP_CL2FE_REQ_PC_WARP_USE_NPC)) return; // malformed packet @@ -127,3 +127,25 @@ void NPCManager::npcWarpManager(CNSocket* sock, CNPacketData* data) sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_WARP_USE_NPC_SUCC, sizeof(sP_FE2CL_REP_PC_WARP_USE_NPC_SUCC)); } + +void NPCManager::npcSummonHandler(CNSocket *sock, CNPacketData *data) { + if (data->size != sizeof(sP_CL2FE_REQ_NPC_SUMMON)) + return; // malformed packet + + sP_CL2FE_REQ_NPC_SUMMON* req = (sP_CL2FE_REQ_NPC_SUMMON*)data->buf; + INITSTRUCT(sP_FE2CL_NPC_ENTER, resp); + Player *plr = PlayerManager::getPlayer(sock); + + // permission & sanity check + if (!plr->IsGM || req->iNPCType >= NPCs.size()) + return; + + resp.NPCAppearanceData.iNPC_ID = rand(); // cpunch-style + resp.NPCAppearanceData.iNPCType = req->iNPCType; + resp.NPCAppearanceData.iHP = 1000; // TODO: placeholder + resp.NPCAppearanceData.iX = plr->x; + resp.NPCAppearanceData.iY = plr->y; + resp.NPCAppearanceData.iZ = plr->z; + + sock->sendPacket((void*)&resp, P_FE2CL_NPC_ENTER, sizeof(sP_FE2CL_NPC_ENTER)); +} diff --git a/src/NPCManager.hpp b/src/NPCManager.hpp index 12f17a3..b6a3c10 100644 --- a/src/NPCManager.hpp +++ b/src/NPCManager.hpp @@ -21,5 +21,6 @@ namespace NPCManager { void init(); void updatePlayerNPCS(CNSocket* sock, PlayerView& plr); - void npcWarpManager(CNSocket* sock, CNPacketData* data); + void npcWarpHandler(CNSocket* sock, CNPacketData* data); + void npcSummonHandler(CNSocket* sock, CNPacketData* data); } diff --git a/src/settings.cpp b/src/settings.cpp index 7564ab5..fcb4606 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -20,6 +20,7 @@ std::string settings::GMPASS = "pass"; std::string settings::NPCJSON = "NPCs.json"; std::string settings::WARPJSON = "warps.json"; std::string settings::MOTDSTRING = "Welcome to OpenFusion!"; +bool settings::GM = false; void settings::init() { INIReader reader("config.ini"); @@ -46,5 +47,5 @@ void settings::init() { NPCJSON = reader.Get("shard", "npcdata", NPCJSON); WARPJSON = reader.Get("shard", "warpdata", WARPJSON); MOTDSTRING = reader.Get("shard", "motd", MOTDSTRING); - + GM = reader.GetBoolean("shard", "gm", GM); } diff --git a/src/settings.hpp b/src/settings.hpp index ac0186e..163939b 100644 --- a/src/settings.hpp +++ b/src/settings.hpp @@ -14,6 +14,7 @@ namespace settings { extern std::string NPCJSON; extern std::string WARPJSON; extern std::string GMPASS; + extern bool GM; void init(); }