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

Socket help


Post New Thread Reply   
 
Thread Tools Display Modes
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 12-27-2018 , 04:52   Re: Socket help
Reply With Quote #11

Code:
#include < amxmodx >
#include < amxmisc >
#include < cstrike >
#include < regex >
#include < httpx >

new g_CurrentVotes, g_LastStoredVotes;

public plugin_init ( )
{
	register_plugin ( "Vote and get bonus", "2.0", "LondoN eXtream" );
	register_clcmd ( "say /vote", "Func_VoteServer" );
}

public Func_VoteServer ( id )
{
	HTTPX_Download ( "www.csservers.ro/evidenta/zm.darkland.ro", _, _, "StoreVotes" );

	show_motd ( id, "www.csservers.ro/voteaza/zm.darkland.ro" );

	set_task ( 10.0, "CheckAgainVotes", id );
}

public StoreVotes ( id )
{
	new Buffer [ 1024 ], len;
	new szError [ 50 ], iNum;
	new Regex: FindVote;

	while ( ( len = HTTPX_GetData ( Buffer, charsmax ( Buffer ) ) ) )
	{
		FindVote = regex_match ( Buffer, "voturi-azi^">(.*?)</a>", iNum, szError, charsmax ( szError ) );

		if ( FindVote )
		{
			new szVotes [ 16 ];
			regex_substr ( FindVote, 1, szVotes, charsmax ( szVotes ) );
			server_print ( "Votes right now: %d", str_to_num ( szVotes ) );
			g_LastStoredVotes = str_to_num ( szVotes );
			regex_free ( FindVote );
		}
	}
}

public CheckAgainVotes ( id )
{
	HTTPX_Download ( "www.csservers.ro/evidenta/zm.darkland.ro", _, _, "CheckAgainVotes" );
}

public CheckAgainVotes ( id )
{
	new Buffer [ 1024 ], len;
	new szError [ 50 ], iNum;
	new Regex: NewVote;

	while ( ( len = HTTPX_GetData ( Buffer, charsmax ( Buffer ) ) ) )
	{
		NewVote = regex_match ( Buffer, "voturi-azi^">(.*?)</a>", iNum, szError, charsmax ( szError ) );

		if ( NewVote )
		{
			new szVotes [ 16 ];
			regex_substr ( NewVote, 1, szVotes, charsmax ( szVotes ) );
			server_print ( "Votes now: %d", str_to_num ( szVotes ) );

			g_CurrentVotes = str_to_num ( szVotes );

			if ( g_CurrentVotes > g_LastStoredVotes )
			{
				cs_set_user_money ( id, 16000 );
				client_print ( id, print_chat, "You voted the server!" );
			}
		}
	}
}
i've tried, no good result.
__________________
LondoN is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 12-27-2018 , 08:43   Re: Socket help
Reply With Quote #12

you dont get this printed?
Code:
server_print ( "Votes right now: %d", str_to_num ( szVotes ) );
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 12-27-2018 , 09:49   Re: Socket help
Reply With Quote #13

len is assignet to a value it's never used, compiler says.
__________________
LondoN is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 12-27-2018 , 14:37   Re: Socket help
Reply With Quote #14

Can't test fully because the site only accepts IP addresses from Romania.

But...

Just remove "len", you obviously don't use it.



You have multiple functions with the same name, you need to change the name of one of them.
Code:
public CheckAgainVotes ( id ) {     HTTPX_Download ( "www.csservers.ro/evidenta/zm.darkland.ro", _, _, "CheckAgainVotesResult" ); } public CheckAgainVotesResult ( id ) // ...



I also had to change
Code:
show_motd ( id, "www.csservers.ro/voteaza/zm.darkland.ro" );
->
Code:
show_motd ( id, "http://www.csservers.ro/voteaza/zm.darkland.ro" );
Otherwise it would just open a window with the the text.
__________________

Last edited by Black Rose; 12-27-2018 at 14:40.
Black Rose is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-27-2018 , 15:13   Re: Socket help
Reply With Quote #15

May be worthwhile to use len, just in case the page is retrieved in multiple chunks. Would need to make the buffer & len variables static, or better as global so you can reset len to 0 when a new request is made.
PHP Code:
while ( ( iPacketLen HTTPX_GetData Bufferlen ], charsmax Buffer ) - len ) ) )
{
    
len += iPacketLen
__________________

Last edited by Bugsy; 12-27-2018 at 15:18.
Bugsy is offline
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 12-27-2018 , 16:05   Re: Socket help
Reply With Quote #16

Code:
#include < amxmodx >
#include < amxmisc >
#include < cstrike >
#include < regex >
#include < httpx >

new g_CurrentVotes, g_LastStoredVotes;

public plugin_init ( )
{
	register_plugin ( "Vote and get bonus", "2.0", "LondoN eXtream" );
	register_clcmd ( "say /vote", "Func_VoteServer" );
	HTTPX_Download ( "www.csservers.ro/evidenta/zm.darkland.ro", _, _, "StoreVotes" );
}

public Func_VoteServer ( id )
{
	HTTPX_Download ( "www.csservers.ro/evidenta/zm.darkland.ro", _, _, "StoreVotes" );

	show_motd ( id, "www.csservers.ro/voteaza/zm.darkland.ro" );

	set_task ( 10.0, "CheckAgainVotes", id );
}

public StoreVotes ( id )
{
	new Buffer [ 1024 ];
	new szError [ 50 ], iNum;
	new Regex: FindVote;

	while ( HTTPX_GetData ( Buffer, charsmax ( Buffer ) ) )
	{
		FindVote = regex_match ( Buffer, "voturi-azi^">(.*?)</a>", iNum, szError, charsmax ( szError ) );

		if ( FindVote )
		{
			new szVotes [ 16 ];
			regex_substr ( FindVote, 1, szVotes, charsmax ( szVotes ) );
			server_print ( "Votes right now: %d", str_to_num ( szVotes ) );
			g_LastStoredVotes = str_to_num ( szVotes );
			regex_free ( FindVote );
		}
	}
}

public CheckAgainVotes ( id )
{
	HTTPX_Download ( "www.csservers.ro/evidenta/zm.darkland.ro", _, _, "CheckAgainVotes123" );
}

public CheckAgainVotes123 ( id )
{
	new Buffer [ 1024 ];
	new szError [ 50 ], iNum;
	new Regex: NewVote;

	while ( HTTPX_GetData ( Buffer, charsmax ( Buffer ) ) ) 
	{
		NewVote = regex_match ( Buffer, "voturi-azi^">(.*?)</a>", iNum, szError, charsmax ( szError ) );

		if ( NewVote )
		{
			new szVotes [ 16 ];
			regex_substr ( NewVote, 1, szVotes, charsmax ( szVotes ) );
			server_print ( "Votes now: %d", str_to_num ( szVotes ) );

			g_CurrentVotes = str_to_num ( szVotes );

			if ( g_CurrentVotes > g_LastStoredVotes )
			{
				cs_set_user_money ( id, 16000 );
				client_print ( id, print_chat, "You voted the server!" );
			}

			regex_free ( NewVote );
		}
	}
}
I've tried that..no print to the server.
__________________
LondoN is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 12-30-2018 , 15:41   Re: Socket help
Reply With Quote #17

Run it once.
Post the complete output. (The file in your server folder called "YOURPLUGINNAME_debug.log")
Also, please post the debug .htm files called "DEBUG1.htm" and "DEBUG2.htm" from the same folder.

Also, note the highlighted changes. You had the download id and the player id mixed up.

Spoiler
__________________

Last edited by Black Rose; 12-30-2018 at 16:02.
Black Rose is offline
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 12-30-2018 , 16:04   Re: Socket help
Reply With Quote #18

Thank's a lot BlackRose, now it's working fine!


L 12/30/2018 - 23:04:04: -------- Mapchange to de_dust2 --------
Votes right now: 3
__________________
LondoN is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 12-30-2018 , 20:42   Re: Socket help
Reply With Quote #19

Quote:
Originally Posted by LondoN View Post
Thank's a lot BlackRose, now it's working fine!


L 12/30/2018 - 23:04:04: -------- Mapchange to de_dust2 --------
Votes right now: 3
I didn't change anything that would affect the outcome of the print, only the receiving of money.
But hey, great.
__________________
Black Rose is offline
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 12-31-2018 , 04:54   Re: Socket help
Reply With Quote #20

Yes, i see, the money give doesn't work, but i resolve this with creating global PlayerID and when func_vote called PlayerID = id then check votes.
__________________
LondoN 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 23:34.


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