Change buddy message.
[spider.git] / perl / DXChannel.pm
index 6da3ecbe36d0be30a00ee2a47ce64bdac9f1e411..127f3a0604665e6631784dbc8a871253f72cfb95 100644 (file)
@@ -153,7 +153,8 @@ sub alloc
        if (defined $user) {
                $self->{user} = $user;
                $self->{lang} = $user->lang;
-               $user->new_group() if !$user->group;
+               $user->new_group unless $user->group;
+               $user->new_buddies unless $user->buddies;
                $self->{group} = $user->group;
                $self->{sort} = $user->sort;
        }
@@ -178,6 +179,14 @@ sub alloc
        return $channels{$call} = $self;
 }
 
+# rebless this channel as something else
+sub rebless
+{
+       my $self = shift;
+       my $class = shift;
+       return $channels{$self->{call}} = bless $self, $class;
+}
+
 sub rec        
 {
        my ($self, $msg) = @_;
@@ -388,15 +397,16 @@ sub send                                          # this is always later and always data
        return unless $conn;
        my $call = $self->{call};
 
-       for (@_) {
-#              chomp;
-        my @lines = split /\n/;
-               for (@lines) {
-                       $conn->send_later("D$call|$_");
-                       dbg("-> D $call $_") if isdbg('chan');
+       foreach my $l (@_) {
+               for (ref $l ? @$l : $l) {
+                       my @lines = split /\n/;
+                       for (@lines) {
+                               $conn->send_later("D$call|$_");
+                               dbg("-> D $call $_") if isdbg('chan');
+                       }
                }
        }
-       $self->{t} = time;
+       $self->{t} = $main::systime;
 }
 
 # send a file (always later)
@@ -484,7 +494,30 @@ sub closeall
 #
 sub tell_login
 {
-       my ($self, $m) = @_;
+       my ($self, $m, $call) = @_;
+       
+       $call ||= $self->{call};
+       
+       # send info to all logged in thingies
+       my @dxchan = get_all_users();
+       my $dxchan;
+       foreach $dxchan (@dxchan) {
+               next if $dxchan == $self;
+               next if $dxchan->{call} eq $main::mycall;
+               $dxchan->send($dxchan->msg($m, $call)) if $dxchan->{logininfo};
+       }
+}
+
+#
+# Tell all the users if a buddy is logged or out
+#
+sub tell_buddies
+{
+       my ($self, $m, $call, $node) = @_;
+       
+       $call ||= $self->{call};
+       $call =~ s/-\d+$//;
+       $m .= 'n' if $node;
        
        # send info to all logged in thingies
        my @dxchan = get_all_users();
@@ -492,7 +525,7 @@ sub tell_login
        foreach $dxchan (@dxchan) {
                next if $dxchan == $self;
                next if $dxchan->{call} eq $main::mycall;
-               $dxchan->send($dxchan->msg($m, $self->{call})) if $dxchan->{logininfo};
+               $dxchan->send($dxchan->msg($m, $call, $node)) if grep $_ eq $call, @{$dxchan->{user}->{buddies}} ;
        }
 }