2016-12-12 19:03:25 -05:00
|
|
|
|
using FFXIVClassic_World_Server.DataObjects.Group;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace FFXIVClassic_World_Server
|
|
|
|
|
{
|
|
|
|
|
class LinkshellManager
|
|
|
|
|
{
|
2019-06-08 17:06:10 -04:00
|
|
|
|
public const int LS_MAX_ALLOWED = 8;
|
|
|
|
|
public const int LS_MAX_MEMBERS = 128;
|
2019-06-08 15:51:17 -04:00
|
|
|
|
public const byte RANK_GUEST = 0x1;
|
|
|
|
|
public const byte RANK_MEMBER = 0x4;
|
|
|
|
|
public const byte RANK_LEADER = 0x7;
|
|
|
|
|
public const byte RANK_MASTER = 0xA;
|
|
|
|
|
|
2016-12-17 09:37:18 -05:00
|
|
|
|
private WorldManager mWorldManager;
|
2016-12-12 19:03:25 -05:00
|
|
|
|
private Object mGroupLockReference;
|
2016-12-21 18:02:50 -05:00
|
|
|
|
private Dictionary<ulong, Group> mCurrentWorldGroupsReference; //GroupId, LS
|
|
|
|
|
private Dictionary<ulong, Linkshell> mLinkshellList = new Dictionary<ulong, Linkshell>(); //GroupId, LS
|
|
|
|
|
private Dictionary<ulong, Linkshell> mLSIdToIdLookup = new Dictionary<ulong, Linkshell>(); //Name, GroupId
|
|
|
|
|
private Dictionary<string, ulong> mNameToIdLookup = new Dictionary<string, ulong>(); //Name, GroupId
|
2016-12-12 19:03:25 -05:00
|
|
|
|
|
2016-12-17 09:37:18 -05:00
|
|
|
|
public LinkshellManager(WorldManager worldManager, Object groupLock, Dictionary<ulong, Group> worldGroupList)
|
2016-12-12 19:03:25 -05:00
|
|
|
|
{
|
2016-12-17 09:37:18 -05:00
|
|
|
|
mWorldManager = worldManager;
|
2016-12-12 19:03:25 -05:00
|
|
|
|
mGroupLockReference = groupLock;
|
|
|
|
|
mCurrentWorldGroupsReference = worldGroupList;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-10 01:07:11 -04:00
|
|
|
|
//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;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-12 19:03:25 -05:00
|
|
|
|
//Creates a new linkshell and adds it to the list
|
2018-04-10 01:07:11 -04:00
|
|
|
|
public Linkshell CreateLinkshell(string name, ushort crest, uint master)
|
2016-12-12 19:03:25 -05:00
|
|
|
|
{
|
|
|
|
|
lock (mGroupLockReference)
|
|
|
|
|
{
|
|
|
|
|
ulong resultId = Database.CreateLinkshell(name, crest, master);
|
|
|
|
|
if (resultId >= 0)
|
|
|
|
|
{
|
2019-06-08 15:51:17 -04:00
|
|
|
|
Linkshell newLs = new Linkshell(resultId, mWorldManager.GetGroupIndex(), name, crest, master, RANK_MASTER);
|
2018-04-10 01:07:11 -04:00
|
|
|
|
|
|
|
|
|
mLinkshellList.Add(mWorldManager.GetGroupIndex(), newLs);
|
|
|
|
|
mNameToIdLookup.Add(newLs.name, newLs.groupIndex);
|
|
|
|
|
mLSIdToIdLookup.Add(newLs.dbId, newLs);
|
|
|
|
|
mCurrentWorldGroupsReference.Add(mWorldManager.GetGroupIndex(), newLs);
|
|
|
|
|
mWorldManager.IncrementGroupIndex();
|
2016-12-12 19:03:25 -05:00
|
|
|
|
|
|
|
|
|
//Add founder to the LS
|
2019-06-08 15:51:17 -04:00
|
|
|
|
AddMemberToLinkshell(master, newLs.name, RANK_MASTER);
|
2018-04-10 01:07:11 -04:00
|
|
|
|
|
|
|
|
|
return newLs;
|
2016-12-12 19:03:25 -05:00
|
|
|
|
}
|
2018-04-10 01:07:11 -04:00
|
|
|
|
return null;
|
2016-12-12 19:03:25 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-18 09:50:23 -05:00
|
|
|
|
//Modifies the LS master
|
|
|
|
|
public bool ChangeLinkshellMaster(string name, uint newMaster)
|
2016-12-12 19:03:25 -05:00
|
|
|
|
{
|
2016-12-21 08:27:23 -05:00
|
|
|
|
ulong groupInstanceId;
|
|
|
|
|
if (mNameToIdLookup.ContainsKey(name))
|
|
|
|
|
groupInstanceId = mNameToIdLookup[name];
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (mCurrentWorldGroupsReference.ContainsKey(groupInstanceId))
|
2016-12-18 09:50:23 -05:00
|
|
|
|
{
|
2016-12-21 08:27:23 -05:00
|
|
|
|
Linkshell ls = (Linkshell)mCurrentWorldGroupsReference[groupInstanceId];
|
|
|
|
|
return false;
|
2016-12-18 09:50:23 -05:00
|
|
|
|
}
|
2016-12-21 08:27:23 -05:00
|
|
|
|
|
2016-12-18 09:50:23 -05:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Modifies the LS crest
|
|
|
|
|
public bool ChangeLinkshellCrest(string name, ushort newCrestId)
|
|
|
|
|
{
|
2016-12-21 08:27:23 -05:00
|
|
|
|
ulong groupInstanceId;
|
|
|
|
|
if (mNameToIdLookup.ContainsKey(name))
|
|
|
|
|
groupInstanceId = mNameToIdLookup[name];
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (mCurrentWorldGroupsReference.ContainsKey(groupInstanceId))
|
2016-12-18 09:50:23 -05:00
|
|
|
|
{
|
2016-12-21 08:27:23 -05:00
|
|
|
|
Linkshell ls = (Linkshell)mCurrentWorldGroupsReference[groupInstanceId];
|
|
|
|
|
return Database.ChangeLinkshellCrest(ls.dbId, newCrestId);
|
2016-12-18 09:50:23 -05:00
|
|
|
|
}
|
2016-12-21 08:27:23 -05:00
|
|
|
|
|
2016-12-12 19:03:25 -05:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-21 08:27:23 -05:00
|
|
|
|
//Deletes a LS
|
|
|
|
|
public bool DeleteLinkshell(string name)
|
2016-12-12 19:03:25 -05:00
|
|
|
|
{
|
2016-12-21 08:27:23 -05:00
|
|
|
|
lock (mGroupLockReference)
|
2016-12-12 19:03:25 -05:00
|
|
|
|
{
|
2016-12-21 08:27:23 -05:00
|
|
|
|
ulong groupInstanceId;
|
|
|
|
|
if (mNameToIdLookup.ContainsKey(name))
|
|
|
|
|
groupInstanceId = mNameToIdLookup[name];
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (mCurrentWorldGroupsReference.ContainsKey(groupInstanceId))
|
|
|
|
|
{
|
2016-12-12 19:03:25 -05:00
|
|
|
|
Linkshell ls = (Linkshell)mCurrentWorldGroupsReference[groupInstanceId];
|
|
|
|
|
bool result = Database.DeleteLinkshell(ls.dbId);
|
|
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
mCurrentWorldGroupsReference.Remove(groupInstanceId);
|
|
|
|
|
mLinkshellList.Remove(groupInstanceId);
|
2016-12-21 08:27:23 -05:00
|
|
|
|
mNameToIdLookup.Remove(name);
|
2016-12-12 19:03:25 -05:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Adds a player to the linkshell
|
2019-06-08 15:51:17 -04:00
|
|
|
|
public bool AddMemberToLinkshell(uint charaId, string LSName, byte rank = RANK_MEMBER)
|
2016-12-12 19:03:25 -05:00
|
|
|
|
{
|
|
|
|
|
//Get the LS
|
2017-01-08 21:42:43 -05:00
|
|
|
|
Linkshell ls = GetLinkshell(LSName);
|
2016-12-12 19:03:25 -05:00
|
|
|
|
if (ls == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
//Add player to ls in db
|
|
|
|
|
lock (mGroupLockReference)
|
|
|
|
|
{
|
2019-06-08 15:51:17 -04:00
|
|
|
|
bool result = Database.LinkshellAddPlayer(ls.dbId, charaId, rank);
|
2016-12-12 19:03:25 -05:00
|
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
2019-06-08 15:51:17 -04:00
|
|
|
|
ls.AddMember(charaId, rank);
|
2016-12-12 19:03:25 -05:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Removes a player from the linkshell
|
2017-01-08 21:42:43 -05:00
|
|
|
|
public bool RemoveMemberFromLinkshell(uint charaId, string LSName)
|
2016-12-12 19:03:25 -05:00
|
|
|
|
{
|
|
|
|
|
//Get the LS
|
2017-01-08 21:42:43 -05:00
|
|
|
|
Linkshell ls = GetLinkshell(LSName);
|
2016-12-12 19:03:25 -05:00
|
|
|
|
if (ls == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
//Delete the player in the db
|
|
|
|
|
lock (mGroupLockReference)
|
|
|
|
|
{
|
|
|
|
|
bool result = Database.LinkshellRemovePlayer(ls.dbId, charaId);
|
|
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
//Remove from group instance
|
2016-12-16 20:06:17 -05:00
|
|
|
|
ls.RemoveMember(charaId);
|
2016-12-12 19:03:25 -05:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-08 21:42:43 -05:00
|
|
|
|
//Get a single linkshell group either already instantiated or make one from the db by Name
|
2016-12-21 08:27:23 -05:00
|
|
|
|
public Linkshell GetLinkshell(string name)
|
|
|
|
|
{
|
|
|
|
|
if (mNameToIdLookup.ContainsKey(name))
|
2016-12-21 09:27:51 -05:00
|
|
|
|
return (Linkshell)mCurrentWorldGroupsReference[mNameToIdLookup[name]];
|
2016-12-21 08:27:23 -05:00
|
|
|
|
else
|
2016-12-21 18:02:50 -05:00
|
|
|
|
{
|
|
|
|
|
lock (mGroupLockReference)
|
|
|
|
|
{
|
|
|
|
|
Linkshell ls = Database.GetLinkshell(mWorldManager.GetGroupIndex(), name);
|
2019-06-08 15:51:17 -04:00
|
|
|
|
|
|
|
|
|
if (ls == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
2016-12-21 18:02:50 -05:00
|
|
|
|
ls.LoadMembers();
|
|
|
|
|
|
|
|
|
|
if (ls != null)
|
|
|
|
|
{
|
|
|
|
|
mLinkshellList.Add(ls.groupIndex, ls);
|
|
|
|
|
mNameToIdLookup.Add(ls.name, ls.groupIndex);
|
2017-01-08 21:42:43 -05:00
|
|
|
|
mLSIdToIdLookup.Add(ls.dbId, ls);
|
2016-12-21 18:02:50 -05:00
|
|
|
|
mCurrentWorldGroupsReference.Add(ls.groupIndex, ls);
|
|
|
|
|
mWorldManager.IncrementGroupIndex();
|
|
|
|
|
return ls;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-21 08:27:23 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-08 21:42:43 -05:00
|
|
|
|
//Get a single linkshell group either already instantiated or make one from the db by ID
|
2016-12-21 08:27:23 -05:00
|
|
|
|
public Linkshell GetLinkshell(ulong lsId)
|
2016-12-12 19:03:25 -05:00
|
|
|
|
{
|
2016-12-21 18:02:50 -05:00
|
|
|
|
if (mLSIdToIdLookup.ContainsKey(lsId))
|
2017-01-08 21:42:43 -05:00
|
|
|
|
return (Linkshell)mCurrentWorldGroupsReference[mLSIdToIdLookup[lsId].groupIndex];
|
2016-12-12 19:03:25 -05:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
lock (mGroupLockReference)
|
|
|
|
|
{
|
2016-12-21 08:27:23 -05:00
|
|
|
|
Linkshell ls = Database.GetLinkshell(mWorldManager.GetGroupIndex(), lsId);
|
2016-12-16 20:06:17 -05:00
|
|
|
|
ls.LoadMembers();
|
2016-12-12 19:03:25 -05:00
|
|
|
|
|
|
|
|
|
if (ls != null)
|
2017-01-08 21:42:43 -05:00
|
|
|
|
{
|
2016-12-21 08:27:23 -05:00
|
|
|
|
mLinkshellList.Add(ls.groupIndex, ls);
|
|
|
|
|
mNameToIdLookup.Add(ls.name, ls.groupIndex);
|
2016-12-21 18:02:50 -05:00
|
|
|
|
mLSIdToIdLookup.Add(ls.dbId, ls);
|
2016-12-21 08:27:23 -05:00
|
|
|
|
mCurrentWorldGroupsReference.Add(ls.groupIndex, ls);
|
2016-12-17 09:37:18 -05:00
|
|
|
|
mWorldManager.IncrementGroupIndex();
|
2016-12-12 19:03:25 -05:00
|
|
|
|
return ls;
|
|
|
|
|
}
|
2017-01-08 21:42:43 -05:00
|
|
|
|
else
|
|
|
|
|
return null;
|
2016-12-12 19:03:25 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Get the linkshells player is part of
|
|
|
|
|
public List<Linkshell> GetPlayerLinkshellMembership(uint charaId)
|
|
|
|
|
{
|
|
|
|
|
List<LinkshellMember> memberships = Database.GetPlayerLSMembership(charaId);
|
|
|
|
|
List<Linkshell> linkshells = new List<Linkshell>();
|
|
|
|
|
foreach (LinkshellMember membership in memberships)
|
|
|
|
|
linkshells.Add(GetLinkshell(membership.lsId));
|
|
|
|
|
return linkshells;
|
|
|
|
|
}
|
2016-12-21 08:27:23 -05:00
|
|
|
|
|
2016-12-12 19:03:25 -05:00
|
|
|
|
}
|
|
|
|
|
}
|