Skip to content
This repository has been archived by the owner on Jun 10, 2023. It is now read-only.

Commit

Permalink
map packs
Browse files Browse the repository at this point in the history
  • Loading branch information
RealistikDash committed Oct 3, 2020
1 parent 786a119 commit 99e5f16
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 9 deletions.
5 changes: 5 additions & 0 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class Colours():
white = u"\u001b[37m"
all_col = [red, green, yellow, blue, magenta, cyan, white]

class CryptKeys():
solo = "xI25fpAapCQg"
solo3 = "oC36fpYaPtdg"
solo4 = "pC26fpYaQCtg"

ASCII_ART = r"""
{col1} _____ {col2} _____ {col3} _____ {col4} _____ {col5} _____ {reset}
{col1} /\ \ {col2} /\ \ {col3} /\ \ {col4} |\ \ {col5} /\ \ {reset}
Expand Down
36 changes: 33 additions & 3 deletions handlers/levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import aiohttp
from helpers.levelhelper import level_helper
from helpers.searchhelper import search_helper
from helpers.generalhelper import create_offsets_from_page, string_bool, joint_string, list_comma_string
from helpers.generalhelper import create_offsets_from_page, string_bool, joint_string, list_comma_string, paginate_list
from helpers.songhelper import songs
from helpers.userhelper import user_helper
from helpers.crypthelper import cipher_xor
from helpers.crypthelper import cipher_xor, hash_sha1
from helpers.auth import auth
from helpers.timehelper import time_since_midnight, get_timestamp
from objects.levels import SearchQuery, Level
from constants import XorKeys, ResponseCodes
from cron.cachempgauntlets import map_packs
from constants import XorKeys, ResponseCodes, CryptKeys
from config import user_config

async def level_search_modular_hanlder(request : aiohttp.web.Request) -> aiohttp.web.Response:
Expand Down Expand Up @@ -226,3 +227,32 @@ async def get_daily_handler(request : aiohttp.web.Request):
response = f"{level_id}|{change_time}"
logging.debug(response)
return aiohttp.web.Response(text=response)

async def get_map_packs_handler(request : aiohttp.web.Request):
"""Handles getting in-game map packs."""
post_data = await request.post()

page = int(post_data["page"])
offset = create_offsets_from_page(post_data["page"]) # Used for server resposne

packs = paginate_list(map_packs, page)
response = ""
hashed = ""
for pack in packs:
response += joint_string({
1 : pack.ID,
2 : pack.name,
3 : list_comma_string(pack.levels),
4 : pack.stars,
5 : pack.coins,
6 : pack.difficulty,
7 : str(pack.colour),
8 : str(pack.colour)
}) + "|"
id_str = str(pack.ID) # So we don't have to convert every time in the formatted str
hashed += f"{id_str[0]}{id_str[len(id_str)-1]}{pack.stars}{pack.coins}"

hashed = hash_sha1(hashed+CryptKeys.solo)
response = f"{response[:-1]}#{len(map_packs)}:{offset}:10#{hashed}"
logging.debug(response)
return aiohttp.web.Response(text=response)
4 changes: 2 additions & 2 deletions helpers/crypthelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import string
import random
from itertools import cycle
from constants import XorKeys
from constants import XorKeys, CryptKeys
import logging

def hash_sha1(text: str) -> str:
Expand Down Expand Up @@ -58,4 +58,4 @@ def decode_chk(text : str) -> str:

def solo_gen3(string: str):
"""Port of genSolo3 from Cvolton's GMDPrivateServer."""
return hash_sha1(string + "oC36fpYaPtdg")
return hash_sha1(string + CryptKeys.solo3)
5 changes: 5 additions & 0 deletions helpers/generalhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ def deprecated(func):
"""Decorator for deprecation warning"""
raise DeprecationWarning("Function is deprecated!")

def paginate_list(list_to_paginate : list, page : int, elems_page : int = 10):
"""Gets a page from list."""
offset = create_offsets_from_page(page, elems_page)
return list_to_paginate[offset:offset+elems_page]

class UpdateQueryBuilder():
"""Makes it simple to work with long update queries."""
def __init__(self, target_db : str):
Expand Down
7 changes: 4 additions & 3 deletions helpers/levelhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from conn.mysql import myconn
from objects.levels import Level, Rating, DailyLevel
from config import user_config
from constants import CryptKeys
from aiofile import AIOFile
import os
import logging
Expand Down Expand Up @@ -99,7 +100,7 @@ async def multi_gen(self, levels : list) -> str:

Hash += f"{str(level.ID)[0]}{str(level.ID)[len(str(level.ID))-1]}{level.stars}{int(level.verified_coins)}"

return hash_sha1(Hash + "xI25fpAapCQg")
return hash_sha1(Hash + CryptKeys.solo)


def solo_gen(self, level_str: str):
Expand All @@ -108,10 +109,10 @@ def solo_gen(self, level_str: str):
str_len = len(level_str) // 40
for i in range(40):
return_str += level_str[i * str_len]
return hash_sha1(return_str + "xI25fpAapCQg")
return hash_sha1(return_str + CryptKeys.solo)

def solo_gen2(self, level_string : str) -> str:
return hash_sha1(level_string + "xI25fpAapCQg")
return hash_sha1(level_string + CryptKeys.solo)

async def bump_download(self, level_id : int):
"""Bumps a level's download count by one."""
Expand Down
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from handlers.register import register_handler
from handlers.profiles import profile_comment_handler, profile_handler, user_search_handler, post_account_comment_handler, update_profile_stats_handler, get_account_url_handler, save_user_data_handler, load_save_data_handler, update_acc_settings_handler, leaderboards_handler, mod_check_handler
from handlers.songs import featured_artists_handler, get_songinfo_handler
from handlers.levels import level_search_modular_hanlder, download_level, upload_level_handler, get_daily_handler
from handlers.levels import level_search_modular_hanlder, download_level, upload_level_handler, get_daily_handler, get_map_packs_handler
from handlers.rewards import quests_handler
from handlers.levelextras import level_comments_handler, post_comment_handler, rate_level_handler
from helpers.userhelper import user_helper
Expand Down Expand Up @@ -51,6 +51,7 @@ def config_routes(app: web.Application) -> None:
app.router.add_post("/database/suggestGJStars20.php", rate_level_handler)
app.router.add_post("/database/requestUserAccess.php", mod_check_handler)
app.router.add_post("/database/getGJDailyLevel.php", get_daily_handler)
app.router.add_post("/database/getGJMapPacks21.php", get_map_packs_handler)
#app.add_subapp("/api/", api)
app.add_subapp("/tools/", tools)

Expand Down

0 comments on commit 99e5f16

Please sign in to comment.