goofy Goodfeel implementation & SetWarshipAvatar

This commit is contained in:
rafi1212122
2023-06-01 23:26:58 +07:00
parent 31e3c4a814
commit 86dc83d448
8 changed files with 130 additions and 10 deletions

48
Common/Database/Login.cs Normal file
View File

@@ -0,0 +1,48 @@
using MongoDB.Bson;
using MongoDB.Driver;
namespace Common.Database
{
public class Login
{
public static readonly IMongoCollection<LoginScheme> collection = Global.db.GetCollection<LoginScheme>("Logins");
public static bool UserLogin(uint Uid)
{
LoginScheme? LastLogin = GetUserLastLogin(Uid);
if (LastLogin is not null && LastLogin.Id.CreationTime.Date < DateTime.Now.Date)
{
collection.InsertOne(new() { OwnerUid = Uid });
return true;
}
collection.InsertOne(new() { OwnerUid = Uid });
return false;
}
public static List<LoginScheme> GetUserLogins(uint Uid)
{
return collection.AsQueryable().Where(login => login.OwnerUid == Uid).ToList();
}
public static LoginScheme? GetUserLastLogin(uint Uid)
{
return GetUserLogins(Uid).LastOrDefault();
}
public static uint GetUserLoginDays(uint Uid)
{
return (uint)GetUserLogins(Uid).DistinctBy(login => login.Id.CreationTime.Date).Count();
}
}
public class LoginScheme
{
public ObjectId Id { get; set; }
public uint OwnerUid { get; set; }
public uint GetCreationTime()
{
return (uint)((DateTimeOffset)Id.CreationTime).ToUnixTimeSeconds();
}
}
}

View File

@@ -25,5 +25,13 @@ namespace PemukulPaku.GameServer.Game
Avatar.Save();
}
}
public void ResetAvatarsTodayGoodfeel()
{
foreach (AvatarScheme avatar in AvatarList)
{
avatar.TodayHasAddGoodfeel = 0;
}
}
}
}

View File

@@ -0,0 +1,24 @@
using Common.Database;
using Common.Resources.Proto;
namespace PemukulPaku.GameServer.Handlers
{
[PacketCmdId(CmdId.AddGoodfeelReq)]
internal class AddGoodfeelReqHandler : IPacketHandler
{
public void Handle(Session session, Packet packet)
{
AddGoodfeelReq Data = packet.GetDecodedBody<AddGoodfeelReq>();
AvatarScheme? avatar = session.Player.AvatarList.Where(avatar => avatar.AvatarId == Data.AvatarId).FirstOrDefault();
if(avatar != null)
{
avatar.TodayHasAddGoodfeel += (uint)Data.AddGoodfeel;
avatar.TouchGoodfeel += (uint)Data.AddGoodfeel;
session.ProcessPacket(Packet.FromProto(new GetAvatarDataReq() { AvatarIdLists = new uint[] { avatar.AvatarId } }, CmdId.GetAvatarDataReq));
}
session.Send(Packet.FromProto(new AddGoodfeelRsp() { retcode = AddGoodfeelRsp.Retcode.Succ }, CmdId.AddGoodfeelRsp));
}
}
}

View File

@@ -1,4 +1,5 @@
using Common.Resources.Proto;
using Common.Database;
using Common.Resources.Proto;
namespace PemukulPaku.GameServer.Handlers
{
@@ -8,6 +9,7 @@ namespace PemukulPaku.GameServer.Handlers
public void Handle(Session session, Packet packet)
{
GetAvatarDataReq Packet = packet.GetDecodedBody<GetAvatarDataReq>();
LoginScheme LastLogin = Login.GetUserLastLogin(session.Player.User.Uid);
GetAvatarDataRsp Rsp = new()
{
@@ -16,9 +18,9 @@ namespace PemukulPaku.GameServer.Handlers
if (Packet.AvatarIdLists.Contains((uint)0))
{
IEnumerable<Avatar> Avatars = session.Player.AvatarList.Select(avatar =>
IEnumerable<Common.Resources.Proto.Avatar> Avatars = session.Player.AvatarList.Select(avatar =>
{
Avatar a = new()
Common.Resources.Proto.Avatar a = new()
{
AvatarId = avatar.AvatarId,
AvatarArtifact = avatar.AvatarArtifact,
@@ -48,9 +50,9 @@ namespace PemukulPaku.GameServer.Handlers
}
else
{
IEnumerable<Avatar> Avatars = session.Player.AvatarList.Where(avatar => Packet.AvatarIdLists.Contains(avatar.AvatarId)).Select(avatar =>
IEnumerable<Common.Resources.Proto.Avatar> Avatars = session.Player.AvatarList.Where(avatar => Packet.AvatarIdLists.Contains(avatar.AvatarId)).Select(avatar =>
{
Avatar a = new()
Common.Resources.Proto.Avatar a = new()
{
AvatarId = avatar.AvatarId,
AvatarArtifact = avatar.AvatarArtifact,

View File

@@ -1,4 +1,5 @@
using Common.Resources.Proto;
using Common.Database;
using Common.Resources.Proto;
namespace PemukulPaku.GameServer.Handlers
{
@@ -12,7 +13,7 @@ namespace PemukulPaku.GameServer.Handlers
Rsp.LoginLists.Add(new LoginActivityData
{
Id = 581,
LoginDays = 1,
LoginDays = Login.GetUserLoginDays(session.Player.User.Uid),
AcceptTime = session.Player.User.GetCreationTime(),
DurationEndTime = session.Player.User.GetCreationTime() + 604800 * 2
});

View File

@@ -11,6 +11,11 @@ namespace PemukulPaku.GameServer.Handlers
{
UserScheme User = session.Player.User;
if(Login.UserLogin(User.Uid))
{
session.Player.ResetAvatarsTodayGoodfeel();
}
PlayerLoginRsp Rsp = new()
{
retcode = PlayerLoginRsp.Retcode.Succ,

View File

@@ -0,0 +1,31 @@
using Common.Resources.Proto;
namespace PemukulPaku.GameServer.Handlers
{
[PacketCmdId(CmdId.SetWarshipAvatarReq)]
internal class SetWarshipAvatarReqHandler : IPacketHandler
{
public void Handle(Session session, Packet packet)
{
SetWarshipAvatarReq Data = packet.GetDecodedBody<SetWarshipAvatarReq>();
// extra redundancy
if (Data.FirstAvatarId == 0)
Data.FirstAvatarId = 101;
session.Player.User.WarshipAvatar = new()
{
WarshipFirstAvatarId = Data.FirstAvatarId,
WarshipSecondAvatarId = Data.SecondAvatarId
};
GetMainDataRsp MainDataRsp = new()
{
retcode = GetMainDataRsp.Retcode.Succ,
WarshipAvatar = session.Player.User.WarshipAvatar
};
session.Send(Packet.FromProto(MainDataRsp, CmdId.GetMainDataRsp), Packet.FromProto(new SetWarshipAvatarRsp() { retcode = SetWarshipAvatarRsp.Retcode.Succ }, CmdId.SetWarshipAvatarRsp));
}
}
}

View File

@@ -68,7 +68,7 @@ namespace PemukulPaku.GameServer
{
if (Packet.IsValid(packet))
{
ProcessPacket(new Packet(packet));
ProcessPacket(new Packet(packet), true);
}
else
{
@@ -103,7 +103,7 @@ namespace PemukulPaku.GameServer
Server.GetInstance().LogClients();
}
public void ProcessPacket(Packet _packet)
public void ProcessPacket(Packet _packet, bool log = false)
{
string PacketName = Enum.GetName(typeof(CmdId), _packet.CmdId)!;
if(PacketName == "KeepAliveNotify") { LastClientKeepAlive = Global.GetUnixInSeconds(); c.Log(PacketName); return; }
@@ -118,7 +118,8 @@ namespace PemukulPaku.GameServer
return;
}
c.Log(PacketName);
if(log)
c.Log(PacketName);
handler.Handle(this, _packet);
}