Jump to content

Migrate TXT Exp Table To MySQL


Recommended Posts

M2 Download Center

This is the hidden content, please
( Internal )

Hello. Yesterday I have to measure exp table on server, so I decidet to move exp table from array to mysql to avoid recompile every time.

 

Go to constant.cpp and delete:

Spoiler


const DWORD * exp_table = NULL;

const DWORD exp_table_euckr[PLAYER_EXP_TABLE_MAX + 1] =    
{
    0,            // 0

    100,
    150,
    260,
    380,
    600,

    1300,
    3300,
    5700,
    8700,
    12800,        // 10
    18000,
    25000,
    36000,
    52000,
    73000,
    100000,
    125000,
    160000,
    220000,
    280000,        // 20
    370000,
    540000,
    670000,
    880000,
    1000000,

    1237000,
    1418000,
    1624000,
    1857000,
    2122000,    // 30
    2421000,
    2761000,
    3145000,
    3580000,
    4073000,
    4632000,
    5194000,
    5717000,
    6264000,
    6837000,    // 40
    7600000,
    8274000,
    8990000,
    9753000,
    10560000,
    11410000,
    12320000,
    13270000,
    14280000,
    15340000,    // 50
    16870000,
    18960000,
    19980000,
    21420000,
    22930000,
    24530000,
    26200000,
    27960000,
    29800000,
    32780000,    // 60
    36060000,
    39670000,
    43640000,
    48000000,
    52800000,
    58080000,
    63890000,
    70280000,
    77310000,
    85040000,     // 70
    93540000,
    102900000,
    113200000,
    124500000,
    137000000,
    150700000,
    165700000,
    236990000,
    260650000,
    286780000,    // 80
    315380000,
    346970000,
    381680000,
    419770000,
    461760000,
    508040000,
    558740000,
    614640000,
    676130000,
    743730000,    // 90
    1041222000,
    1145344200,
    1259878620,
    1385866482,
    1524453130,
    1676898443,
    1844588288,
    2029047116,
    2100000000,    //    99        99레벨일 때 필요경험치 (100레벨이 되기 위한)
    2100000000,    //    100
    2100000000,        
    2100000000,        
    2100000000,        
    2100000000,        
    2100000000,    //    105
    2100000000,        
    2100000000,        
    2100000000,        
    2100000000,        
    2100000000,    //    110
    2100000000,        
    2100000000,        
    2100000000,        
    2100000000,        
    2100000000,    //    115
    2100000000,        
    2100000000,        
    2100000000,        
    2100000000,        
    2100000000,    //    120
};

const DWORD exp_table_common[PLAYER_EXP_TABLE_MAX + 1] =
{
    0,    //    0
    300,        
    800,        
    1500,        
    2500,        
    4300,        
    7200,        
    11000,        
    17000,        
    24000,        
    33000,    //    10
    43000,        
    58000,        
    76000,        
    100000,        
    130000,        
    169000,        
    219000,        
    283000,        
    365000,        
    472000,    //    20
    610000,        
    705000,        
    813000,        
    937000,        
    1077000,        
    1237000,        
    1418000,        
    1624000,        
    1857000,        
    2122000,    //    30
    2421000,        
    2761000,        
    3145000,        
    3580000,        
    4073000,        
    4632000,        
    5194000,        
    5717000,        
    6264000,        
    6837000,    //    40
    7600000,        
    8274000,        
    8990000,        
    9753000,        
    10560000,        
    11410000,        
    12320000,        
    13270000,        
    14280000,        
    15340000,    //    50
    16870000,        
    18960000,        
    19980000,        
    21420000,        
    22930000,        
    24530000,        
    26200000,        
    27960000,        
    29800000,        
    32780000,    //    60
    36060000,        
    39670000,        
    43640000,        
    48000000,        
    52800000,        
    58080000,        
    63890000,        
    70280000,        
    77310000,        
    85040000,    //    70
    93540000,        
    102900000,        
    113200000,        
    124500000,        
    137000000,        
    150700000,        
    165700000,        
    236990000,        
    260650000,        
    286780000,    //    80
    315380000,        
    346970000,        
    381680000,        
    419770000,        
    461760000,        
    508040000,        
    558740000,        
    614640000,        
    676130000,        
    743730000,    //    90
    1041222000,        
    1145344200,        
    1259878620,        
    1385866482,        
    1524453130,        
    1676898443,        
    1844588288,        
    2029047116,        
    2050000000,    //    99레벨 일 때 필요경험치 (100레벨이 되기 위한)
    2150000000,    //    100
    2210000000,        
    2250000000,        
    2280000000,        
    2310000000,        
    2330000000,    //    105
    2350000000,        
    2370000000,        
    2390000000,        
    2400000000,        
    2410000000,    //    110
    2420000000,        
    2430000000,        
    2440000000,        
    2450000000,        
    2460000000,    //    115
    2470000000,        
    2480000000,        
    2490000000,        
    2490000000,        
    2500000000,    //    120
};

const DWORD exp_table_newcibn[PLAYER_EXP_TABLE_MAX + 1 ] =
{
    300,    // 0
    800,    // 1
    1500,
    2500,
    4300,
    7200,
    11400,
    17000,
    24000,
    33000,
    46000,    // 10
    62000,
    83000,
    111000,
    149000,
    200000,
    268000,
    360000,
    482000,
    647000,
    868000,    // 20
    996000,
    1143000,
    1312000,
    1506000,
    1729000,
    1984000,
    2277000,
    2614000,
    3000000,
    3443000,    // 30
    3952000,
    4536000,
    5206000,
    5975000,
    6858000,
    7730000,
    8504000,
    9307000,
    10140000,
    11330000,    // 40
    12320000,
    13370000,
    14490000,
    15670000,
    16920000,
    18240000,
    19630000,
    21090000,
    22630000,
    24670000,    // 50
    26890000,
    29310000,
    31950000,
    34820000,
    37960000,
    41370000,
    45100000,
    49160000,
    53580000,
    58400000,    // 60
    63660000,
    69390000,
    75630000,
    82440000,
    89860000,
    97950000,
    106760000,
    136370000,
    151800000,
    168300000,    // 70
    250000000,
    340000000,
    450000000,
    570000000,
    690000000,
    810000000,
    912600000,
    1004000000,
    1094000000,
    1182000000,    // 80
    1269000000,
    1354000000,
    1438000000,
    1521000000,
    1603000000,
    1684000000,
    1764000000,
    1844000000,
    1922000000,
    2000000000,    // 90
    2000000000,
    2000000000,
    2000000000,
    2000000000,
    2000000000,
    2000000000,
    2000000000,
    2000000000,
    2000000000,    //    99        99레벨일 때 필요경험치 (100레벨이 되기 위한).. 현재 CIBN이 어떻게 운영하고 있는 지 모르니 신규 테이블을 쓰지 않고 기존값 계속 연장 유지
    2000000000,    //    100
    2000000000,        
    2000000000,        
    2000000000,        
    2000000000,        
    2000000000,    //    105
    2000000000,        
    2000000000,        
    2000000000,        
    2000000000,        
    2000000000,    //    110
    2000000000,        
    2000000000,        
    2000000000,        
    2000000000,        
    2000000000,    //    115
    2000000000,        
    2000000000,        
    2000000000,        
    2000000000,        
    2000000000,    //    120
};

 

2. Go to constants.h and delete

Spoiler


extern const DWORD*        exp_table;

then add



typedef std::vector<long long> exp_vec;
extern exp_vec exp_vector;
bool LoadExpTableFromMYSQL(void);

 

3. Go to constants.cpp and add on last line or whatever you want in file

#include "db.h"
#include "dev_log.h"

exp_vec exp_vector;

bool LoadExpTableFromMYSQL(void)
{
    char szCountQuery[64];
    char szExp[64];

    sprintf(szCountQuery, "%s", "SELECT COUNT(level) FROM common.exp_table");
    sprintf(szExp, "%s", "SELECT exp FROM common.exp_table");

    std::auto_ptr<SQLMsg> pCountQuery(DBManager::Instance().DirectQuery(szCountQuery));


    if (pCountQuery.get() == NULL)
    {
        sys_err("Failed to fetch level count from mysql! Check table or database.");
        pCountQuery.release();
        pCountQuery.reset();
        return false;
    }

    std::auto_ptr<SQLResult> pRes(pCountQuery.get()->Get());

    if (pRes->uiNumRows > 0)
    {

        MYSQL_ROW row = mysql_fetch_row(pRes.get()->pSQLResult);

        int level = 0; str_to_number(level, row[0]);

        exp_vector.reserve(level);

        sys_log(0, "ExpTable reserved for %d levels", level);

        pCountQuery.release();
        pRes.release();
        pCountQuery.reset();
        pRes.reset();
    }


    std::auto_ptr<SQLMsg> pExp(DBManager::Instance().DirectQuery(szExp));

    if (pExp.get() == NULL)
    {
        sys_err("Failed to fetch level count from mysql! Check table or database.");
        pExp.release();
        pExp.reset();
        return false;
    }

    std::auto_ptr<SQLResult> pRes2(pExp.get()->Get());

    if (pRes2->uiNumRows > 0)
    {
        for (uint uiRow = 0; uiRow != pRes2->uiNumRows; ++uiRow)
        {
            MYSQL_ROW row = mysql_fetch_row(pRes2->pSQLResult);

            long long exp = 0; str_to_number(exp, row[0]);

            exp_vector.push_back(exp);
            sys_log(0, "Pushing exp %d to exp_vector", exp);


        }
        pExp.release();
        pExp.reset();
        pRes2.release();
        pRes2.reset();
        return true;
    }
    return false;
}

4. Go to static void __LocaleService_Init_Korea() in locale_service.cpp and delete exp_table = exp_table_euckr;

static void __LocaleService_Init_YMIR() delete exp_table = exp_table_euckr;
static void __LocaleService_Init_Singapore() delete exp_table = exp_table_newcibn;
static void __LocaleService_Init_Vietnam() delete exp_table = exp_table_newcibn;

void LocaleService_TransferDefaultSetting() change

if (!exp_table)
        exp_table = exp_table_common;

to

if(!LoadExpTableFromMYSQL())
{
  sys_err("Failed to load exp table from mysql!");
  exit(1);
}

 

char.cpp CHARACTER::GetNextExp() const

change exp_table to exp_vector

questlua_pc.cpp int pc_give_exp_perc(lua_State* L)

change exp_table to exp_vector

and int pc_get_exp_perc(lua_State* L)

change exp_table to exp_vector

 

Thats all.

Code can be refactored.

Written in 10min

  • Metin2 Dev 6
  • Good 4
  • Love 11
Link to comment
Share on other sites

  • Premium

Refactored like this?

std::vector<DWORD> exp_vector;
bool LoadExpTableFromMySQL()
{
    std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT level, exp FROM common.exp_table"));
    if (pMsg->uiSQLErrno != 0)
    {
        sys_err("Failed to load exp table!");
        return false;
    }

    exp_vector.reserve(pMsg->Get()->uiNumRows);

    MYSQL_ROW row;
    while((row = mysql_fetch_row(pMsg->Get()->pSQLResult)))
    {
        DWORD level, exp;
        str_to_number(level, row[0]);
        str_to_nubmer(exp, row[1]);

        exp_vector[level] = exp;

        if (test_server)
            sys_log(0, "MYSQL EXP LOAD: LEVEL %u EXP %u", level, exp);
    }

    return true;
}

Since GetNextExp() will return DWORD, you should use DWORD too for your vector. You will fool the users thinking that they can increase exp limit over 4kkk (DWORD limit).

Also, if you're using C++11 or higher consider using unique_ptr instead of auto_ptr.

  • Love 1
Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.