View Single Post
  #25  
Old 03-11-2012, 09:10 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
I am still very opposed to storing actual item data on clients, one way or the other. Fills up attributes with useless garbage that only have to be sent to clients once per session and stored in a weapon NPC.

I don't know if reading this script will help you at all, since it's not commented, but this is exactly how temporary data like descriptions etc. is handled on Maloria.

PHP Code:
function onCreated()
{
  
join("functions_sql");
  
requestSQL("PRAGMA synchronous=OFF"true);
}

function 
onActionServerSide(action)
{
  if (
action == "query") {
    
temp.cache params[1];
    
temp.identifier params[2];
    
temp.querier params[3];
    
    
queryToClient(temp.cachetemp.identifiertemp.querier);
  }
}

public function 
queryToClient(temp.cachetemp.identifiertemp.querier) {
  
temp.object query(temp.cachetemp.identifier);
  
temp.object temp.object.saveVarsToArray(false);
  
  
triggerClient("gui"name"queryReturn"temp.cachetemp.identifiertemp.objecttemp.querier);
}

public function 
query(categoryidentifier)
{
  if (
category in "items""skills""spells""buffs""quests""baddies""nations""enchants" }) {
    
temp.tableName category;
    
    
temp.queryString "SELECT * FROM" SPC temp.tableName SPC "WHERE identifier='" identifier "'";
    
temp.query getSQL(temp.queryString);
    if (
temp.query.rows[0].size() == 0) {
      return;
      echo(
"Query for '" identifier "' failed (" category SPC "@" SPC player.account "), testing callstack:");
      
temp.callstack getCallStack();
    
      for (
temp.temp.callstack.size() - 1temp.>= 0temp.--)
        echo(
"call stack entry " temp.": " temp.callstack[temp.i].scriptcallobject.name "." temp.callstack[temp.i].name);
      
//echo("[" @ name @ "]: Query on '" @ identifier @ "' failed (" @ category SPC "@" SPC player.account @ ")");
      
return false;
    }
    
    
temp.object.copyFrom(temp.query.rows[0]);
    if (
category == "nations") {
      
temp.object.ranks.loadVarsFromArray(temp.object.ranks);
      
temp.object.ranks "";
    }
    return 
temp.object;
  }
  
  else {
    if (
category == null)
      echo(
name ".getObject - parameter category is null");
    else
      echo(
name ".getObject - " category " is not a valid category.");
  }
}

public function 
getTimestamp(tableidentifier)
{
  
temp.query getSQL("SELECT * FROM" SPC table SPC "WHERE identifier='" identifier "'");
  
  if (
temp.query.rows.size() == 0)
    return 
false//return echo("[" @ name @ "]: Query on '" @ identifier @ "' failed");
  
else
    return 
temp.query.timestamp;
}

//#CLIENTSIDE
function onCreated()
{
  
this.queryList = new TStaticVar();
  const 
QUERYTIMELIMIT 5;
  
  
setTimer(0.05);
}

function 
onActionClientside(action)
{
  if (
action == "queryReturn") {
    
temp.cache params[1];
    
temp.identifier params[2];
    
temp.serializedObject params[3];
    
temp.querier params[4];
    
    
temp.object = new TStaticVar();
    
temp.object.loadVarsFromArray(temp.serializedObject);
    
updateCacheEntry(temp.cachetemp.identifiertemp.objecttemp.querier);
    
    
updatePlayerVariables();
    
    
this.(@"query_" querier "_list").remove(temp.identifier);
    
temp.querier this.(@"query_" temp.querier);
    
    
//echo("Debug Query: (" @ temp.identifier @ ") (" @ temp.querier @ ")");
    
if (isObject(temp.querier)) {
      
//echo("yes");
      
temp.querier.onReceivedCacheObject(temp.identifiertemp.cache);
    }
  }
}

public function 
query(cacheidentifierquerier)
{
  if (
cacheEntryExist(cacheidentifier))
    return 
getCacheEntry(cacheidentifier);
  
  
//echo("Query(" @ cache @ "," SPC identifier @ ")...");
  
if (identifier in this.(@"query_" querier "_list"))
    return;
  
  
this.(@"query_" querier) = querier;
  
this.(@"query_" querier "_list").add(identifier);
  
  
triggerServer("gui"name"query"cacheidentifierquerier);
}

public function 
updatePlayerVariables()
{
  
this.playerItemNames player.getItemNames();
  
this.playerItemIdentifiers player.getItemIdentifiers();
}

public function 
getCacheSize(cache)
  return 
cacheExist(cache) ? this.(@"cache_" cache).getDynamicVarNames().size() : -1;

public function 
getCache(cache)
  return 
cacheExist(cache) ? this.(@"cache_" cache).getDynamicVarNames() : -1;

public function 
cacheExist(cache)
  return (
this.(@"cache_" cache).getDynamicVarNames().size() > 0);
  
  
//return this.(@"cache_" @ cache).getDynamicVarNames().size() > 0 ? true : false;

public function getCacheEntrySize(cacheidentifier)
  return 
cacheEntryExist(cacheidentifier) ? this.(@"cache_" cache).(@identifier).getDynamicVarNames().size() : -1;

public function 
getCacheEntry(cacheidentifier)
  return 
cacheEntryExist(cacheidentifier) ? this.(@"cache_" cache).(@identifier) : -1;

public function 
cacheEntryExist(cacheidentifier)
  return (
this.(@"cache_" cache).(@identifier).objecttype() == "TStaticVar");

  
//return this.(@"cache_" @ cache).(@identifier).objecttype() == "TStaticVar" ? true : false;

function updateCacheEntry(cacheidentifierdata)
{
  
this.(@"cache_" cache).(@identifier) = new TStaticVar();
  
this.(@"cache_" cache).(@identifier).copyFrom(data);
  
this.trigger("onCacheUpdated_" cache "_" identifier"");

__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote