示例#1
0
def client_sync():
    global time_since_last_update

    should_update = time.time() - time_since_last_update > 0.01
    if should_update:
        time_since_last_update = time.time()
    else:
        return


    client_manager = services.client_manager()
    client = None

    if client_manager is not None:
        client = client_manager.get_first_client()

        if client is None:
            return
    else:
        return
    while True:
        pop_element = commandQueue.pop_incoming_command()
        if not pop_element:
            # no more entries left in the queue.
            return False


        if isinstance(pop_element, ProtocolBufferMessage):
            omega.send(client.id, pop_element.msg_id, pop_element.msg)
        elif isinstance(pop_element, HeartbeatMessage):
            # we don't do anything with Heartbeats.
            ts4mp_log("latency", time.time() - pop_element.sent_time, force = True)
            pass
示例#2
0
 def send_message(self, msg_id, msg):
     if self.active:
         omega.send(self.id, msg_id, msg.SerializeToString())
     else:
         logger.warn(
             'Message sent to client {} after it has already disconnected.',
             self)
示例#3
0
def client_sync():
    output("locks", "acquiring incoming lock 1")

    with incoming_lock:
        global incoming_commands
        output("receive", "{} \n".format(len(incoming_commands)))
        for unpacked_msg_data in incoming_commands:
            if type(unpacked_msg_data) is Message:
                try:
                    client = services.client_manager().get_first_client()
                    client_instance = services.client_manager().get_first_client()
                    
                    if client == None:
                        return
                except Exception:
                    continue
                    
                omega.send(client_instance.id, unpacked_msg_data.msg_id, unpacked_msg_data.msg)
                incoming_commands.remove(unpacked_msg_data)

            elif type(unpacked_msg_data) is File:
                client_file = open(get_file_matching_name(unpacked_msg_data.file_name)[0], "wb")
                new_architecture_data = unpacked_msg_data.file_contents
                client_file.write(new_architecture_data)
                client_file.close()
                incoming_commands.remove(unpacked_msg_data)
    output("locks", "releasing incoming lock")
def send_message_server(self, msg_id, msg):
    # Send message override for the server.
    # This overrides it so any message for a client with an id of 1000 gets packed into a Message and is placed in the outgoing_commands list for
    # sending out to the multiplayer clients.
    # Only supports one multiplayer client at the moment.

    # TODO: You should not be referring to a global variable that is in a different module
    if self.id != 1000 and self.active:
        omega.send(self.id, msg_id, msg.SerializeToString())
        # ts4mp_log_debug("msg", msg)
    else:
        message = Message(msg_id, msg.SerializeToString())

        ts4mp_log("locks", "acquiring outgoing lock")

        # We use a lock here because outgoing_commands is also being altered by the client socket thread.
        with outgoing_lock:
            outgoing_commands.append(message)

        ts4mp_log("locks", "releasing outgoing lock")
def send_message_server(self, msg_id, msg):
    #Send message override for the server.
    #This overrides it so any message for a client with an id of 1000 gets packed into a Message and is placed in the outgoing_commands list for
    #sending out to the multiplayer clients.
    #Only supports one multiplayer client at the moment.

    global outgoing_commands
    if self.id != 1000:
        if self.active:

            omega.send(self.id, msg_id, msg.SerializeToString())
            # output_irregardelessly("msg", msg)
    else:
        message = Message(msg_id, msg.SerializeToString())
        output("locks", "acquiring outgoing lock")
        #We use a lock here because outgoing_commands is also being altered by the client socket thread.
        with outgoing_lock:
            outgoing_commands.append(message)
        output("locks", "releasing outgoing lock")
        pass
示例#6
0
def send_message_server(self, msg_id, msg):
    # Send message override for the server.
    # This overrides it so any message for a client with an id of 1000 gets packed into a Message and is placed in the outgoing_commands list for
    # sending out to the multiplayer clients.
    # Only supports one multiplayer client at the moment.
    ts4mp_log("network", "Sending message to client id: {}".format(self.id))

    if self.id != 1000:
        if self.active:
            omega.send(self.id, msg_id, msg.SerializeToString())
        # ts4mp_log_debug("msg", msg)
    else:
        message = ProtocolBufferMessage(msg_id, msg.SerializeToString())
        ts4mp_log("locks", "acquiring outgoing lock")

        # We use a lock here because outgoing_commands is also being altered by the client socket thread.
        commandQueue.queue_outgoing_command(message)
        ts4mp_log("network",
                  "Queueing outgoing command for {}".format(self.id))

        ts4mp_log("locks", "releasing outgoing lock")
示例#7
0
def client_sync():
    global time_since_last_update

    should_update = time.time() - time_since_last_update > 0.1
    if should_update:
        time_since_last_update = time.time()
    else:
        return

    with incoming_lock:
        global incoming_commands

        client_manager = services.client_manager()
        client = None

        if client_manager is not None:
            client = client_manager.get_first_client()

            if client is None:
                return
        else:
            return
        for unpacked_msg_data in incoming_commands:
            if isinstance(unpacked_msg_data, ProtocolBufferMessage):
                omega.send(client.id, unpacked_msg_data.msg_id, unpacked_msg_data.msg)
                incoming_commands.remove(unpacked_msg_data)
            elif isinstance(unpacked_msg_data, HeartbeatMessage):
                incoming_commands.remove(unpacked_msg_data)

            elif type(unpacked_msg_data) is ArbritraryFileMessage:
                (file_path, _) = get_file_matching_name(unpacked_msg_data.file_name)
                client_file = open(file_path, "wb")
                new_architecture_data = unpacked_msg_data.file_contents

                client_file.write(new_architecture_data)
                client_file.close()

                incoming_commands.remove(unpacked_msg_data)
示例#8
0
def client_sync():
    ts4mp_log("locks", "acquiring incoming lock 1")
    ts4mp_log("simulate", "Syncing client.")

    with incoming_lock:
        global incoming_commands

        client_manager = services.client_manager()
        client = None

        if client_manager is not None:
            client = client_manager.get_first_client()

            if client is None:
                return
        else:
            return
        ts4mp_log("simulate",
                  "Sending {} commands.".format(len(incoming_commands)),
                  force=False)
        for unpacked_msg_data in incoming_commands:
            if type(unpacked_msg_data) is Message:
                omega.send(client.id, unpacked_msg_data.msg_id,
                           unpacked_msg_data.msg)
                incoming_commands.remove(unpacked_msg_data)
            elif type(unpacked_msg_data) is File:
                (file_path,
                 _) = get_file_matching_name(unpacked_msg_data.file_name)
                client_file = open(file_path, "wb")
                new_architecture_data = unpacked_msg_data.file_contents

                client_file.write(new_architecture_data)
                client_file.close()

                incoming_commands.remove(unpacked_msg_data)

    ts4mp_log("locks", "releasing incoming lock")
示例#9
0
 def send_serialized_message(self, msg_id, msg):
     if self.active:
         omega.send(self.id, msg_id, msg)
     else:
         logger.warn('Serialized message sent to client {} after it has already disconnected.', self)