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

Sockets Problem


Post New Thread Reply   
 
Thread Tools Display Modes
vlad_slick
Member
Join Date: Jul 2009
Old 07-05-2014 , 10:11   Re: Sockets Problem
Reply With Quote #11

1) test it yourself if you don't want to just trust what I say, add a server print in the read_web function.
2) the fact that the tutorials where from alliedmods doesn't make them get a "perfect" label, 0 bugs, perfect forward compatibility, etc.
3) if you think that it's worth waiting for a solution that may never come, ok, but as I see it it's better to not waste time fixing a broken wheel when there are working alternatives

Edit:
PHP Code:
                stock chat_color(const id, const input[], any:...)
                {
                    new 
count 1players[32]
                    static 
msg[191]
                    
vformat(msg190input3)

                    
replace_all(msg190".v""^4")
                    
replace_all(msg190".g""^1")
                    
replace_all(msg190".e""^3")

                    if (
idplayers[0] = id; else get_players(playerscount"ch")
//this is useless >    {
//i = 0 is correct >    for (new i = 1; i < count; i++) // now you're skipping players[0]
                        
{
                            if (
is_user_connected(players[i]))
                            {
                                
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("SayText"), _players[i])
                                
write_byte(players[i]);
                                
write_string(msg);
                                
message_end();
                            }
                        }
//this is useless >    }
                


Last edited by vlad_slick; 07-05-2014 at 10:23. Reason: added more details about chat_color bugs
vlad_slick is offline
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 07-06-2014 , 07:09   Re: Sockets Problem
Reply With Quote #12

Here are some corrections in your plugin. Don't declare huge arrays ( like new lines[30][100] ) in a function which is being looped frequently. As Black Rose said, Threaded MySql queries are better. You can make your SqlDb to accept remote sql connections form your GameServer IP only.

Form what i had observed, the parser.php file get newer data for more than 5 secs, so you can increase the the set_task() time.

PHP Code:
#include <amxmodx>
#include <sockets>

#define PLUGIN_NAME     "Radio BZ"
#define PLUGIN_AUTHOR   "aron9forever"
#define PLUGIN_VERSION  "1.1"

#define TASKREAD         12312

new g_sckweb

const SIZE 63
new const REMOTE_HOST[] =    "piratefm.ro"
new const SCRIPT_NAME[] = "/comm/parser.php"

/* new g_esong[64]
new g_rsong[64]
new g_dsong[64] */

// Make all the above vars as a 2D Array
new g_szSongs[3][SIZE+1];
new 
bool:isDisconnected true;

new const 
gVarsSizes[] = { 10// Size of "some_value" - 10
                            
11// Size of "some_value1" - 11
                            
11  // Size of "some_value2" - 11
}

new const 
gMessages[][] = {

    
".v[AMXX].e PirateFM Rap canta: -%s-",
    
".v[AMXX].e PirateFM Electro canta: -%s-",
    
".v[AMXX].e PirateFM Dub canta: -%s-"
}
    
public 
plugin_init()
{
    
register_plugin(PLUGIN_NAMEPLUGIN_VERSIONPLUGIN_AUTHOR)
    
set_task(10.0"tests", .flags="b")
    
    
register_clcmd"say /test""cmdTest" );
    
//set_task(40.0,"announce",_,_,_,"b",0)
}

public 
cmdTest(id)
{
    
client_printidprint_chat"g_eSong - %s"g_szSongs[0] );
    
client_printidprint_chat"g_rSong - %s"g_szSongs[1] );
    
client_printidprint_chat"g_dSong - %s"g_szSongs[2] );
}

public 
tests()
{
    
connect_web()
}

public 
connect_web()
{
    static 
constring[512], error;
    
error 0;

    if( !
isDisconnected disconnect_web();

    
g_sckweb socket_open(REMOTE_HOST80SOCKET_TCPerror)
    
isDisconnected false;

    if (
g_sckweb 0)
    {
        
chat_color(0".v[AMXX].e Socket Connected");
        
formatex(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: { chat_color(0".v[AMXX].e Error creating socket"); }
            case 
2: { chat_color(0".v[AMXX].e Error resolving remote hostname"); }
            case 
3: { chat_color(0".v[AMXX].e Error connecting socket"); }
        }
    }
    return 
PLUGIN_CONTINUE
}

public 
read_web()
{
    
// static line_variable[SIZE + 1], line_value[SIZE + 1]
    
static some_values[3][SIZE+1];
    static 
szBuffer[512]
    static 
bool:iReadiRead false;
    static 
jkiiReadLine;
    
iReadLine 00;

    if (
socket_change(g_sckweb100))
    {
        
/*new lines[30][100], count = 0 ;*/
        
socket_recv(g_sckwebszBuffer511)
        
iRead true;

        
// Read Full String
        
while( szBuffer[i] != '^0' )
        {
            
// Are we at |"|some_value" "<value>" ??
            
if( szBuffer[i] == '^"' )
            { 
                
// log_amx( "%s", szBuffer[i] );
                // Position of the char '"' (i) + length of var (gVarsSizes) + '"' (1) + <space> (1) + '"' (1) + 1
                // "some_value" "<Value>"
                // log_amx( "%d", iReadLine );
                
=  gVarsSizes[iReadLine] + 4;
                
                
// log_amx( "%s", szBuffer[j] );
                
0;
                
// Read until we reach "some_value" "<value>|"| 
                
while( szBuffer[j] != '^"' && (<= SIZE) && (511) )
                {
                    
some_values[iReadLine][k] = szBuffer[j];
                    
k++; j++;
                }
                
iReadLine++;
                
some_values[iReadLine-1][k] = '^0'// Complete the string with a null character
                
j;
            }

            
// All three lines are Read, So stop looping now
            
if( iReadLine ) break;
            
i++;
        }

        for( 
03i++ )
        {
            if( !
equal(some_values[i], g_szSongs[i]) )
            {
                
// set_hudmessage(0, 255, 0, 0.02, -1.0);
                // show_hudmessage(0, "PirateFM Rap canta: -%s-", some_values[i]);
                
chat_color(0gMessages[i], some_values[i]);
                
g_szSongs[i] = some_values[i];
            }
        }            
        
        
/* count = ExplodeString(lines, 50, 119, szBuffer, 13)
        for(new i=0;i<count;i++)
        {
            parse(lines[i], line_variable, SIZE, line_value, SIZE)
            if (equal(line_variable, "some_value"))
            {
                if(!equal(line_value, g_rsong))
                {
                    set_hudmessage(0, 255, 0, 0.02, -1.0);
                    show_hudmessage(0, "PirateFM Rap canta: -%s-", line_value);
                    chat_color(0, ".v[AMXX].ePirateFM Rap canta: -%s-", line_value)
                    g_rsong = line_value
                }
            }
            if (equal(line_variable, "some_value2"))
            {
                if(!equal(line_value, g_esong))
                {
                    set_hudmessage(0, 255, 0, 0.02, -1.0);
                    show_hudmessage(0, "PirateFM Electro canta: -%s-", line_value);
                    chat_color(0, ".v[AMXX].ePirateFM Electro canta: -%s-", line_value)
                    g_esong = line_value
                }
            }
            if (equal(line_variable, "some_value3"))
            {
                if(!equal(line_value, g_dsong))
                {
                    set_hudmessage(0, 255, 0, 0.02, -1.0);
                    show_hudmessage(0, "PirateFM Dub canta: -%s-", line_value);
                    chat_color(0, ".v[AMXX].ePirateFM Dub canta: -%s-", line_value)
                    g_dsong = line_value
                }
            }
        } */
    
}

    
remove_taskTASKREAD );
    if (!
iRead)
    {
        
// We didn't read, so set a task
        
set_task(0.5"read_web"TASKREAD );
    }
    else
        
disconnect_web();

    return 
PLUGIN_HANDLED
}

public 
write_web(text[])
{
    
socket_send(g_sckwebtext511)
}

public 
disconnect_web()
{
    
isDisconnected true;
    
chat_color(0".v[AMXX].e Socket disconnected")
    
socket_close(g_sckweb)
}

/* 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
} */

stock chat_color(const id, const input[], any:...)
{
    new 
count 1players[32]
    static 
msg[191]
    
vformat(msg190input3)

    
replace_all(msg190".v""^4")
    
replace_all(msg190".g""^1")
    
replace_all(msg190".e""^3")

    if (
idplayers[0] = id; else get_players(playerscount"ch")
    {
        for (new 
0counti++)
        {
            if (
is_user_connected(players[i]))
            {
                
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("SayText"), _players[i])
                
write_byte(players[i]);
                
write_string(msg);
                
message_end();
            }
        }
    }

__________________
As every time said, don't ever UNDERESTIMATE me.

Donate - Here

Last edited by Shooting King; 07-06-2014 at 07:11.
Shooting King is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 07-06-2014 , 08:33   Re: Sockets Problem
Reply With Quote #13

Quote:
Originally Posted by Shooting King View Post
Here are some corrections in your plugin. Don't declare huge arrays ( like new lines[30][100] ) in a function which is being looped frequently. As Black Rose said, Threaded MySql queries are better. You can make your SqlDb to accept remote sql connections form your GameServer IP only.

Form what i had observed, the parser.php file get newer data for more than 5 secs, so you can increase the the set_task() time.

PHP Code:
#include <amxmodx>
#include <sockets>

#define PLUGIN_NAME     "Radio BZ"
#define PLUGIN_AUTHOR   "aron9forever"
#define PLUGIN_VERSION  "1.1"

#define TASKREAD         12312

new g_sckweb

const SIZE 63
new const REMOTE_HOST[] =    "piratefm.ro"
new const SCRIPT_NAME[] = "/comm/parser.php"

/* new g_esong[64]
new g_rsong[64]
new g_dsong[64] */

// Make all the above vars as a 2D Array
new g_szSongs[3][SIZE+1];
new 
bool:isDisconnected true;

new const 
gVarsSizes[] = { 10// Size of "some_value" - 10
                            
11// Size of "some_value1" - 11
                            
11  // Size of "some_value2" - 11
}

new const 
gMessages[][] = {

    
".v[AMXX].e PirateFM Rap canta: -%s-",
    
".v[AMXX].e PirateFM Electro canta: -%s-",
    
".v[AMXX].e PirateFM Dub canta: -%s-"
}
    
public 
plugin_init()
{
    
register_plugin(PLUGIN_NAMEPLUGIN_VERSIONPLUGIN_AUTHOR)
    
set_task(10.0"tests", .flags="b")
    
    
register_clcmd"say /test""cmdTest" );
    
//set_task(40.0,"announce",_,_,_,"b",0)
}

public 
cmdTest(id)
{
    
client_printidprint_chat"g_eSong - %s"g_szSongs[0] );
    
client_printidprint_chat"g_rSong - %s"g_szSongs[1] );
    
client_printidprint_chat"g_dSong - %s"g_szSongs[2] );
}

public 
tests()
{
    
connect_web()
}

public 
connect_web()
{
    static 
constring[512], error;
    
error 0;

    if( !
isDisconnected disconnect_web();

    
g_sckweb socket_open(REMOTE_HOST80SOCKET_TCPerror)
    
isDisconnected false;

    if (
g_sckweb 0)
    {
        
chat_color(0".v[AMXX].e Socket Connected");
        
formatex(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: { chat_color(0".v[AMXX].e Error creating socket"); }
            case 
2: { chat_color(0".v[AMXX].e Error resolving remote hostname"); }
            case 
3: { chat_color(0".v[AMXX].e Error connecting socket"); }
        }
    }
    return 
PLUGIN_CONTINUE
}

public 
read_web()
{
    
// static line_variable[SIZE + 1], line_value[SIZE + 1]
    
static some_values[3][SIZE+1];
    static 
szBuffer[512]
    static 
bool:iReadiRead false;
    static 
jkiiReadLine;
    
iReadLine 00;

    if (
socket_change(g_sckweb100))
    {
        
/*new lines[30][100], count = 0 ;*/
        
socket_recv(g_sckwebszBuffer511)
        
iRead true;

        
// Read Full String
        
while( szBuffer[i] != '^0' )
        {
            
// Are we at |"|some_value" "<value>" ??
            
if( szBuffer[i] == '^"' )
            { 
                
// log_amx( "%s", szBuffer[i] );
                // Position of the char '"' (i) + length of var (gVarsSizes) + '"' (1) + <space> (1) + '"' (1) + 1
                // "some_value" "<Value>"
                // log_amx( "%d", iReadLine );
                
=  gVarsSizes[iReadLine] + 4;
                
                
// log_amx( "%s", szBuffer[j] );
                
0;
                
// Read until we reach "some_value" "<value>|"| 
                
while( szBuffer[j] != '^"' && (<= SIZE) && (511) )
                {
                    
some_values[iReadLine][k] = szBuffer[j];
                    
k++; j++;
                }
                
iReadLine++;
                
some_values[iReadLine-1][k] = '^0'// Complete the string with a null character
                
j;
            }

            
// All three lines are Read, So stop looping now
            
if( iReadLine ) break;
            
i++;
        }

        for( 
03i++ )
        {
            if( !
equal(some_values[i], g_szSongs[i]) )
            {
                
// set_hudmessage(0, 255, 0, 0.02, -1.0);
                // show_hudmessage(0, "PirateFM Rap canta: -%s-", some_values[i]);
                
chat_color(0gMessages[i], some_values[i]);
                
g_szSongs[i] = some_values[i];
            }
        }            
        
        
/* count = ExplodeString(lines, 50, 119, szBuffer, 13)
        for(new i=0;i<count;i++)
        {
            parse(lines[i], line_variable, SIZE, line_value, SIZE)
            if (equal(line_variable, "some_value"))
            {
                if(!equal(line_value, g_rsong))
                {
                    set_hudmessage(0, 255, 0, 0.02, -1.0);
                    show_hudmessage(0, "PirateFM Rap canta: -%s-", line_value);
                    chat_color(0, ".v[AMXX].ePirateFM Rap canta: -%s-", line_value)
                    g_rsong = line_value
                }
            }
            if (equal(line_variable, "some_value2"))
            {
                if(!equal(line_value, g_esong))
                {
                    set_hudmessage(0, 255, 0, 0.02, -1.0);
                    show_hudmessage(0, "PirateFM Electro canta: -%s-", line_value);
                    chat_color(0, ".v[AMXX].ePirateFM Electro canta: -%s-", line_value)
                    g_esong = line_value
                }
            }
            if (equal(line_variable, "some_value3"))
            {
                if(!equal(line_value, g_dsong))
                {
                    set_hudmessage(0, 255, 0, 0.02, -1.0);
                    show_hudmessage(0, "PirateFM Dub canta: -%s-", line_value);
                    chat_color(0, ".v[AMXX].ePirateFM Dub canta: -%s-", line_value)
                    g_dsong = line_value
                }
            }
        } */
    
}

    
remove_taskTASKREAD );
    if (!
iRead)
    {
        
// We didn't read, so set a task
        
set_task(0.5"read_web"TASKREAD );
    }
    else
        
disconnect_web();

    return 
PLUGIN_HANDLED
}

public 
write_web(text[])
{
    
socket_send(g_sckwebtext511)
}

public 
disconnect_web()
{
    
isDisconnected true;
    
chat_color(0".v[AMXX].e Socket disconnected")
    
socket_close(g_sckweb)
}

/* 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
} */

stock chat_color(const id, const input[], any:...)
{
    new 
count 1players[32]
    static 
msg[191]
    
vformat(msg190input3)

    
replace_all(msg190".v""^4")
    
replace_all(msg190".g""^1")
    
replace_all(msg190".e""^3")

    if (
idplayers[0] = id; else get_players(playerscount"ch")
    {
        for (new 
0counti++)
        {
            if (
is_user_connected(players[i]))
            {
                
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("SayText"), _players[i])
                
write_byte(players[i]);
                
write_string(msg);
                
message_end();
            }
        }
    }

This is great. Added some timestamps to the messages and it's working great
any particular reason you removed my huds, except the fact that they're not synced?

edit:: title says it all
sorry for the shitty crop, recorder didn't like my screen size, ill set it fine next time
also the footage is short because the encoder kept crashing at one point of the video, doesn't matter, it shows what's happening
https://www.youtube.com/watch?v=lcisger0oHE
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.

Last edited by aron9forever; 07-06-2014 at 09:06.
aron9forever is offline
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 07-06-2014 , 09:01   Re: Sockets Problem
Reply With Quote #14

I was lazy to make three different pairs of Origins for 3 Messages ( those three song names ) I think you can make them yourself. No specific reason.

EDIT : It works fine for me

EDIT2:
Code:
[AMXX] Socket Connected
[AMXX] PirateFM Rap canta: -Doc - Toata lumea canta-
[AMXX] PirateFM Electro canta: -Rusko - Jahova-
[AMXX] PirateFM Dub canta: -Melodica Roots - Tor.Ma In Dub-
[AMXX] Socket disconnected
[AMXX] Socket Connected
[AMXX] PirateFM Dub canta: -So High (Dub) - Rebelution-
[AMXX] Socket disconnected
[AMXX] Socket Connected
[AMXX] Socket disconnected
[AMXX] Socket Connected
[AMXX] Socket disconnected
[AMXX] Socket Connected
[AMXX] Socket disconnected
[AMXX] Socket Connected
[AMXX] Socket disconnected
__________________
As every time said, don't ever UNDERESTIMATE me.

Donate - Here

Last edited by Shooting King; 07-06-2014 at 09:20.
Shooting King is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 07-06-2014 , 09:14   Re: Sockets Problem
Reply With Quote #15

worked fine for me too, in the beggining
left server alone for a while then it popped up from my taskbar because I got kicked

came back and saw the latest message in console "socket connection failed"
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.

Last edited by aron9forever; 07-06-2014 at 09:14.
aron9forever is offline
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 07-06-2014 , 09:45   Re: Sockets Problem
Reply With Quote #16

I think there is something interrupting this plugin on your server. First test on your localhost.

EDIT:

The maxSize of the Song name is not 64. Increase it to around 128.

Code:
"some_value" "Vlad Dobrescu - Sateli-i (feat. Aforic, raku, Nwanda, Flou Rege, Pietonu')"
"some_value2" "EnrightBeats - Piano Man"
"some_value3" "Ravi Shankar (live) - Dub Syndicate"
__________________
As every time said, don't ever UNDERESTIMATE me.

Donate - Here

Last edited by Shooting King; 07-06-2014 at 14:46.
Shooting King is offline
Old 07-06-2014, 09:46
aron9forever
This message has been deleted by aron9forever. Reason: not double post. hah, suck on dat
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 07-10-2014 , 12:41   Re: Sockets Problem
Reply With Quote #17

Quote:
Originally Posted by Shooting King View Post
I think there is something interrupting this plugin on your server. First test on your localhost.

EDIT:

The maxSize of the Song name is not 64. Increase it to around 128.

Code:
"some_value" "Vlad Dobrescu - Sateli-i (feat. Aforic, raku, Nwanda, Flou Rege, Pietonu')"
"some_value2" "EnrightBeats - Piano Man"
"some_value3" "Ravi Shankar (live) - Dub Syndicate"
hey, do you think this same code could be converted to UDP?
I have a feel the reason the server hangs is because with tcp it freezes to wait for the answer

the remote php may fuck up, the server needs to get over it

I have no idea how to convert it, is changing socket_open(REMOTE_HOST, 80, SOCKET_TCP, error) to socket_open(REMOTE_HOST, 80, SOCKET_UDP, error) enough?
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever is offline
vlad_slick
Member
Join Date: Jul 2009
Old 07-10-2014 , 13:37   Re: Sockets Problem
Reply With Quote #18

Quote:
Originally Posted by aron9forever View Post
hey, do you think this same code could be converted to UDP?
I have a feel the reason the server hangs is because with tcp it freezes to wait for the answer

the remote php may fuck up, the server needs to get over it

I have no idea how to convert it, is changing socket_open(REMOTE_HOST, 80, SOCKET_TCP, error) to socket_open(REMOTE_HOST, 80, SOCKET_UDP, error) enough?
It's not enough to just change how you open the socket, you'd have to change how the php script sends info (now it's sending with TCP) and adapt the sma to the new protocol.
But it would all be useless, TCP is much more reliable than UDP.
The problem is not with the protocol you're using, but the pawn code you're using to read http responses.

Last edited by vlad_slick; 07-10-2014 at 13:41.
vlad_slick is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 08-03-2014 , 23:43   Re: Sockets Problem
Reply With Quote #19

I'm gonna bump this old thread because the issue is yet to be fixed.
I thought about switching to SQL, but that's a bad idea, since I intend to make this plug-in public.

Quote:
Originally Posted by vlad_slick View Post
The problem is not with the protocol you're using, but the pawn code you're using to read http responses.
Provide a better solution then, please. I can't understand what can be so troublesome with reading two sentences each couple of seconds. There's also nowhere to learn from, I can't find anything that would resemble what I need.

I also suspect this is so hard because at some point some amxx updates changed something rendering old plugins unusable, so I really can't find any examples to use.
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever is offline
vlad_slick
Member
Join Date: Jul 2009
Old 08-04-2014 , 14:01   Re: Sockets Problem
Reply With Quote #20

Quote:
Originally Posted by aron9forever View Post
I'm gonna bump this old thread because the issue is yet to be fixed.
Quote:
Originally Posted by vlad_slick View Post
3) if you think that it's worth waiting for a solution that may never come, ok, but as I see it it's better to not waste time fixing a broken wheel when there are working alternatives
Quote:
Originally Posted by aron9forever View Post
Provide a better solution then, please. I can't understand what can be so troublesome with reading two sentences each couple of seconds. There's also nowhere to learn from, I can't find anything that would resemble what I need.
I have already given you more than enough links from were you could learn. But it seems like you didn't bother checking them:

Quote:
Originally Posted by vlad_slick View Post
- if you want to handle the sockets, have a look at how xREDIRECT by xOR handles socket communication (error handling, socket reading, etc.); it's made for UDP sockets, but you can get ideas from it;

- another sockets option would be to use Bugsy's [INC] HTTP, which handles the socket communications, and just downloads a file, which you could read with amx

-if you don't want to use sockets you could try the Threaded HTTP module by joropito, it's much easier to use ( but I haven't been able to make it work on Windows)
Quote:
Originally Posted by aron9forever View Post
I also suspect this is so hard because at some point some amxx updates changed something rendering old plugins unusable, so I really can't find any examples to use.
I doubt that you're right, I think it's just that your way of handling sockets is wrong. (I don't know what is wrong as this is not a 'fix my code' forum, but as I said twice already you can look at xREDIRECT to see how it should be done)

Here's a working example (with much less code) using one of the modules I suggested you should use:
PHP Code:
#include <amxmodx>
#include <thttp>

#define PLUGIN_NAME "Radio Track Announcer"
#define PLUGIN_AUTHOR   "vlad&aron9forever"
#define PLUGIN_VERSION  "1.0"

#define REMOTE_HOST "piratefm.ro"
#define SCRIPT_NAME "/rapcur.php"


public plugin_init()
{
    
register_plugin(PLUGIN_NAMEPLUGIN_VERSIONPLUGIN_AUTHOR)
    
set_task(5.0,"tests")
    
//set_task(40.0,"announce",_,_,_,"b",0)
}

public 
tests()
{
    
set_task(15.0,"tests")
    
httpget()
}


stock chat_color(const id, const input[], any:...)
{    
    new 
count 1players[32]
    static 
msg[191]
    
vformat(msg190input3)
    
    
replace_all(msg190".v""^4")
    
replace_all(msg190".g""^1")
    
replace_all(msg190".e""^3")
    
    if (
id
        
players[0] = id
    
else
        
get_players(playerscount"ch")
        
    for (new 
0counti++)
    {
        if (
is_user_connected(players[i]))
        {
            
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("SayText"), _players[i])
            
write_byte(players[i])
            
write_string(msg)
            
message_end()
        }
    }
    
}

public 
thttp_response(key[], data[], codereason[])
{
    
//log_amx("HTTP: key:%s code:%i reason:%s data:%s\n", key, code, reason, data)
    
format(datastrlen(data)-4,"%s",data)
    new 
startPosData containi(data,"^">") + 2
        
    show_hudmessage(0, "
PirateFM Rap canta: -%s-", data[startPosData])
    chat_color(0, "
.v[AMXX].ePirateFM Rap canta: -%s-", data[startPosData])
    
    
}

public httpget()
{
        thttp_request("
thisisthekey", REMOTE_HOST, "GET", SCRIPT_NAME)
        return PLUGIN_HANDLED

vlad_slick is offline
Reply



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


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