Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-09-2008, 12:28 AM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Introducing Callstack Access

Introduction

This is possibly my most wanted feature in GScript for some time: callstack access.

Callstack access allows you to see which objects and functions are calling other objects or functions. This means you can add better script security by, say, checking which NPCs are trying to call your bank functions, for example. It also can be used for script debugging.

Does it work on all servers yet? Probably not. Try it, and if it doesn't work, you can request your NPC-Server to be updated with it.

How callstack access works

First, let's examine how to get the contents of the callstack.

The getCallStack() function returns an array of links. The array that getCallStack() returns is a chronological list of the function call chain.

The important thing to recognise about these links is that they are not direct links to the calling function or NPC themselves, but instead they are an object linking to the temp. scope of the calling functions. Yes, this means that you can access temp. variables of functions earlier in the call chain. (See section below)

There is also a sub-object named "scriptcallobject", which is a link to the object that is calling the function.

Finally, there is another variable called "name" which returns the name of the calling function.

Code Example

Now, just to make the example a bit more straight-forward, we'll demonstrate this with just two NPCs; TestNPC, and TestNPC2.

Here is the code in TestNPC:
PHP Code:
function onCreated()
{
  
this.testCallStack();
}

public function 
testCallStack()
{
  
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);
  }

(You'll notice that the for (temp.foo: bar) iterator is not used here, or otherwise you might overwrite temp variables.)

And then TestNPC2:
PHP Code:
function onCreated()
{
  
TestNPC.testCallStack();

Updating the script of TestNPC will reveal this in RC:
Quote:
call stack entry 1: TestNPC.testCallStack
call stack entry 0: TestNPC.onCreated
Updating TestNPC2 instead reveals this:
Quote:
call stack entry 1: TestNPC.testCallStack
call stack entry 0: TestNPC.onCreated
This shows the order in which functions have been called in order to reach the current function.

Accessing temp variables

Instead of using scriptcallobject, you can access temp names directly, i.e.:
PHP Code:
function onCreated()
{
  
temp.foo "two";
  
  
this.testCallStack();
}

public function 
testCallStack()
{
  
temp.foo "one";
  
temp.callstack getCallStack();

  for (
temp.temp.callstack.size() - 1temp.>= 0temp.--)
  {
    echo(
"variable contents " temp.callstack[temp.i].foo);
  }

Upon updating the script, this will appear in RC:
Quote:
variable contents one
variable contents two
Reply With Quote
  #2  
Old 01-09-2008, 12:36 AM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
A wicked way to secure scripts from pesky staff . Although I wanted protected variables, this will definitely help <3 for Stefan!

Bank DBNPC
PHP Code:
public function deposit()
{
  
temp.stack getCallStack();
  
  if (
temp.stack[0].scriptcallobject.name != "Twinny/Test"//Could become an array of TEMPORARY allowed scripts
    
printf("Recieved illegal call from %s"temp.stack[0].scriptcallobject.name);
  else
    echo(
"Money deposited ^^");

Twinny/test and Twinny/Test2
PHP Code:
function onCreated() 
  
Bank.deposit(); 
Result!
PHP Code:
Weapon/GUI-script Twinny/Test2 added/updated by Twinny
Recieved illegal call from Twinny
/Test2
Weapon
/GUI-script Twinny/Test added/updated by Twinny
Money deposited 
^^ 

Last edited by Twinny; 01-09-2008 at 12:56 AM..
Reply With Quote
  #3  
Old 01-09-2008, 01:13 AM
Kyranki Kyranki is offline
Freelance Coder
Join Date: Aug 2007
Location: At the end of the rainbow, in the pot of gold.
Posts: 202
Kyranki is on a distinguished road
Send a message via AIM to Kyranki Send a message via MSN to Kyranki
Oh, totally cool dude. I think there've been a few people awaiting the ability to view the callstack and script accordingly to improve script efficiencies. Though, I'm still with Twinny on protected/password protected variables, etc. this is an excellent addition!
__________________
Stan.
Reply With Quote
  #4  
Old 01-09-2008, 01:42 AM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
I like this Great news. I'll start implementing into my MUDlib right away.
Reply With Quote
  #5  
Old 01-09-2008, 02:06 AM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
Nice
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #6  
Old 01-12-2008, 11:41 AM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
uhm, may i request that triggers are traced too?
__________________
Reply With Quote
  #7  
Old 01-12-2008, 08:26 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Here are two functions, one to get the object that calls the function that calls it, and one to get the calling function in the same way.
PHP Code:
function getcallingfunction() {
  
temp.callstack getcallstack();
  return 
temp.callstack[temp.callstack.size() - 3];
}
function 
getcallingobject() {
  
temp.callstack getcallstack();
  return 
temp.callstack[temp.callstack.size() - 3].scriptcallobject;

__________________
Reply With Quote
  #8  
Old 01-14-2008, 08:48 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Quote:
Originally Posted by projectigi View Post
uhm, may i request that triggers are traced too?
Triggers are meant to be insecure, for easy script interaction. Also npcs could trigger each other endlessly. It could eventually be possible to find out who has triggered it.
Reply With Quote
  #9  
Old 01-14-2008, 09:16 PM
projectigi projectigi is offline
Registered User
Join Date: Jan 2004
Posts: 403
projectigi is an unknown quantity at this point
well i just want to make sure that e.g. a onActionServerSide can only be called from the same weapon xD
__________________
Reply With Quote
  #10  
Old 01-14-2008, 09:43 PM
Dan Dan is offline
Daniel
Join Date: Oct 2007
Posts: 383
Dan is an unknown quantity at this point
Send a message via MSN to Dan
Very nice feature.
__________________
Reply With Quote
  #11  
Old 01-15-2008, 04:46 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Very nice, I love it.
Now I just want to be able to use it on Maloria
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #12  
Old 08-15-2008, 05:17 AM
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 missed this completely, very nice function!
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #13  
Old 08-15-2008, 05:40 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by xXziroXx View Post
I missed this completely, very nice function!
Me too, thanks for bringing it to light :O
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #14  
Old 08-15-2008, 02:40 PM
Programmer Programmer is offline
Coder
Programmer's Avatar
Join Date: Jan 2008
Location: -78.464422, 106.837328
Posts: 449
Programmer has a spectacular aura aboutProgrammer has a spectacular aura about
Send a message via AIM to Programmer Send a message via MSN to Programmer Send a message via Yahoo to Programmer
Quote:
Originally Posted by xXziroXx View Post
I missed this completely, very nice function!
Same, didn't even notice it o.O
__________________
- Iᴀɴ Zɪᴍᴍᴇʀᴍᴀɴ
Reply With Quote
  #15  
Old 08-15-2008, 03:54 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
Couldn't have provided that first class bump without Dusty.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 03:09 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.