Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NetServerSocialModule.cs
Go to the documentation of this file.
1using System;
4using System.IO;
5using Steamworks;
7using Terraria.Net;
9
10namespace Terraria.Social.Steam;
11
13{
15
17
18 private bool _acceptingClients;
19
20 private SocketConnectionAccepted _connectionAcceptedCallback;
21
23 : base(1, 2)
24 {
25 }
26
28 {
29 //IL_0028: Unknown result type (might be due to invalid IL or missing references)
32 {
33 if (item.Value == ConnectionState.Connected)
34 {
35 list.Add(item.Key.m_SteamID);
36 }
37 }
38 byte[] array = new byte[list.Count * 8 + 1];
40 {
42 binaryWriter.Write((byte)1);
43 foreach (ulong item2 in list)
44 {
45 binaryWriter.Write(item2);
46 }
47 }
49 }
50
51 public override void Initialize()
52 {
56 if (Program.LaunchParameters.ContainsKey("-lobby"))
57 {
58 _mode |= ServerMode.Lobby;
59 string text = Program.LaunchParameters["-lobby"];
60 if (!(text == "private"))
61 {
62 if (text == "friends")
63 {
64 _mode |= ServerMode.FriendsCanJoin;
66 }
67 else
68 {
69 Console.WriteLine(Language.GetTextValue("Error.InvalidLobbyFlag", "private", "friends"));
70 }
71 }
72 else
73 {
75 }
76 }
77 if (Program.LaunchParameters.ContainsKey("-friendsoffriends"))
78 {
79 _mode |= ServerMode.FriendsOfFriends;
80 }
81 }
82
83 public override ulong GetLobbyId()
84 {
85 return _lobby.Id.m_SteamID;
86 }
87
88 public override void OpenInviteInterface()
89 {
90 }
91
92 public override void CancelJoin()
93 {
94 }
95
96 public override bool CanInvite()
97 {
98 return false;
99 }
100
101 public override void LaunchLocalServer(Process process, ServerMode mode)
102 {
103 }
104
105 public override bool StartListening(SocketConnectionAccepted callback)
106 {
107 _acceptingClients = true;
109 return true;
110 }
111
112 public override void StopListening()
113 {
114 _acceptingClients = false;
115 }
116
117 public override void Connect(RemoteAddress address)
118 {
119 }
120
121 public override void Close(RemoteAddress address)
122 {
123 //IL_0002: Unknown result type (might be due to invalid IL or missing references)
124 //IL_0007: Unknown result type (might be due to invalid IL or missing references)
125 //IL_0009: Unknown result type (might be due to invalid IL or missing references)
126 CSteamID user = RemoteAddressToSteamId(address);
127 Close(user);
128 }
129
130 private void Close(CSteamID user)
131 {
132 //IL_0006: Unknown result type (might be due to invalid IL or missing references)
133 //IL_000f: Unknown result type (might be due to invalid IL or missing references)
134 //IL_0015: Unknown result type (might be due to invalid IL or missing references)
135 //IL_0022: Unknown result type (might be due to invalid IL or missing references)
136 //IL_002f: Unknown result type (might be due to invalid IL or missing references)
137 //IL_003b: Unknown result type (might be due to invalid IL or missing references)
139 {
140 SteamUser.EndAuthSession(user);
141 SteamNetworking.CloseP2PSessionWithUser(user);
145 }
146 }
147
148 private void OnLobbyCreated(LobbyCreated_t result, bool failure)
149 {
150 if (!failure)
151 {
152 SteamFriends.SetRichPresence("status", Language.GetTextValue("Social.StatusInGame"));
153 }
154 }
155
156 private bool OnPacketRead(byte[] data, int length, CSteamID userId)
157 {
158 //IL_0006: Unknown result type (might be due to invalid IL or missing references)
159 //IL_001e: Unknown result type (might be due to invalid IL or missing references)
160 //IL_001f: Unknown result type (might be due to invalid IL or missing references)
161 //IL_0025: Unknown result type (might be due to invalid IL or missing references)
162 //IL_0031: Unknown result type (might be due to invalid IL or missing references)
163 //IL_0014: Unknown result type (might be due to invalid IL or missing references)
164 //IL_003f: Unknown result type (might be due to invalid IL or missing references)
165 //IL_004f: Unknown result type (might be due to invalid IL or missing references)
166 //IL_0095: Unknown result type (might be due to invalid IL or missing references)
167 //IL_0096: Unknown result type (might be due to invalid IL or missing references)
168 //IL_009b: Unknown result type (might be due to invalid IL or missing references)
169 //IL_009c: Unknown result type (might be due to invalid IL or missing references)
170 //IL_00ba: Expected I4, but got Unknown
171 //IL_00c2: Unknown result type (might be due to invalid IL or missing references)
172 //IL_00ed: Unknown result type (might be due to invalid IL or missing references)
173 //IL_00d2: Unknown result type (might be due to invalid IL or missing references)
174 //IL_00f6: Unknown result type (might be due to invalid IL or missing references)
175 //IL_00e4: Unknown result type (might be due to invalid IL or missing references)
176 //IL_00db: Unknown result type (might be due to invalid IL or missing references)
178 {
180 result.m_steamIDRemote = userId;
181 OnP2PSessionRequest(result);
183 {
184 return false;
185 }
186 }
188 if (connectionState == ConnectionState.Authenticating)
189 {
190 if (length < 3)
191 {
192 return false;
193 }
194 if (((data[1] << 8) | data[0]) != length)
195 {
196 return false;
197 }
198 if (data[2] != 93)
199 {
200 return false;
201 }
202 byte[] array = new byte[data.Length - 3];
203 Array.Copy(data, 3, array, 0, array.Length);
204 EBeginAuthSessionResult val = SteamUser.BeginAuthSession(array, array.Length, userId);
205 switch ((int)val)
206 {
207 case 0:
210 break;
211 case 2:
212 Close(userId);
213 break;
214 case 5:
215 Close(userId);
216 break;
217 case 4:
218 Close(userId);
219 break;
220 case 1:
221 Close(userId);
222 break;
223 case 3:
224 Close(userId);
225 break;
226 }
227 return false;
228 }
229 return connectionState == ConnectionState.Connected;
230 }
231
233 {
234 //IL_0000: Unknown result type (might be due to invalid IL or missing references)
235 //IL_0001: Unknown result type (might be due to invalid IL or missing references)
236 //IL_0006: Unknown result type (might be due to invalid IL or missing references)
237 //IL_000d: Unknown result type (might be due to invalid IL or missing references)
238 //IL_001b: Unknown result type (might be due to invalid IL or missing references)
239 //IL_0023: Unknown result type (might be due to invalid IL or missing references)
240 //IL_0056: Unknown result type (might be due to invalid IL or missing references)
241 //IL_004c: Unknown result type (might be due to invalid IL or missing references)
242 //IL_004d: Unknown result type (might be due to invalid IL or missing references)
243 //IL_0053: Invalid comparison between Unknown and I4
244 //IL_005d: Unknown result type (might be due to invalid IL or missing references)
245 //IL_0070: Unknown result type (might be due to invalid IL or missing references)
246 //IL_0067: Unknown result type (might be due to invalid IL or missing references)
247 //IL_0085: Unknown result type (might be due to invalid IL or missing references)
248 //IL_0092: Unknown result type (might be due to invalid IL or missing references)
249 //IL_0079: Unknown result type (might be due to invalid IL or missing references)
250 CSteamID steamIDRemote = result.m_steamIDRemote;
252 {
253 SteamNetworking.AcceptP2PSessionWithUser(steamIDRemote);
254 }
255 else if (_acceptingClients && (_mode.HasFlag(ServerMode.FriendsOfFriends) || (int)SteamFriends.GetFriendRelationship(steamIDRemote) == 3))
256 {
257 SteamNetworking.AcceptP2PSessionWithUser(steamIDRemote);
259 while (SteamNetworking.GetP2PSessionState(steamIDRemote, ref val) && val.m_bConnecting == 1)
260 {
261 }
262 if (val.m_bConnectionActive == 0)
263 {
265 }
268 }
269 }
270}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
static void WriteLine()
Definition Console.cs:733
static string GetTextValue(string key)
Definition Language.cs:15
static Dictionary< string, string > LaunchParameters
Definition Program.cs:29
bool SendMessage(byte[] data)
Definition Lobby.cs:101
void Create(bool inviteOnly, APIDispatchDelegate< LobbyCreated_t > callResult)
Definition Lobby.cs:37
Callback< P2PSessionRequest_t > _p2pSessionRequest
bool OnPacketRead(byte[] data, int length, CSteamID userId)
void OnLobbyCreated(LobbyCreated_t result, bool failure)
override void Close(RemoteAddress address)
override bool StartListening(SocketConnectionAccepted callback)
override void LaunchLocalServer(Process process, ServerMode mode)
override void Connect(RemoteAddress address)
void OnP2PSessionRequest(P2PSessionRequest_t result)
CSteamID RemoteAddressToSteamId(RemoteAddress address)
ConcurrentDictionary< CSteamID, ConnectionState > _connectionStateMap
void SetReadEvent(OnReadEvent method)