Advertisement
KeplerBR

Plugin listAllPlayers

Jan 1st, 2013
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.87 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 (in English)
  5. #  * http://forum.xkore.com.br/index.php?/topic/64-plugin-listallplayers/ (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.         );
  22.  
  23.  
  24.     # On Unload code
  25.     sub on_unload {
  26.         Plugins::delHook("packet/character_name", $hooks);
  27.         Plugins::delHook("AI_pre/received_sync", $hooks);
  28.     }
  29.  
  30.     # Global variables
  31.     my $idLoop = 150000;    # In which ID will start the loop
  32.     my $limit = 20;         # Limit how often will send the package by sync
  33.  
  34.     # Prepare and send packet asking the nick of character
  35.     sub send_packet {
  36.     warning "Starting sending the packet \n";
  37.  
  38.         for (my $i = 0; $i < $limit; $i++) {
  39.             $idLoop++;
  40.  
  41.             # Send packet
  42.             my $idSend = $idLoop;
  43.             $idSend = pack("V", $idSend);
  44.             $idSend = getHex($idSend);
  45.             message "Send ID $idSend ($idLoop)\n";
  46.            
  47.             $messageSender->sendRaw("68 03 $idSend");
  48.         }
  49.  
  50.     warning "Completing the packet sent \n";
  51.     }
  52.  
  53.     # Add the result to text file
  54.     sub list_player_id_name {
  55.         my $hookname = shift;
  56.         my $args = shift;
  57.  
  58.         # Defining and organizing variables
  59.         my $id = unpack("V1", $args->{ID});
  60.         my $idHex = getHex($args->{ID});
  61.         my $nick = $args->{name};
  62.  
  63.         # Write
  64.         warning "New player on file: $id - $nick \n";
  65.         open FILE_TXT,">>". 'listAllPlayers.txt' or die "Cannot create file listAllPlayers.txt: $!";
  66.         print FILE_TXT "* $idHex - $id - $nick\n";
  67.         close FILE_TXT;
  68.     }
  69.  
  70.     1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement