Any idea for sending actions from php to server?
#1

Hello guys, i want to ask here if you know any method to send actions like "mute player" from the website and take action on the sa-mp server... Provide some documentation/code ex. if you have any reply, thank you in advice!
Reply
#2

So, I've quickly created and tested out a filterscript which would perform something of this manner.

Код:
#include <a_samp>
#include <a_http>

new cmdstate = 1;

forward OnServerCommand(playerid, response_code, data[]);
forward ProcessCommand(playerid, response_code, data[]);
forward CheckHTTP ();

public OnFilterScriptInit ()
{
	SetTimerEx("CheckHTTP", 1000, true, "i");
	return 1;
}

public CheckHTTP ()
{
	HTTP(0, HTTP_GET, "state.txt", "", "OnServerCommand");
}

public OnServerCommand(playerid, response_code, data[])
{
	new string[1028];

	if(response_code == 200)
	{
		format(string, sizeof(string), "%s", data);

		if (strval(string) == cmdstate)
		{
			if (strval(string) == 1)
			{
				cmdstate = 0;
			}
			
			else
			{
				cmdstate = 1;
			}
			
			HTTP(0, HTTP_GET, "command.txt", "", "ProcessCommand");
		}
	}
	
	else
	{
		//request failed
	}
	
	return 1;
}

public ProcessCommand(playerid, response_code, data[])
{
	new string[1028];
 
	if(response_code == 200)
	{
		format(string, sizeof(string), "%s", data);
			
		new cmd[256];
		format (cmd, sizeof(cmd), "ID %s has been muted!", string);
		SendClientMessageToAll (-1, cmd);
		//add mute command here//
	}
	
	else
	{
		//request failed
	}
	
	return 1;
}
So, the way it works is that through your PHP file; you will make amendments to two files called state.txt and command.txt, state.txt informs the SA:MP server that you are processing a new command whilst command.txt informs the SA:MP server of the ID you want to perform the command with.

Through your PHP script, you should check the value of state.txt then differ the value between 0 and 1, the opposite of the value which is currently assigned, but ensure that the command.txt has been replaced with the correct ID beforehand.

I've tested it out and it does work, although you could probably make it more advance by sorting out data within a single file instead of one and maybe prefixes to distinguish bans, mutes, kicks and etc.

Edit:

In terms of the PHP, you could also do something as simple as this:

PHP код:
<?php
$user 
$_GET["user"];
$file fopen ("command.txt""w");
fwrite ($file$user);
fclose ($file);
$status file_get_contents ("state.txt");
$sfile fopen ("state.txt""w");
if (
$status == 0)
{
    
fwrite ($sfile"1");
    
fclose ($sfile);
}
else
{
    
fwrite ($sfile"0");
    
fclose ($sfile);
}
echo (
"ID $user has been muted from the server.");
?>
Save that as a PHP file, for example mute.php

If you want to mute someone visit: http://yourwebsite.com/mute.php?user=3 - this will mute ID 3.
Reply
#3

I will try to use your code, it's awesome. It's nice to see someone is still helping other sa-mp scripters I'm using Laravel as user control panel framework. I did something right now with socket plugin and i think it's a better ideea xD I will see what would be better for my webhost/gamehost etc. rep++;
Reply
#4

One little tip:
Westies API already opens a socket. Use this connection for stuff. I do it too without any problems.
Reply
#5

Use socket plugin. Polling the remote server for changes may work but IMO that's a waste of resources.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)