Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "NativeFeatureIncludes.h"
00009 #if _RAKNET_SUPPORT_LightweightDatabaseServer==1
00010
00011 #ifndef __LIGHTWEIGHT_DATABASE_SERVER_H
00012 #define __LIGHTWEIGHT_DATABASE_SERVER_H
00013
00014 #include "Export.h"
00015 #include "PluginInterface2.h"
00016 #include "LightweightDatabaseCommon.h"
00017 #include "DS_Map.h"
00018
00019 class RakPeerInterface;
00020 struct Packet;
00021
00027 class RAK_DLL_EXPORT LightweightDatabaseServer : public PluginInterface2
00028 {
00029 public:
00030
00031 LightweightDatabaseServer();
00032
00033
00034 virtual ~LightweightDatabaseServer();
00035
00040 DataStructures::Table *GetTable(const char *tableName);
00041
00057 DataStructures::Table* AddTable(const char *tableName,
00058 bool allowRemoteQuery,
00059 bool allowRemoteUpdate,
00060 bool allowRemoteRemove,
00061 const char *queryPassword,
00062 const char *updatePassword,
00063 const char *removePassword,
00064 bool oneRowPerSystemAddress,
00065 bool onlyUpdateOwnRows,
00066 bool removeRowOnPingFailure,
00067 bool removeRowOnDisconnect,
00068 bool autogenerateRowIDs);
00069
00073 bool RemoveTable(const char *tableName);
00074
00076 void Clear(void);
00077
00078
00079 unsigned GetAndIncrementRowID(const char *tableName);
00080
00086 DataStructures::Page<unsigned, DataStructures::Table::Row*, _TABLE_BPLUS_TREE_ORDER> *GetTableRows(const char *tableName);
00087
00089 virtual void Update(void);
00091 virtual PluginReceiveResult OnReceive(Packet *packet);
00093 virtual void OnClosedConnection(SystemAddress systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason );
00094
00095 struct DatabaseTable
00096 {
00097 bool allowRemoteUpdate;
00098 bool allowRemoteQuery;
00099 bool allowRemoteRemove;
00100
00101 char updatePassword[_SIMPLE_DATABASE_PASSWORD_LENGTH];
00102 char queryPassword[_SIMPLE_DATABASE_PASSWORD_LENGTH];
00103 char removePassword[_SIMPLE_DATABASE_PASSWORD_LENGTH];
00104 bool oneRowPerSystemAddress;
00105 bool onlyUpdateOwnRows;
00106 bool removeRowOnPingFailure;
00107 bool removeRowOnDisconnect;
00108 bool autogenerateRowIDs;
00109 char tableName[_SIMPLE_DATABASE_TABLE_NAME_LENGTH];
00110
00111
00112 unsigned nextRowId;
00113
00114 unsigned SystemAddressColumnIndex;
00115 unsigned SystemGuidColumnIndex;
00116 unsigned lastPingResponseColumnIndex;
00117 unsigned nextPingSendColumnIndex;
00118 RakNetTime nextRowPingCheck;
00119 DataStructures::Table table;
00120 };
00121
00122 static int DatabaseTableComp( const char* const &key1, const char* const &key2 );
00123
00124 protected:
00125 DataStructures::Map<const char *, LightweightDatabaseServer::DatabaseTable*, LightweightDatabaseServer::DatabaseTableComp> database;
00126 void OnQueryRequest(Packet *packet);
00127 void OnUpdateRow(Packet *packet);
00128 void OnRemoveRow(Packet *packet);
00129 void OnPong(Packet *packet);
00130
00131 DatabaseTable * DeserializeClientHeader(RakNet::BitStream *inBitstream, RakPeerInterface *peer, Packet *packet, int mode);
00132 DataStructures::Table::Row * GetRowFromIP(DatabaseTable *databaseTable, SystemAddress systemAddress, unsigned *rowId);
00133 bool RowHasIP(DataStructures::Table::Row *row, SystemAddress systemAddress, unsigned SystemAddressColumnIndex);
00134 DataStructures::Table::Row * AddRow(LightweightDatabaseServer::DatabaseTable *databaseTable, SystemAddress systemAddress, RakNetGUID guid, bool hasRowId, unsigned rowId);
00135 void RemoveRowsFromIP(SystemAddress systemAddress);
00136
00137 };
00138
00139 #endif
00140
00141 #endif // _RAKNET_SUPPORT_*