TamaTown/DreamTown/cgi-bin/dreamtown_config.py

209 lines
3.0 KiB
Python
Raw Normal View History

2019-12-25 23:24:56 +00:00
# Add <server_path>/friends/cgi-bin to $PYTHONPATH in /etc/enviroment and as a SetVar for your VirtualHost in apache2
2022-07-31 03:21:37 +00:00
import mariadb
2019-12-25 23:24:56 +00:00
import binascii
import hashlib
2019-09-15 19:08:58 +00:00
2022-11-09 15:44:49 +00:00
2019-09-15 19:08:58 +00:00
#MAKE SURE THE DB IS *OUTSIDE* THE PUBLIC_HTML!!!
2022-07-31 03:21:37 +00:00
#SQLLITE_DB_PATH = "/home/web/DreamTown.db"
2019-09-15 19:08:58 +00:00
SUCCESS = 1
USER_DOES_NOT_EXIST = 2
INVALID_PASSWORD = 3
NAME_ALREADY_USED = 4
ANSWER_INCORRECT = 5
2022-07-31 03:21:37 +00:00
def DbConnect():
return mariadb.connect(
user="root",
2022-07-31 03:25:00 +00:00
password="DB_CREDENTIALS",
2022-07-31 03:21:37 +00:00
host="127.0.0.1",
port=3306,
database="dreamtown"
)
db = DbConnect()
2019-12-25 23:24:56 +00:00
2022-11-09 15:44:49 +00:00
def raise e:
print("".join(traceback.TracebackException.from_exception(e).format())
2019-12-25 23:24:56 +00:00
def xor(data, key):
l = len(key)
return bytearray((
(data[i] ^ key[i % l]) for i in range(0,len(data))
))
def pass_salt_algo(passwd, Salt):
m = hashlib.sha512()
m.update(passwd.encode('utf-8'))
passHash = m.digest()
salt = bytearray(binascii.unhexlify(Salt))
saltedHash = xor(passHash,salt);
m = hashlib.sha512()
m.update(saltedHash)
outHash = m.digest();
return binascii.hexlify(outHash).decode("utf-8")
2019-09-15 19:08:58 +00:00
c = db.cursor()
2022-07-31 02:23:33 +00:00
2019-09-15 19:08:58 +00:00
try:
c.execute("""
CREATE TABLE users(
Name TEXT(12),
PassHash TEXT(128),
Salt TEXT(128),
LastSession TEXT(128),
2022-11-09 15:44:49 +00:00
CreationDate bigint
2019-09-15 19:08:58 +00:00
);
""")
except:
pass
try:
c.execute("""
CREATE TABLE securityQuestion(
Name TEXT(12),
QuestionType int,
AnswerHash TEXT(128)
);
""")
except:
pass
try:
c.execute("""
CREATE TABLE characterList(
Name TEXT(12),
CharacterId int,
ActualCharacterId int
);
""")
except:
pass
try:
c.execute("""
CREATE TABLE relationsList(
Name TEXT(12),
CharacterId int,
Level int,
Progress int
);
""")
except:
pass
try:
c.execute("""
CREATE TABLE npcList(
Name TEXT(12),
CharacterId int,
2022-11-09 15:53:09 +00:00
NextTimestamp bigint,
2019-09-15 19:08:58 +00:00
Pool TEXT(8024),
RequestLevel int
);
""")
except:
pass
try:
c.execute("""
CREATE TABLE areaList(
Name TEXT(12),
2022-11-09 17:10:48 +00:00
LastVisit bigint,
2019-09-15 19:08:58 +00:00
AreaId int,
2022-11-09 15:53:09 +00:00
NextRubishSpawnTime bigint,
2019-09-15 19:08:58 +00:00
ActualAreaId int
);
""")
except:
pass
try:
c.execute("""
CREATE TABLE itemList(
Name TEXT(12),
ItemId int,
Quantity int
);
""")
except:
pass
try:
c.execute("""
CREATE TABLE currencyList(
Name TEXT(12),
CurrencyId int,
Quantity int
);
""")
except:
pass
try:
c.execute("""
2019-09-16 23:21:07 +00:00
CREATE TABLE containerList(
2019-09-15 19:08:58 +00:00
Name TEXT(12),
HarvestableTemplateId int,
2022-11-09 15:44:49 +00:00
LastHarvest bigint,
2019-09-15 19:08:58 +00:00
ContainerName TEXT(128),
AreaId int
);
""")
except:
pass
2019-09-16 23:21:07 +00:00
try:
c.execute("""
CREATE TABLE harvestablesList(
Name TEXT(12),
ItemTemplateId int,
2022-11-09 15:53:09 +00:00
UpdateTime bigint,
2019-09-16 23:21:07 +00:00
SlotIndex int,
HarvestableName TEXT(128),
AreaId int,
ParentContainerName TEXT(128)
);
""")
except:
pass
2019-09-15 19:08:58 +00:00
try:
c.execute("""
CREATE TABLE rubishList(
Name TEXT(12),
Id Text(64),
X int,
Y int,
AreaId int,
ItemTemplateId int
);
""")
except:
pass
try:
c.execute("""
CREATE TABLE tutorial(
Name TEXT(12),
TutorialTemplateId int
);
""")
except:
pass
try:
c.execute("""
CREATE TABLE scenario(
Name TEXT(12),
ScenarioId int,
CustomData TEXT(128),
StepId int,
Completed int
);
""")
except:
pass
db.commit()
db.close()
2022-07-31 03:25:00 +00:00