feat(common/cool): 更新GetClient函数支持端口参数 更新GetClient函数签名以接收端口参数,并修改客户端映射键的计算方式, 添加GetClientOnly函数用于仅通过uid获取客户端。 fix(common/rpc): 修复RPC调用中的客户端获取方法 将GetClient调用替换为GetClientOnly,确保正确的客户端获取逻辑。 refactor(logic/controller): 重命名Port字段为UID并优化道具列表处理 将Controller结构体中的Port字段重命名为UID以更好地反映其用途, 优化GetUserItemList函数中道具列表的初始化和填充逻辑。 perf(logic): 调整性能分析web服务启动位置 将PprofWeb服务从全局启动移至调试模式下启动,优化服务配置。 refactor(logic/server): 更新服务器UID生成逻辑 修改Maincontroller的UID字段设置方式,使用服务器ID和端口组合生成唯一标识。 refactor(logic/service/player): 移除未使用的导入并优化怪物生成 移除未使用的service导入,优化怪物生成逻辑中的地图数据访问。 feat(logic/service/space): 添加PitS缓存映射并重构空间初始化 添加新的PitS字段
This commit is contained in:
@@ -7,9 +7,19 @@ func AddClient(id uint32, client *ClientHandler) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 取值示例
|
// 取值示例
|
||||||
func GetClient(id uint32) (*ClientHandler, bool) {
|
func GetClient(id, port uint32) (*ClientHandler, bool) {
|
||||||
// 普通map:client, ok := Clientmap[id]
|
// 普通map:client, ok := Clientmap[id]
|
||||||
val, ok := Clientmap.Load(id) // sync.Map取值
|
val, ok := Clientmap.Load(100000*id + port) // sync.Map取值
|
||||||
|
if !ok {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
// 类型断言(确保value是*ClientHandler)
|
||||||
|
client, ok := val.(*ClientHandler)
|
||||||
|
return client, ok
|
||||||
|
}
|
||||||
|
func GetClientOnly(uid uint32) (*ClientHandler, bool) {
|
||||||
|
// 普通map:client, ok := Clientmap[id]
|
||||||
|
val, ok := Clientmap.Load(uid) // sync.Map取值
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ func (*ServerHandler) Kick(_ context.Context, userid uint32) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cl, ok := cool.GetClient(useid1)
|
cl, ok := cool.GetClientOnly(useid1)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,7 @@ func (*ServerHandler) RegisterLogic(ctx context.Context, id, port uint32) error
|
|||||||
}
|
}
|
||||||
t := config.NewServerService().GetServerID((id))
|
t := config.NewServerService().GetServerID((id))
|
||||||
|
|
||||||
aa, ok := cool.GetClient(t.OnlineID*100000 + t.Port)
|
aa, ok := cool.GetClient(t.OnlineID, t.Port)
|
||||||
if ok && aa != nil { //如果已经存在且这个端口已经被存过
|
if ok && aa != nil { //如果已经存在且这个端口已经被存过
|
||||||
aa.QuitSelf(0)
|
aa.QuitSelf(0)
|
||||||
}
|
}
|
||||||
|
|||||||
18
help/诊断较慢.sql
Normal file
18
help/诊断较慢.sql
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
-- 查看当前活跃的 SQL(排查慢查询)
|
||||||
|
SELECT pid, now() - query_start AS duration, query
|
||||||
|
FROM pg_stat_activity
|
||||||
|
WHERE state = 'active' AND now() - query_start > '5 seconds'::interval;
|
||||||
|
|
||||||
|
-- 查看表的访问统计(找出热点表)
|
||||||
|
SELECT relname, seq_scan, idx_scan, n_live_tup
|
||||||
|
FROM pg_stat_user_tables
|
||||||
|
ORDER BY seq_scan DESC LIMIT 10;
|
||||||
|
|
||||||
|
-- 查看索引使用情况(找出未使用的索引)
|
||||||
|
SELECT relname AS table_name, indexrelname AS index_name, idx_scan
|
||||||
|
FROM pg_stat_user_indexes
|
||||||
|
WHERE idx_scan = 0;
|
||||||
|
|
||||||
|
-- 更新统计信息(当执行计划不准时)
|
||||||
|
ANALYZE users; -- 单表更新
|
||||||
|
ANALYZE; -- 全库更新
|
||||||
@@ -23,7 +23,7 @@ var Maincontroller = &Controller{} //注入service
|
|||||||
|
|
||||||
// Controller 分发cmd逻辑实现
|
// Controller 分发cmd逻辑实现
|
||||||
type Controller struct {
|
type Controller struct {
|
||||||
Port uint32
|
UID uint32
|
||||||
RPCClient *struct {
|
RPCClient *struct {
|
||||||
Kick func(uint32) error
|
Kick func(uint32) error
|
||||||
|
|
||||||
|
|||||||
@@ -23,18 +23,16 @@ const (
|
|||||||
// 返回: 道具列表和错误码
|
// 返回: 道具列表和错误码
|
||||||
func (h Controller) GetUserItemList(data *item.ItemListInboundInfo, c *player.Player) (result *item.ItemListOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) GetUserItemList(data *item.ItemListInboundInfo, c *player.Player) (result *item.ItemListOutboundInfo, err errorcode.ErrorCode) {
|
||||||
result = &item.ItemListOutboundInfo{}
|
result = &item.ItemListOutboundInfo{}
|
||||||
result.ItemList = make([]model.SingleItemInfo, 0)
|
|
||||||
|
|
||||||
items := c.Service.Item.Get(data.Param1, data.Param2)
|
items := c.Service.Item.Get(data.Param1, data.Param2)
|
||||||
|
result.ItemList = make([]model.SingleItemInfo, len(items))
|
||||||
for _, itemData := range items {
|
for _, itemData := range items {
|
||||||
itemInfo := model.SingleItemInfo{
|
|
||||||
|
result.ItemList = append(result.ItemList, model.SingleItemInfo{
|
||||||
ItemId: itemData.ItemId,
|
ItemId: itemData.ItemId,
|
||||||
ItemCnt: uint32(itemData.ItemCnt),
|
ItemCnt: uint32(itemData.ItemCnt),
|
||||||
LeftTime: ItemDefaultLeftTime,
|
LeftTime: ItemDefaultLeftTime,
|
||||||
}
|
})
|
||||||
if itemInfo.ItemCnt > 0 {
|
|
||||||
result.ItemList = append(result.ItemList, itemInfo)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result, 0
|
return result, 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ func (h Controller) Login(data *user.MAIN_LOGIN_IN, c gnet.Conn) (result *user.L
|
|||||||
currentPlayer.Service = service.NewUserService(data.Head.UserID)
|
currentPlayer.Service = service.NewUserService(data.Head.UserID)
|
||||||
|
|
||||||
currentPlayer.Info = currentPlayer.Service.Info.SetLogin()
|
currentPlayer.Info = currentPlayer.Service.Info.SetLogin()
|
||||||
share.ShareManager.SetUserOnline(data.Head.UserID, h.Port) //设置用户登录服务器
|
share.ShareManager.SetUserOnline(data.Head.UserID, h.UID) //设置用户登录服务器
|
||||||
if currentPlayer.Info == nil {
|
if currentPlayer.Info == nil {
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ func main() {
|
|||||||
// if cool.Config.GameOnlineID == 2 { //只分析1服务器的
|
// if cool.Config.GameOnlineID == 2 { //只分析1服务器的
|
||||||
// go PprofWeb()
|
// go PprofWeb()
|
||||||
// }
|
// }
|
||||||
go PprofWeb()
|
|
||||||
//go PprofWeb()
|
//go PprofWeb()
|
||||||
go monitorMemAndQuit()
|
go monitorMemAndQuit()
|
||||||
fmt.Println("Process start, pid:", os.Getpid())
|
fmt.Println("Process start, pid:", os.Getpid())
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ func Start() {
|
|||||||
|
|
||||||
if cool.Config.ServerInfo.IsDebug == 1 {
|
if cool.Config.ServerInfo.IsDebug == 1 {
|
||||||
g.DB().SetDebug(true)
|
g.DB().SetDebug(true)
|
||||||
|
|
||||||
|
go PprofWeb()
|
||||||
}
|
}
|
||||||
|
|
||||||
port, err := determinePort(cool.Config.ServerInfo.CanPort)
|
port, err := determinePort(cool.Config.ServerInfo.CanPort)
|
||||||
@@ -78,7 +80,8 @@ func Start() {
|
|||||||
rpcClient := rpc.StartClient(serverID, uint32(port), server) //连接rpc
|
rpcClient := rpc.StartClient(serverID, uint32(port), server) //连接rpc
|
||||||
|
|
||||||
controller.Maincontroller.RPCClient = rpcClient //将RPC赋值Start
|
controller.Maincontroller.RPCClient = rpcClient //将RPC赋值Start
|
||||||
controller.Maincontroller.Port = uint32(port) //赋值服务器ID
|
|
||||||
|
controller.Maincontroller.UID = uint32(100000*serverID + uint32(port)) //赋值服务器ID
|
||||||
controller.Init(true)
|
controller.Init(true)
|
||||||
xmlres.Initfile()
|
xmlres.Initfile()
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package player
|
|||||||
import (
|
import (
|
||||||
"blazing/common/utils"
|
"blazing/common/utils"
|
||||||
"blazing/modules/config/model"
|
"blazing/modules/config/model"
|
||||||
"blazing/modules/config/service"
|
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -38,10 +37,6 @@ func (p *Player) GenMonster() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
mapinfo := service.NewMapService().GetData(p.Info.MapID)
|
|
||||||
if mapinfo == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var oldnum, newNum int
|
var oldnum, newNum int
|
||||||
var replce []int
|
var replce []int
|
||||||
p.monsters, oldnum, newNum = replaceOneNumber(p.monsters)
|
p.monsters, oldnum, newNum = replaceOneNumber(p.monsters)
|
||||||
@@ -56,7 +51,11 @@ func (p *Player) GenMonster() {
|
|||||||
p.Data[oldnum] = OgrePetInfo{} //切地图清空
|
p.Data[oldnum] = OgrePetInfo{} //切地图清空
|
||||||
|
|
||||||
for _, i := range replce {
|
for _, i := range replce {
|
||||||
ogreconfig := service.NewMapPitService().GetData(p.Info.MapID, uint32(i))
|
|
||||||
|
ogreconfig, ok := p.GetSpace().PitS.Load(i) //service.NewMapPitService().GetData(p.Info.MapID, uint32(i))
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
for _, v := range ogreconfig {
|
for _, v := range ogreconfig {
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"blazing/logic/service/common"
|
"blazing/logic/service/common"
|
||||||
"blazing/logic/service/space/info"
|
"blazing/logic/service/space/info"
|
||||||
|
|
||||||
|
"blazing/modules/config/model"
|
||||||
"blazing/modules/config/service"
|
"blazing/modules/config/service"
|
||||||
infomodel "blazing/modules/player/model"
|
infomodel "blazing/modules/player/model"
|
||||||
|
|
||||||
@@ -44,7 +45,8 @@ type Space struct {
|
|||||||
TimeBoss info.S2C_2022
|
TimeBoss info.S2C_2022
|
||||||
//Weather uint32
|
//Weather uint32
|
||||||
IsTime bool
|
IsTime bool
|
||||||
//CanWeather uint32
|
|
||||||
|
PitS *csmap.CsMap[int, []model.MapPit]
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSyncMap 创建一个新的玩家同步map
|
// NewSyncMap 创建一个新的玩家同步map
|
||||||
@@ -143,20 +145,40 @@ func (ret *Space) init() {
|
|||||||
maphot[ret.Super] = &MapTip{}
|
maphot[ret.Super] = &MapTip{}
|
||||||
maphot[ret.Super].TipInfoS = make(map[uint32]*TipInfo, 0)
|
maphot[ret.Super].TipInfoS = make(map[uint32]*TipInfo, 0)
|
||||||
}
|
}
|
||||||
_, ok = maphot[ret.Super].TipInfoS[ret.ID]
|
|
||||||
if !ok {
|
|
||||||
tips := &TipInfo{}
|
tips := &TipInfo{}
|
||||||
r := service.NewMapService().GetData(ret.ID)
|
r := service.NewMapService().GetData(ret.ID)
|
||||||
if r != nil {
|
if r != nil {
|
||||||
tips.Diao = service.NewMapService().GetData(ret.ID).DropItemIds
|
tips.Diao = service.NewMapService().GetData(ret.ID).DropItemIds
|
||||||
}
|
}
|
||||||
|
|
||||||
tips.Pet = service.NewMapPitService().GetDataALL(ret.ID)
|
pits := service.NewMapPitService().GetDataALL(ret.ID)
|
||||||
|
ret.PitS = csmap.New[int, []model.MapPit]()
|
||||||
|
|
||||||
|
for _, v := range pits {
|
||||||
|
|
||||||
|
tips.Pet = append(tips.Pet, v.RefreshID...)
|
||||||
|
for _, vp := range v.Pos {
|
||||||
|
t, ok := ret.PitS.Load(vp)
|
||||||
|
if ok {
|
||||||
|
t = append(t, v)
|
||||||
|
ret.PitS.Store(vp, t)
|
||||||
|
} else {
|
||||||
|
ret.PitS.Store(vp, []model.MapPit{v})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
tips.Pet = lo.Union(tips.Pet)
|
||||||
tips.Talk = service.NewTalkConfigService().GetTip(ret.ID)
|
tips.Talk = service.NewTalkConfigService().GetTip(ret.ID)
|
||||||
tips.Boss = service.NewMapNodeService().GetTip(ret.ID)
|
tips.Boss = service.NewMapNodeService().GetTip(ret.ID)
|
||||||
maphot[ret.Super].TipInfoS[ret.ID] = tips
|
maphot[ret.Super].TipInfoS[ret.ID] = tips
|
||||||
}
|
|
||||||
ret.Name = v.Name
|
ret.Name = v.Name
|
||||||
|
|
||||||
|
//ogreconfig := service.NewMapPitService().GetData(ret.ID, uint32(i))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ func (s *BaseSysRoleService) GetByUser(userId uint) []string {
|
|||||||
)
|
)
|
||||||
res, _ := cool.DBM(baseSysUserRole).Where("userId", userId).Array("roleId")
|
res, _ := cool.DBM(baseSysUserRole).Where("userId", userId).Array("roleId")
|
||||||
for _, v := range res {
|
for _, v := range res {
|
||||||
roles = append(roles, gconv.String(v))
|
roles = append(roles, v.String())
|
||||||
}
|
}
|
||||||
return roles
|
return roles
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func (this *ServerController) Quit(ctx context.Context, req *QuitSReq) (res *coo
|
|||||||
res = &cool.BaseRes{}
|
res = &cool.BaseRes{}
|
||||||
serv := service.NewServerService().GetServerID(req.ID)
|
serv := service.NewServerService().GetServerID(req.ID)
|
||||||
|
|
||||||
aa, ok := cool.GetClient(serv.OnlineID*100000 + serv.Port)
|
aa, ok := cool.GetClient(serv.OnlineID, serv.Port)
|
||||||
if ok && aa != nil { //如果已经存在且这个端口已经被存过
|
if ok && aa != nil { //如果已经存在且这个端口已经被存过
|
||||||
aa.QuitSelf(req.Code)
|
aa.QuitSelf(req.Code)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ package service
|
|||||||
import (
|
import (
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
"blazing/modules/config/model"
|
"blazing/modules/config/model"
|
||||||
|
|
||||||
"github.com/samber/lo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MapPitService struct {
|
type MapPitService struct {
|
||||||
@@ -22,24 +20,20 @@ func NewMapPitService() *MapPitService {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (s *MapPitService) GetData(mapid, pos uint32) []model.MapPit {
|
|
||||||
|
// func (s *MapPitService) GetData(mapid, pos uint32) []model.MapPit {
|
||||||
|
|
||||||
|
// var pet []model.MapPit //一个特性应该是唯一的,但是我们要获取默认随机特性
|
||||||
|
// dbm_enable(s.Model).Where("map_id", mapid).Wheref(`pos @> ARRAY[?]::integer[]`, pos).Scan(&pet)
|
||||||
|
|
||||||
|
// return pet
|
||||||
|
|
||||||
|
// }
|
||||||
|
func (s *MapPitService) GetDataALL(mapid uint32) []model.MapPit {
|
||||||
|
|
||||||
var pet []model.MapPit //一个特性应该是唯一的,但是我们要获取默认随机特性
|
var pet []model.MapPit //一个特性应该是唯一的,但是我们要获取默认随机特性
|
||||||
dbm_enable(s.Model).Where("map_id", mapid).Wheref(`pos @> ARRAY[?]::integer[]`, pos).Scan(&pet)
|
dbm_enable(s.Model).Where("map_id", mapid).Scan(&pet)
|
||||||
|
|
||||||
return pet
|
return pet
|
||||||
|
|
||||||
}
|
}
|
||||||
func (s *MapPitService) GetDataALL(mapid uint32) []uint32 {
|
|
||||||
|
|
||||||
var pet []model.MapPit //一个特性应该是唯一的,但是我们要获取默认随机特性
|
|
||||||
dbm_enable(s.Model).Where("map_id", mapid).Scan(&pet)
|
|
||||||
var ret []uint32
|
|
||||||
for _, v := range pet {
|
|
||||||
|
|
||||||
ret = append(ret, v.RefreshID...)
|
|
||||||
}
|
|
||||||
|
|
||||||
return lo.Union(ret)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func NewServerService() *ServerService {
|
|||||||
var rr []g.MapStrAny
|
var rr []g.MapStrAny
|
||||||
r, _ := gconv.Map(data)["list"].(gdb.Result)
|
r, _ := gconv.Map(data)["list"].(gdb.Result)
|
||||||
for i := 0; i < len(r); i++ {
|
for i := 0; i < len(r); i++ {
|
||||||
t, ok := cool.GetClient(10000*gconv.Uint32(r[i].Map()["online_id"])+gconv.Uint32(r[i].Map()["port"]))
|
t, ok := cool.GetClient(gconv.Uint32(r[i].Map()["online_id"]), gconv.Uint32(r[i].Map()["port"]))
|
||||||
// tt.Friends = v.Friends
|
// tt.Friends = v.Friends
|
||||||
subm := r[i].GMap()
|
subm := r[i].GMap()
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,11 @@ func (s *DictInfoService) Data(ctx context.Context, types []string) (data interf
|
|||||||
dictInfoModel = model.NewDictInfo()
|
dictInfoModel = model.NewDictInfo()
|
||||||
dictTypeModel = model.NewDictType()
|
dictTypeModel = model.NewDictType()
|
||||||
)
|
)
|
||||||
mType := cool.DBM(dictTypeModel)
|
mType := cool.DBM(dictTypeModel).Cache(gdb.CacheOption{
|
||||||
|
// Duration: time.Hour,
|
||||||
|
|
||||||
|
Force: false,
|
||||||
|
})
|
||||||
// 如果types不为空, 则查询指定类型的数据
|
// 如果types不为空, 则查询指定类型的数据
|
||||||
if len(types) > 0 {
|
if len(types) > 0 {
|
||||||
mType = mType.Where("key in (?)", types)
|
mType = mType.Where("key in (?)", types)
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ func (s *InfoService) Kick(id uint32) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cl, ok := cool.GetClient(useid1)
|
cl, ok := cool.GetClientOnly(useid1)
|
||||||
if ok {
|
if ok {
|
||||||
err := cl.KickPerson(id) //实现指定服务器踢人
|
err := cl.KickPerson(id) //实现指定服务器踢人
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func (s *ItemService) Get(min, max uint32) []model.Item {
|
|||||||
s.dbm(s.Model).Where(g.Map{
|
s.dbm(s.Model).Where(g.Map{
|
||||||
"item_id <=": max,
|
"item_id <=": max,
|
||||||
"item_id >=": min,
|
"item_id >=": min,
|
||||||
}).Scan(&ttt)
|
}).Where("item_cnt >", 0).Scan(&ttt)
|
||||||
|
|
||||||
return ttt
|
return ttt
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user