Browse Source

change implementation of packet classes

pull/25/head
Xadhoom 7 years ago
parent
commit
7d0ab8cae8
  1. 17
      Stub/dvlnet.h
  2. 1
      Stub/dvlnet_udp.cpp
  3. 4
      Stub/dvlnet_udp_packet.cpp

17
Stub/dvlnet.h

@ -107,22 +107,26 @@ public:
plr_t newplr(); plr_t newplr();
plr_t oldplr(); plr_t oldplr();
const buffer_t &info(); const buffer_t &info();
template<class P> void process_data(P &self);
}; };
class packet_in : public packet { template<class P> class packet_proc : public packet {
public: public:
using packet::packet; using packet::packet;
void process_data();
};
class packet_in : public packet_proc<packet_in> {
public:
using packet_proc<packet_in>::packet_proc;
void create(buffer_t buf); void create(buffer_t buf);
void process_element(buffer_t &x); void process_element(buffer_t &x);
template <class T> void process_element(T &x); template <class T> void process_element(T &x);
void decrypt(); void decrypt();
}; };
class packet_out : public packet { class packet_out : public packet_proc<packet_out> {
public: public:
using packet::packet; using packet_proc<packet_out>::packet_proc;
void create(packet_type t, plr_t s, plr_t d, buffer_t m); void create(packet_type t, plr_t s, plr_t d, buffer_t m);
void create(packet_type t, plr_t s, plr_t d, turn_t u); void create(packet_type t, plr_t s, plr_t d, turn_t u);
void create(packet_type t, plr_t s, plr_t d, cookie_t c); void create(packet_type t, plr_t s, plr_t d, cookie_t c);
@ -186,8 +190,9 @@ private:
void run_event_handler(_SNETEVENT &ev); void run_event_handler(_SNETEVENT &ev);
}; };
template<class P> void dvlnet_udp::packet::process_data(P &self) template<class P> void dvlnet_udp::packet_proc<P>::process_data()
{ {
P &self = static_cast<P&>(*this);
self.process_element(m_type); self.process_element(m_type);
self.process_element(m_src); self.process_element(m_src);
self.process_element(m_dest); self.process_element(m_dest);

1
Stub/dvlnet_udp.cpp

@ -278,7 +278,6 @@ int dvlnet_udp::SNetGetProviderCaps(struct _SNETCAPS *caps)
return 1; return 1;
} }
void *dvlnet_udp::SNetUnregisterEventHandler(event_type evtype, void(__stdcall *func)(struct _SNETEVENT *)) void *dvlnet_udp::SNetUnregisterEventHandler(event_type evtype, void(__stdcall *func)(struct _SNETEVENT *))
{ {
registered_handlers.erase(evtype); registered_handlers.erase(evtype);

4
Stub/dvlnet_udp_packet.cpp

@ -116,7 +116,7 @@ void dvlnet_udp::packet_in::decrypt()
decrypted_buffer = encrypted_buffer; decrypted_buffer = encrypted_buffer;
} }
process_data(*this); process_data();
have_decrypted = true; have_decrypted = true;
} }
@ -212,7 +212,7 @@ void dvlnet_udp::packet_out::encrypt()
if (have_encrypted) if (have_encrypted)
return; return;
process_data(*this); process_data();
if (!disable_encryption) { if (!disable_encryption) {
auto len_cleartext = encrypted_buffer.size(); auto len_cleartext = encrypted_buffer.size();

Loading…
Cancel
Save