Example #1
0
def change_persona_client(name, _connection=None):
    output = sims4.commands.CheatOutput(_connection)
    # output("working")
    client_manager = services.client_manager()
    client = client_manager.get(1000)
    client._account._persona_name = name
    output(client._account._persona_name)
    def add_event(self, msg_id, msg, immediate=False):
        if self.client is None:
            logger.error(
                'Could not add event {0} because there are no attached clients',
                msg_id)
            return
        output("client_specific", "Trying to add an event to a client.")
        function_name = get_command_function_from_pb(msg_id)
        output("client_specific", "Function is {}".format(function_name))

        if function_name is not None:
            client_id = try_get_client_id_of_pending_command(function_name)
            output("client_specific", "Client is {}".format(client_id))

            if client_id is not None:
                remove_earliest_command_client(function_name)
                target_client = self.get_client(client_id)
                if target_client is not None:
                    target_client.add_event(msg_id, msg, immediate)
                    output("client_specific", "Adding event to client")

                    return
        output(
            "client_specific",
            "No suitable client found, so I'm just going to send it to everybody"
        )
        self.events.append((msg_id, msg))
        if immediate:
            self.process_events()
Example #3
0
def rem(_connection=None):
    #Forcefully remove the multiplayer client. Only supports one multiplayer client at the moment.
    output = sims4.commands.CheatOutput(_connection)
    output("Attempting to remove client")
    distributor.system._distributor_instance.remove_client_from_id(1000)
    client_manager = services.client_manager()
    client = client_manager.get(1000)
    client_manager.remove(client)

    output("Removed client")
Example #4
0
def distribute_dialog(self, dialog_type, dialog_msg, immediate=False):
    distributor = Distributor.instance()
    # distributor.add_event(dialog_type, dialog_msg, immediate=immediate)
    distributor_to_send_to = distributor.get_distributor_with_active_sim_matching_sim_id(
        dialog_msg.owner_id)
    distributor.add_event_for_client(distributor_to_send_to, dialog_type,
                                     dialog_msg, immediate)
    try:
        output("events", "{}".format(dialog_msg.owner_id))
    except Exception as e:
        pass
    def send_loop(self):
        while True:
            if self.clientsocket is not None:
                output("locks", "acquiring outgoing lock")

                with outgoing_lock:
                    for data in outgoing_commands:
                        generic_send_loop(data, self.clientsocket)
                        outgoing_commands.remove(data)

                output("locks", "releasing outgoing lock")
Example #6
0
def add_client_sims(_connection=None):
    output = sims4.commands.CheatOutput(_connection)
    client = services.client_manager().get(1000)
    first_client = services.client_manager().get_first_client()
    #Add the first client's selectable sims to the new client's. Only expecst one multiplayer client at the moment.
    for sim in client._selectable_sims:
        output(str(sim))

    output(str(len(client._selectable_sims)))

    for sim_info in first_client._selectable_sims:
        client._selectable_sims.add_selectable_sim_info(sim_info)
    client.set_next_sim()
Example #7
0
def cnc(_connection=None):
    #Create a new client. Deprecated.
    output = sims4.commands.CheatOutput(_connection)
    client = services.client_manager().get_first_client()
    account = server.account.Account(865431, "Jon Snow")
    new_client = services.client_manager().create_client(
        1000, account, client._household_id)
    # new_client.clear_selectable_sims()
    # for sim_info in client._selectable_sims:
    # new_client._selectable_sims.add_selectable_sim_info(sim_info)
    # new_client.set_next_sim()

    output("Adding client")
    def send_loop(self):
        self.serversocket.connect((self.host, self.port))
        self.connected = True

        while True:
            output("locks", "acquiring outgoing lock")

            with outgoing_lock:
                for data in outgoing_commands:
                    generic_send_loop(data, self.serversocket)
                    outgoing_commands.remove(data)

            output("locks", "releasing outgoing lock")
Example #9
0
        def enter_dialog_callback(dialog):
            if not dialog.accepted:
                return
            dialog_text = dialog.text_input_responses.get("dialog")
            output("chat", 'Showing message')

            distributor = Distributor.instance(
            ).get_distributor_with_active_sim_matching_sim_id(target_id)
            if distributor is not None:
                client = distributor.client
                output("chat", 'Showing message')

                show_notif(client.active_sim, dialog_text)
Example #10
0
def send_lot_architecture_and_reload(_connection=None):
    # output = sims4.commands.CheatOutput(_connection)
    # output("working")
    zone = services.current_zone()
    name = str(hex(zone.id)).replace("0x", "")
    output("zone_id", "{}, {}".format(name, zone.id))
    file_path = None
    # output(str(name))
    file_path, file_name = get_file_matching_name(name)

    if file_path is not None:
        with outgoing_lock:
            output("zone_id", "{}, {}".format(file_path, file_name))
            msg = File(name, open(file_path, "rb").read())
            outgoing_commands.append(msg)
Example #11
0
def parse_arg(arg):
    #Horrible, hacky way of parsing arguments from the client commands.
    new_arg = arg
    orig_arg = new_arg.replace('"', "").replace("(", "").replace(")", "").replace("'", "").strip()
    new_arg = orig_arg
    try:
        new_arg = float(orig_arg)

        try: 
            new_arg = int(orig_arg)
        except BaseException:
            pass 
    except BaseException:
        pass 
    output("arg_handler", str(new_arg) + "\n")

    return new_arg
Example #12
0
def mp_chat(target_id=None, _connection=None):
    try:
        target_id = int(target_id)

        output("chat", target_id)
        distributor = Distributor.instance(
        ).get_distributor_with_active_sim_matching_sim_id(target_id)

        client = distributor.client
        output("chat", client)

        def enter_dialog_callback(dialog):
            if not dialog.accepted:
                return
            dialog_text = dialog.text_input_responses.get("dialog")
            output("chat", 'Showing message')

            distributor = Distributor.instance(
            ).get_distributor_with_active_sim_matching_sim_id(target_id)
            if distributor is not None:
                client = distributor.client
                output("chat", 'Showing message')

                show_notif(client.active_sim, dialog_text)

        localized_title = lambda **_: LocalizationHelperTuning.get_raw_text(
            "Say Something")
        localized_text = lambda **_: LocalizationHelperTuning.get_raw_text(
            "Say something to anybody who's listening.")
        localized_fname = lambda **_: LocalizationHelperTuning.get_raw_text(
            "Type your message here!")
        localized_lname = lambda **_: LocalizationHelperTuning.get_raw_text(
            "Type your emote here!")

        text_input_1 = UiTextInput(sort_order=0)
        text_input_1.default_text = localized_fname
        text_input_1.title = None
        text_input_1.max_length = 100
        text_input_1.initial_value = localized_fname
        text_input_1.length_restriction = Scum_TextInputLengthName()

        inputs = AttributeDict({'dialog': text_input_1})
        dialog = UiDialogTextInputOkCancel.TunableFactory().default(
            client.active_sim,
            text=localized_text,
            title=localized_title,
            text_inputs=inputs,
            is_special_dialog=True)
        output("chat", "Dialog id: {}".format(dialog.dialog_id))
        dialog.add_listener(enter_dialog_callback)
        dialog.show_dialog()
    except Exception as e:
        output('chat', e)
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")
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
Example #15
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")
Example #16
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")
Example #17
0
def load_zone(_connection=None):
    try:
        zone = services.current_zone()
        name = str(hex(zone.id)).replace("0x", "")
        zone_objects_pb = serialization.ZoneObjectData()
        zone_objects_message = open(get_file_matching_name(name)[0],
                                    "rb").read()
        output("msg", dir(zone_objects_pb))
        zone_objects_pb.ParseFromString(zone_objects_message)
        output("msg", zone_objects_pb)
        output("msg", zone_objects_message)
        persistence_module.run_persistence_operation(
            persistence_module.PersistenceOpType.kPersistenceOpLoadZoneObjects,
            zone_objects_pb, 0, None)
    except Exception as e:
        output("er", e)
Example #18
0
def generic_listen_loop(socket, recieved_commands, data, size):
    # output("receive", "{}, {} \n".format(size, sys.getsizeof(data)))
    if size == None:
        size = socket.recv(8)
        (size,) = unpack('>Q', size)

        size = int(size)
    
    elif size > sys.getsizeof(data):
        bytes_to_recieve = size - sys.getsizeof(data)
        new_data = socket.recv(bytes_to_recieve)
        data += new_data
        
    elif size == sys.getsizeof(data):
        data = pickle.loads(data)
        output("locks", "acquiring incoming lock")
        with incoming_lock:
            recieved_commands.append(data)
        output("locks", "releasing incoming lock")

        size = None
        data = b''
        
    return recieved_commands, data, size
Example #19
0
def get_con(_connection=None):
    #Gets the current client connection
    output = sims4.commands.CheatOutput(_connection)
    output(str(_connection))
Example #20
0
def get_name(_connection=None):
    output = sims4.commands.CheatOutput(_connection)
    output(str(socket.gethostname()))
Example #21
0
def change_persona(_connection=None):
    output = sims4.commands.CheatOutput(_connection)
    # output("working")
    client = services.client_manager().get_first_client()
    client._account._persona_name = "Corrin"
    output(client._account._persona_name)
Example #22
0
def csn_show_usage(output):
    output("usage: rename [OldFirst OldLast]")
Example #23
0
def get_modules(_connection=None):
    for thing in sys.modules.keys():
        output("modules", thing)
Example #24
0
def get_zone_id(_connection=None):
    output = sims4.commands.CheatOutput(_connection)

    client = services.client_manager().get_first_client()
    zone = services.current_zone()
    output(str(zone.id))
Example #25
0
def stuff(_connection=None):
    output("msg", dir(_buildbuy))
Example #26
0
import sims4
import socket
from config import user_directory
try:
    is_client = False
    try:
        open("{}client".format(user_directory), "rb")
        is_client = True

    except Exception:
        pass

    import multiplayer_server
    import multiplayer_client
    if is_client:
        client_instance = multiplayer_client.Client()
        client_instance.listen()
        client_instance.send()
    else:
        server_instance = multiplayer_server.Server()
        server_instance.listen()
        server_instance.send()

    @sims4.commands.Command('shutdown',
                            command_type=sims4.commands.CommandType.Live)
    def shutdown_server(_connection=None):
        server_instance.shutdown(socket.SHUT_RDWR)
        server_instance.close()
except Exception as e:
    output("errors", str(e))
Example #27
0
def get_clients(_connection=None):
    output = sims4.commands.CheatOutput(_connection)
    clients = services.client_manager()._objects.values()
    #Gets all the current client connections
    for client in clients:
        output(str(client.id))