自动定时数据落地

This commit is contained in:
bob
2025-08-01 18:05:25 +08:00
parent 96f22a3e48
commit c97bd0ab55
30 changed files with 477 additions and 310 deletions

View File

@@ -16,89 +16,13 @@ public class G2Game_EnterRequestHandler : RouteRPC<Scene, G2Game_EnterRequest, G
{
Log.Debug("收到 G2Game_EnterRequestHandler");
var accountId = request.AccountId;
// 在缓存中检查该账号是否存在
var gameAccountManageComponent = scene.GetComponent<PlayerManageComponent>();
Log.Debug("检查账号是否在缓存中");
if (!gameAccountManageComponent.TryGet(accountId, out var account))
{
// 首先要先到数据库中查询是否有这个账号
account = await PlayerHelper.LoadDataBase(scene, accountId);
// 如果有的话,就直接加入在缓存中就可以了
if (account == null)
{
Log.Debug("检查到账号没有在数据库中,需要创建一个新的账号并且保存到数据库中");
// 如果没有,就要创建一个新的并且保存到数据库。
// 如果不存在,表示这是一个新的账号,需要创建一下这个账号。
account = await PlayerFactory.Create(scene, accountId);
account.Level = 99;
account.NickName = "王麻子";
account.Country = "cn";
account.Exp = 999;
account.Head = "xxx.png";
for (int i = 0; i < 500; i++)
{
var item = Entity.Create<Item>(scene, true, true);
account.Items.Add(item.Id, item);
}
for (int i = 0; i < 500; i++)
{
var item = Entity.Create<Fish>(scene, true, true);
account.Fishes.Add(item.Id, item);
}
// account.Items
account.NeedSave = true;
await account.SaveDataBase();
}
else
{
Log.Debug("检查到账号在数据库中");
}
Log.Debug("把当前账号添加到缓存中");
// 把创建完成的Account放入到缓存中
gameAccountManageComponent.Add(account);
}
else
{
Log.Debug("检测到当前账号已经在缓存中了");
// 如果有延迟下线的计划任务,那就先取消一下。
account.CancelTimeout();
// 如果在Gate的缓存中已经存在了该账号那只能以下几种可能:
// 1、同一客户端发送了重复登录的请求数据。
// 2、客户端经历的断线然后又重新连接到这个服务器上了断线重连
// 3、多个客户端同时登录了这个账号顶号
if (request.GateRouteId == account.SessionRunTimeId)
{
// 如果执行到这里,说明是客户端发送了多次登录的请求,这样的情况下,直接返回就可以了,不需要做任何操作。
return;
}
}
account.LoginTime = TimeHelper.Now;
var account = await gameAccountManageComponent.Online(scene, request.AccountId, request.GateRouteId);
response.RoleRouteId = account.RuntimeId;
if (account.GetComponent<MailComponent>() == null)
{
var mailComponent = await scene.World.DataBase.Query<MailComponent>(account.Id, true);
if (mailComponent == null)
{
//如果没有邮件组件
account.AddComponent<MailComponent>();
}
else
{
account.AddComponent(mailComponent);
}
}
await FTask.CompletedTask;
}
}

View File

@@ -1,6 +0,0 @@
namespace NB.Game;
public class ItemFactory
{
}