From 42e1df9e61f8efb6340ed1c9238cd247d553d9b8 Mon Sep 17 00:00:00 2001 From: Haru Date: Thu, 23 Jan 2014 18:40:29 +0100 Subject: Replaced some of the hardcoded values with constants (char) - Replaced several hardcoded values with the appropriate enums. - Added documentation for some hardcoded values that haven't been replaced by enums (yet) - Minor code legibility improvements. Signed-off-by: Haru --- src/char/char.c | 114 +++++++++++++++++++++++++-------------------------- src/char/int_guild.c | 24 +++++------ src/char/int_party.c | 13 +++--- src/char/inter.c | 4 +- 4 files changed, 76 insertions(+), 79 deletions(-) (limited to 'src/char') diff --git a/src/char/char.c b/src/char/char.c index d8d9d386e..910c3fcf6 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -148,11 +148,6 @@ struct fame_list smith_fame_list[MAX_FAME_LIST]; struct fame_list chemist_fame_list[MAX_FAME_LIST]; struct fame_list taekwon_fame_list[MAX_FAME_LIST]; -// check for exit signal -// 0 is saving complete -// other is char_id -unsigned int save_flag = 0; - // Initial position (it's possible to set it in conf file) struct point start_point = { 0, 53, 111 }; @@ -240,7 +235,7 @@ void char_set_char_online(int map_id, int char_id, int account_id) { ShowNotice("chr->set_char_online: Character %d:%d marked in map server %d, but map server %d claims to have (%d:%d) online!\n", character->account_id, character->char_id, character->server, map_id, account_id, char_id); - mapif->disconnectplayer(chr->server[character->server].fd, character->account_id, character->char_id, 2); + mapif->disconnectplayer(chr->server[character->server].fd, character->account_id, character->char_id, 2); // 2: Already connected to server } //Update state data @@ -345,7 +340,7 @@ static int char_db_kickoffline(DBKey key, DBData *data, va_list ap) //Kick out any connected characters, and set them offline as appropriate. if (character->server > -1 && character->server < MAX_MAP_SERVERS) - mapif->disconnectplayer(chr->server[character->server].fd, character->account_id, character->char_id, 1); + mapif->disconnectplayer(chr->server[character->server].fd, character->account_id, character->char_id, 1); // 1: Server closed else if (character->waiting_disconnect == INVALID_TIMER) chr->set_char_offline(character->char_id, character->account_id); else @@ -1998,7 +1993,8 @@ int char_mmo_char_tobuf(uint8* buffer, struct mmo_charstatus* p) { #endif //When the weapon is sent and your option is riding, the client crashes on login!? - WBUFW(buf,56) = (p->option&(0x20|0x80000|0x100000|0x200000|0x400000|0x800000|0x1000000|0x2000000|0x4000000|0x8000000)) ? 0 : p->weapon; + // FIXME[Haru]: is OPTION_HANBOK intended to be part of this list? And if it is, should the list also include other OPTION_ costumes? + WBUFL(buf,56) = p->option&(OPTION_RIDING|OPTION_DRAGON|OPTION_WUG|OPTION_WUGRIDER|OPTION_MADOGEAR|OPTION_HANBOK) ? 0 : p->weapon; WBUFW(buf,58) = p->base_level; WBUFW(buf,60) = min(p->skill_point, INT16_MAX); @@ -2247,7 +2243,7 @@ static void char_auth_ok(int fd, struct char_session_data *sd) // check if character is not online already. [Skotlex] if (character->server > -1) { //Character already online. KICK KICK KICK - mapif->disconnectplayer(chr->server[character->server].fd, character->account_id, character->char_id, 2); + mapif->disconnectplayer(chr->server[character->server].fd, character->account_id, character->char_id, 2); // 2: Already connected to server if (character->waiting_disconnect == INVALID_TIMER) character->waiting_disconnect = timer->add(timer->gettick()+20000, chr->waiting_disconnect, character->account_id, 0); character->pincode_enable = -1; @@ -2534,7 +2530,7 @@ void char_parse_fromlogin_kick(int fd) {// account is already marked as online! if( character->server > -1 ) { //Kick it from the map server it is on. - mapif->disconnectplayer(chr->server[character->server].fd, character->account_id, character->char_id, 2); + mapif->disconnectplayer(chr->server[character->server].fd, character->account_id, character->char_id, 2); // 2: Already connected to server if (character->waiting_disconnect == INVALID_TIMER) character->waiting_disconnect = timer->add(timer->gettick()+AUTH_TIMEOUT, chr->waiting_disconnect, character->account_id, 0); } @@ -3181,7 +3177,7 @@ void char_parse_frommap_set_users(int fd, int id) if (character->server > -1 && character->server != id) { ShowNotice("Set map user: Character (%d:%d) marked on map server %d, but map server %d claims to have (%d:%d) online!\n", character->account_id, character->char_id, character->server, id, aid, cid); - mapif->disconnectplayer(chr->server[character->server].fd, character->account_id, character->char_id, 2); + mapif->disconnectplayer(chr->server[character->server].fd, character->account_id, character->char_id, 2); // 2: Already connected to server } character->server = id; character->char_id = cid; @@ -3547,36 +3543,37 @@ void char_parse_frommap_change_account(int fd) #endif // 0 } else { switch (type) { - case 1: // block - loginif->block_account(account_id, 5); + case CHAR_ASK_NAME_BLOCK: + loginif->block_account(account_id, 5); break; - case 2: // ban - loginif->ban_account(account_id, year, month, day, hour, minute, second); + case CHAR_ASK_NAME_BAN: + loginif->ban_account(account_id, year, month, day, hour, minute, second); break; - case 3: // unblock - loginif->block_account(account_id, 0); + case CHAR_ASK_NAME_UNBLOCK: + loginif->block_account(account_id, 0); break; - case 4: // unban - loginif->unban_account(account_id); + case CHAR_ASK_NAME_UNBAN: + loginif->unban_account(account_id); break; - case 5: // changesex - loginif->changesex(account_id); + case CHAR_ASK_NAME_CHANGESEX: + loginif->changesex(account_id); break; - case 6: // char ban - handled by char server, so no redirection - chr->ban(account_id, char_id, &unban_time, year, month, day, hour, minute, second); + case CHAR_ASK_NAME_CHARBAN: + /* handled by char server, so no redirection */ + chr->ban(account_id, char_id, &unban_time, year, month, day, hour, minute, second); break; - case 7: // char unban - handled by char server, so no redirection - chr->unban(char_id, &result); + case CHAR_ASK_NAME_CHARUNBAN: + chr->unban(char_id, &result); break; - case 8: // changecharsex - handled by char server, so no redirection - result = chr->changecharsex(char_id, sex); + case CHAR_ASK_NAME_CHANGECHARSEX: + result = chr->changecharsex(char_id, sex); break; } } } // send answer if a player ask, not if the server ask - if (acc != -1 && type != 5 && type != 8) { // Don't send answer for changesex + if (acc != -1 && type != CHAR_ASK_NAME_CHANGESEX && type != CHAR_ASK_NAME_CHANGECHARSEX) { // Don't send answer for changesex chr->ask_name_ack(fd, acc, name, type, result); } } @@ -4264,21 +4261,21 @@ static void char_delete2_req(int fd, struct char_session_data* sd) ARR_FIND( 0, MAX_CHARS, i, sd->found_char[i] == char_id ); if( i == MAX_CHARS ) {// character not found - chr->delete2_ack(fd, char_id, 3, 0); + chr->delete2_ack(fd, char_id, 3, 0); // 3: A database error occurred return; } if( SQL_SUCCESS != SQL->Query(inter->sql_handle, "SELECT `delete_date` FROM `%s` WHERE `char_id`='%d'", char_db, char_id) || SQL_SUCCESS != SQL->NextRow(inter->sql_handle) ) { Sql_ShowDebug(inter->sql_handle); - chr->delete2_ack(fd, char_id, 3, 0); + chr->delete2_ack(fd, char_id, 3, 0); // 3: A database error occurred return; } SQL->GetData(inter->sql_handle, 0, &data, NULL); delete_date = strtoul(data, NULL, 10); if( delete_date ) {// character already queued for deletion - chr->delete2_ack(fd, char_id, 0, 0); + chr->delete2_ack(fd, char_id, 0, 0); // 0: An unknown error occurred return; } @@ -4291,7 +4288,7 @@ static void char_delete2_req(int fd, struct char_session_data* sd) || SQL_SUCCESS != SQL->NextRow(inter->sql_handle) ) { Sql_ShowDebug(inter->sql_handle); - chr->delete2_ack(fd, char_id, 3, 0); + chr->delete2_ack(fd, char_id, 3, 0); // 3: A database error occurred return; } SQL->GetData(inter->sql_handle, 0, &data, NULL); party_id = atoi(data); @@ -4299,13 +4296,13 @@ static void char_delete2_req(int fd, struct char_session_data* sd) if( guild_id ) { - chr->delete2_ack(fd, char_id, 4, 0); + chr->delete2_ack(fd, char_id, 4, 0); // 4: To delete a character you must withdraw from the guild return; } if( party_id ) { - chr->delete2_ack(fd, char_id, 5, 0); + chr->delete2_ack(fd, char_id, 5, 0); // 5: To delete a character you must withdraw from the party return; } } @@ -4316,11 +4313,11 @@ static void char_delete2_req(int fd, struct char_session_data* sd) if( SQL_SUCCESS != SQL->Query(inter->sql_handle, "UPDATE `%s` SET `delete_date`='%lu' WHERE `char_id`='%d'", char_db, (unsigned long)delete_date, char_id) ) { Sql_ShowDebug(inter->sql_handle); - chr->delete2_ack(fd, char_id, 3, 0); + chr->delete2_ack(fd, char_id, 3, 0); // 3: A database error occurred return; } - chr->delete2_ack(fd, char_id, 1, delete_date); + chr->delete2_ack(fd, char_id, 1, delete_date); // 1: success } static void char_delete2_accept(int fd, struct char_session_data* sd) @@ -4349,14 +4346,14 @@ static void char_delete2_accept(int fd, struct char_session_data* sd) ARR_FIND( 0, MAX_CHARS, i, sd->found_char[i] == char_id ); if( i == MAX_CHARS ) {// character not found - chr->delete2_accept_ack(fd, char_id, 3); + chr->delete2_accept_ack(fd, char_id, 3); // 3: A database error occurred return; } if( SQL_SUCCESS != SQL->Query(inter->sql_handle, "SELECT `base_level`,`delete_date` FROM `%s` WHERE `char_id`='%d'", char_db, char_id) || SQL_SUCCESS != SQL->NextRow(inter->sql_handle) ) {// data error Sql_ShowDebug(inter->sql_handle); - chr->delete2_accept_ack(fd, char_id, 3); + chr->delete2_accept_ack(fd, char_id, 3); // 3: A database error occurred return; } @@ -4365,33 +4362,33 @@ static void char_delete2_accept(int fd, struct char_session_data* sd) if( !delete_date || delete_date>time(NULL) ) {// not queued or delay not yet passed - chr->delete2_accept_ack(fd, char_id, 4); + chr->delete2_accept_ack(fd, char_id, 4); // 4: Deleting not yet possible time return; } if( strcmp(sd->birthdate+2, birthdate) ) // +2 to cut off the century {// birth date is wrong - chr->delete2_accept_ack(fd, char_id, 5); + chr->delete2_accept_ack(fd, char_id, 5); // 5: Date of birth do not match return; } if( ( char_del_level > 0 && base_level >= (unsigned int)char_del_level ) || ( char_del_level < 0 && base_level <= (unsigned int)(-char_del_level) ) ) {// character level config restriction - chr->delete2_accept_ack(fd, char_id, 2); + chr->delete2_accept_ack(fd, char_id, 2); // 2: Due to system settings can not be deleted return; } // success if( chr->delete_char_sql(char_id) < 0 ) { - chr->delete2_accept_ack(fd, char_id, 3); + chr->delete2_accept_ack(fd, char_id, 3); // 3: A database error occurred return; } // refresh character list cache sd->found_char[i] = -1; - chr->delete2_accept_ack(fd, char_id, 1); + chr->delete2_accept_ack(fd, char_id, 1); // 1: success } static void char_delete2_cancel(int fd, struct char_session_data* sd) @@ -4403,7 +4400,7 @@ static void char_delete2_cancel(int fd, struct char_session_data* sd) ARR_FIND( 0, MAX_CHARS, i, sd->found_char[i] == char_id ); if( i == MAX_CHARS ) {// character not found - chr->delete2_cancel_ack(fd, char_id, 2); + chr->delete2_cancel_ack(fd, char_id, 2); // 2: A database error occurred return; } @@ -4413,11 +4410,11 @@ static void char_delete2_cancel(int fd, struct char_session_data* sd) if( SQL_SUCCESS != SQL->Query(inter->sql_handle, "UPDATE `%s` SET `delete_date`='0' WHERE `char_id`='%d'", char_db, char_id) ) { Sql_ShowDebug(inter->sql_handle); - chr->delete2_cancel_ack(fd, char_id, 2); + chr->delete2_cancel_ack(fd, char_id, 2); // 2: A database error occurred return; } - chr->delete2_cancel_ack(fd, char_id, 1); + chr->delete2_cancel_ack(fd, char_id, 1); // 1: success } void char_send_account_id(int fd, int account_id) @@ -4587,7 +4584,7 @@ void char_parse_char_select(int fd, struct char_session_data* sd, uint32 ipl) //Not found?? May be forged packet. Sql_ShowDebug(inter->sql_handle); SQL->FreeResult(inter->sql_handle); - chr->auth_error(fd, 0); + chr->auth_error(fd, 0); // rejected from server return; } @@ -4596,7 +4593,7 @@ void char_parse_char_select(int fd, struct char_session_data* sd, uint32 ipl) /* client doesn't let it get to this point if you're banned, so its a forged packet */ if( sd->found_char[slot] == char_id && sd->unban_time[slot] > time(NULL) ) { - chr->auth_error(fd, 0); + chr->auth_error(fd, 0); // rejected from server return; } @@ -4605,7 +4602,7 @@ void char_parse_char_select(int fd, struct char_session_data* sd, uint32 ipl) if( !chr->mmo_char_fromsql(char_id, &char_dat, true) ) { /* failed? set it back offline */ chr->set_char_offline(char_id, sd->account_id); /* failed to load something. REJECT! */ - chr->auth_error(fd, 0); + chr->auth_error(fd, 0); // rejected from server return;/* jump off this boat */ } @@ -4636,14 +4633,14 @@ void char_parse_char_select(int fd, struct char_session_data* sd, uint32 ipl) ARR_FIND( 0, ARRAYLENGTH(chr->server), j, chr->server[j].fd >= 0 && chr->server[j].map ); if (j == ARRAYLENGTH(chr->server)) { ShowInfo("Connection Closed. No map servers available.\n"); - chr->authfail_fd(fd, 1); + chr->authfail_fd(fd, 1); // 1 = Server closed return; } i = chr->search_default_maps_mapserver(cd); if (i < 0) { ShowInfo("Connection Closed. No map server available that has a major city, and unable to find map-server for '%s'.\n", mapindex_id2name(cd->last_point.map)); - chr->authfail_fd(fd, 1); + chr->authfail_fd(fd, 1); // 1 = Server closed return; } } @@ -4655,8 +4652,7 @@ void char_parse_char_select(int fd, struct char_session_data* sd, uint32 ipl) ShowError("chr->parse_char: Attempting to write to invalid session %d! Map Server #%d disconnected.\n", map_fd, i); chr->server[i].fd = -1; memset(&chr->server[i], 0, sizeof(struct mmo_map_server)); - //Send server closed. - chr->authfail_fd(fd, 1); + chr->authfail_fd(fd, 1); // 1 = Server closed return; } @@ -4714,15 +4710,18 @@ void char_creation_ok(int fd, struct mmo_charstatus *char_dat) void char_parse_char_create_new_char(int fd, struct char_session_data* sd) { int result; - if( !char_new ) //turn character creation on/off [Kevin] + if( !char_new ) { + //turn character creation on/off [Kevin] result = -2; - else + } else { #if PACKETVER >= 20120307 result = chr->make_new_char_sql(sd, (char*)RFIFOP(fd,2), 1, 1, 1, 1, 1, 1, RFIFOB(fd,26),RFIFOW(fd,27),RFIFOW(fd,29)); #else result = chr->make_new_char_sql(sd, (char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27),RFIFOB(fd,28),RFIFOB(fd,29),RFIFOB(fd,30),RFIFOB(fd,31),RFIFOB(fd,32),RFIFOW(fd,33),RFIFOW(fd,35)); #endif + } + //'Charname already exists' (-1), 'Char creation denied' (-2) and 'You are underaged' (-3) if (result < 0) { chr->creation_failed(fd, result); } else { @@ -4961,9 +4960,9 @@ void char_parse_char_login_map_server(int fd) strcmp(l_user, chr->userid) != 0 || strcmp(l_pass, chr->passwd) != 0 ) { - chr->login_map_server_ack(fd, 3); + chr->login_map_server_ack(fd, 3); // Failure } else { - chr->login_map_server_ack(fd, 0); + chr->login_map_server_ack(fd, 0); // Success chr->server[i].fd = fd; chr->server[i].ip = ntohl(RFIFOL(fd,54)); @@ -5101,7 +5100,6 @@ int char_parse_char(int fd) FIFOSD_CHECK(3); { chr->parse_char_select(fd, sd, ipl); - } break; diff --git a/src/char/int_guild.c b/src/char/int_guild.c index 3ba51e1f0..2753964e8 100644 --- a/src/char/int_guild.c +++ b/src/char/int_guild.c @@ -837,7 +837,7 @@ int inter_guild_calcinfo(struct guild *g) g->next_exp = nextexp; // Set the max number of members, Guild Extension skill - currently adds 6 to max per skill lv. - g->max_member = 16 + inter_guild->checkskill(g, GD_EXTENSION) * 6; + g->max_member = BASE_GUILD_SIZE + inter_guild->checkskill(g, GD_EXTENSION) * 6; if(g->max_member > MAX_GUILD) { ShowError("Guild %d:%s has capacity for too many guild members (%d), max supported is %d\n", g->guild_id, g->name, g->max_member, MAX_GUILD); @@ -1186,7 +1186,7 @@ int mapif_parse_CreateGuild(int fd,int account_id,char *name,struct guild_member g->member[0].modified = GS_MEMBER_MODIFIED; // Set default positions - g->position[0].mode=0x11; + g->position[0].mode = GPERM_BOTH; strcpy(g->position[0].name,"GuildMaster"); strcpy(g->position[MAX_GUILDPOSITION-1].name,"Newbie"); g->position[0].modified = g->position[MAX_GUILDPOSITION-1].modified = GS_POSITION_MODIFIED; @@ -1196,10 +1196,10 @@ int mapif_parse_CreateGuild(int fd,int account_id,char *name,struct guild_member } // Initialize guild property - g->max_member=16; - g->average_lv=master->lv; - g->connect_member=1; - g->guild_lv=1; + g->max_member = BASE_GUILD_SIZE; + g->average_lv = master->lv; + g->connect_member = 1; + g->guild_lv = 1; for(i=0;iskill[i].id=i + GD_SKILLBASE; @@ -1252,8 +1252,7 @@ int mapif_parse_GuildAddMember(int fd, int guild_id, struct guild_member *m) nullpo_ret(m); g = inter_guild->fromsql(guild_id); if(g==NULL){ - // Failed to add - mapif->guild_memberadded(fd,guild_id,m->account_id,m->char_id,1); + mapif->guild_memberadded(fd,guild_id,m->account_id,m->char_id,1); // 1: Failed to add return 0; } @@ -1264,7 +1263,7 @@ int mapif_parse_GuildAddMember(int fd, int guild_id, struct guild_member *m) { memcpy(&g->member[i],m,sizeof(struct guild_member)); g->member[i].modified = (GS_MEMBER_NEW | GS_MEMBER_MODIFIED); - mapif->guild_memberadded(fd,guild_id,m->account_id,m->char_id,0); + mapif->guild_memberadded(fd,guild_id,m->account_id,m->char_id,0); // 0: success if (!inter_guild->calcinfo(g)) //Send members if it was not invoked. mapif->guild_info(-1,g); @@ -1275,8 +1274,7 @@ int mapif_parse_GuildAddMember(int fd, int guild_id, struct guild_member *m) } } - // Failed to add - mapif->guild_memberadded(fd,guild_id,m->account_id,m->char_id,1); + mapif->guild_memberadded(fd,guild_id,m->account_id,m->char_id,1); // 1: Failed to add return 0; } @@ -1883,8 +1881,8 @@ int mapif_parse_GuildMasterChange(int fd, int guild_id, const char* name, int le // Data packet length that you set to inter.c //- Shouldn't do checking and packet length, RFIFOSKIP is done by the caller // Must Return -// 1 : ok -// 0 : error +// 1 : ok +// 0 : error int inter_guild_parse_frommap(int fd) { RFIFOHEAD(fd); diff --git a/src/char/int_party.c b/src/char/int_party.c index 79bd1139c..8d50c45fa 100644 --- a/src/char/int_party.c +++ b/src/char/int_party.c @@ -70,9 +70,10 @@ static void inter_party_calc_state(struct party_data *p) if(p->party.member[i].online) p->party.count++; } + // FIXME[Haru]: What if the occupied positions aren't the first three? It can happen if some party members leave. This is the reason why family sharing some times stops working until you recreate your party if( p->size == 2 && ( chr->char_child(p->party.member[0].char_id,p->party.member[1].char_id) || chr->char_child(p->party.member[1].char_id,p->party.member[0].char_id) ) ) { //Child should be able to share with either of their parents [RoM] - if(p->party.member[0].class_&0x2000) //first slot is the child? + if(p->party.member[0].class_&JOBL_BABY) //first slot is the child? p->family = p->party.member[0].char_id; else p->family = p->party.member[1].char_id; @@ -261,12 +262,12 @@ int inter_party_sql_init(void) exit(EXIT_FAILURE); } - /* Uncomment the following if you want to do a party_db cleanup (remove parties with no members) on startup.[Skotlex] +#if 0 // Enable if you want to do a party_db cleanup (remove parties with no members) on startup.[Skotlex] ShowStatus("cleaning party table...\n"); if( SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` USING `%s` LEFT JOIN `%s` ON `%s`.leader_id =`%s`.account_id AND `%s`.leader_char = `%s`.char_id WHERE `%s`.account_id IS NULL", party_db, party_db, char_db, party_db, char_db, party_db, char_db, char_db) ) Sql_ShowDebug(inter->sql_handle); - */ +#endif // 0 return 0; } @@ -594,7 +595,7 @@ int mapif_parse_PartyChangeOption(int fd,int party_id,int account_id,int exp,int int mapif_parse_PartyLeave(int fd, int party_id, int account_id, int char_id) { struct party_data *p; - int i,j=-1; + int i,j; p = inter_party->fromsql(party_id); if( p == NULL ) @@ -745,8 +746,8 @@ int mapif_parse_PartyLeaderChange(int fd, int party_id, int account_id, int char // Data packet length is set to inter.c that you // Do NOT go and check the packet length, RFIFOSKIP is done by the caller // Return : -// 0 : error -// 1 : ok +// 0 : error +// 1 : ok int inter_party_parse_frommap(int fd) { RFIFOHEAD(fd); diff --git a/src/char/inter.c b/src/char/inter.c index ec06df0f9..3571a3e2e 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -1219,9 +1219,9 @@ int mapif_parse_Registry(int fd) int mapif_parse_RegistryRequest(int fd) { //Load Char Registry - if (RFIFOB(fd,12)) mapif->account_reg_reply(fd,RFIFOL(fd,2),RFIFOL(fd,6),3); + if (RFIFOB(fd,12)) mapif->account_reg_reply(fd,RFIFOL(fd,2),RFIFOL(fd,6),3); // 3: char reg //Load Account Registry - if (RFIFOB(fd,11)) mapif->account_reg_reply(fd,RFIFOL(fd,2),RFIFOL(fd,6),2); + if (RFIFOB(fd,11)) mapif->account_reg_reply(fd,RFIFOL(fd,2),RFIFOL(fd,6),2); // 2: account reg //Ask Login Server for Account2 values. if (RFIFOB(fd,10)) chr->request_accreg2(RFIFOL(fd,2),RFIFOL(fd,6)); return 1; -- cgit v1.2.3-70-g09d2