Raised This Month: $ Target: $400
 0% 

Reading data


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Turle
Junior Member
Join Date: Aug 2013
Old 08-13-2013 , 07:12   Re: Reading data
Reply With Quote #1

Wow, it works great, you're amazing

If you could add a few more features, it'll be perfect.
  • The info should be shown when you type /myinfo in the chat - and if you can show it trough hud [ a menu ] or console [tried with console_print(id, "%s %s", Info[i][Prefix], Results[i]); but wasn't working]
  • Replace in the link the name of the player.
    Example: HTTP_DownloadFile("http://www.gametracker.com/player/%s/78.110.163.197:27015/",name, "result.txt");

Thanks again very much !

Last edited by Turle; 08-13-2013 at 07:12.
Turle is offline
Turle
Junior Member
Join Date: Aug 2013
Old 08-13-2013 , 08:37   Re: Reading data
Reply With Quote #2

Quote:
Originally Posted by Turle View Post
Wow, it works great, you're amazing

If you could add a few more features, it'll be perfect.
  • The info should be shown when you type /myinfo in the chat - and if you can show it trough hud [ a menu ] or console [tried with console_print(id, "%s %s", Info[i][Prefix], Results[i]); but wasn't working]
  • Replace in the link the name of the player.
    Example: HTTP_DownloadFile("http://www.gametracker.com/player/%s/78.110.163.197:27015/",name, "result.txt");

Thanks again very much !
Could you do it like this please ? I'll be very thankful.
Turle is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 08-13-2013 , 07:47   Re: Reading data
Reply With Quote #3

StringId was a bad name choice by me. It should be GroupNumber or something.
It tells which matching group of regex that should be returned.

For example in "\s+(\d+)", () defines a group. I do want the digits that has a whitespace before it but I don't want the whitespace included in the result, only the actual group. Therefor I return group 1 (StringId 1). If I remove the whitespace check I could end up with numbers that are part of the HTML code. Like <div id=test1>

Group 0: \s+(\d+)
Returns:
0

Group 1: (\d+)
Returns: 0

I could've used lookbehind and lookahead instead, but I didn't realize that when I created this example.
__________________

Last edited by Black Rose; 08-13-2013 at 10:32.
Black Rose is offline
red_bull2oo6
Senior Member
Join Date: Mar 2012
Location: Braila, Romania
Old 08-13-2013 , 09:38   Re: Reading data
Reply With Quote #4

i got it.. but also the ScorePerMinute regex should be:

PHP Code:
"Score per Minute:",  "\n*\s*(\d+\.?\d*)\s*\n*" 
instead of
PHP Code:
"Score per Minute:",  "\n*\s*(\d+.?\d*)\s*\n*" 
with \. ( i tested it with exolent's regex test plugin ) because it'll stop at Score:

thanks again, i love you!
red_bull2oo6 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 08-13-2013 , 10:10   Re: Reading data
Reply With Quote #5

Quote:
Originally Posted by red_bull2oo6 View Post
i got it.. but also the ScorePerMinute regex should be:

PHP Code:
"Score per Minute:",  "\n*\s*(\d+\.?\d*)\s*\n*" 
instead of
PHP Code:
"Score per Minute:",  "\n*\s*(\d+.?\d*)\s*\n*" 
with \. ( i tested it with exolent's regex test plugin ) because it'll stop at Score:

thanks again, i love you!
You're absolutely right. I updated it.
It should also be "\s+(\d+\.?\d*)" instead of "\n*\s*(\d+\.?\d*)\s*\n*" since all the "*" could match part of the html if it were to change in the future.

But I updated it using positive lookbehind instead.
__________________

Last edited by Black Rose; 08-13-2013 at 10:38.
Black Rose is offline
Turle
Junior Member
Join Date: Aug 2013
Old 08-13-2013 , 10:50   Re: Reading data
Reply With Quote #6

Quote:
Originally Posted by Black Rose View Post


But I updated it using positive lookbehind instead.
Great

Could you make these modifications too ?
PHP Code:
If you could add a few more featuresit'll be perfect.
The info should be shown when you type /myinfo in the chat - and if you can show it trough hud [ a menu  ] or console [tried with console_print(id, "%s %s", Info[i][Prefix], Results[i]); but wasn'
t working]
Replace in the link the name of the player.
ExampleHTTP_DownloadFile("http://www.gametracker.com/player/%s/78.110.163.197:27015/",name"result.txt");

Thanks again very much 
Turle is offline
red_bull2oo6
Senior Member
Join Date: Mar 2012
Location: Braila, Romania
Old 08-13-2013 , 11:00   Re: Reading data
Reply With Quote #7

do you know how can i fix this:

Code:
First Seen: Jun 27, 2013
Last Seen: Today 10:00 AM
Score: 
                39
                
Minutes Played: 
                188
                
Score per Minute: 
                0.2
                
Rank on Server: #909 out of 15054
i took it directly with sockets ( from receive public ).

it's not an important fix.. because i`ll str_to_num( score and minutes ) and floatstr( score per minute ) but i`d like to know how ( if possible )
red_bull2oo6 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 08-13-2013 , 11:32   Re: Reading data
Reply With Quote #8

Quote:
Originally Posted by red_bull2oo6 View Post
do you know how can i fix this:

Code:
First Seen: Jun 27, 2013
Last Seen: Today 10:00 AM
Score: 
                39
                
Minutes Played: 
                188
                
Score per Minute: 
                0.2
                
Rank on Server: #909 out of 15054
i took it directly with sockets ( from receive public ).

it's not an important fix.. because i`ll str_to_num( score and minutes ) and floatstr( score per minute ) but i`d like to know how ( if possible )
It's because you use the first regex match when you should use the second.
I explained how this works in post #12.

You can also use the new regexes I made since the old ones were pretty bad.

Quote:
Originally Posted by Turle View Post
Great

Could you make these modifications too ?
PHP Code:
If you could add a few more featuresit'll be perfect.
The info should be shown when you type /myinfo in the chat - and if you can show it trough hud [ a menu  ] or console [tried with console_print(id, "%s %s", Info[i][Prefix], Results[i]); but wasn'
t working]
Replace in the link the name of the player.
ExampleHTTP_DownloadFile("http://www.gametracker.com/player/%s/78.110.163.197:27015/",name"result.txt");

Thanks again very much 
Relax dude. I've been working on it as I was answering in this thread.
Here's the code, you'll have to format the hudmessage yourself.
I threw in a couple of comments to make it easier to edit to your liking.
Code:
#include <amxmodx> #include <fakemeta> #include <regex> #include <http> #define SERVER_IP   "78.110.163.197:27015" new g_DownloadId[33]; new g_MaxClients; enum patternsEnum {     Prefix[32],     Pattern[128] } new g_Info[][patternsEnum] = {     { "First Seen:",        "\w{3} [0-3][0-9], [12][019][0-9][0-9]" },     { "Last Seen:",         "Online Now|(((Yester|To)day)|(\w{3} [0-3][0-9], [12][019][0-9][0-9])) (1[0-2]|[0-9]):[0-5]\d [A|P]M" },     { "Score:",             "(?<=\s)\d+" },     { "Minutes Played:",    "(?<=\s)\d+" },     { "Score per Minute:""(?<=\s)\d+\.?\d?" },     { "Rank on Server:",    "#\d+ out of \d+" } }; public plugin_init() {     register_plugin("Test Plugin 9", "", "");     register_clcmd("say /myinfo", "cmd_MyInfo");         g_MaxClients = global_get(glb_maxClients); // Get maximum possible ammount of players } public cmd_MyInfo(id, level, cid) {     if ( g_DownloadId[id] ) // Spam protection.         return;         new name[40];     new url[128];         get_user_name(id, name, charsmax(name)); // Retrieve user name.         formatex(url, charsmax(url), "http://www.gametracker.com/player/%s/%s/", name, SERVER_IP); // Format the url.     formatex(name[strlen(name)], charsmax(name) - strlen(name), ".txt"); // We'll reuse the name variable to store the filename since we're done with the name.         g_DownloadId[id] = HTTP_DownloadFile(url, name); } public client_disconnect(id) {     HTTP_AbortTransfer(g_DownloadId[id]); // No need to download the file if the user isn't interested.     g_DownloadId[id] = 0; // We have to reset the spam protection, otherwise a joining player might be blocked for no reason. } public HTTP_Download(const szFile[] , iDownloadID , iBytesRecv , iFileSize , bool:TransferComplete) {         if ( ! TransferComplete )         return; // SHUT UP!         new id;         for ( new i = 0 ; i <= g_MaxClients ; i++ ) {         if ( g_DownloadId[i] == iDownloadID ) // Find the person who's requested this download.             id = i; // Store it.     }         g_DownloadId[id] = 0; // Reset the spam protection so people can use the command more than once.         if ( ! is_user_connected(id) ) // Just in case.         return;         new buffer[1024], i, bool: searching; // Variables of the file reading.     new result[128], num; // Variables of RegEx.     new message[1024], len; // Variables of the hudmessage.         new hFile = fopen(szFile, "r"); // Open the file.         if ( ! hFile ) // Just in case.         return;         while ( ! feof(hFile) && i < sizeof g_Info ) {         fgets(hFile, buffer, charsmax(buffer)); // Read contents of result.                 if ( ! searching && contain(buffer, g_Info[i][Prefix]) != -1 ) // Does it contain the prefix?             searching = true; // Because then we will start the regex search.                 if ( searching ) { // To avoid false positives since this is a multiple line file.                         new Regex:hRegex = regex_match(buffer, g_Info[i][Pattern], num, result, 127); // Search for the pattern in the current line.                         if ( hRegex <= REGEX_PATTERN_FAIL )                 server_print("Regex error: %d, %s", num, result); // WROOOOONG!                         if ( hRegex >= REGEX_OK ) { // Do we have a match?                 regex_substr(hRegex, 0, result, charsmax(result)); // Read the first match of the regex.                 len += formatex(message[len], charsmax(message) - len, "%s^t%s^n", g_Info[i][Prefix], result); // Add the prefix and result to the hudmessage.                 regex_free(hRegex); // We don't want leaked memory and open handles.                 searching = false; // To avoid false positives.                 i++; // NEXT!             }         }     }         fclose(hFile); // We don't want leaked memory and open handles.         set_hudmessage(_,_,_,_,_,_,_,15.0,_,_,-1);     show_hudmessage(id, message);         set_task(3.0, "DeleteFile", id + 1253862, szFile, strlen(szFile)); // It doesn't seem to work if you do it instantly for some reason. } public DeleteFile(const szFile[]) {     delete_file(szFile); }
__________________

Last edited by Black Rose; 08-13-2013 at 11:51.
Black Rose is offline
Turle
Junior Member
Join Date: Aug 2013
Old 08-13-2013 , 20:10   Re: Reading data
Reply With Quote #9

Quote:
Originally Posted by Black Rose View Post
Code:
#include <amxmodx> #include <fakemeta> #include <regex> #include <http> #define SERVER_IP   "78.110.163.197:27015" new g_DownloadId[33]; new g_MaxClients; enum patternsEnum {     Prefix[32],     Pattern[128] } new g_Info[][patternsEnum] = {     { "First Seen:",        "\w{3} [0-3][0-9], [12][019][0-9][0-9]" },     { "Last Seen:",         "Online Now|(((Yester|To)day)|(\w{3} [0-3][0-9], [12][019][0-9][0-9])) (1[0-2]|[0-9]):[0-5]\d [A|P]M" },     { "Score:",             "(?<=\s)\d+" },     { "Minutes Played:",    "(?<=\s)\d+" },     { "Score per Minute:""(?<=\s)\d+\.?\d?" },     { "Rank on Server:",    "#\d+ out of \d+" } }; public plugin_init() {     register_plugin("Test Plugin 9", "", "");     register_clcmd("say /myinfo", "cmd_MyInfo");         g_MaxClients = global_get(glb_maxClients); // Get maximum possible ammount of players } public cmd_MyInfo(id, level, cid) {     if ( g_DownloadId[id] ) // Spam protection.         return;         new name[40];     new url[128];         get_user_name(id, name, charsmax(name)); // Retrieve user name.         formatex(url, charsmax(url), "http://www.gametracker.com/player/%s/%s/", name, SERVER_IP); // Format the url.     formatex(name[strlen(name)], charsmax(name) - strlen(name), ".txt"); // We'll reuse the name variable to store the filename since we're done with the name.         g_DownloadId[id] = HTTP_DownloadFile(url, name); } public client_disconnect(id) {     HTTP_AbortTransfer(g_DownloadId[id]); // No need to download the file if the user isn't interested.     g_DownloadId[id] = 0; // We have to reset the spam protection, otherwise a joining player might be blocked for no reason. } public HTTP_Download(const szFile[] , iDownloadID , iBytesRecv , iFileSize , bool:TransferComplete) {         if ( ! TransferComplete )         return; // SHUT UP!         new id;         for ( new i = 0 ; i <= g_MaxClients ; i++ ) {         if ( g_DownloadId[i] == iDownloadID ) // Find the person who's requested this download.             id = i; // Store it.     }         g_DownloadId[id] = 0; // Reset the spam protection so people can use the command more than once.         if ( ! is_user_connected(id) ) // Just in case.         return;         new buffer[1024], i, bool: searching; // Variables of the file reading.     new result[128], num; // Variables of RegEx.     new message[1024], len; // Variables of the hudmessage.         new hFile = fopen(szFile, "r"); // Open the file.         if ( ! hFile ) // Just in case.         return;         while ( ! feof(hFile) && i < sizeof g_Info ) {         fgets(hFile, buffer, charsmax(buffer)); // Read contents of result.                 if ( ! searching && contain(buffer, g_Info[i][Prefix]) != -1 ) // Does it contain the prefix?             searching = true; // Because then we will start the regex search.                 if ( searching ) { // To avoid false positives since this is a multiple line file.                         new Regex:hRegex = regex_match(buffer, g_Info[i][Pattern], num, result, 127); // Search for the pattern in the current line.                         if ( hRegex <= REGEX_PATTERN_FAIL )                 server_print("Regex error: %d, %s", num, result); // WROOOOONG!                         if ( hRegex >= REGEX_OK ) { // Do we have a match?                 regex_substr(hRegex, 0, result, charsmax(result)); // Read the first match of the regex.                 len += formatex(message[len], charsmax(message) - len, "%s^t%s^n", g_Info[i][Prefix], result); // Add the prefix and result to the hudmessage.                 regex_free(hRegex); // We don't want leaked memory and open handles.                 searching = false; // To avoid false positives.                 i++; // NEXT!             }         }     }         fclose(hFile); // We don't want leaked memory and open handles.         set_hudmessage(_,_,_,_,_,_,_,15.0,_,_,-1);     show_hudmessage(id, message);         set_task(3.0, "DeleteFile", id + 1253862, szFile, strlen(szFile)); // It doesn't seem to work if you do it instantly for some reason. } public DeleteFile(const szFile[]) {     delete_file(szFile); }
Wow, it looks great Thanks A LOT !

Unfortunately, it doesn't seem to be working, when I type /myinfo, nothing appears.
Btw, I set the hud like this:
set_hudmessage(20, 232, 20, 0.0, 0.14, 0, 6.0, 12.0)

With channel -1 it gave me error [tag mismatch ]

Thanks again!
Turle is offline
KinderBueno
Junior Member
Join Date: Sep 2011
Old 08-21-2013 , 15:18   Re: Reading data
Reply With Quote #10

Quote:
Originally Posted by Black Rose View Post
It's because you use the first regex match when you should use the second.
I explained how this works in post #12.

You can also use the new regexes I made since the old ones were pretty bad.



Relax dude. I've been working on it as I was answering in this thread.
Here's the code, you'll have to format the hudmessage yourself.
I threw in a couple of comments to make it easier to edit to your liking.
Code:
#include <amxmodx> #include <fakemeta> #include <regex> #include <http> #define SERVER_IP   "78.110.163.197:27015" new g_DownloadId[33]; new g_MaxClients; enum patternsEnum {     Prefix[32],     Pattern[128] } new g_Info[][patternsEnum] = {     { "First Seen:",        "\w{3} [0-3][0-9], [12][019][0-9][0-9]" },     { "Last Seen:",         "Online Now|(((Yester|To)day)|(\w{3} [0-3][0-9], [12][019][0-9][0-9])) (1[0-2]|[0-9]):[0-5]\d [A|P]M" },     { "Score:",             "(?<=\s)\d+" },     { "Minutes Played:",    "(?<=\s)\d+" },     { "Score per Minute:""(?<=\s)\d+\.?\d?" },     { "Rank on Server:",    "#\d+ out of \d+" } }; public plugin_init() {     register_plugin("Test Plugin 9", "", "");     register_clcmd("say /myinfo", "cmd_MyInfo");         g_MaxClients = global_get(glb_maxClients); // Get maximum possible ammount of players } public cmd_MyInfo(id, level, cid) {     if ( g_DownloadId[id] ) // Spam protection.         return;         new name[40];     new url[128];         get_user_name(id, name, charsmax(name)); // Retrieve user name.         formatex(url, charsmax(url), "http://www.gametracker.com/player/%s/%s/", name, SERVER_IP); // Format the url.     formatex(name[strlen(name)], charsmax(name) - strlen(name), ".txt"); // We'll reuse the name variable to store the filename since we're done with the name.         g_DownloadId[id] = HTTP_DownloadFile(url, name); } public client_disconnect(id) {     HTTP_AbortTransfer(g_DownloadId[id]); // No need to download the file if the user isn't interested.     g_DownloadId[id] = 0; // We have to reset the spam protection, otherwise a joining player might be blocked for no reason. } public HTTP_Download(const szFile[] , iDownloadID , iBytesRecv , iFileSize , bool:TransferComplete) {         if ( ! TransferComplete )         return; // SHUT UP!         new id;         for ( new i = 0 ; i <= g_MaxClients ; i++ ) {         if ( g_DownloadId[i] == iDownloadID ) // Find the person who's requested this download.             id = i; // Store it.     }         g_DownloadId[id] = 0; // Reset the spam protection so people can use the command more than once.         if ( ! is_user_connected(id) ) // Just in case.         return;         new buffer[1024], i, bool: searching; // Variables of the file reading.     new result[128], num; // Variables of RegEx.     new message[1024], len; // Variables of the hudmessage.         new hFile = fopen(szFile, "r"); // Open the file.         if ( ! hFile ) // Just in case.         return;         while ( ! feof(hFile) && i < sizeof g_Info ) {         fgets(hFile, buffer, charsmax(buffer)); // Read contents of result.                 if ( ! searching && contain(buffer, g_Info[i][Prefix]) != -1 ) // Does it contain the prefix?             searching = true; // Because then we will start the regex search.                 if ( searching ) { // To avoid false positives since this is a multiple line file.                         new Regex:hRegex = regex_match(buffer, g_Info[i][Pattern], num, result, 127); // Search for the pattern in the current line.                         if ( hRegex <= REGEX_PATTERN_FAIL )                 server_print("Regex error: %d, %s", num, result); // WROOOOONG!                         if ( hRegex >= REGEX_OK ) { // Do we have a match?                 regex_substr(hRegex, 0, result, charsmax(result)); // Read the first match of the regex.                 len += formatex(message[len], charsmax(message) - len, "%s^t%s^n", g_Info[i][Prefix], result); // Add the prefix and result to the hudmessage.                 regex_free(hRegex); // We don't want leaked memory and open handles.                 searching = false; // To avoid false positives.                 i++; // NEXT!             }         }     }         fclose(hFile); // We don't want leaked memory and open handles.         set_hudmessage(_,_,_,_,_,_,_,15.0,_,_,-1);     show_hudmessage(id, message);         set_task(3.0, "DeleteFile", id + 1253862, szFile, strlen(szFile)); // It doesn't seem to work if you do it instantly for some reason. } public DeleteFile(const szFile[]) {     delete_file(szFile); }




Ok, i tryed this plugin but ... When i type /myinfo i dont have no results ...


If anyone can help i will be glad, i want this result




Last edited by KinderBueno; 08-21-2013 at 15:19.
KinderBueno is offline
Send a message via Yahoo to KinderBueno
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 15:56.


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