summaryrefslogtreecommitdiff
path: root/Impostor-dev/src/Impostor.Api/Innersloth/ServerInfo.cs
blob: 7785823493a925628a9bc2fc6c6f33cca8b4fdb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System.IO;
using System.Net;

namespace Impostor.Api.Innersloth
{
    public class ServerInfo
    {
        public string Name { get; }
        public string Ip { get; }
        public ushort Port { get; }

        public ServerInfo(string name, string ip, ushort port)
        {
            Name = name;
            Ip = ip;
            Port = port;
        }
        
        public void Serialize(BinaryWriter writer)
        {
            writer.Write(Name);
            writer.Write(IPAddress.Parse(Ip).GetAddressBytes());
            writer.Write(Port);
            writer.Write(0);
        }

        public static ServerInfo Deserialize(BinaryReader reader)
        {
            var name = reader.ReadString();
            var ip = new IPAddress(reader.ReadBytes(4)).ToString();
            var port = reader.ReadUInt16();
            var unknown = reader.ReadInt32();
            
            return new ServerInfo(name, ip, port);
        }
    }
}