X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/28b410b2cc8630fc1b3466c6b3fb6214ba9396b6..6ce56fd8481f4fc5ae2cf9383e6b6ecbff42b41d:/projects/sgauthstress/proto.h diff --git a/projects/sgauthstress/proto.h b/projects/sgauthstress/proto.h new file mode 100644 index 00000000..f478c0e1 --- /dev/null +++ b/projects/sgauthstress/proto.h @@ -0,0 +1,66 @@ +#ifndef __PROTO_H__ +#define __PROTO_H__ + +#include +#include + +#include +#include + +#include "stg/os_int.h" +#include "stg/blowfish.h" + +#include "user.h" + +class PROTO; + +typedef bool (PROTO::*PacketProcessor)(char *); + +class PROTO { + public: + PROTO(const std::string & server, + uint16_t port, + uint16_t localPort, + int timeout = 1); + ~PROTO(); + + bool Start(); + bool Stop(); + + const std::string GetStrError() const { return errorStr; } + + bool Connect(const std::string & login); + bool Disconnect(const std::string & login); + private: + int sock; + BLOWFISH_CTX ctx; + struct sockaddr_in localAddr; + struct sockaddr_in serverAddr; + int timeout; + + std::map users; + + bool running; + bool stopped; + + pthread_t tid; + + std::string errorStr; + + std::map processors; + + static void * Runner(void * data); + + void Run(); + bool RecvPacket(); + bool HandlePacket(char * buffer); + + bool CONN_SYN_ACK_Proc(char * buffer); + bool ALIVE_SYN_Proc(char * buffer); + bool DISCONN_SYN_ACK_Proc(char * buffer); + bool FIN_Proc(char * buffer); + bool INFO_Proc(char * buffer); + bool ERR_Proc(char * buffer); +}; + +#endif