• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

LightweightDatabaseClient.cpp

Go to the documentation of this file.
00001 #include "NativeFeatureIncludes.h"
00002 #if _RAKNET_SUPPORT_LightweightDatabaseClient==1
00003 
00004 #include "LightweightDatabaseClient.h"
00005 #include "StringCompressor.h"
00006 #include "MessageIdentifiers.h"
00007 #include "RakPeerInterface.h"
00008 #include "TableSerializer.h"
00009 #include "BitStream.h"
00010 #include "RakAssert.h"
00011 
00012 #ifdef _MSC_VER
00013 #pragma warning( push )
00014 #endif
00015 
00016 LightweightDatabaseClient::LightweightDatabaseClient()
00017 {
00018 }
00019 LightweightDatabaseClient::~LightweightDatabaseClient()
00020 {
00021 
00022 }
00023 void LightweightDatabaseClient::QueryTable(const char *tableName, const char *queryPassword, const char **columnNamesSubset, unsigned char numColumnSubset, DatabaseFilter *filter, unsigned char numFilters, unsigned *rowIds, unsigned char numRowIDs, SystemAddress systemAddress, bool broadcast)
00024 {
00025         if (tableName==0 || tableName[0]==0)
00026                 return;
00027         if (rakPeerInterface==0)
00028                 return;
00029 
00030         RakNet::BitStream out;
00031         out.Write((MessageID)ID_DATABASE_QUERY_REQUEST);
00032         stringCompressor->EncodeString(tableName, _SIMPLE_DATABASE_TABLE_NAME_LENGTH, &out);
00033         if (queryPassword && queryPassword[0])
00034         {
00035         out.Write(true);
00036                 // This is sent in plain text.  I can do this securely but it's not worth the trouble.
00037                 // Use secure connections if you want security.
00038                 stringCompressor->EncodeString(queryPassword, _SIMPLE_DATABASE_PASSWORD_LENGTH, &out);
00039         }
00040         else
00041                 out.Write(false);
00042 
00043         out.Write(numColumnSubset);
00044         unsigned i;
00045         for (i=0; i < numColumnSubset; i++)
00046         {
00047                 stringCompressor->EncodeString(columnNamesSubset[i],256,&out);
00048         }
00049 
00050         out.Write(numFilters);
00051         for (i=0; i < numFilters; i++)
00052         {
00053                 RakAssert((int)filter[i].operation<=(int)DataStructures::Table::QF_NOT_EMPTY);
00054                 filter[i].Serialize(&out);
00055         }
00056 
00057         out.Write(numRowIDs);
00058         for (i=0; i < numRowIDs; i++)
00059                 out.Write(rowIds[i]);
00060 
00061         SendUnified(&out, HIGH_PRIORITY, RELIABLE_ORDERED,0,systemAddress, broadcast);
00062 }
00063 void LightweightDatabaseClient::RemoveRow(const char *tableName, const char *removePassword, unsigned rowId, SystemAddress systemAddress, bool broadcast)
00064 {
00065         if (tableName==0 || tableName[0]==0)
00066                 return;
00067         if (rakPeerInterface==0)
00068                 return;
00069 
00070         RakNet::BitStream out;
00071         out.Write((MessageID)ID_DATABASE_REMOVE_ROW);
00072         stringCompressor->EncodeString(tableName, _SIMPLE_DATABASE_TABLE_NAME_LENGTH, &out);
00073         if (removePassword && removePassword[0])
00074         {
00075                 out.Write(true);
00076                 // This is sent in plain text.  I can do this securely but it's not worth the trouble.
00077                 // Use secure connections if you want security.
00078                 stringCompressor->EncodeString(removePassword, _SIMPLE_DATABASE_PASSWORD_LENGTH, &out);
00079         }
00080         else
00081                 out.Write(false);
00082 
00083         out.Write(rowId);
00084 
00085         SendUnified(&out, HIGH_PRIORITY, RELIABLE_ORDERED,0,systemAddress, broadcast);
00086 }
00087 void LightweightDatabaseClient::UpdateRow(const char *tableName, const char *updatePassword, RowUpdateMode updateMode, bool hasRowId, unsigned rowId, DatabaseCellUpdate *cellUpdates, unsigned char numCellUpdates, SystemAddress systemAddress, bool broadcast)
00088 {
00089         if (tableName==0 || tableName[0]==0)
00090                 return;
00091         if (rakPeerInterface==0)
00092                 return;
00093         if (cellUpdates==0 || numCellUpdates==0)
00094                 return;
00095 
00096         RakNet::BitStream out;
00097         out.Write((MessageID)ID_DATABASE_UPDATE_ROW);
00098         stringCompressor->EncodeString(tableName, _SIMPLE_DATABASE_TABLE_NAME_LENGTH, &out);
00099         if (updatePassword && updatePassword[0])
00100         {
00101                 out.Write(true);
00102                 // This is sent in plain text.  I can do this securely but it's not worth the trouble.
00103                 // Use secure connections if you want security.
00104                 stringCompressor->EncodeString(updatePassword, _SIMPLE_DATABASE_PASSWORD_LENGTH, &out);
00105         }
00106         else
00107                 out.Write(false);
00108 
00109         out.Write((unsigned char) updateMode);
00110         out.Write(hasRowId);
00111         if (hasRowId)
00112                 out.Write(rowId);
00113         out.Write(numCellUpdates);
00114         unsigned i;
00115         for (i=0; i < numCellUpdates; i++)
00116                 cellUpdates[i].Serialize(&out);
00117 
00118         SendUnified(&out, HIGH_PRIORITY, RELIABLE_ORDERED,0,systemAddress, broadcast);
00119 }
00120 
00121 #ifdef _MSC_VER
00122 #pragma warning( pop )
00123 #endif
00124 
00125 #endif // _RAKNET_SUPPORT_*

Generated on Thu Sep 30 2010 01:27:24 for RakNet by  doxygen 1.7.1