-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServerSock.cs
176 lines (169 loc) · 5.5 KB
/
ServerSock.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
namespace Terraria
{
using System;
using System.Diagnostics;
using System.Net.Sockets;
public class ServerSock
{
public bool active = false;
public bool announced = false;
public Socket clientSocket;
public bool kill = false;
public bool locked = false;
public string name = "Anonymous";
public NetworkStream networkStream;
public string oldName = "";
public byte[] readBuffer;
public float spamAddBlock = 0f;
public float spamAddBlockMax = 60f;
public bool spamCheck = true;
public float spamDelBlock = 0f;
public float spamDelBlockMax = 400f;
public float spamProjectile = 0f;
public float spamProjectileMax = 60f;
public float spamWater = 0f;
public float spamWaterMax = 20f;
public int state = 0;
public int statusCount;
public int statusMax;
public string statusText = "";
public string statusText2;
public TcpClient tcpClient = new TcpClient();
public bool[,] tileSection = new bool[Main.maxTilesX / 200, Main.maxTilesY / 150];
public int timeOut = 0;
public int whoAmI = 0;
public byte[] writeBuffer;
public void Reset()
{
for (int i = 0; i < Main.maxSectionsX; i++)
{
for (int j = 0; j < Main.maxSectionsY; j++)
{
this.tileSection[i, j] = false;
}
}
if (this.whoAmI < 0xff)
{
Main.player[this.whoAmI] = new Player();
}
this.timeOut = 0;
this.statusCount = 0;
this.statusMax = 0;
this.statusText2 = "";
this.statusText = "";
this.name = "Anonymous";
this.state = 0;
this.locked = false;
this.kill = false;
this.SpamClear();
this.active = false;
NetMessage.buffer[this.whoAmI].Reset();
if (this.networkStream != null)
{
this.networkStream.Close();
}
if (this.tcpClient != null)
{
this.tcpClient.Close();
}
}
public void ServerReadCallBack(IAsyncResult ar)
{
int streamLength = 0;
if (!Netplay.disconnect)
{
try
{
streamLength = this.networkStream.EndRead(ar);
}
catch
{
}
if (streamLength == 0)
{
this.kill = true;
}
else if (Main.ignoreErrors)
{
try
{
NetMessage.RecieveBytes(this.readBuffer, streamLength, this.whoAmI);
}
catch
{
Debug.WriteLine(string.Concat(new object[] { "Error: NetMessage.RecieveBytes(", this.readBuffer, ", ", streamLength, ")" }));
}
}
else
{
NetMessage.RecieveBytes(this.readBuffer, streamLength, this.whoAmI);
}
}
this.locked = false;
}
public void ServerWriteCallBack(IAsyncResult ar)
{
messageBuffer buffer1 = NetMessage.buffer[this.whoAmI];
buffer1.spamCount--;
if (this.statusMax > 0)
{
this.statusCount++;
}
}
public void SpamClear()
{
this.spamProjectile = 0f;
this.spamAddBlock = 0f;
this.spamDelBlock = 0f;
}
public void SpamUpdate()
{
if (!this.spamCheck)
{
this.spamProjectile = 0f;
this.spamDelBlock = 0f;
this.spamAddBlock = 0f;
this.spamWater = 0f;
}
else
{
if (this.spamProjectile > this.spamProjectileMax)
{
NetMessage.BootPlayer(this.whoAmI, "Cheating attempt detected: Projectile spam");
}
if (this.spamAddBlock > this.spamAddBlockMax)
{
NetMessage.BootPlayer(this.whoAmI, "Cheating attempt detected: Add tile spam");
}
if (this.spamDelBlock > this.spamDelBlockMax)
{
NetMessage.BootPlayer(this.whoAmI, "Cheating attempt detected: Remove tile spam");
}
if (this.spamWater > this.spamWaterMax)
{
NetMessage.BootPlayer(this.whoAmI, "Cheating attempt detected: Liquid spam");
}
this.spamProjectile -= 0.2f;
if (this.spamProjectile < 0f)
{
this.spamProjectile = 0f;
}
this.spamAddBlock -= 0.1f;
if (this.spamAddBlock < 0f)
{
this.spamAddBlock = 0f;
}
this.spamDelBlock -= 2f;
if (this.spamDelBlock < 0f)
{
this.spamDelBlock = 0f;
}
this.spamWater -= 0.1f;
if (this.spamWater < 0f)
{
this.spamWater = 0f;
}
}
}
}
}