Non-blocking logout

This commit is contained in:
Blake Bourque
2015-06-24 22:25:34 -04:00
parent f8a8985fb6
commit a1bf4cb98c
4 changed files with 55 additions and 21 deletions
+8 -4
View File
@@ -29,7 +29,7 @@ namespace PlexView
// }
//create a new user and begin the login process
public Guid NewUserLogin(Creds creds)
public Guid BeginNewUserLogin(Creds creds)
{
//create the user object
User client = new User(creds);
@@ -37,15 +37,19 @@ namespace PlexView
//add the user to the list of users
users.Add(client.sessionID, client);
//initiate login
client.Login();
client.BeginLogin();
return client.sessionID;
}
public bool Logout(Guid sessionID)
public bool BeginLogout(Guid sessionID)
{
if (users.ContainsKey(sessionID)) {
users[sessionID].Network.Logout(); //@note this is a blocking call
//begin the logot process
users[sessionID].BeginLogout();
//remove the user from the active list
users.Remove(sessionID);
return true;
} else {
return false;
-3
View File
@@ -8,9 +8,6 @@ namespace PlexView
{
public class PlexView
{
// public GridMgr grids;
// public ClientMgr clients;
public PlexView (string[] args)
{
//bootstrap the app here, initialize services, start http, get ready!
@@ -10,37 +10,49 @@ namespace PlexView
{
public UserMod () : base("/api")
{
//When the users requests to login
//When the user requests to login
Post["/login"] = parameters =>
{
//parese their credentials
Creds creds = this.Bind<Creds>();
//initiate login process
Guid sessionID = ClientMgr.Instance.NewUserLogin(creds);
Guid sessionID = ClientMgr.Instance.BeginNewUserLogin(creds);
//tell them that we have started login
Hashtable msg = new Hashtable();
msg.Add("status", "login begin");
msg.Add("status", "login begun");
msg.Add("sessionID", sessionID);
return msg;
};
//when the user requests to logout
Post["/logout"] = parameters =>
{
//parse their logout credentials
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");
if (ClientMgr.Instance.BeginLogout(logout.sessionID))
{
//tell them that we have started logout
Hashtable msg = new Hashtable();
msg.Add("status", "logout begun");
msg.Add("sessionID", logout.sessionID);
return msg;
}
return msg;
else
{
Console.WriteLine("Unable to begin logout");
//tell them that we have FAILEDstarted login
Hashtable msg = new Hashtable();
msg.Add("status", "logout FAILED");
msg.Add("sessionID", logout.sessionID);
return msg;
}
};
}
+24 -3
View File
@@ -62,26 +62,47 @@ namespace PlexView
Settings.LOGIN_SERVER = creds.gridURL;
this.creds = creds;
}
public void Login()
public void BeginLogin()
{
//setup a callback (delagate) as the lgon status changes
Network.LoginProgress += delegate(NetworkManager sender, LoginProgressEventArgs e)
Network.LoginProgress += delegate(object sender, LoginProgressEventArgs e)
{
if (e.Status == LoginStatus.Success)
{
//@todo login successfull
Console.WriteLine ("Login Success "+sender.client.ToString());
Console.WriteLine ("Login Success for user "+GetAvatarName());
//send e.Message
}
else if (e.Status == LoginStatus.Failed)
{
//@todo login failure
Console.WriteLine ("Login Failure");
//send e.FailReason
}
};
Network.BeginLogin(new LoginParams(this, creds.first, creds.last, creds.pass, Constants.CHANNEL, Constants.VERSION));
}
public void BeginLogout()
{
Network.LoggedOut += delegate(object sender, LoggedOutEventArgs e) {
Console.WriteLine (String.Format("Logout for user {0}", GetAvatarName()));
};
Network.BeginLogout();
}
public string GetAvatarName()
{
if (! creds.last.Equals("Resident")) {
return String.Format("{0} {1}", creds.first, creds.last);
} else {
return String.Format("{0}", creds.first);
}
}
// public bool IsLoggedIn()
// {
// }