diff --git a/FFXIVClassic Proxy Server/ConfigConstants.cs b/FFXIVClassic Proxy Server/ConfigConstants.cs
index ff39412a..dff311f8 100644
--- a/FFXIVClassic Proxy Server/ConfigConstants.cs
+++ b/FFXIVClassic Proxy Server/ConfigConstants.cs
@@ -18,15 +18,15 @@ namespace FFXIVClassic_World_Server
public static bool Load()
{
- Program.Log.Info("Loading config.ini");
+ Program.Log.Info("Loading world_config.ini");
- if (!File.Exists("./config.ini"))
+ if (!File.Exists("./world_config.ini"))
{
Program.Log.Error("FILE NOT FOUND!");
return false;
}
- INIFile configIni = new INIFile("./config.ini");
+ INIFile configIni = new INIFile("./world_config.ini");
ConfigConstants.OPTIONS_BINDIP = configIni.GetValue("General", "server_ip", "127.0.0.1");
ConfigConstants.OPTIONS_PORT = configIni.GetValue("General", "server_port", "54994");
diff --git a/FFXIVClassic Proxy Server/DataObjects/ZoneServer.cs b/FFXIVClassic Proxy Server/DataObjects/ZoneServer.cs
index 2f7943e0..eafe5dae 100644
--- a/FFXIVClassic Proxy Server/DataObjects/ZoneServer.cs
+++ b/FFXIVClassic Proxy Server/DataObjects/ZoneServer.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
@@ -9,8 +10,31 @@ namespace FFXIVClassic_World_Server.DataObjects
{
class ZoneServer
{
- public string zoneServerIp;
- public int zoneServerPort;
+ public readonly string zoneServerIp;
+ public readonly int zoneServerPort;
+ public bool isConnected = false;
public Socket zoneServerConnection;
+
+ public ZoneServer(string ip, int port)
+ {
+ zoneServerIp = ip;
+ zoneServerPort = port;
+ }
+
+ public void Connect()
+ {
+ Program.Log.Info("Connecting to zone server @ {0}:{1}", zoneServerIp, zoneServerPort);
+ IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse(zoneServerIp), zoneServerPort);
+ zoneServerConnection = new Socket(AddressFamily.InterNetwork,
+ SocketType.Stream, ProtocolType.Tcp);
+
+ try
+ {
+ zoneServerConnection.Connect(remoteEP);
+ isConnected = true;
+ }
+ catch (Exception e)
+ { Program.Log.Error("Failed to connect"); return; }
+ }
}
}
diff --git a/FFXIVClassic Proxy Server/FFXIVClassic World Server.csproj b/FFXIVClassic Proxy Server/FFXIVClassic World Server.csproj
index f05479d2..8ef6fac2 100644
--- a/FFXIVClassic Proxy Server/FFXIVClassic World Server.csproj
+++ b/FFXIVClassic Proxy Server/FFXIVClassic World Server.csproj
@@ -66,6 +66,7 @@
+
diff --git a/FFXIVClassic Proxy Server/Server.cs b/FFXIVClassic Proxy Server/Server.cs
index 011f5015..d02d8312 100644
--- a/FFXIVClassic Proxy Server/Server.cs
+++ b/FFXIVClassic Proxy Server/Server.cs
@@ -18,6 +18,8 @@ namespace FFXIVClassic_World_Server
private Socket mServerSocket;
+ WorldManager worldManager;
+
private List mConnectionList = new List();
private Dictionary mSessionList = new Dictionary();
@@ -33,7 +35,10 @@ namespace FFXIVClassic_World_Server
public bool StartServer()
{
-
+ worldManager = new WorldManager(this);
+ worldManager.LoadZoneServerList();
+ worldManager.ConnectToZoneServers();
+
IPEndPoint serverEndPoint = new System.Net.IPEndPoint(IPAddress.Parse(ConfigConstants.OPTIONS_BINDIP), int.Parse(ConfigConstants.OPTIONS_PORT));
try
@@ -63,7 +68,7 @@ namespace FFXIVClassic_World_Server
}
Console.ForegroundColor = ConsoleColor.White;
- Program.Log.Info("Map Server has started @ {0}:{1}", (mServerSocket.LocalEndPoint as IPEndPoint).Address, (mServerSocket.LocalEndPoint as IPEndPoint).Port);
+ Program.Log.Info("World Server accepting connections @ {0}:{1}", (mServerSocket.LocalEndPoint as IPEndPoint).Address, (mServerSocket.LocalEndPoint as IPEndPoint).Port);
Console.ForegroundColor = ConsoleColor.Gray;
return true;
diff --git a/FFXIVClassic Proxy Server/WorldMaster.cs b/FFXIVClassic Proxy Server/WorldMaster.cs
new file mode 100644
index 00000000..40c47d60
--- /dev/null
+++ b/FFXIVClassic Proxy Server/WorldMaster.cs
@@ -0,0 +1,144 @@
+using FFXIVClassic.Common;
+using FFXIVClassic_World_Server.DataObjects;
+using MySql.Data.MySqlClient;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Net.Sockets;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FFXIVClassic_World_Server
+{
+ class WorldManager
+ {
+ private Server mServer;
+ private Dictionary mZoneServerList;
+
+ public WorldManager(Server server)
+ {
+ mServer = server;
+ }
+
+ public void LoadZoneServerList()
+ {
+ mZoneServerList = new Dictionary();
+
+ 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
+ serverIp,
+ serverPort
+ FROM server_zones
+ WHERE serverIp IS NOT NULL";
+
+ MySqlCommand cmd = new MySqlCommand(query, conn);
+
+ using (MySqlDataReader reader = cmd.ExecuteReader())
+ {
+ while (reader.Read())
+ {
+ string ip = reader.GetString(0);
+ int port = reader.GetInt32(1);
+ string address = ip + ":" + port;
+
+ if (!mZoneServerList.ContainsKey(address))
+ {
+ ZoneServer zone = new ZoneServer(ip, port);
+ mZoneServerList.Add(address, zone);
+ }
+ }
+ }
+ }
+ catch (MySqlException e)
+ { Console.WriteLine(e); }
+ finally
+ {
+ conn.Dispose();
+ }
+ }
+
+ }
+
+ public void ConnectToZoneServers()
+ {
+ Program.Log.Info("--------------------------");
+ Program.Log.Info("Connecting to zone servers");
+ Program.Log.Info("--------------------------");
+
+ foreach (ZoneServer zs in mZoneServerList.Values)
+ {
+ zs.Connect();
+ }
+ }
+
+ //Moves the actor to the new zone if exists. No packets are sent nor position changed.
+ public void DoSeamlessZoneServerChange(Session session, uint destinationZoneId)
+ {
+
+ }
+
+ //Moves actor to new zone, and sends packets to spawn at the given zone entrance
+ public void DoZoneServerChange(Session session, uint zoneEntrance)
+ {
+ /*
+ ->Tell old server to save session info and remove
+ ->Update the position to zoneEntrance
+ ->Update routing
+ ->Tell new server to load session info and add
+ */
+ }
+
+ //Moves actor to new zone, and sends packets to spawn at the given coords.
+ public void DoZoneServerChange(Session session, uint destinationZoneId, string destinationPrivateArea, byte spawnType, float spawnX, float spawnY, float spawnZ, float spawnRotation)
+ {
+ /*
+ ->Tell old server to save session info and remove
+ ->Update the position to params
+ ->Update routing
+ ->Tell new server to load session info and add
+ */
+ }
+
+ //Login Zone In
+ public void DoLogin(Session session)
+ {
+ /*
+ ->Update routing
+ ->Tell new server to load session info and add
+ */
+
+
+ }
+
+ public class ZoneEntrance
+ {
+ public uint zoneId;
+ public string privateAreaName;
+ public byte spawnType;
+ public float spawnX;
+ public float spawnY;
+ public float spawnZ;
+ public float spawnRotation;
+
+ public ZoneEntrance(uint zoneId, string privateAreaName, byte spawnType, float x, float y, float z, float rot)
+ {
+ this.zoneId = zoneId;
+ this.privateAreaName = privateAreaName;
+ this.spawnType = spawnType;
+ this.spawnX = x;
+ this.spawnY = y;
+ this.spawnZ = z;
+ this.spawnRotation = rot;
+ }
+ }
+
+ }
+
+}
diff --git a/FFXIVClassic Proxy Server/packages.config b/FFXIVClassic Proxy Server/packages.config
index e99b9209..043c0d66 100644
--- a/FFXIVClassic Proxy Server/packages.config
+++ b/FFXIVClassic Proxy Server/packages.config
@@ -6,4 +6,5 @@
+
\ No newline at end of file
diff --git a/data/world_config.ini b/data/world_config.ini
new file mode 100644
index 00000000..2251736f
--- /dev/null
+++ b/data/world_config.ini
@@ -0,0 +1,11 @@
+[General]
+server_ip=127.0.0.1
+showtimestamp = true
+
+[Database]
+worldid=1
+host=127.0.0.1
+port=3306
+database=ffxiv_server
+username=root
+password=