Merge branch 'develop' into release

This commit is contained in:
sk 2024-06-04 09:27:19 +08:00
commit 46a4255273
127 changed files with 4185 additions and 7547 deletions

View File

@ -19,10 +19,6 @@ var ActionMgrSington = &ActionMgr{
pool: make(map[int]ActionBase),
}
func init() {
}
type ActionMgr struct {
pool map[int]ActionBase
}

View File

@ -169,7 +169,6 @@ const (
// 房间模式
const (
SceneMode_Public = iota //公共房间
SceneMode_Club //俱乐部房间
SceneMode_Private //私人房间
SceneMode_Match //赛事房间
SceneMode_Thr //三方房间
@ -187,78 +186,88 @@ const (
)
const (
GainWay_NewPlayer int32 = 0 //0.新建角色
GainWay_Pay = 1 //1.后台增加(主要是充值)
GainWay_ByPMCmd = 2 //2.pm命令
GainWay_MatchBreakBack = 3 //3.退赛退还
GainWay_MatchSystemSupply = 4 //4.比赛奖励
GainWay_Exchange = 5 //5.兑换
GainWay_ServiceFee = 6 //6.桌费
GainWay_CoinSceneWin = 7 //7.金豆场赢取
GainWay_CoinSceneLost = 8 //8.金豆场输
GainWay_CoinSceneEnter = 9 //9.进入金币场预扣
GainWay_ShopBuy = 10 //10.商城购买或者兑换
GainWay_CoinSceneLeave = 11 //11.金豆场回兑
GainWay_HundredSceneWin = 12 //12.万人场赢取
GainWay_HundredSceneLost = 13 //13.万人场输
GainWay_MessageAttach = 14 //14.邮件
GainWay_SafeBoxSave = 15 //15.保险箱存入
GainWay_SafeBoxTakeOut = 16 //16.保险箱取出
GainWay_Fishing = 17 //17.捕鱼
GainWay_CoinSceneExchange = 18 //18.金豆场兑换
GainWay_UpgradeAccount = 19 //19.升级账号
GainWay_API_AddCoin = 20 //20.API操作钱包
GainWay_GoldCome = 21 //21.财神降临
GainWay_Transfer_System2Thrid = 22 //22.系统平台转入到第三方平台的金币
GainWay_Transfer_Thrid2System = 23 //23.第三方平台转入到系统平台的金币
GainWay_RebateTask = 24 //24.返利获取
GainWay_IOSINSTALLSTABLE = 25 //25.ios安装奖励
GainWay_VirtualChange = 26 //26.德州虚拟账变
GainWay_CreatePrivateScene = 27 //27.创建私有房间
GainWay_PrivateSceneReturn = 28 //28.解散私有房间返还
GainWay_OnlineRandCoin = 29 //29.红包雨
GainWay_Expire = 30 //30.到期清理
GainWay_PromoterBind = 31 //31.手动绑定推广员
GainWay_GradeShopReturn = 32 //32.积分商城撤单退还积分
GainWay_Api_In = 33 //33.转移金币
GainWay_Api_Out = 34 //34.转移金币
GainWay_Shop_Buy = 35 //35.购买记录
GainWay_MAIL_MTEM = 36 //36.邮件领取道具
GainWay_Item_Sale = 37 //37.道具出售
GainWay_ReliefFund = 38 //38.领取救济金
GainWay_Shop_Revoke = 39 //39.撤单
GainWay_ActSign = 40 //40.签到
GainWay_NewPlayer int32 = 0 //新建角色
GainWay_Pay = 1 //后台增加(主要是充值)
GainWay_ByPMCmd = 2 //pm命令
GainWay_MatchBreakBack = 3 //退赛退还
GainWay_MatchSystemSupply = 4 //比赛奖励
GainWay_Exchange = 5 //兑换
GainWay_ServiceFee = 6 //桌费
GainWay_CoinSceneWin = 7 //金豆场赢取
GainWay_CoinSceneLost = 8 //金豆场输
GainWay_CoinSceneEnter = 9 //进入金币场预扣
GainWay_ShopBuy = 10 //商城购买或者兑换
GainWay_CoinSceneLeave = 11 //金豆场回兑
GainWay_HundredSceneWin = 12 //万人场赢取
GainWay_HundredSceneLost = 13 //万人场输
GainWay_MessageAttach = 14 //邮件
GainWay_SafeBoxSave = 15 //保险箱存入
GainWay_SafeBoxTakeOut = 16 //保险箱取出
GainWay_Fishing = 17 //捕鱼
GainWay_CoinSceneExchange = 18 //金豆场兑换
GainWay_UpgradeAccount = 19 //升级账号
GainWay_API_AddCoin = 20 //API操作钱包
GainWay_GoldCome = 21 //财神降临
GainWay_Transfer_System2Thrid = 22 //系统平台转入到第三方平台的金币
GainWay_Transfer_Thrid2System = 23 //第三方平台转入到系统平台的金币
GainWay_RebateTask = 24 //返利获取
GainWay_IOSINSTALLSTABLE = 25 //ios安装奖励
GainWay_VirtualChange = 26 //德州虚拟账变
GainWay_CreatePrivateScene = 27 //创建私有房间
GainWay_PrivateSceneReturn = 28 //解散私有房间返还
GainWay_OnlineRandCoin = 29 //红包雨
GainWay_Expire = 30 //到期清理
GainWay_PromoterBind = 31 //手动绑定推广员
GainWay_GradeShopReturn = 32 //积分商城撤单退还积分
GainWay_Api_In = 33 //转移金币
GainWay_Api_Out = 34 //转移金币
GainWay_Shop_Buy = 35 //购买记录
GainWay_MAIL_MTEM = 36 //邮件领取道具
GainWay_Item_Sale = 37 //道具出售
GainWay_ReliefFund = 38 //领取救济金
GainWay_Shop_Revoke = 39 //撤单
GainWay_ActSign = 40 //
GainWay_MatchSignup = 41 //比赛报名费用
GainWay_MatchSeason = 42 //比赛赛季奖励
GainWay_ActSignNew = 43 //43.新签到
GainWay_ActTurnplate = 44 //44.轮盘
GainWay_ActBlindBox = 45 //45.盲盒
GainWay_ActFirstPay = 46 //46.首充
GainWay_VIPGift = 47 //47.vip礼包
GainWay_ActContinuousPay = 48 //48.连续充值
GainWay_ActJybAward = 49 //49.礼包码兑换
GainWay_LeaveDeduct = 50 //50.离开扣分
GainWay_LeaveCombat = 51 //51.离开补偿
GainWay_RankMatch = 52 //52.排位赛段位奖励
GainWay_AddBag = 53 //53 增加背包接口调用
GainWay_SmallRocket = 54 //54.小火箭收入
GainWay_BindTel = 55 //55.绑定手机号
GainWay_ReliefFund2 = 56 //56.救济金看视频双倍领取
GainWay_ActTurnplate2 = 57 //57.轮盘看视频双倍领取
GainWay_ActSignNew2 = 58 //58.签到看视频双倍领取
GainWay_ItemUse = 59 //59.道具使用
GainWay_PhoneScore = 60 //60.积分抽奖活动
GainWay_RankReward = 61 //61.段位奖励
GainWay_TaskReward = 62 //62.任务奖励
GainWay_Interact = 63 //63.房间内互动效果
GainWay_Collect = 64 //64.集卡活动
GainWay_WeekCardAward = 65 //65.周卡每日奖励
GainWay_PigrankTakeCoin = 66 //66.存钱罐领取耗费钻石
GainWay_PigrankGainCoin = 67 //66.存钱罐打开获取金币
GainWay_ItemMove = 68 //68.道具赠送
GainWay_RoleUpgrade = 69 //69.角色升级
GainWay_PetUpgrade = 70 //70.宠物升级
GainWay_Game = 71 //71.玩游戏获得
GainWay_ActSignNew = 43 //新签到
GainWay_ActTurnplate = 44 //轮盘
GainWay_ActBlindBox = 45 //盲盒
GainWay_ActFirstPay = 46 //首充
GainWay_VIPGift = 47 //vip礼包
GainWay_ActContinuousPay = 48 //连续充值
GainWay_ActJybAward = 49 //礼包码兑换
GainWay_LeaveDeduct = 50 //离开扣分
GainWay_LeaveCombat = 51 //离开补偿
GainWay_RankMatch = 52 //排位赛段位奖励
GainWay_AddBag = 53 //增加背包接口调用
GainWay_SmallRocket = 54 //小火箭收入
GainWay_BindTel = 55 //绑定手机号
GainWay_ReliefFund2 = 56 //救济金看视频双倍领取
GainWay_ActTurnplate2 = 57 //轮盘看视频双倍领取
GainWay_ActSignNew2 = 58 //签到看视频双倍领取
GainWay_ItemUse = 59 //道具使用
GainWay_PhoneScore = 60 //手机积分活动
GainWay_RankReward = 61 //排位奖励
GainWay_TaskReward = 62 //任务奖励
GainWay_Interact = 63 //房间内互动效果
GainWay_Collect = 64 //集卡活动
GainWay_WeekCardAward = 65 //周卡奖励
GainWay_PigrankTakeCoin = 66 //存钱罐领取耗费钻石
GainWay_PigrankGainCoin = 67 //存钱罐打开获取金币
GainWay_ItemMove = 68 //道具赠送
GainWay_RoleUpgrade = 69 //角色升级
GainWay_PetUpgrade = 70 //宠物升级
GainWay_Game = 71 //游戏掉落
GainWayItemCollectLogin = 73 //集卡活动登录
GainWayItemCollectExchange = 74 //集卡活动兑换
GainWayItemPhoneScoreExchange = 75 //抽手机活动兑换
GainWayItemTaskInvite = 78 //邀请任务
GainWayItemTaskNewPlayer = 79 //新手任务
GainWayItemTaskAchievement = 80 //成就任务
GainWayItemTaskEveryDay = 81 //每日任务
GainWayItemWeekActive = 82 //周活跃奖励
GainWayContinueSign = 83 //累计签到
GainWayBackend = 84 // 后台操作
)
// 后台选择 金币变化类型 的充值 类型id号起始

View File

@ -5,13 +5,12 @@ import (
"path/filepath"
"github.com/howeyc/fsnotify"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/basic"
"mongo.games.com/goserver/core/logger"
)
var LastModifyConfig int64
func init() {
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
var err error
@ -62,7 +61,7 @@ type loggerParamModifiedCommand struct {
}
func (lmc *loggerParamModifiedCommand) Done(o *basic.Object) error {
logger.Logger.Info("===reload ", lmc.fileName)
logger.Logger.Info("reload logger.xml:", lmc.fileName)
data, err := os.ReadFile(lmc.fileName)
if err != nil {
return err
@ -70,7 +69,7 @@ func (lmc *loggerParamModifiedCommand) Done(o *basic.Object) error {
if len(data) != 0 {
err = logger.Reload(lmc.fileName)
if err != nil {
logger.Logger.Warn("===reload ", lmc.fileName, err)
logger.Logger.Warnf("reload logger.xml %v err: %v", lmc.fileName, err)
}
}
return err

View File

@ -1,16 +1,15 @@
ъУ†
ъФ†
ъХ†
ъЦ†
ъЧ†
ИШ†
ИЩ†
ИЪ†
 ИЫ†
иУ†
иФ†
иХ†
иЦ†
ЮЧ†
2Ш†
2Щ†
2Ъ†
 2Ы†


Ь†
 2ЎЌђN
 ¬ЎЌР†
 2ЎЌ Ќ
Ь†
 фЎЌђN
 dЎЌР†
 ЎЌ Ќ

View File

@ -2,91 +2,91 @@
"Arr": [
{
"Id": 1,
"Rate": 250,
"Rate": 1000,
"ItemID": {
"50003": 1
}
},
{
"Id": 2,
"Rate": 250,
"Rate": 1000,
"ItemID": {
"50004": 1
}
},
{
"Id": 3,
"Rate": 250,
"Rate": 1000,
"ItemID": {
"50005": 1
}
},
{
"Id": 4,
"Rate": 250,
"Rate": 1000,
"ItemID": {
"50006": 1
}
},
{
"Id": 5,
"Rate": 250,
"Rate": 350,
"ItemID": {
"50007": 1
}
},
{
"Id": 6,
"Rate": 200,
"Rate": 50,
"ItemID": {
"50008": 1
}
},
{
"Id": 7,
"Rate": 200,
"Rate": 50,
"ItemID": {
"50009": 1
}
},
{
"Id": 8,
"Rate": 200,
"Rate": 50,
"ItemID": {
"50010": 1
}
},
{
"Id": 9,
"Rate": 200,
"Rate": 50,
"ItemID": {
"50011": 1
}
},
{
"Id": 10,
"Rate": 10,
"Rate": 1,
"ItemID": {
"50012": 1
}
},
{
"Id": 11,
"Rate": 50,
"Rate": 500,
"ItemID": {
"100001": 10000
}
},
{
"Id": 12,
"Rate": 300,
"Rate": 100,
"ItemID": {
"100001": 50000
}
},
{
"Id": 13,
"Rate": 50,
"Rate": 20,
"ItemID": {
"100001": 100000
}

Binary file not shown.

View File

@ -748,7 +748,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 6,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -806,7 +805,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 4,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -863,7 +861,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -919,7 +916,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -975,7 +971,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -1031,7 +1026,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -1089,7 +1083,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 6,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -1147,7 +1140,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 4,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -1204,7 +1196,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -1260,7 +1251,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -1316,7 +1306,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -1372,7 +1361,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -1430,7 +1418,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 4,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -1488,7 +1475,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -1545,7 +1531,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 2,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -1601,7 +1586,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 2,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -1657,7 +1641,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 2,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -1713,7 +1696,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 2,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -1771,7 +1753,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 6,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -1829,7 +1810,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 4,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -1886,7 +1866,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -1942,7 +1921,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -1998,7 +1976,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -2054,7 +2031,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -2114,7 +2090,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 6,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -2174,7 +2149,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 4,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -2233,7 +2207,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -2291,7 +2264,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -2349,7 +2321,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -2407,7 +2378,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -2467,7 +2437,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 6,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -2527,7 +2496,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 4,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -2586,7 +2554,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -2644,7 +2611,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -2702,7 +2668,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -2760,7 +2725,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -2820,7 +2784,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 4,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -2880,7 +2843,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -2939,7 +2901,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 2,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -2997,7 +2958,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 2,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -3055,7 +3015,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 2,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -3113,7 +3072,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 2,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -3173,7 +3131,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 6,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -3233,7 +3190,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 4,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -3292,7 +3248,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -3350,7 +3305,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -3408,7 +3362,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -3466,7 +3419,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 3,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -3874,7 +3826,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -3933,7 +3884,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -3992,7 +3942,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -4051,7 +4000,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -4110,7 +4058,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -4166,7 +4113,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": -1,
"PlayerWaterRate": 100,
"BetWaterRate": 100
@ -4218,7 +4164,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": -1,
"PlayerWaterRate": 100,
"BetWaterRate": 100
@ -4270,7 +4215,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": -1,
"PlayerWaterRate": 100,
"BetWaterRate": 100
@ -4322,7 +4266,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": -1,
"PlayerWaterRate": 100,
"BetWaterRate": 100
@ -4374,7 +4317,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": -1,
"PlayerWaterRate": 100,
"BetWaterRate": 100
@ -4426,7 +4368,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -4480,7 +4421,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -4533,7 +4473,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -4586,7 +4525,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -4639,7 +4577,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -4692,7 +4629,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -4746,7 +4682,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -4800,7 +4735,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -4853,7 +4787,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -4906,7 +4839,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -4959,7 +4891,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -5012,7 +4943,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -5066,7 +4996,7 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"CreateRoomNum": 6,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -5120,7 +5050,7 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"CreateRoomNum": 4,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -5174,7 +5104,7 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"CreateRoomNum": 2,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -5228,7 +5158,7 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"CreateRoomNum": 6,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -5282,7 +5212,7 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"CreateRoomNum": 4,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -5336,7 +5266,7 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"CreateRoomNum": 2,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100,
@ -5430,7 +5360,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100
},
@ -6179,8 +6108,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100
},
@ -6221,8 +6148,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100
},
@ -6263,8 +6188,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100
},
@ -6305,8 +6228,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100
},
@ -6347,8 +6268,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100
},
@ -6389,8 +6308,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100
},
@ -6431,8 +6348,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100
},
@ -6473,8 +6388,6 @@
"MaxBetCoin": [
0
],
"CreateRoomNum": 1,
"MatchTrueMan": 1,
"PlayerWaterRate": 100,
"BetWaterRate": 100
}

Binary file not shown.

Binary file not shown.

View File

@ -44,6 +44,15 @@
"AppId": "5c56d1644966f078bfb90c71",
"IsDevMode": true
},
"data":{
"RootPath":"../data"
},
"etcd": {
"Url": ["127.0.0.1:2379"],
"UserName": "",
"Password": "",
"DialTimeout": 60
},
"costum": {
"MgoRpcCliNet": "tcp",
"MgoRpcCliAddr": "127.0.0.1:8999",
@ -51,11 +60,6 @@
"RMQExchange": "win88",
"RMQQosPrefetchCount": 2,
"RMQQosPrefetchSize": 0,
"RMQQosGlobal": true,
"etcdurl": [
"127.0.0.1:2379"
],
"etcduser": "",
"etcdpwd": ""
"RMQQosGlobal": true
}
}

View File

@ -7,53 +7,46 @@ import (
"net/rpc"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/broker/rabbitmq"
"mongo.games.com/goserver/core/etcd"
"mongo.games.com/goserver/core/module"
_ "mongo.games.com/game"
_ "mongo.games.com/game/dbproxy/mq"
"mongo.games.com/game/common"
_ "mongo.games.com/game/dbproxy/mq"
"mongo.games.com/game/dbproxy/svc"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
_ "mongo.games.com/game/srvdata"
)
var rabbitMqConsumer *mq.RabbitMQConsumer
func init() {
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
model.InitGameParam()
rabbitMqConsumer = mq.NewRabbitMQConsumer(common.CustomConfig.GetString("RabbitMQURL"), rabbitmq.Exchange{Name: common.CustomConfig.GetString("RMQExchange"), Durable: true})
if rabbitMqConsumer != nil {
rabbitMqConsumer.Start()
}
//尝试初始化
svc.GetOnePlayerIdFromBucket()
return nil
})
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
if rabbitMqConsumer != nil {
rabbitMqConsumer.Stop()
}
model.ShutdownRPClient()
return nil
})
}
func main() {
// 自定义配置文件
model.InitGameParam()
// package模块
defer core.ClosePackages()
core.LoadPackages("config.json")
rpc.HandleHTTP() // 采用http协议作为rpc载体
lis, err := net.Listen(common.CustomConfig.GetString("MgoRpcCliNet"), common.CustomConfig.GetString("MgoRpcCliAddr"))
if err != nil {
log.Fatalln("fatal error: ", err)
}
go http.Serve(lis, nil)
waitor := module.Start()
waitor.Wait("main()")
// core hook
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
etcd.Start()
mq.StartConsumer(common.CustomConfig.GetString("RabbitMQURL"), common.CustomConfig.GetString("RMQExchange"), true)
mq.StartPublisher(common.CustomConfig.GetString("RabbitMQURL"), common.CustomConfig.GetString("RMQExchange"), true, common.CustomConfig.GetInt("RMQPublishBacklog"))
// 尝试初始化玩家id
svc.GetOnePlayerIdFromBucket()
// rpc 服务
rpc.HandleHTTP() // 采用http协议作为rpc载体
lis, err := net.Listen(common.CustomConfig.GetString("MgoRpcCliNet"), common.CustomConfig.GetString("MgoRpcCliAddr"))
if err != nil {
log.Fatalln("rpc start fatal error: ", err)
}
go http.Serve(lis, nil)
return nil
})
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
mq.StopConsumer()
mq.StopPublisher()
return nil
})
// module模块
w := module.Start()
w.Wait("main()")
}

View File

@ -2,11 +2,13 @@ package mq
import (
"encoding/json"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
"mongo.games.com/game/dbproxy/svc"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
)
func init() {
@ -14,13 +16,7 @@ func init() {
msg := e.Message()
if msg != nil {
defer func() {
if err != nil {
mq.BackUp(e, err)
}
e.Ack()
recover()
}()
var log model.APILog

View File

@ -1,56 +0,0 @@
package mq
func init() {
//mq.RegisteSubscriber(model.ClientLogCollName, func(e broker.Event) (err error) {
// msg := e.Message()
// if msg != nil {
// defer func() {
// if err != nil {
// mq.BackUp(e, err)
// }
//
// e.Ack()
//
// recover()
// }()
//
// var log model.ClientLog
// err = json.Unmarshal(msg.Body, &log)
// if err != nil {
// logger.Logger.Errorf("[mq] %s %v", model.ClientLogCollName, err)
// return
// }
//
// logger.Logger.Tracef("[mq] %s %v", model.ClientLogCollName, string(msg.Body))
//
// data := map[string]interface{}{}
// err = json.Unmarshal([]byte(log.Data), &data)
// if err != nil {
// logger.Logger.Errorf("[mq] %s %v", model.ClientLogCollName, err)
// return
// }
//
// // 获取平台id
// platform := log.Platform
// if log.Platform == "" {
// id, ok := data["platform"]
// if ok {
// platform = string(id.([]byte))
// }
// }
//
// data["ts"] = log.Ts
// if log.Snid > 0 {
// data["snid"] = log.Snid
// }
//
// c := svc.ClientLogStartCollection(platform)
// if c != nil {
// err = c.Insert(data)
// }
//
// return
// }
// return nil
//}, broker.Queue(model.ClientLogCollName), broker.DisableAutoAck(), rabbitmq.DurableQueue())
}

View File

@ -2,11 +2,13 @@ package mq
import (
"encoding/json"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
"mongo.games.com/game/dbproxy/svc"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
)
func init() {
@ -14,13 +16,7 @@ func init() {
msg := e.Message()
if msg != nil {
defer func() {
if err != nil {
mq.BackUp(e, err)
}
e.Ack()
recover()
}()
var log model.CoinGiveLog

View File

@ -2,11 +2,13 @@ package mq
import (
"encoding/json"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
"mongo.games.com/game/dbproxy/svc"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
)
func init() {
@ -14,13 +16,7 @@ func init() {
msg := e.Message()
if msg != nil {
defer func() {
if err != nil {
mq.BackUp(e, err)
}
e.Ack()
recover()
}()
var log model.CoinLog
@ -30,7 +26,7 @@ func init() {
}
if log.Count == 0 { //玩家冲账探针
RabbitMQPublisher.Send(model.TopicProbeCoinLogAck, log)
mq.Send(model.TopicProbeCoinLogAck, log)
} else {
c := svc.CoinLogsCollection(log.Platform)
if c != nil {

View File

@ -2,11 +2,13 @@ package mq
import (
"encoding/json"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
"mongo.games.com/game/dbproxy/svc"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
)
func init() {
@ -14,13 +16,7 @@ func init() {
msg := e.Message()
if msg != nil {
defer func() {
if err != nil {
mq.BackUp(e, err)
}
e.Ack()
recover()
}()
var log model.FriendRecord

View File

@ -2,12 +2,14 @@ package mq
import (
"encoding/json"
"mongo.games.com/game/dbproxy/svc"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/game/dbproxy/svc"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
)
func init() {
@ -15,13 +17,7 @@ func init() {
msg := e.Message()
if msg != nil {
defer func() {
if err != nil {
mq.BackUp(e, err)
}
e.Ack()
recover()
}()
var log model.GameDetailedLog

View File

@ -2,11 +2,13 @@ package mq
import (
"encoding/json"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
"mongo.games.com/game/dbproxy/svc"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
)
func init() {
@ -14,13 +16,7 @@ func init() {
msg := e.Message()
if msg != nil {
defer func() {
if err != nil {
mq.BackUp(e, err)
}
e.Ack()
recover()
}()
var log model.GamePlayerListLog

View File

@ -22,13 +22,7 @@ func init() {
msg := e.Message()
if msg != nil {
defer func() {
if err != nil {
mq.BackUp(e, err)
}
e.Ack()
recover()
}()
var log model.BindInvite
@ -59,7 +53,7 @@ func init() {
InviteNumCache.Put(name, n, int64(time.Hour.Seconds()))
// 更新绑定数量
RabbitMQPublisher.Send(model.AckBindNum, &model.BindNum{
mq.Send(model.AckBindNum, &model.BindNum{
SnId: log.InviteSnId,
Num: n,
})

View File

@ -2,11 +2,13 @@ package mq
import (
"encoding/json"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
"mongo.games.com/game/dbproxy/svc"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
)
func init() {
@ -14,13 +16,7 @@ func init() {
msg := e.Message()
if msg != nil {
defer func() {
if err != nil {
mq.BackUp(e, err)
}
e.Ack()
recover()
}()
var log model.ItemLog

View File

@ -1,31 +0,0 @@
package mq
//func init() {
// mq.RegisteSubscriber(model.JackPotLogCollName, func(e broker.Event) (err error) {
// msg := e.Message()
// if msg != nil {
// defer func() {
// if err != nil {
// mq.BackUp(e, err)
// }
//
// e.Ack()
//
// recover()
// }()
//
// var log model.JackPotLog
// err = json.Unmarshal(msg.Body, &log)
// if err != nil {
// return
// }
//
// c := svc.JackPotLogsCollection(log.Platform)
// if c != nil {
// _, err = c.Upsert(bson.M{"_id": log.LogId}, log)
// }
// return
// }
// return nil
// }, broker.Queue(model.JackPotLogCollName), broker.DisableAutoAck(), rabbitmq.DurableQueue())
//}

View File

@ -2,11 +2,13 @@ package mq
import (
"encoding/json"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
"mongo.games.com/game/dbproxy/svc"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
)
func init() {
@ -14,13 +16,7 @@ func init() {
msg := e.Message()
if msg != nil {
defer func() {
if err != nil {
mq.BackUp(e, err)
}
e.Ack()
recover()
}()
var log model.LoginLog

View File

@ -16,13 +16,7 @@ func init() {
msg := e.Message()
if msg != nil {
defer func() {
if err != nil {
mq.BackUp(e, err)
}
e.Ack()
recover()
}()
var log model.OnlineLog

View File

@ -2,14 +2,16 @@ package mq
import (
"encoding/json"
"mongo.games.com/game/dbproxy/svc"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/basic"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/game/dbproxy/svc"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
)
func init() {
@ -18,13 +20,7 @@ func init() {
msg := e.Message()
if msg != nil {
defer func() {
if err != nil {
mq.BackUp(e, err)
}
e.Ack()
recover()
}()
var log model.PlayerRankScore
@ -53,13 +49,7 @@ func init() {
msg := e.Message()
if msg != nil {
defer func() {
if err != nil {
mq.BackUp(e, err)
}
e.Ack()
recover()
}()
var log model.RankPlayerCoin
@ -88,13 +78,7 @@ func init() {
msg := e.Message()
if msg != nil {
defer func() {
if err != nil {
mq.BackUp(e, err)
}
e.Ack()
recover()
}()
var log model.PlayerLevelInfo

View File

@ -2,11 +2,13 @@ package mq
import (
"encoding/json"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
"mongo.games.com/game/dbproxy/svc"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
)
func init() {
@ -14,13 +16,7 @@ func init() {
msg := e.Message()
if msg != nil {
defer func() {
if err != nil {
mq.BackUp(e, err)
}
e.Ack()
recover()
}()
var log model.SceneCoinLog

View File

@ -3,11 +3,12 @@ package mq
import (
"encoding/json"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
"mongo.games.com/game/dbproxy/svc"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
)
func init() {
@ -15,13 +16,7 @@ func init() {
msg := e.Message()
if msg != nil {
defer func() {
if err != nil {
mq.BackUp(e, err)
}
e.Ack()
recover()
}()
var log model.WelfareLog

View File

@ -1,33 +0,0 @@
package mq
import (
"mongo.games.com/game/common"
"mongo.games.com/game/mq"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/broker/rabbitmq"
)
var RabbitMQPublisher *mq.RabbitMQPublisher
func init() {
////首先加载游戏配置
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
//rabbitmq打开链接
RabbitMQPublisher = mq.NewRabbitMQPublisher(common.CustomConfig.GetString("RabbitMQURL"), rabbitmq.Exchange{Name: common.CustomConfig.GetString("RMQExchange"), Durable: true}, common.CustomConfig.GetInt("RMQPublishBacklog"))
if RabbitMQPublisher != nil {
err := RabbitMQPublisher.Start()
if err != nil {
panic(err)
}
}
return nil
})
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
//关闭rabbitmq连接
if RabbitMQPublisher != nil {
RabbitMQPublisher.Stop()
}
return nil
})
}

View File

@ -1,260 +0,0 @@
package etcd
import (
"context"
"time"
"go.etcd.io/etcd/client/v3"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/basic"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/game/model"
)
/*
etcd常用操作和数据监听
*/
type (
InitFunc func() int64
WatchFunc func(context.Context, int64)
FuncPair struct {
initFunc InitFunc
watchFunc WatchFunc
}
)
type Client struct {
cli *clientv3.Client
functions []FuncPair
closed bool
}
func (c *Client) IsClosed() bool {
return c.closed
}
func (c *Client) Ctx() context.Context {
if c.cli != nil {
return c.cli.Ctx()
}
return context.TODO()
}
func (c *Client) Open(etcdUrl []string, userName, passWord string, dialTimeout time.Duration) error {
var err error
c.cli, err = clientv3.New(clientv3.Config{
Endpoints: etcdUrl,
Username: userName,
Password: passWord,
DialTimeout: dialTimeout,
DialKeepAliveTime: 5 * time.Second,
DialKeepAliveTimeout: 30 * time.Second,
})
if err != nil {
logger.Logger.Errorf("EtcdClient.open(%v) err:%v", etcdUrl, err)
return err
}
c.closed = false
return err
}
func (c *Client) Close() error {
logger.Logger.Warn("EtcdClient.close")
c.closed = true
if c.cli != nil {
return c.cli.Close()
}
return nil
}
// PutValue 添加键值对
func (c *Client) PutValue(key, value string) (*clientv3.PutResponse, error) {
resp, err := c.cli.Put(context.TODO(), key, value)
if err != nil {
logger.Logger.Warnf("EtcdClient.PutValue(%v,%v) error:%v", key, value, err)
}
return resp, err
}
// GetValue 查询
func (c *Client) GetValue(key string) (*clientv3.GetResponse, error) {
resp, err := c.cli.Get(context.TODO(), key)
if err != nil {
logger.Logger.Warnf("EtcdClient.GetValue(%v) error:%v", key, err)
}
return resp, err
}
// DelValue 返回删除了几条数据
func (c *Client) DelValue(key string) (*clientv3.DeleteResponse, error) {
res, err := c.cli.Delete(context.TODO(), key)
if err != nil {
logger.Logger.Warnf("EtcdClient.DelValue(%v) error:%v", key, err)
}
return res, err
}
// DelValueWithPrefix 按照前缀删除
func (c *Client) DelValueWithPrefix(prefix string) (*clientv3.DeleteResponse, error) {
res, err := c.cli.Delete(context.TODO(), prefix, clientv3.WithPrefix())
if err != nil {
logger.Logger.Warnf("EtcdClient.DelValueWithPrefix(%v) error:%v", prefix, err)
}
return res, err
}
// GetValueWithPrefix 获取前缀
func (c *Client) GetValueWithPrefix(prefix string) (*clientv3.GetResponse, error) {
resp, err := c.cli.Get(context.TODO(), prefix, clientv3.WithPrefix())
if err != nil {
logger.Logger.Warnf("EtcdClient.GetValueWIthPrefix(%v) error:%v", prefix, err)
}
return resp, err
}
// WatchWithPrefix 监测前缀创建事件
func (c *Client) WatchWithPrefix(prefix string, revision int64) clientv3.WatchChan {
if c.cli != nil {
opts := []clientv3.OpOption{clientv3.WithPrefix(), clientv3.WithCreatedNotify()}
if revision > 0 {
opts = append(opts, clientv3.WithRev(revision))
}
return c.cli.Watch(clientv3.WithRequireLeader(context.Background()), prefix, opts...)
}
return nil
}
// Compact 压缩数据
//func (this *Client) Compact() {
// if this.closed {
// return
// }
//
// resp, err := this.GetValue("@@@GET_LASTEST_REVISION@@@")
// if err == nil {
// ctx, _ := context.WithCancel(this.cli.Ctx())
// start := time.Now()
// compactResponse, err := this.cli.Compact(ctx, resp.Header.Revision, clientv3.WithCompactPhysical())
// if err == nil {
// logger.Logger.Infof("EtcdClient.Compact From %v CompactResponse %v take %v", resp.Header.Revision, compactResponse.Header, time.Now().Sub(start))
// } else {
// logger.Logger.Errorf("EtcdClient.Compact From %v CompactResponse:%v take:%v err:%v", resp.Header.Revision, compactResponse, time.Now().Sub(start), err)
// }
// endpoints := this.cli.Endpoints()
// for _, endpoint := range endpoints {
// ctx1, _ := context.WithCancel(this.cli.Ctx())
// start := time.Now()
// defragmentResponse, err := this.cli.Defragment(ctx1, endpoint)
// if err == nil {
// logger.Logger.Infof("EtcdClient.Defragment %v,%v take %v", endpoint, defragmentResponse.Header, time.Now().Sub(start))
// } else {
// logger.Logger.Errorf("EtcdClient.Defragment DefragmentResponse:%v take:%v err:%v", defragmentResponse, time.Now().Sub(start), err)
// }
// }
// }
//}
// AddFunc 添加监听函数
func (c *Client) AddFunc(initFunc InitFunc, watchFunc WatchFunc) {
funcPair := FuncPair{
initFunc: initFunc,
watchFunc: watchFunc,
}
c.functions = append(c.functions, funcPair)
}
// ReInitAndWatchAll 重新监听
func (c *Client) ReInitAndWatchAll() {
if c.closed {
return
}
oldFunc := c.functions
c.functions = nil
for i := 0; i < len(oldFunc); i++ {
c.InitAndWatch(oldFunc[i].initFunc, oldFunc[i].watchFunc)
}
}
// InitAndWatch 开始监听
func (c *Client) InitAndWatch(initFunc InitFunc, watchFunc WatchFunc) {
funcPair := FuncPair{
initFunc: initFunc,
watchFunc: watchFunc,
}
c.functions = append(c.functions, funcPair)
lastRevision := initFunc()
ctx, _ := context.WithCancel(c.cli.Ctx())
watchFunc(ctx, lastRevision+1)
}
// GoWatch 异步监听
func (c *Client) GoWatch(ctx context.Context, revision int64, prefix string, f func(res clientv3.WatchResponse) error) {
go func() {
defer func() {
if err := recover(); err != nil {
logger.Logger.Errorf("etcd watch WithPrefix(%v) panic:%v", prefix, err)
}
logger.Logger.Warnf("etcd watch WithPrefix(%v) quit!!!", prefix)
}()
var times int64
for !c.closed {
times++
logger.Logger.Warnf("etcd watch WithPrefix(%v) base revision %v start[%v]!!!", prefix, revision, times)
rch := c.WatchWithPrefix(prefix, revision)
for {
skip := false
select {
case _, ok := <-ctx.Done():
if !ok {
return
}
case resp, ok := <-rch:
if !ok {
logger.Logger.Warnf("etcd watch WithPrefix(%v) be closed", prefix)
skip = true
break
}
if resp.Header.Revision > revision {
revision = resp.Header.Revision
}
if resp.Canceled {
logger.Logger.Warnf("etcd watch WithPrefix(%v) be closed, reason:%v", prefix, resp.Err())
skip = true
break
}
if err := resp.Err(); err != nil {
logger.Logger.Warnf("etcd watch WithPrefix(%v) err:%v", prefix, resp.Err())
continue
}
if !model.GameParamData.UseEtcd {
continue
}
if len(resp.Events) == 0 {
continue
}
logger.Logger.Tracef("@goWatch %v changed, header:%#v", prefix, resp.Header)
obj := core.CoreObject()
if obj != nil {
func(res clientv3.WatchResponse) {
obj.SendCommand(basic.CommandWrapper(func(*basic.Object) error {
return f(res)
}), true)
}(resp)
}
}
if skip {
break
}
}
time.Sleep(time.Second)
}
}()
}

View File

@ -1,17 +0,0 @@
package etcd
import (
"mongo.games.com/goserver/core"
)
func init() {
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
mgr.Start()
return nil
})
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
mgr.Shutdown()
return nil
})
}

View File

@ -2,56 +2,32 @@ package etcd
const (
// 系统配置
ETCDKEY_SYS_ROOT_PREFIX = "/sys/"
ETCDKEY_SYS_PLT_DBCFG_PREFIX = "/sys/plt/dbcfg/"
//业务配置
ETCDKEY_ROOT_PREFIX = "/game/"
ETCDKEY_PLATFORM_PREFIX = "/game/plt/config/"
ETCDKEY_BULLETIN_PREFIX = "/game/plt/bulletin/"
ETCDKEY_AGENTCUSTOMER_PREFIX = "/game/plt/agent_customer/"
ETCDKEY_GAME_CONFIG_GLOBAL = "/game/plt/game_config_global" // 超管平台游戏开关
ETCDKEY_GAMECONFIG_PREFIX = "/game/plt/game_config/" // 平台游戏配置
ETCDKEY_PACKAGE_PREFIX = "/game/plt/package/"
ETCDKEY_GROUPCONFIG_PREFIX = "/game/group_config/"
ETCDKEY_BLACKLIST_PREFIX = "/game/plt/black_list/"
ETCDKEY_ACT_SIGNIN_PREFIX = "/game/activity/signin/"
ETCDKEY_ACT_TASK_PREFIX = "/game/activity/task/"
ETCDKEY_ACT_GOLDTASK_PREFIX = "/game/activity/goldtask/"
ETCDKEY_ACT_GOLDCOME_PREFIX = "/game/activity/goldcome/"
ETCDKEY_ACT_ONLINEREWARD_PREFIX = "/game/activity/onlinereward/"
ETCDKEY_ACT_LUCKLYTURNTABLE_PREFIX = "/game/activity/lucklyturntable/"
ETCDKEY_ACT_YEB_PREFIX = "/game/activity/yeb/"
ETCDKEY_CONFIG_REBATE = "/game/plt/game_rebate_config/"
ETCDKEY_PROMOTER_PREFIX = "/game/plt/promoter/"
ETCDKEY_ACT_VIP_PREFIX = "/game/plt/actvip/"
ETCDKEY_ACT_WEIXIN_SHARE_PREFIX = "/game/plt/actshare/"
ETCDKEY_ACT_GIVE_PREFIX = "/game/plt/actgive/"
ETCDKEY_ACT_PAY_PREFIX = "/game/plt/payact/"
ETCDKEY_ACT_RANDCOIN_PREFIX = "/game/plt/randcoin/"
ETCDKEY_ACT_FPAY_PREFIX = "/game/plt/fpay/"
ETCDKEY_PLATFORM_PROFITCONTROL = "/game/plt/profitcontrol/"
ETCDKEY_MATCH_PROFIX = "/game/match/"
ETCDKEY_ACT_TICKET_PROFIX = "/game/activity/ticket/"
ETCDKEY_ACT_TICKET_RUNNING = "/game/activity/ticket/running"
ETCDKEY_MATCH_GRADESHOP = "/game/match/gradeshop/"
ETCDKEY_CONFIG_LOGICLEVEL = "/game/logiclevel/"
ETCDKEY_SHOP_EXCHANGE = "/game/exchange_shop"
ETCDKEY_GAME_NOTICE = "/game/common_notice"
ETCDKEY_SHOP_ITEM = "/game/item_shop"
ETCDKEY_GAME_MATCH = "/game/game_match"
ETCDKEY_ACT_TURNPLATE = "/game/act_turnplate"
ETCDKEY_ACT_7SIGN = "/game/act_7sign"
ETCDKEY_ACT_BLINDBOX = "/game/act_blindbox"
ETCDKEY_ACT_FIRSTPAY = "/game/act_FirstPay"
ETCDKEY_ACT_CONTINUOUSPAY = "/game/act_ContinuousPay"
ETCDKEY_ACT_Collect = "/game/act_collect"
ETCDKEY_VIP_CFG = "/game/VIPcfg"
ETCDKEY_WBCtrl_CFG = "/game/WBCtrlCfg"
ETCDKEY_PACKAGE_ENTRYSWITCH = "/game/plt/entryswitch/" //界面入口开关
ETCDKEY_CHESSRANK_CFG = "/game/plt/chessrank/" // 象棋段位配置
ETCDKEY_PLAYERPOOL = "/game/plt/playerpool/" // 个人水池调控配置
ETCDKEY_GAME_CONFIG = "/game/plt/gameconfig/" // 游戏管理/全局配置
ETCDKEY_ACT_PHONELOTTERY = "/game/act_phoneLottery"
ETCDKEY_ChannelSwitch = "/game/channel/switch" // 渠道开关
ETCDKEY_PLATFORM_PREFIX = "/game/plt/config/"
ETCDKEY_GAME_CONFIG_GLOBAL = "/game/plt/game_config_global" // 超管平台游戏开关
ETCDKEY_GAMECONFIG_PREFIX = "/game/plt/game_config/" // 平台游戏配置
ETCDKEY_PACKAGE_PREFIX = "/game/plt/package/"
ETCDKEY_GROUPCONFIG_PREFIX = "/game/group_config/"
ETCDKEY_BLACKLIST_PREFIX = "/game/plt/black_list/"
ETCDKEY_PROMOTER_PREFIX = "/game/plt/promoter/"
ETCDKEY_ACT_GIVE_PREFIX = "/game/plt/actgive/"
ETCDKEY_SHOP_EXCHANGE = "/game/exchange_shop"
ETCDKEY_GAME_NOTICE = "/game/common_notice"
ETCDKEY_SHOP_ITEM = "/game/item_shop"
ETCDKEY_GAME_MATCH = "/game/game_match"
ETCDKEY_ACT_TURNPLATE = "/game/act_turnplate"
ETCDKEY_ACT_7SIGN = "/game/act_7sign"
ETCDKEY_ACT_BLINDBOX = "/game/act_blindbox"
ETCDKEY_ACT_FIRSTPAY = "/game/act_FirstPay"
ETCDKEY_ACT_CONTINUOUSPAY = "/game/act_ContinuousPay"
ETCDKEY_ACT_Collect = "/game/act_collect"
ETCDKEY_VIP_CFG = "/game/VIPcfg"
ETCDKEY_PACKAGE_ENTRYSWITCH = "/game/plt/entryswitch/" //界面入口开关
ETCDKEY_CHESSRANK_CFG = "/game/plt/chessrank/" // 象棋段位配置
ETCDKEY_PLAYERPOOL = "/game/plt/playerpool/" // 个人水池调控配置
ETCDKEY_GAME_CONFIG = "/game/plt/gameconfig/" // 游戏管理/全局配置
ETCDKEY_ACT_PHONELOTTERY = "/game/act_phoneLottery"
ETCDKEY_ChannelSwitch = "/game/channel/switch" // 渠道开关
)

View File

@ -1,123 +0,0 @@
package etcd
import (
"context"
"reflect"
"time"
"go.etcd.io/etcd/client/v3"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/game/common"
"mongo.games.com/game/proto"
)
var mgr = &Manager{Client: new(Client)}
type Manager struct {
*Client
}
// Register .
func (this *Manager) Register(key string, msgType interface{}, f func(ctx context.Context, completeKey string, isInit bool, event *clientv3.Event, data interface{})) {
createFunc := func() interface{} {
tp := reflect.TypeOf(msgType)
if tp.Kind() == reflect.Ptr {
tp = tp.Elem()
}
return reflect.New(tp).Interface()
}
initFunc := func() int64 {
logger.Logger.Info("ETCD 拉取数据:", key)
res, err := this.GetValueWithPrefix(key)
if err == nil {
for i := int64(0); i < res.Count; i++ {
data := createFunc()
v, ok := data.(proto.Message)
if !ok {
logger.Logger.Errorf("ETCD %v error: not proto message", key)
continue
}
err := proto.Unmarshal(res.Kvs[i].Value, v)
if err != nil {
logger.Logger.Errorf("ETCD %v unmarshal error:%v", key, err)
continue
}
logger.Logger.Tracef("ETCD 拉取成功 %v ==> %v", string(res.Kvs[i].Key), v)
event := &clientv3.Event{
Type: 0,
}
f(context.TODO(), string(res.Kvs[i].Key), true, event, v)
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("ETCD get WithPrefix(%v) panic:%v", key, err)
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, key, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypePut:
data := createFunc()
v, ok := data.(proto.Message)
if !ok {
logger.Logger.Errorf("ETCD %v error: not proto message", string(ev.Kv.Key))
continue
}
err := proto.Unmarshal(ev.Kv.Value, v)
if err != nil {
logger.Logger.Errorf("etcd unmarshal(%v) error:%v", string(ev.Kv.Key), err)
continue
}
logger.Logger.Tracef("ETCD 更新事件 %v ==> %v", string(ev.Kv.Key), v)
f(ctx, string(ev.Kv.Key), false, ev, v)
case clientv3.EventTypeDelete:
logger.Logger.Tracef("ETCD 删除事件 %v", string(ev.Kv.Key))
f(ctx, string(ev.Kv.Key), false, ev, nil)
}
}
return nil
})
}
this.AddFunc(initFunc, watchFunc)
}
func (this *Manager) Start() {
logger.Logger.Infof("EtcdClient开始连接url:%v;etcduser:%v;etcdpwd:%v", common.CustomConfig.GetStrings("etcdurl"), common.CustomConfig.GetString("etcduser"), common.CustomConfig.GetString("etcdpwd"))
err := this.Open(common.CustomConfig.GetStrings("etcdurl"), common.CustomConfig.GetString("etcduser"), common.CustomConfig.GetString("etcdpwd"), time.Minute)
if err != nil {
logger.Logger.Tracef("Manager.Open err:%v", err)
}
this.ReInitAndWatchAll()
}
func (this *Manager) Shutdown() {
this.Close()
}
func (this *Manager) Reset() {
this.Close()
this.Start()
}
// Register 注册etcd监听方法
// key:监听的key
// msgType:数据类型
// f:数据变更回调方法, completeKey:完整键, isInit:第一次主动拉取数据,event:事件类型, data:已经反序列化的数据类型为msgType,是指针类型
func Register(key string, msgType interface{}, f func(ctx context.Context, completeKey string, isInit bool, event *clientv3.Event, data interface{})) {
mgr.Register(key, msgType, f)
}
func Reset() {
mgr.Reset()
}

120
etcd/register.go Normal file
View File

@ -0,0 +1,120 @@
package etcd
import (
"context"
"encoding/json"
"reflect"
"go.etcd.io/etcd/client/v3"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/basic"
"mongo.games.com/goserver/core/etcd"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/game/proto"
)
// Register 注册etcd监听方法
// key:监听的key
// msgType:数据类型
// f:数据变更回调方法, completeKey:完整键, isInit:第一次主动拉取数据,event:事件类型, data:已经反序列化的数据类型为msgType,是指针类型
func Register(key string, msgType interface{}, f func(ctx context.Context, completeKey string, isInit bool, event *clientv3.Event, data interface{})) {
createFunc := func() interface{} {
tp := reflect.TypeOf(msgType)
if tp.Kind() == reflect.Ptr {
tp = tp.Elem()
}
return reflect.New(tp).Interface()
}
initFunc := func(ctx context.Context, res *clientv3.GetResponse) {
if res == nil {
return
}
f := func() {
for i := int64(0); i < res.Count; i++ {
data := createFunc()
switch d := data.(type) {
case proto.Message:
err := proto.Unmarshal(res.Kvs[i].Value, d)
if err != nil {
logger.Logger.Errorf("ETCD %v proto.Unmarshal error:%v", key, err)
continue
}
logger.Logger.Tracef("ETCD 拉取成功 %v ==> %v", string(res.Kvs[i].Key), d)
event := &clientv3.Event{
Type: 0,
}
f(context.TODO(), string(res.Kvs[i].Key), true, event, d)
default:
err := json.Unmarshal(res.Kvs[i].Value, d)
if err != nil {
logger.Logger.Errorf("ETCD %v josn.Unmarshal error:%v", key, err)
continue
}
logger.Logger.Tracef("ETCD 拉取成功 %v ==> %v", string(res.Kvs[i].Key), d)
event := &clientv3.Event{
Type: 0,
}
f(context.TODO(), string(res.Kvs[i].Key), true, event, d)
}
}
}
obj := core.CoreObject()
if obj == nil {
f()
return
}
obj.SendCommand(basic.CommandWrapper(func(*basic.Object) error {
f()
return nil
}), true)
}
// 监控数据变动
watchFunc := func(ctx context.Context, res *clientv3.WatchResponse) {
if res == nil {
return
}
f := func() {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypePut:
data := createFunc()
switch d := data.(type) {
case proto.Message:
err := proto.Unmarshal(ev.Kv.Value, d)
if err != nil {
logger.Logger.Errorf("ETCD %v proto.Unmarshal error:%v", key, err)
continue
}
logger.Logger.Tracef("ETCD 更新事件 %v ==> %v", string(ev.Kv.Key), d)
f(ctx, string(ev.Kv.Key), false, ev, d)
default:
err := json.Unmarshal(ev.Kv.Value, d)
if err != nil {
logger.Logger.Errorf("ETCD %v josn.Unmarshal error:%v", key, err)
continue
}
logger.Logger.Tracef("ETCD 更新事件 %v ==> %v", string(ev.Kv.Key), d)
f(ctx, string(ev.Kv.Key), false, ev, d)
}
case clientv3.EventTypeDelete:
logger.Logger.Tracef("ETCD 删除事件 %v", string(ev.Kv.Key))
f(ctx, string(ev.Kv.Key), false, ev, nil)
}
}
}
obj := core.CoreObject()
if obj == nil {
f()
return
}
obj.SendCommand(basic.CommandWrapper(func(*basic.Object) error {
f()
return nil
}), true)
}
etcd.AddFunc(key, initFunc, watchFunc)
}

View File

@ -164,7 +164,6 @@ func init() {
p.LastSyncCoin = p.Coin
p.IsQM = IsQM
p.AppChannel = msg.GetAppChannel()
if sid == 0 && (scene != nil && !scene.IsMatchScene()) {
logger.Logger.Warnf("when WGPlayerEnter (sid == 0)")
@ -308,7 +307,6 @@ func init() {
p.SetTakeCoin(msg.GetTakeCoin())
p.LastSyncCoin = p.Coin
p.IsQM = IsQM
p.AppChannel = msg.GetAppChannel()
if scene != nil {
scene.AudienceEnter(p, isload)
if !p.IsRobot() && !scene.Testing {
@ -559,7 +557,7 @@ func init() {
return nil
}))
//玩家离开
//同步记牌器过期时间
netlib.RegisterFactory(int(server.SSPacketID_PACKET_WG_BUYRECTIMEITEM), netlib.PacketFactoryWrapper(func() interface{} {
return &server.WGBuyRecTimeItem{}
}))

View File

@ -1,45 +0,0 @@
package base
import (
"time"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/broker/rabbitmq"
"mongo.games.com/game/common"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
)
var RabbitMQPublisher *mq.RabbitMQPublisher
func init() {
model.InitGameParam()
model.InitFishingParam()
model.InitNormalParam()
model.InitGMAC()
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
model.StartupRPClient(common.CustomConfig.GetString("MgoRpcCliNet"), common.CustomConfig.GetString("MgoRpcCliAddr"), time.Duration(common.CustomConfig.GetInt("MgoRpcCliReconnInterV"))*time.Second)
model.InitGameKVData()
//rabbitmq打开链接
RabbitMQPublisher = mq.NewRabbitMQPublisher(common.CustomConfig.GetString("RabbitMQURL"), rabbitmq.Exchange{Name: common.CustomConfig.GetString("RMQExchange"), Durable: true}, common.CustomConfig.GetInt("RMQPublishBacklog"))
if RabbitMQPublisher != nil {
err := RabbitMQPublisher.Start()
if err != nil {
panic(err)
}
}
return nil
})
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
//关闭rabbitmq连接
if RabbitMQPublisher != nil {
RabbitMQPublisher.Stop()
}
return nil
})
}

View File

@ -4,6 +4,7 @@ import (
"reflect"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
)
// LogChannelSingleton 日志记录器
@ -37,11 +38,11 @@ func (c *LogChannel) WriteLog(log interface{}) {
if cname == "" {
cname = "_null_"
}
RabbitMQPublisher.Send(cname, log)
mq.Send(cname, log)
}
func (c *LogChannel) WriteMQData(data *model.RabbitMQData) {
RabbitMQPublisher.Send(data.MQName, data.Data)
mq.Send(data.MQName, data.Data)
}
func init() {

View File

@ -118,7 +118,6 @@ type Player struct {
MatchRobotGrades []MatchRobotGrade
TestLog []string // 调试日志
RankScore map[int32]int64 // 段位积分
AppChannel string // app渠道(玩家本次登录使用的包的渠道类型,换登录包,这个值也会变;玩家model.PlayerData存储的渠道是玩家第一次登录的渠道不会修改)
}
type MatchRobotGrade struct {

View File

@ -1632,6 +1632,8 @@ func (this *Scene) NewBigCoinNotice(player *Player, num int64, msgType int64) {
type GameDetailedParam struct {
Trend20Lately string //最近20局开奖结果
CtrlType int
PlayerPool map[int]int
}
// 保存详细游戏日志
@ -1651,7 +1653,8 @@ func (this *Scene) SaveGameDetailedLog(logid string, gamedetailednote string, ga
log := model.NewGameDetailedLogEx(logid, int32(this.GameId), int32(this.SceneId),
this.DbGameFree.GetGameMode(), this.DbGameFree.Id, int32(len(this.Players)),
int32(time.Now().Unix()-this.GameNowTime.Unix()), baseScore,
gamedetailednote, p.Platform, this.ClubId, this.RoomId, this.CpCtx, GameDetailedVer[this.GameId], trend20Lately)
gamedetailednote, p.Platform, this.ClubId, this.RoomId, this.CpCtx, GameDetailedVer[this.GameId], trend20Lately,
gameDetailedParam.CtrlType, gameDetailedParam.PlayerPool)
if log != nil {
if this.IsMatchScene() {
log.MatchId = this.MatchId
@ -1664,7 +1667,8 @@ func (this *Scene) SaveGameDetailedLog(logid string, gamedetailednote string, ga
log := model.NewGameDetailedLogEx(logid, int32(this.GameId), int32(this.SceneId),
this.DbGameFree.GetGameMode(), this.DbGameFree.Id, int32(len(this.Players)),
int32(time.Now().Unix()-this.GameNowTime.Unix()), baseScore,
gamedetailednote, this.Platform, this.ClubId, this.RoomId, this.CpCtx, GameDetailedVer[this.GameId], trend20Lately)
gamedetailednote, this.Platform, this.ClubId, this.RoomId, this.CpCtx, GameDetailedVer[this.GameId], trend20Lately,
gameDetailedParam.CtrlType, gameDetailedParam.PlayerPool)
if log != nil {
if this.IsMatchScene() {
log.MatchId = this.MatchId
@ -2128,7 +2132,7 @@ func (this *Scene) TryBillExGameDrop(p *Player) {
// 渠道开关
conf := ConfigMgrInst.GetConfig(p.Platform).ChannelSwitch[common.ChannelSwitchDropItem]
if !model.GameParamData.CloseChannelSwitch && (conf == nil || !common.InSliceString(conf.OnChannelName, p.AppChannel)) {
if !model.GameParamData.CloseChannelSwitch && (conf == nil || !common.InSliceString(conf.OnChannelName, p.LastChannel)) {
return
}
@ -2158,6 +2162,7 @@ func (this *Scene) TryBillExGameDrop(p *Player) {
pack := &player.SCGameExDropItems{}
pack.Items = make(map[int32]int32)
for id, num := range realDrop {
remark := fmt.Sprintf("游戏掉落%v", id)
pack.Items[id] = proto.Int32(num)
itemData := srvdata.PBDB_GameItemMgr.GetData(id)
if itemData != nil {
@ -2169,8 +2174,8 @@ func (this *Scene) TryBillExGameDrop(p *Player) {
ItemId: itemData.Id,
ItemName: itemData.Name,
Count: int64(num),
Remark: "tienlen游戏掉落",
TypeId: common.GainWay_Interact,
Remark: remark,
TypeId: common.GainWay_Game,
GameId: int64(this.GameId),
GameFreeId: int64(this.GetGameFreeId()),
})

View File

@ -2,7 +2,6 @@ package base
import (
"mongo.games.com/game/common"
"mongo.games.com/goserver/core"
)
var ServerStateMgr = &ServerStateManager{
@ -24,10 +23,3 @@ func (this *ServerStateManager) SetState(state common.GameSessState) {
func (this *ServerStateManager) GetState() common.GameSessState {
return this.State
}
func init() {
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
ServerStateMgr.Init()
return nil
})
}

View File

@ -3,7 +3,6 @@ package base
import (
"mongo.games.com/game/common"
"mongo.games.com/game/srvdata"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/logger"
)
@ -186,12 +185,3 @@ func (this *DB_FishOutMgrEx) InitFishAppear() {
}
}
}
// 初始化在线奖励系统
func init() {
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
logger.Logger.Info("初始化牌库[S]")
defer logger.Logger.Info("初始化牌库[E]")
return nil
})
}

View File

@ -148,18 +148,19 @@
"profile": {
"SlowMS": 500
},
"etcd": {
"Url": ["127.0.0.1:2379"],
"UserName": "",
"Password": "",
"DialTimeout": 60
},
"costum": {
"MgoRpcCliNet": "tcp",
"MgoRpcCliAddr": "127.0.0.1:8999",
"MgoRpcCliReconnInterV": 3,
"RabbitMQURL": "amqp://win88:123456@127.0.0.1:5672/win88",
"RMQExchange": "win88",
"RMQPublishBacklog": 1024,
"etcdurl": [
"127.0.0.1:2379"
],
"etcduser": "",
"etcdpwd": ""
"RMQPublishBacklog": 1024
},
"webapi": {
"GameApiURL": "http://127.0.0.1:8000/api/game_srv"

View File

@ -1,17 +1,21 @@
package main
import (
"time"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/etcd"
_ "mongo.games.com/goserver/core/i18n"
"mongo.games.com/goserver/core/module"
_ "mongo.games.com/game"
"mongo.games.com/game/common"
_ "mongo.games.com/game/srvdata"
_ "mongo.games.com/game/gamesrv/action"
_ "mongo.games.com/game/gamesrv/base"
_ "mongo.games.com/game/gamesrv/transact"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
_ "mongo.games.com/game/srvdata"
// game
_ "mongo.games.com/game/gamesrv/chess"
@ -31,10 +35,27 @@ import (
)
func main() {
core.RegisterConfigEncryptor(common.ConfigFE)
// 自定义配置文件
model.InitGameParam()
model.InitFishingParam()
model.InitNormalParam()
model.InitGMAC()
// package模块
defer core.ClosePackages()
core.LoadPackages("config.json")
waiter := module.Start()
waiter.Wait("main()")
// core hook
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
etcd.Start()
model.StartupRPClient(common.CustomConfig.GetString("MgoRpcCliNet"), common.CustomConfig.GetString("MgoRpcCliAddr"), time.Duration(common.CustomConfig.GetInt("MgoRpcCliReconnInterV"))*time.Second)
mq.StartPublisher(common.CustomConfig.GetString("RabbitMQURL"), common.CustomConfig.GetString("RMQExchange"), true, common.CustomConfig.GetInt("RMQPublishBacklog"))
model.InitGameKVData()
return nil
})
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
mq.StopPublisher()
return nil
})
// module模块
w := module.Start()
w.Wait("main()")
}

View File

@ -29,6 +29,7 @@ type TienLenPlayerData struct {
curHandLimitTimeOut time.Duration // 出牌时间上限
isNotOverLastHand bool //手牌不能压过上家出牌标志
cardScore int // 手牌评分
playerPool int // 个人水池分
}
func (this *TienLenPlayerData) init() {
@ -49,6 +50,7 @@ func (this *TienLenPlayerData) init() {
this.curHandLimitTimeOut = rule.TienLenPlayerOpTimeout
this.isNotOverLastHand = false
this.cardScore = 0
this.playerPool = 0
}
func (this *TienLenPlayerData) Clear() {
@ -67,6 +69,7 @@ func (this *TienLenPlayerData) Clear() {
this.ThinkLongCnt = 0
this.curHandLimitTimeOut = rule.TienLenPlayerOpTimeout
this.isNotOverLastHand = false
this.playerPool = 0
this.MarkFlag(base.PlayerState_WaitNext)
this.TestLog = this.TestLog[:0]

View File

@ -55,6 +55,7 @@ type TienLenSceneData struct {
cHintCards []int32 //客户端提示出牌记录
isCardsKu bool //是否是牌库
cardsKuId int32 //牌库ID
ctrlType int // 1控赢 2控输 0不控
}
func NewTienLenSceneData(s *base.Scene) *TienLenSceneData {
@ -85,6 +86,7 @@ func (this *TienLenSceneData) init() bool {
this.card_play_action_seq_int32 = [][]int32{}
this.bombToEnd = 0
this.allPlayerCards = [][]int32{}
this.ctrlType = 0
this.recordId, _ = model.AutoIncGameLogId()
if this.GetPlayerNum() == 0 {
this.SetPlayerNum(rule.MaxNumOfPlayer)
@ -114,6 +116,7 @@ func (this *TienLenSceneData) Clear() {
this.isAllRob = false
this.robotGamingNum = 0
this.allPlayerCards = [][]int32{}
this.ctrlType = 0
this.recordId, _ = model.AutoIncGameLogId()
for _, player := range this.players {
if player != nil {
@ -1053,6 +1056,7 @@ func (this *TienLenSceneData) SendHandCardOdds() {
robotPlayers = append(robotPlayers, seat)
} else {
seat.odds = this.GetPlayerOdds(seat.Player, this.GameId, this.robotGamingNum > 0)
seat.playerPool = int(this.PlayerPoolOdds(seat.Player))
if seat.odds > 0 {
realPlayersGood = append(realPlayersGood, seat)
G += seat.odds
@ -1106,88 +1110,89 @@ func (this *TienLenSceneData) SendHandCardOdds() {
// 前两局不能天胡,之后根据概率给一次天胡,至少天胡一次
noviceTianHu := false
noviceCtrl := false
config := srvdata.PBDB_NewPlayerMgr.GetData(int32(this.GameId))
if config != nil && config.GetTianHuRate() > 0 && len(this.testPokers) == 0 { // 启用新手天胡体验
rand.Shuffle(len(novicePlayers), func(i, j int) {
novicePlayers[i], novicePlayers[j] = novicePlayers[j], novicePlayers[i]
})
keyNovice := common.GetKeyNoviceGameId(this.GameId)
for _, v := range novicePlayers {
data, ok := v.GDatas[keyNovice]
if !ok {
data = &model.PlayerGameInfo{FirstTime: time.Now()}
v.GDatas[keyNovice] = data
}
// 前两局不能天胡
if data.Statics.GameTimes < 2 {
continue
}
if int(config.GetTianHuRate()) > this.RandInt(1000) {
var allcs []int32
for i := 0; i < 52; i++ {
allcs = append(allcs, int32(i))
}
rand.Shuffle(len(allcs), func(i, j int) {
allcs[i], allcs[j] = allcs[j], allcs[i]
})
cs, _ := rule.GetTianHu()
allcs = common.DelSliceIn32s(allcs, cs)
for _, seat := range this.seats {
if seat != nil && seat.IsGameing() {
if seat != v {
f1(seat, allcs[:13])
allcs = allcs[13:]
} else {
f1(seat, cs)
}
}
}
v.TestLog = append(v.TestLog, fmt.Sprintf("新手天胡体验,玩家:%d 发天胡 num:%v", v.SnId, data.Statics.GameTimes))
logger.Logger.Tracef("新手天胡体验,玩家:%d 发天胡", v.SnId)
noviceTianHu = true
noviceCtrl = true
}
}
if !noviceTianHu {
// 没有新手玩家天胡,随机一个非新手玩家,如果没有天胡过,给一次天胡
rand.Shuffle(len(notNoviceRealPlayers), func(i, j int) {
notNoviceRealPlayers[i], notNoviceRealPlayers[j] = notNoviceRealPlayers[j], notNoviceRealPlayers[i]
})
for _, v := range notNoviceRealPlayers {
data, ok := v.GDatas[keyNovice]
if !ok {
data = &model.PlayerGameInfo{FirstTime: time.Now()}
v.GDatas[keyNovice] = data
}
if data.Statics.GetInt(rule.StaticsTianHuTimes) == 0 {
var allcs []int32
for i := 0; i < 52; i++ {
allcs = append(allcs, int32(i))
}
rand.Shuffle(len(allcs), func(i, j int) {
allcs[i], allcs[j] = allcs[j], allcs[i]
})
cs, _ := rule.GetTianHu()
allcs = common.DelSliceIn32s(allcs, cs)
for _, seat := range this.seats {
if seat != nil && seat.IsGameing() {
if seat != v {
f1(seat, allcs[:13])
allcs = allcs[13:]
} else {
f1(seat, cs)
}
}
}
v.TestLog = append(v.TestLog, fmt.Sprintf("新手阶段没有天胡过,玩家:%d 发天胡 num:%v", v.SnId, data.Statics.GameTimes))
logger.Logger.Tracef("新手阶段没有天胡过,玩家:%v 发天胡", v.SnId)
noviceCtrl = true
}
}
}
}
//config := srvdata.PBDB_NewPlayerMgr.GetData(int32(this.GameId))
//if config != nil && config.GetTianHuRate() > 0 && len(this.testPokers) == 0 { // 启用新手天胡体验
// rand.Shuffle(len(novicePlayers), func(i, j int) {
// novicePlayers[i], novicePlayers[j] = novicePlayers[j], novicePlayers[i]
// })
// keyNovice := common.GetKeyNoviceGameId(this.GameId)
// for _, v := range novicePlayers {
// data, ok := v.GDatas[keyNovice]
// if !ok {
// data = &model.PlayerGameInfo{FirstTime: time.Now()}
// v.GDatas[keyNovice] = data
// }
// // 前两局不能天胡
// if data.Statics.GameTimes < 2 {
// continue
// }
// if int(config.GetTianHuRate()) > this.RandInt(1000) {
// var allcs []int32
// for i := 0; i < 52; i++ {
// allcs = append(allcs, int32(i))
// }
// rand.Shuffle(len(allcs), func(i, j int) {
// allcs[i], allcs[j] = allcs[j], allcs[i]
// })
// cs, _ := rule.GetTianHu()
// allcs = common.DelSliceIn32s(allcs, cs)
// for _, seat := range this.seats {
// if seat != nil && seat.IsGameing() {
// if seat != v {
// f1(seat, allcs[:13])
// allcs = allcs[13:]
// } else {
// f1(seat, cs)
// }
// }
// }
// v.TestLog = append(v.TestLog, fmt.Sprintf("新手天胡体验,玩家:%d 发天胡 num:%v", v.SnId, data.Statics.GameTimes))
// logger.Logger.Tracef("新手天胡体验,玩家:%d 发天胡", v.SnId)
// noviceTianHu = true
// noviceCtrl = true
// }
// }
// if !noviceTianHu {
// // 没有新手玩家天胡,随机一个非新手玩家,如果没有天胡过,给一次天胡
// rand.Shuffle(len(notNoviceRealPlayers), func(i, j int) {
// notNoviceRealPlayers[i], notNoviceRealPlayers[j] = notNoviceRealPlayers[j], notNoviceRealPlayers[i]
// })
// for _, v := range notNoviceRealPlayers {
// data, ok := v.GDatas[keyNovice]
// if !ok {
// data = &model.PlayerGameInfo{FirstTime: time.Now()}
// v.GDatas[keyNovice] = data
// }
//
// if data.Statics.GetInt(rule.StaticsTianHuTimes) == 0 {
// var allcs []int32
// for i := 0; i < 52; i++ {
// allcs = append(allcs, int32(i))
// }
// rand.Shuffle(len(allcs), func(i, j int) {
// allcs[i], allcs[j] = allcs[j], allcs[i]
// })
// cs, _ := rule.GetTianHu()
// allcs = common.DelSliceIn32s(allcs, cs)
// for _, seat := range this.seats {
// if seat != nil && seat.IsGameing() {
// if seat != v {
// f1(seat, allcs[:13])
// allcs = allcs[13:]
// } else {
// f1(seat, cs)
// }
// }
// }
// v.TestLog = append(v.TestLog, fmt.Sprintf("新手阶段没有天胡过,玩家:%d 发天胡 num:%v", v.SnId, data.Statics.GameTimes))
// logger.Logger.Tracef("新手阶段没有天胡过,玩家:%v 发天胡", v.SnId)
// noviceCtrl = true
// }
// }
// }
//}
// 全局配置
gameConfig := base.ConfigMgrInst.GetConfig(this.Platform).GameConfig
// testPokers 用于测试
@ -1232,6 +1237,7 @@ func (this *TienLenSceneData) SendHandCardOdds() {
logger.Logger.Tracef("TienLen SendHandCardOdds Good:%v G:%v Bad:%v B:%v", isGood, G, isBad, B)
if isBad && !isTestPoker && len(robotPlayers) > 0 && !noviceCtrl && !noviceTianHu {
this.ctrlType = 2
gf := base.ConfigMgrInst.GetConfig(this.Platform).GameConfig
items := []int32{gf.GetTianHu(), gf.GetPaiKu(), gf.GetFenCha()}
score := this.RandInt(int(gf.GetTianHu() + gf.GetPaiKu() + gf.GetFenCha()))
@ -1494,7 +1500,8 @@ func (this *TienLenSceneData) SendHandCardOdds() {
}
if !isBad && !isTestPoker && !noviceCtrl && !noviceTianHu { // 天胡调控没有生效
if isGood || isBad {
if isGood {
this.ctrlType = 1
// 牌平分,按从大到小排序
// 使用分差配置,最好牌和最差牌的牌型分差大于分差配置
for i := 0; i < 20; i++ { // 尝试20次如果还不能满足分差配置则直接发牌

View File

@ -1606,6 +1606,13 @@ func (this *SceneBilledStateTienLen) OnEnter(s *base.Scene) {
BaseScore: s.GetBaseScore(),
TaxRate: s.DbGameFree.GetTaxRate(),
RoomMode: s.GetSceneMode(),
PlayerPool: make(map[int]int),
}
for _, v := range sceneEx.seats {
if v == nil || !v.IsGameing() {
continue
}
tienlenType.PlayerPool[int(v.SnId)] = v.playerPool
}
nGamingPlayerCount := sceneEx.GetGameingPlayerCnt()
@ -2499,7 +2506,11 @@ func (this *SceneBilledStateTienLen) OnEnter(s *base.Scene) {
}
if isSave {
// 牌局记录
sceneEx.SaveGameDetailedLog(sceneEx.recordId, info, &base.GameDetailedParam{})
sceneEx.SaveGameDetailedLog(sceneEx.recordId, info, &base.GameDetailedParam{
Trend20Lately: "",
CtrlType: sceneEx.ctrlType,
PlayerPool: tienlenType.PlayerPool,
})
}
}

View File

@ -3,10 +3,6 @@ package main
import (
"reflect"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/broker/rabbitmq"
"mongo.games.com/game/common"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
)
@ -42,33 +38,9 @@ func (c *LogChannel) WriteLog(log interface{}) {
if cname == "" {
cname = "_null_"
}
RabbitMQPublisher.Send(cname, log)
mq.Send(cname, log)
}
func (c *LogChannel) WriteMQData(data *model.RabbitMQData) {
RabbitMQPublisher.Send(data.MQName, data.Data)
}
var RabbitMQPublisher *mq.RabbitMQPublisher
func init() {
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
//rabbitmq打开链接
RabbitMQPublisher = mq.NewRabbitMQPublisher(common.CustomConfig.GetString("RabbitMQURL"), rabbitmq.Exchange{Name: common.CustomConfig.GetString("RMQExchange"), Durable: true}, common.CustomConfig.GetInt("RMQPublishBacklog"))
if RabbitMQPublisher != nil {
err := RabbitMQPublisher.Start()
if err != nil {
panic(err)
}
}
return nil
})
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
//关闭rabbitmq连接
if RabbitMQPublisher != nil {
RabbitMQPublisher.Stop()
}
return nil
})
mq.Send(data.MQName, data.Data)
}

View File

@ -1,21 +1,31 @@
package main
import (
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/module"
_ "mongo.games.com/game"
"mongo.games.com/game/common"
"mongo.games.com/game/model"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/module"
"mongo.games.com/game/mq"
)
func main() {
core.RegisterConfigEncryptor(common.ConfigFE)
// 自定义配置文件
model.InitGameParam()
// package模块
defer core.ClosePackages()
core.LoadPackages("config.json")
model.InitGameParam()
waiter := module.Start()
waiter.Wait("main()")
// core hook
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
mq.StartPublisher(common.CustomConfig.GetString("RabbitMQURL"), common.CustomConfig.GetString("RMQExchange"), true, common.CustomConfig.GetInt("RMQPublishBacklog"))
return nil
})
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
mq.StopPublisher()
return nil
})
// module模块
w := module.Start()
w.Wait("main()")
}

View File

@ -3,11 +3,8 @@ package api
import (
"reflect"
"mongo.games.com/game/common"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/broker/rabbitmq"
)
/*
@ -15,11 +12,9 @@ import (
*/
const (
LOGCHANEL_BLACKHOLE = "_null_"
LogChanelBlackHole = "_null_"
)
var RabbitMQPublisher *mq.RabbitMQPublisher
var LogChannelSington = &LogChannel{
cName: make(map[reflect.Type]string),
}
@ -48,36 +43,15 @@ func (c *LogChannel) getLogCName(log interface{}) string {
func (c *LogChannel) WriteLog(log interface{}) {
cname := c.getLogCName(log)
if cname == "" {
cname = LOGCHANEL_BLACKHOLE
cname = LogChanelBlackHole
}
RabbitMQPublisher.Send(cname, log)
mq.Send(cname, log)
}
func (c *LogChannel) WriteMQData(data *model.RabbitMQData) {
RabbitMQPublisher.Send(data.MQName, data.Data)
mq.Send(data.MQName, data.Data)
}
func init() {
LogChannelSington.RegisteLogCName(model.APILogCollName, &model.APILog{})
//首先加载游戏配置
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
//rabbitmq打开链接
RabbitMQPublisher = mq.NewRabbitMQPublisher(common.CustomConfig.GetString("RabbitMQURL"), rabbitmq.Exchange{Name: common.CustomConfig.GetString("RMQExchange"), Durable: true}, common.CustomConfig.GetInt("RMQPublishBacklog"))
if RabbitMQPublisher != nil {
err := RabbitMQPublisher.Start()
if err != nil {
panic(err)
}
}
return nil
})
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
//关闭rabbitmq连接
if RabbitMQPublisher != nil {
RabbitMQPublisher.Stop()
}
return nil
})
}

View File

@ -1,203 +0,0 @@
package api
//
//import (
// "encoding/json"
// "io/ioutil"
// "net/http"
// "time"
//
// "crypto/md5"
// "encoding/hex"
// "fmt"
// "mongo.games.com/game/common"
// "mongo.games.com/game/model"
// "mongo.games.com/game/webapi"
// "mongo.games.com/goserver/core"
// "mongo.games.com/goserver/core/admin"
// "mongo.games.com/goserver/core/logger"
// "mongo.games.com/goserver/core/netlib"
// "mongo.games.com/goserver/core/transact"
// "mongo.games.com/goserver/core/utils"
// "io"
// "sync/atomic"
//)
//
//// API
//// http://127.0.0.1:9595/api/Report/QueryOnlineReportList?ts=20141024000000&sign=41cc8cee8dd93f7dc70b6426cfd1029d
//
//func ActThrSrvApi(rw http.ResponseWriter, req *http.Request) {
// defer utils.DumpStackIfPanic("api.ActThrSrvApi")
// logger.Logger.Info("ActThrSrvApi receive:", req.URL.Path, req.URL.RawQuery)
//
// if common.RequestCheck(req, model.GameParamData.WhiteHttpAddr) == false {
// logger.Logger.Info("RemoteAddr [%v] require api.", req.RemoteAddr)
// return
// }
// data, err := io.ReadAll(req.Body)
// if err != nil {
// logger.Logger.Info("Body err.", err)
// webApiResponse(rw, map[string]interface{}{webapi.RESPONSE_STATE: webapi.STATE_ERR, webapi.RESPONSE_ERRMSG: "Post data is null!"})
// return
// }
// m := req.URL.Query()
// timestamp := m.Get("nano")
// if timestamp == "" {
// logger.Logger.Info(req.RemoteAddr, " ActThrSrvApi param error: nano not allow null")
// return
// }
// sign := m.Get("sign")
// if sign == "" {
// logger.Logger.Info(req.RemoteAddr, " ActThrSrvApi param error: sign not allow null")
// return
// }
// startTime := time.Now().UnixNano()
// args := fmt.Sprintf("%v;%v;%v;%v", common.Config.AppId, req.URL.Path, string(data), timestamp)
// h := md5.New()
// io.WriteString(h, args)
// realSign := hex.EncodeToString(h.Sum(nil))
// if realSign != sign && !common.Config.IsDevMode {
// logger.Logger.Info(req.RemoteAddr, " srvCtrlMain sign error: expect ", realSign, " ; but get ", sign, " raw=", args)
// webApiResponse(rw, map[string]interface{}{webapi.RESPONSE_STATE: webapi.STATE_ERR, webapi.RESPONSE_ERRMSG: "Sign error!"})
// return
// }
//
// var stats *ApiStats
// if v, exist := WebApiStats.Load(req.URL.Path); exist {
// stats = v.(*ApiStats)
// } else {
// stats = &ApiStats{}
// WebApiStats.Store(req.URL.Path, stats)
// }
// var rep map[string]interface{}
// start := time.Now()
// res := make(chan map[string]interface{}, 1)
// core.CoreObject().SendCommand(&WebApiEvent{req: req, path: req.URL.Path, h: HandlerWrapper(func(event *WebApiEvent, data []byte) bool {
// logger.Logger.Trace("ActThrSrvApi start transcate")
// tnp := &transact.TransNodeParam{
// Tt: common.TransType_ActThrSrvWebApi,
// Ot: transact.TransOwnerType(common.GetSelfSrvType()),
// Oid: common.GetSelfSrvId(),
// AreaID: common.GetSelfAreaId(),
// }
// tNode := transact.DTCModule.StartTrans(tnp, event, transact.DefaultTransactTimeout) //超时时间30秒
// if tNode != nil {
// tNode.TransEnv.SetField(WEBAPI_TRANSACTE_EVENT, event)
// tNode.Go(core.CoreObject())
// }
// return true
// }), body: data, rawQuery: req.URL.RawQuery, res: res}, false)
// select {
// case rep = <-res:
// if rep != nil {
// webApiResponse(rw, rep)
// }
// case <-time.After(ApiDefaultTimeout):
// rep = make(map[string]interface{})
// rep[webapi.RESPONSE_STATE] = webapi.STATE_ERR
// rep[webapi.RESPONSE_ERRMSG] = "proccess timeout!"
// webApiResponse(rw, rep)
// if stats != nil {
// atomic.AddInt64(&stats.TimeoutTimes, 1)
// }
// }
// ps := int64(time.Now().Sub(start) / time.Millisecond)
// if stats != nil {
// atomic.AddInt64(&stats.RunTimes, 1)
// atomic.AddInt64(&stats.TotalRuningTime, ps)
// if atomic.LoadInt64(&stats.MaxRuningTime) < ps {
// atomic.StoreInt64(&stats.MaxRuningTime, ps)
// }
// }
// result, err := json.Marshal(rep)
// if err == nil {
// log := model.NewAPILog(req.URL.Path, req.URL.RawQuery, string(data[:]), req.RemoteAddr, string(result[:]), startTime, ps)
// APILogChannelSington.Write(log)
// }
// return
//}
//
////--------------------------------------------------------------------------------------
//func init() {
// transact.RegisteHandler(common.TransType_ActThrSrvWebApi, &transact.TransHanderWrapper{
// OnExecuteWrapper: transact.OnExecuteWrapper(func(tNode *transact.TransNode, ud interface{}) transact.TransExeResult {
// logger.Logger.Trace("ActThrSrvApi start TransType_WebApi OnExecuteWrapper ")
// tnp := &transact.TransNodeParam{
// Tt: common.TransType_ActThrSrvWebApi,
// Ot: transact.TransOwnerType(common.ActThrServerType),
// Oid: common.ActThrServerID,
// AreaID: common.GetSelfAreaId(),
// Tct: transact.TransactCommitPolicy_TwoPhase,
// }
// if event, ok := ud.(*WebApiEvent); ok {
// userData := &common.M2GWebApiRequest{Path: event.path, RawQuery: event.rawQuery, Body: event.body, ReqIp: event.req.RemoteAddr}
// tNode.StartChildTrans(tnp, userData, transact.DefaultTransactTimeout)
//
// pid := tNode.MyTnp.TId
// cid := tnp.TId
// logger.Logger.Tracef("ActThrSrvApi start TransType_WebApi OnExecuteWrapper tid:%x childid:%x", pid, cid)
// return transact.TransExeResult_Success
// }
// return transact.TransExeResult_Failed
// }),
// OnCommitWrapper: transact.OnCommitWrapper(func(tNode *transact.TransNode) transact.TransExeResult {
// logger.Logger.Trace("ActThrSrvApi start TransType_WebApi OnCommitWrapper")
// event := tNode.TransEnv.GetField(WEBAPI_TRANSACTE_EVENT).(*WebApiEvent)
// resp := tNode.TransEnv.GetField(WEBAPI_TRANSACTE_RESPONSE)
// if userData, ok := resp.(*common.M2GWebApiResponse); ok {
// if len(userData.Body) > 0 {
// m := make(map[string]interface{})
// err := json.Unmarshal(userData.Body, &m)
// if err == nil {
// event.Response(m)
// return transact.TransExeResult_Success
// }
// }
// }
// event.Response(map[string]interface{}{webapi.RESPONSE_STATE: webapi.STATE_ERR, webapi.RESPONSE_ERRMSG: "execute failed!"})
// return transact.TransExeResult_Success
// }),
// OnRollBackWrapper: transact.OnRollBackWrapper(func(tNode *transact.TransNode) transact.TransExeResult {
// logger.Logger.Trace("ActThrSrvApi start TransType_WebApi OnRollBackWrapper")
// event := tNode.TransEnv.GetField(WEBAPI_TRANSACTE_EVENT).(*WebApiEvent)
// resp := tNode.TransEnv.GetField(WEBAPI_TRANSACTE_RESPONSE)
// if userData, ok := resp.(*common.M2GWebApiResponse); ok {
// if len(userData.Body) > 0 {
// m := make(map[string]interface{})
// err := json.Unmarshal(userData.Body, &m)
// if err == nil {
// event.Response(m)
// return transact.TransExeResult_Success
// }
// }
// return transact.TransExeResult_Success
// }
// event.Response(map[string]interface{}{webapi.RESPONSE_STATE: webapi.STATE_ERR, webapi.RESPONSE_ERRMSG: "execute failed!"})
// return transact.TransExeResult_Success
// }),
// OnChildRespWrapper: transact.OnChildRespWrapper(func(tNode *transact.TransNode, hChild transact.TransNodeID, retCode int, ud interface{}) transact.TransExeResult {
// logger.Logger.Tracef("ActThrSrvApi start TransType_WebApi OnChildRespWrapper ret:%v childid:%x", retCode, hChild)
// userData := &common.M2GWebApiResponse{}
// err := netlib.UnmarshalPacketNoPackId(ud.([]byte), userData)
// if err == nil {
// tNode.TransEnv.SetField(WEBAPI_TRANSACTE_RESPONSE, userData)
// } else {
// logger.Logger.Trace("trascate.OnChildRespWrapper err:", err)
// }
// return transact.TransExeResult(retCode)
// }),
// })
//
// //测试
// admin.MyAdminApp.Route("/api/ActThr/Test", ActThrSrvApi)
//
// //增加自动黑白名单控制
// admin.MyAdminApp.Route("/api/ActThr/Upsert", ActThrSrvApi)
//
// //删除自动黑白名单控制
// admin.MyAdminApp.Route("/api/ActThr/Delete", ActThrSrvApi)
//
// //删除所有添加的黑名单
// admin.MyAdminApp.Route("/api/ActThr/ResetBW", ActThrSrvApi)
//
//}

View File

@ -1,186 +0,0 @@
package api
//
//import (
// "crypto/md5"
// "encoding/hex"
// "encoding/json"
// "fmt"
// "mongo.games.com/game/common"
// "mongo.games.com/game/model"
// "mongo.games.com/game/webapi"
// "mongo.games.com/goserver/core"
// "mongo.games.com/goserver/core/admin"
// "mongo.games.com/goserver/core/logger"
// "mongo.games.com/goserver/core/netlib"
// "mongo.games.com/goserver/core/transact"
// "mongo.games.com/goserver/core/utils"
// "io"
// "io/ioutil"
// "net/http"
// "time"
//)
//
//const (
// RANKSRVAPI_TRANSACTE_EVENT = "GAMESRVAPI_TRANSACTE_EVENT"
// RANKSRVAPI_TRANSACTE_RESPONSE = "RANKSRVAPI_TRANSACTE_RESPONSE"
//)
//
//// 处理 web 请求 rank server 相关的配置协议, 转发至 rank server 处理
//
//func RankSrvApi(rw http.ResponseWriter, req *http.Request) {
// defer utils.DumpStackIfPanic("api.RankSrvApi")
// logger.Logger.Info("RankSrvApi receive:", req.URL.Path, req.URL.RawQuery)
//
// if common.RequestCheck(req, model.GameParamData.WhiteHttpAddr) == false {
// logger.Logger.Info("RemoteAddr [%v] require api.", req.RemoteAddr)
// return
// }
// data, err := io.ReadAll(req.Body)
// if err != nil {
// logger.Logger.Info("Body err.", err)
// webApiResponse(rw, map[string]interface{}{
// webapi.RESPONSE_STATE: webapi.STATE_ERR,
// webapi.RESPONSE_ERRMSG: "Post data is null!",
// })
// return
// }
// logger.Logger.Info(string(data))
// m := req.URL.Query()
// timestamp := m.Get("nano")
// if timestamp == "" {
// logger.Logger.Info(req.RemoteAddr, " RankSrvApi param error: nano not allow null")
// return
// }
// sign := m.Get("sign")
// if sign == "" {
// logger.Logger.Info(req.RemoteAddr, " RankSrvApi param error: sign not allow null")
// return
// }
// startTime := time.Now().UnixNano()
// args := fmt.Sprintf("%v;%v;%v;%v", common.Config.AppId, req.URL.Path, string(data), timestamp)
// h := md5.New()
// io.WriteString(h, args)
// realSign := hex.EncodeToString(h.Sum(nil))
// if realSign != sign && !common.Config.IsDevMode {
// logger.Logger.Info(req.RemoteAddr, " srvCtrlMain sign error: expect ", realSign, " ; but get ", sign, " raw=", args)
// webApiResponse(rw, map[string]interface{}{webapi.RESPONSE_STATE: webapi.STATE_ERR, webapi.RESPONSE_ERRMSG: "Sign error!"})
// return
// }
// var rep map[string]interface{}
// start := time.Now()
// res := make(chan map[string]interface{}, 1)
// core.CoreObject().SendCommand(&WebApiEvent{req: req, path: req.URL.Path, h: HandlerWrapper(func(event *WebApiEvent, data []byte) bool {
// logger.Logger.Trace("RankSrvApi start transcate")
// tnp := &transact.TransNodeParam{
// Tt: common.TransType_WebApi_ForRank,
// Ot: transact.TransOwnerType(common.GetSelfSrvType()),
// Oid: common.GetSelfSrvId(),
// AreaID: common.GetSelfAreaId(),
// }
// logger.Info("call info:", common.GetSelfAreaId(), common.GetSelfSrvType(), common.GetSelfSrvId())
// tNode := transact.DTCModule.StartTrans(tnp, event, transact.DefaultTransactTimeout) //超时时间30秒
// if tNode != nil {
// tNode.TransEnv.SetField(RANKSRVAPI_TRANSACTE_EVENT, event)
// tNode.Go(core.CoreObject())
// }
// return true
// }), body: data, rawQuery: req.URL.RawQuery, res: res}, false)
// select {
// case rep = <-res:
// if rep != nil {
// webApiResponse(rw, rep)
// }
// case <-time.After(ApiDefaultTimeout):
// rep = make(map[string]interface{})
// rep[webapi.RESPONSE_STATE] = webapi.STATE_ERR
// rep[webapi.RESPONSE_ERRMSG] = "proccess timeout!"
// webApiResponse(rw, rep)
// }
// ps := int64(time.Now().Sub(start) / time.Millisecond)
// result, err := json.Marshal(rep)
// if err == nil {
// log := model.NewAPILog(req.URL.Path, req.URL.RawQuery, string(data[:]), req.RemoteAddr, string(result[:]), startTime, ps)
// APILogChannelSington.Write(log)
// }
// return
//}
//
//func init() {
// transact.RegisteHandler(common.TransType_WebApi_ForRank, &transact.TransHanderWrapper{
// OnExecuteWrapper: transact.OnExecuteWrapper(func(tNode *transact.TransNode, ud interface{}) transact.TransExeResult {
// logger.Logger.Trace("RankSrvApi start TransType_WebApi_ForRank OnExecuteWrapper ")
// tnp := &transact.TransNodeParam{
// Tt: common.TransType_WebApi_ForRank,
// Ot: transact.TransOwnerType(common.RankServerType),
// Oid: common.GetRankSrvId(),
// AreaID: common.GetSelfAreaId(),
// Tct: transact.TransactCommitPolicy_TwoPhase,
// }
// logger.Infof("params: %+v", tnp)
// if event, ok := ud.(*WebApiEvent); ok {
// userData := &common.M2GWebApiRequest{Path: event.path, RawQuery: event.rawQuery, Body: event.body, ReqIp: event.req.RemoteAddr}
// tNode.StartChildTrans(tnp, userData, transact.DefaultTransactTimeout)
//
// pid := tNode.MyTnp.TId
// cid := tnp.TId
// logger.Logger.Tracef("RankSrvApi start TransType_WebApi_ForRank OnExecuteWrapper tid:%x childid:%x", pid, cid)
// return transact.TransExeResult_Success
// }
// return transact.TransExeResult_Failed
// }),
// OnCommitWrapper: transact.OnCommitWrapper(func(tNode *transact.TransNode) transact.TransExeResult {
// logger.Logger.Trace("RankSrvApi start TransType_WebApi_ForRank OnCommitWrapper")
// event := tNode.TransEnv.GetField(RANKSRVAPI_TRANSACTE_EVENT).(*WebApiEvent)
// resp := tNode.TransEnv.GetField(RANKSRVAPI_TRANSACTE_RESPONSE)
// if userData, ok := resp.(*common.M2GWebApiResponse); ok {
// if len(userData.Body) > 0 {
// m := make(map[string]interface{})
// err := json.Unmarshal(userData.Body, &m)
// if err == nil {
// event.Response(m)
// return transact.TransExeResult_Success
// }
// }
// }
// event.Response(map[string]interface{}{webapi.RESPONSE_STATE: webapi.STATE_ERR, webapi.RESPONSE_ERRMSG: "execute failed!"})
// return transact.TransExeResult_Success
// }),
// OnRollBackWrapper: transact.OnRollBackWrapper(func(tNode *transact.TransNode) transact.TransExeResult {
// logger.Logger.Trace("RankSrvApi start TransType_WebApi_ForRank OnRollBackWrapper")
// event := tNode.TransEnv.GetField(RANKSRVAPI_TRANSACTE_EVENT).(*WebApiEvent)
// resp := tNode.TransEnv.GetField(RANKSRVAPI_TRANSACTE_RESPONSE)
// if userData, ok := resp.(*common.M2GWebApiResponse); ok {
// if len(userData.Body) > 0 {
// m := make(map[string]interface{})
// err := json.Unmarshal(userData.Body, &m)
// if err == nil {
// event.Response(m)
// return transact.TransExeResult_Success
// }
// }
// return transact.TransExeResult_Success
// }
// event.Response(map[string]interface{}{webapi.RESPONSE_STATE: webapi.STATE_ERR, webapi.RESPONSE_ERRMSG: "execute failed!"})
// return transact.TransExeResult_Success
// }),
// OnChildRespWrapper: transact.OnChildRespWrapper(func(tNode *transact.TransNode, hChild transact.TransNodeID, retCode int, ud interface{}) transact.TransExeResult {
// logger.Logger.Tracef("RankSrvApi start TransType_WebApi_ForRank OnChildRespWrapper ret:%v childid:%x", retCode, hChild)
// userData := &common.M2GWebApiResponse{}
// err := netlib.UnmarshalPacketNoPackId(ud.([]byte), userData)
// if err == nil {
// tNode.TransEnv.SetField(RANKSRVAPI_TRANSACTE_RESPONSE, userData)
// } else {
// logger.Logger.Trace("trascate.OnChildRespWrapper err:", err)
// }
// return transact.TransExeResult(retCode)
// }),
// }) //RegisteHandler
//
// admin.MyAdminApp.Route("/api/rank/getConfig", RankSrvApi)
// admin.MyAdminApp.Route("/api/rank/updateConfig", RankSrvApi)
// admin.MyAdminApp.Route("/api/rank/debug/settings", RankSrvApi)
// admin.MyAdminApp.Route("/api/rank/debug/board", RankSrvApi)
// admin.MyAdminApp.Route("/api/rank/reset", RankSrvApi)
// admin.MyAdminApp.Route("/api/rank/syncUser", RankSrvApi) // 同步主库玩家信息
//}

View File

@ -83,6 +83,12 @@
"SupportAdmin": true,
"AdminHttpPort": 9899
},
"etcd": {
"Url": ["127.0.0.1:2379"],
"UserName": "",
"Password": "",
"DialTimeout": 60
},
"costum": {
"MgoRpcCliNet": "tcp",
"MgoRpcCliAddr": "127.0.0.1:8999",

View File

@ -1,39 +1,37 @@
package main
import (
_ "mongo.games.com/game"
_ "mongo.games.com/game/mgrsrv/api"
_ "mongo.games.com/game/srvdata"
"time"
"mongo.games.com/game/common"
"mongo.games.com/game/model"
"mongo.games.com/game/srvdata"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/module"
_ "mongo.games.com/game"
"mongo.games.com/game/common"
_ "mongo.games.com/game/mgrsrv/api"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
_ "mongo.games.com/game/srvdata"
)
func main() {
core.RegisterConfigEncryptor(common.ConfigFE)
// 自定义配置文件
model.InitGameParam()
// package模块
defer core.ClosePackages()
core.LoadPackages("config.json")
model.InitGameParam()
logger.Logger.Warnf("log data %v", srvdata.Config.RootPath)
waiter := module.Start()
waiter.Wait("main()")
}
func init() {
//首先加载游戏配置
// core hook
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
model.StartupRPClient(common.CustomConfig.GetString("MgoRpcCliNet"), common.CustomConfig.GetString("MgoRpcCliAddr"), time.Duration(common.CustomConfig.GetInt("MgoRpcCliReconnInterV"))*time.Second)
mq.StartPublisher(common.CustomConfig.GetString("RabbitMQURL"), common.CustomConfig.GetString("RMQExchange"), true, common.CustomConfig.GetInt("RMQPublishBacklog"))
return nil
})
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
mq.StopPublisher()
model.ShutdownRPClient()
return nil
})
// module模块
w := module.Start()
w.Wait("main()")
}

View File

@ -55,6 +55,8 @@ type GameDetailedLog struct {
Time time.Time //记录时间
Trend20Lately string //最近游戏走势
Ts int64 //时间戳
CtrlType int // 1控赢 2控输 0不控
PlayerPool map[int]int // 个人水池分
}
func NewGameDetailedLog() *GameDetailedLog {
@ -63,7 +65,7 @@ func NewGameDetailedLog() *GameDetailedLog {
}
func NewGameDetailedLogEx(logid string, gameid, sceneid, gamemode, gamefreeid, playercount, gametiming, gamebasebet int32,
gamedetailednote string, platform string, clubId int32, clubRoom string, cpCtx CoinPoolCtx, ver int32, trend20Lately string) *GameDetailedLog {
gamedetailednote string, platform string, clubId int32, clubRoom string, cpCtx CoinPoolCtx, ver int32, trend20Lately string, ctrlType int, playerPool map[int]int) *GameDetailedLog {
cl := NewGameDetailedLog()
cl.LogId = logid
cl.GameId = gameid
@ -83,6 +85,8 @@ func NewGameDetailedLogEx(logid string, gameid, sceneid, gamemode, gamefreeid, p
cl.GameDetailVer = ver
cl.Trend20Lately = trend20Lately
cl.Ts = time.Now().Unix()
cl.CtrlType = ctrlType
cl.PlayerPool = playerPool
return cl
}

View File

@ -1521,6 +1521,8 @@ type TienLenType struct {
TaxRate int32 //税率(万分比)
PlayerData []TienLenPerson //玩家信息
RoomMode int
CtrlType int `json:"-"` // 1控赢 2控输 0不控
PlayerPool map[int]int `json:"-"`
}
type TienLenAddItem struct {

View File

@ -88,6 +88,7 @@ type GameParam struct {
TestActSwitch bool // 开启所有活动开关
RankPlayerLevelMaxNum int //等级榜最大人数
CloseChannelSwitch bool //关闭渠道开关功能
BackendTimeLocal int //后台时区
}
var GameParamPath = "../data/gameparam.json"
@ -238,4 +239,7 @@ func InitGameParam() {
if GameParamData.RankPlayerLevelMaxNum == 0 {
GameParamData.RankPlayerLevelMaxNum = 100
}
if GameParamData.BackendTimeLocal == 0 {
GameParamData.BackendTimeLocal = 8
}
}

View File

@ -74,10 +74,11 @@ type Message struct {
Params []int32 //额外参数
Platform string //平台信息
ShowId int64 //区分主子游戏大厅
Channel []string //渠道
}
func NewMessage(pid string, srcId int32, srcName string, snid, mType int32, title, content string, coin, diamond int64,
state int32, addTime int64, attachState int32, giftId string, params []int32, platform string, showId int64) *Message {
state int32, addTime int64, attachState int32, giftId string, params []int32, platform string, showId int64, channel []string) *Message {
if srcName == "" {
srcName = "{\"zh\":\"系统\",\"vi\":\"GM\",\"en\":\"GM\",\"kh\":\"GM\"}"
}
@ -99,6 +100,7 @@ func NewMessage(pid string, srcId int32, srcName string, snid, mType int32, titl
Platform: platform,
Diamond: diamond,
ShowId: showId,
Channel: channel,
}
if msg.Pid == "" {
msg.Pid = msg.Id.Hex()

View File

@ -359,7 +359,7 @@ type PlayerData struct {
Coin int64 //金豆
CoinPayTs int64 //金豆冲账时间戳
CoinPayTotal int64 //在线总充值金额
MoneyPayTotal int64 //在线总充值金额(实充)
MoneyPayTotal int64 //VIP经验值注意这里是没有乘充V比之前的值
CoinExchangeTotal int64 //总提现金额 兑换
SafeBoxCoin int64 //保险箱金币
SafeBoxPassword string //保险箱密码
@ -458,6 +458,7 @@ type PlayerData struct {
ItemRecExpireTime int64 // 记牌器到期时间
RequestAddFriend map[int32]int64 // 玩家申请好友记录
IsTakeExpireItem bool // 是否领取
LastChannel string // 最后包类型
}
// 七日签到数据
@ -578,11 +579,18 @@ type PlayerDataForWeb struct {
WinTimes int32
}
type WebItem struct {
Id int64
N int64
Name string
}
type WebPlayerDataParam struct {
*PlayerData
RankScore map[int64]int64
PlayerPoolUpper, PlayerPoolLower, PlayerPoolCurrent, PlayerPoolOdds int64
RoleAdded, VipAdded, VipExp int64
Items []*WebItem
}
func ConvertPlayerDataToWebData(param *WebPlayerDataParam) *webapi.PlayerData {
@ -651,6 +659,14 @@ func ConvertPlayerDataToWebData(param *WebPlayerDataParam) *webapi.PlayerData {
pdfw.InviteSnId = param.InviteSnId
pdfw.InviteScore = param.InviteScore
pdfw.Channel = param.Channel
pdfw.LastChannel = param.LastChannel
for _, v := range param.Items {
pdfw.Items = append(pdfw.Items, &webapi.ItemInfo{
ItemId: int32(v.Id),
ItemNum: v.N,
Name: v.Name,
})
}
return pdfw
}
func (this *PlayerData) IsMarkFlag(flag int) bool {

View File

@ -18,8 +18,11 @@ import (
为了使用方便这里统一启动订阅
*/
var subscriberLock sync.RWMutex
var subscriber = make(map[string][]*Subscriber)
var (
globalConsumer *RabbitMQConsumer
subscriberLock sync.RWMutex
subscriber = make(map[string][]*Subscriber)
)
type Subscriber struct {
broker.Subscriber
@ -27,6 +30,96 @@ type Subscriber struct {
opts []broker.SubscribeOption
}
type RabbitMQConsumer struct {
broker.Broker
url string
exchange rabbitmq.Exchange
}
func NewRabbitMQConsumer(url string, exchange rabbitmq.Exchange, opts ...broker.Option) *RabbitMQConsumer {
mq := &RabbitMQConsumer{
url: url,
exchange: exchange,
}
options := []broker.Option{
broker.Addrs(url), rabbitmq.ExchangeName(exchange.Name),
}
if exchange.Durable {
options = append(options, rabbitmq.DurableExchange())
}
if len(opts) > 0 {
options = append(options, opts...)
}
mq.Broker = rabbitmq.NewBroker(options...)
mq.Broker.Init()
return mq
}
func (c *RabbitMQConsumer) Start() error {
if ok, _ := common.PathExists(BackupPath); !ok {
os.MkdirAll(BackupPath, os.ModePerm)
}
if err := c.Connect(); err != nil {
return err
}
logger.Logger.Infof("RabbitMQConsumer.Start() url:%s exchange:%s", c.url, c.exchange.Name)
for topic, ss := range GetSubscribers() {
for _, s := range ss {
sub, err := c.Subscribe(topic, func(event broker.Event) error {
var err error
defer func() {
e := recover()
if e != nil {
logger.Logger.Errorf("RabbitMQConsumer.Subscriber() topic:%v message:%v recover:%v", event.Topic(), event.Message(), e)
}
if err != nil {
c.backUp(event, err)
}
}()
err = s.h(event)
return err
}, s.opts...)
if err != nil {
return err
}
s.Subscriber = sub
}
}
return nil
}
func (c *RabbitMQConsumer) Stop() error {
logger.Logger.Infof("RabbitMQConsumer.Stop() url:%s exchange:%s", c.url, c.exchange.Name)
for _, ss := range GetSubscribers() {
for _, s := range ss {
s.Unsubscribe()
}
}
return c.Disconnect()
}
func (c *RabbitMQConsumer) backUp(e broker.Event, err error) {
tNow := time.Now()
filePath := fmt.Sprintf(FilePathFormat, BackupPath, e.Topic(), tNow.Format(TimeFormat), tNow.Nanosecond(), rand.Int31n(10000))
f, er := os.Create(filePath)
if er != nil {
logger.Logger.Errorf("RabbitMQPublisher.public() topic:%v message:%v err:%v", e.Topic(), e.Message(), er)
return
}
defer f.Close()
var reason string
if err != nil {
reason = err.Error()
}
f.WriteString("reason:" + reason + "\n")
f.WriteString("data:" + string(e.Message().Body) + "\n")
}
// RegisterSubscriber 注册订阅处理方法
// 不同订阅是在各自的协程中执行的
func RegisterSubscriber(topic string, h broker.Handler, opts ...broker.SubscribeOption) {
@ -37,21 +130,7 @@ func RegisterSubscriber(topic string, h broker.Handler, opts ...broker.Subscribe
subscriberLock.Lock()
subscriber[topic] = append(subscriber[topic], &s)
subscriberLock.Unlock()
}
func UnregisterSubscriber(topic string) {
subscriberLock.Lock()
delete(subscriber, topic)
subscriberLock.Unlock()
}
func GetSubscriber(topic string) []*Subscriber {
subscriberLock.RLock()
defer subscriberLock.RUnlock()
if s, ok := subscriber[topic]; ok {
return s
}
return nil
logger.Logger.Infof("RegisterSubscriber topic:%v", topic)
}
func GetSubscribers() map[string][]*Subscriber {
@ -66,75 +145,18 @@ func GetSubscribers() map[string][]*Subscriber {
return ret
}
type RabbitMQConsumer struct {
broker.Broker
url string
exchange rabbitmq.Exchange
}
func NewRabbitMQConsumer(url string, exchange rabbitmq.Exchange) *RabbitMQConsumer {
mq := &RabbitMQConsumer{
url: url,
exchange: exchange,
}
rabbitmq.DefaultRabbitURL = mq.url
rabbitmq.DefaultExchange = mq.exchange
mq.Broker = rabbitmq.NewBroker()
mq.Broker.Init()
return mq
}
func (c *RabbitMQConsumer) Start() error {
if err := c.Connect(); err != nil {
return err
}
sss := GetSubscribers()
for topic, ss := range sss {
for _, s := range ss {
sub, err := c.Subscribe(topic, s.h, s.opts...)
if err != nil {
return err
}
s.Subscriber = sub
}
}
return nil
}
func (c *RabbitMQConsumer) Stop() error {
sss := GetSubscribers()
for _, ss := range sss {
for _, s := range ss {
s.Unsubscribe()
}
}
return c.Disconnect()
}
func BackUp(e broker.Event, err error) {
tNow := time.Now()
filePath := fmt.Sprintf("%s/%s_%s_%09d_%04d.dat", BACKUP_PATH, e.Topic(), tNow.Format(TIME_FORMAT), tNow.Nanosecond(), rand.Int31n(10000))
f, err := os.Create(filePath)
if err != nil {
logger.Logger.Errorf("RabbitMQPublisher.public(%s,%v) err:%v", e.Topic(), e.Message(), err)
return
}
defer f.Close()
var reason string
if err != nil {
reason = err.Error()
}
f.WriteString("reason:" + reason + "\n")
f.WriteString("data:" + string(e.Message().Body) + "\n")
}
func init() {
if ok, _ := common.PathExists(BACKUP_PATH); !ok {
os.MkdirAll(BACKUP_PATH, os.ModePerm)
// StartConsumer 启动消费者
func StartConsumer(url string, exchange string, durableExchange bool, opts ...broker.Option) {
StopConsumer()
globalConsumer = NewRabbitMQConsumer(url, rabbitmq.Exchange{Name: exchange, Durable: durableExchange}, opts...)
if err := globalConsumer.Start(); err != nil {
panic(fmt.Sprintf("RabbitMQConsumer.Start() url:%v exchange:%v err:%v", url, exchange, err))
}
}
// StopConsumer 停止消费者
func StopConsumer() {
if globalConsumer != nil {
globalConsumer.Stop()
}
}

View File

@ -9,10 +9,11 @@ import (
"sync"
"time"
"mongo.games.com/game/common"
"mongo.games.com/goserver/core/broker"
"mongo.games.com/goserver/core/broker/rabbitmq"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/game/common"
)
/*
@ -20,150 +21,176 @@ import (
*/
const (
BACKUP_PATH = "backup"
TIME_FORMAT = "20060102150405"
BackupPath = "backup"
TimeFormat = "20060102150405"
FilePathFormat = "%s/%s_%s_%09d_%04d.dat"
)
var ERR_CLOSED = errors.New("publisher is closed")
var ErrClosed = errors.New("publisher is closed")
var globalPublisher *RabbitMQPublisher
type item struct {
topic string
msg interface{}
opts []broker.PublishOption
}
type RabbitMQPublisher struct {
b broker.Broker
broker.Broker
exchange rabbitmq.Exchange
url string
que chan *item
closed bool
waitor sync.WaitGroup
closed chan struct{}
wg sync.WaitGroup
}
func NewRabbitMQPublisher(url string, exchange rabbitmq.Exchange, backlog int) *RabbitMQPublisher {
if backlog <= 0 {
backlog = 1
func NewRabbitMQPublisher(url string, exchange rabbitmq.Exchange, queueSize int, opts ...broker.Option) *RabbitMQPublisher {
if queueSize <= 0 {
queueSize = 1
}
mq := &RabbitMQPublisher{
url: url,
exchange: exchange,
que: make(chan *item, backlog),
que: make(chan *item, queueSize),
closed: make(chan struct{}),
}
rabbitmq.DefaultRabbitURL = mq.url
rabbitmq.DefaultExchange = mq.exchange
mq.b = rabbitmq.NewBroker()
mq.b.Init()
options := []broker.Option{
broker.Addrs(url), rabbitmq.ExchangeName(exchange.Name),
}
if exchange.Durable {
options = append(options, rabbitmq.DurableExchange())
}
if len(opts) > 0 {
options = append(options, opts...)
}
mq.Broker = rabbitmq.NewBroker(options...)
mq.Broker.Init()
return mq
}
func (p *RabbitMQPublisher) Start() (err error) {
if ok, _ := common.PathExists(BACKUP_PATH); !ok {
err = os.MkdirAll(BACKUP_PATH, os.ModePerm)
if err != nil {
return
}
}
err = p.b.Connect()
if err != nil {
return
}
go p.workerRoutine()
return nil
}
func (p *RabbitMQPublisher) Stop() error {
if p.closed {
return ERR_CLOSED
}
p.closed = true
close(p.que)
for item := range p.que {
p.publish(item.topic, item.msg)
}
//等待所有投递出去的任务全部完成
p.waitor.Wait()
return p.b.Disconnect()
}
// Send 发布消息,异步
func (p *RabbitMQPublisher) Send(topic string, msg interface{}) (err error) {
if p.closed {
return ERR_CLOSED
}
i := &item{topic: topic, msg: msg}
select {
case p.que <- i:
default:
//会不会情况更糟糕
go p.concurrentPublish(topic, msg)
}
return nil
}
func (p *RabbitMQPublisher) concurrentPublish(topic string, msg interface{}) (err error) {
p.waitor.Add(1)
defer p.waitor.Done()
return p.publish(topic, msg)
}
// 发布消息,同步
func (p *RabbitMQPublisher) publish(topic string, msg interface{}) (err error) {
func (p *RabbitMQPublisher) publish(topic string, msg interface{}, opts ...broker.PublishOption) (err error) {
defer func() {
if err != nil {
e := recover()
if e != nil {
logger.Logger.Errorf("RabbitMQPublisher.public() topic:%v message:%v recover:%v", topic, msg, e)
}
if err != nil || e != nil {
p.backup(topic, msg, err)
}
recover()
}()
buf, err := json.Marshal(msg)
if err != nil {
return err
var buf []byte
switch d := msg.(type) {
case []byte:
buf = d
case string:
buf = []byte(d)
default:
buf, err = json.Marshal(msg)
if err != nil {
return err
}
}
err = p.b.Publish(topic, &broker.Message{Body: buf})
err = p.Publish(topic, &broker.Message{Body: buf}, opts...)
if err != nil {
logger.Logger.Error("RabbitMQPublisher.publish err:", err)
logger.Logger.Error("RabbitMQPublisher.publish() topic:%v message:%v err:%v", topic, msg, err)
return
}
return nil
}
func (p *RabbitMQPublisher) workerRoutine() {
p.waitor.Add(1)
defer p.waitor.Done()
func (p *RabbitMQPublisher) publishRoutine() {
p.wg.Add(1)
defer p.wg.Done()
for {
select {
case item, ok := <-p.que:
if ok {
p.publish(item.topic, item.msg)
p.publish(item.topic, item.msg, item.opts...)
} else {
return
}
case <-p.closed:
return
}
}
}
func (p *RabbitMQPublisher) Start() (err error) {
if ok, _ := common.PathExists(BackupPath); !ok {
err = os.MkdirAll(BackupPath, os.ModePerm)
if err != nil {
return
}
}
if err = p.Connect(); err != nil {
return err
}
logger.Logger.Infof("RabbitMQPublisher.Start() url:%s exchange:%s", p.url, p.exchange.Name)
go p.publishRoutine()
return nil
}
func (p *RabbitMQPublisher) Stop() error {
logger.Logger.Infof("RabbitMQPublisher.Stop() url:%s exchange:%s", p.url, p.exchange.Name)
select {
case <-p.closed:
return ErrClosed
default:
}
close(p.closed)
close(p.que)
for item := range p.que {
p.publish(item.topic, item.msg, item.opts...)
}
//等待所有投递出去的任务全部完成
p.wg.Wait()
return p.Disconnect()
}
// Send 发布消息,异步
func (p *RabbitMQPublisher) Send(topic string, msg interface{}, opts ...broker.PublishOption) (err error) {
select {
case <-p.closed:
return ErrClosed
default:
}
i := &item{topic: topic, msg: msg, opts: opts}
select {
case p.que <- i:
default:
//会不会情况更糟糕
go func() {
p.wg.Add(1)
defer p.wg.Done()
p.publish(topic, msg)
}()
}
return nil
}
func (p *RabbitMQPublisher) backup(topic string, msg interface{}, err error) {
buf, err := json.Marshal(msg)
if err != nil {
buf, er := json.Marshal(msg)
if er != nil {
return
}
tNow := time.Now()
filePath := fmt.Sprintf("%s/%s_%s_%09d_%04d.dat", BACKUP_PATH, topic, tNow.Format(TIME_FORMAT), tNow.Nanosecond(), rand.Int31n(10000))
f, err := os.Create(filePath)
if err != nil {
logger.Logger.Errorf("RabbitMQPublisher.public(%s,%v) err:%v", topic, msg, err)
filePath := fmt.Sprintf(FilePathFormat, BackupPath, topic, tNow.Format(TimeFormat), tNow.Nanosecond(), rand.Int31n(10000))
f, er := os.Create(filePath)
if er != nil {
logger.Logger.Errorf("RabbitMQPublisher.public() topic:%v message:%v err:%v", topic, msg, er)
return
}
defer f.Close()
@ -174,3 +201,26 @@ func (p *RabbitMQPublisher) backup(topic string, msg interface{}, err error) {
f.WriteString("reason:" + reason + "\n")
f.WriteString("data:" + string(buf) + "\n")
}
// StartPublisher 启动发布者
func StartPublisher(url string, exchange string, durableExchange bool, queueSize int, opts ...broker.Option) {
StopPublisher()
globalPublisher = NewRabbitMQPublisher(url, rabbitmq.Exchange{Name: exchange, Durable: durableExchange}, queueSize, opts...)
if err := globalPublisher.Start(); err != nil {
panic(fmt.Sprintf("RabbitMQPublisher.Start() url:%v exchange:%v err:%v", url, exchange, err))
}
}
// StopPublisher 停止发布者
func StopPublisher() {
if globalPublisher != nil {
globalPublisher.Stop()
}
}
func Send(topic string, msg interface{}, opts ...broker.PublishOption) (err error) {
if globalPublisher != nil {
return globalPublisher.Send(topic, msg, opts...)
}
return ErrClosed
}

File diff suppressed because it is too large Load Diff

View File

@ -615,6 +615,7 @@ message CSQueryRoomInfo{
repeated int32 GameIds = 1;
int32 GameSite = 2; //1. 2. 3.
repeated int32 Id = 3; //gamefreeid
int32 SceneMode = 4; // 0 1
}
//

File diff suppressed because it is too large Load Diff

View File

@ -991,7 +991,8 @@ message VIPcfg {
int32 Privilege8 = 14;//VIP客服标识
int32 ShopId2 = 15;
int32 ShopId7 = 16;
repeated int32 BagStatus = 17;//||VIP礼包 0 1
repeated int32 BagStatus = 17;//||VIP礼包 0 1
int32 MatchFreeTimes = 18;//
}
//VIP信息
@ -1182,9 +1183,16 @@ message SCPigBankCoin {
}
// PACKET_CSExchangeChannel
message CSExchangeChannel{}
message CSExchangeChannel{
int32 Tp = 1; // 0 1 2v卡掉落
}
message ChannelSwitch {
repeated string OnChannelName = 1; //
int32 Tp = 2; // 1 2v卡掉落
}
// PACKET_SCExchangeChannel
message SCExchangeChannel{
repeated string OnChannelName = 1; //
repeated ChannelSwitch Datas = 1;
}

View File

@ -9916,6 +9916,7 @@ type DB_VIP struct {
Param []int32 `protobuf:"varint,16,rep,packed,name=Param,proto3" json:"Param,omitempty"`
RewardOutlineID []int32 `protobuf:"varint,17,rep,packed,name=RewardOutlineID,proto3" json:"RewardOutlineID,omitempty"`
Award map[int64]int64 `protobuf:"bytes,18,rep,name=Award,proto3" json:"Award,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"`
MatchFreeTimes int32 `protobuf:"varint,19,opt,name=MatchFreeTimes,proto3" json:"MatchFreeTimes,omitempty"`
}
func (x *DB_VIP) Reset() {
@ -10076,6 +10077,13 @@ func (x *DB_VIP) GetAward() map[int64]int64 {
return nil
}
func (x *DB_VIP) GetMatchFreeTimes() int32 {
if x != nil {
return x.MatchFreeTimes
}
return 0
}
type DB_VIPArray struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -11395,7 +11403,7 @@ var file_pbdata_proto_rawDesc = []byte{
0x31, 0x0a, 0x0c, 0x44, 0x42, 0x5f, 0x54, 0x69, 0x70, 0x73, 0x41, 0x72, 0x72, 0x61, 0x79, 0x12,
0x21, 0x0a, 0x03, 0x41, 0x72, 0x72, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73,
0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x44, 0x42, 0x5f, 0x54, 0x69, 0x70, 0x73, 0x52, 0x03, 0x41,
0x72, 0x72, 0x22, 0xc2, 0x05, 0x0a, 0x06, 0x44, 0x42, 0x5f, 0x56, 0x49, 0x50, 0x12, 0x0e, 0x0a,
0x72, 0x72, 0x22, 0xea, 0x05, 0x0a, 0x06, 0x44, 0x42, 0x5f, 0x56, 0x49, 0x50, 0x12, 0x0e, 0x0a,
0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x49, 0x64, 0x12, 0x12, 0x0a,
0x04, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x4e, 0x61, 0x6d,
0x65, 0x12, 0x14, 0x0a, 0x05, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05,
@ -11431,21 +11439,23 @@ var file_pbdata_proto_rawDesc = []byte{
0x77, 0x61, 0x72, 0x64, 0x4f, 0x75, 0x74, 0x6c, 0x69, 0x6e, 0x65, 0x49, 0x44, 0x12, 0x2f, 0x0a,
0x05, 0x41, 0x77, 0x61, 0x72, 0x64, 0x18, 0x12, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x73,
0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x44, 0x42, 0x5f, 0x56, 0x49, 0x50, 0x2e, 0x41, 0x77, 0x61,
0x72, 0x64, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x41, 0x77, 0x61, 0x72, 0x64, 0x1a, 0x3d,
0x0a, 0x0f, 0x50, 0x72, 0x69, 0x76, 0x69, 0x6c, 0x65, 0x67, 0x65, 0x37, 0x45, 0x6e, 0x74, 0x72,
0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03,
0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01,
0x28, 0x03, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x38, 0x0a,
0x0a, 0x41, 0x77, 0x61, 0x72, 0x64, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b,
0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a,
0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x76, 0x61,
0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x2f, 0x0a, 0x0b, 0x44, 0x42, 0x5f, 0x56, 0x49,
0x50, 0x41, 0x72, 0x72, 0x61, 0x79, 0x12, 0x20, 0x0a, 0x03, 0x41, 0x72, 0x72, 0x18, 0x01, 0x20,
0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x44, 0x42, 0x5f,
0x56, 0x49, 0x50, 0x52, 0x03, 0x41, 0x72, 0x72, 0x42, 0x26, 0x5a, 0x24, 0x6d, 0x6f, 0x6e, 0x67,
0x6f, 0x2e, 0x67, 0x61, 0x6d, 0x65, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x61, 0x6d, 0x65,
0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x72, 0x64, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x41, 0x77, 0x61, 0x72, 0x64, 0x12, 0x26,
0x0a, 0x0e, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x46, 0x72, 0x65, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x73,
0x18, 0x13, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0e, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x46, 0x72, 0x65,
0x65, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x1a, 0x3d, 0x0a, 0x0f, 0x50, 0x72, 0x69, 0x76, 0x69, 0x6c,
0x65, 0x67, 0x65, 0x37, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79,
0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76,
0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75,
0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x38, 0x0a, 0x0a, 0x41, 0x77, 0x61, 0x72, 0x64, 0x45, 0x6e,
0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03,
0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02,
0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22,
0x2f, 0x0a, 0x0b, 0x44, 0x42, 0x5f, 0x56, 0x49, 0x50, 0x41, 0x72, 0x72, 0x61, 0x79, 0x12, 0x20,
0x0a, 0x03, 0x41, 0x72, 0x72, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x73, 0x65,
0x72, 0x76, 0x65, 0x72, 0x2e, 0x44, 0x42, 0x5f, 0x56, 0x49, 0x50, 0x52, 0x03, 0x41, 0x72, 0x72,
0x42, 0x26, 0x5a, 0x24, 0x6d, 0x6f, 0x6e, 0x67, 0x6f, 0x2e, 0x67, 0x61, 0x6d, 0x65, 0x73, 0x2e,
0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x61, 0x6d, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f,
0x6c, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (

View File

@ -1633,6 +1633,8 @@ message DB_VIP {
map<int64, int64> Award = 18;
int32 MatchFreeTimes = 19;
}
message DB_VIPArray {

View File

@ -1307,7 +1307,6 @@ type WGPlayerEnter struct {
Items map[int32]int64 `protobuf:"bytes,17,rep,name=Items,proto3" json:"Items,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"`
MatchParams []int32 `protobuf:"varint,18,rep,packed,name=MatchParams,proto3" json:"MatchParams,omitempty"` //比赛参数
RankScore map[int32]int64 `protobuf:"bytes,19,rep,name=RankScore,proto3" json:"RankScore,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // 排位积分
AppChannel string `protobuf:"bytes,20,opt,name=AppChannel,proto3" json:"AppChannel,omitempty"` // 包渠道
}
func (x *WGPlayerEnter) Reset() {
@ -1475,13 +1474,6 @@ func (x *WGPlayerEnter) GetRankScore() map[int32]int64 {
return nil
}
func (x *WGPlayerEnter) GetAppChannel() string {
if x != nil {
return x.AppChannel
}
return ""
}
//从观众席坐到座位
//PACKET_WG_AUDIENCESIT
type WGAudienceSit struct {
@ -8778,7 +8770,7 @@ var file_server_proto_rawDesc = []byte{
0x52, 0x0c, 0x52, 0x65, 0x62, 0x61, 0x74, 0x65, 0x53, 0x77, 0x69, 0x74, 0x63, 0x68, 0x12, 0x24,
0x0a, 0x0d, 0x52, 0x65, 0x62, 0x61, 0x74, 0x65, 0x47, 0x61, 0x6d, 0x65, 0x43, 0x66, 0x67, 0x18,
0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0d, 0x52, 0x65, 0x62, 0x61, 0x74, 0x65, 0x47, 0x61, 0x6d,
0x65, 0x43, 0x66, 0x67, 0x22, 0xc3, 0x06, 0x0a, 0x0d, 0x57, 0x47, 0x50, 0x6c, 0x61, 0x79, 0x65,
0x65, 0x43, 0x66, 0x67, 0x22, 0xa3, 0x06, 0x0a, 0x0d, 0x57, 0x47, 0x50, 0x6c, 0x61, 0x79, 0x65,
0x72, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x53, 0x69, 0x64, 0x18, 0x01, 0x20,
0x01, 0x28, 0x03, 0x52, 0x03, 0x53, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x47, 0x61, 0x74, 0x65,
0x53, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x47, 0x61, 0x74, 0x65, 0x53,
@ -8821,9 +8813,7 @@ var file_server_proto_rawDesc = []byte{
0x0b, 0x32, 0x24, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x57, 0x47, 0x50, 0x6c, 0x61,
0x79, 0x65, 0x72, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x2e, 0x52, 0x61, 0x6e, 0x6b, 0x53, 0x63, 0x6f,
0x72, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x09, 0x52, 0x61, 0x6e, 0x6b, 0x53, 0x63, 0x6f,
0x72, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x41, 0x70, 0x70, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c,
0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x41, 0x70, 0x70, 0x43, 0x68, 0x61, 0x6e, 0x6e,
0x65, 0x6c, 0x1a, 0x38, 0x0a, 0x0a, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79,
0x72, 0x65, 0x1a, 0x38, 0x0a, 0x0a, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79,
0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b,
0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28,
0x03, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x3c, 0x0a, 0x0e,

View File

@ -229,7 +229,6 @@ message WGPlayerEnter {
map<int32, int64> Items = 17;
repeated int32 MatchParams = 18;//
map<int32, int64> RankScore = 19;//
string AppChannel = 20; //
}
//

File diff suppressed because it is too large Load Diff

View File

@ -199,7 +199,9 @@ message PlayerData{
string InviteCode = 50;//
int32 InviteSnId = 51;//
int64 InviteScore = 52;//
string Channel = 53; //
string Channel = 53; //
string LastChannel = 54; // 使
repeated ItemInfo Items = 55; //
}
message RoomInfo{
@ -561,6 +563,7 @@ message VIPcfg {
repeated int32 RewardOutlineID = 14;
int32 ShopId2 = 15;
int32 ShopId7 = 16;
int32 MatchFreeTimes = 17; // vip比赛场免费次数
}
// etcd /game/VIPcfg VIP配置

File diff suppressed because it is too large Load Diff

View File

@ -468,6 +468,7 @@ message ASCreateShortMessage{
int64 Diamond = 8;
int64 ShowId = 9;
repeated int32 Params = 10;
repeated string OnChannelName = 11;
}
message SACreateShortMessage{
TagCode Tag = 1; //
@ -913,6 +914,8 @@ message ASAddItemById{
int32 Snid = 1; // id
string Platform = 2; // id
repeated ItemInfo ItemInfo = 3;//
int32 TypeId = 4; //
string Remark = 5; //
}
message SAAddItemById{

2
public

@ -1 +1 @@
Subproject commit a7fc5af077865e1daf27c8e04ff3247aa643a815
Subproject commit 7f2452e10c176dc35fc5ed1ffdb0b4145aec8160

View File

@ -19,7 +19,7 @@ func Register(mainId int, msgType interface{}, h func(s *netlib.Session, g *rank
return reflect.New(tp).Interface()
}
common.RegisterHandler(mainId, common.HandlerWrapper(func(s *netlib.Session, packetId int, data interface{}, sid int64) error {
common.Register(mainId, rankproto.GateTransmit{}, func(s *netlib.Session, packetId int, data interface{}, sid int64) error {
d, ok := data.(*rankproto.GateTransmit)
if !ok {
return nil
@ -36,9 +36,5 @@ func Register(mainId int, msgType interface{}, h func(s *netlib.Session, g *rank
}
return h(s, d, packetId, msg, sid)
}))
netlib.RegisterFactory(mainId, netlib.PacketFactoryWrapper(func() interface{} {
return &rankproto.GateTransmit{}
}))
})
}

View File

@ -97,7 +97,12 @@
}
}
},
"etcd": {
"Url": ["127.0.0.1:2379"],
"UserName": "",
"Password": "",
"DialTimeout": 60
},
"costum": {
"MgoRpcCliNet": "tcp",
"MgoRpcCliAddr": "127.0.0.1:8999",
@ -106,13 +111,6 @@
"RabbitMQURL": "amqp://win88:123456@127.0.0.1:5672/win88",
"RMQExchange": "win88",
"RMQPublishBacklog": 1024,
"etcdurl":[
"127.0.0.1:2379"
],
"etcduser": "root",
"etcdpwd": "win88",
"GameIdFilter": []
},

View File

@ -1,35 +0,0 @@
package main
import (
"mongo.games.com/game/common"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/broker/rabbitmq"
"time"
)
var RabbitMQPublisher *mq.RabbitMQPublisher
var RabbitMqConsumer *mq.RabbitMQConsumer
func init() {
//首先加载游戏配置
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
//初始化rpc
model.StartupRPClient(common.CustomConfig.GetString("MgoRpcCliNet"), common.CustomConfig.GetString("MgoRpcCliAddr"), time.Duration(common.CustomConfig.GetInt("MgoRpcCliReconnInterV"))*time.Second)
//rabbitmq打开链接
RabbitMqConsumer = mq.NewRabbitMQConsumer(common.CustomConfig.GetString("RabbitMQURL"), rabbitmq.Exchange{Name: common.CustomConfig.GetString("RMQExchange"), Durable: true})
if RabbitMqConsumer != nil {
RabbitMqConsumer.Start()
}
return nil
})
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
if RabbitMqConsumer != nil {
RabbitMqConsumer.Stop()
}
return nil
})
}

View File

@ -1,21 +1,37 @@
package main
import (
"mongo.games.com/game/model"
"time"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/etcd"
"mongo.games.com/goserver/core/module"
_ "mongo.games.com/game"
"mongo.games.com/game/common"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
)
func main() {
core.RegisterConfigEncryptor(common.ConfigFE)
// 自定义配置文件
model.InitGameParam()
// package模块
core.LoadPackages("config.json")
defer core.ClosePackages()
model.InitGameParam()
waitor := module.Start()
waitor.Wait("ranksrv")
// core hook
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
etcd.Start()
model.StartupRPClient(common.CustomConfig.GetString("MgoRpcCliNet"), common.CustomConfig.GetString("MgoRpcCliAddr"), time.Duration(common.CustomConfig.GetInt("MgoRpcCliReconnInterV"))*time.Second)
mq.StartConsumer(common.CustomConfig.GetString("RabbitMQURL"), common.CustomConfig.GetString("RMQExchange"), true)
return nil
})
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
mq.StopConsumer()
model.ShutdownRPClient()
return nil
})
// module模块
w := module.Start()
w.Wait("ranksrv")
}

View File

@ -6,11 +6,7 @@ import (
"time"
"github.com/globalsign/mgo/bson"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/game/common"
"mongo.games.com/game/model"
)
type AccountData struct {
@ -27,19 +23,8 @@ var (
)
var accountFileName = "robotaccount.json"
func init() {
model.InitGameParam()
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
initAccountData()
// 连接数据库服务
model.StartupRPClient(common.CustomConfig.GetString("MgoRpcCliNet"), common.CustomConfig.GetString("MgoRpcCliAddr"), time.Duration(common.CustomConfig.GetInt("MgoRpcCliReconnInterV"))*time.Second)
return nil
})
}
// 初始化机器人账号
func initAccountData() {
// InitAccountData 初始化机器人账号
func InitAccountData() {
dirty := false
newFunc := func(n int) {
for i := 0; i < n; i++ {

View File

@ -1,11 +1,15 @@
package main
import (
"time"
"mongo.games.com/goserver/core"
"mongo.games.com/goserver/core/module"
_ "mongo.games.com/game"
_ "mongo.games.com/game/common"
"mongo.games.com/game/common"
"mongo.games.com/game/model"
"mongo.games.com/game/robot/base"
_ "mongo.games.com/game/robot/base"
_ "mongo.games.com/game/robot/chess"
_ "mongo.games.com/game/robot/thirteen"
@ -14,9 +18,22 @@ import (
)
func main() {
// 自定义配置文件
model.InitGameParam()
// package模块
defer core.ClosePackages()
core.LoadPackages("config.json")
// core hook
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
model.StartupRPClient(common.CustomConfig.GetString("MgoRpcCliNet"), common.CustomConfig.GetString("MgoRpcCliAddr"), time.Duration(common.CustomConfig.GetInt("MgoRpcCliReconnInterV"))*time.Second)
base.InitAccountData()
return nil
})
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
model.ShutdownRPClient()
return nil
})
// module模块
waiter := module.Start()
waiter.Wait("main()")
}

View File

@ -154,7 +154,9 @@ func (this *Configuration) Init() error {
}
func (this *Configuration) Close() error {
this.watcher.Close()
if this.watcher != nil {
this.watcher.Close()
}
return nil
}

View File

@ -74,7 +74,7 @@ func CSUpBagInfo(s *netlib.Session, packetid int, data interface{}, sid int64) e
ItemId: msg.ItemId,
ItemNum: int64(msg.ItemNum),
}}
BagMgrSingleton.AddItems(p, items, 0, common.GainWay_AddBag, "system", "测试", 0, 0, false)
BagMgrSingleton.AddItems(p, items, 0, common.GainWay_ItemUse, "system", "测试", 0, 0, false)
return nil
}
}
@ -112,23 +112,41 @@ func CSUpBagInfo(s *netlib.Session, packetid int, data interface{}, sid int64) e
items := map[int32]*Item{}
var useFunc func()
saleFunc := func() {
saleFunc := func(gainWay int32, oper, remark string) {
if gainWay == 0 {
gainWay = common.GainWay_ItemUse
}
if oper == "" {
oper = "player"
}
if remark == "" {
remark = "道具使用"
}
// 使用道具,减少道具
BagMgrSingleton.AddItem(p, int64(item.ItemId), int64(-msg.ItemNum), 0, common.GainWay_ItemUse, "player", "道具使用", 0, 0, false)
BagMgrSingleton.AddItem(p, int64(item.ItemId), int64(-msg.ItemNum), 0, gainWay, oper, remark, 0, 0, false)
pack.RetCode = bag.OpResultCode_OPRC_Sucess
pack.NowItemId = item.ItemId
pack.NowItemNum = item.ItemNum
}
gainFunc := func() {
gainFunc := func(gainWay int32, oper, remark string) {
for i := 0; i < int(msg.ItemNum); i++ {
useFunc()
}
if gainWay == 0 {
gainWay = common.GainWay_ItemUse
}
if oper == "" {
oper = "player"
}
if remark == "" {
remark = "道具使用"
}
if len(items) > 0 {
var itemArr []*Item
for _, v := range items {
itemArr = append(itemArr, v)
}
BagMgrSingleton.AddItems(p, itemArr, 0, common.GainWay_ItemUse, "player", "道具使用", 0, 0, false)
BagMgrSingleton.AddItems(p, itemArr, 0, gainWay, oper, remark, 0, 0, false)
for _, v := range itemArr {
pack.Infos = append(pack.Infos, &bag.ItemInfo{
ItemId: v.ItemId,
@ -141,7 +159,7 @@ func CSUpBagInfo(s *netlib.Session, packetid int, data interface{}, sid int64) e
switch item.ItemId {
case common.ItemIDGiftBox:
saleFunc()
saleFunc(0, "", "")
useFunc = func() {
sum := 0
for _, v := range srvdata.PBDB_GiftBoxMgr.Datas.GetArr() {
@ -172,10 +190,10 @@ func CSUpBagInfo(s *netlib.Session, packetid int, data interface{}, sid int64) e
}
}
}
gainFunc()
gainFunc(0, "", "")
case common.ItemIDCollectBox:
saleFunc()
saleFunc(0, "", "")
useFunc = func() {
sum := 0
for _, v := range srvdata.PBDB_CollectBoxMgr.Datas.GetArr() {
@ -206,7 +224,7 @@ func CSUpBagInfo(s *netlib.Session, packetid int, data interface{}, sid int64) e
}
}
}
gainFunc()
gainFunc(common.GainWay_Collect, "player", "集卡活动")
default:
logger.Logger.Warnf("道具使用未定义", msg.ItemId)
@ -373,10 +391,10 @@ func CSPropExchange(s *netlib.Session, packetid int, data interface{}, sid int64
}
// 扣除背包物品
for _, item := range costItems {
BagMgrSingleton.AddItem(p, int64(item.ItemId), -item.ItemNum, 0, common.GainWay_Collect, "system", "集卡活动兑换", 0, 0, false)
BagMgrSingleton.AddItem(p, int64(item.ItemId), -item.ItemNum, 0, common.GainWayItemCollectExchange, "system", "集卡活动兑换", 0, 0, false)
}
// 增加背包物品
BagMgrSingleton.AddItems(p, items, 0, common.GainWay_Collect, "system", "集卡活动兑换", 0, 0, false)
BagMgrSingleton.AddItems(p, items, 0, common.GainWayItemCollectExchange, "system", "集卡活动兑换", 0, 0, false)
for _, v := range items {
pack.Items = append(pack.Items, &bag.PropInfo{
ItemId: v.ItemId,

View File

@ -520,7 +520,7 @@ func (this *CSInviteFriendOpHandler) Process(s *netlib.Session, packetid int, da
send(p)
return nil
}
if !p.EnterScene(scene, true, pos) {
if !scene.PlayerEnter(p, pos, true) {
logger.Logger.Trace("CSInviteFriendHandler EnterScene fail")
opRetCode = friend.OpResultCode_OPRC_Error //进入房间失败
send(p)

View File

@ -142,11 +142,6 @@ func (this *CSEnterRoomHandler) Process(s *netlib.Session, packetid int, data in
if scene.IsMatchScene() && p.IsRob {
grade := int32(1000)
snid := p.SnId
ms := MatchSeasonMgrSington.GetMatchSeason(snid) // 玩家赛季信息
lv := MatchSeasonRankMgrSington.CreateRobotLv() //
if ms != nil {
lv = ms.Lv
}
roleId := int32(2000001)
if p.Roles != nil {
roleId = p.Roles.ModId
@ -159,19 +154,18 @@ func (this *CSEnterRoomHandler) Process(s *netlib.Session, packetid int, data in
randIndex := rand.Intn(len(tm.copyRobotGrades))
grade = tm.copyRobotGrades[randIndex].grade
snid = tm.copyRobotGrades[randIndex].copySnid
lv = tm.copyRobotGrades[randIndex].copyLv
roleId = tm.copyRobotGrades[randIndex].copyRoleId
tm.copyRobotGrades = append(tm.copyRobotGrades[:randIndex], tm.copyRobotGrades[randIndex+1:]...)
}
}
mc := NewMatchContext(p, tm, grade, snid, lv, roleId, 0)
mc := NewMatchContext(p, tm, grade, snid, 1, roleId, 0)
if mc != nil {
mc.gaming = true
p.matchCtx = mc
}
}
if !p.EnterScene(scene, true, -1) {
if !scene.PlayerEnter(p, -1, true) {
code = gamehall.OpResultCode_Game_OPRC_Error_Game
}
@ -1310,6 +1304,9 @@ func (this *CSQueryRoomInfoHandler) ProcessLocalGame(s *netlib.Session, packetid
pack.GameIds = append(pack.GameIds, gameid)
scenes := SceneMgrSingleton.GetScenesByGame(int(gameid))
for _, scene := range scenes {
if scene == nil {
continue
}
var isShow bool
if mapGameCfg != nil {
if cfg, have := mapGameCfg[scene.dbGameFree.Id]; have && cfg.GroupId != 0 && cfg.GroupId == scene.groupId {
@ -1317,8 +1314,16 @@ func (this *CSQueryRoomInfoHandler) ProcessLocalGame(s *netlib.Session, packetid
}
}
if p.Platform == scene.limitPlatform.IdStr || isShow {
if scene != nil && scene.sceneMode == common.SceneMode_Public && len(scene.players) != 0 {
if scene.sceneMode == int(msg.GetSceneMode()) && len(scene.players) != 0 {
if scene.gameId == int(gameid) && scene.gameSite == int(msg.GetGameSite()) {
// 私人房需要是好友
if scene.sceneMode == common.SceneMode_Private {
if !FriendMgrSington.IsFriend(p.Platform, p.SnId, scene.creator) {
continue
}
}
roomInfo := &gamehall.QRoomInfo{
GameFreeId: proto.Int32(scene.dbGameFree.GetId()),
GameId: proto.Int32(scene.dbGameFree.GetGameId()),
@ -1345,58 +1350,6 @@ func (this *CSQueryRoomInfoHandler) ProcessLocalGame(s *netlib.Session, packetid
return nil
}
func (this *CSQueryRoomInfoHandler) ProcessId(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSQueryRoomInfoHandler Process recv ProcessId", data)
if msg, ok := data.(*gamehall.CSQueryRoomInfo); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warn("CSQueryRoomInfoHandler p == nil")
return nil
}
pack := &gamehall.SCQueryRoomInfo{}
mapGameCfg := PlatformMgrSingleton.GetGameFrees(p.Platform)
for _, v := range msg.GetId() {
gameid := v / 10000
pack.GameIds = append(pack.GameIds, gameid)
scenes := SceneMgrSingleton.GetScenesByGame(int(gameid))
for _, scene := range scenes {
var isShow bool
if mapGameCfg != nil {
if cfg, have := mapGameCfg[scene.dbGameFree.Id]; have && cfg.GroupId != 0 && cfg.GroupId == scene.groupId {
isShow = true
}
}
if p.Platform == scene.limitPlatform.IdStr || isShow {
if scene != nil && scene.sceneMode == common.SceneMode_Public && len(scene.players) != 0 {
if scene.dbGameFree.Id == v {
roomInfo := &gamehall.QRoomInfo{
GameFreeId: proto.Int32(scene.dbGameFree.GetId()),
GameId: proto.Int32(scene.dbGameFree.GetGameId()),
RoomId: proto.Int(scene.sceneId),
BaseCoin: proto.Int64(int64(scene.BaseScore)),
LimitCoin: proto.Int64(scene.dbGameFree.GetLimitCoin()),
CurrNum: proto.Int(scene.GetPlayerCnt()),
MaxPlayer: proto.Int(scene.playerNum),
Creator: proto.Int32(scene.creator),
CreateTs: proto.Int32(int32(scene.createTime.Unix())),
Params: common.CopySliceInt64ToInt32(scene.params),
}
pack.RoomInfo = append(pack.RoomInfo, roomInfo)
}
}
}
}
}
pack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Sucess_Game
proto.SetDefaults(pack)
p.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_QUERYROOMINFO), pack)
logger.Logger.Trace("SCQueryRoomInfo: ", pack)
}
return nil
}
type CSLotteryLogPacketFactory struct {
}
type CSLotteryLogHandler struct {
@ -1940,15 +1893,11 @@ func (this *CSCreateRoomHandler) ProcessLocalGame(s *netlib.Session, packetid in
}
scene, code = p.CreateLocalGameScene(roomId, int(gameId), int(gameSite), int(msg.GetSceneMode()), maxPlayerNum,
params, dbGameFree, baseScore, csp.groupId)
if scene != nil {
if code == gamehall.OpResultCode_Game_OPRC_Sucess_Game {
logger.Logger.Tracef("CSCreateRoomHandler SnId:%v Create Sucess GameId:%v", p.SnId, gameId)
// try enter scene
csp.scenes[scene.sceneId] = scene
scene.csp = csp
if !p.EnterScene(scene, true, -1) {
code = gamehall.OpResultCode_Game_OPRC_Error_Game
}
if scene != nil && code == gamehall.OpResultCode_Game_OPRC_Sucess_Game {
logger.Logger.Tracef("CSCreateRoomHandler SnId:%v Create Sucess GameId:%v", p.SnId, gameId)
csp.AddScene(scene)
if !scene.PlayerEnter(p, -1, true) {
code = gamehall.OpResultCode_Game_OPRC_Error_Game
}
}
@ -2054,7 +2003,7 @@ func (this *CSCreateRoomHandler) ProcessThirteen(s *netlib.Session, packetid int
// try enter scene
csp.scenes[scene.sceneId] = scene
scene.csp = csp
if !p.EnterScene(scene, true, -1) {
if !scene.PlayerEnter(p, -1, true) {
code = gamehall.OpResultCode_Game_OPRC_Error_Game
}
}

View File

@ -86,7 +86,7 @@ func (this *CSInviteCodePlayerHandler) Process(s *netlib.Session, packetid int,
//发送邮件
var otherParams []int32
newMsg := model.NewMessage("", p.SnId, "", p.SnId, model.MSGTYPE_INVITECODE, p.Name, inviteCode, coin, 0,
model.MSGSTATE_UNREAD, time.Now().Unix(), 0, "", otherParams, p.Platform, model.HallAll)
model.MSGSTATE_UNREAD, time.Now().Unix(), 0, "", otherParams, p.Platform, model.HallAll, nil)
err = model.InsertMessage(p.Platform, newMsg)
if err == nil {
@ -1777,7 +1777,7 @@ func (this *CSVIPPrivilegeInfoHandler) Process(s *netlib.Session, packetid int,
}
switch code {
case 1: //1.VIP比赛场免费次数
pack.Value = p.GetVIPPrivilege1()
pack.Value = p.GetMatchFreeTimes()
pack.NowValue = p.VipMatchTimes
}
p.SendToClient(int(player_proto.PlayerPacketID_PACKET_SC_VIPPrivilegeInfo), pack)
@ -1854,7 +1854,7 @@ func init() {
func CSExchangeChannel(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSExchangeChannel Process recv ", data)
_, ok := data.(*player_proto.CSExchangeChannel)
msg, ok := data.(*player_proto.CSExchangeChannel)
if !ok {
return nil
}
@ -1865,15 +1865,28 @@ func CSExchangeChannel(s *netlib.Session, packetid int, data interface{}, sid in
return nil
}
var onChannelName []string
conf := PlatformMgrSingleton.GetConfig(p.Platform).ChannelSwitch[common.ChannelSwitchExchange]
if conf != nil {
onChannelName = conf.OnChannelName
pack := &player_proto.SCExchangeChannel{}
if msg.Tp == 0 {
for _, v := range PlatformMgrSingleton.GetConfig(p.Platform).ChannelSwitch {
if v == nil {
continue
}
pack.Datas = append(pack.Datas, &player_proto.ChannelSwitch{
OnChannelName: v.OnChannelName,
Tp: v.Tp,
})
}
} else {
v := PlatformMgrSingleton.GetConfig(p.Platform).ChannelSwitch[msg.GetTp()]
if v != nil {
pack.Datas = append(pack.Datas, &player_proto.ChannelSwitch{
OnChannelName: v.OnChannelName,
Tp: v.Tp,
})
}
}
pack := &player_proto.SCExchangeChannel{
OnChannelName: onChannelName,
}
p.SendToClient(int(player_proto.PlayerPacketID_PACKET_SCExchangeChannel), pack)
logger.Logger.Tracef("SCExchangeChannel %v", pack)
return nil
@ -1920,6 +1933,7 @@ func CSPlayerData(s *netlib.Session, packetid int, data interface{}, sid int64)
p.AppVersion = msg.GetAppVersion()
p.BuildVersion = msg.GetBuildVersion()
p.AppChannel = msg.GetAppChannel()
p.LastChannel = p.AppChannel
if (p.Channel == "" || p.Channel == "0") && p.Channel != msg.AppChannel {
p.Channel = msg.AppChannel
}
@ -2839,6 +2853,6 @@ func init() {
common.Register(int(player_proto.PlayerPacketID_PACKET_CSBillList), player_proto.CSBillList{}, CSBillList)
// 看广告一次
common.Register(int(player_proto.PlayerPacketID_PACKET_CSADV), player_proto.CSADV{}, CSADV)
// 开启兑换的渠道
// 渠道开关
common.Register(int(player_proto.PlayerPacketID_PACKET_CSExchangeChannel), player_proto.CSExchangeChannel{}, CSExchangeChannel)
}

View File

@ -254,7 +254,7 @@ func CSRMAward(s *netlib.Session, packetId int, data interface{}, sid int64) err
ItemId: v.Id,
ItemNum: int64(v.Num),
}
BagMgrSingleton.AddItems(p, []*Item{item}, 0, common.GainWay_RankReward, "system", "段位奖励", 0, 0, false)
BagMgrSingleton.AddItems(p, []*Item{item}, 0, common.GainWay_RankMatch, "system", "段位奖励", 0, 0, false)
}
}
}

View File

@ -1,90 +0,0 @@
package main
import (
"mongo.games.com/game/common"
"mongo.games.com/game/proto"
"mongo.games.com/game/protocol/activity"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/netlib"
)
// ------------------------------------------------
type CSSignPacketFactory struct {
}
type CSSignHandler struct {
}
func (this *CSSignPacketFactory) CreatePacket() interface{} {
pack := &activity.CSSign{}
return pack
}
func (this *CSSignHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSSignHandler Process recv ", data)
if msg, ok := data.(*activity.CSSign); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warn("CSSignHandler p == nil")
return nil
}
pack := &activity.SCSign{}
pack.SignIndex = proto.Int32(msg.GetSignIndex())
pack.SignType = proto.Int32(msg.GetSignType())
retCode := ActSignMgrSington.CanSign(p, int(msg.GetSignIndex()))
if retCode != activity.OpResultCode_ActSign_OPRC_Activity_Sign_Sucess {
pack.OpRetCode = retCode
proto.SetDefaults(pack)
p.SendToClient(int(activity.ActSignPacketID_PACKET_SCSign), pack)
return nil
}
retCode = ActSignMgrSington.Sign(p, int(msg.GetSignIndex()), msg.GetSignType())
if retCode != activity.OpResultCode_ActSign_OPRC_Activity_Sign_Sucess {
pack.OpRetCode = retCode
proto.SetDefaults(pack)
p.SendToClient(int(activity.ActSignPacketID_PACKET_SCSign), pack)
return nil
}
pack.OpRetCode = activity.OpResultCode_ActSign_OPRC_Activity_Sign_Sucess
proto.SetDefaults(pack)
p.SendToClient(int(activity.ActSignPacketID_PACKET_SCSign), pack)
}
return nil
}
// ------------------------------------------------
type CSSignDataPacketFactory struct {
}
type CSSignDataHandler struct {
}
func (this *CSSignDataPacketFactory) CreatePacket() interface{} {
pack := &activity.CSSignData{}
return pack
}
func (this *CSSignDataHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
logger.Logger.Trace("CSSignDataHandler Process recv ", data)
if _, ok := data.(*activity.CSSignData); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warn("CSSignDataHandler p == nil")
return nil
}
ActSignMgrSington.SendSignDataToPlayer(p)
}
return nil
}
func init() {
//签到
common.RegisterHandler(int(activity.ActSignPacketID_PACKET_CSSign), &CSSignHandler{})
netlib.RegisterFactory(int(activity.ActSignPacketID_PACKET_CSSign), &CSSignPacketFactory{})
//签到数据
common.RegisterHandler(int(activity.ActSignPacketID_PACKET_CSSignData), &CSSignDataHandler{})
netlib.RegisterFactory(int(activity.ActSignPacketID_PACKET_CSSignData), &CSSignDataPacketFactory{})
}

View File

@ -71,7 +71,7 @@ func IsTaskReward(p *Player, id int32) bool {
return false
}
func SendReward(p *Player, m map[int64]int64) {
func SendReward(p *Player, m map[int64]int64, tp int32) {
var items []*Item
for k, v := range m {
items = append(items, &Item{
@ -79,7 +79,20 @@ func SendReward(p *Player, m map[int64]int64) {
ItemNum: v,
})
}
BagMgrSingleton.AddItems(p, items, 0, common.GainWay_TaskReward, "system", "任务奖励", 0, 0, false)
gain := int32(0)
switch tp {
case 1:
gain = common.GainWayItemTaskEveryDay
case 2:
gain = common.GainWayItemWeekActive
case 3:
gain = common.GainWayItemTaskNewPlayer
case 4:
gain = common.GainWayItemTaskInvite
case 5:
gain = common.GainWayItemTaskAchievement
}
BagMgrSingleton.AddItems(p, items, 0, gain, "system", "任务奖励", 0, 0, false)
}
func CSTaskList(s *netlib.Session, packetId int, data interface{}, sid int64) error {
@ -142,7 +155,7 @@ func CSTaskReward(s *netlib.Session, packetId int, data interface{}, sid int64)
p.WelfData.Task[msg.GetId()].Ts = time.Now().Unix()
data := srvdata.PBDB_TaskMgr.GetData(msg.GetId())
if data != nil {
SendReward(p, data.Award)
SendReward(p, data.Award, msg.Tp)
}
ret.OpCode = taskproto.OpResultCode_OPRC_Success
}

View File

@ -454,7 +454,7 @@ func (this *CSPigBankGetInfoHandler) Process(s *netlib.Session, packetid int, da
if _, ok := data.(*welfare.CSPigbankGetInfo); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warnf("CSPigBankGetInfoHandler p == nil p.SnId = %v", p.SnId)
logger.Logger.Warnf("CSPigBankGetInfoHandler p == nil")
return nil
}
WelfareMgrSington.PigbankGetInfo(p)
@ -479,7 +479,7 @@ func (this *CSPigBankTakeCoinHandler) Process(s *netlib.Session, packetid int, d
if _, ok := data.(*welfare.CSPigbankTakeCoin); ok {
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warnf("CSPigBankTakeCoinHandler p == nil p.SnId = %v", p.SnId)
logger.Logger.Warnf("CSPigBankTakeCoinHandler p == nil")
return nil
}
WelfareMgrSington.PigbankTakeCoin(p)

View File

@ -1,14 +1,8 @@
package main
import (
"mongo.games.com/game/common"
"mongo.games.com/game/webapi"
"encoding/json"
"time"
"mongo.games.com/game/model"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/module"
)
@ -104,33 +98,6 @@ func (this *ActMgr) Init() {
if this.ConfigByPlateform == nil {
this.ConfigByPlateform = make(map[string]*ActGivePlateformConfig)
}
type ApiResult struct {
Tag int
Msg []ActGivePlateformConfig
}
//不使用etcd的情况下走api获取
if !model.GameParamData.UseEtcd {
buff, err := webapi.API_GetActConfig(common.GetAppId())
if err == nil {
ar := ApiResult{}
err = json.Unmarshal(buff, &ar)
if err == nil {
for _, plateformConfig := range ar.Msg {
t := plateformConfig
this.AddGiveConfig(&t, plateformConfig.Platform)
}
} else {
logger.Logger.Error("Unmarshal ActMgr data error:", err, " buff:", string(buff))
}
} else {
logger.Logger.Error("Init ActMgr list failed.")
}
} else {
EtcdMgrSington.InitPlatformAct()
}
}
func (this *ActMgr) Update() {

View File

@ -1,159 +0,0 @@
package main
import (
"github.com/globalsign/mgo"
"mongo.games.com/game/common"
"mongo.games.com/game/model"
"mongo.games.com/game/proto"
"mongo.games.com/game/protocol/activity"
"mongo.games.com/game/protocol/server"
"mongo.games.com/game/srvdata"
"mongo.games.com/goserver/core/logger"
"strconv"
"time"
)
var ActSignMgrSington = &ActSignMgr{
SignConfigs: make(map[int]*server.DB_ActSign),
}
type ActSignMgr struct {
SignConfigs map[int]*server.DB_ActSign
}
func (this *ActSignMgr) Init() {
if this.SignConfigs == nil {
this.SignConfigs = make(map[int]*server.DB_ActSign)
}
for _, v := range srvdata.PBDB_ActSignMgr.Datas.GetArr() {
this.SignConfigs[int(v.Id)] = v
}
}
func (this *ActSignMgr) GetConfig(id int) *server.DB_ActSign {
signConfig, ok := this.SignConfigs[id]
if ok {
return signConfig
}
return nil
}
func (this *ActSignMgr) OnPlayerLogin(player *Player) error {
return this.RefixedPlayerData(player)
}
func (this *ActSignMgr) OnDayChanged(player *Player) error {
//跨天不需要
//this.RefixedPlayerData(player)
//this.SendSignDataToPlayer(player)
return nil
}
func (this *ActSignMgr) RefixedPlayerData(player *Player) error {
if player.IsRob {
return nil
}
if player.SignData == nil {
player.SignData = &model.SignData{
SignIndex: 0,
LastSignTickets: 0,
}
}
return nil
}
func (this *ActSignMgr) SendSignDataToPlayer(player *Player) {
if player.IsRob {
return
}
pack := &activity.SCSignData{}
//已经领取第几个
pack.SignCount = proto.Int(player.SignData.SignIndex)
if player.SignData.LastSignTickets != 0 {
lastSignTime := time.Unix(player.SignData.LastSignTickets, 0)
dayDiff := int32(common.DiffDay(time.Now(), lastSignTime))
if dayDiff == 0 {
pack.TodaySign = proto.Int32(1)
} else {
pack.TodaySign = proto.Int32(0)
}
} else {
pack.TodaySign = proto.Int32(0)
}
proto.SetDefaults(pack)
player.SendToClient(int(activity.ActSignPacketID_PACKET_SCSignData), pack)
logger.Logger.Trace("SCSignData: ", pack)
}
func (this *ActSignMgr) CanSign(player *Player, signIndex int) activity.OpResultCode_ActSign {
signConfig := this.GetConfig(signIndex)
if signConfig == nil {
return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Error
}
if player.SignData.LastSignTickets != 0 {
lastSignTime := time.Unix(player.SignData.LastSignTickets, 0)
dayDiff := int32(common.DiffDay(time.Now(), lastSignTime))
if dayDiff == 0 {
if player.SignData.SignIndex == signIndex {
return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Repeat
} else {
return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Config_Day_Error
}
}
if player.SignData.SignIndex != (signIndex - 1) {
return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Config_Day_Error
}
} else {
if signIndex != 1 {
return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Config_Day_Error
}
}
return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Sucess
}
func (this *ActSignMgr) Sign(player *Player, signIndex int, signType int32) activity.OpResultCode_ActSign {
errCode := this.CanSign(player, signIndex)
if errCode != activity.OpResultCode_ActSign_OPRC_Activity_Sign_Sucess {
return errCode
}
signConfig := this.GetConfig(signIndex)
if signConfig == nil {
return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Error
}
player.SignData.LastSignTickets = time.Now().Unix()
player.SignData.SignIndex = signIndex
logger.Logger.Info("签到成功: ", signConfig)
grade := signConfig.Grade
switch signType {
case 0: //普通签到
case 1: //双倍签到
grade *= 2
}
switch signConfig.Type {
case 1: //金币
player.AddCoin(int64(grade), 0, common.GainWay_ActSign, strconv.Itoa(signIndex), time.Now().Format("2006-01-02 15:04:05"))
case 2: //钻石
player.AddDiamond(int64(grade), 0, common.GainWay_ActSign, strconv.Itoa(signIndex), time.Now().Format("2006-01-02 15:04:05"))
case 3: //道具
item := &Item{
ItemId: signConfig.Item_Id,
ItemNum: int64(grade),
}
BagMgrSingleton.AddItems(player, []*Item{item}, 0, common.GainWay_ActSign, strconv.Itoa(signIndex), time.Now().Format("2006-01-02 15:04:05"), 0, 0, false)
}
return activity.OpResultCode_ActSign_OPRC_Activity_Sign_Sucess
}
func init() {
mgo.SetStats(true)
RegisterParallelLoadFunc("14日签到", func() error {
ActSignMgrSington.Init()
return nil
})
}

View File

@ -256,9 +256,11 @@ func (this *BagMgr) AddItems(p *Player, addItems []*Item, add int64, gainWay int
// 道具日志
if !noLog {
num := v.ItemNum
logType := ItemObtain
if v.ItemNum < 0 {
logType = ItemConsume
num = -v.ItemNum
}
log := model.NewItemLogEx(model.ItemParam{
Platform: p.Platform,
@ -266,7 +268,7 @@ func (this *BagMgr) AddItems(p *Player, addItems []*Item, add int64, gainWay int
LogType: int32(logType),
ItemId: v.ItemId,
ItemName: item.Name,
Count: v.ItemNum,
Count: num,
Remark: remark,
TypeId: gainWay,
GameId: gameId,
@ -277,7 +279,7 @@ func (this *BagMgr) AddItems(p *Player, addItems []*Item, add int64, gainWay int
}
}
if v.ItemId == common.ItemIDWeekScore && v.ItemNum != 0 {
if v.ItemId == common.ItemIDWeekScore && v.ItemNum > 0 {
TaskSubjectSingleton.Touch(common.TaskTypeActivityScore, &TaskData{
SnId: p.SnId,
Num: v.ItemNum,
@ -335,9 +337,11 @@ func (this *BagMgr) AddItemsOffline(platform string, snid int32, addItems []*Ite
if itemData == nil {
continue
}
num := v.ItemNum
logType := ItemObtain
if v.ItemNum < 0 {
logType = ItemConsume
num = -v.ItemNum
}
log := model.NewItemLogEx(model.ItemParam{
Platform: findPlayer.Platform,
@ -345,7 +349,7 @@ func (this *BagMgr) AddItemsOffline(platform string, snid int32, addItems []*Ite
LogType: int32(logType),
ItemId: v.ItemId,
ItemName: itemData.Name,
Count: v.ItemNum,
Count: num,
Remark: remark,
TypeId: gainWay,
GameId: gameId,

View File

@ -16,34 +16,7 @@ const (
BlackState_Max
)
var BlackListMgrSington = &BlackListMgr{
BlackList: make(map[int32]*BlackInfo),
}
type BlackListMgr struct {
BlackList map[int32]*BlackInfo
BlackListByPlatform [BlackState_Max]map[string]map[int32]*BlackInfo
AlipayAccByPlatform [BlackState_Max]map[string]map[string]*BlackInfo
AlipayNameByPlatform [BlackState_Max]map[string]map[string]*BlackInfo
BankcardByPlatform [BlackState_Max]map[string]map[string]*BlackInfo
IpByPlatform [BlackState_Max]map[string]map[string]*BlackInfo
IpNetByPlatform [BlackState_Max]map[string][]*BlackInfo
PackageTagByPlatform [BlackState_Max]map[string]*BlackInfo
DeviceByPlatform [BlackState_Max]map[string]map[string]*BlackInfo
}
type BlackInfo struct {
Id int32
BlackType int //1.游戏2.兑换3.充值4.比赛
Alipay_account string
Alipay_name string
Bankcard string
Ip string //support like "192.0.2.0/24" or "2001:db8::/32", as defined in RFC 4632 and RFC 4291.
Platform string
PackageTag string
DeviceId string //设备ID
ipNet *net.IPNet
}
var BlackListMgrSington = NewBlackListMgr()
type BlackInfoApi struct {
Id int32
@ -62,26 +35,46 @@ type BlackInfoApi struct {
DeviceId string //设备ID
}
func (this *BlackListMgr) Init() {
if this.BlackList == nil {
this.BlackList = make(map[int32]*BlackInfo)
type BlackInfo struct {
Id int32
BlackType int //1.游戏2.兑换3.充值4.比赛
Alipay_account string
Alipay_name string
Bankcard string
Ip string //support like "192.0.2.0/24" or "2001:db8::/32", as defined in RFC 4632 and RFC 4291.
Platform string
PackageTag string
DeviceId string //设备ID
ipNet *net.IPNet
}
type BlackListMgr struct {
BlackList map[int32]*BlackInfo
BlackListByPlatform [BlackState_Max]map[string]map[int32]*BlackInfo
AlipayAccByPlatform [BlackState_Max]map[string]map[string]*BlackInfo
AlipayNameByPlatform [BlackState_Max]map[string]map[string]*BlackInfo
BankcardByPlatform [BlackState_Max]map[string]map[string]*BlackInfo
IpByPlatform [BlackState_Max]map[string]map[string]*BlackInfo
IpNetByPlatform [BlackState_Max]map[string][]*BlackInfo
PackageTagByPlatform [BlackState_Max]map[string]*BlackInfo
DeviceByPlatform [BlackState_Max]map[string]map[string]*BlackInfo
}
func NewBlackListMgr() *BlackListMgr {
ret := &BlackListMgr{
BlackList: make(map[int32]*BlackInfo),
}
for i := uint(0); i < BlackState_Max; i++ {
this.BlackListByPlatform[i] = make(map[string]map[int32]*BlackInfo)
this.AlipayAccByPlatform[i] = make(map[string]map[string]*BlackInfo)
this.AlipayNameByPlatform[i] = make(map[string]map[string]*BlackInfo)
this.BankcardByPlatform[i] = make(map[string]map[string]*BlackInfo)
this.IpByPlatform[i] = make(map[string]map[string]*BlackInfo)
this.IpNetByPlatform[i] = make(map[string][]*BlackInfo)
this.PackageTagByPlatform[i] = make(map[string]*BlackInfo)
this.DeviceByPlatform[i] = make(map[string]map[string]*BlackInfo)
ret.BlackListByPlatform[i] = make(map[string]map[int32]*BlackInfo)
ret.AlipayAccByPlatform[i] = make(map[string]map[string]*BlackInfo)
ret.AlipayNameByPlatform[i] = make(map[string]map[string]*BlackInfo)
ret.BankcardByPlatform[i] = make(map[string]map[string]*BlackInfo)
ret.IpByPlatform[i] = make(map[string]map[string]*BlackInfo)
ret.IpNetByPlatform[i] = make(map[string][]*BlackInfo)
ret.PackageTagByPlatform[i] = make(map[string]*BlackInfo)
ret.DeviceByPlatform[i] = make(map[string]map[string]*BlackInfo)
}
if !model.GameParamData.UseEtcd {
} else {
EtcdMgrSington.InitBlackList()
}
return ret
}
func (this *BlackListMgr) DivBlackInfo(blackInfo *BlackInfo) {
@ -538,8 +531,4 @@ func (this *BlackListMgr) CheckDeviceInBlackByPlatfrom(deviceId string, blackTyp
func init() {
mgo.SetStats(true)
RegisterParallelLoadFunc("平台黑名单", func() error {
BlackListMgrSington.Init()
return nil
})
}

View File

@ -1,7 +1,6 @@
package main
import (
"mongo.games.com/game/model"
webapi_proto "mongo.games.com/game/protocol/webapi"
"mongo.games.com/goserver/core/module"
"sort"
@ -23,11 +22,7 @@ func (this *ChessRankMgr) ModuleName() string {
}
func (this *ChessRankMgr) Init() {
if !model.GameParamData.UseEtcd {
// 后台说现在没有不走ETCD情况~
} else {
EtcdMgrSington.InitUpdateChessRankcfg()
}
}
func (this *ChessRankMgr) UpdateChessRankConfig(cfg *webapi_proto.ChessRankcfgData) {

View File

@ -23,10 +23,10 @@ var CoinSceneMgrSingleton = &CoinSceneMgr{
playerChanging: make(map[int32]int32),
//按平台管理
scenesOfPlatform: make(map[string]map[int32]*CoinScenePool),
platformOfScene: make(map[int32]string),
platformOfScene: make(map[int]string),
//按组管理
scenesOfGroup: make(map[int32]map[int32]*CoinScenePool),
groupOfScene: make(map[int32]int32),
groupOfScene: make(map[int]int32),
}
type CreateRoomCache struct {
@ -39,14 +39,14 @@ type CoinSceneMgr struct {
//按平台管理
scenesOfPlatform map[string]map[int32]*CoinScenePool // platform:gamefreeid
platformOfScene map[int32]string // sceneid:platform; 创建房间后记录房间所在平台
platformOfScene map[int]string // sceneid:platform; 创建房间后记录房间所在平台
//按组管理
scenesOfGroup map[int32]map[int32]*CoinScenePool // groupid:gamefreeid
groupOfScene map[int32]int32 // sceneid:groupid;
groupOfScene map[int]int32 // sceneid:groupid;
//延迟创建房间列表
delayCache []CreateRoomCache // 待预创建房间
delayCache []*CreateRoomCache // 待预创建房间
}
// GetCoinScenePool 获取一个场景池
@ -72,29 +72,33 @@ func (csm *CoinSceneMgr) GetCoinScenePool(plt string, id int32) *CoinScenePool {
}
}
var dbGameFree *server_proto.DB_GameFree
if groupId != 0 {
conf := PlatformGameGroupMgrSington.GetGameGroup(groupId)
if conf != nil {
dbGameFree = conf.GetDbGameFree()
}
}
if dbGameFree == nil {
dbGameFree = gf.GetDbGameFree()
}
if dbGameFree == nil {
if gf.GetDbGameFree() == nil {
return nil
}
// 创建了一个新的
// 应该是走不到这里,因为模块启动时所有场次都创建了房间池
return NewCoinScenePool(plt, groupId, dbGameFree)
pool := newCoinScenePool(plt, groupId, gf.GetDbGameFree())
if groupId != 0 {
v, ok := csm.scenesOfGroup[groupId]
if !ok || v == nil {
csm.scenesOfGroup[groupId] = make(map[int32]*CoinScenePool)
}
csm.scenesOfGroup[groupId][id] = pool
} else {
v, ok := csm.scenesOfPlatform[plt]
if !ok || v == nil {
csm.scenesOfPlatform[plt] = make(map[int32]*CoinScenePool)
}
csm.scenesOfPlatform[plt][id] = pool
}
return pool
}
func (csm *CoinSceneMgr) findCoinScenePool(platform string, id int32) (pools map[int32]*CoinScenePool, groupID int32,
dbGameFree *server.DB_GameFree) {
gf := PlatformMgrSingleton.GetGameFree(platform, id)
if gf == nil {
if gf == nil || gf.GetDbGameFree() == nil {
return nil, 0, nil
}
groupId := gf.GetGroupId()
@ -102,31 +106,24 @@ func (csm *CoinSceneMgr) findCoinScenePool(platform string, id int32) (pools map
var ss map[int32]*CoinScenePool
var ok bool
if groupId != 0 {
pgg := PlatformGameGroupMgrSington.GetGameGroup(groupId)
if pgg != nil {
ss, ok = csm.scenesOfGroup[groupId]
if !ok {
ss = make(map[int32]*CoinScenePool)
csm.scenesOfGroup[groupId] = ss
}
return ss, groupId, pgg.GetDbGameFree()
}
}
if ss == nil {
ss, ok = csm.scenesOfPlatform[platform]
ss, ok = csm.scenesOfGroup[groupId]
if !ok {
ss = make(map[int32]*CoinScenePool)
csm.scenesOfPlatform[platform] = ss
csm.scenesOfGroup[groupId] = ss
}
return ss, 0, gf.GetDbGameFree()
return ss, groupId, gf.GetDbGameFree()
}
return nil, 0, nil
ss, ok = csm.scenesOfPlatform[platform]
if !ok {
ss = make(map[int32]*CoinScenePool)
csm.scenesOfPlatform[platform] = ss
}
return ss, 0, gf.GetDbGameFree()
}
// PlayerEnter 玩家进入房间池
func (csm *CoinSceneMgr) PlayerEnter(p *Player, id int32, roomId int32, exclude []int32, ischangeroom bool) hall_proto.OpResultCode {
func (csm *CoinSceneMgr) PlayerEnter(p *Player, id int32, roomId int32, exclude []int32, isChangeRoom bool) hall_proto.OpResultCode {
logger.Logger.Tracef("(csm *CoinSceneMgr) PlayerEnter snid:%v id:%v roomid:%v exclude:%v", p.SnId, id, roomId, exclude)
if p.isDelete { //删档用户不让进游戏
return hall_proto.OpResultCode_OPRC_RoomHadClosed
@ -144,22 +141,9 @@ func (csm *CoinSceneMgr) PlayerEnter(p *Player, id int32, roomId int32, exclude
return hall_proto.OpResultCode_OPRC_Error
}
pools, groupID, free := csm.findCoinScenePool(platform.IdStr, id)
if pools == nil {
return hall_proto.OpResultCode_OPRC_RoomHadClosed
}
csp := csm.GetCoinScenePool(platform.IdStr, id)
csp, ok := pools[id]
if !ok || csp == nil {
csp = NewCoinScenePool(platform.IdStr, groupID, free)
if csp == nil {
logger.Logger.Warnf("(csm *CoinSceneMgr) PlayerEnter snid:%v find in id:%v exclude:%v NewCoinScenePool failed", p.SnId, id, exclude)
return hall_proto.OpResultCode_OPRC_Error
}
pools[id] = csp
}
ret := csp.PlayerEnter(p, roomId, exclude, ischangeroom)
ret := csp.PlayerEnter(p, roomId, exclude, isChangeRoom)
logger.Logger.Warnf("(csm *CoinSceneMgr) PlayerEnter snid:%v find in id:%v exclude:%v return false", p.SnId, id, exclude)
return ret
@ -244,28 +228,28 @@ func (csm *CoinSceneMgr) PlayerLeave(p *Player, reason int) bool {
// OnDestroyScene 解散房间
// sceneId 房间id
func (csm *CoinSceneMgr) OnDestroyScene(sceneId int) {
if platformName, ok := csm.platformOfScene[int32(sceneId)]; ok {
if platformName, ok := csm.platformOfScene[sceneId]; ok {
if ss, ok := csm.scenesOfPlatform[platformName]; ok {
for _, csp := range ss {
csp.OnDestroyScene(sceneId)
}
}
delete(csm.platformOfScene, int32(sceneId))
delete(csm.platformOfScene, sceneId)
}
if groupId, ok := csm.groupOfScene[int32(sceneId)]; ok {
if groupId, ok := csm.groupOfScene[sceneId]; ok {
if ss, ok := csm.scenesOfGroup[groupId]; ok {
for _, csp := range ss {
csp.OnDestroyScene(sceneId)
}
}
delete(csm.groupOfScene, int32(sceneId))
delete(csm.groupOfScene, sceneId)
}
}
// GetPlatformBySceneId 获取房间所在平台
func (csm *CoinSceneMgr) GetPlatformBySceneId(sceneId int) string {
if platformName, ok := csm.platformOfScene[int32(sceneId)]; ok {
if platformName, ok := csm.platformOfScene[sceneId]; ok {
return platformName
}
s := SceneMgrSingleton.GetScene(sceneId)
@ -417,76 +401,19 @@ func (csm *CoinSceneMgr) StartChangeCoinSceneTransact(p *Player, id int32, exclu
return hall_proto.OpResultCode_OPRC_Error
}
// ListRooms 给客户端发送场次房间列表
// id 场次id
func (csm *CoinSceneMgr) ListRooms(p *Player, id int32) bool {
//多平台支持
platform := p.GetPlatform()
if platform == nil {
return false
}
pools, groupID, free := csm.findCoinScenePool(platform.IdStr, id)
if pools == nil {
return false
}
if csp, ok := pools[id]; ok && csp != nil {
return csp.ListRoom(p)
}
csp := NewCoinScenePool(platform.IdStr, groupID, free)
if csp == nil {
return false
}
pools[id] = csp
return csp.ListRoom(p)
}
// CreateRoomByCache 创建预创建房间
// 每2秒创建一次
func (csm *CoinSceneMgr) CreateRoomByCache() {
cnt := len(csm.delayCache)
if cnt > 0 {
data := csm.delayCache[cnt-1]
csm.delayCache = csm.delayCache[:cnt-1]
pdd := PlatformMgrSingleton.GetGameFree(data.platformName, data.gameFreeId)
//对战场和捕鱼场 预创建
if pdd != nil && pdd.DbGameFree != nil {
var ss map[int32]*CoinScenePool
var ok bool
//分组模式
if pdd.GroupId != 0 {
pgg := PlatformGameGroupMgrSington.GetGameGroup(pdd.GroupId)
if pgg != nil {
ss, ok = csm.scenesOfGroup[pdd.GroupId]
if !ok {
ss = make(map[int32]*CoinScenePool)
csm.scenesOfGroup[pdd.GroupId] = ss
}
}
}
//独立模式
if ss == nil {
ss, ok = csm.scenesOfPlatform[data.platformName]
if !ok {
ss = make(map[int32]*CoinScenePool)
csm.scenesOfPlatform[data.platformName] = ss
}
}
if ss == nil {
return
}
if csp, ok := ss[pdd.DbGameFree.Id]; ok && csp != nil {
csp.PreCreateRoom()
return
}
csp := NewCoinScenePool(data.platformName, 0, pdd.DbGameFree)
if csp != nil {
ss[pdd.DbGameFree.Id] = csp
csp.PreCreateRoom()
return
}
}
// TouchCreateRoom 触发预创建房间
// 1.模块启动后触发
// 2.游戏服建立连接后触发
// 3.房间解散后触发
// 4.场次配置更新后
func (csm *CoinSceneMgr) TouchCreateRoom(platform string, gameFreeId int32) {
gf := PlatformMgrSingleton.GetGameFree(platform, gameFreeId)
if gf.Status && gf.DbGameFree.GetCreateRoomNum() > 0 {
logger.Logger.Tracef("TouchCreateRoom platform:%v gameFreeId:%v", platform, gameFreeId)
csm.delayCache = append(csm.delayCache, &CreateRoomCache{
platformName: platform,
gameFreeId: gameFreeId,
})
}
}
@ -495,42 +422,14 @@ func (csm *CoinSceneMgr) ModuleName() string {
}
func (csm *CoinSceneMgr) Init() {
// 场次池预创建
// 房间池初始化
for _, platform := range PlatformMgrSingleton.GetPlatforms() {
if platform.Isolated || platform.IdStr == "" {
arr := srvdata.PBDB_GameFreeMgr.Datas.GetArr()
for _, dbGame := range arr {
gps := PlatformMgrSingleton.GetGameFree(platform.IdStr, dbGame.GetId())
for _, v := range srvdata.PBDB_GameFreeMgr.Datas.GetArr() {
gps := PlatformMgrSingleton.GetGameFree(platform.IdStr, v.GetId())
if gps != nil {
// dbGameFree
dbGameFree := gps.DbGameFree
if gps.GroupId != 0 {
pgg := PlatformGameGroupMgrSington.GetGameGroup(gps.GroupId)
if pgg != nil {
dbGameFree = pgg.DbGameFree
}
}
// CoinScenePool
csp := NewCoinScenePool(platform.IdStr, gps.GroupId, dbGameFree)
if csp != nil {
if gps.GroupId != 0 {
if ss, exist := csm.scenesOfGroup[gps.GroupId]; exist {
ss[dbGame.GetId()] = csp
} else {
ss = make(map[int32]*CoinScenePool)
ss[dbGame.GetId()] = csp
csm.scenesOfGroup[gps.GroupId] = ss
}
} else {
if ss, exist := csm.scenesOfPlatform[platform.IdStr]; exist {
ss[dbGame.GetId()] = csp
} else {
ss = make(map[int32]*CoinScenePool)
ss[dbGame.GetId()] = csp
csm.scenesOfPlatform[platform.IdStr] = ss
}
}
}
csm.GetCoinScenePool(platform.IdStr, v.GetId())
csm.TouchCreateRoom(platform.IdStr, v.GetId())
}
}
}
@ -538,8 +437,18 @@ func (csm *CoinSceneMgr) Init() {
}
func (csm *CoinSceneMgr) Update() {
// 预创建房间
csm.CreateRoomByCache()
cnt := len(csm.delayCache)
if cnt > 0 {
data := csm.delayCache[cnt-1]
csm.delayCache = csm.delayCache[:cnt-1]
gf := PlatformMgrSingleton.GetGameFree(data.platformName, data.gameFreeId)
if gf != nil && gf.DbGameFree != nil {
csp := csm.GetCoinScenePool(data.platformName, data.gameFreeId)
if csp != nil {
csp.PreCreateRoom()
}
}
}
}
func (csm *CoinSceneMgr) Shutdown() {
@ -549,24 +458,15 @@ func (csm *CoinSceneMgr) Shutdown() {
//=====================PlatformObserver======================
func (this *CoinSceneMgr) OnPlatformCreate(p *Platform) {
if p.IdStr == DefaultPlatform {
return
}
//获取配置
gps := PlatformMgrSingleton.GetGameFrees(p.IdStr)
for _, v := range gps {
if v.Status && v.DbGameFree.GetCreateRoomNum() > 0 {
this.delayCache = append(this.delayCache, CreateRoomCache{gameFreeId: v.DbGameFree.Id, platformName: p.IdStr})
}
}
}
func (this *CoinSceneMgr) OnPlatformDestroy(p *Platform) {
if p == nil {
return
}
if csps, ok := this.scenesOfPlatform[p.IdStr]; ok {
for _, csp := range csps {
if v, ok := this.scenesOfPlatform[p.IdStr]; ok {
for _, csp := range v {
pack := &server_proto.WGGraceDestroyScene{}
for _, scene := range csp.scenes {
pack.Ids = append(pack.Ids, int32(scene.sceneId))
@ -577,12 +477,6 @@ func (this *CoinSceneMgr) OnPlatformDestroy(p *Platform) {
}
}
func (this *CoinSceneMgr) OnPlatformChangeIsolated(p *Platform, isolated bool) {
if !isolated {
this.OnPlatformDestroy(p)
}
}
func (this *CoinSceneMgr) OnPlatformChangeDisabled(p *Platform, disabled bool) {
if disabled {
this.OnPlatformDestroy(p)
@ -613,13 +507,7 @@ func (this *CoinSceneMgr) OnPlatformGameFreeUpdate(p *Platform, oldCfg, newCfg *
}
srvlib.ServerSessionMgrSington.Broadcast(int(server_proto.SSPacketID_PACKET_WG_GRACE_DESTROYSCENE),
pack, common.GetSelfAreaId(), srvlib.GameServerType)
//预创建房间配置更新
if newCfg.DbGameFree.GetCreateRoomNum() != 0 && p.IdStr != DefaultPlatform && newCfg.Status {
logger.Logger.Tracef(">>>预创建房间 platform:%v %v_%v gamefreeid:%v CreateRoomNum:%v", p.Name,
newCfg.DbGameFree.GetName(), newCfg.DbGameFree.GetTitle(), newCfg.DbGameFree.GetId(), newCfg.DbGameFree.GetCreateRoomNum())
this.delayCache = append(this.delayCache, CreateRoomCache{gameFreeId: newCfg.DbGameFree.GetId(), platformName: p.IdStr})
}
this.TouchCreateRoom(p.IdStr, newCfg.DbGameFree.Id)
}
}
@ -683,8 +571,8 @@ func (csm *CoinSceneMgr) OnGameSessionRegiste(gs *GameSession) {
//获取配置
gps := PlatformMgrSingleton.GetGameFrees(platform.IdStr)
for _, v := range gps {
if v.Status && v.DbGameFree.GetCreateRoomNum() > 0 && (wildGs || common.InSliceInt32(gs.gameIds, v.DbGameFree.GetGameId())) {
csm.delayCache = append(csm.delayCache, CreateRoomCache{gameFreeId: v.DbGameFree.Id, platformName: platform.IdStr})
if v != nil && (wildGs || common.InSliceInt32(gs.gameIds, v.DbGameFree.GetGameId())) {
csm.TouchCreateRoom(platform.IdStr, v.DbGameFree.Id)
}
}
}

View File

@ -1,35 +1,38 @@
package main
import (
"mongo.games.com/game/common"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/game/model"
"mongo.games.com/game/proto"
gamehall_proto "mongo.games.com/game/protocol/gamehall"
server_proto "mongo.games.com/game/protocol/server"
gamehallproto "mongo.games.com/game/protocol/gamehall"
serverproto "mongo.games.com/game/protocol/server"
"mongo.games.com/game/srvdata"
)
// CoinScenePool 房间池
type CoinScenePool struct {
platform string // 平台id
groupId int32 // 组id
id int32 // 场次id
dbGameFree *server_proto.DB_GameFree // 场次配置
dbGameRule *server_proto.DB_GameRule // 场次配置
scenes map[int]*Scene // 所有房间,房间id
players map[int32]struct{} // 玩家id
platform string // 平台id
groupId int32 // 组id
id int32 // 场次id
dbGameFree *serverproto.DB_GameFree // 场次配置
dbGameRule *serverproto.DB_GameRule // 场次配置
scenes map[int]*Scene // 所有房间,房间id
players map[int32]struct{} // 玩家id
// 扩展数据
extraData interface{}
// 匹配规则
// 房间池规则
policy ICoinScenePool
}
func NewCoinScenePool(platform string, groupId int32, dbGameFree *server_proto.DB_GameFree) *CoinScenePool {
func newCoinScenePool(platform string, groupId int32, dbGameFree *serverproto.DB_GameFree) *CoinScenePool {
if dbGameFree == nil {
return nil
}
if platform == "" {
platform = DefaultPlatform
}
dbGameRule := srvdata.PBDB_GameRuleMgr.GetData(dbGameFree.GetGameRule())
if dbGameRule == nil {
@ -87,20 +90,20 @@ func (csp *CoinScenePool) CanInviteRob() bool {
}
// CanEnter 检查入场条件
func (csp *CoinScenePool) CanEnter(p *Player) gamehall_proto.OpResultCode {
func (csp *CoinScenePool) CanEnter(p *Player) gamehallproto.OpResultCode {
if csp.dbGameFree == nil || p == nil {
return gamehall_proto.OpResultCode_OPRC_Error
return gamehallproto.OpResultCode_OPRC_Error
}
//检测房间状态是否开启
gps := PlatformMgrSingleton.GetGameFree(p.Platform, csp.id)
if gps == nil || !gps.Status {
return gamehall_proto.OpResultCode_OPRC_RoomHadClosed
return gamehallproto.OpResultCode_OPRC_RoomHadClosed
}
dbGameFree := csp.dbGameFree
if dbGameFree == nil {
return gamehall_proto.OpResultCode_OPRC_RoomHadClosed
return gamehallproto.OpResultCode_OPRC_RoomHadClosed
}
//检查游戏次数限制
@ -109,7 +112,7 @@ func (csp *CoinScenePool) CanEnter(p *Player) gamehall_proto.OpResultCode {
if dbGameFree.GetPlayNumLimit() != 0 &&
todayData != nil &&
todayData.GameTimes >= int64(dbGameFree.GetPlayNumLimit()) {
return gamehall_proto.OpResultCode_OPRC_RoomGameTimes
return gamehallproto.OpResultCode_OPRC_RoomGameTimes
}
}
@ -117,28 +120,44 @@ func (csp *CoinScenePool) CanEnter(p *Player) gamehall_proto.OpResultCode {
}
// CanAudienceEnter 检查观众入场条件
func (csp *CoinScenePool) CanAudienceEnter(p *Player) gamehall_proto.OpResultCode {
func (csp *CoinScenePool) CanAudienceEnter(p *Player) gamehallproto.OpResultCode {
if csp.dbGameFree == nil || p == nil {
return gamehall_proto.OpResultCode_OPRC_Error
return gamehallproto.OpResultCode_OPRC_Error
}
//检测房间状态是否开启
gps := PlatformMgrSingleton.GetGameFree(p.Platform, csp.id)
if gps == nil {
return gamehall_proto.OpResultCode_OPRC_RoomHadClosed
return gamehallproto.OpResultCode_OPRC_RoomHadClosed
}
dbGameFree := csp.dbGameFree
if dbGameFree == nil {
return gamehall_proto.OpResultCode_OPRC_RoomHadClosed
return gamehallproto.OpResultCode_OPRC_RoomHadClosed
}
return csp.policy.CanAudienceEnter(csp, p)
}
// AddScene 添加房间
func (csp *CoinScenePool) AddScene(s *Scene) {
if s == nil {
return
}
csp.scenes[s.sceneId] = s
s.csp = csp
if csp.groupId != 0 {
CoinSceneMgrSingleton.groupOfScene[s.sceneId] = csp.groupId
} else {
CoinSceneMgrSingleton.platformOfScene[s.sceneId] = csp.platform
}
}
// PlayerEnter 玩家进入房间池
func (csp *CoinScenePool) PlayerEnter(p *Player, roomId int32, exclude []int32, ischangeroom bool) gamehall_proto.OpResultCode {
if ret := csp.CanEnter(p); ret != gamehall_proto.OpResultCode_OPRC_Sucess {
// exclude 排除的房间id
// isChangeRoom 是否换房
func (csp *CoinScenePool) PlayerEnter(p *Player, roomId int32, exclude []int32, isChangeRoom bool) gamehallproto.OpResultCode {
if ret := csp.CanEnter(p); ret != gamehallproto.OpResultCode_OPRC_Sucess {
logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter find snid:%v csp.CanEnter coin:%v ret:%v id:%v", p.SnId,
p.Coin, ret, csp.dbGameFree.GetId())
return ret
@ -146,76 +165,77 @@ func (csp *CoinScenePool) PlayerEnter(p *Player, roomId int32, exclude []int32,
if p.scene != nil {
logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter[p.scene != nil] find snid:%v in scene:%v gameId:%v", p.SnId, p.scene.sceneId, p.scene.gameId)
return gamehall_proto.OpResultCode_OPRC_Error
return gamehallproto.OpResultCode_OPRC_Error
}
var scene *Scene
// 进入房间
if roomId != 0 && (p.IsRob || p.GMLevel > 0 || csp.dbGameFree.GetCreateRoomNum() != 0) {
// 指定房间id进入忽略排除exclude只有机器人和进入预创建房间才允许
if roomId != 0 && (p.IsRob || csp.dbGameFree.GetCreateRoomNum() != 0) {
if s, ok := csp.scenes[int(roomId)]; ok {
if s != nil && !s.deleting { //指定房间id进入那么忽略掉排除id
if s.IsFull() {
return gamehall_proto.OpResultCode_OPRC_RoomIsFull
return gamehallproto.OpResultCode_OPRC_RoomIsFull
}
if sp, ok := s.sp.(*ScenePolicyData); ok {
if !s.starting || sp.EnterAfterStart {
scene = s
} else {
logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter[!s.starting || sp.EnterAfterStart] snid:%v sceneid:%v starting:%v EnterAfterStart:%v", p.SnId, s.sceneId, s.starting, sp.EnterAfterStart)
return gamehall_proto.OpResultCode_OPRC_Error
return gamehallproto.OpResultCode_OPRC_Error
}
}
}
} else {
logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter(robot:%v,roomid:%v, exclude:%v, ischangeroom:%v) no found scene", p.SnId, roomId, exclude, ischangeroom)
return gamehall_proto.OpResultCode_OPRC_Error
logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter(robot:%v,roomid:%v, exclude:%v, isChangeRoom:%v) no found scene", p.SnId, roomId, exclude, isChangeRoom)
return gamehallproto.OpResultCode_OPRC_Error
}
}
if scene == nil {
var ret gamehall_proto.OpResultCode
ret, scene = csp.policy.PlayerEnter(csp, p, exclude, ischangeroom)
if ret != gamehall_proto.OpResultCode_OPRC_Sucess {
var ret gamehallproto.OpResultCode
ret, scene = csp.policy.PlayerEnter(csp, p, exclude, isChangeRoom)
if ret != gamehallproto.OpResultCode_OPRC_Sucess {
return ret
}
}
// 没有找到房间,创建新房间
if scene == nil {
scene = csp.policy.NewScene(csp, p)
if scene != nil {
csp.scenes[scene.sceneId] = scene
scene.csp = csp
csp.AddScene(scene)
} else {
logger.Logger.Errorf("Create %v scene failed.", csp.id)
}
}
if scene != nil {
if p.EnterScene(scene, ischangeroom, -1) {
if scene.PlayerEnter(p, -1, isChangeRoom) {
csp.OnPlayerEnter(p, scene)
return gamehall_proto.OpResultCode_OPRC_Sucess
return gamehallproto.OpResultCode_OPRC_Sucess
}
}
logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter snid:%v not found scene", p.SnId)
return gamehall_proto.OpResultCode_OPRC_SceneServerMaintain
return gamehallproto.OpResultCode_OPRC_SceneServerMaintain
}
// AudienceEnter 观众入场
func (csp *CoinScenePool) AudienceEnter(p *Player, roomId int32, exclude []int32, ischangeroom bool) gamehall_proto.OpResultCode {
if ret := csp.CanAudienceEnter(p); ret != gamehall_proto.OpResultCode_OPRC_Sucess {
func (csp *CoinScenePool) AudienceEnter(p *Player, roomId int32, exclude []int32, isChangeRoom bool) gamehallproto.OpResultCode {
if ret := csp.CanAudienceEnter(p); ret != gamehallproto.OpResultCode_OPRC_Sucess {
logger.Logger.Warnf("(csp *CoinScenePool) AudienceEnter find snid:%v csp.CanEnter coin:%v ret:%v id:%v", p.SnId, p.Coin, ret, csp.dbGameFree.GetId())
return ret
}
if p.scene != nil {
logger.Logger.Warnf("(csp *CoinScenePool) AudienceEnter[p.scene != nil] find snid:%v in scene:%v gameId:%v", p.SnId, p.scene.sceneId, p.scene.gameId)
return gamehall_proto.OpResultCode_OPRC_Error
return gamehallproto.OpResultCode_OPRC_Error
}
var scene *Scene
if roomId != 0 {
if s, ok := csp.scenes[int(roomId)]; ok {
if s != nil && !s.deleting /*&& s.sceneId != int(exclude)*/ {
if s != nil && !s.deleting {
scene = s
} else {
logger.Logger.Warnf("(csp *CoinScenePool) AudienceEnter[!s.starting || sp.EnterAfterStart] snid:%v sceneid:%v starting:%v EnterAfterStart:%v", p.SnId, s.sceneId, s.starting)
@ -224,29 +244,29 @@ func (csp *CoinScenePool) AudienceEnter(p *Player, roomId int32, exclude []int32
}
if scene == nil {
var ret gamehall_proto.OpResultCode
ret, scene = csp.policy.AudienceEnter(csp, p, exclude, ischangeroom)
if ret != gamehall_proto.OpResultCode_OPRC_Sucess {
var ret gamehallproto.OpResultCode
ret, scene = csp.policy.AudienceEnter(csp, p, exclude, isChangeRoom)
if ret != gamehallproto.OpResultCode_OPRC_Sucess {
return ret
}
}
if scene == nil {
return gamehall_proto.OpResultCode_OPRC_NoFindDownTiceRoom
return gamehallproto.OpResultCode_OPRC_NoFindDownTiceRoom
}
if scene != nil {
// 预创建房间检查观众数量
if scene.IsPreCreateScene() && scene.GetAudienceCnt() >= model.GameParamData.MaxAudienceNum {
return gamehall_proto.OpResultCode_OPRC_RoomIsFull
}
if scene.AudienceEnter(p, ischangeroom) {
csp.OnPlayerEnter(p, scene)
return gamehall_proto.OpResultCode_OPRC_Sucess
}
// 预创建房间检查观众数量
if scene.IsPreCreateScene() && scene.GetAudienceCnt() >= model.GameParamData.MaxAudienceNum {
return gamehallproto.OpResultCode_OPRC_RoomIsFull
}
if scene.AudienceEnter(p, isChangeRoom) {
csp.OnPlayerEnter(p, scene)
return gamehallproto.OpResultCode_OPRC_Sucess
}
logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter snid:%v not found scene", p.SnId)
return gamehall_proto.OpResultCode_OPRC_NoFindDownTiceRoom
return gamehallproto.OpResultCode_OPRC_NoFindDownTiceRoom
}
// OnPlayerEnter 玩家进入房间完成
@ -351,13 +371,16 @@ func (csp *CoinScenePool) OnPlayerLeave(s *Scene, p *Player) {
}
// OnDestroyScene 解散房间
// todo 是否需要优化
// 房间解散一定是游戏服确认的worldsrv收到游戏房间解散消息后解散房间
func (csp *CoinScenePool) OnDestroyScene(sceneId int) {
scene, ok := csp.scenes[sceneId]
if !ok {
return
}
logger.Logger.Tracef("(csp *CoinScenePool) OnDestroyScene scene:%v", sceneId)
// todo 是否需要优化
for id := range scene.players {
player := PlayerMgrSington.GetPlayerBySnId(id)
if player != nil {
@ -386,6 +409,7 @@ func (csp *CoinScenePool) OnDestroyScene(sceneId int) {
csp.policy.OnDestroyScene(csp, sceneId)
scene.csp = nil // 解除关联
delete(csp.scenes, sceneId)
CoinSceneMgrSingleton.TouchCreateRoom(csp.platform, csp.dbGameFree.Id)
}
// PreCreateRoom 预创建房间
@ -393,68 +417,79 @@ func (csp *CoinScenePool) PreCreateRoom() {
if csp.platform == DefaultPlatform {
return
}
preCreateNum := int(csp.dbGameFree.GetCreateRoomNum())
if preCreateNum == 0 || model.GameParamData.ClosePreCreateRoom {
return
}
if p := PlatformMgrSingleton.GetPlatform(csp.platform); p == nil || p.Disable {
return
}
var num int
for _, scene := range csp.scenes {
if scene.limitPlatform.IdStr == csp.platform {
num++
}
preCreateNum := int(csp.dbGameFree.GetCreateRoomNum())
if preCreateNum <= 0 || model.GameParamData.ClosePreCreateRoom {
return
}
if num < preCreateNum {
inc := preCreateNum - num
for i := 0; i < inc; i++ {
num := preCreateNum - csp.GetRoomNum(common.SceneMode_Public)
if num > 0 {
logger.Logger.Tracef("预创建房间 [inc:%v] platform:%v gameFreeId:%v", num, csp.platform, csp.dbGameFree.Id)
for i := 0; i < num; i++ {
scene := csp.policy.NewPreCreateScene(csp)
if scene != nil {
csp.scenes[scene.sceneId] = scene
scene.csp = csp
csp.AddScene(scene)
}
}
}
}
// ListRoom 房间列表
func (csp *CoinScenePool) ListRoom(p *Player) bool {
if p.scene != nil {
logger.Logger.Warnf("(csp *CoinScenePool) PlayerListRoom[p.scene != nil] find snid:%v in scene:%v gameId:%v", p.SnId, p.scene.sceneId, p.scene.gameId)
return false
func (csp *CoinScenePool) GetRoomNum(mode ...int) int {
tp := 0
if len(mode) > 0 {
tp = mode[0]
}
csp.PreCreateRoom()
if len(csp.scenes) == 0 {
return false
}
pack := &gamehall_proto.SCCoinSceneListRoom{
Id: csp.dbGameFree.Id,
LimitCoin: csp.dbGameFree.LimitCoin,
MaxCoinLimit: csp.dbGameFree.MaxCoinLimit,
BaseScore: csp.dbGameFree.BaseScore,
MaxScore: csp.dbGameFree.MaxChip,
OtherIntParams: csp.dbGameFree.OtherIntParams,
}
maxPlayerNum := 0
for sceneId, s := range csp.scenes {
data := &gamehall_proto.CoinSceneInfo{
SceneId: proto.Int(sceneId),
PlayerNum: proto.Int(len(s.players)),
var num int
for _, scene := range csp.scenes {
if tp > 0 {
if scene.IsSceneMode(tp) {
num++
}
} else {
num++
}
pack.Datas = append(pack.Datas, data)
maxPlayerNum = s.playerNum
}
pack.MaxPlayerNum = proto.Int(maxPlayerNum)
proto.SetDefaults(pack)
p.SendToClient(int(gamehall_proto.CoinSceneGamePacketID_PACKET_SC_COINSCENE_LISTROOM), pack)
return true
return num
}
// ListRoom 房间列表
//func (csp *CoinScenePool) ListRoom(p *Player) bool {
// if p.scene != nil {
// logger.Logger.Warnf("(csp *CoinScenePool) PlayerListRoom[p.scene != nil] find snid:%v in scene:%v gameId:%v", p.SnId, p.scene.sceneId, p.scene.gameId)
// return false
// }
//
// if len(csp.scenes) == 0 {
// return false
// }
//
// pack := &gamehallproto.SCCoinSceneListRoom{
// Id: csp.dbGameFree.Id,
// LimitCoin: csp.dbGameFree.LimitCoin,
// MaxCoinLimit: csp.dbGameFree.MaxCoinLimit,
// BaseScore: csp.dbGameFree.BaseScore,
// MaxScore: csp.dbGameFree.MaxChip,
// OtherIntParams: csp.dbGameFree.OtherIntParams,
// }
//
// maxPlayerNum := 0
// for sceneId, s := range csp.scenes {
// data := &gamehallproto.CoinSceneInfo{
// SceneId: proto.Int(sceneId),
// PlayerNum: proto.Int(len(s.players)),
// }
// pack.Datas = append(pack.Datas, data)
// maxPlayerNum = s.playerNum
// }
// pack.MaxPlayerNum = proto.Int(maxPlayerNum)
// proto.SetDefaults(pack)
// p.SendToClient(int(gamehallproto.CoinSceneGamePacketID_PACKET_SC_COINSCENE_LISTROOM), pack)
// return true
//}
// GetHasTruePlayerSceneCnt 有真人的房间数量
func (csp *CoinScenePool) GetHasTruePlayerSceneCnt() int {
cnt := 0

View File

@ -34,7 +34,7 @@ func (this *BaseCoinScenePool) CanEnter(pool *CoinScenePool, p *Player) gamehall
}
// 通用入场检测
if pool.dbGameFree.GetLimitCoin() != 0 && int64(pool.dbGameFree.GetLimitCoin()) > p.Coin {
if pool.dbGameFree.GetLimitCoin() != 0 && pool.dbGameFree.GetLimitCoin() > p.Coin && !p.IsRob {
return gamehall.OpResultCode_OPRC_CoinNotEnough
}
if pool.dbGameFree.GetMaxCoinLimit() != 0 && int64(pool.dbGameFree.GetMaxCoinLimit()) < p.Coin && !p.IsRob {
@ -67,6 +67,10 @@ func (this *BaseCoinScenePool) PlayerEnter(pool *CoinScenePool, p *Player, exclu
}
if !common.Config.IsDevMode {
// 私人房
if s.IsPrivateScene() {
continue
}
// 禁止真人匹配
if matchTrueManRule == MatchTrueManForbid && !p.IsRob && s.GetTruePlayerCnt() != 0 {
continue
@ -94,7 +98,7 @@ func (this *BaseCoinScenePool) PlayerEnter(pool *CoinScenePool, p *Player, exclu
}
//优先黑白名单
if scene == nil && len(scenes) != 0 {
if len(scenes) != 0 {
gameId := pool.dbGameFree.GetGameId()
if p.WBLevel < 0 { //黑名单玩家
var cntWhite int
@ -172,22 +176,13 @@ func (this *BaseCoinScenePool) PlayerEnter(pool *CoinScenePool, p *Player, exclu
if scene == nil && len(scenes) != 0 {
//1.其次游戏的配桌规则
if scene == nil {
matchFunc := GetCoinSceneMatchFunc(int(gameId))
if matchFunc != nil {
scene = matchFunc(pool, p, scenes, sameIpLimit, exclude)
return gamehall.OpResultCode_OPRC_Sucess, scene
}
matchFunc := GetCoinSceneMatchFunc(int(gameId))
if matchFunc != nil {
scene = matchFunc(pool, p, scenes, sameIpLimit, exclude)
return gamehall.OpResultCode_OPRC_Sucess, scene
}
}
}
// 随机
if scene == nil {
for _, v := range scenes {
scene = v
break
}
}
}
return gamehall.OpResultCode_OPRC_Sucess, scene
@ -219,36 +214,22 @@ func (this *BaseCoinScenePool) NewScene(pool *CoinScenePool, p *Player) *Scene {
gameId := int(pool.dbGameRule.GetGameId())
gs := GameSessMgrSington.GetMinLoadSess(gameId)
if gs == nil {
logger.Logger.Errorf("Get %v game min session failed.", gameId)
logger.Logger.Warnf("Get %v game min session failed.", gameId)
return nil
}
gameMode := pool.dbGameRule.GetGameMode()
params := common.CopySliceInt32ToInt64(pool.dbGameRule.GetParams())
var platformName string
limitPlatform := PlatformMgrSingleton.GetPlatform(pool.platform)
if limitPlatform == nil || !limitPlatform.Isolated {
limitPlatform = PlatformMgrSingleton.GetPlatform(DefaultPlatform)
platformName = DefaultPlatform
} else {
platformName = limitPlatform.IdStr
}
sceneId := SceneMgrSingleton.GenOneCoinSceneId()
scene := SceneMgrSingleton.CreateScene(0, 0, sceneId, gameId, int(gameMode), int(common.SceneMode_Public),
1, -1, params, gs, limitPlatform, pool.groupId, pool.dbGameFree, int32(pool.id))
if scene != nil {
scene.hallId = pool.id
scene.csp = pool
if pool.groupId != 0 {
CoinSceneMgrSingleton.groupOfScene[int32(sceneId)] = pool.groupId
} else {
CoinSceneMgrSingleton.platformOfScene[int32(sceneId)] = platformName
}
return scene
}
return nil
scene := SceneMgrSingleton.CreateScene(0, 0, sceneId, gameId, int(gameMode), common.SceneMode_Public,
1, -1, params, gs, limitPlatform, pool.groupId, pool.dbGameFree, pool.id)
return scene
}
func (this *BaseCoinScenePool) NewPreCreateScene(pool *CoinScenePool) *Scene {

View File

@ -6,7 +6,7 @@ import (
var coinScenePools = map[int32]ICoinScenePool{}
// RegisterCoinScenePool 注册游戏匹配规则
// RegisterCoinScenePool 注册房间池规则
func RegisterCoinScenePool(gameId int32, policy ICoinScenePool) {
coinScenePools[gameId] = policy
}
@ -15,21 +15,36 @@ func GetCoinScenePool(gameId int32) ICoinScenePool {
return coinScenePools[gameId]
}
// ICoinScenePool 定义房间池规则的接口
// 公共处理逻辑可以写在 CoinScenePool不能满足需求时再实现 ICoinScenePool
type ICoinScenePool interface {
// New 创建房间池
New() interface{}
// CanEnter 玩家是否可以进入
CanEnter(pool *CoinScenePool, p *Player) gamehall.OpResultCode
// CanAudienceEnter 观众是否可以进入
CanAudienceEnter(pool *CoinScenePool, p *Player) gamehall.OpResultCode
PlayerEnter(pool *CoinScenePool, p *Player, exclude []int32, ischangeroom bool) (ret gamehall.OpResultCode, scene *Scene)
AudienceEnter(pool *CoinScenePool, p *Player, exclude []int32, ischangeroom bool) (ret gamehall.OpResultCode, scene *Scene)
// PlayerEnter 玩家进入(匹配房间)
// exclude 排除的房间列表
// isChangeRoom 是否是换房间
PlayerEnter(pool *CoinScenePool, p *Player, exclude []int32, isChangeRoom bool) (ret gamehall.OpResultCode, scene *Scene)
// AudienceEnter 观众进入(匹配房间)
AudienceEnter(pool *CoinScenePool, p *Player, exclude []int32, isChangeRoom bool) (ret gamehall.OpResultCode, scene *Scene)
// OnPlayerEnter 玩家进入房间之后
OnPlayerEnter(pool *CoinScenePool, p *Player, scene *Scene)
// PlayerLeave 玩家离开
PlayerLeave(pool *CoinScenePool, p *Player, reason int) bool
// AudienceLeave 观众离开
AudienceLeave(pool *CoinScenePool, p *Player, reason int) bool
// OnPlayerLeave 玩家离开房间之后
OnPlayerLeave(pool *CoinScenePool, s *Scene, p *Player)
// NewScene 创建房间
NewScene(pool *CoinScenePool, p *Player) *Scene
// NewPreCreateScene 创建预创建房间
NewPreCreateScene(pool *CoinScenePool) *Scene
// OnDestroyScene 房间解散之后
OnDestroyScene(pool *CoinScenePool, sceneId int)
}

View File

@ -8,7 +8,7 @@ import (
"mongo.games.com/game/common"
"mongo.games.com/game/model"
"mongo.games.com/game/protocol/gamehall"
server_proto "mongo.games.com/game/protocol/server"
serverproto "mongo.games.com/game/protocol/server"
"mongo.games.com/game/srvdata"
)
@ -30,7 +30,7 @@ type CoinScenePoolLocal struct {
BaseCoinScenePool
}
func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, exclude []int32, ischangeroom bool) (ret gamehall.OpResultCode, scene *Scene) {
func (l *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, exclude []int32, isChangeRoom bool) (ret gamehall.OpResultCode, scene *Scene) {
// 配房规则
// 如果全局为限制则看具体的游戏是否限制,如果全局为不限制则不考虑具体的游戏。
sameIpLimit := !model.GameParamData.SameIpNoLimit
@ -42,12 +42,12 @@ func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, excl
matchTrueManRule := pool.dbGameFree.GetMatchTrueMan()
//根据携带金额取进房间底注 DB_Createroom
var dbCreateRoom *server_proto.DB_Createroom
var dbCreateRoom *serverproto.DB_Createroom
gameId := pool.dbGameFree.GetGameId()
dbCreateRoom = srvdata.CreateRoomMgrSington.GetDataByGameIdWithTakeCoin(gameId, p.Coin)
if dbCreateRoom == nil {
logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter(robot:%v, exclude:%v, ischangeroom:%v) no found scene from DB_Createroom",
p.SnId, exclude, ischangeroom)
logger.Logger.Warnf("(csp *CoinScenePool) PlayerEnter(robot:%v, exclude:%v, isChangeRoom:%v) no found scene from DB_Createroom",
p.SnId, exclude, isChangeRoom)
return gamehall.OpResultCode_OPRC_Error, nil
}
@ -58,6 +58,10 @@ func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, excl
}
if !common.Config.IsDevMode {
// 私人房
if s.IsPrivateScene() {
continue
}
// 禁止真人匹配
if matchTrueManRule == MatchTrueManForbid && !p.IsRob && s.GetTruePlayerCnt() != 0 {
continue
@ -81,7 +85,7 @@ func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, excl
}
}
//根据携带金额取可进房间
if dbCreateRoom != nil && len(dbCreateRoom.GetBetRange()) != 0 {
if len(dbCreateRoom.GetBetRange()) != 0 {
betRange := dbCreateRoom.GetBetRange()
if common.InSliceInt32(betRange, s.BaseScore) {
scenes[sceneId] = s
@ -92,7 +96,7 @@ func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, excl
}
//优先黑白名单
if scene == nil && len(scenes) != 0 {
if len(scenes) != 0 {
gameId := pool.dbGameFree.GetGameId()
if p.WBLevel < 0 { //黑名单玩家
var cntWhite int
@ -151,7 +155,7 @@ func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, excl
}
} else { //按类型匹配
//优先真人
if scene == nil && len(scenes) != 0 && matchTrueManRule == MatchTrueManPriority {
if len(scenes) != 0 && matchTrueManRule == MatchTrueManPriority {
var selScene []*Scene
for _, value := range scenes {
if value != nil {
@ -170,11 +174,9 @@ func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, excl
if scene == nil && len(scenes) != 0 {
//1.其次游戏的配桌规则
if scene == nil {
matchFunc := GetCoinSceneMatchFunc(int(gameId))
if matchFunc != nil {
scene = matchFunc(pool, p, scenes, sameIpLimit, exclude)
}
matchFunc := GetCoinSceneMatchFunc(int(gameId))
if matchFunc != nil {
scene = matchFunc(pool, p, scenes, sameIpLimit, exclude)
}
}
}
@ -183,7 +185,7 @@ func (this *CoinScenePoolLocal) PlayerEnter(pool *CoinScenePool, p *Player, excl
return gamehall.OpResultCode_OPRC_Sucess, scene
}
func (this *CoinScenePoolLocal) NewScene(pool *CoinScenePool, p *Player) *Scene {
func (l *CoinScenePoolLocal) NewScene(pool *CoinScenePool, p *Player) *Scene {
gameId := int(pool.dbGameFree.GetGameId())
gs := GameSessMgrSington.GetMinLoadSess(gameId)
if gs == nil {
@ -194,20 +196,16 @@ func (this *CoinScenePoolLocal) NewScene(pool *CoinScenePool, p *Player) *Scene
sceneId := SceneMgrSingleton.GenOneCoinSceneId()
params := pool.dbGameRule.GetParams()
var platformName string
limitPlatform := PlatformMgrSingleton.GetPlatform(pool.platform)
if limitPlatform == nil || !limitPlatform.Isolated {
limitPlatform = PlatformMgrSingleton.GetPlatform(DefaultPlatform)
platformName = DefaultPlatform
} else {
platformName = limitPlatform.IdStr
}
//根据携带金额取可创房间 DB_Createroom
baseScore := int32(0)
gameSite := 0
playerTakeCoin := p.Coin
var dbCreateRoom *server_proto.DB_Createroom
var dbCreateRoom *serverproto.DB_Createroom
arrs := srvdata.PBDB_CreateroomMgr.Datas.Arr
for i := len(arrs) - 1; i >= 0; i-- {
if arrs[i].GetGameId() == int32(gameId) {
@ -236,33 +234,23 @@ func (this *CoinScenePoolLocal) NewScene(pool *CoinScenePool, p *Player) *Scene
scene := SceneMgrSingleton.CreateLocalGameScene(p.SnId, sceneId, gameId, gameSite, common.SceneMode_Public, 1, common.CopySliceInt32ToInt64(params),
gs, limitPlatform, 0, pool.dbGameFree, baseScore, pool.groupId, pool.id)
if scene != nil {
scene.hallId = pool.id
scene.groupId = pool.groupId
CoinSceneMgrSingleton.platformOfScene[int32(sceneId)] = platformName
return scene
}
return nil
return scene
}
func (this *CoinScenePoolLocal) NewPreCreateScene(pool *CoinScenePool) *Scene {
func (l *CoinScenePoolLocal) NewPreCreateScene(pool *CoinScenePool) *Scene {
gameId := int(pool.dbGameRule.GetGameId())
gs := GameSessMgrSington.GetMinLoadSess(gameId)
if gs == nil {
logger.Logger.Errorf("Get %v game min session failed.", gameId)
logger.Logger.Warnf("Get %v game min session failed.", gameId)
return nil
}
sceneId := SceneMgrSingleton.GenOneCoinSceneId()
params := pool.dbGameRule.GetParams()
var platformName string
limitPlatform := PlatformMgrSingleton.GetPlatform(pool.platform)
if limitPlatform == nil || !limitPlatform.Isolated {
limitPlatform = PlatformMgrSingleton.GetPlatform(DefaultPlatform)
platformName = DefaultPlatform
} else {
platformName = limitPlatform.IdStr
}
var scene *Scene
@ -274,7 +262,7 @@ func (this *CoinScenePoolLocal) NewPreCreateScene(pool *CoinScenePool) *Scene {
//根据SceneType随机可创房间 DB_Createroom
baseScore := int32(0)
gameSite := 0
var dbCreateRooms []*server_proto.DB_Createroom
var dbCreateRooms []*serverproto.DB_Createroom
arrs := srvdata.PBDB_CreateroomMgr.Datas.Arr
for i := len(arrs) - 1; i >= 0; i-- {
if arrs[i].GetGameId() == int32(gameId) && arrs[i].GetGameSite() == pool.dbGameFree.GetSceneType() {
@ -303,16 +291,5 @@ func (this *CoinScenePoolLocal) NewPreCreateScene(pool *CoinScenePool) *Scene {
}
}
}
if scene != nil {
scene.hallId = pool.id
scene.csp = pool
if pool.groupId != 0 {
CoinSceneMgrSingleton.groupOfScene[int32(sceneId)] = pool.groupId
} else {
CoinSceneMgrSingleton.platformOfScene[int32(sceneId)] = platformName
}
return scene
}
return nil
return scene
}

View File

@ -112,12 +112,13 @@
"AppId": "5c56d1644966f078bfb90c71",
"IsDevMode": true
},
"etcd": {
"Url": ["127.0.0.1:2379"],
"UserName": "",
"Password": "",
"DialTimeout": 60
},
"costum": {
"etcdurl": [
"127.0.0.1:2379"
],
"etcduser": "root",
"etcdpwd": "win88",
"MgoRpcCliNet": "tcp",
"MgoRpcCliAddr": "127.0.0.1:8999",
"MgoRpcCliReconnInterV": 3,

View File

@ -2,14 +2,15 @@ package main
import (
"context"
"strconv"
"strings"
"go.etcd.io/etcd/client/v3"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/game/common"
"mongo.games.com/game/etcd"
hallproto "mongo.games.com/game/protocol/gamehall"
loginproto "mongo.games.com/game/protocol/login"
playerproto "mongo.games.com/game/protocol/player"
"mongo.games.com/game/protocol/webapi"
)
@ -17,10 +18,10 @@ import (
func init() {
// 平台配置
etcd.Register(etcd.ETCDKEY_PLATFORM_PREFIX, webapi.Platform{}, platformConfigEvent)
// 游戏场次配置
etcd.Register(etcd.ETCDKEY_GAMECONFIG_PREFIX, webapi.GameFree{}, platformConfigEvent)
// 超管平台游戏开关
etcd.Register(etcd.ETCDKEY_GAME_CONFIG_GLOBAL, webapi.GameConfigGlobal{}, platformConfigEvent)
// 游戏场次配置
etcd.Register(etcd.ETCDKEY_GAMECONFIG_PREFIX, webapi.GameFree{}, platformConfigEvent)
// 平台包数据
etcd.Register(etcd.ETCDKEY_PACKAGE_PREFIX, webapi.AppInfo{}, platformConfigEvent)
// 客户端游戏入口开关
@ -39,6 +40,30 @@ func init() {
etcd.Register(etcd.ETCDKEY_ACT_Collect, webapi.WelfareCollectConfig{}, platformConfigEvent)
// 渠道开关
etcd.Register(etcd.ETCDKEY_ChannelSwitch, webapi.ChannelSwitchConfig{}, platformConfigEvent)
// 组配置
etcd.Register(etcd.ETCDKEY_GROUPCONFIG_PREFIX, webapi.GameConfigGroup{}, platformConfigEvent)
// 黑名单配置
etcd.Register(etcd.ETCDKEY_BLACKLIST_PREFIX, BlackInfoApi{}, handlerEvent)
// 代理
etcd.Register(etcd.ETCDKEY_PROMOTER_PREFIX, PromoterConfig{}, handlerEvent)
// 赠送
etcd.Register(etcd.ETCDKEY_ACT_GIVE_PREFIX, PromoterConfig{}, handlerEvent)
// 7日签到
etcd.Register(etcd.ETCDKEY_ACT_7SIGN, webapi.Welfare7SignDateList{}, platformConfigEvent)
// 转盘
etcd.Register(etcd.ETCDKEY_ACT_TURNPLATE, webapi.WelfareTurnplateDateList{}, platformConfigEvent)
// 盲盒
etcd.Register(etcd.ETCDKEY_ACT_BLINDBOX, webapi.WelfareBlindBoxDataList{}, platformConfigEvent)
// 首充
etcd.Register(etcd.ETCDKEY_ACT_FIRSTPAY, webapi.WelfareFirstPayDataList{}, platformConfigEvent)
// 连充
etcd.Register(etcd.ETCDKEY_ACT_CONTINUOUSPAY, webapi.WelfareContinuousPayDataList{}, platformConfigEvent)
// VIP
etcd.Register(etcd.ETCDKEY_VIP_CFG, webapi.VIPcfgDataList{}, platformConfigEvent)
// 象棋段位
etcd.Register(etcd.ETCDKEY_CHESSRANK_CFG, webapi.ChessRankcfgData{}, platformConfigEvent)
// 手机积分
etcd.Register(etcd.ETCDKEY_ACT_PHONELOTTERY, webapi.WelfarePhoneLotteryStatus{}, platformConfigEvent)
}
func platformConfigEvent(ctx context.Context, completeKey string, isInit bool, event *clientv3.Event, data interface{}) {
@ -132,18 +157,104 @@ func platformConfigEvent(ctx context.Context, completeKey string, isInit bool, e
case *webapi.ChannelSwitchConfig:
PlatformMgrSingleton.GetConfig(config.Platform).ChannelSwitch[config.GetTp()] = config
if !isInit {
switch config.GetTp() {
case common.ChannelSwitchExchange:
// 通知变更
for _, v := range PlayerMgrSington.playerOfPlatform[config.Platform] {
if v != nil && v.IsOnLine() {
v.SendToClient(int(playerproto.PlayerPacketID_PACKET_SCExchangeChannel), &playerproto.SCExchangeChannel{
// 通知变更
for _, v := range PlayerMgrSington.playerOfPlatform[config.Platform] {
if v != nil && v.IsOnLine() {
v.SendToClient(int(playerproto.PlayerPacketID_PACKET_SCExchangeChannel), &playerproto.SCExchangeChannel{
Datas: []*playerproto.ChannelSwitch{{
Tp: config.Tp,
OnChannelName: config.OnChannelName,
})
}},
})
}
}
}
case *webapi.GameConfigGroup:
PlatformGameGroupMgrSington.UpsertGameGroup(config)
case *webapi.Welfare7SignDateList:
WelfareMgrSington.UpdateSign7(config)
case *webapi.WelfareTurnplateDateList:
WelfareMgrSington.UpdateTurnplate(config)
case *webapi.WelfareBlindBoxDataList:
WelfareMgrSington.UpdateBlindBox(config)
case *webapi.WelfareFirstPayDataList:
WelfareMgrSington.UpdateFirstPay(config)
case *webapi.WelfareContinuousPayDataList:
WelfareMgrSington.UpdateContinuousPay(config)
case *webapi.VIPcfgDataList:
VipMgrSington.UpdateVIPcfg(config)
case *webapi.ChessRankcfgData:
ChessRankMgrSington.UpdateChessRankConfig(config)
case *webapi.WelfarePhoneLotteryStatus:
WelfareMgrSington.UpdatePhoneLotteryStatus(config)
default:
logger.Logger.Errorf("etcd completeKey:%s, Not processed", completeKey)
}
}
func handlerEvent(ctx context.Context, completeKey string, isInit bool, event *clientv3.Event, data interface{}) {
if data == nil {
return
}
switch config := data.(type) {
case *BlackInfoApi:
if isInit {
BlackListMgrSington.InitBlackInfo(config)
} else {
switch event.Type {
case clientv3.EventTypeDelete:
dirs := strings.Split(string(event.Kv.Key), "/")
n := len(dirs)
if n > 0 {
last := dirs[n-1]
id, err := strconv.Atoi(last)
if err == nil {
if value, exist := BlackListMgrSington.BlackList[int32(id)]; exist {
BlackListMgrSington.RemoveBlackInfo(value.Id, value.Platform)
}
}
}
case clientv3.EventTypePut:
BlackListMgrSington.UpsertBlackInfo(config)
if (config.Space & int32(BlackState_Login)) != 0 {
var targetPlayer []*Player //确定用户是否在线
for _, value := range PlayerMgrSington.players {
_, ok := BlackListMgrSington.CheckPlayerInBlack(value.PlayerData, BlackState_Login)
if ok {
targetPlayer = append(targetPlayer, value)
}
}
for _, p := range targetPlayer {
if p.sid != 0 {
p.Kickout(int32(loginproto.SSDisconnectTypeCode_SSDTC_BlackList))
} else {
LoginStateMgrSington.LogoutByAccount(p.AccountId)
}
}
}
}
}
case *PromoterConfig:
if isInit {
PromoterMgrSington.AddConfig(config)
} else {
switch event.Type {
case clientv3.EventTypeDelete:
dirs := strings.Split(string(event.Kv.Key), "/")
n := len(dirs)
if n > 0 {
promoterConfig := dirs[n-1]
PromoterMgrSington.RemoveConfigByKey(promoterConfig)
}
case clientv3.EventTypePut:
PromoterMgrSington.AddConfig(config)
}
}
case *ActGivePlateformConfig:
if isInit || event.Type == clientv3.EventTypePut {
ActMgrSington.AddGiveConfig(config, config.Platform)
}
default:
logger.Logger.Errorf("etcd completeKey:%s, Not processed", completeKey)

View File

@ -1,768 +0,0 @@
package main
import (
"context"
"encoding/json"
"strconv"
"strings"
"time"
"go.etcd.io/etcd/client/v3"
"mongo.games.com/game/common"
"mongo.games.com/game/etcd"
"mongo.games.com/game/model"
"mongo.games.com/game/proto"
loginproto "mongo.games.com/game/protocol/login"
webapiproto "mongo.games.com/game/protocol/webapi"
"mongo.games.com/goserver/core/logger"
)
// EtcdMgrSington etcd数据读取
// Deprecated: use [etcd] instead
// 使用 etcd.Register 代替
// todo EtcdMgrSington 用新方法替换
var EtcdMgrSington = &EtcdMgr{
Client: &etcd.Client{},
}
type EtcdMgr struct {
*etcd.Client
}
// 加载组配置
func (this *EtcdMgr) InitGameGroup() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_GROUPCONFIG_PREFIX)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_GROUPCONFIG_PREFIX)
if err == nil {
for i := int64(0); i < res.Count; i++ {
var value webapiproto.GameConfigGroup
err = proto.Unmarshal(res.Kvs[i].Value, &value)
if err == nil {
PlatformGameGroupMgrSington.UpsertGameGroup(&value)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) panic:%v", etcd.ETCDKEY_GROUPCONFIG_PREFIX, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_GROUPCONFIG_PREFIX, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_GROUPCONFIG_PREFIX, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
case clientv3.EventTypePut:
var value webapiproto.GameConfigGroup
err := proto.Unmarshal(ev.Kv.Value, &value)
if err == nil {
PlatformGameGroupMgrSington.UpsertGameGroup(&value)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) panic:%v", etcd.ETCDKEY_GROUPCONFIG_PREFIX, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载黑名单配置
func (this *EtcdMgr) InitBlackList() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_BLACKLIST_PREFIX)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_BLACKLIST_PREFIX)
if err == nil {
for i := int64(0); i < res.Count; i++ {
var value BlackInfoApi
err = json.Unmarshal(res.Kvs[i].Value, &value)
if err == nil {
BlackListMgrSington.InitBlackInfo(&value)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) panic:%v", etcd.ETCDKEY_BLACKLIST_PREFIX, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_BLACKLIST_PREFIX, err)
}
}
return -1
}
//@test code
//go func() {
// for {
// i := int32(1)
// data := BlackInfoApi{
// Id: i,
// Snid: i,
// Creator: rand.Int31(),
// }
// buf, err := json.Marshal(data)
// if err == nil {
// key := fmt.Sprintf("%s%d", etcd.ETCDKEY_BLACKLIST_PREFIX, i)
// putResp, err := this.PutValue(key, string(buf))
// if err == nil {
// if putResp.PrevKv != nil {
// logger.Logger.Trace("@etcdtest put", string(putResp.PrevKv.Key), string(putResp.PrevKv.Value))
// }
// //delResp, err := this.DelValue(key)
// //if err == nil {
// // logger.Logger.Trace("@etcdtest del", delResp.Deleted)
// //}
// }
// }
// }
//}()
//@test code
//ETCD中现在只有公共黑名单信息
//如果删除公共黑名单信息使用ETCD删除
//如果删除个人玩家身上的黑名单信息使用API删除
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_BLACKLIST_PREFIX, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
dirs := strings.Split(string(ev.Kv.Key), "/")
n := len(dirs)
if n > 0 {
last := dirs[n-1]
id, err := strconv.Atoi(last)
if err == nil {
if value, exist := BlackListMgrSington.BlackList[int32(id)]; exist {
BlackListMgrSington.RemoveBlackInfo(value.Id, value.Platform)
}
}
}
case clientv3.EventTypePut:
var value BlackInfoApi
err := json.Unmarshal(ev.Kv.Value, &value)
if err == nil {
BlackListMgrSington.UpsertBlackInfo(&value)
if (value.Space & int32(BlackState_Login)) != 0 {
var targetPlayer []*Player //确定用户是否在线
for _, value := range PlayerMgrSington.players {
_, ok := BlackListMgrSington.CheckPlayerInBlack(value.PlayerData, BlackState_Login)
if ok {
targetPlayer = append(targetPlayer, value)
}
}
for _, p := range targetPlayer {
if p.sid != 0 {
p.Kickout(int32(loginproto.SSDisconnectTypeCode_SSDTC_BlackList))
} else {
LoginStateMgrSington.LogoutByAccount(p.AccountId)
}
}
}
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) panic:%v", etcd.ETCDKEY_BLACKLIST_PREFIX, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 初始化代理数据
func (this *EtcdMgr) InitPromoterConfig() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 初始化代理数据 拉取数据:", etcd.ETCDKEY_PROMOTER_PREFIX)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_PROMOTER_PREFIX)
if err == nil {
for i := int64(0); i < res.Count; i++ {
var promoterConfig *PromoterConfig
err = json.Unmarshal(res.Kvs[i].Value, &promoterConfig)
if err == nil {
PromoterMgrSington.AddConfig(promoterConfig)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) panic:%v", etcd.ETCDKEY_PROMOTER_PREFIX, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_PROMOTER_PREFIX, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_PROMOTER_PREFIX, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
dirs := strings.Split(string(ev.Kv.Key), "/")
n := len(dirs)
if n > 0 {
promoterConfig := dirs[n-1]
PromoterMgrSington.RemoveConfigByKey(promoterConfig)
}
/*
var promoterConfig *PromoterConfig
err := json.Unmarshal(ev.Kv.Value, &promoterConfig)
if err == nil {
PromoterMgrSington.RemoveConfigByKey(promoterConfig)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) panic:%v", etcd.ETCDKEY_PROMOTER_PREFIX, err)
}
*/
case clientv3.EventTypePut:
var promoterConfig *PromoterConfig
err := json.Unmarshal(ev.Kv.Value, &promoterConfig)
if err == nil {
PromoterMgrSington.AddConfig(promoterConfig)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) panic:%v", etcd.ETCDKEY_PROMOTER_PREFIX, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载活动give配置
func (this *EtcdMgr) InitPlatformAct() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_ACT_GIVE_PREFIX)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_ACT_GIVE_PREFIX)
if err == nil {
for i := int64(0); i < res.Count; i++ {
var vipConfig ActGivePlateformConfig
err = json.Unmarshal(res.Kvs[i].Value, &vipConfig)
if err == nil {
ActMgrSington.AddGiveConfig(&vipConfig, vipConfig.Platform)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) panic:%v", etcd.ETCDKEY_ACT_GIVE_PREFIX, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_ACT_GIVE_PREFIX, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_ACT_GIVE_PREFIX, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
case clientv3.EventTypePut:
var vipConfig ActGivePlateformConfig
err := json.Unmarshal(ev.Kv.Value, &vipConfig)
if err == nil {
ActMgrSington.AddGiveConfig(&vipConfig, vipConfig.Platform)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) panic:%v", etcd.ETCDKEY_ACT_GOLDCOME_PREFIX, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载七日签到
func (this *EtcdMgr) InitSign7() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_ACT_7SIGN)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_ACT_7SIGN)
if err == nil {
for i := int64(0); i < res.Count; i++ {
cfg := &webapiproto.Welfare7SignDateList{}
//msg := &webapi.ASSrvCtrlClose{}
err = proto.Unmarshal(res.Kvs[i].Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdateSign7(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_7SIGN, cfg.Platform, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_ACT_7SIGN, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_ACT_7SIGN, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
case clientv3.EventTypePut:
cfg := &webapiproto.Welfare7SignDateList{}
err := proto.Unmarshal(ev.Kv.Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdateSign7(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_7SIGN, cfg.Platform, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载轮盘
func (this *EtcdMgr) InitTurnplate() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_ACT_TURNPLATE)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_ACT_TURNPLATE)
if err == nil {
for i := int64(0); i < res.Count; i++ {
cfg := &webapiproto.WelfareTurnplateDateList{}
//msg := &webapi.ASSrvCtrlClose{}
err = proto.Unmarshal(res.Kvs[i].Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdateTurnplate(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_TURNPLATE, cfg.Platform, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_ACT_TURNPLATE, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_ACT_TURNPLATE, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
case clientv3.EventTypePut:
cfg := &webapiproto.WelfareTurnplateDateList{}
err := proto.Unmarshal(ev.Kv.Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdateTurnplate(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_TURNPLATE, cfg.Platform, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载盲盒
func (this *EtcdMgr) InitBlindBox() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_ACT_BLINDBOX)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_ACT_BLINDBOX)
if err == nil {
for i := int64(0); i < res.Count; i++ {
cfg := &webapiproto.WelfareBlindBoxDataList{}
//msg := &webapi.ASSrvCtrlClose{}
err = proto.Unmarshal(res.Kvs[i].Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdateBlindBox(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_BLINDBOX, cfg.Platform, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_ACT_BLINDBOX, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_ACT_BLINDBOX, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
case clientv3.EventTypePut:
cfg := &webapiproto.WelfareBlindBoxDataList{}
err := proto.Unmarshal(ev.Kv.Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdateBlindBox(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_BLINDBOX, cfg.Platform, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载首充
func (this *EtcdMgr) InitFirstPay() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_ACT_FIRSTPAY)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_ACT_FIRSTPAY)
if err == nil {
for i := int64(0); i < res.Count; i++ {
cfg := &webapiproto.WelfareFirstPayDataList{}
//msg := &webapi.ASSrvCtrlClose{}
err = proto.Unmarshal(res.Kvs[i].Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdateFirstPay(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_FIRSTPAY, cfg.Platform, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_ACT_FIRSTPAY, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_ACT_FIRSTPAY, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
case clientv3.EventTypePut:
cfg := &webapiproto.WelfareFirstPayDataList{}
err := proto.Unmarshal(ev.Kv.Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdateFirstPay(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_FIRSTPAY, cfg.Platform, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载连续充值
func (this *EtcdMgr) InitContinuousPay() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_ACT_CONTINUOUSPAY)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_ACT_CONTINUOUSPAY)
if err == nil {
for i := int64(0); i < res.Count; i++ {
cfg := &webapiproto.WelfareContinuousPayDataList{}
//msg := &webapi.ASSrvCtrlClose{}
err = proto.Unmarshal(res.Kvs[i].Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdateContinuousPay(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_CONTINUOUSPAY, cfg.Platform, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_ACT_CONTINUOUSPAY, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_ACT_CONTINUOUSPAY, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
case clientv3.EventTypePut:
cfg := &webapiproto.WelfareContinuousPayDataList{}
err := proto.Unmarshal(ev.Kv.Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdateContinuousPay(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_CONTINUOUSPAY, cfg.Platform, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载VIP
func (this *EtcdMgr) InitUpdateVIPcfg() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_VIP_CFG)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_VIP_CFG)
if err == nil {
for i := int64(0); i < res.Count; i++ {
cfg := &webapiproto.VIPcfgDataList{}
//msg := &webapi.ASSrvCtrlClose{}
err = proto.Unmarshal(res.Kvs[i].Value, cfg)
if err == nil && cfg.Platform != "" {
VipMgrSington.UpdateVIPcfg(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_VIP_CFG, cfg.Platform, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_VIP_CFG, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_VIP_CFG, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
case clientv3.EventTypePut:
cfg := &webapiproto.VIPcfgDataList{}
err := proto.Unmarshal(ev.Kv.Value, cfg)
if err == nil && cfg.Platform != "" {
VipMgrSington.UpdateVIPcfg(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_VIP_CFG, cfg.Platform, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载段位配置
func (this *EtcdMgr) InitUpdateChessRankcfg() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_CHESSRANK_CFG)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_CHESSRANK_CFG)
if err == nil {
for i := int64(0); i < res.Count; i++ {
cfg := &webapiproto.ChessRankcfgData{}
err = proto.Unmarshal(res.Kvs[i].Value, cfg)
if err == nil && cfg.Platform != "" {
ChessRankMgrSington.UpdateChessRankConfig(cfg)
logger.Logger.Tracef("ChessRankConfig %v", cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_CHESSRANK_CFG, cfg.Platform, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_CHESSRANK_CFG, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_CHESSRANK_CFG, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
case clientv3.EventTypePut:
cfg := &webapiproto.ChessRankcfgData{}
err := proto.Unmarshal(ev.Kv.Value, cfg)
if err == nil && cfg.Platform != "" {
ChessRankMgrSington.UpdateChessRankConfig(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_CHESSRANK_CFG, cfg.Platform, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载抽手机活动
func (this *EtcdMgr) InitPhoneLottery() {
initFunc := func() int64 {
if model.GameParamData.UseEtcd {
logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_ACT_PHONELOTTERY)
res, err := this.GetValueWithPrefix(etcd.ETCDKEY_ACT_PHONELOTTERY)
if err == nil {
for i := int64(0); i < res.Count; i++ {
cfg := &webapiproto.WelfarePhoneLotteryStatus{}
//msg := &webapi.ASSrvCtrlClose{}
err = proto.Unmarshal(res.Kvs[i].Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdatePhoneLotteryStatus(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_PHONELOTTERY, cfg.Platform, err)
}
}
if res.Header != nil {
return res.Header.Revision
}
} else {
logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_ACT_PHONELOTTERY, err)
}
}
return -1
}
// 监控数据变动
watchFunc := func(ctx context.Context, revision int64) {
this.GoWatch(ctx, revision, etcd.ETCDKEY_ACT_PHONELOTTERY, func(res clientv3.WatchResponse) error {
for _, ev := range res.Events {
switch ev.Type {
case clientv3.EventTypeDelete:
case clientv3.EventTypePut:
cfg := &webapiproto.WelfarePhoneLotteryStatus{}
err := proto.Unmarshal(ev.Kv.Value, cfg)
if err == nil && cfg.Platform != "" {
WelfareMgrSington.UpdatePhoneLotteryStatus(cfg)
} else {
logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_ACT_PHONELOTTERY, cfg.Platform, err)
}
}
}
return nil
})
}
this.InitAndWatch(initFunc, watchFunc)
}
// 加载 调控黑白名单
//func (this *EtcdMgr) InitWBCtrlCFG() {
// initFunc := func() int64 {
// if model.GameParamData.UseEtcd {
// logger.Logger.Info("ETCD 拉取数据:", etcd.ETCDKEY_WBCtrl_CFG)
// res, err := this.GetValueWithPrefix(etcd.ETCDKEY_WBCtrl_CFG)
// if err == nil {
// for i := int64(0); i < res.Count; i++ {
// cfg := &webapi_proto.WbCtrlCfg{}
// err = proto.Unmarshal(res.Kvs[i].Value, cfg)
// if err == nil && cfg.Platform != "" {
// WBCtrlCfgMgr.UpdateConfig(cfg)
// } else {
// logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_WBCtrl_CFG, cfg.Platform, err)
// }
// }
// if res.Header != nil {
// return res.Header.Revision
// }
// } else {
// logger.Logger.Errorf("etcd get WithPrefix(%v) panic:%v", etcd.ETCDKEY_WBCtrl_CFG, err)
// }
// }
// return -1
// }
//
// // 监控数据变动
// watchFunc := func(ctx context.Context, revision int64) {
// this.GoWatch(ctx, revision, etcd.ETCDKEY_WBCtrl_CFG, func(res clientv3.WatchResponse) error {
// for _, ev := range res.Events {
// switch ev.Type {
// case clientv3.EventTypeDelete:
// case clientv3.EventTypePut:
// cfg := &webapi_proto.WbCtrlCfg{}
// err := proto.Unmarshal(ev.Kv.Value, cfg)
// if err == nil && cfg.Platform != "" {
// WBCtrlCfgMgr.UpdateConfig(cfg)
// } else {
// logger.Logger.Errorf("etcd desc WithPrefix(%v) Platform %v panic:%v", etcd.ETCDKEY_WBCtrl_CFG, cfg.Platform, err)
// }
// }
// }
// return nil
// })
// }
//
// this.InitAndWatch(initFunc, watchFunc)
//}
func (this *EtcdMgr) Init() {
if model.GameParamData.UseEtcd {
logger.Logger.Infof("EtcdClient开始连接url:%v;etcduser:%v;etcdpwd:%v", common.CustomConfig.GetStrings("etcdurl"), common.CustomConfig.GetString("etcduser"), common.CustomConfig.GetString("etcdpwd"))
err := this.Open(common.CustomConfig.GetStrings("etcdurl"), common.CustomConfig.GetString("etcduser"), common.CustomConfig.GetString("etcdpwd"), time.Minute)
if err != nil {
logger.Logger.Tracef("EtcdMgr.Open err:%v", err)
return
}
}
}
func (this *EtcdMgr) Shutdown() {
this.Close()
}
func (this *EtcdMgr) Reset() {
this.Close()
this.Init()
this.ReInitAndWatchAll()
}

View File

@ -222,7 +222,6 @@ func (this *GameSession) AddScene(s *Scene) {
func (this *GameSession) DelScene(s *Scene) {
delete(this.scenes, s.sceneId)
//from gameserver, so don't need send msg
}
func (this *GameSession) AddPlayer(p *Player) {

Some files were not shown because too many files have changed in this diff Show More