Пример #1
0
    def func(self, args, request):
        if not args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        if 'typeclass' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "typeclass".')

        typeclass = args["typeclass"]
        width = args.get("width", 0)
        height = args.get("height", 0)

        forms = data_edit.query_object_form(typeclass, typeclass, None)
        new_area = []
        for form in forms:
            values = {
                field["name"]: field["value"]
                for field in form["fields"] if "value" in field
            }
            values["width"] = width
            values["height"] = height

            new_area.append({"table": form["table"], "values": values})

        obj_key = data_edit.save_object_form(new_area, typeclass, "")
        data = {"key": obj_key, "width": width, "height": height}
        return success_response(data)
Пример #2
0
class upload_resources(BaseRequestProcesser):
    """
    Upload a zip package of resources.

    Args:
        args: None
    """
    path = "upload_resources"
    name = ""

    def func(self, args, request):
        file_obj = request.FILES.get("file", None)

        if not file_obj:
            raise MudderyError(ERR.missing_args, 'Missing zip files.')

        with tempfile.TemporaryFile() as fp:
            try:
                for chunk in file_obj.chunks():
                    fp.write(chunk)
                importer.unzip_resources_all(fp)
            except Exception, e:
                logger.log_tracemsg("Upload error: %s" % e.message)
                raise MudderyError(ERR.upload_error, e.message)

        return success_response("success")
Пример #3
0
    def func(self, args, request):
        if not args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        if 'tables' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "tables".')

        if 'base_typeclass' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "base_typeclass".')

        if 'obj_typeclass' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "obj_typeclass".')

        if 'obj_key' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "obj_key".')

        tables = args["tables"]
        base_typeclass = args["base_typeclass"]
        obj_typeclass = args["obj_typeclass"]
        obj_key = args["obj_key"]

        new_key = data_edit.save_object_form(tables, obj_typeclass, obj_key)
        if obj_key != new_key:
            data_edit.update_object_key(obj_typeclass, obj_key, new_key)

        return success_response(new_key)
Пример #4
0
    def func(self, args, request):
        if not args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        if 'tables' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "tables".')

        if 'base_typeclass' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "base_typeclass".')

        if 'obj_typeclass' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "obj_typeclass".')

        if 'obj_key' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "obj_key".')

        tables = args["tables"]
        base_typeclass = args["base_typeclass"]
        obj_typeclass = args["obj_typeclass"]
        obj_key = args["obj_key"]

        new_key = data_edit.save_object_form(tables, obj_typeclass, obj_key)
        if obj_key != new_key:
            data_edit.update_object_key(obj_typeclass, obj_key, new_key)

        return success_response(new_key)
Пример #5
0
    def func(self, args, request):
        if not args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        if 'typeclass' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "typeclass".')

        typeclass = args["typeclass"]
        width = args.get("width", 0)
        height = args.get("height", 0)

        forms = data_edit.query_object_form(typeclass, typeclass, None)
        new_area = []
        for form in forms:
            values = {field["name"]: field["value"] for field in form["fields"] if "value" in field}
            values["width"] = width
            values["height"] = height

            new_area.append({
                "table": form["table"],
                "values": values
            })

        obj_key = data_edit.save_object_form(new_area, typeclass, "")
        data = {"key": obj_key,
                "width": width,
                "height": height}
        return success_response(data)
Пример #6
0
    def func(self, args, request):
        if not args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        if 'action' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "action".')

        if 'event' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "event".')

        if 'values' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "values".')

        action_type = args["action"]
        event_key = args["event"]
        values = args["values"]

        # Get action's data.
        action = EVENT_ACTION_SET.get(action_type)
        if not action:
            raise MudderyError(ERR.no_table, "Can not find action: %s" % action_type)

        table_name = action.model_name

        # Remove old records.
        data_edit.delete_records(table_name, event_key=event_key)

        # Add new data.
        for value in values:
            data_edit.save_form(value, table_name)

        return success_response("success")
Пример #7
0
    def func(self, args, request):
        if not args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        if 'typeclass' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "typeclass".')

        if 'location' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "location".')

        if 'destination' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "destination".')

        typeclass = args["typeclass"]
        location = args["location"]
        destination = args["destination"]

        forms = data_edit.query_object_form(typeclass, typeclass, None)
        new_exit = []
        for form in forms:
            values = {field["name"]: field["value"] for field in form["fields"] if "value" in field}
            values["location"] = location
            values["destination"] = destination

            new_exit.append({
                "table": form["table"],
                "values": values
            })

        obj_key = data_edit.save_object_form(new_exit, typeclass, "")
        data = {"key": obj_key}
        return success_response(data)
Пример #8
0
    def func(self, args, request):
        if not args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        if 'typeclass' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "typeclass".')

        if 'location' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "location".')

        if 'destination' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "destination".')

        typeclass = args["typeclass"]
        location = args["location"]
        destination = args["destination"]

        forms = data_edit.query_object_form(typeclass, typeclass, None)
        new_exit = []
        for form in forms:
            values = {
                field["name"]: field["value"]
                for field in form["fields"] if "value" in field
            }
            values["location"] = location
            values["destination"] = destination

            new_exit.append({"table": form["table"], "values": values})

        obj_key = data_edit.save_object_form(new_exit, typeclass, "")
        data = {"key": obj_key}
        return success_response(data)
Пример #9
0
class ApplyChanges(BaseRequestProcesser):
    """
    Query all tables' names.

    Args:
        None.
    """
    path = "apply_changes"
    name = ""

    def func(self, args, request):
        try:
            # reload system data
            # import_syetem_data()

            # reload localized strings
            # LOCALIZED_STRINGS_HANDLER.reload()

            # rebuild the world
            build_all()

            # send client settings
            client_settings = GAME_SETTINGS.get_client_settings()
            text = json.dumps({"settings": client_settings})
            SESSIONS.announce_all(text)

            # restart the server
            SESSIONS.announce_all("Server restarting ...")
            SESSIONS.portal_restart_server()
        except Exception, e:
            message = "Can not build the world: %s" % e
            logger.log_tracemsg(message)
            raise MudderyError(ERR.build_world_error, message)

        return success_response("success")
Пример #10
0
class QueryFormFirstRecord(BaseRequestProcesser):
    """
    Query a form of the first record of a table.

    Args:
        table: (string) table's name
    """
    path = "query_form_first_record"
    name = ""

    def func(self, args, request):
        if 'table' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "table".')

        table_name = args["table"]

        try:
            record = general_query_mapper.get_the_first_record(table_name)
            if record:
                record_id = record.id
            else:
                record_id = None
        except Exception, e:
            raise MudderyError(ERR.invalid_form,
                               "Wrong table: %s." % table_name)

        data = data_edit.query_form(table_name, id=record_id)
        return success_response(data)
Пример #11
0
    def func(self, args, request):
        if 'table' not in args:
            raise MudderyError(ERR.missing_args, 'Missing argument: "table".')

        table_name = args["table"]

        data = general_query.query_table(table_name)
        return success_response(data)
Пример #12
0
    def func(self, args, request):
        if 'object' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "object".')

        object_key = args["object"]

        data = data_query.query_object_events(object_key)
        return success_response(data)
Пример #13
0
    def func(self, args, request):
        if 'dialogue' not in args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        dialogue_key = args["dialogue"]

        data = data_query.query_dialogue_sentences(dialogue_key)
        return success_response(data)
Пример #14
0
    def func(self, args, request):
        if ('object' not in args):
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        object_key = args["object"]

        data = data_query.query_object_events(object_key)
        return success_response(data)
Пример #15
0
    def func(self, args, request):
        """
        Get the server's status.

        Args:
            args: None
        """
        return success_response("running")
Пример #16
0
    def func(self, args, request):
        if 'typeclass' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "typeclass".')

        typeclass = args["typeclass"]

        data = data_query.query_event_triggers(typeclass)
        return success_response(data)
Пример #17
0
    def func(self, args, request):
        """
        Get the server's status.

        Args:
            args: None
        """
        return success_response("running")
Пример #18
0
    def func(self, args, request):
        if 'dialogue' not in args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        dialogue_key = args["dialogue"]

        data = data_query.query_dialogue_sentences(dialogue_key)
        return success_response(data)
Пример #19
0
    def func(self, args, request):
        if 'table' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "table".')

        table_name = args["table"]

        data = general_query.query_table(table_name)
        return success_response(data)
Пример #20
0
    def func(self, args, request):
        """
        Logout the editor.

        Args:
            args: None
        """
        auth.logout(request)
        return success_response("success")
Пример #21
0
    def func(self, args, request):
        if 'action' not in args or 'event' not in args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        action_type = args["action"]
        event_key = args["event"]

        data = data_edit.query_event_action_forms(action_type, event_key)
        return success_response(data)
Пример #22
0
    def func(self, args, request):
        if 'typeclass' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "typeclass".')

        typeclass_key = args["typeclass"]

        # Query data.
        data = data_query.query_typeclass_table(typeclass_key)
        return success_response(data)
Пример #23
0
    def func(self, args, request):
        if ('type' not in args or 'key' not in args):
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        action_type = args["type"]
        event_key = args["key"]

        data = data_query.query_event_action_data(action_type, event_key)
        return success_response(data)
Пример #24
0
    def func(self, args, request):
        if 'table' not in args:
            raise MudderyError(ERR.missing_args, 'Missing argument: "table".')

        table_name = args["table"]
        record = args.get('record', None)

        data = data_edit.query_form(table_name, record)
        return success_response(data)
Пример #25
0
    def func(self, args, request):
        if ('table' not in args) or ('record' not in args):
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        table_name = args["table"]
        record_id = args["record"]

        data = general_query.query_record(table_name, record_id)
        return success_response(data)
Пример #26
0
    def func(self, args, request):
        if ('table' not in args) or ('record' not in args):
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        table_name = args["table"]
        record_id = args["record"]

        data = general_query.query_record(table_name, record_id)
        return success_response(data)
Пример #27
0
    def func(self, args, request):
        if 'typeclass' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "typeclass".')

        typeclass = args["typeclass"]

        data = data_query.query_event_triggers(typeclass)
        return success_response(data)
Пример #28
0
    def func(self, args, request):
        if 'table' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "table".')

        table_name = args["table"]
        record = args.get('record', None)

        data = data_edit.query_form(table_name, id=record)
        return success_response(data)
Пример #29
0
    def func(self, args, request):
        if 'action' not in args or 'event' not in args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        action_type = args["action"]
        event_key = args["event"]

        data = data_edit.query_event_action_forms(action_type, event_key)
        return success_response(data)
Пример #30
0
    def func(self, args, request):
        """
        Logout the editor.

        Args:
            args: None
        """
        auth.logout(request)
        return success_response("success")
Пример #31
0
    def func(self, args, request):
        if ('table' not in args) or ('record' not in args):
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        table_name = args["table"]
        record_id = args["record"]

        data_edit.delete_record(table_name, record_id)
        data = {"record": record_id}
        return success_response(data)
Пример #32
0
    def func(self, args, request):
        if 'typeclass' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "typeclass".')

        typeclass_key = args["typeclass"]

        # Query data.
        data = data_query.query_typeclass_table(typeclass_key)
        return success_response(data)
Пример #33
0
    def func(self, args, request):
        if not args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        if 'area' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "area".')

        area_key = args["area"]

        data = data_query.query_map(area_key)
        return success_response(data)
Пример #34
0
    def func(self, args, request):
        if not args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        if 'area' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "area".')

        area_key = args["area"]

        data = data_query.query_map(area_key)
        return success_response(data)
Пример #35
0
    def func(self, args, request):
        if not args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        if 'base_typeclass' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "base_typeclass".')

        base_typeclass = args["base_typeclass"]
        obj_typeclass = args.get('obj_typeclass', None)
        obj_key = args.get('obj_key', None)

        data = data_edit.query_object_form(base_typeclass, obj_typeclass, obj_key)
        return success_response(data)
Пример #36
0
    def func(self, args, request):
        if 'obj_key' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "obj_key".')

        if 'base_typeclass' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "base_typeclass".')

        obj_key = args["obj_key"]
        base_typeclass = args.get("base_typeclass", None)

        data_edit.delete_object(obj_key, base_typeclass)
        data = {"obj_key": obj_key}
        return success_response(data)
Пример #37
0
    def func(self, args, request):
        if 'table' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "table".')

        if 'record' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "record".')

        table_name = args["table"]
        record_id = args["record"]

        data_edit.delete_record(table_name, record_id)
        data = {"record": record_id}
        return success_response(data)
Пример #38
0
    def func(self, args, request):
        if not args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        if "objects" not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "objects".')

        objects = args["objects"]

        for object_key in objects:
            data_edit.delete_object(object_key)

        return success_response("success")
Пример #39
0
    def func(self, args, request):
        if 'typeclass' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "typeclass".')

        if 'obj_key' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "obj_key".')

        typeclass_key = args["typeclass"]
        obj_key = args["obj_key"]

        data = data_query.query_object_properties(typeclass_key, obj_key)
        return success_response(data)
Пример #40
0
    def func(self, args, request):
        if 'obj_key' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "obj_key".')

        if 'level' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "level".')

        obj_key = args["obj_key"]
        level = args["level"]

        data = data_query.query_object_level_properties(obj_key, level)
        return success_response(data)
Пример #41
0
    def func(self, args, request):
        if not args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        if "objects" not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "objects".')

        objects = args["objects"]

        for object_key in objects:
            data_edit.delete_object(object_key)

        return success_response("success")
Пример #42
0
    def func(self, args, request):
        if not args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        if 'area' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "area".')

        if 'rooms' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "rooms".')

        area = args["area"]
        rooms = args["rooms"]

        data = data_edit.save_map_positions(area, rooms)
        return success_response(data)
Пример #43
0
    def func(self, args, request):
        if not args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        if 'base_typeclass' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "base_typeclass".')

        base_typeclass = args["base_typeclass"]
        obj_typeclass = args.get('obj_typeclass', None)
        obj_key = args.get('obj_key', None)

        data = data_edit.query_object_form(base_typeclass, obj_typeclass,
                                           obj_key)
        return success_response(data)
Пример #44
0
    def func(self, args, request):
        if 'obj_key' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "obj_key".')

        if 'base_typeclass' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "base_typeclass".')

        obj_key = args["obj_key"]
        base_typeclass = args.get("base_typeclass", None)

        data_edit.delete_object(obj_key, base_typeclass)
        data = {"obj_key": obj_key}
        return success_response(data)
Пример #45
0
    def func(self, args, request):
        if not args or ('username' not in args) or ('password' not in args):
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        username = args['username']
        password = args['password']

        user = auth.authenticate(username=username, password=password)
        if not user:
            raise MudderyError(ERR.no_authentication, "Authentication fialed.")

        if not user.is_staff:
            raise MudderyError(ERR.no_permission, "No permission.")

        auth.login(request, user)
        return success_response("success")
Пример #46
0
    def func(self, args, request):
        if not args or ('username' not in args) or ('password' not in args):
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        username = args['username']
        password = args['password']

        user = auth.authenticate(username=username, password=password)
        if not user:
            raise MudderyError(ERR.no_authentication, "Authentication fialed.")

        if not user.is_staff:
            raise MudderyError(ERR.no_permission, "No permission.")

        auth.login(request, user)
        return success_response("success")
Пример #47
0
    def func(self, args, request):
        file_obj = request.FILES.get("file", None)

        if not file_obj:
            raise MudderyError(ERR.missing_args, 'Missing zip files.')

        with tempfile.TemporaryFile() as fp:
            try:
                for chunk in file_obj.chunks():
                    fp.write(chunk)
                importer.unzip_resources_all(fp)
            except Exception as e:
                logger.log_tracemsg("Upload error: %s" % e)
                raise MudderyError(ERR.upload_error, str(e))

        return success_response("success")
Пример #48
0
    def func(self, args, request):
        if not args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        if 'values' not in args:
            raise MudderyError(ERR.missing_args, 'Missing argument: "values".')

        if 'table' not in args:
            raise MudderyError(ERR.missing_args, 'Missing argument: "table".')

        values = args["values"]
        table_name = args["table"]
        record_id = args.get('record', None)

        record_id = data_edit.save_form(values, table_name, record_id)
        data = general_query.query_record(table_name, record_id)
        return success_response(data)
Пример #49
0
    def func(self, args, request):
        if not args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        if 'area' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "area".')

        if 'rooms' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "rooms".')

        area = args["area"]
        rooms = args["rooms"]

        data = data_edit.save_map_positions(area, rooms)
        return success_response(data)
Пример #50
0
    def func(self, args, request):
        if not args:
            raise MudderyError(ERR.missing_args, 'Missing arguments.')

        if 'values' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "values".')

        if 'table' not in args:
            raise MudderyError(ERR.missing_args, 'Missing the argument: "table".')

        values = args["values"]
        table_name = args["table"]
        record_id = args.get('record', None)

        record_id = data_edit.save_form(values, table_name, record_id)
        data = data_edit.query_form(table_name, id=record_id)
        return success_response(data)
Пример #51
0
    def func(self, args, request):
        if 'obj_key' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "obj_key".')

        if 'level' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "level".')

        if 'values' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "values".')

        obj_key = args["obj_key"]
        level = args["level"]
        values = args["values"]

        data_edit.save_object_level_properties(obj_key, level, values)
        return success_response("success")
Пример #52
0
    def func(self, args, request):
        if 'table' not in args:
            raise MudderyError(ERR.missing_args,
                               'Missing the argument: "table".')

        table_name = args["table"]

        try:
            record = general_query_mapper.get_the_first_record(table_name)
            if record:
                record_id = record.id
            else:
                record_id = None
        except Exception as e:
            raise MudderyError(ERR.invalid_form,
                               "Wrong table: %s." % table_name)

        data = data_edit.query_form(table_name, id=record_id)
        return success_response(data)
Пример #53
0
 def func(self, args, request):
     writer_list = writers.get_writers()
     data = [{"type": item.type, "name": item.name} for item in writer_list]
     return success_response(data)
Пример #54
0
            try:
                fp = open(filepath, "rb")
                for chunk in file_obj.chunks():
                    data = fp.read(len(chunk))
                    compare = [0 for item in zip(chunk, data) if item[0] != item[1]]
                    same = (len(compare) == 0)
                    if not same:
                        break
            except Exception, e:
                same = False

            if not same:
                raise MudderyError(ERR.upload_image_exist, 'File %s already exists.' % filename)

            exist = True

        icon_location = settings.IMAGE_PATH + "/" + file_type + "/" + filename
        if not exist:
            try:
                image = Image.open(filepath)
                size = image.size

                IMAGE_RESOURCES.add(icon_location, file_type, size[0], size[1])
            except Exception, e:
                if fp:
                    fp.close()
                logger.log_tracemsg("Upload error: %s" % e.message)
                raise MudderyError(ERR.upload_error, e.message)

        return success_response({"resource": icon_location})
Пример #55
0
 def func(self, args, request):
     data = general_query.query_tables()
     return success_response(data)
Пример #56
0
 def func(self, args, request):
     return success_response("success")
Пример #57
0
 def func(self, args, request):
     data = data_query.query_areas()
     return success_response(data)