00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _BASETRANSPORTSERVER_H_
00012 #define _BASETRANSPORTSERVER_H_
00013 #include "RNPlatform/Inc/DLLExportAPI.h"
00014 #include <map>
00015 #include "RNPlatform/Inc/Encryption.h"
00016 #include "RNPlatform/Inc/ThreadClass.h"
00017 #include "RNPlatform/Inc/Thread.h"
00018 #include "RNXPURL/Inc/Transport.h"
00019 #include "RNPlatform/Inc/MessageHelper.h"
00020 #include "RNLobby/Inc/CommonServer.h"
00021
00022 namespace RNReplicaNet
00023 {
00024
00025 namespace RNLobby
00026 {
00027
00028
00029 #ifdef _WIN32
00030 #pragma warning(disable : 4786)
00031 #endif
00032
00034 class BaseTransportServer : private CommonServer , public ThreadClass , public Thread
00035 {
00036 public:
00037 BaseTransportServer();
00038 virtual ~BaseTransportServer();
00039
00044 void SetEncryptionKey(const void *data,const int length);
00045
00051 virtual bool Start(Transport *transport,const bool allowDelete = true,const bool isListen = true);
00052
00056 virtual bool Stop(void);
00057
00058 static float FloatTime(void);
00059
00060 size_t GetNumConnections(void) const;
00061
00063 bool SetAsDisconnecting(Transport *transport);
00064
00065 protected:
00068 virtual bool CallbackParseValidMessage(Transport *transport,DynamicMessageHelper &message,const size_t length) { return true; }
00069
00071 virtual bool PackageAndSendData(Transport *transport,const DynamicMessageHelper &message);
00072
00076 virtual bool CallbackParsePacketData(Transport *transport,void *data,size_t &length,DynamicMessageHelper &result);
00077
00079 virtual void CallbackAccepted(Transport *transport) {}
00080
00082 virtual void CallbackDisconnected(Transport *transport) {}
00083
00086 virtual void CallbackDataReceived(DynamicMessageHelper &message) {}
00087
00090 virtual void CallbackDataSend(DynamicMessageHelper &message) {}
00091
00094 virtual void CallbackQueryReplyTime(const float seconds) {}
00095
00098 virtual bool CallbackPoll(void) { return true; }
00099
00102 virtual void CallbackTidy(void) {}
00103
00104 int ThreadEntry(void);
00105
00106 void GenerateNewNonce(void);
00107
00108 private:
00109
00110 struct Entry
00111 {
00112 Entry() : mLastPacketTime(0.0f) , mLastPacketsSent(0) , mWaitingForDisconnect(-1.0f) , mError(false) {}
00113 float mLastPacketTime;
00114 int mLastPacketsSent;
00115 float mWaitingForDisconnect;
00116 bool mError;
00117 };
00118
00119 void ThreadExiting(const int returnCode);
00120 void Tidy(void);
00121
00122 int RunThink(Transport *transport,Entry &entry);
00123
00124 protected:
00125 Transport *mTransport;
00126 bool mAllowDelete;
00127
00128 int mNOnce;
00129 std::map<Transport*,Entry> mConnected;
00130
00131 bool mIsListen;
00132 bool mClientIsStable;
00133
00134 Entry mClientEntry;
00135
00136 size_t mNumConnections;
00137 };
00138
00139 }
00140
00141 }
00142
00143 #endif