Added support to send a message to a specific farmer.
This commit is contained in:
parent
9c1314480c
commit
947e0c557f
|
@ -71,10 +71,12 @@ namespace ModdedUtilitiesNetworking
|
||||||
private void ControlEvents_KeyPressed(object sender, StardewModdingAPI.Events.EventArgsKeyPressed e)
|
private void ControlEvents_KeyPressed(object sender, StardewModdingAPI.Events.EventArgsKeyPressed e)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/*
|
||||||
if (e.KeyPressed==Microsoft.Xna.Framework.Input.Keys.K)
|
if (e.KeyPressed==Microsoft.Xna.Framework.Input.Keys.K)
|
||||||
{
|
{
|
||||||
multiplayer.sendModInfoReturnVoid(Framework.Features.Stardew.MessageFeatures.FSTRING_SendHUDMessageWithIcon, MessagesExtentions.HUDMessageIconIdentifier, new HUDMessage("My love is like fire",1),Framework.Enums.MessageTypes.messageTypes.SendToAll);
|
//multiplayer.sendMessage(Framework.Features.Stardew.MessageFeatures.FSTRING_SendHUDMessageWithIcon, MessagesExtentions.HUDMessageIconIdentifier, new HUDMessage("My love is like fire",1),Framework.Enums.MessageTypes.messageTypes.SendToSpecific,Game1.otherFarmers.ElementAt(0).Value);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace ModdedUtilitiesNetworking.Framework
|
||||||
/// Sends an outgoing message to appropriate players.
|
/// Sends an outgoing message to appropriate players.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message"></param>
|
||||||
public void sendMessage(OutgoingMessage message)
|
private void sendMessage(OutgoingMessage message)
|
||||||
{
|
{
|
||||||
if (Game1.server != null)
|
if (Game1.server != null)
|
||||||
{
|
{
|
||||||
|
@ -104,6 +104,27 @@ namespace ModdedUtilitiesNetworking.Framework
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OutgoingMessage sendOutGoingMessageReturnVoid(string functionName, string objectParametersType, object data, Farmer source, Enums.MessageTypes.messageTypes sendingInfo, Farmer recipient)
|
||||||
|
{
|
||||||
|
byte bite = new byte();
|
||||||
|
if (sendingInfo == Enums.MessageTypes.messageTypes.SendOneWay) bite = Enums.MessageTypes.SendOneWay;
|
||||||
|
if (sendingInfo == Enums.MessageTypes.messageTypes.SendToAll) bite = Enums.MessageTypes.SendToAll;
|
||||||
|
if (sendingInfo == Enums.MessageTypes.messageTypes.SendToSpecific) bite = Enums.MessageTypes.SendToSpecific;
|
||||||
|
OutgoingMessage message = new OutgoingMessage(bite, source, makeDataArray(functionName, objectParametersType, data,recipient));
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OutgoingMessage sendOutGoingMessageReturnVoid(string functionName, Type objectParametersType, object data, Farmer source, Enums.MessageTypes.messageTypes sendingInfo, Farmer recipient)
|
||||||
|
{
|
||||||
|
byte bite = new byte();
|
||||||
|
if (sendingInfo == Enums.MessageTypes.messageTypes.SendOneWay) bite = Enums.MessageTypes.SendOneWay;
|
||||||
|
if (sendingInfo == Enums.MessageTypes.messageTypes.SendToAll) bite = Enums.MessageTypes.SendToAll;
|
||||||
|
if (sendingInfo == Enums.MessageTypes.messageTypes.SendToSpecific) bite = Enums.MessageTypes.SendToSpecific;
|
||||||
|
OutgoingMessage message = new OutgoingMessage(bite, source, makeDataArray(functionName, objectParametersType.ToString(), data, recipient));
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public object[] makeDataArray(string functionName, string objectParametersType, object data)
|
public object[] makeDataArray(string functionName, string objectParametersType, object data)
|
||||||
{
|
{
|
||||||
|
@ -117,6 +138,30 @@ namespace ModdedUtilitiesNetworking.Framework
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public object[] makeDataArray(string functionName, string objectParametersType, object data, Farmer recipient)
|
||||||
|
{
|
||||||
|
DataInfo datainfo = new DataInfo(objectParametersType, data,recipient);
|
||||||
|
object[] obj = new object[3]
|
||||||
|
{
|
||||||
|
functionName,
|
||||||
|
typeof(DataInfo).ToString(),
|
||||||
|
datainfo,
|
||||||
|
};
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object[] makeDataArray(string functionName, string objectParametersType, object data, long recipient)
|
||||||
|
{
|
||||||
|
DataInfo datainfo = new DataInfo(objectParametersType, data, recipient.ToString());
|
||||||
|
object[] obj = new object[3]
|
||||||
|
{
|
||||||
|
functionName,
|
||||||
|
typeof(DataInfo).ToString(),
|
||||||
|
datainfo,
|
||||||
|
};
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates all of the necessary parameters for the outgoing message to be sent to the server/client on what to do and how to handle the data sent.
|
/// Creates all of the necessary parameters for the outgoing message to be sent to the server/client on what to do and how to handle the data sent.
|
||||||
/// This message written will attempt to access a function that doesn't return anything. Essentially null.
|
/// This message written will attempt to access a function that doesn't return anything. Essentially null.
|
||||||
|
@ -124,30 +169,65 @@ namespace ModdedUtilitiesNetworking.Framework
|
||||||
/// <param name="uniqueID"></param>
|
/// <param name="uniqueID"></param>
|
||||||
/// <param name="classType"></param>
|
/// <param name="classType"></param>
|
||||||
/// <param name="data"></param>
|
/// <param name="data"></param>
|
||||||
public void sendModInfoReturnVoid(string uniqueID,Type classType,object data, Enums.MessageTypes.messageTypes sendingInfo)
|
public void sendMessage(string uniqueID, Type classType, object data, Enums.MessageTypes.messageTypes sendingInfo, Farmer recipient = null)
|
||||||
{
|
{
|
||||||
Farmer f = Game1.player;
|
Farmer f = Game1.player;
|
||||||
|
|
||||||
OutgoingMessage message =ModCore.multiplayer.sendOutGoingMessageReturnVoid(uniqueID, classType, data, f, sendingInfo);
|
if ((sendingInfo == Enums.MessageTypes.messageTypes.SendOneWay || sendingInfo == Enums.MessageTypes.messageTypes.SendToAll))
|
||||||
|
{
|
||||||
|
OutgoingMessage message = ModCore.multiplayer.sendOutGoingMessageReturnVoid(uniqueID, classType, data, f, sendingInfo);
|
||||||
|
ModCore.multiplayer.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ModCore.multiplayer.sendMessage(message);
|
if (sendingInfo == Enums.MessageTypes.messageTypes.SendToSpecific && recipient != null)
|
||||||
|
{
|
||||||
|
OutgoingMessage message = ModCore.multiplayer.sendOutGoingMessageReturnVoid(uniqueID, classType, data, f, sendingInfo, recipient);
|
||||||
|
ModCore.multiplayer.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sendingInfo == Enums.MessageTypes.messageTypes.SendToSpecific && recipient == null)
|
||||||
|
{
|
||||||
|
ModCore.monitor.Log("ERROR: Attempted to send a target specific message to a NULL recipient");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates all of the necessary parameters for the outgoing message to be sent to the server/client on what to do and how to handle the data sent.
|
/// A way to send mod info across the net.
|
||||||
/// This message written will attempt to access a function that doesn't return anything. Essentially null.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="uniqueID"></param>
|
/// <param name="uniqueID"></param>
|
||||||
/// <param name="classType"></param>
|
/// <param name="classType"></param>
|
||||||
/// <param name="data"></param>
|
/// <param name="data"></param>
|
||||||
public void sendModInfoReturnVoid(string uniqueID, string classType, object data, Enums.MessageTypes.messageTypes sendingInfo)
|
/// <param name="sendingInfo"></param>
|
||||||
|
/// <param name="recipient"></param>
|
||||||
|
public void sendMessage(string uniqueID, string classType, object data, Enums.MessageTypes.messageTypes sendingInfo, Farmer recipient=null)
|
||||||
{
|
{
|
||||||
Farmer f = Game1.player;
|
Farmer f = Game1.player;
|
||||||
|
|
||||||
OutgoingMessage message = ModCore.multiplayer.sendOutGoingMessageReturnVoid(uniqueID, classType, data, f,sendingInfo);
|
if ((sendingInfo == Enums.MessageTypes.messageTypes.SendOneWay || sendingInfo == Enums.MessageTypes.messageTypes.SendToAll))
|
||||||
|
{
|
||||||
|
OutgoingMessage message = ModCore.multiplayer.sendOutGoingMessageReturnVoid(uniqueID, classType, data, f, sendingInfo);
|
||||||
|
ModCore.multiplayer.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ModCore.multiplayer.sendMessage(message);
|
if (sendingInfo == Enums.MessageTypes.messageTypes.SendToSpecific && recipient!=null)
|
||||||
|
{
|
||||||
|
OutgoingMessage message = ModCore.multiplayer.sendOutGoingMessageReturnVoid(uniqueID, classType, data, f, sendingInfo,recipient);
|
||||||
|
ModCore.multiplayer.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sendingInfo == Enums.MessageTypes.messageTypes.SendToSpecific && recipient == null)
|
||||||
|
{
|
||||||
|
ModCore.monitor.Log("ERROR: Attempted to send a target specific message to a NULL recipient");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using StardewValley;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
@ -10,6 +11,7 @@ namespace ModdedUtilitiesNetworking.Framework
|
||||||
{
|
{
|
||||||
public string type;
|
public string type;
|
||||||
public object data;
|
public object data;
|
||||||
|
public string recipientID;
|
||||||
|
|
||||||
public DataInfo()
|
public DataInfo()
|
||||||
{
|
{
|
||||||
|
@ -19,8 +21,21 @@ namespace ModdedUtilitiesNetworking.Framework
|
||||||
{
|
{
|
||||||
this.type = Type;
|
this.type = Type;
|
||||||
this.data = Data;
|
this.data = Data;
|
||||||
|
this.recipientID = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DataInfo(string Type, object Data, Farmer farmer)
|
||||||
|
{
|
||||||
|
this.type = Type;
|
||||||
|
this.data = Data;
|
||||||
|
this.recipientID = farmer.UniqueMultiplayerID.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataInfo(string Type, object Data, string uniqueID)
|
||||||
|
{
|
||||||
|
this.type = Type;
|
||||||
|
this.data = Data;
|
||||||
|
this.recipientID = uniqueID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,8 +96,8 @@ namespace ModdedUtilitiesNetworking.Framework.Extentions
|
||||||
{
|
{
|
||||||
String key=reader.ReadString();
|
String key=reader.ReadString();
|
||||||
object data = ModCore.processTypesToRead(reader, key);
|
object data = ModCore.processTypesToRead(reader, key);
|
||||||
|
string ID = reader.ReadString();
|
||||||
DataInfo info = new DataInfo(key,data);
|
DataInfo info = new DataInfo(key,data,ID);
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +115,7 @@ namespace ModdedUtilitiesNetworking.Framework.Extentions
|
||||||
writer.WriteString(dataInfo.type);
|
writer.WriteString(dataInfo.type);
|
||||||
ModCore.monitor.Log("WRITE DATA INFO FUNCTION3: " + dataInfo.type);
|
ModCore.monitor.Log("WRITE DATA INFO FUNCTION3: " + dataInfo.type);
|
||||||
ModCore.processTypesToWrite(writer, dataInfo.type, dataInfo.data);
|
ModCore.processTypesToWrite(writer, dataInfo.type, dataInfo.data);
|
||||||
|
writer.WriteString(dataInfo.recipientID);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Can do custom classes here for reading and writing.
|
//Can do custom classes here for reading and writing.
|
||||||
|
|
|
@ -393,6 +393,25 @@ namespace ModdedUtilitiesNetworking.Framework.Servers
|
||||||
object actualObject2 = ModCore.processTypesToRead(message.Reader, classType2);
|
object actualObject2 = ModCore.processTypesToRead(message.Reader, classType2);
|
||||||
ModCore.processVoidFunction(functionName2, actualObject2);
|
ModCore.processVoidFunction(functionName2, actualObject2);
|
||||||
this.rebroadcastClientMessageToAllClients(message);
|
this.rebroadcastClientMessageToAllClients(message);
|
||||||
|
break;
|
||||||
|
case Enums.MessageTypes.SendToSpecific:
|
||||||
|
//Read in specific info.
|
||||||
|
object[] obj3 = message.Reader.ReadModdedInfoPacket();
|
||||||
|
string functionName3 = (string)obj3[0];
|
||||||
|
string classType3 = (string)obj3[1];
|
||||||
|
//Parse
|
||||||
|
object actualObject3 = ModCore.processTypesToRead(message.Reader, classType3);
|
||||||
|
DataInfo info = (DataInfo)actualObject3;
|
||||||
|
|
||||||
|
if (info.recipientID == Game1.player.UniqueMultiplayerID.ToString())
|
||||||
|
{
|
||||||
|
ModCore.processVoidFunction(functionName3, actualObject3);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.sendMessageToSpecificClient(message, info);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ModCore.multiplayer.processIncomingMessage(message);
|
ModCore.multiplayer.processIncomingMessage(message);
|
||||||
|
@ -416,7 +435,24 @@ namespace ModdedUtilitiesNetworking.Framework.Servers
|
||||||
ModCore.monitor.Log("RESEND MESSAGE TO CLIENT!!!", StardewModdingAPI.LogLevel.Alert);
|
ModCore.monitor.Log("RESEND MESSAGE TO CLIENT!!!", StardewModdingAPI.LogLevel.Alert);
|
||||||
this.sendMessage(peerId, message1);
|
this.sendMessage(peerId, message1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendMessageToSpecificClient(IncomingMessage message, long farmerID)
|
||||||
|
{
|
||||||
|
byte messageType = Enums.MessageTypes.SendOneWay;
|
||||||
|
Farmer f = Game1.player;
|
||||||
|
object data = message.Data.Clone();
|
||||||
|
OutgoingMessage message1 = new OutgoingMessage(messageType, f, data);
|
||||||
|
this.sendMessage(farmerID, message1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendMessageToSpecificClient(IncomingMessage message, DataInfo info)
|
||||||
|
{
|
||||||
|
byte messageType = Enums.MessageTypes.SendOneWay;
|
||||||
|
Farmer f = Game1.player;
|
||||||
|
object data = message.Data.Clone();
|
||||||
|
OutgoingMessage message1 = new OutgoingMessage(messageType, f, data);
|
||||||
|
this.sendMessage(long.Parse(info.recipientID), message1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rebroadcastClientMessage(IncomingMessage message)
|
private void rebroadcastClientMessage(IncomingMessage message)
|
||||||
|
|
Loading…
Reference in New Issue