diff --git a/Programs/examples/PlexView/ClientMgr.cs b/Programs/examples/PlexView/ClientMgr.cs new file mode 100644 index 0000000..994d95c --- /dev/null +++ b/Programs/examples/PlexView/ClientMgr.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; + +namespace PlexView +{ + public sealed class ClientMgr + { + private static readonly ClientMgr instance = new ClientMgr(); + private Dictionary users; + + private ClientMgr() + { + users = new Dictionary(); + } + + public static ClientMgr Instance { + get { + return instance; + } + } + + public User NewUser(Creds creds) + { + User client = new User(creds); + client.Settings.LOGIN_SERVER = creds.gridURL; + //@todo if creds.gridName not in Grids list add it + users.Add(client.sessionID, client); + return client; + } + + public bool Login(User client) + { + return client.Network.Login(client.creds.first, client.creds.last, client.creds.pass, Constants.CHANNEL, Constants.VERSION); + } + + public bool Logout(Guid sessionID) + { + if (users.ContainsKey(sessionID)) { + users[sessionID].Network.Logout(); //@note this is a blocking call + return true; + } else { + return false; + } + } + } +} + diff --git a/Programs/examples/PlexView/Constants.cs b/Programs/examples/PlexView/Constants.cs new file mode 100644 index 0000000..2d09f9f --- /dev/null +++ b/Programs/examples/PlexView/Constants.cs @@ -0,0 +1,14 @@ +using System; + +namespace PlexView +{ + public static class Constants + { + public static readonly Uri HTTP_URL = new Uri("http://localhost:8080"); + + public static readonly string CHANNEL = "PlexView Chan1"; + + public static readonly string VERSION = "V1.1"; + } +} + diff --git a/Programs/examples/PlexView/Models/Creds.cs b/Programs/examples/PlexView/Models/Creds.cs new file mode 100644 index 0000000..cf9ab09 --- /dev/null +++ b/Programs/examples/PlexView/Models/Creds.cs @@ -0,0 +1,21 @@ +using System; + +namespace PlexView +{ + /// + /// Login Creds model. + /// + public class Creds + { + public string first { get; set; } + + public string last { get; set; } + + public string pass { get; set; } //@todo encrypt this in transit + + public string gridName { get; set; } + + public string gridURL { get; set; } + } +} + diff --git a/Programs/examples/PlexView/Models/Logout.cs b/Programs/examples/PlexView/Models/Logout.cs new file mode 100644 index 0000000..9fad907 --- /dev/null +++ b/Programs/examples/PlexView/Models/Logout.cs @@ -0,0 +1,13 @@ +using System; + +namespace PlexView +{ + /// + /// Logout model. + /// + public class Logout + { + public Guid sessionID { get; set; } + } +} + diff --git a/Programs/examples/PlexView/PlexView.cs b/Programs/examples/PlexView/PlexView.cs index 4acc028..733fe75 100644 --- a/Programs/examples/PlexView/PlexView.cs +++ b/Programs/examples/PlexView/PlexView.cs @@ -1,32 +1,27 @@ using System; +using System.Collections.Generic; using OpenMetaverse; +using Nancy; +using Nancy.Hosting.Self; namespace PlexView { public class PlexView { + +// public GridMgr grids; +// public ClientMgr clients; public PlexView (string[] args) { - GridClient client = new GridClient(); - client.Settings.LOGIN_SERVER = "http://login.osgrid.org/"; - if (client.Network.Login("", "", "", "FirstBot", "1.0")) - { - // Yay we made it! let's print out the message of the day - Console.WriteLine("You have successfully logged into Second Life!\n The Message of the day is {0}\nPress any Key to Logout", - client.Network.LoginMessage); - - Console.ReadLine(); // Wait for user to press a key before we continue - - client.Network.Logout(); // Lets logout since we're done here - } - else - { - // tell the user why the login failed - Console.WriteLine("We were unable to login to Second Life, The Login Server said: {0}", - client.Network.LoginMessage); - } - Console.WriteLine("Press Any Key to Exit"); - Console.ReadLine(); // Wait for user to press a key before we exit + //bootstrap the app here, initialize services, start http, get ready! + Console.WriteLine ("Server Starting"); + + var nancyHost = new NancyHost(Constants.HTTP_URL); + + nancyHost.Start(); + Console.WriteLine("HTTP server listening "+Constants.HTTP_URL); + Console.ReadKey(); + } } } diff --git a/Programs/examples/PlexView/copy2bin/Content/index.html b/Programs/examples/PlexView/copy2bin/Content/index.html new file mode 100644 index 0000000..8645650 --- /dev/null +++ b/Programs/examples/PlexView/copy2bin/Content/index.html @@ -0,0 +1,13 @@ + + + + PlexView + + + + + + + + + \ No newline at end of file diff --git a/Programs/examples/PlexView/copy2bin/Content/readme.md b/Programs/examples/PlexView/copy2bin/Content/readme.md new file mode 100644 index 0000000..bb42962 --- /dev/null +++ b/Programs/examples/PlexView/copy2bin/Content/readme.md @@ -0,0 +1,4 @@ +Content readme +============== + +Static HTML/Javascript/CSS content for Nancy to serve diff --git a/Programs/examples/PlexView/nancyModules/GridMod.cs b/Programs/examples/PlexView/nancyModules/GridMod.cs new file mode 100644 index 0000000..0438e7e --- /dev/null +++ b/Programs/examples/PlexView/nancyModules/GridMod.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using Nancy; + +namespace PlexView +{ + public class GridMod : NancyModule + { + public GridMod () : base("/api") + { + Get["/grid"] = parameters => + { + //return a list of grids + return ""; + }; + } + } +} + diff --git a/Programs/examples/PlexView/nancyModules/UserMod.cs b/Programs/examples/PlexView/nancyModules/UserMod.cs new file mode 100644 index 0000000..67df554 --- /dev/null +++ b/Programs/examples/PlexView/nancyModules/UserMod.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections; +using Nancy; +using Nancy.ModelBinding; +using OpenMetaverse; + +namespace PlexView +{ + public class UserMod : NancyModule + { + public UserMod () : base("/api") + { + Post["/login"] = parameters => + { + //process a login request + Creds creds = this.Bind(); + + User client = ClientMgr.Instance.NewUser(creds); + + if (ClientMgr.Instance.Login(client)) + { + Hashtable msg = new Hashtable(); + msg.Add("status", "success"); + msg.Add("motd", client.Network.LoginMessage); + msg.Add("sessionID", client.sessionID); + return msg; + } + else + { + Hashtable msg = new Hashtable(); + msg.Add("status", "fail"); + msg.Add("motd", client.Network.LoginMessage); + msg.Add("sessionID", client.sessionID); + return msg; + } + }; + + Post["/logout"] = parameters => + { + Logout logout = this.Bind(); + + //figure out who they are based on a parameter + //we don't want users logging eachother out, xss so we need some sort of session ID + + Hashtable msg = new Hashtable(); + if (ClientMgr.Instance.Logout(logout.sessionID)){ + msg.Add("status", "success"); + } else { + msg.Add("status", "fail"); + } + return msg; + + }; + } + } +} + diff --git a/Programs/examples/PlexView/packages.config b/Programs/examples/PlexView/packages.config new file mode 100644 index 0000000..64e4298 --- /dev/null +++ b/Programs/examples/PlexView/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Programs/examples/PlexView/types/User.cs b/Programs/examples/PlexView/types/User.cs new file mode 100644 index 0000000..6ad8088 --- /dev/null +++ b/Programs/examples/PlexView/types/User.cs @@ -0,0 +1,65 @@ +#region License +/* Copyright (c) 2008, Katharine Berry + * All rights reserved. + * + * 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 Katharine Berry nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY KATHARINE BERRY ``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 KATHARINE BERRY 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. + ******************************************************************************/ +#endregion +using System; +using System.Collections.Generic; + +using OpenMetaverse; + +namespace PlexView +{ + + public class User : GridClient + { + + public DateTime lastRequest; + public readonly Guid sessionID; + public readonly Creds creds; + + //@todo Instances of the client class should only be created by the ClientMgr + public User(Creds creds) + { + Settings.ALWAYS_DECODE_OBJECTS = false; + Settings.ALWAYS_REQUEST_OBJECTS = false; + Settings.MULTIPLE_SIMS = false; + Settings.ENABLE_SIMSTATS = true; + Settings.LOGOUT_TIMEOUT = 20000; + Settings.LOG_RESENDS = false; + Settings.USE_ASSET_CACHE = false; + Throttle.Cloud = 0; + Throttle.Task = 0; + Throttle.Wind = 0; + Throttle.Asset = 50000; + Throttle.Resend = 500000; + Throttle.Texture = 500000; + + lastRequest = DateTime.Now; + sessionID = Guid.NewGuid(); + this.creds = creds; + } + } +} diff --git a/packages/repositories.config b/packages/repositories.config new file mode 100644 index 0000000..697d4a7 --- /dev/null +++ b/packages/repositories.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file