This commit is contained in:
@@ -55,8 +55,19 @@ func (s *Server) OnClose(c gnet.Conn, err error) (action gnet.Action) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil { // 恢复 panic,err 为 panic 错误值
|
||||
// 1. 打印错误信息
|
||||
if t, ok := c.Context().(*player.ClientData); ok {
|
||||
if t.Player != nil {
|
||||
if t.Player.Info != nil {
|
||||
cool.Logger.Error(context.TODO(), "OnClose 错误:", t.Player.Info.UserID, err)
|
||||
t.Player.Service.Info.Save(*t.Player.Info)
|
||||
}
|
||||
|
||||
fmt.Println(context.TODO(), "panic 错误:", err)
|
||||
}
|
||||
|
||||
} else {
|
||||
cool.Logger.Error(context.TODO(), "OnClose 错误:", err)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}()
|
||||
@@ -121,7 +132,9 @@ func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action) {
|
||||
if t, ok := c.Context().(*player.ClientData); ok {
|
||||
if t.Player != nil {
|
||||
if t.Player.Info != nil {
|
||||
cool.Logger.Error(context.TODO(), "panic 错误:", t.Player.Info.UserID, err)
|
||||
cool.Logger.Error(context.TODO(), "OnTraffic 错误:", t.Player.Info.UserID, err)
|
||||
t.Player.Service.Info.Save(*t.Player.Info)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -262,11 +275,10 @@ func (s *Server) onevent(c gnet.Conn, v []byte) {
|
||||
// 解析Result(13-16字节)
|
||||
//header.Result = binary.BigEndian.Uint32(v[13:17])
|
||||
// 解析数据部分(17字节之后)
|
||||
header.Data = make([]byte, 0)
|
||||
if len(v) > 17 {
|
||||
header.Data = v[17:]
|
||||
|
||||
} else {
|
||||
header.Data = []byte{} // 数据部分为空时显式初始化
|
||||
}
|
||||
if header.CMD > 1001 {
|
||||
if t.Player == nil {
|
||||
@@ -287,9 +299,6 @@ func (s *Server) onevent(c gnet.Conn, v []byte) {
|
||||
}
|
||||
|
||||
t.LF.Producer().Write(header)
|
||||
// s.workerPool.Submit(func() { //提交任务
|
||||
// t.OnEvent(data)
|
||||
// })
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ func (h Controller) BuyGoldItem(data *item.C2S_GOLD_BUY_PRODUCT, player *player.
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
|
||||
if !player.UseGold(uint32(data.Count) * uint32(pro.JindouPrice) * 100) {
|
||||
if !player.UseGold(int64(data.Count) * int64(pro.JindouPrice) * 100) {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
usegold = uint64(data.Count) * uint64(pro.JindouPrice*100)
|
||||
@@ -138,7 +138,7 @@ func (h Controller) BuyGoldItem(data *item.C2S_GOLD_BUY_PRODUCT, player *player.
|
||||
|
||||
player.SendPackCmd(1105, item.GoldOnlineRemainOutboundInfo{
|
||||
Coin: player.Info.Coins,
|
||||
GoldNumber: player.User.GetGold(uint(player.Info.UserID)),
|
||||
GoldNumber: uint32(player.User.GetGold(uint(player.Info.UserID))),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +123,10 @@ func (h Controller) TogglePetBagWarehouse(
|
||||
|
||||
index, pet, ok := player.FindPet(data.CatchTime)
|
||||
if ok {
|
||||
|
||||
// ========== 新增:index合法性校验 ==========
|
||||
if index < 0 || index >= len(player.Info.PetList) {
|
||||
return result, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
player.Service.Pet.UPdate(*pet)
|
||||
|
||||
player.Info.PetList = append(player.Info.PetList[:index], player.Info.PetList[index+1:]...)
|
||||
|
||||
@@ -41,7 +41,7 @@ func (h Controller) GetPlayerGoldCount(data *item.GoldOnlineRemainInboundInfo, p
|
||||
|
||||
return &item.GoldOnlineRemainOutboundInfo{
|
||||
|
||||
GoldNumber: player.User.GetGold(uint(player.Info.UserID)),
|
||||
GoldNumber: uint32(player.User.GetGold(uint(player.Info.UserID))),
|
||||
Coin: player.Info.Coins,
|
||||
}, 0
|
||||
}
|
||||
|
||||
@@ -120,7 +120,8 @@ func (h Controller) DeleteTask(data *task.DeleteTaskInboundInfo, c *player.Playe
|
||||
if c.Info.GetTask(int(data.TaskId)) != model.Accepted {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
result = &task.DeleteTaskOutboundInfo{TaskId: data.TaskId}
|
||||
result = &task.DeleteTaskOutboundInfo{}
|
||||
result.TaskId = data.TaskId
|
||||
c.Info.SetTask(int(data.TaskId), model.Unaccepted)
|
||||
return &task.DeleteTaskOutboundInfo{}, 0
|
||||
return result, 0
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ type PetReleaseOutboundInfo struct {
|
||||
// 放入背包或者加入仓库
|
||||
type PetReleaseInboundInfo struct {
|
||||
Head common.TomeeHeader `cmd:"2304" struc:"skip"`
|
||||
CatchTime uint32 `json:"catch_time" fieldDescription:"精灵生成时间" autoCodec:"true" uint:"true"`
|
||||
Flag uint32 `json:"flag" fieldDescription:"0为放入仓库,1为放入背包" autoCodec:"true" uint:"true"`
|
||||
CatchTime uint32
|
||||
Flag uint32 `json:"flag" fieldDescription:"0为放入仓库,1为放入背包" autoCodec:"true" uint:"true"`
|
||||
}
|
||||
|
||||
type PetShowInboundInfo struct {
|
||||
|
||||
@@ -51,7 +51,7 @@ func (h *ClientData) Recv(data common.TomeeHeader) {
|
||||
if err := recover(); err != nil { // 恢复 panic,err 为 panic 错误值
|
||||
// 1. 打印错误信息
|
||||
|
||||
cool.Logger.Error(context.TODO(), "panic 错误:", err)
|
||||
cool.Logger.Error(context.TODO(), "Recv 错误:", err)
|
||||
|
||||
}
|
||||
}()
|
||||
@@ -151,7 +151,7 @@ func NewClientData(c gnet.Conn) *ClientData {
|
||||
Conn: c,
|
||||
Wsmsg: &WsCodec{},
|
||||
}
|
||||
cd.LF = lockfree.NewLockfree[common.TomeeHeader](
|
||||
cd.LF = lockfree.NewLockfree(
|
||||
8,
|
||||
cd,
|
||||
lockfree.NewConditionBlockStrategy(),
|
||||
@@ -205,14 +205,14 @@ func (h *ClientData) OnEvent(t common.TomeeHeader) {
|
||||
// 1. 打印错误信息
|
||||
if h.Player != nil {
|
||||
if h.Player.Info != nil {
|
||||
cool.Logger.Error(context.TODO(), "panic 错误:", h.Player.Info.UserID, err)
|
||||
cool.Logger.Error(context.TODO(), "OnEvent 错误:", h.Player.Info.UserID, err)
|
||||
} else {
|
||||
cool.Logger.Error(context.TODO(), "panic 错误:", err)
|
||||
cool.Logger.Error(context.TODO(), "OnEvent 错误:", err)
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
cool.Logger.Error(context.TODO(), "panic 错误:", err)
|
||||
cool.Logger.Error(context.TODO(), "OnEvent 错误:", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ func (p *Player) GetCoins(amount uint32) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (p *Player) UseGold(amount uint32) bool {
|
||||
func (p *Player) UseGold(amount int64) bool {
|
||||
if p.User.GetGold(uint(p.Info.UserID)) < amount {
|
||||
return false
|
||||
}
|
||||
@@ -183,7 +183,7 @@ func (p *Player) SendPack(b []byte) error {
|
||||
return fmt.Errorf("链接错误,取消发包")
|
||||
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
// 添加物品 返回成功添加的物品
|
||||
|
||||
@@ -32,7 +32,7 @@ func (s *BaseOpenService) AdminEPS(ctx g.Ctx) (result *g.Var, err error) {
|
||||
}
|
||||
|
||||
// creatAdminEPS 创建eps
|
||||
func (s *BaseOpenService) creatAdminEPS(ctx g.Ctx) (adminEPS interface{}, err error) {
|
||||
func (s *BaseOpenService) creatAdminEPS(_ g.Ctx) (adminEPS interface{}, err error) {
|
||||
var (
|
||||
baseEpsAdmin = model.NewBaseEpsAdmin()
|
||||
)
|
||||
@@ -134,7 +134,7 @@ func (s *BaseOpenService) AppEPS(ctx g.Ctx) (result *g.Var, err error) {
|
||||
}
|
||||
|
||||
// creatAppEPS 创建app eps
|
||||
func (s *BaseOpenService) creatAppEPS(ctx g.Ctx) (appEPS interface{}, err error) {
|
||||
func (s *BaseOpenService) creatAppEPS(_ g.Ctx) (appEPS interface{}, err error) {
|
||||
var (
|
||||
baseEpsApp = model.NewBaseEpsApp()
|
||||
)
|
||||
|
||||
@@ -53,7 +53,7 @@ func (s *BaseSysDepartmentService) Order(ctx g.Ctx) (err error) {
|
||||
type item struct {
|
||||
Id uint32 `json:"id"`
|
||||
ParentId *uint32 `json:"parentId,omitempty"`
|
||||
ordernum int32 `json:"ordernum"`
|
||||
Ordernum int32 `json:"ordernum"`
|
||||
}
|
||||
|
||||
var data *item
|
||||
|
||||
@@ -67,15 +67,14 @@ func (s *BaseSysUserService) UpdateGold(userId uint32, gold int64) {
|
||||
|
||||
//res.GoldBean, _ = alpacadecimal.NewFromFloat(float64(gold)).Div(alpacadecimal.NewFromFloat(100)).Float64()
|
||||
|
||||
return
|
||||
}
|
||||
func (s *BaseSysUserService) GetGold(userId uint) (res uint32) {
|
||||
func (s *BaseSysUserService) GetGold(userId uint) (res int64) {
|
||||
var res1 model.BaseSysUser
|
||||
m := cool.DBM(s.Model)
|
||||
m.Where("id", userId).FieldsEx("password").Scan(&res1)
|
||||
|
||||
r1 := alpacadecimal.NewFromInt(res1.GoldBean)
|
||||
return uint32(r1.IntPart())
|
||||
return r1.IntPart()
|
||||
}
|
||||
func (s *BaseSysUserService) GetEamil(userId string) (res *model.BaseSysUser) {
|
||||
m := cool.DBM(s.Model)
|
||||
|
||||
@@ -2,25 +2,4 @@ module blazing/modules/space
|
||||
|
||||
go 1.20
|
||||
|
||||
require github.com/gogf/gf/v2 v2.8.0
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.4.0 // indirect
|
||||
github.com/emirpasic/gods v1.18.1 // indirect
|
||||
github.com/fatih/color v1.18.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/go-logr/logr v1.4.2 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/gorilla/websocket v1.5.3 // indirect
|
||||
github.com/grokify/html-strip-tags-go v0.1.0 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/stretchr/testify v1.11.1 // indirect
|
||||
go.opentelemetry.io/otel v1.24.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.24.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.24.0 // indirect
|
||||
golang.org/x/net v0.33.0 // indirect
|
||||
golang.org/x/sys v0.30.0 // indirect
|
||||
golang.org/x/text v0.22.0 // indirect
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user