Skip to content

Commit

Permalink
Trimmed guild information on UserFile and SiteFile
Browse files Browse the repository at this point in the history
  • Loading branch information
Byte-Nova committed Dec 28, 2024
1 parent 30c5d05 commit d2e5e66
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 123 deletions.
13 changes: 6 additions & 7 deletions Source/Client/Managers/SiteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public static void RequestDestroySite()
DialogManager.PushNewDialog(d1);
}

public static void AddSites(SiteIdendityFile[] sites)
public static void AddSites(SiteFile[] sites)
{
foreach (SiteIdendityFile toAdd in sites)
foreach (SiteFile toAdd in sites)
{
SpawnSingleSite(toAdd);
}
Expand All @@ -100,13 +100,13 @@ public static void ClearAllSites()

foreach (Site toRemove in sites)
{
SiteIdendityFile siteFile = new SiteIdendityFile();
SiteFile siteFile = new SiteFile();
siteFile.Tile = toRemove.Tile;
RemoveSingleSite(siteFile);
}
}

public static void SpawnSingleSite(SiteIdendityFile toAdd)
public static void SpawnSingleSite(SiteFile toAdd)
{
if (Find.WorldObjects.Sites.FirstOrDefault(fetch => fetch.Tile == toAdd.Tile) != null) return;
else
Expand All @@ -126,7 +126,7 @@ public static void SpawnSingleSite(SiteIdendityFile toAdd)
}
}

public static void RemoveSingleSite(SiteIdendityFile toRemove)
public static void RemoveSingleSite(SiteFile toRemove)
{
try
{
Expand Down Expand Up @@ -162,7 +162,6 @@ public static void RequestSiteBuild(SiteInfoFile configFile)
siteData._stepMode = SiteStepMode.Build;
siteData._siteFile.Tile = SessionValues.chosenCaravan.Tile;
siteData._siteFile.Type.DefName = configFile.DefName;
if (ServerValues.hasFaction) siteData._siteFile.File = new GuildFile();

Packet packet = Packet.CreatePacketFromObject(nameof(SiteManager), siteData);
Network.listener.EnqueuePacket(packet);
Expand All @@ -188,7 +187,7 @@ public static void RequestSiteChangeConfig(SiteInfoFile config, string reward)

public static class SiteManagerHelper
{
public static SiteIdendityFile[] tempSites;
public static SiteFile[] tempSites;

public static void SetValues(ServerGlobalData serverGlobalData)
{
Expand Down
9 changes: 6 additions & 3 deletions Source/Server/Files/UserFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ public class UserFile

public double AidProtectionTime;

public string GuildName;

public string[] RunningMods;

public UserRelationshipsFile Relationships = new UserRelationshipsFile();
public List<string> AllyPlayers = new List<string>();

public GuildFile GuildFile;
public List<string> EnemyPlayers = new List<string>();

public SiteConfigFile[] SiteConfigs = Array.Empty<SiteConfigFile>();

Expand All @@ -42,7 +44,8 @@ public void SetLoginDetails(LoginData data)

public void UpdateFaction(GuildFile toUpdateWith)
{
GuildFile = toUpdateWith;
if (toUpdateWith == null) GuildName = null;
else GuildName = toUpdateWith.Name;

UserManagerH.SaveUserFile(this);
}
Expand Down
10 changes: 0 additions & 10 deletions Source/Server/Files/UserRelationshipsFile.cs

This file was deleted.

4 changes: 2 additions & 2 deletions Source/Server/Managers/BackupManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public static void BackupUser(string uid, bool persistent = false)
string userSavePath = Path.Combine(Master.savesPath, uid + SaveManager.fileExtension);
if (File.Exists(userSavePath)) toArchive.Add(userSavePath);

SiteIdendityFile[] playerSites = SiteManagerHelper.GetAllSitesFromUID(uid);
foreach (SiteIdendityFile site in playerSites) toArchive.Add(Path.Combine(Master.sitesPath, site.Tile + SiteManagerHelper.fileExtension));
SiteFile[] playerSites = SiteManagerHelper.GetAllSitesFromUID(uid);
foreach (SiteFile site in playerSites) toArchive.Add(Path.Combine(Master.sitesPath, site.Tile + SiteManagerHelper.fileExtension));

SettlementFile[] playerSettlements = PlayerSettlementManager.GetAllSettlementsFromUsername(uid);
foreach (SettlementFile settlementFile in playerSettlements) toArchive.Add(Path.Combine(Master.settlementsPath, settlementFile.Tile + PlayerSettlementManager.fileExtension));
Expand Down
12 changes: 6 additions & 6 deletions Source/Server/Managers/GlobalDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static ServerGlobalData GetClientValues(ServerClient client, ServerGlobal
{
globalData._isClientAdmin = client.userFile.IsAdmin;

globalData._isClientFactionMember = client.userFile.GuildFile != null;
globalData._isClientFactionMember = !string.IsNullOrEmpty(client.userFile.GuildName);

return globalData;
}
Expand Down Expand Up @@ -79,17 +79,17 @@ public static ServerGlobalData GetServerSettlements(ServerClient client, ServerG

public static ServerGlobalData GetServerSites(ServerClient client, ServerGlobalData globalData)
{
List<SiteIdendityFile> tempList = new List<SiteIdendityFile>();
SiteIdendityFile[] sites = SiteManagerHelper.GetAllSites();
foreach (SiteIdendityFile site in sites)
List<SiteFile> tempList = new List<SiteFile>();
SiteFile[] sites = SiteManagerHelper.GetAllSites();
foreach (SiteFile site in sites)
{
SiteIdendityFile file = new SiteIdendityFile();
SiteFile file = new SiteFile();

file.Tile = site.Tile;
file.UID = site.UID;
file.Goodwill = GoodwillManager.GetSiteGoodwill(client, site);
file.Type = site.Type;
file.File = site.File;
file.GuildName = site.GuildName;

tempList.Add(file);
}
Expand Down
70 changes: 35 additions & 35 deletions Source/Server/Managers/GoodwillManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,33 @@ public static void ParsePacket(ServerClient client, Packet packet)
public static void ChangeUserGoodwills(ServerClient client, FactionGoodwillData data)
{
SettlementFile settlementFile = PlayerSettlementManager.GetSettlementFileFromTile(data._tile);
SiteIdendityFile siteFile = SiteManagerHelper.GetSiteFileFromTile(data._tile);
SiteFile siteFile = SiteManagerHelper.GetSiteFileFromTile(data._tile);

if (settlementFile != null) data._uid = settlementFile.UID;
else data._uid = siteFile.UID;

if (client.userFile.GuildFile != null && client.userFile.GuildFile.CurrentUids.Contains(data._uid))
if (GuildManagerH.GetFactionFromFactionName(client.userFile.GuildName).CurrentUids.Contains(data._uid))
{
ResponseShortcutManager.SendBreakPacket(client);
return;
}

client.userFile.Relationships.EnemyPlayers.Remove(data._uid);
client.userFile.Relationships.AllyPlayers.Remove(data._uid);
client.userFile.EnemyPlayers.Remove(data._uid);
client.userFile.AllyPlayers.Remove(data._uid);

if (data._goodwill == Goodwill.Enemy)
{
if (!client.userFile.Relationships.EnemyPlayers.Contains(data._uid))
if (!client.userFile.EnemyPlayers.Contains(data._uid))
{
client.userFile.Relationships.EnemyPlayers.Add(data._uid);
client.userFile.EnemyPlayers.Add(data._uid);
}
}

else if (data._goodwill == Goodwill.Ally)
{
if (!client.userFile.Relationships.AllyPlayers.Contains(data._uid))
if (!client.userFile.AllyPlayers.Contains(data._uid))
{
client.userFile.Relationships.AllyPlayers.Add(data._uid);
client.userFile.AllyPlayers.Add(data._uid);
}
}

Expand All @@ -62,8 +62,8 @@ public static void ChangeUserGoodwills(ServerClient client, FactionGoodwillData
data._settlementGoodwills = tempSettlementList.ToArray();

List<Goodwill> tempSiteList = new List<Goodwill>();
SiteIdendityFile[] sites = SiteManagerHelper.GetAllSites();
foreach (SiteIdendityFile site in sites)
SiteFile[] sites = SiteManagerHelper.GetAllSites();
foreach (SiteFile site in sites)
{
//Check if site owner is the one we are looking for

Expand All @@ -84,56 +84,56 @@ public static void ChangeUserGoodwills(ServerClient client, FactionGoodwillData
public static Goodwill GetGoodwillFromTile(ServerClient client, int tileToCheck)
{
SettlementFile settlementFile = PlayerSettlementManager.GetSettlementFileFromTile(tileToCheck);
SiteIdendityFile siteFile = SiteManagerHelper.GetSiteFileFromTile(tileToCheck);
SiteFile siteFile = SiteManagerHelper.GetSiteFileFromTile(tileToCheck);

string usernameToCheck;
if (settlementFile != null) usernameToCheck = settlementFile.UID;
else usernameToCheck = siteFile.UID;

if (client.userFile.GuildFile != null && GuildManagerH.GetFactionFromFactionName(client.userFile.GuildFile.Name).CurrentUids.Contains(usernameToCheck))
if (GuildManagerH.GetFactionFromFactionName(client.userFile.GuildName).CurrentUids.Contains(usernameToCheck))
{
if (usernameToCheck == client.userFile.Uid) return Goodwill.Personal;
else return Goodwill.Faction;
}

else if (client.userFile.Relationships.EnemyPlayers.Contains(usernameToCheck)) return Goodwill.Enemy;
else if (client.userFile.Relationships.AllyPlayers.Contains(usernameToCheck)) return Goodwill.Ally;
else if (client.userFile.EnemyPlayers.Contains(usernameToCheck)) return Goodwill.Enemy;
else if (client.userFile.AllyPlayers.Contains(usernameToCheck)) return Goodwill.Ally;
else return Goodwill.Neutral;
}

public static Goodwill GetSettlementGoodwill(ServerClient client, SettlementFile settlement)
{
if (client.userFile.GuildFile != null && GuildManagerH.GetFactionFromFactionName(client.userFile.GuildFile.Name).CurrentUids.Contains(settlement.UID))
if (GuildManagerH.GetFactionFromFactionName(client.userFile.GuildName).CurrentUids.Contains(settlement.UID))
{
if (settlement.UID == client.userFile.Uid) return Goodwill.Personal;
else return Goodwill.Faction;
}

else if (client.userFile.Relationships.EnemyPlayers.Contains(settlement.UID)) return Goodwill.Enemy;
else if (client.userFile.Relationships.AllyPlayers.Contains(settlement.UID)) return Goodwill.Ally;
else if (client.userFile.EnemyPlayers.Contains(settlement.UID)) return Goodwill.Enemy;
else if (client.userFile.AllyPlayers.Contains(settlement.UID)) return Goodwill.Ally;
else if (settlement.UID == client.userFile.Uid) return Goodwill.Personal;
else return Goodwill.Neutral;
}

public static Goodwill GetSiteGoodwill(ServerClient client, SiteIdendityFile site)
public static Goodwill GetSiteGoodwill(ServerClient client, SiteFile site)
{
if (client.userFile.Uid == site.UID) return Goodwill.Personal; //We check if the players is the owner

if (site.File != null)
if (!string.IsNullOrEmpty(site.GuildName))
{
GuildFile factionFile = GuildManagerH.GetFactionFromFactionName(site.File.Name);
GuildFile factionFile = GuildManagerH.GetFactionFromFactionName(site.GuildName);

if (client.userFile.GuildFile != null && client.userFile.GuildFile.Name == factionFile.Name) return Goodwill.Faction; // We check if the player is in the faction
if (client.userFile.GuildName == factionFile.Name) return Goodwill.Faction; // We check if the player is in the faction

foreach (string str in client.userFile.Relationships.EnemyPlayers) // We check if the player is enemy with the faction
foreach (string str in client.userFile.EnemyPlayers) // We check if the player is enemy with the faction
{
if (GuildManagerH.CheckIfUserIsInFaction(factionFile, str))
{
return Goodwill.Enemy;
}
}

foreach (string str in client.userFile.Relationships.AllyPlayers) // We check if the player is allied with the faction
foreach (string str in client.userFile.AllyPlayers) // We check if the player is allied with the faction
{
if (GuildManagerH.CheckIfUserIsInFaction(factionFile, str))
{
Expand All @@ -143,9 +143,9 @@ public static Goodwill GetSiteGoodwill(ServerClient client, SiteIdendityFile sit
}
else
{
if (client.userFile.Relationships.EnemyPlayers.Contains(site.UID)) return Goodwill.Enemy; //We check if the player is enemy of the owner
if (client.userFile.EnemyPlayers.Contains(site.UID)) return Goodwill.Enemy; //We check if the player is enemy of the owner

else if (client.userFile.Relationships.AllyPlayers.Contains(site.UID)) return Goodwill.Ally; // We check if the player is allied to the owner
else if (client.userFile.AllyPlayers.Contains(site.UID)) return Goodwill.Ally; // We check if the player is allied to the owner
}
return Goodwill.Neutral;
}
Expand All @@ -164,14 +164,14 @@ public static void ClearAllFactionMemberGoodwills(GuildFile factionFile)
{
for (int i = 0; i < factionFile.CurrentUids.Count(); i++)
{
if (client.userFile.Relationships.EnemyPlayers.Contains(factionFile.CurrentUids[i]))
if (client.userFile.EnemyPlayers.Contains(factionFile.CurrentUids[i]))
{
client.userFile.Relationships.EnemyPlayers.Remove(factionFile.CurrentUids[i]);
client.userFile.EnemyPlayers.Remove(factionFile.CurrentUids[i]);
}

else if (client.userFile.Relationships.AllyPlayers.Contains(factionFile.CurrentUids[i]))
else if (client.userFile.AllyPlayers.Contains(factionFile.CurrentUids[i]))
{
client.userFile.Relationships.AllyPlayers.Remove(factionFile.CurrentUids[i]);
client.userFile.AllyPlayers.Remove(factionFile.CurrentUids[i]);
}
}
}
Expand All @@ -188,14 +188,14 @@ public static void ClearAllFactionMemberGoodwills(GuildFile factionFile)
{
for (int i = 0; i < factionFile.CurrentUids.Count(); i++)
{
if (file.Relationships.EnemyPlayers.Contains(factionFile.CurrentUids[i]))
if (file.EnemyPlayers.Contains(factionFile.CurrentUids[i]))
{
file.Relationships.EnemyPlayers.Remove(factionFile.CurrentUids[i]);
file.EnemyPlayers.Remove(factionFile.CurrentUids[i]);
}

else if (file.Relationships.AllyPlayers.Contains(factionFile.CurrentUids[i]))
else if (file.AllyPlayers.Contains(factionFile.CurrentUids[i]))
{
file.Relationships.AllyPlayers.Remove(factionFile.CurrentUids[i]);
file.AllyPlayers.Remove(factionFile.CurrentUids[i]);
}
}

Expand All @@ -208,7 +208,7 @@ public static void UpdateClientGoodwills(ServerClient client)
SettlementFile[] settlements = PlayerSettlementManager.GetAllSettlements();

FactionGoodwillData factionGoodwillData = new FactionGoodwillData();
SiteIdendityFile[] sites = SiteManagerHelper.GetAllSites();
SiteFile[] sites = SiteManagerHelper.GetAllSites();

List<Goodwill> tempList = new List<Goodwill>();
foreach (SettlementFile settlement in settlements)
Expand All @@ -221,7 +221,7 @@ public static void UpdateClientGoodwills(ServerClient client)
factionGoodwillData._settlementGoodwills = tempList.ToArray();

tempList = new List<Goodwill>();
foreach (SiteIdendityFile site in sites)
foreach (SiteFile site in sites)
{
factionGoodwillData._siteTiles.Add(site.Tile);
tempList.Add(GetSiteGoodwill(client, site));
Expand Down
Loading

0 comments on commit d2e5e66

Please sign in to comment.