从game server继承
This commit is contained in:
parent
28f68495ec
commit
1fdbe979ab
@ -2,14 +2,12 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"game/common/gameService"
|
||||||
"game/common/proto/pb"
|
"game/common/proto/pb"
|
||||||
"game/common/serviceName"
|
"game/common/serviceName"
|
||||||
"game/common/userBindService"
|
|
||||||
"game/server/chat/config"
|
"game/server/chat/config"
|
||||||
"game/server/chat/model"
|
|
||||||
"github.com/fox/fox/ipb"
|
"github.com/fox/fox/ipb"
|
||||||
"github.com/fox/fox/log"
|
"github.com/fox/fox/log"
|
||||||
"github.com/fox/fox/processor"
|
|
||||||
"github.com/fox/fox/service"
|
"github.com/fox/fox/service"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
)
|
)
|
||||||
@ -17,9 +15,7 @@ import (
|
|||||||
var Chat []*ChatService
|
var Chat []*ChatService
|
||||||
|
|
||||||
type ChatService struct {
|
type ChatService struct {
|
||||||
*service.NatsService
|
*gameService.GameService
|
||||||
processor *processor.Processor
|
|
||||||
bindService *userBindService.UserBindService
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
@ -60,8 +56,6 @@ func newChatService(serviceId int) *ChatService {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
s.bindService = userBindService.NewUserBindService(model.UserRedis, s.ServiceEtcd())
|
|
||||||
s.processor = processor.NewProcessor()
|
|
||||||
s.initProcessor()
|
s.initProcessor()
|
||||||
s.OnInit()
|
s.OnInit()
|
||||||
return s
|
return s
|
||||||
@ -93,23 +87,11 @@ func (s *ChatService) OnMessage(data []byte) error {
|
|||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if req, err := s.processor.Unmarshal(iMsg.MsgId, iMsg.Msg); err == nil {
|
if req, err := s.Processor().Unmarshal(iMsg.MsgId, iMsg.Msg); err == nil {
|
||||||
err = s.processor.Dispatch(iMsg.MsgId, iMsg.UserId, req)
|
err = s.Processor().Dispatch(iMsg.MsgId, iMsg.UserId, req)
|
||||||
} else {
|
} else {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
}
|
}
|
||||||
//log.Debug(s.Log("received message:%v", iMsg.MsgId))
|
//log.Debug(s.Log("received message:%v", iMsg.MsgId))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 向内部服务发送消息
|
|
||||||
func (s *ChatService) SendServiceData(topic string, userId int64, msgId int32, data []byte) {
|
|
||||||
iMsg := ipb.MakeMsg(s.Name(), 0, userId, msgId, data)
|
|
||||||
_ = s.Send(topic, iMsg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 向内部服务发送消息
|
|
||||||
func (s *ChatService) SendServiceMsg(topic string, userId int64, msgId int32, msg proto.Message) {
|
|
||||||
data, _ := proto.Marshal(msg)
|
|
||||||
s.SendServiceData(topic, userId, msgId, data)
|
|
||||||
}
|
|
||||||
|
@ -2,15 +2,13 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"game/common/gameService"
|
||||||
"game/common/proto/pb"
|
"game/common/proto/pb"
|
||||||
"game/common/serviceName"
|
"game/common/serviceName"
|
||||||
"game/common/topicName"
|
"game/common/topicName"
|
||||||
"game/common/userBindService"
|
|
||||||
"game/server/gate/config"
|
"game/server/gate/config"
|
||||||
"game/server/gate/model"
|
|
||||||
"github.com/fox/fox/ipb"
|
"github.com/fox/fox/ipb"
|
||||||
"github.com/fox/fox/log"
|
"github.com/fox/fox/log"
|
||||||
"github.com/fox/fox/processor"
|
|
||||||
"github.com/fox/fox/service"
|
"github.com/fox/fox/service"
|
||||||
"github.com/fox/fox/ws"
|
"github.com/fox/fox/ws"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
@ -20,10 +18,8 @@ import (
|
|||||||
var Gates []*GateService
|
var Gates []*GateService
|
||||||
|
|
||||||
type GateService struct {
|
type GateService struct {
|
||||||
*service.NatsService
|
*gameService.GameService
|
||||||
wss *ws.WsServer
|
wss *ws.WsServer
|
||||||
processor *processor.Processor
|
|
||||||
bindService *userBindService.UserBindService
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
@ -45,11 +41,10 @@ func Stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newGateService(serviceId int) *GateService {
|
func newGateService(serviceId int) *GateService {
|
||||||
var err error
|
|
||||||
s := new(GateService)
|
s := new(GateService)
|
||||||
|
|
||||||
sName := fmt.Sprintf("%v-%d", serviceName.Gate, serviceId)
|
sName := fmt.Sprintf("%v-%d", serviceName.Gate, serviceId)
|
||||||
if s.NatsService, err = service.NewNatsService(&service.InitNatsServiceParams{
|
s.GameService = gameService.NewGameService(&service.InitNatsServiceParams{
|
||||||
EtcdAddress: config.Cfg.Etcd.Address,
|
EtcdAddress: config.Cfg.Etcd.Address,
|
||||||
EtcdUsername: "",
|
EtcdUsername: "",
|
||||||
EtcdPassword: "",
|
EtcdPassword: "",
|
||||||
@ -59,10 +54,7 @@ func newGateService(serviceId int) *GateService {
|
|||||||
OnFunc: s,
|
OnFunc: s,
|
||||||
TypeId: int(pb.ServiceTypeId_STI_Gate),
|
TypeId: int(pb.ServiceTypeId_STI_Gate),
|
||||||
Version: config.Cfg.BuildDate,
|
Version: config.Cfg.BuildDate,
|
||||||
}); err != nil {
|
})
|
||||||
log.Fatal(err.Error())
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
addressPos := serviceId - config.Command.ServiceId
|
addressPos := serviceId - config.Command.ServiceId
|
||||||
if len(config.GateCfg.Address) <= addressPos {
|
if len(config.GateCfg.Address) <= addressPos {
|
||||||
@ -71,9 +63,6 @@ func newGateService(serviceId int) *GateService {
|
|||||||
}
|
}
|
||||||
wsAddress := config.GateCfg.Address[addressPos]
|
wsAddress := config.GateCfg.Address[addressPos]
|
||||||
s.wss = ws.NewWsServer(wsAddress, s.WsOnMessage, s.WsOnDisconnect)
|
s.wss = ws.NewWsServer(wsAddress, s.WsOnMessage, s.WsOnDisconnect)
|
||||||
s.bindService = userBindService.NewUserBindService(model.UserBindServiceRedis, s.ServiceEtcd())
|
|
||||||
|
|
||||||
s.processor = processor.NewProcessor()
|
|
||||||
s.initProcessor()
|
s.initProcessor()
|
||||||
s.OnInit()
|
s.OnInit()
|
||||||
return s
|
return s
|
||||||
@ -126,8 +115,8 @@ func (s *GateService) findConn(msg *ipb.InternalMsg) ws.IConn {
|
|||||||
|
|
||||||
// 处理消息
|
// 处理消息
|
||||||
func (s *GateService) connMessage(conn ws.IConn, iMsg *ipb.InternalMsg) {
|
func (s *GateService) connMessage(conn ws.IConn, iMsg *ipb.InternalMsg) {
|
||||||
if req, err := s.processor.Unmarshal(iMsg.MsgId, iMsg.Msg); err == nil {
|
if req, err := s.Processor().Unmarshal(iMsg.MsgId, iMsg.Msg); err == nil {
|
||||||
err = s.processor.Dispatch(iMsg.MsgId, iMsg, conn, req)
|
err = s.Processor().Dispatch(iMsg.MsgId, iMsg, conn, req)
|
||||||
} else {
|
} else {
|
||||||
s.SendClientData(conn, iMsg.ServiceName, iMsg.MsgId, iMsg.Msg)
|
s.SendClientData(conn, iMsg.ServiceName, iMsg.MsgId, iMsg.Msg)
|
||||||
}
|
}
|
||||||
@ -166,7 +155,7 @@ func (s *GateService) WsOnMessage(conn ws.IConn, data []byte) {
|
|||||||
if msg.ServiceName != "" {
|
if msg.ServiceName != "" {
|
||||||
topic = service.TopicEx(msg.ServiceName)
|
topic = service.TopicEx(msg.ServiceName)
|
||||||
} else {
|
} else {
|
||||||
if node, err := s.bindService.FindServiceNode(msg.ServiceTid, conn.UserId()); err == nil {
|
if node, err := s.BindService().FindServiceNode(msg.ServiceTid, conn.UserId()); err == nil {
|
||||||
topic, msg.ServiceName = service.TopicEx(node.Name), node.Name
|
topic, msg.ServiceName = service.TopicEx(node.Name), node.Name
|
||||||
} else {
|
} else {
|
||||||
log.ErrorF("uid:%v 查找节点:%v 失败:%v", conn.UserId(), msg.ServiceTid, err.Error())
|
log.ErrorF("uid:%v 查找节点:%v 失败:%v", conn.UserId(), msg.ServiceTid, err.Error())
|
||||||
@ -174,6 +163,7 @@ func (s *GateService) WsOnMessage(conn ws.IConn, data []byte) {
|
|||||||
}
|
}
|
||||||
if topic != "" {
|
if topic != "" {
|
||||||
if msg.MsgId == int32(pb.MsgId_ReqUserLoginId) {
|
if msg.MsgId == int32(pb.MsgId_ReqUserLoginId) {
|
||||||
|
// 加入登陆ip
|
||||||
req := &pb.ReqUserLogin{}
|
req := &pb.ReqUserLogin{}
|
||||||
_ = proto.Unmarshal(msg.Data, req)
|
_ = proto.Unmarshal(msg.Data, req)
|
||||||
req.Ip = conn.Addr()
|
req.Ip = conn.Addr()
|
||||||
@ -189,7 +179,7 @@ func (s *GateService) WsOnMessage(conn ws.IConn, data []byte) {
|
|||||||
// 向内部服务发送消息
|
// 向内部服务发送消息
|
||||||
func (s *GateService) SendServiceData(topic string, conn ws.IConn, msgId int32, data []byte) {
|
func (s *GateService) SendServiceData(topic string, conn ws.IConn, msgId int32, data []byte) {
|
||||||
iMsg := ipb.MakeMsg(s.Name(), conn.Id(), conn.UserId(), msgId, data)
|
iMsg := ipb.MakeMsg(s.Name(), conn.Id(), conn.UserId(), msgId, data)
|
||||||
_ = s.Send(topic, iMsg)
|
_ = s.SendByTopic(topic, iMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 向内部服务发送消息
|
// 向内部服务发送消息
|
||||||
@ -215,11 +205,11 @@ func (s *GateService) SendClientMsg(conn ws.IConn, serviceName string, msgId int
|
|||||||
|
|
||||||
func (s *GateService) WsOnDisconnect(conn ws.IConn) {
|
func (s *GateService) WsOnDisconnect(conn ws.IConn) {
|
||||||
if conn.UserId() > 0 {
|
if conn.UserId() > 0 {
|
||||||
sName := s.bindService.LoadFromRedis(conn.UserId(), pb.ServiceTypeId_STI_Gate)
|
sName := s.BindService().LoadFromRedis(conn.UserId(), pb.ServiceTypeId_STI_Gate)
|
||||||
// 相同网关,则为正常下线,删除redis信息然后向内网广播下线
|
// 相同网关,则为正常下线,删除redis信息然后向内网广播下线
|
||||||
// 不同网关,异地登陆顶号 由其它网关通知本网关向玩家发送顶号消息(processor中处理),并主动关闭连接,不广播下线消息
|
// 不同网关,异地登陆顶号 由其它网关通知本网关向玩家发送顶号消息(processor中处理),并主动关闭连接,不广播下线消息
|
||||||
if sName == s.Name() {
|
if sName == s.Name() {
|
||||||
s.bindService.DelUserService(conn.UserId(), pb.ServiceTypeId_STI_Gate)
|
s.BindService().DelUserService(conn.UserId(), pb.ServiceTypeId_STI_Gate)
|
||||||
s.SendServiceMsg(topicName.UserOffline, conn, int32(pb.MsgId_NtfUserOfflineId), &pb.NtfUserOffline{UserId: conn.UserId()})
|
s.SendServiceMsg(topicName.UserOffline, conn, int32(pb.MsgId_NtfUserOfflineId), &pb.NtfUserOffline{UserId: conn.UserId()})
|
||||||
}
|
}
|
||||||
log.Debug(s.Log("user:%v disconnect", conn.UserId()))
|
log.Debug(s.Log("user:%v disconnect", conn.UserId()))
|
||||||
|
@ -2,14 +2,12 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"game/common/gameService"
|
||||||
"game/common/proto/pb"
|
"game/common/proto/pb"
|
||||||
"game/common/serviceName"
|
"game/common/serviceName"
|
||||||
"game/common/userBindService"
|
|
||||||
"game/server/lobby/config"
|
"game/server/lobby/config"
|
||||||
"game/server/lobby/model"
|
|
||||||
"github.com/fox/fox/ipb"
|
"github.com/fox/fox/ipb"
|
||||||
"github.com/fox/fox/log"
|
"github.com/fox/fox/log"
|
||||||
"github.com/fox/fox/processor"
|
|
||||||
"github.com/fox/fox/service"
|
"github.com/fox/fox/service"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
)
|
)
|
||||||
@ -18,9 +16,7 @@ import (
|
|||||||
var lobby []*LobbyService
|
var lobby []*LobbyService
|
||||||
|
|
||||||
type LobbyService struct {
|
type LobbyService struct {
|
||||||
*service.NatsService
|
*gameService.GameService
|
||||||
processor *processor.Processor
|
|
||||||
bindService *userBindService.UserBindService
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
@ -42,11 +38,10 @@ func Stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newLobbyService(serviceId int) *LobbyService {
|
func newLobbyService(serviceId int) *LobbyService {
|
||||||
var err error
|
|
||||||
s := new(LobbyService)
|
s := new(LobbyService)
|
||||||
|
|
||||||
sName := fmt.Sprintf("%v-%d", serviceName.Lobby, serviceId)
|
sName := fmt.Sprintf("%v-%d", serviceName.Lobby, serviceId)
|
||||||
if s.NatsService, err = service.NewNatsService(&service.InitNatsServiceParams{
|
s.GameService = gameService.NewGameService(&service.InitNatsServiceParams{
|
||||||
EtcdAddress: config.Cfg.Etcd.Address,
|
EtcdAddress: config.Cfg.Etcd.Address,
|
||||||
EtcdUsername: "",
|
EtcdUsername: "",
|
||||||
EtcdPassword: "",
|
EtcdPassword: "",
|
||||||
@ -56,13 +51,8 @@ func newLobbyService(serviceId int) *LobbyService {
|
|||||||
OnFunc: s,
|
OnFunc: s,
|
||||||
TypeId: int(pb.ServiceTypeId_STI_Lobby),
|
TypeId: int(pb.ServiceTypeId_STI_Lobby),
|
||||||
Version: config.Cfg.BuildDate,
|
Version: config.Cfg.BuildDate,
|
||||||
}); err != nil {
|
})
|
||||||
log.Fatal(err.Error())
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
s.bindService = userBindService.NewUserBindService(model.UserRedis, s.ServiceEtcd())
|
|
||||||
s.processor = processor.NewProcessor()
|
|
||||||
s.initProcessor()
|
s.initProcessor()
|
||||||
s.OnInit()
|
s.OnInit()
|
||||||
return s
|
return s
|
||||||
@ -94,23 +84,11 @@ func (s *LobbyService) OnMessage(data []byte) error {
|
|||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if req, err := s.processor.Unmarshal(iMsg.MsgId, iMsg.Msg); err == nil {
|
if req, err := s.Processor().Unmarshal(iMsg.MsgId, iMsg.Msg); err == nil {
|
||||||
err = s.processor.Dispatch(iMsg.MsgId, iMsg, req)
|
err = s.Processor().Dispatch(iMsg.MsgId, iMsg, req)
|
||||||
} else {
|
} else {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
}
|
}
|
||||||
//log.Debug(s.Log("received message:%v", iMsg.MsgId))
|
//log.Debug(s.Log("received message:%v", iMsg.MsgId))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 向内部服务发送消息
|
|
||||||
func (s *LobbyService) SendServiceData(topic string, userId int64, msgId int32, data []byte) {
|
|
||||||
iMsg := ipb.MakeMsg(s.Name(), 0, userId, msgId, data)
|
|
||||||
_ = s.Send(topic, iMsg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 向内部服务发送消息
|
|
||||||
func (s *LobbyService) SendServiceMsg(topic string, userId int64, msgId int32, msg proto.Message) {
|
|
||||||
data, _ := proto.Marshal(msg)
|
|
||||||
s.SendServiceData(topic, userId, msgId, data)
|
|
||||||
}
|
|
||||||
|
@ -2,14 +2,12 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"game/common/gameService"
|
||||||
"game/common/proto/pb"
|
"game/common/proto/pb"
|
||||||
"game/common/serviceName"
|
"game/common/serviceName"
|
||||||
"game/common/userBindService"
|
|
||||||
"game/server/login/config"
|
"game/server/login/config"
|
||||||
"game/server/login/model"
|
|
||||||
"github.com/fox/fox/ipb"
|
"github.com/fox/fox/ipb"
|
||||||
"github.com/fox/fox/log"
|
"github.com/fox/fox/log"
|
||||||
"github.com/fox/fox/processor"
|
|
||||||
"github.com/fox/fox/service"
|
"github.com/fox/fox/service"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
)
|
)
|
||||||
@ -17,9 +15,7 @@ import (
|
|||||||
var Login []*LoginService
|
var Login []*LoginService
|
||||||
|
|
||||||
type LoginService struct {
|
type LoginService struct {
|
||||||
*service.NatsService
|
*gameService.GameService
|
||||||
processor *processor.Processor
|
|
||||||
bindService *userBindService.UserBindService
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
@ -43,11 +39,10 @@ func Stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newLoginService(serviceId int) *LoginService {
|
func newLoginService(serviceId int) *LoginService {
|
||||||
var err error
|
|
||||||
s := new(LoginService)
|
s := new(LoginService)
|
||||||
|
|
||||||
sName := fmt.Sprintf("%v-%d", serviceName.Login, serviceId)
|
sName := fmt.Sprintf("%v-%d", serviceName.Login, serviceId)
|
||||||
if s.NatsService, err = service.NewNatsService(&service.InitNatsServiceParams{
|
s.GameService = gameService.NewGameService(&service.InitNatsServiceParams{
|
||||||
EtcdAddress: config.Cfg.Etcd.Address,
|
EtcdAddress: config.Cfg.Etcd.Address,
|
||||||
EtcdUsername: "",
|
EtcdUsername: "",
|
||||||
EtcdPassword: "",
|
EtcdPassword: "",
|
||||||
@ -57,13 +52,8 @@ func newLoginService(serviceId int) *LoginService {
|
|||||||
OnFunc: s,
|
OnFunc: s,
|
||||||
TypeId: int(pb.ServiceTypeId_STI_Login),
|
TypeId: int(pb.ServiceTypeId_STI_Login),
|
||||||
Version: config.Cfg.BuildDate,
|
Version: config.Cfg.BuildDate,
|
||||||
}); err != nil {
|
})
|
||||||
log.Fatal(err.Error())
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
s.bindService = userBindService.NewUserBindService(model.UserBindServiceRedis, s.ServiceEtcd())
|
|
||||||
s.processor = processor.NewProcessor()
|
|
||||||
s.initProcessor()
|
s.initProcessor()
|
||||||
s.OnInit()
|
s.OnInit()
|
||||||
return s
|
return s
|
||||||
@ -94,24 +84,11 @@ func (s *LoginService) OnMessage(data []byte) error {
|
|||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if req, err := s.processor.Unmarshal(iMsg.MsgId, iMsg.Msg); err == nil {
|
if req, err := s.Processor().Unmarshal(iMsg.MsgId, iMsg.Msg); err == nil {
|
||||||
err = s.processor.Dispatch(iMsg.MsgId, iMsg, req)
|
err = s.Processor().Dispatch(iMsg.MsgId, iMsg, req)
|
||||||
} else {
|
} else {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
}
|
}
|
||||||
log.Debug(s.Log("received message:%v", pb.MsgId(iMsg.MsgId)))
|
log.Debug(s.Log("received message:%v", pb.MsgId(iMsg.MsgId)))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 向内部服务发送消息
|
|
||||||
func (s *LoginService) SendServiceData(topic string, connId uint32, userId int64, msgId int32, data []byte) {
|
|
||||||
iMsg := ipb.MakeMsg(s.Name(), connId, userId, msgId, data)
|
|
||||||
_ = s.Send(topic, iMsg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 向内部服务发送消息
|
|
||||||
func (s *LoginService) SendServiceMsg(topic string, connId uint32, userId int64, msgId int32, msg proto.Message) {
|
|
||||||
log.DebugF("send to:%v msg id:%v, msg:%v", topic, msgId, msg.String())
|
|
||||||
data, _ := proto.Marshal(msg)
|
|
||||||
s.SendServiceData(topic, connId, userId, msgId, data)
|
|
||||||
}
|
|
||||||
|
@ -2,15 +2,13 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"game/common/gameService"
|
||||||
"game/common/proto/pb"
|
"game/common/proto/pb"
|
||||||
"game/common/serviceName"
|
"game/common/serviceName"
|
||||||
"game/common/userBindService"
|
|
||||||
"game/server/match/config"
|
"game/server/match/config"
|
||||||
"game/server/match/match"
|
"game/server/match/match"
|
||||||
"game/server/match/model"
|
|
||||||
"github.com/fox/fox/ipb"
|
"github.com/fox/fox/ipb"
|
||||||
"github.com/fox/fox/log"
|
"github.com/fox/fox/log"
|
||||||
"github.com/fox/fox/processor"
|
|
||||||
"github.com/fox/fox/service"
|
"github.com/fox/fox/service"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
)
|
)
|
||||||
@ -18,10 +16,8 @@ import (
|
|||||||
var Services []*MatchService
|
var Services []*MatchService
|
||||||
|
|
||||||
type MatchService struct {
|
type MatchService struct {
|
||||||
*service.NatsService
|
*gameService.GameService
|
||||||
processor *processor.Processor
|
matchMgr *match.MatchMgr
|
||||||
bindService *userBindService.UserBindService
|
|
||||||
matchMgr *match.MatchMgr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
@ -45,12 +41,11 @@ func Stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newService(serviceId int) *MatchService {
|
func newService(serviceId int) *MatchService {
|
||||||
var err error
|
|
||||||
s := new(MatchService)
|
s := new(MatchService)
|
||||||
s.matchMgr = match.NewMatchMgr()
|
s.matchMgr = match.NewMatchMgr()
|
||||||
|
|
||||||
sName := fmt.Sprintf("%v-%d", serviceName.Match, serviceId)
|
sName := fmt.Sprintf("%v-%d", serviceName.Match, serviceId)
|
||||||
if s.NatsService, err = service.NewNatsService(&service.InitNatsServiceParams{
|
s.GameService = gameService.NewGameService(&service.InitNatsServiceParams{
|
||||||
EtcdAddress: config.Cfg.Etcd.Address,
|
EtcdAddress: config.Cfg.Etcd.Address,
|
||||||
EtcdUsername: "",
|
EtcdUsername: "",
|
||||||
EtcdPassword: "",
|
EtcdPassword: "",
|
||||||
@ -60,13 +55,8 @@ func newService(serviceId int) *MatchService {
|
|||||||
OnFunc: s,
|
OnFunc: s,
|
||||||
TypeId: int(pb.ServiceTypeId_STI_Match),
|
TypeId: int(pb.ServiceTypeId_STI_Match),
|
||||||
Version: config.Cfg.BuildDate,
|
Version: config.Cfg.BuildDate,
|
||||||
}); err != nil {
|
})
|
||||||
log.Fatal(err.Error())
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
s.bindService = userBindService.NewUserBindService(model.UserBindServiceRedis, s.ServiceEtcd())
|
|
||||||
s.processor = processor.NewProcessor()
|
|
||||||
s.initProcessor()
|
s.initProcessor()
|
||||||
s.OnInit()
|
s.OnInit()
|
||||||
return s
|
return s
|
||||||
@ -97,24 +87,11 @@ func (s *MatchService) OnMessage(data []byte) error {
|
|||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if req, err := s.processor.Unmarshal(iMsg.MsgId, iMsg.Msg); err == nil {
|
if req, err := s.Processor().Unmarshal(iMsg.MsgId, iMsg.Msg); err == nil {
|
||||||
err = s.processor.Dispatch(iMsg.MsgId, iMsg, req)
|
err = s.Processor().Dispatch(iMsg.MsgId, iMsg, req)
|
||||||
} else {
|
} else {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
}
|
}
|
||||||
log.Debug(s.Log("received message:%v", pb.MsgId(iMsg.MsgId)))
|
log.Debug(s.Log("received message:%v", pb.MsgId(iMsg.MsgId)))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 向内部服务发送消息
|
|
||||||
func (s *MatchService) SendServiceData(gateName, topic string, connId uint32, userId int64, msgId int32, data []byte) {
|
|
||||||
iMsg := ipb.MakeMsg(gateName, connId, userId, msgId, data)
|
|
||||||
_ = s.Send(topic, iMsg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 向内部服务发送消息
|
|
||||||
func (s *MatchService) SendServiceMsg(gateName, topic string, connId uint32, userId int64, msgId int32, msg proto.Message) {
|
|
||||||
log.DebugF("send to:%v msg id:%v, msg:%v", topic, pb.MsgId(msgId), msg.String())
|
|
||||||
data, _ := proto.Marshal(msg)
|
|
||||||
s.SendServiceData(gateName, topic, connId, userId, msgId, data)
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user