From 41974ae5265fbc23a06f276f9e008d5dad020e0b Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Thu, 30 Aug 2012 16:16:25 -0700 Subject: Rename files for C++ conversion. Does not compile. After updating, you can remove these files, as shown in 'git status': Untracked files: (use "git add ..." to include in what will be committed) src/map/magic-interpreter-lexer.c src/map/magic-interpreter-parser.c src/map/magic-interpreter-parser.h --- src/tool/adduser.c | 115 --------- src/tool/adduser.cpp | 115 +++++++++ src/tool/convert.c | 302 ---------------------- src/tool/convert.cpp | 302 ++++++++++++++++++++++ src/tool/eathena-monitor.c | 223 ----------------- src/tool/eathena-monitor.cpp | 223 +++++++++++++++++ src/tool/itemfrob.c | 130 ---------- src/tool/itemfrob.cpp | 130 ++++++++++ src/tool/mapfrob.c | 129 ---------- src/tool/mapfrob.cpp | 129 ++++++++++ src/tool/marriage-info.c | 482 ------------------------------------ src/tool/marriage-info.cpp | 482 ++++++++++++++++++++++++++++++++++++ src/tool/moneycount/athena_text.cpp | 4 +- src/tool/moneycount/athena_text.h | 9 - src/tool/moneycount/athena_text.hpp | 9 + src/tool/moneycount/main.cpp | 4 +- src/tool/moneycount/mmo.h | 309 ----------------------- src/tool/moneycount/mmo.hpp | 309 +++++++++++++++++++++++ src/tool/skillfrob.c | 80 ------ src/tool/skillfrob.cpp | 80 ++++++ 20 files changed, 1783 insertions(+), 1783 deletions(-) delete mode 100644 src/tool/adduser.c create mode 100644 src/tool/adduser.cpp delete mode 100644 src/tool/convert.c create mode 100644 src/tool/convert.cpp delete mode 100644 src/tool/eathena-monitor.c create mode 100644 src/tool/eathena-monitor.cpp delete mode 100644 src/tool/itemfrob.c create mode 100644 src/tool/itemfrob.cpp delete mode 100644 src/tool/mapfrob.c create mode 100644 src/tool/mapfrob.cpp delete mode 100644 src/tool/marriage-info.c create mode 100644 src/tool/marriage-info.cpp delete mode 100644 src/tool/moneycount/athena_text.h create mode 100644 src/tool/moneycount/athena_text.hpp delete mode 100644 src/tool/moneycount/mmo.h create mode 100644 src/tool/moneycount/mmo.hpp delete mode 100644 src/tool/skillfrob.c create mode 100644 src/tool/skillfrob.cpp (limited to 'src/tool') diff --git a/src/tool/adduser.c b/src/tool/adduser.c deleted file mode 100644 index 1954b66..0000000 --- a/src/tool/adduser.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - This program adds an user to account.txt - Don't usr it When login-sever is working. -*/ - -#include -#include -#include - -char *account_txt = "../save/account.txt"; - -//----------------------------------------------------- -// Function to suppress control characters in a string. -//----------------------------------------------------- -int remove_control_chars (unsigned char *str) -{ - int i; - int change = 0; - - for (i = 0; str[i]; i++) - { - if (str[i] < 32) - { - str[i] = '_'; - change = 1; - } - } - - return change; -} - -int main (int argc, char *argv[]) -{ - - char username[24]; - char password[24]; - char sex[2]; - - int next_id, id; - char line[1024]; - - // Check to see if account.txt exists. - printf ("Checking if '%s' file exists...\n", account_txt); - FILE *FPaccin = fopen (account_txt, "r"); - if (FPaccin == NULL) - { - printf ("'%s' file not found!\n", account_txt); - printf ("Run the setup wizard please.\n"); - exit (0); - } - - next_id = 2000000; - while (fgets (line, sizeof (line) - 1, FPaccin)) - { - if (line[0] == '/' && line[1] == '/') - { - continue; - } - if (sscanf (line, "%d\t%%newid%%\n", &id) == 1) - { - if (next_id < id) - { - next_id = id; - } - } - else - { - sscanf (line, "%i%[^ ]", &id); - if (next_id <= id) - { - next_id = id + 1; - } - } - } - fclose (FPaccin); - printf ("File exists.\n"); - - printf ("Don't create an account if the login-server is online!!!\n"); - printf - ("If the login-server is online, press ctrl+C now to stop this software.\n"); - printf ("\n"); - - strcpy (username, ""); - while (strlen (username) < 4 || strlen (username) > 23) - { - printf ("Enter an username (4-23 characters): "); - scanf ("%s", &username); - username[23] = 0; - remove_control_chars (username); - } - - strcpy (password, ""); - while (strlen (password) < 4 || strlen (password) > 23) - { - printf ("Enter a password (4-23 characters): "); - scanf ("%s", &password); - password[23] = 0; - remove_control_chars (password); - } - - strcpy (sex, ""); - while (strcmp (sex, "F") != 0 && strcmp (sex, "M") != 0) - { - printf ("Enter a gender (M for male, F for female): "); - scanf ("%s", &sex); - } - - FILE *FPaccout = fopen (account_txt, "r+"); - fseek (FPaccout, 0, SEEK_END); - fprintf (FPaccout, "%i %s %s - %s -\r\n", next_id, username, - password, sex); - fclose (FPaccout); - - printf ("Account added.\n"); -} diff --git a/src/tool/adduser.cpp b/src/tool/adduser.cpp new file mode 100644 index 0000000..1954b66 --- /dev/null +++ b/src/tool/adduser.cpp @@ -0,0 +1,115 @@ +/* + This program adds an user to account.txt + Don't usr it When login-sever is working. +*/ + +#include +#include +#include + +char *account_txt = "../save/account.txt"; + +//----------------------------------------------------- +// Function to suppress control characters in a string. +//----------------------------------------------------- +int remove_control_chars (unsigned char *str) +{ + int i; + int change = 0; + + for (i = 0; str[i]; i++) + { + if (str[i] < 32) + { + str[i] = '_'; + change = 1; + } + } + + return change; +} + +int main (int argc, char *argv[]) +{ + + char username[24]; + char password[24]; + char sex[2]; + + int next_id, id; + char line[1024]; + + // Check to see if account.txt exists. + printf ("Checking if '%s' file exists...\n", account_txt); + FILE *FPaccin = fopen (account_txt, "r"); + if (FPaccin == NULL) + { + printf ("'%s' file not found!\n", account_txt); + printf ("Run the setup wizard please.\n"); + exit (0); + } + + next_id = 2000000; + while (fgets (line, sizeof (line) - 1, FPaccin)) + { + if (line[0] == '/' && line[1] == '/') + { + continue; + } + if (sscanf (line, "%d\t%%newid%%\n", &id) == 1) + { + if (next_id < id) + { + next_id = id; + } + } + else + { + sscanf (line, "%i%[^ ]", &id); + if (next_id <= id) + { + next_id = id + 1; + } + } + } + fclose (FPaccin); + printf ("File exists.\n"); + + printf ("Don't create an account if the login-server is online!!!\n"); + printf + ("If the login-server is online, press ctrl+C now to stop this software.\n"); + printf ("\n"); + + strcpy (username, ""); + while (strlen (username) < 4 || strlen (username) > 23) + { + printf ("Enter an username (4-23 characters): "); + scanf ("%s", &username); + username[23] = 0; + remove_control_chars (username); + } + + strcpy (password, ""); + while (strlen (password) < 4 || strlen (password) > 23) + { + printf ("Enter a password (4-23 characters): "); + scanf ("%s", &password); + password[23] = 0; + remove_control_chars (password); + } + + strcpy (sex, ""); + while (strcmp (sex, "F") != 0 && strcmp (sex, "M") != 0) + { + printf ("Enter a gender (M for male, F for female): "); + scanf ("%s", &sex); + } + + FILE *FPaccout = fopen (account_txt, "r+"); + fseek (FPaccout, 0, SEEK_END); + fprintf (FPaccout, "%i %s %s - %s -\r\n", next_id, username, + password, sex); + fclose (FPaccout); + + printf ("Account added.\n"); +} diff --git a/src/tool/convert.c b/src/tool/convert.c deleted file mode 100644 index e256fc9..0000000 --- a/src/tool/convert.c +++ /dev/null @@ -1,302 +0,0 @@ -#include -#include - -#define MAX_INVENTORY 100 -#define MAX_CART 100 -#define MAX_SKILL 350 -#define GLOBAL_REG_NUM 16 - -struct item -{ - int id; - short nameid; - short amount; - short equip; - char identify; - char refine; - char attribute; - short card[4]; -}; -struct point -{ - char map[16]; - short x, y; -}; -struct skill -{ - unsigned short id, lv, flag; -}; -struct global_reg -{ - char str[16]; - int value; -}; - -struct mmo_charstatus -{ - int char_id; - int account_id; - int base_exp, job_exp, zeny; - - short class; - short status_point, skill_point; - short hp, max_hp, sp, max_sp; - short option, karma, manner; - short hair, hair_color, clothes_color; - int party_id, guild_id, pet_id; - - short weapon, shield; - short head_top, head_mid, head_bottom; - - char name[24]; - unsigned char base_level, job_level; - unsigned char str, agi, vit, int_, dex, luk, char_num, sex; - - struct point last_point, save_point, memo_point[3]; - struct item inventory[MAX_INVENTORY], cart[MAX_CART]; - struct skill skill[MAX_SKILL]; - int global_reg_num; - struct global_reg global_reg[GLOBAL_REG_NUM]; -}; - -int mmo_char_tostr (char *str, struct mmo_charstatus *p) -{ - int i; - sprintf (str, "%d\t%d,%d\t%s\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d\t%d,%d,%d,%d,%d,%d\t%d,%d" "\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d,%d" "\t%s,%d,%d\t%s,%d,%d", p->char_id, p->account_id, p->char_num, p->name, // - p->class, p->base_level, p->job_level, p->base_exp, p->job_exp, p->zeny, p->hp, p->max_hp, p->sp, p->max_sp, p->str, p->agi, p->vit, p->int_, p->dex, p->luk, p->status_point, p->skill_point, p->option, p->karma, p->manner, // - p->party_id, p->guild_id, p->pet_id, p->hair, p->hair_color, p->clothes_color, p->weapon, p->shield, p->head_top, p->head_mid, p->head_bottom, p->last_point.map, p->last_point.x, p->last_point.y, // - p->save_point.map, p->save_point.x, p->save_point.y); - strcat (str, "\t"); - for (i = 0; i < 3; i++) - if (p->memo_point[i].map[0]) - { - sprintf (str + strlen (str), "%s,%d,%d", p->memo_point[i].map, - p->memo_point[i].x, p->memo_point[i].y); - } - strcat (str, "\t"); - for (i = 0; i < MAX_INVENTORY; i++) - if (p->inventory[i].nameid) - { - sprintf (str + strlen (str), "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ", - p->inventory[i].id, p->inventory[i].nameid, - p->inventory[i].amount, p->inventory[i].equip, - p->inventory[i].identify, p->inventory[i].refine, - p->inventory[i].attribute, p->inventory[i].card[0], - p->inventory[i].card[1], p->inventory[i].card[2], - p->inventory[i].card[3]); - } - strcat (str, "\t"); - for (i = 0; i < MAX_CART; i++) - if (p->cart[i].nameid) - { - sprintf (str + strlen (str), "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ", - p->cart[i].id, p->cart[i].nameid, p->cart[i].amount, - p->cart[i].equip, p->cart[i].identify, p->cart[i].refine, - p->cart[i].attribute, p->cart[i].card[0], - p->cart[i].card[1], p->cart[i].card[2], - p->cart[i].card[3]); - } - strcat (str, "\t"); - for (i = 0; i < MAX_SKILL; i++) - if (p->skill[i].id) - { - sprintf (str + strlen (str), "%d,%d ", p->skill[i].id, - p->skill[i].lv); - } - strcat (str, "\t"); - for (i = 0; i < p->global_reg_num; i++) - sprintf (str + strlen (str), "%s,%d ", p->global_reg[i].str, - p->global_reg[i].value); - strcat (str, "\t"); - return 0; -} - -int mmo_char_fromstr (char *str, struct mmo_charstatus *p) -{ - int tmp_int[256]; - int set, next, len, i; - - set = sscanf (str, "%d\t%d,%d\t%[^\t]\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d\t%d,%d,%d,%d,%d,%d\t%d,%d" "\t%d,%d,%d\t%d,%d\t%d,%d,%d\t%d,%d,%d,%d,%d" "\t%[^,],%d,%d\t%[^,],%d,%d%n", &tmp_int[0], &tmp_int[1], &tmp_int[2], p->name, // - &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6], &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], &tmp_int[11], &tmp_int[12], &tmp_int[13], &tmp_int[14], &tmp_int[15], &tmp_int[16], &tmp_int[17], &tmp_int[18], &tmp_int[19], &tmp_int[20], &tmp_int[21], &tmp_int[22], &tmp_int[23], // - &tmp_int[24], &tmp_int[25], &tmp_int[26], &tmp_int[27], &tmp_int[28], &tmp_int[29], &tmp_int[30], &tmp_int[31], &tmp_int[32], &tmp_int[33], p->last_point.map, &tmp_int[34], &tmp_int[35], // - p->save_point.map, &tmp_int[36], &tmp_int[37], &next); - p->char_id = tmp_int[0]; - p->account_id = tmp_int[1]; - p->char_num = tmp_int[2]; - p->class = tmp_int[3]; - p->base_level = tmp_int[4]; - p->job_level = tmp_int[5]; - p->base_exp = tmp_int[6]; - p->job_exp = tmp_int[7]; - p->zeny = tmp_int[8]; - p->hp = tmp_int[9]; - p->max_hp = tmp_int[10]; - p->sp = tmp_int[11]; - p->max_sp = tmp_int[12]; - p->str = tmp_int[13]; - p->agi = tmp_int[14]; - p->vit = tmp_int[15]; - p->int_ = tmp_int[16]; - p->dex = tmp_int[17]; - p->luk = tmp_int[18]; - p->status_point = tmp_int[19]; - p->skill_point = tmp_int[20]; - p->option = tmp_int[21]; - p->karma = tmp_int[22]; - p->manner = tmp_int[23]; - p->party_id = tmp_int[24]; - p->guild_id = tmp_int[25]; - p->pet_id = 0; - p->hair = tmp_int[26]; - p->hair_color = tmp_int[27]; - p->clothes_color = tmp_int[28]; - p->weapon = tmp_int[29]; - p->shield = tmp_int[30]; - p->head_top = tmp_int[31]; - p->head_mid = tmp_int[32]; - p->head_bottom = tmp_int[33]; - p->last_point.x = tmp_int[34]; - p->last_point.y = tmp_int[35]; - p->save_point.x = tmp_int[36]; - p->save_point.y = tmp_int[37]; - if (set != 41) - return 0; - if (str[next] == '\n' || str[next] == '\r') - return 1; // 新規データ - next++; - for (i = 0; str[next] && str[next] != '\t'; i++) - { - set = - sscanf (str + next, "%[^,],%d,%d%n", p->memo_point[i].map, - &tmp_int[0], &tmp_int[1], &len); - if (set != 3) - return 0; - p->memo_point[i].x = tmp_int[0]; - p->memo_point[i].y = tmp_int[1]; - next += len; - if (str[next] == ' ') - next++; - } - next++; - for (i = 0; str[next] && str[next] != '\t'; i++) - { - set = sscanf (str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n", - &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3], - &tmp_int[4], &tmp_int[5], &tmp_int[6], - &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], - &len); - if (set != 11) - return 0; - p->inventory[i].id = tmp_int[0]; - p->inventory[i].nameid = tmp_int[1]; - p->inventory[i].amount = tmp_int[2]; - p->inventory[i].equip = tmp_int[3]; - p->inventory[i].identify = tmp_int[4]; - p->inventory[i].refine = tmp_int[5]; - p->inventory[i].attribute = tmp_int[6]; - p->inventory[i].card[0] = tmp_int[7]; - p->inventory[i].card[1] = tmp_int[8]; - p->inventory[i].card[2] = tmp_int[9]; - p->inventory[i].card[3] = tmp_int[10]; - next += len; - if (str[next] == ' ') - next++; - } - next++; - for (i = 0; str[next] && str[next] != '\t'; i++) - { - set = sscanf (str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n", - &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3], - &tmp_int[4], &tmp_int[5], &tmp_int[6], - &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], - &len); - if (set != 11) - return 0; - p->cart[i].id = tmp_int[0]; - p->cart[i].nameid = tmp_int[1]; - p->cart[i].amount = tmp_int[2]; - p->cart[i].equip = tmp_int[3]; - p->cart[i].identify = tmp_int[4]; - p->cart[i].refine = tmp_int[5]; - p->cart[i].attribute = tmp_int[6]; - p->cart[i].card[0] = tmp_int[7]; - p->cart[i].card[1] = tmp_int[8]; - p->cart[i].card[2] = tmp_int[9]; - p->cart[i].card[3] = tmp_int[10]; - next += len; - if (str[next] == ' ') - next++; - } - next++; - for (i = 0; str[next] && str[next] != '\t'; i++) - { - set = sscanf (str + next, "%d,%d%n", &tmp_int[0], &tmp_int[1], &len); - if (set != 2) - return 0; - p->skill[tmp_int[0]].id = tmp_int[0]; - p->skill[tmp_int[0]].lv = tmp_int[1]; - next += len; - if (str[next] == ' ') - next++; - } - next++; - for (i = 0; - str[next] && str[next] != '\t' && str[next] != '\n' - && str[next] != '\r'; i++) - { //global_reg実装以前のathena.txt互換のため一応'\n'チェック - set = sscanf (str + next, "%[^,],%d%n", - p->global_reg[i].str, &p->global_reg[i].value, &len); - if (set != 2) - return 0; - next += len; - if (str[next] == ' ') - next++; - } - p->global_reg_num = i; - return 1; -} - -int mmo_char_convert (char *fname1, char *fname2) -{ - char line[65536]; - int ret; - struct mmo_charstatus char_dat; - FILE *ifp, *ofp; - - ifp = fopen_ (fname1, "r"); - ofp = fopen_ (fname2, "w"); - if (ifp == NULL) - { - printf ("file not found %s\n", fname1); - return 0; - } - if (ofp == NULL) - { - printf ("file open error %s\n", fname2); - return 0; - } - while (fgets (line, 65535, ifp)) - { - memset (&char_dat, 0, sizeof (struct mmo_charstatus)); - ret = mmo_char_fromstr (line, &char_dat); - if (ret) - { - mmo_char_tostr (line, &char_dat); - fprintf (ofp, "%s\n", line); - } - } - fcloseall (); - return 0; -} - -int main (int argc, char *argv[]) -{ - if (argc < 3) - { - printf ("Usage: convert \n"); - exit (0); - } - mmo_char_convert (argv[1], argv[2]); - - return 0; -} diff --git a/src/tool/convert.cpp b/src/tool/convert.cpp new file mode 100644 index 0000000..e256fc9 --- /dev/null +++ b/src/tool/convert.cpp @@ -0,0 +1,302 @@ +#include +#include + +#define MAX_INVENTORY 100 +#define MAX_CART 100 +#define MAX_SKILL 350 +#define GLOBAL_REG_NUM 16 + +struct item +{ + int id; + short nameid; + short amount; + short equip; + char identify; + char refine; + char attribute; + short card[4]; +}; +struct point +{ + char map[16]; + short x, y; +}; +struct skill +{ + unsigned short id, lv, flag; +}; +struct global_reg +{ + char str[16]; + int value; +}; + +struct mmo_charstatus +{ + int char_id; + int account_id; + int base_exp, job_exp, zeny; + + short class; + short status_point, skill_point; + short hp, max_hp, sp, max_sp; + short option, karma, manner; + short hair, hair_color, clothes_color; + int party_id, guild_id, pet_id; + + short weapon, shield; + short head_top, head_mid, head_bottom; + + char name[24]; + unsigned char base_level, job_level; + unsigned char str, agi, vit, int_, dex, luk, char_num, sex; + + struct point last_point, save_point, memo_point[3]; + struct item inventory[MAX_INVENTORY], cart[MAX_CART]; + struct skill skill[MAX_SKILL]; + int global_reg_num; + struct global_reg global_reg[GLOBAL_REG_NUM]; +}; + +int mmo_char_tostr (char *str, struct mmo_charstatus *p) +{ + int i; + sprintf (str, "%d\t%d,%d\t%s\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d\t%d,%d,%d,%d,%d,%d\t%d,%d" "\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d,%d" "\t%s,%d,%d\t%s,%d,%d", p->char_id, p->account_id, p->char_num, p->name, // + p->class, p->base_level, p->job_level, p->base_exp, p->job_exp, p->zeny, p->hp, p->max_hp, p->sp, p->max_sp, p->str, p->agi, p->vit, p->int_, p->dex, p->luk, p->status_point, p->skill_point, p->option, p->karma, p->manner, // + p->party_id, p->guild_id, p->pet_id, p->hair, p->hair_color, p->clothes_color, p->weapon, p->shield, p->head_top, p->head_mid, p->head_bottom, p->last_point.map, p->last_point.x, p->last_point.y, // + p->save_point.map, p->save_point.x, p->save_point.y); + strcat (str, "\t"); + for (i = 0; i < 3; i++) + if (p->memo_point[i].map[0]) + { + sprintf (str + strlen (str), "%s,%d,%d", p->memo_point[i].map, + p->memo_point[i].x, p->memo_point[i].y); + } + strcat (str, "\t"); + for (i = 0; i < MAX_INVENTORY; i++) + if (p->inventory[i].nameid) + { + sprintf (str + strlen (str), "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ", + p->inventory[i].id, p->inventory[i].nameid, + p->inventory[i].amount, p->inventory[i].equip, + p->inventory[i].identify, p->inventory[i].refine, + p->inventory[i].attribute, p->inventory[i].card[0], + p->inventory[i].card[1], p->inventory[i].card[2], + p->inventory[i].card[3]); + } + strcat (str, "\t"); + for (i = 0; i < MAX_CART; i++) + if (p->cart[i].nameid) + { + sprintf (str + strlen (str), "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ", + p->cart[i].id, p->cart[i].nameid, p->cart[i].amount, + p->cart[i].equip, p->cart[i].identify, p->cart[i].refine, + p->cart[i].attribute, p->cart[i].card[0], + p->cart[i].card[1], p->cart[i].card[2], + p->cart[i].card[3]); + } + strcat (str, "\t"); + for (i = 0; i < MAX_SKILL; i++) + if (p->skill[i].id) + { + sprintf (str + strlen (str), "%d,%d ", p->skill[i].id, + p->skill[i].lv); + } + strcat (str, "\t"); + for (i = 0; i < p->global_reg_num; i++) + sprintf (str + strlen (str), "%s,%d ", p->global_reg[i].str, + p->global_reg[i].value); + strcat (str, "\t"); + return 0; +} + +int mmo_char_fromstr (char *str, struct mmo_charstatus *p) +{ + int tmp_int[256]; + int set, next, len, i; + + set = sscanf (str, "%d\t%d,%d\t%[^\t]\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d\t%d,%d,%d,%d,%d,%d\t%d,%d" "\t%d,%d,%d\t%d,%d\t%d,%d,%d\t%d,%d,%d,%d,%d" "\t%[^,],%d,%d\t%[^,],%d,%d%n", &tmp_int[0], &tmp_int[1], &tmp_int[2], p->name, // + &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6], &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], &tmp_int[11], &tmp_int[12], &tmp_int[13], &tmp_int[14], &tmp_int[15], &tmp_int[16], &tmp_int[17], &tmp_int[18], &tmp_int[19], &tmp_int[20], &tmp_int[21], &tmp_int[22], &tmp_int[23], // + &tmp_int[24], &tmp_int[25], &tmp_int[26], &tmp_int[27], &tmp_int[28], &tmp_int[29], &tmp_int[30], &tmp_int[31], &tmp_int[32], &tmp_int[33], p->last_point.map, &tmp_int[34], &tmp_int[35], // + p->save_point.map, &tmp_int[36], &tmp_int[37], &next); + p->char_id = tmp_int[0]; + p->account_id = tmp_int[1]; + p->char_num = tmp_int[2]; + p->class = tmp_int[3]; + p->base_level = tmp_int[4]; + p->job_level = tmp_int[5]; + p->base_exp = tmp_int[6]; + p->job_exp = tmp_int[7]; + p->zeny = tmp_int[8]; + p->hp = tmp_int[9]; + p->max_hp = tmp_int[10]; + p->sp = tmp_int[11]; + p->max_sp = tmp_int[12]; + p->str = tmp_int[13]; + p->agi = tmp_int[14]; + p->vit = tmp_int[15]; + p->int_ = tmp_int[16]; + p->dex = tmp_int[17]; + p->luk = tmp_int[18]; + p->status_point = tmp_int[19]; + p->skill_point = tmp_int[20]; + p->option = tmp_int[21]; + p->karma = tmp_int[22]; + p->manner = tmp_int[23]; + p->party_id = tmp_int[24]; + p->guild_id = tmp_int[25]; + p->pet_id = 0; + p->hair = tmp_int[26]; + p->hair_color = tmp_int[27]; + p->clothes_color = tmp_int[28]; + p->weapon = tmp_int[29]; + p->shield = tmp_int[30]; + p->head_top = tmp_int[31]; + p->head_mid = tmp_int[32]; + p->head_bottom = tmp_int[33]; + p->last_point.x = tmp_int[34]; + p->last_point.y = tmp_int[35]; + p->save_point.x = tmp_int[36]; + p->save_point.y = tmp_int[37]; + if (set != 41) + return 0; + if (str[next] == '\n' || str[next] == '\r') + return 1; // 新規データ + next++; + for (i = 0; str[next] && str[next] != '\t'; i++) + { + set = + sscanf (str + next, "%[^,],%d,%d%n", p->memo_point[i].map, + &tmp_int[0], &tmp_int[1], &len); + if (set != 3) + return 0; + p->memo_point[i].x = tmp_int[0]; + p->memo_point[i].y = tmp_int[1]; + next += len; + if (str[next] == ' ') + next++; + } + next++; + for (i = 0; str[next] && str[next] != '\t'; i++) + { + set = sscanf (str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n", + &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3], + &tmp_int[4], &tmp_int[5], &tmp_int[6], + &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], + &len); + if (set != 11) + return 0; + p->inventory[i].id = tmp_int[0]; + p->inventory[i].nameid = tmp_int[1]; + p->inventory[i].amount = tmp_int[2]; + p->inventory[i].equip = tmp_int[3]; + p->inventory[i].identify = tmp_int[4]; + p->inventory[i].refine = tmp_int[5]; + p->inventory[i].attribute = tmp_int[6]; + p->inventory[i].card[0] = tmp_int[7]; + p->inventory[i].card[1] = tmp_int[8]; + p->inventory[i].card[2] = tmp_int[9]; + p->inventory[i].card[3] = tmp_int[10]; + next += len; + if (str[next] == ' ') + next++; + } + next++; + for (i = 0; str[next] && str[next] != '\t'; i++) + { + set = sscanf (str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n", + &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3], + &tmp_int[4], &tmp_int[5], &tmp_int[6], + &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], + &len); + if (set != 11) + return 0; + p->cart[i].id = tmp_int[0]; + p->cart[i].nameid = tmp_int[1]; + p->cart[i].amount = tmp_int[2]; + p->cart[i].equip = tmp_int[3]; + p->cart[i].identify = tmp_int[4]; + p->cart[i].refine = tmp_int[5]; + p->cart[i].attribute = tmp_int[6]; + p->cart[i].card[0] = tmp_int[7]; + p->cart[i].card[1] = tmp_int[8]; + p->cart[i].card[2] = tmp_int[9]; + p->cart[i].card[3] = tmp_int[10]; + next += len; + if (str[next] == ' ') + next++; + } + next++; + for (i = 0; str[next] && str[next] != '\t'; i++) + { + set = sscanf (str + next, "%d,%d%n", &tmp_int[0], &tmp_int[1], &len); + if (set != 2) + return 0; + p->skill[tmp_int[0]].id = tmp_int[0]; + p->skill[tmp_int[0]].lv = tmp_int[1]; + next += len; + if (str[next] == ' ') + next++; + } + next++; + for (i = 0; + str[next] && str[next] != '\t' && str[next] != '\n' + && str[next] != '\r'; i++) + { //global_reg実装以前のathena.txt互換のため一応'\n'チェック + set = sscanf (str + next, "%[^,],%d%n", + p->global_reg[i].str, &p->global_reg[i].value, &len); + if (set != 2) + return 0; + next += len; + if (str[next] == ' ') + next++; + } + p->global_reg_num = i; + return 1; +} + +int mmo_char_convert (char *fname1, char *fname2) +{ + char line[65536]; + int ret; + struct mmo_charstatus char_dat; + FILE *ifp, *ofp; + + ifp = fopen_ (fname1, "r"); + ofp = fopen_ (fname2, "w"); + if (ifp == NULL) + { + printf ("file not found %s\n", fname1); + return 0; + } + if (ofp == NULL) + { + printf ("file open error %s\n", fname2); + return 0; + } + while (fgets (line, 65535, ifp)) + { + memset (&char_dat, 0, sizeof (struct mmo_charstatus)); + ret = mmo_char_fromstr (line, &char_dat); + if (ret) + { + mmo_char_tostr (line, &char_dat); + fprintf (ofp, "%s\n", line); + } + } + fcloseall (); + return 0; +} + +int main (int argc, char *argv[]) +{ + if (argc < 3) + { + printf ("Usage: convert \n"); + exit (0); + } + mmo_char_convert (argv[1], argv[2]); + + return 0; +} diff --git a/src/tool/eathena-monitor.c b/src/tool/eathena-monitor.c deleted file mode 100644 index 1b1abd5..0000000 --- a/src/tool/eathena-monitor.c +++ /dev/null @@ -1,223 +0,0 @@ -/** - * Name: eAthena processes monitor - * Original Author: Bartosz Waszak - * Rewrite Author: Ben Longbons - * License: GPL - * Compilation: - * gcc -o eathena-monitor eathena-monitor.c - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#define HOME getenv("HOME") -#define LOGIN_SERVER "./login-server" -#define MAP_SERVER "./map-server" -#define CHAR_SERVER "./char-server" -#define CONFIG "conf/eathena-monitor.conf" -#define LOGFILE "log/eathena-monitor.log" - - -#define SKIP_BLANK(ptr) ptr += skip_blank(ptr) -static inline size_t skip_blank(const char* ptr) { - size_t i = 0; - while ( - (ptr[i] == ' ') || - (ptr[i] == '\b') || - (ptr[i] == '\n') || - (ptr[i] == '\r') - ) ptr++; - return i; -} - -#define GOTO_EQL(ptr) ptr += goto_eql(ptr) -static inline size_t goto_eql(const char* ptr) { - size_t i = 0; - while ( - (ptr[i] != '\0') && - (ptr[i] != '=') && - (ptr[i] != '\n') && - (ptr[i] != '\r') - ) ptr++; - return i; -} - -#define GOTO_EOL(ptr) ptr += goto_newline(ptr) -static inline size_t goto_newline(const char* ptr) { - size_t i = 0; - while ( - (ptr[i] != '\0') && - (ptr[i] != '\n') && - (ptr[i] != '\r') - ) ptr++; - return i; -} - -// initialiized to $HOME/tmwserver -const char *workdir; -//the rest are relative to workdir -const char *login_server = LOGIN_SERVER; -const char *map_server = MAP_SERVER; -const char *char_server = CHAR_SERVER; -const char *logfile = LOGFILE; -// this variable is hard-coded, but the command-line is checked first -const char *config = CONFIG; - -pid_t pid_login, pid_map, pid_char; - -const char* make_path (const char* base, const char* path) { - size_t base_len = strlen(base); - size_t path_len = strlen(path); - char* out = (char *)malloc(base_len + 1 + path_len + 1); - memcpy(out, base, base_len); - out[base_len] = '/'; - memcpy(out + base_len + 1, path, path_len); - out[base_len + 1 + path_len] = '\0'; - return out; -} - -void parse_option (char *name, char *value) { - if (!strcasecmp(name, "login_server")) { - login_server = strdup(value); - } else if (!strcasecmp(name, "map_server")) { - map_server = strdup(value); - } else if (!strcasecmp(name, "char_server")) { - char_server = strdup(value); - } else if (!strcasecmp(name, "workdir")) { - workdir = strdup(value); - } else if (!strcasecmp(name, "logfile")) { - logfile = strdup(value); - } else { - fprintf(stderr, "WARNING: ingnoring invalid option '%s' = '%s'\n", name, value); - } -} - -void read_config(const char *filename) { - FILE *input; - char string[1000]; - - if (!(input = fopen(filename,"r")) && !(input = fopen (config, "r"))) { - perror("Unable to load config file"); - return; - } - - while (1) { - if (fgets (string, sizeof (string) - 1, input) == NULL) - break; - char *str = string, *name, *value; - SKIP_BLANK(str); - string[sizeof (string) - 1] = '\0'; - if (*str == '#') - continue; - if (*str == '\0') - continue; - name = str; - - GOTO_EQL (str); - - if (*str != '=') { - continue; - } - - *str++ = '\0'; - SKIP_BLANK(str); - value = str; - GOTO_EOL(str); - *str = '\0'; - parse_option(name, value); - } - - fclose (input); -} - -pid_t start_process(const char *exec) { - const char *args[2] = {exec, NULL}; - pid_t pid = fork(); - if (pid == -1) { - fprintf(stderr, "Failed to fork"); - return 0; - } - if (pid == 0) { - execv(exec, (char**)args); - perror("Failed to exec"); - kill(getppid(), SIGABRT); - exit(1); - } - return pid; -} - -// Kill all children with the same signal we got, then ourself. -void stop_process(int sig) { - if (pid_map) kill(pid_map, sig); - if (pid_login) kill(pid_login, sig); - if (pid_char) kill(pid_char, sig); - signal(sig, SIG_DFL); - raise(sig); -} - -int main(int argc, char *argv[]) { - // These are all the signals we are likely to get - // The shell handles stop/cont - signal(SIGTERM, stop_process); - signal(SIGINT, stop_process); - signal(SIGQUIT, stop_process); - signal(SIGABRT, stop_process); - - workdir = make_path(HOME, "tmwserver"); - - read_config(argc>1 ? argv[1] : NULL); - - if (chdir(workdir) < 0) perror("Failed to change directory"), exit(1); - - printf ("Starting:\n"); - printf ("* workdir: %s\n", workdir); - printf ("* login_server: %s\n", login_server); - printf ("* map_server: %s\n", map_server); - printf ("* char_server: %s\n", char_server); - { - //make sure all possible file descriptors are free for use by the servers - //if there are file descriptors higher than the max open from before the limit dropped, that's not our problem - int fd = sysconf(_SC_OPEN_MAX); - while (--fd > 2) - if (close(fd) == 0) - fprintf(stderr, "close fd %d\n", fd); - fd = open("/dev/null", O_RDWR); - if (fd < 0) perror("open /dev/null"), exit(1); - dup2(fd, 0); - dup2(fd, 1); - close(fd); - } - while (1) { - // write stuff to stderr - time_t t = time(NULL); - struct tm *tmp = localtime(&t); - char timestamp[256]; - strftime(timestamp, sizeof(timestamp), "%F %T", tmp); - - if (!pid_login) { - pid_login = start_process(login_server); - fprintf (stderr, "[%s] forked login server: %lu\n", timestamp, (unsigned long)pid_login); - } - if (!pid_char) { - pid_char = start_process(char_server); - fprintf (stderr, "[%s] forked char server: %lu\n", timestamp, (unsigned long)pid_char); - } - if (!pid_map) { - pid_map = start_process(map_server); - fprintf (stderr, "[%s] forked map server: %lu\n", timestamp, (unsigned long)pid_map); - } - pid_t dead = wait(NULL); - if (dead < 0) perror("Failed to wait for child"), exit(1); - if (pid_login == dead) pid_login = 0; - if (pid_char == dead) pid_char = 0; - if (pid_map == dead) pid_map = 0; - } -} diff --git a/src/tool/eathena-monitor.cpp b/src/tool/eathena-monitor.cpp new file mode 100644 index 0000000..1b1abd5 --- /dev/null +++ b/src/tool/eathena-monitor.cpp @@ -0,0 +1,223 @@ +/** + * Name: eAthena processes monitor + * Original Author: Bartosz Waszak + * Rewrite Author: Ben Longbons + * License: GPL + * Compilation: + * gcc -o eathena-monitor eathena-monitor.c + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#define HOME getenv("HOME") +#define LOGIN_SERVER "./login-server" +#define MAP_SERVER "./map-server" +#define CHAR_SERVER "./char-server" +#define CONFIG "conf/eathena-monitor.conf" +#define LOGFILE "log/eathena-monitor.log" + + +#define SKIP_BLANK(ptr) ptr += skip_blank(ptr) +static inline size_t skip_blank(const char* ptr) { + size_t i = 0; + while ( + (ptr[i] == ' ') || + (ptr[i] == '\b') || + (ptr[i] == '\n') || + (ptr[i] == '\r') + ) ptr++; + return i; +} + +#define GOTO_EQL(ptr) ptr += goto_eql(ptr) +static inline size_t goto_eql(const char* ptr) { + size_t i = 0; + while ( + (ptr[i] != '\0') && + (ptr[i] != '=') && + (ptr[i] != '\n') && + (ptr[i] != '\r') + ) ptr++; + return i; +} + +#define GOTO_EOL(ptr) ptr += goto_newline(ptr) +static inline size_t goto_newline(const char* ptr) { + size_t i = 0; + while ( + (ptr[i] != '\0') && + (ptr[i] != '\n') && + (ptr[i] != '\r') + ) ptr++; + return i; +} + +// initialiized to $HOME/tmwserver +const char *workdir; +//the rest are relative to workdir +const char *login_server = LOGIN_SERVER; +const char *map_server = MAP_SERVER; +const char *char_server = CHAR_SERVER; +const char *logfile = LOGFILE; +// this variable is hard-coded, but the command-line is checked first +const char *config = CONFIG; + +pid_t pid_login, pid_map, pid_char; + +const char* make_path (const char* base, const char* path) { + size_t base_len = strlen(base); + size_t path_len = strlen(path); + char* out = (char *)malloc(base_len + 1 + path_len + 1); + memcpy(out, base, base_len); + out[base_len] = '/'; + memcpy(out + base_len + 1, path, path_len); + out[base_len + 1 + path_len] = '\0'; + return out; +} + +void parse_option (char *name, char *value) { + if (!strcasecmp(name, "login_server")) { + login_server = strdup(value); + } else if (!strcasecmp(name, "map_server")) { + map_server = strdup(value); + } else if (!strcasecmp(name, "char_server")) { + char_server = strdup(value); + } else if (!strcasecmp(name, "workdir")) { + workdir = strdup(value); + } else if (!strcasecmp(name, "logfile")) { + logfile = strdup(value); + } else { + fprintf(stderr, "WARNING: ingnoring invalid option '%s' = '%s'\n", name, value); + } +} + +void read_config(const char *filename) { + FILE *input; + char string[1000]; + + if (!(input = fopen(filename,"r")) && !(input = fopen (config, "r"))) { + perror("Unable to load config file"); + return; + } + + while (1) { + if (fgets (string, sizeof (string) - 1, input) == NULL) + break; + char *str = string, *name, *value; + SKIP_BLANK(str); + string[sizeof (string) - 1] = '\0'; + if (*str == '#') + continue; + if (*str == '\0') + continue; + name = str; + + GOTO_EQL (str); + + if (*str != '=') { + continue; + } + + *str++ = '\0'; + SKIP_BLANK(str); + value = str; + GOTO_EOL(str); + *str = '\0'; + parse_option(name, value); + } + + fclose (input); +} + +pid_t start_process(const char *exec) { + const char *args[2] = {exec, NULL}; + pid_t pid = fork(); + if (pid == -1) { + fprintf(stderr, "Failed to fork"); + return 0; + } + if (pid == 0) { + execv(exec, (char**)args); + perror("Failed to exec"); + kill(getppid(), SIGABRT); + exit(1); + } + return pid; +} + +// Kill all children with the same signal we got, then ourself. +void stop_process(int sig) { + if (pid_map) kill(pid_map, sig); + if (pid_login) kill(pid_login, sig); + if (pid_char) kill(pid_char, sig); + signal(sig, SIG_DFL); + raise(sig); +} + +int main(int argc, char *argv[]) { + // These are all the signals we are likely to get + // The shell handles stop/cont + signal(SIGTERM, stop_process); + signal(SIGINT, stop_process); + signal(SIGQUIT, stop_process); + signal(SIGABRT, stop_process); + + workdir = make_path(HOME, "tmwserver"); + + read_config(argc>1 ? argv[1] : NULL); + + if (chdir(workdir) < 0) perror("Failed to change directory"), exit(1); + + printf ("Starting:\n"); + printf ("* workdir: %s\n", workdir); + printf ("* login_server: %s\n", login_server); + printf ("* map_server: %s\n", map_server); + printf ("* char_server: %s\n", char_server); + { + //make sure all possible file descriptors are free for use by the servers + //if there are file descriptors higher than the max open from before the limit dropped, that's not our problem + int fd = sysconf(_SC_OPEN_MAX); + while (--fd > 2) + if (close(fd) == 0) + fprintf(stderr, "close fd %d\n", fd); + fd = open("/dev/null", O_RDWR); + if (fd < 0) perror("open /dev/null"), exit(1); + dup2(fd, 0); + dup2(fd, 1); + close(fd); + } + while (1) { + // write stuff to stderr + time_t t = time(NULL); + struct tm *tmp = localtime(&t); + char timestamp[256]; + strftime(timestamp, sizeof(timestamp), "%F %T", tmp); + + if (!pid_login) { + pid_login = start_process(login_server); + fprintf (stderr, "[%s] forked login server: %lu\n", timestamp, (unsigned long)pid_login); + } + if (!pid_char) { + pid_char = start_process(char_server); + fprintf (stderr, "[%s] forked char server: %lu\n", timestamp, (unsigned long)pid_char); + } + if (!pid_map) { + pid_map = start_process(map_server); + fprintf (stderr, "[%s] forked map server: %lu\n", timestamp, (unsigned long)pid_map); + } + pid_t dead = wait(NULL); + if (dead < 0) perror("Failed to wait for child"), exit(1); + if (pid_login == dead) pid_login = 0; + if (pid_char == dead) pid_char = 0; + if (pid_map == dead) pid_map = 0; + } +} diff --git a/src/tool/itemfrob.c b/src/tool/itemfrob.c deleted file mode 100644 index 4651452..0000000 --- a/src/tool/itemfrob.c +++ /dev/null @@ -1,130 +0,0 @@ -// Compile with -// gcc -m32 -I src/char -I src/common charfrob.c -o charfrob src/common/timer.o src/common/malloc.o src/common/socket.o src/common/lock.o src/common/db.o src/char/int_pet.o src/char/int_storage.o src/char/inter.o src/char/int_party.o src/char/int_guild.o - -#include -#include -#include "../common/mmo.h" -// Yes, this is intentional -#include "../char/char.c" - -// Well, this is not terribly elegant, but I don't have that much time. -#define MAX_ITEM_ID 65535 -int inv_translate[MAX_ITEM_ID]; - -void transform_char (struct mmo_charstatus *p) -{ - int k; - for (k = 0; k < MAX_INVENTORY; k++) - p->inventory[k].nameid = inv_translate[p->inventory[k].nameid]; -} - -int mmo_char_convert () -{ - char line[965536]; - int ret; - struct mmo_charstatus char_dat; - FILE *ifp, *ofp; - - ifp = stdin; - ofp = stdout; - while (fgets (line, 65535, ifp)) - { - memset (&char_dat, 0, sizeof (struct mmo_charstatus)); - ret = mmo_char_fromstr (line, &char_dat); - if (ret) - { - transform_char (&char_dat); - mmo_char_tostr (line, &char_dat); - fprintf (ofp, "%s\n", line); - } - } - return 0; -} - -#define PARSE_MODE_NEXTNUM 0 -#define PARSE_MODE_RANGE 1 - -int init (char *source, char *dest) -{ - int i; - char *end_of_num; - int dest_nr = strtol (dest, &end_of_num, 0); - int range_start; - int mode = PARSE_MODE_NEXTNUM; - - if (*end_of_num) - { - fprintf (stderr, "Invalid inventory ID: `%s'\n", dest); - return 1; - } - - /* init */ - for (i = 0; i < MAX_ITEM_ID; i++) - inv_translate[i] = i; - - while (*source) - { - int nr = strtol (source, &end_of_num, 0); - char sep; - - if (end_of_num == source) - { - fprintf (stderr, "Invalid source range description: `%s'\n", - source); - return 1; - } - - switch (mode) - { - case PARSE_MODE_NEXTNUM: - inv_translate[nr] = dest_nr; - break; - case PARSE_MODE_RANGE: - for (i = range_start; i <= nr; i++) - inv_translate[i] = dest_nr; - break; - default: - fprintf (stderr, "Internal error at %d\n", __LINE__); - return 1; - }; - - sep = *end_of_num++; - - switch (sep) - { - case '-': - range_start = nr; - mode = PARSE_MODE_RANGE; - break; - case ',': - mode = PARSE_MODE_NEXTNUM; - break; - case 0: - return 0; - default: - fprintf (stderr, "Invalid token in range spec: `%c'\n", sep); - return 1; - } - - source = end_of_num; - } - return 0; -} - -int main (int argc, char *argv[]) -{ - if (argc < 3) - { - printf - ("Usage: %s \n", - argv[0]); - printf ("e.g., %s 501-555 701\n", argv[0]); - exit (0); - } - if (init (argv[1], argv[2])) - return 1; - - mmo_char_convert (); - - return 0; -} diff --git a/src/tool/itemfrob.cpp b/src/tool/itemfrob.cpp new file mode 100644 index 0000000..81638eb --- /dev/null +++ b/src/tool/itemfrob.cpp @@ -0,0 +1,130 @@ +// Compile with +// gcc -m32 -I src/char -I src/common charfrob.c -o charfrob src/common/timer.o src/common/malloc.o src/common/socket.o src/common/lock.o src/common/db.o src/char/int_pet.o src/char/int_storage.o src/char/inter.o src/char/int_party.o src/char/int_guild.o + +#include +#include +#include "../common/mmo.hpp" +// Yes, this is intentional +#include "../char/char.cpp" + +// Well, this is not terribly elegant, but I don't have that much time. +#define MAX_ITEM_ID 65535 +int inv_translate[MAX_ITEM_ID]; + +void transform_char (struct mmo_charstatus *p) +{ + int k; + for (k = 0; k < MAX_INVENTORY; k++) + p->inventory[k].nameid = inv_translate[p->inventory[k].nameid]; +} + +int mmo_char_convert () +{ + char line[965536]; + int ret; + struct mmo_charstatus char_dat; + FILE *ifp, *ofp; + + ifp = stdin; + ofp = stdout; + while (fgets (line, 65535, ifp)) + { + memset (&char_dat, 0, sizeof (struct mmo_charstatus)); + ret = mmo_char_fromstr (line, &char_dat); + if (ret) + { + transform_char (&char_dat); + mmo_char_tostr (line, &char_dat); + fprintf (ofp, "%s\n", line); + } + } + return 0; +} + +#define PARSE_MODE_NEXTNUM 0 +#define PARSE_MODE_RANGE 1 + +int init (char *source, char *dest) +{ + int i; + char *end_of_num; + int dest_nr = strtol (dest, &end_of_num, 0); + int range_start; + int mode = PARSE_MODE_NEXTNUM; + + if (*end_of_num) + { + fprintf (stderr, "Invalid inventory ID: `%s'\n", dest); + return 1; + } + + /* init */ + for (i = 0; i < MAX_ITEM_ID; i++) + inv_translate[i] = i; + + while (*source) + { + int nr = strtol (source, &end_of_num, 0); + char sep; + + if (end_of_num == source) + { + fprintf (stderr, "Invalid source range description: `%s'\n", + source); + return 1; + } + + switch (mode) + { + case PARSE_MODE_NEXTNUM: + inv_translate[nr] = dest_nr; + break; + case PARSE_MODE_RANGE: + for (i = range_start; i <= nr; i++) + inv_translate[i] = dest_nr; + break; + default: + fprintf (stderr, "Internal error at %d\n", __LINE__); + return 1; + }; + + sep = *end_of_num++; + + switch (sep) + { + case '-': + range_start = nr; + mode = PARSE_MODE_RANGE; + break; + case ',': + mode = PARSE_MODE_NEXTNUM; + break; + case 0: + return 0; + default: + fprintf (stderr, "Invalid token in range spec: `%c'\n", sep); + return 1; + } + + source = end_of_num; + } + return 0; +} + +int main (int argc, char *argv[]) +{ + if (argc < 3) + { + printf + ("Usage: %s \n", + argv[0]); + printf ("e.g., %s 501-555 701\n", argv[0]); + exit (0); + } + if (init (argv[1], argv[2])) + return 1; + + mmo_char_convert (); + + return 0; +} diff --git a/src/tool/mapfrob.c b/src/tool/mapfrob.c deleted file mode 100644 index 9dc1a5b..0000000 --- a/src/tool/mapfrob.c +++ /dev/null @@ -1,129 +0,0 @@ -// Compile with -// gcc -m32 -I src/char -I src/common charfrob.c -o charfrob src/common/timer.o src/common/malloc.o src/common/socket.o src/common/lock.o src/common/db.o src/char/int_pet.o src/char/int_storage.o src/char/inter.o src/char/int_party.o src/char/int_guild.o - -#include -#include -#include "../common/mmo.h" -// Yes, this is intentional -#include "../char/char.c" - -// Well, this is not terribly elegant, but I don't have that much time. -#define MAX_MAP 1024 -#define MAP_NAME_SIZE 32 -int maps_nr = 0; -struct -{ - char old[MAP_NAME_SIZE], new[MAP_NAME_SIZE]; -} maps[MAX_MAP]; - -void transform_point (struct point *p) -{ - int k; - - if (!p->map[0]) - return; - - for (k = 0; k < maps_nr; k++) - if (!strcmp (p->map, maps[k].old)) - { - strcpy (p->map, maps[k].new); - return; - } - - fprintf (stderr, "Warning: untranslated map `%s'\n", p->map); -} - -void transform_char (struct mmo_charstatus *p) -{ - int i; - - transform_point (&p->last_point); - transform_point (&p->save_point); - - for (i = 0; i < 10; i++) - transform_point (&p->memo_point[i]); -} - -int mmo_char_convert () -{ - char line[965536]; - int ret; - struct mmo_charstatus char_dat; - FILE *ifp, *ofp; - - ifp = stdin; - ofp = stdout; - while (fgets (line, 65535, ifp)) - { - memset (&char_dat, 0, sizeof (struct mmo_charstatus)); - ret = mmo_char_fromstr (line, &char_dat); - if (ret) - { - transform_char (&char_dat); - mmo_char_tostr (line, &char_dat); - fprintf (ofp, "%s\n", line); - } - } - return 0; -} - -#define PARSE_MODE_NEXTNUM 0 -#define PARSE_MODE_RANGE 1 - -int init (int count, char **translates) -{ - int i; - char *suffix = ".gat"; - - for (i = 0; i < count; i++) - { - char *src = translates[i]; - char *dest = strchr (src, ':'); - - if (!dest) - { - fprintf (stderr, "Missing colon in: `%s'\n", src); - return 1; - } - - *dest++ = 0; - - if (strlen (src) + strlen (suffix) >= MAP_NAME_SIZE) - { - fprintf (stderr, "Map name prefix too long: `%s'\n", src); - return 1; - } - - if (strlen (dest) + strlen (suffix) >= MAP_NAME_SIZE) - { - fprintf (stderr, "Map name prefix too long: `%s'\n", dest); - return 1; - } - - strncpy (maps[maps_nr].old, src, MAP_NAME_SIZE); - strcat (maps[maps_nr].old, suffix); - strncpy (maps[maps_nr].new, dest, MAP_NAME_SIZE); - strcat (maps[maps_nr].new, suffix); - - ++maps_nr; - } - - return 0; -} - -int main (int argc, char *argv[]) -{ - if (argc < 2) - { - printf ("Usage: %s oldmap0:newmap0 oldmap1:newmap1 ...\n", argv[0]); - printf ("e.g., %s new_1-1:001-2 new_2-1:001-1\n", argv[0]); - puts ("The extension `.gat' is appended implicitly."); - exit (0); - } - if (init (argc - 1, argv + 1)) - return 1; - - mmo_char_convert (); - - return 0; -} diff --git a/src/tool/mapfrob.cpp b/src/tool/mapfrob.cpp new file mode 100644 index 0000000..8663ae0 --- /dev/null +++ b/src/tool/mapfrob.cpp @@ -0,0 +1,129 @@ +// Compile with +// gcc -m32 -I src/char -I src/common charfrob.c -o charfrob src/common/timer.o src/common/malloc.o src/common/socket.o src/common/lock.o src/common/db.o src/char/int_pet.o src/char/int_storage.o src/char/inter.o src/char/int_party.o src/char/int_guild.o + +#include +#include +#include "../common/mmo.hpp" +// Yes, this is intentional +#include "../char/char.cpp" + +// Well, this is not terribly elegant, but I don't have that much time. +#define MAX_MAP 1024 +#define MAP_NAME_SIZE 32 +int maps_nr = 0; +struct +{ + char old[MAP_NAME_SIZE], new[MAP_NAME_SIZE]; +} maps[MAX_MAP]; + +void transform_point (struct point *p) +{ + int k; + + if (!p->map[0]) + return; + + for (k = 0; k < maps_nr; k++) + if (!strcmp (p->map, maps[k].old)) + { + strcpy (p->map, maps[k].new); + return; + } + + fprintf (stderr, "Warning: untranslated map `%s'\n", p->map); +} + +void transform_char (struct mmo_charstatus *p) +{ + int i; + + transform_point (&p->last_point); + transform_point (&p->save_point); + + for (i = 0; i < 10; i++) + transform_point (&p->memo_point[i]); +} + +int mmo_char_convert () +{ + char line[965536]; + int ret; + struct mmo_charstatus char_dat; + FILE *ifp, *ofp; + + ifp = stdin; + ofp = stdout; + while (fgets (line, 65535, ifp)) + { + memset (&char_dat, 0, sizeof (struct mmo_charstatus)); + ret = mmo_char_fromstr (line, &char_dat); + if (ret) + { + transform_char (&char_dat); + mmo_char_tostr (line, &char_dat); + fprintf (ofp, "%s\n", line); + } + } + return 0; +} + +#define PARSE_MODE_NEXTNUM 0 +#define PARSE_MODE_RANGE 1 + +int init (int count, char **translates) +{ + int i; + char *suffix = ".gat"; + + for (i = 0; i < count; i++) + { + char *src = translates[i]; + char *dest = strchr (src, ':'); + + if (!dest) + { + fprintf (stderr, "Missing colon in: `%s'\n", src); + return 1; + } + + *dest++ = 0; + + if (strlen (src) + strlen (suffix) >= MAP_NAME_SIZE) + { + fprintf (stderr, "Map name prefix too long: `%s'\n", src); + return 1; + } + + if (strlen (dest) + strlen (suffix) >= MAP_NAME_SIZE) + { + fprintf (stderr, "Map name prefix too long: `%s'\n", dest); + return 1; + } + + strncpy (maps[maps_nr].old, src, MAP_NAME_SIZE); + strcat (maps[maps_nr].old, suffix); + strncpy (maps[maps_nr].new, dest, MAP_NAME_SIZE); + strcat (maps[maps_nr].new, suffix); + + ++maps_nr; + } + + return 0; +} + +int main (int argc, char *argv[]) +{ + if (argc < 2) + { + printf ("Usage: %s oldmap0:newmap0 oldmap1:newmap1 ...\n", argv[0]); + printf ("e.g., %s new_1-1:001-2 new_2-1:001-1\n", argv[0]); + puts ("The extension `.gat' is appended implicitly."); + exit (0); + } + if (init (argc - 1, argv + 1)) + return 1; + + mmo_char_convert (); + + return 0; +} diff --git a/src/tool/marriage-info.c b/src/tool/marriage-info.c deleted file mode 100644 index 4d7cbc3..0000000 --- a/src/tool/marriage-info.c +++ /dev/null @@ -1,482 +0,0 @@ -/* To build: -gcc -O2 -m32 -Isrc/common -Isrc/char -Isrc/map -Isrc/login -o marriage-info \ -marriage-info.c src/common/socket.o src/common/timer.o src/common/db.o \ -src/common/lock.o src/common/malloc.o src/char/int_guild.o \ -src/char/int_party.o src/char/int_storage.o src/char/inter.o -*/ - -#include -#include -#include "../login/login.h" -#include "../common/mmo.h" -// Yes, this is intentional -#include "../char/char.c" - -int mode; -#define MODE_MARRIED 0 -#define MODE_SINGLES_F 1 -#define MODE_SINGLES_M 2 -#define MODE_SINGLES_A 3 - -#define CHUNK_SIZE 1024 - -/* chunked list to represent leaves */ -typedef struct { - int char_id; - int exp; - char name[24]; - unsigned char level; - unsigned char sex; -} char_leaf_t; - -/* Chunks are in descending order, but chars are in ascending order */ -typedef struct chunklist_node { - int size; - char_leaf_t chars[CHUNK_SIZE]; - struct chunklist_node *next; -} chunklist_node_t; - -chunklist_node_t *list = NULL; - -static void -insert(chunklist_node_t **listp, struct mmo_charstatus *p) -{ - chunklist_node_t *chunk = *listp; - char_leaf_t *l; - - if ((chunk && chunk->size == CHUNK_SIZE) - || (!chunk)) { - chunk = malloc(sizeof(chunklist_node_t)); - chunk->size = 0; - chunk->next = *listp; - *listp = chunk; - } - - l = &chunk->chars[chunk->size++]; - - l->char_id = p->char_id; - l->level = p->base_level; - l->exp = p->base_exp; - l->sex = p->sex; - strcpy(l->name, p->name); -} - -static int -compare_leaf(const void *l, const void *r) -{ - return ((char_leaf_t *)l)->char_id - ((char_leaf_t *)r)->char_id; -} - -static char_leaf_t * -find(chunklist_node_t *list, int char_id) -{ - if (!list) - return NULL; /* fatal error */ - else { - int start = list->chars[0].char_id; - int stop = list->chars[list->size - 1].char_id; - - if (char_id >= start && char_id <= stop) { /* in this chunk */ - char_leaf_t key; - key.char_id = char_id; - return (char_leaf_t *) - bsearch(&key, &list->chars, list->size, sizeof(char_leaf_t), - compare_leaf); - } - else find(list->next, char_id); - } -} - - -void /* replace blanks with percent signs */ -namefrob(char *n) -{ - while (*n++) /* can't start with a blank */ - if (*n == ' ') - *n = '%'; -} - -/* --------------------------------------------------------------------------------- - Copied and pasted due to lacking modularity -*/ - -char account_filename[1024] = "save/account.txt"; -int account_id_count = START_ACCOUNT_NUM; - -struct auth_dat { - int account_id, sex; - char userid[24], pass[24], lastlogin[24]; - int logincount; - int state; - char email[40]; - char error_message[20]; - time_t ban_until_time; - time_t connect_until_time; - char last_ip[16]; - char memo[255]; - int account_reg2_num; - struct global_reg account_reg2[ACCOUNT_REG2_NUM]; -} *auth_dat; - -int auth_num = 0, auth_max = 0; - - -/* - Reading of the accounts database -*/ -int mmo_auth_init(void) { - FILE *fp; - int account_id, logincount, state, n, i, j, v; - char line[2048], *p, userid[2048], pass[2048], lastlogin[2048], sex, email[2048], error_message[2048], last_ip[2048], memo[2048]; - time_t ban_until_time; - time_t connect_until_time; - char str[2048]; - int GM_count = 0; - int server_count = 0; - - auth_dat = calloc(sizeof(struct auth_dat) * 256, 1); - auth_max = 256; - - fp = fopen(account_filename, "r"); - if (fp == NULL) { - printf("\033[1;31mmmo_auth_init: Accounts file [%s] not found.\033[0m\n", account_filename); - return 0; - } - - while(fgets(line, sizeof(line)-1, fp) != NULL) { - if (line[0] == '/' && line[1] == '/') - continue; - line[sizeof(line)-1] = '\0'; - p = line; - - if (((i = sscanf(line, "%d\t%[^\t]\t%[^\t]\t%[^\t]\t%c\t%d\t%d\t" - "%[^\t]\t%[^\t]\t%ld\t%[^\t]\t%[^\t]\t%ld%n", - &account_id, userid, pass, lastlogin, &sex, &logincount, &state, - email, error_message, &connect_until_time, last_ip, memo, &ban_until_time, &n)) == 13 && line[n] == '\t') || - ((i = sscanf(line, "%d\t%[^\t]\t%[^\t]\t%[^\t]\t%c\t%d\t%d\t" - "%[^\t]\t%[^\t]\t%ld\t%[^\t]\t%[^\t]%n", - &account_id, userid, pass, lastlogin, &sex, &logincount, &state, - email, error_message, &connect_until_time, last_ip, memo, &n)) == 12 && line[n] == '\t')) { - n = n + 1; - - if (account_id > END_ACCOUNT_NUM) { - continue; - } - userid[23] = '\0'; - remove_control_chars(userid); - for(j = 0; j < auth_num; j++) { - if (auth_dat[j].account_id == account_id) { - break; - } else if (strcmp(auth_dat[j].userid, userid) == 0) { - break; - } - } - if (j != auth_num) - continue; - - if (auth_num >= auth_max) { - auth_max += 256; - auth_dat = realloc(auth_dat, sizeof(struct auth_dat) * auth_max); - } - - memset(&auth_dat[auth_num], '\0', sizeof(struct auth_dat)); - - auth_dat[auth_num].account_id = account_id; - - strncpy(auth_dat[auth_num].userid, userid, 24); - - pass[23] = '\0'; - remove_control_chars(pass); - strncpy(auth_dat[auth_num].pass, pass, 24); - - lastlogin[23] = '\0'; - remove_control_chars(lastlogin); - strncpy(auth_dat[auth_num].lastlogin, lastlogin, 24); - - auth_dat[auth_num].sex = (sex == 'S' || sex == 's') ? 2 : (sex == 'M' || sex == 'm'); - - if (logincount >= 0) - auth_dat[auth_num].logincount = logincount; - else - auth_dat[auth_num].logincount = 0; - - if (state > 255) - auth_dat[auth_num].state = 100; - else if (state < 0) - auth_dat[auth_num].state = 0; - else - auth_dat[auth_num].state = state; - - if (e_mail_check(email) == 0) { - strncpy(auth_dat[auth_num].email, "a@a.com", 40); - } else { - remove_control_chars(email); - strncpy(auth_dat[auth_num].email, email, 40); - } - - error_message[19] = '\0'; - remove_control_chars(error_message); - if (error_message[0] == '\0' || state != 7) { - strncpy(auth_dat[auth_num].error_message, "-", 20); - } else { - strncpy(auth_dat[auth_num].error_message, error_message, 20); - } - - if (i == 13) - auth_dat[auth_num].ban_until_time = ban_until_time; - else - auth_dat[auth_num].ban_until_time = 0; - - auth_dat[auth_num].connect_until_time = connect_until_time; - - last_ip[15] = '\0'; - remove_control_chars(last_ip); - strncpy(auth_dat[auth_num].last_ip, last_ip, 16); - - memo[254] = '\0'; - remove_control_chars(memo); - strncpy(auth_dat[auth_num].memo, memo, 255); - - for(j = 0; j < ACCOUNT_REG2_NUM; j++) { - p += n; - if (sscanf(p, "%[^\t,],%d %n", str, &v, &n) != 2) { - if (p[0] == ',' && sscanf(p, ",%d %n", &v, &n) == 1) { - j--; - continue; - } else - break; - } - str[31] = '\0'; - remove_control_chars(str); - strncpy(auth_dat[auth_num].account_reg2[j].str, str, 32); - auth_dat[auth_num].account_reg2[j].value = v; - } - auth_dat[auth_num].account_reg2_num = j; - - if (isGM(account_id) > 0) - GM_count++; - if (auth_dat[auth_num].sex == 2) - server_count++; - - auth_num++; - if (account_id >= account_id_count) - account_id_count = account_id + 1; - - } else if ((i = sscanf(line, "%d\t%[^\t]\t%[^\t]\t%[^\t]\t%c\t%d\t%d\t%n", - &account_id, userid, pass, lastlogin, &sex, &logincount, &state, &n)) >= 5) { - if (account_id > END_ACCOUNT_NUM) { - continue; - } - userid[23] = '\0'; - remove_control_chars(userid); - for(j = 0; j < auth_num; j++) { - if (auth_dat[j].account_id == account_id) { - break; - } else if (strcmp(auth_dat[j].userid, userid) == 0) { - break; - } - } - if (j != auth_num) - continue; - - if (auth_num >= auth_max) { - auth_max += 256; - auth_dat = realloc(auth_dat, sizeof(struct auth_dat) * auth_max); - } - - memset(&auth_dat[auth_num], '\0', sizeof(struct auth_dat)); - - auth_dat[auth_num].account_id = account_id; - - strncpy(auth_dat[auth_num].userid, userid, 24); - - pass[23] = '\0'; - remove_control_chars(pass); - strncpy(auth_dat[auth_num].pass, pass, 24); - - lastlogin[23] = '\0'; - remove_control_chars(lastlogin); - strncpy(auth_dat[auth_num].lastlogin, lastlogin, 24); - - auth_dat[auth_num].sex = (sex == 'S' || sex == 's') ? 2 : (sex == 'M' || sex == 'm'); - - if (i >= 6) { - if (logincount >= 0) - auth_dat[auth_num].logincount = logincount; - else - auth_dat[auth_num].logincount = 0; - } else - auth_dat[auth_num].logincount = 0; - - if (i >= 7) { - if (state > 255) - auth_dat[auth_num].state = 100; - else if (state < 0) - auth_dat[auth_num].state = 0; - else - auth_dat[auth_num].state = state; - } else - auth_dat[auth_num].state = 0; - - strncpy(auth_dat[auth_num].email, "a@a.com", 40); - strncpy(auth_dat[auth_num].error_message, "-", 20); - auth_dat[auth_num].ban_until_time = 0; - auth_dat[auth_num].connect_until_time = 0; - strncpy(auth_dat[auth_num].last_ip, "-", 16); - strncpy(auth_dat[auth_num].memo, "-", 255); - - for(j = 0; j < ACCOUNT_REG2_NUM; j++) { - p += n; - if (sscanf(p, "%[^\t,],%d %n", str, &v, &n) != 2) { - if (p[0] == ',' && sscanf(p, ",%d %n", &v, &n) == 1) { - j--; - continue; - } else - break; - } - str[31] = '\0'; - remove_control_chars(str); - strncpy(auth_dat[auth_num].account_reg2[j].str, str, 32); - auth_dat[auth_num].account_reg2[j].value = v; - } - auth_dat[auth_num].account_reg2_num = j; - - if (isGM(account_id) > 0) - GM_count++; - if (auth_dat[auth_num].sex == 2) - server_count++; - - auth_num++; - if (account_id >= account_id_count) - account_id_count = account_id + 1; - - } else { - i = 0; - if (sscanf(line, "%d\t%%newid%%\n%n", &account_id, &i) == 1 && - i > 0 && account_id > account_id_count) - account_id_count = account_id; - } - } - fclose(fp); - - if (auth_num == 0) { - sprintf(line, "No account found in %s.", account_filename); - } else { - if (auth_num == 1) { - sprintf(line, "1 account read in %s,", account_filename); - } else { - sprintf(line, "%d accounts read in %s,", auth_num, account_filename); - } - if (GM_count == 0) { - sprintf(str, "%s of which is no GM account and", line); - } else if (GM_count == 1) { - sprintf(str, "%s of which is 1 GM account and", line); - } else { - sprintf(str, "%s of which is %d GM accounts and", line, GM_count); - } - if (server_count == 0) { - sprintf(line, "%s no server account ('S').", str); - } else if (server_count == 1) { - sprintf(line, "%s 1 server account ('S').", str); - } else { - sprintf(line, "%s %d server accounts ('S').", str, server_count); - } - } - - return 0; -} - -/*--------------------------------------------------------------------------------*/ - - -void -mmo_check_dumpworthy(struct mmo_charstatus *p) -{ - int i; - namefrob(p->name); - - for (i = 0; i < auth_num; i++) - if (auth_dat[i].account_id == p->account_id) { - p->sex = auth_dat[i].sex; - break; - } - - if (p->partner_id) { - if (mode != MODE_MARRIED) - return; - - if (p->partner_id < p->char_id) { - char_leaf_t *partner = find(list, p->partner_id); - if (!partner) - fprintf(stderr, "Char %d (%s)'s partner (%d) no longer available\n", - p->char_id, - p->name, - p->partner_id); - else - printf ("%d\t%d\t%s\t%s\t%d\t%s\t%s\t%d--%d,%d\n", - p->base_level + partner->level, - p->base_exp + partner->exp, - p->name, p->sex? "M" : "F", p->base_level, - partner->name, partner->sex? "M" : "F", partner->level); - } else { - insert(&list, p); - } - } else if (p->sex == (mode - 1)) - printf("%d\t%d\t%s\n", p->base_level, p->base_exp, p->name); - else if (mode == MODE_SINGLES_A) - printf("%d\t%d\t%s\t%s\n", p->base_level, p->base_exp, p->name, p->sex? "M" : "F"); -} - -int mmo_char_dump() -{ - char line[965536]; - int ret; - struct mmo_charstatus char_dat; - FILE *ifp,*ofp; - - ifp=stdin; - while(fgets(line,65535,ifp)){ - memset(&char_dat,0,sizeof(struct mmo_charstatus)); - ret=mmo_char_fromstr(line,&char_dat); - if(ret){ - mmo_check_dumpworthy(&char_dat); - } - } - return 0; -} - - -int init(char *mode_s) -{ - if (!strcmp(mode_s, "-c")) - mode = MODE_MARRIED; - else if (!strcmp(mode_s, "-f")) - mode = MODE_SINGLES_F; - else if (!strcmp(mode_s, "-m")) - mode = MODE_SINGLES_M; - else if (!strcmp(mode_s, "-s")) - mode = MODE_SINGLES_A; - else { - fprintf(stderr, "Unknown mode `%s'\n", mode_s); - return 1; - } - return 0; -} - -int main(int argc,char *argv[]) -{ - mmo_auth_init(); - - if(argc < 2) { - printf("Usage: %s \n", argv[0]); - printf("Where is one of -c (couples), -s (singles), -f (female singles), -m (male singles)\n", argv[0]); - exit(0); - } - if (init(argv[1])) - return 1; - - mmo_char_dump(); - - return 0; -} diff --git a/src/tool/marriage-info.cpp b/src/tool/marriage-info.cpp new file mode 100644 index 0000000..3552a9b --- /dev/null +++ b/src/tool/marriage-info.cpp @@ -0,0 +1,482 @@ +/* To build: +gcc -O2 -m32 -Isrc/common -Isrc/char -Isrc/map -Isrc/login -o marriage-info \ +marriage-info.c src/common/socket.o src/common/timer.o src/common/db.o \ +src/common/lock.o src/common/malloc.o src/char/int_guild.o \ +src/char/int_party.o src/char/int_storage.o src/char/inter.o +*/ + +#include +#include +#include "../login/login.hpp" +#include "../common/mmo.hpp" +// Yes, this is intentional +#include "../char/char.cpp" + +int mode; +#define MODE_MARRIED 0 +#define MODE_SINGLES_F 1 +#define MODE_SINGLES_M 2 +#define MODE_SINGLES_A 3 + +#define CHUNK_SIZE 1024 + +/* chunked list to represent leaves */ +typedef struct { + int char_id; + int exp; + char name[24]; + unsigned char level; + unsigned char sex; +} char_leaf_t; + +/* Chunks are in descending order, but chars are in ascending order */ +typedef struct chunklist_node { + int size; + char_leaf_t chars[CHUNK_SIZE]; + struct chunklist_node *next; +} chunklist_node_t; + +chunklist_node_t *list = NULL; + +static void +insert(chunklist_node_t **listp, struct mmo_charstatus *p) +{ + chunklist_node_t *chunk = *listp; + char_leaf_t *l; + + if ((chunk && chunk->size == CHUNK_SIZE) + || (!chunk)) { + chunk = malloc(sizeof(chunklist_node_t)); + chunk->size = 0; + chunk->next = *listp; + *listp = chunk; + } + + l = &chunk->chars[chunk->size++]; + + l->char_id = p->char_id; + l->level = p->base_level; + l->exp = p->base_exp; + l->sex = p->sex; + strcpy(l->name, p->name); +} + +static int +compare_leaf(const void *l, const void *r) +{ + return ((char_leaf_t *)l)->char_id - ((char_leaf_t *)r)->char_id; +} + +static char_leaf_t * +find(chunklist_node_t *list, int char_id) +{ + if (!list) + return NULL; /* fatal error */ + else { + int start = list->chars[0].char_id; + int stop = list->chars[list->size - 1].char_id; + + if (char_id >= start && char_id <= stop) { /* in this chunk */ + char_leaf_t key; + key.char_id = char_id; + return (char_leaf_t *) + bsearch(&key, &list->chars, list->size, sizeof(char_leaf_t), + compare_leaf); + } + else find(list->next, char_id); + } +} + + +void /* replace blanks with percent signs */ +namefrob(char *n) +{ + while (*n++) /* can't start with a blank */ + if (*n == ' ') + *n = '%'; +} + +/* +-------------------------------------------------------------------------------- + Copied and pasted due to lacking modularity +*/ + +char account_filename[1024] = "save/account.txt"; +int account_id_count = START_ACCOUNT_NUM; + +struct auth_dat { + int account_id, sex; + char userid[24], pass[24], lastlogin[24]; + int logincount; + int state; + char email[40]; + char error_message[20]; + time_t ban_until_time; + time_t connect_until_time; + char last_ip[16]; + char memo[255]; + int account_reg2_num; + struct global_reg account_reg2[ACCOUNT_REG2_NUM]; +} *auth_dat; + +int auth_num = 0, auth_max = 0; + + +/* + Reading of the accounts database +*/ +int mmo_auth_init(void) { + FILE *fp; + int account_id, logincount, state, n, i, j, v; + char line[2048], *p, userid[2048], pass[2048], lastlogin[2048], sex, email[2048], error_message[2048], last_ip[2048], memo[2048]; + time_t ban_until_time; + time_t connect_until_time; + char str[2048]; + int GM_count = 0; + int server_count = 0; + + auth_dat = calloc(sizeof(struct auth_dat) * 256, 1); + auth_max = 256; + + fp = fopen(account_filename, "r"); + if (fp == NULL) { + printf("\033[1;31mmmo_auth_init: Accounts file [%s] not found.\033[0m\n", account_filename); + return 0; + } + + while(fgets(line, sizeof(line)-1, fp) != NULL) { + if (line[0] == '/' && line[1] == '/') + continue; + line[sizeof(line)-1] = '\0'; + p = line; + + if (((i = sscanf(line, "%d\t%[^\t]\t%[^\t]\t%[^\t]\t%c\t%d\t%d\t" + "%[^\t]\t%[^\t]\t%ld\t%[^\t]\t%[^\t]\t%ld%n", + &account_id, userid, pass, lastlogin, &sex, &logincount, &state, + email, error_message, &connect_until_time, last_ip, memo, &ban_until_time, &n)) == 13 && line[n] == '\t') || + ((i = sscanf(line, "%d\t%[^\t]\t%[^\t]\t%[^\t]\t%c\t%d\t%d\t" + "%[^\t]\t%[^\t]\t%ld\t%[^\t]\t%[^\t]%n", + &account_id, userid, pass, lastlogin, &sex, &logincount, &state, + email, error_message, &connect_until_time, last_ip, memo, &n)) == 12 && line[n] == '\t')) { + n = n + 1; + + if (account_id > END_ACCOUNT_NUM) { + continue; + } + userid[23] = '\0'; + remove_control_chars(userid); + for(j = 0; j < auth_num; j++) { + if (auth_dat[j].account_id == account_id) { + break; + } else if (strcmp(auth_dat[j].userid, userid) == 0) { + break; + } + } + if (j != auth_num) + continue; + + if (auth_num >= auth_max) { + auth_max += 256; + auth_dat = realloc(auth_dat, sizeof(struct auth_dat) * auth_max); + } + + memset(&auth_dat[auth_num], '\0', sizeof(struct auth_dat)); + + auth_dat[auth_num].account_id = account_id; + + strncpy(auth_dat[auth_num].userid, userid, 24); + + pass[23] = '\0'; + remove_control_chars(pass); + strncpy(auth_dat[auth_num].pass, pass, 24); + + lastlogin[23] = '\0'; + remove_control_chars(lastlogin); + strncpy(auth_dat[auth_num].lastlogin, lastlogin, 24); + + auth_dat[auth_num].sex = (sex == 'S' || sex == 's') ? 2 : (sex == 'M' || sex == 'm'); + + if (logincount >= 0) + auth_dat[auth_num].logincount = logincount; + else + auth_dat[auth_num].logincount = 0; + + if (state > 255) + auth_dat[auth_num].state = 100; + else if (state < 0) + auth_dat[auth_num].state = 0; + else + auth_dat[auth_num].state = state; + + if (e_mail_check(email) == 0) { + strncpy(auth_dat[auth_num].email, "a@a.com", 40); + } else { + remove_control_chars(email); + strncpy(auth_dat[auth_num].email, email, 40); + } + + error_message[19] = '\0'; + remove_control_chars(error_message); + if (error_message[0] == '\0' || state != 7) { + strncpy(auth_dat[auth_num].error_message, "-", 20); + } else { + strncpy(auth_dat[auth_num].error_message, error_message, 20); + } + + if (i == 13) + auth_dat[auth_num].ban_until_time = ban_until_time; + else + auth_dat[auth_num].ban_until_time = 0; + + auth_dat[auth_num].connect_until_time = connect_until_time; + + last_ip[15] = '\0'; + remove_control_chars(last_ip); + strncpy(auth_dat[auth_num].last_ip, last_ip, 16); + + memo[254] = '\0'; + remove_control_chars(memo); + strncpy(auth_dat[auth_num].memo, memo, 255); + + for(j = 0; j < ACCOUNT_REG2_NUM; j++) { + p += n; + if (sscanf(p, "%[^\t,],%d %n", str, &v, &n) != 2) { + if (p[0] == ',' && sscanf(p, ",%d %n", &v, &n) == 1) { + j--; + continue; + } else + break; + } + str[31] = '\0'; + remove_control_chars(str); + strncpy(auth_dat[auth_num].account_reg2[j].str, str, 32); + auth_dat[auth_num].account_reg2[j].value = v; + } + auth_dat[auth_num].account_reg2_num = j; + + if (isGM(account_id) > 0) + GM_count++; + if (auth_dat[auth_num].sex == 2) + server_count++; + + auth_num++; + if (account_id >= account_id_count) + account_id_count = account_id + 1; + + } else if ((i = sscanf(line, "%d\t%[^\t]\t%[^\t]\t%[^\t]\t%c\t%d\t%d\t%n", + &account_id, userid, pass, lastlogin, &sex, &logincount, &state, &n)) >= 5) { + if (account_id > END_ACCOUNT_NUM) { + continue; + } + userid[23] = '\0'; + remove_control_chars(userid); + for(j = 0; j < auth_num; j++) { + if (auth_dat[j].account_id == account_id) { + break; + } else if (strcmp(auth_dat[j].userid, userid) == 0) { + break; + } + } + if (j != auth_num) + continue; + + if (auth_num >= auth_max) { + auth_max += 256; + auth_dat = realloc(auth_dat, sizeof(struct auth_dat) * auth_max); + } + + memset(&auth_dat[auth_num], '\0', sizeof(struct auth_dat)); + + auth_dat[auth_num].account_id = account_id; + + strncpy(auth_dat[auth_num].userid, userid, 24); + + pass[23] = '\0'; + remove_control_chars(pass); + strncpy(auth_dat[auth_num].pass, pass, 24); + + lastlogin[23] = '\0'; + remove_control_chars(lastlogin); + strncpy(auth_dat[auth_num].lastlogin, lastlogin, 24); + + auth_dat[auth_num].sex = (sex == 'S' || sex == 's') ? 2 : (sex == 'M' || sex == 'm'); + + if (i >= 6) { + if (logincount >= 0) + auth_dat[auth_num].logincount = logincount; + else + auth_dat[auth_num].logincount = 0; + } else + auth_dat[auth_num].logincount = 0; + + if (i >= 7) { + if (state > 255) + auth_dat[auth_num].state = 100; + else if (state < 0) + auth_dat[auth_num].state = 0; + else + auth_dat[auth_num].state = state; + } else + auth_dat[auth_num].state = 0; + + strncpy(auth_dat[auth_num].email, "a@a.com", 40); + strncpy(auth_dat[auth_num].error_message, "-", 20); + auth_dat[auth_num].ban_until_time = 0; + auth_dat[auth_num].connect_until_time = 0; + strncpy(auth_dat[auth_num].last_ip, "-", 16); + strncpy(auth_dat[auth_num].memo, "-", 255); + + for(j = 0; j < ACCOUNT_REG2_NUM; j++) { + p += n; + if (sscanf(p, "%[^\t,],%d %n", str, &v, &n) != 2) { + if (p[0] == ',' && sscanf(p, ",%d %n", &v, &n) == 1) { + j--; + continue; + } else + break; + } + str[31] = '\0'; + remove_control_chars(str); + strncpy(auth_dat[auth_num].account_reg2[j].str, str, 32); + auth_dat[auth_num].account_reg2[j].value = v; + } + auth_dat[auth_num].account_reg2_num = j; + + if (isGM(account_id) > 0) + GM_count++; + if (auth_dat[auth_num].sex == 2) + server_count++; + + auth_num++; + if (account_id >= account_id_count) + account_id_count = account_id + 1; + + } else { + i = 0; + if (sscanf(line, "%d\t%%newid%%\n%n", &account_id, &i) == 1 && + i > 0 && account_id > account_id_count) + account_id_count = account_id; + } + } + fclose(fp); + + if (auth_num == 0) { + sprintf(line, "No account found in %s.", account_filename); + } else { + if (auth_num == 1) { + sprintf(line, "1 account read in %s,", account_filename); + } else { + sprintf(line, "%d accounts read in %s,", auth_num, account_filename); + } + if (GM_count == 0) { + sprintf(str, "%s of which is no GM account and", line); + } else if (GM_count == 1) { + sprintf(str, "%s of which is 1 GM account and", line); + } else { + sprintf(str, "%s of which is %d GM accounts and", line, GM_count); + } + if (server_count == 0) { + sprintf(line, "%s no server account ('S').", str); + } else if (server_count == 1) { + sprintf(line, "%s 1 server account ('S').", str); + } else { + sprintf(line, "%s %d server accounts ('S').", str, server_count); + } + } + + return 0; +} + +/*--------------------------------------------------------------------------------*/ + + +void +mmo_check_dumpworthy(struct mmo_charstatus *p) +{ + int i; + namefrob(p->name); + + for (i = 0; i < auth_num; i++) + if (auth_dat[i].account_id == p->account_id) { + p->sex = auth_dat[i].sex; + break; + } + + if (p->partner_id) { + if (mode != MODE_MARRIED) + return; + + if (p->partner_id < p->char_id) { + char_leaf_t *partner = find(list, p->partner_id); + if (!partner) + fprintf(stderr, "Char %d (%s)'s partner (%d) no longer available\n", + p->char_id, + p->name, + p->partner_id); + else + printf ("%d\t%d\t%s\t%s\t%d\t%s\t%s\t%d--%d,%d\n", + p->base_level + partner->level, + p->base_exp + partner->exp, + p->name, p->sex? "M" : "F", p->base_level, + partner->name, partner->sex? "M" : "F", partner->level); + } else { + insert(&list, p); + } + } else if (p->sex == (mode - 1)) + printf("%d\t%d\t%s\n", p->base_level, p->base_exp, p->name); + else if (mode == MODE_SINGLES_A) + printf("%d\t%d\t%s\t%s\n", p->base_level, p->base_exp, p->name, p->sex? "M" : "F"); +} + +int mmo_char_dump() +{ + char line[965536]; + int ret; + struct mmo_charstatus char_dat; + FILE *ifp,*ofp; + + ifp=stdin; + while(fgets(line,65535,ifp)){ + memset(&char_dat,0,sizeof(struct mmo_charstatus)); + ret=mmo_char_fromstr(line,&char_dat); + if(ret){ + mmo_check_dumpworthy(&char_dat); + } + } + return 0; +} + + +int init(char *mode_s) +{ + if (!strcmp(mode_s, "-c")) + mode = MODE_MARRIED; + else if (!strcmp(mode_s, "-f")) + mode = MODE_SINGLES_F; + else if (!strcmp(mode_s, "-m")) + mode = MODE_SINGLES_M; + else if (!strcmp(mode_s, "-s")) + mode = MODE_SINGLES_A; + else { + fprintf(stderr, "Unknown mode `%s'\n", mode_s); + return 1; + } + return 0; +} + +int main(int argc,char *argv[]) +{ + mmo_auth_init(); + + if(argc < 2) { + printf("Usage: %s \n", argv[0]); + printf("Where is one of -c (couples), -s (singles), -f (female singles), -m (male singles)\n", argv[0]); + exit(0); + } + if (init(argv[1])) + return 1; + + mmo_char_dump(); + + return 0; +} diff --git a/src/tool/moneycount/athena_text.cpp b/src/tool/moneycount/athena_text.cpp index 59269fa..8cf5457 100644 --- a/src/tool/moneycount/athena_text.cpp +++ b/src/tool/moneycount/athena_text.cpp @@ -1,10 +1,10 @@ -#include "athena_text.h" +#include "athena_text.hpp" #include #include #include -#include "mmo.h" +#include "mmo.hpp" //------------------------------------------------------------------------- // Function to set the character from the line (at read of characters file) diff --git a/src/tool/moneycount/athena_text.h b/src/tool/moneycount/athena_text.h deleted file mode 100644 index 705c979..0000000 --- a/src/tool/moneycount/athena_text.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef ATHENA_TEXT_H -#define ATHENA_TEXT_H -#include "mmo.h" - -int mmo_char_fromstr (char *str, struct mmo_charstatus *p); - -int accreg_fromstr (char *str, struct accreg *reg); - -#endif diff --git a/src/tool/moneycount/athena_text.hpp b/src/tool/moneycount/athena_text.hpp new file mode 100644 index 0000000..e4b7025 --- /dev/null +++ b/src/tool/moneycount/athena_text.hpp @@ -0,0 +1,9 @@ +#ifndef ATHENA_TEXT_HPP +#define ATHENA_TEXT_HPP +#include "mmo.hpp" + +int mmo_char_fromstr (char *str, struct mmo_charstatus *p); + +int accreg_fromstr (char *str, struct accreg *reg); + +#endif diff --git a/src/tool/moneycount/main.cpp b/src/tool/moneycount/main.cpp index d15f223..2c3d56c 100644 --- a/src/tool/moneycount/main.cpp +++ b/src/tool/moneycount/main.cpp @@ -7,8 +7,8 @@ #include #include -#include "mmo.h" -#include "athena_text.h" +#include "mmo.hpp" +#include "athena_text.hpp" #include "inf.hpp" #define ATHENA_FILE "save/athena.txt" diff --git a/src/tool/moneycount/mmo.h b/src/tool/moneycount/mmo.h deleted file mode 100644 index bd62b49..0000000 --- a/src/tool/moneycount/mmo.h +++ /dev/null @@ -1,309 +0,0 @@ -// $Id: mmo.h,v 1.3 2004/09/25 20:12:25 PoW Exp $ -// Original : mmo.h 2003/03/14 12:07:02 Rev.1.7 - -#ifndef _MMO_H_ -#define _MMO_H_ - -#include - -#define FIFOSIZE_SERVERLINK 256*1024 - -// set to 0 to not check IP of player between each server. -// set to another value if you want to check (1) -#define CMP_AUTHFIFO_IP 1 - -#define CMP_AUTHFIFO_LOGIN2 1 - -#define MAX_MAP_PER_SERVER 512 -#define MAX_INVENTORY 100 -#define MAX_AMOUNT 30000 -#define MAX_ZENY 1000000000 // 1G zeny -#define MAX_CART 100 -#define MAX_SKILL 450 -#define GLOBAL_REG_NUM 96 -#define ACCOUNT_REG_NUM 16 -#define ACCOUNT_REG2_NUM 16 -#define DEFAULT_WALK_SPEED 150 -#define MIN_WALK_SPEED 0 -#define MAX_WALK_SPEED 1000 -#define MAX_STORAGE 300 -#define MAX_GUILD_STORAGE 1000 -#define MAX_PARTY 12 -#define MAX_GUILD 120 // increased max guild members to accomodate for +2 increase for extension levels [Valaris] (removed) [PoW] -#define MAX_GUILDPOSITION 20 // increased max guild positions to accomodate for all members [Valaris] (removed) [PoW] -#define MAX_GUILDEXPLUSION 32 -#define MAX_GUILDALLIANCE 16 -#define MAX_GUILDSKILL 8 -#define MAX_GUILDCASTLE 24 // increased to include novice castles [Valaris] -#define MAX_GUILDLEVEL 50 - -#define MIN_HAIR_STYLE battle_config.min_hair_style -#define MAX_HAIR_STYLE battle_config.max_hair_style -#define MIN_HAIR_COLOR battle_config.min_hair_color -#define MAX_HAIR_COLOR battle_config.max_hair_color -#define MIN_CLOTH_COLOR battle_config.min_cloth_color -#define MAX_CLOTH_COLOR battle_config.max_cloth_color - -// for produce -#define MIN_ATTRIBUTE 0 -#define MAX_ATTRIBUTE 4 -#define ATTRIBUTE_NORMAL 0 -#define MIN_STAR 0 -#define MAX_STAR 3 - -#define MIN_PORTAL_MEMO 0 -#define MAX_PORTAL_MEMO 2 - -#define MAX_STATUS_TYPE 5 - -#define CHAR_CONF_NAME "conf/char_athena.conf" - -struct account -{ - int account_id; - char name[50]; - char password[50]; - char lastlogin[50]; - char sex; - int num_logins; - int state; - char email[50]; - char error_message[50]; - long valitidy_time; - char last_ip[50]; - char memo[50]; - long ban_time; -}; - - -struct item -{ - int id; - short nameid; - short amount; - unsigned short equip; - char identify; - char refine; - char attribute; - short card[4]; - short broken; -}; - -struct point -{ - char map[24]; - short x, y; -}; - -struct skill -{ - unsigned short id, lv, flags; -}; - -struct global_reg -{ - char str[32]; - int value; -}; - -struct accreg -{ - int account_id, reg_num; - struct global_reg reg[ACCOUNT_REG_NUM]; -}; - -struct mmo_charstatus -{ - int char_id; - int account_id; - int partner_id; - - int base_exp, job_exp, zeny; - - short classb; - short status_point, skill_point; - int hp, max_hp, sp, max_sp; - short option, karma, manner; - short hair, hair_color, clothes_color; - int party_id, guild_id; - - short weapon, shield; - short head_top, head_mid, head_bottom; - - char name[24]; - unsigned char base_level, job_level; - short str, agi, vit, int_, dex, luk; - unsigned char char_num, sex; - - unsigned long mapip; - unsigned int mapport; - - struct point last_point, save_point, memo_point[10]; - struct item inventory[MAX_INVENTORY], cart[MAX_CART]; - struct skill skill[MAX_SKILL]; - int global_reg_num; - struct global_reg global_reg[GLOBAL_REG_NUM]; - int account_reg_num; - struct global_reg account_reg[ACCOUNT_REG_NUM]; - int account_reg2_num; - struct global_reg account_reg2[ACCOUNT_REG2_NUM]; -}; - -struct storage -{ - int dirty; - int account_id; - short storage_status; - short storage_amount; - struct item storage_[MAX_STORAGE]; -}; - -struct guild_storage -{ - int dirty; - int guild_id; - short storage_status; - short storage_amount; - struct item storage_[MAX_GUILD_STORAGE]; -}; - -struct map_session_data; - -struct gm_account -{ - int account_id; - int level; -}; - -struct party_member -{ - int account_id; - char name[24], map[24]; - int leader, online, lv; - struct map_session_data *sd; -}; - -struct party -{ - int party_id; - char name[24]; - int exp; - int item; - struct party_member member[MAX_PARTY]; -}; - -struct guild_member -{ - int account_id, char_id; - short hair, hair_color, gender, classb, lv; - int exp, exp_payper; - short online, position; - int rsv1, rsv2; - char name[24]; - struct map_session_data *sd; -}; - -struct guild_position -{ - char name[24]; - int mode; - int exp_mode; -}; - -struct guild_alliance -{ - int opposition; - int guild_id; - char name[24]; -}; - -struct guild_explusion -{ - char name[24]; - char mes[40]; - char acc[40]; - int account_id; - int rsv1, rsv2, rsv3; -}; - -struct guild_skill -{ - int id, lv; -}; - -struct guild -{ - int guild_id; - short guild_lv, connect_member, max_member, average_lv; - int exp, next_exp, skill_point, castle_id; - char name[24], master[24]; - struct guild_member member[MAX_GUILD]; - struct guild_position position[MAX_GUILDPOSITION]; - char mes1[60], mes2[120]; - int emblem_len, emblem_id; - char emblem_data[2048]; - struct guild_alliance alliance[MAX_GUILDALLIANCE]; - struct guild_explusion explusion[MAX_GUILDEXPLUSION]; - struct guild_skill skill[MAX_GUILDSKILL]; -}; - -struct guild_castle -{ - int castle_id; - char map_name[24]; - char castle_name[24]; - char castle_event[24]; - int guild_id; - int economy; - int defense; - int triggerE; - int triggerD; - int nextTime; - int payTime; - int createTime; - int visibleC; - int visibleG0; - int visibleG1; - int visibleG2; - int visibleG3; - int visibleG4; - int visibleG5; - int visibleG6; - int visibleG7; - int Ghp0; // added Guardian HP [Valaris] - int Ghp1; - int Ghp2; - int Ghp3; - int Ghp4; - int Ghp5; - int Ghp6; - int Ghp7; - int GID0; - int GID1; - int GID2; - int GID3; - int GID4; - int GID5; - int GID6; - int GID7; // end addition [Valaris] -}; -struct square -{ - int val1[5]; - int val2[5]; -}; - -enum -{ - GBI_EXP = 1, // ?M???h??EXP - GBI_GUILDLV = 2, // ?M???h??Lv - GBI_SKILLPOINT = 3, // ?M???h?~X?L???|?C???g - GBI_SKILLLV = 4, // ?M???h?X?L??Lv - - GMI_POSITION = 0, // ?????o?[???E??X - GMI_EXP = 1, // ?????o?[??EXP - -}; - -#endif // _MMO_H_ - diff --git a/src/tool/moneycount/mmo.hpp b/src/tool/moneycount/mmo.hpp new file mode 100644 index 0000000..beb29c5 --- /dev/null +++ b/src/tool/moneycount/mmo.hpp @@ -0,0 +1,309 @@ +// $Id: mmo.h,v 1.3 2004/09/25 20:12:25 PoW Exp $ +// Original : mmo.h 2003/03/14 12:07:02 Rev.1.7 + +#ifndef MMO_HPP +#define MMO_HPP + +#include + +#define FIFOSIZE_SERVERLINK 256*1024 + +// set to 0 to not check IP of player between each server. +// set to another value if you want to check (1) +#define CMP_AUTHFIFO_IP 1 + +#define CMP_AUTHFIFO_LOGIN2 1 + +#define MAX_MAP_PER_SERVER 512 +#define MAX_INVENTORY 100 +#define MAX_AMOUNT 30000 +#define MAX_ZENY 1000000000 // 1G zeny +#define MAX_CART 100 +#define MAX_SKILL 450 +#define GLOBAL_REG_NUM 96 +#define ACCOUNT_REG_NUM 16 +#define ACCOUNT_REG2_NUM 16 +#define DEFAULT_WALK_SPEED 150 +#define MIN_WALK_SPEED 0 +#define MAX_WALK_SPEED 1000 +#define MAX_STORAGE 300 +#define MAX_GUILD_STORAGE 1000 +#define MAX_PARTY 12 +#define MAX_GUILD 120 // increased max guild members to accomodate for +2 increase for extension levels [Valaris] (removed) [PoW] +#define MAX_GUILDPOSITION 20 // increased max guild positions to accomodate for all members [Valaris] (removed) [PoW] +#define MAX_GUILDEXPLUSION 32 +#define MAX_GUILDALLIANCE 16 +#define MAX_GUILDSKILL 8 +#define MAX_GUILDCASTLE 24 // increased to include novice castles [Valaris] +#define MAX_GUILDLEVEL 50 + +#define MIN_HAIR_STYLE battle_config.min_hair_style +#define MAX_HAIR_STYLE battle_config.max_hair_style +#define MIN_HAIR_COLOR battle_config.min_hair_color +#define MAX_HAIR_COLOR battle_config.max_hair_color +#define MIN_CLOTH_COLOR battle_config.min_cloth_color +#define MAX_CLOTH_COLOR battle_config.max_cloth_color + +// for produce +#define MIN_ATTRIBUTE 0 +#define MAX_ATTRIBUTE 4 +#define ATTRIBUTE_NORMAL 0 +#define MIN_STAR 0 +#define MAX_STAR 3 + +#define MIN_PORTAL_MEMO 0 +#define MAX_PORTAL_MEMO 2 + +#define MAX_STATUS_TYPE 5 + +#define CHAR_CONF_NAME "conf/char_athena.conf" + +struct account +{ + int account_id; + char name[50]; + char password[50]; + char lastlogin[50]; + char sex; + int num_logins; + int state; + char email[50]; + char error_message[50]; + long valitidy_time; + char last_ip[50]; + char memo[50]; + long ban_time; +}; + + +struct item +{ + int id; + short nameid; + short amount; + unsigned short equip; + char identify; + char refine; + char attribute; + short card[4]; + short broken; +}; + +struct point +{ + char map[24]; + short x, y; +}; + +struct skill +{ + unsigned short id, lv, flags; +}; + +struct global_reg +{ + char str[32]; + int value; +}; + +struct accreg +{ + int account_id, reg_num; + struct global_reg reg[ACCOUNT_REG_NUM]; +}; + +struct mmo_charstatus +{ + int char_id; + int account_id; + int partner_id; + + int base_exp, job_exp, zeny; + + short classb; + short status_point, skill_point; + int hp, max_hp, sp, max_sp; + short option, karma, manner; + short hair, hair_color, clothes_color; + int party_id, guild_id; + + short weapon, shield; + short head_top, head_mid, head_bottom; + + char name[24]; + unsigned char base_level, job_level; + short str, agi, vit, int_, dex, luk; + unsigned char char_num, sex; + + unsigned long mapip; + unsigned int mapport; + + struct point last_point, save_point, memo_point[10]; + struct item inventory[MAX_INVENTORY], cart[MAX_CART]; + struct skill skill[MAX_SKILL]; + int global_reg_num; + struct global_reg global_reg[GLOBAL_REG_NUM]; + int account_reg_num; + struct global_reg account_reg[ACCOUNT_REG_NUM]; + int account_reg2_num; + struct global_reg account_reg2[ACCOUNT_REG2_NUM]; +}; + +struct storage +{ + int dirty; + int account_id; + short storage_status; + short storage_amount; + struct item storage_[MAX_STORAGE]; +}; + +struct guild_storage +{ + int dirty; + int guild_id; + short storage_status; + short storage_amount; + struct item storage_[MAX_GUILD_STORAGE]; +}; + +struct map_session_data; + +struct gm_account +{ + int account_id; + int level; +}; + +struct party_member +{ + int account_id; + char name[24], map[24]; + int leader, online, lv; + struct map_session_data *sd; +}; + +struct party +{ + int party_id; + char name[24]; + int exp; + int item; + struct party_member member[MAX_PARTY]; +}; + +struct guild_member +{ + int account_id, char_id; + short hair, hair_color, gender, classb, lv; + int exp, exp_payper; + short online, position; + int rsv1, rsv2; + char name[24]; + struct map_session_data *sd; +}; + +struct guild_position +{ + char name[24]; + int mode; + int exp_mode; +}; + +struct guild_alliance +{ + int opposition; + int guild_id; + char name[24]; +}; + +struct guild_explusion +{ + char name[24]; + char mes[40]; + char acc[40]; + int account_id; + int rsv1, rsv2, rsv3; +}; + +struct guild_skill +{ + int id, lv; +}; + +struct guild +{ + int guild_id; + short guild_lv, connect_member, max_member, average_lv; + int exp, next_exp, skill_point, castle_id; + char name[24], master[24]; + struct guild_member member[MAX_GUILD]; + struct guild_position position[MAX_GUILDPOSITION]; + char mes1[60], mes2[120]; + int emblem_len, emblem_id; + char emblem_data[2048]; + struct guild_alliance alliance[MAX_GUILDALLIANCE]; + struct guild_explusion explusion[MAX_GUILDEXPLUSION]; + struct guild_skill skill[MAX_GUILDSKILL]; +}; + +struct guild_castle +{ + int castle_id; + char map_name[24]; + char castle_name[24]; + char castle_event[24]; + int guild_id; + int economy; + int defense; + int triggerE; + int triggerD; + int nextTime; + int payTime; + int createTime; + int visibleC; + int visibleG0; + int visibleG1; + int visibleG2; + int visibleG3; + int visibleG4; + int visibleG5; + int visibleG6; + int visibleG7; + int Ghp0; // added Guardian HP [Valaris] + int Ghp1; + int Ghp2; + int Ghp3; + int Ghp4; + int Ghp5; + int Ghp6; + int Ghp7; + int GID0; + int GID1; + int GID2; + int GID3; + int GID4; + int GID5; + int GID6; + int GID7; // end addition [Valaris] +}; +struct square +{ + int val1[5]; + int val2[5]; +}; + +enum +{ + GBI_EXP = 1, // ?M???h??EXP + GBI_GUILDLV = 2, // ?M???h??Lv + GBI_SKILLPOINT = 3, // ?M???h?~X?L???|?C???g + GBI_SKILLLV = 4, // ?M???h?X?L??Lv + + GMI_POSITION = 0, // ?????o?[???E??X + GMI_EXP = 1, // ?????o?[??EXP + +}; + +#endif // MMO_HPP + diff --git a/src/tool/skillfrob.c b/src/tool/skillfrob.c deleted file mode 100644 index 44855ac..0000000 --- a/src/tool/skillfrob.c +++ /dev/null @@ -1,80 +0,0 @@ -// Compile with -// gcc -m32 -Wall -Wno-pointer-sign -fno-strict-aliasing -I src/char -I src/common src/tool/skillfrob.c -o skillfrob src/common/timer.o src/common/malloc.o src/common/socket.o src/common/lock.o src/common/db.o src/char/int_storage.o src/char/inter.o src/char/int_party.o src/char/int_guild.o - -#include -#include -#include "../common/mmo.h" -#include "../char/char.c" - -unsigned char skills[MAX_SKILL]; - -void transform_char (struct mmo_charstatus *p) -{ - int i; - - for (i = 0; i < MAX_SKILL; i++) - { - if (skills[(*p).skill[i].id]) - { - (*p).skill[i].lv = 0; - (*p).skill[i].flags = 0; - } - } -} - -int mmo_char_convert () -{ - char line[965536]; - int ret; - struct mmo_charstatus char_dat; - FILE *ifp, *ofp; - - ifp = stdin; - ofp = stdout; - while (fgets (line, 65535, ifp)) - { - memset (&char_dat, 0, sizeof (struct mmo_charstatus)); - ret = mmo_char_fromstr (line, &char_dat); - if (ret) - { - transform_char (&char_dat); - mmo_char_tostr (line, &char_dat); - fprintf (ofp, "%s\n", line); - } - } - fcloseall (); - return 0; -} - -int init (int count, char **translates) -{ - int i, skill; - - memset (skills, 0, sizeof (skills)); - - for (i = 0; i < count; i++) - { - skill = atoi (translates[i]); - if (skill > 0) - { - skills[skill] = 1; - } - } - - return 0; -} - -int main (int argc, char *argv[]) -{ - if (argc < 2) - { - printf ("Usage: %s skillid1 skillid2 ...\n", argv[0]); - exit (0); - } - if (init (argc - 1, argv + 1)) - return 1; - - mmo_char_convert (); - - return 0; -} diff --git a/src/tool/skillfrob.cpp b/src/tool/skillfrob.cpp new file mode 100644 index 0000000..901f765 --- /dev/null +++ b/src/tool/skillfrob.cpp @@ -0,0 +1,80 @@ +// Compile with +// gcc -m32 -Wall -Wno-pointer-sign -fno-strict-aliasing -I src/char -I src/common src/tool/skillfrob.c -o skillfrob src/common/timer.o src/common/malloc.o src/common/socket.o src/common/lock.o src/common/db.o src/char/int_storage.o src/char/inter.o src/char/int_party.o src/char/int_guild.o + +#include +#include +#include "../common/mmo.hpp" +#include "../char/char.cpp" + +unsigned char skills[MAX_SKILL]; + +void transform_char (struct mmo_charstatus *p) +{ + int i; + + for (i = 0; i < MAX_SKILL; i++) + { + if (skills[(*p).skill[i].id]) + { + (*p).skill[i].lv = 0; + (*p).skill[i].flags = 0; + } + } +} + +int mmo_char_convert () +{ + char line[965536]; + int ret; + struct mmo_charstatus char_dat; + FILE *ifp, *ofp; + + ifp = stdin; + ofp = stdout; + while (fgets (line, 65535, ifp)) + { + memset (&char_dat, 0, sizeof (struct mmo_charstatus)); + ret = mmo_char_fromstr (line, &char_dat); + if (ret) + { + transform_char (&char_dat); + mmo_char_tostr (line, &char_dat); + fprintf (ofp, "%s\n", line); + } + } + fcloseall (); + return 0; +} + +int init (int count, char **translates) +{ + int i, skill; + + memset (skills, 0, sizeof (skills)); + + for (i = 0; i < count; i++) + { + skill = atoi (translates[i]); + if (skill > 0) + { + skills[skill] = 1; + } + } + + return 0; +} + +int main (int argc, char *argv[]) +{ + if (argc < 2) + { + printf ("Usage: %s skillid1 skillid2 ...\n", argv[0]); + exit (0); + } + if (init (argc - 1, argv + 1)) + return 1; + + mmo_char_convert (); + + return 0; +} -- cgit v1.2.3-60-g2f50