mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-22 03:05:16 +00:00
Add init packet
This commit is contained in:
parent
6a63eb47c2
commit
99aabeffc9
4 changed files with 24 additions and 1 deletions
|
@ -123,6 +123,9 @@ public class Server {
|
||||||
private async void HandleSocket(Socket socket) {
|
private async void HandleSocket(Socket socket) {
|
||||||
Client client = new Client(socket) {Server = this};
|
Client client = new Client(socket) {Server = this};
|
||||||
IMemoryOwner<byte> memory = null!;
|
IMemoryOwner<byte> memory = null!;
|
||||||
|
await client.Send(new InitPacket {
|
||||||
|
MaxPlayers = Settings.Instance.Server.MaxPlayers
|
||||||
|
});
|
||||||
bool first = true;
|
bool first = true;
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class Settings {
|
||||||
public class ServerTable {
|
public class ServerTable {
|
||||||
public string Address { get; set; } = IPAddress.Any.ToString();
|
public string Address { get; set; } = IPAddress.Any.ToString();
|
||||||
public ushort Port { get; set; } = 1027;
|
public ushort Port { get; set; } = 1027;
|
||||||
public byte MaxPlayers { get; set; } = 8;
|
public ushort MaxPlayers { get; set; } = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ScenarioTable {
|
public class ScenarioTable {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
public enum PacketType : short {
|
public enum PacketType : short {
|
||||||
Unknown,
|
Unknown,
|
||||||
|
Init,
|
||||||
Player,
|
Player,
|
||||||
Cap,
|
Cap,
|
||||||
Game,
|
Game,
|
||||||
|
|
19
Shared/Packet/Packets/InitPacket.cs
Normal file
19
Shared/Packet/Packets/InitPacket.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue