Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #16  
Old 02-04-2011, 11:30 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by MattKan View Post
PHP Code:
function onActionServerSide(action) {
  switch (
action) {
    case 
"DecRup":
      
player.rupees -= params[1];
    break; 
This in itself ruins the script. Not only does this allow you to set your own price via Cheat Engine or the like, but you could even set the price to a negative value in order to spawn money.

Quote:
PHP Code:
function Bomb_Button1.onAction() {
  
//Button "Purchase"
 
if (player.rupees >= 9) {
   
triggerserver("gui",this.name,"DecRup",10);
   
player.bombs += 10;
  }else
    
player.chat "Insufficient Funds";

Always do checks like this on serverside. A player could change the amount of darts to gain, the number of rupees to pay, or even negate the trigger entirely. The proper way to do it would be to send a trigger with a parameter "item" (which is either "bomb" or "arrow"), and only add the bombs/arrows on serverside. This ensures that nothing can be tampered with. As a general rule, assume that any script you write on clientside can be changed by a hacker.

An example of how it should be done:
PHP Code:
function onActionServerSide(actionitem) { 
  if (
action == "purchase") {
    if (! (
item in {"bombs""darts"})) {
      return; 
// player sent a non-existing item
    
}
    
    if (
player.rupees 10) {
      return 
player.chat "You need at least 10 rupees!";
    }
    
    
player.rupees -= 10;
    
    if (
item == "bombs") {
      
player.bombs += 10;
    } else if (
item == "darts") {
      
player.darts += 20;
    }
  }


//#CLIENTSIDE 
// all of the GUI stuff here

function Bomb_Button1.onAction() { 
  
triggerServer("gui"this.name"purchase""darts");


function 
Bomb_Button2.onAction() { 
  
triggerServer("gui"this.name"purchase""bombs");

edit: Tig and Cubical beat me to it, but this should help as well
__________________
Reply With Quote
  #17  
Old 02-05-2011, 12:00 AM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
Quote:
Originally Posted by Tigairius View Post
I would check both clientside and serverside. That way if they aren't hacking, it won't send a needless trigger to the server.
I need to start doing that.
Reply With Quote
  #18  
Old 02-05-2011, 12:30 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by Tigairius View Post
I would check both clientside and serverside. That way if they aren't hacking, it won't send a needless trigger to the server.
Unfortunately this results in code duplication, which makes going back and editing things annoying (twice the work, and you better not forget one of the checks). I usually only add in the extra clientside check if it's something that's going to be triggering extremely frequently. Of course this is a matter of preference but this is what I've found to be a nice balance.

The code duplication issue is sadly a hard problem to solve, even outside of Graal, and I haven't really seen a solution I've liked anywhere to port it, so I guess we'll just have deal with it for now in the critical areas.
Reply With Quote
  #19  
Old 02-05-2011, 01:09 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 WhiteDragon View Post
Unfortunately this results in code duplication, which makes going back and editing things annoying (twice the work, and you better not forget one of the checks). I usually only add in the extra clientside check if it's something that's going to be triggering extremely frequently. Of course this is a matter of preference but this is what I've found to be a nice balance.

The code duplication issue is sadly a hard problem to solve, even outside of Graal, and I haven't really seen a solution I've liked anywhere to port it, so I guess we'll just have deal with it for now in the critical areas.
I usually use a this.attr[#] serverside to store the price which can be read clientside. Then if price is edited serverside, it applies clientside as well. Basically no code duplication involved?
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #20  
Old 02-05-2011, 01:14 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Tigairius View Post
I usually use a this.attr[#] serverside to store the price which can be read clientside. Then if price is edited serverside, it applies clientside as well. Basically no code duplication involved?
You'll still have duplication (two of the same if statements) even though it's still only one extra line and not really much of a problem since you have the value synced on both.
__________________
Quote:
Reply With Quote
  #21  
Old 02-05-2011, 01:21 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by Tigairius View Post
I usually use a this.attr[#] serverside to store the price which can be read clientside. Then if price is edited serverside, it applies clientside as well. Basically no code duplication involved?
This only works for values. If your logic is complex enough to require a function, you will have to duplicate it since there is no way to pass a function as data (like you can with a value) from the client<->server (and it'd certainly be impossible to find a way to serialize a function with GS2).
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 05:21 PM.


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