mirror of
https://github.com/rafi1212122/PemukulPaku
synced 2025-12-12 19:14:34 +01:00
goofy Goodfeel implementation & SetWarshipAvatar
This commit is contained in:
48
Common/Database/Login.cs
Normal file
48
Common/Database/Login.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,5 +25,13 @@ namespace PemukulPaku.GameServer.Game
|
||||
Avatar.Save();
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetAvatarsTodayGoodfeel()
|
||||
{
|
||||
foreach (AvatarScheme avatar in AvatarList)
|
||||
{
|
||||
avatar.TodayHasAddGoodfeel = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
24
GameServer/Handlers/AddGoodfeelReqHandler.cs
Normal file
24
GameServer/Handlers/AddGoodfeelReqHandler.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
|
||||
31
GameServer/Handlers/SetWarshipAvatarReqHandler.cs
Normal file
31
GameServer/Handlers/SetWarshipAvatarReqHandler.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,6 +118,7 @@ namespace PemukulPaku.GameServer
|
||||
return;
|
||||
}
|
||||
|
||||
if(log)
|
||||
c.Log(PacketName);
|
||||
|
||||
handler.Handle(this, _packet);
|
||||
|
||||
Reference in New Issue
Block a user