Got linkshell creation working.

This commit is contained in:
Filip Maj
2018-04-10 01:07:11 -04:00
parent c3c19c3592
commit 1d3dd99414
10 changed files with 149 additions and 13 deletions

View File

@@ -529,5 +529,35 @@ namespace FFXIVClassic_World_Server
}
return success;
}
public static bool LinkshellIsBannedName(string name)
{
return false;
}
public static bool LinkshellExists(string name)
{
bool hasLS = false;
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();
MySqlCommand cmd = new MySqlCommand("SELECT * FROM server_linkshells WHERE name = @lsName", conn);
cmd.Parameters.AddWithValue("@lsName", name);
object result = cmd.ExecuteScalar();
hasLS = result != null && ((uint)result > 0);
}
catch (MySqlException e)
{
Program.Log.Error(e.ToString());
}
finally
{
conn.Dispose();
}
}
return hasLS;
}
}
}

View File

@@ -146,6 +146,7 @@
<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\LinkshellResultPacket.cs" />
<Compile Include="Packets\WorldPackets\Send\SessionBeginPacket.cs" />
<Compile Include="Packets\WorldPackets\Send\SessionEndPacket.cs" />
<Compile Include="PartyManager.cs" />

View File

@@ -23,8 +23,22 @@ namespace FFXIVClassic_World_Server
mCurrentWorldGroupsReference = worldGroupList;
}
//Checks if the LS name is in use or banned
public int CanCreateLinkshell(string name)
{
bool nameBanned = Database.LinkshellIsBannedName(name);
bool alreadyExists = Database.LinkshellExists(name);
if (nameBanned)
return 2;
if (alreadyExists)
return 1;
else
return 0;
}
//Creates a new linkshell and adds it to the list
public ulong CreateLinkshell(string name, ushort crest, uint master)
public Linkshell CreateLinkshell(string name, ushort crest, uint master)
{
lock (mGroupLockReference)
{
@@ -32,18 +46,19 @@ namespace FFXIVClassic_World_Server
if (resultId >= 0)
{
Linkshell newLs = new Linkshell(resultId, mWorldManager.GetGroupIndex(), name, crest, master, 0xa);
mLinkshellList.Add(mWorldManager.GetGroupIndex(), newLs);
mNameToIdLookup.Add(newLs.name, newLs.groupIndex);
mLSIdToIdLookup.Add(newLs.dbId, newLs);
mCurrentWorldGroupsReference.Add(mWorldManager.GetGroupIndex(), newLs);
mWorldManager.IncrementGroupIndex();
//Add founder to the LS
if (AddMemberToLinkshell(master, newLs.name))
{
mLinkshellList.Add(mWorldManager.GetGroupIndex(), newLs);
mNameToIdLookup.Add(newLs.name, newLs.groupIndex);
mLSIdToIdLookup.Add(newLs.dbId, newLs);
mCurrentWorldGroupsReference.Add(mWorldManager.GetGroupIndex(), newLs);
mWorldManager.IncrementGroupIndex();
}
AddMemberToLinkshell(master, newLs.name);
return newLs;
}
return resultId;
return null;
}
}

View File

@@ -0,0 +1,32 @@
using FFXIVClassic.Common;
using FFXIVClassic_World_Server.DataObjects;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_World_Server.Packets.WorldPackets.Send
{
class LinkshellResultPacket
{
public const ushort OPCODE = 0x1025;
public const uint PACKET_SIZE = 0x24;
public static SubPacket BuildPacket(Session session, int result)
{
byte[] data = new byte[PACKET_SIZE - 0x20];
using (MemoryStream mem = new MemoryStream(data))
{
using (BinaryWriter binWriter = new BinaryWriter(mem))
{
binWriter.Write((Int32)result);
}
}
return new SubPacket(true, OPCODE, session.sessionId, data);
}
}
}

View File

@@ -5,6 +5,7 @@ using FFXIVClassic_World_Server.Packets.Receive.Subpackets;
using FFXIVClassic_World_Server.Packets.Send.Subpackets.Groups;
using FFXIVClassic_World_Server.Packets.WorldPackets.Receive;
using FFXIVClassic_World_Server.Packets.WorldPackets.Receive.Group;
using FFXIVClassic_World_Server.Packets.WorldPackets.Send;
using System;
using System.Collections.Generic;
using System.Net;
@@ -282,7 +283,22 @@ namespace FFXIVClassic_World_Server
//Linkshell create request
case 0x1025:
CreateLinkshellPacket createLinkshellPacket = new CreateLinkshellPacket(subpacket.data);
mWorldManager.GetLinkshellManager().CreateLinkshell(createLinkshellPacket.name, createLinkshellPacket.crestid, createLinkshellPacket.master);
Linkshell newLs = null;
int lsError = mWorldManager.GetLinkshellManager().CanCreateLinkshell(createLinkshellPacket.name);
if (lsError == 0)
{
newLs = mWorldManager.GetLinkshellManager().CreateLinkshell(createLinkshellPacket.name, createLinkshellPacket.crestid, createLinkshellPacket.master);
if (newLs != null)
newLs.SendGroupPackets(session);
else
lsError = 3;
}
SubPacket resultPacket = LinkshellResultPacket.BuildPacket(session, lsError);
zoneServer.SendPacket(resultPacket);
break;
//Linkshell modify request
case 0x1026: