refactor: 重构运行时ID组合逻辑

将硬编码的 ID 组合逻辑(100000*OnlineID + Port)提取为通用函数 ComposeRuntimeID,
使用 16 位位移掩码优化,并新增辅助方法与类型转换。同时修复踢人流程中的资源清理问题。
This commit is contained in:
xinian
2026-04-28 04:03:13 +08:00
parent deae6d371e
commit 7d49aaa212
10 changed files with 59 additions and 15 deletions

View File

@@ -34,7 +34,13 @@ type QuitSReq struct {
func (this *ServerController) Quit(ctx context.Context, req *QuitSReq) (res *cool.BaseRes, err error) {
res = &cool.BaseRes{}
serv := service.NewServerService().GetServerID(req.ID)
serverService := service.NewServerService()
if req.Code != 0 {
if err = serverService.SetServerOpen(req.ID, 0); err != nil {
return res, err
}
}
serv := serverService.GetServerID(req.ID)
aa, ok := cool.GetClient(serv.OnlineID, serv.Port)
if ok && aa != nil { //如果已经存在且这个端口已经被存过

View File

@@ -167,6 +167,15 @@ func (s *ServerService) StartUPdate(OnlineID uint16, isinstall int) model.Server
return tttt
}
func (s *ServerService) SetServerOpen(OnlineID uint32, isOpen uint8) error {
m := cool.DBM(s.Model).Where("online_id", OnlineID)
var tttt model.ServerList
m.Scan(&tttt)
tttt.IsOpen = isOpen
_, err := m.Save(tttt)
return err
}
func (s *ServerService) SetServerID(OnlineID uint32, Port uint32) error {
m := cool.DBM(s.Model).Where("online_id", OnlineID)
var tttt model.ServerList