Commits

Anonymous committed fa0b655

God this fails. :|

  • Participants
  • Parent commits cdb252a

Comments (0)

Files changed (2)

File bin/keldair.pl

     "PORT"   => $SETTINGS->{'uplink'}->{'port'}
 );
 
-$irc->connect($SETTINGS->{'uplink'}->{'port'},$SETTINGS->{'uplink'}->{'host'});
+$irc->connect("0.0.0.0",$SETTINGS->{'uplink'}->{'port'},$SETTINGS->{'uplink'}->{'host'});

File lib/Keldair.pm

     $params{ lc $_ } = delete $params{$_} for keys %params;
     delete $params{options} if ref $params{options} ne 'HASH';
 
-    #my $self = bless {}, $package;
-    #$self->_create();
+    my $self = bless {}, $package;
+    $self->_create();
     %bot = %params;
 }
 
 sub io_loop {
-    my $select = new IO::Select;
     my $buffer;
 
   # This main loop runs continuously throughout the lifetime of the program with
     while (1) {
 
         # Check if socket is still active.
-        if ( !defined( *UPLINK{IO} ) || !UPLINK->opened() ) {
+        if ( !defined( $sock ) || !$sock->opened() ) {
             sconnect();
-            $select->add( \*UPLINK );
+            $select->add( \$sock );
             next;
         }
 
 
             # Process at most BUFSIZ bytes per second
             my $incoming;
-            recv( UPLINK, $incoming, BUFSIZ, 0 );
+            recv( $sock, $incoming, BUFSIZ, 0 );
 
             if ( !defined($incoming) || ( length($incoming) == 0 ) ) {
 
                 # Received EOF, close socket
                 slog('Uplink connection lost: Connection reset by peer.');
-                $select->remove( \*UPLINK );
-                close(UPLINK);
+                $select->remove( \$sock );
+                close($sock);
                 sleep(90);
                 last;
             }
 }
 
 sub connect {
-    my (undef,$port,$server) = @_;
+    my (undef,$vhost,$port,$server) = @_;
     print($port.' '.$server."\n");
-  socket(UPLINK, PF_INET, SOCK_STREAM, getprotobyname('tcp')) or
-    slog('Failed to register socket.');
-  bind(UPLINK, sockaddr_in(0, INADDR_ANY));
+    our $sock = IO::Socket::INET->new(
+    Proto     => "tcp",
+    LocalAddr => $vhost,
+    PeerAddr  => $port,
+    PeerPort  => $server,
+  ) or die("Uplink connection failed.");
+  print("Uplink connection successfully established.\n");
+  #socket(UPLINK, PF_INET, SOCK_STREAM, getprotobyname('tcp')) or
+    #slog('Failed to register socket.');
+  #bind(UPLINK, sockaddr_in(0, INADDR_ANY));
 
-  my $sin = sockaddr_in($port, inet_aton($server));
-  if (connect(UPLINK, $sin)) {
-    print("Uplink connection successfully established.\n");
-  }
-  else {
-    print("Uplink connection failed.\n");
-    return 0;
-  }
-  UPLINK->autoflush(1);
+  #my $sin = sockaddr_in($port, inet_aton($server));
+ # if (connect(UPLINK, $sin)) {
+  #  print("Uplink connection successfully established.\n");
+  #}
+  #else {
+   # print("Uplink connection failed.\n");
+    #return 0;
+  #}
+  $sock->autoflush(1);
+  our $select = new IO::Select;
 
   _register;
   io_loop;
 #}
 
 sub snd {
-    if ( !defined( *UPLINK{IO} ) || !UPLINK->opened() ) {
-        return 0;
-    }
-
-    #my $line = sprintf( shift(@_), @_ );
-    my $link = @_;
+    my $line = sprintf( shift(@_), @_ );
+    #my $link = @_;
 
     # trim line to 510 chars (510+2 for CRLF)
+    chomp($line);
     $line = substr( $line, 0, 510 ) . "\015\012";
 
     my $bytes = length($line);
 
-    syswrite( UPLINK, $line, $bytes );
+    #syswrite( UPLINK, $line, $bytes );
+    send( $sock, $line, 0 );
     return 1;
 }