PHP && Pawn
#1

Hey,

So i have just began to learn PHP, And just like most things am doing really well, but i have a question, is there anyway that i can include my logs/players onto a PHP Script? If so how is this done? sorry if it is in wrong places.

Thanks in advance
Reply
#2

Save it into a MySQL database and you can use it with PHP.
Reply
#3

could you help me over skype or something?
Reply
#4

As an example would this work?

pawn Код:
public PhpUpdate()
{
    HTTP(-1,HTTP_GET,"myforums.com/players.php","striptfiles/users/%s.ini","MyHttpCallback");
    return 1;
}

public MyHttpCallback(index, response_code, data[])
{
    // In this callback "index" would normally be called "playerid" ( if you didn't get it already :) )
    new
        buffer[ 128 ];
    if(response_code == 200) //Did the request succeed?
    {
        //Yes!
        format(buffer, sizeof(buffer), "The URL replied: %s", data);
        SendClientMessage(index, 0xFFFFFFFF, buffer);
    }
    else
    {
        //No!
        format(buffer, sizeof(buffer), "The request failed! The response code was: %d", response_code);
        SendClientMessage(index, 0xFFFFFFFF, buffer);
    }
}
Reply
#5

Quote:
Originally Posted by ******
Посмотреть сообщение
I've been trying to figure this same thing out myself. While MySQL, SQLite and files are options, they're generally very bad options as you're using permenant storage systems for temporary data transfer - they're really not designed or optimised for that (plus MySQL doesn't come with the server). On the other hand some database systems (not sure which) do have a fast purely in-memory database structure that is volatile and may be useful.

You can use HTTP to send and receive data, but only PAWN can initiate that.
Would it not be possible to use the Sockets plugin? The SA:MP server could connect to the web server or vice versa and send data to the php script.

References:
https://sampforum.blast.hk/showthread.php?tid=171598
http://php.net/manual/en/book.sockets.php
Reply
#6

You want to send your logs from the samp server to the web server?
Reply
#7

no i need to send logs/files from SA:MP to PHP files.
Reply
#8

PHP код:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Player List</title>
</head>
<body>
<?php
    $filename 
'players.txt';
    
$allowed_ip "127.0.0.1";
    
$allowed_user_agent "SAMP/0.3";
    if(isset(
$_GET['d'])) {
        if(
$_SERVER['REMOTE_ADDR'] == $allowed_ip && $_SERVER['HTTP_USER_AGENT'] == $allowed_user_agent) {
            
$fp fopen($filename'w');
            
fwrite($fp$_GET['d']);
            
fclose($fp);
        }
        else {
            die(
"ACCESS DENIED.");
        }
    }
    else
    {
        if(
file_exists($filename)) {
            
$handle fopen($filename"r");
            
$contents fread($handlefilesize($filename));
            
fclose($handle);
            
$players explode("*"$contents);
            foreach(
$players as $p) {
                
$inner_data explode(":"$p);
                
$name $inner_data[0];
                
$score $inner_data[1];
                
$playerid $inner_data[2];
                echo(
"[ID: ".$playerid."] ".$name." - Score: ".$score."<br />\n");
            }
        }
    }
?>
</body>
</html>
pawn Код:
public SendPlayerData() {
    new str[3800 + 13], count;
    format(str, sizeof(str), "localhost/?d=");
    for(new iLP = 0; iLP < MAX_PLAYERS; iLP++) {
        if(IsPlayerConnected(iLP)) {
            new name[MAX_PLAYER_NAME];
            GetPlayerName(iLP, name, MAX_PLAYER_NAME);
            if(!count) {
                format(str, sizeof(str), "%s%s:%d:%d", str, name, GetPlayerScore(iLP), iLP);
            } else {
                format(str, sizeof(str), "%s%s:%d:%d*", str, name, GetPlayerScore(iLP), iLP);
            }
            count++;
        }
    }
    HTTP(0, HTTP_HEAD, str, "", "");
    return true;
}
Quote:
Originally Posted by players.txt
Norn:0:0*Scooby_Doo:1337:1
You can just run that on a timer every 10 minutes, although you'll more than likely need to detect how many names you've added to the string so far and if the amount of data exceeds the max amount if so call http multiple times, just an example I quickly fired up.

I'll look into sockets tomorrow when I've read the documentation, this is just a method I thought of.
Reply
#9

Quote:
Originally Posted by Silentzx
Посмотреть сообщение
no i need to send logs/files from SA:MP to PHP files.
Wouldn't it just be easier to have PHP read the files from the server?
Or is your hosting on shared hosting on another server?
Reply
#10

Quote:
Originally Posted by Aldo.
Посмотреть сообщение
Wouldn't it just be easier to have PHP read the files from the server?
Or is your hosting on shared hosting on another server?
Majority of SA-MP servers aren't dedicated servers/vps.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)