summaryrefslogtreecommitdiff
path: root/hercules/code
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-02-18 15:26:11 +0300
committerAndrei Karas <akaras@inbox.ru>2015-02-18 15:30:41 +0300
commita78224ded6873bbb3078a7f01f123551b34a82fb (patch)
treef286da32fb0018820ae59d9eeadbe5de31e6486c /hercules/code
parent1cf8a73eaab31a1a868ea9edf88d256a37d21fc2 (diff)
downloadevol-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/code')
-rw-r--r--hercules/code/server/account.py63
-rw-r--r--hercules/code/server/evol/main.py4
-rw-r--r--hercules/code/stringutils.py7
3 files changed, 74 insertions, 0 deletions
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