Skip to content

Commit

Permalink
Groundwork for rework
Browse files Browse the repository at this point in the history
  • Loading branch information
Byte-Nova committed Sep 7, 2024
1 parent eba4f83 commit 7fda25e
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 1,785 deletions.
2 changes: 1 addition & 1 deletion Source/Client/Managers/OfflineActivityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void RequestOfflineActivity(OfflineActivityType activityType)
return;
}

SessionValues.ToggleOfflineFunction(activityType);
SessionValues.ToggleOfflineActivity(activityType);

if (activityType == OfflineActivityType.Spy)
{
Expand Down
1,211 changes: 109 additions & 1,102 deletions Source/Client/Managers/OnlineActivityManager.cs

Large diffs are not rendered by default.

597 changes: 6 additions & 591 deletions Source/Client/Patches/OnlineActivityPatches.cs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Source/Client/Values/SessionValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public static void SetValues(ServerGlobalData serverGlobalData)
actionValues = serverGlobalData._actionValues;
}

public static void ToggleOnlineFunction(OnlineActivityType type) { currentRealTimeEvent = type; }
public static void ToggleOnlineActivity(OnlineActivityType type) { currentRealTimeEvent = type; }

public static void ToggleOfflineFunction(OfflineActivityType type) { latestOfflineActivity = type; }
public static void ToggleOfflineActivity(OfflineActivityType type) { latestOfflineActivity = type; }

public static void CleanValues()
{
ToggleOnlineFunction(OnlineActivityType.None);
ToggleOfflineFunction(OfflineActivityType.None);
ToggleOnlineActivity(OnlineActivityType.None);
ToggleOfflineActivity(OfflineActivityType.None);

chosenSettlement = null;
chosenCaravan = null;
Expand Down
30 changes: 15 additions & 15 deletions Source/Server/Managers/ChatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,27 +143,27 @@ public static class ChatCommandManager

private static readonly ChatCommand helpCommand = new ChatCommand("/help", 0,
"Shows a list of all available commands",
ChatHelpCommandAction);
HelpCommandAction);

private static readonly ChatCommand toolsCommand = new ChatCommand("/tools", 0,
"Shows a list of all available chat tools",
ChatToolsCommandAction);
ToolsCommandAction);

private static readonly ChatCommand pingCommand = new ChatCommand("/ping", 0,
"Checks if the connection to the server is working",
ChatPingCommandAction);
PingCommandAction);

private static readonly ChatCommand disconnectCommand = new ChatCommand("/dc", 0,
"Forcefully disconnects you from the server",
ChatDisconnectCommandAction);
DisconnectCommandAction);

private static readonly ChatCommand stopOnlineActivityCommand = new ChatCommand("/sv", 0,
"Forcefully disconnects you from a visit",
ChatStopOnlineActivityCommandAction);
private static readonly ChatCommand stopOnlineActivityCommand = new ChatCommand("/stopactivity", 0,
"Forcefully disconnects you from an activity",
StopOnlineActivityCommandAction);

private static readonly ChatCommand privateMessage = new ChatCommand("/w", 0,
"Sends a private message to a specific user",
ChatPrivateMessageCommandAction);
PrivateMessageCommandAction);

public static readonly ChatCommand[] chatCommands = new ChatCommand[]
{
Expand All @@ -175,7 +175,7 @@ public static class ChatCommandManager
privateMessage
};

private static void ChatHelpCommandAction()
private static void HelpCommandAction()
{
if (targetClient == null) return;
else
Expand All @@ -187,7 +187,7 @@ private static void ChatHelpCommandAction()
}
}

private static void ChatToolsCommandAction()
private static void ToolsCommandAction()
{
if (targetClient == null) return;
else
Expand All @@ -199,25 +199,25 @@ private static void ChatToolsCommandAction()
}
}

private static void ChatPingCommandAction()
private static void PingCommandAction()
{
if (targetClient == null) return;
else ChatManager.SendSystemMessage(targetClient, "Pong!");
}

private static void ChatDisconnectCommandAction()
private static void DisconnectCommandAction()
{
if (targetClient == null) return;
else targetClient.listener.disconnectFlag = true;
}

private static void ChatStopOnlineActivityCommandAction()
private static void StopOnlineActivityCommandAction()
{
if (targetClient == null) return;
else OnlineActivityManager.SendVisitStop(targetClient);
else OnlineActivityManager.StopActivity(targetClient);
}

private static void ChatPrivateMessageCommandAction()
private static void PrivateMessageCommandAction()
{
if (targetClient == null) return;
else
Expand Down
90 changes: 28 additions & 62 deletions Source/Server/Managers/OnlineActivityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,68 +13,32 @@ public static void ParseOnlineActivityPacket(ServerClient client, Packet packet)
return;
}

OnlineActivityData visitData = Serializer.ConvertBytesToObject<OnlineActivityData>(packet.contents);
OnlineActivityData data = Serializer.ConvertBytesToObject<OnlineActivityData>(packet.contents);

switch (visitData._stepMode)
switch (data._stepMode)
{
case OnlineActivityStepMode.Request:
SendVisitRequest(client, visitData);
RequestActivity(client, data);
break;

case OnlineActivityStepMode.Accept:
AcceptVisitRequest(client, visitData);
AcceptActivity(client, data);
break;

case OnlineActivityStepMode.Reject:
RejectVisitRequest(client, visitData);
break;

case OnlineActivityStepMode.Action:
SendVisitActions(client, visitData);
break;

case OnlineActivityStepMode.Create:
SendVisitActions(client, visitData);
break;

case OnlineActivityStepMode.Destroy:
SendVisitActions(client, visitData);
break;

case OnlineActivityStepMode.Damage:
SendVisitActions(client, visitData);
break;

case OnlineActivityStepMode.Hediff:
SendVisitActions(client, visitData);
break;

case OnlineActivityStepMode.TimeSpeed:
SendVisitActions(client, visitData);
break;

case OnlineActivityStepMode.GameCondition:
SendVisitActions(client, visitData);
break;

case OnlineActivityStepMode.Weather:
SendVisitActions(client, visitData);
break;

case OnlineActivityStepMode.Kill:
SendVisitActions(client, visitData);
RejectActivity(client, data);
break;

case OnlineActivityStepMode.Stop:
SendVisitStop(client);
StopActivity(client);
break;
}
}

private static void SendVisitRequest(ServerClient client, OnlineActivityData data)
private static void RequestActivity(ServerClient client, OnlineActivityData data)
{
SettlementFile settlementFile = SettlementManager.GetSettlementFileFromTile(data._toTile);
if (settlementFile == null) ResponseShortcutManager.SendIllegalPacket(client, $"Player {client.userFile.Username} tried to visit a settlement at tile {data._toTile}, but no settlement could be found");
if (settlementFile == null) ResponseShortcutManager.SendIllegalPacket(client, $"Player {client.userFile.Username} tried to engage with settlement at tile {data._toTile}, but no settlement could be found");
else
{
ServerClient toGet = UserManagerHelper.GetConnectedClientFromUsername(settlementFile.Owner);
Expand All @@ -87,7 +51,7 @@ private static void SendVisitRequest(ServerClient client, OnlineActivityData dat

else
{
if (toGet.inVisitWith != null)
if (toGet.activityPartner != null)
{
data._stepMode = OnlineActivityStepMode.Unavailable;
Packet packet = Packet.CreatePacketFromObject(nameof(PacketHandler.OnlineActivityPacket), data);
Expand All @@ -104,7 +68,7 @@ private static void SendVisitRequest(ServerClient client, OnlineActivityData dat
}
}

private static void AcceptVisitRequest(ServerClient client, OnlineActivityData data)
private static void AcceptActivity(ServerClient client, OnlineActivityData data)
{
SettlementFile settlementFile = SettlementManager.GetSettlementFileFromTile(data._fromTile);
if (settlementFile == null) return;
Expand All @@ -114,16 +78,17 @@ private static void AcceptVisitRequest(ServerClient client, OnlineActivityData d
if (toGet == null) return;
else
{
client.inVisitWith = toGet;
toGet.inVisitWith = client;
client.activityPartner = toGet;
toGet.activityPartner = client;

Packet packet = Packet.CreatePacketFromObject(nameof(PacketHandler.OnlineActivityPacket), data);
client.listener.EnqueuePacket(packet);
toGet.listener.EnqueuePacket(packet);
}
}
}

private static void RejectVisitRequest(ServerClient client, OnlineActivityData data)
private static void RejectActivity(ServerClient client, OnlineActivityData data)
{
SettlementFile settlementFile = SettlementManager.GetSettlementFileFromTile(data._fromTile);
if (settlementFile == null) return;
Expand All @@ -134,14 +99,15 @@ private static void RejectVisitRequest(ServerClient client, OnlineActivityData d
else
{
Packet packet = Packet.CreatePacketFromObject(nameof(PacketHandler.OnlineActivityPacket), data);
client.listener.EnqueuePacket(packet);
toGet.listener.EnqueuePacket(packet);
}
}
}

private static void SendVisitActions(ServerClient client, OnlineActivityData data)
private static void SendActions(ServerClient client, OnlineActivityData data)
{
if (client.inVisitWith == null)
if (client.activityPartner == null)
{
data._stepMode = OnlineActivityStepMode.Stop;
Packet packet = Packet.CreatePacketFromObject(nameof(PacketHandler.OnlineActivityPacket), data);
Expand All @@ -151,25 +117,25 @@ private static void SendVisitActions(ServerClient client, OnlineActivityData dat
else
{
Packet packet = Packet.CreatePacketFromObject(nameof(PacketHandler.OnlineActivityPacket), data);
client.inVisitWith.listener.EnqueuePacket(packet);
client.activityPartner.listener.EnqueuePacket(packet);
}
}

public static void SendVisitStop(ServerClient client)
public static void StopActivity(ServerClient client)
{
OnlineActivityData visitData = new OnlineActivityData();
visitData._stepMode = OnlineActivityStepMode.Stop;
OnlineActivityData data = new OnlineActivityData();
data._stepMode = OnlineActivityStepMode.Stop;

Packet packet = Packet.CreatePacketFromObject(nameof(PacketHandler.OnlineActivityPacket), visitData);
client.listener.EnqueuePacket(packet);
Packet packet = Packet.CreatePacketFromObject(nameof(PacketHandler.OnlineActivityPacket), data);

ServerClient otherPlayer = client.inVisitWith;
if (otherPlayer != null)
if (client.activityPartner != null)
{
otherPlayer.listener.EnqueuePacket(packet);
otherPlayer.inVisitWith = null;
client.inVisitWith = null;
client.activityPartner.listener.EnqueuePacket(packet);
client.activityPartner.activityPartner = null;
}

client.listener.EnqueuePacket(packet);
client.activityPartner = null;
}
}
}
2 changes: 1 addition & 1 deletion Source/Server/Network/Clients/ServerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ServerClient

[NonSerialized] public Listener listener;

[NonSerialized] public ServerClient inVisitWith;
[NonSerialized] public ServerClient activityPartner;

public ServerClient(TcpClient tcp)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Server/Network/Listener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void DestroyConnection()
connection.Close();
uploadManager?.fileStream.Close();
downloadManager?.fileStream.Close();
if (targetClient.inVisitWith != null) OnlineActivityManager.SendVisitStop(targetClient);
if (targetClient.activityPartner != null) OnlineActivityManager.StopActivity(targetClient);
}
}
}
2 changes: 1 addition & 1 deletion Source/Shared/Misc/CommonEnumerators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public enum TransferStepMode { TradeRequest, TradeAccept, TradeReject, TradeReRe

public enum OfflineActivityStepMode { Request, Deny, Unavailable }

public enum OnlineActivityStepMode { Request, Accept, Reject, Unavailable, Action, Create, Destroy, Damage, Hediff, Kill, TimeSpeed, GameCondition, Weather, Stop }
public enum OnlineActivityStepMode { Request, Accept, Reject, Unavailable, Stop }

public enum OnlineActivityTargetFaction { Faction, NonFaction, None }

Expand Down
10 changes: 3 additions & 7 deletions Source/Shared/PacketData/OnlineActivityData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@ public class OnlineActivityData

//Map

public MapFile _mapData;
public MapFile _mapFile;

public List<HumanFile> _mapHumans = new List<HumanFile>();
public HumanFile[] _guestHumans = new HumanFile[0];

public List<AnimalFile> _mapAnimals = new List<AnimalFile>();

public List<HumanFile> _caravanHumans = new List<HumanFile>();

public List<AnimalFile> _caravanAnimals = new List<AnimalFile>();
public AnimalFile[] _guestAnimals = new AnimalFile[0];

//Misc

Expand Down

0 comments on commit 7fda25e

Please sign in to comment.