ReplicaNet and RNLobby  1
CodeServer.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 _CODESERVER_H_
13 #define _CODESERVER_H_
14 #include "RNPlatform/Inc/SysTime.h"
15 #include "RNPlatform/Inc/RegistryManagerMap.h"
16 #include "RNPlatform/Inc/Encryption.h"
17 #include "RNPlatform/Inc/ThreadClass.h"
18 #include "RNPlatform/Inc/Thread.h"
19 #include "RNXPSockets/Inc/XPSockets.h"
20 #include <string.h>
21 
22 namespace RNReplicaNet
23 {
24 
25 namespace RNLobby
26 {
27 
30 class CodeServer : private ThreadClass , private Thread
31 {
32 public:
33  class CodeEntry
34  {
35  public:
36  struct ThisLess
37  {
38  bool operator()(const std::string &s1, const std::string &s2) const;
39  };
40  CodeEntry();
41 
42  // ctor variables
43  XPAddress mLastAddress;
44  SysTimeType mLastTime;
45  int mUserSuppliedReply;
46  int mLastNOnce1,mLastNOnce2;
47 
48  // ctor body variables
49  std::string mTheCode;
50  };
51 
52  enum Reply
53  {
54  kReply_ValidKey = 0,
55  kReply_UnspecifiedError,
56  kReply_InvalidKey,
57  kReply_KeyInUse,
58  kReply_Timeout,
59  kReply_CorruptReply
60  };
61  enum
62  {
63  kDefaultPort = 4003
64  };
65 
66 
67  CodeServer();
68  virtual ~CodeServer();
69 
75  bool ReadCodeFile(const char *filename, const bool duplicateCodeCheck = false);
76 
83  bool AddCode(const char *code, const bool duplicateCodeCheck = false,const int userSuppliedReply = 0);
84 
89  bool RemoveCode(const char *code = 0);
90 
93  bool Start(const XPAddress &address = XPAddress(kDefaultPort));
94 
98  bool Stop(bool hardware = false);
99 
104  void SetEncryptionKey(const void *data,const int length);
105 
109  void SetCodeTimeout(const float time = (60.0f * 30.0f));
110 
113  float GetCodeTimeout(void) const;
114 
120  virtual void CallbackDataReceived(void *data,int &length,const int maxLength,XPAddress &address) {}
121 
124  virtual void CallbackVersion(const int version) {}
125 
133  virtual void CallbackKeyData(char *keyData,const int maxLength,int &nOnce1,int &nOnce2,bool &updateDatabase) {}
134 
140  virtual void CallbackQueryReply(Reply &reply,int &userSuppliedReply,int &nOnce1,int &nOnce2) {}
141 
147  virtual void CallbackDataSend(void *data,int &length,const int maxLength,XPAddress &address) {}
148 
151  virtual void CallbackQueryReplyTime(const float seconds) {}
152 
154  int GetNumRequests(void) const;
155 
157  int GetNumFailed(void) const;
158 
159 private:
160  int ThreadEntry(void);
161 
162 protected:
164  MutexClass mCodesMutex;
165 private:
166  XPSocketUrgent *mListen;
167 
168  Encryption::Key mCryptoKey;
169  float mCodeTimeout;
170  int mNumRequests;
171  int mNumFailed;
172 };
173 
174 } // namespace RNLobby
175 
176 } // namespace RNReplicaNet
177 
178 #endif
void SetCodeTimeout(const float time=(60.0f *30.0f))
bool Start(const XPAddress &address=XPAddress(kDefaultPort))
virtual void CallbackVersion(const int version)
Definition: CodeServer.h:124
void SetEncryptionKey(const void *data, const int length)
Definition: Encryption.h:27
Definition: XPSocket.h:91
virtual void CallbackDataReceived(void *data, int &length, const int maxLength, XPAddress &address)
Definition: CodeServer.h:120
bool ReadCodeFile(const char *filename, const bool duplicateCodeCheck=false)
bool Stop(bool hardware=false)
virtual void CallbackKeyData(char *keyData, const int maxLength, int &nOnce1, int &nOnce2, bool &updateDatabase)
Definition: CodeServer.h:133
int GetNumRequests(void) const
Returns the total number of codes queries.
bool RemoveCode(const char *code=0)
virtual void CallbackQueryReplyTime(const float seconds)
Definition: CodeServer.h:151
Definition: RegistryManagerMap.h:25
Definition: CodeServer.h:30
int GetNumFailed(void) const
Returns the total number of codes queries that were returned as kReply_InvalidKey.
bool AddCode(const char *code, const bool duplicateCodeCheck=false, const int userSuppliedReply=0)
float GetCodeTimeout(void) const
Definition: ThreadClass.h:39
virtual void CallbackDataSend(void *data, int &length, const int maxLength, XPAddress &address)
Definition: CodeServer.h:147
Definition: XPSocketUrgentClass.h:26
virtual void CallbackQueryReply(Reply &reply, int &userSuppliedReply, int &nOnce1, int &nOnce2)
Definition: CodeServer.h:140
Definition: ThreadClass.h:96
Definition: Thread.h:29