* 处理一个回执业务 */
(msg *Message)
| 161 | 处理一个回执业务 |
| 162 | */ |
| 163 | func (this *TcpClient) DoMsg(msg *Message) { |
| 164 | //处理消息 |
| 165 | fmt.Println(fmt.Sprintf("msg ID :%d, data len: %d", msg.MsgID, msg.Len)) |
| 166 | if msg.MsgID == 1 { |
| 167 | //服务器回执给客户端 分配ID |
| 168 | |
| 169 | //解析proto |
| 170 | syncpID := &pb.SyncPID{} |
| 171 | _ = proto.Unmarshal(msg.Data, syncpID) |
| 172 | |
| 173 | //给当前客户端ID进行赋值 |
| 174 | this.PID = syncpID.PID |
| 175 | } else if msg.MsgID == 200 { |
| 176 | //服务器回执客户端广播数据 |
| 177 | |
| 178 | //解析proto |
| 179 | bdata := &pb.BroadCast{} |
| 180 | _ = proto.Unmarshal(msg.Data, bdata) |
| 181 | |
| 182 | //初次玩家上线 广播位置消息 |
| 183 | if bdata.Tp == 2 && bdata.PID == this.PID { |
| 184 | //本人 |
| 185 | //更新客户端坐标 |
| 186 | this.X = bdata.GetP().X |
| 187 | this.Y = bdata.GetP().Y |
| 188 | this.Z = bdata.GetP().Z |
| 189 | this.V = bdata.GetP().V |
| 190 | fmt.Println(fmt.Sprintf("player ID: %d online.. at(%f,%f,%f,%f)", bdata.PID, this.X, this.Y, this.Z, this.V)) |
| 191 | |
| 192 | //玩家已经成功上线 |
| 193 | this.isOnline <- true |
| 194 | |
| 195 | } else if bdata.Tp == 1 { |
| 196 | fmt.Println(fmt.Sprintf("世界聊天,玩家%d说的话是: %s", bdata.PID, bdata.GetContent())) |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | func (this *TcpClient) Start() { |
| 202 | go func() { |
no test coverage detected