Update To new godot system, Migrate the login system to auth.mistox.com
This commit is contained in:
@@ -1 +1 @@
|
||||
uid://b4pflwlbpbu1b
|
||||
uid://dnmloqvjwrigb
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://qsbk1qvvurnk
|
||||
uid://bcqncbv71hv7f
|
||||
|
||||
@@ -10,7 +10,7 @@ public partial class DayCycle : DirectionalLight3D {
|
||||
_Options = GetNode<Options>( "/root/Options" );
|
||||
_Reference = GetNode<Reference>("/root/Reference");
|
||||
if ( _Options.isServer ){
|
||||
Rotation = Rotation + new Vector3(Convert.ToSingle(delta),0,0);
|
||||
Rotation += new Vector3(Convert.ToSingle(delta),0,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://www1orn2bphw
|
||||
uid://cnfn7826p2upw
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://buy8ynfr36cb7
|
||||
uid://dvlqdsi6jmx5g
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://cs6w27xegmn3g
|
||||
uid://ccpvnrbxr855v
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://b4i4hta2aywup
|
||||
uid://bd1tifuc7cih1
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://uhnffw14mc3a
|
||||
uid://gau0mrx50am2
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://cjfadm1jgncoy
|
||||
uid://dua4p4u1xukoj
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://ccrwjsylojer2
|
||||
uid://cjsss3hmqaaum
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://05tlk373hpor
|
||||
uid://c6d2sk2xkad6q
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public partial class MainMenu : Control {
|
||||
Options _Options;
|
||||
@@ -18,25 +20,24 @@ public partial class MainMenu : Control {
|
||||
public async void _on_join_game_pressed() {
|
||||
SettingsFile sf = _Options._SettingsFile;
|
||||
GameSettings gs = sf.Game;
|
||||
string userN = gs.UserName;
|
||||
string passW = gs.SessionToken;
|
||||
(bool, Account) User = await _Reference.MistoxNet.TrySession( userN, passW );
|
||||
if( User.Item1 ) {
|
||||
_Reference.Lighting.Environment.SsrEnabled = sf.Display.ScreenSpaceReflections;
|
||||
_Reference.Lighting.Environment.SsaoEnabled = sf.Display.ScreenSpaceAmbiantOcclusion;
|
||||
_Reference.Lighting.Environment.SdfgiEnabled = sf.Display.GlobalIllumination;
|
||||
_Reference.GameHandler.Visible = true;
|
||||
_Reference.GameUI.Visible = true;
|
||||
Visible = false;
|
||||
_Options.Host = GetNode<TextEdit>("Host").Text;
|
||||
_Reference.GameHandler.StartClient();
|
||||
this.Visible = false;
|
||||
_Reference.PreGame.Visible = true;
|
||||
|
||||
} else {
|
||||
(bool, Account) tAccount = await _Reference.MistoxNet.TryValidateSessionToken( gs.SessionToken );
|
||||
if( !tAccount.Item1 ) {
|
||||
_Reference.Alert.PerformAlert( "Login failed" );
|
||||
_Reference.SessionHandler.GetParent<Control>().Visible = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_Reference.Lighting.Environment.SsrEnabled = sf.Display.ScreenSpaceReflections;
|
||||
_Reference.Lighting.Environment.SsaoEnabled = sf.Display.ScreenSpaceAmbiantOcclusion;
|
||||
_Reference.Lighting.Environment.SdfgiEnabled = sf.Display.GlobalIllumination;
|
||||
_Reference.GameHandler.Visible = true;
|
||||
_Reference.GameUI.Visible = true;
|
||||
Visible = false;
|
||||
_Options.Host = GetNode<TextEdit>("Host").Text;
|
||||
_Reference.GameHandler.StartClient();
|
||||
this.Visible = false;
|
||||
_Reference.PreGame.Visible = true;
|
||||
}
|
||||
|
||||
public void _on_start_server_pressed(){
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://bl0rkhiv11xlw
|
||||
uid://cgk3ybaxnvan6
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://dng4m5svd37r6
|
||||
uid://cgra737ky483a
|
||||
|
||||
@@ -15,11 +15,12 @@ public partial class SessionHandler : Panel {
|
||||
}
|
||||
|
||||
public async void onLogin() {
|
||||
(bool, Account) User = await _Reference.MistoxNet.TryLogin( UsernameBox.Text, PasswordBox.Text );
|
||||
if( User.Item1 ) {
|
||||
|
||||
(bool, string) tSessionToken = await _Reference.MistoxNet.TryGetSessionToken( UsernameBox.Text, PasswordBox.Text );
|
||||
if( tSessionToken.Item1 ) {
|
||||
_Reference.Alert.PerformAlert( "Login Success" );
|
||||
_Options._SettingsFile.Game.UserName = User.Item2.UserName;
|
||||
_Options._SettingsFile.Game.SessionToken = User.Item2.PasswordHash;
|
||||
_Options._SettingsFile.Game.UserName = UsernameBox.Text;
|
||||
_Options._SettingsFile.Game.SessionToken = tSessionToken.Item2;
|
||||
_Options._SettingsFile.Save();
|
||||
GetParent<Control>().Visible = false;
|
||||
} else {
|
||||
@@ -28,6 +29,6 @@ public partial class SessionHandler : Panel {
|
||||
}
|
||||
|
||||
public void onRegister() {
|
||||
OS.ShellOpen("https://www.mistox.net/account/register");
|
||||
OS.ShellOpen("https://auth.mistox.com/account/register");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
uid://66m0tj8fp24l
|
||||
uid://dxxwl4k43ihnx
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://dj0pgl0vcm6gc
|
||||
uid://6m6sspt1v1ot
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://bnglonmv1dwdk
|
||||
uid://bxn3y4ogerbjv
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
using Godot;
|
||||
using Newtonsoft.Json;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using System.Security.Claims;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public partial class MistoxNet : Node{
|
||||
@@ -14,31 +18,77 @@ public partial class MistoxNet : Node{
|
||||
_Reference.MistoxNet = this;
|
||||
}
|
||||
|
||||
public async Task<(bool, Account)> TrySession( string UserName, string Password ) {
|
||||
public static string TokenAudience = "mistox-llc-auth-token";
|
||||
public static string TokenIssuer = "https://auth.mistox.com";
|
||||
public static string TokenName = "mistox_session";
|
||||
|
||||
public async Task<(bool, string)> TryGetSessionToken( string UserName, string Password ) {
|
||||
using( System.Net.Http.HttpClient client = new System.Net.Http.HttpClient() ) {
|
||||
HttpResponseMessage response = await client.PostAsJsonAsync( "https://mistox.com/api/account/session", new Account { UserName = UserName, PasswordHash = Password } );
|
||||
string result = await response.Content.ReadAsStringAsync();
|
||||
Account User = JsonConvert.DeserializeObject<Account>(result);
|
||||
if( User != null && string.IsNullOrEmpty( User.Error ) ) {
|
||||
return (true, User);
|
||||
}
|
||||
return (false, User);
|
||||
// Get LoginTicket
|
||||
HttpResponseMessage response = await client.PostAsJsonAsync( "https://auth.mistox.com/api/auth/login", new LoginRequest { UserName = UserName, Password = Password, Site = "PolyphiaGame", StayLoggedIn = true } );
|
||||
string LoginTicket = await response.Content.ReadAsStringAsync();
|
||||
// Login Via Ticket
|
||||
HttpResponseMessage response2 = await client.PostAsJsonAsync( "https://auth.mistox.com/api/auth/token", new JWTRequest { Ticket = LoginTicket } );
|
||||
return (response2.IsSuccessStatusCode, await response2.Content.ReadAsStringAsync());
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(bool, Account)> TryLogin( string UserName, string Password ) {
|
||||
public async Task<(bool, string)> TryUpdateSessionToken( string LoginTicket ) {
|
||||
using( System.Net.Http.HttpClient client = new System.Net.Http.HttpClient() ) {
|
||||
HttpResponseMessage response = await client.PostAsJsonAsync( "https://mistox.com/api/account/login", new Account { UserName = UserName, PasswordHash = Password } );
|
||||
string result = await response.Content.ReadAsStringAsync();
|
||||
Account User = JsonConvert.DeserializeObject<Account>(result);
|
||||
if( User != null && string.IsNullOrEmpty( User.Error ) ) {
|
||||
return (true, User);
|
||||
HttpResponseMessage response = await client.PostAsJsonAsync( "https://auth.mistox.com/api/auth/renew", new JWTRenewRequest { JWT = LoginTicket } );
|
||||
return (response.IsSuccessStatusCode, await response.Content.ReadAsStringAsync());
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(bool, Account)> TryValidateSessionToken( string SessionToken ) {
|
||||
using( System.Net.Http.HttpClient client = new System.Net.Http.HttpClient() ) {
|
||||
HttpResponseMessage response = await client.GetAsync( "https://auth.mistox.com/api/auth/publickey" );
|
||||
string PublicKey = await response.Content.ReadAsStringAsync();
|
||||
RSA rsa = RSA.Create();
|
||||
rsa.ImportFromPem(PublicKey);
|
||||
|
||||
TokenValidationParameters TokenParameters = new TokenValidationParameters {
|
||||
ValidateIssuer = true,
|
||||
ValidateAudience = true,
|
||||
ValidateLifetime = true,
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidIssuer = TokenIssuer,
|
||||
ValidAudience = TokenAudience,
|
||||
IssuerSigningKey = new RsaSecurityKey(rsa),
|
||||
ClockSkew = TimeSpan.FromMinutes(1)
|
||||
};
|
||||
|
||||
try {
|
||||
JwtSecurityTokenHandler tokenHandler = new JwtSecurityTokenHandler();
|
||||
ClaimsPrincipal principal = tokenHandler.ValidateToken( SessionToken, TokenParameters, out SecurityToken validatedToken );
|
||||
return (true, new Account {
|
||||
ID = Convert.ToInt32(principal.FindFirst(ClaimTypes.NameIdentifier).Value),
|
||||
UserName = principal.FindFirst(ClaimTypes.Name).Value,
|
||||
Email = principal.FindFirst(ClaimTypes.Email).Value
|
||||
});
|
||||
} catch (Exception) {
|
||||
return (false, null);
|
||||
}
|
||||
return (false, User);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class LoginRequest {
|
||||
public string UserName { get; set; } = "";
|
||||
public string Password { get; set; } = "";
|
||||
public string Site { get; set; } = "";
|
||||
public bool StayLoggedIn { get; set; }
|
||||
}
|
||||
|
||||
public class JWTRequest {
|
||||
public string Ticket { get; set; } = "";
|
||||
}
|
||||
|
||||
public class JWTRenewRequest {
|
||||
public string JWT { get; set; } = "";
|
||||
}
|
||||
|
||||
public class Account {
|
||||
public int ID { get; set; } // PK
|
||||
public string UserName { get; set; } = "";
|
||||
@@ -49,11 +99,11 @@ public class Account {
|
||||
}
|
||||
|
||||
public class ProjectMistData {
|
||||
public int AccountID { get; set; } // PK
|
||||
public int Credits { get; set; }
|
||||
public int OddballTimer { get; set; }
|
||||
public string SessionToken { get; set; } = "";
|
||||
public int SessionID { get; set; }
|
||||
public int Kills { get; set; }
|
||||
public int Deaths { get; set; }
|
||||
}
|
||||
public int AccountID { get; set; } // PK
|
||||
public int Credits { get; set; }
|
||||
public int OddballTimer { get; set; }
|
||||
public string SessionToken { get; set; } = "";
|
||||
public int SessionID { get; set; }
|
||||
public int Kills { get; set; }
|
||||
public int Deaths { get; set; }
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
uid://ca2ujuppt1716
|
||||
uid://dcwk2h5txbtkd
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://dyalj7cgqmxac
|
||||
uid://b4oqvvrbiq2ei
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://ddljq4uh8l2g8
|
||||
uid://dmou28p8w4gxs
|
||||
|
||||
Reference in New Issue
Block a user