删除比赛场段位
This commit is contained in:
parent
c86e28383d
commit
489395ebb1
|
@ -1,203 +0,0 @@
|
|||
package api
|
||||
|
||||
//
|
||||
//import (
|
||||
// "encoding/json"
|
||||
// "io/ioutil"
|
||||
// "net/http"
|
||||
// "time"
|
||||
//
|
||||
// "crypto/md5"
|
||||
// "encoding/hex"
|
||||
// "fmt"
|
||||
// "mongo.games.com/game/common"
|
||||
// "mongo.games.com/game/model"
|
||||
// "mongo.games.com/game/webapi"
|
||||
// "mongo.games.com/goserver/core"
|
||||
// "mongo.games.com/goserver/core/admin"
|
||||
// "mongo.games.com/goserver/core/logger"
|
||||
// "mongo.games.com/goserver/core/netlib"
|
||||
// "mongo.games.com/goserver/core/transact"
|
||||
// "mongo.games.com/goserver/core/utils"
|
||||
// "io"
|
||||
// "sync/atomic"
|
||||
//)
|
||||
//
|
||||
//// API
|
||||
//// http://127.0.0.1:9595/api/Report/QueryOnlineReportList?ts=20141024000000&sign=41cc8cee8dd93f7dc70b6426cfd1029d
|
||||
//
|
||||
//func ActThrSrvApi(rw http.ResponseWriter, req *http.Request) {
|
||||
// defer utils.DumpStackIfPanic("api.ActThrSrvApi")
|
||||
// logger.Logger.Info("ActThrSrvApi receive:", req.URL.Path, req.URL.RawQuery)
|
||||
//
|
||||
// if common.RequestCheck(req, model.GameParamData.WhiteHttpAddr) == false {
|
||||
// logger.Logger.Info("RemoteAddr [%v] require api.", req.RemoteAddr)
|
||||
// return
|
||||
// }
|
||||
// data, err := io.ReadAll(req.Body)
|
||||
// if err != nil {
|
||||
// logger.Logger.Info("Body err.", err)
|
||||
// webApiResponse(rw, map[string]interface{}{webapi.RESPONSE_STATE: webapi.STATE_ERR, webapi.RESPONSE_ERRMSG: "Post data is null!"})
|
||||
// return
|
||||
// }
|
||||
// m := req.URL.Query()
|
||||
// timestamp := m.Get("nano")
|
||||
// if timestamp == "" {
|
||||
// logger.Logger.Info(req.RemoteAddr, " ActThrSrvApi param error: nano not allow null")
|
||||
// return
|
||||
// }
|
||||
// sign := m.Get("sign")
|
||||
// if sign == "" {
|
||||
// logger.Logger.Info(req.RemoteAddr, " ActThrSrvApi param error: sign not allow null")
|
||||
// return
|
||||
// }
|
||||
// startTime := time.Now().UnixNano()
|
||||
// args := fmt.Sprintf("%v;%v;%v;%v", common.Config.AppId, req.URL.Path, string(data), timestamp)
|
||||
// h := md5.New()
|
||||
// io.WriteString(h, args)
|
||||
// realSign := hex.EncodeToString(h.Sum(nil))
|
||||
// if realSign != sign && !common.Config.IsDevMode {
|
||||
// logger.Logger.Info(req.RemoteAddr, " srvCtrlMain sign error: expect ", realSign, " ; but get ", sign, " raw=", args)
|
||||
// webApiResponse(rw, map[string]interface{}{webapi.RESPONSE_STATE: webapi.STATE_ERR, webapi.RESPONSE_ERRMSG: "Sign error!"})
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// var stats *ApiStats
|
||||
// if v, exist := WebApiStats.Load(req.URL.Path); exist {
|
||||
// stats = v.(*ApiStats)
|
||||
// } else {
|
||||
// stats = &ApiStats{}
|
||||
// WebApiStats.Store(req.URL.Path, stats)
|
||||
// }
|
||||
// var rep map[string]interface{}
|
||||
// start := time.Now()
|
||||
// res := make(chan map[string]interface{}, 1)
|
||||
// core.CoreObject().SendCommand(&WebApiEvent{req: req, path: req.URL.Path, h: HandlerWrapper(func(event *WebApiEvent, data []byte) bool {
|
||||
// logger.Logger.Trace("ActThrSrvApi start transcate")
|
||||
// tnp := &transact.TransNodeParam{
|
||||
// Tt: common.TransType_ActThrSrvWebApi,
|
||||
// Ot: transact.TransOwnerType(common.GetSelfSrvType()),
|
||||
// Oid: common.GetSelfSrvId(),
|
||||
// AreaID: common.GetSelfAreaId(),
|
||||
// }
|
||||
// tNode := transact.DTCModule.StartTrans(tnp, event, transact.DefaultTransactTimeout) //超时时间30秒
|
||||
// if tNode != nil {
|
||||
// tNode.TransEnv.SetField(WEBAPI_TRANSACTE_EVENT, event)
|
||||
// tNode.Go(core.CoreObject())
|
||||
// }
|
||||
// return true
|
||||
// }), body: data, rawQuery: req.URL.RawQuery, res: res}, false)
|
||||
// select {
|
||||
// case rep = <-res:
|
||||
// if rep != nil {
|
||||
// webApiResponse(rw, rep)
|
||||
// }
|
||||
// case <-time.After(ApiDefaultTimeout):
|
||||
// rep = make(map[string]interface{})
|
||||
// rep[webapi.RESPONSE_STATE] = webapi.STATE_ERR
|
||||
// rep[webapi.RESPONSE_ERRMSG] = "proccess timeout!"
|
||||
// webApiResponse(rw, rep)
|
||||
// if stats != nil {
|
||||
// atomic.AddInt64(&stats.TimeoutTimes, 1)
|
||||
// }
|
||||
// }
|
||||
// ps := int64(time.Now().Sub(start) / time.Millisecond)
|
||||
// if stats != nil {
|
||||
// atomic.AddInt64(&stats.RunTimes, 1)
|
||||
// atomic.AddInt64(&stats.TotalRuningTime, ps)
|
||||
// if atomic.LoadInt64(&stats.MaxRuningTime) < ps {
|
||||
// atomic.StoreInt64(&stats.MaxRuningTime, ps)
|
||||
// }
|
||||
// }
|
||||
// result, err := json.Marshal(rep)
|
||||
// if err == nil {
|
||||
// log := model.NewAPILog(req.URL.Path, req.URL.RawQuery, string(data[:]), req.RemoteAddr, string(result[:]), startTime, ps)
|
||||
// APILogChannelSington.Write(log)
|
||||
// }
|
||||
// return
|
||||
//}
|
||||
//
|
||||
////--------------------------------------------------------------------------------------
|
||||
//func init() {
|
||||
// transact.RegisteHandler(common.TransType_ActThrSrvWebApi, &transact.TransHanderWrapper{
|
||||
// OnExecuteWrapper: transact.OnExecuteWrapper(func(tNode *transact.TransNode, ud interface{}) transact.TransExeResult {
|
||||
// logger.Logger.Trace("ActThrSrvApi start TransType_WebApi OnExecuteWrapper ")
|
||||
// tnp := &transact.TransNodeParam{
|
||||
// Tt: common.TransType_ActThrSrvWebApi,
|
||||
// Ot: transact.TransOwnerType(common.ActThrServerType),
|
||||
// Oid: common.ActThrServerID,
|
||||
// AreaID: common.GetSelfAreaId(),
|
||||
// Tct: transact.TransactCommitPolicy_TwoPhase,
|
||||
// }
|
||||
// if event, ok := ud.(*WebApiEvent); ok {
|
||||
// userData := &common.M2GWebApiRequest{Path: event.path, RawQuery: event.rawQuery, Body: event.body, ReqIp: event.req.RemoteAddr}
|
||||
// tNode.StartChildTrans(tnp, userData, transact.DefaultTransactTimeout)
|
||||
//
|
||||
// pid := tNode.MyTnp.TId
|
||||
// cid := tnp.TId
|
||||
// logger.Logger.Tracef("ActThrSrvApi start TransType_WebApi OnExecuteWrapper tid:%x childid:%x", pid, cid)
|
||||
// return transact.TransExeResult_Success
|
||||
// }
|
||||
// return transact.TransExeResult_Failed
|
||||
// }),
|
||||
// OnCommitWrapper: transact.OnCommitWrapper(func(tNode *transact.TransNode) transact.TransExeResult {
|
||||
// logger.Logger.Trace("ActThrSrvApi start TransType_WebApi OnCommitWrapper")
|
||||
// event := tNode.TransEnv.GetField(WEBAPI_TRANSACTE_EVENT).(*WebApiEvent)
|
||||
// resp := tNode.TransEnv.GetField(WEBAPI_TRANSACTE_RESPONSE)
|
||||
// if userData, ok := resp.(*common.M2GWebApiResponse); ok {
|
||||
// if len(userData.Body) > 0 {
|
||||
// m := make(map[string]interface{})
|
||||
// err := json.Unmarshal(userData.Body, &m)
|
||||
// if err == nil {
|
||||
// event.Response(m)
|
||||
// return transact.TransExeResult_Success
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// event.Response(map[string]interface{}{webapi.RESPONSE_STATE: webapi.STATE_ERR, webapi.RESPONSE_ERRMSG: "execute failed!"})
|
||||
// return transact.TransExeResult_Success
|
||||
// }),
|
||||
// OnRollBackWrapper: transact.OnRollBackWrapper(func(tNode *transact.TransNode) transact.TransExeResult {
|
||||
// logger.Logger.Trace("ActThrSrvApi start TransType_WebApi OnRollBackWrapper")
|
||||
// event := tNode.TransEnv.GetField(WEBAPI_TRANSACTE_EVENT).(*WebApiEvent)
|
||||
// resp := tNode.TransEnv.GetField(WEBAPI_TRANSACTE_RESPONSE)
|
||||
// if userData, ok := resp.(*common.M2GWebApiResponse); ok {
|
||||
// if len(userData.Body) > 0 {
|
||||
// m := make(map[string]interface{})
|
||||
// err := json.Unmarshal(userData.Body, &m)
|
||||
// if err == nil {
|
||||
// event.Response(m)
|
||||
// return transact.TransExeResult_Success
|
||||
// }
|
||||
// }
|
||||
// return transact.TransExeResult_Success
|
||||
// }
|
||||
// event.Response(map[string]interface{}{webapi.RESPONSE_STATE: webapi.STATE_ERR, webapi.RESPONSE_ERRMSG: "execute failed!"})
|
||||
// return transact.TransExeResult_Success
|
||||
// }),
|
||||
// OnChildRespWrapper: transact.OnChildRespWrapper(func(tNode *transact.TransNode, hChild transact.TransNodeID, retCode int, ud interface{}) transact.TransExeResult {
|
||||
// logger.Logger.Tracef("ActThrSrvApi start TransType_WebApi OnChildRespWrapper ret:%v childid:%x", retCode, hChild)
|
||||
// userData := &common.M2GWebApiResponse{}
|
||||
// err := netlib.UnmarshalPacketNoPackId(ud.([]byte), userData)
|
||||
// if err == nil {
|
||||
// tNode.TransEnv.SetField(WEBAPI_TRANSACTE_RESPONSE, userData)
|
||||
// } else {
|
||||
// logger.Logger.Trace("trascate.OnChildRespWrapper err:", err)
|
||||
// }
|
||||
// return transact.TransExeResult(retCode)
|
||||
// }),
|
||||
// })
|
||||
//
|
||||
// //测试
|
||||
// admin.MyAdminApp.Route("/api/ActThr/Test", ActThrSrvApi)
|
||||
//
|
||||
// //增加自动黑白名单控制
|
||||
// admin.MyAdminApp.Route("/api/ActThr/Upsert", ActThrSrvApi)
|
||||
//
|
||||
// //删除自动黑白名单控制
|
||||
// admin.MyAdminApp.Route("/api/ActThr/Delete", ActThrSrvApi)
|
||||
//
|
||||
// //删除所有添加的黑名单
|
||||
// admin.MyAdminApp.Route("/api/ActThr/ResetBW", ActThrSrvApi)
|
||||
//
|
||||
//}
|
|
@ -1,186 +0,0 @@
|
|||
package api
|
||||
|
||||
//
|
||||
//import (
|
||||
// "crypto/md5"
|
||||
// "encoding/hex"
|
||||
// "encoding/json"
|
||||
// "fmt"
|
||||
// "mongo.games.com/game/common"
|
||||
// "mongo.games.com/game/model"
|
||||
// "mongo.games.com/game/webapi"
|
||||
// "mongo.games.com/goserver/core"
|
||||
// "mongo.games.com/goserver/core/admin"
|
||||
// "mongo.games.com/goserver/core/logger"
|
||||
// "mongo.games.com/goserver/core/netlib"
|
||||
// "mongo.games.com/goserver/core/transact"
|
||||
// "mongo.games.com/goserver/core/utils"
|
||||
// "io"
|
||||
// "io/ioutil"
|
||||
// "net/http"
|
||||
// "time"
|
||||
//)
|
||||
//
|
||||
//const (
|
||||
// RANKSRVAPI_TRANSACTE_EVENT = "GAMESRVAPI_TRANSACTE_EVENT"
|
||||
// RANKSRVAPI_TRANSACTE_RESPONSE = "RANKSRVAPI_TRANSACTE_RESPONSE"
|
||||
//)
|
||||
//
|
||||
//// 处理 web 请求 rank server 相关的配置协议, 转发至 rank server 处理
|
||||
//
|
||||
//func RankSrvApi(rw http.ResponseWriter, req *http.Request) {
|
||||
// defer utils.DumpStackIfPanic("api.RankSrvApi")
|
||||
// logger.Logger.Info("RankSrvApi receive:", req.URL.Path, req.URL.RawQuery)
|
||||
//
|
||||
// if common.RequestCheck(req, model.GameParamData.WhiteHttpAddr) == false {
|
||||
// logger.Logger.Info("RemoteAddr [%v] require api.", req.RemoteAddr)
|
||||
// return
|
||||
// }
|
||||
// data, err := io.ReadAll(req.Body)
|
||||
// if err != nil {
|
||||
// logger.Logger.Info("Body err.", err)
|
||||
// webApiResponse(rw, map[string]interface{}{
|
||||
// webapi.RESPONSE_STATE: webapi.STATE_ERR,
|
||||
// webapi.RESPONSE_ERRMSG: "Post data is null!",
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
// logger.Logger.Info(string(data))
|
||||
// m := req.URL.Query()
|
||||
// timestamp := m.Get("nano")
|
||||
// if timestamp == "" {
|
||||
// logger.Logger.Info(req.RemoteAddr, " RankSrvApi param error: nano not allow null")
|
||||
// return
|
||||
// }
|
||||
// sign := m.Get("sign")
|
||||
// if sign == "" {
|
||||
// logger.Logger.Info(req.RemoteAddr, " RankSrvApi param error: sign not allow null")
|
||||
// return
|
||||
// }
|
||||
// startTime := time.Now().UnixNano()
|
||||
// args := fmt.Sprintf("%v;%v;%v;%v", common.Config.AppId, req.URL.Path, string(data), timestamp)
|
||||
// h := md5.New()
|
||||
// io.WriteString(h, args)
|
||||
// realSign := hex.EncodeToString(h.Sum(nil))
|
||||
// if realSign != sign && !common.Config.IsDevMode {
|
||||
// logger.Logger.Info(req.RemoteAddr, " srvCtrlMain sign error: expect ", realSign, " ; but get ", sign, " raw=", args)
|
||||
// webApiResponse(rw, map[string]interface{}{webapi.RESPONSE_STATE: webapi.STATE_ERR, webapi.RESPONSE_ERRMSG: "Sign error!"})
|
||||
// return
|
||||
// }
|
||||
// var rep map[string]interface{}
|
||||
// start := time.Now()
|
||||
// res := make(chan map[string]interface{}, 1)
|
||||
// core.CoreObject().SendCommand(&WebApiEvent{req: req, path: req.URL.Path, h: HandlerWrapper(func(event *WebApiEvent, data []byte) bool {
|
||||
// logger.Logger.Trace("RankSrvApi start transcate")
|
||||
// tnp := &transact.TransNodeParam{
|
||||
// Tt: common.TransType_WebApi_ForRank,
|
||||
// Ot: transact.TransOwnerType(common.GetSelfSrvType()),
|
||||
// Oid: common.GetSelfSrvId(),
|
||||
// AreaID: common.GetSelfAreaId(),
|
||||
// }
|
||||
// logger.Info("call info:", common.GetSelfAreaId(), common.GetSelfSrvType(), common.GetSelfSrvId())
|
||||
// tNode := transact.DTCModule.StartTrans(tnp, event, transact.DefaultTransactTimeout) //超时时间30秒
|
||||
// if tNode != nil {
|
||||
// tNode.TransEnv.SetField(RANKSRVAPI_TRANSACTE_EVENT, event)
|
||||
// tNode.Go(core.CoreObject())
|
||||
// }
|
||||
// return true
|
||||
// }), body: data, rawQuery: req.URL.RawQuery, res: res}, false)
|
||||
// select {
|
||||
// case rep = <-res:
|
||||
// if rep != nil {
|
||||
// webApiResponse(rw, rep)
|
||||
// }
|
||||
// case <-time.After(ApiDefaultTimeout):
|
||||
// rep = make(map[string]interface{})
|
||||
// rep[webapi.RESPONSE_STATE] = webapi.STATE_ERR
|
||||
// rep[webapi.RESPONSE_ERRMSG] = "proccess timeout!"
|
||||
// webApiResponse(rw, rep)
|
||||
// }
|
||||
// ps := int64(time.Now().Sub(start) / time.Millisecond)
|
||||
// result, err := json.Marshal(rep)
|
||||
// if err == nil {
|
||||
// log := model.NewAPILog(req.URL.Path, req.URL.RawQuery, string(data[:]), req.RemoteAddr, string(result[:]), startTime, ps)
|
||||
// APILogChannelSington.Write(log)
|
||||
// }
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//func init() {
|
||||
// transact.RegisteHandler(common.TransType_WebApi_ForRank, &transact.TransHanderWrapper{
|
||||
// OnExecuteWrapper: transact.OnExecuteWrapper(func(tNode *transact.TransNode, ud interface{}) transact.TransExeResult {
|
||||
// logger.Logger.Trace("RankSrvApi start TransType_WebApi_ForRank OnExecuteWrapper ")
|
||||
// tnp := &transact.TransNodeParam{
|
||||
// Tt: common.TransType_WebApi_ForRank,
|
||||
// Ot: transact.TransOwnerType(common.RankServerType),
|
||||
// Oid: common.GetRankSrvId(),
|
||||
// AreaID: common.GetSelfAreaId(),
|
||||
// Tct: transact.TransactCommitPolicy_TwoPhase,
|
||||
// }
|
||||
// logger.Infof("params: %+v", tnp)
|
||||
// if event, ok := ud.(*WebApiEvent); ok {
|
||||
// userData := &common.M2GWebApiRequest{Path: event.path, RawQuery: event.rawQuery, Body: event.body, ReqIp: event.req.RemoteAddr}
|
||||
// tNode.StartChildTrans(tnp, userData, transact.DefaultTransactTimeout)
|
||||
//
|
||||
// pid := tNode.MyTnp.TId
|
||||
// cid := tnp.TId
|
||||
// logger.Logger.Tracef("RankSrvApi start TransType_WebApi_ForRank OnExecuteWrapper tid:%x childid:%x", pid, cid)
|
||||
// return transact.TransExeResult_Success
|
||||
// }
|
||||
// return transact.TransExeResult_Failed
|
||||
// }),
|
||||
// OnCommitWrapper: transact.OnCommitWrapper(func(tNode *transact.TransNode) transact.TransExeResult {
|
||||
// logger.Logger.Trace("RankSrvApi start TransType_WebApi_ForRank OnCommitWrapper")
|
||||
// event := tNode.TransEnv.GetField(RANKSRVAPI_TRANSACTE_EVENT).(*WebApiEvent)
|
||||
// resp := tNode.TransEnv.GetField(RANKSRVAPI_TRANSACTE_RESPONSE)
|
||||
// if userData, ok := resp.(*common.M2GWebApiResponse); ok {
|
||||
// if len(userData.Body) > 0 {
|
||||
// m := make(map[string]interface{})
|
||||
// err := json.Unmarshal(userData.Body, &m)
|
||||
// if err == nil {
|
||||
// event.Response(m)
|
||||
// return transact.TransExeResult_Success
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// event.Response(map[string]interface{}{webapi.RESPONSE_STATE: webapi.STATE_ERR, webapi.RESPONSE_ERRMSG: "execute failed!"})
|
||||
// return transact.TransExeResult_Success
|
||||
// }),
|
||||
// OnRollBackWrapper: transact.OnRollBackWrapper(func(tNode *transact.TransNode) transact.TransExeResult {
|
||||
// logger.Logger.Trace("RankSrvApi start TransType_WebApi_ForRank OnRollBackWrapper")
|
||||
// event := tNode.TransEnv.GetField(RANKSRVAPI_TRANSACTE_EVENT).(*WebApiEvent)
|
||||
// resp := tNode.TransEnv.GetField(RANKSRVAPI_TRANSACTE_RESPONSE)
|
||||
// if userData, ok := resp.(*common.M2GWebApiResponse); ok {
|
||||
// if len(userData.Body) > 0 {
|
||||
// m := make(map[string]interface{})
|
||||
// err := json.Unmarshal(userData.Body, &m)
|
||||
// if err == nil {
|
||||
// event.Response(m)
|
||||
// return transact.TransExeResult_Success
|
||||
// }
|
||||
// }
|
||||
// return transact.TransExeResult_Success
|
||||
// }
|
||||
// event.Response(map[string]interface{}{webapi.RESPONSE_STATE: webapi.STATE_ERR, webapi.RESPONSE_ERRMSG: "execute failed!"})
|
||||
// return transact.TransExeResult_Success
|
||||
// }),
|
||||
// OnChildRespWrapper: transact.OnChildRespWrapper(func(tNode *transact.TransNode, hChild transact.TransNodeID, retCode int, ud interface{}) transact.TransExeResult {
|
||||
// logger.Logger.Tracef("RankSrvApi start TransType_WebApi_ForRank OnChildRespWrapper ret:%v childid:%x", retCode, hChild)
|
||||
// userData := &common.M2GWebApiResponse{}
|
||||
// err := netlib.UnmarshalPacketNoPackId(ud.([]byte), userData)
|
||||
// if err == nil {
|
||||
// tNode.TransEnv.SetField(RANKSRVAPI_TRANSACTE_RESPONSE, userData)
|
||||
// } else {
|
||||
// logger.Logger.Trace("trascate.OnChildRespWrapper err:", err)
|
||||
// }
|
||||
// return transact.TransExeResult(retCode)
|
||||
// }),
|
||||
// }) //RegisteHandler
|
||||
//
|
||||
// admin.MyAdminApp.Route("/api/rank/getConfig", RankSrvApi)
|
||||
// admin.MyAdminApp.Route("/api/rank/updateConfig", RankSrvApi)
|
||||
// admin.MyAdminApp.Route("/api/rank/debug/settings", RankSrvApi)
|
||||
// admin.MyAdminApp.Route("/api/rank/debug/board", RankSrvApi)
|
||||
// admin.MyAdminApp.Route("/api/rank/reset", RankSrvApi)
|
||||
// admin.MyAdminApp.Route("/api/rank/syncUser", RankSrvApi) // 同步主库玩家信息
|
||||
//}
|
|
@ -142,11 +142,6 @@ func (this *CSEnterRoomHandler) Process(s *netlib.Session, packetid int, data in
|
|||
if scene.IsMatchScene() && p.IsRob {
|
||||
grade := int32(1000)
|
||||
snid := p.SnId
|
||||
ms := MatchSeasonMgrSington.GetMatchSeason(snid) // 玩家赛季信息
|
||||
lv := MatchSeasonRankMgrSington.CreateRobotLv() //
|
||||
if ms != nil {
|
||||
lv = ms.Lv
|
||||
}
|
||||
roleId := int32(2000001)
|
||||
if p.Roles != nil {
|
||||
roleId = p.Roles.ModId
|
||||
|
@ -159,12 +154,11 @@ func (this *CSEnterRoomHandler) Process(s *netlib.Session, packetid int, data in
|
|||
randIndex := rand.Intn(len(tm.copyRobotGrades))
|
||||
grade = tm.copyRobotGrades[randIndex].grade
|
||||
snid = tm.copyRobotGrades[randIndex].copySnid
|
||||
lv = tm.copyRobotGrades[randIndex].copyLv
|
||||
roleId = tm.copyRobotGrades[randIndex].copyRoleId
|
||||
tm.copyRobotGrades = append(tm.copyRobotGrades[:randIndex], tm.copyRobotGrades[randIndex+1:]...)
|
||||
}
|
||||
}
|
||||
mc := NewMatchContext(p, tm, grade, snid, lv, roleId, 0)
|
||||
mc := NewMatchContext(p, tm, grade, snid, 1, roleId, 0)
|
||||
if mc != nil {
|
||||
mc.gaming = true
|
||||
p.matchCtx = mc
|
||||
|
|
|
@ -1,393 +0,0 @@
|
|||
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)
|
||||
}
|
|
@ -1,379 +0,0 @@
|
|||
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)
|
||||
}
|
|
@ -1597,7 +1597,6 @@ func (this *Player) OnLogouted() {
|
|||
|
||||
if !this.IsRob {
|
||||
FriendUnreadMgrSington.SaveFriendUnreadData(this.Platform, this.SnId)
|
||||
MatchSeasonMgrSington.SaveMatchSeasonData(this.SnId, true)
|
||||
}
|
||||
//平台数据
|
||||
//PlayerSingleAdjustMgr.DelPlayerData(this.Platform, this.SnId)
|
||||
|
|
|
@ -299,16 +299,10 @@ func (this *Scene) PlayerEnter(p *Player, pos int, ischangeroom bool) bool {
|
|||
if this.IsMatchScene() && p.matchCtx != nil {
|
||||
takeCoin = int64(p.matchCtx.grade)
|
||||
matchParams = append(matchParams, p.matchCtx.rank) //排名
|
||||
ms := MatchSeasonMgrSington.GetMatchSeason(p.SnId)
|
||||
if ms != nil {
|
||||
matchParams = append(matchParams, ms.Lv) //段位
|
||||
if p.IsRob {
|
||||
matchParams = append(matchParams, p.matchCtx.copyLv) //机器人随机段位
|
||||
} else {
|
||||
if p.IsRob {
|
||||
//robotRandLv := MatchSeasonRankMgrSington.CreateRobotLv()
|
||||
matchParams = append(matchParams, p.matchCtx.copyLv) //机器人随机段位
|
||||
} else {
|
||||
matchParams = append(matchParams, 1) //段位默认值
|
||||
}
|
||||
matchParams = append(matchParams, 1) //段位默认值
|
||||
}
|
||||
matchParams = append(matchParams, p.matchCtx.copySnid) //假snid
|
||||
matchParams = append(matchParams, p.matchCtx.copyRoleId) //假snid
|
||||
|
|
|
@ -1,129 +0,0 @@
|
|||
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)
|
||||
}
|
|
@ -1,252 +0,0 @@
|
|||
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,12 +142,7 @@ func (tm *TmMatch) CreateRobotGrades(round int) {
|
|||
}
|
||||
if player != nil && player.IsRob {
|
||||
snids = append(snids, player.SnId)
|
||||
ms := MatchSeasonMgrSington.GetMatchSeason(player.SnId)
|
||||
lv := MatchSeasonRankMgrSington.CreateRobotLv()
|
||||
if ms != nil {
|
||||
lv = ms.Lv
|
||||
}
|
||||
lvs = append(lvs, lv)
|
||||
lvs = append(lvs, 1)
|
||||
roleId := int32(2000001)
|
||||
if player.Roles != nil && player.Roles.ModId != 0 {
|
||||
roleId = player.Roles.ModId
|
||||
|
@ -167,8 +162,7 @@ func (tm *TmMatch) CreateRobotGrades(round int) {
|
|||
tmpSnid = rand.Int31n(max-min) + min
|
||||
}
|
||||
snids = append(snids, tmpSnid)
|
||||
lv := MatchSeasonRankMgrSington.CreateRobotLv()
|
||||
lvs = append(lvs, lv)
|
||||
lvs = append(lvs, 1)
|
||||
roleIds = append(roleIds, int32(2000001))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -728,17 +728,12 @@ func (this *Tournament) GetTm(sortId int64) *TmMatch {
|
|||
|
||||
// CreatePlayerMatchContext 创建玩家比赛信息
|
||||
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)
|
||||
if p.Roles != nil {
|
||||
roleId = p.Roles.ModId
|
||||
}
|
||||
|
||||
mc := NewMatchContext(p, m, 1000, p.SnId, lv, roleId, seq)
|
||||
mc := NewMatchContext(p, m, 1000, p.SnId, 1, roleId, seq)
|
||||
if mc != nil {
|
||||
if this.players[m.SortId] == nil {
|
||||
this.players[m.SortId] = make(map[int32]*PlayerMatchContext)
|
||||
|
|
|
@ -26,7 +26,6 @@ import (
|
|||
"mongo.games.com/game/model"
|
||||
"mongo.games.com/game/proto"
|
||||
"mongo.games.com/game/protocol/bag"
|
||||
"mongo.games.com/game/protocol/gamehall"
|
||||
loginproto "mongo.games.com/game/protocol/login"
|
||||
playerproto "mongo.games.com/game/protocol/player"
|
||||
"mongo.games.com/game/protocol/qpapi"
|
||||
|
@ -34,7 +33,6 @@ import (
|
|||
"mongo.games.com/game/protocol/telegramapi"
|
||||
webapiproto "mongo.games.com/game/protocol/webapi"
|
||||
"mongo.games.com/game/srvdata"
|
||||
"mongo.games.com/game/webapi"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -4024,202 +4022,7 @@ func init() {
|
|||
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(
|
||||
func(tNode *transact.TransNode, params []byte) (int, proto.Message) {
|
||||
msg := &webapiproto.ASCallbackPayment{}
|
||||
|
|
Loading…
Reference in New Issue