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:
parent
7a088eb314
commit
6964c3bbf4
2 changed files with 7 additions and 3 deletions
|
@ -237,6 +237,7 @@ public class Server {
|
|||
MemoryMarshal.Write(tempBuffer.Memory.Span, ref connectHeader);
|
||||
ConnectPacket connectPacket = new ConnectPacket {
|
||||
ConnectionType = ConnectPacket.ConnectionTypes.FirstConnection, // doesn't matter what it is
|
||||
MaxPlayers = Settings.Instance.Server.MaxPlayers,
|
||||
ClientName = other.Name
|
||||
};
|
||||
connectPacket.Serialize(tempBuffer.Memory.Span[Constants.HeaderSize..]);
|
||||
|
|
|
@ -6,20 +6,23 @@ namespace Shared.Packet.Packets;
|
|||
[Packet(PacketType.Connect)]
|
||||
public struct ConnectPacket : IPacket {
|
||||
public ConnectionTypes ConnectionType = ConnectionTypes.FirstConnection;
|
||||
public ushort MaxPlayers = 0;
|
||||
public string ClientName = "?????";
|
||||
|
||||
public ConnectPacket() { }
|
||||
|
||||
public short Size => 4 + Constants.CostumeNameSize;
|
||||
public short Size => 6 + Constants.CostumeNameSize;
|
||||
|
||||
public void Serialize(Span<byte> data) {
|
||||
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) {
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue