From 646bbbc84b8010e0dacbeed5342cdb045f46cc49 Mon Sep 17 00:00:00 2001 From: MW Date: Wed, 27 Jun 2007 15:28:52 +0000 Subject: Some work on restructuring the namespaces / project names. Note this doesn't compile yet as not all the code has been changed to use the new namespaces. Am committing it now for feedback on the namespaces. --- OpenSim/Region/ClientStack/UDPServer.cs | 208 ++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 OpenSim/Region/ClientStack/UDPServer.cs (limited to 'OpenSim/Region/ClientStack/UDPServer.cs') diff --git a/OpenSim/Region/ClientStack/UDPServer.cs b/OpenSim/Region/ClientStack/UDPServer.cs new file mode 100644 index 0000000..f2a02d9 --- /dev/null +++ b/OpenSim/Region/ClientStack/UDPServer.cs @@ -0,0 +1,208 @@ +/* +* Copyright (c) Contributors, http://www.openmetaverse.org/ +* See CONTRIBUTORS.TXT for a full list of copyright holders. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of the OpenSim Project nor the +* names of its contributors may be used to endorse or promote products +* derived from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY +* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ +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.Terrain; +using OpenSim.Framework.Interfaces; +using OpenSim.Framework.Types; +using OpenSim.Assets; +using OpenSim.Caches; +using OpenSim.Framework.Console; +using OpenSim.Framework; +using Nwc.XmlRpc; +using OpenSim.Servers; +using OpenSim.GenericConfig; + +namespace OpenSim +{ + + public class UDPServer : ClientStackNetworkHandler + { + protected Dictionary clientCircuits = new Dictionary(); + 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 PacketServer _packetServer; + + protected int listenPort; + protected IWorld m_localWorld; + protected AssetCache m_assetCache; + protected InventoryCache m_inventoryCache; + protected LogBase m_log; + protected AuthenticateSessionsBase m_authenticateSessionsClass; + + public PacketServer PacketServer + { + get + { + return _packetServer; + } + set + { + _packetServer = value; + } + } + + public IWorld LocalWorld + { + set + { + this.m_localWorld = value; + this._packetServer.LocalWorld = this.m_localWorld; + } + } + + public UDPServer() + { + } + + public UDPServer(int port, AssetCache assetCache, InventoryCache inventoryCache, LogBase console, AuthenticateSessionsBase authenticateClass) + { + listenPort = port; + this.m_assetCache = assetCache; + this.m_inventoryCache = inventoryCache; + this.m_log = console; + this.m_authenticateSessionsClass = authenticateClass; + this.CreatePacketServer(); + + } + + protected virtual void CreatePacketServer() + { + PacketServer packetServer = new PacketServer(this, (uint) listenPort); + } + + 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); + + // do we already have a circuit for this endpoint + if (this.clientCircuits.ContainsKey(epSender)) + { + //if so then send packet to the packetserver + this._packetServer.ClientInPacket(this.clientCircuits[epSender], packet); + } + else if (packet.Type == PacketType.UseCircuitCode) + { + // new client + this.AddNewClient(packet); + } + else + { // invalid client + m_log.Warn("UDPServer.cs:OnReceivedData() - WARNING: Got a packet from an invalid client - " + epSender.ToString()); + } + + Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); + } + + protected virtual void AddNewClient(Packet packet) + { + UseCircuitCodePacket useCircuit = (UseCircuitCodePacket)packet; + this.clientCircuits.Add(epSender, useCircuit.CircuitCode.Code); + + this.PacketServer.AddNewClient(epSender, useCircuit, m_assetCache, m_inventoryCache, m_authenticateSessionsClass); + } + + public void ServerListener() + { + m_log.Status("UDPServer.cs:ServerListener() - Opening UDP socket on " + listenPort); + + ServerIncoming = new IPEndPoint(IPAddress.Any, listenPort); + Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); + Server.Bind(ServerIncoming); + + m_log.Verbose("UDPServer.cs:ServerListener() - UDP socket bound, getting ready to listen"); + + 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); + + m_log.Verbose("UDPServer.cs:ServerListener() - Listening..."); + + } + + public virtual void RegisterPacketServer(PacketServer server) + { + this._packetServer = server; + } + + public virtual void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode)//EndPoint packetSender) + { + // find the endpoint for this circuit + EndPoint sendto = null; + foreach (KeyValuePair p in this.clientCircuits) + { + if (p.Value == circuitcode) + { + sendto = p.Key; + break; + } + } + if (sendto != null) + { + //we found the endpoint so send the packet to it + this.Server.SendTo(buffer, size, flags, sendto); + } + } + + public virtual void RemoveClientCircuit(uint circuitcode) + { + foreach (KeyValuePair p in this.clientCircuits) + { + if (p.Value == circuitcode) + { + this.clientCircuits.Remove(p.Key); + break; + } + } + } + + + } +} \ No newline at end of file -- cgit v1.1 From e41eedc9aeba3eb36cdba4fcdf1e57bea976cab4 Mon Sep 17 00:00:00 2001 From: mingchen Date: Wed, 27 Jun 2007 16:39:11 +0000 Subject: *Some more restructuring/fixing -- should compile, but high chance I forgot to add/remove something --- OpenSim/Region/ClientStack/UDPServer.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region/ClientStack/UDPServer.cs') diff --git a/OpenSim/Region/ClientStack/UDPServer.cs b/OpenSim/Region/ClientStack/UDPServer.cs index f2a02d9..33097ed 100644 --- a/OpenSim/Region/ClientStack/UDPServer.cs +++ b/OpenSim/Region/ClientStack/UDPServer.cs @@ -41,14 +41,13 @@ using OpenSim.Terrain; using OpenSim.Framework.Interfaces; using OpenSim.Framework.Types; using OpenSim.Assets; -using OpenSim.Caches; +using OpenSim.Region.Caches; using OpenSim.Framework.Console; using OpenSim.Framework; using Nwc.XmlRpc; -using OpenSim.Servers; -using OpenSim.GenericConfig; +using OpenSim.Framework.Servers; -namespace OpenSim +namespace OpenSim.Region.ClientStack { public class UDPServer : ClientStackNetworkHandler -- cgit v1.1 From 9eaecabdd0884cfe17d249440badce1ecdbcc142 Mon Sep 17 00:00:00 2001 From: mingchen Date: Wed, 27 Jun 2007 19:04:23 +0000 Subject: *Moved VersionInfo.cs to its correct place in OpenSim.csproj *Added OpenSim.Region.Caps *Updated prebuild.xml and ran prebuild --- OpenSim/Region/ClientStack/UDPServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/ClientStack/UDPServer.cs') diff --git a/OpenSim/Region/ClientStack/UDPServer.cs b/OpenSim/Region/ClientStack/UDPServer.cs index 33097ed..259352c 100644 --- a/OpenSim/Region/ClientStack/UDPServer.cs +++ b/OpenSim/Region/ClientStack/UDPServer.cs @@ -37,7 +37,7 @@ using System.Collections; using System.Collections.Generic; using libsecondlife; using libsecondlife.Packets; -using OpenSim.Terrain; +using OpenSim.Region.Terrain; using OpenSim.Framework.Interfaces; using OpenSim.Framework.Types; using OpenSim.Assets; -- cgit v1.1 From 72cd28be1b743a61c739d7d13f933cf41e948fdf Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Fri, 29 Jun 2007 20:09:29 +0000 Subject: * Experimental patch: Replaced IPAddress.Any with IPAddress.Parse("0.0.0.0") to force IPv4 --- OpenSim/Region/ClientStack/UDPServer.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/ClientStack/UDPServer.cs') diff --git a/OpenSim/Region/ClientStack/UDPServer.cs b/OpenSim/Region/ClientStack/UDPServer.cs index 259352c..b764519 100644 --- a/OpenSim/Region/ClientStack/UDPServer.cs +++ b/OpenSim/Region/ClientStack/UDPServer.cs @@ -112,7 +112,7 @@ namespace OpenSim.Region.ClientStack protected virtual void OnReceivedData(IAsyncResult result) { - ipeSender = new IPEndPoint(IPAddress.Any, 0); + ipeSender = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0); epSender = (EndPoint)ipeSender; Packet packet = null; int numBytes = Server.EndReceiveFrom(result, ref epSender); @@ -151,13 +151,13 @@ namespace OpenSim.Region.ClientStack { m_log.Status("UDPServer.cs:ServerListener() - Opening UDP socket on " + listenPort); - ServerIncoming = new IPEndPoint(IPAddress.Any, listenPort); + ServerIncoming = new IPEndPoint(IPAddress.Parse("0.0.0.0"), listenPort); Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); Server.Bind(ServerIncoming); m_log.Verbose("UDPServer.cs:ServerListener() - UDP socket bound, getting ready to listen"); - ipeSender = new IPEndPoint(IPAddress.Any, 0); + ipeSender = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0); epSender = (EndPoint)ipeSender; ReceivedData = new AsyncCallback(this.OnReceivedData); Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); -- cgit v1.1 From 06a8c132005b4ab804f25d54c0c0f899fc98e3a1 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Sun, 1 Jul 2007 16:07:41 +0000 Subject: MAJOR IP RESTRUCTURING * moving towards IPEndPoints all over the place * trying to make the internal/external division --- OpenSim/Region/ClientStack/UDPServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/ClientStack/UDPServer.cs') diff --git a/OpenSim/Region/ClientStack/UDPServer.cs b/OpenSim/Region/ClientStack/UDPServer.cs index b764519..8ad5332 100644 --- a/OpenSim/Region/ClientStack/UDPServer.cs +++ b/OpenSim/Region/ClientStack/UDPServer.cs @@ -107,7 +107,7 @@ namespace OpenSim.Region.ClientStack protected virtual void CreatePacketServer() { - PacketServer packetServer = new PacketServer(this, (uint) listenPort); + PacketServer packetServer = new PacketServer(this); } protected virtual void OnReceivedData(IAsyncResult result) -- cgit v1.1 From 9b6b6d05d45cf0f754a0b26bf6240ef50be66563 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Tue, 3 Jul 2007 14:37:29 +0000 Subject: * Optimized usings (the 'LL ate my scripts' commit) * added some licensing info --- OpenSim/Region/ClientStack/UDPServer.cs | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) (limited to 'OpenSim/Region/ClientStack/UDPServer.cs') diff --git a/OpenSim/Region/ClientStack/UDPServer.cs b/OpenSim/Region/ClientStack/UDPServer.cs index 8ad5332..6eea524 100644 --- a/OpenSim/Region/ClientStack/UDPServer.cs +++ b/OpenSim/Region/ClientStack/UDPServer.cs @@ -26,26 +26,15 @@ * */ using System; -using System.Text; -using System.IO; -using System.Threading; +using System.Collections.Generic; 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.Region.Terrain; -using OpenSim.Framework.Interfaces; -using OpenSim.Framework.Types; using OpenSim.Assets; -using OpenSim.Region.Caches; -using OpenSim.Framework.Console; using OpenSim.Framework; -using Nwc.XmlRpc; -using OpenSim.Framework.Servers; +using OpenSim.Framework.Console; +using OpenSim.Framework.Interfaces; +using OpenSim.Region.Caches; namespace OpenSim.Region.ClientStack { -- cgit v1.1