55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using FlaxEngine.Networking;
|
|
using FlaxEngine;
|
|
|
|
namespace Game;
|
|
|
|
public struct AcceptConnectionMessage
|
|
{
|
|
public struct PlayerInfo
|
|
{
|
|
public uint PlayerId;
|
|
public Float3 PlayerPosition;
|
|
}
|
|
public ulong Frame;
|
|
public float GameTime;
|
|
public PlayerInfo[] Players;
|
|
|
|
public static AcceptConnectionMessage Read(ref NetworkMessage networkMessage)
|
|
{
|
|
AcceptConnectionMessage packet = new AcceptConnectionMessage();
|
|
packet.Frame = networkMessage.ReadUInt64();
|
|
packet.GameTime = networkMessage.ReadSingle();
|
|
int numActors = (int)networkMessage.ReadUInt32();
|
|
|
|
packet.Players = new PlayerInfo[numActors];
|
|
for (int i = 0; i < numActors; i++)
|
|
{
|
|
packet.Players[i].PlayerId = networkMessage.ReadUInt32();
|
|
packet.Players[i].PlayerPosition.X = networkMessage.ReadSingle();
|
|
packet.Players[i].PlayerPosition.Y = networkMessage.ReadSingle();
|
|
packet.Players[i].PlayerPosition.Z = networkMessage.ReadSingle();
|
|
}
|
|
return packet;
|
|
}
|
|
|
|
public void Write(ref NetworkMessage networkMessage)
|
|
{
|
|
networkMessage.WriteByte((byte)GameModeMessageType2.AcceptConnection);
|
|
networkMessage.WriteUInt64(Frame);
|
|
networkMessage.WriteSingle(GameTime);
|
|
networkMessage.WriteUInt32((uint)Players.Length);
|
|
foreach (PlayerInfo player in Players)
|
|
{
|
|
networkMessage.WriteUInt32(player.PlayerId);
|
|
networkMessage.WriteSingle(player.PlayerPosition.X);
|
|
networkMessage.WriteSingle(player.PlayerPosition.Y);
|
|
networkMessage.WriteSingle(player.PlayerPosition.Z);
|
|
}
|
|
}
|
|
}
|