2023-08-18 16:40:45 +00:00
|
|
|
#
|
|
|
|
# Copyright © 2023 adithyagenie
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
#
|
|
|
|
|
2022-11-17 14:02:25 +00:00
|
|
|
import os
|
|
|
|
import pickle
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
2022-11-26 18:09:00 +00:00
|
|
|
import maze.modules.PlayerBase_func as player
|
2022-11-30 12:57:18 +00:00
|
|
|
from maze.modules import bruh
|
2022-11-17 14:02:25 +00:00
|
|
|
|
2022-11-22 10:35:23 +00:00
|
|
|
user = password = None
|
|
|
|
|
2022-11-30 15:57:28 +00:00
|
|
|
"""Gets mysql pass and username"""
|
2023-08-18 16:40:45 +00:00
|
|
|
if os.path.exists("credentials.pickle"):
|
|
|
|
with open("credentials.pickle", "rb") as f:
|
|
|
|
try:
|
|
|
|
while True:
|
|
|
|
d = pickle.load(f)
|
|
|
|
if d["credtype"] == "mysql":
|
|
|
|
user = d["user"]
|
|
|
|
password = d["pass"]
|
|
|
|
break
|
|
|
|
except:
|
|
|
|
user = password = None
|
|
|
|
else:
|
|
|
|
print("credentials.pickle file missing. Refer to README to set it up.")
|
|
|
|
sys.exit()
|
2022-11-17 14:02:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
def getcreds():
|
2022-11-30 15:57:28 +00:00
|
|
|
"""Checks mysql creds"""
|
2022-11-22 10:35:23 +00:00
|
|
|
if user:
|
2022-11-17 14:02:25 +00:00
|
|
|
return user, password
|
|
|
|
else:
|
|
|
|
print(
|
|
|
|
"""MySQL username or password not initialised. Defaulting to 'root' and ''.
|
|
|
|
Run 'python starter.py initsql' to initialise credentials of your choice. """
|
|
|
|
)
|
|
|
|
with open("credentials.pickle", "rb+") as f:
|
|
|
|
try:
|
|
|
|
while True:
|
|
|
|
pos = f.tell()
|
|
|
|
d = pickle.load(f)
|
|
|
|
if d["credtype"] == "mysql":
|
|
|
|
d["user"] = "root"
|
|
|
|
d["pass"] = ""
|
|
|
|
f.seek(pos)
|
|
|
|
pickle.dump(d, f)
|
2022-11-23 18:03:16 +00:00
|
|
|
except:
|
2022-11-17 14:02:25 +00:00
|
|
|
pass
|
|
|
|
return None, None
|
|
|
|
|
2022-11-02 20:02:13 +00:00
|
|
|
|
2022-11-17 14:02:25 +00:00
|
|
|
if len(sys.argv) == 1:
|
2022-11-30 15:57:28 +00:00
|
|
|
"""Called with no arguments"""
|
2022-11-17 14:02:25 +00:00
|
|
|
getcreds()
|
2022-11-27 17:59:24 +00:00
|
|
|
try:
|
|
|
|
bruh()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
2022-11-27 20:02:47 +00:00
|
|
|
player.sql.close()
|
|
|
|
sys.exit()
|
2022-11-17 14:02:25 +00:00
|
|
|
else:
|
|
|
|
if sys.argv[1] == "dumpsample":
|
2022-11-30 15:57:28 +00:00
|
|
|
"""dumps sample database"""
|
2022-11-17 14:02:25 +00:00
|
|
|
getcreds()
|
2022-11-26 18:09:00 +00:00
|
|
|
player.databaseinit()
|
2022-11-17 14:02:25 +00:00
|
|
|
subprocess.call(
|
2022-11-22 10:35:23 +00:00
|
|
|
f"mysql -u {user} --password={password} -D labyrinth < {os.path.abspath('dbdump.sql')}",
|
2022-11-23 18:03:16 +00:00
|
|
|
shell=True # ,
|
|
|
|
# stdout=subprocess.DEVNULL,
|
|
|
|
# stderr=subprocess.DEVNULL,
|
2022-11-17 14:02:25 +00:00
|
|
|
)
|
2022-11-22 10:35:23 +00:00
|
|
|
print("Successfully dumped sample data")
|
2022-11-26 18:09:00 +00:00
|
|
|
|
2022-11-17 14:02:25 +00:00
|
|
|
elif sys.argv[1] == "initsql":
|
2022-11-30 15:57:28 +00:00
|
|
|
"""Stores mysql creds"""
|
2022-11-17 14:02:25 +00:00
|
|
|
user = input("Enter MySQL username: ")
|
|
|
|
password = input("Enter MySQL password: ")
|
|
|
|
with open("credentials.pickle", "rb+") as f:
|
|
|
|
try:
|
|
|
|
while True:
|
|
|
|
pos = f.tell()
|
|
|
|
d = pickle.load(f)
|
|
|
|
if d["credtype"] == "mysql":
|
|
|
|
d["user"] = user
|
|
|
|
d["pass"] = password
|
|
|
|
f.seek(pos)
|
|
|
|
pickle.dump(d, f)
|
2022-11-23 18:03:16 +00:00
|
|
|
except:
|
2022-11-17 14:02:25 +00:00
|
|
|
pass
|
|
|
|
print("Successfully set.")
|
2023-08-18 16:40:45 +00:00
|
|
|
elif sys.argv[1] == "setup":
|
|
|
|
"""Set up credentials.pickle"""
|
|
|
|
with open("credentials.pickle", "wb") as f:
|
|
|
|
print("SETTING UP EMAIL CLIENT\n")
|
|
|
|
email = input(
|
|
|
|
"Enter your gmail mail-id which sends the emails (abcd@gmail.com): "
|
|
|
|
)
|
|
|
|
apppass = input(
|
|
|
|
"Create an app-specific password for that mail and input it here: "
|
|
|
|
)
|
|
|
|
pickle.dump({"credtype": "email", "email": email, "pass": apppass}, f)
|
|
|
|
print("Email credentials set successfully!\n")
|
|
|
|
|
|
|
|
print("SETTING UP MYSQL CREDENTIALS\n")
|
|
|
|
user = input("Enter MySQL username: ")
|
|
|
|
password = input("Enter MySQL password: ")
|
|
|
|
pickle.dump({"credtype": "mysql", "user": user, "pass": password}, f)
|
|
|
|
print("MySQL credentials set successfully!\n")
|
|
|
|
|
|
|
|
print(
|
|
|
|
"SETTING UP OXFORD API\nGenerate your Oxford API key from https://developer.oxforddictionaries.com/ \n"
|
|
|
|
)
|
|
|
|
appid = input("Enter the app_id: ")
|
|
|
|
appkey = input("Enter the app_key: ")
|
|
|
|
pickle.dump(
|
|
|
|
{
|
|
|
|
"credtype": "oxfordapi",
|
|
|
|
"app_id": appid,
|
|
|
|
"app_key": appkey,
|
|
|
|
},
|
|
|
|
f,
|
|
|
|
)
|
|
|
|
print("Oxford API key successfully set!\n")
|
|
|
|
print("Set up has completed! You can now play the game!")
|
|
|
|
sys.exit()
|