diff --git a/app/classes/minecraft/serverjars.py b/app/classes/minecraft/serverjars.py index dc76bffa..1006ab2c 100644 --- a/app/classes/minecraft/serverjars.py +++ b/app/classes/minecraft/serverjars.py @@ -71,6 +71,29 @@ class ServerJars: data = self._read_cache() return data.get('servers') + def get_serverjar_data_sorted(self): + data = self.get_serverjar_data() + + def str_to_int(x, counter=0): + try: + return ord(x[0]) + str_to_int(x[1:], counter + 1) + len(x) + except IndexError: + return 0 + + def to_int(x): + try: + return int(x) + except ValueError: + temp = x.split('-') + return to_int(temp[0]) + str_to_int(temp[1]) / 100000 + + sort_key_fn = lambda x: [to_int(y) for y in x.split('.')] + + for key in data.keys(): + data[key] = sorted(data[key], key=sort_key_fn) + + return data + def _check_api_alive(self): logger.info("Checking serverjars.com API status") diff --git a/app/classes/web/server_handler.py b/app/classes/web/server_handler.py index 788748ad..7768280d 100644 --- a/app/classes/web/server_handler.py +++ b/app/classes/web/server_handler.py @@ -63,7 +63,7 @@ class ServerHandler(BaseHandler): if page == "step1": - page_data['server_types'] = server_jar_obj.get_serverjar_data() + page_data['server_types'] = server_jar_obj.get_serverjar_data_sorted() template = "server/wizard.html" self.render(