func Dispatch(player player.Player, packet encoding.Decodable) { typeString := reflect.TypeOf(packet).String() if handler, ok := routingTable[typeString]; ok { handler(player, packet) } else { player.Log().Info("Unhandled packet of type %v: %v", typeString, packet) } }
// packetConsumer is the goroutine which picks packets from the readQueue and does something with them func (svc *GameService) packetConsumer(client player.Player) { L: for { select { case <-client.Conn().DisconnectChan: break L case pkt := <-client.Conn().Read: if _, ok := pkt.(*game_protocol.UnknownPacket); ok { /* unknown packet; dump to the log */ client.Log().Debug("Got unknown packet: %v", pkt) continue } packet.Dispatch(client, pkt) } } }
// decodeLoginBlock handles the unencrypted login block func (svc *GameService) decodeLoginBlock(client player.Player) error { loginBlock := game_protocol.InboundLoginBlock{} if err := loginBlock.Decode(client.Conn().ReadBuffer, nil); err != nil { return err } expectedSecureBlockSize := int(loginBlock.LoginLen) - ((9 * 4) + 1 + 1 + 1 + 2) if expectedSecureBlockSize != int(loginBlock.SecureBlockSize) { client.Log().Error("Secure block size mismatch: got %v expected %v", loginBlock.SecureBlockSize, expectedSecureBlockSize) client.Conn().Disconnect() } client.SetSecureBlockSize(int(loginBlock.SecureBlockSize)) client.SetDecodeFunc(svc.decodeSecureBlock) return nil }