diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-02-18 15:26:11 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-02-18 15:30:41 +0300 |
commit | a78224ded6873bbb3078a7f01f123551b34a82fb (patch) | |
tree | f286da32fb0018820ae59d9eeadbe5de31e6486c /hercules | |
parent | 1cf8a73eaab31a1a868ea9edf88d256a37d21fc2 (diff) | |
download | evol-tools-a78224ded6873bbb3078a7f01f123551b34a82fb.tar.gz evol-tools-a78224ded6873bbb3078a7f01f123551b34a82fb.tar.bz2 evol-tools-a78224ded6873bbb3078a7f01f123551b34a82fb.tar.xz evol-tools-a78224ded6873bbb3078a7f01f123551b34a82fb.zip |
hercules: add converter for account.txt
Diffstat (limited to 'hercules')
-rw-r--r-- | hercules/.gitignore | 2 | ||||
-rw-r--r-- | hercules/code/server/account.py | 63 | ||||
-rw-r--r-- | hercules/code/server/evol/main.py | 4 | ||||
-rw-r--r-- | hercules/code/stringutils.py | 7 | ||||
-rwxr-xr-x | hercules/convert_db.py | 25 | ||||
-rw-r--r-- | hercules/templates/login.sql | 21 |
6 files changed, 122 insertions, 0 deletions
diff --git a/hercules/.gitignore b/hercules/.gitignore index b21c9db..a2120ce 100644 --- a/hercules/.gitignore +++ b/hercules/.gitignore @@ -4,5 +4,7 @@ serverdata oldserverdata newserverdata mapcache +olddb +newdb *.pyc diff --git a/hercules/code/server/account.py b/hercules/code/server/account.py new file mode 100644 index 0000000..28aafe4 --- /dev/null +++ b/hercules/code/server/account.py @@ -0,0 +1,63 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import re + +from code.fileutils import * +from code.stringutils import * + +def convertSex(sex): + if sex == "M" or sex == "F" or sex == "S": + return sex + return "M" + +def convertAccount(): + srcFile = "olddb/account.txt" + dstFile = "newdb/login.sql" + fieldsSplit = re.compile("\t") + tpl = readFile("templates/login.sql") + firstLine = True + with open(dstFile, "w") as w: + w.write(tpl) + w.write("INSERT INTO `login` 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) != 14: + print "wrong account.txt line: " + stripNewLine(line) + continue + + if firstLine == False: + w.write(",\n") + else: + firstLine = False + + w.write(("({account_id},'{userid}','{user_pass}','{sex}'," + + "'{email}',{group_id},{state},{unban_time}," + + "{expiration_time},{logincount},'{lastlogin}'," + + "'{last_ip}','{birthdate}',{character_slots}," + + "'{pincode}',{pincode_change})").format( + account_id = rows[0], + userid = escapeSqlStr(rows[1]), + user_pass = escapeSqlStr(rows[2]), + sex = convertSex(rows[4]), + email = escapeSqlStr(rows[7]), + group_id = 0, + state = 0, + unban_time = rows[12], + expiration_time = rows[9], + logincount = rows[5], + lastlogin = rows[3], + last_ip = rows[10], + birthdate = '0000-00-00', + character_slots = 0, + pincode = '', + pincode_change = 0 + )) + w.write("\n") diff --git a/hercules/code/server/evol/main.py b/hercules/code/server/evol/main.py index ca5ce84..2b8681b 100644 --- a/hercules/code/server/evol/main.py +++ b/hercules/code/server/evol/main.py @@ -4,6 +4,7 @@ # Copyright (C) 2014 Evol Online # Author: Andrei Karas (4144) +from code.server.account import * from code.server.evol.consts import * from code.server.evol.itemdb import * from code.server.evol.mobdb import * @@ -22,3 +23,6 @@ def serverEvolMain(): quests = convertQuestsDb() convertConsts(quests) convertMobSkillDb() + +def dbEvolMain(): + convertAccount() diff --git a/hercules/code/stringutils.py b/hercules/code/stringutils.py index 3d0b77a..fccf403 100644 --- a/hercules/code/stringutils.py +++ b/hercules/code/stringutils.py @@ -33,3 +33,10 @@ def stripNewLine(data): if data[-1] == "\n": data = data[:-1] return data + +def escapeSqlStr(data): + data = data.replace("'", "\\'"); + data = data.replace("`", "\\`"); + data = data.replace("{", "\\{"); + data = data.replace("}", "\\}"); + return data diff --git a/hercules/convert_db.py b/hercules/convert_db.py new file mode 100755 index 0000000..1c367ff --- /dev/null +++ b/hercules/convert_db.py @@ -0,0 +1,25 @@ +#! /usr/bin/env python +# -*- coding: utf8 -*- +# +# Copyright (C) 2015 Evol Online +# Author: Andrei Karas (4144) + +import sys + +from code.server.evol.main import * +from code.server.tmw.main import * + +def showHelp(): + print "Usage: ./convert_db.py evol" + print " ./convert_db.py tmw" + exit(1) + +if len(sys.argv) != 2: + showHelp() + +if sys.argv[1] == "evol": + dbEvolMain() +elif sys.argv[1] == "tmw": + dbTmwMain() +else: + showHelp() diff --git a/hercules/templates/login.sql b/hercules/templates/login.sql new file mode 100644 index 0000000..39bf531 --- /dev/null +++ b/hercules/templates/login.sql @@ -0,0 +1,21 @@ +CREATE TABLE IF NOT EXISTS `login` ( + `account_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `userid` VARCHAR(23) NOT NULL DEFAULT '', + `user_pass` VARCHAR(32) NOT NULL DEFAULT '', + `sex` ENUM('M','F','S') NOT NULL DEFAULT 'M', + `email` VARCHAR(39) NOT NULL DEFAULT '', + `group_id` TINYINT(3) NOT NULL DEFAULT '0', + `state` INT(11) UNSIGNED NOT NULL DEFAULT '0', + `unban_time` INT(11) UNSIGNED NOT NULL DEFAULT '0', + `expiration_time` INT(11) UNSIGNED NOT NULL DEFAULT '0', + `logincount` MEDIUMINT(9) UNSIGNED NOT NULL DEFAULT '0', + `lastlogin` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', + `last_ip` VARCHAR(100) NOT NULL DEFAULT '', + `birthdate` DATE NOT NULL DEFAULT '0000-00-00', + `character_slots` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0', + `pincode` VARCHAR(4) NOT NULL DEFAULT '', + `pincode_change` INT(11) UNSIGNED NOT NULL DEFAULT '0', + PRIMARY KEY (`account_id`), + KEY `name` (`userid`) +) ENGINE=InnoDB AUTO_INCREMENT=2000000; + |