Author: nornagon
Date: 2004-12-29 21:58:38 -0500 (Wed, 29 Dec 2004)
New Revision: 468

Modified:
   trunk/clients/termvisual/termvisual.pl
Log:
Term::Visual client sucks slightly less

Modified: trunk/clients/termvisual/termvisual.pl
===================================================================
--- trunk/clients/termvisual/termvisual.pl      2004-12-29 21:46:48 UTC (rev 
467)
+++ trunk/clients/termvisual/termvisual.pl      2004-12-30 02:58:38 UTC (rev 
468)
@@ -42,7 +42,7 @@
     $heap->{config} = Haver::Config->new(
         file => "config",
         default => {
-            UID     => $ENV{USER} || 'A_User',
+            UID     => 'blah' || 'A_User',
             Channel => 'lobby',
             HistSize    => 50,
             BufferSize  => 1000,
@@ -136,7 +136,7 @@
 
 sub handle_socket_input {
     my ($heap, $input) = @_[HEAP, ARG0];
-    $heap->{vt}->print($heap->{window_id}, 'Received '.join(' ', @$input));
+#    $heap->{vt}->print($heap->{window_id}, 'Received '.join(' ', @$input));
     if (exists $scommands{$$input[0]}) {
         my $cmd = shift @$input;
         &{$scommands{$cmd}}(@$input);
@@ -153,9 +153,13 @@
     HAVER   => \&server_haver,
     WANT    => \&server_want,
     ACCEPT  => \&server_accept,
+    FAIL    => \&server_fail,
     LIST    => \&server_list,
     JOIN    => \&server_join,
+    PART    => \&server_part,
+    QUIT    => \&server_quit,
     MSG     => \&server_msg,
+    PMSG    => \&server_pmsg,
 );
 
 sub server_haver {
@@ -169,16 +173,25 @@
     if ($want eq 'IDENT') {
         $heap->{socket}->put(['IDENT', $heap->{config}{UID}]);
     } else {
-        $heap->{vt}->print($heap->{window_id}, "Unhandlable WANT: $want");
+        vt_print("Unhandlable WANT: $want");
+        $heap->{socket}->put(['CANT', $want]);
     }
 }
 
 sub server_accept {
-    my $heap = $poe_kernel->get_active_session()->get_heap();
     my ($uid) = $_[0];
-    $heap->{vt}->print($heap->{window_id}, "UID accepted: $uid");
+    vt_print("UID accepted: $uid");
 }
 
+sub server_fail {
+    my $heap = $poe_kernel->get_active_session()->get_heap();
+    my ($command, $errorcode, @args) = @_;
+    vt_print("$command failed: $errorcode");
+    if ($command eq 'IDENT') {
+        $heap->{config}{UID} .= '_';
+    }
+}
+
 sub server_list {
     my $cid = shift;
     my $type = shift;
@@ -194,11 +207,34 @@
     vt_print("$user has joined $cid");
 }
 
+sub server_part {
+    my ($cid, $user) = @_;
+    vt_print("$user has left $cid");
+}
+
+sub server_quit {
+    my ($uid, $type, $reason) = @_;
+    if ($type eq 'ACTIVE') {
+        vt_print("$uid has quit Haver (Active Quit: $reason)");
+    } else {
+        vt_print("$uid has quit Haver ($type)");
+    }
+}
+
 sub server_msg {
-    my ($cid, $user, $msg) = @_;
-    vt_print("$cid:<$user> $msg");
+    my ($cid, $user, $type, $msg) = @_;
+    if ($type eq '"') { # Message
+        vt_print("$cid:<$user> $msg");
+    } elsif ($type eq ':') { # Action
+        vt_print("$cid:* $user $msg");
+    }
 }
 
+sub server_pmsg {
+    my ($user, $msg) = @_;
+    vt_print("<$user> $msg");
+}
+
 ###########################################################
 #                      USER COMMANDS                      #
 ###########################################################
@@ -208,7 +244,10 @@
     connect => \&command_connect,
     save    => \&command_save,
     join    => \&command_join,
+    part    => \&command_part,
     names   => \&command_names,
+    me      => \&command_me,
+    say     => \&command_say,
 );
 
 sub command_quit {
@@ -253,31 +292,53 @@
     my $heap = $poe_kernel->get_active_session()->get_heap();
     my $cid = $_[0] || undef;
     if (!defined $cid) {
-        $heap->{vt}->print($heap->{window_id}, "Syntax: /join <cid>");
+        vt_print("Syntax: /join <cid>");
         return;
     }
-    $heap->{vt}->print($heap->{window_id}, "Joining channel $cid");
+    vt_print("Joining channel $cid");
     $heap->{socket}->put(['JOIN', $cid]);
 }
 
+sub command_part {
+    my $heap = $poe_kernel->get_active_session()->get_heap();
+    my $cid = $_[0] || undef;
+    vt_print('Syntax: /part <cid>') and return if !defined $cid;
+    $heap->{socket}->put(['PART', $cid]);
+}
+
 sub command_names {
-    my $heap = $poe_kernel->get_active_session()->get_heap();
+    my $heap = get_heap();
     vt_print("Retrieving name list...");
     $heap->{socket}->put(['LIST', 'lobby', 'user']);
 }
 
+sub command_me {
+    my $heap = get_heap();
+    my ($msg) = join " ", @_;
+    $heap->{socket}->put(['MSG', 'lobby', ':', $msg]);
+}
+
+sub command_say {
+    my ($msg) = join " ", @_;
+    chan_msg('lobby', $msg);
+}
+
 # Misc functions
 
 sub vt_print {
-    my $heap = $poe_kernel->get_active_session()->get_heap();
+    my $heap = get_heap();
     $heap->{vt}->print($heap->{window_id}, @_);
 }
 
 sub chan_msg {
-    my $heap = $poe_kernel->get_active_session()->get_heap();
+    my $heap = get_heap();
     my ($chan, $msg) = (shift, shift);
-    $heap->{socket}->put(['MSG', $chan, $msg]);
+    $heap->{socket}->put(['MSG', $chan, '"', $msg]);
 }
 
+sub get_heap {
+    return $poe_kernel->get_active_session()->get_heap();
+}
+
 POE::Kernel->run();
 exit 0;


Reply via email to