-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSteamConnection.cs
68 lines (54 loc) · 2.07 KB
/
SteamConnection.cs
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
// This file is a 1:1 conversion from Tom Weilands Riptide Transport https://github.com/tom-weiland/RiptideSteamTransport/
using Steamworks;
using System;
using System.Collections.Generic;
namespace Riptide.Transports.Steam
{
public class SteamConnection : Connection, IEquatable<SteamConnection>
{
public readonly CSteamID SteamId;
public readonly HSteamNetConnection SteamNetConnection;
internal bool DidReceiveConnect;
private readonly SteamPeer peer;
internal SteamConnection(CSteamID steamId, HSteamNetConnection steamNetConnection, SteamPeer peer)
{
SteamId = steamId;
SteamNetConnection = steamNetConnection;
this.peer = peer;
}
protected override void Send(byte[] dataBuffer, int amount)
{
peer.Send(dataBuffer, amount, SteamNetConnection);
}
/// <inheritdoc/>
public override string ToString() => SteamNetConnection.ToString();
/// <inheritdoc/>
public override bool Equals(object obj) => Equals(obj as SteamConnection);
/// <inheritdoc/>
public bool Equals(SteamConnection other)
{
if (other is null)
return false;
if (ReferenceEquals(this, other))
return true;
return SteamNetConnection.Equals(other.SteamNetConnection);
}
/// <inheritdoc/>
public override int GetHashCode()
{
return -721414014 + EqualityComparer<HSteamNetConnection>.Default.GetHashCode(SteamNetConnection);
}
public static bool operator ==(SteamConnection left, SteamConnection right)
{
if (left is null)
{
if (right is null)
return true;
return false; // Only the left side is null
}
// Equals handles case of null on right side
return left.Equals(right);
}
public static bool operator !=(SteamConnection left, SteamConnection right) => !(left == right);
}
}