MCPcopy
hub / github.com/aceld/zinx / Handle

Method Handle

zinx_app_demo/mmo_game/api/move.go:19–47  ·  view source on GitHub ↗
(request ziface.IRequest)

Source from the content-addressed store, hash-verified

17}
18
19func (*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}

Callers

nothing calls this directly

Calls 6

GetPlayerByPIDMethod · 0.80
UpdatePosMethod · 0.80
GetDataMethod · 0.65
GetPropertyMethod · 0.65
GetConnectionMethod · 0.65
StopMethod · 0.65

Tested by

no test coverage detected