Compare commits
No commits in common. "a6c1b37e0c389fe2d9e5b64f38f900585a5e8f31" and "eba76584ce0ac493212f15bca37eb60eb4f8511a" have entirely different histories.
a6c1b37e0c
...
eba76584ce
|
|
@ -19,6 +19,10 @@ var ActionMgrSington = &ActionMgr{
|
||||||
pool: make(map[int]ActionBase),
|
pool: make(map[int]ActionBase),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
type ActionMgr struct {
|
type ActionMgr struct {
|
||||||
pool map[int]ActionBase
|
pool map[int]ActionBase
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,13 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/howeyc/fsnotify"
|
"github.com/howeyc/fsnotify"
|
||||||
|
|
||||||
"mongo.games.com/goserver/core"
|
"mongo.games.com/goserver/core"
|
||||||
"mongo.games.com/goserver/core/basic"
|
"mongo.games.com/goserver/core/basic"
|
||||||
"mongo.games.com/goserver/core/logger"
|
"mongo.games.com/goserver/core/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var LastModifyConfig int64
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
|
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
|
||||||
var err error
|
var err error
|
||||||
|
|
@ -61,7 +62,7 @@ type loggerParamModifiedCommand struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lmc *loggerParamModifiedCommand) Done(o *basic.Object) error {
|
func (lmc *loggerParamModifiedCommand) Done(o *basic.Object) error {
|
||||||
logger.Logger.Info("reload logger.xml:", lmc.fileName)
|
logger.Logger.Info("===reload ", lmc.fileName)
|
||||||
data, err := os.ReadFile(lmc.fileName)
|
data, err := os.ReadFile(lmc.fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -69,7 +70,7 @@ func (lmc *loggerParamModifiedCommand) Done(o *basic.Object) error {
|
||||||
if len(data) != 0 {
|
if len(data) != 0 {
|
||||||
err = logger.Reload(lmc.fileName)
|
err = logger.Reload(lmc.fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Logger.Warnf("reload logger.xml %v err: %v", lmc.fileName, err)
|
logger.Logger.Warn("===reload ", lmc.fileName, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -5,48 +5,55 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/rpc"
|
"net/rpc"
|
||||||
"time"
|
|
||||||
|
|
||||||
"mongo.games.com/goserver/core"
|
"mongo.games.com/goserver/core"
|
||||||
|
"mongo.games.com/goserver/core/broker/rabbitmq"
|
||||||
"mongo.games.com/goserver/core/module"
|
"mongo.games.com/goserver/core/module"
|
||||||
|
|
||||||
_ "mongo.games.com/game"
|
_ "mongo.games.com/game"
|
||||||
|
_ "mongo.games.com/game/dbproxy/mq"
|
||||||
|
|
||||||
"mongo.games.com/game/common"
|
"mongo.games.com/game/common"
|
||||||
"mongo.games.com/game/dbproxy/svc"
|
"mongo.games.com/game/dbproxy/svc"
|
||||||
"mongo.games.com/game/etcd"
|
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/game/mq"
|
"mongo.games.com/game/mq"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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() {
|
func main() {
|
||||||
// 自定义配置文件
|
|
||||||
model.InitGameParam()
|
|
||||||
// package模块
|
|
||||||
defer core.ClosePackages()
|
defer core.ClosePackages()
|
||||||
core.LoadPackages("config.json")
|
core.LoadPackages("config.json")
|
||||||
// core hook
|
|
||||||
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
|
rpc.HandleHTTP() // 采用http协议作为rpc载体
|
||||||
etcd.Start(common.CustomConfig.GetStrings("etcdurl"), common.CustomConfig.GetString("etcduser"), common.CustomConfig.GetString("etcdpwd"), time.Minute)
|
lis, err := net.Listen(common.CustomConfig.GetString("MgoRpcCliNet"), common.CustomConfig.GetString("MgoRpcCliAddr"))
|
||||||
mq.StartConsumer(common.CustomConfig.GetString("RabbitMQURL"), common.CustomConfig.GetString("RMQExchange"), true)
|
if err != nil {
|
||||||
mq.StartPublisher(common.CustomConfig.GetString("RabbitMQURL"), common.CustomConfig.GetString("RMQExchange"), true, common.CustomConfig.GetInt("RMQPublishBacklog"))
|
log.Fatalln("fatal error: ", err)
|
||||||
// 尝试初始化玩家id
|
}
|
||||||
svc.GetOnePlayerIdFromBucket()
|
go http.Serve(lis, nil)
|
||||||
// rpc 服务
|
|
||||||
rpc.HandleHTTP() // 采用http协议作为rpc载体
|
waitor := module.Start()
|
||||||
lis, err := net.Listen(common.CustomConfig.GetString("MgoRpcCliNet"), common.CustomConfig.GetString("MgoRpcCliAddr"))
|
waitor.Wait("main()")
|
||||||
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 {
|
|
||||||
etcd.Close()
|
|
||||||
mq.StopConsumer()
|
|
||||||
mq.StopPublisher()
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
// module模块
|
|
||||||
w := module.Start()
|
|
||||||
w.Wait("main()")
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,11 @@ package mq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"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/dbproxy/svc"
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/game/mq"
|
"mongo.games.com/game/mq"
|
||||||
|
"mongo.games.com/goserver/core/broker"
|
||||||
|
"mongo.games.com/goserver/core/broker/rabbitmq"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -16,7 +14,13 @@ func init() {
|
||||||
msg := e.Message()
|
msg := e.Message()
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
mq.BackUp(e, err)
|
||||||
|
}
|
||||||
|
|
||||||
e.Ack()
|
e.Ack()
|
||||||
|
|
||||||
|
recover()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var log model.APILog
|
var log model.APILog
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,56 @@
|
||||||
|
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())
|
||||||
|
}
|
||||||
|
|
@ -2,13 +2,11 @@ package mq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"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/dbproxy/svc"
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/game/mq"
|
"mongo.games.com/game/mq"
|
||||||
|
"mongo.games.com/goserver/core/broker"
|
||||||
|
"mongo.games.com/goserver/core/broker/rabbitmq"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -16,7 +14,13 @@ func init() {
|
||||||
msg := e.Message()
|
msg := e.Message()
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
mq.BackUp(e, err)
|
||||||
|
}
|
||||||
|
|
||||||
e.Ack()
|
e.Ack()
|
||||||
|
|
||||||
|
recover()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var log model.CoinGiveLog
|
var log model.CoinGiveLog
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,11 @@ package mq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"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/dbproxy/svc"
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/game/mq"
|
"mongo.games.com/game/mq"
|
||||||
|
"mongo.games.com/goserver/core/broker"
|
||||||
|
"mongo.games.com/goserver/core/broker/rabbitmq"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -16,7 +14,13 @@ func init() {
|
||||||
msg := e.Message()
|
msg := e.Message()
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
mq.BackUp(e, err)
|
||||||
|
}
|
||||||
|
|
||||||
e.Ack()
|
e.Ack()
|
||||||
|
|
||||||
|
recover()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var log model.CoinLog
|
var log model.CoinLog
|
||||||
|
|
@ -26,7 +30,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if log.Count == 0 { //玩家冲账探针
|
if log.Count == 0 { //玩家冲账探针
|
||||||
mq.Send(model.TopicProbeCoinLogAck, log)
|
RabbitMQPublisher.Send(model.TopicProbeCoinLogAck, log)
|
||||||
} else {
|
} else {
|
||||||
c := svc.CoinLogsCollection(log.Platform)
|
c := svc.CoinLogsCollection(log.Platform)
|
||||||
if c != nil {
|
if c != nil {
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,11 @@ package mq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"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/dbproxy/svc"
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/game/mq"
|
"mongo.games.com/game/mq"
|
||||||
|
"mongo.games.com/goserver/core/broker"
|
||||||
|
"mongo.games.com/goserver/core/broker/rabbitmq"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -16,7 +14,13 @@ func init() {
|
||||||
msg := e.Message()
|
msg := e.Message()
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
mq.BackUp(e, err)
|
||||||
|
}
|
||||||
|
|
||||||
e.Ack()
|
e.Ack()
|
||||||
|
|
||||||
|
recover()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var log model.FriendRecord
|
var log model.FriendRecord
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,12 @@ package mq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"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/dbproxy/svc"
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/game/mq"
|
"mongo.games.com/game/mq"
|
||||||
|
"mongo.games.com/goserver/core/broker"
|
||||||
|
"mongo.games.com/goserver/core/broker/rabbitmq"
|
||||||
|
"mongo.games.com/goserver/core/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -17,7 +15,13 @@ func init() {
|
||||||
msg := e.Message()
|
msg := e.Message()
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
mq.BackUp(e, err)
|
||||||
|
}
|
||||||
|
|
||||||
e.Ack()
|
e.Ack()
|
||||||
|
|
||||||
|
recover()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var log model.GameDetailedLog
|
var log model.GameDetailedLog
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,11 @@ package mq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"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/dbproxy/svc"
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/game/mq"
|
"mongo.games.com/game/mq"
|
||||||
|
"mongo.games.com/goserver/core/broker"
|
||||||
|
"mongo.games.com/goserver/core/broker/rabbitmq"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -16,7 +14,13 @@ func init() {
|
||||||
msg := e.Message()
|
msg := e.Message()
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
mq.BackUp(e, err)
|
||||||
|
}
|
||||||
|
|
||||||
e.Ack()
|
e.Ack()
|
||||||
|
|
||||||
|
recover()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var log model.GamePlayerListLog
|
var log model.GamePlayerListLog
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,13 @@ func init() {
|
||||||
msg := e.Message()
|
msg := e.Message()
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
mq.BackUp(e, err)
|
||||||
|
}
|
||||||
|
|
||||||
e.Ack()
|
e.Ack()
|
||||||
|
|
||||||
|
recover()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var log model.BindInvite
|
var log model.BindInvite
|
||||||
|
|
@ -53,7 +59,7 @@ func init() {
|
||||||
InviteNumCache.Put(name, n, int64(time.Hour.Seconds()))
|
InviteNumCache.Put(name, n, int64(time.Hour.Seconds()))
|
||||||
|
|
||||||
// 更新绑定数量
|
// 更新绑定数量
|
||||||
mq.Send(model.AckBindNum, &model.BindNum{
|
RabbitMQPublisher.Send(model.AckBindNum, &model.BindNum{
|
||||||
SnId: log.InviteSnId,
|
SnId: log.InviteSnId,
|
||||||
Num: n,
|
Num: n,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,11 @@ package mq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"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/dbproxy/svc"
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/game/mq"
|
"mongo.games.com/game/mq"
|
||||||
|
"mongo.games.com/goserver/core/broker"
|
||||||
|
"mongo.games.com/goserver/core/broker/rabbitmq"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -16,7 +14,13 @@ func init() {
|
||||||
msg := e.Message()
|
msg := e.Message()
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
mq.BackUp(e, err)
|
||||||
|
}
|
||||||
|
|
||||||
e.Ack()
|
e.Ack()
|
||||||
|
|
||||||
|
recover()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var log model.ItemLog
|
var log model.ItemLog
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
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())
|
||||||
|
//}
|
||||||
|
|
@ -2,13 +2,11 @@ package mq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"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/dbproxy/svc"
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/game/mq"
|
"mongo.games.com/game/mq"
|
||||||
|
"mongo.games.com/goserver/core/broker"
|
||||||
|
"mongo.games.com/goserver/core/broker/rabbitmq"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -16,7 +14,13 @@ func init() {
|
||||||
msg := e.Message()
|
msg := e.Message()
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
mq.BackUp(e, err)
|
||||||
|
}
|
||||||
|
|
||||||
e.Ack()
|
e.Ack()
|
||||||
|
|
||||||
|
recover()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var log model.LoginLog
|
var log model.LoginLog
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,13 @@ func init() {
|
||||||
msg := e.Message()
|
msg := e.Message()
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
mq.BackUp(e, err)
|
||||||
|
}
|
||||||
|
|
||||||
e.Ack()
|
e.Ack()
|
||||||
|
|
||||||
|
recover()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var log model.OnlineLog
|
var log model.OnlineLog
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,14 @@ package mq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"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"
|
||||||
"mongo.games.com/goserver/core/basic"
|
"mongo.games.com/goserver/core/basic"
|
||||||
"mongo.games.com/goserver/core/broker"
|
"mongo.games.com/goserver/core/broker"
|
||||||
"mongo.games.com/goserver/core/broker/rabbitmq"
|
"mongo.games.com/goserver/core/broker/rabbitmq"
|
||||||
"mongo.games.com/goserver/core/logger"
|
"mongo.games.com/goserver/core/logger"
|
||||||
|
|
||||||
"mongo.games.com/game/dbproxy/svc"
|
|
||||||
"mongo.games.com/game/model"
|
|
||||||
"mongo.games.com/game/mq"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -20,7 +18,13 @@ func init() {
|
||||||
msg := e.Message()
|
msg := e.Message()
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
mq.BackUp(e, err)
|
||||||
|
}
|
||||||
|
|
||||||
e.Ack()
|
e.Ack()
|
||||||
|
|
||||||
|
recover()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var log model.PlayerRankScore
|
var log model.PlayerRankScore
|
||||||
|
|
@ -49,7 +53,13 @@ func init() {
|
||||||
msg := e.Message()
|
msg := e.Message()
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
mq.BackUp(e, err)
|
||||||
|
}
|
||||||
|
|
||||||
e.Ack()
|
e.Ack()
|
||||||
|
|
||||||
|
recover()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var log model.RankPlayerCoin
|
var log model.RankPlayerCoin
|
||||||
|
|
@ -78,7 +88,13 @@ func init() {
|
||||||
msg := e.Message()
|
msg := e.Message()
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
mq.BackUp(e, err)
|
||||||
|
}
|
||||||
|
|
||||||
e.Ack()
|
e.Ack()
|
||||||
|
|
||||||
|
recover()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var log model.PlayerLevelInfo
|
var log model.PlayerLevelInfo
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,11 @@ package mq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"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/dbproxy/svc"
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/game/mq"
|
"mongo.games.com/game/mq"
|
||||||
|
"mongo.games.com/goserver/core/broker"
|
||||||
|
"mongo.games.com/goserver/core/broker/rabbitmq"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -16,7 +14,13 @@ func init() {
|
||||||
msg := e.Message()
|
msg := e.Message()
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
mq.BackUp(e, err)
|
||||||
|
}
|
||||||
|
|
||||||
e.Ack()
|
e.Ack()
|
||||||
|
|
||||||
|
recover()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var log model.SceneCoinLog
|
var log model.SceneCoinLog
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,11 @@ package mq
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"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/dbproxy/svc"
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/game/mq"
|
"mongo.games.com/game/mq"
|
||||||
|
"mongo.games.com/goserver/core/broker"
|
||||||
|
"mongo.games.com/goserver/core/broker/rabbitmq"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -16,7 +15,13 @@ func init() {
|
||||||
msg := e.Message()
|
msg := e.Message()
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
mq.BackUp(e, err)
|
||||||
|
}
|
||||||
|
|
||||||
e.Ack()
|
e.Ack()
|
||||||
|
|
||||||
|
recover()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var log model.WelfareLog
|
var log model.WelfareLog
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -5,8 +5,11 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.etcd.io/etcd/client/v3"
|
"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/goserver/core/logger"
|
||||||
|
|
||||||
|
"mongo.games.com/game/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -229,12 +232,22 @@ func (c *Client) GoWatch(ctx context.Context, revision int64, prefix string, f f
|
||||||
logger.Logger.Warnf("etcd watch WithPrefix(%v) err:%v", prefix, resp.Err())
|
logger.Logger.Warnf("etcd watch WithPrefix(%v) err:%v", prefix, resp.Err())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if !model.GameParamData.UseEtcd {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if len(resp.Events) == 0 {
|
if len(resp.Events) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Logger.Tracef("@goWatch %v changed, header:%#v", prefix, resp.Header)
|
logger.Logger.Tracef("@goWatch %v changed, header:%#v", prefix, resp.Header)
|
||||||
f(resp)
|
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 {
|
if skip {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
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
|
||||||
|
})
|
||||||
|
}
|
||||||
122
etcd/manager.go
122
etcd/manager.go
|
|
@ -7,31 +7,21 @@ import (
|
||||||
|
|
||||||
"go.etcd.io/etcd/client/v3"
|
"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/goserver/core/logger"
|
||||||
|
|
||||||
|
"mongo.games.com/game/common"
|
||||||
"mongo.games.com/game/proto"
|
"mongo.games.com/game/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
var mgr = &Manager{Client: new(Client)}
|
||||||
ETCD Manager
|
|
||||||
*/
|
|
||||||
|
|
||||||
var (
|
type Manager struct {
|
||||||
defaultUrl = []string{"localhost:2379"}
|
*Client
|
||||||
defaultUser = ""
|
}
|
||||||
defaultPasswd = ""
|
|
||||||
defaultDialTimeout = time.Minute
|
|
||||||
)
|
|
||||||
|
|
||||||
var globalClient = new(Client)
|
// Register .
|
||||||
|
func (this *Manager) Register(key string, msgType interface{}, f func(ctx context.Context, completeKey string, isInit bool, event *clientv3.Event, data interface{})) {
|
||||||
|
|
||||||
// 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{} {
|
createFunc := func() interface{} {
|
||||||
tp := reflect.TypeOf(msgType)
|
tp := reflect.TypeOf(msgType)
|
||||||
if tp.Kind() == reflect.Ptr {
|
if tp.Kind() == reflect.Ptr {
|
||||||
|
|
@ -42,7 +32,7 @@ func Register(key string, msgType interface{}, f func(ctx context.Context, compl
|
||||||
|
|
||||||
initFunc := func() int64 {
|
initFunc := func() int64 {
|
||||||
logger.Logger.Info("ETCD 拉取数据:", key)
|
logger.Logger.Info("ETCD 拉取数据:", key)
|
||||||
res, err := globalClient.GetValueWithPrefix(key)
|
res, err := this.GetValueWithPrefix(key)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for i := int64(0); i < res.Count; i++ {
|
for i := int64(0); i < res.Count; i++ {
|
||||||
data := createFunc()
|
data := createFunc()
|
||||||
|
|
@ -73,61 +63,61 @@ func Register(key string, msgType interface{}, f func(ctx context.Context, compl
|
||||||
|
|
||||||
// 监控数据变动
|
// 监控数据变动
|
||||||
watchFunc := func(ctx context.Context, revision int64) {
|
watchFunc := func(ctx context.Context, revision int64) {
|
||||||
globalClient.GoWatch(ctx, revision, key, func(res clientv3.WatchResponse) error {
|
this.GoWatch(ctx, revision, key, func(res clientv3.WatchResponse) error {
|
||||||
obj := core.CoreObject()
|
for _, ev := range res.Events {
|
||||||
if obj != nil {
|
switch ev.Type {
|
||||||
obj.SendCommand(basic.CommandWrapper(func(*basic.Object) error {
|
case clientv3.EventTypePut:
|
||||||
for _, ev := range res.Events {
|
data := createFunc()
|
||||||
switch ev.Type {
|
v, ok := data.(proto.Message)
|
||||||
case clientv3.EventTypePut:
|
if !ok {
|
||||||
data := createFunc()
|
logger.Logger.Errorf("ETCD %v error: not proto message", string(ev.Kv.Key))
|
||||||
v, ok := data.(proto.Message)
|
continue
|
||||||
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
|
err := proto.Unmarshal(ev.Kv.Value, v)
|
||||||
}), true)
|
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
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
globalClient.AddFunc(initFunc, watchFunc)
|
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() {
|
func Reset() {
|
||||||
globalClient.Close()
|
mgr.Reset()
|
||||||
Start(defaultUrl, defaultUser, defaultPasswd, defaultDialTimeout)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Close() {
|
|
||||||
globalClient.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
func Start(url []string, user, passwd string, dialTimeout time.Duration) {
|
|
||||||
defaultUrl = url
|
|
||||||
defaultUser = user
|
|
||||||
defaultPasswd = passwd
|
|
||||||
if dialTimeout > 0 {
|
|
||||||
defaultDialTimeout = dialTimeout
|
|
||||||
}
|
|
||||||
|
|
||||||
err := globalClient.Open(defaultUrl, defaultUser, defaultPasswd, defaultDialTimeout)
|
|
||||||
if err != nil {
|
|
||||||
logger.Logger.Errorf("etcd.Open err:%v", err)
|
|
||||||
}
|
|
||||||
globalClient.ReInitAndWatchAll()
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -559,7 +559,7 @@ func init() {
|
||||||
return nil
|
return nil
|
||||||
}))
|
}))
|
||||||
|
|
||||||
//同步记牌器过期时间
|
//玩家离开
|
||||||
netlib.RegisterFactory(int(server.SSPacketID_PACKET_WG_BUYRECTIMEITEM), netlib.PacketFactoryWrapper(func() interface{} {
|
netlib.RegisterFactory(int(server.SSPacketID_PACKET_WG_BUYRECTIMEITEM), netlib.PacketFactoryWrapper(func() interface{} {
|
||||||
return &server.WGBuyRecTimeItem{}
|
return &server.WGBuyRecTimeItem{}
|
||||||
}))
|
}))
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/game/mq"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// LogChannelSingleton 日志记录器
|
// LogChannelSingleton 日志记录器
|
||||||
|
|
@ -38,11 +37,11 @@ func (c *LogChannel) WriteLog(log interface{}) {
|
||||||
if cname == "" {
|
if cname == "" {
|
||||||
cname = "_null_"
|
cname = "_null_"
|
||||||
}
|
}
|
||||||
mq.Send(cname, log)
|
RabbitMQPublisher.Send(cname, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *LogChannel) WriteMQData(data *model.RabbitMQData) {
|
func (c *LogChannel) WriteMQData(data *model.RabbitMQData) {
|
||||||
mq.Send(data.MQName, data.Data)
|
RabbitMQPublisher.Send(data.MQName, data.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package base
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mongo.games.com/game/common"
|
"mongo.games.com/game/common"
|
||||||
|
"mongo.games.com/goserver/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ServerStateMgr = &ServerStateManager{
|
var ServerStateMgr = &ServerStateManager{
|
||||||
|
|
@ -23,3 +24,10 @@ func (this *ServerStateManager) SetState(state common.GameSessState) {
|
||||||
func (this *ServerStateManager) GetState() common.GameSessState {
|
func (this *ServerStateManager) GetState() common.GameSessState {
|
||||||
return this.State
|
return this.State
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
|
||||||
|
ServerStateMgr.Init()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package base
|
||||||
import (
|
import (
|
||||||
"mongo.games.com/game/common"
|
"mongo.games.com/game/common"
|
||||||
"mongo.games.com/game/srvdata"
|
"mongo.games.com/game/srvdata"
|
||||||
|
"mongo.games.com/goserver/core"
|
||||||
"mongo.games.com/goserver/core/logger"
|
"mongo.games.com/goserver/core/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -185,3 +186,12 @@ 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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,17 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
"mongo.games.com/goserver/core"
|
"mongo.games.com/goserver/core"
|
||||||
_ "mongo.games.com/goserver/core/i18n"
|
_ "mongo.games.com/goserver/core/i18n"
|
||||||
"mongo.games.com/goserver/core/module"
|
"mongo.games.com/goserver/core/module"
|
||||||
|
|
||||||
_ "mongo.games.com/game"
|
_ "mongo.games.com/game"
|
||||||
"mongo.games.com/game/common"
|
"mongo.games.com/game/common"
|
||||||
"mongo.games.com/game/etcd"
|
_ "mongo.games.com/game/srvdata"
|
||||||
|
|
||||||
_ "mongo.games.com/game/gamesrv/action"
|
_ "mongo.games.com/game/gamesrv/action"
|
||||||
_ "mongo.games.com/game/gamesrv/base"
|
_ "mongo.games.com/game/gamesrv/base"
|
||||||
_ "mongo.games.com/game/gamesrv/transact"
|
_ "mongo.games.com/game/gamesrv/transact"
|
||||||
"mongo.games.com/game/model"
|
|
||||||
"mongo.games.com/game/mq"
|
|
||||||
_ "mongo.games.com/game/srvdata"
|
|
||||||
|
|
||||||
// game
|
// game
|
||||||
_ "mongo.games.com/game/gamesrv/chess"
|
_ "mongo.games.com/game/gamesrv/chess"
|
||||||
|
|
@ -35,28 +31,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// 自定义配置文件
|
core.RegisterConfigEncryptor(common.ConfigFE)
|
||||||
model.InitGameParam()
|
|
||||||
model.InitFishingParam()
|
|
||||||
model.InitNormalParam()
|
|
||||||
model.InitGMAC()
|
|
||||||
// package模块
|
|
||||||
defer core.ClosePackages()
|
defer core.ClosePackages()
|
||||||
core.LoadPackages("config.json")
|
core.LoadPackages("config.json")
|
||||||
// core hook
|
|
||||||
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
|
waiter := module.Start()
|
||||||
model.StartupRPClient(common.CustomConfig.GetString("MgoRpcCliNet"), common.CustomConfig.GetString("MgoRpcCliAddr"), time.Duration(common.CustomConfig.GetInt("MgoRpcCliReconnInterV"))*time.Second)
|
waiter.Wait("main()")
|
||||||
etcd.Start(common.CustomConfig.GetStrings("etcdurl"), common.CustomConfig.GetString("etcduser"), common.CustomConfig.GetString("etcdpwd"), time.Minute)
|
|
||||||
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 {
|
|
||||||
etcd.Close()
|
|
||||||
mq.StopPublisher()
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
// module模块
|
|
||||||
w := module.Start()
|
|
||||||
w.Wait("main()")
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@ package main
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"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/model"
|
||||||
"mongo.games.com/game/mq"
|
"mongo.games.com/game/mq"
|
||||||
)
|
)
|
||||||
|
|
@ -38,9 +42,33 @@ func (c *LogChannel) WriteLog(log interface{}) {
|
||||||
if cname == "" {
|
if cname == "" {
|
||||||
cname = "_null_"
|
cname = "_null_"
|
||||||
}
|
}
|
||||||
mq.Send(cname, log)
|
RabbitMQPublisher.Send(cname, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *LogChannel) WriteMQData(data *model.RabbitMQData) {
|
func (c *LogChannel) WriteMQData(data *model.RabbitMQData) {
|
||||||
mq.Send(data.MQName, data.Data)
|
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
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,27 +4,18 @@ import (
|
||||||
_ "mongo.games.com/game"
|
_ "mongo.games.com/game"
|
||||||
"mongo.games.com/game/common"
|
"mongo.games.com/game/common"
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/game/mq"
|
|
||||||
"mongo.games.com/goserver/core"
|
"mongo.games.com/goserver/core"
|
||||||
"mongo.games.com/goserver/core/module"
|
"mongo.games.com/goserver/core/module"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// 自定义配置文件
|
core.RegisterConfigEncryptor(common.ConfigFE)
|
||||||
model.InitGameParam()
|
|
||||||
// package模块
|
|
||||||
defer core.ClosePackages()
|
defer core.ClosePackages()
|
||||||
core.LoadPackages("config.json")
|
core.LoadPackages("config.json")
|
||||||
// core hook
|
|
||||||
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
|
model.InitGameParam()
|
||||||
mq.StartPublisher(common.CustomConfig.GetString("RabbitMQURL"), common.CustomConfig.GetString("RMQExchange"), true, common.CustomConfig.GetInt("RMQPublishBacklog"))
|
|
||||||
return nil
|
waiter := module.Start()
|
||||||
})
|
waiter.Wait("main()")
|
||||||
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
|
|
||||||
mq.StopPublisher()
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
// module模块
|
|
||||||
w := module.Start()
|
|
||||||
w.Wait("main()")
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,11 @@ package api
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
|
"mongo.games.com/game/common"
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/game/mq"
|
"mongo.games.com/game/mq"
|
||||||
|
"mongo.games.com/goserver/core"
|
||||||
|
"mongo.games.com/goserver/core/broker/rabbitmq"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -12,9 +15,11 @@ import (
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LogChanelBlackHole = "_null_"
|
LOGCHANEL_BLACKHOLE = "_null_"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var RabbitMQPublisher *mq.RabbitMQPublisher
|
||||||
|
|
||||||
var LogChannelSington = &LogChannel{
|
var LogChannelSington = &LogChannel{
|
||||||
cName: make(map[reflect.Type]string),
|
cName: make(map[reflect.Type]string),
|
||||||
}
|
}
|
||||||
|
|
@ -43,15 +48,36 @@ func (c *LogChannel) getLogCName(log interface{}) string {
|
||||||
func (c *LogChannel) WriteLog(log interface{}) {
|
func (c *LogChannel) WriteLog(log interface{}) {
|
||||||
cname := c.getLogCName(log)
|
cname := c.getLogCName(log)
|
||||||
if cname == "" {
|
if cname == "" {
|
||||||
cname = LogChanelBlackHole
|
cname = LOGCHANEL_BLACKHOLE
|
||||||
}
|
}
|
||||||
mq.Send(cname, log)
|
RabbitMQPublisher.Send(cname, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *LogChannel) WriteMQData(data *model.RabbitMQData) {
|
func (c *LogChannel) WriteMQData(data *model.RabbitMQData) {
|
||||||
mq.Send(data.MQName, data.Data)
|
RabbitMQPublisher.Send(data.MQName, data.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
LogChannelSington.RegisteLogCName(model.APILogCollName, &model.APILog{})
|
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
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,203 @@
|
||||||
|
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)
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
|
@ -0,0 +1,186 @@
|
||||||
|
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) // 同步主库玩家信息
|
||||||
|
//}
|
||||||
|
|
@ -1,37 +1,39 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
_ "mongo.games.com/game"
|
||||||
|
_ "mongo.games.com/game/mgrsrv/api"
|
||||||
|
_ "mongo.games.com/game/srvdata"
|
||||||
"time"
|
"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/mgrsrv/api"
|
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/game/mq"
|
"mongo.games.com/game/srvdata"
|
||||||
_ "mongo.games.com/game/srvdata"
|
"mongo.games.com/goserver/core"
|
||||||
|
"mongo.games.com/goserver/core/logger"
|
||||||
|
"mongo.games.com/goserver/core/module"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// 自定义配置文件
|
core.RegisterConfigEncryptor(common.ConfigFE)
|
||||||
model.InitGameParam()
|
|
||||||
// package模块
|
|
||||||
defer core.ClosePackages()
|
defer core.ClosePackages()
|
||||||
core.LoadPackages("config.json")
|
core.LoadPackages("config.json")
|
||||||
// core hook
|
|
||||||
|
model.InitGameParam()
|
||||||
|
logger.Logger.Warnf("log data %v", srvdata.Config.RootPath)
|
||||||
|
waiter := module.Start()
|
||||||
|
waiter.Wait("main()")
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
//首先加载游戏配置
|
||||||
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
|
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.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
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
|
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
|
||||||
mq.StopPublisher()
|
|
||||||
model.ShutdownRPClient()
|
model.ShutdownRPClient()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
// module模块
|
|
||||||
w := module.Start()
|
|
||||||
w.Wait("main()")
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
185
mq/consumer.go
185
mq/consumer.go
|
|
@ -18,11 +18,8 @@ import (
|
||||||
为了使用方便,这里统一启动订阅
|
为了使用方便,这里统一启动订阅
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var (
|
var subscriberLock sync.RWMutex
|
||||||
globalConsumer *RabbitMQConsumer
|
var subscriber = make(map[string][]*Subscriber)
|
||||||
subscriberLock sync.RWMutex
|
|
||||||
subscriber = make(map[string][]*Subscriber)
|
|
||||||
)
|
|
||||||
|
|
||||||
type Subscriber struct {
|
type Subscriber struct {
|
||||||
broker.Subscriber
|
broker.Subscriber
|
||||||
|
|
@ -30,90 +27,6 @@ type Subscriber struct {
|
||||||
opts []broker.SubscribeOption
|
opts []broker.SubscribeOption
|
||||||
}
|
}
|
||||||
|
|
||||||
type RabbitMQConsumer struct {
|
|
||||||
broker.Broker
|
|
||||||
url string
|
|
||||||
exchange rabbitmq.Exchange
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewRabbitMQConsumer(url string, exchange rabbitmq.Exchange) *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())
|
|
||||||
}
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
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(%s,%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 {
|
|
||||||
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(%s,%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 注册订阅处理方法
|
// RegisterSubscriber 注册订阅处理方法
|
||||||
// 不同订阅是在各自的协程中执行的
|
// 不同订阅是在各自的协程中执行的
|
||||||
func RegisterSubscriber(topic string, h broker.Handler, opts ...broker.SubscribeOption) {
|
func RegisterSubscriber(topic string, h broker.Handler, opts ...broker.SubscribeOption) {
|
||||||
|
|
@ -126,6 +39,21 @@ func RegisterSubscriber(topic string, h broker.Handler, opts ...broker.Subscribe
|
||||||
subscriberLock.Unlock()
|
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
|
||||||
|
}
|
||||||
|
|
||||||
func GetSubscribers() map[string][]*Subscriber {
|
func GetSubscribers() map[string][]*Subscriber {
|
||||||
ret := make(map[string][]*Subscriber)
|
ret := make(map[string][]*Subscriber)
|
||||||
subscriberLock.RLock()
|
subscriberLock.RLock()
|
||||||
|
|
@ -138,18 +66,75 @@ func GetSubscribers() map[string][]*Subscriber {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartConsumer 启动消费者
|
type RabbitMQConsumer struct {
|
||||||
func StartConsumer(url string, exchange string, durableExchange bool) {
|
broker.Broker
|
||||||
StopConsumer()
|
url string
|
||||||
globalConsumer = NewRabbitMQConsumer(url, rabbitmq.Exchange{Name: exchange, Durable: durableExchange})
|
exchange rabbitmq.Exchange
|
||||||
if err := globalConsumer.Start(); err != nil {
|
|
||||||
panic(fmt.Sprintf("RabbitMQConsumer.Start() err:%v", err))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// StopConsumer 停止消费者
|
func NewRabbitMQConsumer(url string, exchange rabbitmq.Exchange) *RabbitMQConsumer {
|
||||||
func StopConsumer() {
|
mq := &RabbitMQConsumer{
|
||||||
if globalConsumer != nil {
|
url: url,
|
||||||
globalConsumer.Stop()
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
226
mq/publisher.go
226
mq/publisher.go
|
|
@ -9,11 +9,10 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"mongo.games.com/game/common"
|
||||||
"mongo.games.com/goserver/core/broker"
|
"mongo.games.com/goserver/core/broker"
|
||||||
"mongo.games.com/goserver/core/broker/rabbitmq"
|
"mongo.games.com/goserver/core/broker/rabbitmq"
|
||||||
"mongo.games.com/goserver/core/logger"
|
"mongo.games.com/goserver/core/logger"
|
||||||
|
|
||||||
"mongo.games.com/game/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -21,14 +20,11 @@ import (
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const (
|
const (
|
||||||
BackupPath = "backup"
|
BACKUP_PATH = "backup"
|
||||||
TimeFormat = "20060102150405"
|
TIME_FORMAT = "20060102150405"
|
||||||
FilePathFormat = "%s/%s_%s_%09d_%04d.dat"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrClosed = errors.New("publisher is closed")
|
var ERR_CLOSED = errors.New("publisher is closed")
|
||||||
|
|
||||||
var globalPublisher *RabbitMQPublisher
|
|
||||||
|
|
||||||
type item struct {
|
type item struct {
|
||||||
topic string
|
topic string
|
||||||
|
|
@ -36,71 +32,115 @@ type item struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type RabbitMQPublisher struct {
|
type RabbitMQPublisher struct {
|
||||||
broker.Broker
|
b broker.Broker
|
||||||
exchange rabbitmq.Exchange
|
exchange rabbitmq.Exchange
|
||||||
url string
|
url string
|
||||||
que chan *item
|
que chan *item
|
||||||
closed chan struct{}
|
closed bool
|
||||||
wg sync.WaitGroup
|
waitor sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRabbitMQPublisher(url string, exchange rabbitmq.Exchange, queueSize int) *RabbitMQPublisher {
|
func NewRabbitMQPublisher(url string, exchange rabbitmq.Exchange, backlog int) *RabbitMQPublisher {
|
||||||
if queueSize <= 0 {
|
if backlog <= 0 {
|
||||||
queueSize = 1
|
backlog = 1
|
||||||
}
|
}
|
||||||
mq := &RabbitMQPublisher{
|
mq := &RabbitMQPublisher{
|
||||||
url: url,
|
url: url,
|
||||||
exchange: exchange,
|
exchange: exchange,
|
||||||
que: make(chan *item, queueSize),
|
que: make(chan *item, backlog),
|
||||||
closed: make(chan struct{}),
|
|
||||||
}
|
}
|
||||||
options := []broker.Option{
|
|
||||||
broker.Addrs(url), rabbitmq.ExchangeName(exchange.Name),
|
rabbitmq.DefaultRabbitURL = mq.url
|
||||||
}
|
rabbitmq.DefaultExchange = mq.exchange
|
||||||
if exchange.Durable {
|
|
||||||
options = append(options, rabbitmq.DurableExchange())
|
mq.b = rabbitmq.NewBroker()
|
||||||
}
|
mq.b.Init()
|
||||||
mq.Broker = rabbitmq.NewBroker(options...)
|
|
||||||
mq.Broker.Init()
|
|
||||||
return mq
|
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{}) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
e := recover()
|
if err != nil {
|
||||||
if e != nil {
|
|
||||||
logger.Logger.Errorf("RabbitMQPublisher.public(%s,%v) recover:%v", topic, msg, e)
|
|
||||||
}
|
|
||||||
if err != nil || e != nil {
|
|
||||||
p.backup(topic, msg, err)
|
p.backup(topic, msg, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
recover()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var buf []byte
|
buf, err := json.Marshal(msg)
|
||||||
switch d := msg.(type) {
|
if err != nil {
|
||||||
case []byte:
|
return err
|
||||||
buf = d
|
|
||||||
case string:
|
|
||||||
buf = []byte(d)
|
|
||||||
default:
|
|
||||||
buf, err = json.Marshal(msg)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = p.Publish(topic, &broker.Message{Body: buf})
|
err = p.b.Publish(topic, &broker.Message{Body: buf})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Logger.Error("RabbitMQPublisher.publish(%s,%v) err:%v", topic, msg, err)
|
logger.Logger.Error("RabbitMQPublisher.publish err:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *RabbitMQPublisher) publishRoutine() {
|
func (p *RabbitMQPublisher) workerRoutine() {
|
||||||
p.wg.Add(1)
|
p.waitor.Add(1)
|
||||||
defer p.wg.Done()
|
defer p.waitor.Done()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|
@ -110,81 +150,20 @@ func (p *RabbitMQPublisher) publishRoutine() {
|
||||||
} else {
|
} else {
|
||||||
return
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err = p.Connect()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
go p.publishRoutine()
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *RabbitMQPublisher) Stop() error {
|
|
||||||
select {
|
|
||||||
case <-p.closed:
|
|
||||||
return ErrClosed
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
close(p.closed)
|
|
||||||
close(p.que)
|
|
||||||
for item := range p.que {
|
|
||||||
p.publish(item.topic, item.msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
//等待所有投递出去的任务全部完成
|
|
||||||
p.wg.Wait()
|
|
||||||
|
|
||||||
return p.Disconnect()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send 发布消息,异步
|
|
||||||
func (p *RabbitMQPublisher) Send(topic string, msg interface{}) (err error) {
|
|
||||||
select {
|
|
||||||
case <-p.closed:
|
|
||||||
return ErrClosed
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
i := &item{topic: topic, msg: msg}
|
|
||||||
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) {
|
func (p *RabbitMQPublisher) backup(topic string, msg interface{}, err error) {
|
||||||
buf, er := json.Marshal(msg)
|
buf, err := json.Marshal(msg)
|
||||||
if er != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tNow := time.Now()
|
tNow := time.Now()
|
||||||
filePath := fmt.Sprintf(FilePathFormat, BackupPath, topic, tNow.Format(TimeFormat), tNow.Nanosecond(), rand.Int31n(10000))
|
filePath := fmt.Sprintf("%s/%s_%s_%09d_%04d.dat", BACKUP_PATH, topic, tNow.Format(TIME_FORMAT), tNow.Nanosecond(), rand.Int31n(10000))
|
||||||
f, er := os.Create(filePath)
|
f, err := os.Create(filePath)
|
||||||
if er != nil {
|
if err != nil {
|
||||||
logger.Logger.Errorf("RabbitMQPublisher.public(%s,%v) err:%v", topic, msg, er)
|
logger.Logger.Errorf("RabbitMQPublisher.public(%s,%v) err:%v", topic, msg, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
@ -195,26 +174,3 @@ func (p *RabbitMQPublisher) backup(topic string, msg interface{}, err error) {
|
||||||
f.WriteString("reason:" + reason + "\n")
|
f.WriteString("reason:" + reason + "\n")
|
||||||
f.WriteString("data:" + string(buf) + "\n")
|
f.WriteString("data:" + string(buf) + "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartPublisher 启动发布者
|
|
||||||
func StartPublisher(url string, exchange string, durableExchange bool, queueSize int) {
|
|
||||||
StopPublisher()
|
|
||||||
globalPublisher = NewRabbitMQPublisher(url, rabbitmq.Exchange{Name: exchange, Durable: durableExchange}, queueSize)
|
|
||||||
if err := globalPublisher.Start(); err != nil {
|
|
||||||
panic(fmt.Sprintf("RabbitMQPublisher.Start() err:%v", err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// StopPublisher 停止发布者
|
|
||||||
func StopPublisher() {
|
|
||||||
if globalPublisher != nil {
|
|
||||||
globalPublisher.Stop()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func Send(topic string, msg interface{}) (err error) {
|
|
||||||
if globalPublisher != nil {
|
|
||||||
return globalPublisher.Send(topic, msg)
|
|
||||||
}
|
|
||||||
return ErrClosed
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ func Register(mainId int, msgType interface{}, h func(s *netlib.Session, g *rank
|
||||||
return reflect.New(tp).Interface()
|
return reflect.New(tp).Interface()
|
||||||
}
|
}
|
||||||
|
|
||||||
common.Register(mainId, rankproto.GateTransmit{}, func(s *netlib.Session, packetId int, data interface{}, sid int64) error {
|
common.RegisterHandler(mainId, common.HandlerWrapper(func(s *netlib.Session, packetId int, data interface{}, sid int64) error {
|
||||||
d, ok := data.(*rankproto.GateTransmit)
|
d, ok := data.(*rankproto.GateTransmit)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -36,5 +36,9 @@ func Register(mainId int, msgType interface{}, h func(s *netlib.Session, g *rank
|
||||||
}
|
}
|
||||||
|
|
||||||
return h(s, d, packetId, msg, sid)
|
return h(s, d, packetId, msg, sid)
|
||||||
})
|
}))
|
||||||
|
|
||||||
|
netlib.RegisterFactory(mainId, netlib.PacketFactoryWrapper(func() interface{} {
|
||||||
|
return &rankproto.GateTransmit{}
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -1,38 +1,21 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"mongo.games.com/game/model"
|
||||||
|
|
||||||
"mongo.games.com/goserver/core"
|
"mongo.games.com/goserver/core"
|
||||||
"mongo.games.com/goserver/core/module"
|
"mongo.games.com/goserver/core/module"
|
||||||
|
|
||||||
_ "mongo.games.com/game"
|
_ "mongo.games.com/game"
|
||||||
"mongo.games.com/game/common"
|
"mongo.games.com/game/common"
|
||||||
"mongo.games.com/game/etcd"
|
|
||||||
"mongo.games.com/game/model"
|
|
||||||
"mongo.games.com/game/mq"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// 自定义配置文件
|
core.RegisterConfigEncryptor(common.ConfigFE)
|
||||||
model.InitGameParam()
|
|
||||||
// package模块
|
|
||||||
core.LoadPackages("config.json")
|
core.LoadPackages("config.json")
|
||||||
defer core.ClosePackages()
|
defer core.ClosePackages()
|
||||||
// core hook
|
|
||||||
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
|
model.InitGameParam()
|
||||||
model.StartupRPClient(common.CustomConfig.GetString("MgoRpcCliNet"), common.CustomConfig.GetString("MgoRpcCliAddr"), time.Duration(common.CustomConfig.GetInt("MgoRpcCliReconnInterV"))*time.Second)
|
|
||||||
etcd.Start(common.CustomConfig.GetStrings("etcdurl"), common.CustomConfig.GetString("etcduser"), common.CustomConfig.GetString("etcdpwd"), time.Minute)
|
waitor := module.Start()
|
||||||
mq.StartConsumer(common.CustomConfig.GetString("RabbitMQURL"), common.CustomConfig.GetString("RMQExchange"), true)
|
waitor.Wait("ranksrv")
|
||||||
return nil
|
|
||||||
})
|
|
||||||
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
|
|
||||||
etcd.Close()
|
|
||||||
mq.StopConsumer()
|
|
||||||
model.ShutdownRPClient()
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
// module模块
|
|
||||||
w := module.Start()
|
|
||||||
w.Wait("ranksrv")
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,11 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/globalsign/mgo/bson"
|
"github.com/globalsign/mgo/bson"
|
||||||
|
"mongo.games.com/goserver/core"
|
||||||
"mongo.games.com/goserver/core/logger"
|
"mongo.games.com/goserver/core/logger"
|
||||||
|
|
||||||
|
"mongo.games.com/game/common"
|
||||||
|
"mongo.games.com/game/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AccountData struct {
|
type AccountData struct {
|
||||||
|
|
@ -23,8 +27,19 @@ var (
|
||||||
)
|
)
|
||||||
var accountFileName = "robotaccount.json"
|
var accountFileName = "robotaccount.json"
|
||||||
|
|
||||||
// InitAccountData 初始化机器人账号
|
func init() {
|
||||||
func InitAccountData() {
|
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() {
|
||||||
dirty := false
|
dirty := false
|
||||||
newFunc := func(n int) {
|
newFunc := func(n int) {
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,11 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
"mongo.games.com/goserver/core"
|
"mongo.games.com/goserver/core"
|
||||||
"mongo.games.com/goserver/core/module"
|
"mongo.games.com/goserver/core/module"
|
||||||
|
|
||||||
_ "mongo.games.com/game"
|
_ "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/base"
|
||||||
_ "mongo.games.com/game/robot/chess"
|
_ "mongo.games.com/game/robot/chess"
|
||||||
_ "mongo.games.com/game/robot/thirteen"
|
_ "mongo.games.com/game/robot/thirteen"
|
||||||
|
|
@ -18,22 +14,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// 自定义配置文件
|
|
||||||
model.InitGameParam()
|
|
||||||
// package模块
|
|
||||||
defer core.ClosePackages()
|
defer core.ClosePackages()
|
||||||
core.LoadPackages("config.json")
|
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 := module.Start()
|
||||||
waiter.Wait("main()")
|
waiter.Wait("main()")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,11 @@ func (this *CSEnterRoomHandler) Process(s *netlib.Session, packetid int, data in
|
||||||
if scene.IsMatchScene() && p.IsRob {
|
if scene.IsMatchScene() && p.IsRob {
|
||||||
grade := int32(1000)
|
grade := int32(1000)
|
||||||
snid := p.SnId
|
snid := p.SnId
|
||||||
|
ms := MatchSeasonMgrSington.GetMatchSeason(snid) // 玩家赛季信息
|
||||||
|
lv := MatchSeasonRankMgrSington.CreateRobotLv() //
|
||||||
|
if ms != nil {
|
||||||
|
lv = ms.Lv
|
||||||
|
}
|
||||||
roleId := int32(2000001)
|
roleId := int32(2000001)
|
||||||
if p.Roles != nil {
|
if p.Roles != nil {
|
||||||
roleId = p.Roles.ModId
|
roleId = p.Roles.ModId
|
||||||
|
|
@ -154,11 +159,12 @@ func (this *CSEnterRoomHandler) Process(s *netlib.Session, packetid int, data in
|
||||||
randIndex := rand.Intn(len(tm.copyRobotGrades))
|
randIndex := rand.Intn(len(tm.copyRobotGrades))
|
||||||
grade = tm.copyRobotGrades[randIndex].grade
|
grade = tm.copyRobotGrades[randIndex].grade
|
||||||
snid = tm.copyRobotGrades[randIndex].copySnid
|
snid = tm.copyRobotGrades[randIndex].copySnid
|
||||||
|
lv = tm.copyRobotGrades[randIndex].copyLv
|
||||||
roleId = tm.copyRobotGrades[randIndex].copyRoleId
|
roleId = tm.copyRobotGrades[randIndex].copyRoleId
|
||||||
tm.copyRobotGrades = append(tm.copyRobotGrades[:randIndex], tm.copyRobotGrades[randIndex+1:]...)
|
tm.copyRobotGrades = append(tm.copyRobotGrades[:randIndex], tm.copyRobotGrades[randIndex+1:]...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mc := NewMatchContext(p, tm, grade, snid, 1, roleId, 0)
|
mc := NewMatchContext(p, tm, grade, snid, lv, roleId, 0)
|
||||||
if mc != nil {
|
if mc != nil {
|
||||||
mc.gaming = true
|
mc.gaming = true
|
||||||
p.matchCtx = mc
|
p.matchCtx = mc
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,90 @@
|
||||||
|
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{})
|
||||||
|
}
|
||||||
|
|
@ -152,4 +152,8 @@ func (this *ActSignMgr) Sign(player *Player, signIndex int, signType int32) acti
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
mgo.SetStats(true)
|
mgo.SetStats(true)
|
||||||
|
RegisterParallelLoadFunc("14日签到", func() error {
|
||||||
|
ActSignMgrSington.Init()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -538,4 +538,8 @@ func (this *BlackListMgr) CheckDeviceInBlackByPlatfrom(deviceId string, blackTyp
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
mgo.SetStats(true)
|
mgo.SetStats(true)
|
||||||
|
RegisterParallelLoadFunc("平台黑名单", func() error {
|
||||||
|
BlackListMgrSington.Init()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,11 @@ func (gsm *GameStateManager) BrodcastGameState(gameId int32, platform string, pa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func init() {
|
func init() {
|
||||||
|
//使用并行加载
|
||||||
|
RegisterParallelLoadFunc("选场游戏场次配置", func() error {
|
||||||
|
gameStateMgr.Init()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
//gameStateMgr.gameIds[int32(common.GameId_RollCoin)] = []int32{110030001, 110030002, 110030003, 110030004}
|
//gameStateMgr.gameIds[int32(common.GameId_RollCoin)] = []int32{110030001, 110030002, 110030003, 110030004}
|
||||||
//gameStateMgr.gameIds[int32(common.GameId_RollColor)] = []int32{150010001, 150010002, 150010003, 150010004}
|
//gameStateMgr.gameIds[int32(common.GameId_RollColor)] = []int32{150010001, 150010002, 150010003, 150010004}
|
||||||
//gameStateMgr.gameIds[int32(common.GameId_RedVsBlack)] = []int32{140010001, 140010002, 140010003, 140010004}
|
//gameStateMgr.gameIds[int32(common.GameId_RedVsBlack)] = []int32{140010001, 140010002, 140010003, 140010004}
|
||||||
|
|
|
||||||
|
|
@ -406,4 +406,9 @@ func (this *HorseRaceLampMgr) BroadcastHorseRaceLampMsg(horseRaceLamp *HorseRace
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
module.RegisteModule(HorseRaceLampMgrSington, time.Second*3, 0)
|
module.RegisteModule(HorseRaceLampMgrSington, time.Second*3, 0)
|
||||||
|
|
||||||
|
RegisterParallelLoadFunc("平台通知", func() error {
|
||||||
|
HorseRaceLampMgrSington.InitHorseRaceLamp()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,207 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"mongo.games.com/game/common"
|
||||||
|
"mongo.games.com/game/gamerule/crash"
|
||||||
|
"mongo.games.com/game/mq"
|
||||||
|
"mongo.games.com/goserver/core/broker/rabbitmq"
|
||||||
|
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego/cache"
|
||||||
|
"mongo.games.com/game/model"
|
||||||
|
"mongo.games.com/game/webapi"
|
||||||
|
"mongo.games.com/goserver/core"
|
||||||
|
"mongo.games.com/goserver/core/logger"
|
||||||
|
"mongo.games.com/goserver/core/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ParalleFunc func() error
|
||||||
|
|
||||||
|
var CacheMemory cache.Cache
|
||||||
|
var wgParalleLoad = &sync.WaitGroup{}
|
||||||
|
var ParalleLoadModules []*ParalleLoadModule
|
||||||
|
var RabbitMQPublisher *mq.RabbitMQPublisher
|
||||||
|
var RabbitMqConsumer *mq.RabbitMQConsumer
|
||||||
|
|
||||||
|
type ParalleLoadModule struct {
|
||||||
|
name string
|
||||||
|
f ParalleFunc
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterParallelLoadFunc(name string, f ParalleFunc) {
|
||||||
|
ParalleLoadModules = append(ParalleLoadModules, &ParalleLoadModule{name: name, f: f})
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
|
//首先加载游戏配置
|
||||||
|
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.InitGameParam()
|
||||||
|
model.InitNormalParam()
|
||||||
|
|
||||||
|
hs := model.GetCrashHash(0)
|
||||||
|
if hs == nil {
|
||||||
|
for i := 0; i < crash.POKER_CART_CNT; i++ {
|
||||||
|
model.InsertCrashHash(i, crash.Sha256(fmt.Sprintf("%v%v", i, time.Now().UnixNano())))
|
||||||
|
}
|
||||||
|
hs = model.GetCrashHash(0)
|
||||||
|
}
|
||||||
|
model.GameParamData.InitGameHash = []string{}
|
||||||
|
for _, v := range hs {
|
||||||
|
model.GameParamData.InitGameHash = append(model.GameParamData.InitGameHash, v.Hash)
|
||||||
|
}
|
||||||
|
hsatom := model.GetCrashHashAtom(0)
|
||||||
|
if hsatom == nil {
|
||||||
|
for i := 0; i < crash.POKER_CART_CNT; i++ {
|
||||||
|
model.InsertCrashHashAtom(i, crash.Sha256(fmt.Sprintf("%v%v", i, time.Now().UnixNano())))
|
||||||
|
}
|
||||||
|
hsatom = model.GetCrashHashAtom(0)
|
||||||
|
}
|
||||||
|
model.GameParamData.AtomGameHash = []string{}
|
||||||
|
for _, v := range hsatom {
|
||||||
|
model.GameParamData.AtomGameHash = append(model.GameParamData.AtomGameHash, v.Hash)
|
||||||
|
}
|
||||||
|
//if len(model.GameParamData.AtomGameHash) < crash.POKER_CART_CNT ||
|
||||||
|
// len(model.GameParamData.InitGameHash) < crash.POKER_CART_CNT {
|
||||||
|
// panic(errors.New("hash is read error"))
|
||||||
|
//}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
//RegisterParallelLoadFunc("平台红包数据", func() error {
|
||||||
|
// actRandCoinMgr.LoadPlatformData()
|
||||||
|
// return nil
|
||||||
|
//})
|
||||||
|
|
||||||
|
RegisterParallelLoadFunc("GMAC", func() error {
|
||||||
|
model.InitGMAC()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
RegisterParallelLoadFunc("三方游戏配置", func() error {
|
||||||
|
model.InitGameConfig()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
RegisterParallelLoadFunc("GameKVData", func() error {
|
||||||
|
model.InitGameKVData()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
RegisterParallelLoadFunc("水池配置", func() error {
|
||||||
|
return model.GetAllCoinPoolSettingData()
|
||||||
|
})
|
||||||
|
|
||||||
|
RegisterParallelLoadFunc("三方平台热载数据设置", func() error {
|
||||||
|
f := func() {
|
||||||
|
webapi.ReqCgAddr = model.GameParamData.CgAddr
|
||||||
|
if plt, ok := webapi.ThridPlatformMgrSington.ThridPlatformMap.Load("XHJ平台"); ok {
|
||||||
|
//plt.(*webapi.XHJThridPlatform).IsNeedCheckQuota = model.GameParamData.FGCheckPlatformQuota
|
||||||
|
plt.(*webapi.XHJThridPlatform).ReqTimeOut = model.GameParamData.ThirdPltReqTimeout
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f()
|
||||||
|
model.GameParamData.Observers = append(model.GameParamData.Observers, f)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
core.RegisteHook(core.HOOK_BEFORE_START, func() error {
|
||||||
|
|
||||||
|
//for _, v := range data {
|
||||||
|
// PlatformMgrSingleton.UpsertPlatform(v.Name, v.Isolated, v.GameStatesData)
|
||||||
|
//}
|
||||||
|
|
||||||
|
//ps := []model.GamePlatformState{model.GamePlatformState{LogicId:130000001,Param:"",State:1},model.GamePlatformState{LogicId:150000001,Param:"",State:1}}
|
||||||
|
|
||||||
|
//model.InsertPlatformGameConfig("360",true,ps)
|
||||||
|
|
||||||
|
var err error
|
||||||
|
CacheMemory, err = cache.NewCache("memory", `{"interval":60}`)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
//etcd打开连接
|
||||||
|
EtcdMgrSington.Init()
|
||||||
|
|
||||||
|
//go func() {
|
||||||
|
// for {
|
||||||
|
// time.Sleep(time.Minute)
|
||||||
|
// EtcdMgrSington.Reset()
|
||||||
|
// }
|
||||||
|
//}()
|
||||||
|
|
||||||
|
//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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RabbitMqConsumer = mq.NewRabbitMQConsumer(common.CustomConfig.GetString("RabbitMQURL"), rabbitmq.Exchange{Name: common.CustomConfig.GetString("RMQExchange"), Durable: true})
|
||||||
|
if RabbitMqConsumer != nil {
|
||||||
|
RabbitMqConsumer.Start()
|
||||||
|
}
|
||||||
|
|
||||||
|
//开始并行加载数据
|
||||||
|
//改为串行加载,后台并发有点扛不住
|
||||||
|
if len(ParalleLoadModules) > 0 {
|
||||||
|
tStart := time.Now()
|
||||||
|
logger.Logger.Infof("===[开始串行加载]===")
|
||||||
|
//wgParalleLoad.Add(paralleCnt)
|
||||||
|
for _, m := range ParalleLoadModules {
|
||||||
|
/*go*/ func(plm *ParalleLoadModule) {
|
||||||
|
ts := time.Now()
|
||||||
|
defer func() {
|
||||||
|
utils.DumpStackIfPanic(plm.name)
|
||||||
|
//wgParalleLoad.Done()
|
||||||
|
logger.Logger.Infof("[串行加载结束][%v] 耗时[%v]", plm.name, time.Now().Sub(ts))
|
||||||
|
}()
|
||||||
|
logger.Logger.Infof("[开始串行加载][%v] ", plm.name)
|
||||||
|
|
||||||
|
err := plm.f()
|
||||||
|
if err != nil {
|
||||||
|
logger.Logger.Warnf("[串行加载][%v][error:%v]", plm.name, err)
|
||||||
|
}
|
||||||
|
}(m)
|
||||||
|
}
|
||||||
|
//wgParalleLoad.Wait()
|
||||||
|
logger.Logger.Infof("===[串行加载结束,总耗时:%v]===", time.Now().Sub(tStart))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
|
||||||
|
//etcd关闭连接
|
||||||
|
EtcdMgrSington.Shutdown()
|
||||||
|
//关闭rabbitmq连接
|
||||||
|
if RabbitMQPublisher != nil {
|
||||||
|
RabbitMQPublisher.Stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
if RabbitMqConsumer != nil {
|
||||||
|
RabbitMqConsumer.Stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
//model.ShutdownRPClient()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
//core.RegisteHook(core.HOOK_BEFORE_START, func() error {
|
||||||
|
// ThirdPltGameMappingConfig.Init()
|
||||||
|
// return nil
|
||||||
|
//})
|
||||||
|
//RegisterParallelLoadFunc("分层配置数据", func() error {
|
||||||
|
// //加载分层配置
|
||||||
|
// LogicLevelMgrSington.LoadConfig()
|
||||||
|
// return nil
|
||||||
|
//})
|
||||||
|
}
|
||||||
|
|
@ -39,12 +39,12 @@ func (c *LogChannel) WriteLog(log interface{}) {
|
||||||
if cname == "" {
|
if cname == "" {
|
||||||
cname = "_null_"
|
cname = "_null_"
|
||||||
}
|
}
|
||||||
mq.Send(cname, log)
|
RabbitMQPublisher.Send(cname, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteMQData rabbitMQ消息
|
// WriteMQData rabbitMQ消息
|
||||||
func (c *LogChannel) WriteMQData(data *model.RabbitMQData) {
|
func (c *LogChannel) WriteMQData(data *model.RabbitMQData) {
|
||||||
mq.Send(data.MQName, data.Data)
|
RabbitMQPublisher.Send(data.MQName, data.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
||||||
|
|
@ -1,65 +1,26 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/astaxie/beego/cache"
|
_ "mongo.games.com/game"
|
||||||
|
"mongo.games.com/game/common"
|
||||||
"mongo.games.com/goserver/core"
|
"mongo.games.com/goserver/core"
|
||||||
_ "mongo.games.com/goserver/core/i18n"
|
_ "mongo.games.com/goserver/core/i18n"
|
||||||
"mongo.games.com/goserver/core/module"
|
"mongo.games.com/goserver/core/module"
|
||||||
"mongo.games.com/goserver/core/schedule"
|
"mongo.games.com/goserver/core/schedule"
|
||||||
|
|
||||||
_ "mongo.games.com/game"
|
|
||||||
"mongo.games.com/game/common"
|
|
||||||
"mongo.games.com/game/etcd"
|
|
||||||
"mongo.games.com/game/model"
|
|
||||||
"mongo.games.com/game/mq"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var CacheMemory cache.Cache
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// 自定义配置文件
|
rand.Seed(time.Now().Unix())
|
||||||
model.InitGameParam()
|
core.RegisterConfigEncryptor(common.ConfigFE)
|
||||||
model.InitNormalParam()
|
|
||||||
model.InitGMAC()
|
|
||||||
model.InitGameConfig()
|
|
||||||
// package模块
|
|
||||||
defer core.ClosePackages()
|
defer core.ClosePackages()
|
||||||
core.LoadPackages("config.json")
|
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)
|
|
||||||
etcd.Start(common.CustomConfig.GetStrings("etcdurl"), common.CustomConfig.GetString("etcduser"), common.CustomConfig.GetString("etcdpwd"), time.Minute)
|
|
||||||
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"))
|
|
||||||
|
|
||||||
var err error
|
|
||||||
CacheMemory, err = cache.NewCache("memory", `{"interval":60}`)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
EtcdMgrSington.Init()
|
|
||||||
BlackListMgrSington.Init()
|
|
||||||
gameStateMgr.Init()
|
|
||||||
HorseRaceLampMgrSington.InitHorseRaceLamp()
|
|
||||||
model.InitGameKVData()
|
|
||||||
model.GetAllCoinPoolSettingData()
|
|
||||||
MsgMgrSington.InitMsg()
|
|
||||||
PlatformGameGroupMgrSington.LoadGameGroup()
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
core.RegisteHook(core.HOOK_AFTER_STOP, func() error {
|
|
||||||
EtcdMgrSington.Close()
|
|
||||||
etcd.Close()
|
|
||||||
mq.StopPublisher()
|
|
||||||
mq.StopConsumer()
|
|
||||||
model.ShutdownRPClient()
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
//启动定时任务
|
//启动定时任务
|
||||||
schedule.StartTask()
|
schedule.StartTask()
|
||||||
|
|
||||||
//启动业务模块
|
//启动业务模块
|
||||||
waiter := module.Start()
|
waiter := module.Start()
|
||||||
waiter.Wait("main()")
|
waiter.Wait("main()")
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,393 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/globalsign/mgo/bson"
|
||||||
|
"mongo.games.com/game/model"
|
||||||
|
"mongo.games.com/game/proto"
|
||||||
|
"mongo.games.com/game/protocol/tournament"
|
||||||
|
"mongo.games.com/game/srvdata"
|
||||||
|
"mongo.games.com/goserver/core/basic"
|
||||||
|
"mongo.games.com/goserver/core/logger"
|
||||||
|
"mongo.games.com/goserver/core/module"
|
||||||
|
"mongo.games.com/goserver/core/task"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var MatchSeasonMgrSington = &MatchSeasonMgr{
|
||||||
|
MatchSeasonList: make(map[int32]*MatchSeason),
|
||||||
|
MatchSeasonId: make(map[string]*MatchSeasonId),
|
||||||
|
}
|
||||||
|
|
||||||
|
type MatchSeasonMgr struct {
|
||||||
|
BaseClockSinker
|
||||||
|
MatchSeasonList map[int32]*MatchSeason // snid:玩家赛季信息
|
||||||
|
MatchSeasonId map[string]*MatchSeasonId // platform:平台赛季信息
|
||||||
|
}
|
||||||
|
|
||||||
|
// MatchSeason 玩家赛季信息
|
||||||
|
type MatchSeason struct {
|
||||||
|
Id bson.ObjectId `bson:"_id"`
|
||||||
|
Platform string
|
||||||
|
SnId int32
|
||||||
|
Name string
|
||||||
|
SeasonId int32 //赛季id
|
||||||
|
Lv int32 //段位
|
||||||
|
LastLv int32 //上赛季段位
|
||||||
|
IsAward bool //上赛季是否领奖
|
||||||
|
AwardTs int64 //领奖时间
|
||||||
|
UpdateTs int64
|
||||||
|
dirty bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// MatchSeasonId 赛季信息
|
||||||
|
type MatchSeasonId struct {
|
||||||
|
Id bson.ObjectId `bson:"_id"`
|
||||||
|
Platform string
|
||||||
|
SeasonId int32 //赛季id
|
||||||
|
StartStamp int64 //开始时间戳
|
||||||
|
EndStamp int64 //结束时间戳
|
||||||
|
UpdateTs int64 //更新时间戳
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonMgr) exchangeModel2Cache(mms *model.MatchSeason) *MatchSeason {
|
||||||
|
if mms == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
ms := &MatchSeason{
|
||||||
|
Id: mms.Id,
|
||||||
|
Platform: mms.Platform,
|
||||||
|
SnId: mms.SnId,
|
||||||
|
Name: mms.Name,
|
||||||
|
Lv: mms.Lv,
|
||||||
|
LastLv: mms.LastLv,
|
||||||
|
IsAward: mms.IsAward,
|
||||||
|
AwardTs: mms.AwardTs,
|
||||||
|
SeasonId: mms.SeasonId,
|
||||||
|
UpdateTs: mms.UpdateTs,
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonMgr) GetMatchSeason(snid int32) *MatchSeason {
|
||||||
|
return this.MatchSeasonList[snid]
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAllMatchSeason 获取所有玩家赛季信息
|
||||||
|
func (this *MatchSeasonMgr) GetAllMatchSeason() map[int32]*MatchSeason {
|
||||||
|
return this.MatchSeasonList
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonMgr) SetMatchSeason(ms *MatchSeason) {
|
||||||
|
if ms == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.MatchSeasonList[ms.SnId] = ms
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonMgr) DelMatchSeasonCache(snid int32) {
|
||||||
|
if this.MatchSeasonList[snid] == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
delete(this.MatchSeasonList, snid)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateMatchSeasonLv 修改玩家段位
|
||||||
|
// 通知段位变更
|
||||||
|
// 更新排行榜
|
||||||
|
func (this *MatchSeasonMgr) UpdateMatchSeasonLv(p *Player, addlv int32, dirty bool) {
|
||||||
|
logger.Logger.Trace("(this *MatchSeasonMgr) UpdateMatchSeasonLv: SnId: ", p.SnId, " addlv: ", addlv)
|
||||||
|
if p == nil || p.IsRob {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
platform := p.Platform
|
||||||
|
if platform == DefaultPlatform {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ms := this.GetMatchSeason(p.SnId)
|
||||||
|
if ms != nil {
|
||||||
|
ms.Lv = ms.Lv + addlv
|
||||||
|
ms.dirty = true
|
||||||
|
ms.UpdateTs = time.Now().Unix()
|
||||||
|
msid := this.GetMatchSeasonId(platform)
|
||||||
|
if msid != nil {
|
||||||
|
if addlv != 0 || dirty { //段位有变化或者需要继承
|
||||||
|
//通知客户端段位更新
|
||||||
|
pack := &tournament.SCTMSeasonInfo{
|
||||||
|
Id: msid.SeasonId,
|
||||||
|
SeasonTimeStamp: []int64{msid.StartStamp, msid.EndStamp},
|
||||||
|
Lv: ms.Lv,
|
||||||
|
LastLv: ms.LastLv,
|
||||||
|
IsAward: ms.IsAward,
|
||||||
|
}
|
||||||
|
proto.SetDefaults(pack)
|
||||||
|
ok := p.SendToClient(int(tournament.TOURNAMENTID_PACKET_TM_SCTMSeasonInfo), pack)
|
||||||
|
logger.Logger.Trace("SCTMSeasonInfoHandler: ok: ", ok, pack)
|
||||||
|
}
|
||||||
|
//更新排行榜
|
||||||
|
logger.Logger.Trace("更新排行榜!!!")
|
||||||
|
msrs := MatchSeasonRankMgrSington.GetMatchSeasonRank(platform)
|
||||||
|
if msrs == nil { //排行榜没有数据 去缓存中取
|
||||||
|
ams := MatchSeasonMgrSington.GetAllMatchSeason()
|
||||||
|
mss := []*model.MatchSeason{}
|
||||||
|
if ams != nil {
|
||||||
|
for _, season := range ams {
|
||||||
|
if season.Platform == platform {
|
||||||
|
mms := &model.MatchSeason{
|
||||||
|
Id: season.Id,
|
||||||
|
Platform: season.Platform,
|
||||||
|
SnId: season.SnId,
|
||||||
|
Name: season.Name,
|
||||||
|
SeasonId: season.SeasonId,
|
||||||
|
Lv: season.Lv,
|
||||||
|
LastLv: season.LastLv,
|
||||||
|
IsAward: season.IsAward,
|
||||||
|
AwardTs: season.AwardTs,
|
||||||
|
}
|
||||||
|
mss = append(mss, mms)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if mss != nil && len(mss) > 0 {
|
||||||
|
cmsrs := []*MatchSeasonRank{}
|
||||||
|
sort.Slice(mss, func(i, j int) bool {
|
||||||
|
return mss[i].Lv > mss[j].Lv
|
||||||
|
})
|
||||||
|
if len(mss) > model.GameParamData.MatchSeasonRankMaxNum {
|
||||||
|
mss = append(mss[:model.GameParamData.MatchSeasonRankMaxNum])
|
||||||
|
}
|
||||||
|
for i := 0; i < len(mss); i++ {
|
||||||
|
season := mss[i]
|
||||||
|
msr := &MatchSeasonRank{
|
||||||
|
Id: season.Id,
|
||||||
|
Platform: season.Platform,
|
||||||
|
SnId: season.SnId,
|
||||||
|
Name: season.Name,
|
||||||
|
Lv: season.Lv,
|
||||||
|
UpdateTs: season.UpdateTs,
|
||||||
|
}
|
||||||
|
cmsrs = append(cmsrs, msr)
|
||||||
|
}
|
||||||
|
MatchSeasonRankMgrSington.SetMatchSeasonRank(platform, cmsrs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MatchSeasonRankMgrSington.UpdateMatchSeasonRank(p, ms.Lv)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MatchSeasonInherit 查询段位继承
|
||||||
|
func (this *MatchSeasonMgr) MatchSeasonInherit(lv int32) int32 {
|
||||||
|
logger.Logger.Trace("(this *MatchSeasonMgr) MatchSeasonInherit: lv: ", lv)
|
||||||
|
destLv := int32(1)
|
||||||
|
for _, v := range srvdata.PBDB_GamMatchLVMgr.Datas.GetArr() {
|
||||||
|
if v.Star != nil && len(v.Star) > 1 {
|
||||||
|
startStar := v.Star[0]
|
||||||
|
endStar := v.Star[1]
|
||||||
|
if lv >= startStar && lv <= endStar { //匹配段位
|
||||||
|
destLv = v.Star2 //继承后段位
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return destLv
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateMatchSeasonAward 更新领奖时间
|
||||||
|
func (this *MatchSeasonMgr) UpdateMatchSeasonAward(snid int32) {
|
||||||
|
logger.Logger.Trace("(this *MatchSeasonMgr) UpdateMatchSeasonAward ", snid)
|
||||||
|
ms := this.GetMatchSeason(snid)
|
||||||
|
if ms != nil {
|
||||||
|
ms.IsAward = true
|
||||||
|
ms.AwardTs = time.Now().Unix()
|
||||||
|
ms.UpdateTs = time.Now().Unix()
|
||||||
|
ms.dirty = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveMatchSeasonData 保存玩家段位信息
|
||||||
|
// logout 删除缓存
|
||||||
|
func (this *MatchSeasonMgr) SaveMatchSeasonData(snid int32, logout bool) {
|
||||||
|
logger.Logger.Trace("(this *MatchSeasonMgr) SaveMatchSeasonData ", snid)
|
||||||
|
ms := this.MatchSeasonList[snid]
|
||||||
|
if ms != nil && ms.dirty {
|
||||||
|
ms.dirty = false
|
||||||
|
mms := &model.MatchSeason{
|
||||||
|
Id: ms.Id,
|
||||||
|
Platform: ms.Platform,
|
||||||
|
SnId: ms.SnId,
|
||||||
|
Name: ms.Name,
|
||||||
|
Lv: ms.Lv,
|
||||||
|
LastLv: ms.LastLv,
|
||||||
|
IsAward: ms.IsAward,
|
||||||
|
AwardTs: ms.AwardTs,
|
||||||
|
SeasonId: ms.SeasonId,
|
||||||
|
UpdateTs: ms.UpdateTs,
|
||||||
|
}
|
||||||
|
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||||||
|
return model.UpsertMatchSeason(mms)
|
||||||
|
}), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) {
|
||||||
|
logger.Logger.Info("SaveMatchSeasonData!!!")
|
||||||
|
if logout {
|
||||||
|
this.DelMatchSeasonCache(snid)
|
||||||
|
}
|
||||||
|
})).StartByFixExecutor("SnId:" + strconv.Itoa(int(snid)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveAllMatchSeasonData 保存所有玩家段位信息
|
||||||
|
func (this *MatchSeasonMgr) SaveAllMatchSeasonData() {
|
||||||
|
for _, msl := range this.MatchSeasonList {
|
||||||
|
this.SaveMatchSeasonData(msl.SnId, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateMatchSeasonId 更新比赛场赛季配置
|
||||||
|
// 更新赛季配置
|
||||||
|
// 更新在线玩家段位
|
||||||
|
// 更新排行榜
|
||||||
|
func (this *MatchSeasonMgr) UpdateMatchSeasonId(platform string) {
|
||||||
|
logger.Logger.Info("(this *MatchSeasonMgr) UpdateMatchSeasonId")
|
||||||
|
if platform == DefaultPlatform {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||||||
|
ret, err := model.QueryMatchSeasonId(platform)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) {
|
||||||
|
var ret *model.MatchSeasonId
|
||||||
|
if data == nil || data.(*model.MatchSeasonId) == nil {
|
||||||
|
sstamp, estamp := this.getNowMonthStartAndEnd()
|
||||||
|
ret = model.NewMatchSeasonId(platform, int32(1), sstamp, estamp) //初始化赛季
|
||||||
|
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||||||
|
return model.UpsertMatchSeasonId(ret)
|
||||||
|
}), nil).StartByFixExecutor("UpsertMatchSeasonId")
|
||||||
|
} else {
|
||||||
|
ret = data.(*model.MatchSeasonId)
|
||||||
|
}
|
||||||
|
logger.Logger.Info("UpdateMatchSeasonId!!!", ret)
|
||||||
|
if ret != nil {
|
||||||
|
nowStamp := time.Now().Unix()
|
||||||
|
if nowStamp < ret.StartStamp {
|
||||||
|
logger.Logger.Error("赛季开始时间错误!!!")
|
||||||
|
}
|
||||||
|
if nowStamp >= ret.EndStamp { //新赛季
|
||||||
|
logger.Logger.Info("新赛季!!!", ret)
|
||||||
|
sstamp, estamp := this.getNowMonthStartAndEnd()
|
||||||
|
ret.SeasonId++
|
||||||
|
ret.StartStamp = sstamp
|
||||||
|
ret.EndStamp = estamp
|
||||||
|
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||||||
|
return model.UpsertMatchSeasonId(ret)
|
||||||
|
}), nil).StartByFixExecutor("UpsertMatchSeasonId")
|
||||||
|
//排行榜内的段位继承
|
||||||
|
MatchSeasonRankMgrSington.MatchSeasonRankInherit(platform)
|
||||||
|
//通知平台玩家继承后的段位数据
|
||||||
|
players := PlayerMgrSington.playerOfPlatform[platform]
|
||||||
|
for _, p := range players {
|
||||||
|
if p != nil && p.IsOnLine() && !p.IsRob {
|
||||||
|
ms := MatchSeasonMgrSington.GetMatchSeason(p.SnId)
|
||||||
|
if ms != nil {
|
||||||
|
if ms.SeasonId < ret.SeasonId { //不同赛季段位继承
|
||||||
|
num := ret.SeasonId - ms.SeasonId
|
||||||
|
finalLv := ms.Lv
|
||||||
|
for i := 0; i < int(num); i++ { //继承几次
|
||||||
|
if i == int(num)-1 { //上个赛季
|
||||||
|
ms.LastLv = finalLv
|
||||||
|
}
|
||||||
|
finalLv = MatchSeasonMgrSington.MatchSeasonInherit(finalLv)
|
||||||
|
}
|
||||||
|
ms.Lv = finalLv
|
||||||
|
ms.SeasonId = ret.SeasonId
|
||||||
|
ms.IsAward = false
|
||||||
|
ms.UpdateTs = time.Now().Unix()
|
||||||
|
ms.dirty = true
|
||||||
|
MatchSeasonMgrSington.SetMatchSeason(ms) //更新缓存
|
||||||
|
pack := &tournament.SCTMSeasonInfo{
|
||||||
|
Id: ret.SeasonId,
|
||||||
|
SeasonTimeStamp: []int64{ret.StartStamp, ret.EndStamp},
|
||||||
|
Lv: ms.Lv,
|
||||||
|
LastLv: ms.LastLv,
|
||||||
|
IsAward: ms.IsAward,
|
||||||
|
}
|
||||||
|
proto.SetDefaults(pack)
|
||||||
|
logger.Logger.Trace("SCTMSeasonInfo:", p.SnId, " pack: ", pack)
|
||||||
|
p.SendToClient(int(tournament.TOURNAMENTID_PACKET_TM_SCTMSeasonInfo), pack)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.MatchSeasonId[platform] = &MatchSeasonId{
|
||||||
|
Id: ret.Id,
|
||||||
|
Platform: ret.Platform,
|
||||||
|
SeasonId: ret.SeasonId,
|
||||||
|
StartStamp: ret.StartStamp,
|
||||||
|
EndStamp: ret.EndStamp,
|
||||||
|
UpdateTs: ret.UpdateTs,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})).StartByFixExecutor("platform: " + platform)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMatchSeasonId 获取比赛场赛季配置
|
||||||
|
func (this *MatchSeasonMgr) GetMatchSeasonId(platform string) *MatchSeasonId {
|
||||||
|
logger.Logger.Info("(this *MatchSeasonMgr) GetMatchSeasonId", platform)
|
||||||
|
return this.MatchSeasonId[platform]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取当月初和月末时间戳
|
||||||
|
func (this *MatchSeasonMgr) getNowMonthStartAndEnd() (int64, int64) {
|
||||||
|
now := time.Now()
|
||||||
|
first := now.Format("2006-01") + "-01"
|
||||||
|
start, _ := time.ParseInLocation("2006-01-02", first, time.Local)
|
||||||
|
last := start.AddDate(0, 1, 0).Format("2006-01-02")
|
||||||
|
end, _ := time.ParseInLocation("2006-01-02", last, time.Local)
|
||||||
|
return start.Unix(), end.Unix() - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonMgr) ModuleName() string {
|
||||||
|
return "MatchSeasonMgr"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonMgr) Init() {
|
||||||
|
for _, platform := range PlatformMgrSingleton.GetPlatforms() {
|
||||||
|
if platform.IdStr == DefaultPlatform {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
this.UpdateMatchSeasonId(platform.IdStr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonMgr) Update() {
|
||||||
|
this.SaveAllMatchSeasonData()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonMgr) Shutdown() {
|
||||||
|
this.SaveAllMatchSeasonData()
|
||||||
|
module.UnregisteModule(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonMgr) InterestClockEvent() int {
|
||||||
|
//TODO implement me
|
||||||
|
//panic("implement me")
|
||||||
|
return 1 << CLOCK_EVENT_MONTH
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonMgr) OnMonthTimer() {
|
||||||
|
logger.Logger.Info("(this *MatchSeasonMgr) OnMonthTimer")
|
||||||
|
for _, platform := range PlatformMgrSingleton.GetPlatforms() {
|
||||||
|
if platform.IdStr == DefaultPlatform {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
this.UpdateMatchSeasonId(platform.IdStr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
module.RegisteModule(MatchSeasonMgrSington, time.Minute*1, 0)
|
||||||
|
ClockMgrSington.RegisteSinker(MatchSeasonMgrSington)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,379 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/globalsign/mgo/bson"
|
||||||
|
"math/rand"
|
||||||
|
"mongo.games.com/game/model"
|
||||||
|
"mongo.games.com/game/srvdata"
|
||||||
|
"mongo.games.com/goserver/core/basic"
|
||||||
|
"mongo.games.com/goserver/core/logger"
|
||||||
|
"mongo.games.com/goserver/core/module"
|
||||||
|
"mongo.games.com/goserver/core/task"
|
||||||
|
"sort"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var MatchSeasonRankMgrSington = &MatchSeasonRankMgr{
|
||||||
|
MatchSeasonRank: make(map[string][]*MatchSeasonRank),
|
||||||
|
MatchSeasonRankDirty: make(map[string]bool),
|
||||||
|
RobotMatchSeasonRankInit: make(map[string]bool),
|
||||||
|
RobotMatchSeasonRank: make(map[string][]*MatchSeasonRank),
|
||||||
|
}
|
||||||
|
|
||||||
|
type MatchSeasonRankMgr struct {
|
||||||
|
BaseClockSinker
|
||||||
|
MatchSeasonRank map[string][]*MatchSeasonRank //平台
|
||||||
|
MatchSeasonRankDirty map[string]bool
|
||||||
|
RobotMatchSeasonRankInit map[string]bool
|
||||||
|
RobotMatchSeasonRank map[string][]*MatchSeasonRank //平台
|
||||||
|
}
|
||||||
|
|
||||||
|
type MatchSeasonRank struct {
|
||||||
|
Id bson.ObjectId `bson:"_id"`
|
||||||
|
Platform string
|
||||||
|
SnId int32
|
||||||
|
Name string
|
||||||
|
Lv int32 //段位
|
||||||
|
UpdateTs int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonRankMgr) UpdateMatchSeasonRank(p *Player, lv int32) {
|
||||||
|
logger.Logger.Trace("(this *MatchSeasonRankMgr) UpdateMatchSeasonRank: SnId: ", p.SnId, " lv: ", lv)
|
||||||
|
platform := p.Platform
|
||||||
|
msrs := this.GetMatchSeasonRank(platform)
|
||||||
|
if msrs == nil {
|
||||||
|
msrs = []*MatchSeasonRank{}
|
||||||
|
}
|
||||||
|
have := false
|
||||||
|
for _, msr := range msrs {
|
||||||
|
if msr.SnId == p.SnId {
|
||||||
|
msr.Lv = lv
|
||||||
|
msr.UpdateTs = time.Now().Unix()
|
||||||
|
have = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !have {
|
||||||
|
msr := &MatchSeasonRank{
|
||||||
|
Id: bson.NewObjectId(),
|
||||||
|
Platform: platform,
|
||||||
|
SnId: p.SnId,
|
||||||
|
Name: p.Name,
|
||||||
|
Lv: lv,
|
||||||
|
UpdateTs: time.Now().Unix(),
|
||||||
|
}
|
||||||
|
msrs = append(msrs, msr)
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(msrs, func(i, j int) bool {
|
||||||
|
return msrs[i].Lv > msrs[j].Lv
|
||||||
|
})
|
||||||
|
if len(msrs) > model.GameParamData.MatchSeasonRankMaxNum {
|
||||||
|
if msrs[len(msrs)-1].SnId != p.SnId { //上榜玩家有变化
|
||||||
|
this.MatchSeasonRankDirty[platform] = true
|
||||||
|
}
|
||||||
|
msrs = append(msrs[:model.GameParamData.MatchSeasonRankMaxNum])
|
||||||
|
} else {
|
||||||
|
this.MatchSeasonRankDirty[platform] = true
|
||||||
|
}
|
||||||
|
this.MatchSeasonRank[platform] = msrs
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonRankMgr) GetMatchSeasonRank(platform string) []*MatchSeasonRank {
|
||||||
|
logger.Logger.Trace("(this *MatchSeasonRankMgr) GetMatchSeasonRank: platform = ", platform)
|
||||||
|
return this.MatchSeasonRank[platform]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonRankMgr) SetMatchSeasonRank(platform string, mss []*MatchSeasonRank) {
|
||||||
|
logger.Logger.Trace("(this *MatchSeasonRankMgr) SetMatchSeasonRank: mss = ", mss)
|
||||||
|
this.MatchSeasonRank[platform] = mss
|
||||||
|
this.MatchSeasonRankDirty[platform] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// MatchSeasonRankInherit 段位继承
|
||||||
|
func (this *MatchSeasonRankMgr) MatchSeasonRankInherit(platform string) {
|
||||||
|
msr := this.GetMatchSeasonRank(platform)
|
||||||
|
logger.Logger.Trace("(this *MatchSeasonRankMgr) MatchSeasonRankInherit: msr = ", msr)
|
||||||
|
if msr == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, rank := range msr {
|
||||||
|
rank.Lv = MatchSeasonMgrSington.MatchSeasonInherit(rank.Lv)
|
||||||
|
}
|
||||||
|
this.SetMatchSeasonRank(platform, msr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonRankMgr) InitMatchSeasonRank(platform string) {
|
||||||
|
logger.Logger.Trace("(this *MatchSeasonRankMgr) InitMatchSeasonRank: ", platform)
|
||||||
|
if platform == DefaultPlatform {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if this.MatchSeasonRank[platform] != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if this.MatchSeasonRank[platform] == nil {
|
||||||
|
logger.Logger.Trace("(this *MatchSeasonRankMgr) InitMatchSeasonRank: ", this.MatchSeasonRank[platform])
|
||||||
|
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||||||
|
ret, err := model.QueryMatchSeasonRank(platform)
|
||||||
|
logger.Logger.Trace("(this *MatchSeasonRankMgr) 1 QueryMatchSeasonRank: ", ret)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) {
|
||||||
|
var ret []*model.MatchSeasonRank
|
||||||
|
if data == nil || data.([]*model.MatchSeasonRank) == nil { //初始数据去log_matchseason里面取段位前n名
|
||||||
|
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||||||
|
retRank, err := model.QueryMatchSeason(platform)
|
||||||
|
logger.Logger.Trace("(this *MatchSeasonRankMgr) 1 QueryMatchSeason: ", ret)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return retRank
|
||||||
|
}), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) {
|
||||||
|
var retRank []*model.MatchSeason
|
||||||
|
logger.Logger.Trace("(this *MatchSeasonRankMgr) 2 QueryMatchSeason: ", ret)
|
||||||
|
if data == nil || data.([]*model.MatchSeason) == nil {
|
||||||
|
ams := MatchSeasonMgrSington.GetAllMatchSeason()
|
||||||
|
if ams != nil {
|
||||||
|
for _, season := range ams {
|
||||||
|
if season.Platform == platform {
|
||||||
|
mms := &model.MatchSeason{
|
||||||
|
Id: season.Id,
|
||||||
|
Platform: season.Platform,
|
||||||
|
SnId: season.SnId,
|
||||||
|
Name: season.Name,
|
||||||
|
SeasonId: season.SeasonId,
|
||||||
|
Lv: season.Lv,
|
||||||
|
LastLv: season.LastLv,
|
||||||
|
IsAward: season.IsAward,
|
||||||
|
AwardTs: season.AwardTs,
|
||||||
|
}
|
||||||
|
retRank = append(retRank, mms)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
retRank = data.([]*model.MatchSeason)
|
||||||
|
}
|
||||||
|
if retRank != nil {
|
||||||
|
this.MatchSeasonRank[platform] = []*MatchSeasonRank{}
|
||||||
|
sort.Slice(retRank, func(i, j int) bool {
|
||||||
|
return retRank[i].Lv > retRank[j].Lv
|
||||||
|
})
|
||||||
|
if len(retRank) > model.GameParamData.MatchSeasonRankMaxNum {
|
||||||
|
retRank = append(retRank[:model.GameParamData.MatchSeasonRankMaxNum])
|
||||||
|
}
|
||||||
|
for i := 0; i < len(retRank); i++ {
|
||||||
|
season := retRank[i]
|
||||||
|
msr := &MatchSeasonRank{
|
||||||
|
Id: season.Id,
|
||||||
|
Platform: season.Platform,
|
||||||
|
SnId: season.SnId,
|
||||||
|
Name: season.Name,
|
||||||
|
Lv: season.Lv,
|
||||||
|
UpdateTs: season.UpdateTs,
|
||||||
|
}
|
||||||
|
this.MatchSeasonRank[platform] = append(this.MatchSeasonRank[platform], msr)
|
||||||
|
this.MatchSeasonRankDirty[platform] = true
|
||||||
|
}
|
||||||
|
logger.Logger.Trace("(this *MatchSeasonRankMgr) 3 QueryMatchSeason: ", this.MatchSeasonRank[platform])
|
||||||
|
}
|
||||||
|
})).StartByFixExecutor("platform:" + platform)
|
||||||
|
} else {
|
||||||
|
ret = data.([]*model.MatchSeasonRank)
|
||||||
|
this.MatchSeasonRank[platform] = []*MatchSeasonRank{}
|
||||||
|
for _, rank := range ret {
|
||||||
|
msr := &MatchSeasonRank{
|
||||||
|
Id: rank.Id,
|
||||||
|
Platform: rank.Platform,
|
||||||
|
SnId: rank.SnId,
|
||||||
|
Name: rank.Name,
|
||||||
|
Lv: rank.Lv,
|
||||||
|
UpdateTs: rank.UpdateTs,
|
||||||
|
}
|
||||||
|
this.MatchSeasonRank[platform] = append(this.MatchSeasonRank[platform], msr)
|
||||||
|
}
|
||||||
|
logger.Logger.Trace("(this *MatchSeasonRankMgr) 3 QueryMatchSeasonRank: ", this.MatchSeasonRank[platform])
|
||||||
|
}
|
||||||
|
})).StartByFixExecutor("platform:" + platform)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveMatchSeasonRank 保存排行榜
|
||||||
|
func (this *MatchSeasonRankMgr) SaveMatchSeasonRank(platform string) {
|
||||||
|
logger.Logger.Trace("(this *MatchSeasonRankMgr) SaveMatchSeasonRank: ", platform)
|
||||||
|
msrp := this.MatchSeasonRank[platform]
|
||||||
|
if msrp != nil && this.MatchSeasonRankDirty[platform] {
|
||||||
|
this.MatchSeasonRankDirty[platform] = false
|
||||||
|
dirtyMsrs := []*model.MatchSeasonRank{}
|
||||||
|
for _, rank := range msrp {
|
||||||
|
msr := &model.MatchSeasonRank{
|
||||||
|
Id: rank.Id,
|
||||||
|
Platform: rank.Platform,
|
||||||
|
SnId: rank.SnId,
|
||||||
|
Name: rank.Name,
|
||||||
|
Lv: rank.Lv,
|
||||||
|
UpdateTs: rank.UpdateTs,
|
||||||
|
}
|
||||||
|
dirtyMsrs = append(dirtyMsrs, msr)
|
||||||
|
}
|
||||||
|
if dirtyMsrs != nil && len(dirtyMsrs) > 0 {
|
||||||
|
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||||||
|
model.UpsertMatchSeasonRank(platform, dirtyMsrs)
|
||||||
|
return nil
|
||||||
|
}), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) {
|
||||||
|
})).StartByFixExecutor("platform:" + platform)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonRankMgr) SaveAllMatchSeasonRank() {
|
||||||
|
for _, platform := range PlatformMgrSingleton.GetPlatforms() {
|
||||||
|
if platform.IdStr == DefaultPlatform {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
this.SaveMatchSeasonRank(platform.IdStr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonRankMgr) CreateRobotLv() int32 {
|
||||||
|
Lv := int32(1)
|
||||||
|
now := time.Now()
|
||||||
|
first := now.Format("2006-01") + "-01"
|
||||||
|
start, _ := time.ParseInLocation("2006-01-02", first, time.Local)
|
||||||
|
diffUnix := now.Unix() - start.Unix()
|
||||||
|
diffDay := diffUnix/int64(24*60*60) + 1
|
||||||
|
data := srvdata.PBDB_MatchRankMgr.GetData(int32(diffDay))
|
||||||
|
if data != nil && data.RankStar != nil && len(data.RankStar) > 0 {
|
||||||
|
diff := data.RankStar[1] - data.RankStar[0]
|
||||||
|
min := data.RankStar[0]
|
||||||
|
if data.RankStar[0] > data.RankStar[1] {
|
||||||
|
diff = data.RankStar[0] - data.RankStar[1]
|
||||||
|
min = data.RankStar[1]
|
||||||
|
}
|
||||||
|
Lv = rand.Int31n(diff) + min
|
||||||
|
}
|
||||||
|
return Lv
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonRankMgr) CreateRobotMatchSeasonRank(platform string) {
|
||||||
|
if this.RobotMatchSeasonRankInit[platform] {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.RobotMatchSeasonRank[platform] = []*MatchSeasonRank{}
|
||||||
|
for _, player := range PlayerMgrSington.snidMap {
|
||||||
|
if player != nil && player.IsRob {
|
||||||
|
msr := &MatchSeasonRank{
|
||||||
|
Platform: platform,
|
||||||
|
SnId: player.SnId,
|
||||||
|
Name: player.Name,
|
||||||
|
Lv: this.CreateRobotLv(),
|
||||||
|
}
|
||||||
|
this.RobotMatchSeasonRank[platform] = append(this.RobotMatchSeasonRank[platform], msr)
|
||||||
|
}
|
||||||
|
if len(this.RobotMatchSeasonRank[platform]) >= model.GameParamData.MatchSeasonRankMaxNum {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(this.RobotMatchSeasonRank[platform]) < model.GameParamData.MatchSeasonRankMaxNum {
|
||||||
|
localSnids := []int32{102917700, 61096000, 21058800, 47291500, 58562600, 22127000, 80639700, 49475400, 60569500, 54746600, 46797900, 88659800, 61118200, 68773200, 92010700, 13305900, 68143500, 86379100, 76177100, 95050900, 23954400, 52524000, 63618100, 31808400, 26929400, 108083700, 50751500, 92179900, 60327700, 69582700, 80156500, 30808000, 53806700, 53235700, 50049200, 30465400, 76672700, 69638500, 12351800, 48705200, 98920500, 32158900, 33519000, 42915300, 30811200, 77037600, 65779800, 22148100, 59819100, 46374600}
|
||||||
|
pool := srvdata.PBDB_NameMgr.Datas.GetArr()
|
||||||
|
cnt := int32(len(pool))
|
||||||
|
for _, snid := range localSnids {
|
||||||
|
msr := &MatchSeasonRank{
|
||||||
|
Platform: platform,
|
||||||
|
SnId: snid,
|
||||||
|
Name: "Guest",
|
||||||
|
Lv: this.CreateRobotLv(),
|
||||||
|
}
|
||||||
|
if cnt > 0 {
|
||||||
|
msr.Name = pool[rand.Int31n(cnt)].GetName()
|
||||||
|
}
|
||||||
|
this.RobotMatchSeasonRank[platform] = append(this.RobotMatchSeasonRank[platform], msr)
|
||||||
|
if len(this.RobotMatchSeasonRank[platform]) >= model.GameParamData.MatchSeasonRankMaxNum {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.RobotMatchSeasonRankInit[platform] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonRankMgr) GetRobotMatchSeasonRank(platform string) []*MatchSeasonRank {
|
||||||
|
logger.Logger.Trace("GetRobotMatchSeasonRank: ", platform)
|
||||||
|
if !this.RobotMatchSeasonRankInit[platform] {
|
||||||
|
this.CreateRobotMatchSeasonRank(platform)
|
||||||
|
}
|
||||||
|
if this.RobotMatchSeasonRank == nil || this.RobotMatchSeasonRank[platform] == nil || len(this.RobotMatchSeasonRank[platform]) < model.GameParamData.MatchSeasonRankMaxNum {
|
||||||
|
this.CreateRobotMatchSeasonRank(platform)
|
||||||
|
}
|
||||||
|
return this.RobotMatchSeasonRank[platform]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonRankMgr) UpdateRobotMatchSeasonRank(platform string) {
|
||||||
|
logger.Logger.Trace("UpdateRobotMatchSeasonRank: ", platform)
|
||||||
|
rmsr := this.GetRobotMatchSeasonRank(platform)
|
||||||
|
if rmsr != nil {
|
||||||
|
for _, rank := range rmsr {
|
||||||
|
diff := rand.Int31n(7) - 3
|
||||||
|
rank.Lv += diff
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonRankMgr) ModuleName() string {
|
||||||
|
return "MatchSeasonRankMgr"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonRankMgr) Init() {
|
||||||
|
for _, platform := range PlatformMgrSingleton.GetPlatforms() {
|
||||||
|
if platform.IdStr == DefaultPlatform {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
this.InitMatchSeasonRank(platform.IdStr)
|
||||||
|
this.RobotMatchSeasonRankInit[platform.IdStr] = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonRankMgr) Update() {
|
||||||
|
this.SaveAllMatchSeasonRank()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonRankMgr) Shutdown() {
|
||||||
|
this.SaveAllMatchSeasonRank()
|
||||||
|
module.UnregisteModule(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonRankMgr) InterestClockEvent() int {
|
||||||
|
//TODO implement me
|
||||||
|
//panic("implement me")
|
||||||
|
return 1<<CLOCK_EVENT_HOUR | 1<<CLOCK_EVENT_DAY
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonRankMgr) OnHourTimer() {
|
||||||
|
//TODO implement me
|
||||||
|
//panic("implement me")
|
||||||
|
logger.Logger.Trace("(this *MatchSeasonRankMgr) OnHourTimer()")
|
||||||
|
for _, platform := range PlatformMgrSingleton.GetPlatforms() {
|
||||||
|
if platform.IdStr == DefaultPlatform {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
this.UpdateRobotMatchSeasonRank(platform.IdStr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MatchSeasonRankMgr) OnDayTimer() {
|
||||||
|
//TODO implement me
|
||||||
|
//panic("implement me")
|
||||||
|
for _, platform := range PlatformMgrSingleton.GetPlatforms() {
|
||||||
|
if platform.IdStr == DefaultPlatform {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
this.RobotMatchSeasonRankInit[platform.IdStr] = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
module.RegisteModule(MatchSeasonRankMgrSington, time.Minute*1, 0)
|
||||||
|
ClockMgrSington.RegisteSinker(MatchSeasonRankMgrSington)
|
||||||
|
}
|
||||||
|
|
@ -19,6 +19,7 @@ func init() {
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
e.Ack()
|
e.Ack()
|
||||||
|
recover()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var log model.CoinLog
|
var log model.CoinLog
|
||||||
|
|
@ -47,6 +48,7 @@ func init() {
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
e.Ack()
|
e.Ack()
|
||||||
|
recover()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var log model.BindNum
|
var log model.BindNum
|
||||||
|
|
|
||||||
|
|
@ -52,5 +52,8 @@ func (mm *MsgMgr) GetSubscribeMsgs(platform string, ts int64) (msgs []*model.Mes
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
RegisterParallelLoadFunc("平台邮件", func() error {
|
||||||
|
MsgMgrSington.InitMsg()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,5 +125,8 @@ func (this *PlatformGameGroupMgr) OnGameGroupUpdate(oldCfg, newCfg *webapi_proto
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
RegisterParallelLoadFunc("平台游戏组数据", func() error {
|
||||||
|
PlatformGameGroupMgrSington.LoadGameGroup()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -365,6 +365,10 @@ func (this *Player) OnLogined() {
|
||||||
this.OnlineLogLogin()
|
this.OnlineLogLogin()
|
||||||
|
|
||||||
this.SendToRepSrv(this.PlayerData)
|
this.SendToRepSrv(this.PlayerData)
|
||||||
|
|
||||||
|
//七日活动
|
||||||
|
ActSignMgrSington.OnPlayerLogin(this)
|
||||||
|
|
||||||
//红点检测
|
//红点检测
|
||||||
this.CheckShowRed()
|
this.CheckShowRed()
|
||||||
|
|
||||||
|
|
@ -419,6 +423,9 @@ func (this *Player) OnRehold() {
|
||||||
FriendMgrSington.ApplyList(this.Platform, this.SnId)
|
FriendMgrSington.ApplyList(this.Platform, this.SnId)
|
||||||
FriendUnreadMgrSington.CheckSendFriendUnreadData(this.Platform, this.SnId)
|
FriendUnreadMgrSington.CheckSendFriendUnreadData(this.Platform, this.SnId)
|
||||||
|
|
||||||
|
//七日活动.
|
||||||
|
ActSignMgrSington.OnPlayerLogin(this)
|
||||||
|
|
||||||
this.CheckShowRed()
|
this.CheckShowRed()
|
||||||
|
|
||||||
this.SendJackPotInit()
|
this.SendJackPotInit()
|
||||||
|
|
@ -1590,6 +1597,7 @@ func (this *Player) OnLogouted() {
|
||||||
|
|
||||||
if !this.IsRob {
|
if !this.IsRob {
|
||||||
FriendUnreadMgrSington.SaveFriendUnreadData(this.Platform, this.SnId)
|
FriendUnreadMgrSington.SaveFriendUnreadData(this.Platform, this.SnId)
|
||||||
|
MatchSeasonMgrSington.SaveMatchSeasonData(this.SnId, true)
|
||||||
}
|
}
|
||||||
//平台数据
|
//平台数据
|
||||||
//PlayerSingleAdjustMgr.DelPlayerData(this.Platform, this.SnId)
|
//PlayerSingleAdjustMgr.DelPlayerData(this.Platform, this.SnId)
|
||||||
|
|
@ -2205,6 +2213,8 @@ func (this *Player) OnDayTimer(login, continuous bool, t int) {
|
||||||
this.ShopLastLookTime = make(map[int32]int64)
|
this.ShopLastLookTime = make(map[int32]int64)
|
||||||
// 福利活动更新
|
// 福利活动更新
|
||||||
WelfareMgrSington.OnDayChanged(this)
|
WelfareMgrSington.OnDayChanged(this)
|
||||||
|
//七日活动
|
||||||
|
ActSignMgrSington.OnDayChanged(this)
|
||||||
this.VipMatchTimes = 0
|
this.VipMatchTimes = 0
|
||||||
//VIP商城数据更新
|
//VIP商城数据更新
|
||||||
this.UpdateVipShopData()
|
this.UpdateVipShopData()
|
||||||
|
|
|
||||||
|
|
@ -299,10 +299,16 @@ func (this *Scene) PlayerEnter(p *Player, pos int, ischangeroom bool) bool {
|
||||||
if this.IsMatchScene() && p.matchCtx != nil {
|
if this.IsMatchScene() && p.matchCtx != nil {
|
||||||
takeCoin = int64(p.matchCtx.grade)
|
takeCoin = int64(p.matchCtx.grade)
|
||||||
matchParams = append(matchParams, p.matchCtx.rank) //排名
|
matchParams = append(matchParams, p.matchCtx.rank) //排名
|
||||||
if p.IsRob {
|
ms := MatchSeasonMgrSington.GetMatchSeason(p.SnId)
|
||||||
matchParams = append(matchParams, p.matchCtx.copyLv) //机器人随机段位
|
if ms != nil {
|
||||||
|
matchParams = append(matchParams, ms.Lv) //段位
|
||||||
} else {
|
} else {
|
||||||
matchParams = append(matchParams, 1) //段位默认值
|
if p.IsRob {
|
||||||
|
//robotRandLv := MatchSeasonRankMgrSington.CreateRobotLv()
|
||||||
|
matchParams = append(matchParams, p.matchCtx.copyLv) //机器人随机段位
|
||||||
|
} else {
|
||||||
|
matchParams = append(matchParams, 1) //段位默认值
|
||||||
|
}
|
||||||
}
|
}
|
||||||
matchParams = append(matchParams, p.matchCtx.copySnid) //假snid
|
matchParams = append(matchParams, p.matchCtx.copySnid) //假snid
|
||||||
matchParams = append(matchParams, p.matchCtx.copyRoleId) //假snid
|
matchParams = append(matchParams, p.matchCtx.copyRoleId) //假snid
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,129 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"mongo.games.com/game/protocol/server"
|
||||||
|
"mongo.games.com/game/srvdata"
|
||||||
|
"mongo.games.com/game/webapi"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ThirdPltGameMappingConfig = &ThirdPlatformGameMappingConfiguration{
|
||||||
|
DB_ThirdPlatformGameMappingMgr: srvdata.PBDB_ThirdPlatformGameMappingMgr,
|
||||||
|
GamefreeIdMappingMap: make(map[int32]*server.DB_ThirdPlatformGameMapping),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
type ThirdPlatformGameMappingConfiguration struct {
|
||||||
|
*srvdata.DB_ThirdPlatformGameMappingMgr
|
||||||
|
GamefreeIdMappingMap map[int32]*server.DB_ThirdPlatformGameMapping
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ThirdPlatformGameMappingConfiguration) Load(fileFullPath string) error {
|
||||||
|
// this.Test()
|
||||||
|
var rawMappingInfo = make(map[int32]*webapi.WebAPI_ThirdPlatformGameMapping)
|
||||||
|
for _, v := range this.Datas.Arr {
|
||||||
|
this.GamefreeIdMappingMap[v.GetSystemGameID()] = v
|
||||||
|
rawMappingInfo[v.GetSystemGameID()] = &webapi.WebAPI_ThirdPlatformGameMapping{
|
||||||
|
GameFreeID: v.GetSystemGameID(),
|
||||||
|
ThirdPlatformName: v.GetThirdPlatformName(),
|
||||||
|
ThirdGameID: v.GetThirdGameID(),
|
||||||
|
Desc: v.GetDesc(),
|
||||||
|
ScreenOrientationType: v.GetScreenOrientationType(),
|
||||||
|
ThirdID: v.GetThirdID(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
webapi.ThridPlatformMgrSington.ThridPlatformMap.Range(func(key, value interface{}) bool {
|
||||||
|
value.(webapi.IThirdPlatform).InitMappingRelation(rawMappingInfo)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ThirdPlatformGameMappingConfiguration) Reload(fileFullPath string) error {
|
||||||
|
//todo 缓存数据加快查找
|
||||||
|
//logger.Logger.Info("=== 缓存三方平台游戏id映射关系数据加快查找===")
|
||||||
|
this.GamefreeIdMappingMap = make(map[int32]*server.DB_ThirdPlatformGameMapping)
|
||||||
|
var rawMappingInfo = make(map[int32]*webapi.WebAPI_ThirdPlatformGameMapping)
|
||||||
|
for _, v := range this.Datas.Arr {
|
||||||
|
this.GamefreeIdMappingMap[v.GetSystemGameID()] = v
|
||||||
|
rawMappingInfo[v.GetSystemGameID()] = &webapi.WebAPI_ThirdPlatformGameMapping{
|
||||||
|
GameFreeID: v.GetSystemGameID(),
|
||||||
|
ThirdPlatformName: v.GetThirdPlatformName(),
|
||||||
|
ThirdGameID: v.GetThirdGameID(),
|
||||||
|
Desc: v.GetDesc(),
|
||||||
|
ScreenOrientationType: v.GetScreenOrientationType(),
|
||||||
|
ThirdID: v.GetThirdID(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
webapi.ThridPlatformMgrSington.ThridPlatformMap.Range(func(key, value interface{}) bool {
|
||||||
|
value.(webapi.IThirdPlatform).InitMappingRelation(rawMappingInfo)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ThirdPlatformGameMappingConfiguration) Test() {
|
||||||
|
var rawMappingInfo = make(map[int32]*webapi.WebAPI_ThirdPlatformGameMapping)
|
||||||
|
v := &server.DB_ThirdPlatformGameMapping{
|
||||||
|
Id: 1,
|
||||||
|
SystemGameID: 9010001,
|
||||||
|
ThirdPlatformName: "测试平台",
|
||||||
|
ThirdGameID: "901",
|
||||||
|
Desc: "",
|
||||||
|
ScreenOrientationType: 0,
|
||||||
|
ThirdID: 901,
|
||||||
|
}
|
||||||
|
this.GamefreeIdMappingMap[v.GetSystemGameID()] = v
|
||||||
|
rawMappingInfo[v.GetSystemGameID()] = &webapi.WebAPI_ThirdPlatformGameMapping{
|
||||||
|
GameFreeID: v.GetSystemGameID(),
|
||||||
|
ThirdPlatformName: v.GetThirdPlatformName(),
|
||||||
|
ThirdGameID: v.GetThirdGameID(),
|
||||||
|
Desc: v.GetDesc(),
|
||||||
|
ScreenOrientationType: v.GetScreenOrientationType(),
|
||||||
|
ThirdID: v.GetThirdID(),
|
||||||
|
}
|
||||||
|
|
||||||
|
webapi.ThridPlatformMgrSington.ThridPlatformMap.Range(func(key, value interface{}) bool {
|
||||||
|
value.(webapi.IThirdPlatform).InitMappingRelation(rawMappingInfo)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ThirdPlatformGameMappingConfiguration) FindByGameID(gamefreeId int32) *server.DB_ThirdPlatformGameMapping {
|
||||||
|
return this.GamefreeIdMappingMap[gamefreeId]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 包含dg的查询
|
||||||
|
func (this *ThirdPlatformGameMappingConfiguration) FindSystemGamefreeidByThirdGameInfo(thirdPlt string, inThirdGameId, inThirdGameName string) (gamefreeid int32) {
|
||||||
|
if v, exist := webapi.ThridPlatformMgrSington.ThridPlatformMap.Load(thirdPlt); exist {
|
||||||
|
return v.(webapi.IThirdPlatform).ThirdGameInfo2GamefreeId(&webapi.WebAPI_ThirdPlatformGameMapping{
|
||||||
|
ThirdPlatformName: thirdPlt,
|
||||||
|
ThirdGameID: inThirdGameId,
|
||||||
|
Desc: inThirdGameName,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
func (this *ThirdPlatformGameMappingConfiguration) FindThirdIdByThird(thirdName string) (thirdId int32) {
|
||||||
|
if v, exist := webapi.ThridPlatformMgrSington.ThridPlatformMap.Load(thirdName); exist {
|
||||||
|
if plt, ok := v.(webapi.IThirdPlatform); ok {
|
||||||
|
return int32(plt.GetPlatformBase().BaseGameID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
func (this *ThirdPlatformGameMappingConfiguration) FindThirdInfoBySystemGameId(systemGameId int32) (*server.DB_ThirdPlatformGameMapping, webapi.IThirdPlatform) {
|
||||||
|
info := this.FindByGameID(systemGameId)
|
||||||
|
if info != nil {
|
||||||
|
if v, exist := webapi.ThridPlatformMgrSington.ThridPlatformMap.Load(info.ThirdPlatformName); exist {
|
||||||
|
if plt, ok := v.(webapi.IThirdPlatform); ok {
|
||||||
|
return info, plt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
srvdata.DataMgr.RegisterLoader("DB_ThirdPlatformGameMapping.dat", ThirdPltGameMappingConfig)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,252 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"mongo.games.com/game/model"
|
||||||
|
"mongo.games.com/goserver/core/basic"
|
||||||
|
"mongo.games.com/goserver/core/logger"
|
||||||
|
"mongo.games.com/goserver/core/module"
|
||||||
|
"mongo.games.com/goserver/core/task"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ThirdPlatformMgrSington = &ThirdPlatformMgr{
|
||||||
|
Platforms: make(map[string]*PlatformOfThirdPlatform),
|
||||||
|
}
|
||||||
|
|
||||||
|
type PlatformOfThirdPlatform struct {
|
||||||
|
*model.PlatformOfThirdPlatform
|
||||||
|
dirty bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *PlatformOfThirdPlatform) AddCoin(platform string, coin int64) {
|
||||||
|
if this.ThdPlatform == nil {
|
||||||
|
this.ThdPlatform = make(map[string]*model.ThirdPlatform)
|
||||||
|
}
|
||||||
|
if this.ThdPlatform != nil {
|
||||||
|
if tpp, exist := this.ThdPlatform[strings.ToLower(platform)]; exist {
|
||||||
|
tpp.Coin += coin
|
||||||
|
|
||||||
|
this.dirty = true
|
||||||
|
} else {
|
||||||
|
this.ThdPlatform[strings.ToLower(platform)] = &model.ThirdPlatform{
|
||||||
|
Coin: coin,
|
||||||
|
}
|
||||||
|
this.dirty = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *PlatformOfThirdPlatform) AddNextCoin(platform string, coin int64) {
|
||||||
|
if this.ThdPlatform == nil {
|
||||||
|
this.ThdPlatform = make(map[string]*model.ThirdPlatform)
|
||||||
|
}
|
||||||
|
if this.ThdPlatform != nil {
|
||||||
|
if tpp, exist := this.ThdPlatform[strings.ToLower(platform)]; exist {
|
||||||
|
tpp.NextCoin += coin
|
||||||
|
|
||||||
|
this.dirty = true
|
||||||
|
} else {
|
||||||
|
this.ThdPlatform[strings.ToLower(platform)] = &model.ThirdPlatform{
|
||||||
|
NextCoin: coin,
|
||||||
|
}
|
||||||
|
this.dirty = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *PlatformOfThirdPlatform) SetCoin(platform string, coin int64) {
|
||||||
|
if this.ThdPlatform == nil {
|
||||||
|
this.ThdPlatform = make(map[string]*model.ThirdPlatform)
|
||||||
|
}
|
||||||
|
if this.ThdPlatform != nil {
|
||||||
|
if tpp, exist := this.ThdPlatform[strings.ToLower(platform)]; exist {
|
||||||
|
tpp.Coin = coin
|
||||||
|
this.dirty = true
|
||||||
|
} else {
|
||||||
|
this.ThdPlatform[strings.ToLower(platform)] = &model.ThirdPlatform{
|
||||||
|
Coin: coin,
|
||||||
|
}
|
||||||
|
this.dirty = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *PlatformOfThirdPlatform) SetNextCoin(platform string, coin int64) {
|
||||||
|
if this.ThdPlatform == nil {
|
||||||
|
this.ThdPlatform = make(map[string]*model.ThirdPlatform)
|
||||||
|
}
|
||||||
|
if this.ThdPlatform != nil {
|
||||||
|
if tpp, exist := this.ThdPlatform[strings.ToLower(platform)]; exist {
|
||||||
|
tpp.NextCoin = coin
|
||||||
|
this.dirty = true
|
||||||
|
} else {
|
||||||
|
this.ThdPlatform[strings.ToLower(platform)] = &model.ThirdPlatform{
|
||||||
|
NextCoin: coin,
|
||||||
|
}
|
||||||
|
this.dirty = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *PlatformOfThirdPlatform) GetCoin(platform string) int64 {
|
||||||
|
if this.ThdPlatform != nil {
|
||||||
|
if tpp, exist := this.ThdPlatform[strings.ToLower(platform)]; exist {
|
||||||
|
return tpp.Coin
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *PlatformOfThirdPlatform) GetNextCoin(platform string) int64 {
|
||||||
|
if this.ThdPlatform != nil {
|
||||||
|
if tpp, exist := this.ThdPlatform[strings.ToLower(platform)]; exist {
|
||||||
|
return tpp.NextCoin
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *PlatformOfThirdPlatform) Clone() *PlatformOfThirdPlatform {
|
||||||
|
var ptp PlatformOfThirdPlatform
|
||||||
|
data, err := json.Marshal(this)
|
||||||
|
if err == nil {
|
||||||
|
err = json.Unmarshal(data, &ptp)
|
||||||
|
if err == nil {
|
||||||
|
return &ptp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type ThirdPlatformMgr struct {
|
||||||
|
BaseClockSinker
|
||||||
|
Platforms map[string]*PlatformOfThirdPlatform
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ThirdPlatformMgr) InitData() {
|
||||||
|
platformList, err := model.GetAllThirdPlatform()
|
||||||
|
if err != nil {
|
||||||
|
logger.Logger.Error("InitData count failed:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < len(platformList); i++ {
|
||||||
|
p := &platformList[i]
|
||||||
|
if p != nil {
|
||||||
|
this.Platforms[p.Platform] = &PlatformOfThirdPlatform{PlatformOfThirdPlatform: p}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ThirdPlatformMgr) AddPlatform(platform string) *PlatformOfThirdPlatform {
|
||||||
|
ptp := &PlatformOfThirdPlatform{
|
||||||
|
PlatformOfThirdPlatform: model.NewThirdPlatform(platform),
|
||||||
|
}
|
||||||
|
this.Platforms[platform] = ptp
|
||||||
|
return ptp
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ThirdPlatformMgr) InsertPlatform(platform *PlatformOfThirdPlatform) {
|
||||||
|
if platform != nil {
|
||||||
|
pCopy := platform.Clone()
|
||||||
|
if pCopy != nil {
|
||||||
|
platform.dirty = false
|
||||||
|
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||||||
|
return model.InsertThirdPlatform(pCopy.PlatformOfThirdPlatform)
|
||||||
|
}), nil, "UpdateThirdPlatform").StartByFixExecutor("ThirdPlatform")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ThirdPlatformMgr) GetThirdPlatform(platform string) *PlatformOfThirdPlatform {
|
||||||
|
if p, exist := this.Platforms[platform]; exist && p != nil {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ThirdPlatformMgr) GetThirdPlatformCoin(platform, thirdPlatform string) int64 {
|
||||||
|
p := this.GetThirdPlatform(platform)
|
||||||
|
if p != nil {
|
||||||
|
return p.GetCoin(thirdPlatform)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ThirdPlatformMgr) AddThirdPlatformCoin(platform, thirdPlatform string, coin int64) bool {
|
||||||
|
p := this.GetThirdPlatform(platform)
|
||||||
|
if p != nil {
|
||||||
|
p.AddCoin(thirdPlatform, coin)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ThirdPlatformMgr) ModuleName() string {
|
||||||
|
return "ThirdPlatformMgr"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ThirdPlatformMgr) Init() {
|
||||||
|
this.InitData()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ThirdPlatformMgr) Update() {
|
||||||
|
this.SaveAll(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ThirdPlatformMgr) Shutdown() {
|
||||||
|
this.SaveAll(true)
|
||||||
|
module.UnregisteModule(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 感兴趣所有clock event
|
||||||
|
func (this *ThirdPlatformMgr) InterestClockEvent() int {
|
||||||
|
return 1 << CLOCK_EVENT_MONTH
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ThirdPlatformMgr) OnMonthTimer() {
|
||||||
|
for _, p := range this.Platforms {
|
||||||
|
if p != nil {
|
||||||
|
p.dirty = true
|
||||||
|
for _, thr := range p.ThdPlatform {
|
||||||
|
if thr != nil {
|
||||||
|
if thr.Coin > thr.NextCoin {
|
||||||
|
thr.Coin = thr.NextCoin
|
||||||
|
} else {
|
||||||
|
thr.NextCoin = thr.Coin
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.SaveAll(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ThirdPlatformMgr) SaveAll(bImm bool) {
|
||||||
|
for _, p := range this.Platforms {
|
||||||
|
if p != nil && p.dirty {
|
||||||
|
pCopy := p.Clone()
|
||||||
|
if pCopy != nil {
|
||||||
|
if bImm {
|
||||||
|
err := model.UpdateThirdPlatform(pCopy.PlatformOfThirdPlatform)
|
||||||
|
if err != nil {
|
||||||
|
logger.Logger.Warnf("UpdateThirdPlatform err:%v", err)
|
||||||
|
} else {
|
||||||
|
p.dirty = false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
p.dirty = false
|
||||||
|
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||||||
|
return model.UpdateThirdPlatform(pCopy.PlatformOfThirdPlatform)
|
||||||
|
}), nil, "UpdateThirdPlatform").StartByFixExecutor("ThirdPlatform")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
//module.RegisteModule(ThirdPlatformMgrSington, time.Minute*5, 0)
|
||||||
|
//ClockMgrSington.RegisteSinker(ThirdPlatformMgrSington)
|
||||||
|
}
|
||||||
|
|
@ -142,7 +142,12 @@ func (tm *TmMatch) CreateRobotGrades(round int) {
|
||||||
}
|
}
|
||||||
if player != nil && player.IsRob {
|
if player != nil && player.IsRob {
|
||||||
snids = append(snids, player.SnId)
|
snids = append(snids, player.SnId)
|
||||||
lvs = append(lvs, 1)
|
ms := MatchSeasonMgrSington.GetMatchSeason(player.SnId)
|
||||||
|
lv := MatchSeasonRankMgrSington.CreateRobotLv()
|
||||||
|
if ms != nil {
|
||||||
|
lv = ms.Lv
|
||||||
|
}
|
||||||
|
lvs = append(lvs, lv)
|
||||||
roleId := int32(2000001)
|
roleId := int32(2000001)
|
||||||
if player.Roles != nil && player.Roles.ModId != 0 {
|
if player.Roles != nil && player.Roles.ModId != 0 {
|
||||||
roleId = player.Roles.ModId
|
roleId = player.Roles.ModId
|
||||||
|
|
@ -162,7 +167,8 @@ func (tm *TmMatch) CreateRobotGrades(round int) {
|
||||||
tmpSnid = rand.Int31n(max-min) + min
|
tmpSnid = rand.Int31n(max-min) + min
|
||||||
}
|
}
|
||||||
snids = append(snids, tmpSnid)
|
snids = append(snids, tmpSnid)
|
||||||
lvs = append(lvs, 1)
|
lv := MatchSeasonRankMgrSington.CreateRobotLv()
|
||||||
|
lvs = append(lvs, lv)
|
||||||
roleIds = append(roleIds, int32(2000001))
|
roleIds = append(roleIds, int32(2000001))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -728,12 +728,17 @@ func (this *Tournament) GetTm(sortId int64) *TmMatch {
|
||||||
|
|
||||||
// CreatePlayerMatchContext 创建玩家比赛信息
|
// CreatePlayerMatchContext 创建玩家比赛信息
|
||||||
func (this *Tournament) CreatePlayerMatchContext(p *Player, m *TmMatch, seq int) *PlayerMatchContext {
|
func (this *Tournament) CreatePlayerMatchContext(p *Player, m *TmMatch, seq int) *PlayerMatchContext {
|
||||||
|
ms := MatchSeasonMgrSington.GetMatchSeason(p.SnId)
|
||||||
|
var lv int32
|
||||||
|
if ms != nil {
|
||||||
|
lv = ms.Lv
|
||||||
|
}
|
||||||
roleId := int32(2000001)
|
roleId := int32(2000001)
|
||||||
if p.Roles != nil {
|
if p.Roles != nil {
|
||||||
roleId = p.Roles.ModId
|
roleId = p.Roles.ModId
|
||||||
}
|
}
|
||||||
|
|
||||||
mc := NewMatchContext(p, m, 1000, p.SnId, 1, roleId, seq)
|
mc := NewMatchContext(p, m, 1000, p.SnId, lv, roleId, seq)
|
||||||
if mc != nil {
|
if mc != nil {
|
||||||
if this.players[m.SortId] == nil {
|
if this.players[m.SortId] == nil {
|
||||||
this.players[m.SortId] = make(map[int32]*PlayerMatchContext)
|
this.players[m.SortId] = make(map[int32]*PlayerMatchContext)
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"mongo.games.com/game/model"
|
"mongo.games.com/game/model"
|
||||||
"mongo.games.com/game/proto"
|
"mongo.games.com/game/proto"
|
||||||
"mongo.games.com/game/protocol/bag"
|
"mongo.games.com/game/protocol/bag"
|
||||||
|
"mongo.games.com/game/protocol/gamehall"
|
||||||
loginproto "mongo.games.com/game/protocol/login"
|
loginproto "mongo.games.com/game/protocol/login"
|
||||||
playerproto "mongo.games.com/game/protocol/player"
|
playerproto "mongo.games.com/game/protocol/player"
|
||||||
"mongo.games.com/game/protocol/qpapi"
|
"mongo.games.com/game/protocol/qpapi"
|
||||||
|
|
@ -33,6 +34,7 @@ import (
|
||||||
"mongo.games.com/game/protocol/telegramapi"
|
"mongo.games.com/game/protocol/telegramapi"
|
||||||
webapiproto "mongo.games.com/game/protocol/webapi"
|
webapiproto "mongo.games.com/game/protocol/webapi"
|
||||||
"mongo.games.com/game/srvdata"
|
"mongo.games.com/game/srvdata"
|
||||||
|
"mongo.games.com/game/webapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -4022,7 +4024,202 @@ func init() {
|
||||||
return common.ResponseTag_TransactYield, pack
|
return common.ResponseTag_TransactYield, pack
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
//更新用户三方的金币到游戏服务器
|
||||||
|
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/thd/UpdatePlayerCoin", WebAPIHandlerWrapper(
|
||||||
|
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||||||
|
msg := &webapiproto.ASThdUpdatePlayerCoin{}
|
||||||
|
pack := &webapiproto.SAThdUpdatePlayerCoin{}
|
||||||
|
err := proto.Unmarshal(params, msg)
|
||||||
|
if err != nil {
|
||||||
|
pack.Tag = webapiproto.TagCode_FAILED
|
||||||
|
pack.Msg = "数据序列化失败" + err.Error()
|
||||||
|
return common.ResponseTag_ParamError, pack
|
||||||
|
}
|
||||||
|
member_snid := msg.Snid
|
||||||
|
BaseGameId := int(msg.BaseGameID)
|
||||||
|
platform := msg.Platform
|
||||||
|
|
||||||
|
plt := webapi.ThridPlatformMgrSington.FindPlatformByPlatformBaseGameId(BaseGameId)
|
||||||
|
if plt == nil {
|
||||||
|
pack.Tag = webapiproto.TagCode_FAILED
|
||||||
|
pack.Msg = "三方不存在"
|
||||||
|
return common.ResponseTag_ParamError, pack
|
||||||
|
}
|
||||||
|
|
||||||
|
p := PlayerMgrSington.GetPlayerBySnId(int32(member_snid))
|
||||||
|
|
||||||
|
if p != nil {
|
||||||
|
if len(platform) > 0 && p.Platform != platform {
|
||||||
|
pack.Tag = webapiproto.TagCode_FAILED
|
||||||
|
pack.Msg = "Platform is err."
|
||||||
|
return common.ResponseTag_ParamError, pack
|
||||||
|
}
|
||||||
|
//请求太快,不做处理,给API减轻一些压力
|
||||||
|
if p.thridBalanceRefreshReqing {
|
||||||
|
pack.Tag = webapiproto.TagCode_FAILED
|
||||||
|
pack.Msg = "刷新频率太高,稍等"
|
||||||
|
return common.ResponseTag_ParamError, pack
|
||||||
|
}
|
||||||
|
|
||||||
|
p.thridBalanceRefreshReqing = true
|
||||||
|
gainway := common.GainWay_Transfer_Thrid2System
|
||||||
|
//isSucces := true
|
||||||
|
timeout := false
|
||||||
|
timeStamp := time.Now().UnixNano()
|
||||||
|
noBaseGameId := false
|
||||||
|
pfConfig := PlatformMgrSingleton.GetPlatform(p.Platform)
|
||||||
|
if pfConfig != nil {
|
||||||
|
if pfConfig.ThirdGameMerchant == nil || pfConfig.ThirdGameMerchant[int32(plt.GetPlatformBase().BaseGameID)] == 0 {
|
||||||
|
// noBaseGameId = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
||||||
|
var err error
|
||||||
|
var coinLog *model.PayCoinLog
|
||||||
|
var coinlogex *model.CoinLog
|
||||||
|
//var apiHasTransfer = false
|
||||||
|
remark := "手动刷新" + plt.GetPlatformBase().Name + "转出到系统"
|
||||||
|
amount := int64(0)
|
||||||
|
|
||||||
|
if pfConfig == nil {
|
||||||
|
return int64(-2)
|
||||||
|
}
|
||||||
|
|
||||||
|
if noBaseGameId {
|
||||||
|
return int64(-3)
|
||||||
|
}
|
||||||
|
|
||||||
|
oper := plt.GetPlatformBase().Name + "2System"
|
||||||
|
err, amount = plt.ReqLeaveGame(p.SnId, fmt.Sprintf("%v", BaseGameId), p.Ip, p.Platform, p.Channel)
|
||||||
|
if err != nil {
|
||||||
|
goto Rollback
|
||||||
|
}
|
||||||
|
if amount <= 0 {
|
||||||
|
return int64(-4)
|
||||||
|
}
|
||||||
|
if plt.GetPlatformBase().TransferInteger {
|
||||||
|
amount = (amount / 100) * 100
|
||||||
|
if amount <= 0 {
|
||||||
|
return int64(-4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//apiHasTransfer = true
|
||||||
|
coinLog = model.NewPayCoinLog(time.Now().UnixNano(), int32(p.SnId), amount, int32(gainway), oper, model.PayCoinLogType_Coin, 0)
|
||||||
|
|
||||||
|
// err = model.InsertPayCoinLogs(coinLog)
|
||||||
|
err = model.InsertPayCoinLogs(p.Platform, coinLog)
|
||||||
|
if err != nil {
|
||||||
|
logger.Logger.Tracef("player snid=%v at %v model.InsertPayCoinLogs() err: %v", p.SnId, plt.GetPlatformBase().Name, err)
|
||||||
|
goto Rollback
|
||||||
|
}
|
||||||
|
timeStamp = coinLog.TimeStamp
|
||||||
|
coinlogex = model.NewCoinLogEx(&model.CoinLogParam{
|
||||||
|
Platform: p.Platform,
|
||||||
|
SnID: p.SnId,
|
||||||
|
ChangeType: common.BillTypeCoin,
|
||||||
|
ChangeNum: amount,
|
||||||
|
RemainNum: p.Coin + amount,
|
||||||
|
Add: 0,
|
||||||
|
LogType: int32(gainway),
|
||||||
|
GameID: 0,
|
||||||
|
GameFreeID: 0,
|
||||||
|
BaseCoin: 0,
|
||||||
|
Operator: oper,
|
||||||
|
Remark: remark,
|
||||||
|
})
|
||||||
|
err = model.InsertCoinLog(coinlogex)
|
||||||
|
if err != nil {
|
||||||
|
logger.Logger.Tracef("player snid=%v at %v model.InsertCoinLogs() err: %v", p.SnId, plt.GetPlatformBase().Name, err)
|
||||||
|
goto Rollback
|
||||||
|
}
|
||||||
|
return amount
|
||||||
|
Rollback:
|
||||||
|
if coinLog != nil {
|
||||||
|
|
||||||
|
model.RemovePayCoinLog(p.Platform, coinLog.LogId)
|
||||||
|
}
|
||||||
|
if coinlogex != nil {
|
||||||
|
model.RemoveCoinLogOne(coinlogex.Platform, coinlogex.LogId)
|
||||||
|
}
|
||||||
|
if timeout {
|
||||||
|
logger.Logger.Errorf("web player snid=%v CSThridBalanceRefreshHandler transfer %v to %v timeout!", p.SnId, -amount, plt.GetPlatformBase().Name)
|
||||||
|
return int64(-1)
|
||||||
|
}
|
||||||
|
//if apiHasTransfer {
|
||||||
|
// err, timeout = plt.ReqTransfer(p.SnId, thirdBalance, strconv.FormatInt(time.Now().UnixNano(), 10), p.Platform, p.Channel)
|
||||||
|
// if timeout {
|
||||||
|
// logger.Logger.Errorf("web player snid=%v CSThridBalanceRefreshHandler transfer rollback %v to %v timeout!", p.SnId, thirdBalance, plt.GetPlatformBase().Name)
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
return int64(-1)
|
||||||
|
}), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) {
|
||||||
|
amount := data.(int64)
|
||||||
|
statePack := &gamehall.SCThridGameBalanceUpdateState{}
|
||||||
|
if amount < 0 {
|
||||||
|
pack.Tag = webapiproto.TagCode_FAILED
|
||||||
|
// return common.ResponseTag_ParamError, pack
|
||||||
|
pack.Msg = "刷新金币失败"
|
||||||
|
if amount == -3 {
|
||||||
|
pack.Msg = "三方关闭中"
|
||||||
|
}
|
||||||
|
statePack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Error_Game
|
||||||
|
p.thridBalanceReqIsSucces = false
|
||||||
|
//isSucces = false
|
||||||
|
logger.Logger.Tracef("player snid=%v at platform=%v CSThridBalanceRefreshHandler third->system transfer fail", p.SnId, plt.GetPlatformBase().Name)
|
||||||
|
} else if amount > 0 {
|
||||||
|
pack.Tag = webapiproto.TagCode_SUCCESS
|
||||||
|
pack.Msg = "刷新金币成功"
|
||||||
|
statePack.OpRetCode = gamehall.OpResultCode_Game_OPRC_Sucess_Game
|
||||||
|
p.thridBalanceReqIsSucces = true
|
||||||
|
|
||||||
|
p.Coin += amount
|
||||||
|
p.SetPayTs(timeStamp)
|
||||||
|
ThirdPlatformMgrSington.AddThirdPlatformCoin(p.Platform, plt.GetPlatformBase().Tag, amount)
|
||||||
|
p.dirty = true
|
||||||
|
logger.Logger.Tracef("player snid=%v at platform=%v CSThridBalanceRefreshHandler third->system transfer succes", p.SnId, plt.GetPlatformBase().Name)
|
||||||
|
//if !model.GameParamData.CloseOftenSavePlayerData {
|
||||||
|
// p.Time2Save()
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
p.diffData.Coin = -1
|
||||||
|
p.SendDiffData()
|
||||||
|
//statePack := &protocol.SCThridGameBalanceUpdateState{}
|
||||||
|
//pack := &protocol.SCThridGameBalanceUpdate{}
|
||||||
|
//if isSucces {
|
||||||
|
// pack.OpRetCode = protocol.OpResultCode_OPRC_Sucess.Enum()
|
||||||
|
// p.thridBalanceReqIsSucces = true
|
||||||
|
// statePack.OpRetCode = protocol.OpResultCode_OPRC_Sucess.Enum()
|
||||||
|
//}
|
||||||
|
|
||||||
|
p.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_THRIDGAMEBALANCEUPDATESTATE), statePack)
|
||||||
|
p.dirty = true
|
||||||
|
|
||||||
|
//pack.Coin = proto.Int64(p.Coin)
|
||||||
|
//p.SendToClient(int(protocol.MmoPacketID_PACKET_SC_THRIDGAMEBALANCEUPDATE), pack)
|
||||||
|
if p.thrscene != 0 {
|
||||||
|
p.thrscene = 0
|
||||||
|
p.scene = nil
|
||||||
|
}
|
||||||
|
p.thridBalanceRefreshReqing = false
|
||||||
|
logger.Logger.Tracef("SendToClient() player snid=%v at CSThridBalanceRefreshHandler() pack:%v", p.SnId, pack.String())
|
||||||
|
|
||||||
|
//dataResp := &common.M2GWebApiResponse{}
|
||||||
|
//dataResp.Body, _ = resp.Marshal()
|
||||||
|
tNode.TransRep.RetFiels = pack
|
||||||
|
tNode.Resume()
|
||||||
|
|
||||||
|
}), "ThrUpdatePlayerCoin").Start()
|
||||||
|
|
||||||
|
} else {
|
||||||
|
pack.Tag = webapiproto.TagCode_FAILED
|
||||||
|
pack.Msg = "暂不支持用户不在线刷新"
|
||||||
|
return common.ResponseTag_ParamError, pack
|
||||||
|
}
|
||||||
|
return common.ResponseTag_TransactYield, pack
|
||||||
|
}))
|
||||||
|
//支付回调
|
||||||
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/pay/CallbackPayment", WebAPIHandlerWrapper(
|
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/pay/CallbackPayment", WebAPIHandlerWrapper(
|
||||||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||||||
msg := &webapiproto.ASCallbackPayment{}
|
msg := &webapiproto.ASCallbackPayment{}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue