summaryrefslogtreecommitdiff
path: root/Assembly_Firstpass/Steamworks/servernetadr_t.cs
blob: 8dfde4ce2844d62580d98da299eb198bc192dbf2 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System;

namespace Steamworks;

[Serializable]
public struct servernetadr_t
{
	private ushort m_usConnectionPort;

	private ushort m_usQueryPort;

	private uint m_unIP;

	public void Init(uint ip, ushort usQueryPort, ushort usConnectionPort)
	{
		m_unIP = ip;
		m_usQueryPort = usQueryPort;
		m_usConnectionPort = usConnectionPort;
	}

	public ushort GetQueryPort()
	{
		return m_usQueryPort;
	}

	public void SetQueryPort(ushort usPort)
	{
		m_usQueryPort = usPort;
	}

	public ushort GetConnectionPort()
	{
		return m_usConnectionPort;
	}

	public void SetConnectionPort(ushort usPort)
	{
		m_usConnectionPort = usPort;
	}

	public uint GetIP()
	{
		return m_unIP;
	}

	public void SetIP(uint unIP)
	{
		m_unIP = unIP;
	}

	public string GetConnectionAddressString()
	{
		return ToString(m_unIP, m_usConnectionPort);
	}

	public string GetQueryAddressString()
	{
		return ToString(m_unIP, m_usQueryPort);
	}

	public static string ToString(uint unIP, ushort usPort)
	{
		return $"{(ulong)(unIP >> 24) & 0xFFuL}.{(ulong)(unIP >> 16) & 0xFFuL}.{(ulong)(unIP >> 8) & 0xFFuL}.{(ulong)unIP & 0xFFuL}:{usPort}";
	}

	public static bool operator <(servernetadr_t x, servernetadr_t y)
	{
		if (x.m_unIP >= y.m_unIP)
		{
			if (x.m_unIP == y.m_unIP)
			{
				return x.m_usQueryPort < y.m_usQueryPort;
			}
			return false;
		}
		return true;
	}

	public static bool operator >(servernetadr_t x, servernetadr_t y)
	{
		if (x.m_unIP <= y.m_unIP)
		{
			if (x.m_unIP == y.m_unIP)
			{
				return x.m_usQueryPort > y.m_usQueryPort;
			}
			return false;
		}
		return true;
	}

	public override bool Equals(object other)
	{
		if (other is servernetadr_t)
		{
			return this == (servernetadr_t)other;
		}
		return false;
	}

	public override int GetHashCode()
	{
		return m_unIP.GetHashCode() + m_usQueryPort.GetHashCode() + m_usConnectionPort.GetHashCode();
	}

	public static bool operator ==(servernetadr_t x, servernetadr_t y)
	{
		if (x.m_unIP == y.m_unIP && x.m_usQueryPort == y.m_usQueryPort)
		{
			return x.m_usConnectionPort == y.m_usConnectionPort;
		}
		return false;
	}

	public static bool operator !=(servernetadr_t x, servernetadr_t y)
	{
		return !(x == y);
	}

	public bool Equals(servernetadr_t other)
	{
		if (m_unIP == other.m_unIP && m_usQueryPort == other.m_usQueryPort)
		{
			return m_usConnectionPort == other.m_usConnectionPort;
		}
		return false;
	}

	public int CompareTo(servernetadr_t other)
	{
		return m_unIP.CompareTo(other.m_unIP) + m_usQueryPort.CompareTo(other.m_usQueryPort) + m_usConnectionPort.CompareTo(other.m_usConnectionPort);
	}
}