diff options
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/chrif.cpp | 24 | ||||
-rw-r--r-- | src/map/chrif.hpp | 2 | ||||
-rw-r--r-- | src/map/clif.cpp | 27 | ||||
-rw-r--r-- | src/map/fwd.hpp | 2 | ||||
-rw-r--r-- | src/map/globals.cpp | 3 | ||||
-rw-r--r-- | src/map/globals.hpp | 3 | ||||
-rw-r--r-- | src/map/intif.cpp | 10 | ||||
-rw-r--r-- | src/map/map.hpp | 15 |
8 files changed, 83 insertions, 3 deletions
diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp index 42a13cf..9361c2e 100644 --- a/src/map/chrif.cpp +++ b/src/map/chrif.cpp @@ -340,6 +340,30 @@ int chrif_charselectreq(dumb_ptr<map_session_data> sd) return 0; } +void chrif_parse_preauth(Session *s, const Packet_Fixed<0x3829>& fixed) +{ + if (auth_fifo_iter == auth_fifo.end()) + auth_fifo_iter = auth_fifo.begin(); + auth_fifo_iter->account_id = fixed.account_id; + auth_fifo_iter->char_id = fixed.char_id; + auth_fifo_iter->login_id1 = fixed.login_id1; + auth_fifo_iter->login_id2 = fixed.login_id2; + auth_fifo_iter->ip = fixed.ip; + auth_fifo_iter->delflag = 0; + auth_fifo_iter++; + + // tell char server we accepted the auth details + Packet_Fixed<0x3830> fixed_3830; + fixed_3830.account_id = fixed.account_id; + fixed_3830.char_id = fixed.char_id; + fixed_3830.login_id1 = fixed.login_id1; + fixed_3830.login_id2 = fixed.login_id2; + fixed_3830.ip = fixed.ip; + send_fpacket<0x3830, 22>(s, fixed_3830); + + MAP_LOG_AND_ECHO("Received pre-auth details for account %d [%s], replying to char server\n"_fmt, fixed.account_id, fixed.ip); +} + /*========================================== * Change Email *------------------------------------------ diff --git a/src/map/chrif.hpp b/src/map/chrif.hpp index 655103d..ea8096c 100644 --- a/src/map/chrif.hpp +++ b/src/map/chrif.hpp @@ -44,6 +44,8 @@ void chrif_char_ask_name(AccountId id, CharName character_name, short operation_ int chrif_saveaccountreg2(dumb_ptr<map_session_data> sd); int chrif_send_divorce(CharId char_id); +void chrif_parse_preauth(Session *s, const Packet_Fixed<0x3829>& fixed); + void do_init_chrif(void); } // namespace map } // namespace tmwa diff --git a/src/map/clif.cpp b/src/map/clif.cpp index f2667ac..a2f3b3a 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -3539,15 +3539,36 @@ RecvResult clif_parse_WantToConnection(Session *s, dumb_ptr<map_session_data> sd if (rv != RecvResult::Complete) return rv; - { - account_id = fixed.account_id; - } + account_id = fixed.account_id; // formerly: account id Packet_Payload<0x8000> special; special.magic_packet_length = 4; send_ppacket<0x8000>(s, special); + bool is_valid = false; + for (AuthFifoEntry& afi : auth_fifo) + { + if (afi.account_id == fixed.account_id + && afi.char_id == fixed.char_id + && afi.login_id1 == fixed.login_id1 + //&& afi.login_id2 == sd->login_id2 + && afi.ip == s->client_ip + && afi.delflag == 0) + { + is_valid = true; + afi.delflag = 1; + break; + } + } + + if (!is_valid) + { + MAP_LOG_AND_ECHO("Attempt to connect without correct authentication (REJECTED IP: %s)!\n"_fmt, s->client_ip); + s->set_eof(); + return RecvResult::Complete; + } + // if same account already connected, we disconnect the 2 sessions dumb_ptr<map_session_data> old_sd = map_id2sd(account_to_block(account_id)); if (old_sd) diff --git a/src/map/fwd.hpp b/src/map/fwd.hpp index 74e0ccf..fc6b284 100644 --- a/src/map/fwd.hpp +++ b/src/map/fwd.hpp @@ -69,5 +69,7 @@ struct ScriptState; struct str_data_t; class SIR; +struct AuthFifoEntry; + } // namespace map } // namespace tmwa diff --git a/src/map/globals.cpp b/src/map/globals.cpp index 49d6074..97533c8 100644 --- a/src/map/globals.cpp +++ b/src/map/globals.cpp @@ -51,6 +51,9 @@ namespace tmwa Map<ItemNameId, item_data> item_db; Map<QuestId, quest_data> quest_db; + std::array<AuthFifoEntry, 256> auth_fifo; + decltype(auth_fifo)::iterator auth_fifo_iter = auth_fifo.begin(); + DMap<BlockId, dumb_ptr<block_list>> id_db; UPMap<MapName, map_abstract> maps_db; DMap<CharName, dumb_ptr<map_session_data>> nick_db; diff --git a/src/map/globals.hpp b/src/map/globals.hpp index 1c8e70d..acf52fd 100644 --- a/src/map/globals.hpp +++ b/src/map/globals.hpp @@ -95,5 +95,8 @@ namespace tmwa extern earray<skill_db_, SkillID, SkillID::MAX_SKILL_DB> skill_db; extern BlockId skill_area_temp_id; extern int skill_area_temp_hp; + + extern std::array<AuthFifoEntry, 256> auth_fifo; + extern AuthFifoEntry *auth_fifo_iter; } // namespace map } // namespace tmwa diff --git a/src/map/intif.cpp b/src/map/intif.cpp index fc34a64..379bb1d 100644 --- a/src/map/intif.cpp +++ b/src/map/intif.cpp @@ -743,6 +743,16 @@ RecvResult intif_parse(Session *s, uint16_t packet_id) intif_parse_PartyLeaderChanged(s, fixed); break; } + case 0x3829: + { + Packet_Fixed<0x3829> fixed; + rv = recv_fpacket<0x3829, 22>(s, fixed); + if (rv != RecvResult::Complete) + return rv; + + chrif_parse_preauth(s, fixed); + break; + } default: return RecvResult::Error; } diff --git a/src/map/map.hpp b/src/map/map.hpp index 24037e9..2f6ef21 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -584,6 +584,12 @@ void map_log(XString line); #define MAP_LOG(format, ...) \ map_log(STRPRINTF(format, ## __VA_ARGS__)) +#define MAP_LOG_AND_ECHO(...) \ + do { \ + PRINTF(__VA_ARGS__); \ + MAP_LOG(__VA_ARGS__); \ + } while (0) + #define MAP_LOG_PC(sd, fmt, ...) \ MAP_LOG("PC%d %s:%d,%d " fmt, \ sd->status_key.char_id, (sd->bl_m->name_), sd->bl_x, sd->bl_y, ## __VA_ARGS__) @@ -692,5 +698,14 @@ struct charid2nick CharName nick; int req_id; }; + +struct AuthFifoEntry +{ + AccountId account_id; + CharId char_id; + int login_id1, login_id2; + IP4Address ip; + int delflag; +}; } // namespace map } // namespace tmwa |