Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # - Plugin listAllPlayers by KeplerBR (thanks to kLabMouse)
- #
- # Topic about the plugin (recommended to read)
- # * http://forums.openkore.com/viewtopic.php?f=34&t=18879&p=67679#p67679 (in English)
- # * http://forum.xkore.com.br/index.php?/topic/64-plugin-listallplayers/page__pid__326#entry326 (in Brazilian Portuguese)
- package listAllPlayers;
- use strict;
- use warnings;
- use Plugins;
- use Log qw(message warning);
- use Settings;
- use Globals;
- use Utils;
- # Register Plugin and Hooks
- Plugins::register("listAllPlayers", "Generate list of all server chars", \&on_unload);
- my $hooks = Plugins::addHooks(
- ['packet/character_name', \&list_player_id_name],
- ['packet/received_sync', \&send_packet],
- ['AI_pre/manual', \&gambiarra]
- );
- # On Unload code
- sub on_unload {
- Plugins::delHook("packet/character_name", $hooks);
- Plugins::delHook("AI_pre/received_sync", $hooks);
- }
- # Global variables
- my $idLoop = 150000; # In which ID will start the loop
- my $limit = 10; # Limit how often will send the package by sync
- my $limitEnvios = 30; # Quantidade de pacotes que deve enviar e não receber resposta para considerar que travou e relogar
- my $envios = 0;
- # Prepare and send packet asking the nick of character
- sub send_packet {
- warning "Starting sending the packet \n";
- for (my $i = 0; $i < $limit; $i++) {
- $idLoop++; $envios++;
- # Send packet
- my $idSend = $idLoop;
- $idSend = pack("V", $idSend);
- $idSend = getHex($idSend);
- message "Send ID $idSend ($idLoop)\n";
- $messageSender->sendRaw("68 03 $idSend");
- }
- warning "Completing the packet sent \n";
- }
- # Add the result to text file
- sub list_player_id_name {
- my $hookname = shift;
- my $args = shift;
- # Defining and organizing variables
- my $id = unpack("V1", $args->{ID});
- my $idHex = getHex($args->{ID});
- my $nick = $args->{name};
- # Write
- warning "New player on file: $id - $nick \n";
- open my $fileTxt,">>". 'listAllPlayers.txt' or die "Cannot create file listAllPlayers.txt: $!";
- print $fileTxt "* $idHex - $id - $nick\n";
- close $fileTxt;
- # Finalizar
- $envios = 0;
- }
- # Gambiarra: caso o valor de $envios seja muito alto, quer dizer que enviou diversos pacotes e não recebeu resposta,
- # logo, é provável que travou
- sub gambiarra {
- if ($envios >= $limitEnvios) {
- # Avisar que travou no arquivo de texto
- open my $fileTxt,">>". 'listAllPlayers.txt' or die "Cannot create file listAllPlayers.txt: $!";
- print $fileTxt "***********************\nTravou aqui\n***********************\n";
- close $fileTxt;
- # Resetar e atualizar as variávies
- $idLoop = $idLoop - $envios - 15;
- $limitEnvios += $limit;
- $envios = 0;
- # Relogar em 300 segundos
- Commands::run("relog 300");
- }
- }
- 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement