From f5de37553d04b3a263ff54aca7e319550cba66ad Mon Sep 17 00:00:00 2001
From: MW
Date: Sat, 19 May 2007 14:08:58 +0000
Subject: Moved CheckSumServer (and added UDPServerBase ) to OpenSim.Servers
---
OpenSim.RegionServer/OpenSim.RegionServer.csproj | 1 -
OpenSim.Servers/CheckSumServer.cs | 99 ++++++++++++++++++++++++
OpenSim.Servers/OpenSim.Servers.csproj | 40 ++++++----
OpenSim.Servers/OpenSim.Servers.dll.build | 2 +
OpenSim.Servers/UDPServerBase.cs | 74 ++++++++++++++++++
5 files changed, 200 insertions(+), 16 deletions(-)
create mode 100644 OpenSim.Servers/CheckSumServer.cs
create mode 100644 OpenSim.Servers/UDPServerBase.cs
diff --git a/OpenSim.RegionServer/OpenSim.RegionServer.csproj b/OpenSim.RegionServer/OpenSim.RegionServer.csproj
index 5b586fa..e736d04 100644
--- a/OpenSim.RegionServer/OpenSim.RegionServer.csproj
+++ b/OpenSim.RegionServer/OpenSim.RegionServer.csproj
@@ -144,7 +144,6 @@
Code
-
Code
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 @@
+using System;
+using System.Text;
+using System.IO;
+using System.Threading;
+using System.Net;
+using System.Net.Sockets;
+using System.Timers;
+using System.Reflection;
+using System.Collections;
+using System.Collections.Generic;
+using libsecondlife;
+using libsecondlife.Packets;
+using OpenSim.Framework.Console;
+
+
+namespace OpenSim.Servers
+{
+ public class CheckSumServer : UDPServerBase
+ {
+ protected ConsoleBase m_console;
+
+ public CheckSumServer(int port, ConsoleBase console)
+ {
+ listenPort = port;
+ this.m_console = console;
+ }
+
+ protected override void OnReceivedData(IAsyncResult result)
+ {
+ ipeSender = new IPEndPoint(IPAddress.Any, 0);
+ epSender = (EndPoint)ipeSender;
+ Packet packet = null;
+ int numBytes = Server.EndReceiveFrom(result, ref epSender);
+ int packetEnd = numBytes - 1;
+
+ packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer);
+
+ // do we already have a circuit for this endpoint
+ if (packet.Type == PacketType.SecuredTemplateChecksumRequest)
+ {
+ SecuredTemplateChecksumRequestPacket checksum = (SecuredTemplateChecksumRequestPacket)packet;
+ TemplateChecksumReplyPacket checkreply = new TemplateChecksumReplyPacket();
+ checkreply.DataBlock.Checksum = 180572585;
+ checkreply.DataBlock.Flags = 0;
+ checkreply.DataBlock.MajorVersion = 1;
+ checkreply.DataBlock.MinorVersion = 15;
+ checkreply.DataBlock.PatchVersion = 0;
+ checkreply.DataBlock.ServerVersion = 2;
+ checkreply.TokenBlock.Token = checksum.TokenBlock.Token;
+ this.SendPacket(checkreply, epSender);
+
+ }
+ else
+ { // invalid client
+ // Console.Error.WriteLine("CheckSumServer.cs:OnReceivedData() - WARNING: Got a invalid packet from an invalid client - " + epSender.ToString());
+ }
+
+ Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
+ }
+
+
+ private void SendPacket(Packet Pack, EndPoint endp)
+ {
+ if (!Pack.Header.Resent)
+ {
+ // Set the sequence number
+
+ Pack.Header.Sequence = 1;
+
+ }
+ byte[] ZeroOutBuffer = new byte[4096];
+ byte[] sendbuffer;
+ sendbuffer = Pack.ToBytes();
+
+ try
+ {
+ if (Pack.Header.Zerocoded)
+ {
+ int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer);
+ this.SendPackTo(ZeroOutBuffer, packetsize, SocketFlags.None, endp);
+ }
+ else
+ {
+ this.SendPackTo(sendbuffer, sendbuffer.Length, SocketFlags.None, endp);
+ }
+ }
+ catch (Exception)
+ {
+ OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "OpenSimClient.cs:ProcessOutPacket() - WARNING: Socket exception occurred on connection ");
+
+ }
+ }
+
+ private void SendPackTo(byte[] buffer, int size, SocketFlags flags, EndPoint endp)
+ {
+ this.Server.SendTo(buffer, size, flags, endp);
+ }
+ }
+}
\ No newline at end of file
diff --git a/OpenSim.Servers/OpenSim.Servers.csproj b/OpenSim.Servers/OpenSim.Servers.csproj
index 6e04463..d59306a 100644
--- a/OpenSim.Servers/OpenSim.Servers.csproj
+++ b/OpenSim.Servers/OpenSim.Servers.csproj
@@ -1,4 +1,4 @@
-
+
Local
8.0.50727
@@ -6,7 +6,8 @@
{8BB20F0A-0000-0000-0000-000000000000}
Debug
AnyCPU
-
+
+
OpenSim.Servers
@@ -15,9 +16,11 @@
IE50
false
Library
-
+
+
OpenSim.Servers
-
+
+
@@ -28,7 +31,8 @@
TRACE;DEBUG
-
+
+
True
4096
False
@@ -37,7 +41,8 @@
False
False
4
-
+
+
False
@@ -46,7 +51,8 @@
TRACE
-
+
+
False
4096
True
@@ -55,18 +61,20 @@
False
False
4
-
+
+
-
+
System.dll
False
-
+
+
System.Xml.dll
False
-
+
..\bin\libsecondlife.dll
False
@@ -76,19 +84,19 @@
OpenSim.Framework
{8ACA2445-0000-0000-0000-000000000000}
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- False
+ False
OpenSim.Framework.Console
{A7CD0630-0000-0000-0000-000000000000}
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- False
+ False
XMLRPC
{8E81D43C-0000-0000-0000-000000000000}
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- False
+ False
@@ -98,6 +106,7 @@
Code
+
Code
@@ -110,6 +119,7 @@
Code
+
Code
@@ -121,4 +131,4 @@
-
+
\ No newline at end of file
diff --git a/OpenSim.Servers/OpenSim.Servers.dll.build b/OpenSim.Servers/OpenSim.Servers.dll.build
index 4ad29dd..5afd9e1 100644
--- a/OpenSim.Servers/OpenSim.Servers.dll.build
+++ b/OpenSim.Servers/OpenSim.Servers.dll.build
@@ -13,10 +13,12 @@
+
+
diff --git a/OpenSim.Servers/UDPServerBase.cs b/OpenSim.Servers/UDPServerBase.cs
new file mode 100644
index 0000000..bdbc772
--- /dev/null
+++ b/OpenSim.Servers/UDPServerBase.cs
@@ -0,0 +1,74 @@
+using System;
+using System.Text;
+using System.IO;
+using System.Threading;
+using System.Net;
+using System.Net.Sockets;
+using System.Timers;
+using System.Reflection;
+using System.Collections;
+using System.Collections.Generic;
+using libsecondlife;
+using libsecondlife.Packets;
+
+namespace OpenSim.Servers
+{
+ public class UDPServerBase
+ {
+
+ public Socket Server;
+ protected IPEndPoint ServerIncoming;
+ protected byte[] RecvBuffer = new byte[4096];
+ protected byte[] ZeroBuffer = new byte[8192];
+ protected IPEndPoint ipeSender;
+ protected EndPoint epSender;
+ protected AsyncCallback ReceivedData;
+ protected int listenPort;
+
+ public UDPServerBase()
+ {
+ }
+
+ protected virtual void OnReceivedData(IAsyncResult result)
+ {
+ ipeSender = new IPEndPoint(IPAddress.Any, 0);
+ epSender = (EndPoint)ipeSender;
+ Packet packet = null;
+ int numBytes = Server.EndReceiveFrom(result, ref epSender);
+ int packetEnd = numBytes - 1;
+
+ packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer);
+
+
+
+ Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
+ }
+
+ protected virtual void AddNewClient(Packet packet)
+ {
+ }
+
+ public void ServerListener()
+ {
+
+ ServerIncoming = new IPEndPoint(IPAddress.Any, listenPort);
+ Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
+ Server.Bind(ServerIncoming);
+
+ ipeSender = new IPEndPoint(IPAddress.Any, 0);
+ epSender = (EndPoint)ipeSender;
+ ReceivedData = new AsyncCallback(this.OnReceivedData);
+ Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
+ }
+
+
+ public virtual void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode)
+ {
+ // find the endpoint for this circuit
+
+ }
+
+
+ }
+}
+
--
cgit v1.1