From 80a251ef022f21f0165280ecda0e8c6c1d51b2e2 Mon Sep 17 00:00:00 2001 From: Aleos Date: Thu, 21 Sep 2017 11:41:57 -0400 Subject: [PATCH] Migrated clif.c to C++ (#2435) * Migrated clif.c to C++ * Needed in preparation for future projects. Thanks to @Daegaladh and @Mikegyver for testing! --- src/common/mmo.h | 2 +- src/map/{clif.c => clif.cpp} | 38 ++++++++++++++++++------------ src/map/map-server.vcxproj | 8 +++++-- src/map/map-server.vcxproj.filters | 2 +- src/map/unit.c | 4 ++-- 5 files changed, 33 insertions(+), 21 deletions(-) rename src/map/{clif.c => clif.cpp} (99%) diff --git a/src/common/mmo.h b/src/common/mmo.h index d793e162e9..670c3ff1e8 100644 --- a/src/common/mmo.h +++ b/src/common/mmo.h @@ -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; diff --git a/src/map/clif.c b/src/map/clif.cpp similarity index 99% rename from src/map/clif.c rename to src/map/clif.cpp index e3d4a5abfb..3e73656ed2 100644 --- a/src/map/clif.c +++ b/src/map/clif.cpp @@ -53,6 +53,10 @@ #include #include +#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 - .w .w ( : ).?B 00 /// true - .w .w .24B .?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 diff --git a/src/map/map-server.vcxproj b/src/map/map-server.vcxproj index 5fd8020415..061514db99 100644 --- a/src/map/map-server.vcxproj +++ b/src/map/map-server.vcxproj @@ -215,7 +215,9 @@ - + + CompileAsCpp + @@ -240,7 +242,9 @@ - + + CompileAsCpp + diff --git a/src/map/map-server.vcxproj.filters b/src/map/map-server.vcxproj.filters index f1ac1a1d17..ac66e5acb0 100644 --- a/src/map/map-server.vcxproj.filters +++ b/src/map/map-server.vcxproj.filters @@ -175,7 +175,7 @@ Source Files - + Source Files diff --git a/src/map/unit.c b/src/map/unit.c index ef713e1ed2..317c7a8be1 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -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);