Cleaned up character saving (#1911)
* Fixes #1910. * Changed chrif_save option to readable constant values. * Added new Inventory and Cart options so that normal character save calls aren't flooded with requests to save Inventory and Cart data. * Cleaned up storage and premium storage saving functions being unused.
This commit is contained in:
@@ -808,7 +808,7 @@ ACMD_FUNC(save)
|
||||
if (sd->status.pet_id > 0 && sd->pd)
|
||||
intif_save_petdata(sd->status.account_id, &sd->pd->pet);
|
||||
|
||||
chrif_save(sd,0);
|
||||
chrif_save(sd, CSAVE_NORMAL);
|
||||
|
||||
clif_displaymessage(fd, msg_txt(sd,6)); // Your save point has been changed.
|
||||
|
||||
@@ -5968,7 +5968,7 @@ ACMD_FUNC(autotrade) {
|
||||
channel_pcquit(sd,0xF); //leave all chan
|
||||
clif_authfail_fd(sd->fd, 15);
|
||||
|
||||
chrif_save(sd,3);
|
||||
chrif_save(sd, CSAVE_AUTOTRADE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -472,8 +472,8 @@ void buyingstore_trade(struct map_session_data* sd, uint32 account_id, unsigned
|
||||
}
|
||||
|
||||
if( save_settings&CHARSAVE_BANK ) {
|
||||
chrif_save(sd, 0);
|
||||
chrif_save(pl_sd, 0);
|
||||
chrif_save(sd, CSAVE_NORMAL);
|
||||
chrif_save(pl_sd, CSAVE_NORMAL);
|
||||
}
|
||||
|
||||
// check whether or not there is still something to buy
|
||||
@@ -626,7 +626,7 @@ void buyingstore_reopen( struct map_session_data* sd ){
|
||||
}
|
||||
|
||||
// Immediate save
|
||||
chrif_save(sd, 3);
|
||||
chrif_save(sd, CSAVE_AUTOTRADE);
|
||||
|
||||
ShowInfo("Buyingstore loaded for '"CL_WHITE"%s"CL_RESET"' with '"CL_WHITE"%d"CL_RESET"' items at "CL_WHITE"%s (%d,%d)"CL_RESET"\n",
|
||||
sd->status.name, count, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y);
|
||||
|
||||
@@ -276,14 +276,19 @@ int chrif_isconnected(void) {
|
||||
return (char_fd > 0 && session[char_fd] != NULL && chrif_state == 2);
|
||||
}
|
||||
|
||||
/*==========================================
|
||||
/**
|
||||
* Saves character data.
|
||||
* Flag = 1: Character is quitting
|
||||
* Flag = 2: Character is changing map-servers
|
||||
* Flag = 3: Character used @autotrade
|
||||
*------------------------------------------*/
|
||||
int chrif_save(struct map_session_data *sd, int flag) {
|
||||
* @param sd: Player data
|
||||
* @param flag: Save flag types:
|
||||
* CSAVE_QUIT: Character is quitting
|
||||
* CSAVE_CHANGE_MAPSERV: Character is changing map-servers
|
||||
* CSAVE_AUTOTRADE: Character used @autotrade
|
||||
* CSAVE_INVENTORY: Character changed inventory data
|
||||
* CSAVE_CART: Character changed cart data
|
||||
*/
|
||||
int chrif_save(struct map_session_data *sd, enum e_chrif_save_opt flag) {
|
||||
uint16 mmo_charstatus_len = 0;
|
||||
|
||||
nullpo_retr(-1, sd);
|
||||
|
||||
pc_makesavestatus(sd);
|
||||
@@ -293,24 +298,26 @@ int chrif_save(struct map_session_data *sd, int flag) {
|
||||
chrif_save_scdata(sd);
|
||||
chrif_skillcooldown_save(sd);
|
||||
}
|
||||
if ( flag != 3 && !chrif_auth_logout(sd,flag == 1 ? ST_LOGOUT : ST_MAPCHANGE) )
|
||||
if ( !(flag&CSAVE_AUTOTRADE) && !chrif_auth_logout(sd, (flag&CSAVE_QUIT) ? ST_LOGOUT : ST_MAPCHANGE) )
|
||||
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_bsdata_save(sd, (flag && (flag != 3)));
|
||||
chrif_bsdata_save(sd, (flag && !(flag&CSAVE_AUTOTRADE)));
|
||||
|
||||
if (&sd->storage && sd->storage.dirty)
|
||||
intif_storage_save(sd,&sd->storage);
|
||||
intif_storage_save(sd,&sd->inventory);
|
||||
intif_storage_save(sd,&sd->cart);
|
||||
storage_storagesave(sd);
|
||||
if (flag&CSAVE_INVENTORY)
|
||||
intif_storage_save(sd,&sd->inventory);
|
||||
if (flag&CSAVE_CART)
|
||||
intif_storage_save(sd,&sd->cart);
|
||||
|
||||
//For data sync
|
||||
if (sd->state.storage_flag == 2)
|
||||
storage_guild_storagesave(sd->status.account_id, sd->status.guild_id, flag);
|
||||
if (&sd->premiumStorage && sd->premiumStorage.dirty)
|
||||
intif_storage_save(sd, &sd->premiumStorage);
|
||||
storage_premiumStorage_save(sd);
|
||||
|
||||
if (flag)
|
||||
sd->state.storage_flag = 0; //Force close it.
|
||||
@@ -325,7 +332,7 @@ int chrif_save(struct map_session_data *sd, int flag) {
|
||||
WFIFOW(char_fd,2) = mmo_charstatus_len;
|
||||
WFIFOL(char_fd,4) = sd->status.account_id;
|
||||
WFIFOL(char_fd,8) = sd->status.char_id;
|
||||
WFIFOB(char_fd,12) = (flag==1)?1:0; //Flag to tell char-server this character is quitting.
|
||||
WFIFOB(char_fd,12) = (flag&CSAVE_QUIT) ? 1 : 0; //Flag to tell char-server this character is quitting.
|
||||
|
||||
// If the user is on a instance map, we have to fake his current position
|
||||
if( map[sd->bl.m].instance_id ){
|
||||
@@ -532,7 +539,7 @@ static int chrif_reconnect(DBKey key, DBData *data, va_list ap) {
|
||||
break;
|
||||
case ST_LOGOUT:
|
||||
//Re-send final save
|
||||
chrif_save(node->sd, 1);
|
||||
chrif_save(node->sd, CSAVE_QUIT|CSAVE_INVENTORY|CSAVE_CART);
|
||||
break;
|
||||
case ST_MAPCHANGE: { //Re-send map-change request.
|
||||
struct map_session_data *sd = node->sd;
|
||||
@@ -770,7 +777,7 @@ int auth_db_cleanup_sub(DBKey key, DBData *data, va_list ap) {
|
||||
case ST_LOGOUT:
|
||||
//Re-save attempt (->sd should never be null here).
|
||||
node->node_created = gettick(); //Refresh tick (avoid char-server load if connection is really bad)
|
||||
chrif_save(node->sd, 1);
|
||||
chrif_save(node->sd, CSAVE_QUIT|CSAVE_INVENTORY|CSAVE_CART);
|
||||
break;
|
||||
default:
|
||||
//Clear data. any connected players should have timed out by now.
|
||||
|
||||
@@ -9,6 +9,16 @@
|
||||
#include <time.h>
|
||||
|
||||
enum sd_state { ST_LOGIN, ST_LOGOUT, ST_MAPCHANGE };
|
||||
|
||||
enum e_chrif_save_opt {
|
||||
CSAVE_NORMAL = 0x0, /// Normal
|
||||
CSAVE_QUIT, /// Character quitting
|
||||
CSAVE_CHANGE_MAPSERV, /// Character changing map server
|
||||
CSAVE_AUTOTRADE, /// Character entering autotrade state
|
||||
CSAVE_INVENTORY, /// Inventory data changed
|
||||
CSAVE_CART, /// Cart data changed
|
||||
};
|
||||
|
||||
struct auth_node {
|
||||
uint32 account_id, char_id;
|
||||
int login_id1, login_id2, sex, fd;
|
||||
@@ -43,7 +53,7 @@ int chrif_skillcooldown_request(uint32 account_id, uint32 char_id);
|
||||
int chrif_skillcooldown_save(struct map_session_data *sd);
|
||||
int chrif_skillcooldown_load(int fd);
|
||||
|
||||
int chrif_save(struct map_session_data* sd, int flag);
|
||||
int chrif_save(struct map_session_data* sd, enum e_chrif_save_opt flag);
|
||||
int chrif_charselectreq(struct map_session_data* sd, uint32 s_ip);
|
||||
int chrif_changemapserver(struct map_session_data* sd, uint32 ip, uint16 port);
|
||||
|
||||
|
||||
@@ -2382,7 +2382,7 @@ static void intif_parse_Mail_send(int fd)
|
||||
{
|
||||
clif_Mail_send(sd->fd, false);
|
||||
if( save_settings&CHARSAVE_MAIL )
|
||||
chrif_save(sd, 0);
|
||||
chrif_save(sd, CSAVE_INVENTORY);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2500,7 +2500,7 @@ static void intif_parse_Auction_register(int fd)
|
||||
{
|
||||
clif_Auction_message(sd->fd, 1); // Confirmation Packet ??
|
||||
if( save_settings&CHARSAVE_AUCTION )
|
||||
chrif_save(sd,0);
|
||||
chrif_save(sd, CSAVE_INVENTORY);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -2115,7 +2115,7 @@ int map_quit(struct map_session_data *sd) {
|
||||
pc_makesavestatus(sd);
|
||||
pc_clean_skilltree(sd);
|
||||
pc_crimson_marker_clear(sd);
|
||||
chrif_save(sd,1);
|
||||
chrif_save(sd, CSAVE_QUIT|CSAVE_INVENTORY|CSAVE_CART);
|
||||
unit_free_pc(sd);
|
||||
return 0;
|
||||
}
|
||||
@@ -4470,7 +4470,7 @@ void do_final(void)
|
||||
|
||||
static int map_abort_sub(struct map_session_data* sd, va_list ap)
|
||||
{
|
||||
chrif_save(sd,1);
|
||||
chrif_save(sd, CSAVE_QUIT|CSAVE_INVENTORY|CSAVE_CART);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
10
src/map/pc.c
10
src/map/pc.c
@@ -5431,7 +5431,7 @@ enum e_setpos pc_setpos(struct map_session_data* sd, unsigned short mapindex, in
|
||||
sd->bl.x=x;
|
||||
sd->bl.y=y;
|
||||
pc_clean_skilltree(sd);
|
||||
chrif_save(sd,2);
|
||||
chrif_save(sd, CSAVE_CHANGE_MAPSERV|CSAVE_INVENTORY|CSAVE_CART);
|
||||
chrif_changemapserver(sd, ip, (short)port);
|
||||
|
||||
//Free session data from this map server [Kevin]
|
||||
@@ -8546,7 +8546,7 @@ bool pc_jobchange(struct map_session_data *sd,int job, char upper)
|
||||
pc_equiplookall(sd);
|
||||
pc_show_questinfo(sd);
|
||||
|
||||
chrif_save(sd, 0);
|
||||
chrif_save(sd, CSAVE_NORMAL);
|
||||
//if you were previously famous, not anymore.
|
||||
if (fame_flag)
|
||||
chrif_buildfamelist();
|
||||
@@ -10291,7 +10291,7 @@ static int pc_autosave(int tid, unsigned int tick, int id, intptr_t data)
|
||||
save_flag = 2;
|
||||
if (pc_isvip(sd)) // Check if we're still VIP
|
||||
chrif_req_login_operation(1, sd->status.name, CHRIF_OP_LOGIN_VIP, 0, 1, 0);
|
||||
chrif_save(sd,0);
|
||||
chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART);
|
||||
break;
|
||||
}
|
||||
mapit_free(iter);
|
||||
@@ -11589,7 +11589,7 @@ enum e_BANKING_DEPOSIT_ACK pc_bank_deposit(struct map_session_data *sd, int mone
|
||||
sd->bank_vault += money;
|
||||
pc_setreg2(sd, BANK_VAULT_VAR, sd->bank_vault);
|
||||
if( save_settings&CHARSAVE_BANK )
|
||||
chrif_save(sd,0);
|
||||
chrif_save(sd, CSAVE_NORMAL);
|
||||
return BDA_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -11617,7 +11617,7 @@ enum e_BANKING_WITHDRAW_ACK pc_bank_withdraw(struct map_session_data *sd, int mo
|
||||
sd->bank_vault -= money;
|
||||
pc_setreg2(sd, BANK_VAULT_VAR, sd->bank_vault);
|
||||
if( save_settings&CHARSAVE_BANK )
|
||||
chrif_save(sd,0);
|
||||
chrif_save(sd, CSAVE_NORMAL);
|
||||
return BWA_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -516,7 +516,7 @@ int pet_birth_process(struct map_session_data *sd, struct s_pet *pet)
|
||||
intif_save_petdata(sd->status.account_id,pet);
|
||||
|
||||
if (save_settings&CHARSAVE_PET)
|
||||
chrif_save(sd,0); //is it REALLY Needed to save the char for hatching a pet? [Skotlex]
|
||||
chrif_save(sd, CSAVE_INVENTORY); //is it REALLY Needed to save the char for hatching a pet? [Skotlex]
|
||||
|
||||
if(sd->bl.prev != NULL) {
|
||||
if(map_addblock(&sd->pd->bl))
|
||||
|
||||
@@ -107,7 +107,7 @@ int quest_add(TBL_PC *sd, int quest_id)
|
||||
clif_quest_update_objective(sd, &sd->quest_log[n], 0);
|
||||
|
||||
if( save_settings&CHARSAVE_QUEST )
|
||||
chrif_save(sd,0);
|
||||
chrif_save(sd, CSAVE_NORMAL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -160,7 +160,7 @@ int quest_change(TBL_PC *sd, int qid1, int qid2)
|
||||
clif_quest_update_objective(sd, &sd->quest_log[i], 0);
|
||||
|
||||
if( save_settings&CHARSAVE_QUEST )
|
||||
chrif_save(sd,0);
|
||||
chrif_save(sd, CSAVE_NORMAL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -199,7 +199,7 @@ int quest_delete(TBL_PC *sd, int quest_id)
|
||||
clif_quest_delete(sd, quest_id);
|
||||
|
||||
if( save_settings&CHARSAVE_QUEST )
|
||||
chrif_save(sd,0);
|
||||
chrif_save(sd, CSAVE_NORMAL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -327,7 +327,7 @@ int quest_update_status(TBL_PC *sd, int quest_id, enum quest_state status)
|
||||
clif_quest_delete(sd, quest_id);
|
||||
|
||||
if( save_settings&CHARSAVE_QUEST )
|
||||
chrif_save(sd,0);
|
||||
chrif_save(sd, CSAVE_NORMAL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -485,12 +485,12 @@ void storage_storageclose(struct map_session_data *sd)
|
||||
return;
|
||||
|
||||
if (sd->storage.dirty) {
|
||||
intif_storage_save(sd, &sd->storage);
|
||||
storage_storagesave(sd);
|
||||
if (sd->state.storage_flag == 1) {
|
||||
sd->state.storage_flag = 0;
|
||||
clif_storageclose(sd);
|
||||
}
|
||||
} else
|
||||
} else
|
||||
storage_storagesaved(sd);
|
||||
}
|
||||
|
||||
@@ -509,7 +509,7 @@ void storage_storage_quit(struct map_session_data* sd, int flag)
|
||||
if (!&sd->storage)
|
||||
return;
|
||||
|
||||
intif_storage_save(sd, &sd->storage);
|
||||
storage_storagesave(sd);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -944,7 +944,7 @@ void storage_guild_storageclose(struct map_session_data* sd)
|
||||
clif_storageclose(sd);
|
||||
if (stor->status) {
|
||||
if (save_settings&CHARSAVE_STORAGE)
|
||||
chrif_save(sd, 0); //This one also saves the storage. [Skotlex]
|
||||
chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART); //This one also saves the storage. [Skotlex]
|
||||
else
|
||||
storage_guild_storagesave(sd->status.account_id, sd->status.guild_id,0);
|
||||
|
||||
@@ -970,7 +970,7 @@ void storage_guild_storage_quit(struct map_session_data* sd, int flag)
|
||||
clif_storageclose(sd);
|
||||
|
||||
if (save_settings&CHARSAVE_STORAGE)
|
||||
chrif_save(sd,0);
|
||||
chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART);
|
||||
|
||||
sd->state.storage_flag = 0;
|
||||
stor->status = false;
|
||||
@@ -979,7 +979,7 @@ void storage_guild_storage_quit(struct map_session_data* sd, int flag)
|
||||
|
||||
if (stor->status) {
|
||||
if (save_settings&CHARSAVE_STORAGE)
|
||||
chrif_save(sd,0);
|
||||
chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART);
|
||||
else
|
||||
storage_guild_storagesave(sd->status.account_id,sd->status.guild_id,1);
|
||||
}
|
||||
@@ -1082,7 +1082,7 @@ void storage_premiumStorage_close(struct map_session_data *sd) {
|
||||
return;
|
||||
|
||||
if (sd->premiumStorage.dirty) {
|
||||
intif_storage_save(sd, &sd->premiumStorage);
|
||||
storage_premiumStorage_save(sd);
|
||||
if (sd->state.storage_flag == 3) {
|
||||
sd->state.storage_flag = 0;
|
||||
clif_storageclose(sd);
|
||||
@@ -1103,5 +1103,5 @@ void storage_premiumStorage_quit(struct map_session_data *sd) {
|
||||
if (!&sd->premiumStorage)
|
||||
return;
|
||||
|
||||
intif_storage_save(sd, &sd->premiumStorage);
|
||||
storage_premiumStorage_save(sd);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ void storage_storageadd(struct map_session_data *sd, struct s_storage *stor, int
|
||||
void storage_storageget(struct map_session_data *sd, struct s_storage *stor, int index, int amount);
|
||||
void storage_storageaddfromcart(struct map_session_data *sd, struct s_storage *stor, int index, int amount);
|
||||
void storage_storagegettocart(struct map_session_data *sd, struct s_storage *stor, int index, int amount);
|
||||
void storage_storagesave(struct map_session_data *sd);
|
||||
void storage_storageclose(struct map_session_data *sd);
|
||||
void storage_sortitem(struct item* items, unsigned int size);
|
||||
void do_init_storage(void);
|
||||
|
||||
@@ -644,7 +644,7 @@ void trade_tradecommit(struct map_session_data *sd)
|
||||
|
||||
// save both player to avoid crash: they always have no advantage/disadvantage between the 2 players
|
||||
if (save_settings&CHARSAVE_TRADE) {
|
||||
chrif_save(sd,0);
|
||||
chrif_save(tsd,0);
|
||||
chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART);
|
||||
chrif_save(tsd, CSAVE_INVENTORY|CSAVE_CART);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,8 +247,8 @@ void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const ui
|
||||
|
||||
//Always save BOTH: customer (buyer) and vender
|
||||
if( save_settings&CHARSAVE_VENDING ) {
|
||||
chrif_save(sd,0);
|
||||
chrif_save(vsd,0);
|
||||
chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART);
|
||||
chrif_save(vsd, CSAVE_INVENTORY|CSAVE_CART);
|
||||
}
|
||||
|
||||
//check for @AUTOTRADE users [durf]
|
||||
@@ -301,7 +301,7 @@ int8 vending_openvending(struct map_session_data* sd, const char* message, const
|
||||
}
|
||||
|
||||
if (save_settings&CHARSAVE_VENDING) // Avoid invalid data from saving
|
||||
chrif_save(sd, 0);
|
||||
chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART);
|
||||
|
||||
// filter out invalid items
|
||||
i = 0;
|
||||
@@ -507,7 +507,7 @@ void vending_reopen( struct map_session_data* sd )
|
||||
}
|
||||
|
||||
// Immediate save
|
||||
chrif_save(sd, 3);
|
||||
chrif_save(sd, CSAVE_AUTOTRADE);
|
||||
|
||||
ShowInfo("Vending loaded for '"CL_WHITE"%s"CL_RESET"' with '"CL_WHITE"%d"CL_RESET"' items at "CL_WHITE"%s (%d,%d)"CL_RESET"\n",
|
||||
sd->status.name, count, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y);
|
||||
|
||||
Reference in New Issue
Block a user