Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 9.02 KB | None | 0 0
  1. # AntiGM        
  2. # Author: otaku
  3. # License: GNU GPL v3
  4. #
  5. # OVERVIEW
  6. #
  7. # This is a plugin to avoid some common GM tests on the bRO server.
  8. # Sometimes the GM will talk to you through the system chat, sometimes through PMs
  9. # and sometimes he'll just speak through the public chat. Amongst other tests.
  10. # It identifies the GM and disconnects if he is talking to/testing you.
  11. #
  12. # * On the system chat it checks for your name on the message (as it happens on tests)
  13. #
  14. # CONFIG
  15. #
  16. # You must add to your control/config.txt de lines:
  17. #
  18. #       antigm_relog <seconds>
  19. #       antigm_warning <boolean>
  20. #       antigm_reaction <option>
  21. #       antigm_alarm <boolean>
  22. #
  23. # DETAILS
  24. #
  25. #   antigm_relog: It will relog for <seconds> seconds if Openkore identifies the GM.
  26. #   If the value of <seconds> is 0 or less, then Openkore will quit instead of relog.
  27. #
  28. #   antigm_warning: If the value is 1, the bot will try to warn the other bots through
  29. #   the bus system.
  30. #
  31. #   antigm_reaction: This is the reaction the bot will take when another bot sends it
  32. #   a bus message with a GM warning. The values of <option> can be:
  33. #           0 (It won't react to the message)
  34. #           1 (It reacts to the message ONLY if the GM is in the same map as him)
  35. #           2 (It reacts to the message regardless of the map)
  36. #
  37. #       antigm_alarm: If set to 1 triggers an alarm sound when Openkore detects a GM.
  38. package AntiGM;
  39.  
  40. use strict;
  41. use warnings;
  42. use encoding "utf8";
  43. use Log qw(warning message error);
  44. use Globals qw($char $bus $field %config @servers %statusHandle);
  45. use Misc qw(relog quit);
  46. use Misc;
  47. use Commands;
  48. use Utils::Win32;
  49.  
  50. # GM name pattern (this is not related to Openkore's built-in pattern)
  51. my $gm_pattern = '^(\[GM\]|\[GE\]|\[LU\])';
  52.  
  53. use constant {
  54.     PLUGIN_NAME => "antiGM",
  55.     DEFAULT_ENABLE => 1,
  56.     RELOG_TAIME => 1200
  57. };
  58.  
  59. Plugins::register(PLUGIN_NAME,'driblar os GMs do jogo',\&onUnload);
  60.  
  61. my $hooks = Plugins::addHooks(
  62.     ['start3', \&checkConfig, undef],
  63.     ['packet/system_chat',\&handleSystemChat],
  64.     ['packet/public_chat',\&handlePublicChat],
  65.     ['packet/private_message',\&handlePrivateMessage],
  66.     ['packet/actor_status_active',\&handleStripEvent],
  67.     ['charNameUpdate',\&handleCharNameUpdate],
  68.     ['initialized',\&setCallback],
  69. );
  70.  
  71. my $debug_cmd = Commands::register(['antigm_emular','emula o avistamento de um GM',\&GMfound]);
  72.  
  73. sub checkConfig {
  74.         configModify('antigm_relog', (RELOG_TAIME+int(rand 500)));
  75.     if (!exists($config{antigm_relog})) {
  76.         configModify('antigm_warning', 1) if (!exists($config{antigm_warning}));
  77.         configModify('antigm_reaction', 1) if (!exists($config{antigm_reaction}));
  78.         configModify('antigm_alarm', 0) if (!exists($config{antigm_alarm}));
  79.         configModify('antigm_enabled', 0) if (!$bus);
  80.     } elsif ($config{antigm_enabled} = 0) {
  81.         Plugins::unload(PLUGIN_NAME);
  82.     }
  83. }
  84.  
  85. sub setCallback {
  86.     return unless $config{'antigm_warning'};
  87.     if ($bus) {
  88.         warning "[AntiGM] Registrando callback: handleBusMessage\n";
  89.         $bus->onMessageReceived->add(undef, \&handleBusMessage);
  90.     } else {
  91.         error "[AntiGM] Bus está desativado!\n";
  92.         error "[AntiGM] Não será possível enviar/receber mensagens para outros bots.\n";
  93.         Plugins::unload(PLUGIN_NAME);
  94.     }
  95. }
  96.  
  97. sub onUnload {
  98.     Plugins::delHooks($hooks);
  99.     Commands::unregister($debug_cmd);
  100.     error("[".PLUGIN_NAME."] Unloading plugin...\n");
  101.     message "[".PLUGIN_NAME."] Plugin Unloaded\n";
  102. }
  103.  
  104. sub handleSystemChat {
  105.     my $message = $_[1]->{message};
  106.     my $name = $char->{name};
  107.     if (index($message,$name) != -1) {
  108.         warning "[AntiGM] Situação suspeita encontrada.\n";
  109.         GMfound('Meu nome apareceu na mensagem do sistema',$message);
  110.     }
  111. }
  112.  
  113. sub handlePublicChat {
  114.     my $message = $_[1]->{message};
  115.     if ($message =~ /$gm_pattern/) {
  116.         warning "[AntiGM] Situação suspeita encontrada.\n";
  117.         GMfound('O GM disse alguma coisa no chat publico',$message);
  118.     }
  119. }
  120.  
  121. sub handlePrivateMessage {
  122.     my $nick = $_[1]->{privMsgUser};
  123.     my $message = $_[1]->{privMsg};
  124.     if ($nick =~ /$gm_pattern/) {
  125.         warning "[AntiGM] Situação suspeita encontrada.\n";
  126.         GMfound('O GM me mandou uma PM',$nick.": ".$message);
  127.     }
  128. }
  129.  
  130. sub handleStripEvent {
  131.     my $args = $_[1];
  132.     return if ($field->{name} eq "thor_v01");
  133.     return if ($field->{name} eq "thor_v02");
  134.     return if ($field->{name} eq "ra_san01");
  135.     return if ($field->{name} eq "ra_san02");
  136.     return if ($field->{name} eq "ra_san03");
  137.     return if ($field->{name} eq "ra_san04");
  138.     return if ($field->{name} eq "ra_san05");
  139.     return if ($field->{name} eq "dew_dun02");
  140.     return if ($field->{name} eq "comodo");
  141.     return if ($field->{name} eq "cmd_fild01");
  142.     if (defined($args->{actor}) && $args->{actor}->isa('Actor::You')) {
  143.         my $type = $args->{type};
  144.         my $status = defined $statusHandle{$type} ? $statusHandle{$type} : "UNKNOWN_STATUS_$type";
  145.         if (
  146.             $status eq "EFST_NOEQUIPSHIELD" || $status eq "EFST_NOEQUIPARMOR" || $status eq "EFST_NOEQUIPWEAPON" ||
  147.             $status eq "EFST_NOEQUIPHELM" || $status eq "EFST_STRIPACCESSARY"
  148.         ) {
  149.             warning "[AntiGM] Situação suspeita encontrada.\n";
  150.             GMfound('O GM removeu meus equipamentos');
  151.         }
  152.     }
  153. }
  154.  
  155. sub handleBusMessage {
  156.     my $msg = $_[2];
  157.     if ($msg->{messageID} eq 'antigm' && $msg->{args}{server} eq $servers[$config{server}]{name}) {    
  158.         if ($config{antigm_reaction} == 2) {
  159.             warning "[AntiGM] ".$msg->{args}{bot_name}." me avisou que há GMs online.\n";
  160.             GMreaction('Avisado através do Bus pelo o bot '. $msg->{args}{bot_name});
  161.             return;
  162.         }
  163.         if ($config{antigm_reaction} == 1 && $msg->{args}{map_name} eq $field->baseName()) {
  164.             warning "[AntiGM] ".$msg->{args}{bot_name}." me avisou que há GMs nesse mapa.\n";
  165.             GMreaction('Avisado através do Bus pelo o bot '. $msg->{args}{bot_name});
  166.             return;
  167.         }
  168.         warning "[AntiGM] ".$msg->{args}{bot_name}." avistou um GM em ". $msg->{args}{map_name} ." no servidor ". $msg->{args}{server} ."\n";
  169.     }
  170. }
  171.  
  172. sub GMfound {
  173.     return if ($field->{name} eq "moc_para01");
  174.     return if ($field->{name} eq "prontera");
  175.     return if ($field->{name} eq "geffen_in");
  176.     return if ($field->{name} eq "geffen");
  177.     my ($reason,$log) = @_;
  178.  
  179.     # Warn other bots through the bus system
  180.     if ($config{'antigm_warning'}) {
  181.         if (!$bus) {
  182.             error "[AntiGM] Não foi possível avisar os outros bots.\n";
  183.             error "[AntiGM] O bus está desativado.\n";
  184.         } else {
  185.             warning "[AntiGM] Enviando informação para o bus para avisar outros bots.\n";
  186.             $bus->send('antigm', {
  187.                 map_name => $field->baseName(),
  188.                 server => $servers[$config{server}]{name},
  189.                 bot_name => $char->{name}
  190.             });
  191.         }
  192.     }
  193.    
  194.     if ($config{antigm_alarm}) {
  195.         my $filepath;
  196.         $filepath = "plugins/antigm.wav" if (-e "plugins/antigm.wav");
  197.         $filepath = "plugins/antigm/antigm.wav" if (-e "plugins/antigm/antigm.wav");
  198.         if ($filepath) {
  199.             Utils::Win32::playSound($filepath);
  200.         } else {
  201.             error "[AntiGM] Sound file not found!\n";
  202.         }
  203.     }
  204.    
  205.     GMreaction($reason,$log);  
  206. }
  207.  
  208. sub handleCharNameUpdate {
  209.   my @gm_ids = (100000, 100040, 103680, 103681, 103682, 103683, 103684, 103685, 103686, 103687, 103688, 103689, 103690, 1909615,
  210.     1909616, 1909617, 1909619, 1909620, 4616699, 2256720, 2256718, 3114920, 3114931, 3114932, 3114933, 3114934, 3114935, 3114936, 3114937,
  211.     3114938, 3114939, 3114930, 3117268, 3125310, 3125311, 3125312, 3125313, 3125314, 3125315, 3146303, 3155450, 3155451, 3155452, 3155453,
  212.     3155454, 3155455, 3178839, 3201057, 3360650, 3360651, 3360652, 3360653, 3360654, 3360655, 3430014, 3586075, 3586076, 3586077, 3586078,
  213.     3586079, 3586080, 3586081, 3586082, 3586083, 3586084, 3586085, 3656290, 3656291, 3656292, 3656293, 3656294, 3656295, 3665242, 3792576,
  214.     3905114, 4474231, 4474239, 4474249, 4474299, 4474326, 4474339, 4560441, 799190, 799191, 799192, 799193, 799194, 799195, 799196, 799197,
  215.     799198, 799199, 799200, 799201, 799202, 799203, 799204, 799205, 4616686, 4616687, 4616688, 4616689, 4616690, 4616691, 4616670, 4616671,
  216.     4616673, 4616674, 4616675, 4616676, 4616678, 4616720, 4616679, 4616680, 4616681, 4616682, 4616683, 4616684, 3334531, 4655431, 4657513,
  217.     4657510, 4657511, 4657512, 4657514, 4657515, 4657516, 4657517, 4657518, 4657519, 4657520);
  218.  
  219.   my $args = $_[1];
  220.   my $targetAccountId = $args->{player}{nameID};
  221.  
  222.   if($targetAccountId ~~ @gm_ids) {
  223.     warning "[AntiGM] Situação suspeita encontrada.\n";
  224.     GMfound('O GM ('.$args->{player}{nameID}.') '.$args->{player}{name}.' apareceu na tela');
  225.   }
  226. }
  227.  
  228. sub GMreaction {
  229.     my ($reason,$log) = @_;
  230.    
  231.     open(FH,'>>:utf8',$Settings::logs_folder.'/antigm_log.txt');
  232.     print FH "================================================================\n";
  233.     print FH "Conta: ". $config{username} ."\n";
  234.     print FH "Personagem: ". $char->{name} ."\n";
  235.     print FH "Mapa: ". $field->baseName() ."\t\tData: ". timeFormat() ."\n";
  236.     print FH "Motivo: ". $reason ."\n";
  237.     print FH "Mensagem que disparou a ação: ". $log ."\n" if (defined($log) && $log ne "");
  238.     close(FH);
  239.    
  240.     if ($config{antigm_relog} > 0) {
  241.         relog($config{antigm_relog});
  242.     } else {
  243.         relog();
  244.         quit();
  245.     }
  246. }
  247.  
  248. sub timeFormat {
  249.   my ($seg,$min,$hora,$dia,$mes,$ano,$resto) = localtime();
  250.   return sprintf("%02d/%02d/%04d %02d:%02d:%02d",$dia,$mes+1,$ano+1900,$hora,$min,$seg);
  251. }
  252.  
  253. 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement