Compare commits
No commits in common. "fcdb12669c23a6122e87aabb74b35cd2db50fcee" and "fbacc4d57b9c0839a042f373c47787f99d3fa2f9" have entirely different histories.
fcdb12669c
...
fbacc4d57b
|
@ -0,0 +1,50 @@
|
||||||
|
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,55 +1,54 @@
|
||||||
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 (
|
||||||
GameSessStateOff GameSessState = iota //关闭状态
|
GAME_SESS_STATE_OFF GameSessState = iota //关闭状态
|
||||||
GameSessStateOn //开启状态
|
GAME_SESS_STATE_ON //开启状态
|
||||||
)
|
)
|
||||||
|
|
||||||
var SrvIsMaintaining = true
|
var ServerCtrlCallback func(int32)
|
||||||
|
|
||||||
var ServerCtrlCallback func(msg *server.ServerCtrl)
|
func RegisteServerCtrlCallback(cb func(int32)) {
|
||||||
|
|
||||||
func RegisterServerCtrlCallback(cb func(msg *server.ServerCtrl)) {
|
|
||||||
ServerCtrlCallback = cb
|
ServerCtrlCallback = cb
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
type ServerCtrlPacketFactory struct {
|
||||||
netlib.Register(int(server.SSPacketID_PACKET_MS_SRVCTRL), &server.ServerCtrl{}, ServerCtrlHandler)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerCtrlHandler 服务器控制,通用事件
|
type ServerCtrlHandler struct {
|
||||||
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() {
|
|
||||||
|
func (this *ServerCtrlPacketFactory) CreatePacket() interface{} {
|
||||||
|
pack := &server.ServerCtrl{}
|
||||||
|
return pack
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ServerCtrlHandler) Process(s *netlib.Session, packetid int, data interface{}) error {
|
||||||
|
|
||||||
|
if sc, ok := data.(*server.ServerCtrl); ok {
|
||||||
|
logger.Logger.Trace("ServerCtrlHandler.Process== ", *sc)
|
||||||
|
switch sc.GetCtrlCode() {
|
||||||
case SrvCtrlCloseCode:
|
case SrvCtrlCloseCode:
|
||||||
module.Stop()
|
module.Stop()
|
||||||
|
|
||||||
case SrvCtrlResetMgoSession:
|
|
||||||
mongo.ResetAllSession()
|
|
||||||
|
|
||||||
default:
|
|
||||||
logger.Logger.Errorf("unknow server ctrl %v", msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 服务自己处理的特殊事件
|
//回调
|
||||||
if ServerCtrlCallback != nil {
|
if ServerCtrlCallback != nil {
|
||||||
ServerCtrlCallback(msg)
|
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{})
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,172 @@
|
||||||
|
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 {
|
func (this *Scene) CheckNeedDestroy() bool {
|
||||||
//if common.IsLocalGame(this.GameId) {
|
//if common.IsLocalGame(this.GameId) {
|
||||||
return ServerStateMgr.GetState() == common.GameSessStateOff || this.graceDestroy
|
return ServerStateMgr.GetState() == common.GAME_SESS_STATE_OFF || 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)
|
||||||
//}
|
//}
|
||||||
|
|
|
@ -1,26 +1,25 @@
|
||||||
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.RegisterServerCtrlCallback(func(msg *server.ServerCtrl) {
|
common.RegisteServerCtrlCallback(func(code int32) {
|
||||||
switch msg.GetCtrlCode() {
|
switch code {
|
||||||
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:
|
||||||
default:
|
mongo.ResetAllSession()
|
||||||
logger.Logger.Errorf("unknow server ctrl code:%d", msg.GetCtrlCode())
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var ServerStateMgr = &ServerStateManager{
|
var ServerStateMgr = &ServerStateManager{
|
||||||
State: common.GameSessStateOn,
|
State: common.GAME_SESS_STATE_ON,
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerStateManager struct {
|
type ServerStateManager struct {
|
||||||
|
@ -13,7 +13,7 @@ type ServerStateManager struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ServerStateManager) Init() {
|
func (this *ServerStateManager) Init() {
|
||||||
this.State = common.GameSessStateOn
|
this.State = common.GAME_SESS_STATE_ON
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ServerStateManager) SetState(state common.GameSessState) {
|
func (this *ServerStateManager) SetState(state common.GameSessState) {
|
||||||
|
|
|
@ -1997,7 +1997,7 @@ func (this *TienLenSceneData) TrySmallGameBilled() {
|
||||||
winPlayer.bombRankScore += rankScore * rule.RankBaseScore
|
winPlayer.bombRankScore += rankScore * rule.RankBaseScore
|
||||||
}
|
}
|
||||||
//lose
|
//lose
|
||||||
if this.IsMatchScene() || this.IsCustom() {
|
if this.IsMatchScene() && this.IsCustom() {
|
||||||
losePlayer.AddCoinNoLog(-score, 0)
|
losePlayer.AddCoinNoLog(-score, 0)
|
||||||
} else {
|
} else {
|
||||||
losePlayer.AddCoin(-score, common.GainWay_CoinSceneLost, 0, "system", this.GetSceneName())
|
losePlayer.AddCoin(-score, common.GainWay_CoinSceneLost, 0, "system", this.GetSceneName())
|
||||||
|
|
|
@ -1,26 +1,25 @@
|
||||||
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.RegisterServerCtrlCallback(func(msg *server.ServerCtrl) {
|
common.RegisteServerCtrlCallback(func(code int32) {
|
||||||
switch msg.GetCtrlCode() {
|
switch code {
|
||||||
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:
|
||||||
default:
|
mongo.ResetAllSession()
|
||||||
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 && common.SrvIsMaintaining {
|
if model.GameParamData.SrvMaintain && 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() {
|
||||||
|
|
|
@ -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.GameSessStateOn {
|
if gameSess.state == common.GAME_SESS_STATE_ON {
|
||||||
gameSess.SwitchState(common.GameSessStateOff)
|
gameSess.SwitchState(common.GAME_SESS_STATE_OFF)
|
||||||
} else {
|
} else {
|
||||||
gameSess.SwitchState(common.GameSessStateOn)
|
gameSess.SwitchState(common.GAME_SESS_STATE_ON)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
gateSess := GameSessMgrSington.GetGateSess(srvid)
|
gateSess := GameSessMgrSington.GetGateSess(srvid)
|
||||||
if gateSess != nil {
|
if gateSess != nil {
|
||||||
if gateSess.state == common.GameSessStateOn {
|
if gateSess.state == common.GAME_SESS_STATE_ON {
|
||||||
gateSess.SwitchState(common.GameSessStateOff)
|
gateSess.SwitchState(common.GAME_SESS_STATE_OFF)
|
||||||
} else {
|
} else {
|
||||||
gateSess.SwitchState(common.GameSessStateOn)
|
gateSess.SwitchState(common.GAME_SESS_STATE_ON)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,12 +43,13 @@ 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.GameSessStateOn,
|
state: common.GAME_SESS_STATE_ON,
|
||||||
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),
|
||||||
|
@ -56,6 +57,13 @@ 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
|
||||||
|
@ -77,6 +85,7 @@ 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)
|
||||||
}
|
}
|
||||||
|
@ -96,8 +105,11 @@ 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)
|
||||||
|
@ -118,13 +130,12 @@ func (this *GameSession) SwitchState(state common.GameSessState) {
|
||||||
}
|
}
|
||||||
this.state = state
|
this.state = state
|
||||||
switch state {
|
switch state {
|
||||||
case common.GameSessStateOn:
|
case common.GAME_SESS_STATE_ON:
|
||||||
this.OnStateOn()
|
this.OnStateOn()
|
||||||
case common.GameSessStateOff:
|
case common.GAME_SESS_STATE_OFF:
|
||||||
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)),
|
||||||
|
@ -132,7 +143,6 @@ 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)),
|
||||||
|
|
|
@ -2,19 +2,22 @@ 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"
|
||||||
|
|
||||||
"mongo.games.com/game/common"
|
|
||||||
"mongo.games.com/game/model"
|
|
||||||
"mongo.games.com/game/protocol/webapi"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//const (
|
||||||
|
// ReplayServerType int = 8
|
||||||
|
// ReplayServerId = 801
|
||||||
|
//)
|
||||||
|
|
||||||
var GameSessMgrSington = &GameSessMgr{
|
var GameSessMgrSington = &GameSessMgr{
|
||||||
servers: make(map[int]*GameSession),
|
servers: make(map[int]*GameSession),
|
||||||
gamesrvs: make(map[int][]*GameSession),
|
gamesrvs: make(map[int][]*GameSession),
|
||||||
|
@ -22,9 +25,9 @@ var GameSessMgrSington = &GameSessMgr{
|
||||||
}
|
}
|
||||||
|
|
||||||
type GameSessMgr struct {
|
type GameSessMgr struct {
|
||||||
servers map[int]*GameSession // 游戏服务id
|
servers map[int]*GameSession
|
||||||
gamesrvs map[int][]*GameSession // 游戏id
|
gamesrvs map[int][]*GameSession
|
||||||
gates map[int]*GameSession // 网关id
|
gates map[int]*GameSession
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注册事件
|
// 注册事件
|
||||||
|
@ -131,7 +134,6 @@ 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]
|
||||||
}
|
}
|
||||||
|
@ -144,7 +146,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.GameSessStateOn {
|
if s.state == common.GAME_SESS_STATE_ON {
|
||||||
loadFactor = s.GetLoadFactor()
|
loadFactor = s.GetLoadFactor()
|
||||||
if minLoad > loadFactor {
|
if minLoad > loadFactor {
|
||||||
minLoad = loadFactor
|
minLoad = loadFactor
|
||||||
|
@ -160,7 +162,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.GameSessStateOn {
|
if s.state == common.GAME_SESS_STATE_ON {
|
||||||
loadFactor = s.GetLoadFactor()
|
loadFactor = s.GetLoadFactor()
|
||||||
if minLoad > loadFactor {
|
if minLoad > loadFactor {
|
||||||
minLoad = loadFactor
|
minLoad = loadFactor
|
||||||
|
@ -182,7 +184,6 @@ 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 {
|
||||||
|
@ -190,13 +191,17 @@ 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 {
|
||||||
|
@ -294,17 +299,15 @@ 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.GameSessStateOn),
|
State: int32(common.GAME_SESS_STATE_ON),
|
||||||
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 model.GameParamData.SrvMaintain {
|
if SrvIsMaintaining {
|
||||||
if !common.SrvIsMaintaining {
|
myInfo.State = int32(common.GAME_SESS_STATE_ON)
|
||||||
myInfo.State = int32(common.GameSessStateOn)
|
|
||||||
} else {
|
} else {
|
||||||
myInfo.State = int32(common.GameSessStateOff)
|
myInfo.State = int32(common.GAME_SESS_STATE_OFF)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//把自己加进去
|
//把自己加进去
|
||||||
datas = append(datas, myInfo)
|
datas = append(datas, myInfo)
|
||||||
|
|
|
@ -1,23 +1,19 @@
|
||||||
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/game/model"
|
"mongo.games.com/goserver/core/mongo"
|
||||||
"mongo.games.com/game/protocol/server"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
var SrvIsMaintaining = true
|
||||||
common.RegisterServerCtrlCallback(func(msg *server.ServerCtrl) {
|
|
||||||
switch msg.GetCtrlCode() {
|
|
||||||
case common.SrvCtrlStateSwitchCode:
|
|
||||||
if model.GameParamData.SrvMaintain {
|
|
||||||
common.SrvIsMaintaining = !common.SrvIsMaintaining
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
func init() {
|
||||||
logger.Logger.Errorf("unknown server ctrl code:%d", msg.GetCtrlCode())
|
common.RegisteServerCtrlCallback(func(code int32) {
|
||||||
|
switch code {
|
||||||
|
case common.SrvCtrlStateSwitchCode:
|
||||||
|
SrvIsMaintaining = !SrvIsMaintaining
|
||||||
|
case common.SrvCtrlResetMgoSession:
|
||||||
|
mongo.ResetAllSession()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue