Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NetSocialModule.cs
Go to the documentation of this file.
1
using
System.Collections.Concurrent
;
2
using
rail;
3
using
Terraria.Net
;
4
using
Terraria.Social.Base
;
5
6
namespace
Terraria.Social.WeGame
;
7
8
public
abstract
class
NetSocialModule
:
Terraria
.Social.Base.
NetSocialModule
9
{
10
public
enum
ConnectionState
11
{
12
Inactive
,
13
Authenticating
,
14
Connected
15
}
16
17
protected
const
int
LobbyMessageJoin
= 1;
18
19
protected
Lobby
_lobby
=
new
Lobby
();
20
21
protected
WeGameP2PReader
_reader
;
22
23
protected
WeGameP2PWriter
_writer
;
24
25
protected
ConcurrentDictionary<RailID, ConnectionState>
_connectionStateMap
=
new
ConcurrentDictionary<RailID, ConnectionState>
();
26
27
protected
static
readonly
byte
[]
_handshake
=
new
byte
[10] { 10, 0, 93, 114, 101, 108, 111, 103, 105, 99 };
28
29
protected
NetSocialModule
()
30
{
31
_reader
=
new
WeGameP2PReader
();
32
_writer
=
new
WeGameP2PWriter
();
33
}
34
35
public
override
void
Initialize
()
36
{
37
CoreSocialModule.OnTick +=
_reader
.
ReadTick
;
38
CoreSocialModule.OnTick +=
_writer
.
SendAll
;
39
}
40
41
public
override
void
Shutdown
()
42
{
43
_lobby
.
Leave
();
44
}
45
46
public
override
bool
IsConnected
(
RemoteAddress
address)
47
{
48
if
(address ==
null
)
49
{
50
return
false
;
51
}
52
RailID key =
RemoteAddressToRailId
(address);
53
if
(!
_connectionStateMap
.
ContainsKey
(key) ||
_connectionStateMap
[key] !=
ConnectionState
.Connected)
54
{
55
return
false
;
56
}
57
return
true
;
58
}
59
60
protected
RailID
GetLocalPeer
()
61
{
62
return
rail_api.RailFactory().RailPlayer().GetRailID();
63
}
64
65
protected
bool
GetSessionState
(RailID userId, RailNetworkSessionState state)
66
{
67
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
68
IRailNetwork val = rail_api.RailFactory().RailNetworkHelper();
69
if
((
int
)val.GetSessionState(userId, state) != 0)
70
{
71
WeGameHelper
.
WriteDebugString
(
"GetSessionState Failed user:{0}"
, ((RailComparableID)userId).id_);
72
return
false
;
73
}
74
return
true
;
75
}
76
77
protected
RailID
RemoteAddressToRailId
(
RemoteAddress
address)
78
{
79
return
((
WeGameAddress
)address).rail_id;
80
}
81
82
public
override
bool
Send
(
RemoteAddress
address,
byte
[] data,
int
length)
83
{
84
RailID user =
RemoteAddressToRailId
(address);
85
_writer
.
QueueSend
(user, data, length);
86
return
true
;
87
}
88
89
public
override
int
Receive
(
RemoteAddress
address,
byte
[] data,
int
offset,
int
length)
90
{
91
if
(address ==
null
)
92
{
93
return
0;
94
}
95
RailID user =
RemoteAddressToRailId
(address);
96
return
_reader
.
Receive
(user, data, offset, length);
97
}
98
99
public
override
bool
IsDataAvailable
(
RemoteAddress
address)
100
{
101
RailID
id
=
RemoteAddressToRailId
(address);
102
return
_reader
.
IsDataAvailable
(
id
);
103
}
104
}
System.Collections.Concurrent.ConcurrentDictionary.ContainsKey
bool ContainsKey(TKey key)
Definition
ConcurrentDictionary.cs:438
System.Collections.Concurrent.ConcurrentDictionary
Definition
ConcurrentDictionary.cs:13
Terraria.Net.RemoteAddress
Definition
RemoteAddress.cs:4
Terraria.Net.WeGameAddress
Definition
WeGameAddress.cs:6
Terraria.Social.WeGame.Lobby.Leave
void Leave()
Definition
Lobby.cs:144
Terraria.Social.WeGame.Lobby
Definition
Lobby.cs:7
Terraria.Social.WeGame.NetSocialModule.Receive
override int Receive(RemoteAddress address, byte[] data, int offset, int length)
Definition
NetSocialModule.cs:89
Terraria.Social.WeGame.NetSocialModule.LobbyMessageJoin
const int LobbyMessageJoin
Definition
NetSocialModule.cs:17
Terraria.Social.WeGame.NetSocialModule.Shutdown
override void Shutdown()
Definition
NetSocialModule.cs:41
Terraria.Social.WeGame.NetSocialModule.IsConnected
override bool IsConnected(RemoteAddress address)
Definition
NetSocialModule.cs:46
Terraria.Social.WeGame.NetSocialModule.GetSessionState
bool GetSessionState(RailID userId, RailNetworkSessionState state)
Definition
NetSocialModule.cs:65
Terraria.Social.WeGame.NetSocialModule._reader
WeGameP2PReader _reader
Definition
NetSocialModule.cs:21
Terraria.Social.WeGame.NetSocialModule.RemoteAddressToRailId
RailID RemoteAddressToRailId(RemoteAddress address)
Definition
NetSocialModule.cs:77
Terraria.Social.WeGame.NetSocialModule.ConnectionState
ConnectionState
Definition
NetSocialModule.cs:11
Terraria.Social.WeGame.NetSocialModule.ConnectionState.Connected
@ Connected
Terraria.Social.WeGame.NetSocialModule.ConnectionState.Inactive
@ Inactive
Terraria.Social.WeGame.NetSocialModule.ConnectionState.Authenticating
@ Authenticating
Terraria.Social.WeGame.NetSocialModule._writer
WeGameP2PWriter _writer
Definition
NetSocialModule.cs:23
Terraria.Social.WeGame.NetSocialModule.NetSocialModule
NetSocialModule()
Definition
NetSocialModule.cs:29
Terraria.Social.WeGame.NetSocialModule._lobby
Lobby _lobby
Definition
NetSocialModule.cs:19
Terraria.Social.WeGame.NetSocialModule._handshake
static readonly byte[] _handshake
Definition
NetSocialModule.cs:27
Terraria.Social.WeGame.NetSocialModule.Initialize
override void Initialize()
Definition
NetSocialModule.cs:35
Terraria.Social.WeGame.NetSocialModule.Send
override bool Send(RemoteAddress address, byte[] data, int length)
Definition
NetSocialModule.cs:82
Terraria.Social.WeGame.NetSocialModule.GetLocalPeer
RailID GetLocalPeer()
Definition
NetSocialModule.cs:60
Terraria.Social.WeGame.NetSocialModule._connectionStateMap
ConcurrentDictionary< RailID, ConnectionState > _connectionStateMap
Definition
NetSocialModule.cs:25
Terraria.Social.WeGame.NetSocialModule.IsDataAvailable
override bool IsDataAvailable(RemoteAddress address)
Definition
NetSocialModule.cs:99
Terraria.Social.WeGame.NetSocialModule
Definition
NetSocialModule.cs:9
Terraria.Social.WeGame.WeGameHelper.WriteDebugString
static void WriteDebugString(string format, params object[] args)
Definition
WeGameHelper.cs:13
Terraria.Social.WeGame.WeGameHelper
Definition
WeGameHelper.cs:9
Terraria.Social.WeGame.WeGameP2PReader.Receive
int Receive(RailID user, byte[] buffer, int bufferOffset, int bufferSize)
Definition
WeGameP2PReader.cs:155
Terraria.Social.WeGame.WeGameP2PReader.ReadTick
void ReadTick()
Definition
WeGameP2PReader.cs:109
Terraria.Social.WeGame.WeGameP2PReader.IsDataAvailable
bool IsDataAvailable(RailID id)
Definition
WeGameP2PReader.cs:49
Terraria.Social.WeGame.WeGameP2PReader
Definition
WeGameP2PReader.cs:8
Terraria.Social.WeGame.WeGameP2PWriter.QueueSend
void QueueSend(RailID user, byte[] data, int length)
Definition
WeGameP2PWriter.cs:40
Terraria.Social.WeGame.WeGameP2PWriter.SendAll
void SendAll()
Definition
WeGameP2PWriter.cs:116
Terraria.Social.WeGame.WeGameP2PWriter
Definition
WeGameP2PWriter.cs:8
System.Collections.Concurrent
Definition
BlockingCollection.cs:8
Terraria.Net.ServerMode.Lobby
@ Lobby
Terraria.Net
Definition
ISocket.cs:1
Terraria.Social.Base
Definition
AchievementsSocialModule.cs:1
Terraria.Social.WeGame
Definition
AchievementsSocialModule.cs:6
Terraria
Definition
Achievement.cs:7
source
Terraria.Social.WeGame
NetSocialModule.cs
Generated by
1.10.0