mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-23 14:32:27 +08:00
添加了节点服务器,各个服务器之间支持多对多
This commit is contained in:
@@ -10,12 +10,20 @@ import (
|
||||
pb "google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// 用于服务器之间传输游戏协议
|
||||
// 仅用于传递数据平面(client<--->server)和控制平面(server<--->server)的消息
|
||||
// 目前是全部消息都走NATS 之后可以做优化服务器之间socket直连
|
||||
// 请不要用这个来搞RPC写一大堆异步回调!!!
|
||||
// 要用RPC有专门的NATSRPC
|
||||
|
||||
type MessageQueue struct {
|
||||
natsConn *nats.Conn
|
||||
natsMsgChan chan *nats.Msg
|
||||
netMsgInput chan *NetMsg
|
||||
netMsgOutput chan *NetMsg
|
||||
cmdProtoMap *cmd.CmdProtoMap
|
||||
serverType string
|
||||
appId string
|
||||
}
|
||||
|
||||
func NewMessageQueue(serverType string, appId string) (r *MessageQueue) {
|
||||
@@ -35,6 +43,8 @@ func NewMessageQueue(serverType string, appId string) (r *MessageQueue) {
|
||||
r.netMsgInput = make(chan *NetMsg, 1000)
|
||||
r.netMsgOutput = make(chan *NetMsg, 1000)
|
||||
r.cmdProtoMap = cmd.NewCmdProtoMap()
|
||||
r.serverType = serverType
|
||||
r.appId = appId
|
||||
go r.recvHandler()
|
||||
go r.sendHandler()
|
||||
return r
|
||||
|
||||
@@ -9,12 +9,14 @@ const (
|
||||
)
|
||||
|
||||
type NetMsg struct {
|
||||
MsgType uint8 `msgpack:"MsgType"`
|
||||
EventId uint16 `msgpack:"EventId"`
|
||||
Topic string `msgpack:"-"`
|
||||
GameMsg *GameMsg `msgpack:"GameMsg"`
|
||||
FightMsg *FightMsg `msgpack:"FightMsg"`
|
||||
ConnCtrlMsg *ConnCtrlMsg `msgpack:"ConnCtrlMsg"`
|
||||
MsgType uint8 `msgpack:"MsgType"`
|
||||
EventId uint16 `msgpack:"EventId"`
|
||||
Topic string `msgpack:"-"`
|
||||
GameMsg *GameMsg `msgpack:"GameMsg"`
|
||||
FightMsg *FightMsg `msgpack:"FightMsg"`
|
||||
ConnCtrlMsg *ConnCtrlMsg `msgpack:"ConnCtrlMsg"`
|
||||
OriginServerType string `msgpack:"OriginServerType"`
|
||||
OriginServerAppId string `msgpack:"OriginServerAppId"`
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -33,15 +35,17 @@ type GameMsg struct {
|
||||
const (
|
||||
ClientRttNotify = iota
|
||||
ClientTimeNotify
|
||||
FightServerSelectNotify
|
||||
KickPlayerNotify
|
||||
)
|
||||
|
||||
type ConnCtrlMsg struct {
|
||||
UserId uint32 `msgpack:"UserId"`
|
||||
ClientRtt uint32 `msgpack:"ClientRtt"`
|
||||
ClientTime uint32 `msgpack:"ClientTime"`
|
||||
KickUserId uint32 `msgpack:"KickUserId"`
|
||||
KickReason uint32 `msgpack:"KickReason"`
|
||||
UserId uint32 `msgpack:"UserId"`
|
||||
ClientRtt uint32 `msgpack:"ClientRtt"`
|
||||
ClientTime uint32 `msgpack:"ClientTime"`
|
||||
FightServerAppId string `msgpack:"FightServerAppId"`
|
||||
KickUserId uint32 `msgpack:"KickUserId"`
|
||||
KickReason uint32 `msgpack:"KickReason"`
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -52,9 +56,10 @@ const (
|
||||
)
|
||||
|
||||
type FightMsg struct {
|
||||
FightRoutineId uint32 `msgpack:"FightRoutineId"`
|
||||
EntityId uint32 `msgpack:"EntityId"`
|
||||
FightPropMap map[uint32]float32 `msgpack:"FightPropMap"`
|
||||
Uid uint32 `msgpack:"Uid"`
|
||||
AvatarGuid uint64 `msgpack:"AvatarGuid"`
|
||||
FightRoutineId uint32 `msgpack:"FightRoutineId"`
|
||||
EntityId uint32 `msgpack:"EntityId"`
|
||||
FightPropMap map[uint32]float32 `msgpack:"FightPropMap"`
|
||||
Uid uint32 `msgpack:"Uid"`
|
||||
AvatarGuid uint64 `msgpack:"AvatarGuid"`
|
||||
GateServerAppId string `msgpack:"GateServerAppId"`
|
||||
}
|
||||
|
||||
@@ -1,37 +1,48 @@
|
||||
package mq
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"hk4e/node/api"
|
||||
)
|
||||
|
||||
const (
|
||||
GATE = "GATE_${APPID}_HK4E"
|
||||
GS = "GS_${APPID}_HK4E"
|
||||
FIGHT = "FIGHT_${APPID}_HK4E"
|
||||
PATHFINDING = "PATHFINDING_${APPID}_HK4E"
|
||||
)
|
||||
func (m *MessageQueue) getOriginServer() (originServerType string, originServerAppId string) {
|
||||
originServerType = m.serverType
|
||||
originServerAppId = m.appId
|
||||
return originServerType, originServerAppId
|
||||
}
|
||||
|
||||
func (m *MessageQueue) getTopic(serverType string, appId string) string {
|
||||
topic := strings.ReplaceAll(serverType, "${APPID}", appId)
|
||||
topic := serverType + "_" + appId + "_" + "HK4E"
|
||||
return topic
|
||||
}
|
||||
|
||||
func (m *MessageQueue) SendToGate(appId string, netMsg *NetMsg) {
|
||||
netMsg.Topic = m.getTopic(GATE, appId)
|
||||
netMsg.Topic = m.getTopic(api.GATE, appId)
|
||||
originServerType, originServerAppId := m.getOriginServer()
|
||||
netMsg.OriginServerType = originServerType
|
||||
netMsg.OriginServerAppId = originServerAppId
|
||||
m.netMsgInput <- netMsg
|
||||
}
|
||||
|
||||
func (m *MessageQueue) SendToGs(appId string, netMsg *NetMsg) {
|
||||
netMsg.Topic = m.getTopic(GS, appId)
|
||||
netMsg.Topic = m.getTopic(api.GS, appId)
|
||||
originServerType, originServerAppId := m.getOriginServer()
|
||||
netMsg.OriginServerType = originServerType
|
||||
netMsg.OriginServerAppId = originServerAppId
|
||||
m.netMsgInput <- netMsg
|
||||
}
|
||||
|
||||
func (m *MessageQueue) SendToFight(appId string, netMsg *NetMsg) {
|
||||
netMsg.Topic = m.getTopic(FIGHT, appId)
|
||||
netMsg.Topic = m.getTopic(api.FIGHT, appId)
|
||||
originServerType, originServerAppId := m.getOriginServer()
|
||||
netMsg.OriginServerType = originServerType
|
||||
netMsg.OriginServerAppId = originServerAppId
|
||||
m.netMsgInput <- netMsg
|
||||
}
|
||||
|
||||
func (m *MessageQueue) SendToPathfinding(appId string, netMsg *NetMsg) {
|
||||
netMsg.Topic = m.getTopic(PATHFINDING, appId)
|
||||
netMsg.Topic = m.getTopic(api.PATHFINDING, appId)
|
||||
originServerType, originServerAppId := m.getOriginServer()
|
||||
netMsg.OriginServerType = originServerType
|
||||
netMsg.OriginServerAppId = originServerAppId
|
||||
m.netMsgInput <- netMsg
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user