diff options
Moved CheckSumServer (and added UDPServerBase ) to OpenSim.Servers
Diffstat (limited to 'OpenSim.Servers/CheckSumServer.cs')
-rw-r--r-- | OpenSim.Servers/CheckSumServer.cs | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/OpenSim.Servers/CheckSumServer.cs b/OpenSim.Servers/CheckSumServer.cs new file mode 100644 index 0000000..dc83192 --- /dev/null +++ b/OpenSim.Servers/CheckSumServer.cs | |||
@@ -0,0 +1,99 @@ | |||
1 | using System; | ||
2 | using System.Text; | ||
3 | using System.IO; | ||
4 | using System.Threading; | ||
5 | using System.Net; | ||
6 | using System.Net.Sockets; | ||
7 | using System.Timers; | ||
8 | using System.Reflection; | ||
9 | using System.Collections; | ||
10 | using System.Collections.Generic; | ||
11 | using libsecondlife; | ||
12 | using libsecondlife.Packets; | ||
13 | using OpenSim.Framework.Console; | ||
14 | |||
15 | |||
16 | namespace OpenSim.Servers | ||
17 | { | ||
18 | public class CheckSumServer : UDPServerBase | ||
19 | { | ||
20 | protected ConsoleBase m_console; | ||
21 | |||
22 | public CheckSumServer(int port, ConsoleBase console) | ||
23 | { | ||
24 | listenPort = port; | ||
25 | this.m_console = console; | ||
26 | } | ||
27 | |||
28 | protected override void OnReceivedData(IAsyncResult result) | ||
29 | { | ||
30 | ipeSender = new IPEndPoint(IPAddress.Any, 0); | ||
31 | epSender = (EndPoint)ipeSender; | ||
32 | Packet packet = null; | ||
33 | int numBytes = Server.EndReceiveFrom(result, ref epSender); | ||
34 | int packetEnd = numBytes - 1; | ||
35 | |||
36 | packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer); | ||
37 | |||
38 | // do we already have a circuit for this endpoint | ||
39 | if (packet.Type == PacketType.SecuredTemplateChecksumRequest) | ||
40 | { | ||
41 | SecuredTemplateChecksumRequestPacket checksum = (SecuredTemplateChecksumRequestPacket)packet; | ||
42 | TemplateChecksumReplyPacket checkreply = new TemplateChecksumReplyPacket(); | ||
43 | checkreply.DataBlock.Checksum = 180572585; | ||
44 | checkreply.DataBlock.Flags = 0; | ||
45 | checkreply.DataBlock.MajorVersion = 1; | ||
46 | checkreply.DataBlock.MinorVersion = 15; | ||
47 | checkreply.DataBlock.PatchVersion = 0; | ||
48 | checkreply.DataBlock.ServerVersion = 2; | ||
49 | checkreply.TokenBlock.Token = checksum.TokenBlock.Token; | ||
50 | this.SendPacket(checkreply, epSender); | ||
51 | |||
52 | } | ||
53 | else | ||
54 | { // invalid client | ||
55 | // Console.Error.WriteLine("CheckSumServer.cs:OnReceivedData() - WARNING: Got a invalid packet from an invalid client - " + epSender.ToString()); | ||
56 | } | ||
57 | |||
58 | Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); | ||
59 | } | ||
60 | |||
61 | |||
62 | private void SendPacket(Packet Pack, EndPoint endp) | ||
63 | { | ||
64 | if (!Pack.Header.Resent) | ||
65 | { | ||
66 | // Set the sequence number | ||
67 | |||
68 | Pack.Header.Sequence = 1; | ||
69 | |||
70 | } | ||
71 | byte[] ZeroOutBuffer = new byte[4096]; | ||
72 | byte[] sendbuffer; | ||
73 | sendbuffer = Pack.ToBytes(); | ||
74 | |||
75 | try | ||
76 | { | ||
77 | if (Pack.Header.Zerocoded) | ||
78 | { | ||
79 | int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer); | ||
80 | this.SendPackTo(ZeroOutBuffer, packetsize, SocketFlags.None, endp); | ||
81 | } | ||
82 | else | ||
83 | { | ||
84 | this.SendPackTo(sendbuffer, sendbuffer.Length, SocketFlags.None, endp); | ||
85 | } | ||
86 | } | ||
87 | catch (Exception) | ||
88 | { | ||
89 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "OpenSimClient.cs:ProcessOutPacket() - WARNING: Socket exception occurred on connection "); | ||
90 | |||
91 | } | ||
92 | } | ||
93 | |||
94 | private void SendPackTo(byte[] buffer, int size, SocketFlags flags, EndPoint endp) | ||
95 | { | ||
96 | this.Server.SendTo(buffer, size, flags, endp); | ||
97 | } | ||
98 | } | ||
99 | } \ No newline at end of file | ||