#include "inc_mysql_tables" #include "nwnx_funcs_l" #include "colors_inc" // Max number of keys able to be stored const int AUTHORIZATION_MAX_NUMBER_OF_KEYS = 7; // Status ID number for adding a new key const int AUTHORIZATION_STATUS_ADDING_NEW_KEY = 1; void main() { object oPC = GetEnteringObject(); // Only fires for PCs if(!GetIsPC(oPC) || GetIsDM(oPC)) return; string sAccount = SQLEncodeSpecialChars(GetPCPlayerName(oPC)); string sCDKey = SQLEncodeSpecialChars(GetPCPublicCDKey(oPC, TRUE)); string sSQL = "SELECT Status, CDKey1, CDKey2, CDKey3, CDKey4, CDKey5, CDKey6, CDKey7, NumberOfKeys FROM " + AUTHORIZATION_TABLE +" WHERE Account='" + sAccount + "'"; SQLExecDirect(sSQL); if(SQLFetch() == SQL_SUCCESS) { int bStatus = StringToInt(SQLGetData(1)); string sKey1 = SQLGetData(2); string sKey2 = SQLGetData(3); string sKey3 = SQLGetData(4); string sKey4 = SQLGetData(5); string sKey5 = SQLGetData(6); string sKey6 = SQLGetData(7); string sKey7 = SQLGetData(8); int iNumberOfKeys = StringToInt(SQLGetData(9)); // Check if player is adding a new CD key if(bStatus == AUTHORIZATION_STATUS_ADDING_NEW_KEY) { // Reached the maximum number of keys - boot PC with an error message if(iNumberOfKeys >= AUTHORIZATION_MAX_NUMBER_OF_KEYS) { BootPCWithMessage(oPC, 16782505); sSQL = "UPDATE " + AUTHORIZATION_TABLE + " Set Status=0 WHERE Account='" + sAccount + "'"; SQLExecDirect(sSQL); return; } // CD key is already in the list of accepted keys else if(sCDKey == sKey1 || sCDKey == sKey2 || sCDKey == sKey3 || sCDKey == sKey4 || sCDKey == sKey5 || sCDKey == sKey6 || sCDKey == sKey7) { DelayCommand(8.0, FloatingTextStringOnCreature(ColorTokenRed() + "The CD key '" + sCDKey + "' is already tied to this account." + ColorTokenEnd(), oPC, FALSE)); sSQL = "UPDATE " + AUTHORIZATION_TABLE + " Set Status=0 WHERE Account='" + sAccount + "'"; SQLExecDirect(sSQL); return; } // Otherwise we just add the new key to the list. else { DelayCommand(8.0, FloatingTextStringOnCreature(ColorTokenGreen() + "The CD key '" + sCDKey + "' is now tied to this account." + ColorTokenEnd(), oPC, FALSE)); iNumberOfKeys++; sSQL = "UPDATE " + AUTHORIZATION_TABLE + " Set CDKey" + IntToString(iNumberOfKeys) + "='" + sCDKey + "', NumberOfKeys=" + IntToString(iNumberOfKeys) + " WHERE Account='" + sAccount + "'"; SQLExecDirect(sSQL); return; } } // Login is valid else if(sCDKey == sKey1 || sCDKey == sKey2 || sCDKey == sKey3 || sCDKey == sKey4 || sCDKey == sKey5 || sCDKey == sKey6 || sCDKey == sKey7) { return; } // Login isn't valid - boot them immediately else { if(GetIsObjectValid(oPC)) { BootPCWithMessage(oPC, 16782506); } return; } } // If we reach this point then the PC isn't in the list of valid keys // We need to add their key to the list. else { sSQL = "INSERT INTO " + AUTHORIZATION_TABLE + " (Account, CDKey1, NumberOfKeys) VALUES ('" + sAccount + "','" + sCDKey + "',1)"; SQLExecDirect(sSQL); } }