/// <summary>A callback raised when sending a message as a farmhand.</summary> /// <param name="client">The client sending the message.</param> /// <param name="message">The message being sent.</param> /// <param name="resume">Send the underlying message.</param> protected void OnClientSendingMessage(SLidgrenClient client, OutgoingMessage message, Action resume) { if (this.Monitor.IsVerbose) { this.Monitor.Log($"CLIENT SEND {(MessageType)message.MessageType} {message.FarmerID}", LogLevel.Trace); } switch (message.MessageType) { // sync mod context (step 1) case (byte)MessageType.PlayerIntroduction: client.sendMessage((byte)MessageType.ModContext, this.GetContextSyncMessageFields()); resume(); break; // run default logic default: resume(); break; } }
/// <summary>Process an incoming network message as a farmhand.</summary> /// <param name="client">The client instance that received the connection.</param> /// <param name="message">The message to process.</param> /// <param name="resume">Process the message using the game's default logic.</param> /// <returns>Returns whether the message was handled.</returns> public void OnClientProcessingMessage(SLidgrenClient client, IncomingMessage message, Action resume) { if (this.Monitor.IsVerbose) { this.Monitor.Log($"CLIENT RECV {(MessageType)message.MessageType} {message.FarmerID}", LogLevel.Trace); } switch (message.MessageType) { // mod context sync (step 4) case (byte)MessageType.ModContext: { // parse message RemoteContextModel model = this.ReadContext(message.Reader); this.Monitor.Log($"Received context for {(model?.IsHost == true ? "host" : "farmhand")} {message.FarmerID} running {(model != null ? $"SMAPI {model.ApiVersion} with {model.Mods.Length} mods" : "vanilla")}.", LogLevel.Trace); // store peer MultiplayerPeer peer = MultiplayerPeer.ForConnectionToHost(message.FarmerID, model, client, model?.IsHost ?? this.HostPeer == null); if (peer.IsHost && this.HostPeer != null) { this.Monitor.Log($"Rejected mod context from host player {peer.PlayerID}: already received host data from {(peer.PlayerID == this.HostPeer.PlayerID ? "that player" : $"player {peer.PlayerID}")}.", LogLevel.Error); return; }