add separate LogNetworkTraffic option
This commit is contained in:
parent
d4e09c5a85
commit
bf3738eacb
|
@ -25,6 +25,7 @@ These changes have not been released yet.
|
|||
* Added `IContentPack.HasFile` method.
|
||||
* Added `Context.IsGameLaunched` field.
|
||||
* Mods are now loaded much earlier in the game launch. This lets mods intercept any content asset, but the game is not fully initialised when `Entry` is called (use the `GameLaunched` event if you need to run code when the game is initialised).
|
||||
* Added separate `LogNetworkTraffic` option to make verbose logging less overwhelmingly verbose.
|
||||
* When a mod is incompatible, the trace logs now list all detected issues instead of the first one.
|
||||
* Removed all deprecated APIs.
|
||||
* Removed the `Monitor.ExitGameImmediately` method.
|
||||
|
|
|
@ -34,6 +34,9 @@ namespace StardewModdingAPI.Framework.Models
|
|||
/// <summary>Whether SMAPI should log more information about the game context.</summary>
|
||||
public bool VerboseLogging { get; set; }
|
||||
|
||||
/// <summary>Whether SMAPI should log network traffic. Best combined with <see cref="VerboseLogging"/>, which includes network metadata.</summary>
|
||||
public bool LogNetworkTraffic { get; set; }
|
||||
|
||||
/// <summary>Whether to generate a file in the mods folder with detailed metadata about the detected mods.</summary>
|
||||
public bool DumpMetadata { get; set; }
|
||||
|
||||
|
|
|
@ -223,7 +223,8 @@ namespace StardewModdingAPI.Framework
|
|||
deprecationManager: SCore.DeprecationManager,
|
||||
onGameInitialised: this.InitialiseAfterGameStart,
|
||||
onGameExiting: this.Dispose,
|
||||
cancellationToken: this.CancellationToken
|
||||
cancellationToken: this.CancellationToken,
|
||||
logNetworkTraffic: this.Settings.LogNetworkTraffic
|
||||
);
|
||||
StardewValley.Program.gamePtr = this.GameInstance;
|
||||
|
||||
|
|
|
@ -141,7 +141,8 @@ namespace StardewModdingAPI.Framework
|
|||
/// <param name="onGameInitialised">A callback to invoke after the game finishes initialising.</param>
|
||||
/// <param name="onGameExiting">A callback to invoke when the game exits.</param>
|
||||
/// <param name="cancellationToken">Propagates notification that SMAPI should exit.</param>
|
||||
internal SGame(Monitor monitor, IMonitor monitorForGame, Reflector reflection, EventManager eventManager, JsonHelper jsonHelper, ModRegistry modRegistry, DeprecationManager deprecationManager, Action onGameInitialised, Action onGameExiting, CancellationTokenSource cancellationToken)
|
||||
/// <param name="logNetworkTraffic">Whether to log network traffic.</param>
|
||||
internal SGame(Monitor monitor, IMonitor monitorForGame, Reflector reflection, EventManager eventManager, JsonHelper jsonHelper, ModRegistry modRegistry, DeprecationManager deprecationManager, Action onGameInitialised, Action onGameExiting, CancellationTokenSource cancellationToken, bool logNetworkTraffic)
|
||||
{
|
||||
this.OnLoadingFirstAsset = SGame.ConstructorHack.OnLoadingFirstAsset;
|
||||
SGame.ConstructorHack = null;
|
||||
|
@ -163,7 +164,7 @@ namespace StardewModdingAPI.Framework
|
|||
this.OnGameInitialised = onGameInitialised;
|
||||
this.OnGameExiting = onGameExiting;
|
||||
Game1.input = new SInputState();
|
||||
Game1.multiplayer = new SMultiplayer(monitor, eventManager, jsonHelper, modRegistry, reflection, this.OnModMessageReceived);
|
||||
Game1.multiplayer = new SMultiplayer(monitor, eventManager, jsonHelper, modRegistry, reflection, this.OnModMessageReceived, logNetworkTraffic);
|
||||
Game1.hooks = new SModHooks(this.OnNewDayAfterFade);
|
||||
this.CancellationToken = cancellationToken;
|
||||
|
||||
|
|
|
@ -51,6 +51,9 @@ namespace StardewModdingAPI.Framework
|
|||
/// <summary>A callback to invoke when a mod message is received.</summary>
|
||||
private readonly Action<ModMessageModel> OnModMessageReceived;
|
||||
|
||||
/// <summary>Whether to log network traffic.</summary>
|
||||
private readonly bool LogNetworkTraffic;
|
||||
|
||||
|
||||
/*********
|
||||
** Accessors
|
||||
|
@ -72,7 +75,8 @@ namespace StardewModdingAPI.Framework
|
|||
/// <param name="modRegistry">Tracks the installed mods.</param>
|
||||
/// <param name="reflection">Simplifies access to private code.</param>
|
||||
/// <param name="onModMessageReceived">A callback to invoke when a mod message is received.</param>
|
||||
public SMultiplayer(IMonitor monitor, EventManager eventManager, JsonHelper jsonHelper, ModRegistry modRegistry, Reflector reflection, Action<ModMessageModel> onModMessageReceived)
|
||||
/// <param name="logNetworkTraffic">Whether to log network traffic.</param>
|
||||
public SMultiplayer(IMonitor monitor, EventManager eventManager, JsonHelper jsonHelper, ModRegistry modRegistry, Reflector reflection, Action<ModMessageModel> onModMessageReceived, bool logNetworkTraffic)
|
||||
{
|
||||
this.Monitor = monitor;
|
||||
this.EventManager = eventManager;
|
||||
|
@ -80,6 +84,7 @@ namespace StardewModdingAPI.Framework
|
|||
this.ModRegistry = modRegistry;
|
||||
this.Reflection = reflection;
|
||||
this.OnModMessageReceived = onModMessageReceived;
|
||||
this.LogNetworkTraffic = logNetworkTraffic;
|
||||
}
|
||||
|
||||
/// <summary>Perform cleanup needed when a multiplayer session ends.</summary>
|
||||
|
@ -143,7 +148,7 @@ namespace StardewModdingAPI.Framework
|
|||
/// <param name="resume">Resume sending the underlying message.</param>
|
||||
protected void OnClientSendingMessage(OutgoingMessage message, Action<OutgoingMessage> sendMessage, Action resume)
|
||||
{
|
||||
if (this.Monitor.IsVerbose)
|
||||
if (this.LogNetworkTraffic)
|
||||
this.Monitor.Log($"CLIENT SEND {(MessageType)message.MessageType} {message.FarmerID}", LogLevel.Trace);
|
||||
|
||||
switch (message.MessageType)
|
||||
|
@ -167,7 +172,7 @@ namespace StardewModdingAPI.Framework
|
|||
/// <param name="resume">Process the message using the game's default logic.</param>
|
||||
public void OnServerProcessingMessage(IncomingMessage message, Action<OutgoingMessage> sendMessage, Action resume)
|
||||
{
|
||||
if (this.Monitor.IsVerbose)
|
||||
if (this.LogNetworkTraffic)
|
||||
this.Monitor.Log($"SERVER RECV {(MessageType)message.MessageType} {message.FarmerID}", LogLevel.Trace);
|
||||
|
||||
switch (message.MessageType)
|
||||
|
@ -247,7 +252,7 @@ namespace StardewModdingAPI.Framework
|
|||
/// <returns>Returns whether the message was handled.</returns>
|
||||
public void OnClientProcessingMessage(IncomingMessage message, Action<OutgoingMessage> sendMessage, Action resume)
|
||||
{
|
||||
if (this.Monitor.IsVerbose)
|
||||
if (this.LogNetworkTraffic)
|
||||
this.Monitor.Log($"CLIENT RECV {(MessageType)message.MessageType} {message.FarmerID}", LogLevel.Trace);
|
||||
|
||||
switch (message.MessageType)
|
||||
|
@ -371,7 +376,7 @@ namespace StardewModdingAPI.Framework
|
|||
string data = JsonConvert.SerializeObject(model, Formatting.None);
|
||||
|
||||
// log message
|
||||
if (this.Monitor.IsVerbose)
|
||||
if (this.LogNetworkTraffic)
|
||||
this.Monitor.Log($"Broadcasting '{messageType}' message: {data}.", LogLevel.Trace);
|
||||
|
||||
// send message
|
||||
|
@ -432,7 +437,7 @@ namespace StardewModdingAPI.Framework
|
|||
string json = message.Reader.ReadString();
|
||||
ModMessageModel model = this.JsonHelper.Deserialise<ModMessageModel>(json);
|
||||
HashSet<long> playerIDs = new HashSet<long>(model.ToPlayerIDs ?? this.GetKnownPlayerIDs());
|
||||
if (this.Monitor.IsVerbose)
|
||||
if (this.LogNetworkTraffic)
|
||||
this.Monitor.Log($"Received message: {json}.", LogLevel.Trace);
|
||||
|
||||
// notify local mods
|
||||
|
|
|
@ -61,6 +61,11 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha
|
|||
*/
|
||||
"VerboseLogging": false,
|
||||
|
||||
/**
|
||||
* Whether SMAPI should log network traffic (may be very verbose). Best combined with VerboseLogging, which includes network metadata.
|
||||
*/
|
||||
"LogNetworkTraffic": false,
|
||||
|
||||
/**
|
||||
* Whether to generate a 'SMAPI-latest.metadata-dump.json' file in the logs folder with the full mod
|
||||
* metadata for detected mods. This is only needed when troubleshooting some cases.
|
||||
|
|
Loading…
Reference in New Issue