mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-12-22 19:30:05 +00:00
Implement NPC spawning.
Protected by a simplified GM system. Either everyone is a GM (local servers) or nobody is (public servers).
This commit is contained in:
parent
9aa9b76826
commit
b79bc56b31
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ namespace settings {
|
||||
extern std::string NPCJSON;
|
||||
extern std::string WARPJSON;
|
||||
extern std::string GMPASS;
|
||||
extern bool GM;
|
||||
|
||||
void init();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user