aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.RegionServer/UDPServer.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/OpenSim.RegionServer/UDPServer.cs265
1 files changed, 0 insertions, 265 deletions
diff --git a/OpenSim/OpenSim.RegionServer/UDPServer.cs b/OpenSim/OpenSim.RegionServer/UDPServer.cs
deleted file mode 100644
index ae62607..0000000
--- a/OpenSim/OpenSim.RegionServer/UDPServer.cs
+++ /dev/null
@@ -1,265 +0,0 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Text;
30using System.IO;
31using System.Threading;
32using System.Net;
33using System.Net.Sockets;
34using System.Timers;
35using System.Reflection;
36using System.Collections;
37using System.Collections.Generic;
38using libsecondlife;
39using libsecondlife.Packets;
40using OpenSim.Terrain;
41
42using OpenSim.Framework.Interfaces;
43using OpenSim.Framework.Types;
44using OpenSim.Framework.Console;
45
46using OpenSim.UserServer;
47
48using OpenSim.RegionServer.Simulator;
49using OpenSim.RegionServer.Assets;
50using OpenSim.RegionServer.CAPS;
51using OpenSim.RegionServer.Client;
52
53using Nwc.XmlRpc;
54using OpenSim.Servers;
55using OpenSim.GenericConfig;
56
57namespace OpenSim.RegionServer
58{
59 public delegate AuthenticateResponse AuthenticateSessionHandler(LLUUID sessionID, LLUUID agentID, uint circuitCode);
60
61 public class UDPServer : OpenSimNetworkHandler
62 {
63 protected Dictionary<EndPoint, uint> clientCircuits = new Dictionary<EndPoint, uint>();
64 private Socket Server;
65 protected IPEndPoint ServerIncoming;
66 protected byte[] RecvBuffer = new byte[4096];
67 protected byte[] ZeroBuffer = new byte[8192];
68 protected IPEndPoint ipeSender;
69 protected EndPoint epSender;
70 protected AsyncCallback ReceivedData;
71 protected PacketServer _packetServer;
72
73 protected int listenPort;
74 protected Grid m_gridServers;
75 protected World m_localWorld;
76 protected AssetCache m_assetCache;
77 protected InventoryCache m_inventoryCache;
78 protected RegionInfo m_regionData;
79 protected bool m_sandbox = false;
80 protected bool user_accounts = false;
81 protected ConsoleBase m_console;
82 protected AuthenticateSessionsBase m_authenticateSessionsClass;
83
84 public AuthenticateSessionHandler AuthenticateHandler;
85
86 public PacketServer PacketServer
87 {
88 get
89 {
90 return _packetServer;
91 }
92 set
93 {
94 _packetServer = value;
95 }
96 }
97
98 public World LocalWorld
99 {
100 set
101 {
102 this.m_localWorld = value;
103 this._packetServer.LocalWorld = this.m_localWorld;
104 }
105 }
106
107 public UDPServer()
108 {
109 }
110
111 public UDPServer(int port, Grid gridServers, AssetCache assetCache, InventoryCache inventoryCache, RegionInfo _regionData, bool sandbox, bool accounts, ConsoleBase console, AuthenticateSessionsBase authenticateClass)
112 {
113 listenPort = port;
114 this.m_gridServers = gridServers;
115 this.m_assetCache = assetCache;
116 this.m_inventoryCache = inventoryCache;
117 this.m_regionData = _regionData;
118 this.m_sandbox = sandbox;
119 this.user_accounts = accounts;
120 this.m_console = console;
121 this.m_authenticateSessionsClass = authenticateClass;
122 this.CreatePacketServer();
123
124 //set up delegate for authenticate sessions
125 this.AuthenticateHandler = new AuthenticateSessionHandler(this.m_authenticateSessionsClass.AuthenticateSession);
126 }
127
128 protected virtual void CreatePacketServer()
129 {
130 PacketServer packetServer = new PacketServer(this);
131 }
132
133 protected virtual void OnReceivedData(IAsyncResult result)
134 {
135 ipeSender = new IPEndPoint(IPAddress.Any, 0);
136 epSender = (EndPoint)ipeSender;
137 Packet packet = null;
138
139 int numBytes;
140
141 try
142 {
143 numBytes = Server.EndReceiveFrom(result, ref epSender);
144 }
145 catch (SocketException e)
146 {
147 switch( e.SocketErrorCode )
148 {
149 case SocketError.NotConnected:
150 case SocketError.ConnectionReset:
151 // At this point, we should clear the client connection altogether.
152 // The app should hook a disconnect event into the UDPServer.
153 // But for now, just ignore it.
154 return;
155 default:
156 throw;
157 }
158 }
159
160 int packetEnd = numBytes - 1;
161
162 packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer);
163
164 // do we already have a circuit for this endpoint
165 if (this.clientCircuits.ContainsKey(epSender))
166 {
167 //if so then send packet to the packetserver
168 this._packetServer.ClientInPacket(this.clientCircuits[epSender], packet);
169 }
170 else if (packet.Type == PacketType.UseCircuitCode)
171 {
172 // new client
173 this.AddNewClient(packet);
174 }
175 else
176 { // invalid client
177 Console.Error.WriteLine("UDPServer.cs:OnReceivedData() - WARNING: Got a packet from an invalid client - " + epSender.ToString());
178 }
179
180 Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
181 }
182
183 protected virtual void AddNewClient(Packet packet)
184 {
185 UseCircuitCodePacket useCircuit = (UseCircuitCodePacket)packet;
186 this.clientCircuits.Add(epSender, useCircuit.CircuitCode.Code);
187 bool isChildAgent = false;
188
189 ClientView newuser = new ClientView(epSender, useCircuit, m_localWorld, _packetServer.ClientThreads, m_assetCache, m_gridServers.GridServer, this, m_inventoryCache, m_sandbox, isChildAgent, this.m_regionData, m_authenticateSessionsClass);
190 if ((this.m_gridServers.UserServer != null) && (user_accounts))
191 {
192 newuser.UserServer = this.m_gridServers.UserServer;
193 }
194 //OpenSimRoot.Instance.ClientThreads.Add(epSender, newuser);
195 this._packetServer.ClientThreads.Add(useCircuit.CircuitCode.Code, newuser);
196 }
197
198 public void ServerListener()
199 {
200 m_console.Notice("UDPServer.cs:ServerListener() - Opening UDP socket on " + listenPort);
201
202 ServerIncoming = new IPEndPoint(IPAddress.Any, listenPort);
203 Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
204
205 /// Add this new socket to the list of sockets that was opened by the application. When the application
206 /// closes, either gracefully or not, all sockets can be cleaned up. Right now I am not aware of any method
207 /// to get all of the sockets for a process within .NET, but if so, this process can be refactored, as
208 /// socket registration would not be neccessary.
209 SocketRegistry.Register(Server);
210
211 Server.Bind(ServerIncoming);
212
213 m_console.Notice("UDPServer.cs:ServerListener() - UDP socket bound, getting ready to listen");
214
215 ipeSender = new IPEndPoint(IPAddress.Any, 0);
216 epSender = (EndPoint)ipeSender;
217 ReceivedData = new AsyncCallback(this.OnReceivedData);
218 Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
219
220 m_console.Notice("UDPServer.cs:ServerListener() - Listening...");
221
222 }
223
224 public virtual void RegisterPacketServer(PacketServer server)
225 {
226 this._packetServer = server;
227 }
228
229 public virtual void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode)//EndPoint packetSender)
230 {
231 // find the endpoint for this circuit
232 EndPoint sendto = null;
233 foreach (KeyValuePair<EndPoint, uint> p in this.clientCircuits)
234 {
235 if (p.Value == circuitcode)
236 {
237 sendto = p.Key;
238 break;
239 }
240 }
241 if (sendto != null)
242 {
243 //we found the endpoint so send the packet to it
244 this.Server.SendTo(buffer, size, flags, sendto);
245 }
246 }
247
248 public virtual void RemoveClientCircuit(uint circuitcode)
249 {
250 foreach (KeyValuePair<EndPoint, uint> p in this.clientCircuits)
251 {
252 if (p.Value == circuitcode)
253 {
254 this.clientCircuits.Remove(p.Key);
255 break;
256 }
257 }
258 }
259
260 public virtual AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitCode)
261 {
262 return this.AuthenticateHandler(sessionID, agentID, circuitCode);
263 }
264 }
265}