```
feat(config): 重构配置结构并添加服务器列表支持 - 重命名PortBL字段为GameOnlineID,改进命名语义 - 添加ServerList结构体用于管理服务器配置 - 移除七牛云配置相关字段 - 更新ID生成器使用GameOnlineID参数 fix(server): 调整服务器启动参数和VIP逻辑 - 将启动参数从-port改为-id,统一参数命名 - 更新服务器启动逻辑,基于GameOnlineID获取服务器信息 - 为VIP服务器启用调试模式 - 优化端口可用性检查逻辑 refactor(model): 统一模型基类结构 - 将各模型中的*cool.Model嵌入改为Base基类 - 移除soul.go
This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -29,7 +29,7 @@
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"args": ["-port=2"],
|
||||
"args": ["-id=2"],
|
||||
|
||||
"program": "${workspaceFolder}/logic"
|
||||
}
|
||||
|
||||
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
@@ -6,8 +6,8 @@
|
||||
"targetOS": "linux",
|
||||
"targetArch": "current",
|
||||
"enableRace": false,
|
||||
"enableOptimization": true,
|
||||
"stripSymbols": true,
|
||||
"enableOptimization": false,
|
||||
"stripSymbols": false,
|
||||
"cgoEnabled": false,
|
||||
"buildTags": "",
|
||||
"customLdflags": "",
|
||||
@@ -16,7 +16,7 @@
|
||||
"keepWorkDir": false,
|
||||
"forceRebuild": false,
|
||||
"dryRun": false,
|
||||
"trimPath": true,
|
||||
"trimPath": false,
|
||||
"currentPreset": "dev"
|
||||
},
|
||||
"go.toolsEnvVars": {},
|
||||
|
||||
@@ -1,18 +1,45 @@
|
||||
package coolconfig
|
||||
|
||||
import "github.com/gogf/gf/v2/frame/g"
|
||||
import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// cool config
|
||||
type sConfig struct {
|
||||
AutoMigrate bool `json:"auto_migrate,omitempty"` // 是否自动创建表
|
||||
Eps bool `json:"eps,omitempty"` // 是否开启eps
|
||||
File *file `json:"file,omitempty"` // 文件上传配置
|
||||
Name string `json:"name"` // 项目名称
|
||||
Port string `json:"port"`
|
||||
PortBL uint16 `json:"port_bl"` //这个是命令行输入的参数
|
||||
RPC uint16 //rpc端口
|
||||
GamePort []uint64
|
||||
Qiniu *qiniu `json:"qiniu,omitempty"` // 七牛云配置
|
||||
AutoMigrate bool `json:"auto_migrate,omitempty"` // 是否自动创建表
|
||||
Eps bool `json:"eps,omitempty"` // 是否开启eps
|
||||
File *file `json:"file,omitempty"` // 文件上传配置
|
||||
Name string `json:"name"` // 项目名称
|
||||
Port string `json:"port"`
|
||||
GameOnlineID uint16 `json:"port_bl"` //这个是命令行输入的参数
|
||||
ServerInfo ServerList
|
||||
|
||||
RPC uint16 //rpc端口
|
||||
|
||||
}
|
||||
type ServerList struct {
|
||||
OnlineID uint16 `gorm:"column:online_id;comment:'在线ID';uniqueIndex" json:"online_id"`
|
||||
//服务器名称Desc
|
||||
Name string `gorm:"comment:'服务器名称'" json:"name"`
|
||||
IP string `gorm:"type:string;comment:'服务器IP'" json:"ip"`
|
||||
Port uint16 `gorm:"comment:'端口号,通常是小整数'" json:"port"`
|
||||
IsOpen uint8 `gorm:"default:0;not null;comment:'是否开启'" json:"is_open"`
|
||||
//登录地址
|
||||
LoginAddr string `gorm:"type:string;comment:'登录地址'" json:"login_addr"`
|
||||
//账号
|
||||
Account string `gorm:"type:string;comment:'账号'" json:"account"`
|
||||
//密码
|
||||
Password string `gorm:"type:string;comment:'密码'" json:"password"`
|
||||
CanPort []uint32 `gorm:"type:jsonb;comment:'可连接端口'" json:"can_port"`
|
||||
IsVip uint32 `gorm:"default:0;not null;comment:'是否为VIP服务器'" json:"is_vip"`
|
||||
//服务器异色概率设定ServerList
|
||||
ShinyRate uint8 `gorm:"default:0;comment:'异色概率'" json:"shiny_rate"`
|
||||
//服务器天气设定ServerList
|
||||
WeatherRate uint8 `gorm:"default:0;comment:'天气概率'" json:"weather_rate"`
|
||||
|
||||
//服务器属主Desc
|
||||
Owner uint32 `gorm:"comment:'服务器属主'" json:"owner"`
|
||||
Desc string `gorm:"comment:'服务器描述'" json:"desc"`
|
||||
}
|
||||
|
||||
// OSS相关配置
|
||||
@@ -57,14 +84,6 @@ func newConfig() *sConfig {
|
||||
},
|
||||
}
|
||||
|
||||
// 七牛云配置
|
||||
config.Qiniu = &qiniu{
|
||||
AccessKey: GetCfgWithDefault(ctx, "blazing.qiniu.ak", g.NewVar("")).String(),
|
||||
SecretKey: GetCfgWithDefault(ctx, "blazing.qiniu.sk", g.NewVar("")).String(),
|
||||
Bucket: GetCfgWithDefault(ctx, "blazing.qiniu.bucket", g.NewVar("")).String(),
|
||||
CDN: GetCfgWithDefault(ctx, "blazing.qiniu.cdn", g.NewVar("")).String(),
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
|
||||
12
common/cool/gdb.go
Normal file
12
common/cool/gdb.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package cool
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func SetTest(m g.Map) g.Map {
|
||||
if Config.ServerInfo.IsVip != 0 {
|
||||
m["is_vip"] = Config.ServerInfo.IsVip
|
||||
}
|
||||
return m
|
||||
}
|
||||
@@ -33,7 +33,7 @@ var (
|
||||
|
||||
)
|
||||
var Filter *sensitive.Manager
|
||||
var DefaultGenerator = utils.NewGen(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC), uint8(Config.PortBL))
|
||||
var DefaultGenerator = utils.NewGen(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC), uint8(Config.GameOnlineID))
|
||||
|
||||
func init() {
|
||||
// 创建 IdGeneratorOptions 对象,可在构造函数中输入 WorkerId:
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/model"
|
||||
|
||||
"context"
|
||||
"blazing/modules/config/service"
|
||||
|
||||
"github.com/butoften/array"
|
||||
)
|
||||
|
||||
func GetServerInfoList() []ServerInfo {
|
||||
dictInfoModel1 := model.NewServerList()
|
||||
|
||||
var ret []model.ServerList
|
||||
cool.DBM(dictInfoModel1).Scan(&ret)
|
||||
ret := service.NewServerService().GetServer()
|
||||
|
||||
//fmt.Println(t)
|
||||
var ret1 []ServerInfo
|
||||
// ip, _ := service.NewBaseSysParamService().DataByKey(context.Background(), "server_ip")
|
||||
@@ -21,28 +17,34 @@ func GetServerInfoList() []ServerInfo {
|
||||
|
||||
for _, v := range ret {
|
||||
tt := newServerInfo()
|
||||
tt.OnlineID = uint32(v.OnlineID)
|
||||
|
||||
tt.IP = v.IP
|
||||
if v.IsVip != 0 {
|
||||
tt.UserCnt = 300
|
||||
// tt.Friends = v.Friends
|
||||
if v.IsOpen == 1 {
|
||||
tt.OnlineID = uint32(v.OnlineID)
|
||||
|
||||
}
|
||||
tt.Port = v.Port
|
||||
tt.IP = v.IP
|
||||
if v.IsVip != 0 {
|
||||
tt.UserCnt = 300
|
||||
|
||||
t, ok := cool.GetClient(v.Port)
|
||||
|
||||
if ok {
|
||||
cool.Logger.Info(context.TODO(), "服务器假踢人")
|
||||
err := t.KickPerson(0) //实现指定服务器踢人
|
||||
|
||||
if err == nil {
|
||||
// tt.Friends = v.Friends
|
||||
ret1 = append(ret1, *tt)
|
||||
}
|
||||
|
||||
tt.Name = v.Name
|
||||
tt.Port = v.Port
|
||||
ret1 = append(ret1, *tt)
|
||||
}
|
||||
|
||||
//t, ok := cool.GetClient(v.Port)
|
||||
|
||||
// if ok {
|
||||
// cool.Logger.Info(context.TODO(), "服务器假踢人")
|
||||
// err := t.KickPerson(0) //实现指定服务器踢人
|
||||
|
||||
// if err == nil {
|
||||
// // tt.Friends = v.Friends
|
||||
// ret1 = append(ret1, *tt)
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
array.Sort(&ret1, func(a ServerInfo, b ServerInfo) bool {
|
||||
@@ -89,6 +91,7 @@ func NewInInfo() *CommendSvrInfo {
|
||||
type ServerInfo struct {
|
||||
// 连接ID, 即服务器序号
|
||||
OnlineID uint32
|
||||
Name string `struc:"[16]byte"` // 定长模式:16字节
|
||||
// 当前服务器玩家在线数量, 供SWF显示
|
||||
UserCnt uint32
|
||||
// 服务器IP, 16字节UTF-8, 不足16补齐到16
|
||||
|
||||
@@ -244,9 +244,18 @@ func QueryIPDat(ipv4 string) (location *Location, err error) {
|
||||
var offset uint32 = 0
|
||||
for {
|
||||
mid := posA + (((posZ-posA)/indexLen)>>1)*indexLen
|
||||
// if int(mid+indexLen) > len(data) {
|
||||
// return nil, errors.New("ip not found")
|
||||
// }
|
||||
if int(mid+indexLen) > len(data) {
|
||||
r, _ := LookupIP(ipv4, "json")
|
||||
if r != nil {
|
||||
location := &Location{ISP: r.ISP, IP: r.IP, Country: r.CountryName, District: r.CountryCode2}
|
||||
|
||||
locationCache.Store(ipv4, location)
|
||||
return location, nil
|
||||
} else {
|
||||
return nil, errors.New("ip not found")
|
||||
}
|
||||
|
||||
}
|
||||
buf := data[mid : mid+indexLen]
|
||||
_ip := binary.LittleEndian.Uint32(buf[:4])
|
||||
if posZ-posA == indexLen {
|
||||
|
||||
@@ -51,8 +51,8 @@ func main() {
|
||||
// go cool.ListenFunc(gctx.New())
|
||||
// }
|
||||
// 解析命令行参数
|
||||
cool.Config.PortBL = gcmd.GetOpt("port", "1").Uint16()
|
||||
go Start(cool.Config.PortBL) //注入service
|
||||
cool.Config.GameOnlineID = gcmd.GetOpt("id", "1").Uint16()
|
||||
go Start() //注入service
|
||||
// if cool.Config.PortBL == 1 || cool.Config.PortBL == 2 { //只分析1服务器的
|
||||
// go PprofWeb()
|
||||
// }
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"blazing/common/data/xmlres"
|
||||
"blazing/common/rpc"
|
||||
"blazing/common/socket"
|
||||
"blazing/cool"
|
||||
|
||||
"blazing/logic/controller"
|
||||
|
||||
@@ -53,14 +54,15 @@ func isPortAvailable(port uint32) bool {
|
||||
|
||||
// Start 启动服务器
|
||||
// 如果id是0,那就是login server
|
||||
func Start(serverID uint16) {
|
||||
// 确定端口
|
||||
r := blservice.NewLoginServiceService().GetServerID(serverID)
|
||||
if r.IsVip == 1 {
|
||||
func Start() {
|
||||
serverID := cool.Config.GameOnlineID
|
||||
cool.Config.ServerInfo = blservice.NewLoginServiceService().GetServerID(serverID).ServerList
|
||||
|
||||
if cool.Config.ServerInfo.IsVip == 1 {
|
||||
g.DB().SetDebug(true)
|
||||
}
|
||||
|
||||
port, err := determinePort(r.CanPort)
|
||||
port, err := determinePort(cool.Config.ServerInfo.CanPort)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to determine port: %v", err)
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ func (p *Player) genMonster() {
|
||||
}
|
||||
|
||||
}
|
||||
if cool.Config.PortBL == 2 { //测试服,百分百异色
|
||||
if cool.Config.ServerInfo.IsVip != 0 { //测试服,百分百异色
|
||||
p.OgreInfo.Data[i].RandSHiny()
|
||||
}
|
||||
if xmlres.PetMAP[int(p.OgreInfo.Data[i].Id)].CatchRate != 0 && grand.Meet(7, 1000) {
|
||||
|
||||
@@ -13,6 +13,11 @@ import (
|
||||
|
||||
// Save 保存玩家数据
|
||||
func (p *Player) Save() {
|
||||
if cool.Config.ServerInfo.IsVip != 0 {
|
||||
cool.Logger.Info(context.TODO(), "测试服不保存玩家数据", p.Info.UserID)
|
||||
|
||||
return
|
||||
}
|
||||
if p.Info == nil {
|
||||
return
|
||||
|
||||
|
||||
@@ -6,9 +6,11 @@ import (
|
||||
|
||||
"blazing/modules/base/model"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/xiaoqidun/qqwry"
|
||||
)
|
||||
|
||||
type BaseSysLogService struct {
|
||||
@@ -38,6 +40,14 @@ func NewBaseSysLogService() *BaseSysLogService {
|
||||
// location.District,
|
||||
// location.ISP,
|
||||
// )
|
||||
r, _ := gconv.Map(data)["list"].(gdb.Result)
|
||||
for _, v := range r {
|
||||
ipaddr, err := qqwry.QueryIP(v.Map()["ip"].(string))
|
||||
if err == nil {
|
||||
v.GMap().Set("ipAddr", ipaddr)
|
||||
}
|
||||
|
||||
}
|
||||
return data
|
||||
},
|
||||
},
|
||||
|
||||
@@ -54,6 +54,11 @@ func (s *BaseSysUserService) UpdateGold(userId uint32, gold int64) {
|
||||
// Value: 1,
|
||||
// },
|
||||
// }
|
||||
|
||||
if cool.Config.ServerInfo.IsVip != 0 {
|
||||
cool.Logger.Info(context.TODO(), "测试服不操作金币")
|
||||
return
|
||||
}
|
||||
m := cool.DBM(s.Model).Where("id", userId)
|
||||
m.Increment("goldbean", gold)
|
||||
// // UPDATE `article` SET `views`=`views`+1 WHERE `id`=1
|
||||
|
||||
@@ -12,12 +12,12 @@ const (
|
||||
|
||||
// PetBargeListInfo 精灵捕捉击杀数量核心模型(简化版,直接记录数量,摒弃状态判断)
|
||||
type PetBargeListInfo struct {
|
||||
*cool.Model `json:"-" gorm:"embedded"` // 嵌入通用Model(ID/创建时间/更新时间,不参与json序列化)
|
||||
PlayerID uint64 `gorm:"not null;index:idx_milestone_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
PetId uint32 `gorm:"not null;default:0;comment:'精灵ID,关联config_pet_boss表主键'" json:"pet_id" description:"精灵ID"`
|
||||
EnCntCnt uint32 `gorm:"not null;default:0;comment:'预留未知字段,暂未使用'" json:"en_cnt_cnt" description:"未知"`
|
||||
CatchedCount uint32 `gorm:"not null;default:0;comment:'精灵捕捉总数量'" json:"catched_count" description:"捕捉数量"` // 替换原IsCatched,记录捕捉总数
|
||||
KilledCount uint32 `gorm:"not null;default:0;comment:'精灵击杀总数量'" json:"killed_count" description:"击杀数量"` // 替换原IsKilled,记录击杀总数
|
||||
Base
|
||||
PlayerID uint64 `gorm:"not null;index:idx_milestone_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
PetId uint32 `gorm:"not null;default:0;comment:'精灵ID,关联config_pet_boss表主键'" json:"pet_id" description:"精灵ID"`
|
||||
EnCntCnt uint32 `gorm:"not null;default:0;comment:'预留未知字段,暂未使用'" json:"en_cnt_cnt" description:"未知"`
|
||||
CatchedCount uint32 `gorm:"not null;default:0;comment:'精灵捕捉总数量'" json:"catched_count" description:"捕捉数量"` // 替换原IsCatched,记录捕捉总数
|
||||
KilledCount uint32 `gorm:"not null;default:0;comment:'精灵击杀总数量'" json:"killed_count" description:"击杀数量"` // 替换原IsKilled,记录击杀总数
|
||||
}
|
||||
|
||||
// -------------------------- 核心配套方法 --------------------------
|
||||
@@ -35,11 +35,7 @@ func (*PetBargeListInfo) GroupName() string {
|
||||
// NewPetBargeListInfo 创建精灵捕捉击杀数量实例(初始化默认值)
|
||||
func NewPetBargeListInfo() *PetBargeListInfo {
|
||||
return &PetBargeListInfo{
|
||||
Model: cool.NewModel(),
|
||||
PetId: 0,
|
||||
EnCntCnt: 0,
|
||||
CatchedCount: 0, // 默认捕捉数量为0
|
||||
KilledCount: 0, // 默认击杀数量为0
|
||||
Base: *NewBase(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package model
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// 表名常量定义:金豆消费记录表
|
||||
@@ -13,7 +12,7 @@ const (
|
||||
// 通过金豆消费时间来确认金豆物品的购买重置周期
|
||||
// GoldBeanConsume 金豆消费核心模型(与数据库表字段一一对应,存储消费明细)
|
||||
type GoldBeanConsume struct {
|
||||
*cool.Model `json:"-" gorm:"embedded"` // 嵌入通用Model(ID/创建时间/更新时间,不参与json序列化)
|
||||
Base
|
||||
|
||||
UID uint32 `gorm:"not null;default:0;index;comment:'玩家唯一ID,关联玩家表主键'" json:"uid" description:"玩家ID"`
|
||||
ConsumeNum uint32 `gorm:"not null;default:0;comment:'金豆消费数量(非负数)'" json:"consume_num" description:"消费金豆数量"`
|
||||
@@ -21,13 +20,6 @@ type GoldBeanConsume struct {
|
||||
BeforeBalance uint32 `gorm:"not null;default:0;comment:'消费前金豆余额'" json:"before_balance" description:"消费前余额"`
|
||||
}
|
||||
|
||||
// GoldBeanConsumeEX 金豆消费扩展模型(用于前端/业务层展示,补充非存储字段)
|
||||
type GoldBeanConsumeEX struct {
|
||||
GoldBeanConsume // 嵌入核心消费模型
|
||||
UserName string `json:"user_name" description:"玩家昵称"` // 关联玩家表查询,前端展示用
|
||||
ConsumeTypeDesc string `json:"consume_type_desc" description:"消费类型描述"` // 如"购买道具"/"扭蛋抽奖"
|
||||
}
|
||||
|
||||
// -------------------------- 核心配套方法 --------------------------
|
||||
|
||||
// TableName 指定GoldBeanConsume对应的数据库表名(遵循项目规范)
|
||||
@@ -43,24 +35,10 @@ func (*GoldBeanConsume) GroupName() string {
|
||||
// NewGoldBeanConsume 创建金豆消费记录实例(初始化通用Model及默认值)
|
||||
func NewGoldBeanConsume() *GoldBeanConsume {
|
||||
return &GoldBeanConsume{
|
||||
Model: cool.NewModel(),
|
||||
Base: *NewBase(),
|
||||
}
|
||||
}
|
||||
|
||||
// ValidateConsume 校验消费记录的合法性(避免无效/非法数据)
|
||||
func (g *GoldBeanConsume) ValidateConsume() error {
|
||||
// 校验玩家ID
|
||||
if g.UID == 0 {
|
||||
return errors.New("玩家ID不能为空")
|
||||
}
|
||||
// 校验消费数量
|
||||
if g.ConsumeNum <= 0 {
|
||||
return errors.New("金豆消费数量必须大于0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// -------------------------- 表结构自动同步 --------------------------
|
||||
func init() {
|
||||
// 程序启动时自动创建/同步金豆消费记录表
|
||||
|
||||
12
modules/blazing/model/base.go
Normal file
12
modules/blazing/model/base.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package model
|
||||
|
||||
import "blazing/cool"
|
||||
|
||||
type Base struct {
|
||||
*cool.Model
|
||||
|
||||
//是否测试服ItemCnt
|
||||
IsVip uint32 `gorm:"default:0;not null;comment:'是否为VIP服务器'" json:"is_vip"`
|
||||
}
|
||||
|
||||
func NewBase() *Base { return &Base{} }
|
||||
@@ -30,7 +30,7 @@ const TableNameMilestone = "milestone"
|
||||
|
||||
// Milestone 数据库存储结构体,映射milestone表
|
||||
type Milestone struct {
|
||||
*cool.Model
|
||||
Base
|
||||
PlayerID uint64 `gorm:"not null;index:idx_milestone_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
DoneType EnumMilestone `gorm:"not null;comment:'里程碑类型'" json:"done_type"`
|
||||
Args string `gorm:"type:text;not null;comment:'里程碑ID'" json:"args"`
|
||||
@@ -78,7 +78,7 @@ func (*Milestone) GroupName() string {
|
||||
// NewMilestone 创建新里程碑实例
|
||||
func NewMilestone() *Milestone {
|
||||
return &Milestone{
|
||||
Model: cool.NewModel(),
|
||||
Base: *NewBase(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,11 @@ const TableNamePlayerBagItem = "player_bag_item"
|
||||
|
||||
// PlayerBagItem mapped from table <player_bag_item>
|
||||
type Item struct {
|
||||
*cool.Model
|
||||
Base
|
||||
PlayerID uint64 `gorm:"not null;index:idx_player_bag_item_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
// 物品Id,
|
||||
ItemId uint32 `json:"item_id"`
|
||||
|
||||
// 物品数量,
|
||||
ItemCnt uint32 `json:"item_cnt"`
|
||||
}
|
||||
@@ -40,7 +41,7 @@ func (*Item) GroupName() string {
|
||||
// NewPlayerBagItem create a new PlayerBagItem
|
||||
func NewPlayerBag() *Item {
|
||||
return &Item{
|
||||
Model: cool.NewModel(),
|
||||
Base: *NewBase(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ const TableNamePet = "pet"
|
||||
|
||||
// Pet mapped from table <pet>
|
||||
type Pet struct {
|
||||
*cool.Model
|
||||
Base
|
||||
PlayerID uint32 `gorm:"not null;index:idx_pet_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
Free int `gorm:"not null;default:0;comment:'是否放生'" json:"free"` //"0为放入仓库,1为放入背包
|
||||
CatchTime uint32 `gorm:"not null;unique;comment:'捕捉时间'" json:"catch_time"` //唯一键
|
||||
@@ -392,7 +392,7 @@ func (*Pet) GroupName() string {
|
||||
// NewPet create a new Pet
|
||||
func NewPet() *Pet {
|
||||
return &Pet{
|
||||
Model: cool.NewModel(),
|
||||
Base: *NewBase(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,14 +10,14 @@ const TableNameBaseHouse = "room_house"
|
||||
// NewBaseHouse 构造函数:创建基地房型实例
|
||||
func NewBaseHouse() *BaseHouse {
|
||||
return &BaseHouse{
|
||||
Model: cool.NewModel(),
|
||||
Base: *NewBase(),
|
||||
}
|
||||
}
|
||||
|
||||
// BaseHouse 基地房型核心结构体
|
||||
// 包含:基地展示精灵、基地拥有物品、基地摆放物品三大核心字段
|
||||
type BaseHouse struct {
|
||||
*cool.Model // 继承基础Model(包含ID、创建时间、更新时间等通用字段)
|
||||
Base
|
||||
|
||||
// 基础关联字段
|
||||
PlayerID uint64 `gorm:"not null;index:idx_player_house;comment:'所属玩家ID'" json:"player_id"`
|
||||
|
||||
@@ -10,7 +10,7 @@ const TableNameSignInRecord = "player_sign_in_record"
|
||||
// SignInRecord 玩家签到明细记录表
|
||||
// 记录玩家每一次的签到行为,关联签到活动表
|
||||
type SignInRecord struct {
|
||||
*cool.Model // 嵌入基础Model(主键、创建/更新时间等通用字段)
|
||||
Base
|
||||
|
||||
// 核心关联字段
|
||||
PlayerID uint32 `gorm:"not null;index:idx_player_id;comment:'玩家ID'" json:"player_id"`
|
||||
@@ -34,7 +34,7 @@ func (*SignInRecord) GroupName() string {
|
||||
// NewSignInRecord 创建签到明细记录实例(初始化基础Model)
|
||||
func NewSignInRecord() *SignInRecord {
|
||||
return &SignInRecord{
|
||||
Model: cool.NewModel(),
|
||||
Base: *NewBase(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
)
|
||||
|
||||
const TableNameSoulOrb = "soul_orb"
|
||||
|
||||
// SoulOrb mapped from table <soul_orb>
|
||||
type SoulOrb struct {
|
||||
*cool.Model
|
||||
PlayerID uint64 `gorm:"not null;index:idx_soul_orb_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
Data string `gorm:"type:text;not null;comment:'全部数据'" json:"data"`
|
||||
}
|
||||
|
||||
type SoulInfo struct {
|
||||
ItemID int64 `gorm:"not null;comment:'对应物品ID'" json:"item_id"`
|
||||
ObtainTime int64 `gorm:"not null;comment:'捕获时间(时间戳)'" json:"obtain_time"`
|
||||
StartHatchTime string `gorm:"comment:'开始孵化时间'" json:"start_hatch_time"`
|
||||
HatchTime int32 `gorm:"not null;default:0;comment:'剩余孵化时间(秒)'" json:"hatch_time"`
|
||||
PetTypeID int32 `gorm:"not null;comment:'精灵类型ID/精灵图鉴ID'" json:"pet_type_id"`
|
||||
IndividualValue int16 `gorm:"not null;comment:'个体值(DV)'" json:"individual_value"`
|
||||
Nature int16 `gorm:"not null;comment:'性格类型'" json:"nature"`
|
||||
AbilityTypeEnum int16 `gorm:"comment:'特性枚举'" json:"ability_type_enum"`
|
||||
Shiny int32 `gorm:"not null;default:0;comment:'是否为闪光宠物(1=是,0=否)'" json:"shiny"`
|
||||
Level int16 `gorm:"not null;default:1;comment:'当前等级'" json:"level"`
|
||||
CurrentExp int32 `gorm:"not null;default:0;comment:'当前等级已获得经验值'" json:"current_exp"`
|
||||
EvHP int16 `gorm:"not null;default:0;comment:'生命值学习力'" json:"ev_hp"`
|
||||
EvAttack int16 `gorm:"not null;default:0;comment:'攻击学习力'" json:"ev_attack"`
|
||||
EvDefense int16 `gorm:"not null;default:0;comment:'防御学习力'" json:"ev_defense"`
|
||||
EvSpecialAttack int16 `gorm:"not null;default:0;comment:'特殊攻击学习力'" json:"ev_special_attack"`
|
||||
EvSpecialDefense int16 `gorm:"not null;default:0;comment:'特殊防御学习力'" json:"ev_special_defense"`
|
||||
EvSpeed int16 `gorm:"not null;default:0;comment:'速度学习力'" json:"ev_speed"`
|
||||
}
|
||||
|
||||
// TableName SoulOrb's table name
|
||||
func (*SoulOrb) TableName() string {
|
||||
return TableNameSoulOrb
|
||||
}
|
||||
|
||||
// GroupName SoulOrb's table group
|
||||
func (*SoulOrb) GroupName() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
// NewSoulOrb create a new SoulOrb
|
||||
func NewSoulOrb() *SoulOrb {
|
||||
return &SoulOrb{
|
||||
Model: cool.NewModel(),
|
||||
}
|
||||
}
|
||||
|
||||
// init 创建表
|
||||
func init() {
|
||||
cool.CreateTable(&SoulOrb{})
|
||||
}
|
||||
@@ -9,13 +9,13 @@ const TableNameResourceCollection = "talk"
|
||||
|
||||
func NewTalk() *Talk {
|
||||
return &Talk{
|
||||
Model: cool.NewModel(),
|
||||
Base: *NewBase(),
|
||||
}
|
||||
}
|
||||
|
||||
// ResourceCollection 记录玩家每种资源的采集计数
|
||||
type Talk struct {
|
||||
*cool.Model
|
||||
Base
|
||||
PlayerID uint64 `gorm:"not null;index:idx_player_resource;comment:'所属玩家ID'" json:"player_id"`
|
||||
TalkID uint32 `gorm:"not null;comment:'资源ID'" json:"talk_id"`
|
||||
Count uint32 `gorm:"not null;comment:'采集计数'" json:"count"`
|
||||
|
||||
@@ -9,7 +9,7 @@ const TableNameTask = "task"
|
||||
|
||||
// Task mapped from table <task>
|
||||
type Task struct {
|
||||
*cool.Model
|
||||
Base
|
||||
PlayerID uint64 `gorm:"not null;index:idx_task_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
TaskID uint32 `gorm:"not null;comment:'任务ID'" json:"task_id"`
|
||||
Data string `gorm:"type:jsonb;not null;comment:'全部数据'" json:"data"`
|
||||
@@ -45,7 +45,7 @@ func (t *Task) SetData(t1 string) {
|
||||
// NewPlayerInfo create a new PlayerInfo
|
||||
func NewTask() *Task {
|
||||
return &Task{
|
||||
Model: cool.NewModel(),
|
||||
Base: *NewBase(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ const TableNamePlayerTitle = "player_title"
|
||||
|
||||
// PlayerTitle 对应数据库表 <player_title>
|
||||
type Title struct {
|
||||
*cool.Model
|
||||
Base
|
||||
PlayerID uint64 `gorm:"not null;index:idx_player_title_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
TitleID uint32 `gorm:"not null;comment:'称号ID'" json:"title_id"`
|
||||
//可用称号
|
||||
@@ -37,7 +37,7 @@ func (*Title) GroupName() string {
|
||||
// NewPlayerTitle 创建一个新的称号记录
|
||||
func NewPlayerTitle() *Title {
|
||||
return &Title{
|
||||
Model: cool.NewModel(),
|
||||
Base: *NewBase(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
@@ -23,11 +24,16 @@ func NewBargeService(id uint32) *BargeService {
|
||||
}
|
||||
|
||||
func (s *BargeService) Update(petid uint32, isskill bool) {
|
||||
if t, _ := s.GModel(s.Model).Where("pet_id", petid).Count(); t != 0 {
|
||||
|
||||
if cool.Config.ServerInfo.IsVip != 0 {
|
||||
cool.Logger.Info(context.TODO(), "测试服不消耗物品玩家数据", s.userid)
|
||||
return
|
||||
}
|
||||
if t, _ := s.PModel(s.Model).Where("pet_id", petid).Count(); t != 0 {
|
||||
if isskill {
|
||||
s.GModel(s.Model).Where("pet_id", petid).Increment("killed_count", 1)
|
||||
s.PModel(s.Model).Where("pet_id", petid).Increment("killed_count", 1)
|
||||
} else {
|
||||
s.GModel(s.Model).Where("pet_id", petid).Increment("catched_count", 1)
|
||||
s.PModel(s.Model).Where("pet_id", petid).Increment("catched_count", 1)
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -42,30 +48,13 @@ func (s *BargeService) Update(petid uint32, isskill bool) {
|
||||
} else {
|
||||
r["catched_count"] = 1
|
||||
}
|
||||
s.GModel(s.Model).Data(r).Insert()
|
||||
s.PModel(s.Model).Data(r).Insert()
|
||||
}
|
||||
|
||||
}
|
||||
func (s *BargeService) Get(start, end uint32) []model.PetBargeListInfo {
|
||||
var Barges []model.PetBargeListInfo
|
||||
s.GModel(s.Model).WhereBetween("pet_id", start, end).Scan(&Barges)
|
||||
s.PModel(s.Model).WhereBetween("pet_id", start, end).Scan(&Barges)
|
||||
return Barges
|
||||
|
||||
}
|
||||
|
||||
// // BargeCheck 获取玩家当前的Barge数据
|
||||
// // todo 待实现xml解析判断是否溢出
|
||||
// func (s *BargeService) Exec(t func(map[uint32]uint32) bool) {
|
||||
|
||||
// m1 := s.GModel(s.Model)
|
||||
|
||||
// var Barges model.Barge
|
||||
// m1.Scan(&Barges)
|
||||
|
||||
// ok := t(Barges)
|
||||
// if ok {
|
||||
// Barges.PlayerID = uint64(s.userid)
|
||||
// m1.Save(Barges)
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
@@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
@@ -13,8 +14,12 @@ type DoneService struct {
|
||||
}
|
||||
|
||||
func (s *DoneService) Exec(data model.EnumMilestone, id []uint32, fn func(*model.MilestoneEX) bool) {
|
||||
if cool.Config.ServerInfo.IsVip != 0 {
|
||||
cool.Logger.Info(context.TODO(), "测试服不消耗物品玩家数据", s.userid)
|
||||
return
|
||||
}
|
||||
arss := strings.Join(gconv.Strings(id), "-")
|
||||
m := s.GModel(s.Model).Where("done_type", data).Where("args", arss)
|
||||
m := s.PModel(s.Model).Where("done_type", data).Where("args", arss)
|
||||
var tt *model.MilestoneEX
|
||||
m.Scan(&tt)
|
||||
if tt == nil {
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
// 是否注册,如果注册过,那么就会产生用户player信息
|
||||
func (s *InfoService) IsReg() bool {
|
||||
|
||||
m := s.GModel(s.Model)
|
||||
m := s.PModel(s.Model)
|
||||
|
||||
record, err := m.One()
|
||||
if err != nil {
|
||||
@@ -124,7 +124,7 @@ func (s *InfoService) Kick(id uint32) {
|
||||
}
|
||||
func (s *InfoService) Save(data model.PlayerInfo) {
|
||||
|
||||
m := s.GModel(s.Model)
|
||||
m := s.PModel(s.Model)
|
||||
var tt model.PlayerEX
|
||||
m.Scan(&tt)
|
||||
tt.Data = data
|
||||
|
||||
@@ -9,36 +9,47 @@ import (
|
||||
)
|
||||
|
||||
func (s *ItemService) Get(min, max uint32) []model.Item {
|
||||
|
||||
//todo待测试
|
||||
var ttt []model.Item
|
||||
s.GModel(s.Model).Where(g.Map{
|
||||
m := s.TestModel(s.Model).Where(g.Map{
|
||||
"item_id <=": max,
|
||||
"item_id >=": min,
|
||||
}).Scan(&ttt)
|
||||
})
|
||||
|
||||
var ttt []model.Item
|
||||
m.Scan(&ttt)
|
||||
|
||||
return ttt
|
||||
|
||||
}
|
||||
func (s *ItemService) UPDATE(id uint32, count int) {
|
||||
if t, _ := s.GModel(s.Model).Where("item_id", id).Count(); t != 0 {
|
||||
_, err := s.GModel(s.Model).Where("item_id", id).Increment("item_cnt", count)
|
||||
if cool.Config.ServerInfo.IsVip != 0 && count < 0 {
|
||||
cool.Logger.Info(context.TODO(), "测试服不消耗物品玩家数据", s.userid)
|
||||
return
|
||||
}
|
||||
m := s.TestModel(s.Model)
|
||||
|
||||
if t, _ := m.Where("item_id", id).Exist(); t {
|
||||
_, err := m.Where("item_id", id).Increment("item_cnt", count)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
} else {
|
||||
s.GModel(s.Model).Data(g.Map{
|
||||
data := g.Map{
|
||||
"player_id": s.userid,
|
||||
"item_id": id,
|
||||
"item_cnt": count,
|
||||
}).Insert()
|
||||
}
|
||||
data = cool.SetTest(data)
|
||||
|
||||
m.Data(data).Insert()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *ItemService) CheakItem(id uint32) uint32 {
|
||||
var ttt model.Item
|
||||
s.GModel(s.Model).Where("item_id", id).Scan(&ttt)
|
||||
m := s.TestModel(s.Model)
|
||||
|
||||
m.Where("item_id", id).Scan(&ttt)
|
||||
return ttt.ItemCnt
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
// 获取精灵信息 0是仓库,1是放生
|
||||
func (s *PetService) PetInfo(flag int) []model.PetEX {
|
||||
var tt []model.PetEX
|
||||
err := cool.DBM(s.Model).Where("player_id", s.userid).Where("free", flag).Scan(&tt)
|
||||
err := s.TestModel(s.Model).Where("free", flag).Scan(&tt)
|
||||
if err != nil {
|
||||
return []model.PetEX{}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ func (s *PetService) PetInfo(flag int) []model.PetEX {
|
||||
}
|
||||
func (s *PetService) PetCount(flag int) int {
|
||||
|
||||
ret, err := cool.DBM(s.Model).Where("player_id", s.userid).Where("free", flag).Count()
|
||||
ret, err := s.TestModel(s.Model).Where("player_id", s.userid).Where("free", flag).Count()
|
||||
|
||||
if err != nil {
|
||||
return 0
|
||||
@@ -39,7 +39,7 @@ func (s *PetService) PetCount(flag int) int {
|
||||
}
|
||||
func (s *PetService) UPdateFree(ctime uint32, free uint32) {
|
||||
|
||||
cool.DBM(s.Model).Where("player_id", s.userid).Where("catch_time", ctime).Data(
|
||||
s.TestModel(s.Model).Where("player_id", s.userid).Where("catch_time", ctime).Data(
|
||||
|
||||
"free", free,
|
||||
).Update()
|
||||
@@ -47,7 +47,7 @@ func (s *PetService) UPdateFree(ctime uint32, free uint32) {
|
||||
}
|
||||
func (s *PetService) UPdate(t model.PetInfo) {
|
||||
|
||||
m := cool.DBM(s.Model).Where("player_id", s.userid).Where("catch_time", t.CatchTime)
|
||||
m := s.TestModel(s.Model).Where("player_id", s.userid).Where("catch_time", t.CatchTime)
|
||||
var tt model.PetEX
|
||||
m.Scan(&tt)
|
||||
if tt.CatchTime == 0 {
|
||||
@@ -61,7 +61,7 @@ func (s *PetService) UPdate(t model.PetInfo) {
|
||||
}
|
||||
func (s *PetService) PetInfo_One(cachetime uint32) model.PetEX {
|
||||
|
||||
m := cool.DBM(s.Model).Where("player_id", s.userid).Where("catch_time", cachetime)
|
||||
m := s.TestModel(s.Model).Where("player_id", s.userid).Where("catch_time", cachetime)
|
||||
var tt model.PetEX
|
||||
|
||||
m.Scan(&tt)
|
||||
@@ -70,7 +70,7 @@ func (s *PetService) PetInfo_One(cachetime uint32) model.PetEX {
|
||||
}
|
||||
func (s *PetService) PetInfo_One_ohter(userid, cachetime uint32) model.PetEX {
|
||||
|
||||
m := cool.DBM(s.Model).Where("player_id", userid).Where("catch_time", cachetime)
|
||||
m := s.TestModel(s.Model).Where("player_id", userid).Where("catch_time", cachetime)
|
||||
var tt model.PetEX
|
||||
|
||||
m.Scan(&tt)
|
||||
@@ -79,7 +79,7 @@ func (s *PetService) PetInfo_One_ohter(userid, cachetime uint32) model.PetEX {
|
||||
}
|
||||
func (s *PetService) PetInfo_One_Unscoped(cachetime uint32) model.PetEX {
|
||||
|
||||
m := cool.DBM(s.Model).Where("player_id", s.userid).Where("catch_time", cachetime).Unscoped()
|
||||
m := s.TestModel(s.Model).Where("player_id", s.userid).Where("catch_time", cachetime).Unscoped()
|
||||
var tt model.PetEX
|
||||
|
||||
m.Scan(&tt)
|
||||
@@ -88,7 +88,7 @@ func (s *PetService) PetInfo_One_Unscoped(cachetime uint32) model.PetEX {
|
||||
}
|
||||
func (s *PetService) Pet_del(cachetime uint32) {
|
||||
|
||||
cool.DBM(s.Model).Where("player_id", s.userid).Where("catch_time", cachetime).Delete()
|
||||
s.TestModel(s.Model).Where("player_id", s.userid).Where("catch_time", cachetime).Delete()
|
||||
|
||||
}
|
||||
|
||||
@@ -122,22 +122,6 @@ RETURNING max_ts;
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// for {
|
||||
// m1 := cool.DBM(s.Model).Where("player_id", s.userid)
|
||||
// var player model.PetEX
|
||||
// player.PlayerID = s.userid
|
||||
// player.Data = *y
|
||||
// player.CatchTime = y.CatchTime
|
||||
// player.Free = 0
|
||||
|
||||
// _, err := m1.Insert(player)
|
||||
// if err != nil {
|
||||
// fmt.Println("添加失败id自增1继续添加")
|
||||
// y.CatchTime += 1 //自增保持时间排序
|
||||
// continue
|
||||
// }
|
||||
// break
|
||||
// }
|
||||
|
||||
}
|
||||
func (s *PetService) ModifyBefore(ctx context.Context, method string, param map[string]interface{}) (err error) {
|
||||
|
||||
@@ -10,8 +10,9 @@ func (s *RoomService) Get(userid uint32) model.BaseHouseEx {
|
||||
|
||||
//todo待测试
|
||||
var ttt model.BaseHouseEx
|
||||
m := s.TestModel(s.Model)
|
||||
|
||||
cool.DBM(s.Model).Where("player_id", userid).Scan(&ttt)
|
||||
m.Where("player_id", userid).Scan(&ttt)
|
||||
|
||||
return ttt
|
||||
|
||||
@@ -19,7 +20,8 @@ func (s *RoomService) Get(userid uint32) model.BaseHouseEx {
|
||||
func (s *RoomService) Add(id, count uint32) {
|
||||
//todo待测试
|
||||
var ttt model.BaseHouseEx
|
||||
m := s.GModel(s.Model)
|
||||
m := s.TestModel(s.Model)
|
||||
|
||||
m.Scan(&ttt)
|
||||
if ttt.OwnedItems == nil {
|
||||
ttt.OwnedItems = make(map[uint32]uint32)
|
||||
@@ -38,7 +40,8 @@ func (s *RoomService) Add(id, count uint32) {
|
||||
func (s *RoomService) Set(id []model.FitmentShowInfo) {
|
||||
//todo待测试
|
||||
var ttt model.BaseHouseEx
|
||||
m := s.GModel(s.Model)
|
||||
m := s.TestModel(s.Model)
|
||||
|
||||
m.Scan(&ttt)
|
||||
ttt.PlacedItems = id
|
||||
|
||||
@@ -50,7 +53,8 @@ func (s *RoomService) Show(cactime []uint32) {
|
||||
|
||||
//todo待测试
|
||||
var ttt model.BaseHouseEx
|
||||
m := s.GModel(s.Model)
|
||||
m := s.TestModel(s.Model)
|
||||
|
||||
m.Scan(&ttt)
|
||||
ttt.ShowPokemon = cactime
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
config "blazing/modules/config/service"
|
||||
"context"
|
||||
)
|
||||
|
||||
type TalkService struct {
|
||||
@@ -25,7 +26,7 @@ func NewTalkService(id uint32) *TalkService {
|
||||
|
||||
func (s *TalkService) Cheak(mapid uint32, flag int) (int, bool) {
|
||||
|
||||
m1 := s.GModel(s.Model)
|
||||
m1 := s.PModel(s.Model)
|
||||
|
||||
var talks *model.Talk
|
||||
m1.Where("talk_id", flag).Scan(&talks)
|
||||
@@ -33,7 +34,7 @@ func (s *TalkService) Cheak(mapid uint32, flag int) (int, bool) {
|
||||
talks = model.NewTalk()
|
||||
talks.PlayerID = uint64(s.userid)
|
||||
talks.TalkID = uint32(flag)
|
||||
s.GModel(s.Model).Data(talks).FieldsEx("id").Insert()
|
||||
s.PModel(s.Model).Data(talks).FieldsEx("id").Insert()
|
||||
|
||||
return 0, true //如果表里没有记载数据,那么就可以直接挖矿
|
||||
}
|
||||
@@ -56,8 +57,12 @@ func (s *TalkService) Cheak(mapid uint32, flag int) (int, bool) {
|
||||
|
||||
}
|
||||
func (s *TalkService) Update(flag int) {
|
||||
if cool.Config.ServerInfo.IsVip != 0 {
|
||||
cool.Logger.Info(context.TODO(), "测试服不消耗物品玩家数据", s.userid)
|
||||
return
|
||||
}
|
||||
|
||||
m1 := s.GModel(s.Model)
|
||||
m1 := s.PModel(s.Model)
|
||||
|
||||
var talks model.Talk
|
||||
m1.Where("talk_id", flag).Scan(&talks)
|
||||
@@ -68,20 +73,3 @@ func (s *TalkService) Update(flag int) {
|
||||
m1.Save(talks)
|
||||
|
||||
}
|
||||
|
||||
// // TalkCheck 获取玩家当前的Talk数据
|
||||
// // todo 待实现xml解析判断是否溢出
|
||||
// func (s *TalkService) Exec(t func(map[uint32]uint32) bool) {
|
||||
|
||||
// m1 := s.GModel(s.Model)
|
||||
|
||||
// var talks model.Talk
|
||||
// m1.Scan(&talks)
|
||||
|
||||
// ok := t(talks)
|
||||
// if ok {
|
||||
// talks.PlayerID = uint64(s.userid)
|
||||
// m1.Save(talks)
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
@@ -8,38 +8,10 @@ import (
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
// func Exec[T cool.UserModel, F any](userid uint32, s *cool.Service, processFunc func(F) F) bool {
|
||||
// //todo待测试
|
||||
// var player T
|
||||
|
||||
// m1 := cool.DBM(s.Model).Where("player_id", userid)
|
||||
// m1.Scan(&player)
|
||||
// // 方法2:使用反射获取
|
||||
// // 获取反射值对象
|
||||
|
||||
// ttt := player
|
||||
|
||||
// //fmt.Println(dataField.Interface().(string))
|
||||
// var tt F
|
||||
// err := json.Unmarshal([]byte(ttt.GetData()), &tt)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// tt1 := processFunc(tt)
|
||||
// tmep, err := json.Marshal(tt1)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
|
||||
// ttt.SetData(string(tmep))
|
||||
// m1.Save(player)
|
||||
// return false
|
||||
// }
|
||||
|
||||
// 获取任务信息
|
||||
func (s *TaskService) Exec(id uint32, t func(*model.TaskEX) bool) {
|
||||
var gg model.TaskEX
|
||||
m1 := s.GModel(s.Model).Where("task_id", id)
|
||||
m1 := s.PModel(s.Model).Where("task_id", id)
|
||||
m1.Scan(&gg)
|
||||
tre := t(&gg)
|
||||
if !tre { //不需要更新
|
||||
|
||||
@@ -36,11 +36,22 @@ func NewUserService(id uint32) *UserService {
|
||||
|
||||
}
|
||||
|
||||
func (s *BaseService) GModel(m cool.IModel) *gdb.Model {
|
||||
func (s *BaseService) TestModel(m cool.IModel) *gdb.Model {
|
||||
m1 := cool.DBM(m)
|
||||
if s.userid != 0 {
|
||||
return cool.DBM(m).Where("player_id", s.userid)
|
||||
} else {
|
||||
return cool.DBM(m)
|
||||
m1.Where("player_id", s.userid)
|
||||
}
|
||||
m1.Where("is_vip", cool.Config.ServerInfo.IsVip)
|
||||
|
||||
return m1
|
||||
|
||||
}
|
||||
func (s *BaseService) PModel(m cool.IModel) *gdb.Model {
|
||||
m1 := cool.DBM(m)
|
||||
if s.userid != 0 {
|
||||
m1.Where("player_id", s.userid)
|
||||
}
|
||||
|
||||
return m1
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package model
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/cool/coolconfig"
|
||||
)
|
||||
|
||||
const TableNameServerList = "server_list"
|
||||
@@ -10,27 +11,7 @@ const TableNameServerList = "server_list"
|
||||
// ServerList mapped from table <server_list>
|
||||
type ServerList struct {
|
||||
*cool.Model
|
||||
OnlineID uint16 `gorm:"column:online_id;comment:'在线ID';uniqueIndex" json:"online_id"`
|
||||
IP string `gorm:"type:string;comment:'服务器IP'" json:"ip"`
|
||||
Port uint16 `gorm:"comment:'端口号,通常是小整数'" json:"port"`
|
||||
IsOpen uint8 `gorm:"default:0;not null;comment:'是否开启'" json:"is_open"`
|
||||
//登录地址
|
||||
LoginAddr string `gorm:"type:string;comment:'登录地址'" json:"login_addr"`
|
||||
//账号
|
||||
Account string `gorm:"type:string;comment:'账号'" json:"account"`
|
||||
//密码
|
||||
Password string `gorm:"type:string;comment:'密码'" json:"password"`
|
||||
CanPort []uint32 `gorm:"type:jsonb;comment:'可连接端口'" json:"can_port"`
|
||||
IsVip uint32 `gorm:"default:0;not null;comment:'是否为VIP服务器'" json:"is_vip"`
|
||||
//服务器异色概率设定ServerList
|
||||
ShinyRate uint8 `gorm:"default:0;comment:'异色概率'" json:"shiny_rate"`
|
||||
//服务器天气设定ServerList
|
||||
WeatherRate uint8 `gorm:"default:0;comment:'天气概率'" json:"weather_rate"`
|
||||
//服务器名称Desc
|
||||
Name string `gorm:"comment:'服务器名称'" json:"name"`
|
||||
//服务器属主Desc
|
||||
Owner uint32 `gorm:"comment:'服务器属主'" json:"owner"`
|
||||
Desc string `gorm:"comment:'服务器描述'" json:"desc"`
|
||||
coolconfig.ServerList
|
||||
}
|
||||
|
||||
// TableName ServerList's table name
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"sort"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/qiniu/go-sdk/v7/auth/qbox"
|
||||
"github.com/qiniu/go-sdk/v7/storage"
|
||||
"golang.org/x/crypto/ssh"
|
||||
@@ -43,8 +44,19 @@ func (s *ServerService) GetPort() []model.ServerList {
|
||||
return item
|
||||
|
||||
}
|
||||
func (s *ServerService) GetServer() []model.ServerList {
|
||||
var item []model.ServerList
|
||||
cool.DBM(s.Model).
|
||||
Cache(gdb.CacheOption{
|
||||
// Duration: time.Hour,
|
||||
|
||||
func (s *ServerService) GetFileList() []File {
|
||||
Force: false,
|
||||
}).Scan(&item)
|
||||
|
||||
return item
|
||||
|
||||
}
|
||||
func (s *ServerService) GetFileList() File {
|
||||
var files []File
|
||||
prefix := "logic"
|
||||
delimiter := "" // 用于分隔目录
|
||||
@@ -52,7 +64,7 @@ func (s *ServerService) GetFileList() []File {
|
||||
for {
|
||||
entries, _, nextMarker, hasNext, err := s.manager.ListFiles(s.bucket, prefix, delimiter, marker, 100)
|
||||
if err != nil {
|
||||
return nil
|
||||
return File{}
|
||||
}
|
||||
// 添加文件到结果列表
|
||||
for _, entry := range entries {
|
||||
@@ -77,7 +89,7 @@ func (s *ServerService) GetFileList() []File {
|
||||
return files[i].Time > files[j].Time
|
||||
})
|
||||
|
||||
return files
|
||||
return files[0]
|
||||
|
||||
}
|
||||
|
||||
|
||||
BIN
public/logic-logic-linux-amd64
Normal file
BIN
public/logic-logic-linux-amd64
Normal file
Binary file not shown.
BIN
public/login-login-linux-amd64
Normal file
BIN
public/login-login-linux-amd64
Normal file
Binary file not shown.
Reference in New Issue
Block a user