gamemode stub
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using FlaxEditor;
|
||||
@@ -30,6 +31,14 @@ namespace Game
|
||||
|
||||
// NetworkMulticastAttribute: calls methods marked with this in all clients
|
||||
|
||||
public enum NetworkMessageType : byte
|
||||
{
|
||||
Handshake = 1,
|
||||
Message,
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static partial class NetworkManager
|
||||
{
|
||||
private static bool initialized = false;
|
||||
@@ -42,7 +51,8 @@ namespace Game
|
||||
private static ushort MTU = 1500;
|
||||
private static ushort MaximumClients = 32;
|
||||
|
||||
public static uint LocalPlayerClientId { get; private set; } = 0;
|
||||
public delegate bool OnMessageDecl(NetworkMessage message);
|
||||
public static OnMessageDecl OnMessage;
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
@@ -68,6 +78,7 @@ namespace Game
|
||||
#endif
|
||||
|
||||
initialized = true;
|
||||
GameModeManager.Init(); // FIXME
|
||||
}
|
||||
|
||||
public static void Deinitialize()
|
||||
@@ -90,5 +101,44 @@ namespace Game
|
||||
client = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnNetworkMessage(NetworkEvent networkEvent)
|
||||
{
|
||||
byte messageTypeByte = networkEvent.Message.ReadByte();
|
||||
if (!Enum.IsDefined(typeof(NetworkMessageType), messageTypeByte))
|
||||
{
|
||||
Console.PrintError($"Unsupported message type received from client: {messageTypeByte}");
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkMessageType messageType = (NetworkMessageType)messageTypeByte;
|
||||
|
||||
switch (messageType)
|
||||
{
|
||||
case NetworkMessageType.Handshake:
|
||||
{
|
||||
var message = networkEvent.Message.ReadString();
|
||||
Console.Print($"Received handshake from {networkEvent.Sender.ConnectionId}, msg: " + message);
|
||||
break;
|
||||
}
|
||||
case NetworkMessageType.Message:
|
||||
{
|
||||
if (OnMessage != null)
|
||||
{
|
||||
foreach (OnMessageDecl func in OnMessage.GetInvocationList()
|
||||
.Cast<OnMessageDecl>().ToArray())
|
||||
{
|
||||
bool ret = func.Invoke(networkEvent.Message);
|
||||
if (ret)
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
Console.PrintError($"Unsupported message type received from client: {messageTypeByte}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user