gamemode stub

This commit is contained in:
2022-05-05 17:00:45 +03:00
parent 3f1230fdf9
commit 8762138fe3
6 changed files with 99 additions and 37 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using FlaxEngine;
@@ -11,6 +12,8 @@ namespace Game
{
public static partial class NetworkManager
{
public static uint LocalPlayerClientId { get; private set; } = 0;
public static bool ConnectServer()
{
client = NetworkPeer.CreatePeer(new NetworkConfig
@@ -38,14 +41,14 @@ namespace Game
{
using var _ = Utilities.ProfileScope("NetworkManager_OnClientUpdate");
while (client.PopEvent(out NetworkEvent eventData))
while (client.PopEvent(out NetworkEvent networkEvent))
{
switch (eventData.EventType)
switch (networkEvent.EventType)
{
case NetworkEventType.Connected:
{
LocalPlayerClientId = eventData.Sender.ConnectionId;
Console.Print("Connected to server, ConnectionId: " + eventData.Sender.ConnectionId);
LocalPlayerClientId = networkEvent.Sender.ConnectionId;
Console.Print("Connected to server, ConnectionId: " + networkEvent.Sender.ConnectionId);
break;
}
case NetworkEventType.Disconnected:
@@ -62,21 +65,8 @@ namespace Game
}
case NetworkEventType.Message:
{
// Read the message contents
var message = eventData.Message;
var messageData = message.ReadString();
Console.Print($"Received message from Client({eventData.Sender.ConnectionId}): {messageData}");
// Send hello message to the client back
{
var sendmessage = client.BeginSendMessage();
sendmessage.WriteString($"Hello, Server({eventData.Sender.ConnectionId})!");
client.EndSendMessage(NetworkChannelType.Reliable, sendmessage);
}
client.RecycleMessage(message);
OnNetworkMessage(networkEvent);
client.RecycleMessage(networkEvent.Message);
break;
}
default: