ReplicaNet and RNLobby  1
UserServer.h
1 /* START_LICENSE_HEADER
2 
3 Copyright (C) 2000 Martin Piper, original design and program code
4 Copyright (C) 2001 Replica Software
5 
6 This program file is copyright (C) Replica Software and can only be used under license.
7 For more information visit: http://www.replicanet.com/
8 Or email: info@replicanet.com
9 
10 END_LICENSE_HEADER */
11 #include "RNPlatform/Inc/MemoryTracking.h"
12 #ifndef _USERSERVER_H_
13 #define _USERSERVER_H_
14 #include "RNLobby/Inc/RNLobby.h"
15 #include "RNLobby/Inc/BaseTransportServer.h"
16 #include "RNLobby/Inc/UserClient.h"
17 #include "RNXPSockets/Inc/XPSocket.h"
18 #include "RNODBCSQL/Inc/ODBCSQL.h"
19 #include "RNODBCSQL/Inc/Prepare.h"
20 #include "RNLog/Inc/Log.h"
21 #include <map>
22 #include <set>
23 
24 namespace RNReplicaNet
25 {
26 
27 namespace RNLobby
28 {
29 
47 {
48 public:
49  UserServer(const char *lobbyDSN = MRNLobbyDefaultDSN);
50  virtual ~UserServer();
51 
52  enum
53  {
54  kDefaultPort = 4009
55  };
56 
58  bool Start(const XPAddress &address = XPAddress(kDefaultPort));
59 
61  size_t GetNumTotal(void);
62 
64  static int VerifyUserNonce(RNReplicaNet::RNODBCSQL::ODBCSQL &sql, const std::string &userNonce);
65  static bool GetVariable(RNReplicaNet::RNODBCSQL::ODBCSQL &sql, const int titleID, const int loginID, const int section, const UserClient::VariableAccess access, const std::string &name, std::string &value);
66  static bool GetVariable(RNReplicaNet::RNODBCSQL::ODBCSQL &sql, const int titleID, const int loginID, const int section, const UserClient::VariableAccess access, const std::string &name, int &value);
67  static bool GetVariable(RNReplicaNet::RNODBCSQL::ODBCSQL &sql, const int titleID, const int loginID, const int section, const UserClient::VariableAccess access, const std::string &name, float &value);
68  static bool SetVariable(RNReplicaNet::RNODBCSQL::ODBCSQL &sql, const int titleID, const int loginID, const int section, const UserClient::VariableAccess access, const std::string &name, const std::string &value);
69  static bool SetVariable(RNReplicaNet::RNODBCSQL::ODBCSQL &sql, const int titleID, const int loginID, const int section, const UserClient::VariableAccess access, const std::string &name, const int value);
70  static bool SetVariable(RNReplicaNet::RNODBCSQL::ODBCSQL &sql, const int titleID, const int loginID, const int section, const UserClient::VariableAccess access, const std::string &name, const float value);
71  static bool DeleteVariable(RNReplicaNet::RNODBCSQL::ODBCSQL &sql, const int titleID, const int loginID, const int section, const UserClient::VariableAccess access, const std::string &name);
72 
73 private:
74  RNReplicaNet::RNLog::Log mLog;
75 
76  RNODBCSQL::ODBCSQL mWrite;
77  RNODBCSQL::ODBCSQL mRead;
78  struct SessionData
79  {
80  SessionData();
81  int mDBIndex; // This is also actually the loginID
82  std::string mCachedName; // This is the last known cached name for this connection
83  int mClientNonce;
84  int mInRoomID;
85  bool mIsSuperRoomUser;
86  int mLoggedInAsTitleID;
87  };
88  std::map<Transport *,SessionData> mMapSessionDataByTransport;
89  std::map<int,Transport *> mMapTransportByIndex; // As above, the index is the loginID
90  SysTimeType mLastRelationshipUpdate;
91 
92  // By default newly created rooms are mCloseWhenNoAdmin and mCloseWhenEmpty
93  struct RoomData
94  {
95  RoomData();
96  // Also the logout (disconnection or otherwise) needs to remove the player from the room they might have been in.
97  std::string mPasswordHash;
98  std::set<int> mLoginIDs;
99  std::set<int> mAdminLoginIDs; // For future expansion we allow more than one room admin
100  std::set<int> mBannedLoginIDs; // When joining the room the loginID is checked against this
101  bool mCloseWhenNoAdmin;
102  bool mCloseWhenEmpty;
103  };
104  int mRoomID; // A counter for user defined roomIDs
105  std::map<int,RoomData> mRoomByID;
106 
107  bool CallbackPoll(void);
108 
109  bool CallbackParseValidMessage(Transport *transport,DynamicMessageHelper &message,const size_t length);
110 
112  int InsertEntry(const int titleID,const char *name,const char *passwordHash,const char *emailAddress, const char *optionalID);
113 
114  bool RemoveEntry(const int loginID);
115 
116  void CallbackAccepted(Transport *transport);
117 
118  void CallbackDisconnected(Transport *transport);
119 
121  bool RemoveTransportFromDBID(const int dbID,Transport *transport = 0);
122 
123  void SetLoginIDAsUpdated(const int loginID);
124 
125  void SetLoginIDAsLoggedOut(const int loginID);
126 
127  bool RemoveSessionDataFromRoom(SessionData &sessionData);
128 
129  bool IsSuperRoomUser(const int loginID);
130 
131  void AddUserAddressLog(const int loginID, const std::string text);
132 
133 
134  RNODBCSQL::Prepare mPreparedUserRelationshipByID;
135  RNODBCSQL::Prepare mPreparedUsersByID;
136  RNODBCSQL::Prepare mPreparedDeleteUserRelationshipByID;
137  RNODBCSQL::Prepare mPreparedUsers2ByID;
138  RNODBCSQL::Prepare mPreparedUsersByName;
139  RNODBCSQL::Prepare mPreparedUsersByNameMachineUID;
140  RNODBCSQL::Prepare mPreparedUsers2ByName;
141  RNODBCSQL::Prepare mPreparedCountAccountBlockedByID;
142  RNODBCSQL::Prepare mPreparedUpdateUsersByID;
143  RNODBCSQL::Prepare mPreparedUpdateUserRelationshipByID;
144  RNODBCSQL::Prepare mPreparedOfflineMessagesByID;
145  RNODBCSQL::Prepare mPreparedDeleteOfflineMessagesByID;
146  RNODBCSQL::Prepare mPreparedUsers3ByID;
147  RNODBCSQL::Prepare mPreparedInsertOfflineMessages;
148  RNODBCSQL::Prepare mPreparedUsers4ByID;
149  RNODBCSQL::Prepare mPreparedUserRelationshipByIDOtherID;
150  RNODBCSQL::Prepare mPreparedUserRelationship2ByIDOtherID;
151  RNODBCSQL::Prepare mPreparedInsertUserRelationship;
152  RNODBCSQL::Prepare mPreparedUpdateUserRelationship2ByID;
153  RNODBCSQL::Prepare mPreparedInsertUserRelationship2;
154  RNODBCSQL::Prepare mPreparedUpdateUserRelationship3ByID;
155  RNODBCSQL::Prepare mPreparedInsertUserRelationship3;
156  RNODBCSQL::Prepare mPreparedUpdateUserRelationship4ByID;
157  RNODBCSQL::Prepare mPreparedUserRelationship3ByIDOtherID;
158  RNODBCSQL::Prepare mPreparedInsertUserRelationship4;
159  RNODBCSQL::Prepare mPreparedUpdateUserRelationship5ByID;
160  RNODBCSQL::Prepare mPreparedUpdateUserRelationship6ByID;
161  RNODBCSQL::Prepare mPreparedUpdateUserRelationship7ByID;
162  RNODBCSQL::Prepare mPreparedUpdateUserRelationship8ByID;
163  RNODBCSQL::Prepare mPreparedUpdateUserRelationship9ByID;
164  RNODBCSQL::Prepare mPreparedUpdateUserRelationship10ByID;
165  RNODBCSQL::Prepare mPreparedInsertAccountBlocked;
166  RNODBCSQL::Prepare mPreparedCannotChangePasswordByID;
167  RNODBCSQL::Prepare mPreparedSetPasswordHashByID;
168  RNODBCSQL::Prepare mPreparedCannotChangeEmailByID;
169  RNODBCSQL::Prepare mPreparedSetEmailAddressByID;
170  RNODBCSQL::Prepare mPreparedSetPlayingAGameByID;
171  RNODBCSQL::Prepare mPreparedInsertUserNonces;
172  RNODBCSQL::Prepare mPreparedUsersAccountBlockedByIDName;
173  RNODBCSQL::Prepare mPreparedUsersByIDName;
174  RNODBCSQL::Prepare mPreparedDeleteAccountBlockedByID;
175  RNODBCSQL::Prepare mPreparedInsertUsers;
176  RNODBCSQL::Prepare mPreparedDeleteUsersByID;
177  RNODBCSQL::Prepare mPreparedSetUserRelationshipByOtherID;
178  RNODBCSQL::Prepare mPreparedDeleteUserRelationship2ByID;
179  RNODBCSQL::Prepare mPreparedDeleteOfflineMessages2ByID;
180  RNODBCSQL::Prepare mPreparedDeleteVariablesByID;
181  RNODBCSQL::Prepare mPreparedUpdateUserRelationshipByIDIsIgnored;
182  RNODBCSQL::Prepare mPreparedUpdateUsers2ByID;
183  RNODBCSQL::Prepare mPreparedUpdateUserRelationship11ByID;
184  RNODBCSQL::Prepare mPreparedDeleteUserRelationshipByIDIsFriendIsIgnored;
185  RNODBCSQL::Prepare mPreparedCountSuperRoomUsersByID;
186  RNODBCSQL::Prepare mPreparedInsertUserNetworkAddressHistory;
187  RNODBCSQL::Prepare mPreparedCountUserNetworkAddressHistoryByID;
188  RNODBCSQL::Prepare mPreparedDeleteUserNetworkAddressHistoryByID;
189  //RNODBCSQL::Prepare mPreparedUserNoncesByUserNonce;
190 };
191 
192 } // namespace RNLobby
193 
194 } // namespace RNReplicaNet
195 
196 #endif
Definition: Transport.h:35
A server base class that handles encrypted messages to and from a transport.
Definition: BaseTransportServer.h:30
Definition: UserServer.h:46
Definition: XPSocket.h:91
static int VerifyUserNonce(RNReplicaNet::RNODBCSQL::ODBCSQL &sql, const std::string &userNonce)
Verifies the input userNonce and returns the corresponding loginID or UserInfo::kAnyLoginID if the us...
size_t GetNumTotal(void)
Returns the total number of users.
bool Start(const XPAddress &address=XPAddress(kDefaultPort))
Because this uses a TransportUDP connection it will call XPURL::RegisterDefaultTransports() ...
Definition: MessageHelper.h:211