def get_distributor_with_active_sim_matching_sim_id(self, sim_id):
     for distributor in self.client_distributors:
         if distributor.client.active_sim != None:
             output_irregardelessly(
                 "chat", "Active client sim id: {}".format(
                     distributor.client.active_sim.id))
             if distributor.client.active_sim.id == sim_id:
                 return distributor
     return None
Beispiel #2
0
def get_file_matching_name(name):
    for root, dirs, files in os.walk("{}/saves/scratch".format(user_directory.replace("Mods/Heuristics/Scripts/", ""))):
        for file_name in files:
            replaced = file_name.replace("zoneObjects-", "").replace("-6.sav", "").strip()
            replaced = replaced[1:]
            output_irregardelessly("zone_id", "{} , {}".format(replaced, name))
            if name == replaced:
                file_path = str(os.path.join(root, file_name))
                break
    return file_path, file_name
    def listen_loop(self):
        global incoming_commands
        self.serversocket.listen(5)
        self.clientsocket, address = self.serversocket.accept()
        output_irregardelessly("network", "Client Connect")

        clientsocket = self.clientsocket

        size = None
        data = b''

        while True:
            # output_irregardelessly("network", "Server Listen Update")
            incoming_commands, data, size = generic_listen_loop(
                clientsocket, incoming_commands, data, size)
def wrapper_client(func, *args, **kwargs):
    #Wrapper for functions that have their data needed to be sent to the server.
    #This is used for client commands so the server can respond.
    #For example, selecting a choice from the pie menu.
    #Only supports one multiplayer client at the moment.
    output("locks", "acquiring outgoing lock")

    with outgoing_lock:
        output_irregardelessly(
            "arg_handler",
            "\n" + str(func.__name__) + ", " + str(args) + "  " + str(kwargs))

        outgoing_commands.append("\n" + str(func.__name__) + ", " + str(args) +
                                 "  " + str(kwargs))

        def do_nothing():
            pass

        return do_nothing
    output("locks", "releasing outgoing lock")
Beispiel #5
0
def do_command(command_name, *args):
    command_exists = command_name in command_functions
    output_irregardelessly("commands", command_exists)
    if command_exists:
        command_functions[command_name](*args)
        output_irregardelessly("commands", "There is a command named: {}. Executing it.".format(command_name))

    else:
        output_irregardelessly("commands", "There is no such command named: {}!".format(command_name))
    return 
Beispiel #6
0
def server_sync():
  output("locks", "acquiring incoming lock 1")
  with incoming_lock:
    global incoming_commands
    client_instance = services.client_manager().get_first_client()

    for command in incoming_commands:
        
        current_line = command.split(',')
        function_name = current_line[0]
        if function_name == '':
            continue
        parsed_args = []

        for arg_index in range(1, len(current_line)):
            arg = current_line[arg_index].replace(')', '').replace('{}', '').replace('(', '')
            if "'" not in arg:
                arg = regex.sub('', arg)
                arg = arg.replace('<._ = ', '').replace('>', '')
            parsed_arg = parse_arg(arg)
            parsed_args.append(parsed_arg)
        #set connection to other client
        client_id = 1000
        parsed_args[-1] = client_id
        function_to_execute = "{}({})".format(function_name, str(parsed_args).replace('[', '').replace(']',''))
        function_name = function_name.strip()
        output_irregardelessly("client_specific", "New function called {} recieved".format(function_name))
        if function_name in pendable_functions:
            with pending_commands_lock:
                if function_name not in pending_commands:
                    pending_commands[function_name] = []
                if client_id not in pending_commands[function_name]:
                    pending_commands[function_name].append(client_id)
        output_irregardelessly('arg_handler', str(function_to_execute) )
        try:
            do_command(function_name, *parsed_args)
        except Exception as e:
            output_irregardelessly("Execution Errors", "Something happened: {}".format(e))
        incoming_commands.remove(command)
  output("locks", "releasing incoming lock")
 def add_event_for_client(self, client, msg_id, msg, immediate):
     client.add_event(msg_id, msg, immediate)
     output_irregardelessly(
         "events", "Sending msg with id {} to client {}".format(
             msg_id, client.client.id))