AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   amxx+php (https://forums.alliedmods.net/showthread.php?t=312915)

Mikka 12-20-2018 12:04

amxx+php
 
Hello guys, how can I send data to a web server from this code and how to receive this data from it?

https://i.imgur.com/foP9ui1.png

#include <amxmodx>
#include <amxmisc>
#include <sockets>

#define SITE "/index.php/2011/09/12/info-po-smierci/6"
#define HOST "darkgl.pl"

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "DarkGL"

new g_Socket;

public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)

register_clcmd("say /test","test")
}

public test(id){
new iError,szSendBuffer[512]

g_Socket = socket_open(HOST, 80, SOCKET_TCP, iError)

switch (iError)
{
case 1:
{
log_amx("Unable to create socket.")
return ;
}
case 2:
{
log_amx("Unable to connect to hostname.")
return ;
}
case 3:
{
log_amx("Unable to connect to the HTTP port.")
return ;
}
}

format(szSendBuffer, charsmax(szSendBuffer), "GET %s^nHost:%s^r^n^r^n", SITE, HOST)
socket_send(g_Socket, szSendBuffer, charsmax(szSendBuffer))

set_task(1.0, "socketAnswer", .flags = "b")
}

public socketAnswer(){
if (socket_change(g_Socket)) {
new szData[1024]

socket_recv(g_Socket, szData, charsmax(szData) )

log_amx(szData);

socket_close(g_Socket);

remove_task( 0 );
}
}

fysiks 12-20-2018 22:46

Re: amxx+php
 
1 Attachment(s)
You can use sockets to send either a GET or POST query to your web server (which is what it looks like you are already doing). You should be able to receive data from this query. It would require using RCON on the server to be able to have an event on the website send unsolicited data to the server.

I wrote a function a long time ago to send ban information to a webpage that I wrote using POST. I've attached it here for reference. It doesn't retrieve any data back from the server but I didn't need to for this application.

Mikka 12-21-2018 06:46

Re: amxx+php
 
Very very thanks for reply :) but I am totally green when it comes to sockets. You could have an example of using with a web server?

fysiks 12-21-2018 18:47

Re: amxx+php
 
Quote:

Originally Posted by Mikka (Post 2630326)
Very very thanks for reply :) but I am totally green when it comes to sockets. You could have an example of using with a web server?

Did you not look at the file that I attached? Also, you can look for a tutorial or code snippets in the Code Snippets/Tutorials subforum as well as other plugins that use sockets.


All times are GMT -4. The time now is 07:31.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.