Example #1
0
    def handleData(self):
        if self._packet_len >= self._expected_len:
            type = Packet()
            buf = ''.join(self._packet)
            while len(buf) >= self._expected_len:
                type.unpack(buf)
                if type.length <= len(buf):

                    if type.type in PacketFactory:
                        packet = PacketFactory[type.type]()
                        buf = packet.unpack(buf)
                        if type.type != PACKET_PING:
                            self.log.debug("%s(%d bytes) => %s", self._prefix, type.length, packet)
                        if self._poll:
                            self.pushPacket(packet)
                        else:
                            self._handler(packet)
                    else:
                        self.log.warn(
                            "%s: unknown message received (id %d, length %d)\n",
                            self._prefix, type.type, type.length
                        )
                        buf = buf[1:]
                    self._expected_len = Packet.format_size
                else:
                    self._expected_len = type.length
            self._packet[:] = [buf]
            self._packet_len = len(buf)
Example #2
0
    def handleData(self):
        if self._packet_len >= self._expected_len:
            type = Packet()
            buf = ''.join(self._packet)
            while len(buf) >= self._expected_len:
                type.unpack(buf)
                if type.length <= len(buf):

                    if type.type in PacketFactory:
                        packet = PacketFactory[type.type]()
                        buf = packet.unpack(buf)
                        if type.type != PACKET_PING:
                            self.log.debug("%s(%d bytes) => %s", self._prefix,
                                           type.length, packet)
                        if self._poll:
                            self.pushPacket(packet)
                        else:
                            self._handler(packet)
                    else:
                        self.log.warn(
                            "%s: unknown message received (id %d, length %d)\n",
                            self._prefix, type.type, type.length)
                        buf = buf[1:]
                    self._expected_len = Packet.format_size
                else:
                    self._expected_len = type.length
            self._packet[:] = [buf]
            self._packet_len = len(buf)
Example #3
0
    def test01_rest_filter_finished_request(self):
        """proxyfilter.rest_filter should ignore finished request"""
        class Transport:
            def write(self, data):
                pass

        class Channel:
            transport = Transport()

            def requestDone(self, request):
                pass

        class Service:
            verbose = 6

            def packet2resthost(self, packet):
                return (None, None, None)

        class Resource:
            service = Service()

        class Site:
            resource = Resource()

        class Packet:
            pass

        r = pokersite.Request(Channel(), True)
        pinput = '{"type": "PacketPing"}'
        r.gotLength(len(pinput))
        r.handleContentChunk(pinput)
        r.setResponseCode(http.OK)
        r.write("FINISHED")
        r.finish()
        r.noLongerQueued()
        proxyfilter.rest_filter(Site(), r, Packet())
Example #4
0
                best hand is the hand that win the most money
    serial      integer uniquely identifying a player.
    game_id     integer uniquely identifying a game.
    =========== ======================================================================================================================================================================================
    """

    info = PacketPokerCards.info + (
        ("side", "", 's'),
        ("hand", "", 's'),
        ("bestcards", [], 'Bl'),
        ("board", [], 'Bl'),
        ("besthand", 0, 'B'),
    )


Packet.infoDeclare(globals(), PacketPokerBestCards, PacketPokerCards,
                   'POKER_BEST_CARDS', 170)  # 0xaa # %SEQ%

########################################


class PacketPokerPotChips(Packet):
    """\
    =========== ======================================================================================================================================================================================
    Semantics   the "bet" put in the "index" pot of the "game_id" game.
    Direction   client <=> client
    context     this packet is sent at least each time the pot index is
                updated.
    bet         list of pairs ( chip_value, chip_count ).
    index       integer uniquely identifying a side pot in the range [0,10[
    game_id     integer uniquely identifying a game.
    =========== ======================================================================================================================================================================================
Example #5
0
    hand        readable string of the name best hand
    besthand    0 if it's not the best hand and 1 if it's the best hand
                best hand is the hand that win the most money
    serial      integer uniquely identifying a player.
    game_id     integer uniquely identifying a game.
    =========== ======================================================================================================================================================================================
    """

    info = PacketPokerCards.info + ( ("side", "", 's'),
                                     ("hand", "", 's'),
                                     ("bestcards", [], 'Bl'),
                                     ("board", [], 'Bl'),
                                     ("besthand", 0, 'B'),
                                     )

Packet.infoDeclare(globals(), PacketPokerBestCards, PacketPokerCards, 'POKER_BEST_CARDS', 170) # 0xaa # %SEQ%

########################################

class PacketPokerPotChips(Packet):
    """\
    =========== ======================================================================================================================================================================================
    Semantics   the "bet" put in the "index" pot of the "game_id" game.
    Direction   client <=> client
    context     this packet is sent at least each time the pot index is
                updated.
    bet         list of pairs ( chip_value, chip_count ).
    index       integer uniquely identifying a side pot in the range [0,10[
    game_id     integer uniquely identifying a game.
    =========== ======================================================================================================================================================================================
    """