summaryrefslogtreecommitdiff
path: root/hercules/code/server/account.py
blob: ef83bc294331385f3b0cfd5e57f871ba26892e10 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- coding: utf8 -*-
#
# Copyright (C) 2014  Evol Online
# Author: Andrei Karas (4144)

import re

from code.fileutils import readFile
from code.stringutils import stripNewLine, escapeSqlStr

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")