重写消息
This commit is contained in:
parent
143c152b0e
commit
ff058d4a09
@ -10,21 +10,21 @@ import (
|
|||||||
|
|
||||||
func (s *ChatService) initProcessor() {
|
func (s *ChatService) initProcessor() {
|
||||||
s.processor.RegisterMessages(processor.RegisterMetas{
|
s.processor.RegisterMessages(processor.RegisterMetas{
|
||||||
pb.MsgId_C2SChatId: {pb.C2SChat{}, s.onChat},
|
pb.MsgId_ReqChatId: {pb.ReqChat{}, s.onChat},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 收到登陆成功消息,判断是否顶号
|
// 收到登陆成功消息,判断是否顶号
|
||||||
func (s *ChatService) onChat(uid int64, msg *pb.C2SChat) {
|
func (s *ChatService) onChat(uid int64, msg *pb.ReqChat) {
|
||||||
switch msg.Type {
|
switch msg.Type {
|
||||||
case pb.ChatType_CT_Private:
|
case pb.ChatType_CT_Private:
|
||||||
tName, _ := s.bindService.FindTopic(msg.DstUser.UserId, pb.ServiceTypeId_STI_Gate)
|
tName, _ := s.bindService.FindTopic(msg.DstUser.UserId, pb.ServiceTypeId_STI_Gate)
|
||||||
if tName == "" {
|
if tName == "" {
|
||||||
log.DebugF("user:%v find gate failed", uid)
|
log.DebugF("user:%v find gate failed", uid)
|
||||||
}
|
}
|
||||||
s.SendServiceMsg(service.TopicEx(tName), msg.DstUser.UserId, int32(pb.MsgId_S2CChatId), msg)
|
s.SendServiceMsg(service.TopicEx(tName), msg.DstUser.UserId, int32(pb.MsgId_RspChatId), msg)
|
||||||
default:
|
default:
|
||||||
s.SendServiceMsg(service.TopicEx(topicName.WorldMessage), uid, int32(pb.MsgId_S2CChatId), msg)
|
s.SendServiceMsg(service.TopicEx(topicName.WorldMessage), uid, int32(pb.MsgId_RspChatId), msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ func (s *ClientService) chat() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 收到登陆成功消息,判断是否顶号
|
// 收到登陆成功消息,判断是否顶号
|
||||||
func (s *ClientService) onChat(cMsg *pb.ClientMsg, msg *pb.S2CUserLogin) {
|
func (s *ClientService) onChat(cMsg *pb.ClientMsg, msg *pb.RspUserLogin) {
|
||||||
if msg.Code != pb.ErrCode_OK {
|
if msg.Code != pb.ErrCode_OK {
|
||||||
log.ErrorF("login error: %v", msg.Code)
|
log.ErrorF("login error: %v", msg.Code)
|
||||||
return
|
return
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
func (s *ClientService) login() {
|
func (s *ClientService) login() {
|
||||||
log.DebugF("user:%v ready login", s.username)
|
log.DebugF("user:%v ready login", s.username)
|
||||||
s.SendMsg(pb.ServiceTypeId_STI_Login, int32(pb.MsgId_C2SUserLoginId), &pb.C2SUserLogin{
|
s.SendMsg(pb.ServiceTypeId_STI_Login, int32(pb.MsgId_ReqUserLoginId), &pb.ReqUserLogin{
|
||||||
Username: s.username,
|
Username: s.username,
|
||||||
Password: s.password,
|
Password: s.password,
|
||||||
Ip: "",
|
Ip: "",
|
||||||
@ -17,7 +17,7 @@ func (s *ClientService) login() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 收到登陆成功消息,判断是否顶号
|
// 收到登陆成功消息,判断是否顶号
|
||||||
func (s *ClientService) onLogin(cMsg *pb.ClientMsg, msg *pb.S2CUserLogin) {
|
func (s *ClientService) onLogin(cMsg *pb.ClientMsg, msg *pb.RspUserLogin) {
|
||||||
if msg.Code != pb.ErrCode_OK {
|
if msg.Code != pb.ErrCode_OK {
|
||||||
log.ErrorF("login error:%v :%v", msg.Code, msg.Code.String())
|
log.ErrorF("login error:%v :%v", msg.Code, msg.Code.String())
|
||||||
return
|
return
|
||||||
|
@ -7,6 +7,6 @@ import (
|
|||||||
|
|
||||||
func (s *ClientService) initProcessor() {
|
func (s *ClientService) initProcessor() {
|
||||||
s.processor.RegisterMessages(processor.RegisterMetas{
|
s.processor.RegisterMessages(processor.RegisterMetas{
|
||||||
pb.MsgId_S2CUserLoginId: {pb.S2CUserLogin{}, s.onLogin},
|
pb.MsgId_RspUserLoginId: {pb.RspUserLogin{}, s.onLogin},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,12 @@ import (
|
|||||||
"github.com/fox/fox/ipb"
|
"github.com/fox/fox/ipb"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (rm *ColorRoom) checkEnterRoom(user *ColorPlayer, iMsg *ipb.InternalMsg, req *pb.C2SMatchRoom) {
|
func (rm *ColorRoom) checkEnterRoom(user *ColorPlayer, iMsg *ipb.InternalMsg, req *pb.ReqMatchRoom) {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rm *ColorRoom) OnEnterRoom(user *ColorPlayer, iMsg *ipb.InternalMsg, req *pb.C2SMatchRoom) {
|
func (rm *ColorRoom) OnEnterRoom(user *ColorPlayer, iMsg *ipb.InternalMsg, req *pb.ReqMatchRoom) {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -16,17 +16,17 @@ const (
|
|||||||
|
|
||||||
func (s *ColorService) initProcessor() {
|
func (s *ColorService) initProcessor() {
|
||||||
s.processor.RegisterMessages(processor.RegisterMetas{
|
s.processor.RegisterMessages(processor.RegisterMetas{
|
||||||
pb.MsgId_C2SMatchRoomId: {pb.C2SMatchRoom{}, s.onEnterRoom},
|
pb.MsgId_ReqMatchRoomId: {pb.ReqMatchRoom{}, s.onEnterRoom},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 登录或注册
|
// 登录或注册
|
||||||
func (s *ColorService) onEnterRoom(iMsg *ipb.InternalMsg, req *pb.C2SMatchRoom) {
|
func (s *ColorService) onEnterRoom(iMsg *ipb.InternalMsg, req *pb.ReqMatchRoom) {
|
||||||
ksync.GoSafe(func() {
|
ksync.GoSafe(func() {
|
||||||
us, code := rpc.RpcGetGameUser(s.bindService, s, iMsg.UserId)
|
us, code := rpc.RpcGetGameUser(s.bindService, s, iMsg.UserId)
|
||||||
if code != pb.ErrCode_OK {
|
if code != pb.ErrCode_OK {
|
||||||
s.SendServiceMsg(service.TopicEx(iMsg.ServiceName), iMsg.ConnId, iMsg.UserId,
|
s.SendServiceMsg(service.TopicEx(iMsg.ServiceName), iMsg.ConnId, iMsg.UserId,
|
||||||
int32(pb.MsgId_S2CMatchRoomId), &pb.S2CMatchRoom{Code: pb.ErrCode_SystemErr})
|
int32(pb.MsgId_RspMatchRoomId), &pb.RspMatchRoom{Code: pb.ErrCode_SystemErr})
|
||||||
}
|
}
|
||||||
// 切回服务协程处理业务逻辑
|
// 切回服务协程处理业务逻辑
|
||||||
s.RunOnce(func() {
|
s.RunOnce(func() {
|
||||||
|
@ -14,38 +14,38 @@ import (
|
|||||||
*/
|
*/
|
||||||
func (s *GateService) initProcessor() {
|
func (s *GateService) initProcessor() {
|
||||||
s.processor.RegisterMessages(processor.RegisterMetas{
|
s.processor.RegisterMessages(processor.RegisterMetas{
|
||||||
pb.MsgId_S2CUserLoginId: {pb.S2CUserLogin{}, s.onUserLogin},
|
pb.MsgId_RspUserLoginId: {pb.RspUserLogin{}, s.onUserLogin},
|
||||||
pb.MsgId_S2CUserLogoutId: {pb.S2CUserLogout{}, s.onUserLogout},
|
pb.MsgId_RspUserLogoutId: {pb.RspUserLogout{}, s.onUserLogout},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 收到登陆成功消息,判断是否顶号
|
// 收到登陆成功消息,判断是否顶号
|
||||||
func (s *GateService) onUserLogin(iMsg *ipb.InternalMsg, conn ws.IConn, msg *pb.S2CUserLogin) {
|
func (s *GateService) onUserLogin(iMsg *ipb.InternalMsg, conn ws.IConn, msg *pb.RspUserLogin) {
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 登陆失败,回传玩家
|
// 登陆失败,回传玩家
|
||||||
if msg.Code != pb.ErrCode_OK {
|
if msg.Code != pb.ErrCode_OK {
|
||||||
s.SendClientMsg(conn, iMsg.ServiceName, int32(pb.MsgId_S2CUserLoginId), msg)
|
s.SendClientMsg(conn, iMsg.ServiceName, int32(pb.MsgId_RspUserLoginId), msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.SendClientMsg(conn, iMsg.ServiceName, int32(pb.MsgId_S2CUserLoginId), msg)
|
s.SendClientMsg(conn, iMsg.ServiceName, int32(pb.MsgId_RspUserLoginId), msg)
|
||||||
s.wss.SetUserId(conn.Id(), msg.UserId)
|
s.wss.SetUserId(conn.Id(), msg.UserId)
|
||||||
sName := s.bindService.LoadFromRedis(conn.UserId(), pb.ServiceTypeId_STI_Gate)
|
sName := s.bindService.LoadFromRedis(conn.UserId(), pb.ServiceTypeId_STI_Gate)
|
||||||
// 网关不同,说明玩家在其它网关上登陆,
|
// 网关不同,说明玩家在其它网关上登陆,
|
||||||
if sName != "" && sName != s.Name() {
|
if sName != "" && sName != s.Name() {
|
||||||
s.SendServiceMsg(service.TopicEx(sName), conn, int32(pb.MsgId_S2CUserLogoutId), &pb.S2CUserLogout{Code: pb.ErrCode_LoginDiffLoc})
|
s.SendServiceMsg(service.TopicEx(sName), conn, int32(pb.MsgId_RspUserLogoutId), &pb.RspUserLogout{Code: pb.ErrCode_LoginDiffLoc})
|
||||||
}
|
}
|
||||||
// 广播玩家上线
|
// 广播玩家上线
|
||||||
s.SendServiceMsg(topicName.UserOnline, conn, int32(pb.MsgId_NtfUserOnlineId), &pb.NtfUserOnline{UserId: msg.UserId})
|
s.SendServiceMsg(topicName.UserOnline, conn, int32(pb.MsgId_NtfUserOnlineId), &pb.NtfUserOnline{UserId: msg.UserId})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 收到登出消息
|
// 收到登出消息
|
||||||
func (s *GateService) onUserLogout(iMsg *ipb.InternalMsg, conn ws.IConn, msg *pb.S2CUserLogout) {
|
func (s *GateService) onUserLogout(iMsg *ipb.InternalMsg, conn ws.IConn, msg *pb.RspUserLogout) {
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.SendClientMsg(conn, iMsg.ServiceName, int32(pb.MsgId_S2CUserLogoutId), msg)
|
s.SendClientMsg(conn, iMsg.ServiceName, int32(pb.MsgId_RspUserLogoutId), msg)
|
||||||
// 登出的清理工作由WsOnDisconnect实现
|
// 登出的清理工作由WsOnDisconnect实现
|
||||||
conn.Close()
|
conn.Close()
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ func (s *GateService) OnStop() {
|
|||||||
|
|
||||||
func (s *GateService) findConn(msg *ipb.InternalMsg) ws.IConn {
|
func (s *GateService) findConn(msg *ipb.InternalMsg) ws.IConn {
|
||||||
switch msg.MsgId {
|
switch msg.MsgId {
|
||||||
case int32(pb.MsgId_S2CUserLoginId):
|
case int32(pb.MsgId_RspUserLoginId):
|
||||||
conn, _ := s.wss.FindConnByConnId(msg.ConnId)
|
conn, _ := s.wss.FindConnByConnId(msg.ConnId)
|
||||||
return conn
|
return conn
|
||||||
default:
|
default:
|
||||||
@ -169,8 +169,8 @@ func (s *GateService) WsOnMessage(conn ws.IConn, data []byte) {
|
|||||||
topic, msg.ServiceName = s.bindService.FindTopic(conn.UserId(), msg.ServiceTid)
|
topic, msg.ServiceName = s.bindService.FindTopic(conn.UserId(), msg.ServiceTid)
|
||||||
}
|
}
|
||||||
if topic != "" {
|
if topic != "" {
|
||||||
if msg.MsgId == int32(pb.MsgId_C2SUserLoginId) {
|
if msg.MsgId == int32(pb.MsgId_ReqUserLoginId) {
|
||||||
req := &pb.C2SUserLogin{}
|
req := &pb.ReqUserLogin{}
|
||||||
_ = proto.Unmarshal(msg.Data, req)
|
_ = proto.Unmarshal(msg.Data, req)
|
||||||
req.Ip = conn.Addr()
|
req.Ip = conn.Addr()
|
||||||
msg.Data, _ = proto.Marshal(req)
|
msg.Data, _ = proto.Marshal(req)
|
||||||
|
@ -21,11 +21,11 @@ const (
|
|||||||
|
|
||||||
func (s *LoginService) initProcessor() {
|
func (s *LoginService) initProcessor() {
|
||||||
s.processor.RegisterMessages(processor.RegisterMetas{
|
s.processor.RegisterMessages(processor.RegisterMetas{
|
||||||
pb.MsgId_C2SUserLoginId: {pb.C2SUserLogin{}, s.onLoginOrRegister},
|
pb.MsgId_ReqUserLoginId: {pb.ReqUserLogin{}, s.onLoginOrRegister},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *LoginService) checkLoginOrRegister(req *pb.C2SUserLogin) (us *user.UserAccount, code pb.ErrCode, node *etcd.ServiceNode) {
|
func (s *LoginService) checkLoginOrRegister(req *pb.ReqUserLogin) (us *user.UserAccount, code pb.ErrCode, node *etcd.ServiceNode) {
|
||||||
var err error
|
var err error
|
||||||
node, err = s.bindService.RandServiceNode(pb.ServiceTypeId_STI_DB)
|
node, err = s.bindService.RandServiceNode(pb.ServiceTypeId_STI_DB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -116,11 +116,11 @@ func (s *LoginService) getUser(accountId int64, tName string) (*user.User, pb.Er
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 登录或注册
|
// 登录或注册
|
||||||
func (s *LoginService) onLoginOrRegister(iMsg *ipb.InternalMsg, req *pb.C2SUserLogin) {
|
func (s *LoginService) onLoginOrRegister(iMsg *ipb.InternalMsg, req *pb.ReqUserLogin) {
|
||||||
ksync.GoSafe(func() {
|
ksync.GoSafe(func() {
|
||||||
account, code, node := s.checkLoginOrRegister(req)
|
account, code, node := s.checkLoginOrRegister(req)
|
||||||
userId := int64(0)
|
userId := int64(0)
|
||||||
rsp := &pb.S2CUserLogin{Code: code}
|
rsp := &pb.RspUserLogin{Code: code}
|
||||||
if account != nil && code == pb.ErrCode_OK {
|
if account != nil && code == pb.ErrCode_OK {
|
||||||
// 拉取用户数据
|
// 拉取用户数据
|
||||||
us := &user.User{}
|
us := &user.User{}
|
||||||
@ -131,7 +131,7 @@ func (s *LoginService) onLoginOrRegister(iMsg *ipb.InternalMsg, req *pb.C2SUserL
|
|||||||
userId = rsp.UserId
|
userId = rsp.UserId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.SendServiceMsg(service.TopicEx(iMsg.ServiceName), iMsg.ConnId, userId, int32(pb.MsgId_S2CUserLoginId), rsp)
|
s.SendServiceMsg(service.TopicEx(iMsg.ServiceName), iMsg.ConnId, userId, int32(pb.MsgId_RspUserLoginId), rsp)
|
||||||
|
|
||||||
if account != nil && account.ID > 0 {
|
if account != nil && account.ID > 0 {
|
||||||
loginLog := &user.UserLoginLog{
|
loginLog := &user.UserLoginLog{
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// 匹配房间
|
// 匹配房间
|
||||||
func (s *MatchService) onMatchRoom(iMsg *ipb.InternalMsg, req *pb.C2SMatchRoom) {
|
func (s *MatchService) onMatchRoom(iMsg *ipb.InternalMsg, req *pb.ReqMatchRoom) {
|
||||||
ksync.GoSafe(func() {
|
ksync.GoSafe(func() {
|
||||||
// color game无需进入匹配队列
|
// color game无需进入匹配队列
|
||||||
playType := pb.ServiceTypeId(req.PlayType)
|
playType := pb.ServiceTypeId(req.PlayType)
|
||||||
@ -22,18 +22,18 @@ func (s *MatchService) onMatchRoom(iMsg *ipb.InternalMsg, req *pb.C2SMatchRoom)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorF("db service node error:%v", err)
|
log.ErrorF("db service node error:%v", err)
|
||||||
s.SendServiceMsg(service.TopicEx(iMsg.ServiceName), iMsg.ConnId, iMsg.UserId,
|
s.SendServiceMsg(service.TopicEx(iMsg.ServiceName), iMsg.ConnId, iMsg.UserId,
|
||||||
int32(pb.MsgId_S2CMatchRoomId), &pb.S2CMatchRoom{Code: pb.ErrCode_SystemErr})
|
int32(pb.MsgId_RspMatchRoomId), &pb.RspMatchRoom{Code: pb.ErrCode_SystemErr})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.SendServiceMsg(service.TopicEx(node.Name), iMsg.ConnId, iMsg.UserId, int32(pb.MsgId_C2SMatchRoomId), req)
|
s.SendServiceMsg(service.TopicEx(node.Name), iMsg.ConnId, iMsg.UserId, int32(pb.MsgId_ReqMatchRoomId), req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var us *user.GameUser
|
var us *user.GameUser
|
||||||
rsp := &pb.S2CMatchRoom{}
|
rsp := &pb.RspMatchRoom{}
|
||||||
us, rsp.Code = rpc.RpcGetGameUser(s.bindService, s, iMsg.UserId)
|
us, rsp.Code = rpc.RpcGetGameUser(s.bindService, s, iMsg.UserId)
|
||||||
if rsp.Code != pb.ErrCode_OK {
|
if rsp.Code != pb.ErrCode_OK {
|
||||||
s.SendServiceMsg(service.TopicEx(iMsg.ServiceName), iMsg.ConnId, iMsg.UserId, int32(pb.MsgId_S2CMatchRoomId), rsp)
|
s.SendServiceMsg(service.TopicEx(iMsg.ServiceName), iMsg.ConnId, iMsg.UserId, int32(pb.MsgId_RspMatchRoomId), rsp)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vipLv, vipExp := utils.VipLevel(us.VipExp)
|
vipLv, vipExp := utils.VipLevel(us.VipExp)
|
||||||
@ -51,9 +51,9 @@ func (s *MatchService) onMatchRoom(iMsg *ipb.InternalMsg, req *pb.C2SMatchRoom)
|
|||||||
rsp.RoomType = req.RoomType
|
rsp.RoomType = req.RoomType
|
||||||
switch pb.ServiceTypeId(rsp.PlayType) {
|
switch pb.ServiceTypeId(rsp.PlayType) {
|
||||||
case pb.ServiceTypeId_STI_ColorGame:
|
case pb.ServiceTypeId_STI_ColorGame:
|
||||||
rsp.ColorInfo = &pb.S2CMatchRoom_ColorInfo{}
|
rsp.ColorInfo = &pb.RspMatchRoom_ColorInfo{}
|
||||||
}
|
}
|
||||||
|
|
||||||
s.SendServiceMsg(service.TopicEx(iMsg.ServiceName), iMsg.ConnId, iMsg.UserId, int32(pb.MsgId_S2CMatchRoomId), rsp)
|
s.SendServiceMsg(service.TopicEx(iMsg.ServiceName), iMsg.ConnId, iMsg.UserId, int32(pb.MsgId_RspMatchRoomId), rsp)
|
||||||
}, nil)
|
}, nil)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user