Skip to content

Commit

Permalink
Merge branch 'master' into s4act3
Browse files Browse the repository at this point in the history
  • Loading branch information
aristotlepenguin committed Oct 26, 2023
2 parents 44803cd + 168923c commit 8a30379
Show file tree
Hide file tree
Showing 25 changed files with 624 additions and 491 deletions.
64 changes: 29 additions & 35 deletions ew/backend/apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class EwApartment:

name = "a city apartment."
description = "It's drafty in here! You briefly consider moving out, but your SlimeCoin is desperate to leave your pocket."
poi = "downtown"
poi = ""
rent = 0
apt_class = "c"
num_keys = 0
Expand All @@ -24,13 +24,8 @@ def __init__(
self.id_user = id_user
self.id_server = id_server

try:
conn_info = bknd_core.databaseConnect()
conn = conn_info.get('conn')
cursor = conn.cursor()

# Retrieve object
cursor.execute("SELECT {}, {}, {}, {}, {}, {}, {}, {} FROM apartment WHERE id_user = %s and id_server = %s".format(
result = bknd_core.execute_sql_query(
sql_query = "SELECT {}, {}, {}, {}, {}, {}, {}, {} FROM apartment WHERE id_user = %s and id_server = %s".format(
ewcfg.col_apt_name,
ewcfg.col_apt_description,
ewcfg.col_poi,
Expand All @@ -39,36 +34,35 @@ def __init__(
ewcfg.col_num_keys,
ewcfg.col_key_1,
ewcfg.col_key_2
),
sql_replacements = (self.id_user, self.id_server),
fetchone = True
)

), (self.id_user,
self.id_server))
result = cursor.fetchone();

if result != None:
# Record found: apply the data to this object.
self.name = result[0]
self.description = result[1]
self.poi = result[2]
self.rent = result[3]
self.apt_class = result[4]
self.num_keys = result[5]
self.key_1 = result[6]
self.key_2 = result[7]
elif id_server != None:
# Create a new database entry if the object is missing.
cursor.execute("REPLACE INTO apartment({}, {}) VALUES(%s, %s)".format(
if result != None:
# Record found: apply the data to this object.
self.name = result[0]
self.description = result[1]
self.poi = result[2]
self.rent = result[3]
self.apt_class = result[4]
self.num_keys = result[5]
self.key_1 = result[6]
self.key_2 = result[7]
elif id_server is not None and id_user is not None:
# Create a new database entry if the object is missing.
bknd_core.execute_sql_query(
sql_query = "REPLACE INTO apartment({}, {}, {}) VALUES(%s, %s, %s)".format(
ewcfg.col_id_user,
ewcfg.col_id_server
), (
ewcfg.col_id_server,
ewcfg.col_poi
),
sql_replacements = (
self.id_user,
self.id_server
))

conn.commit()
finally:
# Clean up the database handles.
cursor.close()
bknd_core.databaseClose(conn_info)
self.id_server,
self.poi
)
)

def persist(self):
bknd_core.execute_sql_query(
Expand Down
8 changes: 7 additions & 1 deletion ew/backend/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def databaseClose(conn_info):
"""


def execute_sql_query(sql_query = None, sql_replacements = None, fetchone = False):
def execute_sql_query(sql_query = None, sql_replacements = None, fetchone = False, lastrowid = False):
data = None
cursor = None
conn_info = None
Expand All @@ -396,9 +396,15 @@ def execute_sql_query(sql_query = None, sql_replacements = None, fetchone = Fals
conn = conn_info.get('conn')
cursor = conn.cursor()
cursor.execute(sql_query, sql_replacements)

if sql_query.lower().startswith("select"):
data = cursor.fetchall() if not fetchone else cursor.fetchone()

if sql_query.lower().startswith("insert") and lastrowid:
data = cursor.lastrowid

conn.commit()

finally:
# Clean up the database handles.
if cursor is not None: cursor.close()
Expand Down
4 changes: 2 additions & 2 deletions ew/backend/goonscapestats.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ async def add_xp(self, value):
'fashion_style': ewcfg.style_skill,
'freshness': 0,
'adorned': 'true',
'soulbound': 'true'
}
},
soulbound=True
)
await create_quest_record(int(time.time()), self.id_user, self.id_server, "skill_cape", self.stat)

Expand Down
66 changes: 26 additions & 40 deletions ew/backend/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,20 +310,17 @@ def item_create(
id_server = None,
stack_max = -1,
stack_size = 0,
item_props = None
item_props = None,
soulbound = None
):

item_def = static_items.item_def_map.get(item_type)
badRelic = 0


if item_def == None:
ewutils.logMsg('Tried to create invalid item_type: {}'.format(item_type))
return




if item_type == ewcfg.it_item:
if "id_name" in item_props.keys():
template_id = item_props.get("id_name", "bad general item id")
Expand All @@ -345,7 +342,6 @@ def item_create(
template_id = "player book"
elif item_type == ewcfg.it_medal:
template_id = "MEDAL ITEM????" #p sure these are fake news

elif item_type == ewcfg.it_questitem:
template_id = "QUEST ITEM????"
else:
Expand All @@ -355,57 +351,47 @@ def item_create(
badRelic = 1

if badRelic == 0:
try:
# Get database handles if they weren't passed.
conn_info = bknd_core.databaseConnect()
conn = conn_info.get('conn')
cursor = conn.cursor()

# Create the item in the database.

cursor.execute("INSERT INTO items({}, {}, {}, {}, {}, {}, {}) VALUES(%s, %s, %s, %s, %s, %s, %s)".format(
# Create the item in the database.
item_id = bknd_core.execute_sql_query(
sql_query = "INSERT INTO items({}, {}, {}, {}, {}, {}, {}) VALUES(%s, %s, %s, %s, %s, %s, %s)".format(
ewcfg.col_item_type,
ewcfg.col_id_user,
ewcfg.col_id_server,
ewcfg.col_soulbound,
ewcfg.col_stack_max,
ewcfg.col_stack_size,
ewcfg.col_template
), (
),
sql_replacements = (
item_type,
id_user,
id_server,
(1 if item_def.soulbound else 0),
(1 if (item_def.soulbound if soulbound is None else soulbound) else 0),
stack_max,
stack_size,
template_id,
))

item_id = cursor.lastrowid
conn.commit()
),
lastrowid = True
)

if item_id > 0:
# If additional properties are specified in the item definition or in this create call, create and persist them.
if item_props != None or item_def.item_props != None:
item_inst = EwItem(id_item = item_id)
if item_id > 0:
# If additional properties are specified in the item definition or in this create call, create and persist them.
if item_props != None or item_def.item_props != None:
item_inst = EwItem(id_item = item_id)

if item_inst.item_type == ewcfg.it_relic:
gamestate = EwGamestate(id_state=template_id, id_server=id_server)
gamestate.number = item_id
gamestate.persist()
if item_def.item_props != None:
item_inst.item_props.update(item_def.item_props)
if item_inst.item_type == ewcfg.it_relic:
gamestate = EwGamestate(id_state=template_id, id_server=id_server)
gamestate.number = item_id
gamestate.persist()
if item_def.item_props != None:
item_inst.item_props.update(item_def.item_props)

if item_props != None:
item_inst.item_props.update(item_props)
item_inst.persist()
if item_props != None:
item_inst.item_props.update(item_props)
item_inst.persist()

return item_id

conn.commit()
finally:
# Clean up the database handles.
cursor.close()
bknd_core.databaseClose(conn_info)
return item_id
return None


Expand Down
Loading

0 comments on commit 8a30379

Please sign in to comment.