Raised This Month: $132 Target: $400
 33% 

Sockets and webservers


Post New Thread Reply   
 
Thread Tools Display Modes
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 11-26-2007 , 11:40   Re: Sockets and webservers
Reply With Quote #31

Yeah, get the server uptime, then save it to sql, then make a simple .php script to get it on webpage.
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
hackziner
Senior Member
Join Date: Sep 2006
Location: France
Old 11-27-2007 , 02:27   Re: Sockets and webservers
Reply With Quote #32

Of course.

You can find a way to get the uptime here:
http://forums.alliedmods.net/showthr...ghlight=uptime

and you can create a webserver with:
http://forums.alliedmods.net/showthread.php?t=63512 ( check sample 1 )
__________________
hackziner is offline
Send a message via ICQ to hackziner Send a message via AIM to hackziner Send a message via MSN to hackziner Send a message via Yahoo to hackziner Send a message via Skype™ to hackziner
VMAN
Senior Member
Join Date: Oct 2007
Location: California, US
Old 01-25-2008 , 03:57   Re: Sockets and webservers
Reply With Quote #33

My clan runs this on all their servers

Code:
#include <amxmodx>
#include <fakemeta>

new amx_gamename;
public plugin_init( ) { 
	register_plugin( "Game Namer", "1.1", "NeuroToxin" ); 
	amx_gamename = register_cvar( "amx_gamename", "Team Fortress Classic" ); 
	register_forward( FM_GetGameDescription, "GameDesc" ); 
}
 
public GameDesc( ) { 
	static gamename[32]; 
	get_pcvar_string( amx_gamename, gamename, 31 ); 
	forward_return( FMV_STRING, gamename ); 
	return FMRES_SUPERCEDE; 
}
Sometimes we change domains or forums, is their a way to make this plugin retrieve the value of amx_gamename from a web page?
VMAN is offline
413-X-
Member
Join Date: Feb 2008
Old 04-25-2008 , 05:06   Re: Sockets and webservers
Reply With Quote #34

Great Tutorial ! But how to use sockets with an IRC-Bot ???
__________________
--
413-X- is offline
endeffects
Senior Member
Join Date: Nov 2007
Old 06-10-2008 , 09:51   Re: Sockets and webservers
Reply With Quote #35

hallo,

i try to compile the example but i'm getting alot of errors:

Quote:
/home/groups/amxmodx/tmp3/textW7wZxC.sma(24) : error 017: undefined symbol "write_web"
/home/groups/amxmodx/tmp3/textW7wZxC.sma(25) : error 017: undefined symbol "read_web"
/home/groups/amxmodx/tmp3/textW7wZxC.sma(3 : warning 217: loose indentation
/home/groups/amxmodx/tmp3/textW7wZxC.sma(3 : error 029: invalid expression, assumed zero
/home/groups/amxmodx/tmp3/textW7wZxC.sma(3 : error 017: undefined symbol "read_web"
/home/groups/amxmodx/tmp3/textW7wZxC.sma(47) : error 017: undefined symbol "ExplodeString"
/home/groups/amxmodx/tmp3/textW7wZxC.sma(60) : error 017: undefined symbol "disconnect_web"
/home/groups/amxmodx/tmp3/textW7wZxC.sma(63) : warning 217: loose indentation
/home/groups/amxmodx/tmp3/textW7wZxC.sma(63) : error 029: invalid expression, assumed zero
/home/groups/amxmodx/tmp3/textW7wZxC.sma(63) : error 017: undefined symbol "write_web"
/home/groups/amxmodx/tmp3/textW7wZxC.sma(63) : warning 215: expression has no effect
/home/groups/amxmodx/tmp3/textW7wZxC.sma(63) : error 001: expected token: ";", but found "]"
/home/groups/amxmodx/tmp3/textW7wZxC.sma(63) : fatal error 107: too many error messages on one line
Code:
#include <amxmodx>
#include <sockets>
new g_sckweb //socket "id"
#define SCRIPT_NAME "/myplugin/parser.php"
#define REMOTE_HOST "myserver.com" //port d.80
public plugin_init()
{
    register_plugin("Socket sample", "??" ,"Darksnow")
    set_task(5.0,"connect_web") 
}
public connect_web()
{
    new error = 0
    new constring[512]
    g_sckweb = socket_open(REMOTE_HOST, 80, SOCKET_TCP, error)
    if (g_sckweb > 0)
    {
        format(constring,511,"GET %s HTTP/1.1^nHost: %s^n^n",SCRIPT_NAME,REMOTE_HOST)
        write_web(constring)
        read_web()
    }
    else
    {
    switch (error)
    {
        case 1: { server_print("Error creating socket"); }
        case 2: { server_print("Error resolving remote hostname"); }
        case 3: { server_print("Error connecting socket"); }
    }
    return PLUGIN_CONTINUE
}
public read_web()
{
    const SIZE = 63
    new line_variable[SIZE + 1], line_value[SIZE + 1]
    if (socket_change(g_sckweb, 100))
    {
    new buf[512], lines[30][100], count = 0
    socket_recv(g_sckweb, buf, 511)
    count = ExplodeString(lines, 50, 119, buf, 13)
    for(new i=0;i<count;i++)
    {
        parse(lines[i], line_variable, SIZE, line_value, SIZE)
        if (equal(line_variable, "some_value"))
        {
            server_print("Value is %s", line_value)
        }
    }   
    if (g_sckweb != 0)
        set_task(0.5, "read_web")
    else
        disconnect_web()
}
public write_web(text[512])
{
    socket_send(g_sckweb, text, 511)
}
public disconnect_web()
{
    server_print("Socket disconnected")
}
stock ExplodeString( p_szOutput[][], p_nMax, p_nSize, p_szInput[], p_szDelimiter ) { // Function by xeroblood
    new nIdx = 0, l = strlen(p_szInput)
    new nLen = (1 + copyc( p_szOutput[nIdx], p_nSize, p_szInput, p_szDelimiter ))
    while( (nLen < l) && (++nIdx < p_nMax) )
        nLen += (1 + copyc( p_szOutput[nIdx], p_nSize, p_szInput[nLen], p_szDelimiter ))
    return nIdx
}
any ideas to get it working?
__________________
Get rid of all these fake, spam, redirect servers
on your steam server list!
endeffects is offline
Greenberet
AMX Mod X Beta Tester
Join Date: Apr 2004
Location: Vienna
Old 06-10-2008 , 19:33   Re: Sockets and webservers
Reply With Quote #36

download it locally and not with the webcompiler
__________________
Greenberet is offline
Send a message via ICQ to Greenberet Send a message via MSN to Greenberet
xOR
Veteran Member
Join Date: Jun 2006
Location: x-base.info
Old 01-06-2009 , 08:59   Re: Sockets and webservers
Reply With Quote #37

it's not the web compiler, it's the "else" in connect_web() having its closing bracket missing.

EDIT:
oh, and the closing bracket for if (socket_change(g_sckweb, 100)) is missing also. and an include for <amxmodx> before the <sockets> include is needed as well. let me just post the code that compiles:
Code:
#include <amxmodx> #include <sockets> new g_sckweb //socket "id" #define SCRIPT_NAME "/myplugin/parser.php" #define REMOTE_HOST "myserver.com" //port d.80 public plugin_init() {     register_plugin("Socket sample", "??" ,"Darksnow")     set_task(5.0,"connect_web") } public connect_web() {     new error = 0     new constring[512]     g_sckweb = socket_open(REMOTE_HOST, 80, SOCKET_TCP, error)     if (g_sckweb > 0)     {         format(constring,511,"GET %s HTTP/1.1^nHost: %s^n^n",SCRIPT_NAME,REMOTE_HOST)         write_web(constring)         read_web()     }     else     {         switch (error)         {             case 1: { server_print("Error creating socket"); }             case 2: { server_print("Error resolving remote hostname"); }             case 3: { server_print("Error connecting socket"); }         }     }     return PLUGIN_CONTINUE } public read_web() {     const SIZE = 63     new line_variable[SIZE + 1], line_value[SIZE + 1]     if (socket_change(g_sckweb, 100))     {         new buf[512], lines[30][100], count = 0         socket_recv(g_sckweb, buf, 511)         count = ExplodeString(lines, 50, 119, buf, 13)         for(new i=0;i<count;i++)         {             parse(lines[i], line_variable, SIZE, line_value, SIZE)             if (equal(line_variable, "some_value"))             {                 server_print("Value is %s", line_value)             }         }        }     if (g_sckweb != 0)         set_task(0.5, "read_web")     else         disconnect_web() } public write_web(text[512]) {     socket_send(g_sckweb, text, 511) } public disconnect_web() {     server_print("Socket disconnected") } stock ExplodeString( p_szOutput[][], p_nMax, p_nSize, p_szInput[], p_szDelimiter ) { // Function by xeroblood     new nIdx = 0, l = strlen(p_szInput)     new nLen = (1 + copyc( p_szOutput[nIdx], p_nSize, p_szInput, p_szDelimiter ))     while( (nLen < l) && (++nIdx < p_nMax) )         nLen += (1 + copyc( p_szOutput[nIdx], p_nSize, p_szInput[nLen], p_szDelimiter ))     return nIdx }
__________________
Got more than one HL1 (CS, DoD, NS, TS, TFC, HLDM...) server? Check:

Last edited by xOR; 01-06-2009 at 09:08.
xOR is offline
portocala
Member
Join Date: Jun 2010
Old 08-06-2010 , 05:28   Re: Sockets and webservers
Reply With Quote #38

One question about the first sockets sample.

Why don't we need to call socket_close ?
portocala is offline
Clauu
Senior Member
Join Date: Feb 2008
Location: RO
Old 05-06-2011 , 04:46   Re: Sockets and webservers
Reply With Quote #39

Can someone please give a working example about how to retrive some data from a .php file using sockets?
Clauu is offline
ish12321
Veteran Member
Join Date: May 2016
Old 01-07-2018 , 17:18   Re: Sockets and webservers
Reply With Quote #40

https://forums.alliedmods.net/showthread.php?t=304139
__________________
['O|s|G'] | Death Wins a.k.a Ish Chhabra was here
ish12321 is offline
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

Forum Jump


All times are GMT -4. The time now is 00:57.


Powered by vBulletin®
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Theme made by Freecode