Pol  Revision:cb584c9
msghandl.h
Go to the documentation of this file.
1 
8 #ifndef MSGHANDL_H
9 #define MSGHANDL_H
10 
11 #include "../pktboth.h"
12 #include "../pktin.h"
13 #include "../pktout.h"
14 
15 namespace Pol
16 {
17 namespace Network
18 {
19 class Client;
20 
21 
22 enum class PacketVersion
23 {
24  V1 = 1, // The default, used by the earlier client versions
25  V2 = 2, // Used to handle packets which were redefined after 6.0.1.7
26  Default = V1
27 };
28 
29 typedef void ( *PktHandlerFunc )( Client* client, void* msg );
30 
31 typedef struct
32 {
33  int msglen; // if 0, no message handler defined.
35 } MSG_HANDLER;
36 
37 // extended cmds (0x12)
39 {
40  EXTMSGID_SKILL = 0x24, // Form: "SkillId parameter" (SkillId 0-based, param usu. 0)
41  EXTMSGID_CASTSPELL1 = 0x27, // Form: "SpellId SpellBookSerial"
42  EXTMSGID_SPELLBOOK = 0x43, // Form: (empty)
43  EXTMSGID_CASTSPELL2 = 0x56, // Form: "SpellId"
44  EXTMSGID_OPENDOOR = 0x58, // Form: (empty)
45  EXTMSGID_ACTION = 0xC7 // Form: "action_name"
46 };
47 // Extended messages come in the form of a null-terminated string. The
48 // "Extended Message" message handler validates that the string is in
49 // fact null terminated where it's supposed to be. It does not currently
50 // verify that the string isn't terminated early also, or that the string
51 // only contains printables.
53 {
54  void ( *func )( Client* client, Core::PKTIN_12* msg );
55 };
56 
57 // Class for keeping the message handlers
59 {
60 public:
61  // Returns true if the message is defined in either original or v2 packet handlers
62  static bool is_defined( unsigned char msgid );
63 
64  // Returns the message length (or 0 if undefined)
65  static int msglen( unsigned char msgid );
66 
67  // Returns the message length (or 0 if undefined) for a v2 packet
68  static int msglen_v2( unsigned char msgid );
69 
70  // Registers a handler for a certain message type
71  static void set_handler( unsigned char msgid, int len, PktHandlerFunc func,
72  PacketVersion version = PacketVersion::V1 );
73 
74  // Returns the callback function for the handler of a certain message type
75  static PktHandlerFunc get_callback( unsigned char msgid,
76  PacketVersion version = PacketVersion::V1 );
77 
78  // Finds the appropriate handler for a message type according to client version
79  static MSG_HANDLER find_handler( unsigned char msgid, const Client* client );
80 
81  // Handles the specific message type by invoking the callback according to client version
82  static void handle_msg( unsigned char msgid, Client* client, void* data );
83 
84  // registers all pkts, called once on startup
85  static void initialize_msg_handlers();
86 
87  // handler for pkt 12 to call sub handlers
88  static void handle_extended_cmd( Client* client, Core::PKTIN_12* msg );
89 
90 private:
91  // registers all externed handlers (0x12)
92  static void initialize_extended_handlers();
93  static void set_extended_handler( UEXTMSGID submsgtype,
94  void ( *func )( Client* client, Core::PKTIN_12* msg ) );
95 };
96 
97 
98 #define MSGLEN_2BYTELEN_DATA -2
99 
100 
101 } // namspace Network
102 namespace Mobile
103 {
104 void handle_attack( Network::Client* client, Core::PKTIN_05* msg );
105 }
106 namespace Module
107 {
108 void handle_resurrect_menu( Network::Client* client, Core::PKTBI_2C* msg );
109 void handle_selcolor( Network::Client* client, Core::PKTBI_95* msg );
110 void open_book_handler( Network::Client* client, Core::PKTBI_93* msg );
111 void buyhandler( Network::Client* client, Core::PKTBI_3B* msg );
112 void sellhandler( Network::Client* client, Core::PKTIN_9F* msg );
113 void gumpbutton_handler( Network::Client* client, Core::PKTIN_B1* msg );
114 void handle_textentry( Network::Client* client, Core::PKTIN_AC* msg );
115 void read_book_page_handler( Network::Client* client, Core::PKTBI_66* msg );
116 }
117 namespace Core
118 {
119 void ClientCreateChar( Network::Client* client, PKTIN_00* msg );
120 void ClientCreateCharKR( Network::Client* client, PKTIN_8D* msg );
121 void ClientCreateChar70160( Network::Client* client, PKTIN_F8* msg );
122 void doubleclick( Network::Client* client, PKTIN_06* msg );
123 void drop_item( Network::Client* client, PKTIN_08_V1* msg );
124 void drop_item_v2( Network::Client* client, PKTIN_08_V2* msg );
125 void equip_item( Network::Client* client, PKTIN_13* msg );
126 void get_item( Network::Client* client, PKTIN_07* msg );
127 void handle_help( Network::Client* client, PKTIN_9B* msg );
128 void handle_skill_lock( Network::Client* client, PKTBI_3A_LOCKS* msg );
129 void srequest( Network::Client* client, PKTIN_34* msg );
130 void loginserver_login( Network::Client* client, PKTIN_80* msg );
131 void handle_A4( Network::Client* client, PKTIN_A4* msg );
132 void handle_D9( Network::Client* client, PKTIN_D9* msg );
133 void select_server( Network::Client* client, PKTIN_A0* msg );
134 void login2( Network::Client* client, PKTIN_91* msg );
135 void handle_delete_character( Network::Client* client, PKTIN_83* msg );
136 void handle_menu_selection( Network::Client* client, PKTIN_7D* msg );
137 void handle_mode_set( Network::Client* client, PKTBI_72* msg );
138 void handle_rename_char( Network::Client* client, PKTIN_75* msg );
139 void handle_msg_B5( Network::Client* client, PKTIN_B5* msg );
140 void handle_msg_BB( Network::Client* client, PKTBI_BB* msg );
141 void handle_unknown_C4( Network::Client* client, PKTOUT_C4* msg );
142 void handle_update_range_change( Network::Client* client, PKTBI_C8* msg );
143 void handle_allnames( Network::Client* client, PKTBI_98_IN* msg );
144 void handle_ef_seed( Network::Client* client, PKTIN_EF* msg );
145 void handle_e1_clienttype( Network::Client* client, PKTIN_E1* msg );
146 void handle_walk( Network::Client* client, PKTIN_02* msg02 );
147 void char_select( Network::Client* client, PKTIN_5D* msg );
148 void handle_resync_request( Network::Client* client, PKTBI_22_SYNC* msg );
149 void handle_keep_alive( Network::Client* client, PKTBI_73* msg );
150 void handle_singleclick( Network::Client* client, PKTIN_09* msg );
151 void handle_target_cursor( Network::Client* client, PKTBI_6C* msg );
152 void handle_get_tip( Network::Client* client, PKTIN_A7* msg );
153 void handle_request_tooltip( Network::Client* client, PKTIN_B6* msgin );
154 void handle_map_pin( Network::Client* client, PKTBI_56* msg );
155 void handle_unicode_prompt( Network::Client* client, Core::PKTBI_C2* msg );
156 void handle_secure_trade_msg( Network::Client* client, PKTBI_6F* msg );
157 void handle_prompt( Network::Client* client, PKTBI_9A* msg );
158 void KR_Verifier_Response( Network::Client* client, PKTIN_E4* msg );
159 void handle_bulletin_boards( Network::Client* client, PKTBI_71* msg );
160 void handle_char_profile_request( Network::Client* client, PKTBI_B8_IN* msg );
161 void handle_client_version( Network::Client* client, PKTBI_BD* msg );
162 void handle_msg_BF( Network::Client* client, PKTBI_BF* msg );
163 void handle_se_object_list( Network::Client* client, PKTBI_D6_IN* msgin );
164 void handle_aos_commands( Network::Client* client, PKTBI_D7* msg );
165 void SpeechHandler( Network::Client* client, PKTIN_03* mymsg );
166 void UnicodeSpeechHandler( Network::Client* client, PKTIN_AD* msgin );
167 
168 void handle_action( Network::Client* client, PKTIN_12* cmd );
169 void handle_cast_spell( Network::Client* client, PKTIN_12* msg );
170 void handle_open_spellbook( Network::Client* client, PKTIN_12* msg );
171 void handle_use_skill( Network::Client* client, PKTIN_12* msg );
172 }
173 }
174 #endif
void equip_item(Network::Client *client, PKTIN_13 *msg)
Definition: eqpitem.cpp:30
void ClientCreateChar(Network::Client *client, PKTIN_00 *msg)
Definition: create.cpp:201
void handle_target_cursor(Network::Client *client, PKTBI_6C *msg)
Definition: target.cpp:37
void handle_attack(Network::Client *client, Core::PKTIN_05 *msg)
Definition: attack.cpp:28
void handle_secure_trade_msg(Network::Client *client, PKTBI_6F *msg)
Definition: dropitem.cpp:1057
void(* PktHandlerFunc)(Client *client, void *msg)
Definition: msghandl.h:29
void handle_msg_BB(Client *client, PKTBI_BB *)
Definition: miscmsg.cpp:207
void char_select(Network::Client *client, PKTIN_5D *msg)
Definition: pol.cpp:385
void handle_mode_set(Client *client, PKTBI_72 *msg)
Definition: miscmsg.cpp:87
void open_book_handler(Client *client, PKTBI_93 *msg)
Definition: uomod2.cpp:2434
void handle_char_profile_request(Client *client, PKTBI_B8_IN *msg)
Definition: miscmsg.cpp:151
void handle_msg_BF(Client *client, PKTBI_BF *msg)
Definition: miscmsg.cpp:306
void handle_open_spellbook(Network::Client *client, PKTIN_12 *msg)
Definition: spells.cpp:357
PktHandlerFunc func
Definition: msghandl.h:34
void handle_get_tip(Network::Client *client, PKTIN_A7 *msg)
Definition: tips.cpp:59
void gumpbutton_handler(Client *client, PKTIN_B1 *msg)
Definition: uomod2.cpp:1421
void handle_delete_character(Network::Client *client, PKTIN_83 *msg)
Definition: login.cpp:486
void handle_map_pin(Network::Client *client, PKTBI_56 *msg)
Definition: umap.cpp:358
void loginserver_login(Network::Client *client, PKTIN_80 *msg)
Definition: login.cpp:106
void login2(Network::Client *client, PKTIN_91 *msg)
Definition: login.cpp:388
void handle_keep_alive(Network::Client *client, PKTBI_73 *msg)
Definition: pol.cpp:500
void get_item(Network::Client *client, PKTIN_07 *msg)
Definition: getitem.cpp:58
void KR_Verifier_Response(Network::Client *, PKTIN_E4 *)
Definition: login.cpp:517
void handle_prompt(Network::Client *client, PKTBI_9A *msg)
Definition: getmsg.cpp:41
void handle_ef_seed(Client *client, PKTIN_EF *msg)
Definition: miscmsg.cpp:471
void handle_client_version(Client *client, PKTBI_BD *msg)
Definition: miscmsg.cpp:212
void handle_e1_clienttype(Client *client, PKTIN_E1 *msg)
Definition: miscmsg.cpp:508
void handle_help(Network::Client *client, PKTIN_9B *)
Definition: help.cpp:20
void handle_allnames(Client *client, PKTBI_98_IN *msg)
Definition: miscmsg.cpp:428
void drop_item(Network::Client *client, PKTIN_08_V1 *msg)
Definition: dropitem.cpp:792
void srequest(Network::Client *client, PKTIN_34 *msg)
Definition: irequest.cpp:145
void handle_cast_spell(Network::Client *client, PKTIN_12 *msg)
Definition: spells.cpp:349
void UnicodeSpeechHandler(Network::Client *client, PKTIN_AD *msgin)
Definition: speech.cpp:432
void handle_resync_request(Network::Client *client, PKTBI_22_SYNC *msg)
Definition: pol.cpp:483
void handle_bulletin_boards(Client *client, PKTBI_71 *)
Definition: miscmsg.cpp:82
void doubleclick(Network::Client *client, PKTIN_06 *msg)
Definition: dblclick.cpp:78
void handle_rename_char(Client *client, PKTIN_75 *msg)
Definition: miscmsg.cpp:107
void handle_textentry(Client *client, PKTIN_AC *msg)
Definition: uomod2.cpp:1623
void handle_A4(Network::Client *, PKTIN_A4 *)
Definition: login.cpp:225
void handle_menu_selection(Network::Client *client, PKTIN_7D *msg)
Definition: menusel.cpp:22
std::unordered_map< u64, ScriptDiffData > data
Definition: osmod.cpp:966
void handle_unicode_prompt(Client *client, Core::PKTBI_C2 *msg)
Definition: unimod.cpp:48
void buyhandler(Client *client, PKTBI_3B *msg)
Definition: uomod2.cpp:548
void handle_singleclick(Network::Client *client, PKTIN_09 *msg)
Definition: sngclick.cpp:126
void handle_action(Network::Client *client, PKTIN_12 *cmd)
Definition: bowsalut.cpp:247
void handle_skill_lock(Network::Client *client, PKTBI_3A_LOCKS *msg)
Definition: irequest.cpp:105
void handle_msg_B5(Client *client, PKTIN_B5 *)
Definition: miscmsg.cpp:146
void handle_request_tooltip(Network::Client *client, PKTIN_B6 *msgin)
Definition: tooltips.cpp:39
void SpeechHandler(Network::Client *client, PKTIN_03 *mymsg)
Definition: speech.cpp:177
void drop_item_v2(Network::Client *client, PKTIN_08_V2 *msg)
Definition: dropitem.cpp:861
void handle_use_skill(Network::Client *client, PKTIN_12 *msg)
Definition: useskill.cpp:30
void handle_walk(Network::Client *client, PKTIN_02 *msg02)
Definition: movement.cpp:137
void sellhandler(Client *client, PKTIN_9F *msg)
Definition: uomod2.cpp:890
void handle_update_range_change(Client *client, PKTBI_C8 *)
Definition: miscmsg.cpp:423
void handle_selcolor(Client *client, PKTBI_95 *msg)
Definition: uomod2.cpp:2140
void ClientCreateCharKR(Network::Client *client, PKTIN_8D *msg)
Definition: create.cpp:595
void handle_D9(Network::Client *client, PKTIN_D9 *msg)
Definition: login.cpp:227
void read_book_page_handler(Client *client, PKTBI_66 *msg)
Definition: uomod2.cpp:2333
void handle_unknown_C4(Client *client, PKTOUT_C4 *)
Definition: miscmsg.cpp:418
Definition: berror.cpp:12
void handle_se_object_list(Client *client, PKTBI_D6_IN *msgin)
Definition: miscmsg.cpp:455
void handle_aos_commands(Client *client, PKTBI_D7 *msg)
Definition: miscmsg.cpp:529
void handle_resurrect_menu(Client *client, PKTBI_2C *msg)
Definition: uomod2.cpp:2095
void select_server(Network::Client *client, PKTIN_A0 *msg)
Definition: login.cpp:260
void ClientCreateChar70160(Network::Client *client, PKTIN_F8 *msg)
Definition: create.cpp:953