0
0
Fork 0
mirror of https://github.com/Sanae6/SmoOnlineServer.git synced 2024-11-21 18:55:17 +00:00

Add max players to connect packet

This commit is contained in:
Sanae 2022-04-26 23:24:40 -06:00
parent 7a088eb314
commit 6964c3bbf4
2 changed files with 7 additions and 3 deletions

View file

@ -237,6 +237,7 @@ public class Server {
MemoryMarshal.Write(tempBuffer.Memory.Span, ref connectHeader); MemoryMarshal.Write(tempBuffer.Memory.Span, ref connectHeader);
ConnectPacket connectPacket = new ConnectPacket { ConnectPacket connectPacket = new ConnectPacket {
ConnectionType = ConnectPacket.ConnectionTypes.FirstConnection, // doesn't matter what it is ConnectionType = ConnectPacket.ConnectionTypes.FirstConnection, // doesn't matter what it is
MaxPlayers = Settings.Instance.Server.MaxPlayers,
ClientName = other.Name ClientName = other.Name
}; };
connectPacket.Serialize(tempBuffer.Memory.Span[Constants.HeaderSize..]); connectPacket.Serialize(tempBuffer.Memory.Span[Constants.HeaderSize..]);

View file

@ -6,20 +6,23 @@ namespace Shared.Packet.Packets;
[Packet(PacketType.Connect)] [Packet(PacketType.Connect)]
public struct ConnectPacket : IPacket { public struct ConnectPacket : IPacket {
public ConnectionTypes ConnectionType = ConnectionTypes.FirstConnection; public ConnectionTypes ConnectionType = ConnectionTypes.FirstConnection;
public ushort MaxPlayers = 0;
public string ClientName = "?????"; public string ClientName = "?????";
public ConnectPacket() { } public ConnectPacket() { }
public short Size => 4 + Constants.CostumeNameSize; public short Size => 6 + Constants.CostumeNameSize;
public void Serialize(Span<byte> data) { public void Serialize(Span<byte> data) {
MemoryMarshal.Write(data, ref ConnectionType); MemoryMarshal.Write(data, ref ConnectionType);
Encoding.UTF8.GetBytes(ClientName).CopyTo(data[4..(4 + Constants.CostumeNameSize)]); MemoryMarshal.Write(data[4..], ref MaxPlayers);
Encoding.UTF8.GetBytes(ClientName).CopyTo(data[6..(6 + Constants.CostumeNameSize)]);
} }
public void Deserialize(ReadOnlySpan<byte> data) { public void Deserialize(ReadOnlySpan<byte> data) {
ConnectionType = MemoryMarshal.Read<ConnectionTypes>(data); ConnectionType = MemoryMarshal.Read<ConnectionTypes>(data);
ClientName = Encoding.UTF8.GetString(data[4..(4 + Constants.CostumeNameSize)]).TrimNullTerm(); ConnectionType = MemoryMarshal.Read<ConnectionTypes>(data[4..]);
ClientName = Encoding.UTF8.GetString(data[6..(6 + Constants.CostumeNameSize)]).TrimNullTerm();
} }
public enum ConnectionTypes { public enum ConnectionTypes {