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
  #1  
Old 03-19-2012, 08:52 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Communication with a webserver

Just wondering if it's possible.
Eg on a site you could enter an account and if they are online on the server it would trigger a script to display a message to them?
I'm wondering how because I am trying to code something that would allow me to go on a URL and communicate with players on a server.
I already know how to send data to a webserver, but not how to send data to the gserver.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #2  
Old 03-19-2012, 12:48 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
You can use TSocket to listen on a port and then talk to that port from your webserver. If you're using PHP or some language that doesn't make it real easy to work with raw sockets, you might want to consider using Grattpd to wrap your communication in HTML (just like any regular API).

Normally you have to request access to bind to a specific port from Stefan, but you can also bind to port 0, which will randomly choose a port to bind to. Once you do this, call a script on your webserver with the port and have the webserver save the IP and port so that it can contact the gserver when necessary. Look at Grattpd for how I did this.
__________________
Reply With Quote
  #3  
Old 03-20-2012, 10:44 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Thanks for the informative post, I will post in the code gallery when it is complete
I will still be using PHP to handle a few things on the webservers side.

Edit: Already ran into a problem...
Quote:
Originally Posted by GServer
Script connection to wr3ckless.net:0 is not allowed, blocking.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion

Last edited by Gunderak; 03-20-2012 at 11:21 AM..
Reply With Quote
  #4  
Old 03-20-2012, 12:54 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 Gunderak View Post
Thanks for the informative post, I will post in the code gallery when it is complete
I will still be using PHP to handle a few things on the webservers side.

Edit: Already ran into a problem...
You need to bind to a port, not connect to a server. See Grattpd or my FTP server for examples.

Here's the listen socket code I'm using:

PHP Code:
function onCreated() {
  
this.bind(0false);
}

function 
onBind() {
  
// this line can be used if you have a PHP script setup for
  // automatically redirecting requests to the current port;
  // see the example script in the forum post
  // requestURL("http://graalcenter.org/update.php?pass=replace_me&port=" @ this.port);
  
  // this is probably only useful if you're not using a PHP
  // script for redirection; could be a bit of a pain since
  // it's always changing.
  
echo("HTTP: Bound to " this.optionDB.ip ":" this.port ", waiting for connections...");
}

function 
onNewClient(clientSocket) {
  
clientSocket.optionDB this.optionDB;
  
clientSocket.join("http_clientsocket");

and the socket's creation:

PHP Code:
function onCreated() {
  
// get server IP
  
temp.req requestURL("http://www.whatismyip.com/automation/n09230945.asp");
  
  
waitfor(req"onReceiveData"30);
  
this.ip req.data[0];
  
  
// destroy if existing
  
if (isObject("HTTPListenSocket")) {
    
HTTPListenSocket.destroy();
  }
  
  
// create the socket
  
this.listenSocket = new TSocket("HTTPListenSocket");
  
this.listenSocket.optionDB this;
  
this.listenSocket.join("http_listensocket");

__________________
Reply With Quote
  #5  
Old 03-20-2012, 02:14 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Ahh I was doing it wrong....
Thanks for the kick in the right direction.
Ans thanks for the examples, it will definitely help a lot.

Whoever neg repped me for "ran into you", lolwhat what ran into me? XD
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
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 12:54 PM.


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