Fiexed some blaring error messages, gave Happy Birthday it's much needed multiplayer support.

This commit is contained in:
2018-05-09 14:23:42 -07:00
parent 11025947fb
commit bd656c444b
16 changed files with 243 additions and 75 deletions

View File

@ -51,6 +51,8 @@ namespace Omegasis.HappyBirthday.Framework
this.SetUpPositions();
}
/// <summary>The method called when the game window changes size.</summary>
/// <param name="oldBounds">The former viewport.</param>
/// <param name="newBounds">The new viewport.</param>
@ -196,6 +198,7 @@ namespace Omegasis.HappyBirthday.Framework
if (this.OkButton.containsPoint(x, y))
{
if (this.BirthdaySeason == "" || this.BirthdayDay == 0) return;
this.HandleButtonClick(this.OkButton.name);
this.OkButton.scale -= 0.25f;
this.OkButton.scale = Math.Max(0.75f, this.OkButton.scale);

View File

@ -1,4 +1,5 @@
using StardewValley;
using ModdedUtilitiesNetworking.Framework;
using StardewValley;
using System.Collections.Generic;
namespace Omegasis.HappyBirthday.Framework
@ -17,8 +18,6 @@ namespace Omegasis.HappyBirthday.Framework
Game1.addHUDMessage(new HUDMessage(message, 1));
if (!message.Contains("Inventory"))
{
Game1.playSound("cancel");
@ -29,6 +28,9 @@ namespace Omegasis.HappyBirthday.Framework
Game1.player.mailReceived.Add("BackpackTip");
Game1.addMailForTomorrow("pierreBackpack", false, false);
}
}
}
}

View File

@ -0,0 +1,56 @@
using ModdedUtilitiesNetworking.Framework;
using StardewValley;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static ModdedUtilitiesNetworking.Framework.Delegates.DelegateInfo;
namespace Omegasis.HappyBirthday.Framework
{
public class MultiplayerSupport
{
public static string FSTRING_SendBirthdayMessageToOthers = "Omegasis.HappyBirthday.Framework.Messages.SendBirthdayMessageToOtherPlayers";
public static void initializeMultiplayerSupport()
{
ModdedUtilitiesNetworking.ModCore.possibleVoidFunctions.Add(FSTRING_SendBirthdayMessageToOthers,new voidFunc(ShowStarMessage));
}
public static void ShowStarMessage(object obj)
{
//IEnumerable<Farmer> players= Game1.getAllFarmers();
DataInfo info = (DataInfo)obj;
HUDMessage message = (HUDMessage)info.data;
Game1.addHUDMessage(message);
if (!message.message.Contains("Inventory"))
{
Game1.playSound("cancel");
return;
}
if (!Game1.player.mailReceived.Contains("BackpackTip"))
{
Game1.player.mailReceived.Add("BackpackTip");
Game1.addMailForTomorrow("pierreBackpack", false, false);
}
}
public static void SendBirthdayMessageToOtherPlayers()
{
HUDMessage message = new HUDMessage("It's " + Game1.player.Name + "'s birthday! Happy birthday to them!", 1);
List<Farmer> farmers =ModdedUtilitiesNetworking.Framework.CustomMultiplayer.getAllFarmersExceptThisOne();
foreach (Farmer f in farmers)
{
ModdedUtilitiesNetworking.ModCore.multiplayer.sendMessage(FSTRING_SendBirthdayMessageToOthers, ModdedUtilitiesNetworking.Framework.Extentions.StrardewValleyExtentions.MessagesExtentions.HUDMessageIconIdentifier, message, ModdedUtilitiesNetworking.Framework.Enums.MessageTypes.messageTypes.SendToSpecific, f);
}
}
}
}

View File

@ -19,7 +19,7 @@ namespace Omegasis.HappyBirthday
** Properties
*********/
/// <summary>The relative path for the current player's data file.</summary>
private string DataFilePath => Path.Combine("data", $"{Constants.SaveFolderName}.json");
private string DataFilePath;
/// <summary>The absolute path for the current player's legacy data file.</summary>
private string LegacyDataFilePath => Path.Combine(this.Helper.DirectoryPath, "Player_Birthdays", $"HappyBirthday_{Game1.player.Name}.txt");
@ -125,6 +125,8 @@ namespace Omegasis.HappyBirthday
SaveEvents.AfterLoad += this.SaveEvents_AfterLoad;
SaveEvents.BeforeSave += this.SaveEvents_BeforeSave;
ControlEvents.KeyPressed += this.ControlEvents_KeyPressed;
MultiplayerSupport.initializeMultiplayerSupport();
}
@ -154,6 +156,8 @@ namespace Omegasis.HappyBirthday
/// <param name="e">The event data.</param>
private void SaveEvents_AfterLoad(object sender, EventArgs e)
{
this.DataFilePath = Path.Combine("data", Game1.player.Name + "_" + Game1.player.UniqueMultiplayerID+".json");
// reset state
this.VillagerQueue = new List<string>();
this.PossibleBirthdayGifts = new List<Item>();
@ -193,6 +197,8 @@ namespace Omegasis.HappyBirthday
if (this.IsBirthday())
{
Messages.ShowStarMessage("It's your birthday today! Happy birthday!");
MultiplayerSupport.SendBirthdayMessageToOtherPlayers();
Game1.player.mailbox.Add("birthdayMom");
Game1.player.mailbox.Add("birthdayDad");
@ -596,5 +602,6 @@ namespace Omegasis.HappyBirthday
}
}
}
}

View File

@ -71,6 +71,9 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="ModdedUtilitiesNetworking">
<HintPath>..\ModdedUtilitiesNetworking\bin\Release\ModdedUtilitiesNetworking.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
@ -80,6 +83,7 @@
</Compile>
<Compile Include="Framework\BirthdayMenu.cs" />
<Compile Include="Framework\ModConfig.cs" />
<Compile Include="Framework\MultiplayerSupport.cs" />
<Compile Include="Framework\PlayerData.cs" />
<Compile Include="HappyBirthday.cs" />
<Compile Include="Framework\Messages.cs" />

View File

@ -12,5 +12,11 @@
"UniqueID": "Omegasis.HappyBirthday",
"EntryDll": "HappyBirthday.dll",
"MinimumApiVersion": "2.0",
"UpdateKeys": [ "Nexus:520" ]
"UpdateKeys": [ "Nexus:520" ],
"Dependencies": [
{
"UniqueID": "Omegasis.ModdedUtilitiesNetworking",
"IsRequired": true
}
]
}

View File

@ -143,7 +143,7 @@ namespace ModdedUtilitiesNetworking
// get the field info
FieldInfo finfo = typeof(StardewValley.SDKs.GalaxyNetClient).GetField("lobbyId", bindingFlags);
var galaxyID = (GalaxyID)finfo.GetValue(Game1.client);
@ -257,7 +257,7 @@ namespace ModdedUtilitiesNetworking
{
if (v.Key == key)
{
ModCore.monitor.Log("PROCESS TYPES TO WRITE FUNCTION: "+v.Key + " " + data.ToString());
//ModCore.monitor.Log("PROCESS TYPES TO WRITE FUNCTION: "+v.Key + " " + data.ToString());
v.Value.write(msg,data);
return;
}

View File

@ -1,4 +1,5 @@
using Galaxy.Api;
using ModdedUtilitiesNetworking.Framework.Extentions;
using StardewValley;
using StardewValley.Network;
using StardewValley.SDKs;
@ -100,52 +101,25 @@ namespace ModdedUtilitiesNetworking.Framework.Clients
if (this.client == null || !this.client.Connected || this.serverId == (GalaxyID)null)
return;
this.client.Send(this.serverId, message);
//??? I'm asuuming for galaxy net clients I don't need to include any hacks on sending data....
}
protected override void processIncomingMessage(IncomingMessage message)
{
byte messageType = message.MessageType;
if ((uint)messageType <= 9U)
base.processIncomingMessage(message);
//Packet signiture for functions that return nothing.
if (message.MessageType == Enums.MessageTypes.SendOneWay || message.MessageType == Enums.MessageTypes.SendToAll)
{
switch (messageType)
{
case 1:
this.receiveServerIntroduction(message.Reader);
return;
case 2:
this.userNames[message.FarmerID] = message.Reader.ReadString();
ModCore.multiplayer.processIncomingMessage(message);
return;
case 3:
ModCore.multiplayer.processIncomingMessage(message);
return;
case 9:
this.receiveAvailableFarmhands(message.Reader);
return;
}
}
else if ((int)messageType != 11)
{
if ((int)messageType == 16)
{
if (message.FarmerID != Game1.serverHost.Value.UniqueMultiplayerID)
return;
this.receiveUserNameUpdate(message.Reader);
return;
}
}
else
{
this.connectionMessage = message.Reader.ReadString();
object[] obj = message.Reader.ReadModdedInfoPacket();
string functionName = (string)obj[0];
string classType = (string)obj[1];
object actualObject = ModCore.processTypesToRead(message.Reader, classType);
ModCore.processVoidFunction(functionName, actualObject);
return;
}
if (message.MessageType == 20)
{
ModCore.monitor.Log("JUMPING JELLYBEANS!!!");
}
ModCore.multiplayer.processIncomingMessage(message); //If we don't know how to initially process the message, send it to the multiplayer function.
}
}
}

View File

@ -27,6 +27,7 @@ namespace ModdedUtilitiesNetworking.Framework.Clients
public override string getUserID()
{
return "";
}
@ -74,6 +75,19 @@ namespace ModdedUtilitiesNetworking.Framework.Clients
this.connectionMessage = (string)null;
}
public void disconnect(string leaveMeNULL,bool neatly = true)
{
if (this.client.ConnectionStatus != NetConnectionStatus.Disconnected && this.client.ConnectionStatus != NetConnectionStatus.Disconnecting)
{
if (neatly)
this.sendMessage(new OutgoingMessage((byte)19, Game1.player, new object[0]));
this.client.FlushSendQueue();
this.client.Disconnect("");
this.client.FlushSendQueue();
}
this.connectionMessage = (string)null;
}
protected virtual bool validateProtocol(string version)
{
return version == ModCore.multiplayer.protocolVersion;
@ -162,10 +176,6 @@ namespace ModdedUtilitiesNetworking.Framework.Clients
}
int num = (int)this.client.SendMessage(message1, NetDeliveryMethod.ReliableOrdered);
if (num == (int)NetSendResult.Sent)
{
ModCore.monitor.Log("DONE Writing message from client!");
}
}
private void parseDataMessageFromServer(NetIncomingMessage dataMsg)
@ -188,7 +198,7 @@ namespace ModdedUtilitiesNetworking.Framework.Clients
protected override void processIncomingMessage(IncomingMessage message)
{
ModCore.monitor.Log("PROCESS PACKET" + ((int)message.MessageType).ToString());
base.processIncomingMessage(message);
//Packet signiture for functions that return nothing.
@ -201,6 +211,22 @@ namespace ModdedUtilitiesNetworking.Framework.Clients
ModCore.processVoidFunction(functionName, actualObject);
return;
}
else
{
if(message.MessageType == Enums.MessageTypes.SendToSpecific)
{
object[] obj = message.Reader.ReadModdedInfoPacket();
string functionName = (string)obj[0];
string classType = (string)obj[1];
object actualObject = ModCore.processTypesToRead(message.Reader, classType);
DataInfo info = (DataInfo)actualObject;
if (info.recipientID == Game1.player.UniqueMultiplayerID.ToString())
{
ModCore.processVoidFunction(functionName, actualObject);
}
}
}
//message.Reader.ReadChar();
//Write Binary ententions reader

View File

@ -236,6 +236,7 @@ namespace ModdedUtilitiesNetworking.Framework
public static Farmer getServerHost()
{
return Game1.serverHost.Value;
}
/// <summary>
@ -244,7 +245,14 @@ namespace ModdedUtilitiesNetworking.Framework
/// <returns></returns>
public static Farmer getPlayerOne()
{
return getServerHost();
try
{
return Game1.getAllFarmers().ElementAt(0);
}
catch(Exception err)
{
return null;
}
}
/// <summary>
@ -253,7 +261,16 @@ namespace ModdedUtilitiesNetworking.Framework
/// <returns></returns>
public static Farmer getPlayerTwo()
{
return Game1.otherFarmers.ElementAt(0).Value;
try
{
return Game1.getAllFarmers().ElementAt(1);
}
catch(Exception err)
{
return null;
}
}
/// <summary>
@ -262,7 +279,15 @@ namespace ModdedUtilitiesNetworking.Framework
/// <returns></returns>
public static Farmer getPlayerThree()
{
return Game1.otherFarmers.ElementAt(1).Value;
try
{
return Game1.getAllFarmers().ElementAt(2);
}
catch (Exception err)
{
return null;
}
}
/// <summary>
@ -271,7 +296,15 @@ namespace ModdedUtilitiesNetworking.Framework
/// <returns></returns>
public static Farmer getPlayerFour()
{
return Game1.otherFarmers.ElementAt(2).Value;
try
{
return Game1.getAllFarmers().ElementAt(3);
}
catch (Exception err)
{
return null;
}
}
@ -309,6 +342,26 @@ namespace ModdedUtilitiesNetworking.Framework
return otherFarmers;
}
/// <summary>
/// Gets a farmer from a player index number. Player 1 is 0, player two is one, etc.
/// </summary>
/// <param name="number"></param>
public Farmer getFarmerFromIndex(int number)
{
if (number == 0) return getPlayerOne();
if (number == 1) return getPlayerTwo();
if (number == 2) return getPlayerThree();
if (number == 3) return getPlayerFour();
try
{
Game1.getAllFarmers().ElementAt(number);
}
catch(Exception err)
{
return null;
}
return null;
}
}
}

View File

@ -108,12 +108,9 @@ namespace ModdedUtilitiesNetworking.Framework.Extentions
/// <param name="obj"></param>
public static void WriteDataInfo(this BinaryWriter writer, object obj)
{
DataInfo dataInfo = (DataInfo)obj;
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);
writer.WriteString(dataInfo.recipientID);
}

View File

@ -22,16 +22,29 @@ namespace ModdedUtilitiesNetworking.Framework.Servers
public List<Server> servers = new List<Server>();
public List<Action> pendingGameAvailableActions = new List<Action>();
public CustomGameServer()
{
this.servers = new List<Server>();
this.servers.Add(ModCore.multiplayer.InitServer((Server)new CustomLidgrenServer((IGameServer)this)));
ModCore.monitor.Log("Custom Lidgren Server Created");
ModCore.monitor.Log("Custom Game Server Created");
if (Program.sdk.Networking == null)
public CustomGameServer()
{
this.servers = new List<Server>();
this.servers.Add(ModCore.multiplayer.InitServer((Server)new CustomLidgrenServer((IGameServer)this)));
ModCore.monitor.Log("Custom Lidgren Server Created");
ModCore.monitor.Log("Custom Game Server Created");
try {
if (Program.sdk.Networking == null)
return;
this.servers.Add(Program.sdk.Networking.CreateServer((IGameServer)this));
Server server = Program.sdk.Networking.CreateServer((IGameServer)this);
if (server != null)
{
this.servers.Add(server);
ModCore.monitor.Log("Custom Galaxy Server Created");
}
}
catch(Exception err)
{
ModCore.monitor.Log("Issue creating custom galaxy game server. If you are not playing via GOG you may ignore this message.");
return;
}
}
public CustomGameServer(List<Server> servers)
{
@ -78,8 +91,7 @@ namespace ModdedUtilitiesNetworking.Framework.Servers
{
foreach (Server server in this.servers)
{
if (server.connected() == true) continue;
server.initialize();
if(server!=null) server.initialize();
}
this.updateLobbyData();
}
@ -113,7 +125,17 @@ namespace ModdedUtilitiesNetworking.Framework.Servers
public void sendMessage(long peerId, OutgoingMessage message)
{
foreach (Server server in this.servers)
server.sendMessage(peerId, message);
if (server is CustomLidgrenServer)
{
server.sendMessage(peerId, message);
}
else //If I am not a custom lidgren server ignore sending modding info to clients. The lidgren server should handle all of that.
{
if (message.MessageType <= 19)
{
server.sendMessage(peerId, message);
}
}
}
public bool canAcceptIPConnections()
@ -468,7 +490,14 @@ namespace ModdedUtilitiesNetworking.Framework.Servers
private void setLobbyData(string key, string value)
{
foreach (Server server in this.servers)
server.setLobbyData(key, value);
try
{
server.setLobbyData(key, value);
}
catch(Exception err)
{
}
}
private bool unclaimedFarmhandsExist()

View File

@ -35,7 +35,7 @@ namespace ModdedUtilitiesNetworking.Framework.Servers
}
public override string getUserName(long farmerId)
{
{
if (!this.peers.ContainsLeft(farmerId))
return (string)null;
return this.peers[farmerId].RemoteEndPoint.Address.ToString();
@ -150,7 +150,14 @@ namespace ModdedUtilitiesNetworking.Framework.Servers
case NetConnectionStatus.Disconnecting:
if (!this.peers.ContainsRight(message.SenderConnection))
break;
this.playerDisconnected(this.peers[message.SenderConnection]);
try
{
this.playerDisconnected(this.peers[message.SenderConnection]);
}
catch(Exception err)
{
}
break;
}
}
@ -170,7 +177,6 @@ namespace ModdedUtilitiesNetworking.Framework.Servers
{
message.Read(reader);
int type = message.MessageType;
ModCore.monitor.Log("INCOMING MESSAGE TYPE: "+type.ToString());
if (this.peers.ContainsLeft(message.FarmerID) && this.peers[message.FarmerID] == peer)
this.gameServer.processIncomingMessage(message);
else if ((int)message.MessageType == 2)

View File

@ -9,10 +9,11 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ModdedUtilitiesNetworking</RootNamespace>
<AssemblyName>ModdedUtilitiesNetworking</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>

View File

@ -20,6 +20,9 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fall28SnowDay", "Fall28SnowDay\Fall28SnowDay.csproj", "{1DBB583D-4A4F-4A46-8CC5-42017C93D292}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HappyBirthday", "HappyBirthday\HappyBirthday.csproj", "{A7A4B67B-3CD7-421F-A4A7-2D656F0AB4D9}"
ProjectSection(ProjectDependencies) = postProject
{8DB124E3-E892-4E7C-A782-2DA47771338C} = {8DB124E3-E892-4E7C-A782-2DA47771338C}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoreRain", "MoreRain\MoreRain.csproj", "{45721A43-630A-461F-9A50-E47D3D1926D0}"
EndProject

View File

@ -96,6 +96,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="manifest.json" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>