From 87f9bae4da0314e97f1a3e38513960998ee4d05d Mon Sep 17 00:00:00 2001 From: mekolat Date: Tue, 12 May 2015 21:40:18 -0400 Subject: use client version --- src/char/char.cpp | 14 +++++++------- src/char/char.hpp | 2 +- src/map/chrif.cpp | 4 ++-- src/map/clif.cpp | 2 +- src/map/map.hpp | 2 +- src/map/pc.cpp | 7 ++++--- src/map/pc.hpp | 2 +- src/map/script-fun.cpp | 8 ++++++++ tools/protocol.py | 4 ++-- 9 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/char/char.cpp b/src/char/char.cpp index ed9e369..345265f 100644 --- a/src/char/char.cpp +++ b/src/char/char.cpp @@ -98,7 +98,7 @@ struct char_session_data : SessionData AccountId account_id; int login_id1, login_id2; SEX sex; - unsigned short packet_tmw_version; + unsigned short packet_client_version; AccountEmail email; }; } // namespace char_ @@ -1673,10 +1673,10 @@ void parse_frommap(Session *ms) payload_fd.account_id = account_id; payload_fd.login_id2 = afi.login_id2; cd->sex = afi.sex; - payload_fd.packet_tmw_version = afi.packet_tmw_version; + payload_fd.packet_client_version = afi.packet_client_version; FPRINTF(stderr, "From queue index %zd: recalling packet version %d\n"_fmt, - (&afi - &auth_fifo.front()), afi.packet_tmw_version); + (&afi - &auth_fifo.front()), afi.packet_client_version); payload_fd.char_key = *ck; payload_fd.char_data = *cd; send_ppacket<0x2afd>(ms, payload_fd); @@ -2180,7 +2180,7 @@ void handle_x0066(Session *s, struct char_session_data *sd, uint8_t rfifob_2, IP auth_fifo_iter->delflag = 0; auth_fifo_iter->sex = sd->sex; auth_fifo_iter->ip = s->client_ip; - auth_fifo_iter->packet_tmw_version = sd->packet_tmw_version; + auth_fifo_iter->packet_client_version = sd->packet_client_version; auth_fifo_iter++; } } @@ -2251,7 +2251,7 @@ void parse_char(Session *s) sd->account_id = account_id; sd->login_id1 = fixed.login_id1; sd->login_id2 = fixed.login_id2; - sd->packet_tmw_version = fixed.packet_tmw_version; + sd->packet_client_version = fixed.packet_client_version; sd->sex = fixed.sex; // formerly: send back account_id @@ -2280,8 +2280,8 @@ void parse_char(Session *s) send_fpacket<0x2716, 6>(login_session, fixed_16); } // Record client version - afi.packet_tmw_version = - sd->packet_tmw_version; + afi.packet_client_version = + sd->packet_client_version; // send characters to player mmo_char_send006b(s, sd); } diff --git a/src/char/char.hpp b/src/char/char.hpp index 4f55c04..049875b 100644 --- a/src/char/char.hpp +++ b/src/char/char.hpp @@ -50,7 +50,7 @@ struct AuthFifoEntry IP4Address ip; int delflag; SEX sex; - unsigned short packet_tmw_version; + unsigned short packet_client_version; }; struct mmo_map_server diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp index 8127f20..ce5669e 100644 --- a/src/map/chrif.cpp +++ b/src/map/chrif.cpp @@ -867,11 +867,11 @@ void chrif_parse(Session *s) AccountId id = payload.account_id; int login_id2 = payload.login_id2; - short tmw_version = payload.packet_tmw_version; + short client_version = payload.packet_client_version; CharKey st_key = payload.char_key; CharData st_data = payload.char_data; pc_authok(id, login_id2, - tmw_version, + client_version, &st_key, &st_data); break; } diff --git a/src/map/clif.cpp b/src/map/clif.cpp index 6074c43..f94c316 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -2654,7 +2654,7 @@ void clif_skillinfoblock(dumb_ptr sd) std::vector> repeat_10f; for (SkillID i : erange(SkillID(), MAX_SKILL)) { - if (sd->status.skill[i].lv && sd->tmw_version >= 1) + if (sd->status.skill[i].lv && sd->client_version >= 1) { Packet_Repeat<0x010f> info; // [Fate] Version 1 and later don't crash because of bad skill IDs anymore diff --git a/src/map/map.hpp b/src/map/map.hpp index f57dcee..ce434fa 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -153,7 +153,7 @@ struct map_session_data : block_list, SessionData CharId char_id_; int login_id1, login_id2; SEX sex; - unsigned char tmw_version; // tmw client version + int client_version; // tmw client version CharKey status_key; CharData status; GenericArray>, InventoryIndexing> inventory_data = diff --git a/src/map/pc.cpp b/src/map/pc.cpp index 1179792..cb81e29 100644 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -641,7 +641,7 @@ int pc_isequip(dumb_ptr sd, IOff0 n) *------------------------------------------ */ int pc_authok(AccountId id, int login_id2, - short tmw_version, const CharKey *st_key, const CharData *st_data) + short client_version, const CharKey *st_key, const CharData *st_data) { dumb_ptr sd = nullptr; @@ -652,7 +652,7 @@ int pc_authok(AccountId id, int login_id2, return 1; sd->login_id2 = login_id2; - sd->tmw_version = tmw_version; + sd->client_version = client_version; sd->status_key = *st_key; sd->status = *st_data; @@ -797,7 +797,8 @@ int pc_authok(AccountId id, int login_id2, pc_calcstatus(sd, 1); // Init Quest Log - clif_sendallquest(sd); + if(sd->client_version >= 2) + clif_sendallquest(sd); return 0; } diff --git a/src/map/pc.hpp b/src/map/pc.hpp index d100938..fc0bdb0 100644 --- a/src/map/pc.hpp +++ b/src/map/pc.hpp @@ -80,7 +80,7 @@ int pc_counttargeted(dumb_ptr sd, dumb_ptr src, int pc_setrestartvalue(dumb_ptr sd, int type); void pc_makesavestatus(dumb_ptr); int pc_setnewpc(dumb_ptr, AccountId, CharId, int, uint32_t /*tick_t*/, SEX); -int pc_authok(AccountId, int, short tmw_version, const CharKey *, const CharData *); +int pc_authok(AccountId, int, short client_version, const CharKey *, const CharData *); int pc_authfail(AccountId accid); EPOS pc_equippoint(dumb_ptr sd, IOff0 n); diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index 744f2c3..9020203 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -971,6 +971,13 @@ void builtin_delitem(ScriptState *st) } +static +void builtin_getversion(ScriptState *st) +{ + dumb_ptr sd = script_rid2sd(st);; + push_int(st->stack, sd->client_version); +} + /*========================================== *キャラ関係のID取得 *------------------------------------------ @@ -3028,6 +3035,7 @@ BuiltinFunction builtin_functions[] = BUILTIN(makeitem, "IiMxy"_s, '\0'), BUILTIN(delitem, "Ii"_s, '\0'), BUILTIN(getcharid, "i?"_s, 'i'), + BUILTIN(getversion, ""_s, 'i'), BUILTIN(strcharinfo, "i"_s, 's'), BUILTIN(getequipid, "i"_s, 'i'), BUILTIN(bonus, "ii"_s, '\0'), diff --git a/tools/protocol.py b/tools/protocol.py index 688821f..f13d627 100755 --- a/tools/protocol.py +++ b/tools/protocol.py @@ -1984,7 +1984,7 @@ def build_context(): at(2, account_id, 'account id'), at(6, u32, 'login id1'), at(10, u32, 'login id2'), - at(14, u16, 'packet tmw version'), + at(14, u16, 'packet client version'), at(16, sex, 'sex'), ], fixed_size=17, @@ -5124,7 +5124,7 @@ def build_context(): at(4, account_id, 'account id'), at(8, u32, 'login id2'), at(12, time32, 'unused connect until'), - at(16, u16, 'packet tmw version'), + at(16, u16, 'packet client version'), at(18, char_key, 'char key'), at(None, char_data, 'char data'), ], -- cgit v1.2.3-70-g09d2 From 48021640ce0e76f1dfd7527b88fa33f2b74f4909 Mon Sep 17 00:00:00 2001 From: mekolat Date: Sun, 17 May 2015 16:59:59 -0400 Subject: reject very old manaplus versions --- src/char/char.cpp | 9 +++++++++ src/char/char.hpp | 3 +++ 2 files changed, 12 insertions(+) diff --git a/src/char/char.cpp b/src/char/char.cpp index 345265f..7ad6dff 100644 --- a/src/char/char.cpp +++ b/src/char/char.cpp @@ -62,6 +62,7 @@ #include "../proto2/any-user.hpp" #include "../proto2/login-admin.hpp" #include "../proto2/login-char.hpp" +#include "../proto2/login-user.hpp" #include "../proto2/char-map.hpp" #include "../proto2/char-user.hpp" @@ -2259,6 +2260,14 @@ void parse_char(Session *s) special.magic_packet_length = 4; send_ppacket<0x8000>(s, special); + if(sd->packet_client_version < MIN_CLIENT_VERSION) + { + Packet_Fixed<0x006a> fixed_6a; + fixed_6a.error_code = 5; + send_fpacket<0x006a, 23>(s, fixed_6a); + goto x65_out; + } + // search authentification for (AuthFifoEntry& afi : auth_fifo) { diff --git a/src/char/char.hpp b/src/char/char.hpp index 049875b..8adac4d 100644 --- a/src/char/char.hpp +++ b/src/char/char.hpp @@ -42,6 +42,9 @@ std::chrono::seconds DEFAULT_AUTOSAVE_INTERVAL = 5_min; constexpr GmLevel default_gm_level = GmLevel::from(0_u32); +// increase the min version when the protocol is incompatible with old m+ versions +#define MIN_CLIENT_VERSION 1 + struct AuthFifoEntry { AccountId account_id; -- cgit v1.2.3-70-g09d2 From 519deab5c846169b05b92ca9721dadccd476632f Mon Sep 17 00:00:00 2001 From: mekolat Date: Mon, 18 May 2015 10:08:22 -0400 Subject: add version check to mob walkpath --- src/map/clif.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/map/clif.cpp b/src/map/clif.cpp index f94c316..327283a 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -825,6 +825,21 @@ void clif_mob007b(dumb_ptr md, Buffer& buf) * Packet to send server's mob walkpath data *------------------------------------------ */ +static +void clif_0225_being_move3_sub(dumb_ptr bl, const Buffer& buf) +{ + nullpo_retv(bl); + dumb_ptr sd = bl->is_player(); + + if (sd->sess != nullptr) + { + if(sd->client_version >= 3) + { + send_buffer(sd->sess, buf); + } + } +} + static int clif_0225_being_move3(dumb_ptr md) { @@ -844,7 +859,12 @@ int clif_0225_being_move3(dumb_ptr md) } Buffer buf = create_vpacket<0x0225, 14, 1>(head_225, repeat_225); - clif_send(buf, md, SendWho::AREA); + + map_foreachinarea(std::bind(clif_0225_being_move3_sub, ph::_1, buf), + md->bl_m, + md->bl_x - AREA_SIZE, md->bl_y - AREA_SIZE, + md->bl_x + AREA_SIZE, md->bl_y + AREA_SIZE, + BL::PC); return 0; } -- cgit v1.2.3-70-g09d2 From a94330e0b5916ddecd98c2fca58ca6799c0770c2 Mon Sep 17 00:00:00 2001 From: mekolat Date: Mon, 18 May 2015 13:00:37 -0400 Subject: add version check to clif_sendquest --- src/map/clif.cpp | 6 ++++++ src/map/pc.cpp | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/map/clif.cpp b/src/map/clif.cpp index 327283a..2b4570e 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -4724,6 +4724,9 @@ void clif_sendallquest(dumb_ptr sd) if (!sd->sess) return; + if(sd->client_version < 2) + return; + Session *s = sd->sess; Packet_Head<0x0215> head_215; std::vector> repeat_215; @@ -4758,6 +4761,9 @@ void clif_sendquest(dumb_ptr sd, QuestId questid, int value) if (!sd->sess) return; + if(sd->client_version < 2) + return; + Session *s = sd->sess; Packet_Fixed<0x0214> fixed; diff --git a/src/map/pc.cpp b/src/map/pc.cpp index cb81e29..d2b2f44 100644 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -797,8 +797,7 @@ int pc_authok(AccountId id, int login_id2, pc_calcstatus(sd, 1); // Init Quest Log - if(sd->client_version >= 2) - clif_sendallquest(sd); + clif_sendallquest(sd); return 0; } -- cgit v1.2.3-70-g09d2