summaryrefslogtreecommitdiff
path: root/src/map/chrif.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/chrif.c')
-rw-r--r--src/map/chrif.c412
1 files changed, 227 insertions, 185 deletions
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 01af69fbf..301c8ec66 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -88,7 +88,7 @@ struct chrif_interface chrif_s;
//2b27: Incoming, chrif_authfail -> 'client authentication failed'
//This define should spare writing the check in every function. [Skotlex]
-#define chrif_check(a) { if(!chrif->isconnected()) return a; }
+#define chrif_check(a) do { if(!chrif->isconnected()) return a; } while(0)
/// Resets all the data.
void chrif_reset(void) {
@@ -119,18 +119,23 @@ struct auth_node* chrif_auth_check(int account_id, int char_id, enum sd_state st
bool chrif_auth_delete(int account_id, int char_id, enum sd_state state) {
struct auth_node *node;
-
+
if ( (node = chrif->auth_check(account_id, char_id, state) ) ) {
int fd = node->sd ? node->sd->fd : node->fd;
if ( session[fd] && session[fd]->session_data == node->sd )
session[fd]->session_data = NULL;
- if ( node->char_dat )
- aFree(node->char_dat);
-
- if ( node->sd )
+ if ( node->sd ) {
+
+ if( node->sd->var_db )
+ node->sd->var_db->destroy(node->sd->var_db,script->reg_destroy);
+
+ if( node->sd->array_db )
+ node->sd->array_db->destroy(node->sd->array_db,script->array_free_db);
+
aFree(node->sd);
+ }
ers_free(chrif->auth_db_ers, node);
idb_remove(chrif->auth_db,account_id);
@@ -211,20 +216,19 @@ void chrif_checkdefaultlogin(void) {
}
// sets char-server's ip address
-int chrif_setip(const char* ip) {
+bool chrif_setip(const char* ip) {
char ip_str[16];
if ( !( chrif->ip = host2ip(ip) ) ) {
ShowWarning("Failed to Resolve Char Server Address! (%s)\n", ip);
-
- return 0;
+ return false;
}
safestrncpy(chrif->ip_str, ip, sizeof(chrif->ip_str));
ShowInfo("Char Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(chrif->ip, ip_str));
- return 1;
+ return true;
}
// sets char-server's port number
@@ -242,8 +246,8 @@ int chrif_isconnected(void) {
* Flag = 1: Character is quitting
* Flag = 2: Character is changing map-servers
*------------------------------------------*/
-int chrif_save(struct map_session_data *sd, int flag) {
- nullpo_retr(-1, sd);
+bool chrif_save(struct map_session_data *sd, int flag) {
+ nullpo_ret(sd);
pc->makesavestatus(sd);
@@ -255,7 +259,7 @@ int chrif_save(struct map_session_data *sd, int flag) {
ShowError("chrif_save: Failed to set up player %d:%d for proper quitting!\n", sd->status.account_id, sd->status.char_id);
}
- chrif_check(-1); //Character is saved on reconnect.
+ chrif_check(false); //Character is saved on reconnect.
//For data sync
if (sd->state.storage_flag == 2)
@@ -265,12 +269,8 @@ int chrif_save(struct map_session_data *sd, int flag) {
sd->state.storage_flag = 0; //Force close it.
//Saving of registry values.
- if (sd->state.reg_dirty&4)
- intif->saveregistry(sd, 3); //Save char regs
- if (sd->state.reg_dirty&2)
- intif->saveregistry(sd, 2); //Save account regs
- if (sd->state.reg_dirty&1)
- intif->saveregistry(sd, 1); //Save account2 regs
+ if (sd->vars_dirty)
+ intif->saveregistry(sd);
WFIFOHEAD(chrif->fd, sizeof(sd->status) + 13);
WFIFOW(chrif->fd,0) = 0x2b01;
@@ -292,11 +292,11 @@ int chrif_save(struct map_session_data *sd, int flag) {
if( sd->save_quest )
intif->quest_save(sd);
- return 0;
+ return true;
}
// connects to char-server (plaintext)
-int chrif_connect(int fd) {
+void chrif_connect(int fd) {
ShowStatus("Logging in to char server...\n", chrif->fd);
WFIFOHEAD(fd,60);
WFIFOW(fd,0) = 0x2af8;
@@ -306,12 +306,10 @@ int chrif_connect(int fd) {
WFIFOL(fd,54) = htonl(clif->map_ip);
WFIFOW(fd,58) = htons(clif->map_port);
WFIFOSET(fd,60);
-
- return 0;
}
// sends maps to char-server
-int chrif_sendmap(int fd) {
+void chrif_sendmap(int fd) {
int i;
ShowStatus("Sending maps to char server...\n");
@@ -323,12 +321,10 @@ int chrif_sendmap(int fd) {
WFIFOW(fd,4+i*4) = map_id2index(i);
WFIFOW(fd,2) = 4 + i * 4;
WFIFOSET(fd,WFIFOW(fd,2));
-
- return 0;
}
// receive maps from some other map-server (relayed via char-server)
-int chrif_recvmap(int fd) {
+void chrif_recvmap(int fd) {
int i, j;
uint32 ip = ntohl(RFIFOL(fd,4));
uint16 port = ntohs(RFIFOW(fd,8));
@@ -341,12 +337,10 @@ int chrif_recvmap(int fd) {
ShowStatus("Received maps from %d.%d.%d.%d:%d (%d maps)\n", CONVIP(ip), port, j);
chrif->other_mapserver_count++;
-
- return 0;
}
// remove specified maps (used when some other map-server disconnects)
-int chrif_removemap(int fd) {
+void chrif_removemap(int fd) {
int i, j;
uint32 ip = RFIFOL(fd,4);
uint16 port = RFIFOW(fd,8);
@@ -358,8 +352,6 @@ int chrif_removemap(int fd) {
if(battle_config.etc_log)
ShowStatus("remove map of server %d.%d.%d.%d:%d (%d maps)\n", CONVIP(ip), port, j);
-
- return 0;
}
// received after a character has been "final saved" on the char-server
@@ -369,15 +361,15 @@ void chrif_save_ack(int fd) {
}
// request to move a character between mapservers
-int chrif_changemapserver(struct map_session_data* sd, uint32 ip, uint16 port) {
- nullpo_retr(-1, sd);
+bool chrif_changemapserver(struct map_session_data* sd, uint32 ip, uint16 port) {
+ nullpo_ret(sd);
if (chrif->other_mapserver_count < 1) {//No other map servers are online!
clif->authfail_fd(sd->fd, 0);
- return -1;
+ return false;
}
- chrif_check(-1);
+ chrif_check(false);
WFIFOHEAD(chrif->fd,35);
WFIFOW(chrif->fd, 0) = 0x2b05;
@@ -395,19 +387,19 @@ int chrif_changemapserver(struct map_session_data* sd, uint32 ip, uint16 port) {
WFIFOL(chrif->fd,35) = sd->group_id;
WFIFOSET(chrif->fd,39);
- return 0;
+ return true;
}
/// map-server change request acknowledgement (positive or negative)
/// R 2b06 <account_id>.L <login_id1>.L <login_id2>.L <char_id>.L <map_index>.W <x>.W <y>.W <ip>.L <port>.W
-int chrif_changemapserverack(int account_id, int login_id1, int login_id2, int char_id, short map_index, short x, short y, uint32 ip, uint16 port) {
+bool chrif_changemapserverack(int account_id, int login_id1, int login_id2, int char_id, short map_index, short x, short y, uint32 ip, uint16 port) {
struct auth_node *node;
if ( !( node = chrif->auth_check(account_id, char_id, ST_MAPCHANGE) ) )
- return -1;
+ return false;
if ( !login_id1 ) {
- ShowError("map server change failed.\n");
+ ShowError("chrif_changemapserverack: map server change failed.\n");
clif->authfail_fd(node->fd, 0);
} else
clif->changemapserver(node->sd, map_index, x, y, ntohl(ip), ntohs(port));
@@ -415,13 +407,13 @@ int chrif_changemapserverack(int account_id, int login_id1, int login_id2, int c
//Player has been saved already, remove him from memory. [Skotlex]
chrif->auth_delete(account_id, char_id, ST_MAPCHANGE);
- return 0;
+ return (!login_id1)?false:true; // Is this the best approach here?
}
/*==========================================
*
*------------------------------------------*/
-int chrif_connectack(int fd) {
+void chrif_connectack(int fd) {
static bool char_init_done = false;
if (RFIFOB(fd,2)) {
@@ -442,10 +434,8 @@ int chrif_connectack(int fd) {
guild->castle_map_init();
}
- socket_datasync(fd, true);
+ sockt->datasync(fd, true);
chrif->skillid2idx(fd);
-
- return 0;
}
/**
@@ -456,9 +446,9 @@ int chrif_reconnect(DBKey key, DBData *data, va_list ap) {
switch (node->state) {
case ST_LOGIN:
- if ( node->sd && node->char_dat == NULL ) {//Since there is no way to request the char auth, make it fail.
+ if ( node->sd ) {//Since there is no way to request the char auth, make it fail.
pc->authfail(node->sd);
- chrif->char_offline(node->sd);
+ chrif_char_offline(node->sd);
chrif->auth_delete(node->account_id, node->char_id, ST_LOGIN);
}
break;
@@ -475,7 +465,6 @@ int chrif_reconnect(DBKey key, DBData *data, va_list ap) {
chrif->changemapserver(sd, ip, port);
else //too much lag/timeout is the closest explanation for this error.
clif->authfail_fd(sd->fd, 3);
-
break;
}
}
@@ -486,6 +475,7 @@ int chrif_reconnect(DBKey key, DBData *data, va_list ap) {
/// Called when all the connection steps are completed.
void chrif_on_ready(void) {
+ static bool once = false;
ShowStatus("Map Server is now online.\n");
chrif->state = 2;
@@ -503,13 +493,20 @@ void chrif_on_ready(void) {
//Re-save any guild castles that were modified in the disconnection time.
guild->castle_reconnect(-1, 0, 0);
+
+ if( !once ) {
+#ifdef AUTOTRADE_PERSISTENCY
+ pc->autotrade_load();
+#endif
+ once = true;
+ }
}
/*==========================================
*
*------------------------------------------*/
-int chrif_sendmapack(int fd) {
+void chrif_sendmapack(int fd) {
if (RFIFOB(fd,2)) {
ShowFatalError("chrif : send map list to char server failed %d\n", RFIFOB(fd,2));
@@ -519,17 +516,15 @@ int chrif_sendmapack(int fd) {
memcpy(map->wisp_server_name, RFIFOP(fd,3), NAME_LENGTH);
chrif->on_ready();
-
- return 0;
}
/*==========================================
* Request sc_data from charserver [Skotlex]
*------------------------------------------*/
-int chrif_scdata_request(int account_id, int char_id) {
+bool chrif_scdata_request(int account_id, int char_id) {
#ifdef ENABLE_SC_SAVING
- chrif_check(-1);
+ chrif_check(false);
WFIFOHEAD(chrif->fd,10);
WFIFOW(chrif->fd,0) = 0x2afc;
@@ -538,28 +533,29 @@ int chrif_scdata_request(int account_id, int char_id) {
WFIFOSET(chrif->fd,10);
#endif
- return 0;
+ return true;
}
/*==========================================
* Request auth confirmation
*------------------------------------------*/
-void chrif_authreq(struct map_session_data *sd) {
+void chrif_authreq(struct map_session_data *sd, bool hstandalone) {
struct auth_node *node= chrif->search(sd->bl.id);
-
+
if( node != NULL || !chrif->isconnected() ) {
set_eof(sd->fd);
return;
}
- WFIFOHEAD(chrif->fd,19);
+ WFIFOHEAD(chrif->fd,20);
WFIFOW(chrif->fd,0) = 0x2b26;
WFIFOL(chrif->fd,2) = sd->status.account_id;
WFIFOL(chrif->fd,6) = sd->status.char_id;
WFIFOL(chrif->fd,10) = sd->login_id1;
WFIFOB(chrif->fd,14) = sd->status.sex;
WFIFOL(chrif->fd,15) = htonl(session[sd->fd]->client_addr);
- WFIFOSET(chrif->fd,19);
+ WFIFOB(chrif->fd,19) = hstandalone ? 1 : 0;
+ WFIFOSET(chrif->fd,20);
chrif->sd_to_auth(sd, ST_LOGIN);
}
@@ -594,7 +590,7 @@ void chrif_authok(int fd) {
//Causes problems if the currently connected player tries to quit or this data belongs to an already connected player which is trying to re-auth.
if ( ( sd = map->id2sd(account_id) ) != NULL )
return;
-
+
if ( ( node = chrif->search(account_id) ) == NULL )
return; // should not happen
@@ -613,7 +609,6 @@ void chrif_authok(int fd) {
sd = node->sd;
if( runflag == MAPSERVER_ST_RUNNING &&
- node->char_dat == NULL &&
node->account_id == account_id &&
node->char_id == char_id &&
node->login_id1 == login_id1 )
@@ -624,7 +619,7 @@ void chrif_authok(int fd) {
pc->authfail(sd);
}
- chrif->char_offline(sd); //Set him offline, the char server likely has it set as online already.
+ chrif_char_offline(sd); //Set him offline, the char server likely has it set as online already.
chrif->auth_delete(account_id, char_id, ST_LOGIN);
}
@@ -682,22 +677,22 @@ int auth_db_cleanup_sub(DBKey key, DBData *data, va_list ap) {
return 0;
}
-int auth_db_cleanup(int tid, unsigned int tick, int id, intptr_t data) {
+int auth_db_cleanup(int tid, int64 tick, int id, intptr_t data) {
chrif_check(0);
chrif->auth_db->foreach(chrif->auth_db, chrif->auth_db_cleanup_sub);
return 0;
}
/*==========================================
- *
+ * Request char selection
*------------------------------------------*/
-int chrif_charselectreq(struct map_session_data* sd, uint32 s_ip) {
- nullpo_retr(-1, sd);
+bool chrif_charselectreq(struct map_session_data* sd, uint32 s_ip) {
+ nullpo_ret(sd);
- if( !sd || !sd->bl.id || !sd->login_id1 )
- return -1;
+ if( !sd->bl.id || !sd->login_id1 )
+ return false;
- chrif_check(-1);
+ chrif_check(false);
WFIFOHEAD(chrif->fd,18);
WFIFOW(chrif->fd, 0) = 0x2b02;
@@ -707,36 +702,36 @@ int chrif_charselectreq(struct map_session_data* sd, uint32 s_ip) {
WFIFOL(chrif->fd,14) = htonl(s_ip);
WFIFOSET(chrif->fd,18);
- return 0;
+ return true;
}
/*==========================================
* Search Char trough id on char serv
*------------------------------------------*/
-int chrif_searchcharid(int char_id) {
+bool chrif_searchcharid(int char_id) {
if( !char_id )
- return -1;
+ return false;
- chrif_check(-1);
+ chrif_check(false);
WFIFOHEAD(chrif->fd,6);
WFIFOW(chrif->fd,0) = 0x2b08;
WFIFOL(chrif->fd,2) = char_id;
WFIFOSET(chrif->fd,6);
- return 0;
+ return true;
}
/*==========================================
* Change Email
*------------------------------------------*/
-int chrif_changeemail(int id, const char *actual_email, const char *new_email) {
+bool chrif_changeemail(int id, const char *actual_email, const char *new_email) {
if (battle_config.etc_log)
ShowInfo("chrif_changeemail: account: %d, actual_email: '%s', new_email: '%s'.\n", id, actual_email, new_email);
- chrif_check(-1);
+ chrif_check(false);
WFIFOHEAD(chrif->fd,86);
WFIFOW(chrif->fd,0) = 0x2b0c;
@@ -745,18 +740,18 @@ int chrif_changeemail(int id, const char *actual_email, const char *new_email) {
memcpy(WFIFOP(chrif->fd,46), new_email, 40);
WFIFOSET(chrif->fd,86);
- return 0;
+ return true;
}
/*==========================================
* S 2b0e <accid>.l <name>.24B <type>.w { <year>.w <month>.w <day>.w <hour>.w <minute>.w <second>.w }
* Send an account modification request to the login server (via char server).
* type of operation:
- * 1: block, 2: ban, 3: unblock, 4: unban, 5: changesex (use next function for 5)
+ * 1: block, 2: ban, 3: unblock, 4: unban, 5: changesex (use next function for 5), 6: charban
*------------------------------------------*/
-int chrif_char_ask_name(int acc, const char* character_name, unsigned short operation_type, int year, int month, int day, int hour, int minute, int second) {
+bool chrif_char_ask_name(int acc, const char* character_name, unsigned short operation_type, int year, int month, int day, int hour, int minute, int second) {
- chrif_check(-1);
+ chrif_check(false);
WFIFOHEAD(chrif->fd,44);
WFIFOW(chrif->fd,0) = 0x2b0e;
@@ -764,7 +759,7 @@ int chrif_char_ask_name(int acc, const char* character_name, unsigned short oper
safestrncpy((char*)WFIFOP(chrif->fd,6), character_name, NAME_LENGTH);
WFIFOW(chrif->fd,30) = operation_type;
- if ( operation_type == 2 ) {
+ if ( operation_type == 2 || operation_type == 6 ) {
WFIFOW(chrif->fd,32) = year;
WFIFOW(chrif->fd,34) = month;
WFIFOW(chrif->fd,36) = day;
@@ -774,11 +769,11 @@ int chrif_char_ask_name(int acc, const char* character_name, unsigned short oper
}
WFIFOSET(chrif->fd,44);
- return 0;
+ return true;
}
-int chrif_changesex(struct map_session_data *sd) {
- chrif_check(-1);
+bool chrif_changesex(struct map_session_data *sd) {
+ chrif_check(false);
WFIFOHEAD(chrif->fd,44);
WFIFOW(chrif->fd,0) = 0x2b0e;
@@ -793,39 +788,44 @@ int chrif_changesex(struct map_session_data *sd) {
clif->authfail_fd(sd->fd, 15);
else
map->quit(sd);
- return 0;
+ return true;
}
/*==========================================
* R 2b0f <accid>.l <name>.24B <type>.w <answer>.w
* Processing a reply to chrif->char_ask_name() (request to modify an account).
* type of operation:
- * 1: block, 2: ban, 3: unblock, 4: unban, 5: changesex
+ * 1: block, 2: ban, 3: unblock, 4: unban, 5: changesex, 6: charban, 7: charunban
* type of answer:
* 0: login-server request done
* 1: player not found
* 2: gm level too low
* 3: login-server offline
*------------------------------------------*/
-void chrif_char_ask_name_answer(int acc, const char* player_name, uint16 type, uint16 answer) {
+bool chrif_char_ask_name_answer(int acc, const char* player_name, uint16 type, uint16 answer) {
struct map_session_data* sd;
char action[25];
char output[256];
+ bool charsrv = ( type == 6 || type == 7 ) ? true : false;
sd = map->id2sd(acc);
if( acc < 0 || sd == NULL ) {
ShowError("chrif_char_ask_name_answer failed - player not online.\n");
- return;
+ return false;
}
+ /* re-use previous msg_txt */
+ if( type == 6 ) type = 2;
+ if( type == 7 ) type = 4;
+
if( type > 0 && type <= 5 )
snprintf(action,25,"%s",msg_txt(427+type)); //block|ban|unblock|unban|change the sex of
else
snprintf(action,25,"???");
switch( answer ) {
- case 0 : sprintf(output, msg_txt(424), action, NAME_LENGTH, player_name); break;
+ case 0 : sprintf(output, msg_txt(charsrv?434:424), action, NAME_LENGTH, player_name); break;
case 1 : sprintf(output, msg_txt(425), NAME_LENGTH, player_name); break;
case 2 : sprintf(output, msg_txt(426), action, NAME_LENGTH, player_name); break;
case 3 : sprintf(output, msg_txt(427), action, NAME_LENGTH, player_name); break;
@@ -833,12 +833,13 @@ void chrif_char_ask_name_answer(int acc, const char* player_name, uint16 type, u
}
clif->message(sd->fd, output);
+ return true;
}
/*==========================================
* Request char server to change sex of char (modified by Yor)
*------------------------------------------*/
-int chrif_changedsex(int fd) {
+void chrif_changedsex(int fd) {
int acc, sex;
struct map_session_data *sd;
@@ -851,7 +852,7 @@ int chrif_changedsex(int fd) {
sd = map->id2sd(acc);
if ( sd ) { //Normally there should not be a char logged on right now!
if ( sd->status.sex == sex )
- return 0; //Do nothing? Likely safe.
+ return; //Do nothing? Likely safe.
sd->status.sex = !sd->status.sex;
// reset skill of some job
@@ -890,13 +891,12 @@ int chrif_changedsex(int fd) {
set_eof(sd->fd); // forced to disconnect for the change
map->quit(sd); // Remove leftovers (e.g. autotrading) [Paradox924X]
}
- return 0;
}
/*==========================================
* Request Char Server to Divorce Players
*------------------------------------------*/
-int chrif_divorce(int partner_id1, int partner_id2) {
- chrif_check(-1);
+bool chrif_divorce(int partner_id1, int partner_id2) {
+ chrif_check(false);
WFIFOHEAD(chrif->fd,10);
WFIFOW(chrif->fd,0) = 0x2b11;
@@ -904,19 +904,19 @@ int chrif_divorce(int partner_id1, int partner_id2) {
WFIFOL(chrif->fd,6) = partner_id2;
WFIFOSET(chrif->fd,10);
- return 0;
+ return true;
}
/*==========================================
* Divorce players
* only used if 'partner_id' is offline
*------------------------------------------*/
-int chrif_divorceack(int char_id, int partner_id) {
+bool chrif_divorceack(int char_id, int partner_id) {
struct map_session_data* sd;
int i;
if( !char_id || !partner_id )
- return 0;
+ return false;
if( ( sd = map->charid2sd(char_id) ) != NULL && sd->status.partner_id == partner_id ) {
sd->status.partner_id = 0;
@@ -932,12 +932,12 @@ int chrif_divorceack(int char_id, int partner_id) {
pc->delitem(sd, i, 1, 0, 0, LOG_TYPE_OTHER);
}
- return 0;
+ return true;
}
/*==========================================
* Removes Baby from parents
*------------------------------------------*/
-int chrif_deadopt(int father_id, int mother_id, int child_id) {
+void chrif_deadopt(int father_id, int mother_id, int child_id) {
struct map_session_data* sd;
int idx = skill->get_index(WE_CALLBABY);
@@ -957,30 +957,29 @@ int chrif_deadopt(int father_id, int mother_id, int child_id) {
clif->deleteskill(sd,WE_CALLBABY);
}
- return 0;
}
/*==========================================
- * Disconnection of a player (account has been banned of has a status, from login-server) by [Yor]
+ * Disconnection of a player (account or char has been banned of has a status, from login or char server) by [Yor]
*------------------------------------------*/
-int chrif_accountban(int fd) {
- int acc;
+void chrif_idbanned(int fd) {
+ int id;
struct map_session_data *sd;
- acc = RFIFOL(fd,2);
+ id = RFIFOL(fd,2);
if ( battle_config.etc_log )
- ShowNotice("chrif_accountban %d.\n", acc);
+ ShowNotice("chrif_idbanned %d.\n", id);
- sd = map->id2sd(acc);
+ sd = ( RFIFOB(fd,6) == 2 ) ? map->charid2sd(id) : map->id2sd(id);
- if ( acc < 0 || sd == NULL ) {
- ShowError("chrif_accountban failed - player not online.\n");
- return 0;
+ if ( id < 0 || sd == NULL ) {
+ /* player not online or unknown id, either way no error is necessary (since if you try to ban a offline char it still works) */
+ return;
}
sd->login_id1++; // change identify, because if player come back in char within the 5 seconds, he can change its characters
- if (RFIFOB(fd,6) == 0) { // 0: change of statut, 1: ban
+ if (RFIFOB(fd,6) == 0) { // 0: change of statut
int ret_status = RFIFOL(fd,7); // status or final date of a banishment
if(0<ret_status && ret_status<=9)
clif->message(sd->fd, msg_txt(411+ret_status));
@@ -988,18 +987,24 @@ int chrif_accountban(int fd) {
clif->message(sd->fd, msg_txt(421));
else
clif->message(sd->fd, msg_txt(420)); //"Your account has not more authorised."
- } else if (RFIFOB(fd,6) == 1) { // 0: change of statut, 1: ban
+ } else if (RFIFOB(fd,6) == 1) { // 1: ban
time_t timestamp;
char tmpstr[2048];
timestamp = (time_t)RFIFOL(fd,7); // status or final date of a banishment
strcpy(tmpstr, msg_txt(423)); //"Your account has been banished until "
strftime(tmpstr + strlen(tmpstr), 24, "%d-%m-%Y %H:%M:%S", localtime(&timestamp));
clif->message(sd->fd, tmpstr);
+ } else if (RFIFOB(fd,6) == 2) { // 2: change of status for character
+ time_t timestamp;
+ char tmpstr[2048];
+ timestamp = (time_t)RFIFOL(fd,7); // status or final date of a banishment
+ strcpy(tmpstr, msg_txt(433)); //"This character has been banned until "
+ strftime(tmpstr + strlen(tmpstr), 24, "%d-%m-%Y %H:%M:%S", localtime(&timestamp));
+ clif->message(sd->fd, tmpstr);
}
set_eof(sd->fd); // forced to disconnect for the change
map->quit(sd); // Remove leftovers (e.g. autotrading) [Paradox924X]
- return 0;
}
//Disconnect the player out of the game, simple packet
@@ -1062,17 +1067,17 @@ int chrif_updatefamelist(struct map_session_data* sd) {
return 0;
}
-int chrif_buildfamelist(void) {
- chrif_check(-1);
+bool chrif_buildfamelist(void) {
+ chrif_check(false);
WFIFOHEAD(chrif->fd,2);
WFIFOW(chrif->fd,0) = 0x2b1a;
WFIFOSET(chrif->fd,2);
- return 0;
+ return true;
}
-int chrif_recvfamelist(int fd) {
+void chrif_recvfamelist(int fd) {
int num, size;
int total = 0, len = 8;
@@ -1108,8 +1113,6 @@ int chrif_recvfamelist(int fd) {
total += num;
ShowInfo("Received Fame List of '"CL_WHITE"%d"CL_RESET"' characters.\n", total);
-
- return 0;
}
/// fame ranking update confirmation
@@ -1135,16 +1138,16 @@ int chrif_updatefamelist_ack(int fd) {
return 1;
}
-int chrif_save_scdata(struct map_session_data *sd) { //parses the sc_data of the player and sends it to the char-server for saving. [Skotlex]
+bool chrif_save_scdata(struct map_session_data *sd) { //parses the sc_data of the player and sends it to the char-server for saving. [Skotlex]
#ifdef ENABLE_SC_SAVING
int i, count=0;
- unsigned int tick;
+ int64 tick;
struct status_change_data data;
struct status_change *sc = &sd->sc;
const struct TimerData *td;
- chrif_check(-1);
+ chrif_check(false);
tick = timer->gettick();
WFIFOHEAD(chrif->fd, 14 + SC_MAX*sizeof(struct status_change_data));
@@ -1159,7 +1162,7 @@ int chrif_save_scdata(struct map_session_data *sd) { //parses the sc_data of the
td = timer->get(sc->data[i]->timer);
if (td == NULL || td->func != status->change_timer || DIFF_TICK(td->tick,tick) < 0)
continue;
- data.tick = DIFF_TICK(td->tick,tick); //Duration that is left before ending.
+ data.tick = DIFF_TICK32(td->tick,tick); //Duration that is left before ending.
} else
data.tick = -1; //Infinite duration
data.type = i;
@@ -1173,18 +1176,18 @@ int chrif_save_scdata(struct map_session_data *sd) { //parses the sc_data of the
}
if (count == 0)
- return 0; //Nothing to save.
+ return true; //Nothing to save. | Everything was as successful as if there was something to save.
WFIFOW(chrif->fd,12) = count;
WFIFOW(chrif->fd,2) = 14 +count*sizeof(struct status_change_data); //Total packet size
WFIFOSET(chrif->fd,WFIFOW(chrif->fd,2));
#endif
- return 0;
+ return true;
}
//Retrieve and load sc_data for a player. [Skotlex]
-int chrif_load_scdata(int fd) {
+bool chrif_load_scdata(int fd) {
#ifdef ENABLE_SC_SAVING
struct map_session_data *sd;
@@ -1198,31 +1201,33 @@ int chrif_load_scdata(int fd) {
if ( !sd ) {
ShowError("chrif_load_scdata: Player of AID %d not found!\n", aid);
- return -1;
+ return false;
}
if ( sd->status.char_id != cid ) {
ShowError("chrif_load_scdata: Receiving data for account %d, char id does not matches (%d != %d)!\n", aid, sd->status.char_id, cid);
- return -1;
+ return false;
}
count = RFIFOW(fd,12); //sc_count
for (i = 0; i < count; i++) {
data = (struct status_change_data*)RFIFOP(fd,14 + i*sizeof(struct status_change_data));
- status->change_start(&sd->bl, (sc_type)data->type, 10000, data->val1, data->val2, data->val3, data->val4, data->tick, 15);
+ status->change_start(NULL, &sd->bl, (sc_type)data->type, 10000, data->val1, data->val2, data->val3, data->val4, data->tick, 15);
}
+
+ pc->scdata_received(sd);
#endif
- return 0;
+ return true;
}
/*==========================================
* Send rates to char server [Wizputer]
* S 2b16 <base rate>.L <job rate>.L <drop rate>.L
*------------------------------------------*/
-int chrif_ragsrvinfo(int base_rate, int job_rate, int drop_rate) {
- chrif_check(-1);
+bool chrif_ragsrvinfo(int base_rate, int job_rate, int drop_rate) {
+ chrif_check(false);
WFIFOHEAD(chrif->fd,14);
WFIFOW(chrif->fd,0) = 0x2b16;
@@ -1231,26 +1236,15 @@ int chrif_ragsrvinfo(int base_rate, int job_rate, int drop_rate) {
WFIFOL(chrif->fd,10) = drop_rate;
WFIFOSET(chrif->fd,14);
- return 0;
+ return true;
}
/*=========================================
* Tell char-server charcter disconnected [Wizputer]
*-----------------------------------------*/
-int chrif_char_offline(struct map_session_data *sd) {
- chrif_check(-1);
-
- WFIFOHEAD(chrif->fd,10);
- WFIFOW(chrif->fd,0) = 0x2b17;
- WFIFOL(chrif->fd,2) = sd->status.char_id;
- WFIFOL(chrif->fd,6) = sd->status.account_id;
- WFIFOSET(chrif->fd,10);
-
- return 0;
-}
-int chrif_char_offline_nsd(int account_id, int char_id) {
- chrif_check(-1);
+bool chrif_char_offline_nsd(int account_id, int char_id) {
+ chrif_check(false);
WFIFOHEAD(chrif->fd,10);
WFIFOW(chrif->fd,0) = 0x2b17;
@@ -1258,41 +1252,40 @@ int chrif_char_offline_nsd(int account_id, int char_id) {
WFIFOL(chrif->fd,6) = account_id;
WFIFOSET(chrif->fd,10);
- return 0;
+ return true;
}
/*=========================================
* Tell char-server to reset all chars offline [Wizputer]
*-----------------------------------------*/
-int chrif_flush_fifo(void) {
- chrif_check(-1);
+bool chrif_flush(void) {
+ chrif_check(false);
set_nonblocking(chrif->fd, 0);
flush_fifos();
set_nonblocking(chrif->fd, 1);
- return 0;
+ return true;
}
/*=========================================
* Tell char-server to reset all chars offline [Wizputer]
*-----------------------------------------*/
-int chrif_char_reset_offline(void) {
- chrif_check(-1);
+bool chrif_char_reset_offline(void) {
+ chrif_check(false);
WFIFOHEAD(chrif->fd,2);
WFIFOW(chrif->fd,0) = 0x2b18;
WFIFOSET(chrif->fd,2);
- return 0;
+ return true;
}
/*=========================================
* Tell char-server charcter is online [Wizputer]
*-----------------------------------------*/
-
-int chrif_char_online(struct map_session_data *sd) {
- chrif_check(-1);
+bool chrif_char_online(struct map_session_data *sd) {
+ chrif_check(false);
WFIFOHEAD(chrif->fd,10);
WFIFOW(chrif->fd,0) = 0x2b19;
@@ -1300,10 +1293,9 @@ int chrif_char_online(struct map_session_data *sd) {
WFIFOL(chrif->fd,6) = sd->status.account_id;
WFIFOSET(chrif->fd,10);
- return 0;
+ return true;
}
-
/// Called when the connection to Char Server is disconnected.
void chrif_on_disconnect(void) {
if( chrif->connected != 1 )
@@ -1352,6 +1344,9 @@ void chrif_skillid2idx(int fd) {
if( fd == 0 ) fd = chrif->fd;
+ if( !session_isValid(fd) )
+ return;
+
WFIFOHEAD(fd,4 + (MAX_SKILL * 4));
WFIFOW(fd,0) = 0x2b0b;
for(i = 0; i < MAX_SKILL; i++) {
@@ -1384,7 +1379,7 @@ int chrif_parse(int fd) {
chrif->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 */
@@ -1435,11 +1430,11 @@ int chrif_parse(int fd) {
case 0x2b04: chrif->recvmap(fd); break;
case 0x2b06: chrif->changemapserverack(RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOL(fd,14), RFIFOW(fd,18), RFIFOW(fd,20), RFIFOW(fd,22), RFIFOL(fd,24), RFIFOW(fd,28)); break;
case 0x2b09: map->addnickdb(RFIFOL(fd,2), (char*)RFIFOP(fd,6)); break;
- case 0x2b0a: socket_datasync(fd, false); break;
+ case 0x2b0a: sockt->datasync(fd, false); break;
case 0x2b0d: chrif->changedsex(fd); break;
case 0x2b0f: chrif->char_ask_name_answer(RFIFOL(fd,2), (char*)RFIFOP(fd,6), RFIFOW(fd,30), RFIFOW(fd,32)); break;
case 0x2b12: chrif->divorceack(RFIFOL(fd,2), RFIFOL(fd,6)); break;
- case 0x2b14: chrif->accountban(fd); break;
+ case 0x2b14: chrif->idbanned(fd); break;
case 0x2b1b: chrif->recvfamelist(fd); break;
case 0x2b1d: chrif->load_scdata(fd); break;
case 0x2b1e: chrif->update_ip(fd); break;
@@ -1462,7 +1457,7 @@ int chrif_parse(int fd) {
return 0;
}
-int send_usercount_tochar(int tid, unsigned int tick, int id, intptr_t data) {
+int send_usercount_tochar(int tid, int64 tick, int id, intptr_t data) {
chrif_check(-1);
WFIFOHEAD(chrif->fd,4);
@@ -1476,12 +1471,12 @@ int send_usercount_tochar(int tid, unsigned int tick, int id, intptr_t data) {
* timerFunction
* Send to char the number of client connected to map
*------------------------------------------*/
-int send_users_tochar(void) {
+bool send_users_tochar(void) {
int users = 0, i = 0;
struct map_session_data* sd;
struct s_mapiterator* iter;
- chrif_check(-1);
+ chrif_check(false);
users = map->usercount();
@@ -1502,14 +1497,14 @@ int send_users_tochar(void) {
WFIFOW(chrif->fd,4) = users;
WFIFOSET(chrif->fd, 6+8*users);
- return 0;
+ return true;
}
/*==========================================
* timerFunction
- * Chk the connection to char server, (if it down)
+ * Check the connection to char server, (if it down)
*------------------------------------------*/
-int check_connect_char_server(int tid, unsigned int tick, int id, intptr_t data) {
+int check_connect_char_server(int tid, int64 tick, int id, intptr_t data) {
static int displayed = 0;
if ( chrif->fd <= 0 || session[chrif->fd] == NULL ) {
if ( !displayed ) {
@@ -1543,9 +1538,9 @@ int check_connect_char_server(int tid, unsigned int tick, int id, intptr_t data)
/*==========================================
* Asks char server to remove friend_id from the friend list of char_id
*------------------------------------------*/
-int chrif_removefriend(int char_id, int friend_id) {
+bool chrif_removefriend(int char_id, int friend_id) {
- chrif_check(-1);
+ chrif_check(false);
WFIFOHEAD(chrif->fd,10);
WFIFOW(chrif->fd,0) = 0x2b07;
@@ -1553,7 +1548,7 @@ int chrif_removefriend(int char_id, int friend_id) {
WFIFOL(chrif->fd,6) = friend_id;
WFIFOSET(chrif->fd,10);
- return 0;
+ return true;
}
void chrif_send_report(char* buf, int len) {
@@ -1573,26 +1568,74 @@ void chrif_send_report(char* buf, int len) {
}
/**
+ * Sends a single scdata for saving into char server, meant to ensure integrity of durationless conditions
+ **/
+void chrif_save_scdata_single(int account_id, int char_id, short type, struct status_change_entry *sce) {
+
+ if( !chrif->isconnected() )
+ return;
+
+ WFIFOHEAD(chrif->fd, 28);
+
+ WFIFOW(chrif->fd, 0) = 0x2740;
+ WFIFOL(chrif->fd, 2) = account_id;
+ WFIFOL(chrif->fd, 6) = char_id;
+ WFIFOW(chrif->fd, 10) = type;
+ WFIFOL(chrif->fd, 12) = sce->val1;
+ WFIFOL(chrif->fd, 16) = sce->val2;
+ WFIFOL(chrif->fd, 20) = sce->val3;
+ WFIFOL(chrif->fd, 24) = sce->val4;
+
+ WFIFOSET(chrif->fd, 28);
+
+}
+/**
+ * Sends a single scdata deletion request into char server, meant to ensure integrity of durationless conditions
+ **/
+void chrif_del_scdata_single(int account_id, int char_id, short type) {
+
+ if( !chrif->isconnected() ) {
+ ShowError("MAYDAY! failed to delete status %d from CID:%d/AID:%d\n",type,char_id,account_id);
+ return;
+ }
+
+
+ WFIFOHEAD(chrif->fd, 12);
+
+ WFIFOW(chrif->fd, 0) = 0x2741;
+ WFIFOL(chrif->fd, 2) = account_id;
+ WFIFOL(chrif->fd, 6) = char_id;
+ WFIFOW(chrif->fd, 10) = type;
+
+ WFIFOSET(chrif->fd, 12);
+
+}
+
+/** `
* @see DBApply
*/
int auth_db_final(DBKey key, DBData *data, va_list ap) {
struct auth_node *node = DB->data2ptr(data);
- if (node->char_dat)
- aFree(node->char_dat);
-
- if (node->sd)
+ if (node->sd) {
+
+ if( node->sd->var_db )
+ node->sd->var_db->destroy(node->sd->var_db,script->reg_destroy);
+
+ if( node->sd->array_db )
+ node->sd->array_db->destroy(node->sd->array_db,script->array_free_db);
+
aFree(node->sd);
-
+ }
ers_free(chrif->auth_db_ers, node);
-
+
return 0;
}
/*==========================================
* Destructor
*------------------------------------------*/
-int do_final_chrif(void) {
+void do_final_chrif(void) {
if( chrif->fd != -1 ) {
do_close(chrif->fd);
@@ -1602,15 +1645,15 @@ int do_final_chrif(void) {
chrif->auth_db->destroy(chrif->auth_db, chrif->auth_db_final);
ers_destroy(chrif->auth_db_ers);
-
- return 0;
}
/*==========================================
*
*------------------------------------------*/
-int do_init_chrif(void) {
-
+void do_init_chrif(bool minimal) {
+ if (minimal)
+ return;
+
chrif->auth_db = idb_alloc(DB_OPT_BASE);
chrif->auth_db_ers = ers_new(sizeof(struct auth_node),"chrif.c::auth_db_ers",ERS_OPT_NONE);
@@ -1626,8 +1669,6 @@ int do_init_chrif(void) {
// send the user count every 10 seconds, to hide the charserver's online counting problem
timer->add_interval(timer->gettick() + 1000, chrif->send_usercount_tochar, 0, 0, UPDATE_INTERVAL);
-
- return 0;
}
@@ -1698,7 +1739,6 @@ void chrif_defaults(void) {
chrif->buildfamelist = chrif_buildfamelist;
chrif->save_scdata = chrif_save_scdata;
chrif->ragsrvinfo = chrif_ragsrvinfo;
- chrif->char_offline = chrif_char_offline;
chrif->char_offline_nsd = chrif_char_offline_nsd;
chrif->char_reset_offline = chrif_char_reset_offline;
chrif->send_users_tochar = send_users_tochar;
@@ -1710,7 +1750,7 @@ void chrif_defaults(void) {
chrif->removefriend = chrif_removefriend;
chrif->send_report = chrif_send_report;
- chrif->flush_fifo = chrif_flush_fifo;
+ chrif->flush = chrif_flush;
chrif->skillid2idx = chrif_skillid2idx;
chrif->sd_to_auth = chrif_sd_to_auth;
@@ -1732,13 +1772,13 @@ void chrif_defaults(void) {
chrif->changemapserverack = chrif_changemapserverack;
chrif->changedsex = chrif_changedsex;
chrif->divorceack = chrif_divorceack;
- chrif->accountban = chrif_accountban;
+ chrif->idbanned = chrif_idbanned;
chrif->recvfamelist = chrif_recvfamelist;
chrif->load_scdata = chrif_load_scdata;
chrif->update_ip = chrif_update_ip;
chrif->disconnectplayer = chrif_disconnectplayer;
chrif->removemap = chrif_removemap;
- chrif->updatefamelist_ack = chrif->updatefamelist_ack;
+ chrif->updatefamelist_ack = chrif_updatefamelist_ack;
chrif->keepalive = chrif_keepalive;
chrif->keepalive_ack = chrif_keepalive_ack;
chrif->deadopt = chrif_deadopt;
@@ -1746,4 +1786,6 @@ void chrif_defaults(void) {
chrif->on_ready = chrif_on_ready;
chrif->on_disconnect = chrif_on_disconnect;
chrif->parse = chrif_parse;
+ chrif->save_scdata_single = chrif_save_scdata_single;
+ chrif->del_scdata_single = chrif_del_scdata_single;
}