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

^r


Post New Thread Reply   
 
Thread Tools Display Modes
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 09-29-2010 , 00:17   Re: ^r
Reply With Quote #11

Have you tried that example there ?

And you don't need tutorials, just search for plugins that use sokets.
__________________
Hunter-Digital is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-29-2010 , 00:28   Re: ^r
Reply With Quote #12

Here's a basic sockets example, if you need help just ask.

http://forums.alliedmods.net/showpos...12&postcount=4
__________________
Bugsy is offline
crazy.cipry
Member
Join Date: Dec 2008
Location: Romania
Old 09-29-2010 , 08:43   Re: ^r
Reply With Quote #13

Quote:
Originally Posted by Bugsy View Post
Here's a basic sockets example, if you need help just ask.

http://forums.alliedmods.net/showpos...12&postcount=4
I saw that but I want to find out how to store the text which is in the txt file on the host ( and has 3 lines for e.g ),store it in a string, and print it exactly as it was in the file ( with spaces/tabs ).
crazy.cipry is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-29-2010 , 10:13   Re: ^r
Reply With Quote #14

Ok so you want to read 3 lines from the file and print them to the server?
__________________
Bugsy is offline
crazy.cipry
Member
Join Date: Dec 2008
Location: Romania
Old 09-29-2010 , 11:03   Re: ^r
Reply With Quote #15

Quote:
Originally Posted by Bugsy View Post
Ok so you want to read 3 lines from the file and print them to the server?
Yes.
crazy.cipry is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-29-2010 , 22:07   Re: ^r
Reply With Quote #16

This isn't the best way to go about this but it was fast\easy to code. Let me know of any problems.

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

#define TASK_RECV    551122
new Float:g_fResponseTime33 ];

new const 
HOSTSERVER[] = "www.usconstitution.net";
new const 
FILENAME[] = "/const.txt";
new const 
TEMP_FILE_NAME[] = "TempFile.txt";
const 
LINES_TO_READ 3;

public 
plugin_init() 
{
    
register_plugin"sockets" "0.1" "bugsy" );
    
register_concmd"test" "TestConnect" );
}

public 
TestConnectid )
{    
    new 
iSocket iError;
    
    
g_fResponseTimeid ] = get_gametime();
    
iSocket socket_openHOSTSERVER 80 SOCKET_TCP iError );
    
    if ( !
iSocket || iError )
        return 
PLUGIN_HANDLED;
    
    new 
szPacket128 ];
    
formatexszPacket charsmaxszPacket ) , "GET %s HTTP/1.1^r^nHost: %s^r^n^r^n" FILENAME HOSTSERVER);
    
socket_sendiSocket szPacket sizeofszPacket ) );
    
    new 
params];
    
params] = id;
    
params] = iSocket;
    
set_task0.25 "ReadData" TASK_RECV params sizeofparams ) , "b" );

    return 
PLUGIN_HANDLED;
}

public 
ReadDataparams] )
{
    new 
id params];
    new 
iSocket params];
    
    static 
szData512 ] , szLine32 ];
    new 
iDataStart iLinesRead iLen;
    
    if ( 
socket_changeiSocket ) )
    {
        
socket_recviSocket szData charsmaxszData ) );
        
g_fResponseTimeid ] = get_gametime();
        
        
iDataStart strfindszData "^r^n^r^n" ) + 4;
        
        if ( 
iDataStart != )
        {
            
remove_taskTASK_RECV );
            
            if ( 
file_existsTEMP_FILE_NAME ) )
                
delete_fileTEMP_FILE_NAME );
                
            
write_fileTEMP_FILE_NAME szDataiDataStart ] );
            
            while ( 
iLinesRead LINES_TO_READ )
            {
                
read_fileTEMP_FILE_NAME iLinesRead++ , szLine charsmaxszLine ), iLen );
                
client_printprint_chat "WebData: %s" szLine );
            }
        }
    }
    
    if ( ( 
get_gametime() - g_fResponseTimeid ] ) >= 5.0 )
        
remove_taskTASK_RECV );

__________________
Bugsy is offline
crazy.cipry
Member
Join Date: Dec 2008
Location: Romania
Old 09-30-2010 , 13:10   Re: ^r
Reply With Quote #17

Thank you !
It works, but I don't understand this part from code:
PHP Code:
 iDataStart strfindszData "^r^n^r^n" ) + 4
So you search for what in the szData string? And why +4 ? :-??
crazy.cipry is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-30-2010 , 13:46   Re: ^r
Reply With Quote #18

That finds where the data starts (after the http header). At the end of the header there are two carriage returns (4 characters) which strfind locates, you then need to add 4 because you do not want the carriage returns included in your data.
__________________
Bugsy is offline
crazy.cipry
Member
Join Date: Dec 2008
Location: Romania
Old 09-30-2010 , 13:51   Re: ^r
Reply With Quote #19

oh... i understand now :-?
Thanks very much.
crazy.cipry 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 13:39.


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