Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Exporting Variable (https://forums.graalonline.com/forums/showthread.php?t=134259000)

sssssssssss 05-02-2010 07:56 PM

Exporting Variable
 
Ok, I dont know if this is the right section technically. I was wondering if it is possible to pull the value and name of a gs2 variable and display the name and value on a website? Website is in php, but if I have to use a different language I can.

Pelikano 05-02-2010 10:28 PM

Getting the variable name, without having it saved as a string will not work. (Unless GS2 saves it as a string somewhere already, of course)

fowlplay4 05-02-2010 10:44 PM

You can use requesturl and send that value to your php server using get requests.

I.e:

PHP Code:

function onCreated() {
  
temp.url "http://www.example.com/update.php?var=whatever&value=somevalue";
  
requesturl(temp.url);


Then in your PHP page access the GET values and use some functionality and save it to a text file or in a database.

cbk1994 05-02-2010 11:45 PM

If you have a lot of data to send, you can also use this to send it as POST data.

sssssssssss 05-03-2010 12:06 AM

So i just make that ="somevalue" the value of the var correct?

And I would probably grab maybe 3-4 things seperately, so this should work I think.

cbk1994 05-03-2010 12:42 AM

Quote:

Originally Posted by sssssssssss (Post 1573657)
So i just make that ="somevalue" the value of the var correct?

And I would probably grab maybe 3-4 things seperately, so this should work I think.

(sorry if I misunderstood your request and I come off as condescending)

If, for example, you wanted a live feed of the number of players on your server, you could create a DB NPC like this:

PHP Code:

function onCreated() {
  
this.onTimeOut();
}

function 
onInitialized() {
  
this.onTimeOut(); // restart the timeout in case NPC-server restarts
}

function 
onTimeOut() {
  
requestURL("http://example.com/update_players.php?players=" allplayers.size() @ "&pass=as!4dKSxm231");
  
this.setTimer(30); // update every 30 seconds


...then in the PHP script...

PHP Code:

// update_players.php

$password 'as!4dKSxm231'// password used to make sure the request came from the server
$ip '127.0.0.1'// IP of the server (find this on http://statistics.graal.us), for extra security

// is it from the server?
if ($ip != $_SERVER['REMOTE_ADDR'] || $password != $_GET['pass']) {
  die(
"request from unauthorized server"); // either the IP or password was wrong
}

$playerCount $_GET['players'];
// now you can store this in a file, MySQL, whatever 


sssssssssss 05-03-2010 12:48 AM

your comments ran off the snippet (sry if spelt wrong, not in the right mind if that makes sense to u over 21 people).

Stephen 05-03-2010 12:53 AM

Quote:

Originally Posted by sssssssssss (Post 1573678)
your comments ran off the snippet (sry if spelt wrong, not in the right mind if that makes sense to u over 21 people).

You may be a little confused - it should be possible to scroll the script "snippet" box from side to side. >_<

sssssssssss 05-03-2010 02:14 AM

Its that 23 year old "alcohol" problem, my bad, seriously. I would delete my post but then urs wouldnt make 0 sense.

sssssssssss 05-05-2010 06:28 AM

I actually just realized tonight that I dont need to send the variable to a webpage when someone goes to the webpage technically.

Is there a way I can get the webpage to retrieve a variable on a graal server when the webpage opens, no matter how it actually opens. Like, if i search my page in google, then go to it, i would like the information on the webpage to be up to date with the variable on the server still.

napo_p2p 05-05-2010 06:37 AM

Quote:

Originally Posted by sssssssssss (Post 1574253)
I actually just realized tonight that I dont need to send the variable to a webpage when someone goes to the webpage technically.

Is there a way I can get the webpage to retrieve a variable on a graal server when the webpage opens, no matter how it actually opens. Like, if i search my page in google, then go to it, i would like the information on the webpage to be up to date with the variable on the server still.

You can still do what Chris suggested to keep things current:
  • Have the graal server periodically pass a variable to your webserver
  • Store the variable
  • Display the stored variable on a separate webpage

sssssssssss 05-05-2010 06:44 AM

I have no idea how to get graal to just periodically pass something to my website that way without hitting "open url" in graal first, that way it can send the variable to the site unless requesturl works without doing that, then i just didnt know exactly how requesturl works.

sssssssssss 05-06-2010 06:31 AM

Since it's kind of on topic, is there a way to send a variable from a site to a server?

Admins 05-06-2010 01:24 PM

We don't allow binding of sockets for TSocket except in very special cases. So it's technically possible (we run some graal webservers) but is not enabled because of security reasons. It's however possible to open a permanent TSocket to your webserver or whatever, you will have to request to get it enabled for your server (including destination address and port number).


All times are GMT +2. The time now is 02:59 PM.

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