Raised This Month: $32 Target: $400
 8% 

Reading from Sockets


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
endeffects
Senior Member
Join Date: Nov 2007
Old 06-10-2008 , 11:47   Reading from Sockets
Reply With Quote #1

Hallo,

i'm trying to write a plugin which checks the steam id of each player
while connecting. so on putinserver() a request to a webserver
will be send, which seems to work fine. but i'm not able to read
the response from the server with the public read_web() methode.

the "if (socket_change(g_sckweb, 100))" event seems to be never true.

can someone please have a look into it?

Code:
#include <amxmodx>
#include <sockets>
new g_sckweb //socket "id"
#define SCRIPT_NAME "/parser.php"
#define REMOTE_HOST "87.106.44.109" //port d.80
public plugin_init()
{
    register_plugin("Registration Manager", "1.0" ,"Endeffects")
}
public client_putinserver(id) 
{
     if(!is_user_bot(id))
         connect_web(id)
}
public connect_web(id)
{
    new error = 0
    new constring[512]
    g_sckweb = socket_open(REMOTE_HOST, 80, SOCKET_TCP, error)
    if (g_sckweb > 0)
    {
 new steamID[32];
        get_user_authid(id, steamID, 31);
        format(constring,511,"GET %s?%s HTTP/1.1^nHost: %s^nUser-Agent: GameServer^nAccept: */*^nConnection: close^n^n",SCRIPT_NAME,steamID,REMOTE_HOST)
        write_web(constring)
        read_web()
    }
    else
    {
     switch (error)
     {
         case 1: { client_print(0,print_chat,"Error creating socket"); }
         case 2: { client_print(0,print_chat,"Error resolving remote hostname"); }
         case 3: { client_print(0,print_chat,"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))
    {
 client_print(0,print_chat,"match")
     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"))
         {
              client_print(0,print_chat,"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()
{
    client_print(0,print_chat,"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
}
__________________
Get rid of all these fake, spam, redirect servers
on your steam server list!
endeffects is offline
|PJ| Shorty
Veteran Member
Join Date: Aug 2005
Location: Bavaria, Germany
Old 06-10-2008 , 13:01   Re: Reading from Sockets
Reply With Quote #2

try calling function read_web() with a task, maybe 1 sec

2nd: using client_authorized instead of client_putinserver makes sure the client has a steamid
__________________
There are only 10 types of people in the world:
Those who understand binary, and those who donīt.
|PJ| Shorty is offline
Send a message via ICQ to |PJ| Shorty Send a message via AIM to |PJ| Shorty Send a message via MSN to |PJ| Shorty Send a message via Yahoo to |PJ| Shorty Send a message via Skype™ to |PJ| Shorty
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 20:30.


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