1201 lines
39 KiB
Plaintext
1201 lines
39 KiB
Plaintext
#include "mn_i_jvm"
|
||
|
||
const int PERSISTENCE_METHOD_LOCAL_DEBUG = 1;
|
||
const int PERSISTENCE_METHOD_BIOWARE_DB = 2;
|
||
const int PERSISTENCE_METHOD_NWNX_ODBC = 3;
|
||
const int PERSISTENCE_METHOD_NWNX_JVM = 4;
|
||
|
||
const int PERSISTENCE_TYPE = PERSISTENCE_METHOD_BIOWARE_DB;
|
||
|
||
const string DEBUG_LOCAL_STORE_TAG = "LOCALDB";
|
||
|
||
const int DBTYPE_SQLLITE = 1;
|
||
const int DBTYPE_MYSQL = 2;
|
||
|
||
const int SQL_SUCCESS = 1;
|
||
const int SQL_ERROR = 0;
|
||
|
||
// Tablename constants
|
||
const string DEFAULT_TABLE = "pwdata";
|
||
const string OBJECTS_TABLE = "mn_objects";
|
||
const string VARIABLES_TABLE = "mn_variables";
|
||
|
||
const string MARKERS_TABLE = "mn_markers";
|
||
const string OBJECTSTORAGE_TABLE = "mn_storage";
|
||
const string QUESTPROGRESS_TABLE = "mn_quests";
|
||
const string EXPLORATION_TABLE = "mn_exploration";
|
||
const string PLAYERS_TABLE = "mn_players";
|
||
const string LOG_TABLE = "mn_eventlog";
|
||
const string BANLIST_TABLE = "mn_banlist";
|
||
const string LOGTYPE_META_TABLE = "mn_logtypenames";
|
||
const string LOGSUSPECT_META_TABLE = "mn_logsuspectnames";
|
||
const string AUTH_META_TABLE = "mn_authnames";
|
||
|
||
|
||
const int LOGSUSPECT_NORMAL = 0;
|
||
const int LOGSUSPECT_SUSPICIOUS = 1;
|
||
const int LOGSUSPECT_VIOLATION = 2;
|
||
|
||
const int LOGTYPE_MISC = 0;
|
||
const int LOGTYPE_LOGIN = 1;
|
||
const int LOGTYPE_LOGOUT = 2;
|
||
const int LOGTYPE_BOOTED = 3;
|
||
const int LOGTYPE_BANNED = 4;
|
||
const int LOGTYPE_WARNING = 5;
|
||
const int LOGTYPE_DMUSEDFUNCTION = 6;
|
||
const int LOGTYPE_ERROR = 7;
|
||
const int LOGTYPE_UNATHORIZED = 8;
|
||
const int LOGTYPE_SERVERUSEDFUNCTION = 9;
|
||
|
||
const int AUTH_UNVALIDATED = 0;
|
||
const int AUTH_PLAYER = 1;
|
||
const int AUTH_TRUSTED = 2;
|
||
const int AUTH_DM = 3;
|
||
const int AUTH_ADMIN = 4;
|
||
const int AUTH_CHEATER =-1;
|
||
|
||
const int EVENT_SERVERRESET = 1;
|
||
const int EVENT_PERMANENT_ABILITY_CHANGE = 2;
|
||
|
||
// Prototypes - most of these should be commented out, they are
|
||
// not really intended for direct use (except for adding whole new
|
||
// PW-level functions). Especially the indirect ones.
|
||
|
||
// Security functions (called indirectly)
|
||
int IsAccountOrKeyBanned(string accountName, string cdkey);
|
||
int ResolveUserAuth(string accountname, string charactername, string pass="", string cdkey="");
|
||
int ResolveUserID(string accountname, string charactername, string pass="", string cdkey="");
|
||
string ResolvePass(string accountname, string charactername, string cdkey="");
|
||
int IsAuthorized(object oPC, int authRequired);
|
||
string GeneratePass(object oPC);
|
||
void CreatePlayer(object oPC);
|
||
void AuthenticateExistingPlayer(object oPC);
|
||
void OnPlayerLogin(object oPC);
|
||
|
||
// DB Admin functions
|
||
void DbLog(string text, int type = LOGTYPE_ERROR, string uniqueID = "", int suspicious = LOGSUSPECT_NORMAL);
|
||
void InitTable(string table, object oPC = OBJECT_INVALID);
|
||
void InitializeAllTables(object oPC = OBJECT_INVALID);
|
||
void UpdatePlayerKey(object oPC, string newKey, object caller);
|
||
void UpdatePlayerAuthentification(object oPC, int newAuth, object caller);
|
||
void EraseDBForSpecificCharacter(string oPC, object caller);
|
||
|
||
// Raw DB functions (used indirectly)
|
||
void ExecuteSQLStatement( string statement);
|
||
int FetchNextRow();
|
||
string GetDataFromCurrentRow(int column);
|
||
string SQL_ConstructDeleteStatementSQLlite(string table, string ownerid, string varid);
|
||
string SQL_ConstructDropStatementSQLlite(string table);
|
||
|
||
// Data type conversion functions (used indirectly)
|
||
string EncodeVector(vector vVector);
|
||
vector DecodeVector(string sVector);
|
||
string EncodeLocation(location lLocation);
|
||
location DecodeLocation(string sLocation);
|
||
string EncodeSpecialChars(string sString);
|
||
string DecodeSpecialChars(string sString);
|
||
|
||
// Direct DB functions (used directly)
|
||
void InitDBConnection();
|
||
|
||
void StorePString(string table, string ownerid, string varid, string value);
|
||
string FetchPString(string table, string ownerid, string varid);
|
||
void StorePInt(string table, string ownerid, string varid, int value);
|
||
int FetchPInt(string table, string ownerid, string varid);
|
||
void StorePFloat(string table, string ownerid, string varid, float value);
|
||
float FetchPFloat(string table, string ownerid, string varid);
|
||
void StorePLocation(string table, string ownerid, string varid, location value);
|
||
location FetchPLocation(string table, string ownerid, string varid);
|
||
void StorePVector(string table, string ownerid, string varid, vector value);
|
||
vector FetchPVector(string table, string ownerid, string varid);
|
||
void StorePObject(string table, string ownerid, string varid, object value);
|
||
object FetchPObject(string table, string ownerid, string varid, object destinationInventory);
|
||
object FetchPObjectToLocation(string table, string ownerid, string varid, location destinationLocation);
|
||
void DeletePString(string table, string ownerid, string varid);
|
||
void DestroyPersistentVarsOnObject(string ownerid);
|
||
|
||
void ClearTable(string table, string ownerid, string varid, int sDB=DBTYPE_MYSQL, object oPC=OBJECT_INVALID);
|
||
void DropTable(string table, int db=DBTYPE_MYSQL, object oPC=OBJECT_INVALID);
|
||
|
||
|
||
// Methods
|
||
|
||
//void main(){}
|
||
|
||
int IsAccountOrKeyBanned(string accountName, string cdkey)
|
||
{
|
||
return FALSE;
|
||
}
|
||
|
||
void InitDBConnection()
|
||
{
|
||
if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_LOCAL_DEBUG ||
|
||
PERSISTENCE_TYPE == PERSISTENCE_METHOD_BIOWARE_DB ||
|
||
PERSISTENCE_TYPE == PERSISTENCE_METHOD_NWNX_JVM)
|
||
{
|
||
return;
|
||
}
|
||
else if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_NWNX_ODBC)
|
||
{
|
||
int i;
|
||
|
||
// Placeholder for ODBC memory usage
|
||
string sMemory;
|
||
|
||
for (i = 0; i < 8; i++) // reserve 8*128 bytes
|
||
sMemory +=
|
||
"................................................................................................................................";
|
||
|
||
SetLocalString(GetModule(), "NWNX!ODBC!SPACER", sMemory);
|
||
}
|
||
}
|
||
|
||
void ExecuteSQLStatement( string statement)
|
||
{
|
||
if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_LOCAL_DEBUG ||
|
||
PERSISTENCE_TYPE == PERSISTENCE_METHOD_BIOWARE_DB)
|
||
{
|
||
return;
|
||
}
|
||
else if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_NWNX_ODBC)
|
||
{
|
||
// if ( isAuthorized(oPC, AUTH_ADMIN) )
|
||
// {
|
||
SetLocalString(GetModule(), "NWNX!ODBC!EXEC", statement);
|
||
// }
|
||
}
|
||
else if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_NWNX_JVM)
|
||
{
|
||
NWNX_JVM(JVM_EVENT_SQL_EXECUTE, GetModule(), statement);
|
||
}
|
||
}
|
||
|
||
int FetchNextRow()
|
||
{
|
||
if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_LOCAL_DEBUG ||
|
||
PERSISTENCE_TYPE == PERSISTENCE_METHOD_BIOWARE_DB)
|
||
{
|
||
return SQL_ERROR;
|
||
}
|
||
else if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_NWNX_ODBC)
|
||
{
|
||
string row;
|
||
object module = GetModule();
|
||
|
||
SetLocalString(module, "NWNX!ODBC!FETCH", GetLocalString(module, "NWNX!ODBC!SPACER"));
|
||
row = GetLocalString(module, "NWNX!ODBC!FETCH");
|
||
if (GetStringLength(row) > 0)
|
||
{
|
||
SetLocalString(module, "NWNX_ODBC_CurrentRow", row);
|
||
return SQL_SUCCESS;
|
||
}
|
||
else
|
||
{
|
||
SetLocalString(module, "NWNX_ODBC_CurrentRow", "");
|
||
return SQL_ERROR;
|
||
}
|
||
}
|
||
else if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_NWNX_JVM)
|
||
{
|
||
string row = NWNX_JVM(JVM_EVENT_SQL_FETCH, GetModule());
|
||
object module = GetModule();
|
||
|
||
if (GetStringLength(row) > 0)
|
||
{
|
||
SetLocalString(module, "NWNX_JVM_CurrentRow", row);
|
||
return SQL_SUCCESS;
|
||
}
|
||
else
|
||
{
|
||
SetLocalString(module, "NWNX_JVM_CurrentRow", "");
|
||
return SQL_ERROR;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
return SQL_ERROR;
|
||
}
|
||
}
|
||
|
||
string GetDataFromCurrentRow(int column)
|
||
{
|
||
if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_LOCAL_DEBUG ||
|
||
PERSISTENCE_TYPE == PERSISTENCE_METHOD_BIOWARE_DB)
|
||
{
|
||
return "";
|
||
}
|
||
else if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_NWNX_ODBC)
|
||
{
|
||
int position;
|
||
string resultSet = GetLocalString(GetModule(), "NWNX_ODBC_CurrentRow");
|
||
|
||
// find column in current row
|
||
int count = 0;
|
||
string columnValue = "";
|
||
|
||
position = FindSubString(resultSet, "<22>");
|
||
if ((position == -1) && (column == 1))
|
||
{
|
||
// only one column, return value immediately
|
||
columnValue = resultSet;
|
||
}
|
||
else if (position == -1)
|
||
{
|
||
// only one column but requested column > 1
|
||
columnValue = "";
|
||
}
|
||
else
|
||
{
|
||
// loop through columns until found
|
||
while (count != column)
|
||
{
|
||
count++;
|
||
if (count == column)
|
||
columnValue = GetStringLeft(resultSet, position);
|
||
else
|
||
{
|
||
resultSet = GetStringRight(resultSet, GetStringLength(resultSet) - position - 1);
|
||
position = FindSubString(resultSet, "<22>");
|
||
}
|
||
|
||
// special case: last column in row
|
||
if (position == -1)
|
||
position = GetStringLength(resultSet);
|
||
}
|
||
}
|
||
return columnValue;
|
||
}
|
||
else if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_NWNX_JVM)
|
||
{
|
||
int position;
|
||
string resultSet = GetLocalString(GetModule(), "NWNX_JVM_CurrentRow");
|
||
|
||
// find column in current row
|
||
int count = 0;
|
||
string columnValue = "";
|
||
|
||
position = FindSubString(resultSet, "~");
|
||
if ((position == -1) && (column == 1))
|
||
{
|
||
// only one column, return value immediately
|
||
columnValue = resultSet;
|
||
}
|
||
else if (position == -1)
|
||
{
|
||
// only one column but requested column > 1
|
||
columnValue = "";
|
||
}
|
||
else
|
||
{
|
||
// loop through columns until found
|
||
while (count != column)
|
||
{
|
||
count++;
|
||
if (count == column)
|
||
columnValue = GetStringLeft(resultSet, position);
|
||
else
|
||
{
|
||
resultSet = GetStringRight(resultSet, GetStringLength(resultSet) - position - 1);
|
||
position = FindSubString(resultSet, "~");
|
||
}
|
||
|
||
// special case: last column in row
|
||
if (position == -1)
|
||
position = GetStringLength(resultSet);
|
||
}
|
||
}
|
||
return columnValue;
|
||
}
|
||
else
|
||
{
|
||
return "";
|
||
}
|
||
|
||
}
|
||
|
||
// Data type handling
|
||
|
||
string EncodeVector(vector vVector)
|
||
{
|
||
return "#POSITION_X#" + FloatToString(vVector.x) + "#POSITION_Y#" + FloatToString(vVector.y) +
|
||
"#POSITION_Z#" + FloatToString(vVector.z) + "#END#";
|
||
}
|
||
|
||
vector DecodeVector(string sVector)
|
||
{
|
||
float fX, fY, fZ;
|
||
int iPos, iCount;
|
||
int iLen = GetStringLength(sVector);
|
||
|
||
if (iLen > 0)
|
||
{
|
||
iPos = FindSubString(sVector, "#POSITION_X#") + 12;
|
||
iCount = FindSubString(GetSubString(sVector, iPos, iLen - iPos), "#");
|
||
fX = StringToFloat(GetSubString(sVector, iPos, iCount));
|
||
|
||
iPos = FindSubString(sVector, "#POSITION_Y#") + 12;
|
||
iCount = FindSubString(GetSubString(sVector, iPos, iLen - iPos), "#");
|
||
fY = StringToFloat(GetSubString(sVector, iPos, iCount));
|
||
|
||
iPos = FindSubString(sVector, "#POSITION_Z#") + 12;
|
||
iCount = FindSubString(GetSubString(sVector, iPos, iLen - iPos), "#");
|
||
fZ = StringToFloat(GetSubString(sVector, iPos, iCount));
|
||
}
|
||
|
||
return Vector(fX, fY, fZ);
|
||
}
|
||
|
||
string EncodeLocation(location lLocation)
|
||
{
|
||
object oArea = GetAreaFromLocation(lLocation);
|
||
vector vPosition = GetPositionFromLocation(lLocation);
|
||
float fOrientation = GetFacingFromLocation(lLocation);
|
||
string sReturnValue;
|
||
|
||
if (GetIsObjectValid(oArea))
|
||
sReturnValue =
|
||
"#AREA#" + GetTag(oArea) + "#POSITION_X#" + FloatToString(vPosition.x) +
|
||
"#POSITION_Y#" + FloatToString(vPosition.y) + "#POSITION_Z#" +
|
||
FloatToString(vPosition.z) + "#ORIENTATION#" + FloatToString(fOrientation) + "#END#";
|
||
|
||
return sReturnValue;
|
||
}
|
||
|
||
location DecodeLocation(string sLocation)
|
||
{
|
||
location lReturnValue;
|
||
object oArea;
|
||
vector vPosition;
|
||
float fOrientation, fX, fY, fZ;
|
||
|
||
int iPos, iCount;
|
||
int iLen = GetStringLength(sLocation);
|
||
|
||
if (iLen > 0)
|
||
{
|
||
iPos = FindSubString(sLocation, "#AREA#") + 6;
|
||
iCount = FindSubString(GetSubString(sLocation, iPos, iLen - iPos), "#");
|
||
oArea = GetObjectByTag(GetSubString(sLocation, iPos, iCount));
|
||
|
||
iPos = FindSubString(sLocation, "#POSITION_X#") + 12;
|
||
iCount = FindSubString(GetSubString(sLocation, iPos, iLen - iPos), "#");
|
||
fX = StringToFloat(GetSubString(sLocation, iPos, iCount));
|
||
|
||
iPos = FindSubString(sLocation, "#POSITION_Y#") + 12;
|
||
iCount = FindSubString(GetSubString(sLocation, iPos, iLen - iPos), "#");
|
||
fY = StringToFloat(GetSubString(sLocation, iPos, iCount));
|
||
|
||
iPos = FindSubString(sLocation, "#POSITION_Z#") + 12;
|
||
iCount = FindSubString(GetSubString(sLocation, iPos, iLen - iPos), "#");
|
||
fZ = StringToFloat(GetSubString(sLocation, iPos, iCount));
|
||
|
||
vPosition = Vector(fX, fY, fZ);
|
||
|
||
iPos = FindSubString(sLocation, "#ORIENTATION#") + 13;
|
||
iCount = FindSubString(GetSubString(sLocation, iPos, iLen - iPos), "#");
|
||
fOrientation = StringToFloat(GetSubString(sLocation, iPos, iCount));
|
||
|
||
lReturnValue = Location(oArea, vPosition, fOrientation);
|
||
}
|
||
|
||
return lReturnValue;
|
||
}
|
||
// Problems can arise with SQL commands if variables or values have single quotes
|
||
// in their names. These functions are a replace these quote with the tilde character
|
||
|
||
string EncodeSpecialChars(string sString)
|
||
{
|
||
if (FindSubString(sString, "'") == -1) // not found
|
||
return sString;
|
||
|
||
int i;
|
||
string sReturn = "";
|
||
string sChar;
|
||
|
||
// Loop over every character and replace special characters
|
||
for (i = 0; i < GetStringLength(sString); i++)
|
||
{
|
||
sChar = GetSubString(sString, i, 1);
|
||
if (sChar == "'")
|
||
sReturn += "~";
|
||
else
|
||
sReturn += sChar;
|
||
}
|
||
return sReturn;
|
||
}
|
||
|
||
string DecodeSpecialChars(string sString)
|
||
{
|
||
if (FindSubString(sString, "~") == -1) // not found
|
||
return sString;
|
||
|
||
int i;
|
||
string sReturn = "";
|
||
string sChar;
|
||
|
||
// Loop over every character and replace special characters
|
||
for (i = 0; i < GetStringLength(sString); i++)
|
||
{
|
||
sChar = GetSubString(sString, i, 1);
|
||
if (sChar == "~")
|
||
sReturn += "'";
|
||
else
|
||
sReturn += sChar;
|
||
}
|
||
return sReturn;
|
||
}
|
||
|
||
// Data access functions
|
||
void DeletePString(string table, string ownerid, string varid)
|
||
{
|
||
if (ownerid == "")
|
||
{
|
||
// Do not allow persisting if subject id is invalid
|
||
return;
|
||
}
|
||
|
||
varid = EncodeSpecialChars(varid);
|
||
if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_LOCAL_DEBUG)
|
||
{
|
||
object item = GetItemPossessedBy(GetFirstPC(), DEBUG_LOCAL_STORE_TAG);
|
||
if (!GetIsObjectValid(item))
|
||
{
|
||
item = CreateItemOnObject(GetStringLowerCase(DEBUG_LOCAL_STORE_TAG), GetFirstPC(), 1, DEBUG_LOCAL_STORE_TAG);
|
||
return;
|
||
}
|
||
DeleteLocalString(item, table+":"+ownerid+":"+varid);
|
||
return;
|
||
}
|
||
else if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_BIOWARE_DB)
|
||
{
|
||
DeleteCampaignVariable(table, ownerid+":"+varid);
|
||
}
|
||
else
|
||
{
|
||
string SQL = "DELETE * FROM " + table + " WHERE ownerid='" + ownerid +
|
||
"' AND varid='" + varid + "'";
|
||
ExecuteSQLStatement(SQL);
|
||
}
|
||
|
||
}
|
||
|
||
void StorePString(string table, string ownerid, string varid, string value)
|
||
{
|
||
// FloatingTextStringOnCreature("StorePString( table:"+table+", ownerid:"+ownerid+", varid:"+varid+", value:"+value+" )", GetFirstPC(), FALSE);
|
||
|
||
if (ownerid == "" ||varid == "")
|
||
{
|
||
// Do not allow persisting if subject id is invalid
|
||
return;
|
||
}
|
||
|
||
varid = EncodeSpecialChars(varid);
|
||
value = EncodeSpecialChars(value);
|
||
|
||
if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_LOCAL_DEBUG)
|
||
{
|
||
object item = GetItemPossessedBy(GetFirstPC(), DEBUG_LOCAL_STORE_TAG);
|
||
if (!GetIsObjectValid(item))
|
||
{
|
||
item = CreateItemOnObject(GetStringLowerCase(DEBUG_LOCAL_STORE_TAG), GetFirstPC(), 1, DEBUG_LOCAL_STORE_TAG);
|
||
}
|
||
SetLocalString(item, table+":"+ownerid+":"+varid, value);
|
||
return;
|
||
}
|
||
else if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_BIOWARE_DB)
|
||
{
|
||
// SendMessageToPC(GetFirstPC(), "SetCampaignString("+table+", "+ownerid+":"+varid+", "+value+");");
|
||
SetCampaignString(table, ownerid+":"+varid, value);
|
||
}
|
||
else
|
||
{
|
||
string SQL = "SELECT ownerid FROM " + table + " WHERE ownerid='" + ownerid +
|
||
"' AND varid='" + varid + "'";
|
||
ExecuteSQLStatement(SQL);
|
||
|
||
if (FetchNextRow() == SQL_SUCCESS)
|
||
{
|
||
// row exists
|
||
SQL = "UPDATE " + table + " SET value='" + value +
|
||
"' WHERE ownerid='" + ownerid +
|
||
"' AND varid='" + varid + "'";
|
||
ExecuteSQLStatement(SQL);
|
||
}
|
||
else
|
||
{
|
||
// row doesn't exist
|
||
SQL = "INSERT INTO " + table + " (ownerid,varid,value) VALUES" +
|
||
"('" + ownerid + "','" + varid + "','" +
|
||
value + "')";
|
||
ExecuteSQLStatement(SQL);
|
||
}
|
||
}
|
||
}
|
||
|
||
string FetchPString(string table, string ownerid, string varid)
|
||
{
|
||
// FloatingTextStringOnCreature("FetchPString( table:"+table+", ownerid:"+ownerid+", varid:"+varid+" )", GetFirstPC(), FALSE);
|
||
|
||
if (ownerid == "" || varid == "")
|
||
{
|
||
// Do not allow persisting if subject id is invalid
|
||
return "";
|
||
}
|
||
varid = EncodeSpecialChars(varid);
|
||
|
||
if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_LOCAL_DEBUG)
|
||
{
|
||
object item = GetItemPossessedBy(GetFirstPC(), DEBUG_LOCAL_STORE_TAG);
|
||
if (!GetIsObjectValid(item))
|
||
{
|
||
item = CreateItemOnObject(GetStringLowerCase(DEBUG_LOCAL_STORE_TAG), GetFirstPC(), 1, DEBUG_LOCAL_STORE_TAG);
|
||
return "";
|
||
}
|
||
return DecodeSpecialChars(GetLocalString(item, table+":"+ownerid+":"+varid));
|
||
}
|
||
else if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_BIOWARE_DB)
|
||
{
|
||
// SendMessageToPC(GetFirstPC(), "GetCampaignString("+table+", "+ownerid+":"+varid+");");
|
||
return GetCampaignString(table, ownerid+":"+varid);
|
||
}
|
||
else
|
||
{
|
||
string SQL = "SELECT value FROM " + table + " WHERE ownerid='" + ownerid +
|
||
"' AND varid='" + varid + "'";
|
||
ExecuteSQLStatement(SQL);
|
||
|
||
if (FetchNextRow() == SQL_SUCCESS)
|
||
return DecodeSpecialChars(GetDataFromCurrentRow(1));
|
||
else
|
||
{
|
||
return "";
|
||
// If you want to convert your existing persistent data to APS, this
|
||
// would be the place to do it. The requested variable was not found
|
||
// in the database, you should
|
||
// 1) query it's value using your existing persistence functions
|
||
// 2) save the value to the database using SetPersistentString()
|
||
// 3) return the string value here.
|
||
}
|
||
}
|
||
}
|
||
|
||
void StorePInt(string table, string ownerid, string varid, int value)
|
||
{
|
||
StorePString(table, ownerid, varid, IntToString(value) );
|
||
}
|
||
|
||
int FetchPInt(string table, string ownerid, string varid)
|
||
{
|
||
int returnValue = 0;
|
||
string result = FetchPString(table, ownerid, varid);
|
||
if (result != "")
|
||
{
|
||
returnValue = StringToInt(result);
|
||
}
|
||
|
||
return returnValue;
|
||
}
|
||
|
||
void StorePFloat(string table, string ownerid, string varid, float value)
|
||
{
|
||
StorePString(table, ownerid, varid, FloatToString(value) );
|
||
}
|
||
|
||
float FetchPFloat(string table, string ownerid, string varid)
|
||
{
|
||
float returnValue = 0.0;
|
||
string result = FetchPString(table, ownerid, varid);
|
||
if (result != "")
|
||
{
|
||
returnValue = StringToFloat(result);
|
||
}
|
||
|
||
return returnValue;
|
||
}
|
||
|
||
void StorePLocation(string table, string ownerid, string varid, location value)
|
||
{
|
||
StorePString(table, ownerid, varid, EncodeLocation(value) );
|
||
}
|
||
|
||
location FetchPLocation(string table, string ownerid, string varid)
|
||
{
|
||
return DecodeLocation( FetchPString( table, ownerid, varid ) );
|
||
}
|
||
|
||
void StorePVector(string table, string ownerid, string varid, vector value)
|
||
{
|
||
StorePString(table, ownerid, varid, EncodeVector(value) );
|
||
}
|
||
|
||
vector FetchPVector(string table, string ownerid, string varid)
|
||
{
|
||
return DecodeVector( FetchPString( table, ownerid, varid ) );
|
||
}
|
||
|
||
// ------
|
||
|
||
void StorePObject(string table, string ownerid, string varid, object value)
|
||
{
|
||
if (ownerid == "")
|
||
{
|
||
// Do not allow persisting if subject id is invalid
|
||
return;
|
||
}
|
||
|
||
if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_LOCAL_DEBUG)
|
||
{
|
||
return;
|
||
}
|
||
else if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_BIOWARE_DB)
|
||
{
|
||
StoreCampaignObject(table, ownerid+":"+varid, value);
|
||
}
|
||
else if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_NWNX_ODBC)
|
||
{
|
||
varid = EncodeSpecialChars(varid);
|
||
string SQL = "SELECT ownerid FROM " + table + " WHERE ownerid='"+ ownerid +
|
||
"' AND varid='"+ varid + "'";
|
||
ExecuteSQLStatement(SQL);
|
||
|
||
if (FetchNextRow() == SQL_SUCCESS)
|
||
{
|
||
// row exists
|
||
SQL = "UPDATE " + table +" SET value=%s WHERE ownerid='"+ ownerid +"' AND varid='" + varid + "'";
|
||
SetLocalString(GetModule(), "NWNX!ODBC!SETSCORCOSQL", SQL);
|
||
StoreCampaignObject ("NWNX", "-", value);
|
||
}
|
||
else
|
||
{
|
||
// row doesn't exist
|
||
SQL = "INSERT INTO " + table + " (ownerid,varid,value) VALUES" +
|
||
"('" + ownerid + "','" + varid + "',%s)";
|
||
SetLocalString(GetModule(), "NWNX!ODBC!SETSCORCOSQL", SQL);
|
||
StoreCampaignObject ("NWNX", "-", value);
|
||
}
|
||
}
|
||
else if ( PERSISTENCE_TYPE == PERSISTENCE_METHOD_NWNX_JVM )
|
||
{
|
||
string parameters = "db~"+ownerid+"~"+varid;
|
||
StoreCampaignObject("JVM", parameters, value);
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
return;
|
||
}
|
||
|
||
|
||
}
|
||
|
||
object FetchPObject(string table, string ownerid, string varid, object destinationInventory)
|
||
{
|
||
if (ownerid == "")
|
||
{
|
||
// Do not allow persisting if subject id is invalid
|
||
return OBJECT_INVALID;
|
||
}
|
||
|
||
if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_LOCAL_DEBUG)
|
||
{
|
||
return OBJECT_INVALID;
|
||
}
|
||
else if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_BIOWARE_DB)
|
||
{
|
||
return RetrieveCampaignObject(table, ownerid+":"+varid, GetLocation(destinationInventory), destinationInventory);
|
||
}
|
||
else if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_NWNX_ODBC)
|
||
{
|
||
varid = EncodeSpecialChars(varid);
|
||
|
||
string SQL = "SELECT value FROM " + table + " WHERE ownerid='" + ownerid +
|
||
"' AND varid='" + varid + "'";
|
||
SetLocalString(GetModule(), "NWNX!ODBC!SETSCORCOSQL", SQL);
|
||
|
||
return RetrieveCampaignObject ("NWNX", "-", GetLocation(destinationInventory), destinationInventory);
|
||
}
|
||
else if ( PERSISTENCE_TYPE == PERSISTENCE_METHOD_NWNX_JVM )
|
||
{
|
||
object obj;
|
||
string parameters = "db~"+ownerid+"~"+varid;
|
||
obj = RetrieveCampaignObject("JVM", parameters, GetLocation(destinationInventory), destinationInventory);
|
||
return obj;
|
||
}
|
||
else
|
||
{
|
||
return OBJECT_INVALID;
|
||
}
|
||
}
|
||
|
||
object FetchPObjectToLocation(string table, string ownerid, string varid, location destinationLocation)
|
||
{
|
||
if (ownerid == "")
|
||
{
|
||
// Do not allow persisting if subject id is invalid
|
||
return OBJECT_INVALID;
|
||
}
|
||
|
||
if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_LOCAL_DEBUG)
|
||
{
|
||
return OBJECT_INVALID;
|
||
}
|
||
else if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_BIOWARE_DB)
|
||
{
|
||
return RetrieveCampaignObject(table, ownerid+":"+varid, destinationLocation);
|
||
}
|
||
else if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_NWNX_ODBC)
|
||
{
|
||
varid = EncodeSpecialChars(varid);
|
||
|
||
string SQL = "SELECT value FROM " + table + " WHERE ownerid='" + ownerid +
|
||
"' AND varid='" + varid + "'";
|
||
SetLocalString(GetModule(), "NWNX!ODBC!SETSCORCOSQL", SQL);
|
||
|
||
return RetrieveCampaignObject ("NWNX", "-", destinationLocation);
|
||
}
|
||
else if ( PERSISTENCE_TYPE == PERSISTENCE_METHOD_NWNX_JVM )
|
||
{
|
||
object obj;
|
||
string parameters = "db~"+ownerid+"~"+varid;
|
||
obj = RetrieveCampaignObject("JVM", parameters, destinationLocation);
|
||
return obj;
|
||
}
|
||
else
|
||
{
|
||
return OBJECT_INVALID;
|
||
}
|
||
}
|
||
|
||
// General SQL
|
||
|
||
string SQL_ConstructDeleteStatementSQLlite(string table, string ownerid, string varid)
|
||
{
|
||
string id = "ownerid='"+ownerid+"'";
|
||
string statement = "";
|
||
|
||
string end;
|
||
if (varid != "")
|
||
{
|
||
varid = EncodeSpecialChars(varid);
|
||
end = " AND varid='"+varid+"';";
|
||
}
|
||
else
|
||
{
|
||
end = ";";
|
||
}
|
||
|
||
statement = "DELETE FROM "+table+" WHERE "+id+end;
|
||
|
||
return statement;
|
||
}
|
||
|
||
string SQL_ConstructDropStatementSQLlite(string table = "")
|
||
{
|
||
string statement = "";
|
||
if (table != "")
|
||
{
|
||
statement = "DROP TABLE "+table;
|
||
}
|
||
return statement;
|
||
|
||
}
|
||
|
||
void ClearTable(string table, string ownerid, string varid = "", int sDB=DBTYPE_MYSQL, object oPC = OBJECT_INVALID)
|
||
{
|
||
if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_LOCAL_DEBUG)
|
||
{
|
||
return;
|
||
}
|
||
else if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_BIOWARE_DB)
|
||
{
|
||
DestroyCampaignDatabase(table);
|
||
}
|
||
else
|
||
{
|
||
if (IsAuthorized (oPC, AUTH_DM ) )
|
||
{
|
||
string statement = "";
|
||
switch (sDB)
|
||
{
|
||
case DBTYPE_MYSQL:
|
||
statement = SQL_ConstructDeleteStatementSQLlite(table, ownerid, varid);
|
||
break;
|
||
}
|
||
|
||
if (statement != "")
|
||
{
|
||
ExecuteSQLStatement(statement);
|
||
FloatingTextStringOnCreature(statement, GetFirstPC());
|
||
FloatingTextStringOnCreature("ownerid="+ownerid, GetFirstPC());
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void DropTable(string table, int db=DBTYPE_MYSQL, object oPC = OBJECT_INVALID)
|
||
{
|
||
if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_LOCAL_DEBUG)
|
||
{
|
||
return;
|
||
}
|
||
else if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_BIOWARE_DB)
|
||
{
|
||
DestroyCampaignDatabase(table);
|
||
}
|
||
else
|
||
{
|
||
|
||
if (IsAuthorized (oPC, AUTH_ADMIN) )
|
||
{
|
||
string statement = "";
|
||
switch (db)
|
||
{
|
||
case DBTYPE_MYSQL:
|
||
statement = SQL_ConstructDropStatementSQLlite(table);
|
||
break;
|
||
}
|
||
|
||
if (statement != "")
|
||
{
|
||
ExecuteSQLStatement(statement);
|
||
FloatingTextStringOnCreature(statement, GetFirstPC());
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// Administrator/administration scripts
|
||
//void pLog(string logtext, int logtype = LOGTYPE_MISC, int suspicious=LOGSUSPECT_NORMAL, string userid = "")
|
||
//{
|
||
//}
|
||
|
||
int ResolveUserAuth(string accountname, string charactername, string pass = "", string cdkey = "")
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
int ResolveUserID(string accountname, string charactername, string pass = "", string cdkey = "")
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
int IsAuthorized(object oPC, int authRequired)
|
||
{
|
||
int returnValue = FALSE;
|
||
if (oPC == OBJECT_INVALID)
|
||
{
|
||
returnValue = TRUE;
|
||
}
|
||
returnValue = TRUE; //FIXME
|
||
return returnValue;
|
||
}
|
||
|
||
void DbLog(string text, int type = LOGTYPE_ERROR, string uniqueID = "", int suspicious = LOGSUSPECT_NORMAL)
|
||
{
|
||
if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_LOCAL_DEBUG ||
|
||
PERSISTENCE_TYPE == PERSISTENCE_METHOD_BIOWARE_DB)
|
||
{
|
||
return;
|
||
}
|
||
ExecuteSQLStatement("INSERT INTO "+LOG_TABLE+" (text, type, suspicious, uniqueID) VALUES ('"+text+"', "+IntToString(type)+" , "+IntToString(suspicious)+" , "+uniqueID+");");
|
||
}
|
||
|
||
string GeneratePass(object oPC)
|
||
{
|
||
return "";
|
||
}
|
||
|
||
void CreatePlayer(object oPC)
|
||
{
|
||
string accountName = EncodeSpecialChars( GetPCPlayerName(oPC) );
|
||
string characterName = EncodeSpecialChars( GetName(oPC) );
|
||
string cdkey = GetPCPublicCDKey(oPC);
|
||
string auth = IntToString (AUTH_PLAYER) ;
|
||
string pass = GeneratePass(oPC);
|
||
|
||
if ( ResolveUserID(accountName, characterName) == 0 )
|
||
{
|
||
string SQL = "INSERT INTO "+PLAYERS_TABLE+" (accountname, charactername, cdkey, auth, pass) VALUES ('"+accountName+"', '"+characterName+"', '"+cdkey+"', '"+auth+"', '"+pass+"');";
|
||
ExecuteSQLStatement(SQL);
|
||
}
|
||
else
|
||
{
|
||
// Already exists - boot PC
|
||
BootPC(oPC);
|
||
DbLog("Warning - account "+accountName+" tried to login with new character named "+characterName+". Character already exists in database.", LOGTYPE_ERROR, "", LOGSUSPECT_SUSPICIOUS);
|
||
}
|
||
|
||
object token = CreateItemOnObject("mn_servertoken", oPC );
|
||
SetLocalString(token, "pass", pass);
|
||
SetXP(oPC, 1);
|
||
ExportSingleCharacter(oPC);
|
||
}
|
||
|
||
void AuthenticateExistingPlayer(object oPC)
|
||
{
|
||
string accountName = EncodeSpecialChars( GetPCPlayerName(oPC) );
|
||
string characterName = EncodeSpecialChars( GetName(oPC) );
|
||
string cdkey = GetPCPublicCDKey(oPC);
|
||
// int auth = resolveUserAuth(accountName, characterName, )
|
||
object token = GetItemPossessedBy(oPC, "mn_servertoken");
|
||
if (token != OBJECT_INVALID)
|
||
{
|
||
string pass = GetLocalString( token, "pass" );
|
||
}
|
||
|
||
|
||
}
|
||
|
||
void OnPlayerLogin(object oPC)
|
||
{
|
||
|
||
}
|
||
|
||
void UpdatePlayerKey(object oPC, string newKey, object caller=OBJECT_INVALID)
|
||
{
|
||
if (IsAuthorized (caller, AUTH_ADMIN) )
|
||
{
|
||
|
||
}
|
||
|
||
}
|
||
|
||
void UpdatePlayerAuthentification(object oPC, int newAuth, object caller=OBJECT_INVALID)
|
||
{
|
||
if (IsAuthorized (caller, AUTH_ADMIN) )
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
void EraseDBForSpecificCharacter(string oPC, object caller=OBJECT_INVALID)
|
||
{
|
||
|
||
}
|
||
|
||
// PW specific table initialization
|
||
void InitTable(string table, object oPC = OBJECT_INVALID)
|
||
{
|
||
if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_LOCAL_DEBUG ||
|
||
PERSISTENCE_TYPE == PERSISTENCE_METHOD_BIOWARE_DB)
|
||
{
|
||
return;
|
||
}
|
||
if (IsAuthorized (oPC, AUTH_ADMIN) )
|
||
{
|
||
if (table == OBJECTSTORAGE_TABLE)
|
||
{
|
||
DropTable(OBJECTSTORAGE_TABLE);
|
||
|
||
// SendMessageToPC(GetFirstPC(), "Table '"+OBJECTSTORAGE_TABLE+"' deleted.");
|
||
|
||
// For SQLite
|
||
// SendMessageToPC(GetFirstPC(), "Creating Table '"+OBJECTSTORAGE_TABLE+"' for SQLite...");
|
||
ExecuteSQLStatement("CREATE TABLE "+OBJECTSTORAGE_TABLE+" (" +
|
||
"ownerid varchar(64) NOT NULL default '~'," +
|
||
"varid varchar(64) NOT NULL default '~'," +
|
||
"value blob," +
|
||
"insertdate timestamp," +
|
||
"PRIMARY KEY (ownerid,varid)" +
|
||
")");
|
||
string SQL = "CREATE TRIGGER insert_storage AFTER INSERT ON "+OBJECTSTORAGE_TABLE+" BEGIN UPDATE "+OBJECTSTORAGE_TABLE+" SET insertdate = DATETIME('NOW') WHERE rowid = new.rowid; END;";
|
||
ExecuteSQLStatement(SQL);
|
||
|
||
// SendMessageToPC(GetFirstPC(), "Table '"+OBJECTSTORAGE_TABLE+"' created.");
|
||
}
|
||
else if (table == QUESTPROGRESS_TABLE)
|
||
{
|
||
DropTable(QUESTPROGRESS_TABLE);
|
||
|
||
// SendMessageToPC(GetFirstPC(), "Table '"+QUESTPROGRESS_TABLE+"' deleted.");
|
||
|
||
// For SQLite
|
||
// SendMessageToPC(GetFirstPC(), "Creating Table '"+QUESTPROGRESS_TABLE+"' for SQLite...");
|
||
ExecuteSQLStatement("CREATE TABLE "+QUESTPROGRESS_TABLE+" (" +
|
||
"ownerid varchar(64) NOT NULL default '~'," +
|
||
"varid varchar(64) NOT NULL default '~'," +
|
||
"value varchar(64) NOT NULL default '0'," +
|
||
"insertdate timestamp," +
|
||
"PRIMARY KEY (ownerid,varid)" +
|
||
")");
|
||
string SQL = "CREATE TRIGGER insert_quest AFTER INSERT ON "+QUESTPROGRESS_TABLE+" BEGIN UPDATE "+QUESTPROGRESS_TABLE+" SET insertdate = DATETIME('NOW') WHERE rowid = new.rowid; END;";
|
||
ExecuteSQLStatement(SQL);
|
||
|
||
// SendMessageToPC(GetFirstPC(), "Table '"+QUESTPROGRESS_TABLE+"' created.");
|
||
}
|
||
else if (table == EXPLORATION_TABLE)
|
||
{
|
||
DropTable(EXPLORATION_TABLE);
|
||
|
||
// SendMessageToPC(GetFirstPC(), "Table '"+EXPLORATION_TABLE+"' deleted.");
|
||
|
||
// For SQLite
|
||
// SendMessageToPC(GetFirstPC(), "Creating Table '"+EXPLORATION_TABLE+"' for SQLite...");
|
||
ExecuteSQLStatement("CREATE TABLE "+EXPLORATION_TABLE+" (" +
|
||
"ownerid varchar(64) NOT NULL default '~'," +
|
||
"varid varchar(64) NOT NULL default '~'," +
|
||
"value varchar(64) NOT NULL default '0'," +
|
||
"insertdate timestamp," +
|
||
"PRIMARY KEY (ownerid,varid)" +
|
||
")");
|
||
string SQL = "CREATE TRIGGER insert_exploration AFTER INSERT ON "+EXPLORATION_TABLE+" BEGIN UPDATE "+EXPLORATION_TABLE+" SET insertdate = DATETIME('NOW') WHERE rowid = new.rowid; END;";
|
||
ExecuteSQLStatement(SQL);
|
||
|
||
// SendMessageToPC(GetFirstPC(), "Table '"+EXPLORATION_TABLE+"' created.");
|
||
}
|
||
else if (table == PLAYERS_TABLE)
|
||
{
|
||
DropTable(PLAYERS_TABLE);
|
||
|
||
// SendMessageToPC(GetFirstPC(), "Table '"+PLAYERS_TABLE+"' deleted.");
|
||
|
||
// For SQLite
|
||
// SendMessageToPC(GetFirstPC(), "Creating Table '"+PLAYERS_TABLE+"' for SQLite...");
|
||
string SQL =
|
||
"CREATE TABLE "+PLAYERS_TABLE+" (" +
|
||
"uniqueid INTEGER," +
|
||
"accountname varchar(64) NOT NULL default '~'," +
|
||
"charactername varchar(64) NOT NULL default '~'," +
|
||
"cdkey varchar(64) NOT NULL default '~'," +
|
||
"auth varchar(64) NOT NULL default '-1'," +
|
||
"pass varchar(64) NOT NULL default '~'," +
|
||
"insertdate timestamp," +
|
||
"PRIMARY KEY (uniqueid)"+
|
||
");";
|
||
ExecuteSQLStatement(SQL);
|
||
// SendMessageToPC(GetFirstPC(), SQL);
|
||
SQL = "CREATE TRIGGER insert_player AFTER INSERT ON "+PLAYERS_TABLE+" BEGIN UPDATE "+PLAYERS_TABLE+" SET insertdate = DATETIME('NOW') WHERE rowid = new.rowid; END;";
|
||
ExecuteSQLStatement(SQL);
|
||
// SendMessageToPC(GetFirstPC(), SQL);
|
||
// executeSQLStatement("insert into mn_players (accountname, charactername, cdkey, auth, pass) values ('accname', 'charname', 'key', 'auth', 'pass');");
|
||
// SendMessageToPC(GetFirstPC(), "Table '"+PLAYERS_TABLE+"' created.");
|
||
}
|
||
else if (table == LOG_TABLE)
|
||
{
|
||
DropTable(LOG_TABLE);
|
||
|
||
// SendMessageToPC(GetFirstPC(), "Table '"+LOG_TABLE+"' deleted.");
|
||
|
||
// For SQLite
|
||
// SendMessageToPC(GetFirstPC(), "Creating Table '"+LOG_TABLE+"' for SQLite...");
|
||
string SQL = "CREATE TABLE "+LOG_TABLE+" (" +
|
||
"id INTEGER," +
|
||
"insertdate timestamp NOT NULL default current_timestamp," +
|
||
"text varchar(64) NOT NULL default '~'," +
|
||
"type varchar(64) NOT NULL default '0'," +
|
||
"suspicious varchar(64) NOT NULL default '0'," +
|
||
"uniqueid varchar(64) default '~'," +
|
||
"PRIMARY KEY (id)"+
|
||
");";
|
||
ExecuteSQLStatement(SQL);
|
||
SQL = "CREATE TRIGGER insert_log AFTER INSERT ON "+LOG_TABLE+" BEGIN UPDATE "+LOG_TABLE+" SET insertdate = DATETIME('NOW') WHERE rowid = new.rowid; END;";
|
||
ExecuteSQLStatement(SQL);
|
||
|
||
// SendMessageToPC(GetFirstPC(), SQL);
|
||
// SendMessageToPC(GetFirstPC(), "Table '"+LOG_TABLE+"' created.");
|
||
}
|
||
else if (table == LOGSUSPECT_META_TABLE)
|
||
{
|
||
DropTable(LOGSUSPECT_META_TABLE);
|
||
|
||
string SQL = "CREATE TABLE "+LOGSUSPECT_META_TABLE+" (" +
|
||
"id varchar(64) NOT NULL,"+
|
||
"description varchar(64) NOT NULL,"+
|
||
"PRIMARY KEY (id) );";
|
||
ExecuteSQLStatement(SQL);
|
||
ExecuteSQLStatement("INSERT INTO "+LOGSUSPECT_META_TABLE+" (id, description) VALUES ('0', 'Normal');");
|
||
ExecuteSQLStatement("INSERT INTO "+LOGSUSPECT_META_TABLE+" (id, description) VALUES ('1', 'Suspicious');");
|
||
ExecuteSQLStatement("INSERT INTO "+LOGSUSPECT_META_TABLE+" (id, description) VALUES ('2', 'Violation');");
|
||
}
|
||
else if (table == LOGTYPE_META_TABLE)
|
||
{
|
||
DropTable(LOGTYPE_META_TABLE);
|
||
|
||
string SQL = "CREATE TABLE "+LOGTYPE_META_TABLE+" (" +
|
||
"id varchar(64) NOT NULL,"+
|
||
"description varchar(64) NOT NULL,"+
|
||
"PRIMARY KEY (id) );";
|
||
ExecuteSQLStatement(SQL);
|
||
ExecuteSQLStatement("INSERT INTO "+LOGTYPE_META_TABLE+" (id, description) VALUES ('0', 'Misc');");
|
||
ExecuteSQLStatement("INSERT INTO "+LOGTYPE_META_TABLE+" (id, description) VALUES ('1', 'Login');");
|
||
ExecuteSQLStatement("INSERT INTO "+LOGTYPE_META_TABLE+" (id, description) VALUES ('2', 'Logout');");
|
||
ExecuteSQLStatement("INSERT INTO "+LOGTYPE_META_TABLE+" (id, description) VALUES ('3', 'Booted');");
|
||
ExecuteSQLStatement("INSERT INTO "+LOGTYPE_META_TABLE+" (id, description) VALUES ('4', 'Banned');");
|
||
ExecuteSQLStatement("INSERT INTO "+LOGTYPE_META_TABLE+" (id, description) VALUES ('5', 'Warning');");
|
||
ExecuteSQLStatement("INSERT INTO "+LOGTYPE_META_TABLE+" (id, description) VALUES ('6', 'DM function called');");
|
||
ExecuteSQLStatement("INSERT INTO "+LOGTYPE_META_TABLE+" (id, description) VALUES ('7', 'Error');");
|
||
ExecuteSQLStatement("INSERT INTO "+LOGTYPE_META_TABLE+" (id, description) VALUES ('8', 'Unauthorized action');");
|
||
}
|
||
else if (table == AUTH_META_TABLE)
|
||
{
|
||
DropTable(AUTH_META_TABLE);
|
||
|
||
string SQL = "CREATE TABLE "+AUTH_META_TABLE+" (" +
|
||
"id varchar(64) NOT NULL,"+
|
||
"description varchar(64) NOT NULL,"+
|
||
"PRIMARY KEY (id) );";
|
||
ExecuteSQLStatement(SQL);
|
||
ExecuteSQLStatement("INSERT INTO "+AUTH_META_TABLE+" (id, description) VALUES ('-1', 'CHEATER');");
|
||
ExecuteSQLStatement("INSERT INTO "+AUTH_META_TABLE+" (id, description) VALUES ('0', 'Unvalidated');");
|
||
ExecuteSQLStatement("INSERT INTO "+AUTH_META_TABLE+" (id, description) VALUES ('1', 'Player');");
|
||
ExecuteSQLStatement("INSERT INTO "+AUTH_META_TABLE+" (id, description) VALUES ('2', 'Trusted player');");
|
||
ExecuteSQLStatement("INSERT INTO "+AUTH_META_TABLE+" (id, description) VALUES ('3', 'DM');");
|
||
ExecuteSQLStatement("INSERT INTO "+AUTH_META_TABLE+" (id, description) VALUES ('4', 'Admin');");
|
||
}
|
||
else if (table == MARKERS_TABLE)
|
||
{
|
||
DropTable(MARKERS_TABLE);
|
||
ExecuteSQLStatement("CREATE TABLE "+MARKERS_TABLE+" (" +
|
||
"ownerid varchar(64) NOT NULL default '~'," +
|
||
"varid varchar(64) NOT NULL default '~'," +
|
||
"value varchar(64) NOT NULL default '0'," +
|
||
"insertdate timestamp," +
|
||
"PRIMARY KEY (ownerid,varid)" +
|
||
")");
|
||
string SQL = "CREATE TRIGGER insert_quest AFTER INSERT ON "+MARKERS_TABLE+" BEGIN UPDATE "+MARKERS_TABLE+" SET insertdate = DATETIME('NOW') WHERE rowid = new.rowid; END;";
|
||
ExecuteSQLStatement(SQL);
|
||
}
|
||
else
|
||
{
|
||
DbLog("Error: Attempt to reset unknown table called "+table);
|
||
}
|
||
}
|
||
}
|
||
|
||
void DestroyPersistentVarsOnObject(string ownerid)
|
||
{
|
||
// TODO
|
||
|
||
}
|
||
|
||
|
||
void InitializeAllTables(object oPC = OBJECT_INVALID)
|
||
{
|
||
if (PERSISTENCE_TYPE == PERSISTENCE_METHOD_LOCAL_DEBUG)
|
||
{
|
||
object item = GetItemPossessedBy(GetFirstPC(), DEBUG_LOCAL_STORE_TAG);
|
||
if (GetIsObjectValid(item))
|
||
{
|
||
DestroyObject(item);
|
||
}
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
if (IsAuthorized (oPC, AUTH_ADMIN) )
|
||
{
|
||
InitTable(OBJECTSTORAGE_TABLE);
|
||
InitTable(QUESTPROGRESS_TABLE);
|
||
InitTable(EXPLORATION_TABLE);
|
||
InitTable(PLAYERS_TABLE);
|
||
InitTable(LOG_TABLE);
|
||
InitTable(LOGSUSPECT_META_TABLE);
|
||
InitTable(LOGTYPE_META_TABLE);
|
||
InitTable(AUTH_META_TABLE);
|
||
InitTable(MARKERS_TABLE);
|
||
}
|
||
}
|
||
}
|
||
|
||
//void main(){}
|