summaryrefslogtreecommitdiff
path: root/src/char
diff options
context:
space:
mode:
Diffstat (limited to 'src/char')
-rw-r--r--src/char/CMakeLists.txt62
-rw-r--r--src/char/Makefile.in126
-rw-r--r--src/char/char.c1410
-rw-r--r--src/char/char.h33
-rw-r--r--src/char/int_auction.c52
-rw-r--r--src/char/int_auction.h6
-rw-r--r--src/char/int_elemental.c48
-rw-r--r--src/char/int_elemental.h8
-rw-r--r--src/char/int_guild.c180
-rw-r--r--src/char/int_guild.h9
-rw-r--r--src/char/int_homun.c25
-rw-r--r--src/char/int_homun.h8
-rw-r--r--src/char/int_mail.c26
-rw-r--r--src/char/int_mail.h9
-rw-r--r--src/char/int_mercenary.c22
-rw-r--r--src/char/int_mercenary.h10
-rw-r--r--src/char/int_party.c37
-rw-r--r--src/char/int_party.h10
-rw-r--r--src/char/int_pet.c89
-rw-r--r--src/char/int_pet.h6
-rw-r--r--src/char/int_quest.c294
-rw-r--r--src/char/int_quest.h9
-rw-r--r--src/char/int_storage.c278
-rw-r--r--src/char/int_storage.h6
-rw-r--r--src/char/inter.c1133
-rw-r--r--src/char/inter.h30
-rw-r--r--src/char/pincode.c14
-rw-r--r--src/char/pincode.h7
28 files changed, 2474 insertions, 1473 deletions
diff --git a/src/char/CMakeLists.txt b/src/char/CMakeLists.txt
deleted file mode 100644
index 9413ff303..000000000
--- a/src/char/CMakeLists.txt
+++ /dev/null
@@ -1,62 +0,0 @@
-
-#
-# setup
-#
-set( SQL_CHAR_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "" )
-
-
-#
-# char sql
-#
-if( BUILD_SQL_SERVERS )
-message( STATUS "Creating target char-server" )
-set( SQL_CHAR_HEADERS
- "${CMAKE_CURRENT_SOURCE_DIR}/char.h"
- "${CMAKE_CURRENT_SOURCE_DIR}/int_auction.h"
- "${CMAKE_CURRENT_SOURCE_DIR}/int_elemental.h"
- "${CMAKE_CURRENT_SOURCE_DIR}/int_guild.h"
- "${CMAKE_CURRENT_SOURCE_DIR}/int_homun.h"
- "${CMAKE_CURRENT_SOURCE_DIR}/int_mail.h"
- "${CMAKE_CURRENT_SOURCE_DIR}/int_mercenary.h"
- "${CMAKE_CURRENT_SOURCE_DIR}/int_party.h"
- "${CMAKE_CURRENT_SOURCE_DIR}/int_pet.h"
- "${CMAKE_CURRENT_SOURCE_DIR}/int_quest.h"
- "${CMAKE_CURRENT_SOURCE_DIR}/int_storage.h"
- "${CMAKE_CURRENT_SOURCE_DIR}/inter.h"
- "${CMAKE_CURRENT_SOURCE_DIR}/pincode.h"
- )
-set( SQL_CHAR_SOURCES
- "${CMAKE_CURRENT_SOURCE_DIR}/char.c"
- "${CMAKE_CURRENT_SOURCE_DIR}/int_auction.c"
- "${CMAKE_CURRENT_SOURCE_DIR}/int_elemental.c"
- "${CMAKE_CURRENT_SOURCE_DIR}/int_guild.c"
- "${CMAKE_CURRENT_SOURCE_DIR}/int_homun.c"
- "${CMAKE_CURRENT_SOURCE_DIR}/int_mail.c"
- "${CMAKE_CURRENT_SOURCE_DIR}/int_mercenary.c"
- "${CMAKE_CURRENT_SOURCE_DIR}/int_party.c"
- "${CMAKE_CURRENT_SOURCE_DIR}/int_pet.c"
- "${CMAKE_CURRENT_SOURCE_DIR}/int_quest.c"
- "${CMAKE_CURRENT_SOURCE_DIR}/int_storage.c"
- "${CMAKE_CURRENT_SOURCE_DIR}/inter.c"
- "${CMAKE_CURRENT_SOURCE_DIR}/pincode.c"
- )
-set( DEPENDENCIES common_sql )
-set( LIBRARIES ${GLOBAL_LIBRARIES} )
-set( INCLUDE_DIRS ${GLOBAL_INCLUDE_DIRS} ${COMMON_BASE_INCLUDE_DIRS} )
-set( DEFINITIONS "${GLOBAL_DEFINITIONS} ${COMMON_BASE_DEFINITIONS}" )
-set( SOURCE_FILES ${COMMON_BASE_HEADERS} ${COMMON_SQL_HEADERS} ${SQL_CHAR_HEADERS} ${SQL_CHAR_SOURCES} )
-source_group( common FILES ${COMMON_BASE_HEADERS} ${COMMON_SQL_HEADERS} )
-source_group( char FILES ${SQL_CHAR_HEADERS} ${SQL_CHAR_SOURCES} )
-include_directories( ${INCLUDE_DIRS} )
-add_executable( char-server ${SOURCE_FILES} )
-add_dependencies( char-server ${DEPENDENCIES} )
-target_link_libraries( char-server ${LIBRARIES} ${DEPENDENCIES} )
-set_target_properties( char-server PROPERTIES COMPILE_FLAGS "${DEFINITIONS}" )
-if( INSTALL_COMPONENT_RUNTIME )
- cpack_add_component( Runtime_charserver_sql DESCRIPTION "char-server (sql version)" DISPLAY_NAME "char-server" GROUP Runtime )
- install( TARGETS char-server
- DESTINATION "."
- COMPONENT Runtime_charserver_sql )
-endif( INSTALL_COMPONENT_RUNTIME )
-message( STATUS "Creating target char-server - done" )
-endif( BUILD_SQL_SERVERS )
diff --git a/src/char/Makefile.in b/src/char/Makefile.in
index a320579b5..59dc56076 100644
--- a/src/char/Makefile.in
+++ b/src/char/Makefile.in
@@ -1,76 +1,118 @@
-
-COMMON_H = $(shell ls ../common/*.h)
-
-MT19937AR_OBJ = ../../3rdparty/mt19937ar/mt19937ar.o
-MT19937AR_H = ../../3rdparty/mt19937ar/mt19937ar.h
-MT19937AR_INCLUDE = -I../../3rdparty/mt19937ar
-
-LIBCONFIG_OBJ = ../../3rdparty/libconfig/libconfig.o ../../3rdparty/libconfig/grammar.o \
- ../../3rdparty/libconfig/scanctx.o ../../3rdparty/libconfig/scanner.o ../../3rdparty/libconfig/strbuf.o
-LIBCONFIG_H = ../../3rdparty/libconfig/libconfig.h ../../3rdparty/libconfig/grammar.h \
- ../../3rdparty/libconfig/parsectx.h ../../3rdparty/libconfig/scanctx.h ../../3rdparty/libconfig/scanner.h \
- ../../3rdparty/libconfig/strbuf.h ../../3rdparty/libconfig/wincompat.h
-LIBCONFIG_INCLUDE = -I../../3rdparty/libconfig
-
-COMMON_SQL_OBJ = ../common/obj_sql/sql.o
-COMMON_H = ../common/sql.h
-
-CHAR_OBJ = obj_sql/char.o obj_sql/inter.o obj_sql/int_party.o obj_sql/int_guild.o \
- obj_sql/int_storage.o obj_sql/int_pet.o obj_sql/int_homun.o obj_sql/int_mail.o obj_sql/int_auction.o obj_sql/int_quest.o obj_sql/int_mercenary.o obj_sql/int_elemental.o obj_sql/pincode.o
-CHAR_H = char.h inter.h int_party.h int_guild.h int_storage.h int_pet.h int_homun.h int_mail.h int_auction.h int_quest.h int_mercenary.h int_elemental.h pincode.h
+# Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+# See the LICENSE file
+
+# @configure_input@
+
+CONFIG_D = ../config
+CONFIG_H = $(wildcard $(CONFIG_D)/*.h) $(wildcard $(CONFIG_D)/*/*.h)
+
+COMMON_D = ../common
+COMMON_H = $(wildcard $(COMMON_D)/*.h)
+SYSINFO_INC = $(COMMON_D)/sysinfo.inc
+
+LIBCONFIG_D = ../../3rdparty/libconfig
+LIBCONFIG_OBJ = $(addprefix $(LIBCONFIG_D)/, libconfig.o grammar.o scanctx.o \
+ scanner.o strbuf.o)
+LIBCONFIG_H = $(addprefix $(LIBCONFIG_D)/, libconfig.h grammar.h parsectx.h \
+ scanctx.h scanner.h strbuf.h wincompat.h)
+LIBCONFIG_INCLUDE = -I$(LIBCONFIG_D)
+
+MT19937AR_D = ../../3rdparty/mt19937ar
+MT19937AR_OBJ = $(MT19937AR_D)/mt19937ar.o
+MT19937AR_H = $(MT19937AR_D)/mt19937ar.h
+MT19937AR_INCLUDE = -I$(MT19937AR_D)
+
+CHAR_C = char.c inter.c int_auction.c int_elemental.c int_guild.c int_homun.c \
+ int_mail.c int_mercenary.c int_party.c int_pet.c int_quest.c \
+ int_storage.c pincode.c
+CHAR_OBJ = $(addprefix obj_sql/, $(patsubst %.c,%.o,$(CHAR_C)))
+CHAR_H = char.h inter.h int_auction.h int_elemental.h int_guild.h int_homun.h \
+ int_mail.h int_mercenary.h int_party.h int_pet.h int_quest.h \
+ int_storage.h pincode.h
HAVE_MYSQL=@HAVE_MYSQL@
ifeq ($(HAVE_MYSQL),yes)
- CHAR_SERVER_SQL_DEPENDS=obj_sql $(CHAR_OBJ) ../common/obj_sql/common_sql.a ../common/obj_all/common.a $(MT19937AR_OBJ)
+ CHAR_SERVER_SQL_DEPENDS=$(CHAR_OBJ) $(COMMON_D)/obj_sql/common_sql.a $(COMMON_D)/obj_all/common.a $(MT19937AR_OBJ) $(LIBCONFIG_OBJ) $(SYSINFO_INC)
else
CHAR_SERVER_SQL_DEPENDS=needs_mysql
endif
@SET_MAKE@
+CC = @CC@
+export CC
+
#####################################################################
-.PHONY : all char-server clean help
+.PHONY: all sql char-server clean buildclean help
+
+all: sql
-all: char-server
+sql: char-server
-char-server: $(CHAR_SERVER_SQL_DEPENDS)
- @echo " LD $@"
- @@CC@ @LDFLAGS@ -o ../../char-server@EXEEXT@ $(CHAR_OBJ) ../common/obj_sql/common_sql.a ../common/obj_all/common.a $(MT19937AR_OBJ) $(LIBCONFIG_OBJ) @LIBS@ @MYSQL_LIBS@
+buildclean:
+ @echo " CLEAN char (build temp files)"
+ @rm -rf *.o obj_sql
-clean:
+clean: buildclean
@echo " CLEAN char"
- @rm -rf *.o obj_sql ../../char-server@EXEEXT@
+ @rm -rf ../../char-server@EXEEXT@
help:
@echo "possible targets are 'char-server' 'all' 'clean' 'help'"
- @echo "'char-server' - char server (SQL version)"
- @echo "'all' - builds all above targets"
- @echo "'clean' - cleans builds and objects"
- @echo "'help' - outputs this message"
+ @echo "'char-server' - char server"
+ @echo "'all' - builds all above targets"
+ @echo "'clean' - cleans builds and objects"
+ @echo "'buildclean' - cleans build temporary (object) files, without deleting the"
+ @echo " executables"
+ @echo "'help' - outputs this message"
#####################################################################
+Makefile: Makefile.in
+ @$(MAKE) -C ../.. src/char/Makefile
+
+$(SYSINFO_INC): $(CHAR_C) $(CHAR_H) $(COMMON_H) $(CONFIG_H) $(MT19937AR_H) $(LIBCONFIG_H)
+ @echo " MAKE $@"
+ @$(MAKE) -C ../.. sysinfo
+
needs_mysql:
@echo "MySQL not found or disabled by the configure script"
@exit 1
+# object directories
+
obj_sql:
@echo " MKDIR obj_sql"
@-mkdir obj_sql
-obj_sql/%.o: %.c $(CHAR_H) $(COMMON_H) $(COMMON_SQL_H) $(MT19937AR_H) $(LIBCONFIG_H)
+# executables
+
+char-server: ../../char-server@EXEEXT@
+
+../../char-server@EXEEXT@: $(CHAR_SERVER_SQL_DEPENDS) Makefile
+ @echo " LD $(notdir $@)"
+ @$(CC) @LDFLAGS@ -o ../../char-server@EXEEXT@ $(CHAR_OBJ) $(COMMON_D)/obj_sql/common_sql.a \
+ $(COMMON_D)/obj_all/common.a $(MT19937AR_OBJ) $(LIBCONFIG_OBJ) @LIBS@ @MYSQL_LIBS@
+
+# char object files
+
+obj_sql/%.o: %.c $(CHAR_H) $(COMMON_H) $(CONFIG_H) $(MT19937AR_H) $(LIBCONFIG_H) | obj_sql
@echo " CC $<"
- @@CC@ @CFLAGS@ $(MT19937AR_INCLUDE) $(LIBCONFIG_INCLUDE) @MYSQL_CFLAGS@ @CPPFLAGS@ -c $(OUTPUT_OPTION) $<
+ @$(CC) @CFLAGS@ @DEFS@ $(MT19937AR_INCLUDE) $(LIBCONFIG_INCLUDE) @MYSQL_CFLAGS@ @CPPFLAGS@ -c $(OUTPUT_OPTION) $<
# missing object files
-../common/obj_all/common.a:
- @$(MAKE) -C ../common sql
+$(COMMON_D)/obj_all/common.a:
+ @echo " MAKE $@"
+ @$(MAKE) -C $(COMMON_D) sql
-../common/obj_sql/common_sql.a:
- @$(MAKE) -C ../common sql
+$(COMMON_D)/obj_sql/common_sql.a:
+ @echo " MAKE $@"
+ @$(MAKE) -C $(COMMON_D) sql
-MT19937AR_OBJ:
- @$(MAKE) -C ../../3rdparty/mt19937ar
+$(MT19937AR_OBJ):
+ @echo " MAKE $@"
+ @$(MAKE) -C $(MT19937AR_D)
-LIBCONFIG_OBJ:
- @$(MAKE) -C ../../3rdparty/libconfig
+$(LIBCONFIG_OBJ):
+ @echo " MAKE $@"
+ @$(MAKE) -C $(LIBCONFIG_D)
diff --git a/src/char/char.c b/src/char/char.c
index 7dfb6861c..9abb17257 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -2,7 +2,30 @@
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams
+#define HERCULES_CORE
+
+#include "../config/core.h" // CONSOLE_INPUT
+#include "char.h"
+
+#include <signal.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <time.h>
+
+#include "int_elemental.h"
+#include "int_guild.h"
+#include "int_homun.h"
+#include "int_mercenary.h"
+#include "int_party.h"
+#include "int_storage.h"
+#include "inter.h"
+#include "pincode.h"
+#include "../common/HPM.h"
#include "../common/cbasetypes.h"
+#include "../common/console.h"
#include "../common/core.h"
#include "../common/db.h"
#include "../common/malloc.h"
@@ -13,23 +36,6 @@
#include "../common/strlib.h"
#include "../common/timer.h"
#include "../common/utils.h"
-#include "int_guild.h"
-#include "int_homun.h"
-#include "int_mercenary.h"
-#include "int_elemental.h"
-#include "int_party.h"
-#include "int_storage.h"
-#include "char.h"
-#include "inter.h"
-#include "pincode.h"
-
-#include <sys/types.h>
-#include <time.h>
-#include <signal.h>
-#include <string.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
// private declarations
#define CHAR_CONF_NAME "conf/char-server.conf"
@@ -43,7 +49,6 @@ char inventory_db[256] = "inventory";
char charlog_db[256] = "charlog";
char storage_db[256] = "storage";
char interlog_db[256] = "interlog";
-char reg_db[256] = "global_reg_value";
char skill_db[256] = "skill";
char memo_db[256] = "memo";
char guild_db[256] = "guild";
@@ -66,7 +71,13 @@ char skill_homunculus_db[256] = "skill_homunculus";
char mercenary_db[256] = "mercenary";
char mercenary_owner_db[256] = "mercenary_owner";
char ragsrvinfo_db[256] = "ragsrvinfo";
+char elemental_db[256] = "elemental";
char interreg_db[32] = "interreg";
+char account_data_db[256] = "account_data";
+char acc_reg_num_db[32] = "acc_reg_num_db";
+char acc_reg_str_db[32] = "acc_reg_str_db";
+char char_reg_str_db[32] = "char_reg_str_db";
+char char_reg_num_db[32] = "char_reg_num_db";
// show loading/saving messages
int save_log = 1;
@@ -75,7 +86,9 @@ static DBMap* char_db_; // int char_id -> struct mmo_charstatus*
char db_path[1024] = "db";
-int db_use_sqldbs;
+int db_use_sql_item_db;
+int db_use_sql_mob_db;
+int db_use_sql_mob_skill_db;
struct mmo_map_server {
int fd;
@@ -99,12 +112,13 @@ uint32 char_ip = 0;
char bind_ip_str[128];
uint32 bind_ip = INADDR_ANY;
uint16 char_port = 6121;
-int char_maintenance = 0;
+int char_server_type = 0;
+int char_maintenance_min_group_id = 0;
bool char_new = true;
int char_new_display = 0;
bool name_ignoring_case = false; // Allow or not identical name for characters but with a different case by [Yor]
-int char_name_option = 0; // Option to know which letters/symbols are authorised in the name of a character (0: all, 1: only those in char_name_letters, 2: all EXCEPT those in char_name_letters) by [Yor]
+int char_name_option = 0; // Option to know which letters/symbols are authorized in the name of a character (0: all, 1: only those in char_name_letters, 2: all EXCEPT those in char_name_letters) by [Yor]
char unknown_char_name[NAME_LENGTH] = "Unknown"; // Name to use when the requested name cannot be determined
#define TRIM_CHARS "\255\xA0\032\t\x0A\x0D " //The following characters are trimmed regardless because they cause confusion and problems on the servers. [Skotlex]
char char_name_letters[1024] = ""; // list of letters/symbols allowed (or not) in a character name. by [Yor]
@@ -112,8 +126,10 @@ char char_name_letters[1024] = ""; // list of letters/symbols allowed (or not) i
int char_del_level = 0; //From which level u can delete character [Lupus]
int char_del_delay = 86400;
-int log_char = 1; // loggin char or not [devil]
-int log_inter = 1; // loggin inter or not [devil]
+int log_char = 1; // logging char or not [devil]
+int log_inter = 1; // logging inter or not [devil]
+
+int char_aegis_delete = 0; // Verify if char is in guild/party or char and reacts as Aegis does (doesn't allow deletion), see char_delete2_req for more information
// Advanced subnet check [LuzZza]
struct s_subnet {
@@ -127,12 +143,12 @@ int max_connect_user = -1;
int gm_allow_group = -1;
int autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
int start_zeny = 0;
-int start_items[MAX_START_ITEMS*2];
+int start_items[MAX_START_ITEMS*3];
int guild_exp_rate = 100;
//Custom limits for the fame lists. [Skotlex]
int fame_list_size_chemist = MAX_FAME_LIST;
-int fame_list_size_smith = MAX_FAME_LIST;
+int fame_list_size_smith = MAX_FAME_LIST;
int fame_list_size_taekwon = MAX_FAME_LIST;
// Char-server-side stored fame lists [DracoRPG]
@@ -173,7 +189,7 @@ static DBMap* auth_db; // int account_id -> struct auth_node*
// Online User Database
//-----------------------------------------------------
-static int chardb_waiting_disconnect(int tid, unsigned int tick, int id, intptr_t data);
+static int chardb_waiting_disconnect(int tid, int64 tick, int id, intptr_t data);
int delete_char_sql(int char_id);
/**
@@ -185,7 +201,7 @@ static DBData create_online_char_data(DBKey key, va_list args)
CREATE(character, struct online_char_data, 1);
character->account_id = key.i;
character->char_id = -1;
- character->server = -1;
+ character->server = -1;
character->pincode_enable = -1;
character->fd = -1;
character->waiting_disconnect = INVALID_TIMER;
@@ -208,7 +224,7 @@ void set_char_charselect(int account_id)
character->pincode_enable = *pincode->charselect + *pincode->enabled;
if(character->waiting_disconnect != INVALID_TIMER) {
- iTimer->delete_timer(character->waiting_disconnect, chardb_waiting_disconnect);
+ timer->delete(character->waiting_disconnect, chardb_waiting_disconnect);
character->waiting_disconnect = INVALID_TIMER;
}
@@ -249,7 +265,7 @@ void set_char_online(int map_id, int char_id, int account_id)
//Get rid of disconnect timer
if(character->waiting_disconnect != INVALID_TIMER) {
- iTimer->delete_timer(character->waiting_disconnect, chardb_waiting_disconnect);
+ timer->delete(character->waiting_disconnect, chardb_waiting_disconnect);
character->waiting_disconnect = INVALID_TIMER;
}
@@ -294,7 +310,7 @@ void set_char_offline(int char_id, int account_id)
server[character->server].users--;
if(character->waiting_disconnect != INVALID_TIMER){
- iTimer->delete_timer(character->waiting_disconnect, chardb_waiting_disconnect);
+ timer->delete(character->waiting_disconnect, chardb_waiting_disconnect);
character->waiting_disconnect = INVALID_TIMER;
}
@@ -324,15 +340,15 @@ void set_char_offline(int char_id, int account_id)
static int char_db_setoffline(DBKey key, DBData *data, va_list ap)
{
struct online_char_data* character = (struct online_char_data*)DB->data2ptr(data);
- int server = va_arg(ap, int);
- if (server == -1) {
+ int server_id = va_arg(ap, int);
+ if (server_id == -1) {
character->char_id = -1;
character->server = -1;
if(character->waiting_disconnect != INVALID_TIMER){
- iTimer->delete_timer(character->waiting_disconnect, chardb_waiting_disconnect);
+ timer->delete(character->waiting_disconnect, chardb_waiting_disconnect);
character->waiting_disconnect = INVALID_TIMER;
}
- } else if (character->server == server)
+ } else if (character->server == server_id)
character->server = -2; //In some map server that we aren't connected to.
return 0;
}
@@ -457,7 +473,8 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
(p->ele_id != cp->ele_id) || (p->shield != cp->shield) || (p->head_top != cp->head_top) ||
(p->head_mid != cp->head_mid) || (p->head_bottom != cp->head_bottom) || (p->delete_date != cp->delete_date) ||
(p->rename != cp->rename) || (p->slotchange != cp->slotchange) || (p->robe != cp->robe) ||
- (p->show_equip != cp->show_equip) || (p->allow_party != cp->allow_party)
+ (p->show_equip != cp->show_equip) || (p->allow_party != cp->allow_party) || (p->font != cp->font) ||
+ (p->uniqueitem_counter != cp->uniqueitem_counter )
) { //Save status
unsigned int opt = 0;
@@ -473,7 +490,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
"`option`='%d',`party_id`='%d',`guild_id`='%d',`pet_id`='%d',`homun_id`='%d',`elemental_id`='%d',"
"`weapon`='%d',`shield`='%d',`head_top`='%d',`head_mid`='%d',`head_bottom`='%d',"
"`last_map`='%s',`last_x`='%d',`last_y`='%d',`save_map`='%s',`save_x`='%d',`save_y`='%d', `rename`='%d',"
- "`delete_date`='%lu',`robe`='%d',`slotchange`='%d', `char_opt`='%u'"
+ "`delete_date`='%lu',`robe`='%d',`slotchange`='%d', `char_opt`='%u', `font`='%u', `uniqueitem_counter` ='%u'"
" WHERE `account_id`='%d' AND `char_id` = '%d'",
char_db, p->base_level, p->job_level,
p->base_exp, p->job_exp, p->zeny,
@@ -484,7 +501,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
mapindex_id2name(p->last_point.map), p->last_point.x, p->last_point.y,
mapindex_id2name(p->save_point.map), p->save_point.x, p->save_point.y, p->rename,
(unsigned long)p->delete_date, // FIXME: platform-dependent size
- p->robe,p->slotchange,opt,
+ p->robe,p->slotchange,opt,p->font,p->uniqueitem_counter,
p->account_id, p->char_id) )
{
Sql_ShowDebug(sql_handle);
@@ -492,6 +509,14 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
} else
strcat(save_status, " status");
}
+
+ if( p->bank_vault != cp->bank_vault || p->mod_exp != cp->mod_exp || p->mod_drop != cp->mod_drop || p->mod_death != cp->mod_death ) {
+ if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`account_id`,`bank_vault`,`base_exp`,`base_drop`,`base_death`) VALUES ('%d','%d','%d','%d','%d')",account_data_db,p->account_id,p->bank_vault,p->mod_exp,p->mod_drop,p->mod_death) ) {
+ Sql_ShowDebug(sql_handle);
+ errors++;
+ } else
+ strcat(save_status, " accdata");
+ }
//Values that will seldom change (to speed up saving)
if (
@@ -670,6 +695,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p)
strcat(save_status, " hotkeys");
}
#endif
+
StrBuf->Destroy(&buf);
if (save_status[0]!='\0' && save_log)
ShowInfo("Saved char %d - %s:%s.\n", char_id, p->name, save_status);
@@ -709,8 +735,8 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit
// it significantly reduces cpu load on the database server.
StrBuf->Init(&buf);
- StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`");
- for( j = 0; j < MAX_SLOTS; ++j )
+ StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `bound`");
+ for( j = 0; j < MAX_SLOTS; ++j )
StrBuf->Printf(&buf, ", `card%d`", j);
StrBuf->Printf(&buf, " FROM `%s` WHERE `%s`='%d'", tablename, selectoption, id);
@@ -727,13 +753,14 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit
SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &item.id, 0, NULL, NULL);
SQL->StmtBindColumn(stmt, 1, SQLDT_SHORT, &item.nameid, 0, NULL, NULL);
SQL->StmtBindColumn(stmt, 2, SQLDT_SHORT, &item.amount, 0, NULL, NULL);
- SQL->StmtBindColumn(stmt, 3, SQLDT_USHORT, &item.equip, 0, NULL, NULL);
+ SQL->StmtBindColumn(stmt, 3, SQLDT_UINT, &item.equip, 0, NULL, NULL);
SQL->StmtBindColumn(stmt, 4, SQLDT_CHAR, &item.identify, 0, NULL, NULL);
SQL->StmtBindColumn(stmt, 5, SQLDT_CHAR, &item.refine, 0, NULL, NULL);
SQL->StmtBindColumn(stmt, 6, SQLDT_CHAR, &item.attribute, 0, NULL, NULL);
SQL->StmtBindColumn(stmt, 7, SQLDT_UINT, &item.expire_time, 0, NULL, NULL);
- for( j = 0; j < MAX_SLOTS; ++j )
- SQL->StmtBindColumn(stmt, 8+j, SQLDT_SHORT, &item.card[j], 0, NULL, NULL);
+ SQL->StmtBindColumn(stmt, 8, SQLDT_UCHAR, &item.bound, 0, NULL, NULL);
+ for( j = 0; j < MAX_SLOTS; ++j )
+ SQL->StmtBindColumn(stmt, 9+j, SQLDT_SHORT, &item.card[j], 0, NULL, NULL);
// bit array indicating which inventory items have already been matched
flag = (bool*) aCalloc(max, sizeof(bool));
@@ -760,17 +787,18 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit
items[i].identify == item.identify &&
items[i].refine == item.refine &&
items[i].attribute == item.attribute &&
- items[i].expire_time == item.expire_time )
+ items[i].expire_time == item.expire_time &&
+ items[i].bound == item.bound )
; //Do nothing.
else
{
// update all fields.
StrBuf->Clear(&buf);
- StrBuf->Printf(&buf, "UPDATE `%s` SET `amount`='%d', `equip`='%d', `identify`='%d', `refine`='%d',`attribute`='%d', `expire_time`='%u'",
- tablename, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time);
- for( j = 0; j < MAX_SLOTS; ++j )
+ StrBuf->Printf(&buf, "UPDATE `%s` SET `amount`='%d', `equip`='%d', `identify`='%d', `refine`='%d',`attribute`='%d', `expire_time`='%u', `bound`='%d'",
+ tablename, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time, items[i].bound);
+ for( j = 0; j < MAX_SLOTS; ++j )for( j = 0; j < MAX_SLOTS; ++j )
StrBuf->Printf(&buf, ", `card%d`=%d", j, items[i].card[j]);
- StrBuf->Printf(&buf, " WHERE `id`='%d' LIMIT 1", item.id);
+ StrBuf->Printf(&buf, " WHERE `id`='%d' LIMIT 1", item.id);
if( SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) )
{
@@ -795,8 +823,8 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit
SQL->StmtFree(stmt);
StrBuf->Clear(&buf);
- StrBuf->Printf(&buf, "INSERT INTO `%s`(`%s`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `unique_id`", tablename, selectoption);
- for( j = 0; j < MAX_SLOTS; ++j )
+ StrBuf->Printf(&buf, "INSERT INTO `%s`(`%s`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `bound`, `unique_id`", tablename, selectoption);
+ for( j = 0; j < MAX_SLOTS; ++j )
StrBuf->Printf(&buf, ", `card%d`", j);
StrBuf->AppendStr(&buf, ") VALUES ");
@@ -813,15 +841,12 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit
else
found = true;
- StrBuf->Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%u', '%"PRIu64"'",
- id, items[i].nameid, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time, items[i].unique_id);
- for( j = 0; j < MAX_SLOTS; ++j )
+ StrBuf->Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%u', '%d', '%"PRIu64"'",
+ id, items[i].nameid, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time, items[i].bound, items[i].unique_id);
+ for( j = 0; j < MAX_SLOTS; ++j )
StrBuf->Printf(&buf, ", '%d'", items[i].card[j]);
StrBuf->AppendStr(&buf, ")");
-
- updateLastUid(items[i].unique_id); // Unique Non Stackable Item ID
}
- dbUpdateUid(sql_handle); // Unique Non Stackable Item ID
if( found && SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) )
{
@@ -853,8 +878,8 @@ int inventory_to_sql(const struct item items[], int max, int id) {
// it significantly reduces cpu load on the database server.
StrBuf->Init(&buf);
- StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`");
- for( j = 0; j < MAX_SLOTS; ++j )
+ StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`, `bound`");
+ for( j = 0; j < MAX_SLOTS; ++j )
StrBuf->Printf(&buf, ", `card%d`", j);
StrBuf->Printf(&buf, " FROM `%s` WHERE `char_id`='%d'", inventory_db, id);
@@ -871,14 +896,15 @@ int inventory_to_sql(const struct item items[], int max, int id) {
SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &item.id, 0, NULL, NULL);
SQL->StmtBindColumn(stmt, 1, SQLDT_SHORT, &item.nameid, 0, NULL, NULL);
SQL->StmtBindColumn(stmt, 2, SQLDT_SHORT, &item.amount, 0, NULL, NULL);
- SQL->StmtBindColumn(stmt, 3, SQLDT_USHORT, &item.equip, 0, NULL, NULL);
+ SQL->StmtBindColumn(stmt, 3, SQLDT_UINT, &item.equip, 0, NULL, NULL);
SQL->StmtBindColumn(stmt, 4, SQLDT_CHAR, &item.identify, 0, NULL, NULL);
SQL->StmtBindColumn(stmt, 5, SQLDT_CHAR, &item.refine, 0, NULL, NULL);
SQL->StmtBindColumn(stmt, 6, SQLDT_CHAR, &item.attribute, 0, NULL, NULL);
SQL->StmtBindColumn(stmt, 7, SQLDT_UINT, &item.expire_time, 0, NULL, NULL);
SQL->StmtBindColumn(stmt, 8, SQLDT_CHAR, &item.favorite, 0, NULL, NULL);
- for( j = 0; j < MAX_SLOTS; ++j )
- SQL->StmtBindColumn(stmt, 9+j, SQLDT_SHORT, &item.card[j], 0, NULL, NULL);
+ SQL->StmtBindColumn(stmt, 9, SQLDT_UCHAR, &item.bound, 0, NULL, NULL);
+ for( j = 0; j < MAX_SLOTS; ++j )
+ SQL->StmtBindColumn(stmt, 10+j, SQLDT_SHORT, &item.card[j], 0, NULL, NULL);
// bit array indicating which inventory items have already been matched
flag = (bool*) aCalloc(max, sizeof(bool));
@@ -904,15 +930,16 @@ int inventory_to_sql(const struct item items[], int max, int id) {
items[i].refine == item.refine &&
items[i].attribute == item.attribute &&
items[i].expire_time == item.expire_time &&
- items[i].favorite == item.favorite )
+ items[i].favorite == item.favorite &&
+ items[i].bound == item.bound )
; //Do nothing.
else {
// update all fields.
StrBuf->Clear(&buf);
- StrBuf->Printf(&buf, "UPDATE `%s` SET `amount`='%d', `equip`='%d', `identify`='%d', `refine`='%d',`attribute`='%d', `expire_time`='%u', `favorite`='%d'",
- inventory_db, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time, items[i].favorite);
- for( j = 0; j < MAX_SLOTS; ++j )
- StrBuf->Printf(&buf, ", `card%d`=%d", j, items[i].card[j]);
+ StrBuf->Printf(&buf, "UPDATE `%s` SET `amount`='%d', `equip`='%d', `identify`='%d', `refine`='%d',`attribute`='%d', `expire_time`='%u', `favorite`='%d', `bound`='%d'",
+ inventory_db, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time, items[i].favorite, items[i].bound);
+ for( j = 0; j < MAX_SLOTS; ++j )
+ StrBuf->Printf(&buf, ", `card%d`=%d", j, items[i].card[j]);
StrBuf->Printf(&buf, " WHERE `id`='%d' LIMIT 1", item.id);
if( SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) {
@@ -935,8 +962,8 @@ int inventory_to_sql(const struct item items[], int max, int id) {
SQL->StmtFree(stmt);
StrBuf->Clear(&buf);
- StrBuf->Printf(&buf, "INSERT INTO `%s` (`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`, `unique_id`", inventory_db);
- for( j = 0; j < MAX_SLOTS; ++j )
+ StrBuf->Printf(&buf, "INSERT INTO `%s` (`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`, `bound`, `unique_id`", inventory_db);
+ for( j = 0; j < MAX_SLOTS; ++j )
StrBuf->Printf(&buf, ", `card%d`", j);
StrBuf->AppendStr(&buf, ") VALUES ");
@@ -952,15 +979,12 @@ int inventory_to_sql(const struct item items[], int max, int id) {
else
found = true;
- StrBuf->Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%u', '%d', '%"PRIu64"'",
- id, items[i].nameid, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time, items[i].favorite, items[i].unique_id);
- for( j = 0; j < MAX_SLOTS; ++j )
+ StrBuf->Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%u', '%d', '%d', '%"PRIu64"'",
+ id, items[i].nameid, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time, items[i].favorite, items[i].bound, items[i].unique_id);
+ for( j = 0; j < MAX_SLOTS; ++j )
StrBuf->Printf(&buf, ", '%d'", items[i].card[j]);
StrBuf->AppendStr(&buf, ")");
-
- updateLastUid(items[i].unique_id);// Unique Non Stackable Item ID
}
- dbUpdateUid(sql_handle);
if( found && SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) {
Sql_ShowDebug(sql_handle);
@@ -984,6 +1008,7 @@ int mmo_chars_fromsql(struct char_session_data* sd, uint8* buf)
struct mmo_charstatus p;
int j = 0, i;
char last_map[MAP_NAME_LENGTH_EXT];
+ time_t unban_time = 0;
stmt = SQL->StmtMalloc(sql_handle);
if( stmt == NULL ) {
@@ -992,8 +1017,10 @@ int mmo_chars_fromsql(struct char_session_data* sd, uint8* buf)
}
memset(&p, 0, sizeof(p));
- for(i = 0 ; i < MAX_CHARS; i++ )
+ for(i = 0 ; i < MAX_CHARS; i++ ) {
sd->found_char[i] = -1;
+ sd->unban_time[i] = 0;
+ }
// read char data
if( SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT "
@@ -1001,7 +1028,7 @@ int mmo_chars_fromsql(struct char_session_data* sd, uint8* buf)
"`str`,`agi`,`vit`,`int`,`dex`,`luk`,`max_hp`,`hp`,`max_sp`,`sp`,"
"`status_point`,`skill_point`,`option`,`karma`,`manner`,`hair`,`hair_color`,"
"`clothes_color`,`weapon`,`shield`,`head_top`,`head_mid`,`head_bottom`,`last_map`,`rename`,`delete_date`,"
- "`robe`,`slotchange`"
+ "`robe`,`slotchange`,`unban_time`"
" FROM `%s` WHERE `account_id`='%d' AND `char_num` < '%d'", char_db, sd->account_id, MAX_CHARS)
|| SQL_ERROR == SQL->StmtExecute(stmt)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &p.char_id, 0, NULL, NULL)
@@ -1037,10 +1064,11 @@ int mmo_chars_fromsql(struct char_session_data* sd, uint8* buf)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 30, SQLDT_SHORT, &p.head_mid, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 31, SQLDT_SHORT, &p.head_bottom, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 32, SQLDT_STRING, &last_map, sizeof(last_map), NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 33, SQLDT_USHORT, &p.rename, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 33, SQLDT_USHORT, &p.rename, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 34, SQLDT_UINT32, &p.delete_date, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 35, SQLDT_SHORT, &p.robe, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 36, SQLDT_USHORT, &p.slotchange, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 37, SQLDT_LONG, &unban_time, 0, NULL, NULL)
)
{
SqlStmt_ShowDebug(stmt);
@@ -1049,8 +1077,9 @@ int mmo_chars_fromsql(struct char_session_data* sd, uint8* buf)
}
for( i = 0; i < MAX_CHARS && SQL_SUCCESS == SQL->StmtNextRow(stmt); i++ ) {
- p.last_point.map = mapindex_name2id(last_map);
+ p.last_point.map = mapindex->name2id(last_map);
sd->found_char[p.slot] = p.char_id;
+ sd->unban_time[p.slot] = unban_time;
j += mmo_char_tobuf(WBUFP(buf, j), &p);
}
@@ -1080,6 +1109,7 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything
int hotkey_num;
#endif
unsigned int opt;
+ int account_id;
memset(p, 0, sizeof(struct mmo_charstatus));
@@ -1099,7 +1129,7 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything
"`status_point`,`skill_point`,`option`,`karma`,`manner`,`party_id`,`guild_id`,`pet_id`,`homun_id`,`elemental_id`,`hair`,"
"`hair_color`,`clothes_color`,`weapon`,`shield`,`head_top`,`head_mid`,`head_bottom`,`last_map`,`last_x`,`last_y`,"
"`save_map`,`save_x`,`save_y`,`partner_id`,`father`,`mother`,`child`,`fame`,`rename`,`delete_date`,`robe`,`slotchange`,"
- "`char_opt`"
+ "`char_opt`,`font`,`uniqueitem_counter`"
" FROM `%s` WHERE `char_id`=? LIMIT 1", char_db)
|| SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0)
|| SQL_ERROR == SQL->StmtExecute(stmt)
@@ -1132,7 +1162,7 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 26, SQLDT_INT, &p->guild_id, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 27, SQLDT_INT, &p->pet_id, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 28, SQLDT_INT, &p->hom_id, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 29, SQLDT_INT, &p->ele_id, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 29, SQLDT_INT, &p->ele_id, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 30, SQLDT_SHORT, &p->hair, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 31, SQLDT_SHORT, &p->hair_color, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 32, SQLDT_SHORT, &p->clothes_color, 0, NULL, NULL)
@@ -1152,11 +1182,13 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 46, SQLDT_INT, &p->mother, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 47, SQLDT_INT, &p->child, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 48, SQLDT_INT, &p->fame, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 49, SQLDT_USHORT, &p->rename, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 49, SQLDT_USHORT, &p->rename, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 50, SQLDT_UINT32, &p->delete_date, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 51, SQLDT_SHORT, &p->robe, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 52, SQLDT_USHORT, &p->slotchange, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 53, SQLDT_UINT, &opt, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 53, SQLDT_UINT, &opt, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 54, SQLDT_UCHAR, &p->font, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 55, SQLDT_UINT, &p->uniqueitem_counter, 0, NULL, NULL)
)
{
SqlStmt_ShowDebug(stmt);
@@ -1169,17 +1201,20 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything
SQL->StmtFree(stmt);
return 0;
}
- p->last_point.map = mapindex_name2id(last_map);
- p->save_point.map = mapindex_name2id(save_map);
+
+ account_id = p->account_id;
+
+ p->last_point.map = mapindex->name2id(last_map);
+ p->save_point.map = mapindex->name2id(save_map);
if( p->last_point.map == 0 ) {
- p->last_point.map = (unsigned short)strdb_iget(mapindex_db, MAP_DEFAULT);
+ p->last_point.map = (unsigned short)strdb_iget(mapindex->db, MAP_DEFAULT);
p->last_point.x = MAP_DEFAULT_X;
p->last_point.y = MAP_DEFAULT_Y;
}
if( p->save_point.map == 0 ) {
- p->save_point.map = (unsigned short)strdb_iget(mapindex_db, MAP_DEFAULT);
+ p->save_point.map = (unsigned short)strdb_iget(mapindex->db, MAP_DEFAULT);
p->save_point.x = MAP_DEFAULT_X;
p->save_point.y = MAP_DEFAULT_Y;
}
@@ -1203,35 +1238,36 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything
SqlStmt_ShowDebug(stmt);
for( i = 0; i < MAX_MEMOPOINTS && SQL_SUCCESS == SQL->StmtNextRow(stmt); ++i ) {
- tmp_point.map = mapindex_name2id(point_map);
+ tmp_point.map = mapindex->name2id(point_map);
memcpy(&p->memo_point[i], &tmp_point, sizeof(tmp_point));
}
strcat(t_msg, " memo");
//read inventory
- //`inventory` (`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, `expire_time`, `favorite`, `unique_id`)
- StrBuf->Init(&buf);
- StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`, `unique_id`");
- for( i = 0; i < MAX_SLOTS; ++i )
+ //`inventory` (`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, `expire_time`, `favorite`, `bound`, `unique_id`)
+ StrBuf->Init(&buf);
+ StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`, `bound`, `unique_id`");
+ for( i = 0; i < MAX_SLOTS; ++i )
StrBuf->Printf(&buf, ", `card%d`", i);
StrBuf->Printf(&buf, " FROM `%s` WHERE `char_id`=? LIMIT %d", inventory_db, MAX_INVENTORY);
if( SQL_ERROR == SQL->StmtPrepareStr(stmt, StrBuf->Value(&buf))
|| SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0)
|| SQL_ERROR == SQL->StmtExecute(stmt)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &tmp_item.id, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_SHORT, &tmp_item.nameid, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_SHORT, &tmp_item.amount, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_USHORT, &tmp_item.equip, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 4, SQLDT_CHAR, &tmp_item.identify, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 5, SQLDT_CHAR, &tmp_item.refine, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 6, SQLDT_CHAR, &tmp_item.attribute, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 7, SQLDT_UINT, &tmp_item.expire_time, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 8, SQLDT_CHAR, &tmp_item.favorite, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 9, SQLDT_ULONGLONG, &tmp_item.unique_id, 0, NULL, NULL) )
- SqlStmt_ShowDebug(stmt);
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &tmp_item.id, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_SHORT, &tmp_item.nameid, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_SHORT, &tmp_item.amount, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_UINT, &tmp_item.equip, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 4, SQLDT_CHAR, &tmp_item.identify, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 5, SQLDT_CHAR, &tmp_item.refine, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 6, SQLDT_CHAR, &tmp_item.attribute, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 7, SQLDT_UINT, &tmp_item.expire_time, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 8, SQLDT_CHAR, &tmp_item.favorite, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 9, SQLDT_UCHAR, &tmp_item.bound, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 10, SQLDT_UINT64, &tmp_item.unique_id, 0, NULL, NULL) )
+ SqlStmt_ShowDebug(stmt);
for( i = 0; i < MAX_SLOTS; ++i )
- if( SQL_ERROR == SQL->StmtBindColumn(stmt, 10+i, SQLDT_SHORT, &tmp_item.card[i], 0, NULL, NULL) )
+ if( SQL_ERROR == SQL->StmtBindColumn(stmt, 11+i, SQLDT_SHORT, &tmp_item.card[i], 0, NULL, NULL) )
SqlStmt_ShowDebug(stmt);
for( i = 0; i < MAX_INVENTORY && SQL_SUCCESS == SQL->StmtNextRow(stmt); ++i )
@@ -1240,28 +1276,30 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything
strcat(t_msg, " inventory");
//read cart
- //`cart_inventory` (`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, expire_time`, `unique_id`)
- StrBuf->Clear(&buf);
- StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `unique_id`");
- for( j = 0; j < MAX_SLOTS; ++j )
+ //`cart_inventory` (`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, expire_time`, `bound`, `unique_id`)
+ StrBuf->Clear(&buf);
+ StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `bound`, `unique_id`");
+ for( j = 0; j < MAX_SLOTS; ++j )
StrBuf->Printf(&buf, ", `card%d`", j);
StrBuf->Printf(&buf, " FROM `%s` WHERE `char_id`=? LIMIT %d", cart_db, MAX_CART);
+ memset(&tmp_item, 0, sizeof(tmp_item));
if( SQL_ERROR == SQL->StmtPrepareStr(stmt, StrBuf->Value(&buf))
|| SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0)
|| SQL_ERROR == SQL->StmtExecute(stmt)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &tmp_item.id, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_SHORT, &tmp_item.nameid, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_SHORT, &tmp_item.amount, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_USHORT, &tmp_item.equip, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_UINT, &tmp_item.equip, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 4, SQLDT_CHAR, &tmp_item.identify, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 5, SQLDT_CHAR, &tmp_item.refine, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 6, SQLDT_CHAR, &tmp_item.attribute, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 7, SQLDT_UINT, &tmp_item.expire_time, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 8, SQLDT_ULONGLONG, &tmp_item.unique_id, 0, NULL, NULL) )
- SqlStmt_ShowDebug(stmt);
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 8, SQLDT_UCHAR, &tmp_item.bound, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 9, SQLDT_UINT64, &tmp_item.unique_id, 0, NULL, NULL) )
+ SqlStmt_ShowDebug(stmt);
for( i = 0; i < MAX_SLOTS; ++i )
- if( SQL_ERROR == SQL->StmtBindColumn(stmt, 9+i, SQLDT_SHORT, &tmp_item.card[i], 0, NULL, NULL) )
+ if( SQL_ERROR == SQL->StmtBindColumn(stmt, 10+i, SQLDT_SHORT, &tmp_item.card[i], 0, NULL, NULL) )
SqlStmt_ShowDebug(stmt);
for( i = 0; i < MAX_CART && SQL_SUCCESS == SQL->StmtNextRow(stmt); ++i )
@@ -1333,8 +1371,23 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything
mercenary_owner_fromsql(char_id, p);
strcat(t_msg, " mercenary");
+ /* default */
+ p->mod_exp = p->mod_drop = p->mod_death = 100;
+
+ //`account_data` (`account_id`,`bank_vault`,`base_exp`,`base_drop`,`base_death`)
+ if( SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT `bank_vault`,`base_exp`,`base_drop`,`base_death` FROM `%s` WHERE `account_id`=? LIMIT 1", account_data_db)
+ || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &account_id, 0)
+ || SQL_ERROR == SQL->StmtExecute(stmt)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &p->bank_vault, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_USHORT, &p->mod_exp, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_USHORT, &p->mod_drop, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_USHORT, &p->mod_death, 0, NULL, NULL) )
+ SqlStmt_ShowDebug(stmt);
+
+ if( SQL_SUCCESS == SQL->StmtNextRow(stmt) )
+ strcat(t_msg, " accdata");
- if (save_log) ShowInfo("Loaded char (%d - %s): %s\n", char_id, p->name, t_msg); //ok. all data load successfuly!
+ if (save_log) ShowInfo("Loaded char (%d - %s): %s\n", char_id, p->name, t_msg); //ok. all data load successfully!
SQL->StmtFree(stmt);
StrBuf->Destroy(&buf);
@@ -1360,7 +1413,7 @@ int mmo_char_sql_init(void)
//and send the loginserver the new state....
// Force all users offline in sql when starting char-server
- // (useful when servers crashs and don't clean the database)
+ // (useful when servers crashes and don't clean the database)
set_all_offline_sql();
return 0;
@@ -1415,7 +1468,7 @@ bool char_slotchange(struct char_session_data *sd, int fd, unsigned short from,
}
//-----------------------------------
-// Function to change chararcter's names
+// Function to change character's names
//-----------------------------------
int rename_char_sql(struct char_session_data *sd, int char_id)
{
@@ -1456,9 +1509,10 @@ int rename_char_sql(struct char_session_data *sd, int char_id)
// log change
if( log_char )
{
- if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`time`, `char_msg`,`account_id`,`char_num`,`name`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`hair`,`hair_color`)"
- "VALUES (NOW(), '%s', '%d', '%d', '%s', '0', '0', '0', '0', '0', '0', '0', '0')",
- charlog_db, "change char name", sd->account_id, char_dat.slot, esc_name) )
+ if( SQL_ERROR == SQL->Query(sql_handle,
+ "INSERT INTO `%s` (`time`, `char_msg`,`account_id`,`char_id`,`char_num`,`name`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`hair`,`hair_color`)"
+ "VALUES (NOW(), '%s', '%d', '%d', '%d', '%s', '0', '0', '0', '0', '0', '0', '0', '0')",
+ charlog_db, "change char name", sd->account_id, char_dat.char_id, char_dat.slot, esc_name) )
Sql_ShowDebug(sql_handle);
}
@@ -1486,9 +1540,9 @@ int check_char_name(char * name, char * esc_name)
if( strcmpi(name, wisp_server_name) == 0 )
return -1; // nick reserved for internal server messages
- // Check Authorised letters/symbols in the name of the character
+ // Check Authorized letters/symbols in the name of the character
if( char_name_option == 1 )
- { // only letters/symbols in char_name_letters are authorised
+ { // 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 )
return -2;
@@ -1497,7 +1551,7 @@ int check_char_name(char * name, char * esc_name)
{ // 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 )
- return -2;
+ return -5;
}
if( name_ignoring_case ) {
if( SQL_ERROR == SQL->Query(sql_handle, "SELECT 1 FROM `%s` WHERE BINARY `name` = '%s' LIMIT 1", char_db, esc_name) ) {
@@ -1516,9 +1570,16 @@ int check_char_name(char * name, char * esc_name)
return 0;
}
-//-----------------------------------
-// Function to create a new character
-//-----------------------------------
+/**
+ * Creates a new character
+ * Return values:
+ * -1: 'Charname already exists'
+ * -2: 'Char creation denied'/ Unknown error
+ * -3: 'You are underaged'
+ * -4: 'You are not eligible to open the Character Slot.'
+ * -5: 'Symbols in Character Names are forbidden'
+ * char_id: Success
+ **/
#if PACKETVER >= 20120307
int make_new_char_sql(struct char_session_data* sd, char* name_, int slot, int hair_color, int hair_style) {
int str = 1, agi = 1, vit = 1, int_ = 1, dex = 1, luk = 1;
@@ -1528,7 +1589,7 @@ int make_new_char_sql(struct char_session_data* sd, char* name_, int str, int ag
char name[NAME_LENGTH];
char esc_name[NAME_LENGTH*2+1];
- int char_id, flag, k;
+ int char_id, flag, k, l;
safestrncpy(name, name_, NAME_LENGTH);
normalize_name(name,TRIM_CHARS);
@@ -1557,13 +1618,6 @@ int make_new_char_sql(struct char_session_data* sd, char* name_, int str, int ag
if( sd->found_char[slot] != -1 )
return -2; /* character account limit exceeded */
- // validation success, log result
- if (log_char) {
- if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`time`, `char_msg`,`account_id`,`char_num`,`name`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`hair`,`hair_color`)"
- "VALUES (NOW(), '%s', '%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
- charlog_db, "make new char", sd->account_id, slot, esc_name, str, agi, vit, int_, dex, luk, hair_style, hair_color) )
- Sql_ShowDebug(sql_handle);
- }
#if PACKETVER >= 20120307
//Insert the new char entry to the database
if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`account_id`, `char_num`, `name`, `zeny`, `status_point`,`str`, `agi`, `vit`, `int`, `dex`, `luk`, `max_hp`, `hp`,"
@@ -1591,11 +1645,40 @@ int make_new_char_sql(struct char_session_data* sd, char* name_, int str, int ag
#endif
//Retrieve the newly auto-generated char id
char_id = (int)SQL->LastInsertId(sql_handle);
+
+ if( !char_id )
+ return -2;
+
+ // Validation success, log result
+ if (log_char) {
+ if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`time`, `char_msg`,`account_id`,`char_id`,`char_num`,`name`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,`hair`,`hair_color`)"
+ "VALUES (NOW(), '%s', '%d', '%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
+ charlog_db, "make new char", sd->account_id, char_id, slot, esc_name, str, agi, vit, int_, dex, luk, hair_style, hair_color) )
+ Sql_ShowDebug(sql_handle);
+ }
+
//Give the char the default items
-
- for (k = 0; k < ARRAYLENGTH(start_items) && start_items[k] != 0; k += 2) {
- if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` (`char_id`,`nameid`, `amount`, `identify`) VALUES ('%d', '%d', '%d', '%d')", inventory_db, char_id, start_items[k], start_items[k + 1], 1) )
- Sql_ShowDebug(sql_handle);
+ for (k = 0; k < ARRAYLENGTH(start_items) && start_items[k] != 0; k += 3) {
+ // FIXME: How to define if an item is stackable without having to lookup itemdb? [panikon]
+ if( start_items[k+2] == 1 )
+ {
+ if( SQL_ERROR == SQL->Query(sql_handle,
+ "INSERT INTO `%s` (`char_id`,`nameid`, `amount`, `identify`) VALUES ('%d', '%d', '%d', '%d')",
+ inventory_db, char_id, start_items[k], start_items[k + 1], 1) )
+ Sql_ShowDebug(sql_handle);
+ }
+ else if( start_items[k+2] == 0 )
+ {
+ // Non-stackable items should have their own entries (issue: 7279)
+ for( l = 0; l < start_items[k+1]; l++ )
+ {
+ if( SQL_ERROR == SQL->Query(sql_handle,
+ "INSERT INTO `%s` (`char_id`,`nameid`, `amount`, `identify`) VALUES ('%d', '%d', '%d', '%d')",
+ inventory_db, char_id, start_items[k], 1, 1)
+ )
+ Sql_ShowDebug(sql_handle);
+ }
+ }
}
ShowInfo("Created char: account: %d, char: %d, slot: %d, name: %s\n", sd->account_id, char_id, slot, name);
@@ -1655,8 +1738,8 @@ int delete_char_sql(int char_id)
SQL->GetData(sql_handle, 6, &data, NULL); partner_id = atoi(data);
SQL->GetData(sql_handle, 7, &data, NULL); father_id = atoi(data);
SQL->GetData(sql_handle, 8, &data, NULL); mother_id = atoi(data);
- SQL->GetData(sql_handle, 9, &data, NULL);
- elemental_id = atoi(data);
+ SQL->GetData(sql_handle, 9, &data, NULL);
+ elemental_id = atoi(data);
SQL->EscapeStringLen(sql_handle, esc_name, name, min(len, NAME_LENGTH));
SQL->FreeResult(sql_handle);
@@ -1697,7 +1780,7 @@ int delete_char_sql(int char_id)
/* delete char's pet */
//Delete the hatched pet if you have one...
- if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d' AND `incuvate` = '0'", pet_db, char_id) )
+ if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d' AND `incubate` = '0'", pet_db, char_id) )
Sql_ShowDebug(sql_handle);
//Delete all pets that are stored in eggs (inventory + cart)
@@ -1710,9 +1793,9 @@ int delete_char_sql(int char_id)
if( hom_id )
mapif_homunculus_delete(hom_id);
- /* remove elemental */
- if (elemental_id)
- mapif_elemental_delete(elemental_id);
+ /* remove elemental */
+ if (elemental_id)
+ mapif_elemental_delete(elemental_id);
/* remove mercenary data */
mercenary_owner_delete(char_id);
@@ -1745,7 +1828,9 @@ int delete_char_sql(int char_id)
Sql_ShowDebug(sql_handle);
/* delete character registry */
- if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `type`=3 AND `char_id`='%d'", reg_db, char_id) )
+ if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", char_reg_str_db, char_id) )
+ Sql_ShowDebug(sql_handle);
+ if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", char_reg_num_db, char_id) )
Sql_ShowDebug(sql_handle);
/* delete skills */
@@ -1762,15 +1847,16 @@ int delete_char_sql(int char_id)
Sql_ShowDebug(sql_handle);
#endif
- if (log_char) {
- if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s`(`time`, `account_id`,`char_num`,`char_msg`,`name`) VALUES (NOW(), '%d', '%d', 'Deleted char (CID %d)', '%s')",
- charlog_db, account_id, 0, char_id, esc_name) )
- Sql_ShowDebug(sql_handle);
- }
-
/* delete character */
if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", char_db, char_id) )
Sql_ShowDebug(sql_handle);
+ else if( log_char ) {
+ if( SQL_ERROR == SQL->Query(sql_handle,
+ "INSERT INTO `%s`(`time`, `account_id`, `char_id`, `char_num`, `char_msg`, `name`)"
+ " VALUES (NOW(), '%d', '%d', '%d', 'Deleted character', '%s')",
+ charlog_db, account_id, char_id, 0, esc_name) )
+ Sql_ShowDebug(sql_handle);
+ }
/* No need as we used inter_guild_leave [Skotlex]
// Also delete info from guildtables.
@@ -1807,8 +1893,7 @@ int count_users(void)
// Used in packets 0x6b (chars info) and 0x6d (new char info)
// Returns the size
#define MAX_CHAR_BUF 144 //Max size (for WFIFOHEAD calls)
-int mmo_char_tobuf(uint8* buffer, struct mmo_charstatus* p)
-{
+int mmo_char_tobuf(uint8* buffer, struct mmo_charstatus* p) {
unsigned short offset = 0;
uint8* buf;
@@ -1827,10 +1912,15 @@ int mmo_char_tobuf(uint8* buffer, struct mmo_charstatus* p)
WBUFL(buf,32) = p->karma;
WBUFL(buf,36) = p->manner;
WBUFW(buf,40) = min(p->status_point, INT16_MAX);
+#if PACKETVER > 20081217
WBUFL(buf,42) = p->hp;
WBUFL(buf,46) = p->max_hp;
offset+=4;
buf = WBUFP(buffer,offset);
+#else
+ WBUFW(buf,42) = min(p->hp, INT16_MAX);
+ WBUFW(buf,44) = min(p->max_hp, INT16_MAX);
+#endif
WBUFW(buf,46) = min(p->sp, INT16_MAX);
WBUFW(buf,48) = min(p->max_sp, INT16_MAX);
WBUFW(buf,50) = DEFAULT_WALK_SPEED; // p->speed;
@@ -1856,14 +1946,16 @@ int mmo_char_tobuf(uint8* buffer, struct mmo_charstatus* p)
WBUFB(buf,102) = min(p->dex, UINT8_MAX);
WBUFB(buf,103) = min(p->luk, UINT8_MAX);
WBUFW(buf,104) = p->slot;
+#if PACKETVER >= 20061023
WBUFW(buf,106) = ( p->rename > 0 ) ? 0 : 1;
offset += 2;
+#endif
#if (PACKETVER >= 20100720 && PACKETVER <= 20100727) || PACKETVER >= 20100803
- mapindex_getmapname_ext(mapindex_id2name(p->last_point.map), (char*)WBUFP(buf,108));
+ mapindex->getmapname_ext(mapindex_id2name(p->last_point.map), (char*)WBUFP(buf,108));
offset += MAP_NAME_LENGTH_EXT;
#endif
#if PACKETVER >= 20100803
- WBUFL(buf,124) = TOL(p->delete_date);
+ WBUFL(buf,124) = (int)p->delete_date;
offset += 4;
#endif
#if PACKETVER >= 20110111
@@ -1883,6 +1975,7 @@ int mmo_char_tobuf(uint8* buffer, struct mmo_charstatus* p)
return 106+offset;
}
+
/* Made Possible by Yommy~! <3 */
void mmo_char_send099d(int fd, struct char_session_data *sd) {
WFIFOHEAD(fd,4 + (MAX_CHARS*MAX_CHAR_BUF));
@@ -1890,6 +1983,44 @@ void mmo_char_send099d(int fd, struct char_session_data *sd) {
WFIFOW(fd,2) = mmo_chars_fromsql(sd, WFIFOP(fd,4)) + 4;
WFIFOSET(fd,WFIFOW(fd,2));
}
+/* Sends character ban list */
+/* Made Possible by Yommy~! <3 */
+void mmo_char_send020d(int fd, struct char_session_data *sd) {
+ int i;
+ time_t now = time(NULL);
+
+ ARR_FIND(0, MAX_CHARS, i, sd->unban_time[i]);
+
+ if( i != MAX_CHARS ) {
+ int c;
+
+ WFIFOHEAD(fd, 4 + (MAX_CHARS*24));
+
+ WFIFOW(fd, 0) = 0x20d;
+
+ for(i = 0, c = 0; i < MAX_CHARS; i++) {
+ if( sd->unban_time[i] ) {
+ timestamp2string((char*)WFIFOP(fd,8 + (28*c)), 20, sd->unban_time[i], "%Y-%m-%d %H:%M:%S");
+
+ if( sd->unban_time[i] > now )
+ WFIFOL(fd, 4 + (24*c)) = sd->found_char[i];
+ else {
+ /* reset -- client keeps this information even if you logout so we need to clear */
+ WFIFOL(fd, 4 + (24*c)) = 0;
+ /* also update on mysql */
+ sd->unban_time[i] = 0;
+ if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `unban_time`='0' WHERE `char_id`='%d' LIMIT 1", char_db, sd->found_char[i]) )
+ Sql_ShowDebug(sql_handle);
+ }
+ c++;
+ }
+ }
+
+ WFIFOW(fd, 2) = 4 + (24*c);
+
+ WFIFOSET(fd, WFIFOW(fd, 2));
+ }
+}
int mmo_char_send006b(int fd, struct char_session_data* sd);
//----------------------------------------
// [Ind/Hercules] notify client about charselect window data
@@ -1917,7 +2048,7 @@ int mmo_char_send006b(int fd, struct char_session_data* sd)
int j, offset = 0;
#if PACKETVER >= 20100413
offset += 3;
-#endif
+#endif
if (save_log)
ShowInfo("Loading Char Data ("CL_BOLD"%d"CL_RESET")\n",sd->account_id);
@@ -2011,8 +2142,8 @@ void disconnect_player(int account_id)
struct char_session_data* sd;
// disconnect player if online on char-server
- ARR_FIND( 0, fd_max, i, session[i] && (sd = (struct char_session_data*)session[i]->session_data) && sd->account_id == account_id );
- if( i < fd_max )
+ ARR_FIND( 0, sockt->fd_max, i, session[i] && (sd = (struct char_session_data*)session[i]->session_data) && sd->account_id == account_id );
+ if( i < sockt->fd_max )
set_eof(i);
}
@@ -2026,7 +2157,7 @@ static void char_auth_ok(int fd, struct char_session_data *sd)
{ //Character already online. KICK KICK KICK
mapif_disconnectplayer(server[character->server].fd, character->account_id, character->char_id, 2);
if (character->waiting_disconnect == INVALID_TIMER)
- character->waiting_disconnect = iTimer->add_timer(iTimer->gettick()+20000, chardb_waiting_disconnect, character->account_id, 0);
+ character->waiting_disconnect = timer->add(timer->gettick()+20000, chardb_waiting_disconnect, character->account_id, 0);
if (character)
character->pincode_enable = -1;
WFIFOHEAD(fd,3);
@@ -2063,7 +2194,7 @@ static void char_auth_ok(int fd, struct char_session_data *sd)
// continues when account data is received...
}
-int send_accounts_tologin(int tid, unsigned int tick, int id, intptr_t data);
+int send_accounts_tologin(int tid, int64 tick, int id, intptr_t data);
void mapif_server_reset(int id);
@@ -2071,7 +2202,7 @@ void mapif_server_reset(int id);
void loginif_reset(void)
{
int id;
- // TODO kick everyone out and reset everything or wait for connect and try to reaquire locks [FlavioJS]
+ // TODO kick everyone out and reset everything or wait for connect and try to reacquire locks [FlavioJS]
for( id = 0; id < ARRAYLENGTH(server); ++id )
mapif_server_reset(id);
flush_fifos();
@@ -2105,7 +2236,7 @@ void loginif_on_ready(void)
loginif_check_shutdown();
//Send online accounts to login server.
- send_accounts_tologin(INVALID_TIMER, iTimer->gettick(), 0, 0);
+ send_accounts_tologin(INVALID_TIMER, timer->gettick(), 0, 0);
// if no map-server already connected, display a message...
ARR_FIND( 0, ARRAYLENGTH(server), i, server[i].fd > 0 && server[i].map[0] );
@@ -2116,7 +2247,6 @@ void loginif_on_ready(void)
int parse_fromlogin(int fd) {
struct char_session_data* sd = NULL;
- int i;
// only process data from the login-server
if( fd != login_fd ) {
@@ -2131,7 +2261,7 @@ int parse_fromlogin(int fd) {
loginif_on_disconnect();
return 0;
} else if ( session[fd]->flag.ping ) {/* we've reached stall time */
- if( DIFF_TICK(last_tick, session[fd]->rdata_tick) > (stall_time * 2) ) {/* we can't wait any longer */
+ if( DIFF_TICK(sockt->last_tick, session[fd]->rdata_tick) > (sockt->stall_time * 2) ) {/* we can't wait any longer */
set_eof(fd);
return 0;
} else if( session[fd]->flag.ping != 2 ) { /* we haven't sent ping out yet */
@@ -2147,9 +2277,16 @@ int parse_fromlogin(int fd) {
while(RFIFOREST(fd) >= 2) {
uint16 command = RFIFOW(fd,0);
+
+ if( HPM->packetsc[hpParse_FromLogin] ) {
+ int success = HPM->parse_packets(fd,hpParse_FromLogin);
+ if( success == 1 ) continue;
+ else if( success == 2 ) return 0;
+ }
+
switch( command ) {
- // acknowledgement of connect-to-loginserver request
+ // acknowledgment of connect-to-loginserver request
case 0x2711:
if (RFIFOREST(fd) < 3)
return 0;
@@ -2169,9 +2306,9 @@ int parse_fromlogin(int fd) {
RFIFOSKIP(fd,3);
break;
- // acknowledgement of account authentication request
+ // acknowledgment of account authentication request
case 0x2713:
- if (RFIFOREST(fd) < 25)
+ if (RFIFOREST(fd) < 33)
return 0;
{
int account_id = RFIFOL(fd,2);
@@ -2182,7 +2319,9 @@ int parse_fromlogin(int fd) {
int request_id = RFIFOL(fd,16);
uint32 version = RFIFOL(fd,20);
uint8 clienttype = RFIFOB(fd,24);
- RFIFOSKIP(fd,25);
+ int group_id = RFIFOL(fd,25);
+ unsigned int expiration_time = RFIFOL(fd, 29);
+ RFIFOSKIP(fd,33);
if( session_isActive(request_id) && (sd=(struct char_session_data*)session[request_id]->session_data) &&
!sd->auth && sd->account_id == account_id && sd->login_id1 == login_id1 && sd->login_id2 == login_id2 && sd->sex == sex )
@@ -2190,30 +2329,46 @@ int parse_fromlogin(int fd) {
int client_fd = request_id;
sd->version = version;
sd->clienttype = clienttype;
- switch( result )
- {
- case 0:// ok
- char_auth_ok(client_fd, sd);
- break;
- case 1:// auth failed
- WFIFOHEAD(client_fd,3);
- WFIFOW(client_fd,0) = 0x6c;
- WFIFOB(client_fd,2) = 0;// rejected from server
- WFIFOSET(client_fd,3);
- break;
+ switch( result ) {
+ case 0:// ok
+ /* restrictions apply */
+ if( char_server_type == CST_MAINTENANCE && group_id < char_maintenance_min_group_id ) {
+ WFIFOHEAD(client_fd,3);
+ WFIFOW(client_fd,0) = 0x6c;
+ WFIFOB(client_fd,2) = 0;// rejected from server
+ WFIFOSET(client_fd,3);
+ break;
+ }
+ /* the client will already deny this request, this check is to avoid someone bypassing. */
+ if( char_server_type == CST_PAYING && (time_t)expiration_time < time(NULL) ) {
+ WFIFOHEAD(client_fd,3);
+ WFIFOW(client_fd,0) = 0x6c;
+ WFIFOB(client_fd,2) = 0;// rejected from server
+ WFIFOSET(client_fd,3);
+ break;
+ }
+ char_auth_ok(client_fd, sd);
+ break;
+ case 1:// auth failed
+ WFIFOHEAD(client_fd,3);
+ WFIFOW(client_fd,0) = 0x6c;
+ WFIFOB(client_fd,2) = 0;// rejected from server
+ WFIFOSET(client_fd,3);
+ break;
}
}
}
break;
case 0x2717: // account data
+ {
+ int i;
if (RFIFOREST(fd) < 72)
return 0;
// find the authenticated session with this account id
- ARR_FIND( 0, fd_max, i, session[i] && (sd = (struct char_session_data*)session[i]->session_data) && sd->auth && sd->account_id == RFIFOL(fd,2) );
- if( i < fd_max ) {
- int server_id;
+ ARR_FIND( 0, sockt->fd_max, i, session[i] && (sd = (struct char_session_data*)session[i]->session_data) && sd->auth && sd->account_id == RFIFOL(fd,2) );
+ if( i < sockt->fd_max ) {
memcpy(sd->email, RFIFOP(fd,6), 40);
sd->expiration_time = (time_t)RFIFOL(fd,46);
sd->group_id = RFIFOB(fd,50);
@@ -2226,10 +2381,8 @@ int parse_fromlogin(int fd) {
safestrncpy(sd->birthdate, (const char*)RFIFOP(fd,52), sizeof(sd->birthdate));
safestrncpy(sd->pincode, (const char*)RFIFOP(fd,63), sizeof(sd->pincode));
sd->pincode_change = RFIFOL(fd,68);
- ARR_FIND( 0, ARRAYLENGTH(server), server_id, server[server_id].fd > 0 && server[server_id].map[0] );
// continued from char_auth_ok...
- if( server_id == ARRAYLENGTH(server) || //server not online, bugreport:2359
- (max_connect_user == 0 && sd->group_id != gm_allow_group) ||
+ if( (max_connect_user == 0 && sd->group_id != gm_allow_group) ||
( max_connect_user > 0 && count_users() >= max_connect_user && sd->group_id != gm_allow_group ) ) {
// refuse connection (over populated)
WFIFOHEAD(i,3);
@@ -2243,12 +2396,16 @@ int parse_fromlogin(int fd) {
#else
mmo_char_send006b(i, sd);
#endif
+ #if PACKETVER >= 20060819
+ mmo_char_send020d(i, sd);
+ #endif
#if PACKETVER >= 20110309
pincode->handle(i, sd);
#endif
}
}
RFIFOSKIP(fd,72);
+ }
break;
// login-server alive packet
@@ -2266,70 +2423,82 @@ int parse_fromlogin(int fd) {
{
unsigned char buf[7];
+ int char_id[MAX_CHARS];
+ int class_[MAX_CHARS];
+ int guild_id[MAX_CHARS];
+ int num;
+ int i;
+ char* data;
+ struct auth_node* node;
+
int acc = RFIFOL(fd,2);
int sex = RFIFOB(fd,6);
+
RFIFOSKIP(fd,7);
- if( acc > 0 )
- {// TODO: Is this even possible?
- int char_id[MAX_CHARS];
- int class_[MAX_CHARS];
- int guild_id[MAX_CHARS];
- int num;
- char* data;
+ // This should _never_ happen
+ if( acc <= 0 ) {
+ ShowError("Received invalid account id from login server! (aid: %d)\n", acc);
+ return 0;
+ }
- struct auth_node* node = (struct auth_node*)idb_get(auth_db, acc);
- if( node != NULL )
- node->sex = sex;
+ node = (struct auth_node*)idb_get(auth_db, acc);
+ if( node != NULL )
+ node->sex = sex;
- // get characters
- if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `char_id`,`class`,`guild_id` FROM `%s` WHERE `account_id` = '%d'", char_db, acc) )
- Sql_ShowDebug(sql_handle);
- for( i = 0; i < MAX_CHARS && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i )
+ // get characters
+ if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `char_id`,`class`,`guild_id` FROM `%s` WHERE `account_id` = '%d'", char_db, acc) )
+ Sql_ShowDebug(sql_handle);
+ for( i = 0; i < MAX_CHARS && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i )
+ {
+ SQL->GetData(sql_handle, 0, &data, NULL); char_id[i] = atoi(data);
+ SQL->GetData(sql_handle, 1, &data, NULL); class_[i] = atoi(data);
+ SQL->GetData(sql_handle, 2, &data, NULL); guild_id[i] = atoi(data);
+ }
+ num = i;
+ for( i = 0; i < num; ++i )
+ {
+ if( class_[i] == JOB_BARD || class_[i] == JOB_DANCER ||
+ class_[i] == JOB_CLOWN || class_[i] == JOB_GYPSY ||
+ class_[i] == JOB_BABY_BARD || class_[i] == JOB_BABY_DANCER ||
+ class_[i] == JOB_MINSTREL || class_[i] == JOB_WANDERER ||
+ class_[i] == JOB_MINSTREL_T || class_[i] == JOB_WANDERER_T ||
+ class_[i] == JOB_BABY_MINSTREL || class_[i] == JOB_BABY_WANDERER ||
+ class_[i] == JOB_KAGEROU || class_[i] == JOB_OBORO )
{
- SQL->GetData(sql_handle, 0, &data, NULL); char_id[i] = atoi(data);
- SQL->GetData(sql_handle, 1, &data, NULL); class_[i] = atoi(data);
- SQL->GetData(sql_handle, 2, &data, NULL); guild_id[i] = atoi(data);
+ // job modification
+ if( class_[i] == JOB_BARD || class_[i] == JOB_DANCER )
+ class_[i] = (sex ? JOB_BARD : JOB_DANCER);
+ else if( class_[i] == JOB_CLOWN || class_[i] == JOB_GYPSY )
+ class_[i] = (sex ? JOB_CLOWN : JOB_GYPSY);
+ else if( class_[i] == JOB_BABY_BARD || class_[i] == JOB_BABY_DANCER )
+ class_[i] = (sex ? JOB_BABY_BARD : JOB_BABY_DANCER);
+ else if( class_[i] == JOB_MINSTREL || class_[i] == JOB_WANDERER )
+ class_[i] = (sex ? JOB_MINSTREL : JOB_WANDERER);
+ else if( class_[i] == JOB_MINSTREL_T || class_[i] == JOB_WANDERER_T )
+ class_[i] = (sex ? JOB_MINSTREL_T : JOB_WANDERER_T);
+ else if( class_[i] == JOB_BABY_MINSTREL || class_[i] == JOB_BABY_WANDERER )
+ class_[i] = (sex ? JOB_BABY_MINSTREL : JOB_BABY_WANDERER);
+ else if( class_[i] == JOB_KAGEROU || class_[i] == JOB_OBORO )
+ class_[i] = (sex ? JOB_KAGEROU : JOB_OBORO);
}
- num = i;
- for( i = 0; i < num; ++i )
- {
- if( class_[i] == JOB_BARD || class_[i] == JOB_DANCER ||
- class_[i] == JOB_CLOWN || class_[i] == JOB_GYPSY ||
- class_[i] == JOB_BABY_BARD || class_[i] == JOB_BABY_DANCER ||
- class_[i] == JOB_MINSTREL || class_[i] == JOB_WANDERER ||
- class_[i] == JOB_MINSTREL_T || class_[i] == JOB_WANDERER_T ||
- class_[i] == JOB_BABY_MINSTREL || class_[i] == JOB_BABY_WANDERER ||
- class_[i] == JOB_KAGEROU || class_[i] == JOB_OBORO )
- {
- // job modification
- if( class_[i] == JOB_BARD || class_[i] == JOB_DANCER )
- class_[i] = (sex ? JOB_BARD : JOB_DANCER);
- else if( class_[i] == JOB_CLOWN || class_[i] == JOB_GYPSY )
- class_[i] = (sex ? JOB_CLOWN : JOB_GYPSY);
- else if( class_[i] == JOB_BABY_BARD || class_[i] == JOB_BABY_DANCER )
- class_[i] = (sex ? JOB_BABY_BARD : JOB_BABY_DANCER);
- else if( class_[i] == JOB_MINSTREL || class_[i] == JOB_WANDERER )
- class_[i] = (sex ? JOB_MINSTREL : JOB_WANDERER);
- else if( class_[i] == JOB_MINSTREL_T || class_[i] == JOB_WANDERER_T )
- class_[i] = (sex ? JOB_MINSTREL_T : JOB_WANDERER_T);
- else if( class_[i] == JOB_BABY_MINSTREL || class_[i] == JOB_BABY_WANDERER )
- class_[i] = (sex ? JOB_BABY_MINSTREL : JOB_BABY_WANDERER);
- else if( class_[i] == JOB_KAGEROU || class_[i] == JOB_OBORO )
- class_[i] = (sex ? JOB_KAGEROU : JOB_OBORO);
- }
- if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `class`='%d', `weapon`='0', `shield`='0', `head_top`='0', `head_mid`='0', `head_bottom`='0' WHERE `char_id`='%d'", char_db, class_[i], char_id[i]) )
- Sql_ShowDebug(sql_handle);
+ if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `equip`='0' WHERE `char_id`='%d'", inventory_db, char_id[i]) )
+ Sql_ShowDebug(sql_handle);
- if( guild_id[i] )// If there is a guild, update the guild_member data [Skotlex]
- inter_guild_sex_changed(guild_id[i], acc, char_id[i], sex);
- }
- SQL->FreeResult(sql_handle);
+ if( SQL_ERROR == SQL->Query(sql_handle,
+ "UPDATE `%s` SET `class`='%d', `weapon`='0', `shield`='0', `head_top`='0', `head_mid`='0', "
+ "`head_bottom`='0' WHERE `char_id`='%d'",
+ char_db, class_[i], char_id[i]) )
+ Sql_ShowDebug(sql_handle);
- // disconnect player if online on char-server
- disconnect_player(acc);
+ if( guild_id[i] )// If there is a guild, update the guild_member data [Skotlex]
+ inter_guild_sex_changed(guild_id[i], acc, char_id[i], sex);
}
+ SQL->FreeResult(sql_handle);
+
+ // disconnect player if online on char-server
+ disconnect_player(acc);
// notify all mapservers about this change
WBUFW(buf,0) = 0x2b0d;
@@ -2340,17 +2509,12 @@ int parse_fromlogin(int fd) {
break;
// reply to an account_reg2 registry request
- case 0x2729:
+ case 0x3804:
if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
return 0;
-
- { //Receive account_reg2 registry, forward to map servers.
- unsigned char buf[13+ACCOUNT_REG2_NUM*sizeof(struct global_reg)];
- memcpy(buf,RFIFOP(fd,0), RFIFOW(fd,2));
- WBUFW(buf,0) = 0x3804; //Map server can now receive all kinds of reg values with the same packet. [Skotlex]
- mapif_sendall(buf, WBUFW(buf,2));
+ //Receive account_reg2 registry, forward to map servers.
+ mapif_sendall(RFIFOP(fd, 0), RFIFOW(fd,2));
RFIFOSKIP(fd, RFIFOW(fd,2));
- }
break;
// State change of account/ban notification (from login-server)
@@ -2362,7 +2526,7 @@ int parse_fromlogin(int fd) {
unsigned char buf[11];
WBUFW(buf,0) = 0x2b14;
WBUFL(buf,2) = RFIFOL(fd,2);
- WBUFB(buf,6) = RFIFOB(fd,6); // 0: change of statut, 1: ban
+ WBUFB(buf,6) = RFIFOB(fd,6); // 0: change of status, 1: ban
WBUFL(buf,7) = RFIFOL(fd,7); // status or final date of a banishment
mapif_sendall(buf, 11);
}
@@ -2386,14 +2550,14 @@ int parse_fromlogin(int fd) {
{ //Kick it from the map server it is on.
mapif_disconnectplayer(server[character->server].fd, character->account_id, character->char_id, 2);
if (character->waiting_disconnect == INVALID_TIMER)
- character->waiting_disconnect = iTimer->add_timer(iTimer->gettick()+AUTH_TIMEOUT, chardb_waiting_disconnect, character->account_id, 0);
+ character->waiting_disconnect = timer->add(timer->gettick()+AUTH_TIMEOUT, chardb_waiting_disconnect, character->account_id, 0);
}
else
{// Manual kick from char server.
struct char_session_data *tsd;
int i;
- ARR_FIND( 0, fd_max, i, session[i] && (tsd = (struct char_session_data*)session[i]->session_data) && tsd->account_id == aid );
- if( i < fd_max )
+ ARR_FIND( 0, sockt->fd_max, i, session[i] && (tsd = (struct char_session_data*)session[i]->session_data) && tsd->account_id == aid );
+ if( i < sockt->fd_max )
{
WFIFOHEAD(i,3);
WFIFOW(i,0) = 0x81;
@@ -2438,6 +2602,26 @@ int parse_fromlogin(int fd) {
}
break;
+ case 0x2736: // Failed accinfo lookup to forward to mapserver
+ if (RFIFOREST(fd) < 18)
+ return 0;
+
+ mapif_parse_accinfo2(false, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOL(fd,14),
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1, 0, 0);
+ RFIFOSKIP(fd,18);
+ break;
+
+ case 0x2737: // Successful accinfo lookup to forward to mapserver
+ if (RFIFOREST(fd) < 183)
+ return 0;
+
+ mapif_parse_accinfo2(true, RFIFOL(fd,167), RFIFOL(fd,171), RFIFOL(fd,175), RFIFOL(fd,179),
+ (char*)RFIFOP(fd,2), (char*)RFIFOP(fd,26), (char*)RFIFOP(fd,59),
+ (char*)RFIFOP(fd,99), (char*)RFIFOP(fd,119), (char*)RFIFOP(fd,151),
+ (char*)RFIFOP(fd,156), RFIFOL(fd,115), RFIFOL(fd,143), RFIFOL(fd,147));
+ RFIFOSKIP(fd,183);
+ break;
+
default:
ShowError("Unknown packet 0x%04x received from login-server, disconnecting.\n", command);
set_eof(fd);
@@ -2449,18 +2633,17 @@ int parse_fromlogin(int fd) {
return 0;
}
-int check_connect_login_server(int tid, unsigned int tick, int id, intptr_t data);
-int send_accounts_tologin(int tid, unsigned int tick, int id, intptr_t data);
+int check_connect_login_server(int tid, int64 tick, int id, intptr_t data);
void do_init_loginif(void)
{
// establish char-login connection if not present
- iTimer->add_timer_func_list(check_connect_login_server, "check_connect_login_server");
- iTimer->add_timer_interval(iTimer->gettick() + 1000, check_connect_login_server, 0, 0, 10 * 1000);
+ timer->add_func_list(check_connect_login_server, "check_connect_login_server");
+ timer->add_interval(timer->gettick() + 1000, check_connect_login_server, 0, 0, 10 * 1000);
// send a list of all online account IDs to login server
- iTimer->add_timer_func_list(send_accounts_tologin, "send_accounts_tologin");
- iTimer->add_timer_interval(iTimer->gettick() + 1000, send_accounts_tologin, 0, 0, 3600 * 1000); //Sync online accounts every hour
+ timer->add_func_list(send_accounts_tologin, "send_accounts_tologin");
+ timer->add_interval(timer->gettick() + 1000, send_accounts_tologin, 0, 0, 3600 * 1000); //Sync online accounts every hour
}
void do_final_loginif(void)
@@ -2484,23 +2667,77 @@ int request_accreg2(int account_id, int char_id)
}
return 0;
}
-
-//Send packet forward to login-server for account saving
-int save_accreg2(unsigned char* buf, int len)
-{
- if (login_fd > 0) {
- WFIFOHEAD(login_fd,len+4);
- memcpy(WFIFOP(login_fd,4), buf, len);
- WFIFOW(login_fd,0) = 0x2728;
- WFIFOW(login_fd,2) = len+4;
- WFIFOSET(login_fd,len+4);
- return 1;
+/**
+ * Handles global account reg saving that continues with global_accreg_to_login_add and global_accreg_to_send
+ **/
+void global_accreg_to_login_start (int account_id, int char_id) {
+ WFIFOHEAD(login_fd, 60000 + 300);
+ WFIFOW(login_fd,0) = 0x2728;
+ WFIFOW(login_fd,2) = 14;
+ WFIFOL(login_fd,4) = account_id;
+ WFIFOL(login_fd,8) = char_id;
+ WFIFOW(login_fd,12) = 0;/* count */
+}
+/**
+ * Completes global account reg saving that starts global_accreg_to_login_start and continues with global_accreg_to_login_add
+ **/
+void global_accreg_to_login_send (void) {
+ WFIFOSET(login_fd, WFIFOW(login_fd,2));
+}
+/**
+ * Handles global account reg saving that starts global_accreg_to_login_start and ends with global_accreg_to_send
+ **/
+void global_accreg_to_login_add (const char *key, unsigned int index, intptr_t val, bool is_string) {
+ int nlen = WFIFOW(login_fd, 2);
+ size_t len;
+
+ len = strlen(key)+1;
+
+ WFIFOB(login_fd, nlen) = (unsigned char)len;/* won't be higher; the column size is 32 */
+ nlen += 1;
+
+ safestrncpy((char*)WFIFOP(login_fd,nlen), key, len);
+ nlen += len;
+
+ WFIFOL(login_fd, nlen) = index;
+ nlen += 4;
+
+ if( is_string ) {
+ WFIFOB(login_fd, nlen) = val ? 2 : 3;
+ nlen += 1;
+
+ if( val ) {
+ char *sval = (char*)val;
+ len = strlen(sval)+1;
+
+ WFIFOB(login_fd, nlen) = (unsigned char)len;/* won't be higher; the column size is 254 */
+ nlen += 1;
+
+ safestrncpy((char*)WFIFOP(login_fd,nlen), sval, len);
+ nlen += len;
+ }
+
+ } else {
+ WFIFOB(login_fd, nlen) = val ? 0 : 1;
+ nlen += 1;
+
+ if( val ) {
+ WFIFOL(login_fd, nlen) = (int)val;
+ nlen += 4;
+ }
+
+ }
+
+ WFIFOW(login_fd,12) += 1;
+
+ WFIFOW(login_fd, 2) = nlen;
+ if( WFIFOW(login_fd, 2) > 60000 ) {
+ int account_id = WFIFOL(login_fd,4), char_id = WFIFOL(login_fd,8);
+ global_accreg_to_login_send();
+ global_accreg_to_login_start(account_id,char_id);/* prepare next */
}
- return 0;
}
-
-void char_read_fame_list(void)
-{
+void char_read_fame_list(void) {
int i;
char* data;
size_t len;
@@ -2558,8 +2795,7 @@ void char_read_fame_list(void)
}
// Send map-servers the fame ranking lists
-int char_send_fame_list(int fd)
-{
+int char_send_fame_list(int fd) {
int i, len = 8;
unsigned char buf[32000];
@@ -2594,8 +2830,7 @@ int char_send_fame_list(int fd)
return 0;
}
-void char_update_fame_list(int type, int index, int fame)
-{
+void char_update_fame_list(int type, int index, int fame) {
unsigned char buf[8];
WBUFW(buf,0) = 0x2b22;
WBUFB(buf,2) = type;
@@ -2681,6 +2916,16 @@ void mapif_on_disconnect(int id)
mapif_server_reset(id);
}
+void mapif_on_parse_accinfo(int account_id, int u_fd, int u_aid, int u_group, int map_fd) {
+ WFIFOHEAD(login_fd,22);
+ WFIFOW(login_fd,0) = 0x2740;
+ WFIFOL(login_fd,2) = account_id;
+ WFIFOL(login_fd,6) = u_fd;
+ WFIFOL(login_fd,10) = u_aid;
+ WFIFOL(login_fd,14) = u_group;
+ WFIFOL(login_fd,18) = map_fd;
+ WFIFOSET(login_fd,22);
+}
int parse_frommap(int fd)
{
@@ -2701,12 +2946,20 @@ int parse_frommap(int fd)
}
while(RFIFOREST(fd) >= 2) {
+
+ if( HPM->packetsc[hpParse_FromMap] ) {
+ if( (i = HPM->parse_packets(fd,hpParse_FromMap)) ) {
+ if( i == 1 ) continue;
+ if( i == 2 ) return 0;
+ }
+ }
+
switch(RFIFOW(fd,0)) {
case 0x2b0a:
if( RFIFOREST(fd) < RFIFOW(fd, 2) )
return 0;
- socket_datasync(fd, false);
+ sockt->datasync(fd, false);
RFIFOSKIP(fd,RFIFOW(fd,2));
break;
@@ -2796,14 +3049,14 @@ int parse_frommap(int fd)
int aid, cid;
aid = RFIFOL(fd,2);
cid = RFIFOL(fd,6);
- if( SQL_ERROR == SQL->Query(sql_handle, "SELECT type, tick, val1, val2, val3, val4 from `%s` WHERE `account_id` = '%d' AND `char_id`='%d'",
+ if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `type`, `tick`, `val1`, `val2`, `val3`, `val4` "
+ "FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'",
scdata_db, aid, cid) )
{
Sql_ShowDebug(sql_handle);
break;
}
- if( SQL->NumRows(sql_handle) > 0 )
- {
+ if( SQL->NumRows(sql_handle) > 0 ) {
struct status_change_data scdata;
int count;
char* data;
@@ -2824,8 +3077,7 @@ int parse_frommap(int fd)
}
if (count >= 50)
ShowWarning("Too many status changes for %d:%d, some of them were not loaded.\n", aid, cid);
- if (count > 0)
- {
+ if (count > 0) {
WFIFOW(fd,2) = 14 + count*sizeof(struct status_change_data);
WFIFOW(fd,12) = count;
WFIFOSET(fd,WFIFOW(fd,2));
@@ -2834,6 +3086,14 @@ int parse_frommap(int fd)
if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", scdata_db, aid, cid) )
Sql_ShowDebug(sql_handle);
}
+ } else { //no sc (needs a response)
+ WFIFOHEAD(fd,14);
+ WFIFOW(fd,0) = 0x2b1d;
+ WFIFOW(fd,2) = 14;
+ WFIFOL(fd,4) = aid;
+ WFIFOL(fd,8) = cid;
+ WFIFOW(fd,12) = 0;
+ WFIFOSET(fd,WFIFOW(fd,2));
}
SQL->FreeResult(sql_handle);
#endif
@@ -2886,9 +3146,8 @@ int parse_frommap(int fd)
int aid = RFIFOL(fd,4), cid = RFIFOL(fd,8), size = RFIFOW(fd,2);
struct online_char_data* character;
- if (size - 13 != sizeof(struct mmo_charstatus))
- {
- ShowError("parse_from_map (save-char): Size mismatch! %d != %d\n", size-13, sizeof(struct mmo_charstatus));
+ if (size - 13 != sizeof(struct mmo_charstatus)) {
+ ShowError("parse_from_map (save-char): Size mismatch! %d != %"PRIuS"\n", size-13, sizeof(struct mmo_charstatus));
RFIFOSKIP(fd,size);
break;
}
@@ -2901,7 +3160,7 @@ int parse_frommap(int fd)
memcpy(&char_dat, RFIFOP(fd,13), sizeof(struct mmo_charstatus));
mmo_char_tosql(cid, &char_dat);
} else { //This may be valid on char-server reconnection, when re-sending characters that already logged off.
- ShowError("parse_from_map (save-char): Received data for non-existant/offline character (%d:%d).\n", aid, cid);
+ ShowError("parse_from_map (save-char): Received data for non-existing/offline character (%d:%d).\n", aid, cid);
set_char_online(id, cid, aid);
}
@@ -2919,14 +3178,15 @@ int parse_frommap(int fd)
break;
case 0x2b02: // req char selection
- if( RFIFOREST(fd) < 18 )
+ if( RFIFOREST(fd) < 22 )
return 0;
{
int account_id = RFIFOL(fd,2);
uint32 login_id1 = RFIFOL(fd,6);
uint32 login_id2 = RFIFOL(fd,10);
uint32 ip = RFIFOL(fd,14);
- RFIFOSKIP(fd,18);
+ int32 group_id = RFIFOL(fd, 18);
+ RFIFOSKIP(fd,22);
if( runflag != CHARSERVER_ST_RUNNING )
{
@@ -2946,8 +3206,10 @@ int parse_frommap(int fd)
node->char_id = 0;
node->login_id1 = login_id1;
node->login_id2 = login_id2;
+ node->group_id = group_id;
//node->sex = 0;
node->ip = ntohl(ip);
+ /* sounds troublesome. */
//node->expiration_time = 0; // unlimited/unknown time by default (not display in map-server)
//node->gmlevel = 0;
idb_put(auth_db, account_id, node);
@@ -3069,7 +3331,7 @@ int parse_frommap(int fd)
RFIFOSKIP(fd, 86);
break;
- case 0x2b0e: // Request from map-server to change an account's status (will just be forwarded to login server)
+ case 0x2b0e: // Request from map-server to change an account's or character's status (accounts will just be forwarded to login server)
if (RFIFOREST(fd) < 44)
return 0;
{
@@ -3078,7 +3340,7 @@ int parse_frommap(int fd)
int acc = RFIFOL(fd,2); // account_id of who ask (-1 if server itself made this request)
const char* name = (char*)RFIFOP(fd,6); // name of the target character
- int type = RFIFOW(fd,30); // type of operation: 1-block, 2-ban, 3-unblock, 4-unban
+ int type = RFIFOW(fd,30); // type of operation: 1-block, 2-ban, 3-unblock, 4-unban, 5 changesex, 6 charban, 7 charunban
short year = RFIFOW(fd,32);
short month = RFIFOW(fd,34);
short day = RFIFOW(fd,36);
@@ -3088,25 +3350,22 @@ int parse_frommap(int fd)
RFIFOSKIP(fd,44);
SQL->EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH));
- if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`,`name` FROM `%s` WHERE `name` = '%s'", char_db, esc_name) )
+
+ if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id`,`char_id`,`unban_time` FROM `%s` WHERE `name` = '%s'", char_db, esc_name) )
Sql_ShowDebug(sql_handle);
- else
- if( SQL->NumRows(sql_handle) == 0 )
- {
+ else if( SQL->NumRows(sql_handle) == 0 ) {
result = 1; // 1-player not found
- }
- else
- if( SQL_SUCCESS != SQL->NextRow(sql_handle) )
+ } else if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) {
Sql_ShowDebug(sql_handle);
- //FIXME: set proper result value?
- else
- {
- char name[NAME_LENGTH];
- int account_id;
+ result = 1; // 1-player not found
+ } else {
+ int account_id, char_id;
char* data;
+ time_t unban_time;
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, 1, &data, NULL); char_id = atoi(data);
+ SQL->GetData(sql_handle, 2, &data, NULL); unban_time = atol(data);
if( login_fd <= 0 )
result = 3; // 3-login-server offline
@@ -3114,53 +3373,111 @@ int parse_frommap(int fd)
// else
// if( acc != -1 && isGM(acc) < isGM(account_id) )
// result = 2; // 2-gm level too low
- else
- switch( type ) {
- case 1: // block
- WFIFOHEAD(login_fd,10);
- WFIFOW(login_fd,0) = 0x2724;
- WFIFOL(login_fd,2) = account_id;
- WFIFOL(login_fd,6) = 5; // new account status
- WFIFOSET(login_fd,10);
- break;
- case 2: // ban
- WFIFOHEAD(login_fd,18);
- WFIFOW(login_fd, 0) = 0x2725;
- WFIFOL(login_fd, 2) = account_id;
- WFIFOW(login_fd, 6) = year;
- WFIFOW(login_fd, 8) = month;
- WFIFOW(login_fd,10) = day;
- WFIFOW(login_fd,12) = hour;
- WFIFOW(login_fd,14) = minute;
- WFIFOW(login_fd,16) = second;
- WFIFOSET(login_fd,18);
- break;
- case 3: // unblock
- WFIFOHEAD(login_fd,10);
- WFIFOW(login_fd,0) = 0x2724;
- WFIFOL(login_fd,2) = account_id;
- WFIFOL(login_fd,6) = 0; // new account status
- WFIFOSET(login_fd,10);
- break;
- case 4: // unban
- WFIFOHEAD(login_fd,6);
- WFIFOW(login_fd,0) = 0x272a;
- WFIFOL(login_fd,2) = account_id;
- WFIFOSET(login_fd,6);
- break;
- case 5: // changesex
- WFIFOHEAD(login_fd,6);
- WFIFOW(login_fd,0) = 0x2727;
- WFIFOL(login_fd,2) = account_id;
- WFIFOSET(login_fd,6);
- break;
+ else {
+ switch( type ) {
+ case 1: // block
+ WFIFOHEAD(login_fd,10);
+ WFIFOW(login_fd,0) = 0x2724;
+ WFIFOL(login_fd,2) = account_id;
+ WFIFOL(login_fd,6) = 5; // new account status
+ WFIFOSET(login_fd,10);
+ break;
+ case 2: // ban
+ WFIFOHEAD(login_fd,18);
+ WFIFOW(login_fd, 0) = 0x2725;
+ WFIFOL(login_fd, 2) = account_id;
+ WFIFOW(login_fd, 6) = year;
+ WFIFOW(login_fd, 8) = month;
+ WFIFOW(login_fd,10) = day;
+ WFIFOW(login_fd,12) = hour;
+ WFIFOW(login_fd,14) = minute;
+ WFIFOW(login_fd,16) = second;
+ WFIFOSET(login_fd,18);
+ break;
+ case 3: // unblock
+ WFIFOHEAD(login_fd,10);
+ WFIFOW(login_fd,0) = 0x2724;
+ WFIFOL(login_fd,2) = account_id;
+ WFIFOL(login_fd,6) = 0; // new account status
+ WFIFOSET(login_fd,10);
+ break;
+ case 4: // unban
+ WFIFOHEAD(login_fd,6);
+ WFIFOW(login_fd,0) = 0x272a;
+ WFIFOL(login_fd,2) = account_id;
+ WFIFOSET(login_fd,6);
+ break;
+ case 5: // changesex
+ WFIFOHEAD(login_fd,6);
+ WFIFOW(login_fd,0) = 0x2727;
+ WFIFOL(login_fd,2) = account_id;
+ WFIFOSET(login_fd,6);
+ break;
+ case 6: //char ban
+ /* handled by char server, so no redirection */
+ {
+ time_t timestamp;
+ struct tm *tmtime;
+ SqlStmt* stmt = SQL->StmtMalloc(sql_handle);
+
+ if (unban_time == 0 || unban_time < time(NULL))
+ timestamp = time(NULL); // new ban
+ else
+ timestamp = unban_time; // add to existing ban
+
+ tmtime = localtime(&timestamp);
+ tmtime->tm_year = tmtime->tm_year + year;
+ tmtime->tm_mon = tmtime->tm_mon + month;
+ tmtime->tm_mday = tmtime->tm_mday + day;
+ tmtime->tm_hour = tmtime->tm_hour + hour;
+ tmtime->tm_min = tmtime->tm_min + minute;
+ tmtime->tm_sec = tmtime->tm_sec + second;
+ timestamp = mktime(tmtime);
+
+ if( SQL_SUCCESS != SQL->StmtPrepare(stmt,
+ "UPDATE `%s` SET `unban_time` = ? WHERE `char_id` = ? LIMIT 1",
+ char_db)
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_LONG, (void*)&timestamp, sizeof(timestamp))
+ || SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_INT, (void*)&char_id, sizeof(char_id))
+ || SQL_SUCCESS != SQL->StmtExecute(stmt)
+
+ ) {
+ SqlStmt_ShowDebug(stmt);
+ }
+
+ SQL->StmtFree(stmt);
+
+ // condition applies; send to all map-servers to disconnect the player
+ if( timestamp > time(NULL) ) {
+ unsigned char buf[11];
+
+ WBUFW(buf,0) = 0x2b14;
+ WBUFL(buf,2) = char_id;
+ WBUFB(buf,6) = 2;
+ WBUFL(buf,7) = (unsigned int)timestamp;
+ mapif_sendall(buf, 11);
+
+ // disconnect player if online on char-server
+ disconnect_player(account_id);
+ }
+ }
+ break;
+ case 7: //char unban
+ /* handled by char server, so no redirection */
+ if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `unban_time` = '0' WHERE `char_id` = '%d' LIMIT 1", char_db, char_id) ) {
+ Sql_ShowDebug(sql_handle);
+ result = 1;
+ }
+ break;
+
+ }
}
}
SQL->FreeResult(sql_handle);
// send answer if a player ask, not if the server ask
- if( acc != -1 && type != 5) { // Don't send answer for changesex
+ if( acc != -1 && type != 5 ) { // Don't send answer for changesex
WFIFOHEAD(fd,34);
WFIFOW(fd, 0) = 0x2b0f;
WFIFOL(fd, 2) = acc;
@@ -3184,12 +3501,11 @@ int parse_frommap(int fd)
int player_pos;
int fame_pos;
- switch(type)
- {
- case 1: size = fame_list_size_smith; list = smith_fame_list; break;
- case 2: size = fame_list_size_chemist; list = chemist_fame_list; break;
- case 3: size = fame_list_size_taekwon; list = taekwon_fame_list; break;
- default: size = 0; list = NULL; break;
+ switch(type) {
+ case RANKTYPE_BLACKSMITH: size = fame_list_size_smith; list = smith_fame_list; break;
+ case RANKTYPE_ALCHEMIST: size = fame_list_size_chemist; list = chemist_fame_list; break;
+ case RANKTYPE_TAEKWON: size = fame_list_size_taekwon; list = taekwon_fame_list; break;
+ default: size = 0; list = NULL; break;
}
ARR_FIND(0, size, player_pos, list[player_pos].id == cid);// position of the player
@@ -3197,22 +3513,20 @@ int parse_frommap(int fd)
if( player_pos == size && fame_pos == size )
;// not on list and not enough fame to get on it
- else if( fame_pos == player_pos )
- {// same position
+ else if( fame_pos == player_pos ) {
+ // same position
list[player_pos].fame = fame;
char_update_fame_list(type, player_pos, fame);
- }
- else
- {// move in the list
- if( player_pos == size )
- {// new ranker - not in the list
+ } else {
+ // move in the list
+ if( player_pos == size ) {
+ // new ranker - not in the list
ARR_MOVE(size - 1, fame_pos, list, struct fame_list);
list[fame_pos].id = cid;
list[fame_pos].fame = fame;
char_loadName(cid, list[fame_pos].name);
- }
- else
- {// already in the list
+ } else {
+ // already in the list
if( fame_pos == size )
--fame_pos;// move to the end of the list
ARR_MOVE(player_pos, fame_pos, list, struct fame_list);
@@ -3287,11 +3601,14 @@ int parse_frommap(int fd)
cid = RFIFOL(fd, 8);
count = RFIFOW(fd, 12);
+ /* clear; ensure no left overs e.g. permanent */
+ if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", scdata_db, aid, cid) )
+ Sql_ShowDebug(sql_handle);
+
if( count > 0 )
{
struct status_change_data data;
StringBuf buf;
- int i;
StrBuf->Init(&buf);
StrBuf->Printf(&buf, "INSERT INTO `%s` (`account_id`, `char_id`, `type`, `tick`, `val1`, `val2`, `val3`, `val4`) VALUES ", scdata_db);
@@ -3320,14 +3637,14 @@ int parse_frommap(int fd)
break;
case 0x2b26: // auth request from map-server
- if (RFIFOREST(fd) < 19)
+ if (RFIFOREST(fd) < 20)
return 0;
{
int account_id;
int char_id;
int login_id1;
- char sex;
+ char sex, standalone;
uint32 ip;
struct auth_node* node;
struct mmo_charstatus* cd;
@@ -3338,15 +3655,36 @@ int parse_frommap(int fd)
login_id1 = RFIFOL(fd,10);
sex = RFIFOB(fd,14);
ip = ntohl(RFIFOL(fd,15));
- RFIFOSKIP(fd,19);
+ standalone = RFIFOB(fd, 19);
+ RFIFOSKIP(fd,20);
node = (struct auth_node*)idb_get(auth_db, account_id);
cd = (struct mmo_charstatus*)uidb_get(char_db_,char_id);
- if( cd == NULL )
- { //Really shouldn't happen.
+
+ if( cd == NULL ) { //Really shouldn't happen.
mmo_char_fromsql(char_id, &char_dat, true);
cd = (struct mmo_charstatus*)uidb_get(char_db_,char_id);
}
+
+ if( runflag == CHARSERVER_ST_RUNNING && cd && standalone ) {
+ cd->sex = sex;
+
+ WFIFOHEAD(fd,25 + sizeof(struct mmo_charstatus));
+ WFIFOW(fd,0) = 0x2afd;
+ WFIFOW(fd,2) = 25 + sizeof(struct mmo_charstatus);
+ WFIFOL(fd,4) = account_id;
+ WFIFOL(fd,8) = 0;
+ WFIFOL(fd,12) = 0;
+ WFIFOL(fd,16) = 0;
+ WFIFOL(fd,20) = 0;
+ WFIFOB(fd,24) = 0;
+ memcpy(WFIFOP(fd,25), cd, sizeof(struct mmo_charstatus));
+ WFIFOSET(fd, WFIFOW(fd,2));
+
+ set_char_online(id, char_id, account_id);
+ break;
+ }
+
if( runflag == CHARSERVER_ST_RUNNING &&
cd != NULL &&
node != NULL &&
@@ -3429,6 +3767,40 @@ int parse_frommap(int fd)
RFIFOFLUSH(fd);
}
break;
+
+ /* individual sc data insertion/update */
+ case 0x2740:
+ if( RFIFOREST(fd) < 28 )
+ return 0;
+ else {
+ int account_id = RFIFOL(fd, 2), char_id = RFIFOL(fd, 6),
+ val1 = RFIFOL(fd, 12), val2 = RFIFOL(fd, 16),
+ val3 = RFIFOL(fd, 20), val4 = RFIFOL(fd, 24);
+ short type = RFIFOW(fd, 10);
+
+ if( SQL_ERROR == SQL->Query(sql_handle, "REPLACE INTO `%s` (`account_id`,`char_id`,`type`,`tick`,`val1`,`val2`,`val3`,`val4`) VALUES ('%d','%d','%d',-1,'%d','%d','%d','%d')",
+ scdata_db, account_id, char_id, type, val1, val2, val3, val4) )
+ Sql_ShowDebug(sql_handle);
+
+ RFIFOSKIP(fd, 28);
+ }
+ break;
+
+ /* individual sc data delete */
+ case 0x2741:
+ if( RFIFOREST(fd) < 12 )
+ return 0;
+ else {
+ int account_id = RFIFOL(fd, 2), char_id = RFIFOL(fd, 6);
+ short type = RFIFOW(fd, 10);
+
+ if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `char_id` = '%d' AND `type` = '%d' LIMIT 1",
+ scdata_db, account_id, char_id, type) )
+ Sql_ShowDebug(sql_handle);
+
+ RFIFOSKIP(fd, 12);
+ }
+ break;
default:
@@ -3507,6 +3879,7 @@ int lan_subnetcheck(uint32 ip)
}
+/// Answers to deletion request (HC_DELETE_CHAR3_RESERVED)
/// @param result
/// 0 (0x718): An unknown error has occurred.
/// 1: none/success
@@ -3520,7 +3893,12 @@ void char_delete2_ack(int fd, int char_id, uint32 result, time_t delete_date)
WFIFOW(fd,0) = 0x828;
WFIFOL(fd,2) = char_id;
WFIFOL(fd,6) = result;
- WFIFOL(fd,10) = TOL(delete_date);
+#if PACKETVER >= 20130000
+ WFIFOL(fd,10) = (int)(delete_date - time(NULL));
+#else
+ WFIFOL(fd,10) = (int)delete_date;
+
+#endif
WFIFOSET(fd,14);
}
@@ -3535,6 +3913,14 @@ void char_delete2_ack(int fd, int char_id, uint32 result, time_t delete_date)
/// Any (0x718): An unknown error has occurred.
void char_delete2_accept_ack(int fd, int char_id, uint32 result)
{// HC: <082a>.W <char id>.L <Msg:0-5>.L
+
+#if PACKETVER >= 20130000 /* not sure the exact date -- must refresh or client gets stuck */
+ if( result == 1 ) {
+ struct char_session_data* sd = (struct char_session_data*)session[fd]->session_data;
+ mmo_char_send099d(fd, sd);
+ }
+#endif
+
WFIFOHEAD(fd,10);
WFIFOW(fd,0) = 0x82a;
WFIFOL(fd,2) = char_id;
@@ -3559,7 +3945,7 @@ void char_delete2_cancel_ack(int fd, int char_id, uint32 result)
static void char_delete2_req(int fd, struct char_session_data* sd)
{// CH: <0827>.W <char id>.L
- int char_id, i;
+ int char_id, party_id, guild_id, i;
char* data;
time_t delete_date;
@@ -3586,22 +3972,34 @@ static void char_delete2_req(int fd, struct char_session_data* sd)
return;
}
-/*
- // Aegis imposes these checks probably to avoid dead member
- // entries in guilds/parties, otherwise they are not required.
- // TODO: Figure out how these are enforced during waiting.
- if( guild_id )
- {// character in guild
- char_delete2_ack(fd, char_id, 4, 0);
- return;
- }
+ // This check is imposed by Aegis to avoid dead entries in databases
+ // _it is not needed_ as we clear data properly
+ // see issue: 7338
+ if( char_aegis_delete )
+ {
+ if( SQL_SUCCESS != SQL->Query(sql_handle, "SELECT `party_id`, `guild_id` FROM `%s` WHERE `char_id`='%d'", char_db, char_id)
+ || SQL_SUCCESS != SQL->NextRow(sql_handle)
+ )
+ {
+ Sql_ShowDebug(sql_handle);
+ char_delete2_ack(fd, char_id, 3, 0);
+ return;
+ }
+ SQL->GetData(sql_handle, 0, &data, NULL); party_id = atoi(data);
+ SQL->GetData(sql_handle, 1, &data, NULL); guild_id = atoi(data);
- if( party_id )
- {// character in party
- char_delete2_ack(fd, char_id, 5, 0);
- return;
+ if( guild_id )
+ {
+ char_delete2_ack(fd, char_id, 4, 0);
+ return;
+ }
+
+ if( party_id )
+ {
+ char_delete2_ack(fd, char_id, 5, 0);
+ return;
+ }
}
-*/
// success
delete_date = time(NULL)+char_del_delay;
@@ -3620,7 +4018,7 @@ static void char_delete2_req(int fd, struct char_session_data* sd)
static void char_delete2_accept(int fd, struct char_session_data* sd)
{// CH: <0829>.W <char id>.L <birth date:YYMMDD>.6B
char birthdate[8+1];
- int char_id, i, k;
+ int char_id, i;
unsigned int base_level;
char* data;
time_t delete_date;
@@ -3683,11 +4081,8 @@ static void char_delete2_accept(int fd, struct char_session_data* sd)
}
// refresh character list cache
- for(k = i; k < MAX_CHARS-1; k++) {
- sd->found_char[k] = sd->found_char[k+1];
- }
- sd->found_char[MAX_CHARS-1] = -1;
-
+ sd->found_char[i] = -1;
+
char_delete2_accept_ack(fd, char_id, 1);
}
@@ -3721,7 +4116,6 @@ static void char_delete2_cancel(int fd, struct char_session_data* sd)
int parse_char(int fd)
{
- int i, ch;
char email[40];
unsigned short cmd;
int map_fd;
@@ -3750,8 +4144,14 @@ int parse_char(int fd)
while( RFIFOREST(fd) >= 2 ) {
//For use in packets that depend on an sd being present [Skotlex]
- #define FIFOSD_CHECK(rest) { if(RFIFOREST(fd) < rest) return 0; if (sd==NULL || !sd->auth) { RFIFOSKIP(fd,rest); return 0; } }
+ #define FIFOSD_CHECK(rest) do { if(RFIFOREST(fd) < (rest)) return 0; if (sd==NULL || !sd->auth) { RFIFOSKIP(fd,(rest)); return 0; } } while (0)
+ if( HPM->packetsc[hpParse_Char] ) {
+ int success = HPM->parse_packets(fd,hpParse_Char);
+ if( success == 1 ) continue;
+ else if( success == 2 ) return 0;
+ }
+
cmd = RFIFOW(fd,0);
switch( cmd ) {
@@ -3773,7 +4173,7 @@ int parse_char(int fd)
ShowInfo("request connect - account_id:%d/login_id1:%d/login_id2:%d\n", account_id, login_id1, login_id2);
if (sd) {
- //Received again auth packet for already authentified account?? Discard it.
+ //Received again auth packet for already authenticated account?? Discard it.
//TODO: Perhaps log this as a hack attempt?
//TODO: and perhaps send back a reply?
break;
@@ -3792,8 +4192,7 @@ int parse_char(int fd)
WFIFOL(fd,0) = account_id;
WFIFOSET(fd,4);
- if( runflag != CHARSERVER_ST_RUNNING )
- {
+ if( runflag != CHARSERVER_ST_RUNNING ) {
WFIFOHEAD(fd,3);
WFIFOW(fd,0) = 0x6c;
WFIFOB(fd,2) = 0;// rejected from server
@@ -3801,7 +4200,7 @@ int parse_char(int fd)
break;
}
- // search authentification
+ // search authentication
node = (struct auth_node*)idb_get(auth_db, account_id);
if( node != NULL &&
node->account_id == account_id &&
@@ -3809,6 +4208,22 @@ int parse_char(int fd)
node->login_id2 == login_id2 /*&&
node->ip == ipl*/ )
{// authentication found (coming from map server)
+ /* restrictions apply */
+ if( char_server_type == CST_MAINTENANCE && node->group_id < char_maintenance_min_group_id ) {
+ WFIFOHEAD(fd,3);
+ WFIFOW(fd,0) = 0x6c;
+ WFIFOB(fd,2) = 0;// rejected from server
+ WFIFOSET(fd,3);
+ break;
+ }
+ /* the client will already deny this request, this check is to avoid someone bypassing. */
+ if( char_server_type == CST_PAYING && (time_t)node->expiration_time < time(NULL) ) {
+ WFIFOHEAD(fd,3);
+ WFIFOW(fd,0) = 0x6c;
+ WFIFOB(fd,2) = 0;// rejected from server
+ WFIFOSET(fd,3);
+ break;
+ }
idb_remove(auth_db, account_id);
char_auth_ok(fd, sd);
}
@@ -3816,7 +4231,7 @@ int parse_char(int fd)
{// authentication not found (coming from login server)
if (login_fd > 0) { // don't send request if no login-server
WFIFOHEAD(login_fd,23);
- WFIFOW(login_fd,0) = 0x2712; // ask login-server to authentify an account
+ WFIFOW(login_fd,0) = 0x2712; // ask login-server to authenticate an account
WFIFOL(login_fd,2) = sd->account_id;
WFIFOL(login_fd,6) = sd->login_id1;
WFIFOL(login_fd,10) = sd->login_id2;
@@ -3844,12 +4259,15 @@ int parse_char(int fd)
int char_id;
uint32 subnet_map_ip;
struct auth_node* node;
+ int server_id = 0;
+ int i;
int slot = RFIFOB(fd,2);
RFIFOSKIP(fd,3);
+
#if PACKETVER >= 20110309
if( *pincode->enabled ){ // hack check
- struct online_char_data* character;
+ struct online_char_data* character;
character = (struct online_char_data*)idb_get(online_char_db, sd->account_id);
if( character && character->pincode_enable == -1){
WFIFOHEAD(fd,3);
@@ -3860,6 +4278,19 @@ int parse_char(int fd)
}
}
#endif
+
+ ARR_FIND( 0, ARRAYLENGTH(server), server_id, server[server_id].fd > 0 && server[server_id].map[0] );
+ /* not available, tell it to wait (client wont close; char select will respawn).
+ * magic response found by Ind thanks to Yommy <3 */
+ if( server_id == ARRAYLENGTH(server) ) {
+ WFIFOHEAD(fd, 24);
+ WFIFOW(fd, 0) = 0x840;
+ WFIFOW(fd, 2) = 24;
+ safestrncpy((char*)WFIFOP(fd,4), "0", 20);/* we can't send empty (otherwise the list will pop up) */
+ WFIFOSET(fd, 24);
+ break;
+ }
+
if ( SQL_SUCCESS != SQL->Query(sql_handle, "SELECT `char_id` FROM `%s` WHERE `account_id`='%d' AND `char_num`='%d'", char_db, sd->account_id, slot)
|| SQL_SUCCESS != SQL->NextRow(sql_handle)
|| SQL_SUCCESS != SQL->GetData(sql_handle, 0, &data, NULL) )
@@ -3876,7 +4307,16 @@ int parse_char(int fd)
char_id = atoi(data);
SQL->FreeResult(sql_handle);
- /* set char as online prior to loading its data so 3rd party applications will realise the sql data is not reliable */
+ /* client doesn't let it get to this point if you're banned, so its a forged packet */
+ if( sd->found_char[slot] == char_id && sd->unban_time[slot] > time(NULL) ) {
+ WFIFOHEAD(fd,3);
+ WFIFOW(fd,0) = 0x6c;
+ WFIFOB(fd,2) = 0; // rejected from server
+ WFIFOSET(fd,3);
+ break;
+ }
+
+ /* set char as online prior to loading its data so 3rd party applications will realize the sql data is not reliable */
set_char_online(-2,char_id,sd->account_id);
if( !mmo_char_fromsql(char_id, &char_dat, true) ) { /* failed? set it back offline */
set_char_offline(char_id, sd->account_id);
@@ -3894,10 +4334,11 @@ int parse_char(int fd)
if (log_char) {
char esc_name[NAME_LENGTH*2+1];
-
+ // FIXME: Why are we re-escaping the name if it was already escaped in rename/make_new_char? [Panikon]
SQL->EscapeStringLen(sql_handle, esc_name, char_dat.name, strnlen(char_dat.name, NAME_LENGTH));
- if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s`(`time`, `account_id`,`char_num`,`name`) VALUES (NOW(), '%d', '%d', '%s')",
- charlog_db, sd->account_id, slot, esc_name) )
+ if( SQL_ERROR == SQL->Query(sql_handle,
+ "INSERT INTO `%s`(`time`, `account_id`, `char_id`, `char_num`, `name`) VALUES (NOW(), '%d', '%d', '%d', '%s')",
+ charlog_db, sd->account_id, cd->char_id, slot, esc_name) )
Sql_ShowDebug(sql_handle);
}
ShowInfo("Selected char: (Account %d: %d - %s)\n", sd->account_id, slot, char_dat.name);
@@ -3918,22 +4359,22 @@ int parse_char(int fd)
WFIFOSET(fd,3);
break;
}
- if ((i = search_mapserver((j=mapindex_name2id(MAP_PRONTERA)),-1,-1)) >= 0) {
+ if ((i = search_mapserver((j=mapindex->name2id(MAP_PRONTERA)),-1,-1)) >= 0) {
cd->last_point.x = 273;
cd->last_point.y = 354;
- } else if ((i = search_mapserver((j=mapindex_name2id(MAP_GEFFEN)),-1,-1)) >= 0) {
+ } else if ((i = search_mapserver((j=mapindex->name2id(MAP_GEFFEN)),-1,-1)) >= 0) {
cd->last_point.x = 120;
cd->last_point.y = 100;
- } else if ((i = search_mapserver((j=mapindex_name2id(MAP_MORROC)),-1,-1)) >= 0) {
+ } else if ((i = search_mapserver((j=mapindex->name2id(MAP_MORROC)),-1,-1)) >= 0) {
cd->last_point.x = 160;
cd->last_point.y = 94;
- } else if ((i = search_mapserver((j=mapindex_name2id(MAP_ALBERTA)),-1,-1)) >= 0) {
+ } else if ((i = search_mapserver((j=mapindex->name2id(MAP_ALBERTA)),-1,-1)) >= 0) {
cd->last_point.x = 116;
cd->last_point.y = 57;
- } else if ((i = search_mapserver((j=mapindex_name2id(MAP_PAYON)),-1,-1)) >= 0) {
+ } else if ((i = search_mapserver((j=mapindex->name2id(MAP_PAYON)),-1,-1)) >= 0) {
cd->last_point.x = 87;
cd->last_point.y = 117;
- } else if ((i = search_mapserver((j=mapindex_name2id(MAP_IZLUDE)),-1,-1)) >= 0) {
+ } else if ((i = search_mapserver((j=mapindex->name2id(MAP_IZLUDE)),-1,-1)) >= 0) {
cd->last_point.x = 94;
cd->last_point.y = 103;
} else {
@@ -3967,7 +4408,7 @@ int parse_char(int fd)
WFIFOHEAD(fd,28);
WFIFOW(fd,0) = 0x71;
WFIFOL(fd,2) = cd->char_id;
- mapindex_getmapname_ext(mapindex_id2name(cd->last_point.map), (char*)WFIFOP(fd,6));
+ mapindex->getmapname_ext(mapindex_id2name(cd->last_point.map), (char*)WFIFOP(fd,6));
subnet_map_ip = lan_subnetcheck(ipl); // Advanced subnet check [LuzZza]
WFIFOL(fd,22) = htonl((subnet_map_ip) ? subnet_map_ip : server[i].ip);
WFIFOW(fd,26) = ntows(htons(server[i].port)); // [!] LE byte order here [!]
@@ -3992,41 +4433,51 @@ int parse_char(int fd)
#if PACKETVER >= 20120307
// S 0970 <name>.24B <slot>.B <hair color>.W <hair style>.W
case 0x970:
+ {
+ int result;
FIFOSD_CHECK(31);
#else
// S 0067 <name>.24B <str>.B <agi>.B <vit>.B <int>.B <dex>.B <luk>.B <slot>.B <hair color>.W <hair style>.W
case 0x67:
+ {
+ int result;
FIFOSD_CHECK(37);
#endif
if( !char_new ) //turn character creation on/off [Kevin]
- i = -2;
+ result = -2;
else
#if PACKETVER >= 20120307
- i = make_new_char_sql(sd, (char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOW(fd,27),RFIFOW(fd,29));
+ result = make_new_char_sql(sd, (char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOW(fd,27),RFIFOW(fd,29));
#else
- i = make_new_char_sql(sd, (char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27),RFIFOB(fd,28),RFIFOB(fd,29),RFIFOB(fd,30),RFIFOB(fd,31),RFIFOB(fd,32),RFIFOW(fd,33),RFIFOW(fd,35));
+ result = make_new_char_sql(sd, (char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27),RFIFOB(fd,28),RFIFOB(fd,29),RFIFOB(fd,30),RFIFOB(fd,31),RFIFOB(fd,32),RFIFOW(fd,33),RFIFOW(fd,35));
#endif
- //'Charname already exists' (-1), 'Char creation denied' (-2) and 'You are underaged' (-3)
- if (i < 0) {
+ if (result < 0) {
WFIFOHEAD(fd,3);
WFIFOW(fd,0) = 0x6e;
/* Others I found [Ind] */
/* 0x02 = Symbols in Character Names are forbidden */
- /* 0x03 = You are not elegible to open the Character Slot. */
- switch (i) {
- case -1: WFIFOB(fd,2) = 0x00; break;
- case -2: WFIFOB(fd,2) = 0xFF; break;
- case -3: WFIFOB(fd,2) = 0x01; break;
- case -4: WFIFOB(fd,2) = 0x03; break;
+ /* 0x03 = You are not eligible to open the Character Slot. */
+ /* 0x0B = This service is only available for premium users. */
+ switch (result) {
+ case -1: WFIFOB(fd,2) = 0x00; break; // 'Charname already exists'
+ case -2: WFIFOB(fd,2) = 0xFF; break; // 'Char creation denied'
+ case -3: WFIFOB(fd,2) = 0x01; break; // 'You are underaged'
+ case -4: WFIFOB(fd,2) = 0x03; break; // 'You are not eligible to open the Character Slot.'
+ case -5: WFIFOB(fd,2) = 0x02; break; // 'Symbols in Character Names are forbidden'
+
+ default:
+ ShowWarning("parse_char: Unknown result received from make_new_char_sql!\n");
+ WFIFOB(fd,2) = 0xFF;
+ break;
}
WFIFOSET(fd,3);
} else {
int len;
// retrieve data
struct mmo_charstatus char_dat;
- mmo_char_fromsql(i, &char_dat, false); //Only the short data is needed.
+ mmo_char_fromsql(result, &char_dat, false); //Only the short data is needed.
// send to player
WFIFOHEAD(fd,2+MAX_CHAR_BUF);
@@ -4035,15 +4486,14 @@ int parse_char(int fd)
WFIFOSET(fd,len);
// add new entry to the chars list
- ARR_FIND( 0, MAX_CHARS, ch, sd->found_char[ch] == -1 );
- if( ch < MAX_CHARS )
- sd->found_char[ch] = i; // the char_id of the new char
+ sd->found_char[char_dat.slot] = result; // the char_id of the new char
}
#if PACKETVER >= 20120307
RFIFOSKIP(fd,31);
#else
RFIFOSKIP(fd,37);
#endif
+ }
break;
// delete char
@@ -4054,9 +4504,10 @@ int parse_char(int fd)
if (cmd == 0x1fb) FIFOSD_CHECK(56);
{
int cid = RFIFOL(fd,2);
+ int i;
#if PACKETVER >= 20110309
if( *pincode->enabled ){ // hack check
- struct online_char_data* character;
+ struct online_char_data* character;
character = (struct online_char_data*)idb_get(online_char_db, sd->account_id);
if( character && character->pincode_enable == -1 ){
WFIFOHEAD(fd,3);
@@ -4096,9 +4547,7 @@ int parse_char(int fd)
}
// remove char from list and compact it
- for(ch = i; ch < MAX_CHARS-1; ch++)
- sd->found_char[ch] = sd->found_char[ch+1];
- sd->found_char[MAX_CHARS-1] = -1;
+ sd->found_char[i] = -1;
/* Delete character */
if(delete_char_sql(cid)<0){
@@ -4191,7 +4640,7 @@ int parse_char(int fd)
//Confirm change name.
// 0x28f <char_id>.L
case 0x28f:
- // 0: Sucessfull
+ // 0: Successful
// 1: This character's name has already been changed. You cannot change a character's name more than once.
// 2: User information is not correct.
// 3: You have failed to change this character's name.
@@ -4264,6 +4713,7 @@ int parse_char(int fd)
{
char* l_user = (char*)RFIFOP(fd,2);
char* l_pass = (char*)RFIFOP(fd,26);
+ int i;
l_user[23] = '\0';
l_pass[23] = '\0';
ARR_FIND( 0, ARRAYLENGTH(server), i, server[i].fd <= 0 );
@@ -4291,11 +4741,11 @@ int parse_char(int fd)
realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
char_mapif_init(fd);
}
- socket_datasync(fd, true);
+ sockt->datasync(fd, true);
RFIFOSKIP(fd,60);
}
- return 0; // avoid processing of followup packets here
+ return 0; // avoid processing of follow-up packets here
// checks the entered pin
case 0x8b8:
@@ -4426,8 +4876,7 @@ int mapif_send(int fd, unsigned char *buf, unsigned int len)
return 0;
}
-int broadcast_user_count(int tid, unsigned int tick, int id, intptr_t data)
-{
+int broadcast_user_count(int tid, int64 tick, int id, intptr_t data) {
uint8 buf[6];
int users = count_users();
@@ -4472,8 +4921,7 @@ static int send_accounts_tologin_sub(DBKey key, DBData *data, va_list ap)
return 0;
}
-int send_accounts_tologin(int tid, unsigned int tick, int id, intptr_t data)
-{
+int send_accounts_tologin(int tid, int64 tick, int id, intptr_t data) {
if (login_fd > 0 && session[login_fd])
{
// send account list to login server
@@ -4490,8 +4938,7 @@ int send_accounts_tologin(int tid, unsigned int tick, int id, intptr_t data)
return 0;
}
-int check_connect_login_server(int tid, unsigned int tick, int id, intptr_t data)
-{
+int check_connect_login_server(int tid, int64 tick, int id, intptr_t data) {
if (login_fd > 0 && session[login_fd] != NULL)
return 0;
@@ -4515,7 +4962,7 @@ int check_connect_login_server(int tid, unsigned int tick, int id, intptr_t data
WFIFOW(login_fd,58) = htons(char_port);
memcpy(WFIFOP(login_fd,60), server_name, 20);
WFIFOW(login_fd,80) = 0;
- WFIFOW(login_fd,82) = char_maintenance;
+ WFIFOW(login_fd,82) = char_server_type;
WFIFOW(login_fd,84) = char_new_display; //only display (New) if they want to [Kevin]
WFIFOSET(login_fd,86);
@@ -4526,8 +4973,7 @@ int check_connect_login_server(int tid, unsigned int tick, int id, intptr_t data
//Invoked 15 seconds after mapif_disconnectplayer in case the map server doesn't
//replies/disconnect the player we tried to kick. [Skotlex]
//------------------------------------------------
-static int chardb_waiting_disconnect(int tid, unsigned int tick, int id, intptr_t data)
-{
+static int chardb_waiting_disconnect(int tid, int64 tick, int id, intptr_t data) {
struct online_char_data* character;
if ((character = (struct online_char_data*)idb_get(online_char_db, id)) != NULL && character->waiting_disconnect == tid)
{ //Mark it offline due to timeout.
@@ -4553,15 +4999,14 @@ static int online_data_cleanup_sub(DBKey key, DBData *data, va_list ap)
return 0;
}
-static int online_data_cleanup(int tid, unsigned int tick, int id, intptr_t data)
-{
+static int online_data_cleanup(int tid, int64 tick, int id, intptr_t data) {
online_char_db->foreach(online_char_db, online_data_cleanup_sub);
return 0;
}
//----------------------------------
-// Reading Lan Support configuration
-// Rewrote: Anvanced subnet check [LuzZza]
+// Reading LAN Support configuration
+// Rewrote: Advanced subnet check [LuzZza]
//----------------------------------
int char_lan_config_read(const char *lancfgName)
{
@@ -4579,7 +5024,7 @@ int char_lan_config_read(const char *lancfgName)
if ((line[0] == '/' && line[1] == '/') || line[0] == '\n' || line[1] == '\n')
continue;
- if(sscanf(line,"%[^:]: %[^:]:%[^:]:%[^\r\n]", w1, w2, w3, w4) != 4) {
+ if (sscanf(line,"%63[^:]: %63[^:]:%63[^:]:%63[^\r\n]", w1, w2, w3, w4) != 4) {
ShowWarning("Error syntax of configuration file %s in line %d.\n", lancfgName, line_num);
continue;
@@ -4628,7 +5073,7 @@ void sql_config_read(const char* cfgName)
if(line[0] == '/' && line[1] == '/')
continue;
- if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
+ if (sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2) != 2)
continue;
if(!strcmpi(w1,"char_db"))
@@ -4643,8 +5088,6 @@ void sql_config_read(const char* cfgName)
safestrncpy(charlog_db, w2, sizeof(charlog_db));
else if(!strcmpi(w1,"storage_db"))
safestrncpy(storage_db, w2, sizeof(storage_db));
- else if(!strcmpi(w1,"reg_db"))
- safestrncpy(reg_db, w2, sizeof(reg_db));
else if(!strcmpi(w1,"skill_db"))
safestrncpy(skill_db, w2, sizeof(skill_db));
else if(!strcmpi(w1,"interlog_db"))
@@ -4691,8 +5134,21 @@ void sql_config_read(const char* cfgName)
safestrncpy(mercenary_owner_db,w2,sizeof(mercenary_owner_db));
else if(!strcmpi(w1,"ragsrvinfo_db"))
safestrncpy(ragsrvinfo_db,w2,sizeof(ragsrvinfo_db));
+ else if(!strcmpi(w1,"elemental_db"))
+ safestrncpy(elemental_db,w2,sizeof(elemental_db));
else if(!strcmpi(w1,"interreg_db"))
safestrncpy(interreg_db,w2,sizeof(interreg_db));
+ else if(!strcmpi(w1,"account_data_db"))
+ safestrncpy(account_data_db,w2,sizeof(account_data_db));
+ else if(!strcmpi(w1,"char_reg_num_db"))
+ safestrncpy(char_reg_num_db, w2, sizeof(char_reg_num_db));
+ else if(!strcmpi(w1,"char_reg_str_db"))
+ safestrncpy(char_reg_str_db, w2, sizeof(char_reg_str_db));
+ else if(!strcmpi(w1,"acc_reg_str_db"))
+ safestrncpy(acc_reg_str_db, w2, sizeof(acc_reg_str_db));
+ else if(!strcmpi(w1,"acc_reg_num_db"))
+ safestrncpy(acc_reg_num_db, w2, sizeof(acc_reg_num_db));
+
//support the import command, just like any other config
else if(!strcmpi(w1,"import"))
sql_config_read(w2);
@@ -4725,7 +5181,7 @@ int char_config_read(const char* cfgName)
if (line[0] == '/' && line[1] == '/')
continue;
- if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
+ if (sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2) != 2)
continue;
remove_control_chars(w1);
@@ -4773,8 +5229,8 @@ int char_config_read(const char* cfgName)
}
} else if (strcmpi(w1, "char_port") == 0) {
char_port = atoi(w2);
- } else if (strcmpi(w1, "char_maintenance") == 0) {
- char_maintenance = atoi(w2);
+ } else if (strcmpi(w1, "char_server_type") == 0) {
+ char_server_type = atoi(w2);
} else if (strcmpi(w1, "char_new") == 0) {
char_new = (bool)atoi(w2);
} else if (strcmpi(w1, "char_new_display") == 0) {
@@ -4796,7 +5252,7 @@ int char_config_read(const char* cfgName)
int x, y;
if (sscanf(w2, "%15[^,],%d,%d", map, &x, &y) < 3)
continue;
- start_point.map = mapindex_name2id(map);
+ start_point.map = mapindex->name2id(map);
if (!start_point.map)
ShowError("Specified start_point %s not found in map-index cache.\n", map);
start_point.x = x;
@@ -4807,18 +5263,25 @@ int char_config_read(const char* cfgName)
i = 0;
split = strtok(w2, ",");
- while (split != NULL && i < MAX_START_ITEMS*2) {
+ while (split != NULL && i < MAX_START_ITEMS*3) {
split2 = split;
split = strtok(NULL, ",");
start_items[i] = atoi(split2);
+
if (start_items[i] < 0)
start_items[i] = 0;
+
++i;
}
- if (i%2) { //we know it must be a even number
- ShowError("Specified 'start_items' is missing a parameter. Removing '%d'.\n", start_items[i - 1]);
- start_items[i - 1] = 0;
+ // Format is: id1,quantity1,stackable1,idN,quantityN,stackableN
+ if( i%3 )
+ {
+ ShowWarning("char_config_read: There are not enough parameters in start_items, ignoring last item...\n");
+ if( i%3 == 1 )
+ start_items[i-1] = 0;
+ else
+ start_items[i-2] = 0;
}
} else if (strcmpi(w1, "start_zeny") == 0) {
start_zeny = atoi(w2);
@@ -4839,6 +5302,8 @@ int char_config_read(const char* cfgName)
char_del_level = atoi(w2);
} else if (strcmpi(w1, "char_del_delay") == 0) {
char_del_delay = atoi(w2);
+ } else if (strcmpi(w1, "char_aegis_delete") == 0) {
+ char_aegis_delete = atoi(w2);
} else if(strcmpi(w1,"db_path")==0) {
safestrncpy(db_path, w2, sizeof(db_path));
} else if (strcmpi(w1, "fame_list_alchemist") == 0) {
@@ -4861,6 +5326,8 @@ int char_config_read(const char* cfgName)
}
} else if (strcmpi(w1, "guild_exp_rate") == 0) {
guild_exp_rate = atoi(w2);
+ } else if (strcmpi(w1, "char_maintenance_min_group_id") == 0) {
+ char_maintenance_min_group_id = atoi(w2);
} else if (strcmpi(w1, "import") == 0) {
char_config_read(w2);
} else
@@ -4872,10 +5339,13 @@ int char_config_read(const char* cfgName)
return 0;
}
-void do_final(void) {
+int do_final(void) {
int i;
+
ShowStatus("Terminating...\n");
+ HPM->event(HPET_FINAL);
+
set_all_offline(-1);
set_all_offline_sql();
@@ -4899,13 +5369,14 @@ void do_final(void) {
}
SQL->Free(sql_handle);
- mapindex_final();
+ mapindex->final();
for(i = 0; i < MAX_MAP_SERVERS; i++ )
if( server[i].map )
aFree(server[i].map);
ShowStatus("Finished.\n");
+ return EXIT_SUCCESS;
}
//------------------------------
@@ -4946,13 +5417,13 @@ int do_init(int argc, char **argv) {
for(i = 0; i < MAX_MAP_SERVERS; i++ )
server[i].map = NULL;
- //Read map indexes
- mapindex_init();
- start_point.map = mapindex_name2id("new_zone01");
-
-
+ mapindex_defaults();
pincode_defaults();
+ //Read map indexes
+ mapindex->init();
+ start_point.map = mapindex->name2id("new_zone01");
+
char_config_read((argc < 2) ? CHAR_CONF_NAME : argv[1]);
char_lan_config_read((argc > 3) ? argv[3] : LAN_CONF_NAME);
sql_config_read(SQL_CONF_NAME);
@@ -4967,14 +5438,19 @@ int do_init(int argc, char **argv) {
auth_db = idb_alloc(DB_OPT_RELEASE_DATA);
online_char_db = idb_alloc(DB_OPT_RELEASE_DATA);
+
+ HPM->share(sql_handle,"sql_handle");
+ HPM->config_read(NULL, 0);
+ HPM->event(HPET_INIT);
+
mmo_char_sql_init();
char_read_fame_list(); //Read fame lists.
- if ((naddr_ != 0) && (!login_ip || !char_ip)) {
+ if ((sockt->naddr_ != 0) && (!login_ip || !char_ip)) {
char ip_str[16];
- ip2str(addr_[0], ip_str);
+ ip2str(sockt->addr_[0], ip_str);
- if (naddr_ > 1)
+ if (sockt->naddr_ > 1)
ShowStatus("Multiple interfaces detected.. using %s as our IP address\n", ip_str);
else
ShowStatus("Defaulting to %s as our IP address\n", ip_str);
@@ -4992,17 +5468,17 @@ int do_init(int argc, char **argv) {
do_init_mapif();
// periodically update the overall user count on all mapservers + login server
- iTimer->add_timer_func_list(broadcast_user_count, "broadcast_user_count");
- iTimer->add_timer_interval(iTimer->gettick() + 1000, broadcast_user_count, 0, 0, 5 * 1000);
+ timer->add_func_list(broadcast_user_count, "broadcast_user_count");
+ timer->add_interval(timer->gettick() + 1000, broadcast_user_count, 0, 0, 5 * 1000);
// Timer to clear (online_char_db)
- iTimer->add_timer_func_list(chardb_waiting_disconnect, "chardb_waiting_disconnect");
+ timer->add_func_list(chardb_waiting_disconnect, "chardb_waiting_disconnect");
// Online Data timers (checking if char still connected)
- iTimer->add_timer_func_list(online_data_cleanup, "online_data_cleanup");
- iTimer->add_timer_interval(iTimer->gettick() + 1000, online_data_cleanup, 0, 0, 600 * 1000);
+ timer->add_func_list(online_data_cleanup, "online_data_cleanup");
+ timer->add_interval(timer->gettick() + 1000, online_data_cleanup, 0, 0, 600 * 1000);
- //Cleaning the tables for NULL entrys @ startup [Sirius]
+ //Cleaning the tables for NULL entries @ startup [Sirius]
//Chardb clean
if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '0'", char_db) )
Sql_ShowDebug(sql_handle);
@@ -5023,7 +5499,9 @@ int do_init(int argc, char **argv) {
}
Sql_HerculesUpdateCheck(sql_handle);
-
+#ifdef CONSOLE_INPUT
+ console->input->setSQL(sql_handle);
+#endif
ShowStatus("The char-server is "CL_GREEN"ready"CL_RESET" (Server is listening on the port %d).\n\n", char_port);
if( runflag != CORE_ST_STOP )
@@ -5032,5 +5510,7 @@ int do_init(int argc, char **argv) {
runflag = CHARSERVER_ST_RUNNING;
}
+ HPM->event(HPET_READY);
+
return 0;
}
diff --git a/src/char/char.h b/src/char/char.h
index 1a9441868..5a70d2ca7 100644
--- a/src/char/char.h
+++ b/src/char/char.h
@@ -1,10 +1,10 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
+// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// See the LICENSE file
+// Portions Copyright (c) Athena Dev Teams
-#ifndef _CHAR_SQL_H_
-#define _CHAR_SQL_H_
+#ifndef COMMON_CHAR_H
+#define COMMON_CHAR_H
-#include "../config/core.h"
#include "../common/core.h" // CORE_ST_LAST
#include "../common/db.h"
@@ -20,6 +20,7 @@ struct char_session_data {
bool auth; // whether the session is authed or not
int account_id, login_id1, login_id2, sex;
int found_char[MAX_CHARS]; // ids of chars on this account
+ time_t unban_time[MAX_CHARS]; // char unban time array
char email[40]; // e-mail (default: a@a.com) by [Yor]
time_t expiration_time; // # of seconds 1/1/1970 (timestamp): Validity limit of the account (0 = unlimited)
int group_id; // permission
@@ -47,7 +48,7 @@ DBMap* online_char_db; // int account_id -> struct online_char_data*
#define MAX_MAP_SERVERS 2
-#define DEFAULT_AUTOSAVE_INTERVAL 300*1000
+#define DEFAULT_AUTOSAVE_INTERVAL (300*1000)
enum {
TABLE_INVENTORY,
@@ -61,13 +62,15 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit
int mapif_sendall(unsigned char *buf,unsigned int len);
int mapif_sendallwos(int fd,unsigned char *buf,unsigned int len);
int mapif_send(int fd,unsigned char *buf,unsigned int len);
+void mapif_on_parse_accinfo(int account_id,int u_fd, int aid, int castergroup, int map_fd);
+
+void disconnect_player(int account_id);
int char_married(int pl1,int pl2);
int char_child(int parent_id, int child_id);
int char_family(int pl1,int pl2,int pl3);
int request_accreg2(int account_id, int char_id);
-int save_accreg2(unsigned char* buf, int len);
int login_fd;
extern int char_name_option;
extern char char_name_letters[];
@@ -82,7 +85,6 @@ extern char inventory_db[256];
extern char charlog_db[256];
extern char storage_db[256];
extern char interlog_db[256];
-extern char reg_db[256];
extern char skill_db[256];
extern char memo_db[256];
extern char guild_db[256];
@@ -103,11 +105,22 @@ extern char skill_homunculus_db[256];
extern char mercenary_db[256];
extern char mercenary_owner_db[256];
extern char ragsrvinfo_db[256];
+extern char elemental_db[256];
extern char interreg_db[32];
+extern char acc_reg_num_db[32];
+extern char acc_reg_str_db[32];
+extern char char_reg_str_db[32];
+extern char char_reg_num_db[32];
-extern int db_use_sqldbs; // added for sql item_db read for char server [Valaris]
+extern int db_use_sql_item_db;
+extern int db_use_sql_mob_db;
+extern int db_use_sql_mob_skill_db;
extern int guild_exp_rate;
extern int log_inter;
-#endif /* _CHAR_SQL_H_ */
+void global_accreg_to_login_start (int account_id, int char_id);
+void global_accreg_to_login_send (void);
+void global_accreg_to_login_add (const char *key, unsigned int index, intptr_t val, bool is_string);
+
+#endif /* COMMON_CHAR_H */
diff --git a/src/char/int_auction.c b/src/char/int_auction.c
index bf5ea1700..ddfef68c2 100644
--- a/src/char/int_auction.c
+++ b/src/char/int_auction.c
@@ -2,27 +2,30 @@
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams
-#include "../common/mmo.h"
-#include "../common/malloc.h"
+#define HERCULES_CORE
+
+#include "int_auction.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "char.h"
+#include "int_mail.h"
+#include "inter.h"
#include "../common/db.h"
+#include "../common/malloc.h"
+#include "../common/mmo.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
-#include "../common/strlib.h"
#include "../common/sql.h"
+#include "../common/strlib.h"
#include "../common/timer.h"
-#include "char.h"
-#include "inter.h"
-#include "int_mail.h"
-#include "int_auction.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
static DBMap* auction_db_ = NULL; // int auction_id -> struct auction_data*
void auction_delete(struct auction_data *auction);
-static int auction_end_timer(int tid, unsigned int tick, int id, intptr_t data);
+static int auction_end_timer(int tid, int64 tick, int id, intptr_t data);
static int auction_count(int char_id, bool buy)
{
@@ -90,10 +93,6 @@ unsigned int auction_create(struct auction_data *auction)
for( j = 0; j < MAX_SLOTS; j++ )
StrBuf->Printf(&buf, ",'%d'", auction->item.card[j]);
StrBuf->AppendStr(&buf, ")");
-
- //Unique Non Stackable Item ID
- updateLastUid(auction->item.unique_id);
- dbUpdateUid(sql_handle);
stmt = SQL->StmtMalloc(sql_handle);
if( SQL_SUCCESS != SQL->StmtPrepareStr(stmt, StrBuf->Value(&buf))
@@ -108,15 +107,15 @@ unsigned int auction_create(struct auction_data *auction)
else
{
struct auction_data *auction_;
- unsigned int tick = auction->hours * 3600000;
+ int64 tick = auction->hours * 3600000;
auction->item.amount = 1;
auction->item.identify = 1;
auction->item.expire_time = 0;
auction->auction_id = (unsigned int)SQL->StmtLastInsertId(stmt);
- auction->auction_end_timer = iTimer->add_timer( iTimer->gettick() + tick , auction_end_timer, auction->auction_id, 0);
- ShowInfo("New Auction %u | time left %u ms | By %s.\n", auction->auction_id, tick, auction->seller_name);
+ auction->auction_end_timer = timer->add( timer->gettick() + tick , auction_end_timer, auction->auction_id, 0);
+ ShowInfo("New Auction %u | time left %"PRId64" ms | By %s.\n", auction->auction_id, tick, auction->seller_name);
CREATE(auction_, struct auction_data, 1);
memcpy(auction_, auction, sizeof(struct auction_data));
@@ -139,8 +138,7 @@ static void mapif_Auction_message(int char_id, unsigned char result)
mapif_sendall(buf,7);
}
-static int auction_end_timer(int tid, unsigned int tick, int id, intptr_t data)
-{
+static int auction_end_timer(int tid, int64 tick, int id, intptr_t data) {
struct auction_data *auction;
if( (auction = (struct auction_data *)idb_get(auction_db_, id)) != NULL )
{
@@ -170,7 +168,7 @@ void auction_delete(struct auction_data *auction)
Sql_ShowDebug(sql_handle);
if( auction->auction_end_timer != INVALID_TIMER )
- iTimer->delete_timer(auction->auction_end_timer, auction_end_timer);
+ timer->delete(auction->auction_end_timer, auction_end_timer);
idb_remove(auction_db_, auction_id);
}
@@ -182,7 +180,7 @@ void inter_auctions_fromsql(void)
struct item *item;
char *data;
StringBuf buf;
- unsigned int tick = iTimer->gettick(), endtick;
+ int64 tick = timer->gettick(), endtick;
time_t now = time(NULL);
StrBuf->Init(&buf);
@@ -230,11 +228,11 @@ void inter_auctions_fromsql(void)
}
if( auction->timestamp > now )
- endtick = ((unsigned int)(auction->timestamp - now) * 1000) + tick;
+ endtick = ((int64)(auction->timestamp - now) * 1000) + tick;
else
- endtick = tick + 10000; // 10 Second's to process ended auctions
+ endtick = tick + 10000; // 10 seconds to process ended auctions
- auction->auction_end_timer = iTimer->add_timer(endtick, auction_end_timer, auction->auction_id, 0);
+ auction->auction_end_timer = timer->add(endtick, auction_end_timer, auction->auction_id, 0);
idb_put(auction_db_, auction->auction_id, auction);
}
@@ -270,7 +268,7 @@ static void mapif_parse_Auction_requestlist(int fd)
for( auction = dbi_first(iter); dbi_exists(iter); auction = dbi_next(iter) )
{
- if( (type == 0 && auction->type != IT_ARMOR && auction->type != IT_PETARMOR) ||
+ if( (type == 0 && auction->type != IT_ARMOR && auction->type != IT_PETARMOR) ||
(type == 1 && auction->type != IT_WEAPON) ||
(type == 2 && auction->type != IT_CARD) ||
(type == 3 && auction->type != IT_ETC) ||
diff --git a/src/char/int_auction.h b/src/char/int_auction.h
index bf26b152c..17fd75a58 100644
--- a/src/char/int_auction.h
+++ b/src/char/int_auction.h
@@ -1,12 +1,12 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-#ifndef _INT_AUCTION_SQL_H_
-#define _INT_AUCTION_SQL_H_
+#ifndef CHAR_INT_AUCTION_H
+#define CHAR_INT_AUCTION_H
int inter_auction_parse_frommap(int fd);
int inter_auction_sql_init(void);
void inter_auction_sql_final(void);
-#endif /* _INT_AUCTION_SQL_H_ */
+#endif /* CHAR_INT_AUCTION_H */
diff --git a/src/char/int_elemental.c b/src/char/int_elemental.c
index 53a63a212..3a36e75a2 100644
--- a/src/char/int_elemental.c
+++ b/src/char/int_elemental.c
@@ -2,28 +2,32 @@
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams
-#include "../common/mmo.h"
-#include "../common/malloc.h"
-#include "../common/strlib.h"
-#include "../common/showmsg.h"
-#include "../common/socket.h"
-#include "../common/utils.h"
-#include "../common/sql.h"
-#include "char.h"
-#include "inter.h"
+#define HERCULES_CORE
+
+#include "int_elemental.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "char.h"
+#include "inter.h"
+#include "../common/malloc.h"
+#include "../common/mmo.h"
+#include "../common/showmsg.h"
+#include "../common/socket.h"
+#include "../common/sql.h"
+#include "../common/strlib.h"
+#include "../common/utils.h"
+
bool mapif_elemental_save(struct s_elemental* ele) {
bool flag = true;
if( ele->elemental_id == 0 ) { // Create new DB entry
if( SQL_ERROR == SQL->Query(sql_handle,
- "INSERT INTO `elemental` (`char_id`,`class`,`mode`,`hp`,`sp`,`max_hp`,`max_sp`,`atk1`,`atk2`,`matk`,`aspd`,`def`,`mdef`,`flee`,`hit`,`life_time`)"
- "VALUES ('%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%u')",
- ele->char_id, ele->class_, ele->mode, ele->hp, ele->sp, ele->max_hp, ele->max_sp, ele->atk, ele->atk2, ele->matk, ele->amotion, ele->def, ele->mdef, ele->flee, ele->hit, ele->life_time) )
+ "INSERT INTO `%s` (`char_id`,`class`,`mode`,`hp`,`sp`,`max_hp`,`max_sp`,`atk1`,`atk2`,`matk`,`aspd`,`def`,`mdef`,`flee`,`hit`,`life_time`)"
+ "VALUES ('%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%u')",
+ elemental_db, ele->char_id, ele->class_, ele->mode, ele->hp, ele->sp, ele->max_hp, ele->max_sp, ele->atk, ele->atk2, ele->matk, ele->amotion, ele->def, ele->mdef, ele->flee, ele->hit, ele->life_time) )
{
Sql_ShowDebug(sql_handle);
flag = false;
@@ -31,11 +35,11 @@ bool mapif_elemental_save(struct s_elemental* ele) {
else
ele->elemental_id = (int)SQL->LastInsertId(sql_handle);
} else if( SQL_ERROR == SQL->Query(sql_handle,
- "UPDATE `elemental` SET `char_id` = '%d', `class` = '%d', `mode` = '%d', `hp` = '%d', `sp` = '%d',"
- "`max_hp` = '%d', `max_sp` = '%d', `atk1` = '%d', `atk2` = '%d', `matk` = '%d', `aspd` = '%d', `def` = '%d',"
- "`mdef` = '%d', `flee` = '%d', `hit` = '%d', `life_time` = '%u' WHERE `ele_id` = '%d'",
- ele->char_id, ele->class_, ele->mode, ele->hp, ele->sp, ele->max_hp, ele->max_sp, ele->atk, ele->atk2,
- ele->matk, ele->amotion, ele->def, ele->mdef, ele->flee, ele->hit, ele->life_time, ele->elemental_id) )
+ "UPDATE `%s` SET `char_id` = '%d', `class` = '%d', `mode` = '%d', `hp` = '%d', `sp` = '%d',"
+ "`max_hp` = '%d', `max_sp` = '%d', `atk1` = '%d', `atk2` = '%d', `matk` = '%d', `aspd` = '%d', `def` = '%d',"
+ "`mdef` = '%d', `flee` = '%d', `hit` = '%d', `life_time` = '%u' WHERE `ele_id` = '%d'",
+ elemental_db, ele->char_id, ele->class_, ele->mode, ele->hp, ele->sp, ele->max_hp, ele->max_sp, ele->atk, ele->atk2,
+ ele->matk, ele->amotion, ele->def, ele->mdef, ele->flee, ele->hit, ele->life_time, ele->elemental_id) )
{ // Update DB entry
Sql_ShowDebug(sql_handle);
flag = false;
@@ -50,9 +54,11 @@ bool mapif_elemental_load(int ele_id, int char_id, struct s_elemental *ele) {
ele->elemental_id = ele_id;
ele->char_id = char_id;
- if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `class`, `mode`, `hp`, `sp`, `max_hp`, `max_sp`, `atk1`, `atk2`, `matk`, `aspd`,"
- "`def`, `mdef`, `flee`, `hit`, `life_time` FROM `elemental` WHERE `ele_id` = '%d' AND `char_id` = '%d'",
- ele_id, char_id) ) {
+ if( SQL_ERROR == SQL->Query(sql_handle,
+ "SELECT `class`, `mode`, `hp`, `sp`, `max_hp`, `max_sp`, `atk1`, `atk2`, `matk`, `aspd`,"
+ "`def`, `mdef`, `flee`, `hit`, `life_time` FROM `%s` WHERE `ele_id` = '%d' AND `char_id` = '%d'",
+ elemental_db, ele_id, char_id) )
+ {
Sql_ShowDebug(sql_handle);
return false;
}
@@ -85,7 +91,7 @@ bool mapif_elemental_load(int ele_id, int char_id, struct s_elemental *ele) {
}
bool mapif_elemental_delete(int ele_id) {
- if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `elemental` WHERE `ele_id` = '%d'", ele_id) ) {
+ if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `ele_id` = '%d'", elemental_db, ele_id) ) {
Sql_ShowDebug(sql_handle);
return false;
}
diff --git a/src/char/int_elemental.h b/src/char/int_elemental.h
index 7eb5c2958..e28cfedea 100644
--- a/src/char/int_elemental.h
+++ b/src/char/int_elemental.h
@@ -1,10 +1,10 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-#ifndef _INT_ELEMENTAL_SQL_H_
-#define _INT_ELEMENTAL_SQL_H_
+#ifndef CHAR_INT_ELEMENTAL_H
+#define CHAR_INT_ELEMENTAL_H
-struct s_elemental;
+#include "../common/cbasetypes.h"
void inter_elemental_sql_init(void);
void inter_elemental_sql_final(void);
@@ -12,4 +12,4 @@ int inter_elemental_parse_frommap(int fd);
bool mapif_elemental_delete(int ele_id);
-#endif /* _INT_ELEMENTAL_SQL_H_ */
+#endif /* CHAR_INT_ELEMENTAL_H */
diff --git a/src/char/int_guild.c b/src/char/int_guild.c
index a9bce9cbe..a6fcfe48c 100644
--- a/src/char/int_guild.c
+++ b/src/char/int_guild.c
@@ -2,21 +2,25 @@
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams
+#define HERCULES_CORE
+
+#include "../config/core.h" // DBPATH
+#include "int_guild.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "char.h"
+#include "inter.h"
#include "../common/cbasetypes.h"
-#include "../common/mmo.h"
-#include "../common/malloc.h"
-#include "../common/socket.h"
#include "../common/db.h"
+#include "../common/malloc.h"
+#include "../common/mmo.h"
#include "../common/showmsg.h"
+#include "../common/socket.h"
#include "../common/strlib.h"
#include "../common/timer.h"
-#include "char.h"
-#include "inter.h"
-#include "int_guild.h"
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
#define GS_MEMBER_UNMODIFIED 0x00
#define GS_MEMBER_MODIFIED 0x01
@@ -35,7 +39,7 @@ static const char dataToHex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9
static DBMap* guild_db_; // int guild_id -> struct guild*
static DBMap *castle_db;
-static unsigned int guild_exp[100];
+static unsigned int guild_exp[MAX_GUILDLEVEL];
int mapif_parse_GuildLeave(int fd,int guild_id,int account_id,int char_id,int flag,const char *mes);
int mapif_guild_broken(int guild_id,int flag);
@@ -43,11 +47,9 @@ static bool guild_check_empty(struct guild *g);
int guild_calcinfo(struct guild *g);
int mapif_guild_basicinfochanged(int guild_id,int type,const void *data,int len);
int mapif_guild_info(int fd,struct guild *g);
-int guild_break_sub(int key,void *data,va_list ap);
int inter_guild_tosql(struct guild *g,int flag);
-static int guild_save_timer(int tid, unsigned int tick, int id, intptr_t data)
-{
+static int guild_save_timer(int tid, int64 tick, int id, intptr_t data) {
static int last_id = 0; //To know in which guild we were.
int state = 0; //0: Have not reached last guild. 1: Reached last guild, ready for save. 2: Some guild saved, don't do further saving.
DBIterator *iter = db_iterator(guild_db_);
@@ -86,7 +88,7 @@ static int guild_save_timer(int tid, unsigned int tick, int id, intptr_t data)
state = guild_db_->size(guild_db_);
if( state < 1 ) state = 1; //Calculate the time slot for the next save.
- iTimer->add_timer(tick + autosave_interval/state, guild_save_timer, 0, 0);
+ timer->add(tick + autosave_interval/state, guild_save_timer, 0, 0);
return 0;
}
@@ -115,7 +117,7 @@ int inter_guild_tosql(struct guild *g,int flag)
// GS_EXPULSION `guild_expulsion` (`guild_id`,`account_id`,`name`,`mes`)
// GS_SKILL `guild_skill` (`guild_id`,`id`,`lv`)
- // temporary storage for str convertion. They must be twice the size of the
+ // temporary storage for str conversion. They must be twice the size of the
// original string to ensure no overflows will occur. [Skotlex]
char t_info[256];
char esc_name[NAME_LENGTH*2+1];
@@ -448,16 +450,16 @@ struct guild * inter_guild_fromsql(int guild_id)
while( SQL_SUCCESS == SQL->NextRow(sql_handle) )
{
int position;
- struct guild_position* p;
+ struct guild_position *pos;
SQL->GetData(sql_handle, 0, &data, NULL); position = atoi(data);
if( position < 0 || position >= MAX_GUILDPOSITION )
continue;// invalid position
- p = &g->position[position];
- SQL->GetData(sql_handle, 1, &data, &len); memcpy(p->name, data, min(len, NAME_LENGTH));
- SQL->GetData(sql_handle, 2, &data, NULL); p->mode = atoi(data);
- SQL->GetData(sql_handle, 3, &data, NULL); p->exp_mode = atoi(data);
- p->modified = GS_POSITION_UNMODIFIED;
+ pos = &g->position[position];
+ SQL->GetData(sql_handle, 1, &data, &len); memcpy(pos->name, data, min(len, NAME_LENGTH));
+ SQL->GetData(sql_handle, 2, &data, NULL); pos->mode = atoi(data);
+ SQL->GetData(sql_handle, 3, &data, NULL); pos->exp_mode = atoi(data);
+ pos->modified = GS_POSITION_UNMODIFIED;
}
//printf("- Read guild_alliance %d from sql \n",guild_id);
@@ -600,24 +602,22 @@ static struct guild_castle* inter_guildcastle_fromsql(int castle_id)
// Read exp_guild.txt
-static bool exp_guild_parse_row(char* split[], int column, int current)
-{
- unsigned int exp = (unsigned int)atol(split[0]);
+static bool exp_guild_parse_row(char* split[], int column, int current) {
+ int64 exp = strtoll(split[0], NULL, 10);
- if (exp >= UINT_MAX) {
- ShowError("exp_guild: Invalid exp %d at line %d\n", exp, current);
+ if (exp < 0 || exp >= UINT_MAX) {
+ ShowError("exp_guild: Invalid exp %"PRId64" (valid range: 0 - %u) at line %d\n", exp, UINT_MAX, current);
return false;
}
- guild_exp[current] = exp;
+ guild_exp[current] = (unsigned int)exp;
return true;
}
-int inter_guild_CharOnline(int char_id, int guild_id)
-{
- struct guild *g;
- int i;
+int inter_guild_CharOnline(int char_id, int guild_id) {
+ struct guild *g;
+ int i;
if (guild_id == -1) {
//Get guild_id from the database
@@ -727,10 +727,10 @@ int inter_guild_sql_init(void)
castle_db = idb_alloc(DB_OPT_RELEASE_DATA);
//Read exp file
- sv->readdb("db", DBPATH"exp_guild.txt", ',', 1, 1, 100, exp_guild_parse_row);
+ sv->readdb("db", DBPATH"exp_guild.txt", ',', 1, 1, MAX_GUILDLEVEL, exp_guild_parse_row);
- iTimer->add_timer_func_list(guild_save_timer, "guild_save_timer");
- iTimer->add_timer(iTimer->gettick() + 10000, guild_save_timer, 0, 0);
+ timer->add_func_list(guild_save_timer, "guild_save_timer");
+ timer->add(timer->gettick() + 10000, guild_save_timer, 0, 0);
return 0;
}
@@ -796,14 +796,13 @@ static bool guild_check_empty(struct guild *g)
return true;
}
-unsigned int guild_nextexp(int level)
-{
+unsigned int guild_nextexp(int level) {
if (level == 0)
return 1;
- if (level < 100 && level > 0) // Change by hack
- return guild_exp[level-1];
+ if (level <= 0 || level >= MAX_GUILDLEVEL)
+ return 0;
- return 0;
+ return guild_exp[level-1];
}
int guild_checkskill(struct guild *g,int id)
@@ -827,7 +826,7 @@ int guild_calcinfo(struct guild *g)
nextexp = guild_nextexp(g->guild_lv);
// Consume guild exp and increase guild level
- while(g->exp >= nextexp && nextexp > 0){ //fixed guild exp overflow [Kevin]
+ while(g->exp >= nextexp && nextexp > 0) { // nextexp would be 0 if g->guild_lv was >= MAX_GUILDLEVEL
g->exp-=nextexp;
g->guild_lv++;
g->skill_point++;
@@ -837,7 +836,7 @@ int guild_calcinfo(struct guild *g)
// Save next exp step
g->next_exp = nextexp;
- // Set the max number of members, Guild Extention skill - currently adds 6 to max per skill lv.
+ // Set the max number of members, Guild Extension skill - currently adds 6 to max per skill lv.
g->max_member = 16 + guild_checkskill(g, GD_EXTENSION) * 6;
if(g->max_member > MAX_GUILD)
{
@@ -1143,8 +1142,8 @@ int mapif_parse_CreateGuild(int fd,int account_id,char *name,struct guild_member
mapif_guild_created(fd,account_id,NULL);
return 0;
}
- // Check Authorised letters/symbols in the name of the character
- if (char_name_option == 1) { // only letters/symbols in char_name_letters are authorised
+ // Check Authorized letters/symbols in the name of the character
+ 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_guild_created(fd,account_id,NULL);
@@ -1180,6 +1179,7 @@ int mapif_parse_CreateGuild(int fd,int account_id,char *name,struct guild_member
g->max_member=16;
g->average_lv=master->lv;
g->connect_member=1;
+ g->guild_lv=1;
for(i=0;i<MAX_GUILDSKILL;i++)
g->skill[i].id=i + GD_SKILLBASE;
@@ -1212,7 +1212,7 @@ int mapif_parse_CreateGuild(int fd,int account_id,char *name,struct guild_member
// Return guild info to client
int mapif_parse_GuildInfo(int fd,int guild_id)
{
- struct guild * g = inter_guild_fromsql(guild_id); //We use this because on start-up the info of castle-owned guilds is requied. [Skotlex]
+ struct guild * g = inter_guild_fromsql(guild_id); //We use this because on start-up the info of castle-owned guilds is required. [Skotlex]
if(g)
{
if (!guild_calcinfo(g))
@@ -1425,33 +1425,61 @@ int mapif_parse_GuildMessage(int fd,int guild_id,int account_id,char *mes,int le
return mapif_guild_message(guild_id,account_id,mes,len, fd);
}
-// Modification of the guild
-int mapif_parse_GuildBasicInfoChange(int fd,int guild_id,int type,const char *data,int len)
-{
- struct guild * g;
- short dw=*((short *)data);
+/**
+ * Changes basic guild information
+ * The types are available in mmo.h::guild_basic_info
+ **/
+int mapif_parse_GuildBasicInfoChange(int fd, int guild_id, int type, const void *data, int len) {
+ struct guild *g;
+ struct guild_skill gd_skill;
+ short value;
g = inter_guild_fromsql(guild_id);
- if(g==NULL)
+
+ if( g == NULL )
return 0;
- switch(type)
- {
+ switch(type) {
+ case GBI_EXP:
+ value = *((const int16 *)data);
+ if( value < 0 && abs(value) > g->exp )
+ return 0;
+ g->exp += value;
+ guild_calcinfo(g);
+ break;
+
case GBI_GUILDLV:
- if(dw>0 && g->guild_lv+dw<=50)
- {
- g->guild_lv+=dw;
- g->skill_point+=dw;
- }
- else if(dw<0 && g->guild_lv+dw>=1)
- g->guild_lv+=dw;
- mapif_guild_info(-1,g);
- g->save_flag |= GS_LEVEL;
- return 0;
- default:
- ShowError("int_guild: GuildBasicInfoChange: Unknown type %d\n",type);
+ value = *((const int16 *)data);
+ if (value > 0 && g->guild_lv + value <= MAX_GUILDLEVEL) {
+ g->guild_lv += value;
+ g->skill_point += value;
+ } else if (value < 0 && g->guild_lv + value >= 1)
+ g->guild_lv += value;
break;
+
+ case GBI_SKILLPOINT:
+ value = *((const int16 *)data);
+ if( g->skill_point+value < 0 )
+ return 0;
+ g->skill_point += value;
+ break;
+
+ case GBI_SKILLLV:
+ gd_skill = *((const struct guild_skill*)data);
+ memcpy(&(g->skill[(gd_skill.id - GD_SKILLBASE)]), &gd_skill, sizeof(gd_skill));
+ if( !guild_calcinfo(g) )
+ mapif_guild_info(-1,g);
+ g->save_flag |= GS_SKILL;
+ mapif_guild_skillupack(g->guild_id, gd_skill.id, 0);
+ break;
+
+ default:
+ ShowError("int_guild: GuildBasicInfoChange: Unknown type %d, see mmo.h::guild_basic_info for more information\n",type);
+ return 0;
}
- mapif_guild_basicinfochanged(guild_id,type,data,len);
+ mapif_guild_info(-1,g);
+ g->save_flag |= GS_LEVEL;
+ // Information is already sent in mapif_guild_info
+ //mapif_guild_basicinfochanged(guild_id,type,data,len);
return 0;
}
@@ -1665,7 +1693,7 @@ static int mapif_parse_GuildDeleteAlliance(struct guild *g, int guild_id, int ac
int mapif_parse_GuildAlliance(int fd,int guild_id1,int guild_id2,int account_id1,int account_id2,int flag)
{
// Could speed up
- struct guild *g[2];
+ struct guild *g[2] = { NULL };
int j,i;
g[0] = inter_guild_fromsql(guild_id1);
g[1] = inter_guild_fromsql(guild_id2);
@@ -1676,25 +1704,19 @@ int mapif_parse_GuildAlliance(int fd,int guild_id1,int guild_id2,int account_id1
if(g[0]==NULL || g[1]==NULL)
return 0;
- if(flag&GUILD_ALLIANCE_REMOVE)
- {
+ if( flag&GUILD_ALLIANCE_REMOVE ) {
// Remove alliance/opposition, in case of alliance, remove on both side
- for(i=0;i<2-(flag&GUILD_ALLIANCE_TYPE_MASK);i++)
- {
+ for( i = 0; i < ((flag&GUILD_ALLIANCE_TYPE_MASK) ? 1 : 2); i++ ) {
ARR_FIND( 0, MAX_GUILDALLIANCE, j, g[i]->alliance[j].guild_id == g[1-i]->guild_id && g[i]->alliance[j].opposition == (flag&GUILD_ALLIANCE_TYPE_MASK) );
if( j < MAX_GUILDALLIANCE )
g[i]->alliance[j].guild_id = 0;
}
- }
- else
- {
+ } else {
// Add alliance, in case of alliance, add on both side
- for(i=0;i<2-(flag&GUILD_ALLIANCE_TYPE_MASK);i++)
- {
+ for( i = 0; i < ((flag&GUILD_ALLIANCE_TYPE_MASK) ? 1 : 2); i++ ) {
// Search an empty slot
ARR_FIND( 0, MAX_GUILDALLIANCE, j, g[i]->alliance[j].guild_id == 0 );
- if( j < MAX_GUILDALLIANCE )
- {
+ if( j < MAX_GUILDALLIANCE ) {
g[i]->alliance[j].guild_id=g[1-i]->guild_id;
memcpy(g[i]->alliance[j].name,g[1-i]->name,NAME_LENGTH);
// Set alliance type
@@ -1845,7 +1867,7 @@ int inter_guild_parse_frommap(int fd)
case 0x3035: mapif_parse_GuildChangeMemberInfoShort(fd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14),RFIFOW(fd,15),RFIFOW(fd,17)); break;
case 0x3036: mapif_parse_BreakGuild(fd,RFIFOL(fd,2)); break;
case 0x3037: mapif_parse_GuildMessage(fd,RFIFOL(fd,4),RFIFOL(fd,8),(char*)RFIFOP(fd,12),RFIFOW(fd,2)-12); break;
- case 0x3039: mapif_parse_GuildBasicInfoChange(fd,RFIFOL(fd,4),RFIFOW(fd,8),(const char*)RFIFOP(fd,10),RFIFOW(fd,2)-10); break;
+ case 0x3039: mapif_parse_GuildBasicInfoChange(fd,RFIFOL(fd,4),RFIFOW(fd,8),(const int16 *)RFIFOP(fd,10),RFIFOW(fd,2)-10); break;
case 0x303A: mapif_parse_GuildMemberInfoChange(fd,RFIFOL(fd,4),RFIFOL(fd,8),RFIFOL(fd,12),RFIFOW(fd,16),(const char*)RFIFOP(fd,18),RFIFOW(fd,2)-18); break;
case 0x303B: mapif_parse_GuildPosition(fd,RFIFOL(fd,4),RFIFOL(fd,8),(struct guild_position *)RFIFOP(fd,12)); break;
case 0x303C: mapif_parse_GuildSkillUp(fd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOL(fd,14)); break;
diff --git a/src/char/int_guild.h b/src/char/int_guild.h
index 47c42dcc5..bc457d86b 100644
--- a/src/char/int_guild.h
+++ b/src/char/int_guild.h
@@ -1,8 +1,8 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-#ifndef _INT_GUILD_SQL_H_
-#define _INT_GUILD_SQL_H_
+#ifndef CHAR_INT_GUILD_H
+#define CHAR_INT_GUILD_H
enum {
GS_BASIC = 0x0001,
@@ -20,9 +20,6 @@ enum {
GS_REMOVE = 0x8000,
};
-struct guild;
-struct guild_castle;
-
int inter_guild_parse_frommap(int fd);
int inter_guild_sql_init(void);
void inter_guild_sql_final(void);
@@ -34,4 +31,4 @@ int inter_guild_charname_changed(int guild_id,int account_id, int char_id, char
int inter_guild_CharOnline(int char_id, int guild_id);
int inter_guild_CharOffline(int char_id, int guild_id);
-#endif /* _INT_GUILD_SQL_H_ */
+#endif /* CHAR_INT_GUILD_H */
diff --git a/src/char/int_homun.c b/src/char/int_homun.c
index 143277f05..acde9eb38 100644
--- a/src/char/int_homun.c
+++ b/src/char/int_homun.c
@@ -2,20 +2,23 @@
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams
-#include "../common/mmo.h"
-#include "../common/malloc.h"
-#include "../common/strlib.h"
-#include "../common/showmsg.h"
-#include "../common/socket.h"
-#include "../common/utils.h"
-#include "../common/sql.h"
-#include "char.h"
-#include "inter.h"
+#define HERCULES_CORE
+
+#include "int_homun.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "char.h"
+#include "inter.h"
+#include "../common/malloc.h"
+#include "../common/mmo.h"
+#include "../common/showmsg.h"
+#include "../common/socket.h"
+#include "../common/sql.h"
+#include "../common/strlib.h"
+#include "../common/utils.h"
int inter_homunculus_sql_init(void)
{
@@ -245,9 +248,9 @@ bool mapif_homunculus_rename(char *name)
{
int i;
- // Check Authorised letters/symbols in the name of the homun
+ // Check Authorized letters/symbols in the name of the homun
if( char_name_option == 1 )
- {// only letters/symbols in char_name_letters are authorised
+ {// 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 )
return false;
diff --git a/src/char/int_homun.h b/src/char/int_homun.h
index 1c0d76269..6fa4f9dc7 100644
--- a/src/char/int_homun.h
+++ b/src/char/int_homun.h
@@ -1,8 +1,10 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-#ifndef _INT_HOMUN_SQL_H_
-#define _INT_HOMUN_SQL_H_
+#ifndef CHAR_INT_HOMUN_H
+#define CHAR_INT_HOMUN_H
+
+#include "../common/cbasetypes.h"
struct s_homunculus;
@@ -15,4 +17,4 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd);
bool mapif_homunculus_delete(int homun_id);
bool mapif_homunculus_rename(char *name);
-#endif /* _INT_HOMUN_SQL_H_ */
+#endif /* CHAR_INT_HOMUN_H */
diff --git a/src/char/int_mail.c b/src/char/int_mail.c
index e4b88b5bf..86a36d59f 100644
--- a/src/char/int_mail.c
+++ b/src/char/int_mail.c
@@ -2,19 +2,23 @@
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams
-#include "../common/mmo.h"
+#define HERCULES_CORE
+
+#include "int_mail.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "char.h"
+#include "inter.h"
#include "../common/malloc.h"
+#include "../common/mmo.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
-#include "../common/strlib.h"
#include "../common/sql.h"
+#include "../common/strlib.h"
#include "../common/timer.h"
-#include "char.h"
-#include "inter.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
static int mail_fromsql(int char_id, struct mail_data* md)
{
@@ -64,6 +68,7 @@ static int mail_fromsql(int char_id, struct mail_data* md)
SQL->GetData(sql_handle,14, &data, NULL); item->identify = atoi(data);
SQL->GetData(sql_handle,15, &data, NULL); item->unique_id = strtoull(data, NULL, 10);
item->expire_time = 0;
+ item->bound = 0;
for (j = 0; j < MAX_SLOTS; j++)
{
@@ -116,10 +121,6 @@ int mail_savemessage(struct mail_message* msg)
for (j = 0; j < MAX_SLOTS; j++)
StrBuf->Printf(&buf, ", '%d'", msg->item.card[j]);
StrBuf->AppendStr(&buf, ")");
-
- //Unique Non Stackable Item ID
- updateLastUid(msg->item.unique_id);
- dbUpdateUid(sql_handle);
// prepare and execute query
stmt = SQL->StmtMalloc(sql_handle);
@@ -184,6 +185,7 @@ static bool mail_loadmessage(int mail_id, struct mail_message* msg)
SQL->GetData(sql_handle,14, &data, NULL); msg->item.identify = atoi(data);
SQL->GetData(sql_handle,15, &data, NULL); msg->item.unique_id = strtoull(data, NULL, 10);
msg->item.expire_time = 0;
+ msg->item.bound = 0;
for( j = 0; j < MAX_SLOTS; j++ )
{
diff --git a/src/char/int_mail.h b/src/char/int_mail.h
index 77db51e5b..8800061d7 100644
--- a/src/char/int_mail.h
+++ b/src/char/int_mail.h
@@ -1,8 +1,11 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-#ifndef _INT_MAIL_SQL_H_
-#define _INT_MAIL_SQL_H_
+#ifndef CHAR_INT_MAIL_H
+#define CHAR_INT_MAIL_H
+
+struct item;
+struct mail_message;
int inter_mail_parse_frommap(int fd);
void mail_sendmail(int send_id, const char* send_name, int dest_id, const char* dest_name, const char* title, const char* body, int zeny, struct item *item);
@@ -13,4 +16,4 @@ void inter_mail_sql_final(void);
int mail_savemessage(struct mail_message* msg);
void mapif_Mail_new(struct mail_message *msg);
-#endif /* _INT_MAIL_SQL_H_ */
+#endif /* CHAR_INT_MAIL_H */
diff --git a/src/char/int_mercenary.c b/src/char/int_mercenary.c
index aecb3844a..1dffb656c 100644
--- a/src/char/int_mercenary.c
+++ b/src/char/int_mercenary.c
@@ -2,20 +2,24 @@
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams
-#include "../common/mmo.h"
-#include "../common/malloc.h"
-#include "../common/strlib.h"
-#include "../common/showmsg.h"
-#include "../common/socket.h"
-#include "../common/utils.h"
-#include "../common/sql.h"
-#include "char.h"
-#include "inter.h"
+#define HERCULES_CORE
+
+#include "int_mercenary.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "char.h"
+#include "inter.h"
+#include "../common/malloc.h"
+#include "../common/mmo.h"
+#include "../common/showmsg.h"
+#include "../common/socket.h"
+#include "../common/sql.h"
+#include "../common/strlib.h"
+#include "../common/utils.h"
+
bool mercenary_owner_fromsql(int char_id, struct mmo_charstatus *status)
{
char* data;
diff --git a/src/char/int_mercenary.h b/src/char/int_mercenary.h
index 01e4a841f..b03c20de3 100644
--- a/src/char/int_mercenary.h
+++ b/src/char/int_mercenary.h
@@ -1,10 +1,12 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-#ifndef _INT_MERCENARY_SQL_H_
-#define _INT_MERCENARY_SQL_H_
+#ifndef CHAR_INT_MERCENARY_H
+#define CHAR_INT_MERCENARY_H
-struct s_mercenary;
+#include "../common/cbasetypes.h"
+
+struct mmo_charstatus;
int inter_mercenary_sql_init(void);
void inter_mercenary_sql_final(void);
@@ -17,4 +19,4 @@ bool mercenary_owner_delete(int char_id);
bool mapif_mercenary_delete(int merc_id);
-#endif /* _INT_MERCENARY_SQL_H_ */
+#endif /* CHAR_INT_MERCENARY_H */
diff --git a/src/char/int_party.c b/src/char/int_party.c
index 9cb4ccf80..a8722fbe3 100644
--- a/src/char/int_party.c
+++ b/src/char/int_party.c
@@ -2,23 +2,26 @@
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams
-#include "../common/cbasetypes.h"
-#include "../common/mmo.h"
-#include "../common/db.h"
-#include "../common/malloc.h"
-#include "../common/strlib.h"
-#include "../common/socket.h"
-#include "../common/showmsg.h"
-#include "../common/mapindex.h"
-#include "../common/sql.h"
-#include "char.h"
-#include "inter.h"
+#define HERCULES_CORE
+
#include "int_party.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "char.h"
+#include "inter.h"
+#include "../common/cbasetypes.h"
+#include "../common/db.h"
+#include "../common/malloc.h"
+#include "../common/mapindex.h"
+#include "../common/mmo.h"
+#include "../common/showmsg.h"
+#include "../common/socket.h"
+#include "../common/sql.h"
+#include "../common/strlib.h"
+
struct party_data {
struct party party;
unsigned int min_lv, max_lv;
@@ -241,7 +244,7 @@ struct party_data *inter_party_fromsql(int party_id)
SQL->GetData(sql_handle, 1, &data, NULL); m->char_id = atoi(data);
SQL->GetData(sql_handle, 2, &data, &len); memcpy(m->name, data, min(len, NAME_LENGTH));
SQL->GetData(sql_handle, 3, &data, NULL); m->lv = atoi(data);
- SQL->GetData(sql_handle, 4, &data, NULL); m->map = mapindex_name2id(data);
+ SQL->GetData(sql_handle, 4, &data, NULL); m->map = mapindex->name2id(data);
SQL->GetData(sql_handle, 5, &data, NULL); m->online = (atoi(data) ? 1 : 0);
SQL->GetData(sql_handle, 6, &data, NULL); m->class_ = atoi(data);
m->leader = (m->account_id == leader_id && m->char_id == leader_char ? 1 : 0);
@@ -472,8 +475,8 @@ int mapif_parse_CreateParty(int fd, char *name, int item, int item2, struct part
mapif_party_created(fd,leader->account_id,leader->char_id,NULL);
return 0;
}
- // Check Authorised letters/symbols in the name of the character
- if (char_name_option == 1) { // only letters/symbols in char_name_letters are authorised
+ // Check Authorized letters/symbols in the name of the character
+ 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) {
if( name[i] == '"' ) { /* client-special-char */
@@ -649,7 +652,7 @@ int mapif_parse_PartyChangeMap(int fd, int party_id, int account_id, int char_id
if (p == NULL)
return 0;
- for(i = 0; i < MAX_PARTY &&
+ for(i = 0; i < MAX_PARTY &&
(p->party.member[i].account_id != account_id ||
p->party.member[i].char_id != char_id); i++);
@@ -663,7 +666,7 @@ int mapif_parse_PartyChangeMap(int fd, int party_id, int account_id, int char_id
else
p->party.count--;
// Even share check situations: Family state (always breaks)
- // character logging on/off is max/min level (update level range)
+ // character logging on/off is max/min level (update level range)
// or character logging on/off has a different level (update level range using new level)
if (p->family ||
(p->party.member[i].lv <= p->min_lv || p->party.member[i].lv >= p->max_lv) ||
@@ -728,7 +731,7 @@ int mapif_parse_PartyLeaderChange(int fd,int party_id,int account_id,int char_id
for (i = 0; i < MAX_PARTY; i++)
{
- if(p->party.member[i].leader)
+ if(p->party.member[i].leader)
p->party.member[i].leader = 0;
if(p->party.member[i].account_id == account_id &&
p->party.member[i].char_id == char_id)
diff --git a/src/char/int_party.h b/src/char/int_party.h
index d8cdcdc6a..2b24b1d1a 100644
--- a/src/char/int_party.h
+++ b/src/char/int_party.h
@@ -1,12 +1,12 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-#ifndef _INT_PARTY_SQL_H_
-#define _INT_PARTY_SQL_H_
+#ifndef CHAR_INT_PARTY_H
+#define CHAR_INT_PARTY_H
//Party Flags on what to save/delete.
enum {
- PS_CREATE = 0x01, //Create a new party entry (index holds leader's info)
+ PS_CREATE = 0x01, //Create a new party entry (index holds leader's info)
PS_BASIC = 0x02, //Update basic party info.
PS_LEADER = 0x04, //Update party's leader
PS_ADDMEMBER = 0x08, //Specify new party member (index specifies which party member)
@@ -14,8 +14,6 @@ enum {
PS_BREAK = 0x20, //Specify that this party must be deleted.
};
-struct party;
-
int inter_party_parse_frommap(int fd);
int inter_party_sql_init(void);
void inter_party_sql_final(void);
@@ -23,4 +21,4 @@ int inter_party_leave(int party_id,int account_id, int char_id);
int inter_party_CharOnline(int char_id, int party_id);
int inter_party_CharOffline(int char_id, int party_id);
-#endif /* _INT_PARTY_SQL_H_ */
+#endif /* CHAR_INT_PARTY_H */
diff --git a/src/char/int_pet.c b/src/char/int_pet.c
index 2867aed77..bf7961462 100644
--- a/src/char/int_pet.c
+++ b/src/char/int_pet.c
@@ -2,26 +2,30 @@
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams
-#include "../common/mmo.h"
-#include "../common/malloc.h"
-#include "../common/socket.h"
-#include "../common/strlib.h"
-#include "../common/showmsg.h"
-#include "../common/utils.h"
-#include "../common/sql.h"
-#include "char.h"
-#include "inter.h"
+#define HERCULES_CORE
+
+#include "int_pet.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "char.h"
+#include "inter.h"
+#include "../common/malloc.h"
+#include "../common/mmo.h"
+#include "../common/showmsg.h"
+#include "../common/socket.h"
+#include "../common/sql.h"
+#include "../common/strlib.h"
+#include "../common/utils.h"
+
struct s_pet *pet_pt;
//---------------------------------------------------------
int inter_pet_tosql(int pet_id, struct s_pet* p)
{
- //`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate`)
+ //`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`)
char esc_name[NAME_LENGTH*2+1];// escaped pet name
SQL->EscapeStringLen(sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH));
@@ -31,10 +35,10 @@ int inter_pet_tosql(int pet_id, struct s_pet* p)
if( pet_id == -1 )
{// New pet.
if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` "
- "(`class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate`) "
+ "(`class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`) "
"VALUES ('%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
pet_db, p->class_, esc_name, p->account_id, p->char_id, p->level, p->egg_id,
- p->equip, p->intimate, p->hungry, p->rename_flag, p->incuvate) )
+ p->equip, p->intimate, p->hungry, p->rename_flag, p->incubate) )
{
Sql_ShowDebug(sql_handle);
return 0;
@@ -43,9 +47,9 @@ int inter_pet_tosql(int pet_id, struct s_pet* p)
}
else
{// Update pet.
- if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `class`='%d',`name`='%s',`account_id`='%d',`char_id`='%d',`level`='%d',`egg_id`='%d',`equip`='%d',`intimate`='%d',`hungry`='%d',`rename_flag`='%d',`incuvate`='%d' WHERE `pet_id`='%d'",
+ if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `class`='%d',`name`='%s',`account_id`='%d',`char_id`='%d',`level`='%d',`egg_id`='%d',`equip`='%d',`intimate`='%d',`hungry`='%d',`rename_flag`='%d',`incubate`='%d' WHERE `pet_id`='%d'",
pet_db, p->class_, esc_name, p->account_id, p->char_id, p->level, p->egg_id,
- p->equip, p->intimate, p->hungry, p->rename_flag, p->incuvate, p->pet_id) )
+ p->equip, p->intimate, p->hungry, p->rename_flag, p->incubate, p->pet_id) )
{
Sql_ShowDebug(sql_handle);
return 0;
@@ -67,9 +71,9 @@ int inter_pet_fromsql(int pet_id, struct s_pet* p)
#endif
memset(p, 0, sizeof(struct s_pet));
- //`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate`)
+ //`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`)
- if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate` FROM `%s` WHERE `pet_id`='%d'", pet_db, pet_id) )
+ if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate` FROM `%s` WHERE `pet_id`='%d'", pet_db, pet_id) )
{
Sql_ShowDebug(sql_handle);
return 0;
@@ -88,7 +92,7 @@ int inter_pet_fromsql(int pet_id, struct s_pet* p)
SQL->GetData(sql_handle, 8, &data, NULL); p->intimate = atoi(data);
SQL->GetData(sql_handle, 9, &data, NULL); p->hungry = atoi(data);
SQL->GetData(sql_handle, 10, &data, NULL); p->rename_flag = atoi(data);
- SQL->GetData(sql_handle, 11, &data, NULL); p->incuvate = atoi(data);
+ SQL->GetData(sql_handle, 11, &data, NULL); p->incubate = atoi(data);
SQL->FreeResult(sql_handle);
@@ -122,18 +126,18 @@ int inter_pet_delete(int pet_id){
//------------------------------------------------------
int mapif_pet_created(int fd, int account_id, struct s_pet *p)
{
- WFIFOHEAD(fd, 11);
- WFIFOW(fd, 0) =0x3880;
- WFIFOL(fd, 2) =account_id;
+ WFIFOHEAD(fd, 12);
+ WFIFOW(fd, 0) = 0x3880;
+ WFIFOL(fd, 2) = account_id;
if(p!=NULL){
- WFIFOB(fd, 6)=0;
- WFIFOL(fd, 7) =p->pet_id;
+ WFIFOW(fd, 6) = p->class_;
+ WFIFOL(fd, 8) = p->pet_id;
ShowInfo("int_pet: created pet %d - %s\n", p->pet_id, p->name);
}else{
- WFIFOB(fd, 6)=1;
- WFIFOL(fd, 7)=0;
+ WFIFOB(fd, 6) = 0;
+ WFIFOL(fd, 8) = 0;
}
- WFIFOSET(fd, 11);
+ WFIFOSET(fd, 12);
return 0;
}
@@ -182,11 +186,11 @@ int mapif_delete_pet_ack(int fd, int flag){
}
int mapif_create_pet(int fd, int account_id, int char_id, short pet_class, short pet_lv, short pet_egg_id,
- short pet_equip, short intimate, short hungry, char rename_flag, char incuvate, char *pet_name)
+ short pet_equip, short intimate, short hungry, char rename_flag, char incubate, char *pet_name)
{
memset(pet_pt, 0, sizeof(struct s_pet));
safestrncpy(pet_pt->name, pet_name, NAME_LENGTH);
- if(incuvate == 1)
+ if(incubate == 1)
pet_pt->account_id = pet_pt->char_id = 0;
else {
pet_pt->account_id = account_id;
@@ -199,7 +203,7 @@ int mapif_create_pet(int fd, int account_id, int char_id, short pet_class, short
pet_pt->intimate = intimate;
pet_pt->hungry = hungry;
pet_pt->rename_flag = rename_flag;
- pet_pt->incuvate = incuvate;
+ pet_pt->incubate = incubate;
if(pet_pt->hungry < 0)
pet_pt->hungry = 0;
@@ -225,7 +229,7 @@ int mapif_load_pet(int fd, int account_id, int char_id, int pet_id){
inter_pet_fromsql(pet_id, pet_pt);
if(pet_pt!=NULL) {
- if(pet_pt->incuvate == 1) {
+ if(pet_pt->incubate == 1) {
pet_pt->account_id = pet_pt->char_id = 0;
mapif_pet_info(fd, account_id, pet_pt);
}
@@ -245,22 +249,21 @@ int mapif_save_pet(int fd, int account_id, struct s_pet *data) {
int len;
RFIFOHEAD(fd);
len=RFIFOW(fd, 2);
- if(sizeof(struct s_pet)!=len-8) {
- ShowError("inter pet: data size error %d %d\n", sizeof(struct s_pet), len-8);
+ if (sizeof(struct s_pet) != len-8) {
+ ShowError("inter pet: data size mismatch: %d != %"PRIuS"\n", len-8, sizeof(struct s_pet));
+ return 0;
}
- else{
- if(data->hungry < 0)
- data->hungry = 0;
- else if(data->hungry > 100)
- data->hungry = 100;
- if(data->intimate < 0)
- data->intimate = 0;
- else if(data->intimate > 1000)
- data->intimate = 1000;
- inter_pet_tosql(data->pet_id,data);
- mapif_save_pet_ack(fd, account_id, 0);
- }
+ if (data->hungry < 0)
+ data->hungry = 0;
+ else if (data->hungry > 100)
+ data->hungry = 100;
+ if (data->intimate < 0)
+ data->intimate = 0;
+ else if (data->intimate > 1000)
+ data->intimate = 1000;
+ inter_pet_tosql(data->pet_id,data);
+ mapif_save_pet_ack(fd, account_id, 0);
return 0;
}
diff --git a/src/char/int_pet.h b/src/char/int_pet.h
index 733468c77..52642fc54 100644
--- a/src/char/int_pet.h
+++ b/src/char/int_pet.h
@@ -1,8 +1,8 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-#ifndef _INT_PET_SQL_H_
-#define _INT_PET_SQL_H_
+#ifndef CHAR_INT_PET_H
+#define CHAR_INT_PET_H
struct s_pet;
@@ -18,4 +18,4 @@ int inter_pet_sql_init(void);
//Exported for use in the TXT-SQL converter.
int inter_pet_tosql(int pet_id, struct s_pet *p);
-#endif /* _INT_PET_SQL_H_ */
+#endif /* CHAR_INT_PET_H */
diff --git a/src/char/int_quest.c b/src/char/int_quest.c
index af8f83a5d..d4155b0d6 100644
--- a/src/char/int_quest.c
+++ b/src/char/int_quest.c
@@ -2,62 +2,112 @@
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams
-#include "../common/mmo.h"
+#define HERCULES_CORE
+
+#include "int_quest.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "char.h"
+#include "inter.h"
#include "../common/db.h"
#include "../common/malloc.h"
+#include "../common/mmo.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
-#include "../common/strlib.h"
#include "../common/sql.h"
+#include "../common/strlib.h"
#include "../common/timer.h"
-#include "char.h"
-#include "inter.h"
-#include "int_quest.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-//Load entire questlog for a character
-int mapif_quests_fromsql(int char_id, struct quest questlog[])
-{
- int i;
+/**
+ * Loads the entire questlog for a character.
+ *
+ * @param char_id Character ID
+ * @param count Pointer to return the number of found entries.
+ * @return Array of found entries. It has *count entries, and it is care of the
+ * caller to aFree() it afterwards.
+ */
+struct quest *mapif_quests_fromsql(int char_id, int *count) {
+ struct quest *questlog = NULL;
struct quest tmp_quest;
- SqlStmt * stmt;
+ SqlStmt *stmt;
+ StringBuf buf;
+ int i;
+ int sqlerror = SQL_SUCCESS;
+
+ if (!count)
+ return NULL;
stmt = SQL->StmtMalloc(sql_handle);
- if( stmt == NULL )
- {
+ if (stmt == NULL) {
SqlStmt_ShowDebug(stmt);
- return 0;
+ *count = 0;
+ return NULL;
}
+ StrBuf->Init(&buf);
+ StrBuf->AppendStr(&buf, "SELECT `quest_id`, `state`, `time`");
+ for (i = 0; i < MAX_QUEST_OBJECTIVES; i++) {
+ StrBuf->Printf(&buf, ", `count%d`", i+1);
+ }
+ StrBuf->Printf(&buf, " FROM `%s` WHERE `char_id`=?", quest_db);
+
memset(&tmp_quest, 0, sizeof(struct quest));
- if( SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT `quest_id`, `state`, `time`, `count1`, `count2`, `count3` FROM `%s` WHERE `char_id`=? LIMIT %d", quest_db, MAX_QUEST_DB)
- || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0)
- || SQL_ERROR == SQL->StmtExecute(stmt)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &tmp_quest.quest_id, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_INT, &tmp_quest.state, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_UINT, &tmp_quest.time, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_INT, &tmp_quest.count[0], 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 4, SQLDT_INT, &tmp_quest.count[1], 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 5, SQLDT_INT, &tmp_quest.count[2], 0, NULL, NULL) )
+ if (SQL_ERROR == SQL->StmtPrepare(stmt, StrBuf->Value(&buf))
+ || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0)
+ || SQL_ERROR == SQL->StmtExecute(stmt)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &tmp_quest.quest_id, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_INT, &tmp_quest.state, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_UINT, &tmp_quest.time, 0, NULL, NULL)
+ )
+ sqlerror = SQL_ERROR;
+
+ StrBuf->Destroy(&buf);
+
+ for (i = 0; sqlerror != SQL_ERROR && i < MAX_QUEST_OBJECTIVES; i++) { // Stop on the first error
+ sqlerror = SQL->StmtBindColumn(stmt, 3+i, SQLDT_INT, &tmp_quest.count[i], 0, NULL, NULL);
+ }
+
+ if (sqlerror == SQL_ERROR) {
SqlStmt_ShowDebug(stmt);
+ SQL->StmtFree(stmt);
+ *count = 0;
+ return NULL;
+ }
- for( i = 0; i < MAX_QUEST_DB && SQL_SUCCESS == SQL->StmtNextRow(stmt); ++i )
- memcpy(&questlog[i], &tmp_quest, sizeof(tmp_quest));
+ *count = (int)SQL->StmtNumRows(stmt);
+ if (*count > 0) {
+ i = 0;
+ questlog = (struct quest *)aCalloc(*count, sizeof(struct quest));
+
+ while (SQL_SUCCESS == SQL->StmtNextRow(stmt)) {
+ if (i >= *count) // Sanity check, should never happen
+ break;
+ memcpy(&questlog[i++], &tmp_quest, sizeof(tmp_quest));
+ }
+ if (i < *count) {
+ // Should never happen. Compact array
+ *count = i;
+ questlog = aRealloc(questlog, sizeof(struct quest)*i);
+ }
+ }
SQL->StmtFree(stmt);
- return i;
+ return questlog;
}
-//Delete a quest
-bool mapif_quest_delete(int char_id, int quest_id)
-{
- if ( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `quest_id` = '%d' AND `char_id` = '%d'", quest_db, quest_id, char_id) )
- {
+/**
+ * Deletes a quest from a character's questlog.
+ *
+ * @param char_id Character ID
+ * @param quest_id Quest ID
+ * @return false in case of errors, true otherwise
+ */
+bool mapif_quest_delete(int char_id, int quest_id) {
+ if (SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `quest_id` = '%d' AND `char_id` = '%d'", quest_db, quest_id, char_id)) {
Sql_ShowDebug(sql_handle);
return false;
}
@@ -65,66 +115,111 @@ bool mapif_quest_delete(int char_id, int quest_id)
return true;
}
-//Add a quest to a questlog
-bool mapif_quest_add(int char_id, struct quest qd)
-{
- if ( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s`(`quest_id`, `char_id`, `state`, `time`, `count1`, `count2`, `count3`) VALUES ('%d', '%d', '%d','%d', '%d', '%d', '%d')", quest_db, qd.quest_id, char_id, qd.state, qd.time, qd.count[0], qd.count[1], qd.count[2]) )
- {
+/**
+ * Adds a quest to a character's questlog.
+ *
+ * @param char_id Character ID
+ * @param qd Quest data
+ * @return false in case of errors, true otherwise
+ */
+bool mapif_quest_add(int char_id, struct quest qd) {
+ StringBuf buf;
+ int i;
+
+ StrBuf->Init(&buf);
+ StrBuf->Printf(&buf, "INSERT INTO `%s`(`quest_id`, `char_id`, `state`, `time`", quest_db);
+ for (i = 0; i < MAX_QUEST_OBJECTIVES; i++) {
+ StrBuf->Printf(&buf, ", `count%d`", i+1);
+ }
+ StrBuf->Printf(&buf, ") VALUES ('%d', '%d', '%d', '%d'", qd.quest_id, char_id, qd.state, qd.time);
+ for (i = 0; i < MAX_QUEST_OBJECTIVES; i++) {
+ StrBuf->Printf(&buf, ", '%d'", qd.count[i]);
+ }
+ StrBuf->AppendStr(&buf, ")");
+ if (SQL_ERROR == SQL->Query(sql_handle, StrBuf->Value(&buf))) {
Sql_ShowDebug(sql_handle);
+ StrBuf->Destroy(&buf);
return false;
}
+ StrBuf->Destroy(&buf);
return true;
}
-//Update a questlog
-bool mapif_quest_update(int char_id, struct quest qd)
-{
- if ( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `state`='%d', `count1`='%d', `count2`='%d', `count3`='%d' WHERE `quest_id` = '%d' AND `char_id` = '%d'", quest_db, qd.state, qd.count[0], qd.count[1], qd.count[2], qd.quest_id, char_id) )
- {
+/**
+ * Updates a quest in a character's questlog.
+ *
+ * @param char_id Character ID
+ * @param qd Quest data
+ * @return false in case of errors, true otherwise
+ */
+bool mapif_quest_update(int char_id, struct quest qd) {
+ StringBuf buf;
+ int i;
+
+ StrBuf->Init(&buf);
+ StrBuf->Printf(&buf, "UPDATE `%s` SET `state`='%d'", quest_db, qd.state);
+ for (i = 0; i < MAX_QUEST_OBJECTIVES; i++) {
+ StrBuf->Printf(&buf, ", `count%d`='%d'", i+1, qd.count[i]);
+ }
+ StrBuf->Printf(&buf, " WHERE `quest_id` = '%d' AND `char_id` = '%d'", qd.quest_id, char_id);
+
+ if (SQL_ERROR == SQL->Query(sql_handle, StrBuf->Value(&buf))) {
Sql_ShowDebug(sql_handle);
+ StrBuf->Destroy(&buf);
return false;
}
+ StrBuf->Destroy(&buf);
return true;
}
-//Save quests
-int mapif_parse_quest_save(int fd)
-{
- int i, j, k, num2, num1 = (RFIFOW(fd,2)-8)/sizeof(struct quest);
+/**
+ * Handles the save request from mapserver for a character's questlog.
+ *
+ * Received quests are saved, and an ack is sent back to the map server.
+ *
+ * @see inter_parse_frommap
+ */
+int mapif_parse_quest_save(int fd) {
+ int i, j, k, old_n, new_n = (RFIFOW(fd,2)-8)/sizeof(struct quest);
int char_id = RFIFOL(fd,4);
- struct quest qd1[MAX_QUEST_DB],qd2[MAX_QUEST_DB];
+ struct quest *old_qd = NULL, *new_qd = NULL;
bool success = true;
- memset(qd1, 0, sizeof(qd1));
- memset(qd2, 0, sizeof(qd2));
- if( num1 ) memcpy(&qd1, RFIFOP(fd,8), RFIFOW(fd,2)-8);
- num2 = mapif_quests_fromsql(char_id, qd2);
-
- for( i = 0; i < num1; i++ )
- {
- ARR_FIND( 0, num2, j, qd1[i].quest_id == qd2[j].quest_id );
- if( j < num2 ) // Update existed quests
- { // Only states and counts are changable.
- ARR_FIND( 0, MAX_QUEST_OBJECTIVES, k, qd1[i].count[k] != qd2[j].count[k] );
- if( k != MAX_QUEST_OBJECTIVES || qd1[i].state != qd2[j].state )
- success &= mapif_quest_update(char_id, qd1[i]);
-
- if( j < (--num2) )
- {
- memmove(&qd2[j],&qd2[j+1],sizeof(struct quest)*(num2-j));
- memset(&qd2[num2], 0, sizeof(struct quest));
- }
+ if (new_n > 0)
+ new_qd = (struct quest*)RFIFOP(fd,8);
+
+ old_qd = mapif_quests_fromsql(char_id, &old_n);
+ for (i = 0; i < new_n; i++) {
+ ARR_FIND( 0, old_n, j, new_qd[i].quest_id == old_qd[j].quest_id );
+ if (j < old_n) {
+ // Update existing quests
+
+ // Only states and counts are changeable.
+ ARR_FIND( 0, MAX_QUEST_OBJECTIVES, k, new_qd[i].count[k] != old_qd[j].count[k] );
+ if (k != MAX_QUEST_OBJECTIVES || new_qd[i].state != old_qd[j].state)
+ success &= mapif_quest_update(char_id, new_qd[i]);
+
+ if (j < (--old_n)) {
+ // Compact array
+ memmove(&old_qd[j],&old_qd[j+1],sizeof(struct quest)*(old_n-j));
+ memset(&old_qd[old_n], 0, sizeof(struct quest));
+ }
+ } else {
+ // Add new quests
+ success &= mapif_quest_add(char_id, new_qd[i]);
}
- else // Add new quests
- success &= mapif_quest_add(char_id, qd1[i]);
}
- for( i = 0; i < num2; i++ ) // Quests not in qd1 but in qd2 are to be erased.
- success &= mapif_quest_delete(char_id, qd2[i].quest_id);
+ for (i = 0; i < old_n; i++) // Quests not in new_qd but in old_qd are to be erased.
+ success &= mapif_quest_delete(char_id, old_qd[i].quest_id);
+ if (old_qd)
+ aFree(old_qd);
+
+ // Send ack
WFIFOHEAD(fd,7);
WFIFOW(fd,0) = 0x3861;
WFIFOL(fd,2) = char_id;
@@ -134,48 +229,45 @@ int mapif_parse_quest_save(int fd)
return 0;
}
-//Send questlog to map server
-int mapif_parse_quest_load(int fd)
-{
+/**
+ * Sends questlog to the map server
+ *
+ * Note: Completed quests (state == Q_COMPLETE) are guaranteed to be sent last
+ * and the map server relies on this behavior (once the first Q_COMPLETE quest,
+ * all of them are considered to be Q_COMPLETE)
+ *
+ * @see inter_parse_frommap
+ */
+int mapif_parse_quest_load(int fd) {
int char_id = RFIFOL(fd,2);
- struct quest tmp_questlog[MAX_QUEST_DB];
- int num_quests, i, num_complete = 0;
- int complete[MAX_QUEST_DB];
-
- memset(tmp_questlog, 0, sizeof(tmp_questlog));
- memset(complete, 0, sizeof(complete));
+ struct quest *tmp_questlog = NULL;
+ int num_quests;
- num_quests = mapif_quests_fromsql(char_id, tmp_questlog);
+ tmp_questlog = mapif_quests_fromsql(char_id, &num_quests);
WFIFOHEAD(fd,num_quests*sizeof(struct quest)+8);
WFIFOW(fd,0) = 0x3860;
WFIFOW(fd,2) = num_quests*sizeof(struct quest)+8;
WFIFOL(fd,4) = char_id;
- //Active and inactive quests
- for( i = 0; i < num_quests; i++ )
- {
- if( tmp_questlog[i].state == Q_COMPLETE )
- {
- complete[num_complete++] = i;
- continue;
- }
- memcpy(WFIFOP(fd,(i-num_complete)*sizeof(struct quest)+8), &tmp_questlog[i], sizeof(struct quest));
- }
-
- // Completed quests
- for( i = num_quests - num_complete; i < num_quests; i++ )
- memcpy(WFIFOP(fd,i*sizeof(struct quest)+8), &tmp_questlog[complete[i-num_quests+num_complete]], sizeof(struct quest));
+ if (num_quests > 0)
+ memcpy(WFIFOP(fd,8), tmp_questlog, sizeof(struct quest)*num_quests);
WFIFOSET(fd,num_quests*sizeof(struct quest)+8);
+ if (tmp_questlog)
+ aFree(tmp_questlog);
+
return 0;
}
-int inter_quest_parse_frommap(int fd)
-{
- switch(RFIFOW(fd,0))
- {
+/**
+ * Parses questlog related packets from the map server.
+ *
+ * @see inter_parse_frommap
+ */
+int inter_quest_parse_frommap(int fd) {
+ switch(RFIFOW(fd,0)) {
case 0x3060: mapif_parse_quest_load(fd); break;
case 0x3061: mapif_parse_quest_save(fd); break;
default:
diff --git a/src/char/int_quest.h b/src/char/int_quest.h
index f2a0b626e..f0dd370ea 100644
--- a/src/char/int_quest.h
+++ b/src/char/int_quest.h
@@ -1,13 +1,10 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-#ifndef _QUEST_H_
-#define _QUEST_H_
-
-/*questlog system*/
-struct quest;
+#ifndef CHAR_QUEST_H
+#define CHAR_QUEST_H
int inter_quest_parse_frommap(int fd);
-#endif
+#endif /* CHAR_QUEST_H */
diff --git a/src/char/int_storage.c b/src/char/int_storage.c
index 429b80105..882d9b2a5 100644
--- a/src/char/int_storage.c
+++ b/src/char/int_storage.c
@@ -2,19 +2,23 @@
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams
-#include "../common/mmo.h"
-#include "../common/malloc.h"
-#include "../common/showmsg.h"
-#include "../common/socket.h"
-#include "../common/strlib.h" // StringBuf
-#include "../common/sql.h"
-#include "char.h"
-#include "inter.h"
+#define HERCULES_CORE
+
+#include "../config/core.h" // GP_BOUND_ITEMS
+#include "int_storage.h"
#include <stdio.h>
-#include <string.h>
#include <stdlib.h>
+#include <string.h>
+#include "char.h"
+#include "inter.h"
+#include "../common/malloc.h"
+#include "../common/mmo.h"
+#include "../common/showmsg.h"
+#include "../common/socket.h"
+#include "../common/sql.h"
+#include "../common/strlib.h" // StringBuf
#define STORAGE_MEMINC 16
@@ -39,8 +43,8 @@ int storage_fromsql(int account_id, struct storage_data* p)
// storage {`account_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`}
StrBuf->Init(&buf);
- StrBuf->AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`expire_time`,`unique_id`");
- for( j = 0; j < MAX_SLOTS; ++j )
+ StrBuf->AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`expire_time`,`bound`,`unique_id`");
+ for( j = 0; j < MAX_SLOTS; ++j )
StrBuf->Printf(&buf, ",`card%d`", j);
StrBuf->Printf(&buf, " FROM `%s` WHERE `account_id`='%d' ORDER BY `nameid`", storage_db, account_id);
@@ -60,10 +64,11 @@ int storage_fromsql(int account_id, struct storage_data* p)
SQL->GetData(sql_handle, 5, &data, NULL); item->refine = atoi(data);
SQL->GetData(sql_handle, 6, &data, NULL); item->attribute = atoi(data);
SQL->GetData(sql_handle, 7, &data, NULL); item->expire_time = (unsigned int)atoi(data);
- SQL->GetData(sql_handle, 8, &data, NULL); item->unique_id = strtoull(data, NULL, 10);
- for( j = 0; j < MAX_SLOTS; ++j )
+ SQL->GetData(sql_handle, 8, &data, NULL); item->bound = atoi(data);
+ SQL->GetData(sql_handle, 9, &data, NULL); item->unique_id = strtoull(data, NULL, 10);
+ for( j = 0; j < MAX_SLOTS; ++j )
{
- SQL->GetData(sql_handle, 9+j, &data, NULL); item->card[j] = atoi(data);
+ SQL->GetData(sql_handle, 10+j, &data, NULL); item->card[j] = atoi(data);
}
}
p->storage_amount = i;
@@ -96,8 +101,8 @@ int guild_storage_fromsql(int guild_id, struct guild_storage* p)
// storage {`guild_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`}
StrBuf->Init(&buf);
- StrBuf->AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`unique_id`");
- for( j = 0; j < MAX_SLOTS; ++j )
+ StrBuf->AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`bound`,`unique_id`");
+ for( j = 0; j < MAX_SLOTS; ++j )
StrBuf->Printf(&buf, ",`card%d`", j);
StrBuf->Printf(&buf, " FROM `%s` WHERE `guild_id`='%d' ORDER BY `nameid`", guild_storage_db, guild_id);
@@ -106,8 +111,7 @@ int guild_storage_fromsql(int guild_id, struct guild_storage* p)
StrBuf->Destroy(&buf);
- for( i = 0; i < MAX_GUILD_STORAGE && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i )
- {
+ for( i = 0; i < MAX_GUILD_STORAGE && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i ) {
item = &p->items[i];
SQL->GetData(sql_handle, 0, &data, NULL); item->id = atoi(data);
SQL->GetData(sql_handle, 1, &data, NULL); item->nameid = atoi(data);
@@ -116,11 +120,12 @@ int guild_storage_fromsql(int guild_id, struct guild_storage* p)
SQL->GetData(sql_handle, 4, &data, NULL); item->identify = atoi(data);
SQL->GetData(sql_handle, 5, &data, NULL); item->refine = atoi(data);
SQL->GetData(sql_handle, 6, &data, NULL); item->attribute = atoi(data);
- SQL->GetData(sql_handle, 7, &data, NULL); item->unique_id = strtoull(data, NULL, 10);
- item->expire_time = 0;
- for( j = 0; j < MAX_SLOTS; ++j )
- {
- SQL->GetData(sql_handle, 8+j, &data, NULL); item->card[j] = atoi(data);
+ SQL->GetData(sql_handle, 7, &data, NULL); item->bound = atoi(data);
+ SQL->GetData(sql_handle, 8, &data, NULL); item->unique_id = strtoull(data, NULL, 10);
+ item->expire_time = 0;
+
+ for( j = 0; j < MAX_SLOTS; ++j ) {
+ SQL->GetData(sql_handle, 9+j, &data, NULL); item->card[j] = atoi(data);
}
}
p->storage_amount = i;
@@ -159,19 +164,20 @@ int inter_guild_storage_delete(int guild_id)
//---------------------------------------------------------
// packet from map server
-int mapif_load_guild_storage(int fd,int account_id,int guild_id)
+int mapif_load_guild_storage(int fd,int account_id,int guild_id, char flag)
{
if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `guild_id` FROM `%s` WHERE `guild_id`='%d'", guild_db, guild_id) )
Sql_ShowDebug(sql_handle);
else if( SQL->NumRows(sql_handle) > 0 )
{// guild exists
- WFIFOHEAD(fd, sizeof(struct guild_storage)+12);
+ WFIFOHEAD(fd, sizeof(struct guild_storage)+13);
WFIFOW(fd,0) = 0x3818;
- WFIFOW(fd,2) = sizeof(struct guild_storage)+12;
+ WFIFOW(fd,2) = sizeof(struct guild_storage)+13;
WFIFOL(fd,4) = account_id;
WFIFOL(fd,8) = guild_id;
- guild_storage_fromsql(guild_id, (struct guild_storage*)WFIFOP(fd,12));
- WFIFOSET(fd, WFIFOW(fd,2));
+ WFIFOB(fd,12) = flag; //1 open storage, 0 don't open
+ guild_storage_fromsql(guild_id, (struct guild_storage*)WFIFOP(fd,13));
+ WFIFOSET(fd, WFIFOW(fd,2));
return 0;
}
// guild does not exist
@@ -201,7 +207,7 @@ int mapif_save_guild_storage_ack(int fd,int account_id,int guild_id,int fail)
int mapif_parse_LoadGuildStorage(int fd)
{
RFIFOHEAD(fd);
- mapif_load_guild_storage(fd,RFIFOL(fd,2),RFIFOL(fd,6));
+ mapif_load_guild_storage(fd,RFIFOL(fd,2),RFIFOL(fd,6),1);
return 0;
}
@@ -214,16 +220,13 @@ int mapif_parse_SaveGuildStorage(int fd)
guild_id = RFIFOL(fd,8);
len = RFIFOW(fd,2);
- if( sizeof(struct guild_storage) != len - 12 )
- {
- ShowError("inter storage: data size error %d != %d\n", sizeof(struct guild_storage), len - 12);
- }
- else
- {
- if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `guild_id` FROM `%s` WHERE `guild_id`='%d'", guild_db, guild_id) )
+ if (sizeof(struct guild_storage) != len - 12) {
+ ShowError("inter storage: data size mismatch: %d != %"PRIuS"\n", len - 12, sizeof(struct guild_storage));
+ } else {
+ if (SQL_ERROR == SQL->Query(sql_handle, "SELECT `guild_id` FROM `%s` WHERE `guild_id`='%d'", guild_db, guild_id)) {
Sql_ShowDebug(sql_handle);
- else if( SQL->NumRows(sql_handle) > 0 )
- {// guild exists
+ } else if(SQL->NumRows(sql_handle) > 0) {
+ // guild exists
SQL->FreeResult(sql_handle);
guild_storage_tosql(guild_id, (struct guild_storage*)RFIFOP(fd,12));
mapif_save_guild_storage_ack(fd, RFIFOL(fd,4), guild_id, 0);
@@ -235,15 +238,206 @@ int mapif_parse_SaveGuildStorage(int fd)
return 0;
}
+int mapif_itembound_ack(int fd, int aid, int guild_id)
+{
+#ifdef GP_BOUND_ITEMS
+ WFIFOHEAD(fd,8);
+ WFIFOW(fd,0) = 0x3856;
+ WFIFOL(fd,2) = aid;/* the value is not being used, drop? */
+ WFIFOW(fd,6) = guild_id;
+ WFIFOSET(fd,8);
+#endif
+ return 0;
+}
+//------------------------------------------------
+//Guild bound items pull for offline characters [Akinari]
+//Revised by [Mhalicot]
+//------------------------------------------------
+int mapif_parse_ItemBoundRetrieve_sub(int fd)
+{
+#ifdef GP_BOUND_ITEMS
+ StringBuf buf;
+ SqlStmt* stmt;
+ struct item item;
+ int j, i=0, s=0, bound_qt=0;
+ struct item items[MAX_INVENTORY];
+ unsigned int bound_item[MAX_INVENTORY] = {0};
+ int char_id = RFIFOL(fd,2);
+ int aid = RFIFOL(fd,6);
+ int guild_id = RFIFOW(fd,10);
+
+ StrBuf->Init(&buf);
+ StrBuf->AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `bound`, `unique_id`");
+ for( j = 0; j < MAX_SLOTS; ++j )
+ StrBuf->Printf(&buf, ", `card%d`", j);
+ StrBuf->Printf(&buf, " FROM `%s` WHERE `char_id`='%d' AND `bound` = '%d'",inventory_db,char_id,IBT_GUILD);
+
+ stmt = SQL->StmtMalloc(sql_handle);
+ if( SQL_ERROR == SQL->StmtPrepareStr(stmt, StrBuf->Value(&buf))
+ || SQL_ERROR == SQL->StmtExecute(stmt) )
+ {
+ Sql_ShowDebug(sql_handle);
+ SQL->StmtFree(stmt);
+ StrBuf->Destroy(&buf);
+ return 1;
+ }
+
+ SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &item.id, 0, NULL, NULL);
+ SQL->StmtBindColumn(stmt, 1, SQLDT_SHORT, &item.nameid, 0, NULL, NULL);
+ SQL->StmtBindColumn(stmt, 2, SQLDT_SHORT, &item.amount, 0, NULL, NULL);
+ SQL->StmtBindColumn(stmt, 3, SQLDT_USHORT, &item.equip, 0, NULL, NULL);
+ SQL->StmtBindColumn(stmt, 4, SQLDT_CHAR, &item.identify, 0, NULL, NULL);
+ SQL->StmtBindColumn(stmt, 5, SQLDT_CHAR, &item.refine, 0, NULL, NULL);
+ SQL->StmtBindColumn(stmt, 6, SQLDT_CHAR, &item.attribute, 0, NULL, NULL);
+ SQL->StmtBindColumn(stmt, 7, SQLDT_UINT, &item.expire_time, 0, NULL, NULL);
+ SQL->StmtBindColumn(stmt, 8, SQLDT_UCHAR, &item.bound, 0, NULL, NULL);
+ SQL->StmtBindColumn(stmt, 9, SQLDT_UINT64, &item.unique_id, 0, NULL, NULL);
+ for( j = 0; j < MAX_SLOTS; ++j )
+ SQL->StmtBindColumn(stmt, 10+j, SQLDT_SHORT, &item.card[j], 0, NULL, NULL);
+
+ while( SQL_SUCCESS == SQL->StmtNextRow(stmt) ) {
+ memcpy(&items[i],&item,sizeof(struct item));
+ i++;
+ }
+ SQL->FreeResult(sql_handle);
+
+ if(!i) { //No items found - No need to continue
+ StrBuf->Destroy(&buf);
+ SQL->StmtFree(stmt);
+ return 0;
+ }
+
+ //First we delete the character's items
+ StrBuf->Clear(&buf);
+ StrBuf->Printf(&buf, "DELETE FROM `%s` WHERE",inventory_db);
+ for(j=0; j<i; j++) {
+ if( j )
+ StrBuf->AppendStr(&buf, " OR");
+
+ StrBuf->Printf(&buf, " `id`=%d",items[j].id);
+
+ if( items[j].bound && items[j].equip ) {
+ // Only the items that are also stored in `char` `equip`
+ if( items[j].equip&EQP_HAND_R
+ || items[j].equip&EQP_HAND_L
+ || items[j].equip&EQP_HEAD_TOP
+ || items[j].equip&EQP_HEAD_MID
+ || items[j].equip&EQP_HEAD_LOW
+ || items[j].equip&EQP_GARMENT
+ ) {
+ bound_item[bound_qt] = items[j].equip;
+ bound_qt++;
+ }
+ }
+ }
+
+ if( SQL_ERROR == SQL->StmtPrepareStr(stmt, StrBuf->Value(&buf))
+ || SQL_ERROR == SQL->StmtExecute(stmt) )
+ {
+ Sql_ShowDebug(sql_handle);
+ SQL->StmtFree(stmt);
+ StrBuf->Destroy(&buf);
+ return 1;
+ }
+
+ // Removes any view id that was set by an item that was removed
+ if( bound_qt ) {
+
+#define CHECK_REMOVE(var,mask,token) do { /* Verifies equip bitmasks (see item.equip) and handles the sql statement */ \
+ if ((var)&(mask)) { \
+ if ((var) != (mask) && s) StrBuf->AppendStr(&buf, ","); \
+ StrBuf->AppendStr(&buf,"`"#token"`='0'"); \
+ (var) &= ~(mask); \
+ s++; \
+ } \
+} while(0)
+
+ StrBuf->Clear(&buf);
+ StrBuf->Printf(&buf, "UPDATE `%s` SET ", char_db);
+ for( j = 0; j < bound_qt; j++ ) {
+ // Equips can be at more than one slot at the same time
+ CHECK_REMOVE(bound_item[j],EQP_HAND_R,weapon);
+ CHECK_REMOVE(bound_item[j],EQP_HAND_L,shield);
+ CHECK_REMOVE(bound_item[j],EQP_HEAD_TOP,head_top);
+ CHECK_REMOVE(bound_item[j],EQP_HEAD_MID,head_mid);
+ CHECK_REMOVE(bound_item[j],EQP_HEAD_LOW,head_bottom);
+ CHECK_REMOVE(bound_item[j],EQP_GARMENT,robe);
+ }
+ StrBuf->Printf(&buf, " WHERE `char_id`='%d'", char_id);
+
+ if( SQL_ERROR == SQL->StmtPrepareStr(stmt, StrBuf->Value(&buf))
+ || SQL_ERROR == SQL->StmtExecute(stmt) )
+ {
+ Sql_ShowDebug(sql_handle);
+ SQL->StmtFree(stmt);
+ StrBuf->Destroy(&buf);
+ return 1;
+ }
+#undef CHECK_REMOVE
+ }
+
+ //Now let's update the guild storage with those deleted items
+ /// TODO/FIXME:
+ /// This approach is basically the same as the one from memitemdata_to_sql, but
+ /// the latter compares current database values and this is not needed in this case
+ /// maybe sometime separate memitemdata_to_sql into different methods in order to use
+ /// call that function here as well [Panikon]
+ StrBuf->Clear(&buf);
+ StrBuf->Printf(&buf,"INSERT INTO `%s` (`guild_id`,`nameid`,`amount`,`equip`,`identify`,`refine`,"
+ "`attribute`,`expire_time`,`bound`,`unique_id`",
+ guild_storage_db);
+ for( s = 0; s < MAX_SLOTS; ++s )
+ StrBuf->Printf(&buf, ", `card%d`", s);
+ StrBuf->AppendStr(&buf," ) VALUES ");
+ for( j = 0; j < i; ++j ) {
+ if( j )
+ StrBuf->AppendStr(&buf, ",");
+
+ StrBuf->Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%"PRIu64"'",
+ guild_id, items[j].nameid, items[j].amount, items[j].equip, items[j].identify, items[j].refine,
+ items[j].attribute, items[j].expire_time, items[j].bound, items[j].unique_id);
+ for( s = 0; s < MAX_SLOTS; ++s )
+ StrBuf->Printf(&buf, ", '%d'", items[j].card[s]);
+ StrBuf->AppendStr(&buf, ")");
+ }
+
+ if( SQL_ERROR == SQL->StmtPrepareStr(stmt, StrBuf->Value(&buf))
+ || SQL_ERROR == SQL->StmtExecute(stmt) )
+ {
+ Sql_ShowDebug(sql_handle);
+ SQL->StmtFree(stmt);
+ StrBuf->Destroy(&buf);
+ return 1;
+ }
+
+ StrBuf->Destroy(&buf);
+ SQL->StmtFree(stmt);
+
+ //Finally reload storage and tell map we're done
+ mapif_load_guild_storage(fd,aid,guild_id,0);
+
+ // If character is logged in char, disconnect
+ disconnect_player(aid);
+#endif
+ return 0;
+}
+void mapif_parse_ItemBoundRetrieve(int fd) {
+ mapif_parse_ItemBoundRetrieve_sub(fd);
+ /* tell map server the operation is over and it can unlock the storage */
+ mapif_itembound_ack(fd,RFIFOL(fd,6),RFIFOW(fd,10));
+}
int inter_storage_parse_frommap(int fd)
{
RFIFOHEAD(fd);
switch(RFIFOW(fd,0)){
- case 0x3018: mapif_parse_LoadGuildStorage(fd); break;
- case 0x3019: mapif_parse_SaveGuildStorage(fd); break;
- default:
- return 0;
+ case 0x3018: mapif_parse_LoadGuildStorage(fd); break;
+ case 0x3019: mapif_parse_SaveGuildStorage(fd); break;
+#ifdef GP_BOUND_ITEMS
+ case 0x3056: mapif_parse_ItemBoundRetrieve(fd); break;
+#endif
+ default:
+ return 0;
}
return 1;
}
diff --git a/src/char/int_storage.h b/src/char/int_storage.h
index 811608f82..1cef94d98 100644
--- a/src/char/int_storage.h
+++ b/src/char/int_storage.h
@@ -1,8 +1,8 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-#ifndef _INT_STORAGE_SQL_H_
-#define _INT_STORAGE_SQL_H_
+#ifndef CHAR_INT_STORAGE_H
+#define CHAR_INT_STORAGE_H
struct storage_data;
struct guild_storage;
@@ -19,4 +19,4 @@ int storage_fromsql(int account_id, struct storage_data* p);
int storage_tosql(int account_id,struct storage_data *p);
int guild_storage_tosql(int guild_id, struct guild_storage *p);
-#endif /* _INT_STORAGE_SQL_H_ */
+#endif /* CHAR_INT_STORAGE_H */
diff --git a/src/char/inter.c b/src/char/inter.c
index 1ff2bca61..a7794c9c9 100644
--- a/src/char/inter.c
+++ b/src/char/inter.c
@@ -2,32 +2,35 @@
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams
-#include "../common/mmo.h"
-#include "../common/db.h"
-#include "../common/malloc.h"
-#include "../common/strlib.h"
-#include "../common/showmsg.h"
-#include "../common/socket.h"
-#include "../common/timer.h"
-#include "char.h"
+#define HERCULES_CORE
+
#include "inter.h"
-#include "int_party.h"
-#include "int_guild.h"
-#include "int_storage.h"
-#include "int_pet.h"
-#include "int_homun.h"
-#include "int_mercenary.h"
-#include "int_mail.h"
-#include "int_auction.h"
-#include "int_quest.h"
-#include "int_elemental.h"
+#include <errno.h>
#include <stdio.h>
-#include <string.h>
#include <stdlib.h>
-
+#include <string.h>
#include <sys/stat.h> // for stat/lstat/fstat - [Dekamaster/Ultimate GM Tool]
+#include "char.h"
+#include "int_auction.h"
+#include "int_elemental.h"
+#include "int_guild.h"
+#include "int_homun.h"
+#include "int_mail.h"
+#include "int_mercenary.h"
+#include "int_party.h"
+#include "int_pet.h"
+#include "int_quest.h"
+#include "int_storage.h"
+#include "../common/cbasetypes.h"
+#include "../common/db.h"
+#include "../common/malloc.h"
+#include "../common/mmo.h"
+#include "../common/showmsg.h"
+#include "../common/socket.h"
+#include "../common/strlib.h"
+#include "../common/timer.h"
#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
@@ -42,33 +45,32 @@ char char_server_pw[32] = "ragnarok";
char char_server_db[32] = "ragnarok";
char default_codepage[32] = ""; //Feature by irmin.
-static struct accreg *accreg_pt;
unsigned int party_share_level = 10;
// recv. packet list
int inter_recv_packet_length[] = {
-1,-1, 7,-1, -1,13,36, (2 + 4 + 4 + 4 + NAME_LENGTH), 0, 0, 0, 0, 0, 0, 0, 0, // 3000-
- 6,-1, 0, 0, 0, 0, 0, 0, 10,-1, 0, 0, 0, 0, 0, 0, // 3010-
- -1,10,-1,14, 14,19, 6,-1, 14,14, 0, 0, 0, 0, 0, 0, // 3020- Party
- -1, 6,-1,-1, 55,19, 6,-1, 14,-1,-1,-1, 18,19,186,-1, // 3030-
- -1, 9, 0, 0, 0, 0, 0, 0, 7, 6,10,10, 10,-1, 0, 0, // 3040-
- -1,-1,10,10, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3050- Auction System [Zephyrus]
- 6,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3060- Quest system [Kevin] [Inkfish]
- -1,10, 6,-1, 0, 0, 0, 0, 0, 0, 0, 0, -1,10, 6,-1, // 3070- Mercenary packets [Zephyrus], Elemental packets [pakpil]
- 48,14,-1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3080-
- -1,10,-1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3090- Homunculus packets [albator]
+ 6,-1, 0, 0, 0, 0, 0, 0, 10,-1, 0, 0, 0, 0, 0, 0, // 3010-
+ -1,10,-1,14, 14,19, 6,-1, 14,14, 0, 0, 0, 0, 0, 0, // 3020- Party
+ -1, 6,-1,-1, 55,19, 6,-1, 14,-1,-1,-1, 18,19,186,-1, // 3030-
+ -1, 9, 0, 0, 0, 0, 0, 0, 7, 6,10,10, 10,-1, 0, 0, // 3040-
+ -1,-1,10,10, 0,-1,12, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3050- Auction System [Zephyrus], Item Bound [Mhalicot]
+ 6,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3060- Quest system [Kevin] [Inkfish]
+ -1,10, 6,-1, 0, 0, 0, 0, 0, 0, 0, 0, -1,10, 6,-1, // 3070- Mercenary packets [Zephyrus], Elemental packets [pakpil]
+ 48,14,-1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3080-
+ -1,10,-1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3090- Homunculus packets [albator]
};
struct WisData {
int id, fd, count, len;
- unsigned long tick;
+ int64 tick;
unsigned char src[24], dst[24], msg[512];
};
static DBMap* wis_db = NULL; // int wis_id -> struct WisData*
static int wis_dellist[WISDELLIST_MAX], wis_delnum;
-#define MAX_JOB_NAMES 106
-static char* msg_table[MAX_JOB_NAMES]; // messages 550 ~ 655 are job names
+#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) {
msg_number -= 550;
@@ -79,17 +81,24 @@ const char* msg_txt(int msg_number) {
return "Unknown";
}
-/*==========================================
- * Read Message Data -- at char server we only keep job names.
- *------------------------------------------*/
-int msg_config_read(const char* cfgName) {
+/**
+ * Reads Message Data.
+ *
+ * This is a modified version of the mapserver's 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) {
int msg_number;
char line[1024], w1[1024], w2[1024];
FILE *fp;
static int called = 1;
- if ((fp = fopen(cfgName, "r")) == NULL) {
- ShowError("Messages file not found: %s\n", cfgName);
+ if ((fp = fopen(cfg_name, "r")) == NULL) {
+ ShowError("Messages file not found: %s\n", cfg_name);
return 1;
}
@@ -99,19 +108,25 @@ int msg_config_read(const char* cfgName) {
while(fgets(line, sizeof(line), fp) ) {
if (line[0] == '/' && line[1] == '/')
continue;
- if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
+ if (sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2) != 2)
continue;
if (strcmpi(w1, "import") == 0)
- msg_config_read(w2);
+ msg_config_read(w2, true);
else {
msg_number = atoi(w1);
if( msg_number < 550 || msg_number > (550+MAX_JOB_NAMES) )
continue;
msg_number -= 550;
if (msg_number >= 0 && msg_number < MAX_JOB_NAMES) {
- if (msg_table[msg_number] != NULL)
+ if (msg_table[msg_number] != NULL) {
+ if (!allow_override) {
+ ShowError("Duplicate message: ID '%d' was already used for '%s'. Message '%s' will be ignored.\n",
+ msg_number, w2, msg_table[msg_number]);
+ continue;
+ }
aFree(msg_table[msg_number]);
+ }
msg_table[msg_number] = (char *)aMalloc((strlen(w2) + 1)*sizeof (char));
strcpy(msg_table[msg_number],w2);
}
@@ -134,107 +149,107 @@ void do_final_msg(void) {
/* from pc.c due to @accinfo. any ideas to replace this crap are more than welcome. */
const char* job_name(int class_) {
switch (class_) {
- case JOB_NOVICE:
- case JOB_SWORDMAN:
- case JOB_MAGE:
- case JOB_ARCHER:
- case JOB_ACOLYTE:
- case JOB_MERCHANT:
- case JOB_THIEF:
+ case JOB_NOVICE: // 550
+ case JOB_SWORDMAN: // 551
+ case JOB_MAGE: // 552
+ case JOB_ARCHER: // 553
+ case JOB_ACOLYTE: // 554
+ case JOB_MERCHANT: // 555
+ case JOB_THIEF: // 556
return msg_txt(550 - JOB_NOVICE+class_);
- case JOB_KNIGHT:
- case JOB_PRIEST:
- case JOB_WIZARD:
- case JOB_BLACKSMITH:
- case JOB_HUNTER:
- case JOB_ASSASSIN:
+ case JOB_KNIGHT: // 557
+ case JOB_PRIEST: // 558
+ case JOB_WIZARD: // 559
+ case JOB_BLACKSMITH: // 560
+ case JOB_HUNTER: // 561
+ case JOB_ASSASSIN: // 562
return msg_txt(557 - JOB_KNIGHT+class_);
case JOB_KNIGHT2:
return msg_txt(557);
- case JOB_CRUSADER:
- case JOB_MONK:
- case JOB_SAGE:
- case JOB_ROGUE:
- case JOB_ALCHEMIST:
- case JOB_BARD:
- case JOB_DANCER:
+ case JOB_CRUSADER: // 563
+ case JOB_MONK: // 564
+ case JOB_SAGE: // 565
+ case JOB_ROGUE: // 566
+ case JOB_ALCHEMIST: // 567
+ case JOB_BARD: // 568
+ case JOB_DANCER: // 569
return msg_txt(563 - JOB_CRUSADER+class_);
case JOB_CRUSADER2:
return msg_txt(563);
- case JOB_WEDDING:
- case JOB_SUPER_NOVICE:
- case JOB_GUNSLINGER:
- case JOB_NINJA:
- case JOB_XMAS:
+ 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_);
case JOB_SUMMER:
return msg_txt(621);
- case JOB_NOVICE_HIGH:
- case JOB_SWORDMAN_HIGH:
- case JOB_MAGE_HIGH:
- case JOB_ARCHER_HIGH:
- case JOB_ACOLYTE_HIGH:
- case JOB_MERCHANT_HIGH:
- case JOB_THIEF_HIGH:
+ case JOB_NOVICE_HIGH: // 575
+ case JOB_SWORDMAN_HIGH: // 576
+ case JOB_MAGE_HIGH: // 577
+ case JOB_ARCHER_HIGH: // 578
+ case JOB_ACOLYTE_HIGH: // 579
+ case JOB_MERCHANT_HIGH: // 580
+ case JOB_THIEF_HIGH: // 581
return msg_txt(575 - JOB_NOVICE_HIGH+class_);
- case JOB_LORD_KNIGHT:
- case JOB_HIGH_PRIEST:
- case JOB_HIGH_WIZARD:
- case JOB_WHITESMITH:
- case JOB_SNIPER:
- case JOB_ASSASSIN_CROSS:
+ case JOB_LORD_KNIGHT: // 582
+ case JOB_HIGH_PRIEST: // 583
+ case JOB_HIGH_WIZARD: // 584
+ case JOB_WHITESMITH: // 585
+ case JOB_SNIPER: // 586
+ case JOB_ASSASSIN_CROSS: // 587
return msg_txt(582 - JOB_LORD_KNIGHT+class_);
case JOB_LORD_KNIGHT2:
return msg_txt(582);
- case JOB_PALADIN:
- case JOB_CHAMPION:
- case JOB_PROFESSOR:
- case JOB_STALKER:
- case JOB_CREATOR:
- case JOB_CLOWN:
- case JOB_GYPSY:
+ case JOB_PALADIN: // 588
+ case JOB_CHAMPION: // 589
+ case JOB_PROFESSOR: // 590
+ case JOB_STALKER: // 591
+ case JOB_CREATOR: // 592
+ case JOB_CLOWN: // 593
+ case JOB_GYPSY: // 594
return msg_txt(588 - JOB_PALADIN + class_);
case JOB_PALADIN2:
return msg_txt(588);
- case JOB_BABY:
- case JOB_BABY_SWORDMAN:
- case JOB_BABY_MAGE:
- case JOB_BABY_ARCHER:
- case JOB_BABY_ACOLYTE:
- case JOB_BABY_MERCHANT:
- case JOB_BABY_THIEF:
+ case JOB_BABY: // 595
+ case JOB_BABY_SWORDMAN: // 596
+ case JOB_BABY_MAGE: // 597
+ case JOB_BABY_ARCHER: // 598
+ case JOB_BABY_ACOLYTE: // 599
+ case JOB_BABY_MERCHANT: // 600
+ case JOB_BABY_THIEF: // 601
return msg_txt(595 - JOB_BABY + class_);
- case JOB_BABY_KNIGHT:
- case JOB_BABY_PRIEST:
- case JOB_BABY_WIZARD:
- case JOB_BABY_BLACKSMITH:
- case JOB_BABY_HUNTER:
- case JOB_BABY_ASSASSIN:
+ case JOB_BABY_KNIGHT: // 602
+ case JOB_BABY_PRIEST: // 603
+ case JOB_BABY_WIZARD: // 604
+ case JOB_BABY_BLACKSMITH: // 605
+ case JOB_BABY_HUNTER: // 606
+ case JOB_BABY_ASSASSIN: // 607
return msg_txt(602 - JOB_BABY_KNIGHT + class_);
case JOB_BABY_KNIGHT2:
return msg_txt(602);
- case JOB_BABY_CRUSADER:
- case JOB_BABY_MONK:
- case JOB_BABY_SAGE:
- case JOB_BABY_ROGUE:
- case JOB_BABY_ALCHEMIST:
- case JOB_BABY_BARD:
- case JOB_BABY_DANCER:
+ case JOB_BABY_CRUSADER: // 608
+ case JOB_BABY_MONK: // 609
+ case JOB_BABY_SAGE: // 610
+ case JOB_BABY_ROGUE: // 611
+ case JOB_BABY_ALCHEMIST: // 612
+ case JOB_BABY_BARD: // 613
+ case JOB_BABY_DANCER: // 614
return msg_txt(608 - JOB_BABY_CRUSADER + class_);
case JOB_BABY_CRUSADER2:
@@ -251,74 +266,82 @@ const char* job_name(int class_) {
case JOB_SOUL_LINKER:
return msg_txt(618);
- case JOB_GANGSI:
- case JOB_DEATH_KNIGHT:
- case JOB_DARK_COLLECTOR:
+ case JOB_GANGSI: // 622
+ case JOB_DEATH_KNIGHT: // 623
+ case JOB_DARK_COLLECTOR: // 624
return msg_txt(622 - JOB_GANGSI+class_);
- case JOB_RUNE_KNIGHT:
- case JOB_WARLOCK:
- case JOB_RANGER:
- case JOB_ARCH_BISHOP:
- case JOB_MECHANIC:
- case JOB_GUILLOTINE_CROSS:
+ case JOB_RUNE_KNIGHT: // 625
+ case JOB_WARLOCK: // 626
+ case JOB_RANGER: // 627
+ case JOB_ARCH_BISHOP: // 628
+ case JOB_MECHANIC: // 629
+ case JOB_GUILLOTINE_CROSS: // 630
return msg_txt(625 - JOB_RUNE_KNIGHT+class_);
- case JOB_RUNE_KNIGHT_T:
- case JOB_WARLOCK_T:
- case JOB_RANGER_T:
- case JOB_ARCH_BISHOP_T:
- case JOB_MECHANIC_T:
- case JOB_GUILLOTINE_CROSS_T:
- return msg_txt(625 - JOB_RUNE_KNIGHT_T+class_);
-
- case JOB_ROYAL_GUARD:
- case JOB_SORCERER:
- case JOB_MINSTREL:
- case JOB_WANDERER:
- case JOB_SURA:
- case JOB_GENETIC:
- case JOB_SHADOW_CHASER:
+ case JOB_RUNE_KNIGHT_T: // 656
+ case JOB_WARLOCK_T: // 657
+ case JOB_RANGER_T: // 658
+ 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_);
+
+ case JOB_ROYAL_GUARD: // 631
+ case JOB_SORCERER: // 632
+ case JOB_MINSTREL: // 633
+ case JOB_WANDERER: // 634
+ case JOB_SURA: // 635
+ case JOB_GENETIC: // 636
+ case JOB_SHADOW_CHASER: // 637
return msg_txt(631 - JOB_ROYAL_GUARD+class_);
- case JOB_ROYAL_GUARD_T:
- case JOB_SORCERER_T:
- case JOB_MINSTREL_T:
- case JOB_WANDERER_T:
- case JOB_SURA_T:
- case JOB_GENETIC_T:
- case JOB_SHADOW_CHASER_T:
- return msg_txt(631 - JOB_ROYAL_GUARD_T+class_);
+ case JOB_ROYAL_GUARD_T: // 662
+ case JOB_SORCERER_T: // 663
+ case JOB_MINSTREL_T: // 664
+ case JOB_WANDERER_T: // 665
+ 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_);
case JOB_RUNE_KNIGHT2:
- case JOB_RUNE_KNIGHT_T2:
return msg_txt(625);
+ case JOB_RUNE_KNIGHT_T2:
+ return msg_txt(656);
+
case JOB_ROYAL_GUARD2:
- case JOB_ROYAL_GUARD_T2:
return msg_txt(631);
+ case JOB_ROYAL_GUARD_T2:
+ return msg_txt(662);
+
case JOB_RANGER2:
- case JOB_RANGER_T2:
return msg_txt(627);
+ case JOB_RANGER_T2:
+ return msg_txt(658);
+
case JOB_MECHANIC2:
- case JOB_MECHANIC_T2:
return msg_txt(629);
- case JOB_BABY_RUNE:
- case JOB_BABY_WARLOCK:
- case JOB_BABY_RANGER:
- case JOB_BABY_BISHOP:
- case JOB_BABY_MECHANIC:
- case JOB_BABY_CROSS:
- case JOB_BABY_GUARD:
- case JOB_BABY_SORCERER:
- case JOB_BABY_MINSTREL:
- case JOB_BABY_WANDERER:
- case JOB_BABY_SURA:
- case JOB_BABY_GENETIC:
- case JOB_BABY_CHASER:
+ case JOB_MECHANIC_T2:
+ return msg_txt(660);
+
+ case JOB_BABY_RUNE: // 638
+ case JOB_BABY_WARLOCK: // 639
+ case JOB_BABY_RANGER: // 640
+ case JOB_BABY_BISHOP: // 641
+ case JOB_BABY_MECHANIC: // 642
+ case JOB_BABY_CROSS: // 643
+ case JOB_BABY_GUARD: // 644
+ case JOB_BABY_SORCERER: // 645
+ case JOB_BABY_MINSTREL: // 646
+ case JOB_BABY_WANDERER: // 647
+ case JOB_BABY_SURA: // 648
+ case JOB_BABY_GENETIC: // 649
+ case JOB_BABY_CHASER: // 650
return msg_txt(638 - JOB_BABY_RUNE+class_);
case JOB_BABY_RUNE2:
@@ -333,23 +356,28 @@ const char* job_name(int class_) {
case JOB_BABY_MECHANIC2:
return msg_txt(642);
- case JOB_SUPER_NOVICE_E:
- case JOB_SUPER_BABY_E:
+ case JOB_SUPER_NOVICE_E: // 651
+ case JOB_SUPER_BABY_E: // 652
return msg_txt(651 - JOB_SUPER_NOVICE_E+class_);
- case JOB_KAGEROU:
- case JOB_OBORO:
+ case JOB_KAGEROU: // 653
+ case JOB_OBORO: // 654
return msg_txt(653 - JOB_KAGEROU+class_);
- default:
+ case JOB_REBELLION:
return msg_txt(655);
+
+ default:
+ return msg_txt(620); // "Unknown Job"
}
}
-/**
- * [Dekamaster/Nightroad]
- **/
-const char * geoip_countryname[253] = {"Unknown","Asia/Pacific Region","Europe","Andorra","United Arab Emirates","Afghanistan","Antigua and Barbuda","Anguilla","Albania","Armenia","Netherlands Antilles",
+/* [Dekamaster/Nightroad] */
+#define GEOIP_MAX_COUNTRIES 255
+#define GEOIP_STRUCTURE_INFO_MAX_SIZE 20
+#define GEOIP_COUNTRY_BEGIN 16776960
+
+const char * geoip_countryname[GEOIP_MAX_COUNTRIES] = {"Unknown","Asia/Pacific Region","Europe","Andorra","United Arab Emirates","Afghanistan","Antigua and Barbuda","Anguilla","Albania","Armenia","Netherlands Antilles",
"Angola","Antarctica","Argentina","American Samoa","Austria","Australia","Aruba","Azerbaijan","Bosnia and Herzegovina","Barbados",
"Bangladesh","Belgium","Burkina Faso","Bulgaria","Bahrain","Burundi","Benin","Bermuda","Brunei Darussalam","Bolivia",
"Brazil","Bahamas","Bhutan","Bouvet Island","Botswana","Belarus","Belize","Canada","Cocos (Keeling) Islands","Congo, The Democratic Republic of the",
@@ -374,17 +402,15 @@ const char * geoip_countryname[253] = {"Unknown","Asia/Pacific Region","Europe",
"Tanzania, United Republic of","Ukraine","Uganda","United States Minor Outlying Islands","United States","Uruguay","Uzbekistan","Holy See (Vatican City State)","Saint Vincent and the Grenadines","Venezuela",
"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"};
-unsigned char *geoip_cache;
-void geoip_readdb(void){
- struct stat bufa;
- FILE *db=fopen("./db/GeoIP.dat","rb");
- fstat(fileno(db), &bufa);
- geoip_cache = (unsigned char *) malloc(sizeof(unsigned char) * bufa.st_size);
- if(fread(geoip_cache, sizeof(unsigned char), bufa.st_size, db) != bufa.st_size) { ShowError("geoip_cache reading didn't read all elements \n"); }
- fclose(db);
- ShowStatus("Finished Reading "CL_GREEN"GeoIP"CL_RESET" Database.\n");
-}
+ "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){
@@ -393,8 +419,11 @@ const char* geoip_getcountry(uint32 ipnum){
const unsigned char *buf;
unsigned int offset = 0;
+ if( geoip.active == false )
+ return geoip_countryname[0];
+
for (depth = 31; depth >= 0; depth--) {
- buf = geoip_cache + (long)6 *offset;
+ buf = geoip.cache + (long)6 *offset;
if (ipnum & (1 << depth)) {
/* Take the right-hand branch */
x = (buf[3*1 + 0] << (0*8))
@@ -406,24 +435,111 @@ const char* geoip_getcountry(uint32 ipnum){
+ (buf[3*0 + 1] << (1*8))
+ (buf[3*0 + 2] << (2*8));
}
- if (x >= 16776960) {
- x=x-16776960;
+ if (x >= GEOIP_COUNTRY_BEGIN) {
+ x = x-GEOIP_COUNTRY_BEGIN;
+
+ if( x > GEOIP_MAX_COUNTRIES )
+ return geoip_countryname[0];
+
return geoip_countryname[x];
}
offset = x;
}
+ ShowError("geoip_getcountry(): Error traversing database for ipnum %d\n", ipnum);
+ ShowWarning("geoip_getcountry(): Possible database corruption!\n");
+
return geoip_countryname[0];
}
-/* sends a mesasge to map server (fd) to a user (u_fd) although we use fd we keep aid for safe-check */
-/* extremely handy I believe it will serve other uses in the near future */
-void inter_to_fd(int fd, int u_fd, int aid, char* msg, ...) {
+
+/**
+ * Disables GeoIP
+ * frees geoip.cache
+ **/
+void geoip_final(bool shutdown) {
+ if (geoip.cache) {
+ aFree(geoip.cache);
+ geoip.cache = NULL;
+ }
+
+ if (geoip.active) {
+ if (!shutdown)
+ ShowStatus("GeoIP "CL_RED"disabled"CL_RESET".\n");
+ geoip.active = false;
+ }
+}
+
+/**
+ * Reads GeoIP database and stores it into memory
+ * geoip.cache should be freed after use!
+ * http://dev.maxmind.com/geoip/legacy/geolite/
+ **/
+void geoip_init(void) {
+ int i, fno;
+ char db_type = 1;
+ unsigned char delim[3];
+ struct stat bufa;
+ FILE *db;
+
+ geoip.active = true;
+
+ db = fopen("./db/GeoIP.dat","rb");
+ if( db == NULL ) {
+ ShowError("geoip_readdb: Error reading GeoIP.dat!\n");
+ 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);
+ return;
+ }
+ geoip.cache = aMalloc( (sizeof(geoip.cache) * bufa.st_size) );
+ if( fread(geoip.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);
+ return;
+ }
+
+ // Search database type
+ fseek(db, -3l, SEEK_END);
+ for( i = 0; i < GEOIP_STRUCTURE_INFO_MAX_SIZE; i++ ) {
+ fread(delim, sizeof(delim[0]), 3, db);
+ if( delim[0] == 255 && delim[1] == 255 && delim[2] == 255 ) {
+ fread(&db_type, sizeof(db_type), 1, db);
+ break;
+ } else {
+ fseek(db, -4l, SEEK_CUR);
+ }
+ }
+
+ fclose(db);
+
+ if( db_type != 1 ) {
+ if( db_type )
+ ShowError("geoip_init(): Database type is not supported %d!\n", db_type);
+ else
+ ShowError("geoip_init(): GeoIP is corrupted!\n");
+
+ geoip_final(false);
+ return;
+ }
+ ShowStatus("Finished Reading "CL_GREEN"GeoIP"CL_RESET" Database.\n");
+}
+
+/**
+ * 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) {
char msg_out[512];
- va_list ap;
+ va_list apcopy;
int len = 1;/* yes we start at 1 */
- va_start(ap,msg);
- len += vsnprintf(msg_out, 512, msg, ap);
- va_end(ap);
+ va_copy(apcopy, ap);
+ len += vsnprintf(msg_out, 512, msg, apcopy);
+ va_end(apcopy);
WFIFOHEAD(fd,12 + len);
@@ -437,6 +553,24 @@ void inter_to_fd(int fd, int u_fd, int aid, char* msg, ...) {
return;
}
+
+/**
+ * Sends a message to map server (fd) to a user (u_fd) although we use fd we
+ * keep aid for safe-check.
+ * @param fd Mapserver's fd
+ * @param u_fd Recipient's fd
+ * @param aid Recipient's expected for sanity checks on the mapserver
+ * @param msg Message format string
+ * @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, ...) {
+ va_list ap;
+ va_start(ap,msg);
+ inter_vmsg_to_fd(fd, u_fd, aid, msg, ap);
+ va_end(ap);
+}
+
/* [Dekamaster/Nightroad] */
void mapif_parse_accinfo(int fd) {
int u_fd = RFIFOL(fd,2), aid = RFIFOL(fd,6), castergroup = RFIFOL(fd,10);
@@ -451,13 +585,13 @@ void mapif_parse_accinfo(int fd) {
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 `char` WHERE `name` LIKE '%s' LIMIT 10", query_esq)
+ 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_to_fd(fd, u_fd, aid, "No matches were found for your criteria, '%s'",query);
+ inter_msg_to_fd(fd, u_fd, aid, "No matches were found for your criteria, '%s'",query);
} else {
Sql_ShowDebug(sql_handle);
- inter_to_fd(fd, u_fd, aid, "An error occured, bother your admin about it.");
+ inter_msg_to_fd(fd, u_fd, aid, "An error occurred, bother your admin about it.");
}
SQL->FreeResult(sql_handle);
return;
@@ -467,7 +601,7 @@ void mapif_parse_accinfo(int fd) {
SQL->GetData(sql_handle, 0, &data, NULL); account_id = atoi(data);
SQL->FreeResult(sql_handle);
} else {// more than one, listing... [Dekamaster/Nightroad]
- inter_to_fd(fd, u_fd, aid, "Your query returned the following %d results, please be more specific...",(int)SQL->NumRows(sql_handle));
+ 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) ) {
int class_;
short base_level, job_level, online;
@@ -480,7 +614,7 @@ void mapif_parse_accinfo(int fd) {
SQL->GetData(sql_handle, 4, &data, NULL); job_level = atoi(data);
SQL->GetData(sql_handle, 5, &data, NULL); online = atoi(data);
- inter_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, job_name(class_), base_level, job_level, online?"Online":"Offline");
}
SQL->FreeResult(sql_handle);
return;
@@ -489,206 +623,287 @@ 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 ) {
- char userid[NAME_LENGTH], user_pass[NAME_LENGTH], email[40], last_ip[20], lastlogin[30], pincode[5], birthdate[11];
- short level = -1;
- int logincount = 0,state = 0;
- if ( SQL_ERROR == SQL->Query(sql_handle, "SELECT `userid`, `user_pass`, `email`, `last_ip`, `group_id`, `lastlogin`, `logincount`, `state`,`pincode`,`birthdate` FROM `login` WHERE `account_id` = '%d' LIMIT 1", account_id)
- || SQL->NumRows(sql_handle) == 0 ) {
- if( SQL->NumRows(sql_handle) == 0 ) {
- inter_to_fd(fd, u_fd, aid, "No account with ID '%d' was found.", account_id );
- } else {
- inter_to_fd(fd, u_fd, aid, "An error occured, bother your admin about it.");
- Sql_ShowDebug(sql_handle);
- }
- } else {
- SQL->NextRow(sql_handle);
- SQL->GetData(sql_handle, 0, &data, NULL); safestrncpy(userid, data, sizeof(userid));
- SQL->GetData(sql_handle, 1, &data, NULL); safestrncpy(user_pass, data, sizeof(user_pass));
- SQL->GetData(sql_handle, 2, &data, NULL); safestrncpy(email, data, sizeof(email));
- SQL->GetData(sql_handle, 3, &data, NULL); safestrncpy(last_ip, data, sizeof(last_ip));
- SQL->GetData(sql_handle, 4, &data, NULL); level = atoi(data);
- SQL->GetData(sql_handle, 5, &data, NULL); safestrncpy(lastlogin, data, sizeof(lastlogin));
- SQL->GetData(sql_handle, 6, &data, NULL); logincount = atoi(data);
- SQL->GetData(sql_handle, 7, &data, NULL); state = atoi(data);
- SQL->GetData(sql_handle, 8, &data, NULL); safestrncpy(pincode, data, sizeof(pincode));
- SQL->GetData(sql_handle, 9, &data, NULL); safestrncpy(birthdate, data, sizeof(birthdate));
- }
-
- SQL->FreeResult(sql_handle);
-
- if (level == -1)
- return;
-
- inter_to_fd(fd, u_fd, aid, "-- Account %d --", account_id );
- inter_to_fd(fd, u_fd, aid, "User: %s | GM Group: %d | State: %d", userid, level, state );
-
- if (level < castergroup) { /* only show pass if your gm level is greater than the one you're searching for */
- if( strlen(pincode) )
- inter_to_fd(fd, u_fd, aid, "Password: %s (PIN:%s)", user_pass, pincode );
- else
- inter_to_fd(fd, u_fd, aid, "Password: %s", user_pass );
- }
-
- inter_to_fd(fd, u_fd, aid, "Account e-mail: %s | Birthdate: %s", email, birthdate);
- inter_to_fd(fd, u_fd, aid, "Last IP: %s (%s)", last_ip, geoip_getcountry(str2ip(last_ip)) );
- inter_to_fd(fd, u_fd, aid, "This user has logged %d times, the last time were at %s", logincount, lastlogin );
- inter_to_fd(fd, u_fd, aid, "-- Character Details --" );
-
-
- if ( SQL_ERROR == SQL->Query(sql_handle, "SELECT `char_id`, `name`, `char_num`, `class`, `base_level`, `job_level`, `online` FROM `char` WHERE `account_id` = '%d' ORDER BY `char_num` LIMIT %d", account_id, MAX_CHARS)
- || SQL->NumRows(sql_handle) == 0 ) {
-
- if( SQL->NumRows(sql_handle) == 0 )
- inter_to_fd(fd, u_fd, aid,"This account doesn't have characters.");
- else {
- inter_to_fd(fd, u_fd, aid,"An error occured, bother your admin about it.");
- Sql_ShowDebug(sql_handle);
- }
-
- } else {
- while ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) {
- 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);
-
- inter_to_fd(fd, u_fd, 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");
- }
- }
- SQL->FreeResult(sql_handle);
+ mapif_on_parse_accinfo(account_id, u_fd, aid, castergroup, fd);
}
return;
}
-//--------------------------------------------------------
-// Save registry to sql
-int inter_accreg_tosql(int account_id, int char_id, struct accreg* reg, int type)
-{
- struct global_reg* r;
- StringBuf buf;
- int i;
-
- if( account_id <= 0 )
- return 0;
- reg->account_id = account_id;
- reg->char_id = char_id;
+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
- //`global_reg_value` (`type`, `account_id`, `char_id`, `str`, `value`)
- switch( type )
- {
- case 3: //Char Reg
- if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `type`=3 AND `char_id`='%d'", reg_db, char_id) )
- Sql_ShowDebug(sql_handle);
- account_id = 0;
- break;
- case 2: //Account Reg
- if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `type`=2 AND `account_id`='%d'", reg_db, account_id) )
- Sql_ShowDebug(sql_handle);
- char_id = 0;
- break;
- case 1: //Account2 Reg
- ShowError("inter_accreg_tosql: Char server shouldn't handle type 1 registry values (##). That is the login server's work!\n");
- return 0;
- default:
- ShowError("inter_accreg_tosql: Invalid type %d\n", type);
- return 0;
+ if (!success) {
+ inter_msg_to_fd(map_fd, u_fd, u_aid, "No account with ID '%d' was found.", account_id);
+ return;
}
- if( reg->reg_num <= 0 )
- return 0;
-
- StrBuf->Init(&buf);
- StrBuf->Printf(&buf, "INSERT INTO `%s` (`type`,`account_id`,`char_id`,`str`,`value`) VALUES ", reg_db);
-
- for( i = 0; i < reg->reg_num; ++i ) {
- r = &reg->reg[i];
- if( r->str[0] != '\0' && r->value[0] != '\0' ) {
- char str[32];
- char val[256];
+ 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( i > 0 )
- StrBuf->AppendStr(&buf, ",");
+ 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);
+ else
+ inter_msg_to_fd(map_fd, u_fd, u_aid, "Password: %s", user_pass );
+ }
- SQL->EscapeString(sql_handle, str, r->str);
- SQL->EscapeString(sql_handle, val, r->value);
+ 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 --");
- StrBuf->Printf(&buf, "('%d','%d','%d','%s','%s')", type, account_id, char_id, str, val);
+ if ( SQL_ERROR == SQL->Query(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.");
+ } else {
+ inter_msg_to_fd(map_fd, u_fd, u_aid, "An error occurred, bother your admin about it.");
+ Sql_ShowDebug(sql_handle);
+ }
+ } else {
+ while ( SQL_SUCCESS == SQL->NextRow(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);
+
+ 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");
}
}
+ SQL->FreeResult(sql_handle);
- if( SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) {
- Sql_ShowDebug(sql_handle);
+ return;
+}
+/**
+ * Handles save reg data from map server and distributes accordingly.
+ *
+ * @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) {
+ /* to login server we go! */
+ if( key[0] == '#' && key[1] == '#' ) {/* global account reg */
+ global_accreg_to_login_add(key,index,val,is_string);
+ } 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);
+ } 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);
+ }
+ } 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);
+ } 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);
+ }
+ }
+ } 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);
+ } 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);
+ }
+ } 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);
+ } 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);
+ }
+ }
}
-
- StrBuf->Destroy(&buf);
-
- return 1;
+
}
// Load account_reg from sql (type=2)
-int inter_accreg_fromsql(int account_id,int char_id, struct accreg *reg, int type)
+int inter_accreg_fromsql(int account_id,int char_id, int fd, int type)
{
- struct global_reg* r;
char* data;
size_t len;
- int i;
+ unsigned int plen = 0;
- if( reg == NULL)
- return 0;
-
- memset(reg, 0, sizeof(struct accreg));
- reg->account_id = account_id;
- reg->char_id = char_id;
+ 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);
+ 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);
+ 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");
+ return 0;
+ default:
+ ShowError("inter_accreg_fromsql: Invalid type %d\n", type);
+ return 0;
+ }
+
+ WFIFOHEAD(fd, 60000 + 300);
+ WFIFOW(fd, 0) = 0x3804;
+ /* 0x2 = length, set prior to being sent */
+ WFIFOL(fd, 4) = account_id;
+ WFIFOL(fd, 8) = char_id;
+ WFIFOB(fd, 12) = 0;/* var type (only set when all vars have been sent, regardless of type) */
+ WFIFOB(fd, 13) = 1;/* is string type */
+ WFIFOW(fd, 14) = 0;/* count */
+ plen = 16;
+
+ /**
+ * Vessel!
+ *
+ * str type
+ * { keyLength(B), key(<keyLength>), index(L), valLength(B), val(<valLength>) }
+ **/
+ while ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) {
+
+ SQL->GetData(sql_handle, 0, &data, NULL);
+ len = strlen(data)+1;
+
+ WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 32 */
+ plen += 1;
+
+ safestrncpy((char*)WFIFOP(fd,plen), data, len);
+ plen += len;
+
+ SQL->GetData(sql_handle, 1, &data, NULL);
+
+ WFIFOL(fd, plen) = (unsigned int)atol(data);
+ plen += 4;
+
+ SQL->GetData(sql_handle, 2, &data, NULL);
+ len = strlen(data)+1;
+
+ WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 254 */
+ plen += 1;
+
+ safestrncpy((char*)WFIFOP(fd,plen), data, len);
+ plen += len;
+
+ WFIFOW(fd, 14) += 1;
+
+ if( plen > 60000 ) {
+ WFIFOW(fd, 2) = plen;
+ WFIFOSET(fd, plen);
+
+ /* prepare follow up */
+ WFIFOHEAD(fd, 60000 + 300);
+ WFIFOW(fd, 0) = 0x3804;
+ /* 0x2 = length, set prior to being sent */
+ WFIFOL(fd, 4) = account_id;
+ WFIFOL(fd, 8) = char_id;
+ WFIFOB(fd, 12) = 0;/* var type (only set when all vars have been sent, regardless of type) */
+ WFIFOB(fd, 13) = 1;/* is string type */
+ WFIFOW(fd, 14) = 0;/* count */
+ plen = 16;
+ }
+ }
+
+ /* mark & go. */
+ WFIFOW(fd, 2) = plen;
+ WFIFOSET(fd, plen);
- //`global_reg_value` (`type`, `account_id`, `char_id`, `str`, `value`)
- switch( type )
- {
- case 3: //char reg
- if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `str`, `value` FROM `%s` WHERE `type`=3 AND `char_id`='%d'", reg_db, char_id) )
- Sql_ShowDebug(sql_handle);
- break;
- case 2: //account reg
- if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `str`, `value` FROM `%s` WHERE `type`=2 AND `account_id`='%d'", reg_db, account_id) )
- Sql_ShowDebug(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");
- return 0;
- default:
- ShowError("inter_accreg_fromsql: Invalid type %d\n", type);
- return 0;
+ SQL->FreeResult(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);
+ 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);
+ 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");
+ return 0;
}
- for( i = 0; i < MAX_REG_NUM && SQL_SUCCESS == SQL->NextRow(sql_handle); ++i )
- {
- r = &reg->reg[i];
- // str
- SQL->GetData(sql_handle, 0, &data, &len);
- memcpy(r->str, data, min(len, sizeof(r->str)));
- // value
- SQL->GetData(sql_handle, 1, &data, &len);
- memcpy(r->value, data, min(len, sizeof(r->value)));
+
+ WFIFOHEAD(fd, 60000 + 300);
+ WFIFOW(fd, 0) = 0x3804;
+ /* 0x2 = length, set prior to being sent */
+ WFIFOL(fd, 4) = account_id;
+ WFIFOL(fd, 8) = char_id;
+ WFIFOB(fd, 12) = 0;/* var type (only set when all vars have been sent, regardless of type) */
+ WFIFOB(fd, 13) = 0;/* is int type */
+ WFIFOW(fd, 14) = 0;/* count */
+ plen = 16;
+
+ /**
+ * Vessel!
+ *
+ * int type
+ * { keyLength(B), key(<keyLength>), index(L), value(L) }
+ **/
+ while ( SQL_SUCCESS == SQL->NextRow(sql_handle) ) {
+
+ SQL->GetData(sql_handle, 0, &data, NULL);
+ len = strlen(data)+1;
+
+ WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 32 */
+ plen += 1;
+
+ safestrncpy((char*)WFIFOP(fd,plen), data, len);
+ plen += len;
+
+ SQL->GetData(sql_handle, 1, &data, NULL);
+
+ WFIFOL(fd, plen) = (unsigned int)atol(data);
+ plen += 4;
+
+ SQL->GetData(sql_handle, 2, &data, NULL);
+
+ WFIFOL(fd, plen) = atoi(data);
+ plen += 4;
+
+ WFIFOW(fd, 14) += 1;
+
+ if( plen > 60000 ) {
+ WFIFOW(fd, 2) = plen;
+ WFIFOSET(fd, plen);
+
+ /* prepare follow up */
+ WFIFOHEAD(fd, 60000 + 300);
+ WFIFOW(fd, 0) = 0x3804;
+ /* 0x2 = length, set prior to being sent */
+ WFIFOL(fd, 4) = account_id;
+ WFIFOL(fd, 8) = char_id;
+ WFIFOB(fd, 12) = 0;/* var type (only set when all vars have been sent, regardless of type) */
+ WFIFOB(fd, 13) = 0;/* is int type */
+ WFIFOW(fd, 14) = 0;/* count */
+ plen = 16;
+ }
}
- reg->reg_num = i;
+
+ /* mark as complete & go. */
+ WFIFOB(fd, 12) = type;
+ WFIFOW(fd, 2) = plen;
+ WFIFOSET(fd, plen);
+
SQL->FreeResult(sql_handle);
return 1;
}
-// Initialize
-int inter_accreg_sql_init(void)
-{
- CREATE(accreg_pt, struct accreg, 1);
- return 0;
-
-}
-
/*==========================================
* read config file
*------------------------------------------*/
@@ -704,9 +919,8 @@ static int inter_config_read(const char* cfgName)
return 1;
}
- while(fgets(line, sizeof(line), fp))
- {
- i = sscanf(line, "%[^:]: %[^\r\n]", w1, w2);
+ while (fgets(line, sizeof(line), fp)) {
+ i = sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2);
if(i != 2)
continue;
@@ -742,16 +956,18 @@ static int inter_config_read(const char* cfgName)
return 0;
}
-// Save interlog into sql
-int inter_log(char* fmt, ...)
-{
+/**
+ * Save interlog into sql (arglist version)
+ * @see inter_log
+ */
+int inter_vlog(char* fmt, va_list ap) {
char str[255];
char esc_str[sizeof(str)*2+1];// escaped str
- va_list ap;
+ va_list apcopy;
- va_start(ap,fmt);
- vsnprintf(str, sizeof(str), fmt, ap);
- va_end(ap);
+ va_copy(apcopy, 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) )
@@ -760,6 +976,23 @@ int inter_log(char* fmt, ...)
return 0;
}
+/**
+ * Save interlog into sql
+ * @param fmt Message's format string
+ * @param ... Additional (printf-like) arguments
+ * @return Always 0 // FIXME
+ */
+int inter_log(char* fmt, ...) {
+ va_list ap;
+ int ret;
+
+ va_start(ap,fmt);
+ ret = inter_vlog(fmt, ap);
+ va_end(ap);
+
+ return ret;
+}
+
// initialize
int inter_init_sql(const char *file)
{
@@ -790,12 +1023,11 @@ int inter_init_sql(const char *file)
inter_homunculus_sql_init();
inter_mercenary_sql_init();
inter_elemental_sql_init();
- inter_accreg_sql_init();
inter_mail_sql_init();
inter_auction_sql_init();
- geoip_readdb();
- msg_config_read("conf/messages.conf");
+ geoip_init();
+ msg_config_read("conf/messages.conf", false);
return 0;
}
@@ -814,8 +1046,7 @@ void inter_final(void)
inter_mail_sql_final();
inter_auction_sql_final();
- if (accreg_pt) aFree(accreg_pt);
-
+ geoip_final(true);
do_final_msg();
return;
}
@@ -829,7 +1060,7 @@ int inter_mapif_init(int fd)
//--------------------------------------------------------
// broadcast sending
-int mapif_broadcast(unsigned char *mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY, int sfd)
+int mapif_broadcast(unsigned char *mes, int len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY, int sfd)
{
unsigned char *buf = (unsigned char*)aMalloc((len)*sizeof(unsigned char));
@@ -878,36 +1109,15 @@ int mapif_wis_end(struct WisData *wd, int flag)
}
// Account registry transfer to map-server
-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));
-}
+//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));
+//}
// Send the requested account_reg
-int mapif_account_reg_reply(int fd,int account_id,int char_id, int type)
-{
- struct accreg *reg=accreg_pt;
- WFIFOHEAD(fd, 13 + 5000);
- inter_accreg_fromsql(account_id,char_id,reg,type);
-
- WFIFOW(fd,0)=0x3804;
- WFIFOL(fd,4)=account_id;
- WFIFOL(fd,8)=char_id;
- WFIFOB(fd,12)=type;
- if(reg->reg_num==0){
- WFIFOW(fd,2)=13;
- }else{
- int i,p;
- for (p=13,i = 0; i < reg->reg_num && p < 5000; i++) {
- p+= sprintf((char*)WFIFOP(fd,p), "%s", reg->reg[i].str)+1; //We add 1 to consider the '\0' in place.
- p+= sprintf((char*)WFIFOP(fd,p), "%s", reg->reg[i].value)+1;
- }
- WFIFOW(fd,2)=p;
- if (p>= 5000)
- ShowWarning("Too many acc regs for %d:%d, not all values were loaded.\n", account_id, char_id);
- }
- WFIFOSET(fd,WFIFOW(fd,2));
+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;
}
@@ -934,9 +1144,9 @@ int mapif_disconnectplayer(int fd, int account_id, int char_id, int reason)
*/
int check_ttl_wisdata_sub(DBKey key, DBData *data, va_list ap)
{
- unsigned long tick;
+ int64 tick;
struct WisData *wd = DB->data2ptr(data);
- tick = va_arg(ap, unsigned long);
+ tick = va_arg(ap, int64);
if (DIFF_TICK(tick, wd->tick) > WISDATA_TTL && wis_delnum < WISDELLIST_MAX)
wis_dellist[wis_delnum++] = wd->id;
@@ -946,7 +1156,7 @@ int check_ttl_wisdata_sub(DBKey key, DBData *data, va_list ap)
int check_ttl_wisdata(void)
{
- unsigned long tick = iTimer->gettick();
+ int64 tick = timer->gettick();
int i;
do {
@@ -956,7 +1166,7 @@ int check_ttl_wisdata(void)
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 wisper, 1: target character is not loged 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);
@@ -990,7 +1200,7 @@ int mapif_parse_WisRequest(int fd)
if (RFIFOW(fd,2)-52 >= sizeof(wd->msg)) {
ShowWarning("inter: Wis message size too long.\n");
return 0;
- } else if (RFIFOW(fd,2)-52 <= 0) { // normaly, impossible, but who knows...
+ } else if (RFIFOW(fd,2)-52 <= 0) { // normally, impossible, but who knows...
ShowError("inter: Wis message doesn't exist.\n");
return 0;
}
@@ -1007,7 +1217,7 @@ int mapif_parse_WisRequest(int fd)
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 wisper, 1: target character is not loged in?, 2: ignored by target
+ 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);
}
else
@@ -1022,7 +1232,7 @@ int mapif_parse_WisRequest(int fd)
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 wisper, 1: target character is not loged in?, 2: ignored by target
+ 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);
}
else
@@ -1039,7 +1249,7 @@ int mapif_parse_WisRequest(int fd)
memcpy(wd->src, RFIFOP(fd, 4), NAME_LENGTH);
memcpy(wd->dst, RFIFOP(fd,28), NAME_LENGTH);
memcpy(wd->msg, RFIFOP(fd,52), wd->len);
- wd->tick = iTimer->gettick();
+ wd->tick = timer->gettick();
idb_put(wis_db, wd->id, wd);
mapif_wis_message(wd);
}
@@ -1063,7 +1273,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 wisper, 1: target character is not loged 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);
}
@@ -1085,34 +1295,50 @@ int mapif_parse_WisToGM(int fd)
// Save account_reg into sql (type=2)
int mapif_parse_Registry(int fd)
{
- int j,p,len, max;
- struct accreg *reg=accreg_pt;
-
- memset(accreg_pt,0,sizeof(struct accreg));
- switch (RFIFOB(fd, 12)) {
- case 3: //Character registry
- max = GLOBAL_REG_NUM;
- break;
- case 2: //Account Registry
- max = ACCOUNT_REG_NUM;
- break;
- case 1: //Account2 registry, must be sent over to login server.
- return save_accreg2(RFIFOP(fd,4), RFIFOW(fd,2)-4);
- default:
- return 1;
- }
- for(j=0,p=13;j<max && p<RFIFOW(fd,2);j++){
- sscanf((char*)RFIFOP(fd,p), "%31c%n",reg->reg[j].str,&len);
- reg->reg[j].str[len]='\0';
- p +=len+1; //+1 to skip the '\0' between strings.
- sscanf((char*)RFIFOP(fd,p), "%255c%n",reg->reg[j].value,&len);
- reg->reg[j].value[len]='\0';
- p +=len+1;
- }
- reg->reg_num=j;
+ int account_id = RFIFOL(fd, 4), char_id = RFIFOL(fd, 8), count = RFIFOW(fd, 12);
+
+ if( count ) {
+ int cursor = 14, i;
+ char key[32], sval[254];
+ unsigned int index;
+
+ 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));
+ cursor += RFIFOB(fd, cursor) + 1;
+
+ index = RFIFOL(fd, cursor);
+ cursor += 4;
+
+ switch (RFIFOB(fd, cursor++)) {
+ /* int */
+ case 0:
+ 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);
+ 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);
+ break;
+ case 3:
+ inter_savereg(account_id,char_id,key,index,0,true);
+ break;
+
+ default:
+ ShowError("mapif_parse_Registry: unknown type %d\n",RFIFOB(fd, cursor - 1));
+ return 1;
+ }
- inter_accreg_tosql(RFIFOL(fd,4),RFIFOL(fd,8),reg, RFIFOB(fd,12));
- mapif_account_reg(fd,RFIFOP(fd,0)); // Send updated accounts to other map servers.
+ }
+
+ global_accreg_to_login_send();
+ }
return 0;
}
@@ -1151,8 +1377,8 @@ int mapif_parse_NameChangeRequest(int fd)
type = RFIFOB(fd,10);
name = (char*)RFIFOP(fd,11);
- // Check Authorised letters/symbols in the name
- if (char_name_option == 1) { // only letters/symbols in char_name_letters are authorised
+ // Check Authorized letters/symbols in the name
+ 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);
@@ -1239,23 +1465,4 @@ int inter_parse_frommap(int fd)
return 1;
}
-uint64 inter_chk_lastuid(int8 flag, uint64 value){
- static uint64 last_updt_uid = 0;
- static int8 update = 0;
- if(flag)
- {
- if(last_updt_uid < value){
- last_updt_uid = value;
- update = 1;
- }
-
- return 0;
- }else if(update)
- {
- update = 0;
- return last_updt_uid;
- }
- return 0;
-}
-
diff --git a/src/char/inter.h b/src/char/inter.h
index f6663813a..d7d7c3c2b 100644
--- a/src/char/inter.h
+++ b/src/char/inter.h
@@ -2,12 +2,14 @@
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams
-#ifndef _INTER_SQL_H_
-#define _INTER_SQL_H_
+#ifndef CHAR_INTER_H
+#define CHAR_INTER_H
-struct accreg;
-#include "../common/sql.h"
#include "char.h"
+#include "../common/cbasetypes.h"
+#include "../common/sql.h"
+
+struct accreg;
int inter_init_sql(const char *file);
void inter_final(void);
@@ -15,8 +17,10 @@ int inter_parse_frommap(int fd);
int inter_mapif_init(int fd);
int mapif_send_gmaccounts(void);
int mapif_disconnectplayer(int fd, int account_id, int char_id, int reason);
+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);
-int inter_log(char *fmt,...);
+int inter_log(char *fmt, ...) __attribute__((format(printf, 1, 2)));
+int inter_vlog(char *fmt, va_list ap);
#define inter_cfgName "conf/inter-server.conf"
@@ -27,18 +31,4 @@ extern Sql* lsql_handle;
int inter_accreg_tosql(int account_id, int char_id, struct accreg *reg, int type);
-uint64 inter_chk_lastuid(int8 flag, uint64 value);
-#ifdef NSI_UNIQUE_ID
- #define updateLastUid(val_) inter_chk_lastuid(1, val_)
- #define dbUpdateUid(handler_)\
- { \
- uint64 unique_id_ = inter_chk_lastuid(0, 0); \
- if (unique_id_ && SQL_ERROR == SQL->Query(handler_, "UPDATE `%s` SET `value`='%"PRIu64"' WHERE `varname`='unique_id'", interreg_db, unique_id_)) \
- Sql_ShowDebug(handler_);\
- }
-#else
- #define dbUpdateUid(handler_)
- #define updateLastUid(val_)
-#endif
-
-#endif /* _INTER_SQL_H_ */
+#endif /* CHAR_INTER_H */
diff --git a/src/char/pincode.c b/src/char/pincode.c
index 2603df2d8..18ad0ffc8 100644
--- a/src/char/pincode.c
+++ b/src/char/pincode.c
@@ -1,16 +1,20 @@
// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
// See the LICENSE file
+// Portions Copyright (c) Athena Dev Teams
+#define HERCULES_CORE
+
+#include "pincode.h"
+
+#include <stdlib.h>
+
+#include "char.h"
#include "../common/cbasetypes.h"
#include "../common/mmo.h"
#include "../common/random.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
#include "../common/strlib.h"
-#include "char.h"
-#include "pincode.h"
-
-#include <stdlib.h>
int enabled = PINCODE_OK;
int changetime = 0;
@@ -29,7 +33,7 @@ void pincode_handle ( int fd, struct char_session_data* sd ) {
}
if( strlen(sd->pincode) == 4 ){
- if( *pincode->changetime && time(NULL) > (sd->pincode_change+*pincode->changetime) ){ // User hasnt changed his PIN code for a long time
+ if( *pincode->changetime && time(NULL) > (sd->pincode_change+*pincode->changetime) ){ // User hasn't changed his PIN code for a long time
pincode->sendstate( fd, sd, PINCODE_EXPIRED );
} else { // Ask user for his PIN code
pincode->sendstate( fd, sd, PINCODE_ASK );
diff --git a/src/char/pincode.h b/src/char/pincode.h
index 358f21ff7..1ed05095e 100644
--- a/src/char/pincode.h
+++ b/src/char/pincode.h
@@ -1,8 +1,9 @@
// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
// See the LICENSE file
+// Portions Copyright (c) Athena Dev Teams
-#ifndef _PINCODE_H_
-#define _PINCODE_H_
+#ifndef CHAR_PINCODE_H
+#define CHAR_PINCODE_H
#include "char.h"
@@ -39,4 +40,4 @@ struct pincode_interface *pincode;
void pincode_defaults(void);
-#endif /* _PINCODE_H_ */
+#endif /* CHAR_PINCODE_H */