planning to add option to use external sdk for login

This commit is contained in:
AlessandroCH
2025-07-09 19:35:51 +02:00
parent 3fbe2b6fc1
commit 623f7a111c
4 changed files with 20 additions and 31 deletions

View File

@@ -25,22 +25,10 @@
/// Not yet implemented /// Not yet implemented
/// </summary> /// </summary>
public bool useEncryption = false; public bool useEncryption = false;
//public CharactersOptions defaultCharacters = new();
public ServerOptions() public ServerOptions()
{ {
} }
/*public class CharactersOptions
{
public int defaultLevel = 1;
public bool giveAllCharacters = true;
public List<string> characters = new List<string>(); //used if giveAllCharacters is false
public CharactersOptions() { }
}*/
/* public struct WelcomeMail
{
}*/
} }
public class LogSettings public class LogSettings
{ {
@@ -59,6 +47,8 @@
public int bindPort = 30000; public int bindPort = 30000;
public string accessAddress = "127.0.0.1"; public string accessAddress = "127.0.0.1";
public int accessPort = 30000; public int accessPort = 30000;
public bool useExternalAuthSdk = false;
public string externalAuthSdkUrl = "";
public GameserverSettings() public GameserverSettings()
{ {
} }

View File

@@ -362,6 +362,11 @@ namespace Campofinale.Database
} }
public Account GetAccountByTokenGrant(string token) public Account GetAccountByTokenGrant(string token)
{ {
if (Server.config.gameServer.useExternalAuthSdk)
{
//TODO get account info from external auth sdk
return null;
}
try try
{ {
return _database.GetCollection<Account>("accounts").Find(p => p.grantToken == token).ToList().FirstOrDefault(); return _database.GetCollection<Account>("accounts").Find(p => p.grantToken == token).ToList().FirstOrDefault();

View File

@@ -14,10 +14,7 @@ namespace Campofinale.Http
string requestBody = ctx.Request.DataAsString; string requestBody = ctx.Request.DataAsString;
Console.WriteLine(requestBody); Console.WriteLine(requestBody);
string resp = "{}"; string resp = "{}";
ctx.Response.StatusCode = 200; ctx.Response.StatusCode = 200;
//ctx.Response.ContentLength = resp.Length;
ctx.Response.ContentType = "application/json"; ctx.Response.ContentType = "application/json";
await ctx.Response.SendAsync(resp); await ctx.Response.SendAsync(resp);
@@ -42,7 +39,6 @@ namespace Campofinale.Http
} }
ctx.Response.StatusCode = 200; ctx.Response.StatusCode = 200;
//ctx.Response.ContentLength = resp.Length;
ctx.Response.ContentType = "application/json"; ctx.Response.ContentType = "application/json";
await ctx.Response.SendAsync(resp); await ctx.Response.SendAsync(resp);
@@ -66,7 +62,6 @@ namespace Campofinale.Http
} }
ctx.Response.StatusCode = 200; ctx.Response.StatusCode = 200;
//ctx.Response.ContentLength = resp.Length;
ctx.Response.ContentType = "application/json"; ctx.Response.ContentType = "application/json";
await ctx.Response.SendAsync(resp); await ctx.Response.SendAsync(resp);
@@ -87,7 +82,7 @@ namespace Campofinale.Http
if (account != null) if (account != null)
{ {
/* /*
* {"data":{"hgId":"1326618825955","phone":"153****5243","email":null,"identityNum":"5002**********1619","identityName":"金*","isMinor":false,"isLatestUserAgreement":true},"msg":"OK","status":0,"type":"A"} * {"data":{"hgId":"**********","phone":"153****5243","email":null,"identityNum":"5002**********1619","identityName":"金*","isMinor":false,"isLatestUserAgreement":true},"msg":"OK","status":0,"type":"A"}
*/ */
resp = "{\"data\":{\"phone\":\"153****5243\", \"identityNum\": \"5002**********1619\",\"identityName\":\"金*\",\"isMinor\":false,\"hgId\":\"" + account.id + "\",\"email\":\"" + account.username +Server.config.dispatchServer.emailFormat +"\",\"realEmail\":\"" + account.username + Server.config.dispatchServer.emailFormat + "\",\"isLatestUserAgreement\":true,\"nickName\":\"" + account.username + "\"},\"msg\":\"OK\",\"status\":0,\"type\":\"A\"}"; resp = "{\"data\":{\"phone\":\"153****5243\", \"identityNum\": \"5002**********1619\",\"identityName\":\"金*\",\"isMinor\":false,\"hgId\":\"" + account.id + "\",\"email\":\"" + account.username +Server.config.dispatchServer.emailFormat +"\",\"realEmail\":\"" + account.username + Server.config.dispatchServer.emailFormat + "\",\"isLatestUserAgreement\":true,\"nickName\":\"" + account.username + "\"},\"msg\":\"OK\",\"status\":0,\"type\":\"A\"}";
} }
@@ -100,7 +95,6 @@ namespace Campofinale.Http
ctx.Response.StatusCode = 200; ctx.Response.StatusCode = 200;
//ctx.Response.ContentLength = resp.Length;
ctx.Response.ContentType = "application/json"; ctx.Response.ContentType = "application/json";
await ctx.Response.SendAsync(resp); await ctx.Response.SendAsync(resp);
@@ -182,14 +176,7 @@ namespace Campofinale.Http
} }
} }
/*{ public struct RegisterFormData
"appCode": "2fe67ec91610377d",
"code": "121212",
"email": "aaaa@a.cc",
"from": 0,
"password": "aaaaaaaaaaaaaa1"
}*/
public struct RegisterData
{ {
public string appCode; public string appCode;
public string code; public string code;
@@ -203,7 +190,7 @@ namespace Campofinale.Http
{ {
string requestBody = ctx.Request.DataAsString; string requestBody = ctx.Request.DataAsString;
Console.WriteLine(requestBody); Console.WriteLine(requestBody);
RegisterData data = Newtonsoft.Json.JsonConvert.DeserializeObject<RegisterData>(requestBody); RegisterFormData data = Newtonsoft.Json.JsonConvert.DeserializeObject<RegisterFormData>(requestBody);
string username = data.email.Split("@")[0]; string username = data.email.Split("@")[0];
(string,int) msg=DatabaseManager.db.CreateAccount(username); (string,int) msg=DatabaseManager.db.CreateAccount(username);
string resp = ""; string resp = "";
@@ -267,9 +254,6 @@ namespace Campofinale.Http
resp = File.ReadAllText("Data/GachaHistory/index_noplayerfound.html"); resp = File.ReadAllText("Data/GachaHistory/index_noplayerfound.html");
} }
ctx.Response.StatusCode = 200; ctx.Response.StatusCode = 200;
await ctx.Response.SendAsync(resp); await ctx.Response.SendAsync(resp);

View File

@@ -72,6 +72,16 @@ namespace Campofinale.Packets.Cs
return; return;
} }
Account account = DatabaseManager.db.GetAccountByTokenGrant(req.Token); Account account = DatabaseManager.db.GetAccountByTokenGrant(req.Token);
if (account==null)
{
session.Send(ScMsgId.ScNtfErrorCode, new ScNtfErrorCode()
{
Details = "Auth Error",
ErrorCode = (int)CODE.ErrLoginProcessLogin,
});
session.Disconnect();
return;
}
ScLogin rsp = new() ScLogin rsp = new()
{ {
IsEnc = false, IsEnc = false,