# Path: twistedbot/packets.py
# def ucs2(name):
#     def ucs2_encode(data, errors="replace"):
#         def encode(self, input, final=False):
#     def _encode(self, obj, context):
# def AlphaString(name):
# def Bool(*args, **kwargs):
# def ByteString(name, size_name, encoding=None):
#     def _decode(self, obj, context):
# def NBTdata(name, size_name):
# def itemstack_as_slotdata(itemstack):
#     def _decode(self, obj, context):
#     def _encode(self, obj, context):
# def packet_stream_print_header(context):
# def print_and_return(pv, rv):
# def parse_packets(bytestream):
# def parse_packets_incrementally(bytestream):
# def make_packet(packet, payload, template=None):
# def make_error_packet(message):
#     class UCS2IncrementalEncoder(IncrementalEncoder):
#     class UCS2IncrementalDecoder(BufferedIncrementalDecoder):
#     class UCS2StreamWriter(StreamWriter):
#     class UCS2StreamReader(StreamReader):
# class DoubleAdapter(LengthValueAdapter):
# class NBTAdapter(Adapter):
# class MetadataAdapter(Adapter):
# 
# Path: twistedbot/packets.py
# def ucs2(name):
#     def ucs2_encode(data, errors="replace"):
#         def encode(self, input, final=False):
#     def _encode(self, obj, context):
# def AlphaString(name):
# def Bool(*args, **kwargs):
# def ByteString(name, size_name, encoding=None):
#     def _decode(self, obj, context):
# def NBTdata(name, size_name):
# def itemstack_as_slotdata(itemstack):
#     def _decode(self, obj, context):
#     def _encode(self, obj, context):
# def packet_stream_print_header(context):
# def print_and_return(pv, rv):
# def parse_packets(bytestream):
# def parse_packets_incrementally(bytestream):
# def make_packet(packet, payload, template=None):
# def make_error_packet(message):
#     class UCS2IncrementalEncoder(IncrementalEncoder):
#     class UCS2IncrementalDecoder(BufferedIncrementalDecoder):
#     class UCS2StreamWriter(StreamWriter):
#     class UCS2StreamReader(StreamReader):
# class DoubleAdapter(LengthValueAdapter):
# class NBTAdapter(Adapter):
# class MetadataAdapter(Adapter):


import operator
import types
import twistedbot.logbot as logbot
from collections import defaultdict
from twistedbot.packets import packets
from twistedbot.packets import Container, Metadata
from pynbt import NBTFile
def process_packets(streamtype, pcks, encrypted=False, leftover=None):
    """
        main function to use
        @streamtype - values 'CLIENT' or 'SERVER', depending where this data came from
    """
    if not pcks:
        return
    for p in pcks:
        packet_id = p[0]
        packet_body = p[1]
        statistics[streamtype][packet_id] += 1
        if packet_id in ignore_packets:
            continue
        if filter_packets and packet_id not in filter_packets:
            continue
        log.msg("id %d %s\n%s" % (packet_id, packets[packet_id].name, format_packet(packet_body)), header=streamtype)


def finish():
    """
        this is called when the proxy is about to exit to the system
        put here anything usefull, like printing statistics :)
    """
    log.msg("STATISTICS")
    combined = defaultdict(int)
    for ptype in statistics.keys():
        psum = 0
        log.msg('from %s' % ptype)
        sorted_p = sorted(statistics[ptype].iteritems(), key=operator.itemgetter(1), reverse=True)
        for pid, pcount in sorted_p:

# Path: twistedbot/packets.py
# def ucs2(name):
#     def ucs2_encode(data, errors="replace"):
#         def encode(self, input, final=False):
#     def _encode(self, obj, context):
# def AlphaString(name):
# def Bool(*args, **kwargs):
# def ByteString(name, size_name, encoding=None):
#     def _decode(self, obj, context):
# def NBTdata(name, size_name):
# def itemstack_as_slotdata(itemstack):
#     def _decode(self, obj, context):
#     def _encode(self, obj, context):
# def packet_stream_print_header(context):
# def print_and_return(pv, rv):
# def parse_packets(bytestream):
# def parse_packets_incrementally(bytestream):
# def make_packet(packet, payload, template=None):
# def make_error_packet(message):
#     class UCS2IncrementalEncoder(IncrementalEncoder):
#     class UCS2IncrementalDecoder(BufferedIncrementalDecoder):
#     class UCS2StreamWriter(StreamWriter):
#     class UCS2StreamReader(StreamReader):
# class DoubleAdapter(LengthValueAdapter):
# class NBTAdapter(Adapter):
# class MetadataAdapter(Adapter):
# 
# Path: twistedbot/packets.py
# def ucs2(name):
#     def ucs2_encode(data, errors="replace"):
#         def encode(self, input, final=False):
#     def _encode(self, obj, context):
# def AlphaString(name):
# def Bool(*args, **kwargs):
# def ByteString(name, size_name, encoding=None):
#     def _decode(self, obj, context):
# def NBTdata(name, size_name):
# def itemstack_as_slotdata(itemstack):
#     def _decode(self, obj, context):
#     def _encode(self, obj, context):
# def packet_stream_print_header(context):
# def print_and_return(pv, rv):
# def parse_packets(bytestream):
# def parse_packets_incrementally(bytestream):
# def make_packet(packet, payload, template=None):
# def make_error_packet(message):
#     class UCS2IncrementalEncoder(IncrementalEncoder):
#     class UCS2IncrementalDecoder(BufferedIncrementalDecoder):
#     class UCS2StreamWriter(StreamWriter):
#     class UCS2StreamReader(StreamReader):
# class DoubleAdapter(LengthValueAdapter):
# class NBTAdapter(Adapter):
# class MetadataAdapter(Adapter):


# Path: twistedbot/proxy_processors/default.py
import operator
import types
import twistedbot.logbot as logbot
from collections import defaultdict
from twistedbot.packets import packets
from twistedbot.packets import Container, Metadata
from pynbt import NBTFile

def process_packets(streamtype, pcks, encrypted=False, leftover=None):
    """
        main function to use
        @streamtype - values 'CLIENT' or 'SERVER', depending where this data came from
    """
    if not pcks:
        return
    for p in pcks:
        packet_id = p[0]
        packet_body = p[1]
        statistics[streamtype][packet_id] += 1
        if packet_id in ignore_packets:
            continue
        if filter_packets and packet_id not in filter_packets:
            continue
        log.msg("id %d %s\n%s" % (packet_id, packets[packet_id].name, format_packet(packet_body)), header=streamtype)


def finish():
    """
        this is called when the proxy is about to exit to the system
        put here anything usefull, like printing statistics :)
    """
    log.msg("STATISTICS")
    combined = defaultdict(int)
    for ptype in statistics.keys():
        psum = 0
        log.msg('from %s' % ptype)
        sorted_p = sorted(statistics[ptype].iteritems(), key=operator.itemgetter(1), reverse=True)
        for pid, pcount in sorted_p:

            log.msg("\tid:\t%d\tcount\t%d\t%s" % (pid, pcount, packets[pid].name))