Zone server now uses the World server's group classes. MotD now shows proper world name. Added party functions to zone server.

This commit is contained in:
Filip Maj 2016-12-21 09:27:51 -05:00
parent ae38ee1bc1
commit e89b7557b3
22 changed files with 310 additions and 284 deletions

View file

@ -10,12 +10,15 @@ namespace FFXIVClassic_World_Server
public static String OPTIONS_PORT;
public static bool OPTIONS_TIMESTAMP = false;
public static uint DATABASE_WORLDID;
public static String DATABASE_HOST;
public static String DATABASE_PORT;
public static String DATABASE_NAME;
public static String DATABASE_USERNAME;
public static String DATABASE_PASSWORD;
public static String PREF_SERVERNAME;
public static bool Load()
{
Program.Log.Info("Loading world_config.ini");
@ -32,6 +35,7 @@ namespace FFXIVClassic_World_Server
ConfigConstants.OPTIONS_PORT = configIni.GetValue("General", "server_port", "54992");
ConfigConstants.OPTIONS_TIMESTAMP = configIni.GetValue("General", "showtimestamp", "true").ToLower().Equals("true");
ConfigConstants.DATABASE_WORLDID = UInt32.Parse(configIni.GetValue("Database", "worldid", "0"));
ConfigConstants.DATABASE_HOST = configIni.GetValue("Database", "host", "");
ConfigConstants.DATABASE_PORT = configIni.GetValue("Database", "port", "");
ConfigConstants.DATABASE_NAME = configIni.GetValue("Database", "database", "");

View file

@ -0,0 +1,14 @@
namespace FFXIVClassic_World_Server.DataObjects
{
class DBWorld
{
public uint id;
public string address;
public ushort port;
public ushort listPosition;
public ushort population;
public string name;
public bool isActive;
public string motd;
}
}

View file

@ -8,6 +8,41 @@ namespace FFXIVClassic_World_Server
{
class Database
{
public static DBWorld GetServer(uint serverId)
{
using (var 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)))
{
DBWorld world = null;
try
{
conn.Open();
MySqlCommand cmd = new MySqlCommand("SELECT name, address, port FROM servers WHERE id = @serverId", conn);
cmd.Parameters.AddWithValue("@serverId", serverId);
using (MySqlDataReader Reader = cmd.ExecuteReader())
{
while (Reader.Read())
{
world = new DBWorld();
world.id = serverId;
world.name = Reader.GetString("name");
world.address = Reader.GetString("address");
world.port = Reader.GetUInt16("port");
}
}
}
catch (MySqlException e)
{
Program.Log.Error(e.ToString());
}
finally
{
conn.Dispose();
}
return world;
}
}
public static bool LoadZoneSessionInfo(Session session)
{
string characterName;

View file

@ -75,6 +75,7 @@
<Compile Include="ConfigConstants.cs" />
<Compile Include="Database.cs" />
<Compile Include="DataObjects\ClientConnection.cs" />
<Compile Include="DataObjects\DBWorld.cs" />
<Compile Include="DataObjects\Group\Group.cs" />
<Compile Include="DataObjects\Group\Linkshell.cs" />
<Compile Include="DataObjects\Group\LinkshellMember.cs" />
@ -115,6 +116,7 @@
<Compile Include="Packets\WorldPackets\Receive\WorldRequestZoneChangePacket.cs" />
<Compile Include="Packets\WorldPackets\Receive\SessionEndConfirmPacket.cs" />
<Compile Include="Packets\WorldPackets\Send\ErrorPacket.cs" />
<Compile Include="Packets\WorldPackets\Send\Group\PartySyncPacket.cs" />
<Compile Include="Packets\WorldPackets\Send\Group\GroupWorkValuesPacket.cs" />
<Compile Include="Packets\WorldPackets\Send\Group\GroupMemberListPacket.cs" />
<Compile Include="Packets\WorldPackets\Send\Group\GroupMemberListEndPacket.cs" />

View file

@ -160,7 +160,7 @@ namespace FFXIVClassic_World_Server
public Linkshell GetLinkshell(string name)
{
if (mNameToIdLookup.ContainsKey(name))
return mCurrentWorldGroupsReference[mNameToIdLookup[name]];
return (Linkshell)mCurrentWorldGroupsReference[mNameToIdLookup[name]];
else
return null;
}

View file

@ -0,0 +1,33 @@
using FFXIVClassic.Common;
using FFXIVClassic_World_Server.DataObjects;
using FFXIVClassic_World_Server.DataObjects.Group;
using System;
using System.IO;
namespace FFXIVClassic_World_Server.Packets.WorldPackets.Send.Group
{
class PartySyncPacket
{
public const ushort OPCODE = 0x1020;
public const uint PACKET_SIZE = 0x60;
public static SubPacket BuildPacket(Session session, Party party)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Write((UInt64)party.groupIndex);
binWriter.Write((UInt32)party.GetLeader());
binWriter.Write((UInt32)party.members.Count);
for (int i = 0; i < party.members.Count; i++)
binWriter.Write((UInt32)party.members[i]);
}
}
return new SubPacket(true, OPCODE, 0, session.sessionId, data);
}
}
}

View file

@ -1,4 +1,5 @@
using MySql.Data.MySqlClient;
using FFXIVClassic_World_Server.DataObjects;
using MySql.Data.MySqlClient;
using NLog;
using NLog.Fluent;
using System;
@ -56,6 +57,19 @@ namespace FFXIVClassic_World_Server
startServer = false;
}
}
//Check World ID
DBWorld thisWorld = Database.GetServer(ConfigConstants.DATABASE_WORLDID);
if (thisWorld != null)
{
Program.Log.Info("Successfully pulled world info from DB. Server name is {0}.", thisWorld.name);
ConfigConstants.PREF_SERVERNAME = thisWorld.name;
}
else
{
Program.Log.Info("World info could not be retrieved from the DB. Welcome and MOTD will not be displayed.");
ConfigConstants.PREF_SERVERNAME = "Unknown";
}
//Start server if A-OK
if (startServer)

View file

@ -228,7 +228,7 @@ namespace FFXIVClassic_World_Server
//Linkshell set active
case 0x1028:
SetActiveLinkshellPacket setActiveLinkshellPacket = new SetActiveLinkshellPacket(subpacket.data);
Linkshell ls = mWorldManager.GetLinkshellManager().GetLinkshell();
//Linkshell ls = mWorldManager.GetLinkshellManager().GetLinkshell();
break;
}
}

View file

@ -4,6 +4,7 @@ using FFXIVClassic_World_Server.DataObjects.Group;
using FFXIVClassic_World_Server.Packets.Send.Subpackets;
using FFXIVClassic_World_Server.Packets.Send.Subpackets.Groups;
using FFXIVClassic_World_Server.Packets.WorldPackets.Send;
using FFXIVClassic_World_Server.Packets.WorldPackets.Send.Group;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
@ -219,6 +220,7 @@ namespace FFXIVClassic_World_Server
mPartyManager.AddToParty(pt.groupIndex, 161);
mPartyManager.AddToParty(pt.groupIndex, 162);
pt.SendGroupPackets(session);
SendPartySync(pt);
mRetainerGroupManager.GetRetainerGroup(session.sessionId).SendGroupPackets(session);
List<Linkshell> linkshells = mLinkshellManager.GetPlayerLinkshellMembership(session.sessionId);
foreach (Linkshell ls in linkshells)
@ -230,11 +232,23 @@ namespace FFXIVClassic_World_Server
private void SendMotD(Session session)
{
session.clientConnection.QueuePacket(SendMessagePacket.BuildPacket(session.sessionId, session.sessionId, SendMessagePacket.MESSAGE_TYPE_GENERAL_INFO, "", "-------- Login Message --------"), true, false);
session.clientConnection.QueuePacket(SendMessagePacket.BuildPacket(session.sessionId, session.sessionId, SendMessagePacket.MESSAGE_TYPE_GENERAL_INFO, "", "Welcome to <Server Name>!"), true, false);
session.clientConnection.QueuePacket(SendMessagePacket.BuildPacket(session.sessionId, session.sessionId, SendMessagePacket.MESSAGE_TYPE_GENERAL_INFO, "", String.Format("Welcome to {0}!", ConfigConstants.PREF_SERVERNAME)), true, false);
session.clientConnection.QueuePacket(SendMessagePacket.BuildPacket(session.sessionId, session.sessionId, SendMessagePacket.MESSAGE_TYPE_GENERAL_INFO, "", "Welcome to Eorzea!"), true, false);
session.clientConnection.QueuePacket(SendMessagePacket.BuildPacket(session.sessionId, session.sessionId, SendMessagePacket.MESSAGE_TYPE_GENERAL_INFO, "", "Here is a test Message of the Day from the World Server!"), true, false);
}
public void SendPartySync(Party party)
{
foreach (uint member in party.members)
{
Session session = Server.GetServer().GetSession(member);
if (session == null)
continue;
SubPacket syncPacket = PartySyncPacket.BuildPacket(session, party);
session.routing1.SendPacket(syncPacket);
}
}
public class ZoneEntrance
{
public uint zoneId;