Merge branch 'main' of https://cnb.cool/blzing/blazing
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
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))),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -47,19 +47,19 @@ func (h Controller) PetFusion(data *pet.C2S_PetFusion, c *player.Player) (result
|
||||
if Auxpetinfo.Nature == Mcatchpetinfo.Nature {
|
||||
natureId = int32(Auxpetinfo.Nature)
|
||||
}
|
||||
for _, v := range data.Item1 {
|
||||
if c.Service.Item.CheakItem(v) == 0 {
|
||||
return result, errorcode.ErrorCodes.ErrInsufficientItems
|
||||
}
|
||||
|
||||
}
|
||||
resid := int(service.NewPetFusionService().Data(Mcatchpetinfo.ID, Auxpetinfo.ID, Mcatchpetinfo.Level+Auxpetinfo.Level))
|
||||
effect := int(service.NewPetFusionMaterialService().Data(data.Item1))
|
||||
|
||||
if effect == 0 {
|
||||
return result, errorcode.ErrorCodes.ErrSpiritOrbNotExists
|
||||
}
|
||||
for _, v := range data.Item1 {
|
||||
if c.Service.Item.CheakItem(v) == 0 {
|
||||
return &pet.PetFusionInfo{}, 0
|
||||
}
|
||||
|
||||
}
|
||||
for _, v := range data.Item1 {
|
||||
c.Service.Item.UPDATE(v, -1)
|
||||
|
||||
|
||||
@@ -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:]...)
|
||||
|
||||
@@ -1,20 +1,9 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/cool"
|
||||
"blazing/modules/player/service"
|
||||
// // CreatePlayer 处理命令: 1001
|
||||
// func (h Controller) CreatePlayer(data *user.CreatePlayerInboundInfo, c gnet.Conn) (result *user.CreatePlayerOutInfo, err errorcode.ErrorCode) {
|
||||
// data.Nickname = strings.Trim(data.Nickname, "\x00")
|
||||
// service.NewUserService(data.Head.UserID).Info.Reg(cool.Filter.Replace(data.Nickname, '*'), data.Color)
|
||||
|
||||
"blazing/logic/service/user"
|
||||
"strings"
|
||||
|
||||
"github.com/panjf2000/gnet/v2"
|
||||
)
|
||||
|
||||
// CreatePlayer 处理命令: 1001
|
||||
func (h Controller) CreatePlayer(data *user.CreatePlayerInboundInfo, c gnet.Conn) (result *user.CreatePlayerOutInfo, err errorcode.ErrorCode) {
|
||||
data.Nickname = strings.Trim(data.Nickname, "\x00")
|
||||
service.NewUserService(data.Head.UserID).Info.Reg(cool.Filter.Replace(data.Nickname, '*'), data.Color)
|
||||
|
||||
return result, 0
|
||||
}
|
||||
// return result, 0
|
||||
// }
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -61,6 +61,7 @@ func (h *ClientData) OnEvent(data common.TomeeHeader) {
|
||||
} else {
|
||||
cool.Logger.Error(context.TODO(), "panic 错误:", err)
|
||||
}
|
||||
cool.Logger.Error(context.TODO(), "Recv 错误:", err)
|
||||
|
||||
}
|
||||
}()
|
||||
@@ -160,7 +161,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(),
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
|
||||
// 添加物品 返回成功添加的物品
|
||||
|
||||
@@ -111,11 +111,6 @@ func (c *BaseSysUserController) Regrobot(ctx context.Context, req *RegReq) (res
|
||||
|
||||
t1 := service.NewBaseSysUserService().GetPerson(uint32(t.UserId))
|
||||
|
||||
if blazing.NewUserService(uint32(t1.ID)).Info.IsReg() {
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
ser := playerservice.NewUserService(uint32(t1.ID))
|
||||
|
||||
logininfo := ser.Info.Reg(cool.Filter.Replace(strings.Trim(req.Nickname, "\x00"), '*'), req.Color)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -13,7 +13,7 @@ const TableNamePlayerInfo = "player_info"
|
||||
|
||||
type Player struct {
|
||||
*cool.Model
|
||||
PlayerID uint64 `gorm:"not null;index:idx_pet_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
PlayerID uint64 `gorm:"not null;uniqueIndex;index:idx_pet_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
LastResetTime *gtime.Time `struc:"skip" json:"last_reset_time"` // 重置时间,比如电池和每日任务
|
||||
Data PlayerInfo `gorm:"type:jsonb;not null;comment:'全部数据'" json:"data"`
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ func (pet *PetInfo) RandShiny() {
|
||||
|
||||
co := service.NewShinyService().RandShiny(pet.ID)
|
||||
if co != nil {
|
||||
pet.ShinyInfo = append(pet.ShinyInfo, *&co.Color)
|
||||
pet.ShinyInfo = append(pet.ShinyInfo, co.Color)
|
||||
}
|
||||
//o.ShinyInfo[0].ColorMatrixFilter = GenerateRandomOffspringMatrix().Get()
|
||||
//g.Dump(ttt.ShinyInfo)
|
||||
@@ -226,7 +226,7 @@ func (pet *PetInfo) FixShiny() {
|
||||
|
||||
co := service.NewShinyService().FixShiny(pet.ID)
|
||||
if co != nil {
|
||||
pet.ShinyInfo = append(pet.ShinyInfo, *&co.Color)
|
||||
pet.ShinyInfo = append(pet.ShinyInfo, co.Color)
|
||||
}
|
||||
//o.ShinyInfo[0].ColorMatrixFilter = GenerateRandomOffspringMatrix().Get()
|
||||
//g.Dump(ttt.ShinyInfo)
|
||||
|
||||
@@ -29,8 +29,11 @@ func (s *EggService) Get() (out *model.Egg) {
|
||||
s.TestModel(s.Model).Scan(&out)
|
||||
if out != nil {
|
||||
BreedLeftTime := int64(out.Data.StartTime+out.CurEgg.EggID*uint32(time.Hour/1000000000)) - (time.Now().Unix())
|
||||
if cool.Config.ServerInfo.IsVip != 0 {
|
||||
BreedLeftTime = 0
|
||||
}
|
||||
//判断是否繁殖完成
|
||||
if BreedLeftTime < 0 && out.Data.HatchState == 1 {
|
||||
if BreedLeftTime <= 0 && out.Data.HatchState == 1 {
|
||||
out.Data.HatchState = 2
|
||||
} else {
|
||||
out.Data.HatchLeftTime = uint32(BreedLeftTime)
|
||||
@@ -154,7 +157,7 @@ func (s *EggService) GetEgg() *model.PetInfo {
|
||||
shinycont := 0
|
||||
|
||||
if mpets != tt.CurEgg.MalePetID && mpets != tt.CurEgg.FeMalePetID {
|
||||
shinycont = int(tt.CurEgg.EggID)
|
||||
shinycont = int(tt.CurEgg.EggID) * int(tt.CurEgg.EggID)
|
||||
}
|
||||
|
||||
if grand.Meet(shinycont, 100) {
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
csmap "github.com/mhmtszr/concurrent-swiss-map"
|
||||
)
|
||||
|
||||
// 是否注册,如果注册过,那么就会产生用户player信息
|
||||
func (s *InfoService) IsReg() bool {
|
||||
|
||||
m := s.PModel(s.Model)
|
||||
@@ -27,27 +26,34 @@ func (s *InfoService) IsReg() bool {
|
||||
return record
|
||||
}
|
||||
|
||||
// 是否注册,如果注册过,那么就会产生用户player信息
|
||||
|
||||
// 实现注册,id+昵称+颜色
|
||||
func (s *InfoService) Reg(nick string, color uint32) *model.PlayerInfo {
|
||||
if s.IsReg() {
|
||||
return nil
|
||||
|
||||
m := cool.DBM(s.Model).Where("player_id", s.userid)
|
||||
var tt *model.Player
|
||||
m.Scan(&tt)
|
||||
if tt == nil {
|
||||
t := model.NewPlayer()
|
||||
t.PlayerID = uint64(s.userid)
|
||||
//设置用户信息
|
||||
t.Data = model.NewPlayerInfo()
|
||||
t.Data.Nick = nick
|
||||
t.Data.UserID = s.userid
|
||||
t.Data.Color = color
|
||||
t.Data.RegisterTime = uint32(time.Now().Unix()) //写入注册时间
|
||||
|
||||
_, err := cool.DBM(s.Model).Data(t).FieldsEx("id").Insert()
|
||||
if err != nil {
|
||||
glog.Error(context.Background(), err)
|
||||
|
||||
}
|
||||
return &t.Data
|
||||
} else {
|
||||
return &tt.Data
|
||||
}
|
||||
|
||||
t := model.NewPlayer()
|
||||
t.PlayerID = uint64(s.userid)
|
||||
//设置用户信息
|
||||
t.Data = model.NewPlayerInfo()
|
||||
t.Data.Nick = nick
|
||||
t.Data.UserID = s.userid
|
||||
t.Data.Color = color
|
||||
t.Data.RegisterTime = uint32(time.Now().Unix()) //写入注册时间
|
||||
|
||||
_, err := cool.DBM(s.Model).Data(t).FieldsEx("id").Insert()
|
||||
if err != nil {
|
||||
glog.Error(context.Background(), err)
|
||||
|
||||
}
|
||||
return &t.Data
|
||||
}
|
||||
|
||||
func (s *InfoService) Person(userid uint32) (out *model.Player) {
|
||||
|
||||
@@ -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