summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorpanikon <panikon@zoho.com>2014-01-14 00:07:55 -0200
committerpanikon <panikon@zoho.com>2014-01-14 00:07:55 -0200
commit6860ff92acdb9a018e9085676299ef631ecea57c (patch)
tree3e255d196921bf8557e519d8a1dd1020d8a053b9 /src/map
parent9832e82b0e8dbda38bf4feb18e48cf5335e213ee (diff)
downloadhercules-6860ff92acdb9a018e9085676299ef631ecea57c.tar.gz
hercules-6860ff92acdb9a018e9085676299ef631ecea57c.tar.bz2
hercules-6860ff92acdb9a018e9085676299ef631ecea57c.tar.xz
hercules-6860ff92acdb9a018e9085676299ef631ecea57c.zip
Updated return values of some atcommands.
Altered many function types from int to bool(C99) and added meaningful return values. Altered many function types from int to void as they didn't have any meaningful return value. Replaced chrif_char_offline with a macro as this function did exactly the same as chrif_char_offline_nsd.
Diffstat (limited to 'src/map')
-rw-r--r--src/map/atcommand.c60
-rw-r--r--src/map/atcommand.h2
-rw-r--r--src/map/battle.c10
-rw-r--r--src/map/battle.h2
-rw-r--r--src/map/battleground.c37
-rw-r--r--src/map/battleground.h12
-rw-r--r--src/map/chat.c162
-rw-r--r--src/map/chat.h22
-rw-r--r--src/map/chrif.c252
-rw-r--r--src/map/chrif.h72
10 files changed, 315 insertions, 316 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index b2d486520..e5d14fc21 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -83,7 +83,7 @@ const char* atcommand_msg(int msg_number) {
/*==========================================
* Read Message Data
*------------------------------------------*/
-int msg_config_read(const char* cfgName)
+bool msg_config_read(const char* cfgName)
{
int msg_number;
char line[1024], w1[1024], w2[1024];
@@ -92,7 +92,7 @@ int msg_config_read(const char* cfgName)
if ((fp = fopen(cfgName, "r")) == NULL) {
ShowError("Messages file not found: %s\n", cfgName);
- return 1;
+ return false;
}
if ((--called) == 0)
@@ -123,7 +123,7 @@ int msg_config_read(const char* cfgName)
fclose(fp);
- return 0;
+ return true;
}
/*==========================================
@@ -3917,7 +3917,6 @@ ACMD(mapinfo) {
default: // normally impossible to arrive here
clif->message(fd, msg_txt(1118)); // Please enter at least one valid list number (usage: @mapinfo <0-3> <map>).
return false;
- break;
}
return true;
@@ -5339,7 +5338,7 @@ ACMD(skilltree) {
if( j == MAX_SKILL_TREE || pc->skill_tree[c][j].id == 0 )
{
clif->message(fd, msg_txt(1169)); // The player cannot use that skill.
- return true;
+ return false;
}
ent = &pc->skill_tree[c][j];
@@ -7215,7 +7214,7 @@ ACMD(version) {
* @mutearea by MouseJstr
*------------------------------------------*/
int atcommand_mutearea_sub(struct block_list *bl,va_list ap)
-{
+{ // As it is being used [ACMD(mutearea)] there's no need to be a bool, but if there's need to reuse it, it's better to be this way
int time, id;
struct map_session_data *pl_sd = (struct map_session_data *)bl;
@@ -7232,7 +7231,7 @@ int atcommand_mutearea_sub(struct block_list *bl,va_list ap)
else
status_change_end(&pl_sd->bl, SC_NOCHAT, INVALID_TIMER);
}
- return 0;
+ return 1;
}
ACMD(mutearea) {
@@ -7593,10 +7592,11 @@ ACMD(invite) {
unsigned int did = sd->duel_group;
struct map_session_data *target_sd = map->nick2sd((char *)message);
- if(did == 0) {
+ if(did == 0)
+ {
// "Duel: @invite without @duel."
clif->message(fd, msg_txt(350));
- return true;
+ return false;
}
if(duel->list[did].max_players_limit > 0 &&
@@ -7604,26 +7604,27 @@ ACMD(invite) {
// "Duel: Limit of players is reached."
clif->message(fd, msg_txt(351));
- return true;
+ return false;
}
if(target_sd == NULL) {
// "Duel: Player not found."
clif->message(fd, msg_txt(352));
- return true;
+ return false;
}
if(target_sd->duel_group > 0 || target_sd->duel_invite > 0) {
// "Duel: Player already in duel."
clif->message(fd, msg_txt(353));
- return true;
+ return false;
}
if(battle_config.duel_only_on_same_map && target_sd->bl.m != sd->bl.m)
{
+ // "Duel: You can't invite %s because he/she isn't on the same map."
sprintf(atcmd_output, msg_txt(364), message);
clif->message(fd, atcmd_output);
- return true;
+ return false;
}
duel->invite(did, sd, target_sd);
@@ -7643,7 +7644,7 @@ ACMD(duel) {
if(sd->duel_invite > 0) {
// "Duel: @duel without @reject."
clif->message(fd, msg_txt(355));
- return true;
+ return false;
}
if(!duel->checktime(sd)) {
@@ -7651,14 +7652,14 @@ ACMD(duel) {
// "Duel: You can take part in duel only one time per %d minutes."
sprintf(output, msg_txt(356), battle_config.duel_time_interval);
clif->message(fd, output);
- return true;
+ return false;
}
if( message[0] ) {
if(sscanf(message, "%d", &maxpl) >= 1) {
if(maxpl < 2 || maxpl > 65535) {
clif->message(fd, msg_txt(357)); // "Duel: Invalid value."
- return true;
+ return false;
}
duel->create(sd, maxpl);
} else {
@@ -7669,7 +7670,7 @@ ACMD(duel) {
if((newduel = duel->create(sd, 2)) != -1) {
if(target_sd->duel_group > 0 || target_sd->duel_invite > 0) {
clif->message(fd, msg_txt(353)); // "Duel: Player already in duel."
- return true;
+ return false;
}
duel->invite(newduel, sd, target_sd);
clif->message(fd, msg_txt(354)); // "Duel: Invitation has been sent."
@@ -7677,7 +7678,7 @@ ACMD(duel) {
} else {
// "Duel: Player not found."
clif->message(fd, msg_txt(352));
- return true;
+ return false;
}
}
} else
@@ -7691,7 +7692,7 @@ ACMD(leave) {
if(sd->duel_group <= 0) {
// "Duel: @leave without @duel."
clif->message(fd, msg_txt(358));
- return true;
+ return false;
}
duel->leave(sd->duel_group, sd);
@@ -7705,20 +7706,20 @@ ACMD(accept) {
// "Duel: You can take part in duel only one time per %d minutes."
sprintf(output, msg_txt(356), battle_config.duel_time_interval);
clif->message(fd, output);
- return true;
+ return false;
}
if(sd->duel_invite <= 0) {
// "Duel: @accept without invititation."
clif->message(fd, msg_txt(360));
- return true;
+ return false;
}
if( duel->list[sd->duel_invite].max_players_limit > 0
&& duel->list[sd->duel_invite].members_count >= duel->list[sd->duel_invite].max_players_limit ) {
// "Duel: Limit of players is reached."
clif->message(fd, msg_txt(351));
- return true;
+ return false;
}
duel->accept(sd->duel_invite, sd);
@@ -7731,7 +7732,7 @@ ACMD(reject) {
if(sd->duel_invite <= 0) {
// "Duel: @reject without invititation."
clif->message(fd, msg_txt(362));
- return true;
+ return false;
}
duel->reject(sd->duel_invite, sd);
@@ -7800,17 +7801,17 @@ ACMD(clone) {
if (!message || !*message) {
clif->message(sd->fd,msg_txt(1323)); // You must enter a player name or ID.
- return true;
+ return false;
}
if((pl_sd=map->nick2sd((char *)message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) {
clif->message(fd, msg_txt(3)); // Character not found.
- return true;
+ return false;
}
if(pc_get_group_level(pl_sd) > pc_get_group_level(sd)) {
clif->message(fd, msg_txt(126)); // Cannot clone a player of higher GM level than yourself.
- return true;
+ return false;
}
if (strcmpi(info->command, "clone") == 0)
@@ -7818,14 +7819,15 @@ ACMD(clone) {
else if (strcmpi(info->command, "slaveclone") == 0) {
flag = 2;
if(pc_isdead(sd)){
+ //"Unable to spawn slave clone."
clif->message(fd, msg_txt(129+flag*2));
- return true;
+ return false;
}
master = sd->bl.id;
if (battle_config.atc_slave_clone_limit
&& mob->countslave(&sd->bl) >= battle_config.atc_slave_clone_limit) {
clif->message(fd, msg_txt(127)); // You've reached your slave clones limit.
- return true;
+ return false;
}
}
@@ -7844,7 +7846,7 @@ ACMD(clone) {
return true;
}
clif->message(fd, msg_txt(129+flag*2)); // Unable to spawn evil clone. Unable to spawn clone. Unable to spawn slave clone.
- return true;
+ return false;
}
/*=====================================
diff --git a/src/map/atcommand.h b/src/map/atcommand.h
index ab48b2ca6..710499a43 100644
--- a/src/map/atcommand.h
+++ b/src/map/atcommand.h
@@ -86,7 +86,7 @@ struct atcommand_interface {
bool (*can_use2) (struct map_session_data *sd, const char *command, AtCommandType type);
void (*load_groups) (GroupSettings **groups, config_setting_t **commands_, size_t sz);
AtCommandInfo* (*exists) (const char* name);
- int (*msg_read) (const char* cfgName);
+ bool (*msg_read) (const char* cfgName);
void (*final_msg) (void);
/* atcommand binding */
struct atcmd_binding_data* (*get_bind_byname) (const char* name);
diff --git a/src/map/battle.c b/src/map/battle.c
index 1759bea05..fd31f5a1f 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -5747,21 +5747,21 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t
#undef GET_NORMAL_ATTACK
#undef GET_NORMAL_ATTACK2
-int battle_check_undead(int race,int element)
+bool battle_check_undead(int race,int element)
{
if(battle_config.undead_detect_type == 0) {
if(element == ELE_UNDEAD)
- return 1;
+ return true;
}
else if(battle_config.undead_detect_type == 1) {
if(race == RC_UNDEAD)
- return 1;
+ return true;
}
else {
if(element == ELE_UNDEAD || race == RC_UNDEAD)
- return 1;
+ return true;
}
- return 0;
+ return false;
}
//Returns the upmost level master starting with the given object
diff --git a/src/map/battle.h b/src/map/battle.h
index ed5e40988..98f2e37e8 100644
--- a/src/map/battle.h
+++ b/src/map/battle.h
@@ -559,7 +559,7 @@ struct battle_interface {
/* the current skill being processed/casted by this unit */
int (*get_current_skill) (struct block_list *bl);
/* is either this race or element enough to be considered undead? */
- int (*check_undead) (int race,int element);
+ bool (*check_undead) (int race,int element);
/* check if src and target are part of flag (e.g. enemies or allies) */
int (*check_target) (struct block_list *src, struct block_list *target,int flag);
/* is src and bl within range? */
diff --git a/src/map/battleground.c b/src/map/battleground.c
index 96d39aa45..ab44b0953 100644
--- a/src/map/battleground.c
+++ b/src/map/battleground.c
@@ -42,12 +42,12 @@ struct map_session_data* bg_getavailablesd(struct battleground_data *bgd) {
}
/// Deletes BG Team from db
-int bg_team_delete(int bg_id) {
+bool bg_team_delete(int bg_id) {
int i;
struct map_session_data *sd;
struct battleground_data *bgd = bg->team_search(bg_id);
- if( bgd == NULL ) return 0;
+ if( bgd == NULL ) return false;
for( i = 0; i < MAX_BG_MEMBERS; i++ ) {
if( (sd = bgd->members[i].sd) == NULL )
continue;
@@ -56,35 +56,34 @@ int bg_team_delete(int bg_id) {
sd->bg_id = 0;
}
idb_remove(bg->team_db, bg_id);
- return 1;
+ return true;
}
/// Warps a Team
-int bg_team_warp(int bg_id, unsigned short map_index, short x, short y) {
+bool bg_team_warp(int bg_id, unsigned short map_index, short x, short y) {
int i;
struct battleground_data *bgd = bg->team_search(bg_id);
- if( bgd == NULL ) return 0;
+ if( bgd == NULL ) return false;
for( i = 0; i < MAX_BG_MEMBERS; i++ )
if( bgd->members[i].sd != NULL ) pc->setpos(bgd->members[i].sd, map_index, x, y, CLR_TELEPORT);
- return 1;
+ return true;
}
-int bg_send_dot_remove(struct map_session_data *sd) {
+void bg_send_dot_remove(struct map_session_data *sd) {
if( sd && sd->bg_id )
clif->bg_xy_remove(sd);
- return 0;
}
/// Player joins team
-int bg_team_join(int bg_id, struct map_session_data *sd) {
+bool bg_team_join(int bg_id, struct map_session_data *sd) {
int i;
struct battleground_data *bgd = bg->team_search(bg_id);
struct map_session_data *pl_sd;
- if( bgd == NULL || sd == NULL || sd->bg_id ) return 0;
+ if( bgd == NULL || sd == NULL || sd->bg_id ) return false;
ARR_FIND(0, MAX_BG_MEMBERS, i, bgd->members[i].sd == NULL);
- if( i == MAX_BG_MEMBERS ) return 0; // No free slots
+ if( i == MAX_BG_MEMBERS ) return false; // No free slots
sd->bg_id = bg_id;
bgd->members[i].sd = sd;
@@ -110,7 +109,7 @@ int bg_team_join(int bg_id, struct map_session_data *sd) {
clif->bg_hp(sd);
clif->bg_xy(sd);
- return 1;
+ return true;
}
/// Single Player leaves team
@@ -156,16 +155,16 @@ int bg_team_leave(struct map_session_data *sd, int flag) {
}
/// Respawn after killed
-int bg_member_respawn(struct map_session_data *sd) {
+bool bg_member_respawn(struct map_session_data *sd) {
struct battleground_data *bgd;
if( sd == NULL || !pc_isdead(sd) || !sd->bg_id || (bgd = bg->team_search(sd->bg_id)) == NULL )
- return 0;
+ return false;
if( bgd->mapindex == 0 )
- return 0; // Respawn not handled by Core
+ return false; // Respawn not handled by Core
pc->setpos(sd, bgd->mapindex, bgd->x, bgd->y, CLR_OUTSIGHT);
status->revive(&sd->bl, 1, 100);
- return 1; // Warped
+ return true; // Warped
}
int bg_create(unsigned short map_index, short rx, short ry, const char *ev, const char *dev) {
@@ -219,14 +218,14 @@ int bg_team_get_id(struct block_list *bl) {
return 0;
}
-int bg_send_message(struct map_session_data *sd, const char *mes, int len) {
+bool bg_send_message(struct map_session_data *sd, const char *mes, int len) {
struct battleground_data *bgd;
nullpo_ret(sd);
if( sd->bg_id == 0 || (bgd = bg->team_search(sd->bg_id)) == NULL )
- return 0;
+ return false; // Couldn't send message
clif->bg_message(bgd, sd->bl.id, sd->status.name, mes, len);
- return 0;
+ return true;
}
/**
diff --git a/src/map/battleground.h b/src/map/battleground.h
index a24ae5ea9..4aeb9f879 100644
--- a/src/map/battleground.h
+++ b/src/map/battleground.h
@@ -93,15 +93,15 @@ struct battleground_interface {
void (*queue_check) (struct bg_arena *arena);
struct battleground_data* (*team_search) (int bg_id);
struct map_session_data* (*getavailablesd) (struct battleground_data *bgd);
- int (*team_delete) (int bg_id);
- int (*team_warp) (int bg_id, unsigned short map_index, short x, short y);
- int (*send_dot_remove) (struct map_session_data *sd);
- int (*team_join) (int bg_id, struct map_session_data *sd);
+ bool (*team_delete) (int bg_id);
+ bool (*team_warp) (int bg_id, unsigned short map_index, short x, short y);
+ void (*send_dot_remove) (struct map_session_data *sd);
+ bool (*team_join) (int bg_id, struct map_session_data *sd);
int (*team_leave) (struct map_session_data *sd, int flag);
- int (*member_respawn) (struct map_session_data *sd);
+ bool (*member_respawn) (struct map_session_data *sd);
int (*create) (unsigned short map_index, short rx, short ry, const char *ev, const char *dev);
int (*team_get_id) (struct block_list *bl);
- int (*send_message) (struct map_session_data *sd, const char *mes, int len);
+ bool (*send_message) (struct map_session_data *sd, const char *mes, int len);
int (*send_xy_timer_sub) (DBKey key, DBData *data, va_list ap);
int (*send_xy_timer) (int tid, int64 tick, int id, intptr_t data);
/* */
diff --git a/src/map/chat.c b/src/map/chat.c
index 50fe2aeb5..549904ca6 100644
--- a/src/map/chat.c
+++ b/src/map/chat.c
@@ -68,26 +68,26 @@ struct chat_data* chat_createchat(struct block_list* bl, const char* title, cons
/*==========================================
* player chatroom creation
*------------------------------------------*/
-int chat_createpcchat(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub) {
+bool chat_createpcchat(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub) {
struct chat_data* cd;
nullpo_ret(sd);
if( sd->chatID )
- return 0; //Prevent people abusing the chat system by creating multiple chats, as pointed out by End of Exam. [Skotlex]
+ return false; //Prevent people abusing the chat system by creating multiple chats, as pointed out by End of Exam. [Skotlex]
if( sd->state.vending || sd->state.buyingstore )
{// not chat, when you already have a store open
- return 0;
+ return false;
}
if( map->list[sd->bl.m].flag.nochat ) {
clif->message(sd->fd, msg_txt(281));
- return 0; //Can't create chatrooms on this map.
+ return false; //Can't create chatrooms on this map.
}
if( map->getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOCHAT) ) {
- clif->message (sd->fd, msg_txt(665));
- return 0;
+ clif->message (sd->fd, msg_txt(665)); // "Can't create chat rooms in this area."
+ return false;
}
pc_stop_walking(sd,1);
@@ -100,16 +100,17 @@ int chat_createpcchat(struct map_session_data* sd, const char* title, const char
pc_stop_attack(sd);
clif->createchat(sd,0);
clif->dispchat(cd,0);
- } else
- clif->createchat(sd,1);
+ return true;
+ }
+ clif->createchat(sd,1); // 1 = Room limit exceeded
- return 0;
+ return false;
}
/*==========================================
* join an existing chatroom
*------------------------------------------*/
-int chat_joinchat(struct map_session_data* sd, int chatid, const char* pass) {
+bool chat_joinchat(struct map_session_data* sd, int chatid, const char* pass) {
struct chat_data* cd;
nullpo_ret(sd);
@@ -117,33 +118,33 @@ int chat_joinchat(struct map_session_data* sd, int chatid, const char* pass) {
if( cd == NULL || cd->bl.type != BL_CHAT || cd->bl.m != sd->bl.m || sd->state.vending || sd->state.buyingstore || sd->chatID || ((cd->owner->type == BL_NPC) ? cd->users+1 : cd->users) >= cd->limit )
{
- clif->joinchatfail(sd,0);
- return 0;
+ clif->joinchatfail(sd,0); // room full
+ return false;
}
if( !cd->pub && strncmp(pass, cd->pass, sizeof(cd->pass)) != 0 && !pc_has_permission(sd, PC_PERM_JOIN_ALL_CHAT) )
{
- clif->joinchatfail(sd,1);
- return 0;
+ clif->joinchatfail(sd,1); // wrong password
+ return false;
}
if( sd->status.base_level < cd->minLvl || sd->status.base_level > cd->maxLvl ) {
if(sd->status.base_level < cd->minLvl)
- clif->joinchatfail(sd,5);
+ clif->joinchatfail(sd,5); // too low level
else
- clif->joinchatfail(sd,6);
+ clif->joinchatfail(sd,6); // too high level
- return 0;
+ return false;
}
if( sd->status.zeny < cd->zeny ) {
- clif->joinchatfail(sd,4);
- return 0;
+ clif->joinchatfail(sd,4); // not enough zeny
+ return false;
}
if( cd->owner->type != BL_NPC && idb_exists(cd->kick_list,sd->status.char_id) ) {
- clif->joinchatfail(sd,2);//You have been kicked out of the room.
- return 0;
+ clif->joinchatfail(sd,2); // You have been kicked out of the room.
+ return false;
}
pc_stop_walking(sd,1);
@@ -158,31 +159,36 @@ int chat_joinchat(struct map_session_data* sd, int chatid, const char* pass) {
chat->trigger_event(cd); //Event
- return 0;
+ return true;
}
/*==========================================
- * leave a chatroom
+ * Leave a chatroom
+ * Return
+ * 0: User not found in chatroom/Missing data
+ * 1: Success
+ * 2: Chat room deleted (chat room empty)
+ * 3: Owner changed (Owner left and a new one as assigned)
*------------------------------------------*/
int chat_leavechat(struct map_session_data* sd, bool kicked) {
struct chat_data* cd;
int i;
int leavechar;
- nullpo_retr(1, sd);
+ nullpo_retr(0, sd);
cd = (struct chat_data*)map->id2bl(sd->chatID);
if( cd == NULL ) {
pc_setchatid(sd, 0);
- return 1;
+ return 0;
}
ARR_FIND( 0, cd->users, i, cd->usersd[i] == sd );
if ( i == cd->users )
{ // Not found in the chatroom?
pc_setchatid(sd, 0);
- return -1;
+ return 0;
}
clif->leavechat(cd, sd, kicked);
@@ -210,7 +216,7 @@ int chat_leavechat(struct map_session_data* sd, bool kicked) {
if (group != NULL)
skill->unit_onplace(su, &sd->bl, group->tick);
- return 1;
+ return 2;
}
if( leavechar == 0 && cd->owner->type == BL_PC ) {
@@ -226,29 +232,33 @@ int chat_leavechat(struct map_session_data* sd, bool kicked) {
map->addblock( &cd->bl );
clif->dispchat(cd,0);
- } else
- clif->dispchat(cd,0); // refresh chatroom
+ return 3; // Owner changed
+ }
+ clif->dispchat(cd,0); // refresh chatroom
- return 0;
+ return 1;
}
/*==========================================
- * change a chatroom's owner
+ * Change a chatroom's owner
+ * Return
+ * 0: User not found/Missing data
+ * 1: Success
*------------------------------------------*/
-int chat_changechatowner(struct map_session_data* sd, const char* nextownername) {
+bool chat_changechatowner(struct map_session_data* sd, const char* nextownername) {
struct chat_data* cd;
struct map_session_data* tmpsd;
int i;
- nullpo_retr(1, sd);
+ nullpo_ret(sd);
cd = (struct chat_data*)map->id2bl(sd->chatID);
if( cd == NULL || (struct block_list*) sd != cd->owner )
- return 1;
+ return false;
ARR_FIND( 1, cd->users, i, strncmp(cd->usersd[i]->status.name, nextownername, NAME_LENGTH) == 0 );
if( i == cd->users )
- return -1; // name not found
+ return false; // name not found
// erase temporarily
clif->clearchat(cd,0);
@@ -271,20 +281,23 @@ int chat_changechatowner(struct map_session_data* sd, const char* nextownername)
// and display again
clif->dispchat(cd,0);
- return 0;
+ return true;
}
/*==========================================
- * change a chatroom's status (title, etc)
+ * Change a chatroom's status (title, etc)
+ * Return
+ * 0: Missing data
+ * 1: Success
*------------------------------------------*/
-int chat_changechatstatus(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub) {
+bool chat_changechatstatus(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub) {
struct chat_data* cd;
- nullpo_retr(1, sd);
+ nullpo_ret(sd);
cd = (struct chat_data*)map->id2bl(sd->chatID);
if( cd==NULL || (struct block_list *)sd != cd->owner )
- return 1;
+ return false;
safestrncpy(cd->title, title, CHATROOM_TITLE_SIZE);
safestrncpy(cd->pass, pass, CHATROOM_PASS_SIZE);
@@ -294,50 +307,55 @@ int chat_changechatstatus(struct map_session_data* sd, const char* title, const
clif->changechatstatus(cd);
clif->dispchat(cd,0);
- return 0;
+ return true;
}
/*==========================================
- * kick an user from a chatroom
+ * Kick an user from a chatroom
+ * Return:
+ * 0: User cannot be kicked (is gm)/Missing data
+ * 1: Success
*------------------------------------------*/
-int chat_kickchat(struct map_session_data* sd, const char* kickusername) {
+bool chat_kickchat(struct map_session_data* sd, const char* kickusername) {
struct chat_data* cd;
int i;
- nullpo_retr(1, sd);
+ nullpo_ret(sd);
cd = (struct chat_data *)map->id2bl(sd->chatID);
if( cd==NULL || (struct block_list *)sd != cd->owner )
- return -1;
+ return false;
ARR_FIND( 0, cd->users, i, strncmp(cd->usersd[i]->status.name, kickusername, NAME_LENGTH) == 0 );
- if( i == cd->users )
- return -1;
+ if( i == cd->users ) // User not found
+ return false;
if (pc_has_permission(cd->usersd[i], PC_PERM_NO_CHAT_KICK))
- return 0; //gm kick protection [Valaris]
+ return false; //gm kick protection [Valaris]
idb_iput(cd->kick_list,cd->usersd[i]->status.char_id,1);
chat->leave(cd->usersd[i],1);
- return 0;
+ return true;
}
-/// Creates a chat room for the npc.
-int chat_createnpcchat(struct npc_data* nd, const char* title, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl)
+/*==========================================
+ * Creates a chat room for the npc
+ *------------------------------------------*/
+bool chat_createnpcchat(struct npc_data* nd, const char* title, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl)
{
struct chat_data* cd;
nullpo_ret(nd);
if( nd->chat_id ) {
ShowError("chat_createnpcchat: npc '%s' already has a chatroom, cannot create new one!\n", nd->exname);
- return 0;
+ return false;
}
if( zeny > MAX_ZENY || maxLvl > MAX_LEVEL ) {
ShowError("chat_createnpcchat: npc '%s' has a required lvl or amount of zeny over the max limit!\n", nd->exname);
- return 0;
+ return false;
}
cd = chat->create(&nd->bl, title, "", limit, pub, trigger, ev, zeny, minLvl, maxLvl);
@@ -345,19 +363,25 @@ int chat_createnpcchat(struct npc_data* nd, const char* title, int limit, bool p
if( cd ) {
nd->chat_id = cd->bl.id;
clif->dispchat(cd,0);
+ return true;
}
- return 0;
+ return false;
}
-/// Removes the chatroom from the npc.
-int chat_deletenpcchat(struct npc_data* nd) {
+/*==========================================
+ * Removes the chatroom from the npc.
+ * Return:
+ * 0: Missing data
+ * 1: Success
+ *------------------------------------------*/
+bool chat_deletenpcchat(struct npc_data* nd) {
struct chat_data *cd;
nullpo_ret(nd);
cd = (struct chat_data*)map->id2bl(nd->chat_id);
if( cd == NULL )
- return 0;
+ return false;
chat->npc_kick_all(cd);
clif->clearchat(cd, 0);
@@ -366,50 +390,56 @@ int chat_deletenpcchat(struct npc_data* nd) {
map->freeblock(&cd->bl);
nd->chat_id = 0;
- return 0;
+ return true;
}
/*==========================================
* Trigger npc event when we enter the chatroom
+ * Return
+ * 0: Couldn't trigger / Missing data
+ * 1: Success
*------------------------------------------*/
-int chat_triggerevent(struct chat_data *cd)
+bool chat_triggerevent(struct chat_data *cd)
{
nullpo_ret(cd);
if( cd->users >= cd->trigger && cd->npc_event[0] )
+ {
npc->event_do(cd->npc_event);
- return 0;
+ return true;
+ }
+ return false;
}
/// Enables the event of the chat room.
/// At most, 127 users are needed to trigger the event.
-int chat_enableevent(struct chat_data* cd)
+bool chat_enableevent(struct chat_data* cd)
{
nullpo_ret(cd);
cd->trigger &= 0x7f;
chat->trigger_event(cd);
- return 0;
+ return true;
}
/// Disables the event of the chat room
-int chat_disableevent(struct chat_data* cd)
+bool chat_disableevent(struct chat_data* cd)
{
nullpo_ret(cd);
cd->trigger |= 0x80;
- return 0;
+ return true;
}
/// Kicks all the users from the chat room.
-int chat_npckickall(struct chat_data* cd)
+bool chat_npckickall(struct chat_data* cd)
{
nullpo_ret(cd);
while( cd->users > 0 )
chat->leave(cd->usersd[cd->users-1],0);
- return 0;
+ return true;
}
/*=====================================
diff --git a/src/map/chat.h b/src/map/chat.h
index 695e59b6e..fcbadf008 100644
--- a/src/map/chat.h
+++ b/src/map/chat.h
@@ -36,18 +36,18 @@ struct chat_data {
struct chat_interface {
/* funcs */
- int (*create_pc_chat) (struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub);
- int (*join) (struct map_session_data* sd, int chatid, const char* pass);
+ bool (*create_pc_chat) (struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub);
+ bool (*join) (struct map_session_data* sd, int chatid, const char* pass);
int (*leave) (struct map_session_data* sd, bool kicked);
- int (*change_owner) (struct map_session_data* sd, const char* nextownername);
- int (*change_status) (struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub);
- int (*kick) (struct map_session_data* sd, const char* kickusername);
- int (*create_npc_chat) (struct npc_data* nd, const char* title, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl);
- int (*delete_npc_chat) (struct npc_data* nd);
- int (*enable_event) (struct chat_data* cd);
- int (*disable_event) (struct chat_data* cd);
- int (*npc_kick_all) (struct chat_data* cd);
- int (*trigger_event) (struct chat_data *cd);
+ bool (*change_owner) (struct map_session_data* sd, const char* nextownername);
+ bool (*change_status) (struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub);
+ bool (*kick) (struct map_session_data* sd, const char* kickusername);
+ bool (*create_npc_chat) (struct npc_data* nd, const char* title, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl);
+ bool (*delete_npc_chat) (struct npc_data* nd);
+ bool (*enable_event) (struct chat_data* cd);
+ bool (*disable_event) (struct chat_data* cd);
+ bool (*npc_kick_all) (struct chat_data* cd);
+ bool (*trigger_event) (struct chat_data *cd);
struct chat_data* (*create) (struct block_list* bl, const char* title, const char* pass, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl);
};
diff --git a/src/map/chrif.c b/src/map/chrif.c
index aaef0d6ef..964354e24 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -208,20 +208,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
@@ -239,8 +238,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);
@@ -285,11 +284,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;
@@ -299,12 +298,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");
@@ -316,12 +313,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));
@@ -334,12 +329,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);
@@ -351,8 +344,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
@@ -362,12 +353,12 @@ 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);
@@ -388,19 +379,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));
@@ -408,13 +399,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)) {
@@ -437,8 +428,6 @@ int chrif_connectack(int fd) {
socket_datasync(fd, true);
chrif->skillid2idx(fd);
-
- return 0;
}
/**
@@ -451,7 +440,7 @@ int chrif_reconnect(DBKey key, DBData *data, va_list ap) {
case ST_LOGIN:
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;
@@ -510,7 +499,7 @@ void chrif_on_ready(void) {
/*==========================================
*
*------------------------------------------*/
-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));
@@ -520,17 +509,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;
@@ -539,7 +526,7 @@ int chrif_scdata_request(int account_id, int char_id) {
WFIFOSET(chrif->fd,10);
#endif
- return 0;
+ return true;
}
/*==========================================
@@ -625,7 +612,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);
}
@@ -690,15 +677,15 @@ int auth_db_cleanup(int tid, int64 tick, int id, intptr_t data) {
}
/*==========================================
- *
+ * 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;
@@ -708,36 +695,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;
@@ -746,7 +733,7 @@ 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;
}
/*==========================================
@@ -755,9 +742,9 @@ int chrif_changeemail(int id, const char *actual_email, const char *new_email) {
* type of operation:
* 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;
@@ -775,11 +762,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;
@@ -794,7 +781,7 @@ int chrif_changesex(struct map_session_data *sd) {
clif->authfail_fd(sd->fd, 15);
else
map->quit(sd);
- return 0;
+ return true;
}
/*==========================================
@@ -808,7 +795,7 @@ int chrif_changesex(struct map_session_data *sd) {
* 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];
@@ -818,7 +805,7 @@ void chrif_char_ask_name_answer(int acc, const char* player_name, uint16 type, u
if( acc < 0 || sd == NULL ) {
ShowError("chrif_char_ask_name_answer failed - player not online.\n");
- return;
+ return false;
}
/* re-use previous msg_txt */
@@ -839,12 +826,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;
@@ -857,7 +845,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
@@ -896,13 +884,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;
@@ -910,19 +897,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;
@@ -938,12 +925,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);
@@ -963,13 +950,12 @@ int chrif_deadopt(int father_id, int mother_id, int child_id) {
clif->deleteskill(sd,WE_CALLBABY);
}
- return 0;
}
/*==========================================
* Disconnection of a player (account or char has been banned of has a status, from login or char server) by [Yor]
*------------------------------------------*/
-int chrif_idbanned(int fd) {
+void chrif_idbanned(int fd) {
int id;
struct map_session_data *sd;
@@ -982,7 +968,7 @@ int chrif_idbanned(int fd) {
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 0;
+ return;
}
sd->login_id1++; // change identify, because if player come back in char within the 5 seconds, he can change its characters
@@ -1012,7 +998,6 @@ int chrif_idbanned(int fd) {
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
@@ -1075,17 +1060,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;
@@ -1121,8 +1106,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
@@ -1148,7 +1131,7 @@ 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;
@@ -1157,7 +1140,7 @@ int chrif_save_scdata(struct map_session_data *sd) { //parses the sc_data of the
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));
@@ -1186,18 +1169,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;
@@ -1211,12 +1194,12 @@ 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
@@ -1229,15 +1212,15 @@ int chrif_load_scdata(int fd) {
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;
@@ -1246,26 +1229,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;
@@ -1273,41 +1245,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_fifo(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;
@@ -1315,10 +1286,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 )
@@ -1390,18 +1360,18 @@ int chrif_parse(int fd) {
if ( fd != chrif->fd ) {
ShowDebug("chrif_parse: Disconnecting invalid session #%d (is not the char-server)\n", fd);
do_close(fd);
- return 0;
+ return false;
}
if ( session[fd]->flag.eof ) {
do_close(fd);
chrif->fd = -1;
chrif->on_disconnect();
- return 0;
+ return false;
} 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 */
set_eof(fd);
- return 0;
+ return false;
} else if( session[fd]->flag.ping != 2 ) { /* we haven't sent ping out yet */
chrif->keepalive(fd);
session[fd]->flag.ping = 2;
@@ -1413,7 +1383,7 @@ int chrif_parse(int fd) {
if( HPM->packetsc[hpChrif_Parse] ) {
if( (r = HPM->parse_packets(fd,hpChrif_Parse)) ) {
if( r == 1 ) continue;
- if( r == 2 ) return 0;
+ if( r == 2 ) return false;
}
}
@@ -1422,22 +1392,22 @@ int chrif_parse(int fd) {
if (cmd < 0x2af8 || cmd >= 0x2af8 + ARRAYLENGTH(chrif->packet_len_table) || chrif->packet_len_table[cmd-0x2af8] == 0) {
r = intif->parse(fd); // Passed on to the intif
- if (r == 1) continue; // Treated in intif
- if (r == 2) return 0; // Didn't have enough data (len==-1)
+ if (r == 1) continue; // Treated in intif
+ if (r == 2) return false; // Didn't have enough data (len==-1)
ShowWarning("chrif_parse: session #%d, intif->parse failed (unrecognized command 0x%.4x).\n", fd, cmd);
set_eof(fd);
- return 0;
+ return false;
}
if ( ( packet_len = chrif->packet_len_table[cmd-0x2af8] ) == -1) { // dynamic-length packet, second WORD holds the length
if (RFIFOREST(fd) < 4)
- return 0;
+ return false;
packet_len = RFIFOW(fd,2);
}
if ((int)RFIFOREST(fd) < packet_len)
- return 0;
+ return false;
//ShowDebug("Received packet 0x%4x (%d bytes) from char-server (connection %d)\n", RFIFOW(fd,0), packet_len, fd);
@@ -1468,13 +1438,13 @@ int chrif_parse(int fd) {
default:
ShowError("chrif_parse : unknown packet (session #%d): 0x%x. Disconnecting.\n", fd, cmd);
set_eof(fd);
- return 0;
+ return false;
}
if ( fd == chrif->fd ) //There's the slight chance we lost the connection during parse, in which case this would segfault if not checked [Skotlex]
RFIFOSKIP(fd, packet_len);
}
- return 0;
+ return true;
}
int send_usercount_tochar(int tid, int64 tick, int id, intptr_t data) {
@@ -1491,12 +1461,12 @@ int send_usercount_tochar(int tid, int64 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();
@@ -1517,12 +1487,12 @@ 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, int64 tick, int id, intptr_t data) {
static int displayed = 0;
@@ -1558,9 +1528,9 @@ int check_connect_char_server(int tid, int64 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;
@@ -1568,7 +1538,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) {
@@ -1597,14 +1567,14 @@ int auth_db_final(DBKey key, DBData *data, va_list ap) {
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);
@@ -1614,16 +1584,14 @@ 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(bool minimal) {
+void do_init_chrif(bool minimal) {
if (minimal)
- return 0;
+ 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);
@@ -1640,8 +1608,6 @@ int do_init_chrif(bool minimal) {
// 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;
}
@@ -1712,7 +1678,7 @@ 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 = 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;
diff --git a/src/map/chrif.h b/src/map/chrif.h
index 1de0901f0..a7460875f 100644
--- a/src/map/chrif.h
+++ b/src/map/chrif.h
@@ -61,13 +61,13 @@ struct chrif_interface {
char userid[NAME_LENGTH], passwd[NAME_LENGTH];
int state;
/* */
- int (*final) (void);
- int (*init) (bool minimal);
+ void (*init) (bool minimal);
+ void (*final) (void);
/* funcs */
void (*setuserid) (char* id);
void (*setpasswd) (char* pwd);
void (*checkdefaultlogin) (void);
- int (*setip) (const char* ip);
+ bool (*setip) (const char* ip);
void (*setport) (uint16 port);
int (*isconnected) (void);
@@ -80,31 +80,31 @@ struct chrif_interface {
void (*authreq) (struct map_session_data* sd, bool hstandalone);
void (*authok) (int fd);
- int (*scdata_request) (int account_id, int char_id);
- int (*save) (struct map_session_data* sd, int flag);
- int (*charselectreq) (struct map_session_data* sd, uint32 s_ip);
- int (*changemapserver) (struct map_session_data* sd, uint32 ip, uint16 port);
+ bool (*scdata_request) (int account_id, int char_id);
+ bool (*save) (struct map_session_data* sd, int flag);
+ bool (*charselectreq) (struct map_session_data* sd, uint32 s_ip);
+ bool (*changemapserver) (struct map_session_data* sd, uint32 ip, uint16 port);
- int (*searchcharid) (int char_id);
- int (*changeemail) (int id, const char *actual_email, const char *new_email);
- int (*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 (*searchcharid) (int char_id);
+ bool (*changeemail) (int id, const char *actual_email, const char *new_email);
+ bool (*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);
int (*updatefamelist) (struct map_session_data *sd);
- int (*buildfamelist) (void);
- int (*save_scdata) (struct map_session_data *sd);
- int (*ragsrvinfo) (int base_rate,int job_rate, int drop_rate);
- int (*char_offline) (struct map_session_data *sd);
- int (*char_offline_nsd) (int account_id, int char_id);
- int (*char_reset_offline) (void);
- int (*send_users_tochar) (void);
- int (*char_online) (struct map_session_data *sd);
- int (*changesex) (struct map_session_data *sd);
+ bool (*buildfamelist) (void);
+ bool (*save_scdata) (struct map_session_data *sd);
+ bool (*ragsrvinfo) (int base_rate,int job_rate, int drop_rate);
+ //int (*char_offline) (struct map_session_data *sd);
+ bool (*char_offline_nsd) (int account_id, int char_id);
+ bool (*char_reset_offline) (void);
+ bool (*send_users_tochar) (void);
+ bool (*char_online) (struct map_session_data *sd);
+ bool (*changesex) (struct map_session_data *sd);
//int (*chardisconnect) (struct map_session_data *sd); // FIXME: Commented out in clif.c, function does not exist
- int (*divorce) (int partner_id1, int partner_id2);
+ bool (*divorce) (int partner_id1, int partner_id2);
- int (*removefriend) (int char_id, int friend_id);
+ bool (*removefriend) (int char_id, int friend_id);
void (*send_report) (char* buf, int len);
- int (*flush_fifo) (void);
+ bool (*flush_fifo) (void);
void (*skillid2idx) (int fd);
bool (*sd_to_auth) (TBL_PC* sd, enum sd_state state);
@@ -118,24 +118,24 @@ struct chrif_interface {
int (*send_usercount_tochar) (int tid, int64 tick, int id, intptr_t data);
int (*auth_db_cleanup) (int tid, int64 tick, int id, intptr_t data);
- int (*connect) (int fd);
- int (*connectack) (int fd);
- int (*sendmap) (int fd);
- int (*sendmapack) (int fd);
- int (*recvmap) (int fd);
- int (*changemapserverack) (int account_id, int login_id1, int login_id2, int char_id, short map_index, short x, short y, uint32 ip, uint16 port);
- int (*changedsex) (int fd);
- int (*divorceack) (int char_id, int partner_id);
- int (*idbanned) (int fd);
- int (*recvfamelist) (int fd);
- int (*load_scdata) (int fd);
+ void (*connect) (int fd);
+ void (*connectack) (int fd);
+ void (*sendmap) (int fd);
+ void (*sendmapack) (int fd);
+ void (*recvmap) (int fd);
+ void (*changemapserverack) (int account_id, int login_id1, int login_id2, int char_id, short map_index, short x, short y, uint32 ip, uint16 port);
+ void (*changedsex) (int fd);
+ bool (*divorceack) (int char_id, int partner_id);
+ void (*idbanned) (int fd);
+ void (*recvfamelist) (int fd);
+ bool (*load_scdata) (int fd);
void (*update_ip) (int fd);
int (*disconnectplayer) (int fd);
- int (*removemap) (int fd);
+ void (*removemap) (int fd);
int (*updatefamelist_ack) (int fd);
void (*keepalive)(int fd);
void (*keepalive_ack) (int fd);
- int (*deadopt) (int father_id, int mother_id, int child_id);
+ void (*deadopt) (int father_id, int mother_id, int child_id);
void (*authfail) (int fd);
void (*on_ready) (void);
void (*on_disconnect) (void);
@@ -145,5 +145,7 @@ struct chrif_interface {
struct chrif_interface *chrif;
void chrif_defaults(void);
+// There's no need for another function when a simple macro can do exactly the same effect
+#define chrif_char_offline(x) chrif->char_offline_nsd(x->status.account_id,x->status.char_id)
#endif /* _CHRIF_H_ */