Skip to content

Commit

Permalink
client Login,message distribute
Browse files Browse the repository at this point in the history
  • Loading branch information
jzy committed Aug 25, 2021
1 parent a50fb71 commit f920f62
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Navmesh寻路 [服务器](https://github.com/jzyong/game-server/tree/master/game


### TODO
* Influxdb
* mongoDB
* 多网关测试,消息分发
* 编写测试客户端(测试tcp通信,模拟登录流程) (转发大厅返回消息给client)
Expand Down
15 changes: 14 additions & 1 deletion src/gate/manager/game_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewGameManager() *GameManager {
func (this *GameManager) Init() error {
log.Info("GameManager:init")
//启动网络
server, err := network.NewServer("game", config.GateConfigInstance.GameUrl, network.InnerServer, nil)
server, err := network.NewServer("game", config.GateConfigInstance.GameUrl, network.InnerServer, unregisterGameMessageDistribute)
if err != nil {
return err
}
Expand Down Expand Up @@ -104,6 +104,19 @@ func gameChannelInactive(channel network.Channel) {
}
}

//转发不在本地处理的消息
func unregisterGameMessageDistribute(tcpMessage network.TcpMessage) {
//转发给客户端
log.Debugf("转发消息:%d", tcpMessage.GetMsgId())
user, _ := GetUserManager().GetIdUser(tcpMessage.GetObjectId())
if user != nil {
user.SendMessageToClient(tcpMessage)
} else {
log.Warnf("%d send message %d fail, user not find", tcpMessage.GetObjectId(), tcpMessage.GetMsgId())
}

}

func (this *GameManager) Stop() {
// 关闭服务器
if this.server != nil {
Expand Down
9 changes: 9 additions & 0 deletions src/gate/manager/user_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ func (u *User) SendTcpMessageToHall(tcpMessage network.TcpMessage) {
network.SendMsg(u.GameChannel, tcpMessage.GetMsgId(), u.SessionId, u.Id, tcpMessage.GetData())
}

//发送消息给客户端
func (u *User) SendMessageToClient(tcpMessage network.TcpMessage) {
if u.ClientChannel == nil {
log.Warn("%d client channel is nil,message %d send fail", u.Id, tcpMessage.GetMsgId())
return
}
network.SendClientMsg(u.ClientChannel, tcpMessage.GetMsgId(), tcpMessage.GetData())
}

func (u *User) GetGameChanel() network.Channel {
if u.GameChannel == nil {
//TODO 获取链接
Expand Down

0 comments on commit f920f62

Please sign in to comment.