Updated NetMod to prevent redundant messages and errors.
This commit is contained in:
parent
bd656c444b
commit
0fb7e729c1
|
@ -25,6 +25,8 @@ namespace ModdedUtilitiesNetworking.Framework.Clients
|
|||
this.address = address;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override string getUserID()
|
||||
{
|
||||
|
||||
|
@ -199,7 +201,43 @@ namespace ModdedUtilitiesNetworking.Framework.Clients
|
|||
protected override void processIncomingMessage(IncomingMessage message)
|
||||
{
|
||||
|
||||
base.processIncomingMessage(message);
|
||||
byte messageType = message.MessageType;
|
||||
if ((uint)messageType <= 9U)
|
||||
{
|
||||
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();
|
||||
return;
|
||||
}
|
||||
ModCore.multiplayer.baseProcessMessage(message);
|
||||
|
||||
|
||||
//Packet signiture for functions that return nothing.
|
||||
if (message.MessageType == Enums.MessageTypes.SendOneWay || message.MessageType == Enums.MessageTypes.SendToAll)
|
||||
|
@ -250,7 +288,7 @@ namespace ModdedUtilitiesNetworking.Framework.Clients
|
|||
this.setUpGame();
|
||||
if (Game1.chatBox == null)
|
||||
return;
|
||||
Game1.chatBox.listPlayers();
|
||||
//Game1.chatBox.listPlayers();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
using ModdedUtilitiesNetworking.Framework.Clients;
|
||||
using ModdedUtilitiesNetworking.Framework.Messages;
|
||||
using ModdedUtilitiesNetworking.Framework.Servers;
|
||||
using Netcode;
|
||||
using StardewValley;
|
||||
using StardewValley.Menus;
|
||||
using StardewValley.Network;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -15,6 +17,12 @@ namespace ModdedUtilitiesNetworking.Framework
|
|||
{
|
||||
public class CustomMultiplayer : StardewValley.Multiplayer
|
||||
{
|
||||
public List<long> hasConnectedOnce = new List<long>();
|
||||
|
||||
public CustomMultiplayer()
|
||||
{
|
||||
this.hasConnectedOnce = new List<long>();
|
||||
}
|
||||
|
||||
public override bool isClientBroadcastType(byte messageType)
|
||||
{
|
||||
|
@ -78,6 +86,11 @@ namespace ModdedUtilitiesNetworking.Framework
|
|||
this.tickLocationRoots();
|
||||
}
|
||||
|
||||
public void baseProcessMessage(IncomingMessage message)
|
||||
{
|
||||
base.processIncomingMessage(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a net outgoing message that is written specifically to call a void function when sent. USed to specifiy types and specific ways to handle them.
|
||||
/// </summary>
|
||||
|
@ -255,6 +268,20 @@ namespace ModdedUtilitiesNetworking.Framework
|
|||
}
|
||||
}
|
||||
|
||||
public override void addPlayer(NetFarmerRoot f)
|
||||
{
|
||||
long uniqueMultiplayerId = f.Value.UniqueMultiplayerID;
|
||||
//Surpresses the first connected chat info message on non modded clients.
|
||||
if (this.hasConnectedOnce.Contains(uniqueMultiplayerId))
|
||||
{
|
||||
base.addPlayer(f);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.hasConnectedOnce.Add(uniqueMultiplayerId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get's the farmer in the player two slot for the server.
|
||||
/// </summary>
|
||||
|
|
|
@ -21,6 +21,7 @@ namespace ModdedUtilitiesNetworking.Framework.Servers
|
|||
{
|
||||
public List<Server> servers = new List<Server>();
|
||||
public List<Action> pendingGameAvailableActions = new List<Action>();
|
||||
public List<long> hasPlayerDisconnectedOnce = new List<long>();
|
||||
|
||||
public CustomGameServer()
|
||||
{
|
||||
|
@ -28,7 +29,7 @@ namespace ModdedUtilitiesNetworking.Framework.Servers
|
|||
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");
|
||||
|
||||
hasPlayerDisconnectedOnce = new List<long>();
|
||||
try {
|
||||
if (Program.sdk.Networking == null)
|
||||
return;
|
||||
|
@ -46,16 +47,6 @@ namespace ModdedUtilitiesNetworking.Framework.Servers
|
|||
}
|
||||
}
|
||||
|
||||
public CustomGameServer(List<Server> servers)
|
||||
{
|
||||
this.servers = new List<Server>();
|
||||
|
||||
foreach(var server in servers)
|
||||
{
|
||||
this.servers.Add(server);
|
||||
}
|
||||
}
|
||||
|
||||
public int connectionsCount
|
||||
{
|
||||
get
|
||||
|
@ -225,6 +216,9 @@ namespace ModdedUtilitiesNetworking.Framework.Servers
|
|||
ModCore.multiplayer.playerDisconnected(disconnectee);
|
||||
if (sourceFarmer == null)
|
||||
return;
|
||||
|
||||
if (this.hasPlayerDisconnectedOnce.Contains(disconnectee))
|
||||
{
|
||||
OutgoingMessage message = new OutgoingMessage((byte)19, sourceFarmer, new object[0]);
|
||||
foreach (long peerId in (IEnumerable<long>)Game1.otherFarmers.Keys)
|
||||
{
|
||||
|
@ -232,6 +226,13 @@ namespace ModdedUtilitiesNetworking.Framework.Servers
|
|||
this.sendMessage(peerId, message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.hasPlayerDisconnectedOnce.Add(disconnectee);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public bool isGameAvailable()
|
||||
{
|
||||
|
|
|
@ -12,7 +12,7 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace ModdedUtilitiesNetworking.Framework.Servers
|
||||
{
|
||||
class CustomLidgrenServer : LidgrenServer
|
||||
class CustomLidgrenServer : Server
|
||||
{
|
||||
private HashSet<NetConnection> introductionsSent = new HashSet<NetConnection>();
|
||||
private Bimap<long, NetConnection> peers = new Bimap<long, NetConnection>();
|
||||
|
@ -150,18 +150,24 @@ namespace ModdedUtilitiesNetworking.Framework.Servers
|
|||
case NetConnectionStatus.Disconnecting:
|
||||
if (!this.peers.ContainsRight(message.SenderConnection))
|
||||
break;
|
||||
try
|
||||
{
|
||||
this.playerDisconnected(this.peers[message.SenderConnection]);
|
||||
}
|
||||
catch(Exception err)
|
||||
{
|
||||
//Forces a de-sync with money.
|
||||
|
||||
|
||||
this.playerDisconnected(this.peers[message.SenderConnection]);
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void playerDisconnected(long disconnectee)
|
||||
{
|
||||
this.gameServer.playerDisconnected(disconnectee);
|
||||
|
||||
this.introductionsSent.Remove(this.peers[disconnectee]);
|
||||
|
||||
this.peers.RemoveLeft(disconnectee);
|
||||
}
|
||||
|
||||
|
||||
private void parseDataMessageFromClient(NetIncomingMessage dataMsg)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue