Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SteamP2PReader.cs
Go to the documentation of this file.
1using System;
3using Steamworks;
4
6
7public class SteamP2PReader
8{
9 public class ReadResult
10 {
11 public byte[] Data;
12
13 public uint Size;
14
15 public uint Offset;
16
17 public ReadResult(byte[] data, uint size)
18 {
19 Data = data;
20 Size = size;
21 Offset = 0u;
22 }
23 }
24
25 public delegate bool OnReadEvent(byte[] data, int size, CSteamID user);
26
27 public object SteamLock = new object();
28
29 private const int BUFFER_SIZE = 4096;
30
32
34
36
37 private int _channel;
38
39 private OnReadEvent _readEvent;
40
41 public SteamP2PReader(int channel)
42 {
43 _channel = channel;
44 }
45
46 public void ClearUser(CSteamID id)
47 {
48 //IL_0017: Unknown result type (might be due to invalid IL or missing references)
50 {
52 }
53 }
54
55 public bool IsDataAvailable(CSteamID id)
56 {
57 //IL_0017: Unknown result type (might be due to invalid IL or missing references)
58 //IL_0029: Unknown result type (might be due to invalid IL or missing references)
60 {
62 {
63 return false;
64 }
66 if (queue.Count == 0 || queue.Peek().Size == 0)
67 {
68 return false;
69 }
70 return true;
71 }
72 }
73
74 public void SetReadEvent(OnReadEvent method)
75 {
77 }
78
79 private bool IsPacketAvailable(out uint size)
80 {
82 {
83 return SteamNetworking.IsP2PPacketAvailable(ref size, _channel);
84 }
85 }
86
87 public void ReadTick()
88 {
89 //IL_001f: Unknown result type (might be due to invalid IL or missing references)
90 //IL_00c4: Unknown result type (might be due to invalid IL or missing references)
91 //IL_00b5: Unknown result type (might be due to invalid IL or missing references)
92 //IL_00e5: Unknown result type (might be due to invalid IL or missing references)
93 //IL_00d3: Unknown result type (might be due to invalid IL or missing references)
95 {
96 while (_deletionQueue.Count > 0)
97 {
99 }
100 uint size;
101 uint size2 = default(uint);
102 CSteamID val = default(CSteamID);
103 while (IsPacketAvailable(out size))
104 {
105 byte[] array = ((_bufferPool.Count != 0) ? _bufferPool.Dequeue() : new byte[Math.Max(size, 4096u)]);
106 bool flag;
108 {
109 flag = SteamNetworking.ReadP2PPacket(array, (uint)array.Length, ref size2, ref val, _channel);
110 }
111 if (!flag)
112 {
113 continue;
114 }
115 if (_readEvent == null || _readEvent(array, (int)size2, val))
116 {
118 {
120 }
121 _pendingReadBuffers[val].Enqueue(new ReadResult(array, size2));
122 }
123 else
124 {
126 }
127 }
128 }
129 }
130
131 public int Receive(CSteamID user, byte[] buffer, int bufferOffset, int bufferSize)
132 {
133 //IL_0019: Unknown result type (might be due to invalid IL or missing references)
134 //IL_002f: Unknown result type (might be due to invalid IL or missing references)
135 uint num = 0u;
137 {
139 {
140 return 0;
141 }
143 while (queue.Count > 0)
144 {
145 ReadResult readResult = queue.Peek();
146 uint num2 = Math.Min((uint)bufferSize - num, readResult.Size - readResult.Offset);
147 if (num2 == 0)
148 {
149 return (int)num;
150 }
151 Array.Copy(readResult.Data, readResult.Offset, buffer, bufferOffset + num, num2);
152 if (num2 == readResult.Size - readResult.Offset)
153 {
154 _bufferPool.Enqueue(queue.Dequeue().Data);
155 }
156 else
157 {
158 readResult.Offset += num2;
159 }
160 num += num2;
161 }
162 return (int)num;
163 }
164 }
165}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static byte Max(byte val1, byte val2)
Definition Math.cs:738
delegate bool OnReadEvent(byte[] data, int size, CSteamID user)
void SetReadEvent(OnReadEvent method)
int Receive(CSteamID user, byte[] buffer, int bufferOffset, int bufferSize)
Dictionary< CSteamID, Queue< ReadResult > > _pendingReadBuffers