summaryrefslogtreecommitdiff
path: root/hercules/code/server/db
diff options
context:
space:
mode:
Diffstat (limited to 'hercules/code/server/db')
-rw-r--r--hercules/code/server/db/__init__.py0
-rw-r--r--hercules/code/server/db/char.py187
-rw-r--r--hercules/code/server/db/charregnumdb.py34
-rw-r--r--hercules/code/server/db/inventory.py44
-rw-r--r--hercules/code/server/db/skill.py31
5 files changed, 296 insertions, 0 deletions
diff --git a/hercules/code/server/db/__init__.py b/hercules/code/server/db/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/hercules/code/server/db/__init__.py
diff --git a/hercules/code/server/db/char.py b/hercules/code/server/db/char.py
new file mode 100644
index 0000000..cd8e0cc
--- /dev/null
+++ b/hercules/code/server/db/char.py
@@ -0,0 +1,187 @@
+# -*- coding: utf8 -*-
+#
+# Copyright (C) 2015 Evol Online
+# Author: Andrei Karas (4144)
+
+from code.fileutils import readFile
+from code.stringutils import escapeSqlStr
+
+def saveCharTable(users):
+ dstFile = "newdb/char.sql"
+ firstLine = True
+ tpl = readFile("templates/char.sql")
+ with open(dstFile, "w") as w:
+ w.write(tpl)
+ w.write("INSERT INTO `char` VALUES ")
+ for userId in users:
+ user = users[userId]
+
+ if firstLine == False:
+ w.write(",\n")
+ else:
+ firstLine = False
+
+ w.write(("({char_id},{account_id},{char_num},'{name}',{CLASS}," +
+ "{base_level},{job_level},{base_exp},{job_exp},{zeny}," +
+ "{str},{agi},{vit},{INT},{dex},{luk},{max_hp},{hp},{max_sp}," +
+ "{sp},{status_point},{skill_point},{option},{karma},{manner}," +
+ "{party_id},{guild_id},{pet_id},{homun_id},{elemental_id}," +
+ "{hair},{hair_color},{clothes_color},{body},{weapon},{shield}," +
+ "{head_top},{head_mid},{head_bottom},{robe}," +
+ "'{last_map}',{last_x},{last_y},'{save_map}',{save_x},{save_y}," +
+ "{partner_id},{online},{father},{mother},{child},{fame}," +
+ "{rename},{delete_date},{slotchange},{char_opt},{font}," +
+ "{unban_time},{uniqueitem_counter},'{sex}',{hotkey_rowshift})").format(
+ char_id = user.char_id,
+ account_id = user.account_id,
+ char_num = user.char_num,
+ name = escapeSqlStr(user.char_name),
+ CLASS = user.char_class,
+ base_level = user.base_level,
+ job_level = user.job_level,
+ base_exp = user.base_exp,
+ job_exp = user.job_exp,
+ zeny = user.zeny,
+ str = user.stat_str,
+ agi = user.stat_agi,
+ vit = user.stat_vit,
+ INT = user.stat_int,
+ dex = user.stat_dex,
+ luk = user.stat_luk,
+ max_hp = user.max_hp,
+ hp = user.hp,
+ max_sp = user.max_sp,
+ sp = user.sp,
+ status_point = user.status_point,
+ skill_point = user.skill_point,
+ option = user.option,
+ karma = user.karma,
+ manner = user.manner,
+ party_id = user.party_id,
+ guild_id = user.guild_id,
+ pet_id = user.pet_id,
+ homun_id = "0",
+ elemental_id = "0",
+ hair = user.hair,
+ hair_color = user.hair_color,
+ clothes_color = user.clothes_color,
+ body = 0,
+ weapon = user.weapon,
+ shield = user.shield,
+ head_top = user.head_top,
+ head_mid = user.head_mid,
+ head_bottom = user.head_bottom,
+ robe = "0",
+ last_map = escapeSqlStr(user.last_map),
+ last_x = user.last_x,
+ last_y = user.last_y,
+ save_map = escapeSqlStr(user.save_map),
+ save_x = user.save_x,
+ save_y = user.save_y,
+ partner_id = user.partner_id,
+ online = "0",
+ father = "0",
+ mother = "0",
+ child = "0",
+ fame = "0",
+ rename = "0",
+ delete_date = "0",
+ slotchange = "0",
+ char_opt = "0",
+ font = "0",
+ unban_time = "0",
+ uniqueitem_counter = len(user.inventory),
+ sex = "U",
+ hotkey_rowshift = 0
+ ))
+ w.write("\n")
+
+def saveCharTableCustom(users):
+ dstFile = "newdb/char.sql"
+ firstLine = True
+ tpl = readFile("templates/char.sql")
+ with open(dstFile, "w") as w:
+ w.write(tpl)
+ w.write("INSERT INTO `char` VALUES ")
+ for userId in users:
+ user = users[userId]
+
+ if firstLine == False:
+ w.write(",\n")
+ else:
+ firstLine = False
+
+ w.write(("({char_id},{account_id},{char_num},'{name}',{CLASS}," +
+ "{base_level},{job_level},{base_exp},{job_exp},{zeny}," +
+ "{str},{agi},{vit},{INT},{dex},{luk},{max_hp},{hp},{max_sp}," +
+ "{sp},{status_point},{skill_point},{option},{karma},{manner}," +
+ "{party_id},{guild_id},{pet_id},{homun_id},{elemental_id}," +
+ "{hair},{hair_color},{clothes_color},{body},{weapon},{shield}," +
+ "{head_top},{head_mid},{head_bottom},{robe}," +
+ "'{last_map}',{last_x},{last_y},'{save_map}',{save_x},{save_y}," +
+ "{partner_id},{online},{father},{mother},{child},{fame}," +
+ "{rename},{delete_date},{slotchange},{char_opt},{font}," +
+ "{unban_time},{uniqueitem_counter},'{sex}',{hotkey_rowshift})").format(
+ char_id = user.char_id,
+ account_id = user.account_id,
+ char_num = user.char_num,
+ name = escapeSqlStr(user.char_name),
+ CLASS = 0,
+ base_level = user.base_level,
+ job_level = user.job_level,
+ base_exp = user.base_exp,
+ job_exp = user.job_exp,
+ zeny = user.zeny,
+ str = user.stat_str,
+ agi = user.stat_agi,
+ vit = user.stat_vit,
+ INT = user.stat_int,
+ dex = user.stat_dex,
+ luk = user.stat_luk,
+ max_hp = user.max_hp,
+ hp = user.hp,
+ max_sp = user.max_sp,
+ sp = user.sp,
+ status_point = user.status_point,
+ skill_point = user.skill_point,
+ option = user.option,
+ karma = user.karma,
+ manner = user.manner,
+ party_id = 0,
+ guild_id = 0,
+ pet_id = 0,
+ homun_id = "0",
+ elemental_id = "0",
+ hair = user.hair,
+ hair_color = user.hair_color,
+ clothes_color = user.clothes_color,
+ body = 0,
+ weapon = 0,
+ shield = 0,
+ head_top = 0,
+ head_mid = 0,
+ head_bottom = 0,
+ robe = "0",
+ last_map = "000-2-1",
+ last_x = 50,
+ last_y = 37,
+ save_map = "00-2-1",
+ save_x = 50,
+ save_y = 37,
+ partner_id = user.partner_id,
+ online = "0",
+ father = "0",
+ mother = "0",
+ child = "0",
+ fame = "0",
+ rename = "0",
+ delete_date = "0",
+ slotchange = "0",
+ char_opt = "0",
+ font = "0",
+ unban_time = "0",
+ uniqueitem_counter = len(user.inventory),
+ sex = "U",
+ hotkey_rowshift = 0
+ ))
+ w.write("\n")
diff --git a/hercules/code/server/db/charregnumdb.py b/hercules/code/server/db/charregnumdb.py
new file mode 100644
index 0000000..1617c13
--- /dev/null
+++ b/hercules/code/server/db/charregnumdb.py
@@ -0,0 +1,34 @@
+# -*- coding: utf8 -*-
+#
+# Copyright (C) 2015 Evol Online
+# Author: Andrei Karas (4144)
+
+from code.fileutils import readFile
+
+def saveCharRegNumDbTable(users):
+ dstFile = "newdb/char_reg_num_db.sql"
+ firstLine = True
+ tpl = readFile("templates/char_reg_num_db.sql")
+ with open(dstFile, "w") as w:
+ w.write(tpl)
+ w.write("INSERT INTO `char_reg_num_db` VALUES ")
+ for userId in users:
+ user = users[userId]
+ for varKey in user.variables:
+ if varKey == "ShipQuests":
+ continue
+
+ varValue = user.variables[varKey]
+
+ if firstLine == False:
+ w.write(",\n")
+ else:
+ firstLine = False
+
+ w.write(("({char_id},'{key}',{index},{value})").format(
+ char_id = user.char_id,
+ key = varKey,
+ index = "0",
+ value = varValue
+ ))
+ w.write("\n")
diff --git a/hercules/code/server/db/inventory.py b/hercules/code/server/db/inventory.py
new file mode 100644
index 0000000..e5c1e6a
--- /dev/null
+++ b/hercules/code/server/db/inventory.py
@@ -0,0 +1,44 @@
+# -*- coding: utf8 -*-
+#
+# Copyright (C) 2015 Evol Online
+# Author: Andrei Karas (4144)
+
+from code.fileutils import readFile
+
+def saveInventoryTable(users):
+ dstFile = "newdb/inventory.sql"
+ firstLine = True
+ tpl = readFile("templates/inventory.sql")
+ with open(dstFile, "w") as w:
+ w.write(tpl)
+ w.write("INSERT INTO `inventory` VALUES ")
+ for userId in users:
+ user = users[userId]
+ for item in user.inventory:
+
+ if firstLine == False:
+ w.write(",\n")
+ else:
+ firstLine = False
+
+ w.write(("({id},{char_id},{nameid},{amount},{equip},{identify}," +
+ "{refine},{attribute},{card0},{card1},{card2},{card3}," +
+ "{expire_time},{favorite},{bound},{unique_id})").format(
+ id = 0,
+ char_id = user.char_id,
+ nameid = item.itemId,
+ amount = item.amount,
+ equip = item.equip,
+ identify = "1",
+ refine = item.refine,
+ attribute = item.attribute,
+ card0 = "0",
+ card1 = "0",
+ card2 = "0",
+ card3 = "0",
+ expire_time = "0",
+ favorite = "0",
+ bound = "0",
+ unique_id = "0"
+ ))
+ w.write("\n")
diff --git a/hercules/code/server/db/skill.py b/hercules/code/server/db/skill.py
new file mode 100644
index 0000000..d21eb3d
--- /dev/null
+++ b/hercules/code/server/db/skill.py
@@ -0,0 +1,31 @@
+# -*- coding: utf8 -*-
+#
+# Copyright (C) 2015 Evol Online
+# Author: Andrei Karas (4144)
+
+from code.fileutils import readFile
+
+def saveSkillTable(users):
+ dstFile = "newdb/skill.sql"
+ firstLine = True
+ tpl = readFile("templates/skill.sql")
+ with open(dstFile, "w") as w:
+ w.write(tpl)
+ w.write("INSERT INTO `skill` VALUES ")
+ for userId in users:
+ user = users[userId]
+ for skill in user.skills:
+
+ if firstLine == False:
+ w.write(",\n")
+ else:
+ firstLine = False
+
+ w.write(("({char_id},{id},{lv},{flag})").format(
+ char_id = user.char_id,
+ id = skill.skillId,
+ lv = skill.level,
+ flag = 0
+# flag = skill.flags
+ ))
+ w.write("\n")