diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-02-18 21:13:25 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-02-18 21:13:25 +0300 |
commit | 07878798e164453fd208b7187d0f61d0177009b6 (patch) | |
tree | c1350c7429e11d1058ab364cbc4e9fab4032e899 /hercules/code | |
parent | 12e0196bbf34fe878b42b4010be8c08217cf45eb (diff) | |
download | evol-tools-07878798e164453fd208b7187d0f61d0177009b6.tar.gz evol-tools-07878798e164453fd208b7187d0f61d0177009b6.tar.bz2 evol-tools-07878798e164453fd208b7187d0f61d0177009b6.tar.xz evol-tools-07878798e164453fd208b7187d0f61d0177009b6.zip |
hercules: convert to storage.sql
Diffstat (limited to 'hercules/code')
-rw-r--r-- | hercules/code/server/evol/main.py | 4 | ||||
-rw-r--r-- | hercules/code/server/storage.py | 81 |
2 files changed, 84 insertions, 1 deletions
diff --git a/hercules/code/server/evol/main.py b/hercules/code/server/evol/main.py index bdf202b..f00192b 100644 --- a/hercules/code/server/evol/main.py +++ b/hercules/code/server/evol/main.py @@ -5,6 +5,7 @@ # Author: Andrei Karas (4144) from code.server.account import * +from code.server.storage import * from code.server.db.char import * from code.server.db.charregnumdb import * from code.server.db.inventory import * @@ -35,4 +36,5 @@ def dbEvolMain(): saveCharTable(users) saveCharRegNumDbTable(users) saveSkillTable(users) - saveInventoryTable(users)
\ No newline at end of file + saveInventoryTable(users) + convertStorage() diff --git a/hercules/code/server/storage.py b/hercules/code/server/storage.py new file mode 100644 index 0000000..a8d5802 --- /dev/null +++ b/hercules/code/server/storage.py @@ -0,0 +1,81 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import re + +from code.fileutils import * +from code.stringutils import * +from code.server.dbitem import * + +def convertStorage(): + srcFile = "olddb/storage.txt" + dstFile = "newdb/storage.sql" + fieldsSplit = re.compile("\t") + comaSplit = re.compile(",") + spaceSplit = re.compile(" ") + tpl = readFile("templates/storage.sql") + firstLine = True + with open(dstFile, "w") as w: + w.write(tpl) + w.write("INSERT INTO `storage` VALUES ") + with open(srcFile, "r") as r: + for line in r: + if line[:2] == "//": + continue + rows = fieldsSplit.split(line) + if len(rows) == 2: + continue + if len(rows) != 3: + print "wrong storage.txt line: " + stripNewLine(line) + continue + + tmp = comaSplit.split(rows[0]) + accountId = tmp[0] + storage_amount = tmp[1] + + data = spaceSplit.split(rows[1]) + for itemStr in data: + if itemStr == "": + continue + + tmp = comaSplit.split(itemStr) + item = Item() + item.unknownId = tmp[0] + item.itemId = tmp[1] + item.amount = tmp[2] + item.equip = tmp[3] + item.color = tmp[4] + item.refine = tmp[5] + item.attribute = tmp[6] + item.card0 = tmp[7] + item.card1 = tmp[8] + item.card2 = tmp[9] + item.card3 = "0" + + if firstLine == False: + w.write(",\n") + else: + firstLine = False + + w.write(("({id},{account_id},{nameid},{amount},{equip},{identify}," + + "{refine},{attribute},{card0},{card1},{card2},{card3}," + + "{expire_time},{bound},{unique_id})").format( + id = 0, + account_id = accountId, + 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", + bound = "0", + unique_id = "0" + )) + w.write("\n") |