diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-02-19 20:25:14 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-02-19 20:41:14 +0300 |
commit | c6892d9631000859b04a203b1d2e9e5a828c2ffa (patch) | |
tree | 61b995fd164e32d31c5d96efd47f1a594faeae63 | |
parent | 57a76c737b207c83cc0ef597ba470511acf2462e (diff) | |
download | evol-tools-c6892d9631000859b04a203b1d2e9e5a828c2ffa.tar.gz evol-tools-c6892d9631000859b04a203b1d2e9e5a828c2ffa.tar.bz2 evol-tools-c6892d9631000859b04a203b1d2e9e5a828c2ffa.tar.xz evol-tools-c6892d9631000859b04a203b1d2e9e5a828c2ffa.zip |
hercules: convert to party.sql
-rw-r--r-- | hercules/code/server/evol/main.py | 2 | ||||
-rw-r--r-- | hercules/code/server/party.py | 81 | ||||
-rw-r--r-- | hercules/code/server/tmw/main.py | 2 | ||||
-rw-r--r-- | hercules/templates/party.sql | 10 |
4 files changed, 95 insertions, 0 deletions
diff --git a/hercules/code/server/evol/main.py b/hercules/code/server/evol/main.py index 8d62d17..308bc87 100644 --- a/hercules/code/server/evol/main.py +++ b/hercules/code/server/evol/main.py @@ -6,6 +6,7 @@ from code.server.account import * from code.server.accreg import * +from code.server.party import * from code.server.storage import * from code.server.db.char import * from code.server.db.charregnumdb import * @@ -40,3 +41,4 @@ def dbEvolMain(): saveInventoryTable(users) convertStorage() convertAccReg() + convertParty(users)
\ No newline at end of file diff --git a/hercules/code/server/party.py b/hercules/code/server/party.py new file mode 100644 index 0000000..b71f66f --- /dev/null +++ b/hercules/code/server/party.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 findLeaderId(name, users): + for userId in users: + user = users[userId] + if user.char_name == name: + return user.char_id + return 0 + +def convertParty(users): + srcFile = "olddb/party.txt" + dstFile = "newdb/party.sql" + fieldsSplit = re.compile("\t") + comaSplit = re.compile(",") + tpl = readFile("templates/party.sql") + firstLine = True + with open(dstFile, "w") as w: + w.write(tpl) + w.write("INSERT INTO `party` VALUES ") + with open(srcFile, "r") as r: + for line in r: + if line[:2] == "//": + continue + line = stripNewLine(line) + rows = fieldsSplit.split(line) + if len(rows) == 2: + continue + if len(rows) < 3: + print "wrong party.txt line: " + line + continue + + partyId = rows[0] + partyName = rows[1] + + tmp = comaSplit.split(rows[2]) + partyExp = tmp[0] + partyItem = tmp[1] + + leaderId = 0 + leaderName = "" + accountId = "" + + for f in xrange(3, len(rows), 2): + + if rows[f] == "0,0" or rows[f] == "": + continue + + tmp = comaSplit.split(rows[f]) + accountId = tmp[0] + leader = tmp[1] + charName = rows[f + 1] + if leader == "1": + leaderId = accountId + leaderName = charName + + if firstLine == False: + w.write(",\n") + else: + firstLine = False + + leaderCharId = findLeaderId(leaderName, users) + + w.write(("({party_id},'{name}',{exp},{item}," + + "{leader_id},{leader_char})").format( + party_id = partyId, + name = escapeSqlStr(partyName), + exp = partyExp, + item = partyItem, + leader_id = leaderId, + leader_char = leaderCharId + )) + w.write("\n") diff --git a/hercules/code/server/tmw/main.py b/hercules/code/server/tmw/main.py index da8951c..221cfd2 100644 --- a/hercules/code/server/tmw/main.py +++ b/hercules/code/server/tmw/main.py @@ -6,6 +6,7 @@ from code.server.account import * from code.server.accreg import * +from code.server.party import * from code.server.storage import * from code.server.db.char import * from code.server.db.charregnumdb import * @@ -43,3 +44,4 @@ def dbTmwMain(): saveInventoryTable(users) convertStorage() convertAccReg() + convertParty(users) diff --git a/hercules/templates/party.sql b/hercules/templates/party.sql new file mode 100644 index 0000000..69b2c64 --- /dev/null +++ b/hercules/templates/party.sql @@ -0,0 +1,10 @@ +CREATE TABLE IF NOT EXISTS `party` ( + `party_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` VARCHAR(24) NOT NULL DEFAULT '', + `exp` TINYINT(11) UNSIGNED NOT NULL DEFAULT '0', + `item` TINYINT(11) UNSIGNED NOT NULL DEFAULT '0', + `leader_id` INT(11) UNSIGNED NOT NULL DEFAULT '0', + `leader_char` INT(11) UNSIGNED NOT NULL DEFAULT '0', + PRIMARY KEY (`party_id`) +) ENGINE=InnoDB; + |