Advertisement
KeplerBR

Plugin listAllPlayers 2v

Jan 8th, 2013
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.77 KB | None | 0 0
  1. # - Plugin listAllPlayers by KeplerBR (thanks to kLabMouse)
  2. #
  3. # Topic about the plugin (recommended to read)
  4. #  * http://forums.openkore.com/viewtopic.php?f=34&t=18879&p=67679#p67679 (in English)
  5. #  * http://forum.xkore.com.br/index.php?/topic/64-plugin-listallplayers/page__pid__326#entry326 (in Brazilian Portuguese)
  6.  
  7. package listAllPlayers;
  8.     use strict;
  9.     use warnings;
  10.     use Plugins;
  11.     use Log qw(message warning);
  12.     use Settings;
  13.     use Globals;
  14.     use Utils;
  15.  
  16.     # Register Plugin and Hooks
  17.     Plugins::register("listAllPlayers", "Generate list of all server chars", \&on_unload);
  18.         my $hooks = Plugins::addHooks(
  19.         ['packet/character_name', \&list_player_id_name],
  20.         ['packet/received_sync',  \&send_packet],
  21.         ['AI_pre/manual', \&gambiarra]
  22.         );
  23.  
  24.  
  25.     # On Unload code
  26.     sub on_unload {
  27.         Plugins::delHook("packet/character_name", $hooks);
  28.         Plugins::delHook("AI_pre/received_sync", $hooks);
  29.     }
  30.  
  31.     # Global variables
  32.     my $idLoop = 150000;    # In which ID will start the loop
  33.     my $limit = 10;         # Limit how often will send the package by sync
  34.     my $limitEnvios = 30;   # Quantidade de pacotes que deve enviar e não receber resposta para considerar que travou e relogar
  35.     my $envios = 0;
  36.  
  37.     # Prepare and send packet asking the nick of character
  38.     sub send_packet {
  39.     warning "Starting sending the packet \n";
  40.  
  41.         for (my $i = 0; $i < $limit; $i++) {
  42.             $idLoop++; $envios++;
  43.  
  44.             # Send packet
  45.             my $idSend = $idLoop;
  46.             $idSend = pack("V", $idSend);
  47.             $idSend = getHex($idSend);
  48.             message "Send ID $idSend ($idLoop)\n";
  49.            
  50.             $messageSender->sendRaw("68 03 $idSend");
  51.         }
  52.  
  53.     warning "Completing the packet sent \n";
  54.     }
  55.  
  56.     # Add the result to text file
  57.     sub list_player_id_name {
  58.         my $hookname = shift;
  59.         my $args = shift;
  60.  
  61.         # Defining and organizing variables
  62.         my $id = unpack("V1", $args->{ID});
  63.         my $idHex = getHex($args->{ID});
  64.         my $nick = $args->{name};
  65.  
  66.         # Write
  67.         warning "New player on file: $id - $nick \n";
  68.         open my $fileTxt,">>". 'listAllPlayers.txt' or die "Cannot create file listAllPlayers.txt: $!";
  69.         print $fileTxt "* $idHex - $id - $nick\n";
  70.         close $fileTxt;
  71.        
  72.         # Finalizar
  73.         $envios = 0;
  74.     }
  75.  
  76.     # Gambiarra: caso o valor de $envios seja muito alto, quer dizer que enviou diversos pacotes e não recebeu resposta,
  77.     #  logo, é provável que travou
  78.     sub gambiarra {
  79.         if ($envios >= $limitEnvios) {
  80.             # Avisar que travou no arquivo de texto
  81.             open my $fileTxt,">>". 'listAllPlayers.txt' or die "Cannot create file listAllPlayers.txt: $!";
  82.             print $fileTxt "***********************\nTravou aqui\n***********************\n";
  83.             close $fileTxt;
  84.  
  85.             # Resetar e atualizar as variávies
  86.             $idLoop = $idLoop - $envios - 15;
  87.             $limitEnvios += $limit;
  88.             $envios = 0;
  89.            
  90.             # Relogar em 300 segundos
  91.             Commands::run("relog 300");
  92.         }
  93.     }
  94.  
  95.     1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement