Moved CheckSumServer (and added UDPServerBase ) to OpenSim.Servers

zircon^2
MW 2007-05-19 14:08:58 +00:00
parent 42c45a8716
commit f5de37553d
5 changed files with 200 additions and 16 deletions

View File

@ -144,7 +144,6 @@
<Compile Include="AuthenticateSessionsRemote.cs"> <Compile Include="AuthenticateSessionsRemote.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="CheckSumServer.cs" />
<Compile Include="Grid.cs"> <Compile Include="Grid.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>

View File

@ -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);
}
}
}

View File

@ -1,4 +1,4 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<ProjectType>Local</ProjectType> <ProjectType>Local</ProjectType>
<ProductVersion>8.0.50727</ProductVersion> <ProductVersion>8.0.50727</ProductVersion>
@ -6,7 +6,8 @@
<ProjectGuid>{8BB20F0A-0000-0000-0000-000000000000}</ProjectGuid> <ProjectGuid>{8BB20F0A-0000-0000-0000-000000000000}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ApplicationIcon></ApplicationIcon> <ApplicationIcon>
</ApplicationIcon>
<AssemblyKeyContainerName> <AssemblyKeyContainerName>
</AssemblyKeyContainerName> </AssemblyKeyContainerName>
<AssemblyName>OpenSim.Servers</AssemblyName> <AssemblyName>OpenSim.Servers</AssemblyName>
@ -15,9 +16,11 @@
<DefaultTargetSchema>IE50</DefaultTargetSchema> <DefaultTargetSchema>IE50</DefaultTargetSchema>
<DelaySign>false</DelaySign> <DelaySign>false</DelaySign>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder></AppDesignerFolder> <AppDesignerFolder>
</AppDesignerFolder>
<RootNamespace>OpenSim.Servers</RootNamespace> <RootNamespace>OpenSim.Servers</RootNamespace>
<StartupObject></StartupObject> <StartupObject>
</StartupObject>
<FileUpgradeFlags> <FileUpgradeFlags>
</FileUpgradeFlags> </FileUpgradeFlags>
</PropertyGroup> </PropertyGroup>
@ -28,7 +31,8 @@
<ConfigurationOverrideFile> <ConfigurationOverrideFile>
</ConfigurationOverrideFile> </ConfigurationOverrideFile>
<DefineConstants>TRACE;DEBUG</DefineConstants> <DefineConstants>TRACE;DEBUG</DefineConstants>
<DocumentationFile></DocumentationFile> <DocumentationFile>
</DocumentationFile>
<DebugSymbols>True</DebugSymbols> <DebugSymbols>True</DebugSymbols>
<FileAlignment>4096</FileAlignment> <FileAlignment>4096</FileAlignment>
<Optimize>False</Optimize> <Optimize>False</Optimize>
@ -37,7 +41,8 @@
<RemoveIntegerChecks>False</RemoveIntegerChecks> <RemoveIntegerChecks>False</RemoveIntegerChecks>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors> <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<NoWarn></NoWarn> <NoWarn>
</NoWarn>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
@ -46,7 +51,8 @@
<ConfigurationOverrideFile> <ConfigurationOverrideFile>
</ConfigurationOverrideFile> </ConfigurationOverrideFile>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<DocumentationFile></DocumentationFile> <DocumentationFile>
</DocumentationFile>
<DebugSymbols>False</DebugSymbols> <DebugSymbols>False</DebugSymbols>
<FileAlignment>4096</FileAlignment> <FileAlignment>4096</FileAlignment>
<Optimize>True</Optimize> <Optimize>True</Optimize>
@ -55,18 +61,20 @@
<RemoveIntegerChecks>False</RemoveIntegerChecks> <RemoveIntegerChecks>False</RemoveIntegerChecks>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors> <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<NoWarn></NoWarn> <NoWarn>
</NoWarn>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" > <Reference Include="System">
<HintPath>System.dll</HintPath> <HintPath>System.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="System.Xml" > <Reference Include="System.Data" />
<Reference Include="System.Xml">
<HintPath>System.Xml.dll</HintPath> <HintPath>System.Xml.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="libsecondlife.dll" > <Reference Include="libsecondlife.dll">
<HintPath>..\bin\libsecondlife.dll</HintPath> <HintPath>..\bin\libsecondlife.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
@ -76,19 +84,19 @@
<Name>OpenSim.Framework</Name> <Name>OpenSim.Framework</Name>
<Project>{8ACA2445-0000-0000-0000-000000000000}</Project> <Project>{8ACA2445-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package> <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\OpenSim.Framework.Console\OpenSim.Framework.Console.csproj"> <ProjectReference Include="..\OpenSim.Framework.Console\OpenSim.Framework.Console.csproj">
<Name>OpenSim.Framework.Console</Name> <Name>OpenSim.Framework.Console</Name>
<Project>{A7CD0630-0000-0000-0000-000000000000}</Project> <Project>{A7CD0630-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package> <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\XmlRpcCS\XMLRPC.csproj"> <ProjectReference Include="..\XmlRpcCS\XMLRPC.csproj">
<Name>XMLRPC</Name> <Name>XMLRPC</Name>
<Project>{8E81D43C-0000-0000-0000-000000000000}</Project> <Project>{8E81D43C-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package> <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -98,6 +106,7 @@
<Compile Include="BaseServer.cs"> <Compile Include="BaseServer.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="CheckSumServer.cs" />
<Compile Include="IRestHandler.cs"> <Compile Include="IRestHandler.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
@ -110,6 +119,7 @@
<Compile Include="LoginServer.cs"> <Compile Include="LoginServer.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="UDPServerBase.cs" />
<Compile Include="XmlRpcMethod.cs"> <Compile Include="XmlRpcMethod.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>

View File

@ -13,10 +13,12 @@
<sources failonempty="true"> <sources failonempty="true">
<include name="BaseHttpServer.cs" /> <include name="BaseHttpServer.cs" />
<include name="BaseServer.cs" /> <include name="BaseServer.cs" />
<include name="CheckSumServer.cs" />
<include name="IRestHandler.cs" /> <include name="IRestHandler.cs" />
<include name="LocalUserProfileManager.cs" /> <include name="LocalUserProfileManager.cs" />
<include name="LoginResponse.cs" /> <include name="LoginResponse.cs" />
<include name="LoginServer.cs" /> <include name="LoginServer.cs" />
<include name="UDPServerBase.cs" />
<include name="XmlRpcMethod.cs" /> <include name="XmlRpcMethod.cs" />
</sources> </sources>
<references basedir="${project::get-base-directory()}"> <references basedir="${project::get-base-directory()}">

View File

@ -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
}
}
}