You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

38 lines
962 B

package api
import (
"fmt"
"github.com/golang/protobuf/proto"
"github.com/aceld/zinx/ziface"
"github.com/aceld/zinx/zinx_app_demo/mmo_game/core"
"github.com/aceld/zinx/zinx_app_demo/mmo_game/pb"
"github.com/aceld/zinx/znet"
)
//世界聊天 路由业务
type WorldChatApi struct {
znet.BaseRouter
}
func (*WorldChatApi) Handle(request ziface.IRequest) {
//1. 将客户端传来的proto协议解码
msg := &pb.Talk{}
err := proto.Unmarshal(request.GetData(), msg)
if err != nil {
fmt.Println("Talk Unmarshal error ", err)
return
}
//2. 得知当前的消息是从哪个玩家传递来的,从连接属性pid中获取
pid, err := request.GetConnection().GetProperty("pid")
if err != nil {
fmt.Println("GetProperty pid error", err)
request.GetConnection().Stop()
return
}
//3. 根据pid得到player对象
player := core.WorldMgrObj.GetPlayerByPid(pid.(int32))
//4. 让player对象发起聊天广播请求
player.Talk(msg.Content)
}