Multiple zones are now stored on the server and accessed properly.

This commit is contained in:
Filip Maj 2016-01-17 11:48:55 -05:00
parent 0e85e2bddf
commit d77344b725
6 changed files with 187 additions and 19 deletions

View File

@ -14,6 +14,7 @@ using FFXIVClassic_Lobby_Server.packets;
using FFXIVClassic_Map_Server.packets.send.player; using FFXIVClassic_Map_Server.packets.send.player;
using FFXIVClassic_Lobby_Server.dataobjects; using FFXIVClassic_Lobby_Server.dataobjects;
using FFXIVClassic_Map_Server; using FFXIVClassic_Map_Server;
using FFXIVClassic_Map_Server.common.EfficientHashTables;
namespace FFXIVClassic_Lobby_Server namespace FFXIVClassic_Lobby_Server
{ {
@ -143,7 +144,7 @@ namespace FFXIVClassic_Lobby_Server
player.oldPositionZ = player.positionZ = reader.GetFloat(3); player.oldPositionZ = player.positionZ = reader.GetFloat(3);
player.oldRotation = player.rotation = reader.GetFloat(4); player.oldRotation = player.rotation = reader.GetFloat(4);
player.currentMainState = reader.GetUInt16(5); player.currentMainState = reader.GetUInt16(5);
player.currentZoneId = reader.GetUInt32(6); player.zoneId = reader.GetUInt32(6);
player.charaWork.parameterSave.state_mainSkill[0] = reader.GetByte(7); player.charaWork.parameterSave.state_mainSkill[0] = reader.GetByte(7);
player.gcCurrent = reader.GetByte(8); player.gcCurrent = reader.GetByte(8);
player.gcRankLimsa = reader.GetByte(9); player.gcRankLimsa = reader.GetByte(9);
@ -542,16 +543,15 @@ namespace FFXIVClassic_Lobby_Server
return cheevosPacket.buildPacket(player.actorId); return cheevosPacket.buildPacket(player.actorId);
} }
public static List<Zone> loadZones() public static void loadZones(Efficient32bitHashTable<Zone> zoneList)
{ {
List<Zone> zones = new List<Zone>(); 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))) 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 try
{ {
conn.Open(); conn.Open();
//Load Last 5 Completed
string query = @" string query = @"
SELECT SELECT
id, id,
@ -563,7 +563,7 @@ namespace FFXIVClassic_Lobby_Server
isInn, isInn,
canRideChocobo, canRideChocobo,
canStealth, canStealth,
isInstanceRaid, isInstanceRaid
FROM server_zones FROM server_zones
WHERE zoneName IS NOT NULL"; WHERE zoneName IS NOT NULL";
@ -573,7 +573,8 @@ namespace FFXIVClassic_Lobby_Server
{ {
while (reader.Read()) { while (reader.Read()) {
Zone zone = new Zone(reader.GetUInt32(0), reader.GetString(2), reader.GetUInt16(1), reader.GetUInt16(3), reader.GetUInt16(4), reader.GetUInt16(5), reader.GetBoolean(6), reader.GetBoolean(7), reader.GetBoolean(8), reader.GetBoolean(9)); Zone zone = new Zone(reader.GetUInt32(0), reader.GetString(2), reader.GetUInt16(1), reader.GetUInt16(3), reader.GetUInt16(4), reader.GetUInt16(5), reader.GetBoolean(6), reader.GetBoolean(7), reader.GetBoolean(8), reader.GetBoolean(9));
zones.Add(zone); zoneList.Add(zone.actorId, zone);
count++;
} }
} }
} }
@ -585,7 +586,7 @@ namespace FFXIVClassic_Lobby_Server
} }
} }
return zones; Log.info(String.Format("Loaded {0} zones.", count));
} }
} }

View File

@ -75,6 +75,7 @@
<Compile Include="ClientConnection.cs" /> <Compile Include="ClientConnection.cs" />
<Compile Include="common\Bitfield.cs" /> <Compile Include="common\Bitfield.cs" />
<Compile Include="common\Blowfish.cs" /> <Compile Include="common\Blowfish.cs" />
<Compile Include="common\EfficientHashTables.cs" />
<Compile Include="common\Log.cs" /> <Compile Include="common\Log.cs" />
<Compile Include="common\STA_INIFile.cs" /> <Compile Include="common\STA_INIFile.cs" />
<Compile Include="common\Utils.cs" /> <Compile Include="common\Utils.cs" />

View File

@ -36,6 +36,7 @@ using FFXIVClassic_Map_Server.actors;
using System.Net; using System.Net;
using FFXIVClassic_Map_Server.actors.debug; using FFXIVClassic_Map_Server.actors.debug;
using FFXIVClassic_Map_Server.actors.world; using FFXIVClassic_Map_Server.actors.world;
using FFXIVClassic_Map_Server.common.EfficientHashTables;
namespace FFXIVClassic_Lobby_Server namespace FFXIVClassic_Lobby_Server
{ {
@ -50,14 +51,14 @@ namespace FFXIVClassic_Lobby_Server
DebugProg debug = new DebugProg(); DebugProg debug = new DebugProg();
WorldMaster worldMaster = new WorldMaster(); WorldMaster worldMaster = new WorldMaster();
List<Zone> zoneList; Efficient32bitHashTable<Zone> zoneList = new Efficient32bitHashTable<Zone>();
public PacketProcessor(Dictionary<uint, ConnectedPlayer> playerList, List<ClientConnection> connectionList) public PacketProcessor(Dictionary<uint, ConnectedPlayer> playerList, List<ClientConnection> connectionList)
{ {
mPlayers = playerList; mPlayers = playerList;
mConnections = connectionList; mConnections = connectionList;
zoneList = Database.loadZones(); Database.loadZones(zoneList);
} }
public void processPacket(ClientConnection client, BasePacket packet) public void processPacket(ClientConnection client, BasePacket packet)
@ -189,6 +190,9 @@ namespace FFXIVClassic_Lobby_Server
break; break;
//Unknown //Unknown
case 0x0002: case 0x0002:
player.getActor().zone = zoneList.Get(player.getActor().zoneId);
BasePacket reply9 = new BasePacket("./packets/login/login9_zonesetup.bin"); //Bed, Book created BasePacket reply9 = new BasePacket("./packets/login/login9_zonesetup.bin"); //Bed, Book created
BasePacket reply10 = new BasePacket("./packets/login/login10.bin"); //Item Storage, Inn Door created BasePacket reply10 = new BasePacket("./packets/login/login10.bin"); //Item Storage, Inn Door created
BasePacket reply11 = new BasePacket("./packets/login/login11.bin"); //NPC Create ??? Final init BasePacket reply11 = new BasePacket("./packets/login/login11.bin"); //NPC Create ??? Final init
@ -298,9 +302,9 @@ namespace FFXIVClassic_Lobby_Server
//tpacket.debugPrintPacket(); //tpacket.debugPrintPacket();
client.queuePacket(tpacket); client.queuePacket(tpacket);
inn.addActorToZone(player.getActor()); player.getActor().zone.addActorToZone(player.getActor());
BasePacket innSpawn = inn.getSpawnPackets(player.actorID); BasePacket innSpawn = player.getActor().zone.getSpawnPackets(player.actorID);
BasePacket debugSpawn = debug.getSpawnPackets(player.actorID); BasePacket debugSpawn = debug.getSpawnPackets(player.actorID);
BasePacket worldMasterSpawn = worldMaster.getSpawnPackets(player.actorID); BasePacket worldMasterSpawn = worldMaster.getSpawnPackets(player.actorID);
innSpawn.debugPrintPacket(); innSpawn.debugPrintPacket();
@ -330,7 +334,7 @@ namespace FFXIVClassic_Lobby_Server
player.updatePlayerActorPosition(posUpdate.x, posUpdate.y, posUpdate.z, posUpdate.rot, posUpdate.moveState); player.updatePlayerActorPosition(posUpdate.x, posUpdate.y, posUpdate.z, posUpdate.rot, posUpdate.moveState);
//Update Instance //Update Instance
List<BasePacket> instanceUpdatePackets = player.updateInstance(inn.getActorsAroundActor(player.getActor(), 50)); List<BasePacket> instanceUpdatePackets = player.updateInstance(player.getActor().zone.getActorsAroundActor(player.getActor(), 50));
foreach (BasePacket bp in instanceUpdatePackets) foreach (BasePacket bp in instanceUpdatePackets)
client.queuePacket(bp); client.queuePacket(bp);
@ -519,10 +523,12 @@ namespace FFXIVClassic_Lobby_Server
*/ */
private void initNpcs() private void initNpcs()
{ {
/*
List<Npc> npcList = Database.getNpcList(); List<Npc> npcList = Database.getNpcList();
foreach (Npc npc in npcList) foreach (Npc npc in npcList)
inn.addActorToZone(npc); inn.addActorToZone(npc);
Log.info(String.Format("Loaded {0} npcs...", npcList.Count)); Log.info(String.Format("Loaded {0} npcs...", npcList.Count));
* */
} }
private void loadTest(ClientConnection client, ConnectedPlayer player) private void loadTest(ClientConnection client, ConnectedPlayer player)

View File

@ -28,8 +28,8 @@ namespace FFXIVClassic_Map_Server.dataobjects
public float oldPositionX, oldPositionY, oldPositionZ, oldRotation; public float oldPositionX, oldPositionY, oldPositionZ, oldRotation;
public ushort moveState, oldMoveState; public ushort moveState, oldMoveState;
public uint currentZoneId; public uint zoneId;
public Zone zone = null;
public bool isZoning = false; public bool isZoning = false;
public bool spawnedFirstTime = false; public bool spawnedFirstTime = false;

View File

@ -20,9 +20,9 @@ namespace FFXIVClassic_Map_Server.actors.director
this.weatherId = weatherId; this.weatherId = weatherId;
this.displayNameId = 0; this.displayNameId = 0;
this.customDisplayName = String.Format("weatherDire_{0}", zone.zoneName, zone.currentZoneId); this.customDisplayName = String.Format("weatherDire_{0}", zone.zoneName, zone.actorId);
this.actorName = String.Format("weatherDire_{0}@{0:04x}", zone.zoneName, zone.currentZoneId); this.actorName = String.Format("weatherDire_{0}@{0:04x}", zone.zoneName, zone.actorId);
this.className = "Debug"; this.className = "Debug";
} }

View File

@ -0,0 +1,160 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.common
{
namespace EfficientHashTables
{
public class Efficient64bitHashTable<T>
{
private class element
{
public ulong _key;
public T _value;
};
private element[][] _buckets;
private uint _capacity;
public Efficient64bitHashTable()
{
_capacity = 214373; // some prime number
_buckets = new element[_capacity][];
}
public Efficient64bitHashTable(uint capacity)
{
_capacity = capacity;
_buckets = new element[_capacity][];
}
public uint hash(ulong key)
{
return (uint)(key % _capacity);
}
public void Add(ulong key, T value)
{
uint hsh = hash(key);
element[] e;
if (_buckets[hsh] == null)
_buckets[hsh] = e = new element[1];
else
{
foreach (var elem in _buckets[hsh])
if (elem._key == key)
{
elem._value = value;
return;
}
e = new element[_buckets[hsh].Length + 1];
Array.Copy(_buckets[hsh], 0, e, 1, _buckets[hsh].Length);
_buckets[hsh] = e;
}
e[0] = new element { _key = key, _value = value };
}
public T Get(ulong key)
{
uint hsh = hash(key);
element[] e = _buckets[hsh];
if (e == null) return default(T);
foreach (var f in e)
if (f._key == key)
return f._value;
return default(T);
}
public bool Has(ulong key)
{
uint hsh = hash(key);
element[] e = _buckets[hsh];
if (e == null) return false;
foreach (var f in e)
if (f._key == key)
return true;
return false;
}
public int Count()
{
int r = 0;
foreach (var e in _buckets)
if (e != null)
r += e.Length;
return r;
}
}
public class Efficient32bitHashTable<T>
{
private class element
{
public uint _key;
public T _value;
};
private element[][] _buckets;
private uint _capacity;
public Efficient32bitHashTable()
{
_capacity = 463; // some prime number
_buckets = new element[_capacity][];
}
public Efficient32bitHashTable(uint capacity)
{
_capacity = capacity;
_buckets = new element[_capacity][];
}
public uint hash(uint key)
{
return (uint)(key % _capacity);
}
public void Add(uint key, T value)
{
uint hsh = hash(key);
element[] e;
if (_buckets[hsh] == null)
_buckets[hsh] = e = new element[1];
else
{
foreach (var elem in _buckets[hsh])
if (elem._key == key)
{
elem._value = value;
return;
}
e = new element[_buckets[hsh].Length + 1];
Array.Copy(_buckets[hsh], 0, e, 1, _buckets[hsh].Length);
_buckets[hsh] = e;
}
e[0] = new element { _key = key, _value = value };
}
public T Get(uint key)
{
uint hsh = hash(key);
element[] e = _buckets[hsh];
if (e == null) return default(T);
foreach (var f in e)
if (f._key == key)
return f._value;
return default(T);
}
public int Count()
{
int r = 0;
foreach (var e in _buckets)
if (e != null)
r += e.Length;
return r;
}
}
}
}