| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 |
- #include "SQLiteClientLoggerPlugin.h"
- #include "MessageIdentifiers.h"
- #include "PacketizedTCP.h"
- #include "GetTime.h"
- static const char COLUMN_NAMES_DELIMITER=',';
- static const int MAX_COLUMN_NAMES_LENGTH=512;
- using namespace RakNet;
- SQLiteClientLoggerPlugin* SQLiteClientLoggerPlugin::logger;
- SQLiteClientLoggerPlugin::SQLiteClientLoggerPlugin()
- {
- logger=this;
- tickCount=0;
- recursiveCheck=false;
- memoryConstraint=0;
- }
- SQLiteClientLoggerPlugin::~SQLiteClientLoggerPlugin()
- {
- if (logger==this)
- logger=0;
- }
- void SQLiteClientLoggerPlugin::SetServerParameters(const SystemAddress &systemAddress, RakNet::RakString _dbIdentifier)
- {
- serverAddress=systemAddress;
- dbIdentifier=_dbIdentifier;
- }
- void SQLiteClientLoggerPlugin::SetMemoryConstraint(unsigned int constraint)
- {
- memoryConstraint=constraint;
- }
- void SQLiteClientLoggerPlugin::IncrementAutoTickCount(void)
- {
- tickCount++;
- }
- SQLLogResult SQLiteClientLoggerPlugin::SqlLog( bool isFunctionCall, const char *tableName, const char *columnNames, const char *file, const int line, const ParameterListHelper ¶meterList )
- {
- if (recursiveCheck==true)
- return SQLLR_RECURSION;
- recursiveCheck=true;
- RakNet::BitStream bitStream;
- SerializeHeader(&bitStream, isFunctionCall, tableName, columnNames, file, line, parameterList.paramCount);
- // int i;
- //for (i=0; i < parameterList.paramCount; i++)
- // parameterList.parms[i].Serialize(&bitStream);
- if (parameterList.paramCount>=1)
- parameterList.p0.Serialize(&bitStream);
- if (parameterList.paramCount>=2)
- parameterList.p1.Serialize(&bitStream);
- if (parameterList.paramCount>=3)
- parameterList.p2.Serialize(&bitStream);
- if (parameterList.paramCount>=4)
- parameterList.p3.Serialize(&bitStream);
- if (parameterList.paramCount>=5)
- parameterList.p4.Serialize(&bitStream);
- if (parameterList.paramCount>=6)
- parameterList.p5.Serialize(&bitStream);
- if (parameterList.paramCount>=7)
- parameterList.p6.Serialize(&bitStream);
- if (parameterList.paramCount>=8)
- parameterList.p7.Serialize(&bitStream);
- if (parameterList.paramCount>=9)
- parameterList.p8.Serialize(&bitStream);
- if (parameterList.paramCount>=10)
- parameterList.p9.Serialize(&bitStream);
- if (parameterList.paramCount>=11)
- parameterList.p10.Serialize(&bitStream);
- if (parameterList.paramCount>=12)
- parameterList.p11.Serialize(&bitStream);
- if (parameterList.paramCount>=13)
- parameterList.p12.Serialize(&bitStream);
- if (parameterList.paramCount>=14)
- parameterList.p13.Serialize(&bitStream);
- if (parameterList.paramCount>=15)
- parameterList.p14.Serialize(&bitStream);
- if (memoryConstraint!=0 && tcpInterface)
- {
- if (tcpInterface->GetOutgoingDataBufferSize(serverAddress)+bitStream.GetNumberOfBytesUsed()>=memoryConstraint)
- {
- recursiveCheck=false;
- return SQLLR_WOULD_EXCEED_MEMORY_CONSTRAINT;
- }
- }
- SendUnified(&bitStream, LOW_PRIORITY, RELIABLE_ORDERED, 1, serverAddress, false);
- recursiveCheck=false;
- return SQLLR_OK;
- }
- /*
- SQLLogResult SQLiteClientLoggerPlugin::SqlLog( bool isFunctionCall, const char *tableName, const char *columnNames, const char *file, const int line )
- {
- RakNet::BitStream bitStream;
- SerializeHeader(&bitStream, isFunctionCall, tableName, columnNames, file, line, 0);
- SendUnified(&bitStream, LOW_PRIORITY, RELIABLE_ORDERED, 1, serverAddress, false);
- return SQLLR_OK;
- }
- SQLLogResult SQLiteClientLoggerPlugin::SqlLog( bool isFunctionCall, const char *tableName, const char *columnNames, const char *file, const int line, const LogParameter *p1 )
- {
- RakNet::BitStream bitStream;
- SerializeHeader(&bitStream, isFunctionCall, tableName, columnNames, file, line, 1);
- p1->Serialize(&bitStream);
- SendUnified(&bitStream, LOW_PRIORITY, RELIABLE_ORDERED, 1, serverAddress, false);
- return SQLLR_OK;
- }
- SQLLogResult SQLiteClientLoggerPlugin::SqlLog( bool isFunctionCall, const char *tableName, const char *columnNames, const char *file, const int line, const LogParameter *p1, const LogParameter *p2 )
- {
- RakNet::BitStream bitStream;
- SerializeHeader(&bitStream, isFunctionCall, tableName, columnNames, file, line, 2);
- p1->Serialize(&bitStream);
- p2->Serialize(&bitStream);
- SendUnified(&bitStream, LOW_PRIORITY, RELIABLE_ORDERED, 1, serverAddress, false);
- return SQLLR_OK;
- }
- SQLLogResult SQLiteClientLoggerPlugin::SqlLog( bool isFunctionCall, const char *tableName, const char *columnNames, const char *file, const int line, const LogParameter *p1, const LogParameter *p2, const LogParameter *p3 )
- {
- RakNet::BitStream bitStream;
- SerializeHeader(&bitStream, isFunctionCall, tableName, columnNames, file, line, 3);
- p1->Serialize(&bitStream);
- p2->Serialize(&bitStream);
- p3->Serialize(&bitStream);
- SendUnified(&bitStream, LOW_PRIORITY, RELIABLE_ORDERED, 1, serverAddress, false);
- return SQLLR_OK;
- }
- SQLLogResult SQLiteClientLoggerPlugin::SqlLog( bool isFunctionCall, const char *tableName, const char *columnNames, const char *file, const int line, const LogParameter *p1, const LogParameter *p2, const LogParameter *p3, const LogParameter *p4 )
- {
- RakNet::BitStream bitStream;
- SerializeHeader(&bitStream, isFunctionCall, tableName, columnNames, file, line, 4);
- p1->Serialize(&bitStream);
- p2->Serialize(&bitStream);
- p3->Serialize(&bitStream);
- p4->Serialize(&bitStream);
- SendUnified(&bitStream, LOW_PRIORITY, RELIABLE_ORDERED, 1, serverAddress, false);
- return SQLLR_OK;
- }
- SQLLogResult SQLiteClientLoggerPlugin::SqlLog( bool isFunctionCall, const char *tableName, const char *columnNames, const char *file, const int line, const LogParameter *p1, const LogParameter *p2, const LogParameter *p3, const LogParameter *p4, const LogParameter *p5 )
- {
- RakNet::BitStream bitStream;
- SerializeHeader(&bitStream, isFunctionCall, tableName, columnNames, file, line, 5);
- p1->Serialize(&bitStream);
- p2->Serialize(&bitStream);
- p3->Serialize(&bitStream);
- p4->Serialize(&bitStream);
- p5->Serialize(&bitStream);
- SendUnified(&bitStream, LOW_PRIORITY, RELIABLE_ORDERED, 1, serverAddress, false);
- return SQLLR_OK;
- }
- SQLLogResult SQLiteClientLoggerPlugin::SqlLog( bool isFunctionCall, const char *tableName, const char *columnNames, const char *file, const int line, const LogParameter *p1, const LogParameter *p2, const LogParameter *p3, const LogParameter *p4, const LogParameter *p5, const LogParameter *p6 )
- {
- RakNet::BitStream bitStream;
- SerializeHeader(&bitStream, isFunctionCall, tableName, columnNames, file, line, 6);
- p1->Serialize(&bitStream);
- p2->Serialize(&bitStream);
- p3->Serialize(&bitStream);
- p4->Serialize(&bitStream);
- p5->Serialize(&bitStream);
- p6->Serialize(&bitStream);
- SendUnified(&bitStream, LOW_PRIORITY, RELIABLE_ORDERED, 1, serverAddress, false);
- return SQLLR_OK;
- }
- SQLLogResult SQLiteClientLoggerPlugin::SqlLog( bool isFunctionCall, const char *tableName, const char *columnNames, const char *file, const int line, const LogParameter *p1, const LogParameter *p2, const LogParameter *p3, const LogParameter *p4, const LogParameter *p5, const LogParameter *p6, const LogParameter *p7 )
- {
- RakNet::BitStream bitStream;
- SerializeHeader(&bitStream, isFunctionCall, tableName, columnNames, file, line, 7);
- p1->Serialize(&bitStream);
- p2->Serialize(&bitStream);
- p3->Serialize(&bitStream);
- p4->Serialize(&bitStream);
- p5->Serialize(&bitStream);
- p6->Serialize(&bitStream);
- p7->Serialize(&bitStream);
- SendUnified(&bitStream, LOW_PRIORITY, RELIABLE_ORDERED, 1, serverAddress, false);
- return SQLLR_OK;
- }
- SQLLogResult SQLiteClientLoggerPlugin::SqlLog( bool isFunctionCall, const char *tableName, const char *columnNames, const char *file, const int line, const LogParameter *p1, const LogParameter *p2, const LogParameter *p3, const LogParameter *p4, const LogParameter *p5, const LogParameter *p6, const LogParameter *p7, const LogParameter *p8 )
- {
- RakNet::BitStream bitStream;
- SerializeHeader(&bitStream, isFunctionCall, tableName, columnNames, file, line, 8);
- p1->Serialize(&bitStream);
- p2->Serialize(&bitStream);
- p3->Serialize(&bitStream);
- p4->Serialize(&bitStream);
- p5->Serialize(&bitStream);
- p6->Serialize(&bitStream);
- p7->Serialize(&bitStream);
- p8->Serialize(&bitStream);
- SendUnified(&bitStream, LOW_PRIORITY, RELIABLE_ORDERED, 1, serverAddress, false);
- return SQLLR_OK;
- }
- SQLLogResult SQLiteClientLoggerPlugin::SqlLog( bool isFunctionCall, const char *tableName, const char *columnNames, const char *file, const int line, const LogParameter *p1, const LogParameter *p2, const LogParameter *p3, const LogParameter *p4, const LogParameter *p5, const LogParameter *p6, const LogParameter *p7, const LogParameter *p8, const LogParameter *p9 )
- {
- RakNet::BitStream bitStream;
- SerializeHeader(&bitStream, isFunctionCall, tableName, columnNames, file, line, 9);
- p1->Serialize(&bitStream);
- p2->Serialize(&bitStream);
- p3->Serialize(&bitStream);
- p4->Serialize(&bitStream);
- p5->Serialize(&bitStream);
- p6->Serialize(&bitStream);
- p7->Serialize(&bitStream);
- p8->Serialize(&bitStream);
- p9->Serialize(&bitStream);
- SendUnified(&bitStream, LOW_PRIORITY, RELIABLE_ORDERED, 1, serverAddress, false);
- return SQLLR_OK;
- }
- SQLLogResult SQLiteClientLoggerPlugin::SqlLog( bool isFunctionCall, const char *tableName, const char *columnNames, const char *file, const int line, const LogParameter *p1, const LogParameter *p2, const LogParameter *p3, const LogParameter *p4, const LogParameter *p5, const LogParameter *p6, const LogParameter *p7, const LogParameter *p8, const LogParameter *p9, const LogParameter *p10 )
- {
- RakNet::BitStream bitStream;
- SerializeHeader(&bitStream, isFunctionCall, tableName, columnNames, file, line, 10);
- p1->Serialize(&bitStream);
- p2->Serialize(&bitStream);
- p3->Serialize(&bitStream);
- p4->Serialize(&bitStream);
- p5->Serialize(&bitStream);
- p6->Serialize(&bitStream);
- p7->Serialize(&bitStream);
- p8->Serialize(&bitStream);
- p9->Serialize(&bitStream);
- p10->Serialize(&bitStream);
- SendUnified(&bitStream, LOW_PRIORITY, RELIABLE_ORDERED, 1, serverAddress, false);
- return SQLLR_OK;
- }
- SQLLogResult SQLiteClientLoggerPlugin::SqlLog( bool isFunctionCall, const char *tableName, const char *columnNames, const char *file, const int line, const LogParameter *p1, const LogParameter *p2, const LogParameter *p3, const LogParameter *p4, const LogParameter *p5, const LogParameter *p6, const LogParameter *p7, const LogParameter *p8, const LogParameter *p9, const LogParameter *p10, const LogParameter *p11 )
- {
- RakNet::BitStream bitStream;
- SerializeHeader(&bitStream, isFunctionCall, tableName, columnNames, file, line, 11);
- p1->Serialize(&bitStream);
- p2->Serialize(&bitStream);
- p3->Serialize(&bitStream);
- p4->Serialize(&bitStream);
- p5->Serialize(&bitStream);
- p6->Serialize(&bitStream);
- p7->Serialize(&bitStream);
- p8->Serialize(&bitStream);
- p9->Serialize(&bitStream);
- p10->Serialize(&bitStream);
- p11->Serialize(&bitStream);
- SendUnified(&bitStream, LOW_PRIORITY, RELIABLE_ORDERED, 1, serverAddress, false);
- return SQLLR_OK;
- }
- SQLLogResult SQLiteClientLoggerPlugin::SqlLog( bool isFunctionCall, const char *tableName, const char *columnNames, const char *file, const int line, const LogParameter *p1, const LogParameter *p2, const LogParameter *p3, const LogParameter *p4, const LogParameter *p5, const LogParameter *p6, const LogParameter *p7, const LogParameter *p8, const LogParameter *p9, const LogParameter *p10, const LogParameter *p11, const LogParameter *p12 )
- {
- RakNet::BitStream bitStream;
- SerializeHeader(&bitStream, isFunctionCall, tableName, columnNames, file, line, 12);
- p1->Serialize(&bitStream);
- p2->Serialize(&bitStream);
- p3->Serialize(&bitStream);
- p4->Serialize(&bitStream);
- p5->Serialize(&bitStream);
- p6->Serialize(&bitStream);
- p7->Serialize(&bitStream);
- p8->Serialize(&bitStream);
- p9->Serialize(&bitStream);
- p10->Serialize(&bitStream);
- p11->Serialize(&bitStream);
- p12->Serialize(&bitStream);
- SendUnified(&bitStream, LOW_PRIORITY, RELIABLE_ORDERED, 1, serverAddress, false);
- return SQLLR_OK;
- }
- */
- SQLLogResult SQLiteClientLoggerPlugin::CheckQuery(bool isFunction, const char *tableName, const char *columnNames, int numParameters)
- {
- (void) isFunction;
- if (recursiveCheck==true)
- return SQLLR_RECURSION;
- if (tableName==0 || tableName[0]==0)
- return SQLLR_TABLE_NAME_BLANK;
- if (isFunction==true)
- return SQLLR_OK;
- if (columnNames==0 || columnNames[0]==0)
- {
- if (numParameters==0)
- return SQLLR_OK;
- return SQLLR_TABLE_DESCRIPTOR_FORMAT_WRONG_PARAMETER_COUNT;
- }
- recursiveCheck=true;
- if (dbIdentifier.IsEmpty())
- {
- recursiveCheck=false;
- return SQLLR_NO_DATABASE_SET;
- }
- unsigned int parameterCount=1;
- unsigned int columnNamesIndex=0;
- for (columnNamesIndex=1; columnNamesIndex < 512 && columnNames[columnNamesIndex]; columnNamesIndex++)
- {
- if (columnNames[columnNamesIndex]==COLUMN_NAMES_DELIMITER)
- {
- if (columnNames[columnNamesIndex-1]==COLUMN_NAMES_DELIMITER)
- {
- recursiveCheck=false;
- return SQLLR_TABLE_DESCRIPTOR_FORMAT_INVALID_SYNTAX;
- }
- parameterCount++;
- }
- }
- recursiveCheck=false;
- if (columnNamesIndex==MAX_COLUMN_NAMES_LENGTH)
- {
- return SQLLR_COLUMN_NAMES_NOT_TERMINATED;
- }
- if (parameterCount!=numParameters)
- {
- return SQLLR_TABLE_DESCRIPTOR_FORMAT_WRONG_PARAMETER_COUNT;
- }
- return SQLLR_OK;
- }
- void SQLiteClientLoggerPlugin::SerializeHeader(RakNet::BitStream *bitStream, bool isFunctionCall, const char *tableName, const char *columnNames, const char *file, const int line, unsigned char parameterCount ) const
- {
- bitStream->Write((MessageID) ID_SQLLITE_LOGGER);
- bitStream->Write(dbIdentifier);
- bitStream->Write(tableName);
- bitStream->Write(line);
- bitStream->Write(file);
- bitStream->Write(tickCount);
- bitStream->Write(RakNet::GetTimeMS());
- bitStream->Write(isFunctionCall);
- bitStream->Write(parameterCount);
- if (isFunctionCall==false && parameterCount>=1)
- {
- int stringIndices[64];
- int strIndex=0;
- stringIndices[strIndex++]=0;
- char columnNamesCopy[MAX_COLUMN_NAMES_LENGTH];
- RakAssert(strlen(columnNames)<MAX_COLUMN_NAMES_LENGTH);
- strncpy(columnNamesCopy, columnNames, MAX_COLUMN_NAMES_LENGTH);
- columnNamesCopy[MAX_COLUMN_NAMES_LENGTH-1]=0;
- for (int i=0; columnNamesCopy[i]; i++)
- {
- if (columnNamesCopy[i]==COLUMN_NAMES_DELIMITER)
- {
- columnNamesCopy[i]=0;
- stringIndices[strIndex++]=i+1;
- }
- }
- RakAssert(strIndex==parameterCount);
- for (int i=0; i < parameterCount; i++)
- {
- bitStream->Write((char*)columnNamesCopy + stringIndices[i]);
- }
- }
- }
- void SQLiteClientLoggerPlugin::Update(void)
- {
- SQLite3ClientPlugin::Update();
- }
|