Check GM status from server's site [SGCP]

Other plugins for extending OpenKore's functionality. This forum is only for posting new plugins and commenting on existing plugins. For support, use the Support forum.

Moderator: Moderators

Message
Author
Arsenicc
Noob
Noob
Posts: 2
Joined: 11 Feb 2016, 22:49
Noob?: No

Check GM status from server's site [SGCP]

#1 Post by Arsenicc »

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: Select all

									<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!

otaku
Human
Human
Posts: 28
Joined: 29 Nov 2013, 21:50
Noob?: No
Location: Brazil
Contact:

Re: Check GM status from server's site [SGCP]

#2 Post by otaku »

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: Select all

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?

Arsenicc
Noob
Noob
Posts: 2
Joined: 11 Feb 2016, 22:49
Noob?: No

Re: Check GM status from server's site [SGCP]

#3 Post by Arsenicc »

otaku wrote:
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: Select all

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: Select all

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

Mortimal
Developers
Developers
Posts: 389
Joined: 01 Nov 2008, 15:31
Noob?: No

Re: Check GM status from server's site [SGCP]

#4 Post by Mortimal »

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!

Post Reply