(request ziface.IRequest)
| 17 | } |
| 18 | |
| 19 | func (*MoveApi) Handle(request ziface.IRequest) { |
| 20 | //1. MoveApi Player movement |
| 21 | // (1. 将客户端传来的proto协议解码) |
| 22 | msg := &pb.Position{} |
| 23 | err := proto.Unmarshal(request.GetData(), msg) |
| 24 | if err != nil { |
| 25 | fmt.Println("Move: Position Unmarshal error ", err) |
| 26 | return |
| 27 | } |
| 28 | |
| 29 | // 2. Identify which player sent the current message, retrieve from the connection property pID |
| 30 | // (2. 得知当前的消息是从哪个玩家传递来的,从连接属性pID中获取) |
| 31 | pID, err := request.GetConnection().GetProperty("pID") |
| 32 | if err != nil { |
| 33 | fmt.Println("GetProperty pID error", err) |
| 34 | request.GetConnection().Stop() |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | //fmt.Printf("user pID = %d , move(%f,%f,%f,%f)\n", pID, msg.X, msg.Y, msg.Z, msg.V) |
| 39 | |
| 40 | // 3. Get the player object based on pID |
| 41 | // (3. 根据pID得到player对象) |
| 42 | player := core.WorldMgrObj.GetPlayerByPID(pID.(int32)) |
| 43 | |
| 44 | // 4. Have the player object initiate the broadcast of movement position information |
| 45 | // (4. 让player对象发起移动位置信息广播) |
| 46 | player.UpdatePos(msg.X, msg.Y, msg.Z, msg.V) |
| 47 | } |
nothing calls this directly
no test coverage detected