forked from PGR/ascnet
db and real auth
This commit is contained in:
parent
b9b4796d0e
commit
5af2ab34d0
|
@ -0,0 +1,69 @@
|
|||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
using AscNet.Common.MsgPack;
|
||||
|
||||
namespace AscNet.Common.Database
|
||||
{
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
public class Player
|
||||
{
|
||||
public static readonly IMongoCollection<Player> collection = Common.db.GetCollection<Player>("players");
|
||||
|
||||
public static Player FromId(long id)
|
||||
{
|
||||
return collection.AsQueryable().FirstOrDefault(x => x.PlayerData.Id == id) ?? Create(id);
|
||||
}
|
||||
|
||||
public static Player? FromToken(string token)
|
||||
{
|
||||
return collection.AsQueryable().FirstOrDefault(x => x.Token == token);
|
||||
}
|
||||
|
||||
private static Player Create(long id)
|
||||
{
|
||||
Player player = new()
|
||||
{
|
||||
Token = Guid.NewGuid().ToString(),
|
||||
PlayerData = new()
|
||||
{
|
||||
Id = id,
|
||||
Name = $"Commandant{id}",
|
||||
Level = 1,
|
||||
Sign = "",
|
||||
DisplayCharId = 1021001,
|
||||
Birthday = null,
|
||||
HonorLevel = 1,
|
||||
ServerId = "1",
|
||||
CurrTeamId = 1,
|
||||
CurrHeadPortraitId = 9000003,
|
||||
AppearanceSettingInfo = new()
|
||||
{
|
||||
TitleType = 1,
|
||||
CharacterType = 1,
|
||||
FashionType = 1,
|
||||
WeaponFashionType = 1,
|
||||
DormitoryType = 1
|
||||
},
|
||||
CreateTime = DateTimeOffset.Now.ToUnixTimeSeconds(),
|
||||
LastLoginTime = DateTimeOffset.Now.ToUnixTimeSeconds(),
|
||||
Flags = 1
|
||||
}
|
||||
};
|
||||
collection.InsertOne(player);
|
||||
|
||||
return player;
|
||||
}
|
||||
|
||||
[BsonId]
|
||||
public ObjectId Id { get; set; }
|
||||
|
||||
[BsonElement("token")]
|
||||
[BsonRequired]
|
||||
public string Token { get; set; }
|
||||
|
||||
[BsonElement("player_data")]
|
||||
[BsonRequired]
|
||||
public PlayerData PlayerData { get; set; }
|
||||
}
|
||||
}
|
|
@ -229,7 +229,7 @@ namespace AscNet.Common.MsgPack
|
|||
public long Level { get; set; }
|
||||
public string Sign { get; set; }
|
||||
public long DisplayCharId { get; set; }
|
||||
public Birthday Birthday { get; set; }
|
||||
public Birthday? Birthday { get; set; }
|
||||
public long HonorLevel { get; set; }
|
||||
public string ServerId { get; set; }
|
||||
public long Likes { get; set; }
|
||||
|
@ -242,11 +242,11 @@ namespace AscNet.Common.MsgPack
|
|||
public long DailyReceiveGiftCount { get; set; }
|
||||
public long DailyActivenessRewardStatus { get; set; }
|
||||
public long WeeklyActivenessRewardStatus { get; set; }
|
||||
public long[] Marks { get; set; }
|
||||
public long[] GuideData { get; set; }
|
||||
public long[] Communications { get; set; }
|
||||
public long[] ShowCharacters { get; set; }
|
||||
public object[] ShieldFuncList { get; set; }
|
||||
public List<long> Marks { get; set; } = new();
|
||||
public List<long> GuideData { get; set; } = new();
|
||||
public List<long> Communications { get; set; } = new();
|
||||
public List<long> ShowCharacters { get; set; } = new();
|
||||
public List<dynamic> ShieldFuncList { get; set; } = new();
|
||||
public AppearanceSettingInfo AppearanceSettingInfo { get; set; }
|
||||
public long CreateTime { get; set; }
|
||||
public long LastLoginTime { get; set; }
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using AscNet.Common.MsgPack;
|
||||
using AscNet.Common.Database;
|
||||
using AscNet.Common.MsgPack;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
@ -25,10 +26,22 @@ namespace AscNet.GameServer.Handlers
|
|||
[RequestPacketHandler("LoginRequest")]
|
||||
public static void LoginRequestHandler(Session session, Packet.Request packet)
|
||||
{
|
||||
LoginRequest request = MessagePackSerializer.Deserialize<LoginRequest>(packet.Content);
|
||||
Player? player = Player.FromToken(request.Token);
|
||||
|
||||
if (player is null)
|
||||
{
|
||||
session.SendResponse(new LoginResponse
|
||||
{
|
||||
Code = 1007 // LoginInvalidLoginToken
|
||||
}, packet.Id);
|
||||
return;
|
||||
}
|
||||
|
||||
session.SendResponse(new LoginResponse
|
||||
{
|
||||
Code = 0,
|
||||
ReconnectToken = "eeeeeeeeeeeeeeh",
|
||||
ReconnectToken = player.Token,
|
||||
UtcOffset = 0,
|
||||
UtcServerTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
|
||||
}, packet.Id);
|
||||
|
@ -39,12 +52,21 @@ namespace AscNet.GameServer.Handlers
|
|||
[RequestPacketHandler("ReconnectRequest")]
|
||||
public static void ReconnectRequestHandler(Session session, Packet.Request packet)
|
||||
{
|
||||
ReconnectRequest request = MessagePackSerializer.Deserialize<ReconnectRequest>(packet.Content);
|
||||
Player? player = Player.FromToken(request.Token);
|
||||
|
||||
if (player?.PlayerData.Id != request.PlayerId)
|
||||
{
|
||||
session.SendResponse(new ReconnectResponse()
|
||||
{
|
||||
Code = 1029 // ReconnectInvalidToken
|
||||
}, packet.Id);
|
||||
return;
|
||||
}
|
||||
|
||||
session.SendResponse(new ReconnectResponse()
|
||||
{
|
||||
Code = 0,
|
||||
OfflineMessages = { },
|
||||
ReconnectToken = "eeeeeeeeeeeeeeh",
|
||||
RequestNo = 0
|
||||
ReconnectToken = request.Token
|
||||
}, packet.Id);
|
||||
}
|
||||
|
||||
|
|
|
@ -107,6 +107,34 @@ namespace AscNet.SDKServer.Controllers
|
|||
account
|
||||
});
|
||||
});
|
||||
|
||||
app.MapGet("/api/Login/Login", ([FromQuery] int loginType, [FromQuery] int userId, [FromQuery] string token, [FromQuery] string clientIp) =>
|
||||
{
|
||||
Account? account = Account.FromToken(token);
|
||||
|
||||
if (account is null)
|
||||
{
|
||||
return JsonConvert.SerializeObject(new
|
||||
{
|
||||
code = -1,
|
||||
msg = "Invalid credentials!"
|
||||
});
|
||||
}
|
||||
|
||||
Player player = Player.FromId(account.Uid);
|
||||
|
||||
LoginGate gate = new()
|
||||
{
|
||||
Code = 0,
|
||||
Ip = Common.Common.config.GameServer.Host,
|
||||
Port = Common.Common.config.GameServer.Port,
|
||||
Token = player.Token
|
||||
};
|
||||
|
||||
string serializedObject = JsonConvert.SerializeObject(gate);
|
||||
SDKServer.log.Info(serializedObject);
|
||||
return serializedObject;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,21 +131,6 @@ namespace AscNet.SDKServer.Controllers
|
|||
SDKServer.log.Info("1");
|
||||
return "1";
|
||||
});
|
||||
|
||||
app.MapGet("/api/Login/Login", ([FromQuery] int loginType, [FromQuery] int userId, [FromQuery] string token, [FromQuery] string clientIp) =>
|
||||
{
|
||||
LoginGate gate = new()
|
||||
{
|
||||
Code = 0,
|
||||
Ip = Common.Common.config.GameServer.Host,
|
||||
Port = Common.Common.config.GameServer.Port,
|
||||
Token = token
|
||||
};
|
||||
|
||||
string serializedObject = JsonConvert.SerializeObject(gate);
|
||||
SDKServer.log.Info(serializedObject);
|
||||
return serializedObject;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace AscNet.SDKServer
|
|||
private class RequestLoggingMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private static readonly string[] SurpressedRoutes = new string[] { "/report", "/sdk/dataUpload" };
|
||||
private static readonly string[] SurpressedRoutes = new string[] { "/feedback" };
|
||||
|
||||
public RequestLoggingMiddleware(RequestDelegate next)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue