Openkore.com

OpenKore Forums
It is currently 24 Jan 2018, 03:39

All times are UTC - 5 hours [ DST ]





Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Check GM status from server's site [SGCP]
PostPosted: 11 Feb 2016, 23:05 
Offline
Noob
Noob

Joined: 11 Feb 2016, 22:49
Posts: 2
Hi, I have an idea on checking the GM status from server's site for a private servers using Starsgames Control Panel

So here's the idea, the openkore check from Server's site for every minutes or second, precisely from http://www.thePrivateServerDomain.com/index.php?showuser=*****

I have figured out that SGCP use MD5 HASH to encrypt their account ID.
In my case the GM account ID is 2000000 which make the website string is
http://www.thePrivateServerDomain.com/index.php?showuser=805f743866591cb5654b0462e0f5f304

The plugins may be coded to read the server's page source, which is to look for
Code:
                           <TD>1</TD>
                              <TD>Game Master</TD>
                              <TD>High Priest</TD>
                              <TD>98</TD>
                              <TD>70</TD>
                              <TD><font class="status_on">Online</font></TD>

If the page source say its Online, the bot will DC and keep checking the status for every minutes or second, when the GM status is offline (<font class="status_off">Offline</font>), the bot will reconnect again.

That's all, now I'm curious, is this possible? Honestly I have ZERO knowledge about Perl and Openkore's Plugin. But if this thing is possible, maybe I'll try to do so and share my progress here. Thanks!


Top
 Profile  
 
 Post subject: Re: Check GM status from server's site [SGCP]
PostPosted: 25 Feb 2016, 07:43 
Offline
Human
Human
User avatar

Joined: 29 Nov 2013, 21:50
Posts: 28
Location: Brazil
Quote:
That's all, now I'm curious, is this possible? Honestly I have ZERO knowledge about Perl and Openkore's Plugin. But if this thing is possible, maybe I'll try to do so and share my progress here. Thanks!


Yes, it is. It's not even that hard. If it doesn't require login to access that page, LWP::Simple::get() and a little regex is enough. As for the plugin workflow you could have a subroutine to check the website and use it before actually logging in the map server and then periodically when you're logged in the map server.

A sketch (I didn't actually test it):

Code:
package checkWebsiteForGM;

use strict;
use warnings;
use LWP::Simple;
use Misc qw(relog);
use Log qw(warning);

Plugins::register('checkWebsiteForGM','the name is pretty self explanatory', \&onUnload);

my $hooks = Plugins::addHooks(
   ['charSelectScreen', \&charScreenCheck],
   ['AI_pre',\&aiPreCheck]
);

my $timeout = time();
my $wait_seconds = 30;
my $url = "HERE GOES THE PAGE WHERE THE STATUS IS";
my $pattern = "HERE GOES THE PATTERN IN THE SOURCE CODE OF THE PAGE WE'RE LOOKING FOR";

sub onUnload {
   Plugins::delHooks($hooks);
}

sub charScreenCheck {
   my (undef, $args) = @_;
   $args->{return} = 1 if (check()); # Leave it to timeout on select screen
}

sub aiPreCheck {
   return if (time() - $timeout < $wait_seconds); # Check every <$wait_seconds> seconds
   relog() if (check());
}

sub check {
   my $response = LWP::Simple::get($url);

   if ($response =~ /$pattern/) {
      warning "Yikes... the GM is online. Run!\n";
      return 1;
   }

   return 0;
}

1;


It gets tricky if you don't know Perl though... :roll:

_________________
I'm watching my TV or is it watching me?


Top
 Profile  
 
 Post subject: Re: Check GM status from server's site [SGCP]
PostPosted: 10 Mar 2017, 02:30 
Offline
Noob
Noob

Joined: 11 Feb 2016, 22:49
Posts: 2
otaku wrote:
Quote:
That's all, now I'm curious, is this possible? Honestly I have ZERO knowledge about Perl and Openkore's Plugin. But if this thing is possible, maybe I'll try to do so and share my progress here. Thanks!


Yes, it is. It's not even that hard. If it doesn't require login to access that page, LWP::Simple::get() and a little regex is enough. As for the plugin workflow you could have a subroutine to check the website and use it before actually logging in the map server and then periodically when you're logged in the map server.

A sketch (I didn't actually test it):

Code:
package checkWebsiteForGM;

use strict;
use warnings;
use LWP::Simple;
use Misc qw(relog);
use Log qw(warning);

Plugins::register('checkWebsiteForGM','the name is pretty self explanatory', \&onUnload);

my $hooks = Plugins::addHooks(
   ['charSelectScreen', \&charScreenCheck],
   ['AI_pre',\&aiPreCheck]
);

my $timeout = time();
my $wait_seconds = 30;
my $url = "HERE GOES THE PAGE WHERE THE STATUS IS";
my $pattern = "HERE GOES THE PATTERN IN THE SOURCE CODE OF THE PAGE WE'RE LOOKING FOR";

sub onUnload {
   Plugins::delHooks($hooks);
}

sub charScreenCheck {
   my (undef, $args) = @_;
   $args->{return} = 1 if (check()); # Leave it to timeout on select screen
}

sub aiPreCheck {
   return if (time() - $timeout < $wait_seconds); # Check every <$wait_seconds> seconds
   relog() if (check());
}

sub check {
   my $response = LWP::Simple::get($url);

   if ($response =~ /$pattern/) {
      warning "Yikes... the GM is online. Run!\n";
      return 1;
   }

   return 0;
}

1;


It gets tricky if you don't know Perl though... :roll:


Since I'm not familiar with Perl, so I tried using Macro instead, and combine it with the sub you given..
Code:
macro gm {
$gmStats = gmCheck ()
if ($gmStats == 1) goto Online
goto Offline
:Online
log Online
goto End

:Offline
log Offline

:End
release all
}

sub gmCheck {
use strict;
use warnings;
use LWP::Simple;
my $url = 'http://www.google.com';
my $pattern = 'Hello';
my $response = get($url);

   if ($response =~ /$pattern/) {
      return 1;
   }

   return 0;
}


The thing is, I can't get the LWP working, I don't know its because I'm running it from macros or I don't install the modules correctly, I use the strawberry perl and install LWP, reloading the macros, and the openkore responded
Can't locate NET.pm in @INC (@INC contains: plugins/macro src src/deps
So I download the LWP libraries from CPAN and put what inside the /lib folder (/LWP, and LWP.pm) to the /src/deps.
This time the Can't locate NET.pm in @INC (@INC contains: plugins/macro src src/deps gone, but whenever I try to call the sub by using "macro gm" it responded [macro] gm error: error in 0: gmCheck () failed

Am I missing something? Or the LWP sub cannot run via macros?

o_O I just've realized I posted this a (almost) year ago


Top
 Profile  
 
 Post subject: Re: Check GM status from server's site [SGCP]
PostPosted: 10 Mar 2017, 06:20 
Offline
Developers
Developers

Joined: 01 Nov 2008, 15:31
Posts: 361
duno what your link for but u need this file http://cpansearch.perl.org/src/OALDERS/ ... /Simple.pm

like <your_bot>/src/deps/LWP/Simple.pm

_________________
Please use pin function for uploading your file contents!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group