How to use HTTP
#1

Hello.. i create a program (https://sampforum.blast.hk/showthread.php?tid=455023) and they told me to try using HTTP, the only problem is we're all difficult not agree! Someone could advise you on how to program instructions to carry out when connecting to the server? And what kind of script to be used on a server?

Translated by: ******..
Reply
#2

You want this:

If a player is connected w/ your program he will get 500 money, else no.

Ok, if you want to use HTTP function you can do something like this:

(Two ways)

1.
When the player open the application, get his IP and send the IP to a PHP page and save it.

When a player w/ the same IP connect to the server, give him the moneys and remove the IP from the list.

2.

In the application add a "nickname" box, send it to the server.

Same above, just with the nickname.
Reply
#3

Quote:
Originally Posted by ReVo_
Посмотреть сообщение
You want this:

If a player is connected w/ your program he will get 500 money, else no.

Ok, if you want to use HTTP function you can do something like this:

(Two ways)

1.
When the player open the application, get his IP and send the IP to a PHP page and save it.

When a player w/ the same IP connect to the server, give him the moneys and remove the IP from the list.

2.

In the application add a "nickname" box, send it to the server.

Same above, just with the nickname.
Thank you!
And where can i save the nickname, or how to send it to server?

Because here an example:
Код:
forward MyHttpResponse(index, response_code, data[]);
 
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp("/hello",cmdtext,true))
    {
        HTTP(playerid, HTTP_GET, "kc.gd/hello.txt", "", "MyHttpResponse");
        return 1;
    }
    return 0;
}
 
public MyHttpResponse(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);
    }
}
This is if player use command (/hello) then the "hello.txt" to content is written to "SendClientMessage"?
Reply
#4

Emh.. its a bit hard than you think..


I mean:

Код:
        static void Main(string[] args)
        {
            string ip = null;

            // Here your code to get the IP

            if (ip != null)
            {
                // now the have the IP
                // send it

                Console.WriteLine("Your IP is: " + ip);

                WebClient wc = new WebClient();

                // i never used UploadString, but its just an example
             //   wc.UploadString("your_php_page", ip);

                // then you are ok.
            }
            else
            {
                Console.WriteLine("Unable to get your IP");
            }
        }
This should help you to understand the logic.

Then the PHP should save the string he get, anyway a SQLite code might be better since is better to manage than a plain text.


The PAWN script is a simple HTTP request to a page w/ the IP of the connected player as param something like this:

Код:
public OnPlayerConnect(playerid)
{
    new str [16 + 5];
    new IP [16];
    
    str = "d=";
    GetPlayerIp( playerid , ip , 16 );

    strcat(str, ip, 16+5);
       
    HTTP(playerid, HTTP_GET, "your_url", str, "OhWait");
    return true;
}

// remember to forward
public OhWait ( ... )
{
    if (response_code == 200 && strval(data) == 1)
    {
        GivePlayerMoney ( playerid , 50 );
    }
    else
    {
        // Here or the WEBSITE is down
        // Or the player is not connected using Your APP
    }
}
<b>Important</b>: to get this working, when the player is connected w/ the app, the php page should report a response with "1".
Reply
#5

Quote:
Originally Posted by ReVo_
Посмотреть сообщение
Emh.. its a bit hard than you think..


I mean:

Код:
        static void Main(string[] args)
        {
            string ip = null;

            // Here your code to get the IP

            if (ip != null)
            {
                // now the have the IP
                // send it

                Console.WriteLine("Your IP is: " + ip);

                WebClient wc = new WebClient();

                // i never used UploadString, but its just an example
             //   wc.UploadString("your_php_page", ip);

                // then you are ok.
            }
            else
            {
                Console.WriteLine("Unable to get your IP");
            }
        }
This should help you to understand the logic.

Then the PHP should save the string he get, anyway a SQLite code might be better since is better to manage than a plain text.


The PAWN script is a simple HTTP request to a page w/ the IP of the connected player as param something like this:

Код:
public OnPlayerConnect(playerid)
{
    new str [16 + 5];
    new IP [16];
    
    str = "d=";
    GetPlayerIp( playerid , ip , 16 );

    strcat(str, ip, 16+5);
       
    HTTP(playerid, HTTP_GET, "your_url", str, "OhWait");
    return true;
}

// remember to forward
public OhWait ( ... )
{
    if (response_code == 200 && strval(data) == 1)
    {
        GivePlayerMoney ( playerid , 50 );
    }
    else
    {
        // Here or the WEBSITE is down
        // Or the player is not connected using Your APP
    }
}
<b>Important</b>: to get this working, when the player is connected w/ the app, the php page should report a response with "1".
Thanks!!
More questions: What is "My url"? Can i create a website, upload the file the file that contains the
Код:
static void Main (string [] args)
         {
             string ip = null;
             if (ip! = null)
             {
                 / / Now the have the IP
                 / / Send it

                 Console.WriteLine ("Your IP is" + ip);
                 WebClient wc = new WebClient ();

                 / / I never used UploadString, but its just an example
              / / Wc.UploadString ("your_php_page", ip);

                 / / Then you are ok.
             }
             else
             {
                 Console.WriteLine ("Unable to get your IP");
             }
         }
and ready?

And i can use every php page? or what? can i create a website example.. ucoz.com and paste it to "your_php_page"?

Thanks all
Reply
#6

Hmm. .. let see from start ..

I create the program with: visual basic ..
What do I need to provide to do what the program by pressing the "start" button? I have a website (www.example.do.am) .. Here need to upload, and the pawno script should ask here.

Код:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    End Sub
End Class
You writed this:
Код:
    static void Main(string[] args)
        {
            string ip = null;
            if (ip != null)
            {
                // now the have the IP
                // send it

                Console.WriteLine("Your IP is: " + ip);
                WebClient wc = new WebClient();

                // i never used UploadString, but its just an example

                // then you are ok.
            }
            else
            {
                Console.WriteLine("Unable to get your IP");
            }
        }
if i put this to my script, its okay?
Reply
#7

Was just an example in C#, i dont know how to do it in VB but Search for

Webclient in vb
Get IP address in vb

You should create a PHP page (two, really) one for add the IP, one for get and remove the IP.
Reply
#8

Okay .. thanks all

I think i know what is this ..

The bottom line is that my program must upload a file to a php page with the IP address of the player's name, and the samp script to query the existence of .. is not it?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)