no message
This commit is contained in:
parent
0519dbf82b
commit
53f03c1081
|
@ -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
|
||||
}
|
|
@ -1,54 +1,55 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"mongo.games.com/game/protocol/server"
|
||||
"mongo.games.com/goserver/core/logger"
|
||||
"mongo.games.com/goserver/core/module"
|
||||
"mongo.games.com/goserver/core/mongo"
|
||||
"mongo.games.com/goserver/core/netlib"
|
||||
|
||||
"mongo.games.com/game/protocol/server"
|
||||
)
|
||||
|
||||
// GameSessState 服务状态
|
||||
type GameSessState int
|
||||
|
||||
const (
|
||||
GAME_SESS_STATE_OFF GameSessState = iota //关闭状态
|
||||
GAME_SESS_STATE_ON //开启状态
|
||||
GameSessStateOff GameSessState = iota //关闭状态
|
||||
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
|
||||
}
|
||||
|
||||
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{} {
|
||||
pack := &server.ServerCtrl{}
|
||||
return pack
|
||||
}
|
||||
case SrvCtrlResetMgoSession:
|
||||
mongo.ResetAllSession()
|
||||
|
||||
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)
|
||||
switch sc.GetCtrlCode() {
|
||||
case SrvCtrlCloseCode:
|
||||
module.Stop()
|
||||
}
|
||||
|
||||
//回调
|
||||
if ServerCtrlCallback != nil {
|
||||
ServerCtrlCallback(sc.GetCtrlCode())
|
||||
}
|
||||
// 服务自己处理的特殊事件
|
||||
if ServerCtrlCallback != nil {
|
||||
ServerCtrlCallback(msg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
netlib.RegisterHandler(int(server.SSPacketID_PACKET_MS_SRVCTRL), &ServerCtrlHandler{})
|
||||
netlib.RegisterFactory(int(server.SSPacketID_PACKET_MS_SRVCTRL), &ServerCtrlPacketFactory{})
|
||||
}
|
||||
|
|
172
common/aes.go
172
common/aes.go
|
@ -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)
|
||||
}
|
|
@ -1844,7 +1844,7 @@ func (this *Scene) RandInt(args ...int) int {
|
|||
|
||||
func (this *Scene) CheckNeedDestroy() bool {
|
||||
//if common.IsLocalGame(this.GameId) {
|
||||
return ServerStateMgr.GetState() == common.GAME_SESS_STATE_OFF || this.graceDestroy
|
||||
return ServerStateMgr.GetState() == common.GameSessStateOff || this.graceDestroy
|
||||
//} else {
|
||||
// return (ServerStateMgr.GetState() == common.GAME_SESS_STATE_OFF || this.graceDestroy) || (this.IsPrivateScene() && this.NumOfGames >= this.TotalOfGames)
|
||||
//}
|
||||
|
|
|
@ -1,25 +1,26 @@
|
|||
package base
|
||||
|
||||
import (
|
||||
"mongo.games.com/goserver/core/logger"
|
||||
"mongo.games.com/goserver/srvlib"
|
||||
|
||||
"mongo.games.com/game/common"
|
||||
"mongo.games.com/game/proto"
|
||||
"mongo.games.com/game/protocol/server"
|
||||
"mongo.games.com/goserver/core/mongo"
|
||||
"mongo.games.com/goserver/srvlib"
|
||||
)
|
||||
|
||||
func init() {
|
||||
common.RegisteServerCtrlCallback(func(code int32) {
|
||||
switch code {
|
||||
common.RegisterServerCtrlCallback(func(msg *server.ServerCtrl) {
|
||||
switch msg.GetCtrlCode() {
|
||||
case common.SrvCtrlStateSwitchCode:
|
||||
pack := &server.ServerStateSwitch{
|
||||
SrvType: proto.Int(common.GetSelfSrvType()),
|
||||
SrvId: proto.Int(common.GetSelfSrvId()),
|
||||
}
|
||||
proto.SetDefaults(pack)
|
||||
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())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
)
|
||||
|
||||
var ServerStateMgr = &ServerStateManager{
|
||||
State: common.GAME_SESS_STATE_ON,
|
||||
State: common.GameSessStateOn,
|
||||
}
|
||||
|
||||
type ServerStateManager struct {
|
||||
|
@ -13,7 +13,7 @@ type ServerStateManager struct {
|
|||
}
|
||||
|
||||
func (this *ServerStateManager) Init() {
|
||||
this.State = common.GAME_SESS_STATE_ON
|
||||
this.State = common.GameSessStateOn
|
||||
}
|
||||
|
||||
func (this *ServerStateManager) SetState(state common.GameSessState) {
|
||||
|
|
|
@ -1,25 +1,26 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"mongo.games.com/goserver/core/logger"
|
||||
"mongo.games.com/goserver/srvlib"
|
||||
|
||||
"mongo.games.com/game/common"
|
||||
"mongo.games.com/game/proto"
|
||||
"mongo.games.com/game/protocol/server"
|
||||
"mongo.games.com/goserver/core/mongo"
|
||||
"mongo.games.com/goserver/srvlib"
|
||||
)
|
||||
|
||||
func init() {
|
||||
common.RegisteServerCtrlCallback(func(code int32) {
|
||||
switch code {
|
||||
common.RegisterServerCtrlCallback(func(msg *server.ServerCtrl) {
|
||||
switch msg.GetCtrlCode() {
|
||||
case common.SrvCtrlStateSwitchCode:
|
||||
pack := &server.ServerStateSwitch{
|
||||
SrvType: proto.Int(common.GetSelfSrvType()),
|
||||
SrvId: proto.Int(common.GetSelfSrvId()),
|
||||
}
|
||||
proto.SetDefaults(pack)
|
||||
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())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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
|
||||
for i := 0; i < len(model.GMACData.WhiteList); i++ {
|
||||
if model.GMACData.WhiteList[i] == csl.GetUsername() {
|
||||
|
|
|
@ -296,18 +296,18 @@ func init() {
|
|||
srvid := int(sr.GetSrvId())
|
||||
gameSess := GameSessMgrSington.GetGameSess(srvid)
|
||||
if gameSess != nil {
|
||||
if gameSess.state == common.GAME_SESS_STATE_ON {
|
||||
gameSess.SwitchState(common.GAME_SESS_STATE_OFF)
|
||||
if gameSess.state == common.GameSessStateOn {
|
||||
gameSess.SwitchState(common.GameSessStateOff)
|
||||
} else {
|
||||
gameSess.SwitchState(common.GAME_SESS_STATE_ON)
|
||||
gameSess.SwitchState(common.GameSessStateOn)
|
||||
}
|
||||
} else {
|
||||
gateSess := GameSessMgrSington.GetGateSess(srvid)
|
||||
if gateSess != nil {
|
||||
if gateSess.state == common.GAME_SESS_STATE_ON {
|
||||
gateSess.SwitchState(common.GAME_SESS_STATE_OFF)
|
||||
if gateSess.state == common.GameSessStateOn {
|
||||
gateSess.SwitchState(common.GameSessStateOff)
|
||||
} else {
|
||||
gateSess.SwitchState(common.GAME_SESS_STATE_ON)
|
||||
gateSess.SwitchState(common.GameSessStateOn)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,13 +43,12 @@ type GameSession struct {
|
|||
gameIds []int32
|
||||
}
|
||||
|
||||
// 构造函数
|
||||
func NewGameSession(srvId, srvType int, s *netlib.Session) *GameSession {
|
||||
gs := &GameSession{
|
||||
Session: s,
|
||||
srvId: srvId,
|
||||
srvType: srvType,
|
||||
state: common.GAME_SESS_STATE_ON,
|
||||
state: common.GameSessStateOn,
|
||||
players: make(map[int32]*Player),
|
||||
scenes: make(map[int]*Scene),
|
||||
cps: make(map[string]*model.CoinPoolSetting),
|
||||
|
@ -57,13 +56,6 @@ func NewGameSession(srvId, srvType int, s *netlib.Session) *GameSession {
|
|||
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 {
|
||||
if this.Session == nil {
|
||||
return 0
|
||||
|
@ -85,7 +77,6 @@ func (this *GameSession) CloseAllScene() {
|
|||
OpRetCode: gamehall_proto.OpResultCode_Game_OPRC_Sucess_Game,
|
||||
IsForce: proto.Int(1),
|
||||
}
|
||||
proto.SetDefaults(scDestroyRoom)
|
||||
scene.Broadcast(int(gamehall_proto.GameHallPacketID_PACKET_SC_DESTROYROOM), scDestroyRoom, 0)
|
||||
SceneMgrSingleton.DestroyScene(sceneId, true)
|
||||
}
|
||||
|
@ -105,11 +96,8 @@ func (this *GameSession) OnRegiste() {
|
|||
|
||||
// 注销事件
|
||||
func (this *GameSession) OnUnregiste() {
|
||||
//销毁比赛
|
||||
//MatchMgrSington.DestroyAllMatchByGameSession(this)
|
||||
//解散房间
|
||||
this.CloseAllScene()
|
||||
|
||||
GameSessionListenerSet.Range(func(key, val interface{}) bool {
|
||||
if lis, ok := val.(GameSessionListener); ok {
|
||||
lis.OnGameSessionUnregiste(this)
|
||||
|
@ -130,12 +118,13 @@ func (this *GameSession) SwitchState(state common.GameSessState) {
|
|||
}
|
||||
this.state = state
|
||||
switch state {
|
||||
case common.GAME_SESS_STATE_ON:
|
||||
case common.GameSessStateOn:
|
||||
this.OnStateOn()
|
||||
case common.GAME_SESS_STATE_OFF:
|
||||
case common.GameSessStateOff:
|
||||
this.OnStateOff()
|
||||
}
|
||||
}
|
||||
|
||||
func (this *GameSession) OnStateOn() {
|
||||
pack := &server_proto.ServerState{
|
||||
SrvState: proto.Int(int(this.state)),
|
||||
|
@ -143,6 +132,7 @@ func (this *GameSession) OnStateOn() {
|
|||
proto.SetDefaults(pack)
|
||||
this.Send(int(server_proto.SSPacketID_PACKET_WG_SERVER_STATE), pack)
|
||||
}
|
||||
|
||||
func (this *GameSession) OnStateOff() {
|
||||
pack := &server_proto.ServerState{
|
||||
SrvState: proto.Int(int(this.state)),
|
||||
|
|
|
@ -2,21 +2,18 @@ package main
|
|||
|
||||
import (
|
||||
"math"
|
||||
"mongo.games.com/game/protocol/webapi"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"mongo.games.com/game/common"
|
||||
"mongo.games.com/goserver/core/logger"
|
||||
"mongo.games.com/goserver/core/netlib"
|
||||
"mongo.games.com/goserver/srvlib"
|
||||
"mongo.games.com/goserver/srvlib/protocol"
|
||||
)
|
||||
|
||||
//const (
|
||||
// ReplayServerType int = 8
|
||||
// ReplayServerId = 801
|
||||
//)
|
||||
"mongo.games.com/game/common"
|
||||
"mongo.games.com/game/model"
|
||||
"mongo.games.com/game/protocol/webapi"
|
||||
)
|
||||
|
||||
var GameSessMgrSington = &GameSessMgr{
|
||||
servers: make(map[int]*GameSession),
|
||||
|
@ -25,9 +22,9 @@ var GameSessMgrSington = &GameSessMgr{
|
|||
}
|
||||
|
||||
type GameSessMgr struct {
|
||||
servers map[int]*GameSession
|
||||
gamesrvs map[int][]*GameSession
|
||||
gates map[int]*GameSession
|
||||
servers map[int]*GameSession // 游戏服务id
|
||||
gamesrvs map[int][]*GameSession // 游戏id
|
||||
gates map[int]*GameSession // 网关id
|
||||
}
|
||||
|
||||
// 注册事件
|
||||
|
@ -134,6 +131,7 @@ func (this *GameSessMgr) OnUnregiste(s *netlib.Session) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *GameSessMgr) GetGameServerSess(gameid int) []*GameSession {
|
||||
return this.gamesrvs[gameid]
|
||||
}
|
||||
|
@ -146,7 +144,7 @@ func (this *GameSessMgr) GetMinLoadSess(gameid int) *GameSession {
|
|||
if gss, exist := this.gamesrvs[gameid]; exist {
|
||||
if gss != nil {
|
||||
for _, s := range gss {
|
||||
if s.state == common.GAME_SESS_STATE_ON {
|
||||
if s.state == common.GameSessStateOn {
|
||||
loadFactor = s.GetLoadFactor()
|
||||
if minLoad > loadFactor {
|
||||
minLoad = loadFactor
|
||||
|
@ -162,7 +160,7 @@ func (this *GameSessMgr) GetMinLoadSess(gameid int) *GameSession {
|
|||
if gss, exist := this.gamesrvs[0]; exist {
|
||||
if gss != nil {
|
||||
for _, s := range gss {
|
||||
if s.state == common.GAME_SESS_STATE_ON {
|
||||
if s.state == common.GameSessStateOn {
|
||||
loadFactor = s.GetLoadFactor()
|
||||
if minLoad > loadFactor {
|
||||
minLoad = loadFactor
|
||||
|
@ -184,6 +182,7 @@ func (this *GameSessMgr) GetGameSess(srvId int) *GameSession {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *GameSessMgr) GetAllGameSess() []*GameSession {
|
||||
servers := make([]*GameSession, 0)
|
||||
for _, v := range this.servers {
|
||||
|
@ -191,17 +190,13 @@ func (this *GameSessMgr) GetAllGameSess() []*GameSession {
|
|||
}
|
||||
return servers
|
||||
}
|
||||
|
||||
func (this *GameSessMgr) GetGateSess(srvId int) *GameSession {
|
||||
if gs, exist := this.gates[srvId]; exist {
|
||||
return gs
|
||||
}
|
||||
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 {
|
||||
_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{
|
||||
SrvId: int32(common.GetSelfSrvId()),
|
||||
SrvType: int32(common.GetSelfSrvType()),
|
||||
State: int32(common.GAME_SESS_STATE_ON),
|
||||
State: int32(common.GameSessStateOn),
|
||||
PlayerNum: int32(len(PlayerMgrSington.players)),
|
||||
RobotNum: int32(len(PlayerMgrSington.snidMap) - len(PlayerMgrSington.players)),
|
||||
SceneNum: int32(len(SceneMgrSingleton.scenes)),
|
||||
}
|
||||
if SrvIsMaintaining {
|
||||
myInfo.State = int32(common.GAME_SESS_STATE_ON)
|
||||
} else {
|
||||
myInfo.State = int32(common.GAME_SESS_STATE_OFF)
|
||||
if model.GameParamData.SrvMaintain {
|
||||
if !common.SrvIsMaintaining {
|
||||
myInfo.State = int32(common.GameSessStateOn)
|
||||
} else {
|
||||
myInfo.State = int32(common.GameSessStateOff)
|
||||
}
|
||||
}
|
||||
//把自己加进去
|
||||
datas = append(datas, myInfo)
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"mongo.games.com/goserver/core/logger"
|
||||
|
||||
"mongo.games.com/game/common"
|
||||
"mongo.games.com/goserver/core/mongo"
|
||||
"mongo.games.com/game/protocol/server"
|
||||
)
|
||||
|
||||
var SrvIsMaintaining = true
|
||||
|
||||
func init() {
|
||||
common.RegisteServerCtrlCallback(func(code int32) {
|
||||
switch code {
|
||||
common.RegisterServerCtrlCallback(func(msg *server.ServerCtrl) {
|
||||
switch msg.GetCtrlCode() {
|
||||
case common.SrvCtrlStateSwitchCode:
|
||||
SrvIsMaintaining = !SrvIsMaintaining
|
||||
case common.SrvCtrlResetMgoSession:
|
||||
mongo.ResetAllSession()
|
||||
common.SrvIsMaintaining = !common.SrvIsMaintaining
|
||||
|
||||
default:
|
||||
logger.Logger.Errorf("unknown server ctrl code:%d", msg.GetCtrlCode())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue