From 7d8eaee2c22524c19b5918f75a6f08490a422ce9 Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Thu, 26 Sep 2024 16:39:19 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AB=9E=E6=8A=80=E9=A6=86=E8=8E=B7=E5=A5=96?= =?UTF-8?q?=E5=81=87=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/broadcasthandler.go | 45 --------------- common/multicasthandler.go | 50 ----------------- gamesrv/action/action_server.go | 1 - gamesrv/base/playermgr.go | 22 ++------ gamesrv/base/scene.go | 22 ++------ gamesrv/base/scene_mgr.go | 18 +++--- gamesrv/fishing/scenedata_fishing.go | 24 ++++---- gatesrv/broadcasthandler.go | 24 -------- gatesrv/multicasthandler.go | 39 ------------- mgrsrv/api/broadcasthandler.go | 9 --- mgrsrv/api/webapi_srctrl.go | 38 +++++-------- model/gameparam.go | 8 +++ protocol/rank/rank.pb.go | 38 +++++++------ protocol/rank/rank.proto | 2 + ranksrv/com/etcd.go | 12 +++- ranksrv/com/logchannel.go | 53 ++++++++++++++++++ ranksrv/main.go | 1 + ranksrv/rank/customaward.go | 83 ++++++++++++++++++++++++++++ worldsrv/action_server.go | 3 - worldsrv/gamestate.go | 7 +-- worldsrv/platformmgr.go | 6 +- worldsrv/playermgr.go | 35 +++--------- worldsrv/scene.go | 7 +-- worldsrv/tmmatch.go | 7 +-- 24 files changed, 238 insertions(+), 316 deletions(-) delete mode 100644 common/broadcasthandler.go delete mode 100644 common/multicasthandler.go delete mode 100644 gatesrv/broadcasthandler.go delete mode 100644 gatesrv/multicasthandler.go delete mode 100644 mgrsrv/api/broadcasthandler.go create mode 100644 ranksrv/com/logchannel.go diff --git a/common/broadcasthandler.go b/common/broadcasthandler.go deleted file mode 100644 index 0922359..0000000 --- a/common/broadcasthandler.go +++ /dev/null @@ -1,45 +0,0 @@ -package common - -import ( - rawproto "google.golang.org/protobuf/proto" - "mongo.games.com/game/proto" - "mongo.games.com/goserver/core/logger" - "mongo.games.com/goserver/core/netlib" - "mongo.games.com/goserver/srvlib" - "mongo.games.com/goserver/srvlib/protocol" -) - -func RegisterBoardCastHandler() { - netlib.Register(int(protocol.SrvlibPacketID_PACKET_SS_BROADCAST), &protocol.SSPacketBroadcast{}, BroadcastHandler) -} - -func BroadcastHandler(s *netlib.Session, packetId int, data interface{}) error { - if bp, ok := data.(*protocol.SSPacketBroadcast); ok { - pd := bp.GetData() - sp := bp.GetSessParam() - if bcss := sp.GetBcss(); bcss != nil { - srvlib.ServerSessionMgrSington.Broadcast(int(bp.GetPacketId()), pd, int(bcss.GetSArea()), int(bcss.GetSType())) - } - } - return nil -} - -func CreateBroadcastPacket(sp *protocol.BCSessionUnion, packetId int, data interface{}) (rawproto.Message, error) { - pack := &protocol.SSPacketBroadcast{ - SessParam: sp, - PacketId: proto.Int(packetId), - } - - if byteData, ok := data.([]byte); ok { - pack.Data = byteData - } else { - byteData, err := netlib.MarshalPacket(packetId, data) - if err == nil { - pack.Data = byteData - } else { - logger.Logger.Warnf("CreateBroadcastPacket err:%v", err) - return nil, err - } - } - return pack, nil -} diff --git a/common/multicasthandler.go b/common/multicasthandler.go deleted file mode 100644 index 0a60453..0000000 --- a/common/multicasthandler.go +++ /dev/null @@ -1,50 +0,0 @@ -package common - -import ( - rawproto "google.golang.org/protobuf/proto" - "mongo.games.com/game/proto" - "mongo.games.com/goserver/core/logger" - "mongo.games.com/goserver/core/netlib" - "mongo.games.com/goserver/srvlib" - "mongo.games.com/goserver/srvlib/protocol" -) - -func RegisterMulticastHandler() { - netlib.Register(int(protocol.SrvlibPacketID_PACKET_SS_MULTICAST), &protocol.SSPacketMulticast{}, MulticastHandler) -} - -func MulticastHandler(s *netlib.Session, packetId int, data interface{}) error { - if mp, ok := data.(*protocol.SSPacketMulticast); ok { - pd := mp.GetData() - sis := mp.GetSessions() - for _, si := range sis { - ss := si.GetMcss() - if ss != nil { - ns := srvlib.ServerSessionMgrSington.GetSession(int(ss.GetSArea()), int(ss.GetSType()), int(ss.GetSId())) - if ns != nil { - ns.Send(int(mp.GetPacketId()), pd /*, s.GetSessionConfig().IsInnerLink*/) - } - } - } - } - return nil -} - -func CreateMulticastPacket(packetId int, data interface{}, sis ...*protocol.MCSessionUnion) (rawproto.Message, error) { - pack := &protocol.SSPacketMulticast{ - Sessions: sis, - PacketId: proto.Int(packetId), - } - if byteData, ok := data.([]byte); ok { - pack.Data = byteData - } else { - byteData, err := netlib.MarshalPacket(packetId, data) - if err == nil { - pack.Data = byteData - } else { - logger.Logger.Errorf("CreateMulticastPacket err:%v", err) - return nil, err - } - } - return pack, nil -} diff --git a/gamesrv/action/action_server.go b/gamesrv/action/action_server.go index 664ab9b..da40c47 100644 --- a/gamesrv/action/action_server.go +++ b/gamesrv/action/action_server.go @@ -561,7 +561,6 @@ func init() { return nil })) - common.RegisterMulticastHandler() // 玩家离开 //netlib.Register(int(server.SSPacketID_PACKET_WG_PlayerLEAVE), server.WGPlayerLeave{}, HandleWGPlayerLeave) // 同步记牌器过期时间 diff --git a/gamesrv/base/playermgr.go b/gamesrv/base/playermgr.go index 3db0744..c0b35e5 100644 --- a/gamesrv/base/playermgr.go +++ b/gamesrv/base/playermgr.go @@ -1,15 +1,15 @@ package base import ( - server_proto "mongo.games.com/game/protocol/server" "time" - "mongo.games.com/game/common" "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/module" "mongo.games.com/goserver/core/netlib" "mongo.games.com/goserver/srvlib" - "mongo.games.com/goserver/srvlib/protocol" + + "mongo.games.com/game/common" + serverproto "mongo.games.com/game/protocol/server" ) var PlayerMgrSington = &PlayerMgr{ @@ -154,20 +154,8 @@ func (this *PlayerMgr) GetPlayerByAccount(acc string) *Player { // return nil //} -func (this *PlayerMgr) BroadcastMessage(packetid int, rawpack interface{}) bool { - sc := &protocol.BCSessionUnion{ - Bccs: &protocol.BCClientSession{}, - } - pack, err := common.CreateBroadcastPacket(sc, packetid, rawpack) - if err == nil && pack != nil { - srvlib.ServerSessionMgrSington.Broadcast(int(protocol.SrvlibPacketID_PACKET_SS_BROADCAST), pack, common.GetSelfAreaId(), srvlib.GateServerType) - return true - } - return false -} - func (this *PlayerMgr) BroadcastMessageToGroup(packetid int, rawpack interface{}, tags []string) bool { - pack := &server_proto.SSCustomTagMulticast{ + pack := &serverproto.SSCustomTagMulticast{ Tags: tags, } if byteData, ok := rawpack.([]byte); ok { @@ -181,7 +169,7 @@ func (this *PlayerMgr) BroadcastMessageToGroup(packetid int, rawpack interface{} return false } } - srvlib.ServerSessionMgrSington.Broadcast(int(server_proto.SSPacketID_PACKET_SS_CUSTOMTAG_MULTICAST), pack, common.GetSelfAreaId(), srvlib.GateServerType) + srvlib.ServerSessionMgrSington.Broadcast(int(serverproto.SSPacketID_PACKET_SS_CUSTOMTAG_MULTICAST), pack, common.GetSelfAreaId(), srvlib.GateServerType) return true } diff --git a/gamesrv/base/scene.go b/gamesrv/base/scene.go index 7ee4f14..194322c 100644 --- a/gamesrv/base/scene.go +++ b/gamesrv/base/scene.go @@ -4,15 +4,14 @@ import ( "fmt" "math" "math/rand" - "mongo.games.com/game/protocol/webapi" "strconv" "time" rawproto "google.golang.org/protobuf/proto" - "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/netlib" "mongo.games.com/goserver/core/utils" + "mongo.games.com/goserver/srvlib/action" srvlibproto "mongo.games.com/goserver/srvlib/protocol" "mongo.games.com/game/common" @@ -21,6 +20,7 @@ import ( "mongo.games.com/game/protocol/gamehall" "mongo.games.com/game/protocol/player" "mongo.games.com/game/protocol/server" + "mongo.games.com/game/protocol/webapi" "mongo.games.com/game/srvdata" ) @@ -716,11 +716,7 @@ func (this *Scene) Broadcast(packetid int, msg rawproto.Message, excludeSid int6 } for gateSess, v := range mgs { if gateSess != nil && len(v) != 0 { - pack, err := common.CreateMulticastPacket(packetid, msg, v...) - if err == nil { - proto.SetDefaults(pack) - gateSess.Send(int(srvlibproto.SrvlibPacketID_PACKET_SS_MULTICAST), pack) - } + action.MulticastMessageToServer(gateSess, packetid, msg, v...) } } } @@ -740,11 +736,7 @@ func (this *Scene) RobotBroadcast(packetid int, msg rawproto.Message) { } for gateSess, v := range mgs { if gateSess != nil && len(v) != 0 { - pack, err := common.CreateMulticastPacket(packetid, msg, v...) - if err == nil { - proto.SetDefaults(pack) - gateSess.Send(int(srvlibproto.SrvlibPacketID_PACKET_SS_MULTICAST), pack) - } + action.MulticastMessageToServer(gateSess, packetid, msg, v...) } } } @@ -765,11 +757,7 @@ func (this *Scene) BroadcastToAudience(packetid int, msg rawproto.Message) { } for gateSess, v := range mgs { if gateSess != nil && len(v) != 0 { - pack, err := common.CreateMulticastPacket(packetid, msg, v...) - if err == nil { - proto.SetDefaults(pack) - gateSess.Send(int(srvlibproto.SrvlibPacketID_PACKET_SS_MULTICAST), pack) - } + action.MulticastMessageToServer(gateSess, packetid, msg, v...) } } } diff --git a/gamesrv/base/scene_mgr.go b/gamesrv/base/scene_mgr.go index 403251e..5b95bd8 100644 --- a/gamesrv/base/scene_mgr.go +++ b/gamesrv/base/scene_mgr.go @@ -1,16 +1,18 @@ package base import ( - "mongo.games.com/game/common" - "mongo.games.com/game/proto" - "mongo.games.com/game/protocol/gamehall" - "mongo.games.com/game/protocol/server" - srvlibproto "mongo.games.com/goserver/srvlib/protocol" "time" "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/module" "mongo.games.com/goserver/core/netlib" + "mongo.games.com/goserver/srvlib/action" + srvlibproto "mongo.games.com/goserver/srvlib/protocol" + + "mongo.games.com/game/common" + "mongo.games.com/game/proto" + "mongo.games.com/game/protocol/gamehall" + "mongo.games.com/game/protocol/server" ) var SceneMgrSington = &SceneMgr{ @@ -142,11 +144,7 @@ func (this *SceneMgr) JackPotSync(platform string, gameIds ...int32) { for gateSess, v := range mgs { if gateSess != nil && len(v) != 0 { - cPack, err := common.CreateMulticastPacket(int(gamehall.HundredScenePacketID_PACKET_SC_GAMEJACKPOT), pack, v...) - if err == nil { - proto.SetDefaults(cPack) - gateSess.Send(int(srvlibproto.SrvlibPacketID_PACKET_SS_MULTICAST), cPack) - } + action.MulticastMessageToServer(gateSess, int(gamehall.HundredScenePacketID_PACKET_SC_GAMEJACKPOT), pack, v...) } } } diff --git a/gamesrv/fishing/scenedata_fishing.go b/gamesrv/fishing/scenedata_fishing.go index a0afbab..6840842 100644 --- a/gamesrv/fishing/scenedata_fishing.go +++ b/gamesrv/fishing/scenedata_fishing.go @@ -2,25 +2,27 @@ package fishing import ( "fmt" - "github.com/cihub/seelog" "math" "math/rand" - "mongo.games.com/game/gamesrv/base" - fishing_proto "mongo.games.com/game/protocol/fishing" - "mongo.games.com/game/srvdata" - "mongo.games.com/goserver/core" - "mongo.games.com/goserver/core/timer" "strconv" "strings" "sync" "time" + "github.com/cihub/seelog" + "mongo.games.com/goserver/core" + "mongo.games.com/goserver/core/netlib" + "mongo.games.com/goserver/core/timer" + "mongo.games.com/goserver/srvlib/action" + srvlibproto "mongo.games.com/goserver/srvlib/protocol" + "mongo.games.com/game/common" "mongo.games.com/game/gamerule/fishing" + "mongo.games.com/game/gamesrv/base" "mongo.games.com/game/model" "mongo.games.com/game/proto" - "mongo.games.com/goserver/core/netlib" - srvlibproto "mongo.games.com/goserver/srvlib/protocol" + fishing_proto "mongo.games.com/game/protocol/fishing" + "mongo.games.com/game/srvdata" ) var fishlogger seelog.LoggerInterface @@ -1457,11 +1459,7 @@ func (this *FishingSceneData) BroadCastMessage(packetid int, msg proto.Message, if gateSess == nil || len(v) == 0 { continue } - pack, err := common.CreateMulticastPacket(packetid, msg, v...) - if err == nil { - proto.SetDefaults(pack) - gateSess.Send(int(srvlibproto.SrvlibPacketID_PACKET_SS_MULTICAST), pack) - } + action.MulticastMessageToServer(gateSess, packetid, msg, v...) } } diff --git a/gatesrv/broadcasthandler.go b/gatesrv/broadcasthandler.go deleted file mode 100644 index 319bfec..0000000 --- a/gatesrv/broadcasthandler.go +++ /dev/null @@ -1,24 +0,0 @@ -package main - -import ( - "mongo.games.com/goserver/core/netlib" - "mongo.games.com/goserver/srvlib" - "mongo.games.com/goserver/srvlib/protocol" -) - -func init() { - netlib.Register(int(protocol.SrvlibPacketID_PACKET_SS_BROADCAST), &protocol.SSPacketBroadcast{}, BroadcastHandler) -} - -func BroadcastHandler(s *netlib.Session, packetid int, data interface{}) error { - if bp, ok := data.(*protocol.SSPacketBroadcast); ok { - pd := bp.GetData() - sp := bp.GetSessParam() - if bcss := sp.GetBcss(); bcss != nil { - srvlib.ServerSessionMgrSington.Broadcast(int(bp.GetPacketId()), pd, int(bcss.GetSArea()), int(bcss.GetSType())) - } else { - srvlib.ClientSessionMgrSington.Broadcast(int(bp.GetPacketId()), pd) - } - } - return nil -} diff --git a/gatesrv/multicasthandler.go b/gatesrv/multicasthandler.go deleted file mode 100644 index cfcde44..0000000 --- a/gatesrv/multicasthandler.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import ( - "mongo.games.com/goserver/core/netlib" - "mongo.games.com/goserver/srvlib" - "mongo.games.com/goserver/srvlib/protocol" -) - -func init() { - netlib.Register(int(protocol.SrvlibPacketID_PACKET_SS_MULTICAST), &protocol.SSPacketMulticast{}, MulticastHandler) -} - -func MulticastHandler(s *netlib.Session, packetid int, data interface{}) error { - if mp, ok := data.(*protocol.SSPacketMulticast); ok { - pd := mp.GetData() - sis := mp.GetSessions() - for _, si := range sis { - ns := getSession(si) - if ns != nil { - ns.Send(int(mp.GetPacketId()), pd /*, s.GetSessionConfig().IsInnerLink*/) - } - } - } - return nil -} - -func getSession(su *protocol.MCSessionUnion) *netlib.Session { - cs := su.GetMccs() - if cs != nil { - return srvlib.ClientSessionMgrSington.GetSession(cs.GetSId()) - } - - ss := su.GetMcss() - if ss != nil { - return srvlib.ServerSessionMgrSington.GetSession(int(ss.GetSArea()), int(ss.GetSType()), int(ss.GetSId())) - } - - return nil -} diff --git a/mgrsrv/api/broadcasthandler.go b/mgrsrv/api/broadcasthandler.go deleted file mode 100644 index 803adee..0000000 --- a/mgrsrv/api/broadcasthandler.go +++ /dev/null @@ -1,9 +0,0 @@ -package api - -import ( - "mongo.games.com/game/common" -) - -func init() { - common.RegisterBoardCastHandler() -} diff --git a/mgrsrv/api/webapi_srctrl.go b/mgrsrv/api/webapi_srctrl.go index 9d9b932..4047075 100644 --- a/mgrsrv/api/webapi_srctrl.go +++ b/mgrsrv/api/webapi_srctrl.go @@ -2,23 +2,25 @@ package api import ( "io" - "mongo.games.com/game/common" - "mongo.games.com/game/model" - "mongo.games.com/game/proto" - msg_proto "mongo.games.com/game/protocol/message" - "mongo.games.com/game/protocol/server" - "mongo.games.com/game/protocol/webapi" + "net/http" + "os/exec" + "strconv" + "time" + "mongo.games.com/goserver/core/admin" "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/timer" "mongo.games.com/goserver/core/utils" "mongo.games.com/goserver/srvlib" + "mongo.games.com/goserver/srvlib/action" "mongo.games.com/goserver/srvlib/protocol" - srvlibprotocol "mongo.games.com/goserver/srvlib/protocol" - "net/http" - "os/exec" - "strconv" - "time" + + "mongo.games.com/game/common" + "mongo.games.com/game/model" + "mongo.games.com/game/proto" + msgproto "mongo.games.com/game/protocol/message" + "mongo.games.com/game/protocol/server" + "mongo.games.com/game/protocol/webapi" ) //-------------------------------切换状态------------------------------------------------------- @@ -225,20 +227,8 @@ func SrvCtrlNotice(rw http.ResponseWriter, data []byte) { noticePacket := &server.ServerNotice{ Text: proto.String(msg.GetNotice()), } - proto.SetDefaults(noticePacket) - sc := &protocol.BCSessionUnion{ - Bccs: &protocol.BCClientSession{}, - } - broadcast, err := common.CreateBroadcastPacket(sc, int(msg_proto.MSGPacketID_PACKET_SC_NOTICE), noticePacket) - if err != nil || broadcast == nil { - pack.Tag = webapi.TagCode_FAILED - pack.Msg = "send notice failed(inner error)" - r, _ := proto.Marshal(pack) - webApiResponse(rw, r) - return - } funcNotice := func() { - srvlib.ServerSessionMgrSington.Broadcast(int(srvlibprotocol.SrvlibPacketID_PACKET_SS_BROADCAST), broadcast, common.GetSelfAreaId(), srvlib.GateServerType) + action.BroadcastMessage(common.GetSelfAreaId(), srvlib.GateServerType, int(msgproto.MSGPacketID_PACKET_SC_NOTICE), noticePacket, &protocol.BCSessionUnion{}) } funcNotice() h, b := timer.StartTimer(timer.TimerActionWrapper(func(h timer.TimerHandle, ud interface{}) bool { diff --git a/model/gameparam.go b/model/gameparam.go index ff7e31a..6cf2399 100644 --- a/model/gameparam.go +++ b/model/gameparam.go @@ -85,6 +85,8 @@ type GameParam struct { GuideStepMaxNum int32 // 新手引导步骤最大值 GuideTs int64 // 新手引导时间戳,小于这个时间的玩家不显示新手引导 CustomAwardUpdateTime int // 竞技馆奖励更新时间 + CustomAwardMinAddTime int // 竞技馆假奖励方法周期,单位秒 + CustomAwardMaxAddTime int // 竞技馆假奖励方法周期,单位秒 } var GameParamPath = "../data/gameparam.json" @@ -221,4 +223,10 @@ func InitGameParam() { if GameParamData.CustomAwardUpdateTime == 0 { GameParamData.CustomAwardUpdateTime = 60 } + if GameParamData.CustomAwardMinAddTime == 0 { + GameParamData.CustomAwardMinAddTime = 20 * 60 + } + if GameParamData.CustomAwardMaxAddTime == 0 { + GameParamData.CustomAwardMaxAddTime = 30 * 60 + } } diff --git a/protocol/rank/rank.pb.go b/protocol/rank/rank.pb.go index ebb138c..6508d86 100644 --- a/protocol/rank/rank.pb.go +++ b/protocol/rank/rank.pb.go @@ -46,8 +46,9 @@ const ( Rank_PACKET_RANK_CSPermit Rank = 10012 Rank_PACKET_RANK_SCPermit Rank = 10013 // 竞技馆获奖记录 - Rank_PACKET_CSRoomAward Rank = 10014 - Rank_PACKET_SCRoomAward Rank = 10015 + Rank_PACKET_CSRoomAward Rank = 10014 + Rank_PACKET_SCRoomAward Rank = 10015 + Rank_PACKET_SCRoomAwardOne Rank = 10016 // 竞技馆获奖记录通知 ) // Enum value maps for Rank. @@ -70,6 +71,7 @@ var ( 10013: "PACKET_RANK_SCPermit", 10014: "PACKET_CSRoomAward", 10015: "PACKET_SCRoomAward", + 10016: "PACKET_SCRoomAwardOne", } Rank_value = map[string]int32{ "PACKET_RANK_ZERO": 0, @@ -89,6 +91,7 @@ var ( "PACKET_RANK_SCPermit": 10013, "PACKET_CSRoomAward": 10014, "PACKET_SCRoomAward": 10015, + "PACKET_SCRoomAwardOne": 10016, } ) @@ -1907,6 +1910,7 @@ func (x *Item) GetN() int64 { return 0 } +// PACKET_SCRoomAwardOne type UserAward struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -2235,7 +2239,7 @@ var file_rank_proto_rawDesc = []byte{ 0x6b, 0x69, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x2a, - 0xc6, 0x03, 0x0a, 0x04, 0x52, 0x61, 0x6e, 0x6b, 0x12, 0x14, 0x0a, 0x10, 0x50, 0x41, 0x43, 0x4b, + 0xe2, 0x03, 0x0a, 0x04, 0x52, 0x61, 0x6e, 0x6b, 0x12, 0x14, 0x0a, 0x10, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x52, 0x41, 0x4e, 0x4b, 0x5f, 0x5a, 0x45, 0x52, 0x4f, 0x10, 0x00, 0x12, 0x1c, 0x0a, 0x17, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x52, 0x41, 0x4e, 0x4b, 0x5f, 0x43, 0x53, 0x52, 0x61, 0x6e, 0x6b, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x10, 0x90, 0x4e, 0x12, 0x1c, 0x0a, 0x17, @@ -2263,19 +2267,21 @@ var file_rank_proto_rawDesc = []byte{ 0x6d, 0x69, 0x74, 0x10, 0x9d, 0x4e, 0x12, 0x17, 0x0a, 0x12, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x43, 0x53, 0x52, 0x6f, 0x6f, 0x6d, 0x41, 0x77, 0x61, 0x72, 0x64, 0x10, 0x9e, 0x4e, 0x12, 0x17, 0x0a, 0x12, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x53, 0x43, 0x52, 0x6f, 0x6f, 0x6d, - 0x41, 0x77, 0x61, 0x72, 0x64, 0x10, 0x9f, 0x4e, 0x2a, 0x8d, 0x01, 0x0a, 0x0a, 0x52, 0x61, 0x6e, - 0x6b, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x12, 0x13, 0x0a, 0x0f, 0x49, 0x6e, 0x76, 0x69, 0x74, - 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x4e, 0x6f, 0x6e, 0x65, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, - 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x54, 0x6f, 0x74, 0x61, 0x6c, - 0x10, 0x01, 0x12, 0x13, 0x0a, 0x0f, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x54, 0x79, 0x70, 0x65, - 0x5f, 0x57, 0x65, 0x65, 0x6b, 0x10, 0x02, 0x12, 0x14, 0x0a, 0x10, 0x49, 0x6e, 0x76, 0x69, 0x74, - 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x4d, 0x6f, 0x6e, 0x74, 0x68, 0x10, 0x03, 0x12, 0x15, 0x0a, - 0x11, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x55, 0x70, 0x57, 0x65, - 0x65, 0x6b, 0x10, 0x04, 0x12, 0x12, 0x0a, 0x0e, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x54, 0x79, - 0x70, 0x65, 0x5f, 0x4d, 0x61, 0x78, 0x10, 0x05, 0x42, 0x24, 0x5a, 0x22, 0x6d, 0x6f, 0x6e, 0x67, - 0x6f, 0x2e, 0x67, 0x61, 0x6d, 0x65, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x61, 0x6d, 0x65, - 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2f, 0x72, 0x61, 0x6e, 0x6b, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x41, 0x77, 0x61, 0x72, 0x64, 0x10, 0x9f, 0x4e, 0x12, 0x1a, 0x0a, 0x15, 0x50, 0x41, 0x43, 0x4b, + 0x45, 0x54, 0x5f, 0x53, 0x43, 0x52, 0x6f, 0x6f, 0x6d, 0x41, 0x77, 0x61, 0x72, 0x64, 0x4f, 0x6e, + 0x65, 0x10, 0xa0, 0x4e, 0x2a, 0x8d, 0x01, 0x0a, 0x0a, 0x52, 0x61, 0x6e, 0x6b, 0x49, 0x6e, 0x76, + 0x69, 0x74, 0x65, 0x12, 0x13, 0x0a, 0x0f, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x54, 0x79, 0x70, + 0x65, 0x5f, 0x4e, 0x6f, 0x6e, 0x65, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x49, 0x6e, 0x76, 0x69, + 0x74, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x10, 0x01, 0x12, 0x13, + 0x0a, 0x0f, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x57, 0x65, 0x65, + 0x6b, 0x10, 0x02, 0x12, 0x14, 0x0a, 0x10, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x54, 0x79, 0x70, + 0x65, 0x5f, 0x4d, 0x6f, 0x6e, 0x74, 0x68, 0x10, 0x03, 0x12, 0x15, 0x0a, 0x11, 0x49, 0x6e, 0x76, + 0x69, 0x74, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x55, 0x70, 0x57, 0x65, 0x65, 0x6b, 0x10, 0x04, + 0x12, 0x12, 0x0a, 0x0e, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x54, 0x79, 0x70, 0x65, 0x5f, 0x4d, + 0x61, 0x78, 0x10, 0x05, 0x42, 0x24, 0x5a, 0x22, 0x6d, 0x6f, 0x6e, 0x67, 0x6f, 0x2e, 0x67, 0x61, + 0x6d, 0x65, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x61, 0x6d, 0x65, 0x2f, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2f, 0x72, 0x61, 0x6e, 0x6b, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( diff --git a/protocol/rank/rank.proto b/protocol/rank/rank.proto index 30af151..03e8f94 100644 --- a/protocol/rank/rank.proto +++ b/protocol/rank/rank.proto @@ -28,6 +28,7 @@ enum Rank{ // 竞技馆获奖记录 PACKET_CSRoomAward = 10014; PACKET_SCRoomAward = 10015; + PACKET_SCRoomAwardOne = 10016; // 竞技馆获奖记录通知 } // 排位榜 @@ -223,6 +224,7 @@ message Item{ int64 N = 2; // 道具数量 } +// PACKET_SCRoomAwardOne message UserAward{ int32 Snid = 1; // 玩家id string Name = 2; // 昵称 diff --git a/ranksrv/com/etcd.go b/ranksrv/com/etcd.go index 7fe6a23..98babc1 100644 --- a/ranksrv/com/etcd.go +++ b/ranksrv/com/etcd.go @@ -6,17 +6,27 @@ import ( "go.etcd.io/etcd/client/v3" "mongo.games.com/game/etcd" + "mongo.games.com/game/model" "mongo.games.com/game/protocol/webapi" ) +var ConfigMgrInst = model.NewConfigMgr() + func init() { // 平台信息 etcd.Register(etcd.ETCDKEY_PLATFORM_PREFIX, webapi.Platform{}, PlatformConfigEtcd) + // 竞技馆房间配置 + etcd.Register(etcd.ETCDKEY_RoomConfig, webapi.RoomConfig{}, PlatformConfigEtcd) } func PlatformConfigEtcd(ctx context.Context, completeKey string, isInit bool, event *clientv3.Event, data interface{}) { if event.Type == clientv3.EventTypeDelete { return } - PlatformConfigSingleton.Update(data) + switch config := data.(type) { + case *webapi.Platform: + PlatformConfigSingleton.Update(config) + case *webapi.RoomConfig: + ConfigMgrInst.UpdateRoomConfig(config) + } } diff --git a/ranksrv/com/logchannel.go b/ranksrv/com/logchannel.go new file mode 100644 index 0000000..eb7fa5a --- /dev/null +++ b/ranksrv/com/logchannel.go @@ -0,0 +1,53 @@ +package com + +import ( + "reflect" + + "mongo.games.com/goserver/core/logger" + + "mongo.games.com/game/model" + "mongo.games.com/game/mq" +) + +// LogChannelSingleton 日志记录器 +var LogChannelSingleton = &LogChannel{ + cName: make(map[reflect.Type]string), +} + +type LogChannel struct { + cName map[reflect.Type]string +} + +func (c *LogChannel) RegisterLogCName(cname string, log interface{}) { + t := c.getLogType(log) + c.cName[t] = cname +} + +func (c *LogChannel) getLogType(log interface{}) reflect.Type { + return reflect.Indirect(reflect.ValueOf(log)).Type() +} + +func (c *LogChannel) getLogCName(log interface{}) string { + t := c.getLogType(log) + if name, exist := c.cName[t]; exist { + return name + } + return "" +} + +func (c *LogChannel) WriteLog(log interface{}) { + cname := c.getLogCName(log) + if cname == "" { + cname = "_null_" + } + logger.Logger.Tracef("LogChannel ==> %#v", log) + mq.Send(cname, log) +} + +func (c *LogChannel) WriteMQData(data *model.RabbitMQData) { + mq.Send(data.MQName, data.Data) +} + +func init() { + LogChannelSingleton.RegisterLogCName(mq.DBCustomLogAward, &model.CustomLogAward{}) +} diff --git a/ranksrv/main.go b/ranksrv/main.go index 5b8f152..97140c0 100644 --- a/ranksrv/main.go +++ b/ranksrv/main.go @@ -23,6 +23,7 @@ func main() { core.RegisteHook(core.HOOK_BEFORE_START, func() error { model.StartupRPClient(common.CustomConfig.GetString("MgoRpcCliNet"), common.CustomConfig.GetString("MgoRpcCliAddr"), time.Duration(common.CustomConfig.GetInt("MgoRpcCliReconnInterV"))*time.Second) mq.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")) err := model.InitGameKVData() if err != nil { panic(err) diff --git a/ranksrv/rank/customaward.go b/ranksrv/rank/customaward.go index 0cfc9d4..fdafc74 100644 --- a/ranksrv/rank/customaward.go +++ b/ranksrv/rank/customaward.go @@ -1,13 +1,20 @@ package rank import ( + "math/rand" "time" "github.com/jinzhu/now" "mongo.games.com/goserver/core/logger" + "mongo.games.com/goserver/core/module" + "mongo.games.com/goserver/srvlib" + "mongo.games.com/goserver/srvlib/action" + "mongo.games.com/game/common" "mongo.games.com/game/model" + "mongo.games.com/game/protocol/rank" "mongo.games.com/game/ranksrv/com" + "mongo.games.com/game/srvdata" ) var CustomAwardMgrInstance = com.NewListMgr[*model.CustomLogAward]( @@ -22,3 +29,79 @@ var CustomAwardMgrInstance = com.NewListMgr[*model.CustomLogAward]( ret, err := model.CustomLogAwardFind(platform, startTs, endTs) return ret, err }) + +var CustomAwardMgrSingle = &CustomAwardMgr{} + +type CustomAwardMgr struct { + updateTime time.Time +} + +func (c *CustomAwardMgr) ModuleName() string { + return "customaward" +} + +func (c *CustomAwardMgr) Init() { +} + +func (c *CustomAwardMgr) Update() { + nowTime := time.Now() + if nowTime.Unix() < c.updateTime.Unix() { + return + } + c.updateTime = nowTime.Add(time.Duration(common.RandInt(model.GameParamData.CustomAwardMinAddTime, model.GameParamData.CustomAwardMaxAddTime)) * time.Second) + + // 随机添加假数据 + for k := range com.PlatformConfigSingleton.Platforms { + for _, vv := range com.ConfigMgrInst.GetConfig(k).RoomConfig { + if vv.GetOn() == common.Off { + continue + } + var awards []*model.Item + var items []*rank.Item + for _, item := range vv.GetReward() { + awards = append(awards, &model.Item{ + ItemId: item.ItemId, + ItemNum: item.ItemNum, + ObtainTime: nowTime.Unix(), + }) + items = append(items, &rank.Item{ + Id: item.ItemId, + N: item.ItemNum, + }) + } + name := "" + if len(srvdata.PBDB_NameMgr.Datas.GetArr()) > 0 { + n := rand.Intn(len(srvdata.PBDB_NameMgr.Datas.GetArr())) + name = srvdata.PBDB_NameMgr.Datas.GetArr()[n].Name + } + id := common.RandInt(20000000, 99999999) + com.LogChannelSingleton.WriteLog(&model.CustomLogAward{ + Platform: k, + CycleId: "", + SnId: int32(id), + Name: name, + Awards: awards, + StartTs: nowTime.Add(-time.Minute * 8).Unix(), + EndTs: nowTime.Unix(), + }) + // 通知获奖 + pack := &rank.UserAward{ + Snid: int32(id), + Name: name, + Awards: items, + Ts: nowTime.Unix(), + } + action.BroadcastMessage(common.GetSelfAreaId(), srvlib.GateServerType, int(rank.Rank_PACKET_SCRoomAwardOne), pack, nil) + logger.Logger.Tracef("BroadcastMessage UserAward: %v", pack) + break + } + } +} + +func (c *CustomAwardMgr) Shutdown() { + module.UnregisteModule(c) +} + +func init() { + module.RegisteModule(CustomAwardMgrSingle, time.Second*5, 0) +} diff --git a/worldsrv/action_server.go b/worldsrv/action_server.go index 00befb2..dfaee80 100644 --- a/worldsrv/action_server.go +++ b/worldsrv/action_server.go @@ -694,9 +694,6 @@ func (this *CSAccountInvalidHandler) Process(s *netlib.Session, packetid int, da } func init() { - common.RegisterBoardCastHandler() - common.RegisterMulticastHandler() - common.RegisterHandler(int(playerproto.PlayerPacketID_PACKET_CS_PMCMD), &CSPMCmdHandler{}) netlib.RegisterFactory(int(playerproto.PlayerPacketID_PACKET_CS_PMCMD), &CSPMCmdPacketFactory{}) diff --git a/worldsrv/gamestate.go b/worldsrv/gamestate.go index f315cec..540ff50 100644 --- a/worldsrv/gamestate.go +++ b/worldsrv/gamestate.go @@ -5,6 +5,7 @@ import ( "mongo.games.com/game/proto" "mongo.games.com/game/srvdata" "mongo.games.com/goserver/core/netlib" + "mongo.games.com/goserver/srvlib/action" srvproto "mongo.games.com/goserver/srvlib/protocol" ) @@ -75,11 +76,7 @@ func (gsm *GameStateManager) BrodcastGameState(gameId int32, platform string, pa } for gateSess, v := range mgs { if gateSess != nil && len(v) != 0 { - pack, err := common.CreateMulticastPacket(packid, pack, v...) - if err == nil { - proto.SetDefaults(pack) - gateSess.Send(int(srvproto.SrvlibPacketID_PACKET_SS_MULTICAST), pack) - } + action.MulticastMessageToServer(gateSess, packid, pack, v...) } } } diff --git a/worldsrv/platformmgr.go b/worldsrv/platformmgr.go index 9f21517..6b04f24 100644 --- a/worldsrv/platformmgr.go +++ b/worldsrv/platformmgr.go @@ -8,6 +8,7 @@ import ( "mongo.games.com/goserver/core/module" "mongo.games.com/goserver/core/netlib" "mongo.games.com/goserver/core/utils" + "mongo.games.com/goserver/srvlib/action" srvlibproto "mongo.games.com/goserver/srvlib/protocol" "mongo.games.com/game/common" @@ -301,10 +302,7 @@ func (pm *PlatformMgr) Broadcast(packetid int, packet interface{}, players map[i } for gateSess, v := range mgs { if gateSess != nil && len(v) != 0 { - pack, err := common.CreateMulticastPacket(packetid, packet, v...) - if err == nil { - gateSess.Send(int(srvlibproto.SrvlibPacketID_PACKET_SS_MULTICAST), pack) - } + action.MulticastMessageToServer(gateSess, packetid, packet, v...) } } } diff --git a/worldsrv/playermgr.go b/worldsrv/playermgr.go index bd705fd..03ed8cf 100644 --- a/worldsrv/playermgr.go +++ b/worldsrv/playermgr.go @@ -10,6 +10,7 @@ import ( "mongo.games.com/goserver/core/task" "mongo.games.com/goserver/core/utils" "mongo.games.com/goserver/srvlib" + "mongo.games.com/goserver/srvlib/action" srvproto "mongo.games.com/goserver/srvlib/protocol" "mongo.games.com/game/common" @@ -290,14 +291,8 @@ func (this *PlayerMgr) UpdatePlayerToken(p *Player, newToken string) { // BroadcastMessage 给所有玩家发消息 func (this *PlayerMgr) BroadcastMessage(packetid int, rawpack interface{}) bool { - sc := &srvproto.BCSessionUnion{ - Bccs: &srvproto.BCClientSession{}, - } - pack, err := common.CreateBroadcastPacket(sc, packetid, rawpack) - if err == nil && pack != nil { - srvlib.ServerSessionMgrSington.Broadcast(int(srvproto.SrvlibPacketID_PACKET_SS_BROADCAST), pack, common.GetSelfAreaId(), srvlib.GateServerType) - return true - } + sc := &srvproto.BCSessionUnion{} + action.BroadcastMessage(common.GetSelfAreaId(), srvlib.GateServerType, packetid, rawpack, sc) return false } @@ -319,11 +314,7 @@ func (this *PlayerMgr) BroadcastMessageToPlatform(platform string, packetid int, } for gateSess, v := range mgs { if gateSess != nil && len(v) != 0 { - pack, err := common.CreateMulticastPacket(packetid, rawpack, v...) - if err == nil { - proto.SetDefaults(pack) - gateSess.Send(int(srvproto.SrvlibPacketID_PACKET_SS_MULTICAST), pack) - } + action.MulticastMessageToServer(gateSess, packetid, rawpack, v...) } } } @@ -361,11 +352,7 @@ func (this *PlayerMgr) BroadcastMessageToPlatformByFunc(platform string, packeti } for gateSess, v := range mgs { if gateSess != nil && len(v) != 0 { - pack, err := common.CreateMulticastPacket(packetid, rawpack, v...) - if err == nil { - proto.SetDefaults(pack) - gateSess.Send(int(srvproto.SrvlibPacketID_PACKET_SS_MULTICAST), pack) - } + action.MulticastMessageToServer(gateSess, packetid, rawpack, v...) } } } @@ -394,11 +381,7 @@ func (this *PlayerMgr) BroadcastMessageToPlatformWithHall(platform string, snid } for gateSess, v := range mgs { if gateSess != nil && len(v) != 0 { - pack, err := common.CreateMulticastPacket(packetid, rawpack, v...) - if err == nil { - proto.SetDefaults(pack) - gateSess.Send(int(srvproto.SrvlibPacketID_PACKET_SS_MULTICAST), pack) - } + action.MulticastMessageToServer(gateSess, packetid, rawpack, v...) } } } @@ -441,11 +424,7 @@ func (this *PlayerMgr) BroadcastMessageToTarget(target []int32, packetid int, ra for gateSess, v := range mgs { if gateSess != nil && len(v) != 0 { - pack, err := common.CreateMulticastPacket(packetid, rawpack, v...) - if err == nil { - proto.SetDefaults(pack) - gateSess.Send(int(srvproto.SrvlibPacketID_PACKET_SS_MULTICAST), pack) - } + action.MulticastMessageToServer(gateSess, packetid, rawpack, v...) } } } diff --git a/worldsrv/scene.go b/worldsrv/scene.go index 59fc908..06327ea 100644 --- a/worldsrv/scene.go +++ b/worldsrv/scene.go @@ -9,6 +9,7 @@ import ( "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/netlib" "mongo.games.com/goserver/srvlib" + "mongo.games.com/goserver/srvlib/action" srvlibproto "mongo.games.com/goserver/srvlib/protocol" "mongo.games.com/game/common" @@ -864,11 +865,7 @@ func (this *Scene) Broadcast(packetId int, msg rawproto.Message, excludeSid int6 for gateSess, v := range mgs { if gateSess != nil && len(v) != 0 { - pack, err := common.CreateMulticastPacket(packetId, msg, v...) - if err == nil { - proto.SetDefaults(pack) - gateSess.Send(int(srvlibproto.SrvlibPacketID_PACKET_SS_MULTICAST), pack) - } + action.MulticastMessageToServer(gateSess, packetId, msg, v...) } } } diff --git a/worldsrv/tmmatch.go b/worldsrv/tmmatch.go index bc23dc5..ec50184 100644 --- a/worldsrv/tmmatch.go +++ b/worldsrv/tmmatch.go @@ -9,6 +9,7 @@ import ( "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/netlib" "mongo.games.com/goserver/core/timer" + "mongo.games.com/goserver/srvlib/action" srvproto "mongo.games.com/goserver/srvlib/protocol" "mongo.games.com/game/common" @@ -112,11 +113,7 @@ func (tm *TmMatch) BroadcastMessage(packetId int, rawPack interface{}) { } for gateSess, v := range mgs { if gateSess != nil && len(v) != 0 { - pack, err := common.CreateMulticastPacket(packetId, rawPack, v...) - if err == nil { - proto.SetDefaults(pack) - gateSess.Send(int(srvproto.SrvlibPacketID_PACKET_SS_MULTICAST), pack) - } + action.MulticastMessageToServer(gateSess, packetId, rawPack, v...) } } }