Skip to content

Commit

Permalink
Remove log file spam
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmrcina committed Sep 2, 2023
1 parent 0e56c27 commit 38c0e5c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 29 deletions.
19 changes: 0 additions & 19 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,6 @@
],
"console": "internalConsole",
"internalConsoleOptions": "openOnSessionStart",
},
{
"name": "Launch Client (.NET)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "Build (Debug)",
"program": "${env:VINTAGE_STORY}/Vintagestory.exe",
"args": [
"--playStyle",
"preset-surviveandbuild",
"--openWorld",
"modding test world",
"--addModPath",
"${workspaceFolder}/bin/Debug",
"--addOrigin",
"${workspaceFolder}/resources/assets",
],
"console": "internalConsole",
"internalConsoleOptions": "openOnSessionStart",
}
]
}
2 changes: 1 addition & 1 deletion resources/modinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "code",
"name": "VsWaypointSharing",
"modid": "VsWaypointSharing",
"version": "1.0.4",
"version": "1.0.5",
"description": "A mod to allow sharing of waypoints in VS for multiplayer",
"website": "https://github.com/jsmrcina/VsWaypointSharing",
"authors": [
Expand Down
73 changes: 64 additions & 9 deletions src/VsWaypointSharing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Vintagestory.API.MathTools;
using Vintagestory.API.Config;
using Vintagestory.GameContent;
using System.Reflection;

[assembly: ModInfo("VsWaypointSharing",
Description = "Allows sharing waypoints to other users",
Expand Down Expand Up @@ -47,9 +48,14 @@ private class AddWpArgs
private Dictionary<IServerPlayer, SharingState> clientStates = new Dictionary<IServerPlayer, SharingState>();
private readonly int autoSyncThreadDelay = 15;

private bool debug = false;
private bool conflictingModErrorLogged = false;


public override void StartClientSide(ICoreClientAPI api)
{
{
ClientApi = api ?? throw new ArgumentException("Client API is null");
DetectDebugBuild(false);

ClientChannel = ClientApi.Network.RegisterChannel(_waypointSharingChannel)
.RegisterMessageType(typeof(WaypointShareMessage))
Expand All @@ -66,6 +72,7 @@ public override void StartClientSide(ICoreClientAPI api)
public override void StartServerSide(ICoreServerAPI api)
{
ServerApi = api ?? throw new ArgumentException("Server API is null");
DetectDebugBuild(true);

ServerChannel = ServerApi.Network.RegisterChannel(_waypointSharingChannel)
.RegisterMessageType(typeof(WaypointShareMessage))
Expand All @@ -81,19 +88,45 @@ public override void StartServerSide(ICoreServerAPI api)
ServerApi.Event.PlayerDisconnect += OnPlayerLeaveDisconnect;
}

public void DetectDebugBuild(bool isServer)
{
var assemblyConfigurationAttribute = typeof(VsWaypointSharing).Assembly.GetCustomAttribute<AssemblyConfigurationAttribute>();
var buildConfigurationName = assemblyConfigurationAttribute?.Configuration;
if(isServer)
{
ServerApi.Logger.Notification($"Build of VsWaypointSharing is of type: {buildConfigurationName}");
}
else
{
ClientApi.Logger.Notification($"Build of VsWaypointSharing is of type: {buildConfigurationName}");
}

if (buildConfigurationName.Equals("Debug"))
{
debug = true;
}
}

public void OnPlayerLeaveDisconnect(IServerPlayer player)
{
clientStates.Remove(player);
}

private void AutoSyncThreadFunction()
{
ServerApi.Logger.Notification($"Auto-sync thread running");
if (debug)
{
ServerApi.Logger.Notification($"Auto-sync thread running");
}

foreach (var sharingState in clientStates)
{
if (sharingState.Value.isAutoSyncEnabled == true)
{
ServerApi.Logger.Notification($"Auto-syncing client {sharingState.Key.PlayerUID}");
if (debug)
{
ServerApi.Logger.Notification($"Auto-syncing client {sharingState.Key.PlayerUID}");
}
WaypointShareMessage wsm = new WaypointShareMessage();
wsm.LogSuccess = false;
OnShareRequested(sharingState.Key, wsm);
Expand Down Expand Up @@ -131,7 +164,12 @@ private void OnRevertRequested(IServerPlayer fromPlayer, WaypointRevertMessage m
if (waypointLayer == null)
{
// Something has gone wrong
ServerApi.Logger.Notification($"VsWaypointSharing cannot function as the WaypointMapLayer is not WaypointMapLayerExtension class");
if (!conflictingModErrorLogged)
{
ServerApi.Logger.Error($"VsWaypointSharing cannot function as the WaypointMapLayer is not WaypointMapLayerExtension class");
conflictingModErrorLogged = true;
}
return;
}

List<Waypoint> waypoints = waypointLayer.Waypoints;
Expand Down Expand Up @@ -188,7 +226,12 @@ private void OnShareRequested(IServerPlayer fromPlayer, WaypointShareMessage wsm
if (waypointLayer == null)
{
// Something has gone wrong
ServerApi.Logger.Notification($"VsWaypointSharing cannot function as the WaypointMapLayer is not WaypointMapLayerExtension class");
if (!conflictingModErrorLogged)
{
ServerApi.Logger.Error($"VsWaypointSharing cannot function as the WaypointMapLayer is not WaypointMapLayerExtension class");
conflictingModErrorLogged = true;
}
return;
}

List<Waypoint> waypoints = waypointLayer.Waypoints;
Expand Down Expand Up @@ -223,11 +266,17 @@ private void OnShareRequested(IServerPlayer fromPlayer, WaypointShareMessage wsm
if (fromPlayerWaypoints.ContainsKey(w.Position))
{
// Don't clone this waypoint to the player, they already have a waypoint there
ServerApi.Logger.Notification($"Skipping waypoint, player already has it");
if (debug)
{
ServerApi.Logger.Notification($"Skipping waypoint, player already has it");
}
}
else
{
ServerApi.Logger.Notification($"Cloning waypoint {w.Icon} to player {fromPlayer.ClientId}");
if (debug)
{
ServerApi.Logger.Notification($"Cloning waypoint {w.Icon} to player {fromPlayer.ClientId}");
}

// TODO: When cloning another user's tombstone, use their name for the name

Expand All @@ -254,12 +303,18 @@ private void OnShareRequested(IServerPlayer fromPlayer, WaypointShareMessage wsm
}
else
{
ServerApi.Logger.Notification($"Skipping waypoint to player {fromPlayer.ClientId} as it is a copy (a synced waypoint)");
if (debug)
{
ServerApi.Logger.Notification($"Skipping waypoint to player {fromPlayer.ClientId} as it is a copy (a synced waypoint)");
}
}
}
else
{
ServerApi.Logger.Notification($"Skipping waypoint to player {fromPlayer.ClientId} as it's their own");
if (debug)
{
ServerApi.Logger.Notification($"Skipping waypoint to player {fromPlayer.ClientId} as it's their own");
}
}
}

Expand Down

0 comments on commit 38c0e5c

Please sign in to comment.