Added character deleter

Added character deleter.  Updated aps_include.  Updated NWNxEE.
 Boosted XP rewards.  Added XP reward for skinnable creatures.  Full compile.  Updated release archive.
This commit is contained in:
Jaysyn904
2024-08-31 20:23:36 -04:00
parent 94b4c689da
commit 65af23f08d
404 changed files with 7949 additions and 6005 deletions

View File

@@ -1,7 +1,7 @@
// Name : Avlis Persistence System include
// Purpose : Various APS/NWNX2 related functions
// Authors : Ingmar Stieger, Adam Colon, Josh Simon
// Modified : January 1st, 2005
// Modified : December 21, 2003
// This file is licensed under the terms of the
// GNU GENERAL PUBLIC LICENSE (GPL) Version 2
@@ -10,12 +10,13 @@
/* Return codes */
/************************************/
const int SQL_ERROR = 0;
const int SQL_SUCCESS = 1;
int SQL_ERROR = 0;
int SQL_SUCCESS = 1;
/************************************/
/* Function prototypes */
/************************************/
sqlquery last_sql_query;
// Setup placeholders for ODBC requests and responses
void SQLInit();
@@ -61,45 +62,33 @@ vector APSStringToVector(string sVector);
// Optional parameters:
// iExpiration: Number of days the persistent variable should be kept in database (default: 0=forever)
// sTable: Name of the table where variable should be stored (default: pwdata)
void SetPersistentString(object oObject, string sVarName, string sValue, int iExpiration =
0, string sTable = "pwdata");
void SetPersistentString(object oObject, string sVarName, string sValue, int iExpiration = 0, string sTable = "pwdata");
// Set oObject's persistent integer variable sVarName to iValue
// Optional parameters:
// iExpiration: Number of days the persistent variable should be kept in database (default: 0=forever)
// sTable: Name of the table where variable should be stored (default: pwdata)
void SetPersistentInt(object oObject, string sVarName, int iValue, int iExpiration =
0, string sTable = "pwdata");
void SetPersistentInt(object oObject, string sVarName, int iValue, int iExpiration = 0, string sTable = "pwdata");
// Set oObject's persistent float variable sVarName to fValue
// Optional parameters:
// iExpiration: Number of days the persistent variable should be kept in database (default: 0=forever)
// sTable: Name of the table where variable should be stored (default: pwdata)
void SetPersistentFloat(object oObject, string sVarName, float fValue, int iExpiration =
0, string sTable = "pwdata");
void SetPersistentFloat(object oObject, string sVarName, float fValue, int iExpiration = 0, string sTable = "pwdata");
// Set oObject's persistent location variable sVarName to lLocation
// Optional parameters:
// iExpiration: Number of days the persistent variable should be kept in database (default: 0=forever)
// sTable: Name of the table where variable should be stored (default: pwdata)
// This function converts location to a string for storage in the database.
void SetPersistentLocation(object oObject, string sVarName, location lLocation, int iExpiration =
0, string sTable = "pwdata");
void SetPersistentLocation(object oObject, string sVarName, location lLocation, int iExpiration = 0, string sTable = "pwdata");
// Set oObject's persistent vector variable sVarName to vVector
// Optional parameters:
// iExpiration: Number of days the persistent variable should be kept in database (default: 0=forever)
// sTable: Name of the table where variable should be stored (default: pwdata)
// This function converts vector to a string for storage in the database.
void SetPersistentVector(object oObject, string sVarName, vector vVector, int iExpiration =
0, string sTable = "pwdata");
// Set oObject's persistent object with sVarName to sValue
// Optional parameters:
// iExpiration: Number of days the persistent variable should be kept in database (default: 0=forever)
// sTable: Name of the table where variable should be stored (default: pwobjdata)
void SetPersistentObject(object oObject, string sVarName, object oObject2, int iExpiration =
0, string sTable = "pwobjdata");
void SetPersistentVector(object oObject, string sVarName, vector vVector, int iExpiration = 0, string sTable = "pwdata");
// Get oObject's persistent string variable sVarName
// Optional parameters:
@@ -131,12 +120,6 @@ location GetPersistentLocation(object oObject, string sVarname, string sTable =
// * Return value on error: 0
vector GetPersistentVector(object oObject, string sVarName, string sTable = "pwdata");
// Get oObject's persistent object sVarName
// Optional parameters:
// sTable: Name of the table where object is stored (default: pwobjdata)
// * Return value on error: 0
object GetPersistentObject(object oObject, string sVarName, object oOwner = OBJECT_INVALID, string sTable = "pwobjdata");
// Delete persistent variable sVarName stored on oObject
// Optional parameters:
// sTable: Name of the table where variable is stored (default: pwdata)
@@ -156,40 +139,22 @@ string SQLDecodeSpecialChars(string sString);
void SQLInit()
{
int i;
// Placeholder for ODBC persistence
string sMemory;
for (i = 0; i < 8; i++) // reserve 8*128 bytes
sMemory +=
"................................................................................................................................";
SetLocalString(GetModule(), "NWNX!ODBC!SPACER", sMemory);
SQLExecDirect("CREATE TABLE IF NOT EXISTS pwdata(player varchar(64), tag varchar(64), name varchar(64), val text, expire int(11), last timestamp NOT NULL DEFAULT DEFAULT_TIMESTAMP, PRIMARY KEY (player,tag,name))");
}
void SQLExecDirect(string sSQL)
{
SetLocalString(GetModule(), "NWNX!ODBC!EXEC", sSQL);
sqlquery sql = SqlPrepareQueryCampaign("db",sSQL);
last_sql_query = sql;
if(GetStringLowerCase(GetStringLeft(sSQL,6)) != "select")
{
SqlStep(sql);
}
}
int SQLFetch()
{
string sRow;
object oModule = GetModule();
SetLocalString(oModule, "NWNX!ODBC!FETCH", GetLocalString(oModule, "NWNX!ODBC!SPACER"));
sRow = GetLocalString(oModule, "NWNX!ODBC!FETCH");
if (GetStringLength(sRow) > 0)
{
SetLocalString(oModule, "NWNX_ODBC_CurrentRow", sRow);
return SQL_SUCCESS;
}
else
{
SetLocalString(oModule, "NWNX_ODBC_CurrentRow", "");
return SQL_ERROR;
}
return SqlStep(last_sql_query);
}
// deprecated. use SQLFetch().
@@ -206,45 +171,7 @@ int SQLNextRow()
string SQLGetData(int iCol)
{
int iPos;
string sResultSet = GetLocalString(GetModule(), "NWNX_ODBC_CurrentRow");
// find column in current row
int iCount = 0;
string sColValue = "";
iPos = FindSubString(sResultSet, "<22>");
if ((iPos == -1) && (iCol == 1))
{
// only one column, return value immediately
sColValue = sResultSet;
}
else if (iPos == -1)
{
// only one column but requested column > 1
sColValue = "";
}
else
{
// loop through columns until found
while (iCount != iCol)
{
iCount++;
if (iCount == iCol)
sColValue = GetStringLeft(sResultSet, iPos);
else
{
sResultSet = GetStringRight(sResultSet, GetStringLength(sResultSet) - iPos - 1);
iPos = FindSubString(sResultSet, "<22>");
}
// special case: last column in row
if (iPos == -1)
iPos = GetStringLength(sResultSet);
}
}
return sColValue;
return SqlGetString(last_sql_query,iCol-1);
}
// These functions deal with various data types. Ultimately, all information
@@ -364,7 +291,7 @@ void SetPersistentString(object oObject, string sVarName, string sValue, int iEx
"' AND tag='" + sTag + "' AND name='" + sVarName + "'";
SQLExecDirect(sSQL);
if (SQLFetch() == SQL_SUCCESS)
if (SQLFirstRow() == SQL_SUCCESS)
{
// row exists
sSQL = "UPDATE " + sTable + " SET val='" + sValue +
@@ -404,7 +331,7 @@ string GetPersistentString(object oObject, string sVarName, string sTable = "pwd
"' AND tag='" + sTag + "' AND name='" + sVarName + "'";
SQLExecDirect(sSQL);
if (SQLFetch() == SQL_SUCCESS)
if (SQLFirstRow() == SQL_SUCCESS)
return SQLDecodeSpecialChars(SQLGetData(1));
else
{
@@ -426,30 +353,7 @@ void SetPersistentInt(object oObject, string sVarName, int iValue, int iExpirati
int GetPersistentInt(object oObject, string sVarName, string sTable = "pwdata")
{
string sPlayer;
string sTag;
object oModule;
if (GetIsPC(oObject))
{
sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oObject));
sTag = SQLEncodeSpecialChars(GetName(oObject));
}
else
{
sPlayer = "~";
sTag = GetTag(oObject);
}
sVarName = SQLEncodeSpecialChars(sVarName);
string sSQL = "SELECT val FROM " + sTable + " WHERE player='" + sPlayer +
"' AND tag='" + sTag + "' AND name='" + sVarName + "'";
SQLExecDirect(sSQL);
oModule = GetModule();
SetLocalString(oModule, "NWNX!ODBC!FETCH", "-2147483647");
return StringToInt(GetLocalString(oModule, "NWNX!ODBC!FETCH"));
return StringToInt(GetPersistentString(oObject, sVarName, sTable));
}
void SetPersistentFloat(object oObject, string sVarName, float fValue, int iExpiration =
@@ -460,30 +364,7 @@ void SetPersistentFloat(object oObject, string sVarName, float fValue, int iExpi
float GetPersistentFloat(object oObject, string sVarName, string sTable = "pwdata")
{
string sPlayer;
string sTag;
object oModule;
if (GetIsPC(oObject))
{
sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oObject));
sTag = SQLEncodeSpecialChars(GetName(oObject));
}
else
{
sPlayer = "~";
sTag = GetTag(oObject);
}
sVarName = SQLEncodeSpecialChars(sVarName);
string sSQL = "SELECT val FROM " + sTable + " WHERE player='" + sPlayer +
"' AND tag='" + sTag + "' AND name='" + sVarName + "'";
SQLExecDirect(sSQL);
oModule = GetModule();
SetLocalString(oModule, "NWNX!ODBC!FETCH", "-340282306073709650000000000000000000000.000000000");
return StringToFloat(GetLocalString(oModule, "NWNX!ODBC!FETCH"));
return StringToFloat(GetPersistentString(oObject, sVarName, sTable));
}
void SetPersistentLocation(object oObject, string sVarName, location lLocation, int iExpiration =
@@ -508,73 +389,6 @@ vector GetPersistentVector(object oObject, string sVarName, string sTable = "pwd
return APSStringToVector(GetPersistentString(oObject, sVarName, sTable));
}
void SetPersistentObject(object oOwner, string sVarName, object oObject, int iExpiration =
0, string sTable = "pwobjdata")
{
string sPlayer;
string sTag;
if (GetIsPC(oOwner))
{
sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oOwner));
sTag = SQLEncodeSpecialChars(GetName(oOwner));
}
else
{
sPlayer = "~";
sTag = GetTag(oOwner);
}
sVarName = SQLEncodeSpecialChars(sVarName);
string sSQL = "SELECT player FROM " + sTable + " WHERE player='" + sPlayer +
"' AND tag='" + sTag + "' AND name='" + sVarName + "'";
SQLExecDirect(sSQL);
if (SQLFetch() == SQL_SUCCESS)
{
// row exists
sSQL = "UPDATE " + sTable + " SET val=%s,expire=" + IntToString(iExpiration) +
" WHERE player='" + sPlayer + "' AND tag='" + sTag + "' AND name='" + sVarName + "'";
SetLocalString(GetModule(), "NWNX!ODBC!SETSCORCOSQL", sSQL);
StoreCampaignObject ("NWNX", "-", oObject);
}
else
{
// row doesn't exist
sSQL = "INSERT INTO " + sTable + " (player,tag,name,val,expire) VALUES" +
"('" + sPlayer + "','" + sTag + "','" + sVarName + "',%s," + IntToString(iExpiration) + ")";
SetLocalString(GetModule(), "NWNX!ODBC!SETSCORCOSQL", sSQL);
StoreCampaignObject ("NWNX", "-", oObject);
}
}
object GetPersistentObject(object oObject, string sVarName, object oOwner = OBJECT_INVALID, string sTable = "pwobjdata")
{
string sPlayer;
string sTag;
object oModule;
if (GetIsPC(oObject))
{
sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oObject));
sTag = SQLEncodeSpecialChars(GetName(oObject));
}
else
{
sPlayer = "~";
sTag = GetTag(oObject);
}
sVarName = SQLEncodeSpecialChars(sVarName);
string sSQL = "SELECT val FROM " + sTable + " WHERE player='" + sPlayer +
"' AND tag='" + sTag + "' AND name='" + sVarName + "'";
SetLocalString(GetModule(), "NWNX!ODBC!SETSCORCOSQL", sSQL);
if (!GetIsObjectValid(oOwner))
oOwner = oObject;
return RetrieveCampaignObject ("NWNX", "-", GetLocation(oOwner), oOwner);
}
void DeletePersistentVariable(object oObject, string sVarName, string sTable = "pwdata")
{
string sPlayer;
@@ -642,52 +456,3 @@ string SQLDecodeSpecialChars(string sString)
return sReturn;
}
// Gets the current REAL WORLD time, uses NWNX2
// Year-Month-Day Time
// 1997-12-15 23:50:26
string GetSQLTime();
string GetSQLTime()
{
string sSQL = "SELECT CURRENT_TIME";
SQLExecDirect(sSQL);
if(SQLFetch() == SQL_SUCCESS)
{
return SQLGetData(1);
}
else
{
return "Database error";
}
}
// Gets the current REAL WORLD date, uses NWNX2
string GetSQLDate();
string GetSQLDate()
{
string sSQL = "SELECT CURRENT_DATE";
SQLExecDirect(sSQL);
if(SQLFetch() == SQL_SUCCESS)
{
return SQLGetData(1);
}
else
{
return "Database error";
}
}
// Gets the current REAL WORLD time stamp, uses NWNX2
string GetSQLTimeStamp();
string GetSQLTimeStamp()
{
string sSQL = "SELECT CURRENT_TIMESTAMP";
SQLExecDirect(sSQL);
if(SQLFetch() == SQL_SUCCESS)
{
return SQLGetData(1);
}
else
{
return "Database error";
}
}