From e043be5ca4800aa079264138da74ee250c24a12d Mon Sep 17 00:00:00 2001 From: Filip Maj Date: Sun, 24 Jan 2016 03:10:17 -0500 Subject: [PATCH] Added a way to reset a zone and reload the NPC list. --- FFXIVClassic Map Server/Server.cs | 44 ++++++++---- FFXIVClassic Map Server/WorldManager.cs | 77 +++++++++++++++++++++ FFXIVClassic Map Server/actors/area/Zone.cs | 13 ++++ 3 files changed, 122 insertions(+), 12 deletions(-) diff --git a/FFXIVClassic Map Server/Server.cs b/FFXIVClassic Map Server/Server.cs index 0279ad41..e2d02fd0 100644 --- a/FFXIVClassic Map Server/Server.cs +++ b/FFXIVClassic Map Server/Server.cs @@ -290,13 +290,18 @@ namespace FFXIVClassic_Lobby_Server } public void doWarp(ConnectedPlayer client, string entranceId) - { + { uint id; - if (entranceId.ToLower().StartsWith("0x")) - id = Convert.ToUInt32(entranceId, 16); - else - id = Convert.ToUInt32(entranceId); + try + { + if (entranceId.ToLower().StartsWith("0x")) + id = Convert.ToUInt32(entranceId, 16); + else + id = Convert.ToUInt32(entranceId); + } + catch(FormatException e) + {return;} FFXIVClassic_Map_Server.WorldManager.ZoneEntrance ze = mWorldManager.getZoneEntrance(id); @@ -314,27 +319,34 @@ namespace FFXIVClassic_Lobby_Server } } - public void doWarp(ConnectedPlayer client, string map, string sx, string sy, string sz) + public void doWarp(ConnectedPlayer client, string zone, string sx, string sy, string sz) { - uint mapId; + uint zoneId; float x,y,z; - if (map.ToLower().StartsWith("0x")) - mapId = Convert.ToUInt32(map, 16); + if (zone.ToLower().StartsWith("0x")) + zoneId = Convert.ToUInt32(zone, 16); else - mapId = Convert.ToUInt32(map); + zoneId = Convert.ToUInt32(zone); + if (mWorldManager.GetZone(zoneId) == null) + { + if (client != null) + client.queuePacket(BasePacket.createPacket(SendMessagePacket.buildPacket(client.actorID, client.actorID, SendMessagePacket.MESSAGE_TYPE_GENERAL_INFO, "", "Zone does not exist or setting isn't valid."), true, false)); + Log.error("Zone does not exist or setting isn't valid."); + } + x = Single.Parse(sx); y = Single.Parse(sy); z = Single.Parse(sz); if (client != null) - mWorldManager.DoZoneChange(client.getActor(), mapId, 0x2, x, y, z, 0.0f); + mWorldManager.DoZoneChange(client.getActor(), zoneId, 0x2, x, y, z, 0.0f); else { foreach (KeyValuePair entry in mConnectedPlayerList) { - mWorldManager.DoZoneChange(entry.Value.getActor(), mapId, 0x2, x, y, z, 0.0f); + mWorldManager.DoZoneChange(entry.Value.getActor(), zoneId, 0x2, x, y, z, 0.0f); } } } @@ -364,6 +376,8 @@ namespace FFXIVClassic_Lobby_Server internal void doCommand(string input, ConnectedPlayer client) { + input.Trim(); + String[] split = input.Split(' '); if (split.Length >= 1) @@ -379,6 +393,12 @@ namespace FFXIVClassic_Lobby_Server Log.error("Could not load packet: " + e); } } + else if (split[0].Equals("resetzone")) + { + Log.info(String.Format("Got request to reset zone: {0}", client.getActor().zoneId)); + client.queuePacket(BasePacket.createPacket(SendMessagePacket.buildPacket(client.actorID, client.actorID, SendMessagePacket.MESSAGE_TYPE_GENERAL_INFO, "", String.Format("Resting zone {0}...", client.getActor().zoneId)), true, false)); + mWorldManager.reloadZone(client.getActor().zoneId); + } } if (split.Length >= 2) { diff --git a/FFXIVClassic Map Server/WorldManager.cs b/FFXIVClassic Map Server/WorldManager.cs index 4ae77867..9853cc16 100644 --- a/FFXIVClassic Map Server/WorldManager.cs +++ b/FFXIVClassic Map Server/WorldManager.cs @@ -186,6 +186,72 @@ namespace FFXIVClassic_Map_Server Log.info(String.Format("Loaded {0} npc(s).", count)); } + public void LoadNPCs(uint zoneId) + { + int count = 0; + using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD))) + { + try + { + conn.Open(); + + string query = @" + SELECT + id, + name, + zoneId, + actorTemplateId, + positionX, + positionY, + positionZ, + rotation, + actorState, + animationId, + actorClassName, + eventConditions + FROM server_npclist + WHERE zoneId = @zoneId + "; + + MySqlCommand cmd = new MySqlCommand(query, conn); + cmd.Parameters.AddWithValue("@zoneId", zoneId); + + using (MySqlDataReader reader = cmd.ExecuteReader()) + { + while (reader.Read()) + { + Npc npc = new Npc(reader.GetUInt32(0), reader.GetString(1), reader.GetUInt32(2), reader.GetUInt32(3), reader.GetFloat(4), reader.GetFloat(5), reader.GetFloat(6), reader.GetFloat(7), reader.GetUInt16(8), reader.GetUInt32(9), reader.GetString(10)); + + if (!reader.IsDBNull(11)) + { + string eventConditions = reader.GetString(11); + npc.loadEventConditions(eventConditions); + } + + if (!zoneList.ContainsKey(npc.zoneId)) + continue; + Zone zone = zoneList[npc.zoneId]; + if (zone == null) + continue; + npc.zone = zone; + zone.addActorToZone(npc); + count++; + + } + } + + } + catch (MySqlException e) + { Console.WriteLine(e); } + finally + { + conn.Dispose(); + } + } + + Log.info(String.Format("Loaded {0} npc(s).", count)); + } + //Moves the actor to the new zone if exists. No packets are sent nor position changed. public void DoSeamlessZoneChange(Player player, uint destinationZoneId) { @@ -273,6 +339,17 @@ namespace FFXIVClassic_Map_Server player.sendZoneInPackets(this, 0x1); } + public void reloadZone(uint zoneId) + { + if (!zoneList.ContainsKey(zoneId)) + return; + + Zone zone = zoneList[zoneId]; + zone.clear(); + LoadNPCs(zone.actorId); + + } + public Player GetPCInWorld(string name) { foreach (Zone zone in zoneList.Values) diff --git a/FFXIVClassic Map Server/actors/area/Zone.cs b/FFXIVClassic Map Server/actors/area/Zone.cs index 085da01b..af0a43ef 100644 --- a/FFXIVClassic Map Server/actors/area/Zone.cs +++ b/FFXIVClassic Map Server/actors/area/Zone.cs @@ -268,5 +268,18 @@ namespace FFXIVClassic_Map_Server.Actors return (Player)mActorList[id]; } + public void clear() + { + //Clear All + mActorList.Clear(); + for (int y = 0; y < numYBlocks; y++) + { + for (int x = 0; x < numXBlocks; x++) + { + mActorBlock[x, y].Clear(); + } + } + } + } }