Add init packet

This commit is contained in:
Sanae 2022-05-08 16:04:57 -06:00
parent 6a63eb47c2
commit 99aabeffc9
4 changed files with 24 additions and 1 deletions

View File

@ -123,6 +123,9 @@ public class Server {
private async void HandleSocket(Socket socket) {
Client client = new Client(socket) {Server = this};
IMemoryOwner<byte> memory = null!;
await client.Send(new InitPacket {
MaxPlayers = Settings.Instance.Server.MaxPlayers
});
bool first = true;
try {
while (true) {

View File

@ -46,7 +46,7 @@ public class Settings {
public class ServerTable {
public string Address { get; set; } = IPAddress.Any.ToString();
public ushort Port { get; set; } = 1027;
public byte MaxPlayers { get; set; } = 8;
public ushort MaxPlayers { get; set; } = 8;
}
public class ScenarioTable {

View File

@ -2,6 +2,7 @@
public enum PacketType : short {
Unknown,
Init,
Player,
Cap,
Game,

View File

@ -0,0 +1,19 @@
using System.Runtime.InteropServices;
namespace Shared.Packet.Packets;
[Packet(PacketType.Init)]
public struct InitPacket : IPacket {
public short Size { get; } = 2;
public ushort MaxPlayers = 0;
public InitPacket() { }
public void Serialize(Span<byte> data) {
MemoryMarshal.Write(data, ref MaxPlayers);
}
public void Deserialize(ReadOnlySpan<byte> data) {
MaxPlayers = MemoryMarshal.Read<ushort>(data);
}
}