mirror of
https://github.com/rafi1212122/PemukulPaku
synced 2025-12-12 22:34:36 +01:00
login 💀
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Config.Net" Version="5.1.5" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.19.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="protobuf-net" Version="3.2.16" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
28
Common/Database/AutoIncrement.cs
Normal file
28
Common/Database/AutoIncrement.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Common.Resources.Proto;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace Common.Database
|
||||
{
|
||||
public class AutoIncrement
|
||||
{
|
||||
public static readonly IMongoCollection<AI> collection = Global.db.GetCollection<AI>("AutoIncrements");
|
||||
|
||||
public static int GetNextNumber(string name, int starting = 100)
|
||||
{
|
||||
AI AutoIncrement = collection.FindOneAndUpdate(Builders<AI>.Filter.Eq("Name", name), Builders<AI>.Update.SetOnInsert("Count", starting), new FindOneAndUpdateOptions<AI> { IsUpsert = true, ReturnDocument = ReturnDocument.After });
|
||||
collection.UpdateOne(Builders<AI>.Filter.Eq("Name", AutoIncrement.Name), Builders<AI>.Update.Inc("Count", 1));
|
||||
return AutoIncrement.Count + 1;
|
||||
}
|
||||
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
public class AI
|
||||
{
|
||||
public ObjectId Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
}
|
||||
}
|
||||
@@ -14,14 +14,14 @@ namespace Common.Database
|
||||
UserScheme user = new()
|
||||
{
|
||||
Name = name,
|
||||
Uid = 1001,
|
||||
Uid = (uint)AutoIncrement.GetNextNumber("UID", 1000),
|
||||
Nick = "",
|
||||
Exp = 0,
|
||||
Hcoin = 0,
|
||||
Stamina = 80,
|
||||
SelfDesc = "",
|
||||
IsFirstLogin = true,
|
||||
Token = Guid.NewGuid(),
|
||||
Token = Guid.NewGuid().ToString(),
|
||||
WarshipId = 0,
|
||||
WarshipAvatar = new WarshipAvatarData()
|
||||
{
|
||||
@@ -39,6 +39,18 @@ namespace Common.Database
|
||||
return user;
|
||||
}
|
||||
|
||||
public static UserScheme FromName(string name)
|
||||
{
|
||||
UserScheme? user = collection.AsQueryable().Where(d => d.Name == name).FirstOrDefault();
|
||||
return user ?? CreateUser(name);
|
||||
}
|
||||
|
||||
public static UserScheme? FromToken(string token)
|
||||
{
|
||||
UserScheme? user = collection.AsQueryable().Where(d => d.Token == token).FirstOrDefault();
|
||||
return user;
|
||||
}
|
||||
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
public class UserScheme
|
||||
{
|
||||
@@ -51,9 +63,7 @@ namespace Common.Database
|
||||
public int Stamina { get; set; }
|
||||
public string SelfDesc { get; set; }
|
||||
public bool IsFirstLogin { get; set; }
|
||||
|
||||
[BsonGuidRepresentation(GuidRepresentation.Standard)]
|
||||
public Guid Token { get; set; }
|
||||
public string Token { get; set; }
|
||||
public int WarshipId { get; set; }
|
||||
public WarshipAvatarData WarshipAvatar { get; set; }
|
||||
public int AssistantAvatarId { get; set; }
|
||||
|
||||
@@ -19,7 +19,10 @@ namespace Common
|
||||
|
||||
[Option(DefaultValue = false)]
|
||||
bool UseLocalCache { get; }
|
||||
|
||||
|
||||
[Option(DefaultValue = true)]
|
||||
bool CreateAccountOnLoginAttempt { get; }
|
||||
|
||||
[Option(DefaultValue = "mongodb://localhost:27017/PemukulPaku")]
|
||||
string DatabaseUri { get; }
|
||||
|
||||
@@ -32,7 +35,7 @@ namespace Common
|
||||
public interface IGameserver
|
||||
{
|
||||
[Option(DefaultValue = "127.0.0.1")]
|
||||
public string Host { get; }
|
||||
public string Host { get; set; }
|
||||
|
||||
[Option(DefaultValue = (uint)(16100))]
|
||||
public uint Port { get; }
|
||||
|
||||
Reference in New Issue
Block a user