Files
bl/logic/controller/login.go
昔念 5e01837f78 refactor(logic): 重构逻辑层代码
- 移除未使用的 SocketHandler_Tomee.go、ai.go、effect_1.go 文件
- 更新 player 包名引用,替换原 service 包
- 调整 TomeeHeader 和相关处理逻辑至 player 包
- 更新各控制器中的 Player 引用为 player 包中的类型
- 移除冗余的 GetPlayer 方法,使用新逻辑
2025-09-14 01:35:16 +08:00

92 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package controller
import (
"blazing/common/data/share"
"blazing/common/socket/errorcode"
"blazing/logic/service/common"
"blazing/logic/service/login"
"blazing/logic/service/maps"
"blazing/logic/service/player"
"blazing/logic/service/space"
"blazing/modules/blazing/model"
blservice "blazing/modules/blazing/service"
"context"
"time"
"github.com/gogf/gf/v2/os/glog"
)
func IsToday(t time.Time) bool {
// 获取当前时间
now := time.Now()
// 比较年、月、日是否相同
return t.Year() == now.Year() &&
t.Month() == now.Month() &&
t.Day() == now.Day()
}
// 处理命令: 1001
func (h *Controller) Login(data *login.InInfo, c *player.Conn) (result *login.OutInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
if tt := data.CheakSession(); tt { //说明sid正确
h.RPCClient.Kick(data.Head.UserID) //先踢人
t := player.GetPlayer(c, data.Head.UserID)
t.Service = blservice.NewUserService(data.Head.UserID)
t.Info = t.Service.Person()
t.Info.UserID = data.Head.UserID
t.Onlinetime = uint32(time.Now().Unix()) //保存时间戳
share.ShareManager.SetUserOnline(data.Head.UserID, h.Port) //设置用户登录服务器
if !IsToday(t.Info.LastResetTime) { //判断是否是今天
t.Info.LastResetTime = time.Now()
//每天login时候检查重置时间然后把电池任务挖矿重置
t.Info.TimeToday = 0 //重置电池
go func() {
for i := 400; i < 500; i++ { //每日任务区段
t.Info.TaskList[i] = 0 //重置每日任务
_, ok := t.Service.TaskInfo((uint32(i)))
if ok {
t.Service.TaskSet((uint32(i)), model.TaskInfo{
Info: []uint32{},
})
}
}
}()
}
if t.MapID() > 10000 {
t.Info.MapID = 1
}
t.CompleteLogin() //通知客户端登录成功
glog.Debug(context.Background(), "登录成功,初始地图 人数:", space.GetSpace(t.Info.MapID).Len())
result = login.NewOutInfo() //设置登录消息
result.PlayerInfo = *t.Info
tt := maps.NewOutInfo()
//copier.Copy(t.Info, tt)
t1 := player.NewTomeeHeader(2001, t.Info.UserID)
defer space.GetSpace(t.Info.MapID).Set(t.Info.UserID, t).Range(func(playerID uint32, player common.PlayerI) bool {
player.SendPack(t1.Pack(&tt))
return true
})
return result, 0
} else {
err = errorcode.ErrorCodes.ErrLoginServerError
}
return
}