Transfering data between servers
Posted: Mon Jun 21, 2004 12:22 am
I made a system to transfer data between servers using PC hides. If we adopted it, it would be useful in sharing data across servers, such as crafting skill data and scripted quest data.
1) All PC's get a hide if they don't already have one.
2) When portalling, portal code writes important variables to the hide (using functions I wrote below).
3) Upon arrival, the script on that server (onenter, or onarea enter) takes the variables off the hide, writes them to where they need to go, and deletes them off the hide.
I made some functions below to do this. Let me know if you see anything blaringly wrong with them. They do compile.
1) All PC's get a hide if they don't already have one.
2) When portalling, portal code writes important variables to the hide (using functions I wrote below).
3) Upon arrival, the script on that server (onenter, or onarea enter) takes the variables off the hide, writes them to where they need to go, and deletes them off the hide.
I made some functions below to do this. Let me know if you see anything blaringly wrong with them. They do compile.
Code: Select all
//data_trans_inc.nss
//By Josh Simon
//June 21st, 2004
//File governs data transfer between CoPaP servers by taking data
//from PC hide and loading to or from module
#include "ars_include"
// int constants
const int NULL = 0;
// Gets a local integer from a PC's hide. Returns NULL if PC has no hide.
int GetLocalHideInt(object oPC, string sVarName);
//Sets a local integer with sVarName on the PC's hide. If PC has no hide,
//it creates one and then calls itself again.
void SetLocalHideInt(object oPC, string sVarName, int iValue);
//Deletes the local integer with name sVarName on the PC's hide
void DeleteLocalHideInt(object oPC, string sVarName);
//Takes an int variable from the PC's hide, and writes it into pwdata table
//of the database. Deletes the variable off the hide when done.
void TransferHideIntToDB(object oPC, string sVarName);
//Takes all of the player's crafting skills (names and xp values) from the
//database and writes them onto the hide with local variable name being
//the skill, and the value being the amount of xp in that skill
void TransferCraftingSkillsToHide(object oPC);
//Takes ONE crafting skill variable off the hide and writes it into the
//crafting skill table in the database. Deletes the variable off the hide
//when finished.
void TransferCraftingSkillToDB(object oPC, string sSkill);
//////////////////////////////////////////////////
//GetLocalHideInt(object oPC, string sVarName)
//////////////////////////////////////////////////
int GetLocalHideInt(object oPC, string sVarName)
{
object oHide = GetItemInSlot(INVENTORY_SLOT_CARMOUR, oPC);
int iNumber;
if (GetIsObjectValid(oHide)){
iNumber = GetLocalInt(oHide, sVarName);
return iNumber;
}
else
WriteTimestampedLogEntry("HIDE VARIABLE ERROR: "+GetName(oPC)+" does not have a hide.");
return NULL;
}
//////////////////////////////////////////////////
//void SetLocalHideInt(object oPC, string sVarName, int iValue)
//////////////////////////////////////////////////
void SetLocalHideInt(object oPC, string sVarName, int iValue)
{
object oHide = GetItemInSlot(INVENTORY_SLOT_CARMOUR, oPC);
if (GetIsObjectValid(oHide))
SetLocalInt(oHide, sVarName, iValue);
else{
oHide = CreateItemOnObject("no_pc_hide", oPC);
DelayCommand(0.1,AssignCommand(oPC,ActionEquipItem(oHide,INVENTORY_SLOT_CARMOUR)));
SetLocalHideInt(oPC, sVarName, iValue);
WriteTimestampedLogEntry("HIDE VARIABLE ERROR: "+GetName(oPC)+" does not have a hide.");
}
}
//////////////////////////////////////////////////
//void DeleteLocalHideInt(object oPC, string sVarName)
//////////////////////////////////////////////////
void DeleteLocalHideInt(object oPC, string sVarName)
{
object oHide = GetItemInSlot(INVENTORY_SLOT_CARMOUR, oPC);
if (GetIsObjectValid(oHide))
DeleteLocalInt(oHide, sVarName);
else
WriteTimestampedLogEntry("HIDE VARIABLE ERROR: "+GetName(oPC)+" does not have a hide.");
}
//////////////////////////////////////////////////
//void TransferHideIntToDB(object oPC, string sVarName)
//////////////////////////////////////////////////
void TransferHideIntToDB(object oPC, string sVarName)
{
int iHideInt = GetLocalHideInt(oPC, sVarName);
SetPersistentInt(oPC, sVarName, iHideInt);
DeleteLocalHideInt(oPC, sVarName);
}
//////////////////////////////////////////////////
//void TransferCraftingSkillsToHide(object oPC)
//////////////////////////////////////////////////
void TransferCraftingSkillsToHide(object oPC)
{
int iSkillCount = ARS_GetSkillCount();
int i;
int iXP;
string sKey;
ARS_FetchPlayerSkills(oPC);
for (i=0; i<iSkillCount ; i++)
{
sKey = ARS_GetSkillName(i);
iXP = ARS_GetPlayerXP(oPC, sKey);
SetLocalHideInt(oPC, sKey, iXP);
}
}
//////////////////////////////////////////////////
//void TransferCraftingSkillToDB(object oPC, string sSkill)
//////////////////////////////////////////////////
void TransferCraftingSkillToDB(object oPC, string sSkill)
{
int iXP = GetLocalHideInt(oPC, sSkill);
string sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oPC));
string sCharName = SQLEncodeSpecialChars(GetName(oPC));
if (iXP > ARS_GetPlayerXP(oPC, sSkill)){
SQLExecDirect("SELECT skill FROM tradeskills WHERE player='" + sPlayer +
"' AND charname='" + sCharName + "' AND skill='" + sSkill + "'");
if (SQLFetch() == SQL_SUCCESS)
{
SQLExecDirect("UPDATE tradeskills SET xp=" + IntToString(iXP) +
" WHERE player='" + sPlayer + "' AND charname='" +
sCharName + "' AND skill='" + sSkill + "'");
}
else
{
SQLExecDirect("INSERT INTO tradeskills (player,charname,skill,xp,expire) " +
"VALUES ('" + sPlayer + "','" + sCharName + "','" +
sSkill + "'," + IntToString(iXP) + ",365)");
}
}
else
WriteTimestampedLogEntry("ERROR: Skill in database is greater than skill on hide.");
DeleteLocalHideInt(oPC, sSkill);
}