Migrated clif.c to C++ (#2435)

* Migrated clif.c to C++
* Needed in preparation for future projects.
Thanks to @Daegaladh and @Mikegyver for testing!
This commit is contained in:
Aleos
2017-09-21 11:41:57 -04:00
committed by GitHub
parent 1bfe8475c8
commit 80a251ef02
5 changed files with 33 additions and 21 deletions

View File

@@ -517,7 +517,7 @@ struct mail_message {
char dest_name[NAME_LENGTH]; //receiver nickname
char title[MAIL_TITLE_LENGTH];
char body[MAIL_BODY_LENGTH];
int type; // enum mail_inbox_type
enum mail_inbox_type type;
time_t scheduled_deletion;
mail_status status;

View File

@@ -53,6 +53,10 @@
#include <stdarg.h>
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
/* for clif_clearunit_delayed */
static struct eri *delay_clearunit_ers;
@@ -213,7 +217,7 @@ int clif_setip(const char* ip) {
}
safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
ShowInfo("Map Server IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(map_ip, ip_str));
return 1;
}
@@ -222,7 +226,7 @@ void clif_setbindip(const char* ip)
bind_ip = host2ip(ip);
if (bind_ip) {
char ip_str[16];
ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
ShowInfo("Map Server Bind IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(bind_ip, ip_str));
} else {
ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
}
@@ -9875,7 +9879,7 @@ void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
/// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
/// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
char* seperator = " : ";
const char* seperator = " : ";
int fd;
struct s_packet_db* info;
uint16 packetLength, inputLength;
@@ -13206,7 +13210,7 @@ void clif_parse_OpenVending(int fd, struct map_session_data* sd){
bool flag;
len -= 85;
flag = (bool)RFIFOB(fd,info->pos[2]);
flag = RFIFOB(fd,info->pos[2]) != 0;
if (!flag) {
sd->state.prevend = 0;
sd->state.workinprogress = WIP_DISABLE_NONE;
@@ -15222,7 +15226,7 @@ void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
}
if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
intif_Mail_requestinbox(sd->status.char_id, 1, openType);
intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
return;
}
@@ -15534,7 +15538,7 @@ void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){
memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
}
intif_mail_getattach(sd,msg,attachment);
intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
clif_Mail_read(sd, mail_id);
}
@@ -16450,7 +16454,7 @@ void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
void clif_parse_EquipTick(int fd, struct map_session_data* sd)
{
//int type = RFIFOL(fd,packet_db[cmd].pos[0]);
bool flag = (bool)RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
bool flag = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]) != 0;
sd->status.show_equip = flag;
clif_equiptickack(sd, flag);
}
@@ -20022,11 +20026,11 @@ static int clif_parse(int fd)
//Disassociate character from the socket connection.
session[fd]->session_data = NULL;
sd->fd = 0;
ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
} else
if (sd->state.active) {
// Player logout display [Valaris]
ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
clif_quitsave(fd, sd);
} else {
//Unusual logout (during log on/off/map-changer procedure)
@@ -20034,7 +20038,7 @@ static int clif_parse(int fd)
map_quit(sd);
}
} else {
ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
}
do_close(fd);
return 0;
@@ -20173,12 +20177,12 @@ void packetdb_readdb(){
#include "clif_packetdb.h"
#include "clif_shuffle.h"
ShowStatus("Using packet version: "CL_WHITE"%d"CL_RESET".\n", PACKETVER);
ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
#ifdef PACKET_OBFUSCATION
ShowStatus("Packet Obfuscation: "CL_GREEN"Enabled"CL_RESET". Keys: "CL_WHITE"0x%08X, 0x%08X, 0x%08X"CL_RESET"\n", clif_cryptKey[0], clif_cryptKey[1], clif_cryptKey[2]);
ShowStatus("Packet Obfuscation: " CL_GREEN "Enabled" CL_RESET ". Keys: " CL_WHITE "0x%08X, 0x%08X, 0x%08X" CL_RESET "\n", clif_cryptKey[0], clif_cryptKey[1], clif_cryptKey[2]);
#else
ShowStatus("Packet Obfuscation: "CL_RED"Disabled"CL_RESET".\n");
ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
#endif
}
@@ -20207,16 +20211,20 @@ void do_init_clif(void) {
set_defaultparse(clif_parse);
if( make_listen_bind(bind_ip,map_port) == -1 ) {
ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",map_port);
ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
exit(EXIT_FAILURE);
}
add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
add_timer_func_list(clif_delayquit, "clif_delayquit");
delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.c::delay_clearunit_ers",ERS_OPT_CLEAR);
delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
}
void do_final_clif(void) {
ers_destroy(delay_clearunit_ers);
}
#ifdef __cplusplus
}
#endif

View File

@@ -215,7 +215,9 @@
<ClCompile Include="chat.c" />
<ClCompile Include="chrif.c" />
<ClCompile Include="clan.c" />
<ClCompile Include="clif.c" />
<ClCompile Include="clif.cpp">
<CompileAs>CompileAsCpp</CompileAs>
</ClCompile>
<ClCompile Include="date.c" />
<ClCompile Include="duel.c" />
<ClCompile Include="elemental.c" />
@@ -240,7 +242,9 @@
<ClCompile Include="pc_groups.c" />
<ClCompile Include="pet.c" />
<ClCompile Include="quest.c" />
<ClCompile Include="script.cpp" />
<ClCompile Include="script.cpp">
<CompileAs>CompileAsCpp</CompileAs>
</ClCompile>
<ClCompile Include="searchstore.c" />
<ClCompile Include="skill.c" />
<ClCompile Include="status.c" />

View File

@@ -175,7 +175,7 @@
<ClCompile Include="clan.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="clif.c">
<ClCompile Include="clif.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="date.c">

View File

@@ -1602,7 +1602,7 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui
if( battle_config.ksprotection && sd && mob_ksprotected(src, target) )
return 0;
// Normally not needed because clif.c checks for it, but the at/char/script commands don't! [Skotlex]
// Normally not needed because clif.cpp checks for it, but the at/char/script commands don't! [Skotlex]
if(ud->skilltimer != INVALID_TIMER && skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST)
return 0;
@@ -1965,7 +1965,7 @@ int unit_skilluse_pos2( struct block_list *src, short skill_x, short skill_y, ui
if (ud && ud->state.blockedskill)
return 0;
if(ud->skilltimer != INVALID_TIMER) // Normally not needed since clif.c checks for it, but at/char/script commands don't! [Skotlex]
if(ud->skilltimer != INVALID_TIMER) // Normally not needed since clif.cpp checks for it, but at/char/script commands don't! [Skotlex]
return 0;
sc = status_get_sc(src);