diff options
Diffstat (limited to 'Common-Source/OpenSim.Servers/CheckSumServer.cs')
-rw-r--r-- | Common-Source/OpenSim.Servers/CheckSumServer.cs | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/Common-Source/OpenSim.Servers/CheckSumServer.cs b/Common-Source/OpenSim.Servers/CheckSumServer.cs new file mode 100644 index 0000000..ae1724f --- /dev/null +++ b/Common-Source/OpenSim.Servers/CheckSumServer.cs | |||
@@ -0,0 +1,113 @@ | |||
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) | ||
23 | : base(port) | ||
24 | { | ||
25 | } | ||
26 | |||
27 | protected override void OnReceivedData(IAsyncResult result) | ||
28 | { | ||
29 | ipeSender = new IPEndPoint(IPAddress.Any, 0); | ||
30 | epSender = (EndPoint)ipeSender; | ||
31 | Packet packet = null; | ||
32 | int numBytes = Server.EndReceiveFrom(result, ref epSender); | ||
33 | int packetEnd = numBytes - 1; | ||
34 | |||
35 | packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer); | ||
36 | |||
37 | if (packet.Type == PacketType.SecuredTemplateChecksumRequest) | ||
38 | { | ||
39 | SecuredTemplateChecksumRequestPacket checksum = (SecuredTemplateChecksumRequestPacket)packet; | ||
40 | TemplateChecksumReplyPacket checkreply = new TemplateChecksumReplyPacket(); | ||
41 | checkreply.DataBlock.Checksum = 180572585; | ||
42 | checkreply.DataBlock.Flags = 0; | ||
43 | checkreply.DataBlock.MajorVersion = 1; | ||
44 | checkreply.DataBlock.MinorVersion = 15; | ||
45 | checkreply.DataBlock.PatchVersion = 0; | ||
46 | checkreply.DataBlock.ServerVersion = 0; | ||
47 | checkreply.TokenBlock.Token = checksum.TokenBlock.Token; | ||
48 | this.SendPacket(checkreply, epSender); | ||
49 | |||
50 | /* | ||
51 | //if we wanted to echo the the checksum/ version from the client (so that any client worked) | ||
52 | SecuredTemplateChecksumRequestPacket checkrequest = new SecuredTemplateChecksumRequestPacket(); | ||
53 | checkrequest.TokenBlock.Token = checksum.TokenBlock.Token; | ||
54 | this.SendPacket(checkrequest, epSender); | ||
55 | */ | ||
56 | } | ||
57 | else if (packet.Type == PacketType.TemplateChecksumReply) | ||
58 | { | ||
59 | //echo back the client checksum reply (Hegemon's method) | ||
60 | TemplateChecksumReplyPacket checksum2 = (TemplateChecksumReplyPacket)packet; | ||
61 | TemplateChecksumReplyPacket checkreply2 = new TemplateChecksumReplyPacket(); | ||
62 | checkreply2.DataBlock.Checksum = checksum2.DataBlock.Checksum; | ||
63 | checkreply2.DataBlock.Flags = checksum2.DataBlock.Flags; | ||
64 | checkreply2.DataBlock.MajorVersion = checksum2.DataBlock.MajorVersion; | ||
65 | checkreply2.DataBlock.MinorVersion = checksum2.DataBlock.MinorVersion; | ||
66 | checkreply2.DataBlock.PatchVersion = checksum2.DataBlock.PatchVersion; | ||
67 | checkreply2.DataBlock.ServerVersion = checksum2.DataBlock.ServerVersion; | ||
68 | checkreply2.TokenBlock.Token = checksum2.TokenBlock.Token; | ||
69 | this.SendPacket(checkreply2, epSender); | ||
70 | } | ||
71 | else | ||
72 | { | ||
73 | } | ||
74 | |||
75 | Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); | ||
76 | } | ||
77 | |||
78 | private void SendPacket(Packet Pack, EndPoint endp) | ||
79 | { | ||
80 | if (!Pack.Header.Resent) | ||
81 | { | ||
82 | Pack.Header.Sequence = 1; | ||
83 | } | ||
84 | |||
85 | byte[] ZeroOutBuffer = new byte[4096]; | ||
86 | byte[] sendbuffer; | ||
87 | sendbuffer = Pack.ToBytes(); | ||
88 | |||
89 | try | ||
90 | { | ||
91 | if (Pack.Header.Zerocoded) | ||
92 | { | ||
93 | int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer); | ||
94 | this.SendPackTo(ZeroOutBuffer, packetsize, SocketFlags.None, endp); | ||
95 | } | ||
96 | else | ||
97 | { | ||
98 | this.SendPackTo(sendbuffer, sendbuffer.Length, SocketFlags.None, endp); | ||
99 | } | ||
100 | } | ||
101 | catch (Exception) | ||
102 | { | ||
103 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "OpenSimClient.cs:ProcessOutPacket() - WARNING: Socket exception occurred on connection "); | ||
104 | |||
105 | } | ||
106 | } | ||
107 | |||
108 | private void SendPackTo(byte[] buffer, int size, SocketFlags flags, EndPoint endp) | ||
109 | { | ||
110 | this.Server.SendTo(buffer, size, flags, endp); | ||
111 | } | ||
112 | } | ||
113 | } \ No newline at end of file | ||