Able to login and out user

This commit is contained in:
Blake Bourque
2015-06-23 23:39:06 -04:00
parent 0bb2dff347
commit 068d53279e
12 changed files with 277 additions and 20 deletions
+47
View File
@@ -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<Guid, User> users;
private ClientMgr()
{
users = new Dictionary<Guid, User>();
}
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;
}
}
}
}
+14
View File
@@ -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";
}
}
@@ -0,0 +1,21 @@
using System;
namespace PlexView
{
/// <summary>
/// Login Creds model.
/// </summary>
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; }
}
}
@@ -0,0 +1,13 @@
using System;
namespace PlexView
{
/// <summary>
/// Logout model.
/// </summary>
public class Logout
{
public Guid sessionID { get; set; }
}
}
+15 -20
View File
@@ -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();
}
}
}
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>PlexView</title>
</head>
<body>
<input type="text" name="first">
<input type="text" name="last">
<input type="password" name="pass">
<input type="text" name="gridName">
<input type="text" name="gridURL">
</body>
</html>
@@ -0,0 +1,4 @@
Content readme
==============
Static HTML/Javascript/CSS content for Nancy to serve
@@ -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 "";
};
}
}
}
@@ -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<Creds>();
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<Logout>();
//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;
};
}
}
}
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Nancy" version="1.2.0" targetFramework="net40" />
<package id="Nancy.Hosting.Self" version="1.2.0" targetFramework="net40" />
</packages>
+65
View File
@@ -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;
}
}
}