func (self *Player) HandleRequest(data []byte, conn net.Conn) { self.lastActive = time.Now().Unix() self.Conn = conn // defer func() { // if x := recover(); x != nil { // fmt.Println("caught panic in player HandleRequest(): ", x) // } // }() reader := packet.Reader(data) protocol := reader.ReadUint16() decode_method := api.IdToName[protocol] handler, err := routes.Route(decode_method) if err == nil { params := api.Decode(decode_method, reader) encode_method, response := handler(self, params) writer := api.Encode(encode_method, response) self.processed++ // INFO("Processed: ", self.processed, " Response Data: ", response_data) if self.Conn != nil { writer.Send(self.Conn) } } else { ERR(err) } }
func (self *Player) SendData(encode_method string, msg interface{}) { if self.Conn != nil { writer := api.Encode(encode_method, msg) writer.Send(self.Conn) } }