From 406d9129b01f18fdb8a0c25ac3d32e397a9c3466 Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Thu, 28 Aug 2025 21:57:30 +0000 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=80=80=E5=87=BA=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/data/socket/player.go | 12 ++++++++++++ common/socket/ServerEvent.go | 1 + logic/controller/login.go | 4 +++- modules/blazing/service/reg.go | 3 ++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/common/data/socket/player.go b/common/data/socket/player.go index 979d2760f..abdf2105e 100644 --- a/common/data/socket/player.go +++ b/common/data/socket/player.go @@ -3,6 +3,7 @@ package socket import ( "blazing/common/utils" "blazing/modules/blazing/model" + "blazing/modules/blazing/service" "context" "fmt" "sync" @@ -51,6 +52,7 @@ type Player struct { IsFighting bool context.Context Playerinvite uint32 //当前邀请的玩家ID + Onlinetime uint32 //当前登录时间 } // PlayerOption 定义配置 Player 的函数类型 @@ -85,6 +87,16 @@ func (p *Player) Cheak(b error) { } +// Save 保存玩家数据 +func (p *Player) Save() { + + p.Info.TimeToday = p.Info.TimeToday + uint32(time.Now().Unix()) - uint32(p.Onlinetime) //保存电池时间 + p.Onlinetime = uint32(time.Now().Unix()) + + service.NewUserService(p.Info.UserID).Save(p.Info) + +} + // IsLoggedIn 检查是否已登录 func (lw *Player) IsLoggedIn() bool { lw.mu.Lock() diff --git a/common/socket/ServerEvent.go b/common/socket/ServerEvent.go index 879f9c4a6..c9b469c17 100644 --- a/common/socket/ServerEvent.go +++ b/common/socket/ServerEvent.go @@ -52,6 +52,7 @@ func (s *Server) OnClose(c gnet.Conn, _ error) (action gnet.Action) { t.IsLogin = false socket.Mainplayer.Delete(t.Info.UserID) share.ShareManager.DeleteUserOnline(t.Info.UserID) //设置用户登录服务器 + t.Save() //保存玩家数据 } //} diff --git a/logic/controller/login.go b/logic/controller/login.go index 2a2c3d559..98164da5a 100644 --- a/logic/controller/login.go +++ b/logic/controller/login.go @@ -11,6 +11,7 @@ import ( "blazing/logic/service/space" blservice "blazing/modules/blazing/service" "context" + "time" "github.com/gogf/gf/v2/os/glog" "github.com/jinzhu/copier" @@ -23,11 +24,12 @@ func (h *Controller) Login(data *login.InInfo, c *socket.Conn) (result *login.Ou h.RPCClient.Kick(data.Head.UserID) //先踢人 playerinfo := blservice.NewUserService(data.Head.UserID).Person() t := service.SetPlayer(c, playerinfo) + t.Onlinetime = uint32(time.Now().Unix()) //保存时间戳 copier.Copy(playerinfo, t) //先复制给内存信息 share.ShareManager.SetUserOnline(data.Head.UserID, h.Port) //设置用户登录服务器 t.CompleteLogin() //通知客户端登录成功 - glog.Debug(context.Background(), "登录成功,初始地图 人数:", space.GetSpace(1).Len()) + glog.Debug(context.Background(), "登录成功,初始地图 人数:", space.GetSpace(t.Info.MapID).Len()) result = login.NewOutInfo() //设置登录消息 copier.Copy(playerinfo, result) diff --git a/modules/blazing/service/reg.go b/modules/blazing/service/reg.go index 0812810c8..7acef926a 100644 --- a/modules/blazing/service/reg.go +++ b/modules/blazing/service/reg.go @@ -6,6 +6,7 @@ import ( "context" "encoding/json" "strings" + "time" "github.com/gogf/gf/v2/os/glog" ) @@ -37,7 +38,7 @@ func (s *UserService) Reg(nick string, color uint32) { t1.Nick = nick t1.Color = color - + t1.RegisterTime = uint32(time.Now().Unix())//写入注册时间 t22, err := json.Marshal(t1) if err != nil { return