SA-MP Forums

Go Back   SA-MP Forums > Other > Everything and Nothing

Reply
 
Thread Tools Display Modes
Old 02/04/2015, 02:38 PM   #1
Banditukas
Gangsta
 
Join Date: Jul 2014
Posts: 535
Reputation: 1
Default javascript.

Hi,
Code:
$.post("http://mywebsite/server_status.php", {code: "0ay3j5as1Zua55f9T9s2upo"}, function( data ) {
		var value = parseINIString(data);

		if(value["status"])
			document.getElementById("serverStatus").innerHTML = '<span class="label label-success">Server is ON</span>';
		else
			document.getElementById("serverStatus").innerHTML = '<span class="label label-danger">Server is OFF</span>';
		
		if(value["players"] != "")
		{
			output = 'Players: ' + value["players"] + '/' + value["maxplayers"] + '<br>';
			output += 'Version: ' + value["gamemode"] + '<br>';
			document.getElementById("serverInfo").innerHTML	= output;
			
			document.getElementById("serverUpdate").innerHTML = value["lastupdate"];
		}	
		else
		{
			menuHomeTime = 0;	
		}
Please explain structure of this code first thing is:

code: "0ay3j5as1Zua55f9T9s2upo" what is code and for what he is using.

What need to write into .php file to get "status", "players" and another server information.
Banditukas is offline   Reply With Quote
Old 02/04/2015, 03:13 PM   #2
BleverCastard
Gangsta
 
Join Date: Dec 2011
Posts: 881
Reputation: 43
Default Re: javascript.

Quote:
Originally Posted by Banditukas View Post
Hi,
Code:
$.post("http://mywebsite/server_status.php", {code: "0ay3j5as1Zua55f9T9s2upo"}, function( data ) {
		var value = parseINIString(data);

		if(value["status"])
			document.getElementById("serverStatus").innerHTML = '<span class="label label-success">Server is ON</span>';
		else
			document.getElementById("serverStatus").innerHTML = '<span class="label label-danger">Server is OFF</span>';
		
		if(value["players"] != "")
		{
			output = 'Players: ' + value["players"] + '/' + value["maxplayers"] + '<br>';
			output += 'Version: ' + value["gamemode"] + '<br>';
			document.getElementById("serverInfo").innerHTML	= output;
			
			document.getElementById("serverUpdate").innerHTML = value["lastupdate"];
		}	
		else
		{
			menuHomeTime = 0;	
		}
Please explain structure of this code first thing is:

code: "0ay3j5as1Zua55f9T9s2upo" what is code and for what he is using.

What need to write into .php file to get "status", "players" and another server information.
That code can be anything. It could be authorization code, security code, anything. Something tells me this is not your code anyway.

And as for the other issue, you can find includes around the forum for that type of stuff. Search! You can't just think "Hey, I'll type this bit of code and get a bounceback".
__________________
Quote:
Originally Posted by Mauzen View Post
You earned 8000 euros by luring credulous people into your gingerbread house of paid-click reflinks?
BleverCastard is offline   Reply With Quote
Old 02/04/2015, 03:29 PM   #3
Banditukas
Gangsta
 
Join Date: Jul 2014
Posts: 535
Reputation: 1
Default Re: javascript.

I was searching but no similar found that's why i'am creating thread. Maybe most important question is how to send server information, or other things in php files.
Banditukas is offline   Reply With Quote
Old 02/04/2015, 03:33 PM   #4
BleverCastard
Gangsta
 
Join Date: Dec 2011
Posts: 881
Reputation: 43
Default Re: javascript.

Quote:
Originally Posted by Banditukas View Post
Maybe most important question is how to send server information, or other things in php files.
Like I said, search.

Also,
Quote:
Originally Posted by Banditukas View Post
i'am
defeats the whole purpose of using '. I'm is an abbreviation of "I am".
__________________
Quote:
Originally Posted by Mauzen View Post
You earned 8000 euros by luring credulous people into your gingerbread house of paid-click reflinks?
BleverCastard is offline   Reply With Quote
Old 02/04/2015, 03:37 PM   #5
Banditukas
Gangsta
 
Join Date: Jul 2014
Posts: 535
Reputation: 1
Default Re: javascript.

I was searching but don't found is it hard to help find and give link or examples..
Banditukas is offline   Reply With Quote
Old 02/04/2015, 07:12 PM   #6
Banditukas
Gangsta
 
Join Date: Jul 2014
Posts: 535
Reputation: 1
Default Re: javascript.

Code:
<?php>

$serverIP = 'localhost';
$serverPort = 7777;
require 'samp_query.php';
try
{
    $data = new QueryServer( $serverIP, $serverPort );

    How now to send information?
    $rQuery->Close( );
}
catch (QueryServerException $pError)
{

}
?>
Banditukas is offline   Reply With Quote
Old 03/04/2015, 04:56 AM   #7
BroZeus
High-roller
 
BroZeus's Avatar
 
Join Date: Jan 2014
Location: India
Posts: 1,413
Reputation: 173
Default Re: javascript.

Quote:
Originally Posted by Banditukas View Post
Code:
<?php>

$serverIP = 'localhost';
$serverPort = 7777;
require 'samp_query.php';
try
{
    $data = new QueryServer( $serverIP, $serverPort );

    How now to send information?
    $rQuery->Close( );
}
catch (QueryServerException $pError)
{

}
?>
You can't send info with simple samp query, you need rcon query api which can be found here http://forum.sa-mp.com/showthread.php?t=104299

After you have got it, you need something like this to send info :
PHP Code:
<?php
require("SampRconAPI.php");
$rcon = new SampRconAPI('127.0.0.1'7777'rcon_password_here');
if(!
$rcon->isOnline())
{
     
//if connection failed
     
echo "Connection failed";
     exit();
}

//now lets create a custom function named "rrcon"
$rcon->Call('rrcon Hello from PHP file');//this will send info to server
echo "Info send to server";
?>
The info 'rrcon Hello from PHP file' is received on server in callback named OnRconCommand
Now we need to check for our custom function named 'rrcon' in OnRconCommand.
So ingame script will he like this
PHP Code:
//pawn
public OnRconCommand(cmd[])
{
    
//now first we need to seperate command name from rest of the text so we will use strtok
    
new cmd2[128], idx;
    
cmd2 strtok(cmdidx);
    if(!
strcmp(cmd2"rrcon"true))//if it matches custom function 'rrcon' then
    
{
        
//now we seperate rrcon with rest of text and send it to all players online
        
new tmp[128];
        
tmp strtok(cmdidx);     
        
SendClientMessageToAll(0xFFFFFFAAtmp);//this will show message 'Hello from PHP file' to all players
        
return 1;
    }
    return 
0;

But this is not the preferred method to send info to server, the best method that I am aware of is using sockets plugin with php sockets function.
__________________


"Be the change that you wish to see in the world."

Check out my Github profile!
BroZeus is offline   Reply With Quote
Old 03/04/2015, 05:01 AM   #8
Emmet_
Guest
 
Posts: n/a
Default Re: javascript.

^ Better to use sscanf for that, strtok is an outdated piece of shit. It was made about 11 years ago.

To OP: looks like an API code to me.
  Reply With Quote
Old 03/04/2015, 05:29 AM   #9
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,993
Reputation: 2649
Default Re: javascript.

For your information: that piece of Javascript uses jQuery and it is what's known as an AJAX request. The script sends a POST request to the PHP page when the user does something (e.g. clicking an "update" button) or on a timer (so the status refreshes every minute or so).
__________________
Vince is offline   Reply With Quote
Old 03/04/2015, 09:36 AM   #10
Banditukas
Gangsta
 
Join Date: Jul 2014
Posts: 535
Reputation: 1
Default Re: javascript.

I don't need to send info to server. I need to parse it to data and get parameters to show how much is players, is server on, off, what is gamemode and etc.
Banditukas is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use PHP in javascript Banditukas Everything and Nothing 5 08/11/2014 05:44 AM
unity3D, javascript Baboon Everything and Nothing 5 17/02/2014 05:19 PM
PHP, Javascript cnoopers Everything and Nothing 5 27/12/2013 09:03 PM
[Off] Iniciando em Javascript ipsBruno Português/Portuguese 43 31/03/2013 06:03 AM


All times are GMT. The time now is 06:42 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.