BF2MC-Matchmaker
gpcm/client.h
1 #ifndef GPCM_CLIENT_H
2 #define GPCM_CLIENT_H
3 
4 #include <gamespy.h>
5 #include <net/socket.h>
6 
7 
8 namespace GPCM
9 {
10  class Client;
11 
18  struct Session
19  {
20  std::string challenge;
21  int profileid = -1;
22  std::string authtoken;
23  std::shared_ptr<Client> client;
24  std::string status;
25  };
26 
33  class Client : public Net::Socket
34  {
35  private:
37  std::vector<int> _sync_friends;
39  public:
46  Client(int socket, struct sockaddr_in address);
47 
53  ~Client();
54 
61  void Listen();
62 
69  void Disconnect();
70 
76  GPCM::Session GetSession() const;
77 
78  /*
79  Events
80  */
88  void onRequest(const std::string& msg);
89 
90  /*
91  Requests
92  */
98  void requestChallenge();
99 
107  void requestLogin(const GameSpy::Parameter& parameter);
108 
116  void requestInviteTo(const GameSpy::Parameter& parameter);
117 
125  void requestGetProfile(const GameSpy::Parameter& parameter);
126 
134  void requestStatus(const GameSpy::Parameter& parameter);
135 
143  void requestBm(const GameSpy::Parameter& parameter);
144 
152  void requestAddBuddy(const GameSpy::Parameter& parameter);
153 
161  void requestRevoke(const GameSpy::Parameter& parameter);
162 
170  void requestDeleteBuddy(const GameSpy::Parameter& parameter);
171 
179  void requestAuthAdd(const GameSpy::Parameter& parameter);
180 
188  void requestPlayerInvite(const GameSpy::Parameter& parameter);
189 
197  void requestLogout(const GameSpy::Parameter& parameter);
198 
199  private:
209  void _LogTransaction(const std::string& direction, const std::string& response) const;
210 
216  void _SendNewStatus() const;
217 
223  void _SyncFriends();
224 
225 
226  public:
227  /*
228  Static
229  */
236  static GPCM::Session findSessionByProfileId(int profileid);
237 
244  static GPCM::Session findSessionByAuthtoken(const std::string& authtoken);
245 
254  static void SendBuddyMessage(int profileid, int target_profileid, const std::string& bm, const std::string& message);
255 
261  static void Disconnect(int profileid);
262 
269  static void Heartbeat();
270  };
271 }
272 
273 #endif // GPCM_CLIENT_H
Represents a GPCM client.
Definition: gpcm/client.h:34
void requestChallenge()
Sends a challenge to the client.
void requestInviteTo(const GameSpy::Parameter &parameter)
Process an invite request from the client.
void requestGetProfile(const GameSpy::Parameter &parameter)
Process a get-profile request from the client.
void requestAuthAdd(const GameSpy::Parameter &parameter)
Process an auth-add request from the client.
void Disconnect()
Disconnects the client.
void Listen()
Listens for incoming messages from the GPCM client.
Definition: gpcm/client.cpp:45
void _LogTransaction(const std::string &direction, const std::string &response) const
Log a transaction with direction and response.
GPCM::Session _session
Definition: gpcm/client.h:36
~Client()
Destroys the GPCM client.
Definition: gpcm/client.cpp:40
void requestRevoke(const GameSpy::Parameter &parameter)
Process a revoke request from the client.
void requestPlayerInvite(const GameSpy::Parameter &parameter)
Process a player-invite request from the client.
void _SyncFriends()
Synchronizes friends with the client.
static GPCM::Session findSessionByProfileId(int profileid)
Finds a session by profile ID.
static void SendBuddyMessage(int profileid, int target_profileid, const std::string &bm, const std::string &message)
Sends a buddy message from one profile ID to another.
Client(int socket, struct sockaddr_in address)
Constructs a new GPCM client.
Definition: gpcm/client.cpp:33
static void Heartbeat()
Heartbeat function to manage client connections.
void requestStatus(const GameSpy::Parameter &parameter)
Process a status request from the client.
void requestBm(const GameSpy::Parameter &parameter)
Process a BM request from the client.
void requestDeleteBuddy(const GameSpy::Parameter &parameter)
Process a delete-buddy request from the client.
void requestLogout(const GameSpy::Parameter &parameter)
Process a logout request from the client.
std::vector< int > _sync_friends
Definition: gpcm/client.h:37
void onRequest(const std::string &msg)
Event handler for incoming messages from the client.
static GPCM::Session findSessionByAuthtoken(const std::string &authtoken)
Finds a session by authentication token.
void requestAddBuddy(const GameSpy::Parameter &parameter)
Process an add-buddy request from the client.
void requestLogin(const GameSpy::Parameter &parameter)
Process a login request from the client.
void _SendNewStatus() const
Sends a new status to the client.
GPCM::Session GetSession() const
Get the session information of the client.
A base class representing a network socket.
Definition: socket.h:15
Represents a session with a GPCM client.
Definition: gpcm/client.h:19