Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NetSocialModule.cs
Go to the documentation of this file.
2using System.IO;
3using Steamworks;
4using Terraria.Net;
6
8
9public abstract class NetSocialModule : Terraria.Social.Base.NetSocialModule
10{
11 public enum ConnectionState
12 {
16 }
17
18 protected delegate void AsyncHandshake(CSteamID client);
19
20 protected const int ServerReadChannel = 1;
21
22 protected const int ClientReadChannel = 2;
23
24 protected const int LobbyMessageJoin = 1;
25
26 protected const ushort GamePort = 27005;
27
28 protected const ushort SteamPort = 27006;
29
30 protected const ushort QueryPort = 27007;
31
32 protected static readonly byte[] _handshake = new byte[10] { 10, 0, 93, 114, 101, 108, 111, 103, 105, 99 };
33
35
37
38 protected Lobby _lobby = new Lobby();
39
41
42 protected object _steamLock = new object();
43
44 private Callback<LobbyChatMsg_t> _lobbyChatMessage;
45
46 protected NetSocialModule(int readChannel, int writeChannel)
47 {
48 _reader = new SteamP2PReader(readChannel);
49 _writer = new SteamP2PWriter(writeChannel);
50 }
51
52 public override void Initialize()
53 {
54 CoreSocialModule.OnTick += _reader.ReadTick;
55 CoreSocialModule.OnTick += _writer.SendAll;
56 _lobbyChatMessage = Callback<LobbyChatMsg_t>.Create((DispatchDelegate<LobbyChatMsg_t>)OnLobbyChatMessage);
57 }
58
59 public override void Shutdown()
60 {
61 _lobby.Leave();
62 }
63
64 public override bool IsConnected(RemoteAddress address)
65 {
66 //IL_0007: Unknown result type (might be due to invalid IL or missing references)
67 //IL_000c: Unknown result type (might be due to invalid IL or missing references)
68 //IL_0013: Unknown result type (might be due to invalid IL or missing references)
69 //IL_0021: Unknown result type (might be due to invalid IL or missing references)
70 //IL_002d: Unknown result type (might be due to invalid IL or missing references)
71 //IL_002e: Unknown result type (might be due to invalid IL or missing references)
72 if (address == null)
73 {
74 return false;
75 }
76 CSteamID val = RemoteAddressToSteamId(address);
78 {
79 return false;
80 }
81 if (GetSessionState(val).m_bConnectionActive != 1)
82 {
83 Close(address);
84 return false;
85 }
86 return true;
87 }
88
89 protected virtual void OnLobbyChatMessage(LobbyChatMsg_t result)
90 {
91 //IL_0000: Unknown result type (might be due to invalid IL or missing references)
92 //IL_0019: Unknown result type (might be due to invalid IL or missing references)
93 //IL_0023: Unknown result type (might be due to invalid IL or missing references)
94 //IL_0042: Unknown result type (might be due to invalid IL or missing references)
95 //IL_007b: Unknown result type (might be due to invalid IL or missing references)
96 //IL_007d: Unknown result type (might be due to invalid IL or missing references)
97 //IL_008f: Unknown result type (might be due to invalid IL or missing references)
98 if (result.m_ulSteamIDLobby != _lobby.Id.m_SteamID || result.m_eChatEntryType != 1 || result.m_ulSteamIDUser != _lobby.Owner.m_SteamID)
99 {
100 return;
101 }
102 byte[] message = _lobby.GetMessage((int)result.m_iChatID);
103 if (message.Length == 0)
104 {
105 return;
106 }
107 using MemoryStream memoryStream = new MemoryStream(message);
108 using BinaryReader binaryReader = new BinaryReader(memoryStream);
109 byte b = binaryReader.ReadByte();
110 if (b != 1)
111 {
112 return;
113 }
114 CSteamID val = default(CSteamID);
115 while (message.Length - memoryStream.Position >= 8)
116 {
117 ((CSteamID)(ref val))._002Ector(binaryReader.ReadUInt64());
118 if (val != SteamUser.GetSteamID())
119 {
121 }
122 }
123 }
124
125 protected P2PSessionState_t GetSessionState(CSteamID userId)
126 {
127 //IL_0000: Unknown result type (might be due to invalid IL or missing references)
128 //IL_0009: Unknown result type (might be due to invalid IL or missing references)
129 P2PSessionState_t result = default(P2PSessionState_t);
130 SteamNetworking.GetP2PSessionState(userId, ref result);
131 return result;
132 }
133
134 protected CSteamID RemoteAddressToSteamId(RemoteAddress address)
135 {
136 //IL_0006: Unknown result type (might be due to invalid IL or missing references)
137 return ((SteamAddress)address).SteamId;
138 }
139
140 public override bool Send(RemoteAddress address, byte[] data, int length)
141 {
142 //IL_0002: Unknown result type (might be due to invalid IL or missing references)
143 //IL_0007: Unknown result type (might be due to invalid IL or missing references)
144 //IL_000e: Unknown result type (might be due to invalid IL or missing references)
145 CSteamID user = RemoteAddressToSteamId(address);
146 _writer.QueueSend(user, data, length);
147 return true;
148 }
149
150 public override int Receive(RemoteAddress address, byte[] data, int offset, int length)
151 {
152 //IL_0007: Unknown result type (might be due to invalid IL or missing references)
153 //IL_000c: Unknown result type (might be due to invalid IL or missing references)
154 //IL_0013: Unknown result type (might be due to invalid IL or missing references)
155 if (address == null)
156 {
157 return 0;
158 }
159 CSteamID user = RemoteAddressToSteamId(address);
160 return _reader.Receive(user, data, offset, length);
161 }
162
163 public override bool IsDataAvailable(RemoteAddress address)
164 {
165 //IL_0002: Unknown result type (might be due to invalid IL or missing references)
166 //IL_0007: Unknown result type (might be due to invalid IL or missing references)
167 //IL_000e: Unknown result type (might be due to invalid IL or missing references)
168 CSteamID id = RemoteAddressToSteamId(address);
169 return _reader.IsDataAvailable(id);
170 }
171}
void Close(RemoteAddress address)
byte[] GetMessage(int index)
Definition Lobby.cs:77
void SetPlayedWith(CSteamID userId)
Definition Lobby.cs:128
CSteamID RemoteAddressToSteamId(RemoteAddress address)
ConcurrentDictionary< CSteamID, ConnectionState > _connectionStateMap
delegate void AsyncHandshake(CSteamID client)
override int Receive(RemoteAddress address, byte[] data, int offset, int length)
virtual void OnLobbyChatMessage(LobbyChatMsg_t result)
P2PSessionState_t GetSessionState(CSteamID userId)
Callback< LobbyChatMsg_t > _lobbyChatMessage
override bool Send(RemoteAddress address, byte[] data, int length)
override bool IsConnected(RemoteAddress address)
override bool IsDataAvailable(RemoteAddress address)
NetSocialModule(int readChannel, int writeChannel)
int Receive(CSteamID user, byte[] buffer, int bufferOffset, int bufferSize)
void QueueSend(CSteamID user, byte[] data, int length)