X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXChannel.pm;h=b3929c1f2a2d5b45b53a09169294b29aa952952f;hb=fb554d0fdb1d30120dbfff15514c51f683dc17a8;hp=c494f59b3a60cc9b1098663b009f26b6acf0501e;hpb=69c8aeb338cc485103e289fbab7ec4e7e056ed20;p=spider.git diff --git a/perl/DXChannel.pm b/perl/DXChannel.pm index c494f59b..b3929c1f 100644 --- a/perl/DXChannel.pm +++ b/perl/DXChannel.pm @@ -34,7 +34,7 @@ use Carp; use strict; use vars qw(%channels %valid); -%channels = undef; +%channels = (); %valid = ( call => '0,Callsign', @@ -49,8 +49,9 @@ use vars qw(%channels %valid); list => '9,Dep Chan List', name => '0,User Name', consort => '9,Connection Type', - sort => '9,Type of Channel', + 'sort' => '9,Type of Channel', wwv => '0,Want WWV,yesno', + wx => '0,Want WX,yesno', talk => '0,Want Talk,yesno', ann => '0,Want Announce,yesno', here => '0,Here?,yesno', @@ -68,6 +69,7 @@ use vars qw(%channels %valid); pagedata => '9,Page Data Store', group => '0,Access Group,parray', # used to create a group of users/nodes for some purpose or other isolate => '9,Isolate network,yesno', + delayed => '9,Delayed messages,parray', ); # create a new channel object [$obj = DXChannel->new($call, $msg_conn_obj, $user_obj)] @@ -79,14 +81,17 @@ sub alloc die "trying to create a duplicate channel for $call" if $channels{$call}; $self->{call} = $call; $self->{conn} = $conn if defined $conn; # if this isn't defined then it must be a list - $self->{user} = $user if defined $user; + if (defined $user) { + $self->{user} = $user; + $self->{lang} = $user->lang; + $user->new_group() if !$user->group; + $self->{group} = $user->group; + } $self->{startt} = $self->{t} = time; $self->{state} = 0; $self->{oldstate} = 0; - $self->{lang} = $user->{lang} if defined $user; $self->{lang} = $main::lang if !$self->{lang}; - $user->new_group() if !$user->group; - $self->{group} = $user->group; + $self->{func} = ""; bless $self, $pkg; return $channels{$call} = $self; } @@ -130,21 +135,21 @@ sub del sub is_ak1a { my $self = shift; - return $self->{sort} eq 'A'; + return $self->{'sort'} eq 'A'; } # is it a user? sub is_user { my $self = shift; - return $self->{sort} eq 'U'; + return $self->{'sort'} eq 'U'; } # is it a connect type sub is_connect { my $self = shift; - return $self->{sort} eq 'C'; + return $self->{'sort'} eq 'C'; } # handle out going messages, immediately without waiting for the select to drop @@ -155,12 +160,11 @@ sub send_now my $conn = $self->{conn}; my $sort = shift; my $call = $self->{call}; - my $line; - foreach $line (@_) { - chomp $line; - $conn->send_now("$sort$call|$line") if $conn; - dbg('chan', "-> $sort $call $line") if $conn; + for (@_) { + chomp; + $conn->send_now("$sort$call|$_") if $conn; + dbg('chan', "-> $sort $call $_") if $conn; } $self->{t} = time; } @@ -173,12 +177,11 @@ sub send # this is always later and always data my $self = shift; my $conn = $self->{conn}; my $call = $self->{call}; - my $line; - foreach $line (@_) { - chomp $line; - $conn->send_later("D$call|$line") if $conn; - dbg('chan', "-> D $call $line") if $conn; + for (@_) { + chomp; + $conn->send_later("D$call|$_") if $conn; + dbg('chan', "-> D $call $_") if $conn; } $self->{t} = time; } @@ -204,6 +207,16 @@ sub msg return DXM::msg($self->{lang}, @_); } +# stick a broadcast on the delayed queue +sub delay +{ + my $self = shift; + my $s = shift; + + $self->{delayed} = [] unless $self->{delayed}; + push @{$self->{delayed}}, $s; +} + # change the state of the channel - lots of scope for debugging here :-) sub state { @@ -211,7 +224,16 @@ sub state if (@_) { $self->{oldstate} = $self->{state}; $self->{state} = shift; + $self->{func} = '' unless defined $self->{func}; dbg('state', "$self->{call} channel func $self->{func} state $self->{oldstate} -> $self->{state}\n"); + + # if there is any queued up broadcasts then splurge them out here + if ($self->{delayed} && ($self->{state} eq 'prompt' || $self->{state} eq 'convers')) { + for (@{$self->{delayed}}) { + $self->send($_); + } + delete $self->{delayed}; + } } return $self->{state}; } @@ -231,6 +253,22 @@ sub disconnect $self->del(); } +# +# just close all the socket connections down without any fiddling about, cleaning, being +# nice to other processes and otherwise telling them what is going on. +# +# This is for the benefit of forked processes to prepare for starting new programs, they +# don't want or need all this baggage. +# + +sub closeall +{ + my $ref; + foreach $ref (values %channels) { + $ref->{conn}->disconnect() if $ref->{conn}; + } +} + # various access routines #