Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

An event-esque system.

Thanks Ice_Blade for the inspiration.
  • Loading branch information...
commit 50f97077863064b641903270166e0cb1057ccef4 1 parent 3243183
@grickit authored
Showing with 34 additions and 0 deletions.
  1. +20 −0 gambot.pl
  2. +14 −0 modules/Gambot/GAPIL.pm
View
20 gambot.pl
@@ -40,10 +40,12 @@
##%core stores other core data.
##%variables allows message processors to store strings
##%persistent is just like variables, but is saved to disk on shutdown>
+##%locks is for the event-like system. It allows children to block for certain input.
my %config;
my %core;
my %variables;
my %persistent;
+my %locks;
$core{'home_directory'} = $FindBin::Bin;
$core{'configuration_file'} = 'config.txt';
@@ -170,6 +172,24 @@ sub check_persistence_domain_exists {
return defined $persistent{$domain};
}
+sub event_lock {
+ my ($pipeid, $lock) = @_;
+ if(!defined $locks{$lock}) { $locks{$lock} = (); }
+ push(@{$locks{$lock}},$pipeid);
+}
+sub event_unlock {
+ my $lock = shift;
+ debug_output("Unlocking $lock.");
+ foreach my $pipeid (@{$locks{$lock}}) {
+ send_pipe_message($pipeid,$lock);
+ }
+ delete $locks{$lock};
+}
+sub check_event_lock_exists {
+ my $lock = shift;
+ return defined $locks{$lock};
+}
+
####-----#----- Actual Work -----#-----####
&load_switches();
&read_configuration_file($core{'home_directory'} . '/configurations/' . $core{'configuration_file'});
View
14 modules/Gambot/GAPIL.pm
@@ -146,6 +146,20 @@ sub parse_command {
}
}
+ elsif ($command =~ /^event_lock>([a-zA-Z0-9_#-]+)$/) {
+ event_lock($pipeid,$1);
+ }
+ elsif ($command =~ /^event_unlock>([a-zA-Z0-9_#-]+)$/) {
+ event_unlock($1);
+ }
+ elsif ($command =~ /^check_event_lock_exists>([a-zA-Z0-9_#-]+)$/) {
+ if (&check_event_lock_exists($1)) {
+ &send_pipe_message($pipeid,"1");
+ }
+ else {
+ &send_pipe_message($pipeid,"");
+ }
+ }
else {
&error_output("Unknown API call: $command");
Please sign in to comment.
Something went wrong with that request. Please try again.