Raised This Month: $51 Target: $400
 12% 

Reading from Sockets


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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 14:02.


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