Ejemplo n.º 1
0
    def write_state(self, room_positions: CubeDataStream,
                    room_messages: CubeDataStream) -> None:
        if self.state.position is not None:
            room_positions.write(self.state.position)

        if not self.state.messages.empty():
            swh.put_clientdata(room_messages, self, self.state.messages)
Ejemplo n.º 2
0
def get_ext_info_reply_cds(rcds):
    cds = CubeDataStream()

    cds.write(rcds.data)

    cds.putint(EXT_ACK)
    cds.putint(EXT_VERSION)

    return cds
Ejemplo n.º 3
0
def get_ext_info_reply_cds(rcds):
    cds = CubeDataStream()

    cds.write(rcds.data)

    cds.putint(EXT_ACK)
    cds.putint(EXT_VERSION)

    return cds
Ejemplo n.º 4
0
    def flush_messages(self) -> None:
        try:

            class ClientBufferReference(object):
                def __init__(self, client, positions_next_byte, positions_size,
                             messages_next_byte, messages_size):
                    self.client = client
                    self.positions_next_byte = positions_next_byte
                    self.positions_size = positions_size
                    self.messages_next_byte = messages_next_byte
                    self.messages_size = messages_size

            room_positions = CubeDataStream()
            room_messages = CubeDataStream()

            references = []

            positions_next_byte = 0
            messages_next_byte = 0

            for client in self._client_collection.to_iterator():
                player = client.get_player()

                positions_first_byte = positions_next_byte
                messages_first_byte = messages_next_byte

                player.write_state(room_positions, room_messages)

                positions_next_byte = len(room_positions)
                messages_next_byte = len(room_messages)

                positions_size = positions_next_byte - positions_first_byte
                messages_size = messages_next_byte - messages_first_byte

                references.append(
                    ClientBufferReference(client, positions_next_byte,
                                          positions_size, messages_next_byte,
                                          messages_size))

            positions_len = len(room_positions)
            messages_len = len(room_messages)

            room_positions.write(room_positions)
            room_messages.write(room_messages)

            position_data = memoryview(room_positions.data)
            message_data = memoryview(room_messages.data)

            for ref in references:
                client = ref.client

                pnb = ref.positions_next_byte
                mnb = ref.messages_next_byte

                psize = ref.positions_size
                msize = ref.messages_size

                if positions_len - psize > 0:
                    # TODO: Use no_allocate option here
                    client.send(
                        0, position_data[pnb:pnb + (positions_len - psize)],
                        False, False)

                if messages_len - msize > 0:
                    # TODO: Use no_allocate option here
                    client.send(1,
                                message_data[mnb:mnb + (messages_len - msize)],
                                True, False)

            for player in self._player_collection.to_iterator():
                player.state.clear_flushed_state()
        except:
            traceback.print_exc()
Ejemplo n.º 5
0
    def flush_messages(self):
        try:
            class ClientBufferReference(object):
                def __init__(self, client, positions_next_byte, positions_size, messages_next_byte, messages_size):
                    self.client = client
                    self.positions_next_byte = positions_next_byte
                    self.positions_size = positions_size
                    self.messages_next_byte = messages_next_byte
                    self.messages_size = messages_size

            room_positions = CubeDataStream()
            room_messages = CubeDataStream()

            references = []

            positions_next_byte = 0
            messages_next_byte = 0

            for client in self._client_collection.to_iterator():
                player = client.get_player()

                positions_first_byte = positions_next_byte
                messages_first_byte = messages_next_byte

                player.write_state(room_positions, room_messages)

                positions_next_byte = len(room_positions)
                messages_next_byte = len(room_messages)

                positions_size = positions_next_byte - positions_first_byte
                messages_size = messages_next_byte - messages_first_byte

                references.append(ClientBufferReference(client, positions_next_byte, positions_size, messages_next_byte, messages_size))

            positions_len = len(room_positions)
            messages_len = len(room_messages)

            room_positions.write(room_positions)
            room_messages.write(room_messages)

            position_data = memoryview(room_positions.data)
            message_data = memoryview(room_messages.data)

            for ref in references:
                client = ref.client

                pnb = ref.positions_next_byte
                mnb = ref.messages_next_byte

                psize = ref.positions_size
                msize = ref.messages_size

                if positions_len - psize > 0:
                    # TODO: Use no_allocate option here
                    client.send(0, position_data[pnb:pnb + (positions_len - psize)], False, False)

                if messages_len - msize > 0:
                    # TODO: Use no_allocate option here
                    client.send(1, message_data[mnb:mnb + (messages_len - msize)], True, False)

            for player in self._player_collection.to_iterator():
                player.state.clear_flushed_state()
        except:
            traceback.print_exc()