diff options
author | Haruna <haru@dotalux.com> | 2014-11-15 17:04:09 +0100 |
---|---|---|
committer | Haruna <haru@dotalux.com> | 2014-11-15 17:04:09 +0100 |
commit | a6f077063eeff08ee27ae5170de1bb5cf4b2defb (patch) | |
tree | 9bb5ab158230301e604918883ce6d06c31890341 /src/char/inter.c | |
parent | 77b88fe80b907122b24d698938538c22e029d25f (diff) | |
parent | 7f9fa7f59a82682fb139be4301e9a12a99644a19 (diff) | |
download | hercules-a6f077063eeff08ee27ae5170de1bb5cf4b2defb.tar.gz hercules-a6f077063eeff08ee27ae5170de1bb5cf4b2defb.tar.bz2 hercules-a6f077063eeff08ee27ae5170de1bb5cf4b2defb.tar.xz hercules-a6f077063eeff08ee27ae5170de1bb5cf4b2defb.zip |
Merge pull request #388 from 4144/charplugins
char server plugins
Diffstat (limited to 'src/char/inter.c')
-rw-r--r-- | src/char/inter.c | 582 |
1 files changed, 305 insertions, 277 deletions
diff --git a/src/char/inter.c b/src/char/inter.c index df2920aa0..5ac065f23 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -13,6 +13,7 @@ #include <sys/stat.h> // for stat/lstat/fstat - [Dekamaster/Ultimate GM Tool] #include "char.h" +#include "geoip.h" #include "int_auction.h" #include "int_elemental.h" #include "int_guild.h" @@ -23,6 +24,7 @@ #include "int_pet.h" #include "int_quest.h" #include "int_storage.h" +#include "mapif.h" #include "../common/cbasetypes.h" #include "../common/db.h" #include "../common/malloc.h" @@ -35,8 +37,7 @@ #define WISDATA_TTL (60*1000) //Wis data Time To Live (60 seconds) #define WISDELLIST_MAX 256 // Number of elements in the list Delete data Wis - -Sql* sql_handle = NULL; +struct inter_interface inter_s; int char_server_port = 3306; char char_server_ip[32] = "127.0.0.1"; @@ -72,7 +73,7 @@ static int wis_dellist[WISDELLIST_MAX], wis_delnum; #define MAX_JOB_NAMES 150 static char* msg_table[MAX_JOB_NAMES]; // messages 550 ~ 699 are job names -const char* msg_txt(int msg_number) { +const char* inter_msg_txt(int msg_number) { msg_number -= 550; if (msg_number >= 0 && msg_number < MAX_JOB_NAMES && msg_table[msg_number] != NULL && msg_table[msg_number][0] != '\0') @@ -84,14 +85,15 @@ const char* msg_txt(int msg_number) { /** * Reads Message Data. * - * This is a modified version of the mapserver's msg_config_read to + * This is a modified version of the mapserver's inter->msg_config_read to * only read messages with IDs between 550 and 550+MAX_JOB_NAMES. * * @param[in] cfg_name configuration filename to read. * @param[in] allow_override whether to allow duplicate message IDs to override the original value. * @return success state. */ -bool msg_config_read(const char *cfg_name, bool allow_override) { +bool inter_msg_config_read(const char *cfg_name, bool allow_override) +{ int msg_number; char line[1024], w1[1024], w2[1024]; FILE *fp; @@ -112,7 +114,7 @@ bool msg_config_read(const char *cfg_name, bool allow_override) { continue; if (strcmpi(w1, "import") == 0) - msg_config_read(w2, true); + inter->msg_config_read(w2, true); else { msg_number = atoi(w1); if( msg_number < 550 || msg_number > (550+MAX_JOB_NAMES) ) @@ -141,13 +143,15 @@ bool msg_config_read(const char *cfg_name, bool allow_override) { /*========================================== * Cleanup Message Data *------------------------------------------*/ -void do_final_msg(void) { +void inter_do_final_msg(void) +{ int i; for (i = 0; i < MAX_JOB_NAMES; i++) aFree(msg_table[i]); } /* from pc.c due to @accinfo. any ideas to replace this crap are more than welcome. */ -const char* job_name(int class_) { +const char* inter_job_name(int class_) +{ switch (class_) { case JOB_NOVICE: // 550 case JOB_SWORDMAN: // 551 @@ -156,7 +160,7 @@ const char* job_name(int class_) { case JOB_ACOLYTE: // 554 case JOB_MERCHANT: // 555 case JOB_THIEF: // 556 - return msg_txt(550 - JOB_NOVICE+class_); + return inter->msg_txt(550 - JOB_NOVICE+class_); case JOB_KNIGHT: // 557 case JOB_PRIEST: // 558 @@ -164,10 +168,10 @@ const char* job_name(int class_) { case JOB_BLACKSMITH: // 560 case JOB_HUNTER: // 561 case JOB_ASSASSIN: // 562 - return msg_txt(557 - JOB_KNIGHT+class_); + return inter->msg_txt(557 - JOB_KNIGHT+class_); case JOB_KNIGHT2: - return msg_txt(557); + return inter->msg_txt(557); case JOB_CRUSADER: // 563 case JOB_MONK: // 564 @@ -176,20 +180,20 @@ const char* job_name(int class_) { case JOB_ALCHEMIST: // 567 case JOB_BARD: // 568 case JOB_DANCER: // 569 - return msg_txt(563 - JOB_CRUSADER+class_); + return inter->msg_txt(563 - JOB_CRUSADER+class_); case JOB_CRUSADER2: - return msg_txt(563); + return inter->msg_txt(563); case JOB_WEDDING: // 570 case JOB_SUPER_NOVICE: // 571 case JOB_GUNSLINGER: // 572 case JOB_NINJA: // 573 case JOB_XMAS: // 574 - return msg_txt(570 - JOB_WEDDING+class_); + return inter->msg_txt(570 - JOB_WEDDING+class_); case JOB_SUMMER: - return msg_txt(621); + return inter->msg_txt(621); case JOB_NOVICE_HIGH: // 575 case JOB_SWORDMAN_HIGH: // 576 @@ -198,7 +202,7 @@ const char* job_name(int class_) { case JOB_ACOLYTE_HIGH: // 579 case JOB_MERCHANT_HIGH: // 580 case JOB_THIEF_HIGH: // 581 - return msg_txt(575 - JOB_NOVICE_HIGH+class_); + return inter->msg_txt(575 - JOB_NOVICE_HIGH+class_); case JOB_LORD_KNIGHT: // 582 case JOB_HIGH_PRIEST: // 583 @@ -206,10 +210,10 @@ const char* job_name(int class_) { case JOB_WHITESMITH: // 585 case JOB_SNIPER: // 586 case JOB_ASSASSIN_CROSS: // 587 - return msg_txt(582 - JOB_LORD_KNIGHT+class_); + return inter->msg_txt(582 - JOB_LORD_KNIGHT+class_); case JOB_LORD_KNIGHT2: - return msg_txt(582); + return inter->msg_txt(582); case JOB_PALADIN: // 588 case JOB_CHAMPION: // 589 @@ -218,10 +222,10 @@ const char* job_name(int class_) { case JOB_CREATOR: // 592 case JOB_CLOWN: // 593 case JOB_GYPSY: // 594 - return msg_txt(588 - JOB_PALADIN + class_); + return inter->msg_txt(588 - JOB_PALADIN + class_); case JOB_PALADIN2: - return msg_txt(588); + return inter->msg_txt(588); case JOB_BABY: // 595 case JOB_BABY_SWORDMAN: // 596 @@ -230,7 +234,7 @@ const char* job_name(int class_) { case JOB_BABY_ACOLYTE: // 599 case JOB_BABY_MERCHANT: // 600 case JOB_BABY_THIEF: // 601 - return msg_txt(595 - JOB_BABY + class_); + return inter->msg_txt(595 - JOB_BABY + class_); case JOB_BABY_KNIGHT: // 602 case JOB_BABY_PRIEST: // 603 @@ -238,10 +242,10 @@ const char* job_name(int class_) { case JOB_BABY_BLACKSMITH: // 605 case JOB_BABY_HUNTER: // 606 case JOB_BABY_ASSASSIN: // 607 - return msg_txt(602 - JOB_BABY_KNIGHT + class_); + return inter->msg_txt(602 - JOB_BABY_KNIGHT + class_); case JOB_BABY_KNIGHT2: - return msg_txt(602); + return inter->msg_txt(602); case JOB_BABY_CRUSADER: // 608 case JOB_BABY_MONK: // 609 @@ -250,26 +254,26 @@ const char* job_name(int class_) { case JOB_BABY_ALCHEMIST: // 612 case JOB_BABY_BARD: // 613 case JOB_BABY_DANCER: // 614 - return msg_txt(608 - JOB_BABY_CRUSADER + class_); + return inter->msg_txt(608 - JOB_BABY_CRUSADER + class_); case JOB_BABY_CRUSADER2: - return msg_txt(608); + return inter->msg_txt(608); case JOB_SUPER_BABY: - return msg_txt(615); + return inter->msg_txt(615); case JOB_TAEKWON: - return msg_txt(616); + return inter->msg_txt(616); case JOB_STAR_GLADIATOR: case JOB_STAR_GLADIATOR2: - return msg_txt(617); + return inter->msg_txt(617); case JOB_SOUL_LINKER: - return msg_txt(618); + return inter->msg_txt(618); case JOB_GANGSI: // 622 case JOB_DEATH_KNIGHT: // 623 case JOB_DARK_COLLECTOR: // 624 - return msg_txt(622 - JOB_GANGSI+class_); + return inter->msg_txt(622 - JOB_GANGSI+class_); case JOB_RUNE_KNIGHT: // 625 case JOB_WARLOCK: // 626 @@ -277,7 +281,7 @@ const char* job_name(int class_) { case JOB_ARCH_BISHOP: // 628 case JOB_MECHANIC: // 629 case JOB_GUILLOTINE_CROSS: // 630 - return msg_txt(625 - JOB_RUNE_KNIGHT+class_); + return inter->msg_txt(625 - JOB_RUNE_KNIGHT+class_); case JOB_RUNE_KNIGHT_T: // 656 case JOB_WARLOCK_T: // 657 @@ -285,7 +289,7 @@ const char* job_name(int class_) { case JOB_ARCH_BISHOP_T: // 659 case JOB_MECHANIC_T: // 660 case JOB_GUILLOTINE_CROSS_T: // 661 - return msg_txt(656 - JOB_RUNE_KNIGHT_T+class_); + return inter->msg_txt(656 - JOB_RUNE_KNIGHT_T+class_); case JOB_ROYAL_GUARD: // 631 case JOB_SORCERER: // 632 @@ -294,7 +298,7 @@ const char* job_name(int class_) { case JOB_SURA: // 635 case JOB_GENETIC: // 636 case JOB_SHADOW_CHASER: // 637 - return msg_txt(631 - JOB_ROYAL_GUARD+class_); + return inter->msg_txt(631 - JOB_ROYAL_GUARD+class_); case JOB_ROYAL_GUARD_T: // 662 case JOB_SORCERER_T: // 663 @@ -303,31 +307,31 @@ const char* job_name(int class_) { case JOB_SURA_T: // 666 case JOB_GENETIC_T: // 667 case JOB_SHADOW_CHASER_T: // 668 - return msg_txt(662 - JOB_ROYAL_GUARD_T+class_); + return inter->msg_txt(662 - JOB_ROYAL_GUARD_T+class_); case JOB_RUNE_KNIGHT2: - return msg_txt(625); + return inter->msg_txt(625); case JOB_RUNE_KNIGHT_T2: - return msg_txt(656); + return inter->msg_txt(656); case JOB_ROYAL_GUARD2: - return msg_txt(631); + return inter->msg_txt(631); case JOB_ROYAL_GUARD_T2: - return msg_txt(662); + return inter->msg_txt(662); case JOB_RANGER2: - return msg_txt(627); + return inter->msg_txt(627); case JOB_RANGER_T2: - return msg_txt(658); + return inter->msg_txt(658); case JOB_MECHANIC2: - return msg_txt(629); + return inter->msg_txt(629); case JOB_MECHANIC_T2: - return msg_txt(660); + return inter->msg_txt(660); case JOB_BABY_RUNE: // 638 case JOB_BABY_WARLOCK: // 639 @@ -342,33 +346,33 @@ const char* job_name(int class_) { case JOB_BABY_SURA: // 648 case JOB_BABY_GENETIC: // 649 case JOB_BABY_CHASER: // 650 - return msg_txt(638 - JOB_BABY_RUNE+class_); + return inter->msg_txt(638 - JOB_BABY_RUNE+class_); case JOB_BABY_RUNE2: - return msg_txt(638); + return inter->msg_txt(638); case JOB_BABY_GUARD2: - return msg_txt(644); + return inter->msg_txt(644); case JOB_BABY_RANGER2: - return msg_txt(640); + return inter->msg_txt(640); case JOB_BABY_MECHANIC2: - return msg_txt(642); + return inter->msg_txt(642); case JOB_SUPER_NOVICE_E: // 651 case JOB_SUPER_BABY_E: // 652 - return msg_txt(651 - JOB_SUPER_NOVICE_E+class_); + return inter->msg_txt(651 - JOB_SUPER_NOVICE_E+class_); case JOB_KAGEROU: // 653 case JOB_OBORO: // 654 - return msg_txt(653 - JOB_KAGEROU+class_); + return inter->msg_txt(653 - JOB_KAGEROU+class_); case JOB_REBELLION: - return msg_txt(655); + return inter->msg_txt(655); default: - return msg_txt(620); // "Unknown Job" + return inter->msg_txt(620); // "Unknown Job" } } @@ -403,27 +407,21 @@ const char * geoip_countryname[GEOIP_MAX_COUNTRIES] = {"Unknown","Asia/Pacific R "Virgin Islands, British","Virgin Islands, U.S.","Vietnam","Vanuatu","Wallis and Futuna","Samoa","Yemen","Mayotte","Serbia","South Africa", "Zambia","Montenegro","Zimbabwe","Anonymous Proxy","Satellite Provider","Other","Aland Islands","Guernsey","Isle of Man","Jersey", "Saint Barthelemy", "Saint Martin", "Bonaire, Saint Eustatius and Saba", "South Sudan"}; -/** - * GeoIP information - **/ -struct s_geoip { - unsigned char *cache; // GeoIP.dat information see geoip_init() - bool active; -} geoip; /* [Dekamaster/Nightroad] */ /* WHY NOT A DBMAP: There are millions of entries in GeoIP and it has its own algorithm to go quickly through them, a DBMap wouldn't be efficient */ -const char* geoip_getcountry(uint32 ipnum){ +const char* geoip_getcountry(uint32 ipnum) +{ int depth; unsigned int x; const unsigned char *buf; unsigned int offset = 0; - if( geoip.active == false ) + if( geoip->data->active == false ) return geoip_countryname[0]; for (depth = 31; depth >= 0; depth--) { - buf = geoip.cache + (long)6 *offset; + buf = geoip->data->cache + (long)6 *offset; if (ipnum & (1 << depth)) { /* Take the right-hand branch */ x = (buf[3*1 + 0] << (0*8)) @@ -455,16 +453,17 @@ const char* geoip_getcountry(uint32 ipnum){ * Disables GeoIP * frees geoip.cache **/ -void geoip_final(bool shutdown) { - if (geoip.cache) { - aFree(geoip.cache); - geoip.cache = NULL; +void geoip_final(bool shutdown) +{ + if (geoip->data->cache) { + aFree(geoip->data->cache); + geoip->data->cache = NULL; } - if (geoip.active) { + if (geoip->data->active) { if (!shutdown) ShowStatus("GeoIP "CL_RED"disabled"CL_RESET".\n"); - geoip.active = false; + geoip->data->active = false; } } @@ -473,32 +472,33 @@ void geoip_final(bool shutdown) { * geoip.cache should be freed after use! * http://dev.maxmind.com/geoip/legacy/geolite/ **/ -void geoip_init(void) { +void geoip_init(void) +{ int i, fno; char db_type = 1; unsigned char delim[3]; struct stat bufa; FILE *db; - geoip.active = true; + geoip->data->active = true; db = fopen("./db/GeoIP.dat","rb"); if (db == NULL) { ShowError("geoip_readdb: Error reading GeoIP.dat!\n"); - geoip_final(false); + geoip->final(false); return; } fno = fileno(db); if (fstat(fno, &bufa) < 0) { ShowError("geoip_readdb: Error stating GeoIP.dat! Error %d\n", errno); - geoip_final(false); + geoip->final(false); return; } - geoip.cache = aMalloc( (sizeof(geoip.cache) * bufa.st_size) ); - if (fread(geoip.cache, sizeof(unsigned char), bufa.st_size, db) != bufa.st_size) { + geoip->data->cache = aMalloc( (sizeof(geoip->data->cache) * bufa.st_size) ); + if (fread(geoip->data->cache, sizeof(unsigned char), bufa.st_size, db) != bufa.st_size) { ShowError("geoip_cache: Couldn't read all elements!\n"); fclose(db); - geoip_final(false); + geoip->final(false); return; } @@ -527,7 +527,7 @@ void geoip_init(void) { else ShowError("geoip_init(): GeoIP is corrupted!\n"); - geoip_final(false); + geoip->final(false); return; } ShowStatus("Finished Reading "CL_GREEN"GeoIP"CL_RESET" Database.\n"); @@ -537,7 +537,8 @@ void geoip_init(void) { * Argument-list version of inter_msg_to_fd * @see inter_msg_to_fd */ -void inter_vmsg_to_fd(int fd, int u_fd, int aid, char* msg, va_list ap) { +void inter_vmsg_to_fd(int fd, int u_fd, int aid, char* msg, va_list ap) +{ char msg_out[512]; va_list apcopy; int len = 1;/* yes we start at 1 */ @@ -569,15 +570,17 @@ void inter_vmsg_to_fd(int fd, int u_fd, int aid, char* msg, va_list ap) { * @param ... Additional parameters for (v)sprinf */ void inter_msg_to_fd(int fd, int u_fd, int aid, char *msg, ...) __attribute__((format(printf, 4, 5))); -void inter_msg_to_fd(int fd, int u_fd, int aid, char *msg, ...) { +void inter_msg_to_fd(int fd, int u_fd, int aid, char *msg, ...) +{ va_list ap; va_start(ap,msg); - inter_vmsg_to_fd(fd, u_fd, aid, msg, ap); + inter->vmsg_to_fd(fd, u_fd, aid, msg, ap); va_end(ap); } /* [Dekamaster/Nightroad] */ -void mapif_parse_accinfo(int fd) { +void mapif_parse_accinfo(int fd) +{ int u_fd = RFIFOL(fd,2), aid = RFIFOL(fd,6), castergroup = RFIFOL(fd,10); char query[NAME_LENGTH], query_esq[NAME_LENGTH*2+1]; int account_id; @@ -585,43 +588,43 @@ void mapif_parse_accinfo(int fd) { safestrncpy(query, (char*) RFIFOP(fd,14), NAME_LENGTH); - SQL->EscapeString(sql_handle, query_esq, query); + SQL->EscapeString(inter->sql_handle, query_esq, query); account_id = atoi(query); if (account_id < START_ACCOUNT_NUM) { // is string - if ( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`,`name`,`class`,`base_level`,`job_level`,`online` FROM `%s` WHERE `name` LIKE '%s' LIMIT 10", char_db, query_esq) - || SQL->NumRows(sql_handle) == 0 ) { - if( SQL->NumRows(sql_handle) == 0 ) { - inter_msg_to_fd(fd, u_fd, aid, "No matches were found for your criteria, '%s'",query); + if ( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `account_id`,`name`,`class`,`base_level`,`job_level`,`online` FROM `%s` WHERE `name` LIKE '%s' LIMIT 10", char_db, query_esq) + || SQL->NumRows(inter->sql_handle) == 0 ) { + if( SQL->NumRows(inter->sql_handle) == 0 ) { + inter->msg_to_fd(fd, u_fd, aid, "No matches were found for your criteria, '%s'",query); } else { - Sql_ShowDebug(sql_handle); - inter_msg_to_fd(fd, u_fd, aid, "An error occurred, bother your admin about it."); + Sql_ShowDebug(inter->sql_handle); + inter->msg_to_fd(fd, u_fd, aid, "An error occurred, bother your admin about it."); } - SQL->FreeResult(sql_handle); + SQL->FreeResult(inter->sql_handle); return; } else { - if( SQL->NumRows(sql_handle) == 1 ) {//we found a perfect match - SQL->NextRow(sql_handle); - SQL->GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); - SQL->FreeResult(sql_handle); + if( SQL->NumRows(inter->sql_handle) == 1 ) {//we found a perfect match + SQL->NextRow(inter->sql_handle); + SQL->GetData(inter->sql_handle, 0, &data, NULL); account_id = atoi(data); + SQL->FreeResult(inter->sql_handle); } else {// more than one, listing... [Dekamaster/Nightroad] - inter_msg_to_fd(fd, u_fd, aid, "Your query returned the following %d results, please be more specific...",(int)SQL->NumRows(sql_handle)); - while ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { + inter->msg_to_fd(fd, u_fd, aid, "Your query returned the following %d results, please be more specific...",(int)SQL->NumRows(inter->sql_handle)); + while ( SQL_SUCCESS == SQL->NextRow(inter->sql_handle) ) { int class_; short base_level, job_level, online; char name[NAME_LENGTH]; - SQL->GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); - SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name)); - SQL->GetData(sql_handle, 2, &data, NULL); class_ = atoi(data); - SQL->GetData(sql_handle, 3, &data, NULL); base_level = atoi(data); - SQL->GetData(sql_handle, 4, &data, NULL); job_level = atoi(data); - SQL->GetData(sql_handle, 5, &data, NULL); online = atoi(data); + SQL->GetData(inter->sql_handle, 0, &data, NULL); account_id = atoi(data); + SQL->GetData(inter->sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name)); + SQL->GetData(inter->sql_handle, 2, &data, NULL); class_ = atoi(data); + SQL->GetData(inter->sql_handle, 3, &data, NULL); base_level = atoi(data); + SQL->GetData(inter->sql_handle, 4, &data, NULL); job_level = atoi(data); + SQL->GetData(inter->sql_handle, 5, &data, NULL); online = atoi(data); - inter_msg_to_fd(fd, u_fd, aid, "[AID: %d] %s | %s | Level: %d/%d | %s", account_id, name, job_name(class_), base_level, job_level, online?"Online":"Offline"); + inter->msg_to_fd(fd, u_fd, aid, "[AID: %d] %s | %s | Level: %d/%d | %s", account_id, name, inter->job_name(class_), base_level, job_level, online?"Online":"Offline"); } - SQL->FreeResult(sql_handle); + SQL->FreeResult(inter->sql_handle); return; } } @@ -630,63 +633,65 @@ void mapif_parse_accinfo(int fd) { /* it will only get here if we have a single match */ /* and we will send packet with account id to login server asking for account info */ if( account_id ) { - mapif_on_parse_accinfo(account_id, u_fd, aid, castergroup, fd); + mapif->on_parse_accinfo(account_id, u_fd, aid, castergroup, fd); } return; } -void mapif_parse_accinfo2(bool success, int map_fd, int u_fd, int u_aid, int account_id, const char *userid, const char *user_pass, const char *email, const char *last_ip, const char *lastlogin, const char *pin_code, const char *birthdate, int group_id, int logincount, int state) { +void mapif_parse_accinfo2(bool success, int map_fd, int u_fd, int u_aid, int account_id, const char *userid, const char *user_pass, + const char *email, const char *last_ip, const char *lastlogin, const char *pin_code, const char *birthdate, int group_id, int logincount, int state) +{ if (map_fd <= 0 || !session_isActive(map_fd)) return; // check if we have a valid fd if (!success) { - inter_msg_to_fd(map_fd, u_fd, u_aid, "No account with ID '%d' was found.", account_id); + inter->msg_to_fd(map_fd, u_fd, u_aid, "No account with ID '%d' was found.", account_id); return; } - inter_msg_to_fd(map_fd, u_fd, u_aid, "-- Account %d --", account_id); - inter_msg_to_fd(map_fd, u_fd, u_aid, "User: %s | GM Group: %d | State: %d", userid, group_id, state); + inter->msg_to_fd(map_fd, u_fd, u_aid, "-- Account %d --", account_id); + inter->msg_to_fd(map_fd, u_fd, u_aid, "User: %s | GM Group: %d | State: %d", userid, group_id, state); if (user_pass && *user_pass != '\0') { /* password is only received if your gm level is greater than the one you're searching for */ if (pin_code && *pin_code != '\0') - inter_msg_to_fd(map_fd, u_fd, u_aid, "Password: %s (PIN:%s)", user_pass, pin_code); + inter->msg_to_fd(map_fd, u_fd, u_aid, "Password: %s (PIN:%s)", user_pass, pin_code); else - inter_msg_to_fd(map_fd, u_fd, u_aid, "Password: %s", user_pass ); + inter->msg_to_fd(map_fd, u_fd, u_aid, "Password: %s", user_pass ); } - inter_msg_to_fd(map_fd, u_fd, u_aid, "Account e-mail: %s | Birthdate: %s", email, birthdate); - inter_msg_to_fd(map_fd, u_fd, u_aid, "Last IP: %s (%s)", last_ip, geoip_getcountry(str2ip(last_ip))); - inter_msg_to_fd(map_fd, u_fd, u_aid, "This user has logged %d times, the last time were at %s", logincount, lastlogin); - inter_msg_to_fd(map_fd, u_fd, u_aid, "-- Character Details --"); + inter->msg_to_fd(map_fd, u_fd, u_aid, "Account e-mail: %s | Birthdate: %s", email, birthdate); + inter->msg_to_fd(map_fd, u_fd, u_aid, "Last IP: %s (%s)", last_ip, geoip->getcountry(str2ip(last_ip))); + inter->msg_to_fd(map_fd, u_fd, u_aid, "This user has logged %d times, the last time were at %s", logincount, lastlogin); + inter->msg_to_fd(map_fd, u_fd, u_aid, "-- Character Details --"); - if ( SQL_ERROR == SQL->Query(sql_handle, "SELECT `char_id`, `name`, `char_num`, `class`, `base_level`, `job_level`, `online` " + if ( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `char_id`, `name`, `char_num`, `class`, `base_level`, `job_level`, `online` " "FROM `%s` WHERE `account_id` = '%d' ORDER BY `char_num` LIMIT %d", char_db, account_id, MAX_CHARS) - || SQL->NumRows(sql_handle) == 0 ) { - if (SQL->NumRows(sql_handle) == 0) { - inter_msg_to_fd(map_fd, u_fd, u_aid, "This account doesn't have characters."); + || SQL->NumRows(inter->sql_handle) == 0 ) { + if (SQL->NumRows(inter->sql_handle) == 0) { + inter->msg_to_fd(map_fd, u_fd, u_aid, "This account doesn't have characters."); } else { - inter_msg_to_fd(map_fd, u_fd, u_aid, "An error occurred, bother your admin about it."); - Sql_ShowDebug(sql_handle); + inter->msg_to_fd(map_fd, u_fd, u_aid, "An error occurred, bother your admin about it."); + Sql_ShowDebug(inter->sql_handle); } } else { - while ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { + while ( SQL_SUCCESS == SQL->NextRow(inter->sql_handle) ) { char *data; int char_id, class_; short char_num, base_level, job_level, online; char name[NAME_LENGTH]; - SQL->GetData(sql_handle, 0, &data, NULL); char_id = atoi(data); - SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name)); - SQL->GetData(sql_handle, 2, &data, NULL); char_num = atoi(data); - SQL->GetData(sql_handle, 3, &data, NULL); class_ = atoi(data); - SQL->GetData(sql_handle, 4, &data, NULL); base_level = atoi(data); - SQL->GetData(sql_handle, 5, &data, NULL); job_level = atoi(data); - SQL->GetData(sql_handle, 6, &data, NULL); online = atoi(data); + SQL->GetData(inter->sql_handle, 0, &data, NULL); char_id = atoi(data); + SQL->GetData(inter->sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name)); + SQL->GetData(inter->sql_handle, 2, &data, NULL); char_num = atoi(data); + SQL->GetData(inter->sql_handle, 3, &data, NULL); class_ = atoi(data); + SQL->GetData(inter->sql_handle, 4, &data, NULL); base_level = atoi(data); + SQL->GetData(inter->sql_handle, 5, &data, NULL); job_level = atoi(data); + SQL->GetData(inter->sql_handle, 6, &data, NULL); online = atoi(data); - inter_msg_to_fd(map_fd, u_fd, u_aid, "[Slot/CID: %d/%d] %s | %s | Level: %d/%d | %s", char_num, char_id, name, job_name(class_), base_level, job_level, online?"On":"Off"); + inter->msg_to_fd(map_fd, u_fd, u_aid, "[Slot/CID: %d/%d] %s | %s | Level: %d/%d | %s", char_num, char_id, name, inter->job_name(class_), base_level, job_level, online?"On":"Off"); } } - SQL->FreeResult(sql_handle); + SQL->FreeResult(inter->sql_handle); return; } @@ -696,48 +701,49 @@ void mapif_parse_accinfo2(bool success, int map_fd, int u_fd, int u_aid, int acc * @param val either str or int, depending on type * @param type false when int, true otherwise **/ -void inter_savereg(int account_id, int char_id, const char *key, unsigned int index, intptr_t val, bool is_string) { +void inter_savereg(int account_id, int char_id, const char *key, unsigned int index, intptr_t val, bool is_string) +{ /* to login server we go! */ if( key[0] == '#' && key[1] == '#' ) {/* global account reg */ - if( session_isValid(login_fd) ) - global_accreg_to_login_add(key,index,val,is_string); + if( session_isValid(chr->login_fd) ) + chr->global_accreg_to_login_add(key,index,val,is_string); else { ShowError("Login server unavailable, cant perform update on '%s' variable for AID:%d CID:%d\n",key,account_id,char_id); } } else if ( key[0] == '#' ) {/* local account reg */ if( is_string ) { if( val ) { - if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`account_id`,`key`,`index`,`value`) VALUES ('%d','%s','%u','%s')", acc_reg_str_db, account_id, key, index, (char*)val) ) - Sql_ShowDebug(sql_handle); + if( SQL_ERROR == SQL->Query(inter->sql_handle, "REPLACE INTO `%s` (`account_id`,`key`,`index`,`value`) VALUES ('%d','%s','%u','%s')", acc_reg_str_db, account_id, key, index, (char*)val) ) + Sql_ShowDebug(inter->sql_handle); } else { - if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `key` = '%s' AND `index` = '%u' LIMIT 1", acc_reg_str_db, account_id, key, index) ) - Sql_ShowDebug(sql_handle); + if( SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `key` = '%s' AND `index` = '%u' LIMIT 1", acc_reg_str_db, account_id, key, index) ) + Sql_ShowDebug(inter->sql_handle); } } else { if( val ) { - if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`account_id`,`key`,`index`,`value`) VALUES ('%d','%s','%u','%d')", acc_reg_num_db, account_id, key, index, (int)val) ) - Sql_ShowDebug(sql_handle); + if( SQL_ERROR == SQL->Query(inter->sql_handle, "REPLACE INTO `%s` (`account_id`,`key`,`index`,`value`) VALUES ('%d','%s','%u','%d')", acc_reg_num_db, account_id, key, index, (int)val) ) + Sql_ShowDebug(inter->sql_handle); } else { - if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `key` = '%s' AND `index` = '%u' LIMIT 1", acc_reg_num_db, account_id, key, index) ) - Sql_ShowDebug(sql_handle); + if( SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `key` = '%s' AND `index` = '%u' LIMIT 1", acc_reg_num_db, account_id, key, index) ) + Sql_ShowDebug(inter->sql_handle); } } } else { /* char reg */ if( is_string ) { if( val ) { - if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`char_id`,`key`,`index`,`value`) VALUES ('%d','%s','%u','%s')", char_reg_str_db, char_id, key, index, (char*)val) ) - Sql_ShowDebug(sql_handle); + if( SQL_ERROR == SQL->Query(inter->sql_handle, "REPLACE INTO `%s` (`char_id`,`key`,`index`,`value`) VALUES ('%d','%s','%u','%s')", char_reg_str_db, char_id, key, index, (char*)val) ) + Sql_ShowDebug(inter->sql_handle); } else { - if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d' AND `key` = '%s' AND `index` = '%u' LIMIT 1", char_reg_str_db, char_id, key, index) ) - Sql_ShowDebug(sql_handle); + if( SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d' AND `key` = '%s' AND `index` = '%u' LIMIT 1", char_reg_str_db, char_id, key, index) ) + Sql_ShowDebug(inter->sql_handle); } } else { if( val ) { - if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`char_id`,`key`,`index`,`value`) VALUES ('%d','%s','%u','%d')", char_reg_num_db, char_id, key, index, (int)val) ) - Sql_ShowDebug(sql_handle); + if( SQL_ERROR == SQL->Query(inter->sql_handle, "REPLACE INTO `%s` (`char_id`,`key`,`index`,`value`) VALUES ('%d','%s','%u','%d')", char_reg_num_db, char_id, key, index, (int)val) ) + Sql_ShowDebug(inter->sql_handle); } else { - if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d' AND `key` = '%s' AND `index` = '%u' LIMIT 1", char_reg_num_db, char_id, key, index) ) - Sql_ShowDebug(sql_handle); + if( SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d' AND `key` = '%s' AND `index` = '%u' LIMIT 1", char_reg_num_db, char_id, key, index) ) + Sql_ShowDebug(inter->sql_handle); } } } @@ -753,18 +759,18 @@ int inter_accreg_fromsql(int account_id,int char_id, int fd, int type) switch( type ) { case 3: //char reg - if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `char_id`='%d'", char_reg_str_db, char_id) ) - Sql_ShowDebug(sql_handle); + if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `char_id`='%d'", char_reg_str_db, char_id) ) + Sql_ShowDebug(inter->sql_handle); break; case 2: //account reg - if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%d'", acc_reg_str_db, account_id) ) - Sql_ShowDebug(sql_handle); + if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%d'", acc_reg_str_db, account_id) ) + Sql_ShowDebug(inter->sql_handle); break; case 1: //account2 reg - ShowError("inter_accreg_fromsql: Char server shouldn't handle type 1 registry values (##). That is the login server's work!\n"); + ShowError("inter->accreg_fromsql: Char server shouldn't handle type 1 registry values (##). That is the login server's work!\n"); return 0; default: - ShowError("inter_accreg_fromsql: Invalid type %d\n", type); + ShowError("inter->accreg_fromsql: Invalid type %d\n", type); return 0; } @@ -784,9 +790,9 @@ int inter_accreg_fromsql(int account_id,int char_id, int fd, int type) * str type * { keyLength(B), key(<keyLength>), index(L), valLength(B), val(<valLength>) } **/ - while ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { + while ( SQL_SUCCESS == SQL->NextRow(inter->sql_handle) ) { - SQL->GetData(sql_handle, 0, &data, NULL); + SQL->GetData(inter->sql_handle, 0, &data, NULL); len = strlen(data)+1; WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 32 */ @@ -795,12 +801,12 @@ int inter_accreg_fromsql(int account_id,int char_id, int fd, int type) safestrncpy((char*)WFIFOP(fd,plen), data, len); plen += len; - SQL->GetData(sql_handle, 1, &data, NULL); + SQL->GetData(inter->sql_handle, 1, &data, NULL); WFIFOL(fd, plen) = (unsigned int)atol(data); plen += 4; - SQL->GetData(sql_handle, 2, &data, NULL); + SQL->GetData(inter->sql_handle, 2, &data, NULL); len = strlen(data)+1; WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 254 */ @@ -832,19 +838,19 @@ int inter_accreg_fromsql(int account_id,int char_id, int fd, int type) WFIFOW(fd, 2) = plen; WFIFOSET(fd, plen); - SQL->FreeResult(sql_handle); + SQL->FreeResult(inter->sql_handle); switch( type ) { case 3: //char reg - if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `char_id`='%d'", char_reg_num_db, char_id) ) - Sql_ShowDebug(sql_handle); + if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `char_id`='%d'", char_reg_num_db, char_id) ) + Sql_ShowDebug(inter->sql_handle); break; case 2: //account reg - if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%d'", acc_reg_num_db, account_id) ) - Sql_ShowDebug(sql_handle); + if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%d'", acc_reg_num_db, account_id) ) + Sql_ShowDebug(inter->sql_handle); break; case 1: //account2 reg - ShowError("inter_accreg_fromsql: Char server shouldn't handle type 1 registry values (##). That is the login server's work!\n"); + ShowError("inter->accreg_fromsql: Char server shouldn't handle type 1 registry values (##). That is the login server's work!\n"); return 0; } @@ -864,9 +870,9 @@ int inter_accreg_fromsql(int account_id,int char_id, int fd, int type) * int type * { keyLength(B), key(<keyLength>), index(L), value(L) } **/ - while ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) { + while ( SQL_SUCCESS == SQL->NextRow(inter->sql_handle) ) { - SQL->GetData(sql_handle, 0, &data, NULL); + SQL->GetData(inter->sql_handle, 0, &data, NULL); len = strlen(data)+1; WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 32 */ @@ -875,12 +881,12 @@ int inter_accreg_fromsql(int account_id,int char_id, int fd, int type) safestrncpy((char*)WFIFOP(fd,plen), data, len); plen += len; - SQL->GetData(sql_handle, 1, &data, NULL); + SQL->GetData(inter->sql_handle, 1, &data, NULL); WFIFOL(fd, plen) = (unsigned int)atol(data); plen += 4; - SQL->GetData(sql_handle, 2, &data, NULL); + SQL->GetData(inter->sql_handle, 2, &data, NULL); WFIFOL(fd, plen) = atoi(data); plen += 4; @@ -909,7 +915,7 @@ int inter_accreg_fromsql(int account_id,int char_id, int fd, int type) WFIFOW(fd, 2) = plen; WFIFOSET(fd, plen); - SQL->FreeResult(sql_handle); + SQL->FreeResult(inter->sql_handle); return 1; } @@ -956,7 +962,7 @@ static int inter_config_read(const char* cfgName) else if(!strcmpi(w1,"log_inter")) log_inter = atoi(w2); else if(!strcmpi(w1,"import")) - inter_config_read(w2); + inter->config_read(w2); } fclose(fp); @@ -969,7 +975,8 @@ static int inter_config_read(const char* cfgName) * Save interlog into sql (arglist version) * @see inter_log */ -int inter_vlog(char* fmt, va_list ap) { +int inter_vlog(char* fmt, va_list ap) +{ char str[255]; char esc_str[sizeof(str)*2+1];// escaped str va_list apcopy; @@ -978,9 +985,9 @@ int inter_vlog(char* fmt, va_list ap) { vsnprintf(str, sizeof(str), fmt, apcopy); va_end(apcopy); - SQL->EscapeStringLen(sql_handle, esc_str, str, strnlen(str, sizeof(str))); - if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`time`, `log`) VALUES (NOW(), '%s')", interlog_db, esc_str) ) - Sql_ShowDebug(sql_handle); + SQL->EscapeStringLen(inter->sql_handle, esc_str, str, strnlen(str, sizeof(str))); + if( SQL_ERROR == SQL->Query(inter->sql_handle, "INSERT INTO `%s` (`time`, `log`) VALUES (NOW(), '%s')", interlog_db, esc_str) ) + Sql_ShowDebug(inter->sql_handle); return 0; } @@ -991,12 +998,13 @@ int inter_vlog(char* fmt, va_list ap) { * @param ... Additional (printf-like) arguments * @return Always 0 // FIXME */ -int inter_log(char* fmt, ...) { +int inter_log(char* fmt, ...) +{ va_list ap; int ret; va_start(ap,fmt); - ret = inter_vlog(fmt, ap); + ret = inter->vlog(fmt, ap); va_end(ap); return ret; @@ -1007,36 +1015,36 @@ int inter_init_sql(const char *file) { //int i; - inter_config_read(file); + inter->config_read(file); //DB connection initialized - sql_handle = SQL->Malloc(); + inter->sql_handle = SQL->Malloc(); ShowInfo("Connect Character DB server.... (Character Server)\n"); - if( SQL_ERROR == SQL->Connect(sql_handle, char_server_id, char_server_pw, char_server_ip, (uint16)char_server_port, char_server_db) ) + if( SQL_ERROR == SQL->Connect(inter->sql_handle, char_server_id, char_server_pw, char_server_ip, (uint16)char_server_port, char_server_db) ) { - Sql_ShowDebug(sql_handle); - SQL->Free(sql_handle); + Sql_ShowDebug(inter->sql_handle); + SQL->Free(inter->sql_handle); exit(EXIT_FAILURE); } if( *default_codepage ) { - if( SQL_ERROR == SQL->SetEncoding(sql_handle, default_codepage) ) - Sql_ShowDebug(sql_handle); + if( SQL_ERROR == SQL->SetEncoding(inter->sql_handle, default_codepage) ) + Sql_ShowDebug(inter->sql_handle); } wis_db = idb_alloc(DB_OPT_RELEASE_DATA); - inter_guild_sql_init(); - inter_storage_sql_init(); - inter_party_sql_init(); - inter_pet_sql_init(); - inter_homunculus_sql_init(); - inter_mercenary_sql_init(); - inter_elemental_sql_init(); - inter_mail_sql_init(); - inter_auction_sql_init(); - - geoip_init(); - msg_config_read("conf/messages.conf", false); + inter_guild->sql_init(); + inter_storage->sql_init(); + inter_party->sql_init(); + inter_pet->sql_init(); + inter_homunculus->sql_init(); + inter_mercenary->sql_init(); + inter_elemental->sql_init(); + inter_mail->sql_init(); + inter_auction->sql_init(); + + geoip->init(); + inter->msg_config_read("conf/messages.conf", false); return 0; } @@ -1045,18 +1053,18 @@ void inter_final(void) { wis_db->destroy(wis_db, NULL); - inter_guild_sql_final(); - inter_storage_sql_final(); - inter_party_sql_final(); - inter_pet_sql_final(); - inter_homunculus_sql_final(); - inter_mercenary_sql_final(); - inter_elemental_sql_final(); - inter_mail_sql_final(); - inter_auction_sql_final(); - - geoip_final(true); - do_final_msg(); + inter_guild->sql_final(); + inter_storage->sql_final(); + inter_party->sql_final(); + inter_pet->sql_final(); + inter_homunculus->sql_final(); + inter_mercenary->sql_final(); + inter_elemental->sql_final(); + inter_mail->sql_final(); + inter_auction->sql_final(); + + geoip->final(true); + inter->do_final_msg(); return; } @@ -1081,7 +1089,7 @@ int mapif_broadcast(unsigned char *mes, int len, unsigned int fontColor, short f WBUFW(buf,12) = fontAlign; WBUFW(buf,14) = fontY; memcpy(WBUFP(buf,16), mes, len - 16); - mapif_sendallwos(sfd, buf, len); + mapif->sendallwos(sfd, buf, len); if (buf) aFree(buf); @@ -1100,20 +1108,24 @@ int mapif_wis_message(struct WisData *wd) memcpy(WBUFP(buf, 8), wd->src, NAME_LENGTH); memcpy(WBUFP(buf,32), wd->dst, NAME_LENGTH); memcpy(WBUFP(buf,56), wd->msg, wd->len); - wd->count = mapif_sendall(buf,WBUFW(buf,2)); + wd->count = mapif->sendall(buf,WBUFW(buf,2)); return 0; } -// Wis sending result -int mapif_wis_end(struct WisData *wd, int flag) +void mapif_wis_response(int fd, unsigned char *src, int flag) { unsigned char buf[27]; - WBUFW(buf, 0)=0x3802; - memcpy(WBUFP(buf, 2),wd->src,24); + memcpy(WBUFP(buf, 2),src,24); WBUFB(buf,26)=flag; - mapif_send(wd->fd,buf,27); + mapif->send(fd,buf,27); +} + +// Wis sending result +int mapif_wis_end(struct WisData *wd, int flag) +{ + mapif->wis_response(wd->fd, wd->src, flag); return 0; } @@ -1121,12 +1133,13 @@ int mapif_wis_end(struct WisData *wd, int flag) //static void mapif_account_reg(int fd, unsigned char *src) //{ // WBUFW(src,0)=0x3804; //NOTE: writing to RFIFO -// mapif_sendallwos(fd, src, WBUFW(src,2)); +// mapif->sendallwos(fd, src, WBUFW(src,2)); //} // Send the requested account_reg -int mapif_account_reg_reply(int fd,int account_id,int char_id, int type) { - inter_accreg_fromsql(account_id,char_id,fd,type); +int mapif_account_reg_reply(int fd,int account_id,int char_id, int type) +{ + inter->accreg_fromsql(account_id,char_id,fd,type); return 0; } @@ -1151,7 +1164,7 @@ int mapif_disconnectplayer(int fd, int account_id, int char_id, int reason) * Existence check of WISP data * @see DBApply */ -int check_ttl_wisdata_sub(DBKey key, DBData *data, va_list ap) +int inter_check_ttl_wisdata_sub(DBKey key, DBData *data, va_list ap) { int64 tick; struct WisData *wd = DB->data2ptr(data); @@ -1163,19 +1176,19 @@ int check_ttl_wisdata_sub(DBKey key, DBData *data, va_list ap) return 0; } -int check_ttl_wisdata(void) +int inter_check_ttl_wisdata(void) { int64 tick = timer->gettick(); int i; do { wis_delnum = 0; - wis_db->foreach(wis_db, check_ttl_wisdata_sub, tick); + wis_db->foreach(wis_db, inter->check_ttl_wisdata_sub, tick); for(i = 0; i < wis_delnum; i++) { struct WisData *wd = (struct WisData*)idb_get(wis_db, wis_dellist[i]); ShowWarning("inter: wis data id=%d time out : from %s to %s\n", wd->id, wd->src, wd->dst); // removed. not send information after a timeout. Just no answer for the player - //mapif_wis_end(wd, 1); // flag: 0: success to send whisper, 1: target character is not logged in?, 2: ignored by target + //mapif->wis_end(wd, 1); // flag: 0: success to send whisper, 1: target character is not logged in?, 2: ignored by target idb_remove(wis_db, wd->id); } } while(wis_delnum >= WISDELLIST_MAX); @@ -1188,7 +1201,7 @@ int check_ttl_wisdata(void) // broadcast sending int mapif_parse_broadcast(int fd) { - mapif_broadcast(RFIFOP(fd,16), RFIFOW(fd,2), RFIFOL(fd,4), RFIFOW(fd,8), RFIFOW(fd,10), RFIFOW(fd,12), RFIFOW(fd,14), fd); + mapif->broadcast(RFIFOP(fd,16), RFIFOW(fd,2), RFIFOL(fd,4), RFIFOW(fd,8), RFIFOW(fd,10), RFIFOW(fd,12), RFIFOW(fd,14), fd); return 0; } @@ -1216,41 +1229,32 @@ int mapif_parse_WisRequest(int fd) safestrncpy(name, (char*)RFIFOP(fd,28), NAME_LENGTH); //Received name may be too large and not contain \0! [Skotlex] - SQL->EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); - if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `name` FROM `%s` WHERE `name`='%s'", char_db, esc_name) ) - Sql_ShowDebug(sql_handle); + SQL->EscapeStringLen(inter->sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); + if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `name` FROM `%s` WHERE `name`='%s'", char_db, esc_name) ) + Sql_ShowDebug(inter->sql_handle); // search if character exists before to ask all map-servers - if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) + if( SQL_SUCCESS != SQL->NextRow(inter->sql_handle) ) { - unsigned char buf[27]; - WBUFW(buf, 0) = 0x3802; - memcpy(WBUFP(buf, 2), RFIFOP(fd, 4), NAME_LENGTH); - WBUFB(buf,26) = 1; // flag: 0: success to send whisper, 1: target character is not logged in?, 2: ignored by target - mapif_send(fd, buf, 27); + mapif->wis_response(fd, RFIFOP(fd, 4), 1); } else {// Character exists. So, ask all map-servers // to be sure of the correct name, rewrite it - SQL->GetData(sql_handle, 0, &data, &len); + SQL->GetData(inter->sql_handle, 0, &data, &len); memset(name, 0, NAME_LENGTH); memcpy(name, data, min(len, NAME_LENGTH)); // if source is destination, don't ask other servers. if( strncmp((const char*)RFIFOP(fd,4), name, NAME_LENGTH) == 0 ) { - uint8 buf[27]; - WBUFW(buf, 0) = 0x3802; - memcpy(WBUFP(buf, 2), RFIFOP(fd, 4), NAME_LENGTH); - WBUFB(buf,26) = 1; // flag: 0: success to send whisper, 1: target character is not logged in?, 2: ignored by target - mapif_send(fd, buf, 27); + mapif->wis_response(fd, RFIFOP(fd, 4), 1); } else { - CREATE(wd, struct WisData, 1); // Whether the failure of previous wisp/page transmission (timeout) - check_ttl_wisdata(); + inter->check_ttl_wisdata(); wd->id = ++wisid; wd->fd = fd; @@ -1260,11 +1264,11 @@ int mapif_parse_WisRequest(int fd) memcpy(wd->msg, RFIFOP(fd,52), wd->len); wd->tick = timer->gettick(); idb_put(wis_db, wd->id, wd); - mapif_wis_message(wd); + mapif->wis_message(wd); } } - SQL->FreeResult(sql_handle); + SQL->FreeResult(inter->sql_handle); return 0; } @@ -1282,7 +1286,7 @@ int mapif_parse_WisReply(int fd) return 0; // This wisp was probably suppress before, because it was timeout of because of target was found on another map-server if ((--wd->count) <= 0 || flag != 1) { - mapif_wis_end(wd, flag); // flag: 0: success to send whisper, 1: target character is not logged in?, 2: ignored by target + mapif->wis_end(wd, flag); // flag: 0: success to send whisper, 1: target character is not logged in?, 2: ignored by target idb_remove(wis_db, id); } @@ -1296,7 +1300,7 @@ int mapif_parse_WisToGM(int fd) memcpy(WBUFP(buf,0), RFIFOP(fd,0), RFIFOW(fd,2)); WBUFW(buf, 0) = 0x3803; - mapif_sendall(buf, RFIFOW(fd,2)); + mapif->sendall(buf, RFIFOW(fd,2)); return 0; } @@ -1310,10 +1314,10 @@ int mapif_parse_Registry(int fd) int cursor = 14, i; char key[32], sval[254]; unsigned int index; - bool isLoginActive = session_isActive(login_fd); + bool isLoginActive = session_isActive(chr->login_fd); if( isLoginActive ) - global_accreg_to_login_start(account_id,char_id); + chr->global_accreg_to_login_start(account_id,char_id); for(i = 0; i < count; i++) { safestrncpy(key, (char*)RFIFOP(fd, cursor + 1), RFIFOB(fd, cursor)); @@ -1325,31 +1329,31 @@ int mapif_parse_Registry(int fd) switch (RFIFOB(fd, cursor++)) { /* int */ case 0: - inter_savereg(account_id,char_id,key,index,RFIFOL(fd, cursor),false); + inter->savereg(account_id,char_id,key,index,RFIFOL(fd, cursor),false); cursor += 4; break; case 1: - inter_savereg(account_id,char_id,key,index,0,false); + inter->savereg(account_id,char_id,key,index,0,false); break; /* str */ case 2: safestrncpy(sval, (char*)RFIFOP(fd, cursor + 1), RFIFOB(fd, cursor)); cursor += RFIFOB(fd, cursor) + 1; - inter_savereg(account_id,char_id,key,index,(intptr_t)sval,true); + inter->savereg(account_id,char_id,key,index,(intptr_t)sval,true); break; case 3: - inter_savereg(account_id,char_id,key,index,0,true); + inter->savereg(account_id,char_id,key,index,0,true); break; default: - ShowError("mapif_parse_Registry: unknown type %d\n",RFIFOB(fd, cursor - 1)); + ShowError("mapif->parse_Registry: unknown type %d\n",RFIFOB(fd, cursor - 1)); return 1; } } if( isLoginActive ) - global_accreg_to_login_send(); + chr->global_accreg_to_login_send(); } return 0; } @@ -1358,15 +1362,15 @@ int mapif_parse_Registry(int fd) int mapif_parse_RegistryRequest(int fd) { //Load Char Registry - if (RFIFOB(fd,12)) mapif_account_reg_reply(fd,RFIFOL(fd,2),RFIFOL(fd,6),3); + if (RFIFOB(fd,12)) mapif->account_reg_reply(fd,RFIFOL(fd,2),RFIFOL(fd,6),3); //Load Account Registry - if (RFIFOB(fd,11)) mapif_account_reg_reply(fd,RFIFOL(fd,2),RFIFOL(fd,6),2); + if (RFIFOB(fd,11)) mapif->account_reg_reply(fd,RFIFOL(fd,2),RFIFOL(fd,6),2); //Ask Login Server for Account2 values. - if (RFIFOB(fd,10)) request_accreg2(RFIFOL(fd,2),RFIFOL(fd,6)); + if (RFIFOB(fd,10)) chr->request_accreg2(RFIFOL(fd,2),RFIFOL(fd,6)); return 1; } -static void mapif_namechange_ack(int fd, int account_id, int char_id, int type, int flag, char *name) +void mapif_namechange_ack(int fd, int account_id, int char_id, int type, int flag, const char *const name) { WFIFOHEAD(fd, NAME_LENGTH+13); WFIFOW(fd, 0) = 0x3806; @@ -1393,13 +1397,13 @@ int mapif_parse_NameChangeRequest(int fd) if (char_name_option == 1) { // only letters/symbols in char_name_letters are authorized for (i = 0; i < NAME_LENGTH && name[i]; i++) if (strchr(char_name_letters, name[i]) == NULL) { - mapif_namechange_ack(fd, account_id, char_id, type, 0, name); + mapif->namechange_ack(fd, account_id, char_id, type, 0, name); return 0; } } else if (char_name_option == 2) { // letters/symbols in char_name_letters are forbidden for (i = 0; i < NAME_LENGTH && name[i]; i++) if (strchr(char_name_letters, name[i]) != NULL) { - mapif_namechange_ack(fd, account_id, char_id, type, 0, name); + mapif->namechange_ack(fd, account_id, char_id, type, 0, name); return 0; } } @@ -1408,7 +1412,7 @@ int mapif_parse_NameChangeRequest(int fd) //updated here, because changing it on the map won't make it be saved [Skotlex] //name allowed. - mapif_namechange_ack(fd, account_id, char_id, type, 1, name); + mapif->namechange_ack(fd, account_id, char_id, type, 1, name); return 0; } @@ -1443,30 +1447,30 @@ int inter_parse_frommap(int fd) return 0; // Check packet length - if((len = inter_check_length(fd, inter_recv_packet_length[cmd - 0x3000])) == 0) + if((len = inter->check_length(fd, inter_recv_packet_length[cmd - 0x3000])) == 0) return 2; switch(cmd) { - case 0x3000: mapif_parse_broadcast(fd); break; - case 0x3001: mapif_parse_WisRequest(fd); break; - case 0x3002: mapif_parse_WisReply(fd); break; - case 0x3003: mapif_parse_WisToGM(fd); break; - case 0x3004: mapif_parse_Registry(fd); break; - case 0x3005: mapif_parse_RegistryRequest(fd); break; - case 0x3006: mapif_parse_NameChangeRequest(fd); break; - case 0x3007: mapif_parse_accinfo(fd); break; + case 0x3000: mapif->parse_broadcast(fd); break; + case 0x3001: mapif->parse_WisRequest(fd); break; + case 0x3002: mapif->parse_WisReply(fd); break; + case 0x3003: mapif->parse_WisToGM(fd); break; + case 0x3004: mapif->parse_Registry(fd); break; + case 0x3005: mapif->parse_RegistryRequest(fd); break; + case 0x3006: mapif->parse_NameChangeRequest(fd); break; + case 0x3007: mapif->parse_accinfo(fd); break; /* 0x3008 is used by the report stuff */ default: - if( inter_party_parse_frommap(fd) - || inter_guild_parse_frommap(fd) - || inter_storage_parse_frommap(fd) - || inter_pet_parse_frommap(fd) - || inter_homunculus_parse_frommap(fd) - || inter_mercenary_parse_frommap(fd) - || inter_elemental_parse_frommap(fd) - || inter_mail_parse_frommap(fd) - || inter_auction_parse_frommap(fd) - || inter_quest_parse_frommap(fd) + if( inter_party->parse_frommap(fd) + || inter_guild->parse_frommap(fd) + || inter_storage->parse_frommap(fd) + || inter_pet->parse_frommap(fd) + || inter_homunculus->parse_frommap(fd) + || inter_mercenary->parse_frommap(fd) + || inter_elemental->parse_frommap(fd) + || inter_mail->parse_frommap(fd) + || inter_auction->parse_frommap(fd) + || inter_quest->parse_frommap(fd) ) break; else @@ -1477,4 +1481,28 @@ int inter_parse_frommap(int fd) return 1; } - +void inter_defaults(void) +{ + inter = &inter_s; + + inter->sql_handle = NULL; + + inter->msg_txt = inter_msg_txt; + inter->msg_config_read = inter_msg_config_read; + inter->do_final_msg = inter_do_final_msg; + inter->job_name = inter_job_name; + inter->vmsg_to_fd = inter_vmsg_to_fd; + inter->msg_to_fd = inter_msg_to_fd; + inter->savereg = inter_savereg; + inter->accreg_fromsql = inter_accreg_fromsql; + inter->config_read = inter_config_read; + inter->vlog = inter_vlog; + inter->log = inter_log; + inter->init_sql = inter_init_sql; + inter->mapif_init = inter_mapif_init; + inter->check_ttl_wisdata_sub = inter_check_ttl_wisdata_sub; + inter->check_ttl_wisdata = inter->check_ttl_wisdata; + inter->check_length = inter_check_length; + inter->parse_frommap = inter_parse_frommap; + inter->final = inter_final; +} |