Terraria v1.4.4.9
Terraria source code documentation
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros
WeGameP2PWriter.cs
Go to the documentation of this file.
1using System;
3using rail;
4
6
7public class WeGameP2PWriter
8{
9 public class WriteInformation
10 {
11 public byte[] Data;
12
13 public int Size;
14
16 {
17 Data = new byte[1024];
18 Size = 0;
19 }
20
21 public WriteInformation(byte[] data)
22 {
23 Data = data;
24 Size = 0;
25 }
26 }
27
28 private const int BUFFER_SIZE = 1024;
29
30 private RailID _local_id;
31
33
35
37
38 private object _lock = new object();
39
40 public void QueueSend(RailID user, byte[] data, int length)
41 {
42 lock (_lock)
43 {
45 int num = length;
46 int num2 = 0;
47 while (num > 0)
48 {
50 if (queue2.Count == 0 || 1024 - queue2.Peek().Size == 0)
51 {
52 writeInformation = ((_bufferPool.Count <= 0) ? new WriteInformation() : new WriteInformation(_bufferPool.Dequeue()));
53 queue2.Enqueue(writeInformation);
54 }
55 else
56 {
57 writeInformation = queue2.Peek();
58 }
59 int num3 = Math.Min(num, 1024 - writeInformation.Size);
61 writeInformation.Size += num3;
62 num -= num3;
63 num2 += num3;
64 }
65 }
66 }
67
68 public void ClearUser(RailID user)
69 {
70 lock (_lock)
71 {
73 {
75 while (queue.Count > 0)
76 {
77 _bufferPool.Enqueue(queue.Dequeue().Data);
78 }
79 }
81 {
83 while (queue2.Count > 0)
84 {
85 _bufferPool.Enqueue(queue2.Dequeue().Data);
86 }
87 }
88 }
89 }
90
91 public void SetLocalPeer(RailID rail_id)
92 {
93 //IL_000f: Unknown result type (might be due to invalid IL or missing references)
94 //IL_0019: Expected O, but got Unknown
95 if ((RailComparableID)(object)_local_id == (RailComparableID)null)
96 {
97 _local_id = new RailID();
98 }
99 ((RailComparableID)_local_id).id_ = ((RailComparableID)rail_id).id_;
100 }
101
102 private RailID GetLocalPeer()
103 {
104 return _local_id;
105 }
106
107 private bool IsValid()
108 {
109 if ((RailComparableID)(object)_local_id != (RailComparableID)null)
110 {
111 return ((RailComparableID)_local_id).IsValid();
112 }
113 return false;
114 }
115
116 public void SendAll()
117 {
118 //IL_0086: Unknown result type (might be due to invalid IL or missing references)
119 //IL_008c: Invalid comparison between Unknown and I4
120 if (!IsValid())
121 {
122 return;
123 }
124 lock (_lock)
125 {
127 }
129 {
131 while (value.Count > 0)
132 {
134 _ = (int)rail_api.RailFactory().RailNetworkHelper().SendData(GetLocalPeer(), item.Key, writeInformation.Data, (uint)writeInformation.Size) == 0;
136 }
137 }
138 }
139}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
static byte Min(byte val1, byte val2)
Definition Math.cs:912
Dictionary< RailID, Queue< WriteInformation > > _pendingSendData
Dictionary< RailID, Queue< WriteInformation > > _pendingSendDataSwap
void QueueSend(RailID user, byte[] data, int length)