BF2MC-Matchmaker
browsing/client.h
1 #ifndef BROWSING_CLIENT_H
2 #define BROWSING_CLIENT_H
3 
4 #include <gamespy.h>
5 #include <net/socket.h>
6 #include <battlefield/gameserver.h>
7 
8 
9 namespace Browsing
10 {
14  class Client : public Net::Socket
15  {
16  private:
23  std::vector<unsigned char> _client_challenge;
24 
25  public:
32  Client(int socket, struct sockaddr_in address);
33 
37  ~Client();
38 
42  void Listen();
43 
47  void Disconnect();
48 
49  /*
50  Events
51  */
57  void onRequest(const std::vector<unsigned char>& request);
58 
59  /*
60  Requests
61  */
67  void requestServerList(const std::vector<unsigned char>& request);
68 
74  void requestServerInfo(const std::vector<unsigned char>& request);
75 
76  private:
83  void _BufferToRequests(const std::vector<unsigned char>& buffer,
84  std::vector<std::vector<unsigned char>>& requests);
85 
91  void _insertClientInfo(std::vector<unsigned char>& response);
92 
99  void _insertGameServerFlagIpPort(std::vector<unsigned char>& response,
100  const Battlefield::GameServer& game_server);
101 
107  void _Encrypt(std::vector<unsigned char>& response);
108 
115  void _LogTransaction(const std::string& direction, const std::string& response) const;
116 
123  void _FilterServers(const std::string& filter, Battlefield::GameServers& game_servers);
124 
132  bool _FilterServerGameVersion(const std::string& filter, const Battlefield::GameServer& game_server);
133 
141  bool _FilterServerRegion(const std::string& filter, const Battlefield::GameServer& game_server);
142 
150  bool _FilterServerNumPlayers(const std::string& filter, const Battlefield::GameServer& game_server);
151 
159  bool _FilterServerGameType(const std::string& filter, const Battlefield::GameServer& game_server);
160 
168  bool _FilterServerMapName(const std::string& filter, const Battlefield::GameServer& game_server);
169 
177  bool _FilterServerStatsTracking(const std::string& filter, const Battlefield::GameServer& game_server);
178 
186  bool _FilterServerReconfigurable(const std::string& filter, const Battlefield::GameServer& game_server);
187 
195  bool _FilterServerClan(const std::string& filter, const Battlefield::GameServer& game_server);
196 
204  bool _FilterServerTeamplay(const std::string& filter, const Battlefield::GameServer& game_server);
205 
206  public:
210  static void Test();
211 
215  static void Crack();
216 
223  static void Heartbeat();
224  };
225 }
226 
227 #endif // BROWSING_CLIENT_H
Class representing game server information.
Definition: gameserver.h:63
Client class for handling browsing requests.
bool _FilterServerReconfigurable(const std::string &filter, const Battlefield::GameServer &game_server)
Checks if a game server matches the filter criteria based on reconfigurability.
bool _FilterServerNumPlayers(const std::string &filter, const Battlefield::GameServer &game_server)
Checks if a game server matches the filter criteria based on number of players.
bool _FilterServerGameVersion(const std::string &filter, const Battlefield::GameServer &game_server)
Checks if a game server matches the filter criteria based on game version.
void Listen()
Listens for incoming requests from the client.
void Disconnect()
Disconnects the client.
bool _FilterServerMapName(const std::string &filter, const Battlefield::GameServer &game_server)
Checks if a game server matches the filter criteria based on map name.
void _FilterServers(const std::string &filter, Battlefield::GameServers &game_servers)
Filters game servers based on the provided filter criteria.
~Client()
Destroys the Client object.
void _BufferToRequests(const std::vector< unsigned char > &buffer, std::vector< std::vector< unsigned char >> &requests)
Converts a buffer to a list of requests.
void _insertClientInfo(std::vector< unsigned char > &response)
Inserts client information into the response.
Client(int socket, struct sockaddr_in address)
Constructs a new Client object.
void requestServerList(const std::vector< unsigned char > &request)
Sends a request for the server list.
static void Crack()
Cracking function to find the secret key from a package.
bool _FilterServerRegion(const std::string &filter, const Battlefield::GameServer &game_server)
Checks if a game server matches the filter criteria based on region.
bool _FilterServerTeamplay(const std::string &filter, const Battlefield::GameServer &game_server)
Checks if a game server matches the filter criteria based on teamplay.
bool _FilterServerStatsTracking(const std::string &filter, const Battlefield::GameServer &game_server)
Checks if a game server matches the filter criteria based on stats tracking.
void _LogTransaction(const std::string &direction, const std::string &response) const
Logs a transaction.
void _Encrypt(std::vector< unsigned char > &response)
Encrypts the response.
void onRequest(const std::vector< unsigned char > &request)
Event handler for incoming requests.
void requestServerInfo(const std::vector< unsigned char > &request)
Sends a request for server information.
bool _FilterServerClan(const std::string &filter, const Battlefield::GameServer &game_server)
Checks if a game server matches the filter criteria based on clan.
void _insertGameServerFlagIpPort(std::vector< unsigned char > &response, const Battlefield::GameServer &game_server)
Inserts game server flag, IP, and port into the response.
static void Heartbeat()
Heartbeat function to manage client connections.
std::vector< unsigned char > _client_challenge
Challenge data sent to the client.
static void Test()
Testing function to encrypt/decrypt a package.
bool _FilterServerGameType(const std::string &filter, const Battlefield::GameServer &game_server)
Checks if a game server matches the filter criteria based on game type.
A base class representing a network socket.
Definition: socket.h:15