i want to load "thread" model for openkore...
i have installed ActivePerl-5.12.3.1204-MSWin32-x86-294330.msi..(path : C:\Perl)
i am trying to write a code for thread in Perl.
Code: Select all
package test2;
use threads;
use strict;
my $t1 = threads->new(
{ 'context' => 'list',
'stack_size' => 32*4096,
'exit' => 'thread_only' },
\&doSomething) ;
sleep(5) ;
$t1->exit() ;
sub doSomething {
while(1){
print("test String..\n") ;
sleep(1) ;
}
}
1;
however, i write the following code to plugins
Code: Select all
package test;
use lib "C:/Perl/lib" ;
use Utils;
use strict;
use Plugins;
use Globals;
use Settings;
use Log qw(message debug);
use Socket;
use threads;
Plugins::register('test', 'Record console messages after bot died', \&unload);
my $cHook = Plugins::addHooks( [ "disconnected" , \&onDisconnected , undef]
, [ "in_game" , \&onInGame , undef ]
, [ "start3" , \&onLoad , undef ]
, [ "base_level" , \&onBaseLevel , undef ]
, [ "self_died" , \&onDeath , undef ]
, [ "map_loaded" , \&onMapLoaded , undef ]
);
my $t1 ;
my $sock ;
my $address = 0;
my $port = 0;
sub unload {
close($sock) ;
$t1->join() ;
Plugins::delHooks( $cHook ) ;
}
sub onDisconnected {
message ("error:disConnected....\n" , "error") ;
}
sub onInGame {
}
sub onLoad {
my $flag = $config{StatusReportMode} ;
if ( $flag == 0 ) {
message ("Report Mode off\n" , "info") ;
unload() ;
} else {
message ("Start Connect to Report Server\n" , "info") ;
$address = inet_aton( $config{"StatusReportIp"} ) ;
$port = $config{"StatusReportPort"} ;
$t1 = threads->new(
{ 'context' => 'list',
'stack_size' => 32*4096,
'exit' => 'thread_only' },
\&RecThreadFunc) ;
while ( 1 ) {
message ("Connect to -> ".$config{"StatusReportIp"}.":".$port."..." , "info") ;
last unless(ConnectToServer() == 0 ) ;
message ("Connect Fail!\n" , "info") ;
sleep ( $config{"StatusRetryDelay"} ) ;
}
message ("Connect Success!\n" , "info") ;
}
}
sub RecThreadFunc {
message ("in thread ...\n" , "info") ;
}
sub ConnectToServer {
socket( $sock ,AF_INET,SOCK_STREAM,6);
my $result=sockaddr_in($port,$address);
my $flag = connect( $sock , $result ) ;
return $flag ;
}
sub onBaseLevel {
}
sub onDeath {
}
sub onMapLoaded {
}
1;
thanks..