52 lines
1.7 KiB
Go
52 lines
1.7 KiB
Go
package server
|
||
|
||
import (
|
||
"game/common/proto/pb"
|
||
"game/common/topicName"
|
||
"github.com/fox/fox/ipb"
|
||
"github.com/fox/fox/processor"
|
||
"github.com/fox/fox/service"
|
||
"github.com/fox/fox/ws"
|
||
)
|
||
|
||
/*
|
||
如果需要gate处理后,继续将消息转发给玩家,则最后需要调用SendClientData
|
||
*/
|
||
func (s *GateService) initProcessor() {
|
||
s.processor.RegisterMessages(processor.RegisterMetas{
|
||
pb.MsgId_S2CUserLoginId: {pb.S2CUserLogin{}, s.onUserLogin},
|
||
pb.MsgId_S2CUserLogoutId: {pb.S2CUserLogout{}, s.onUserLogout},
|
||
})
|
||
}
|
||
|
||
// 收到登陆成功消息,判断是否顶号
|
||
func (s *GateService) onUserLogin(iMsg *ipb.InternalMsg, conn ws.IConn, msg *pb.S2CUserLogin) {
|
||
if conn == nil {
|
||
return
|
||
}
|
||
// 登陆失败,回传玩家
|
||
if msg.Code != pb.ErrCode_OK {
|
||
s.SendClientMsg(conn, iMsg.ServiceName, int32(pb.MsgId_S2CUserLoginId), msg)
|
||
return
|
||
}
|
||
s.SendClientMsg(conn, iMsg.ServiceName, int32(pb.MsgId_S2CUserLoginId), msg)
|
||
s.wss.SetUserId(conn.Id(), msg.UserId)
|
||
sName := s.bindService.LoadFromRedis(conn.UserId(), pb.ServiceTypeId_STI_Gate)
|
||
// 网关不同,说明玩家在其它网关上登陆,
|
||
if sName != "" && sName != s.Name() {
|
||
s.SendServiceMsg(service.TopicEx(sName), conn, int32(pb.MsgId_S2CUserLogoutId), &pb.S2CUserLogout{Code: pb.ErrCode_LoginDiffLoc})
|
||
}
|
||
// 广播玩家上线
|
||
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) {
|
||
if conn == nil {
|
||
return
|
||
}
|
||
s.SendClientMsg(conn, iMsg.ServiceName, int32(pb.MsgId_S2CUserLogoutId), msg)
|
||
// 登出的清理工作由WsOnDisconnect实现
|
||
conn.NotifyClose()
|
||
}
|