#!/usr/bin/perl $MUD = ""; $Character = ""; $Password = ""; $Machine = ""; $Port = 0; $Editor = '/usr/bin/vi'; $LocalEditFile = "/tmp/creremote.$$"; print "CreRemote> "; while(<>) { chop; if( $_ ) { @tmp = split(/ /, $_); $cmd = shift(@tmp); $args = join(' ', @tmp); if( ! $MUD ) { if( $cmd eq "connect" ) { &cmdConnect($args); } elsif( $cmd eq "help" ) { &cmdHelp($args); } elsif( $cmd eq "exit" ) { exit; } elsif( substr($cmd, 0, 1) eq "!" ) { system(substr($cmd, 1, length($cmd) - 1)); } else { print "Bad command: $cmd $args\n"; } } else { if( $cmd eq "connect" ) { print "You are already connected to $MUD.\n"; } elsif( $cmd eq "quit" ) { close(S); $MUD = ""; $Buffer = ""; $InEdit = 0; $EditFile = ""; } elsif( $cmd eq "edit" ) { $EditFile = $args; system("rm $LocalEditFile") if -f $LocalEditFile; print S "$cmd $args\n"; $x = 1; while( $x ) { if( -f $LocalEditFile ) { $x = 0; } } @bugger = stat($LocalEditFile); $sz = $bugger[7]; $tme = $bugger[9]; system("$Editor $LocalEditFile"); @bugger = stat($LocalEditFile); if( $bugger[7] == 0 || $tme == $bugger[9] ) { $EditFile = ""; system("rm $LocalEditFile"); } else { $Buffer = ""; open(LEF, $LocalEditFile); while(<LEF>) { $Buffer = "$Buffer$_"; } close(LEF); print S "100 ".length($Buffer)." $EditFile\n"; $EditFile = ""; sleep(2); print S $Buffer; $Buffer = ""; system("rm $LocalEditFile"); } } elsif( $cmd eq "100" ) { print "Illegal command.\n"; } elsif( substr($cmd, 0, 1) eq "!" ) { system(substr($cmd, 1, length($cmd) - 1)); } else { print S "$cmd $args\n"; } } } print "CreRemote> " unless $MUD; } sub cmdConnect { local($mud) = shift(@_); local($rcfile) = $ENV{'HOME'} || './'; $rcfile = $rcfile."/.creremoterc"; local($found) = 0; local($writerc) = 0; if( -f $rcfile ) { open(RCFILE, $rcfile); while(<RCFILE>) { chop; local(@words) = split; local($thismud) = shift(@words); if( ! $charname && $thismud eq $mud ) { $Character = shift(@words); $Password = shift(@words); $Machine= shift(@words); $Port = shift(@words); $found = 1; } } close(RCFILE); } if( ! $found ) { print "Character name: "; chop($Character = <>); print "Password: "; system 'stty', '-echo'; chop($Password = <>); system 'stty', 'echo'; print "\n$mud ip: "; chop($Machine = <>); print "port: "; chop($Port = <>); $writerc = 1; } $MUD = $mud; if( ! $Character || !$MUD || ! $Password || ! $Machine || ! $Port ) { print "Vital information is missing\n"; return; } $AF_INET = 2; $SOCK_STREAM = 1; $SIG{'INT'} = 'killconnection'; $port = $Port; $sockaddr = 'S n a4 x8'; chop($hostname = `hostname`); ($name, $aliases, $proto) = getprotobyname('tcp'); ($name, $aliases, $port) = getservbyname($port, 'tcp') unless $port =~ /^\d+$/; ($name, $aliases, $type, $len, $thisaddr) = gethostbyname($hostname); ($name, $aliases, $type, $len, $thataddr) = gethostbyname($Machine); $this = pack($sockaddr, $AF_INET, 0, $thisaddr); $that = pack($sockaddr, $AF_INET, $port, $thataddr); if( !socket(S, $AF_INET, $SOCK_STREAM, $proto) ) { print "Error creating socket for $MUD: $!\n"; $MUD = ""; $Character = ""; $Password = ""; $Machine = ""; $Port = ""; return; } if( !bind(S, $this) ) { print "Error binding to $MUD: $!\n"; $MUD = ""; $Character = ""; $Password = ""; $Machine = ""; $Port = ""; return; } if( !connect(S, $that) ) { print "Error connecting to $MUD: $!\n"; $MUD = ""; $Character = ""; $Password = ""; $Machine = ""; $Port = ""; return; } if( $writerc ) { open(NRCFILE, ">> $rcfile"); print NRCFILE "$MUD $Character $Password $Machine $Port\n"; close(NRCFILE); } select(S); $| = 1; select(STDOUT); if( $child = fork ) { print S "login $Character $Password\n"; return; } else { while(<S>) { if( $InEdit > 0 ) { $Buffer = "$Buffer$_"; if( length($Buffer) == $InEdit ) { $InEdit = 0; open(LEF, ">$LocalEditFile"); print LEF $Buffer; close(LEF); while( -f $LocalEditFile ) { } $Buffer = ""; $InEdit = 0; print "$MUD> "; } } else { chop; local(@borg) = split; $remcmd = shift(@borg); if ( $remcmd == 100 ) { $InEdit = shift(@borg); if( ! $InEdit ) { system("touch $LocalEditFile"); while( -f $LocalEditFile ) { } $Buffer = ""; $InEdit = 0; print "$MUD> "; } } elsif( $remcmd == 500 ) { $format = "Directory: %s\n"; $tmpx = @borg - 1; if( $tmpx ) { while($tmpx--) { if( $tmpx % 3 == 0 ) { $format = "$format%20s\n"; } else { $format = "$format%20s"; } } } printf($format, @borg); print "\n$MUD> "; } else { local($out) = join(' ', @borg); print "$out\n$MUD> "; } } } exit; } } sub cmdHelp { print "CreRemote is a way to work on a MUD without physically\n"; print "being on that MUD. When you first issue the CreRemote\n"; print "command, you are given the CreRemote prompt. At that time\n"; print "you are not connected to any MUD. You can issue the\n"; print "following commands from the CreRemote prompt:\n"; print "\tconnect <mud>\n"; print "\texit\n\n"; print "Once connect to a MUD, the commands available to you may\n"; print "vary from MUD to MUD, generally you will have commands like:\n"; print "cd, ls, update, mkdir, rmdir, rm, mv, cp, etc.\n"; print "No matter whcih MUD, you will have the command \"edit\"\n"; print "which allows you to edit your files with your favourite UNIX\n"; print "editor. The default is vi, however, it will use the value\n"; print "of your EDITOR environment variable.\n"; print "When connecting to a MUD, remember to specify its RCP port,\n"; print "NOT its MUD port. This is generally MUD port - 10.\n"; }