Raised This Month: $ Target: $400
 0% 

Socket help


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 12-21-2018 , 11:54   Re: Socket help
Reply With Quote #9

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

#define FILE	"addons/amxmodx/configs/page.txt"

new Socket, Error;

new const FindLine [ ] = "<a href=^"http://www.csservers.ro/evidenta/zm.darkland.ro/voturi-azi^">";
new const FindLine2 [ ] = "</a></div>";

public plugin_init ( )	set_task ( 2.0, "SavePage" );
public SavePage ( )
{
	Socket = socket_open ( "www.csservers.ro", 80, SOCKET_TCP, Error );

	new Pos, Pos2;
	new Result [ 3 ];
	
	if ( Socket > 0 )
	{
		new Query [ 512 ], DataRecived [ 2048 ];
		formatex ( Query, charsmax ( Query ), "GET /evidenta/zm.darkland.ro HTTP/1.1^r^nHost:www.csservers.ro^r^nConnection: close^r^n^r^n" );

		if ( !Error )
		{
			socket_send ( Socket, Query, charsmax ( Query ) );
		
			while ( socket_recv ( Socket, DataRecived, charsmax ( DataRecived ) ) )
			{
				if ( socket_change ( Socket, 1 ) )
				{
					socket_recv ( Socket, DataRecived, charsmax ( DataRecived ) );
					
					Pos = strfind ( DataRecived, FindLine );
					Pos2 = strfind ( DataRecived, FindLine2, Pos );
					
					if ( ( Pos > -1 ) && ( Pos2 > -1 ) )
					{
						copyc ( Result, charsmax ( Result ), DataRecived [ Pos + ( sizeof ( FindLine ) -1 ) ], Pos2 - ( sizeof ( FindLine2 ) -1 ) );
						server_print ( "Votes: %d", str_to_num ( Result ) );
					}
					
				}
			}

			socket_close ( Socket );

		}
	}
}
I've tried to strfiind in DataRecived but no server_print in console..that's not good )
With regex hmm.. i will try this
__________________
LondoN 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 07:32.


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