From 3376b82501000692d6dac24b051af738cdaf2737 Mon Sep 17 00:00:00 2001 From: MW Date: Thu, 24 May 2007 12:16:50 +0000 Subject: Some more code refactoring, plus a restructuring of the directories so that the Grid servers can be a separate solution to the region server. --- Common-Source/OpenSim.Servers/BaseHttpServer.cs | 256 ++++++++ Common-Source/OpenSim.Servers/BaseServer.cs | 10 + Common-Source/OpenSim.Servers/CheckSumServer.cs | 113 ++++ Common-Source/OpenSim.Servers/IRestHandler.cs | 8 + .../OpenSim.Servers/LocalUserProfileManager.cs | 123 ++++ Common-Source/OpenSim.Servers/LoginResponse.cs | 670 +++++++++++++++++++++ Common-Source/OpenSim.Servers/LoginServer.cs | 284 +++++++++ .../OpenSim.Servers/OpenSim.Servers.csproj | 130 ++++ .../OpenSim.Servers/OpenSim.Servers.csproj.user | 12 + .../OpenSim.Servers/OpenSim.Servers.dll.build | 52 ++ Common-Source/OpenSim.Servers/UDPServerBase.cs | 68 +++ Common-Source/OpenSim.Servers/XmlRpcMethod.cs | 7 + 12 files changed, 1733 insertions(+) create mode 100644 Common-Source/OpenSim.Servers/BaseHttpServer.cs create mode 100644 Common-Source/OpenSim.Servers/BaseServer.cs create mode 100644 Common-Source/OpenSim.Servers/CheckSumServer.cs create mode 100644 Common-Source/OpenSim.Servers/IRestHandler.cs create mode 100644 Common-Source/OpenSim.Servers/LocalUserProfileManager.cs create mode 100644 Common-Source/OpenSim.Servers/LoginResponse.cs create mode 100644 Common-Source/OpenSim.Servers/LoginServer.cs create mode 100644 Common-Source/OpenSim.Servers/OpenSim.Servers.csproj create mode 100644 Common-Source/OpenSim.Servers/OpenSim.Servers.csproj.user create mode 100644 Common-Source/OpenSim.Servers/OpenSim.Servers.dll.build create mode 100644 Common-Source/OpenSim.Servers/UDPServerBase.cs create mode 100644 Common-Source/OpenSim.Servers/XmlRpcMethod.cs (limited to 'Common-Source/OpenSim.Servers') diff --git a/Common-Source/OpenSim.Servers/BaseHttpServer.cs b/Common-Source/OpenSim.Servers/BaseHttpServer.cs new file mode 100644 index 0000000..38f4370 --- /dev/null +++ b/Common-Source/OpenSim.Servers/BaseHttpServer.cs @@ -0,0 +1,256 @@ +using System; +using System.Collections.Generic; +using System.Net; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +//using OpenSim.CAPS; +using Nwc.XmlRpc; +using System.Collections; +using OpenSim.Framework.Console; + +namespace OpenSim.Servers +{ + public class BaseHttpServer + { + protected class RestMethodEntry + { + private string m_path; + public string Path + { + get { return m_path; } + } + + private RestMethod m_restMethod; + public RestMethod RestMethod + { + get { return m_restMethod; } + } + + public RestMethodEntry(string path, RestMethod restMethod) + { + m_path = path; + m_restMethod = restMethod; + } + } + + protected Thread m_workerThread; + protected HttpListener m_httpListener; + protected Dictionary m_restHandlers = new Dictionary(); + protected Dictionary m_rpcHandlers = new Dictionary(); + protected int m_port; + + public BaseHttpServer(int port) + { + m_port = port; + } + + public bool AddRestHandler(string method, string path, RestMethod handler) + { + string methodKey = String.Format("{0}: {1}", method, path); + + if (!this.m_restHandlers.ContainsKey(methodKey)) + { + this.m_restHandlers.Add(methodKey, new RestMethodEntry(path, handler)); + return true; + } + + //must already have a handler for that path so return false + return false; + } + + public bool AddXmlRPCHandler(string method, XmlRpcMethod handler) + { + if (!this.m_rpcHandlers.ContainsKey(method)) + { + this.m_rpcHandlers.Add(method, handler); + return true; + } + + //must already have a handler for that path so return false + return false; + } + + protected virtual string ProcessXMLRPCMethod(string methodName, XmlRpcRequest request) + { + XmlRpcResponse response; + + XmlRpcMethod method; + if (this.m_rpcHandlers.TryGetValue(methodName, out method)) + { + response = method(request); + } + else + { + response = new XmlRpcResponse(); + Hashtable unknownMethodError = new Hashtable(); + unknownMethodError["reason"] = "XmlRequest"; ; + unknownMethodError["message"] = "Unknown Rpc request"; + unknownMethodError["login"] = "false"; + response.Value = unknownMethodError; + } + + return XmlRpcResponseSerializer.Singleton.Serialize(response); + } + + protected virtual string ParseREST(string request, string path, string method) + { + string response; + + string requestKey = String.Format("{0}: {1}", method, path); + + string bestMatch = String.Empty; + foreach (string currentKey in m_restHandlers.Keys) + { + if (requestKey.StartsWith(currentKey)) + { + if (currentKey.Length > bestMatch.Length) + { + bestMatch = currentKey; + } + } + } + + RestMethodEntry restMethodEntry; + if (m_restHandlers.TryGetValue(bestMatch, out restMethodEntry)) + { + RestMethod restMethod = restMethodEntry.RestMethod; + + string param = path.Substring(restMethodEntry.Path.Length); + response = restMethod(request, path, param); + + } + else + { + response = String.Empty; + } + + return response; + } + + protected virtual string ParseLLSDXML(string requestBody) + { + // dummy function for now - IMPLEMENT ME! + return ""; + } + + protected virtual string ParseXMLRPC(string requestBody) + { + string responseString = String.Empty; + + try + { + XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody); + + string methodName = request.MethodName; + + responseString = ProcessXMLRPCMethod(methodName, request); + } + catch (Exception e) + { + Console.WriteLine(e.ToString()); + } + return responseString; + } + + public virtual void HandleRequest(Object stateinfo) + { + try + { + HttpListenerContext context = (HttpListenerContext)stateinfo; + + HttpListenerRequest request = context.Request; + HttpListenerResponse response = context.Response; + + response.KeepAlive = false; + response.SendChunked = false; + + System.IO.Stream body = request.InputStream; + System.Text.Encoding encoding = System.Text.Encoding.UTF8; + System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding); + + string requestBody = reader.ReadToEnd(); + body.Close(); + reader.Close(); + + //Console.WriteLine(request.HttpMethod + " " + request.RawUrl + " Http/" + request.ProtocolVersion.ToString() + " content type: " + request.ContentType); + //Console.WriteLine(requestBody); + + string responseString = ""; + switch (request.ContentType) + { + case "text/xml": + // must be XML-RPC, so pass to the XML-RPC parser + + responseString = ParseXMLRPC(requestBody); + responseString = Regex.Replace(responseString, "utf-16", "utf-8"); + + response.AddHeader("Content-type", "text/xml"); + break; + + case "application/xml": + // probably LLSD we hope, otherwise it should be ignored by the parser + responseString = ParseLLSDXML(requestBody); + response.AddHeader("Content-type", "application/xml"); + break; + + case "application/x-www-form-urlencoded": + // a form data POST so send to the REST parser + responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); + response.AddHeader("Content-type", "text/html"); + break; + + case null: + // must be REST or invalid crap, so pass to the REST parser + responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); + response.AddHeader("Content-type", "text/html"); + break; + + } + + byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); + System.IO.Stream output = response.OutputStream; + response.SendChunked = false; + response.ContentLength64 = buffer.Length; + output.Write(buffer, 0, buffer.Length); + output.Close(); + } + catch (Exception e) + { + Console.WriteLine(e.ToString()); + } + } + + public void Start() + { + OpenSim.Framework.Console.MainConsole.Instance.WriteLine(LogPriority.LOW, "BaseHttpServer.cs: Starting up HTTP Server"); + + m_workerThread = new Thread(new ThreadStart(StartHTTP)); + m_workerThread.IsBackground = true; + m_workerThread.Start(); + } + + private void StartHTTP() + { + try + { + OpenSim.Framework.Console.MainConsole.Instance.WriteLine(LogPriority.LOW, "BaseHttpServer.cs: StartHTTP() - Spawned main thread OK"); + m_httpListener = new HttpListener(); + + m_httpListener.Prefixes.Add("http://+:" + m_port + "/"); + m_httpListener.Start(); + + HttpListenerContext context; + while (true) + { + context = m_httpListener.GetContext(); + ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), context); + } + } + catch (Exception e) + { + OpenSim.Framework.Console.MainConsole.Instance.WriteLine(LogPriority.MEDIUM, e.Message); + } + } + } +} diff --git a/Common-Source/OpenSim.Servers/BaseServer.cs b/Common-Source/OpenSim.Servers/BaseServer.cs new file mode 100644 index 0000000..0a4c498 --- /dev/null +++ b/Common-Source/OpenSim.Servers/BaseServer.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Servers +{ + public class BaseServer + { + } +} 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 @@ +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) + : base(port) + { + } + + 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); + + 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 = 0; + checkreply.TokenBlock.Token = checksum.TokenBlock.Token; + this.SendPacket(checkreply, epSender); + + /* + //if we wanted to echo the the checksum/ version from the client (so that any client worked) + SecuredTemplateChecksumRequestPacket checkrequest = new SecuredTemplateChecksumRequestPacket(); + checkrequest.TokenBlock.Token = checksum.TokenBlock.Token; + this.SendPacket(checkrequest, epSender); + */ + } + else if (packet.Type == PacketType.TemplateChecksumReply) + { + //echo back the client checksum reply (Hegemon's method) + TemplateChecksumReplyPacket checksum2 = (TemplateChecksumReplyPacket)packet; + TemplateChecksumReplyPacket checkreply2 = new TemplateChecksumReplyPacket(); + checkreply2.DataBlock.Checksum = checksum2.DataBlock.Checksum; + checkreply2.DataBlock.Flags = checksum2.DataBlock.Flags; + checkreply2.DataBlock.MajorVersion = checksum2.DataBlock.MajorVersion; + checkreply2.DataBlock.MinorVersion = checksum2.DataBlock.MinorVersion; + checkreply2.DataBlock.PatchVersion = checksum2.DataBlock.PatchVersion; + checkreply2.DataBlock.ServerVersion = checksum2.DataBlock.ServerVersion; + checkreply2.TokenBlock.Token = checksum2.TokenBlock.Token; + this.SendPacket(checkreply2, epSender); + } + else + { + } + + Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); + } + + private void SendPacket(Packet Pack, EndPoint endp) + { + if (!Pack.Header.Resent) + { + 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/Common-Source/OpenSim.Servers/IRestHandler.cs b/Common-Source/OpenSim.Servers/IRestHandler.cs new file mode 100644 index 0000000..c322505 --- /dev/null +++ b/Common-Source/OpenSim.Servers/IRestHandler.cs @@ -0,0 +1,8 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Servers +{ + public delegate string RestMethod( string request, string path, string param ); +} diff --git a/Common-Source/OpenSim.Servers/LocalUserProfileManager.cs b/Common-Source/OpenSim.Servers/LocalUserProfileManager.cs new file mode 100644 index 0000000..a8b5f1f --- /dev/null +++ b/Common-Source/OpenSim.Servers/LocalUserProfileManager.cs @@ -0,0 +1,123 @@ +/* +* Copyright (c) OpenSim project, http://sim.opensecondlife.org/ +* +* 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 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 ``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 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.Collections.Generic; +using System.Collections; +using System.Text; +using OpenSim.Framework.User; +using OpenSim.Framework.Grid; +using OpenSim.Framework.Inventory; +using OpenSim.Framework.Interfaces; +using OpenSim.Framework.Types; +using libsecondlife; + +namespace OpenSim.UserServer +{ + public class LocalUserProfileManager : UserProfileManager + { + private IGridServer m_gridServer; + private int m_port; + private string m_ipAddr; + private uint regionX; + private uint regionY; + private AddNewSessionHandler AddSession; + + public LocalUserProfileManager(IGridServer gridServer, int simPort, string ipAddr , uint regX, uint regY) + { + m_gridServer = gridServer; + m_port = simPort; + m_ipAddr = ipAddr; + regionX = regX; + regionY = regY; + } + + public void SetSessionHandler(AddNewSessionHandler sessionHandler) + { + this.AddSession = sessionHandler; + } + + public override void InitUserProfiles() + { + // TODO: need to load from database + } + + public override void CustomiseResponse(ref System.Collections.Hashtable response, UserProfile theUser) + { + Int32 circode = (Int32)response["circuit_code"]; + theUser.AddSimCircuit((uint)circode, LLUUID.Random()); + response["home"] = "{'region_handle':[r" + (997 * 256).ToString() + ",r" + (996 * 256).ToString() + "], 'position':[r" + theUser.homepos.X.ToString() + ",r" + theUser.homepos.Y.ToString() + ",r" + theUser.homepos.Z.ToString() + "], 'look_at':[r" + theUser.homelookat.X.ToString() + ",r" + theUser.homelookat.Y.ToString() + ",r" + theUser.homelookat.Z.ToString() + "]}"; + response["sim_port"] = m_port; + response["sim_ip"] = m_ipAddr; + response["region_y"] = (Int32)regionY* 256; + response["region_x"] = (Int32)regionX* 256; + + string first; + string last; + if (response.Contains("first_name")) + { + first = (string)response["first_name"]; + } + else + { + first = "test"; + } + + if (response.Contains("last_name")) + { + last = (string)response["last_name"]; + } + else + { + last = "User"; + } + + ArrayList InventoryList = (ArrayList)response["inventory-skeleton"]; + Hashtable Inventory1 = (Hashtable)InventoryList[0]; + + Login _login = new Login(); + //copy data to login object + _login.First = first; + _login.Last = last; + _login.Agent = new LLUUID((string)response["agent_id"]) ; + _login.Session = new LLUUID((string)response["session_id"]); + _login.SecureSession = new LLUUID((string)response["secure_session_id"]); + _login.CircuitCode =(uint) circode; + _login.BaseFolder = null; + _login.InventoryFolder = new LLUUID((string)Inventory1["folder_id"]); + + //working on local computer if so lets add to the gridserver's list of sessions? + /*if (m_gridServer.GetName() == "Local") + { + Console.WriteLine("adding login data to gridserver"); + ((LocalGridBase)this.m_gridServer).AddNewSession(_login); + }*/ + + this.AddSession(_login); + } + } +} diff --git a/Common-Source/OpenSim.Servers/LoginResponse.cs b/Common-Source/OpenSim.Servers/LoginResponse.cs new file mode 100644 index 0000000..7333d1f --- /dev/null +++ b/Common-Source/OpenSim.Servers/LoginResponse.cs @@ -0,0 +1,670 @@ +/* +* Copyright (c) OpenSim project, http://sim.opensecondlife.org/ +* +* 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 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 ``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 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 Nwc.XmlRpc; +using System; +using System.IO; +using System.Net; +using System.Net.Sockets; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Collections; +using System.Security.Cryptography; +using System.Xml; +using libsecondlife; +using OpenSim; +using OpenSim.Framework.User; +using OpenSim.Framework.Inventory; +using OpenSim.Framework.Utilities; +using OpenSim.Framework.Interfaces; + +// ? +using OpenSim.Framework.Grid; + +namespace OpenSim.UserServer +{ + /// + /// A temp class to handle login response. + /// Should make use of UserProfileManager where possible. + /// + + public class LoginResponse + { + private Hashtable loginFlagsHash; + private Hashtable globalTexturesHash; + private Hashtable loginError; + private Hashtable eventCategoriesHash; + private Hashtable uiConfigHash; + private Hashtable classifiedCategoriesHash; + + private ArrayList loginFlags; + private ArrayList globalTextures; + private ArrayList eventCategories; + private ArrayList uiConfig; + private ArrayList classifiedCategories; + private ArrayList inventoryRoot; + private ArrayList initialOutfit; + private ArrayList agentInventory; + + private UserProfile userProfile; + + private LLUUID agentID; + private LLUUID sessionID; + private LLUUID secureSessionID; + private LLUUID baseFolderID; + private LLUUID inventoryFolderID; + + // Login Flags + private string dst; + private string stipendSinceLogin; + private string gendered; + private string everLoggedIn; + private string login; + private string simPort; + private string simAddress; + private string agentAccess; + private Int32 circuitCode; + private uint regionX; + private uint regionY; + + // Login + private string firstname; + private string lastname; + + // Global Textures + private string sunTexture; + private string cloudTexture; + private string moonTexture; + + // Error Flags + private string errorReason; + private string errorMessage; + + // Response + private XmlRpcResponse xmlRpcResponse; + private XmlRpcResponse defaultXmlRpcResponse; + + private string welcomeMessage; + private string startLocation; + private string allowFirstLife; + private string home; + private string seedCapability; + private string lookAt; + + public LoginResponse() + { + this.loginFlags = new ArrayList(); + this.globalTextures = new ArrayList(); + this.eventCategories = new ArrayList(); + this.uiConfig = new ArrayList(); + this.classifiedCategories = new ArrayList(); + + this.loginError = new Hashtable(); + this.eventCategoriesHash = new Hashtable(); + this.classifiedCategoriesHash = new Hashtable(); + this.uiConfigHash = new Hashtable(); + + this.defaultXmlRpcResponse = new XmlRpcResponse(); + this.userProfile = new UserProfile(); + this.inventoryRoot = new ArrayList(); + this.initialOutfit = new ArrayList(); + this.agentInventory = new ArrayList(); + + this.xmlRpcResponse = new XmlRpcResponse(); + this.defaultXmlRpcResponse = new XmlRpcResponse(); + + this.SetDefaultValues(); + } // LoginServer + + public void SetDefaultValues() + { + try + { + this.DST = "N"; + this.StipendSinceLogin = "N"; + this.Gendered = "Y"; + this.EverLoggedIn = "Y"; + this.login = "false"; + this.firstname = "Test"; + this.lastname = "User"; + this.agentAccess = "M"; + this.startLocation = "last"; + this.allowFirstLife = "Y"; + + this.SunTexture = "cce0f112-878f-4586-a2e2-a8f104bba271"; + this.CloudTexture = "fc4b9f0b-d008-45c6-96a4-01dd947ac621"; + this.MoonTexture = "fc4b9f0b-d008-45c6-96a4-01dd947ac621"; + + this.ErrorMessage = "You have entered an invalid name/password combination. Check Caps/lock."; + this.ErrorReason = "key"; + this.welcomeMessage = "Welcome to OpenSim!"; + this.seedCapability = ""; + this.home = "{'region_handle':[r" + (997 * 256).ToString() + ",r" + (996 * 256).ToString() + "], 'position':[r" + this.userProfile.homepos.X.ToString() + ",r" + this.userProfile.homepos.Y.ToString() + ",r" + this.userProfile.homepos.Z.ToString() + "], 'look_at':[r" + this.userProfile.homelookat.X.ToString() + ",r" + this.userProfile.homelookat.Y.ToString() + ",r" + this.userProfile.homelookat.Z.ToString() + "]}"; + this.lookAt = "[r0.99949799999999999756,r0.03166859999999999814,r0]"; + this.RegionX = (uint)255232; + this.RegionY = (uint)254976; + + // Classifieds; + this.AddClassifiedCategory((Int32)1, "Shopping"); + this.AddClassifiedCategory((Int32)2, "Land Rental"); + this.AddClassifiedCategory((Int32)3, "Property Rental"); + this.AddClassifiedCategory((Int32)4, "Special Attraction"); + this.AddClassifiedCategory((Int32)5, "New Products"); + this.AddClassifiedCategory((Int32)6, "Employment"); + this.AddClassifiedCategory((Int32)7, "Wanted"); + this.AddClassifiedCategory((Int32)8, "Service"); + this.AddClassifiedCategory((Int32)9, "Personal"); + + int SessionRand = Util.RandomClass.Next(1, 999); + this.SessionID = new LLUUID("aaaabbbb-0200-" + SessionRand.ToString("0000") + "-8664-58f53e442797"); + this.SecureSessionID = LLUUID.Random(); + + this.userProfile.Inventory.CreateRootFolder(this.userProfile.UUID, true); + this.baseFolderID = this.userProfile.Inventory.GetFolderID("Textures"); + this.inventoryFolderID = this.userProfile.Inventory.GetFolderID("My Inventory-"); + Hashtable InventoryRootHash = new Hashtable(); + InventoryRootHash["folder_id"] = this.userProfile.Inventory.InventoryRoot.FolderID.ToStringHyphenated(); + this.inventoryRoot.Add(InventoryRootHash); + + Hashtable TempHash; + foreach (InventoryFolder InvFolder in this.userProfile.Inventory.InventoryFolders.Values) + { + TempHash = new Hashtable(); + TempHash["name"] = InvFolder.FolderName; + TempHash["parent_id"] = InvFolder.ParentID.ToStringHyphenated(); + TempHash["version"] = (Int32)InvFolder.Version; + TempHash["type_default"] = (Int32)InvFolder.DefaultType; + TempHash["folder_id"] = InvFolder.FolderID.ToStringHyphenated(); + this.agentInventory.Add(TempHash); + } + + Hashtable InitialOutfitHash = new Hashtable(); + InitialOutfitHash["folder_name"] = "Nightclub Female"; + InitialOutfitHash["gender"] = "female"; + this.initialOutfit.Add(InitialOutfitHash); + } + catch (Exception e) + { + OpenSim.Framework.Console.MainConsole.Instance.WriteLine( + OpenSim.Framework.Console.LogPriority.LOW, + "LoginResponse: Unable to set default values: " + e.Message + ); + } + + } // SetDefaultValues + + protected virtual LLUUID GetAgentId() + { + // todo + LLUUID Agent; + int AgentRand = Util.RandomClass.Next(1, 9999); + Agent = new LLUUID("99998888-0100-" + AgentRand.ToString("0000") + "-8ec1-0b1d5cd6aead"); + return Agent; + } // GetAgentId + + private XmlRpcResponse GenerateFailureResponse(string reason, string message, string login) + { + // Overwrite any default values; + this.xmlRpcResponse = new XmlRpcResponse(); + + // Ensure Login Failed message/reason; + this.ErrorMessage = message; + this.ErrorReason = reason; + + this.loginError["reason"] = this.ErrorReason; + this.loginError["message"] = this.ErrorMessage; + this.loginError["login"] = login; + this.xmlRpcResponse.Value = this.loginError; + return (this.xmlRpcResponse); + } // GenerateResponse + + public XmlRpcResponse LoginFailedResponse() + { + return (this.GenerateFailureResponse("key", "You have entered an invalid name/password combination. Check Caps/lock.", "false")); + } // LoginFailedResponse + + public XmlRpcResponse ConnectionFailedResponse() + { + return (this.LoginFailedResponse()); + } // CreateErrorConnectingToGridResponse() + + public XmlRpcResponse CreateAlreadyLoggedInResponse() + { + return (this.GenerateFailureResponse("presence", "You appear to be already logged in, if this is not the case please wait for your session to timeout, if this takes longer than a few minutes please contact the grid owner", "false")); + } // CreateAlreadyLoggedInResponse() + + public XmlRpcResponse ToXmlRpcResponse() + { + try + { + + Hashtable responseData = new Hashtable(); + + this.loginFlagsHash = new Hashtable(); + this.loginFlagsHash["daylight_savings"] = this.DST; + this.loginFlagsHash["stipend_since_login"] = this.StipendSinceLogin; + this.loginFlagsHash["gendered"] = this.Gendered; + this.loginFlagsHash["ever_logged_in"] = this.EverLoggedIn; + this.loginFlags.Add(this.loginFlagsHash); + + responseData["first_name"] = this.Firstname; + responseData["last_name"] = this.Lastname; + responseData["agent_access"] = this.agentAccess; + + this.globalTexturesHash = new Hashtable(); + this.globalTexturesHash["sun_texture_id"] = this.SunTexture; + this.globalTexturesHash["cloud_texture_id"] = this.CloudTexture; + this.globalTexturesHash["moon_texture_id"] = this.MoonTexture; + this.globalTextures.Add(this.globalTexturesHash); + this.eventCategories.Add(this.eventCategoriesHash); + + this.AddToUIConfig("allow_first_life", this.allowFirstLife); + this.uiConfig.Add(this.uiConfigHash); + + // Create a agent and session LLUUID + this.agentID = this.GetAgentId(); + + responseData["sim_port"] = this.SimPort; + responseData["sim_ip"] = this.SimAddress; + responseData["agent_id"] = this.AgentID.ToStringHyphenated(); + responseData["session_id"] = this.SessionID.ToStringHyphenated(); + responseData["secure_session_id"] = this.SecureSessionID.ToStringHyphenated(); + responseData["circuit_code"] = this.CircuitCode; + responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; + responseData["login-flags"] = this.loginFlags; + responseData["global-textures"] = this.globalTextures; + responseData["seed_capability"] = this.seedCapability; + + responseData["event_categories"] = this.eventCategories; + responseData["event_notifications"] = new ArrayList(); // todo + responseData["classified_categories"] = this.classifiedCategories; + responseData["ui-config"] = this.uiConfig; + + responseData["inventory-skeleton"] = this.agentInventory; + responseData["inventory-skel-lib"] = new ArrayList(); // todo + responseData["inventory-root"] = this.inventoryRoot; + responseData["gestures"] = new ArrayList(); // todo + responseData["inventory-lib-owner"] = new ArrayList(); // todo + responseData["initial-outfit"] = this.initialOutfit; + responseData["start_location"] = this.startLocation; + responseData["seed_capability"] = this.seedCapability; + responseData["home"] = this.home; + responseData["look_at"] = this.lookAt; + responseData["message"] = this.welcomeMessage; + responseData["region_x"] = (Int32)this.RegionX * 256; + responseData["region_y"] = (Int32)this.RegionY * 256; + + responseData["login"] = "true"; + this.xmlRpcResponse.Value = responseData; + + return (this.xmlRpcResponse); + } + catch (Exception e) + { + OpenSim.Framework.Console.MainConsole.Instance.WriteLine( + OpenSim.Framework.Console.LogPriority.LOW, + "LoginResponse: Error creating XML-RPC Response: " + e.Message + ); + return (this.GenerateFailureResponse("Internal Error", "Error generating Login Response", "false")); + + } + + } // ToXmlRpcResponse + + public void SetEventCategories(string category, string value) + { + this.eventCategoriesHash[category] = value; + } // SetEventCategories + + public void AddToUIConfig(string itemName, string item) + { + this.uiConfigHash[itemName] = item; + } // SetUIConfig + + public void AddClassifiedCategory(Int32 ID, string categoryName) + { + this.classifiedCategoriesHash["category_name"] = categoryName; + this.classifiedCategoriesHash["category_id"] = ID; + this.classifiedCategories.Add(this.classifiedCategoriesHash); + // this.classifiedCategoriesHash.Clear(); + } // SetClassifiedCategory + + public string Login + { + get + { + return this.login; + } + set + { + this.login = value; + } + } // Login + + public string DST + { + get + { + return this.dst; + } + set + { + this.dst = value; + } + } // DST + + public string StipendSinceLogin + { + get + { + return this.stipendSinceLogin; + } + set + { + this.stipendSinceLogin = value; + } + } // StipendSinceLogin + + public string Gendered + { + get + { + return this.gendered; + } + set + { + this.gendered = value; + } + } // Gendered + + public string EverLoggedIn + { + get + { + return this.everLoggedIn; + } + set + { + this.everLoggedIn = value; + } + } // EverLoggedIn + + public string SimPort + { + get + { + return this.simPort; + } + set + { + this.simPort = value; + } + } // SimPort + + public string SimAddress + { + get + { + return this.simAddress; + } + set + { + this.simAddress = value; + } + } // SimAddress + + public LLUUID AgentID + { + get + { + return this.agentID; + } + set + { + this.agentID = value; + } + } // AgentID + + public LLUUID SessionID + { + get + { + return this.sessionID; + } + set + { + this.sessionID = value; + } + } // SessionID + + public LLUUID SecureSessionID + { + get + { + return this.secureSessionID; + } + set + { + this.secureSessionID = value; + } + } // SecureSessionID + + public LLUUID BaseFolderID + { + get + { + return this.baseFolderID; + } + set + { + this.baseFolderID = value; + } + } // BaseFolderID + + public LLUUID InventoryFolderID + { + get + { + return this.inventoryFolderID; + } + set + { + this.inventoryFolderID = value; + } + } // InventoryFolderID + + public Int32 CircuitCode + { + get + { + return this.circuitCode; + } + set + { + this.circuitCode = value; + } + } // CircuitCode + + public uint RegionX + { + get + { + return this.regionX; + } + set + { + this.regionX = value; + } + } // RegionX + + public uint RegionY + { + get + { + return this.regionY; + } + set + { + this.regionY = value; + } + } // RegionY + + public string SunTexture + { + get + { + return this.sunTexture; + } + set + { + this.sunTexture = value; + } + } // SunTexture + + public string CloudTexture + { + get + { + return this.cloudTexture; + } + set + { + this.cloudTexture = value; + } + } // CloudTexture + + public string MoonTexture + { + get + { + return this.moonTexture; + } + set + { + this.moonTexture = value; + } + } // MoonTexture + + public string Firstname + { + get + { + return this.firstname; + } + set + { + this.firstname = value; + } + } // Firstname + + public string Lastname + { + get + { + return this.lastname; + } + set + { + this.lastname = value; + } + } // Lastname + + public string AgentAccess + { + get + { + return this.agentAccess; + } + set + { + this.agentAccess = value; + } + } + + public string StartLocation + { + get + { + return this.startLocation; + } + set + { + this.startLocation = value; + } + } // StartLocation + + public string LookAt + { + get + { + return this.lookAt; + } + set + { + this.lookAt = value; + } + } + + public string SeedCapability + { + get + { + return this.seedCapability; + } + set + { + this.seedCapability = value; + } + } // SeedCapability + + public string ErrorReason + { + get + { + return this.errorReason; + } + set + { + this.errorReason = value; + } + } // ErrorReason + + public string ErrorMessage + { + get + { + return this.errorMessage; + } + set + { + this.errorMessage = value; + } + } // ErrorMessage + + } // LoginResponse +} // namespace OpenSim.UserServer \ No newline at end of file diff --git a/Common-Source/OpenSim.Servers/LoginServer.cs b/Common-Source/OpenSim.Servers/LoginServer.cs new file mode 100644 index 0000000..6fd174b --- /dev/null +++ b/Common-Source/OpenSim.Servers/LoginServer.cs @@ -0,0 +1,284 @@ +/* +* Copyright (c) OpenSim project, http://sim.opensecondlife.org/ +* +* 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 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 ``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 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 Nwc.XmlRpc; +using System; +using System.IO; +using System.Net; +using System.Net.Sockets; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Collections; +using System.Security.Cryptography; +using System.Xml; +using libsecondlife; +using OpenSim; +using OpenSim.Framework.Interfaces; +using OpenSim.Framework.Grid; +using OpenSim.Framework.Inventory; +using OpenSim.Framework.User; +using OpenSim.Framework.Utilities; +using OpenSim.Framework.Types; + +namespace OpenSim.UserServer +{ + public delegate void AddNewSessionHandler(Login loginData); + /// + /// When running in local (default) mode , handles client logins. + /// + public class LoginServer : LoginService, IUserServer + { + private IGridServer m_gridServer; + public IPAddress clientAddress = IPAddress.Loopback; + public IPAddress remoteAddress = IPAddress.Any; + private int NumClients; + private bool userAccounts = false; + private string _mpasswd; + private bool _needPasswd = false; + private LocalUserProfileManager userManager; + private int m_simPort; + private string m_simAddr; + private uint regionX; + private uint regionY; + private AddNewSessionHandler AddSession; + + public LocalUserProfileManager LocalUserManager + { + get + { + return userManager; + } + } + + public LoginServer( string simAddr, int simPort, uint regX, uint regY, bool useAccounts) + { + m_simPort = simPort; + m_simAddr = simAddr; + regionX = regX; + regionY = regY; + this.userAccounts = useAccounts; + } + + public void SetSessionHandler(AddNewSessionHandler sessionHandler) + { + this.AddSession = sessionHandler; + this.userManager.SetSessionHandler(sessionHandler); + } + + public void Startup() + { + this._needPasswd = false; + + this._mpasswd = EncodePassword("testpass"); + + userManager = new LocalUserProfileManager(this.m_gridServer, m_simPort, m_simAddr, regionX, regionY); + //userManager.InitUserProfiles(); + userManager.SetKeys("", "", "", "Welcome to OpenSim"); + } + + public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request) + { + Console.WriteLine("login attempt"); + Hashtable requestData = (Hashtable)request.Params[0]; + string first; + string last; + string passwd; + + LoginResponse loginResponse = new LoginResponse(); + loginResponse.RegionX = regionX; + loginResponse.RegionY = regionY; + + //get login name + if (requestData.Contains("first")) + { + first = (string)requestData["first"]; + } + else + { + first = "test"; + } + + if (requestData.Contains("last")) + { + last = (string)requestData["last"]; + } + else + { + last = "User" + NumClients.ToString(); + } + + if (requestData.Contains("passwd")) + { + passwd = (string)requestData["passwd"]; + } + else + { + passwd = "notfound"; + } + + if (!Authenticate(first, last, passwd)) + { + return loginResponse.LoginFailedResponse(); + } + + NumClients++; + + // Create a agent and session LLUUID + // Agent = GetAgentId(first, last); + // int SessionRand = Util.RandomClass.Next(1, 999); + // Session = new LLUUID("aaaabbbb-0200-" + SessionRand.ToString("0000") + "-8664-58f53e442797"); + // LLUUID secureSess = LLUUID.Random(); + + loginResponse.SimPort = m_simPort.ToString(); + loginResponse.SimAddress = m_simAddr.ToString(); + // loginResponse.AgentID = Agent.ToStringHyphenated(); + // loginResponse.SessionID = Session.ToStringHyphenated(); + // loginResponse.SecureSessionID = secureSess.ToStringHyphenated(); + loginResponse.CircuitCode = (Int32)(Util.RandomClass.Next()); + XmlRpcResponse response = loginResponse.ToXmlRpcResponse(); + Hashtable responseData = (Hashtable)response.Value; + + //inventory + /* ArrayList InventoryList = (ArrayList)responseData["inventory-skeleton"]; + Hashtable Inventory1 = (Hashtable)InventoryList[0]; + Hashtable Inventory2 = (Hashtable)InventoryList[1]; + LLUUID BaseFolderID = LLUUID.Random(); + LLUUID InventoryFolderID = LLUUID.Random(); + Inventory2["name"] = "Textures"; + Inventory2["folder_id"] = BaseFolderID.ToStringHyphenated(); + Inventory2["type_default"] = 0; + Inventory1["folder_id"] = InventoryFolderID.ToStringHyphenated(); + + ArrayList InventoryRoot = (ArrayList)responseData["inventory-root"]; + Hashtable Inventoryroot = (Hashtable)InventoryRoot[0]; + Inventoryroot["folder_id"] = InventoryFolderID.ToStringHyphenated(); + */ + CustomiseLoginResponse(responseData, first, last); + + Login _login = new Login(); + //copy data to login object + _login.First = first; + _login.Last = last; + _login.Agent = loginResponse.AgentID; + _login.Session = loginResponse.SessionID; + _login.SecureSession = loginResponse.SecureSessionID; + _login.CircuitCode = (uint) loginResponse.CircuitCode; + _login.BaseFolder = loginResponse.BaseFolderID; + _login.InventoryFolder = loginResponse.InventoryFolderID; + + //working on local computer if so lets add to the gridserver's list of sessions? + /* if (m_gridServer.GetName() == "Local") + { + ((LocalGridBase)m_gridServer).AddNewSession(_login); + }*/ + AddSession(_login); + + return response; + } + + protected virtual void CustomiseLoginResponse(Hashtable responseData, string first, string last) + { + } + + protected virtual LLUUID GetAgentId(string firstName, string lastName) + { + LLUUID Agent; + int AgentRand = Util.RandomClass.Next(1, 9999); + Agent = new LLUUID("99998888-0100-" + AgentRand.ToString("0000") + "-8ec1-0b1d5cd6aead"); + return Agent; + } + + protected virtual bool Authenticate(string first, string last, string passwd) + { + if (this._needPasswd) + { + //every user needs the password to login + string encodedPass = passwd.Remove(0, 3); //remove $1$ + if (encodedPass == this._mpasswd) + { + return true; + } + else + { + return false; + } + } + else + { + //do not need password to login + return true; + } + } + + private static string EncodePassword(string passwd) + { + Byte[] originalBytes; + Byte[] encodedBytes; + MD5 md5; + + md5 = new MD5CryptoServiceProvider(); + originalBytes = ASCIIEncoding.Default.GetBytes(passwd); + encodedBytes = md5.ComputeHash(originalBytes); + + return Regex.Replace(BitConverter.ToString(encodedBytes), "-", "").ToLower(); + } + + public bool CreateUserAccount(string firstName, string lastName, string password) + { + Console.WriteLine("creating new user account"); + string mdPassword = EncodePassword(password); + Console.WriteLine("with password: " + mdPassword); + this.userManager.CreateNewProfile(firstName, lastName, mdPassword); + return true; + } + + //IUserServer implementation + public AgentInventory RequestAgentsInventory(LLUUID agentID) + { + AgentInventory aInventory = null; + if (this.userAccounts) + { + aInventory = this.userManager.GetUsersInventory(agentID); + } + + return aInventory; + } + + public bool UpdateAgentsInventory(LLUUID agentID, AgentInventory inventory) + { + return true; + } + + public void SetServerInfo(string ServerUrl, string SendKey, string RecvKey) + { + + } + } + + +} diff --git a/Common-Source/OpenSim.Servers/OpenSim.Servers.csproj b/Common-Source/OpenSim.Servers/OpenSim.Servers.csproj new file mode 100644 index 0000000..72f637b --- /dev/null +++ b/Common-Source/OpenSim.Servers/OpenSim.Servers.csproj @@ -0,0 +1,130 @@ + + + Local + 8.0.50727 + 2.0 + {8BB20F0A-0000-0000-0000-000000000000} + Debug + AnyCPU + + + + OpenSim.Servers + JScript + Grid + IE50 + false + Library + + OpenSim.Servers + + + + + + False + 285212672 + False + + + TRACE;DEBUG + + True + 4096 + False + ..\bin\ + False + False + False + 4 + + + + False + 285212672 + False + + + TRACE + + False + 4096 + True + ..\bin\ + False + False + False + 4 + + + + + System.dll + False + + + System.Xml.dll + False + + + ..\bin\libsecondlife.dll + False + + + + + OpenSim.Framework + {8ACA2445-0000-0000-0000-000000000000} + {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + False + + + OpenSim.Framework.Console + {A7CD0630-0000-0000-0000-000000000000} + {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + False + + + XMLRPC + {8E81D43C-0000-0000-0000-000000000000} + {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + False + + + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + + + + + + + diff --git a/Common-Source/OpenSim.Servers/OpenSim.Servers.csproj.user b/Common-Source/OpenSim.Servers/OpenSim.Servers.csproj.user new file mode 100644 index 0000000..d47d65d --- /dev/null +++ b/Common-Source/OpenSim.Servers/OpenSim.Servers.csproj.user @@ -0,0 +1,12 @@ + + + Debug + AnyCPU + C:\New Folder\second-life-viewer\opensim-dailys2\opensim15-07\bin\ + 8.0.50727 + ProjectFiles + 0 + + + + diff --git a/Common-Source/OpenSim.Servers/OpenSim.Servers.dll.build b/Common-Source/OpenSim.Servers/OpenSim.Servers.dll.build new file mode 100644 index 0000000..5afd9e1 --- /dev/null +++ b/Common-Source/OpenSim.Servers/OpenSim.Servers.dll.build @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Common-Source/OpenSim.Servers/UDPServerBase.cs b/Common-Source/OpenSim.Servers/UDPServerBase.cs new file mode 100644 index 0000000..a308052 --- /dev/null +++ b/Common-Source/OpenSim.Servers/UDPServerBase.cs @@ -0,0 +1,68 @@ +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(int port) + { + listenPort = port; + } + + 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 virtual 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) + { + + } + } +} + diff --git a/Common-Source/OpenSim.Servers/XmlRpcMethod.cs b/Common-Source/OpenSim.Servers/XmlRpcMethod.cs new file mode 100644 index 0000000..2295405 --- /dev/null +++ b/Common-Source/OpenSim.Servers/XmlRpcMethod.cs @@ -0,0 +1,7 @@ +using System; +using Nwc.XmlRpc; + +namespace OpenSim.Servers +{ + public delegate XmlRpcResponse XmlRpcMethod( XmlRpcRequest request ); +} -- cgit v1.1