no message

This commit is contained in:
sk 2024-09-27 11:36:12 +08:00
parent 0519dbf82b
commit 53f03c1081
12 changed files with 89 additions and 320 deletions

View File

@ -1,50 +0,0 @@
package common
import (
"mongo.games.com/goserver/core/logger"
)
const (
A_USER_BLACK = 1 //增加黑名单
)
type Action struct {
ActionID int //执行id
ActionParamInt64 []int //整形参数
ActionParamFloat []float64 //浮点参数
ActionParamString []string //字符串参数
}
var ActionMgrSington = &ActionMgr{
pool: make(map[int]ActionBase),
}
type ActionMgr struct {
pool map[int]ActionBase
}
func (this *ActionMgr) ActionGroup(need interface{}, action []*Action) bool {
for i := 0; i < len(action); i++ {
this.action(need, action[i])
}
return true
}
func (this *ActionMgr) action(need interface{}, action *Action) bool {
a, ok := this.pool[action.ActionID]
if !ok {
logger.Logger.Warnf("no this action %v", action.ActionID)
return false
}
return a.Action(need, action)
}
func (this *ActionMgr) Register(cid int, c ActionBase) {
this.pool[cid] = c
}
type ActionBase interface {
Action(need interface{}, action *Action) bool
}

View File

@ -1,54 +1,55 @@
package common package common
import ( import (
"mongo.games.com/game/protocol/server"
"mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/module" "mongo.games.com/goserver/core/module"
"mongo.games.com/goserver/core/mongo"
"mongo.games.com/goserver/core/netlib" "mongo.games.com/goserver/core/netlib"
"mongo.games.com/game/protocol/server"
) )
// GameSessState 服务状态
type GameSessState int type GameSessState int
const ( const (
GAME_SESS_STATE_OFF GameSessState = iota //关闭状态 GameSessStateOff GameSessState = iota //关闭状态
GAME_SESS_STATE_ON //开启状态 GameSessStateOn //开启状态
) )
var ServerCtrlCallback func(int32) var SrvIsMaintaining = true
func RegisteServerCtrlCallback(cb func(int32)) { var ServerCtrlCallback func(msg *server.ServerCtrl)
func RegisterServerCtrlCallback(cb func(msg *server.ServerCtrl)) {
ServerCtrlCallback = cb ServerCtrlCallback = cb
} }
type ServerCtrlPacketFactory struct { func init() {
netlib.Register(int(server.SSPacketID_PACKET_MS_SRVCTRL), &server.ServerCtrl{}, ServerCtrlHandler)
} }
type ServerCtrlHandler struct { // ServerCtrlHandler 服务器控制,通用事件
} func ServerCtrlHandler(s *netlib.Session, packetid int, data interface{}) error {
logger.Logger.Infof("ServerCtrlHandler %v", data)
msg, ok := data.(*server.ServerCtrl)
if !ok {
return nil
}
switch msg.GetCtrlCode() {
case SrvCtrlCloseCode:
module.Stop()
func (this *ServerCtrlPacketFactory) CreatePacket() interface{} { case SrvCtrlResetMgoSession:
pack := &server.ServerCtrl{} mongo.ResetAllSession()
return pack
}
func (this *ServerCtrlHandler) Process(s *netlib.Session, packetid int, data interface{}) error { default:
logger.Logger.Errorf("unknow server ctrl %v", msg)
}
if sc, ok := data.(*server.ServerCtrl); ok { // 服务自己处理的特殊事件
logger.Logger.Trace("ServerCtrlHandler.Process== ", *sc) if ServerCtrlCallback != nil {
switch sc.GetCtrlCode() { ServerCtrlCallback(msg)
case SrvCtrlCloseCode:
module.Stop()
}
//回调
if ServerCtrlCallback != nil {
ServerCtrlCallback(sc.GetCtrlCode())
}
} }
return nil return nil
} }
func init() {
netlib.RegisterHandler(int(server.SSPacketID_PACKET_MS_SRVCTRL), &ServerCtrlHandler{})
netlib.RegisterFactory(int(server.SSPacketID_PACKET_MS_SRVCTRL), &ServerCtrlPacketFactory{})
}

View File

@ -1,172 +0,0 @@
package common
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"encoding/base64"
"fmt"
"mongo.games.com/goserver/core/logger"
"regexp"
"strconv"
)
var key = []byte("kjh-vgjhhionoommmkokmokoo$%JH")
// 加密
func EnCrypt(orig []byte) (str string) {
defer func() {
err := recover()
if err != nil {
logger.Logger.Errorf("EnCrypt %v Error %v", string(orig), err)
str = string(orig)
}
}()
//将秘钥中的每个字节累加,通过sum实现orig的加密工作
sum := 0
for i := 0; i < len(key); i++ {
sum += int(key[0])
}
//给明文补码
var pkcs_code = PKCS5Padding(orig, 8)
//通过秘钥,对补码后的明文进行加密
for j := 0; j < len(pkcs_code); j++ {
pkcs_code[j] += byte(sum)
}
//base64.URLEncoding.EncodeToString()
return base64.URLEncoding.EncodeToString(pkcs_code)
}
// 补码
func PKCS5Padding(orig []byte, size int) []byte {
//计算明文的长度
length := len(orig)
padding := size - length%size
//向byte类型的数组中重复添加padding
repeats := bytes.Repeat([]byte{byte(padding)}, padding)
return append(orig, repeats...)
}
// 解密
func DeCrypt(text string) (str string) {
defer func() {
err := recover()
if err != nil {
logger.Logger.Errorf("DeCrypt %v Error %v", text, err)
str = text
}
}()
//orig, err := base64.StdEncoding.DecodeString(text)
orig, err := base64.URLEncoding.DecodeString(text)
if err != nil {
return "密文类型错误"
}
sum := 0
for i := 0; i < len(key); i++ {
sum += int(key[0])
}
//解密
for j := 0; j < len(orig); j++ {
orig[j] -= byte(sum)
}
//去码
var pkcs_unCode = PKCS5UnPadding(orig)
return string(pkcs_unCode)
}
// 去码
func PKCS5UnPadding(orig []byte) []byte {
//获取最后一位补码的数字
var tail = int(orig[len(orig)-1])
return orig[:(len(orig) - tail)]
}
var aesRule, _ = regexp.Compile(`^[0-9]+$`)
const (
aeskey = "DoNotEditThisKeyDoNotEditThisKey" // 加密的密钥,绝不可以更改
)
// 下面的字符串,也绝不可以更改
var defaultLetters = []rune("idjGfiRogsFnkdKgokdfgdow07u6978uxcvvLiPiDfjafOd2fuFJYYGBJuykbvfk")
func AesEncrypt(origDataStr string) (str string) {
defer func() {
err := recover()
if err != nil {
logger.Logger.Errorf("AesEncrypt %v Error %v", origDataStr, err)
str = origDataStr
}
}()
strlen := len(origDataStr)
b := aesRule.MatchString(origDataStr)
//不全是数字,或长度为零,不加密
if !b || strlen == 0 {
return origDataStr
}
phonenum, errint := strconv.Atoi(origDataStr)
if errint != nil {
return origDataStr
}
text := []byte(origDataStr)
//指定加密、解密算法为AES返回一个AES的Block接口对象
block, err := aes.NewCipher([]byte(aeskey))
if err != nil {
panic(err)
}
//指定计数器,长度必须等于block的块尺寸
iv := string(defaultLetters[phonenum%(len(defaultLetters))])
count := []byte(fmt.Sprintf("%016v", iv))
//指定分组模式
blockMode := cipher.NewCTR(block, count)
//执行加密、解密操作
message := make([]byte, len(text))
blockMode.XORKeyStream(message, text)
//返回明文或密文
return fmt.Sprintf("%v%v", iv, base64.StdEncoding.EncodeToString(message))
//return base64.StdEncoding.EncodeToString(message)
}
func AesDecrypt(cryptedstr string) (str string) {
defer func() {
err := recover()
if err != nil {
logger.Logger.Errorf("AesDecrypt %v Error %v", cryptedstr, err)
str = cryptedstr
}
}()
strlen := len(cryptedstr)
b := aesRule.MatchString(cryptedstr)
//全是数字,或长度为零,不解密
if b || strlen == 0 {
return cryptedstr
}
iv := cryptedstr[:1]
str = cryptedstr[1:]
text, err := base64.StdEncoding.DecodeString(str)
if err != nil {
logger.Logger.Errorf("AesDecrypt %v Err:%v", cryptedstr, err)
return cryptedstr
}
//指定加密、解密算法为AES返回一个AES的Block接口对象
block, err := aes.NewCipher([]byte(aeskey))
if err != nil {
panic(err)
}
//指定计数器,长度必须等于block的块尺寸
count := []byte(fmt.Sprintf("%016v", iv))
//指定分组模式
blockMode := cipher.NewCTR(block, count)
//执行加密、解密操作
message := make([]byte, len(text))
blockMode.XORKeyStream(message, text)
//返回明文或密文
return string(message)
}

View File

@ -1844,7 +1844,7 @@ func (this *Scene) RandInt(args ...int) int {
func (this *Scene) CheckNeedDestroy() bool { func (this *Scene) CheckNeedDestroy() bool {
//if common.IsLocalGame(this.GameId) { //if common.IsLocalGame(this.GameId) {
return ServerStateMgr.GetState() == common.GAME_SESS_STATE_OFF || this.graceDestroy return ServerStateMgr.GetState() == common.GameSessStateOff || this.graceDestroy
//} else { //} else {
// return (ServerStateMgr.GetState() == common.GAME_SESS_STATE_OFF || this.graceDestroy) || (this.IsPrivateScene() && this.NumOfGames >= this.TotalOfGames) // return (ServerStateMgr.GetState() == common.GAME_SESS_STATE_OFF || this.graceDestroy) || (this.IsPrivateScene() && this.NumOfGames >= this.TotalOfGames)
//} //}

View File

@ -1,25 +1,26 @@
package base package base
import ( import (
"mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/srvlib"
"mongo.games.com/game/common" "mongo.games.com/game/common"
"mongo.games.com/game/proto" "mongo.games.com/game/proto"
"mongo.games.com/game/protocol/server" "mongo.games.com/game/protocol/server"
"mongo.games.com/goserver/core/mongo"
"mongo.games.com/goserver/srvlib"
) )
func init() { func init() {
common.RegisteServerCtrlCallback(func(code int32) { common.RegisterServerCtrlCallback(func(msg *server.ServerCtrl) {
switch code { switch msg.GetCtrlCode() {
case common.SrvCtrlStateSwitchCode: case common.SrvCtrlStateSwitchCode:
pack := &server.ServerStateSwitch{ pack := &server.ServerStateSwitch{
SrvType: proto.Int(common.GetSelfSrvType()), SrvType: proto.Int(common.GetSelfSrvType()),
SrvId: proto.Int(common.GetSelfSrvId()), SrvId: proto.Int(common.GetSelfSrvId()),
} }
proto.SetDefaults(pack)
srvlib.ServerSessionMgrSington.Broadcast(int(server.SSPacketID_PACKET_GB_STATE_SWITCH), pack, common.GetSelfAreaId(), srvlib.WorldServerType) srvlib.ServerSessionMgrSington.Broadcast(int(server.SSPacketID_PACKET_GB_STATE_SWITCH), pack, common.GetSelfAreaId(), srvlib.WorldServerType)
case common.SrvCtrlResetMgoSession:
mongo.ResetAllSession() default:
logger.Logger.Errorf("unknow server ctrl code:%d", msg.GetCtrlCode())
} }
}) })
} }

View File

@ -5,7 +5,7 @@ import (
) )
var ServerStateMgr = &ServerStateManager{ var ServerStateMgr = &ServerStateManager{
State: common.GAME_SESS_STATE_ON, State: common.GameSessStateOn,
} }
type ServerStateManager struct { type ServerStateManager struct {
@ -13,7 +13,7 @@ type ServerStateManager struct {
} }
func (this *ServerStateManager) Init() { func (this *ServerStateManager) Init() {
this.State = common.GAME_SESS_STATE_ON this.State = common.GameSessStateOn
} }
func (this *ServerStateManager) SetState(state common.GameSessState) { func (this *ServerStateManager) SetState(state common.GameSessState) {

View File

@ -1,25 +1,26 @@
package main package main
import ( import (
"mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/srvlib"
"mongo.games.com/game/common" "mongo.games.com/game/common"
"mongo.games.com/game/proto" "mongo.games.com/game/proto"
"mongo.games.com/game/protocol/server" "mongo.games.com/game/protocol/server"
"mongo.games.com/goserver/core/mongo"
"mongo.games.com/goserver/srvlib"
) )
func init() { func init() {
common.RegisteServerCtrlCallback(func(code int32) { common.RegisterServerCtrlCallback(func(msg *server.ServerCtrl) {
switch code { switch msg.GetCtrlCode() {
case common.SrvCtrlStateSwitchCode: case common.SrvCtrlStateSwitchCode:
pack := &server.ServerStateSwitch{ pack := &server.ServerStateSwitch{
SrvType: proto.Int(common.GetSelfSrvType()), SrvType: proto.Int(common.GetSelfSrvType()),
SrvId: proto.Int(common.GetSelfSrvId()), SrvId: proto.Int(common.GetSelfSrvId()),
} }
proto.SetDefaults(pack)
srvlib.ServerSessionMgrSington.Broadcast(int(server.SSPacketID_PACKET_GB_STATE_SWITCH), pack, common.GetSelfAreaId(), srvlib.WorldServerType) srvlib.ServerSessionMgrSington.Broadcast(int(server.SSPacketID_PACKET_GB_STATE_SWITCH), pack, common.GetSelfAreaId(), srvlib.WorldServerType)
case common.SrvCtrlResetMgoSession:
mongo.ResetAllSession() default:
logger.Logger.Errorf("unknown server ctrl code:%d", msg.GetCtrlCode())
} }
}) })
} }

View File

@ -139,7 +139,7 @@ func (this *CSLoginHandler) Process(s *netlib.Session, packetid int, data interf
} }
// 是否正在维护 // 是否正在维护
if model.GameParamData.SrvMaintain && SrvIsMaintaining { if model.GameParamData.SrvMaintain && common.SrvIsMaintaining {
inWhiteList := false inWhiteList := false
for i := 0; i < len(model.GMACData.WhiteList); i++ { for i := 0; i < len(model.GMACData.WhiteList); i++ {
if model.GMACData.WhiteList[i] == csl.GetUsername() { if model.GMACData.WhiteList[i] == csl.GetUsername() {

View File

@ -296,18 +296,18 @@ func init() {
srvid := int(sr.GetSrvId()) srvid := int(sr.GetSrvId())
gameSess := GameSessMgrSington.GetGameSess(srvid) gameSess := GameSessMgrSington.GetGameSess(srvid)
if gameSess != nil { if gameSess != nil {
if gameSess.state == common.GAME_SESS_STATE_ON { if gameSess.state == common.GameSessStateOn {
gameSess.SwitchState(common.GAME_SESS_STATE_OFF) gameSess.SwitchState(common.GameSessStateOff)
} else { } else {
gameSess.SwitchState(common.GAME_SESS_STATE_ON) gameSess.SwitchState(common.GameSessStateOn)
} }
} else { } else {
gateSess := GameSessMgrSington.GetGateSess(srvid) gateSess := GameSessMgrSington.GetGateSess(srvid)
if gateSess != nil { if gateSess != nil {
if gateSess.state == common.GAME_SESS_STATE_ON { if gateSess.state == common.GameSessStateOn {
gateSess.SwitchState(common.GAME_SESS_STATE_OFF) gateSess.SwitchState(common.GameSessStateOff)
} else { } else {
gateSess.SwitchState(common.GAME_SESS_STATE_ON) gateSess.SwitchState(common.GameSessStateOn)
} }
} }
} }

View File

@ -43,13 +43,12 @@ type GameSession struct {
gameIds []int32 gameIds []int32
} }
// 构造函数
func NewGameSession(srvId, srvType int, s *netlib.Session) *GameSession { func NewGameSession(srvId, srvType int, s *netlib.Session) *GameSession {
gs := &GameSession{ gs := &GameSession{
Session: s, Session: s,
srvId: srvId, srvId: srvId,
srvType: srvType, srvType: srvType,
state: common.GAME_SESS_STATE_ON, state: common.GameSessStateOn,
players: make(map[int32]*Player), players: make(map[int32]*Player),
scenes: make(map[int]*Scene), scenes: make(map[int]*Scene),
cps: make(map[string]*model.CoinPoolSetting), cps: make(map[string]*model.CoinPoolSetting),
@ -57,13 +56,6 @@ func NewGameSession(srvId, srvType int, s *netlib.Session) *GameSession {
return gs return gs
} }
func (this *GameSession) RebindPlayerSnId(oldSnId, newSnId int32) {
if p, exist := this.players[oldSnId]; exist {
delete(this.players, oldSnId)
this.players[newSnId] = p
}
}
func (this *GameSession) GetSrvId() int32 { func (this *GameSession) GetSrvId() int32 {
if this.Session == nil { if this.Session == nil {
return 0 return 0
@ -85,7 +77,6 @@ func (this *GameSession) CloseAllScene() {
OpRetCode: gamehall_proto.OpResultCode_Game_OPRC_Sucess_Game, OpRetCode: gamehall_proto.OpResultCode_Game_OPRC_Sucess_Game,
IsForce: proto.Int(1), IsForce: proto.Int(1),
} }
proto.SetDefaults(scDestroyRoom)
scene.Broadcast(int(gamehall_proto.GameHallPacketID_PACKET_SC_DESTROYROOM), scDestroyRoom, 0) scene.Broadcast(int(gamehall_proto.GameHallPacketID_PACKET_SC_DESTROYROOM), scDestroyRoom, 0)
SceneMgrSingleton.DestroyScene(sceneId, true) SceneMgrSingleton.DestroyScene(sceneId, true)
} }
@ -105,11 +96,8 @@ func (this *GameSession) OnRegiste() {
// 注销事件 // 注销事件
func (this *GameSession) OnUnregiste() { func (this *GameSession) OnUnregiste() {
//销毁比赛
//MatchMgrSington.DestroyAllMatchByGameSession(this)
//解散房间 //解散房间
this.CloseAllScene() this.CloseAllScene()
GameSessionListenerSet.Range(func(key, val interface{}) bool { GameSessionListenerSet.Range(func(key, val interface{}) bool {
if lis, ok := val.(GameSessionListener); ok { if lis, ok := val.(GameSessionListener); ok {
lis.OnGameSessionUnregiste(this) lis.OnGameSessionUnregiste(this)
@ -130,12 +118,13 @@ func (this *GameSession) SwitchState(state common.GameSessState) {
} }
this.state = state this.state = state
switch state { switch state {
case common.GAME_SESS_STATE_ON: case common.GameSessStateOn:
this.OnStateOn() this.OnStateOn()
case common.GAME_SESS_STATE_OFF: case common.GameSessStateOff:
this.OnStateOff() this.OnStateOff()
} }
} }
func (this *GameSession) OnStateOn() { func (this *GameSession) OnStateOn() {
pack := &server_proto.ServerState{ pack := &server_proto.ServerState{
SrvState: proto.Int(int(this.state)), SrvState: proto.Int(int(this.state)),
@ -143,6 +132,7 @@ func (this *GameSession) OnStateOn() {
proto.SetDefaults(pack) proto.SetDefaults(pack)
this.Send(int(server_proto.SSPacketID_PACKET_WG_SERVER_STATE), pack) this.Send(int(server_proto.SSPacketID_PACKET_WG_SERVER_STATE), pack)
} }
func (this *GameSession) OnStateOff() { func (this *GameSession) OnStateOff() {
pack := &server_proto.ServerState{ pack := &server_proto.ServerState{
SrvState: proto.Int(int(this.state)), SrvState: proto.Int(int(this.state)),

View File

@ -2,21 +2,18 @@ package main
import ( import (
"math" "math"
"mongo.games.com/game/protocol/webapi"
"strconv" "strconv"
"strings" "strings"
"mongo.games.com/game/common"
"mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/netlib" "mongo.games.com/goserver/core/netlib"
"mongo.games.com/goserver/srvlib" "mongo.games.com/goserver/srvlib"
"mongo.games.com/goserver/srvlib/protocol" "mongo.games.com/goserver/srvlib/protocol"
)
//const ( "mongo.games.com/game/common"
// ReplayServerType int = 8 "mongo.games.com/game/model"
// ReplayServerId = 801 "mongo.games.com/game/protocol/webapi"
//) )
var GameSessMgrSington = &GameSessMgr{ var GameSessMgrSington = &GameSessMgr{
servers: make(map[int]*GameSession), servers: make(map[int]*GameSession),
@ -25,9 +22,9 @@ var GameSessMgrSington = &GameSessMgr{
} }
type GameSessMgr struct { type GameSessMgr struct {
servers map[int]*GameSession servers map[int]*GameSession // 游戏服务id
gamesrvs map[int][]*GameSession gamesrvs map[int][]*GameSession // 游戏id
gates map[int]*GameSession gates map[int]*GameSession // 网关id
} }
// 注册事件 // 注册事件
@ -134,6 +131,7 @@ func (this *GameSessMgr) OnUnregiste(s *netlib.Session) {
} }
} }
} }
func (this *GameSessMgr) GetGameServerSess(gameid int) []*GameSession { func (this *GameSessMgr) GetGameServerSess(gameid int) []*GameSession {
return this.gamesrvs[gameid] return this.gamesrvs[gameid]
} }
@ -146,7 +144,7 @@ func (this *GameSessMgr) GetMinLoadSess(gameid int) *GameSession {
if gss, exist := this.gamesrvs[gameid]; exist { if gss, exist := this.gamesrvs[gameid]; exist {
if gss != nil { if gss != nil {
for _, s := range gss { for _, s := range gss {
if s.state == common.GAME_SESS_STATE_ON { if s.state == common.GameSessStateOn {
loadFactor = s.GetLoadFactor() loadFactor = s.GetLoadFactor()
if minLoad > loadFactor { if minLoad > loadFactor {
minLoad = loadFactor minLoad = loadFactor
@ -162,7 +160,7 @@ func (this *GameSessMgr) GetMinLoadSess(gameid int) *GameSession {
if gss, exist := this.gamesrvs[0]; exist { if gss, exist := this.gamesrvs[0]; exist {
if gss != nil { if gss != nil {
for _, s := range gss { for _, s := range gss {
if s.state == common.GAME_SESS_STATE_ON { if s.state == common.GameSessStateOn {
loadFactor = s.GetLoadFactor() loadFactor = s.GetLoadFactor()
if minLoad > loadFactor { if minLoad > loadFactor {
minLoad = loadFactor minLoad = loadFactor
@ -184,6 +182,7 @@ func (this *GameSessMgr) GetGameSess(srvId int) *GameSession {
} }
return nil return nil
} }
func (this *GameSessMgr) GetAllGameSess() []*GameSession { func (this *GameSessMgr) GetAllGameSess() []*GameSession {
servers := make([]*GameSession, 0) servers := make([]*GameSession, 0)
for _, v := range this.servers { for _, v := range this.servers {
@ -191,17 +190,13 @@ func (this *GameSessMgr) GetAllGameSess() []*GameSession {
} }
return servers return servers
} }
func (this *GameSessMgr) GetGateSess(srvId int) *GameSession { func (this *GameSessMgr) GetGateSess(srvId int) *GameSession {
if gs, exist := this.gates[srvId]; exist { if gs, exist := this.gates[srvId]; exist {
return gs return gs
} }
return nil return nil
} }
func (this *GameSessMgr) RebindPlayerSnId(oldSnId, newSnId int32) {
for _, gs := range this.servers {
gs.RebindPlayerSnId(oldSnId, newSnId)
}
}
func (this *GameSessMgr) ListServerState(srvId, srvType int) []*webapi.ServerInfo { func (this *GameSessMgr) ListServerState(srvId, srvType int) []*webapi.ServerInfo {
_createGateServerInfo := func(srvId, srvType int, s *GameSession) *webapi.ServerInfo { _createGateServerInfo := func(srvId, srvType int, s *GameSession) *webapi.ServerInfo {
@ -299,15 +294,17 @@ func (this *GameSessMgr) ListServerState(srvId, srvType int) []*webapi.ServerInf
myInfo := &webapi.ServerInfo{ myInfo := &webapi.ServerInfo{
SrvId: int32(common.GetSelfSrvId()), SrvId: int32(common.GetSelfSrvId()),
SrvType: int32(common.GetSelfSrvType()), SrvType: int32(common.GetSelfSrvType()),
State: int32(common.GAME_SESS_STATE_ON), State: int32(common.GameSessStateOn),
PlayerNum: int32(len(PlayerMgrSington.players)), PlayerNum: int32(len(PlayerMgrSington.players)),
RobotNum: int32(len(PlayerMgrSington.snidMap) - len(PlayerMgrSington.players)), RobotNum: int32(len(PlayerMgrSington.snidMap) - len(PlayerMgrSington.players)),
SceneNum: int32(len(SceneMgrSingleton.scenes)), SceneNum: int32(len(SceneMgrSingleton.scenes)),
} }
if SrvIsMaintaining { if model.GameParamData.SrvMaintain {
myInfo.State = int32(common.GAME_SESS_STATE_ON) if !common.SrvIsMaintaining {
} else { myInfo.State = int32(common.GameSessStateOn)
myInfo.State = int32(common.GAME_SESS_STATE_OFF) } else {
myInfo.State = int32(common.GameSessStateOff)
}
} }
//把自己加进去 //把自己加进去
datas = append(datas, myInfo) datas = append(datas, myInfo)

View File

@ -1,19 +1,20 @@
package main package main
import ( import (
"mongo.games.com/goserver/core/logger"
"mongo.games.com/game/common" "mongo.games.com/game/common"
"mongo.games.com/goserver/core/mongo" "mongo.games.com/game/protocol/server"
) )
var SrvIsMaintaining = true
func init() { func init() {
common.RegisteServerCtrlCallback(func(code int32) { common.RegisterServerCtrlCallback(func(msg *server.ServerCtrl) {
switch code { switch msg.GetCtrlCode() {
case common.SrvCtrlStateSwitchCode: case common.SrvCtrlStateSwitchCode:
SrvIsMaintaining = !SrvIsMaintaining common.SrvIsMaintaining = !common.SrvIsMaintaining
case common.SrvCtrlResetMgoSession:
mongo.ResetAllSession() default:
logger.Logger.Errorf("unknown server ctrl code:%d", msg.GetCtrlCode())
} }
}) })
} }