Mr. H.G.M.
When a message is to be delivered to the ICS InterAction window, this emulator (which is written in Perl) uses a subroutine called iprint:
- Code: Select all
{ # make $width and $buffer private to iprint
my $width=0;
my $buffer='';
sub iprint ($;$) {
my ($mess,$nl)=shift;
$nl=$nl ? '' : "\\ ";
foreach (split(//,$mess)) {
$buffer.=$_;
$width++;
if ($_ eq "\n") {
$width=0;
# most interfaces expect a \n\r line terminator
print "$buffer\r";
$buffer='';
} elsif ($width==80) {
$width=length($nl)+length($buffer);
print "\n\r$nl";
} elsif ($_ eq ' ') {
print $buffer;
$buffer='';
}
}
}
}
Concerning the emulator, its true function is to make WinBoard believe that is connecting to an ICS server, when in reality is connecting to POGO or Yahoo. Of course, WinBoard does not understand Yahoo neither POGO languages so the other function is to act as a middle man and parse commands between Yahoo and Winboard or POGO and Winboard.
If you still think the code for this emulator might be of some help for your project, you can take a look at sourceforge.net and search for YtoICS, there you will find the perl code for the original project called YtoICS, or the "c" code for the young project called yics. Please be aware that neither of these programs work any more because the author abandoned the projects and never implemented a fix for Yahoo CAPTCHA scheme, but never the less, I consider those 50KB of code a real jewel.
The emulator needs to be waiting for WinBoard and not the other way around.
- Code: Select all
if (defined($options{'p'})) { #option p is the port number, usually 6000
$server=int($options{'p'});
my $lsn=new IO::Socket::INET(
Proto => 'tcp',
LocalPort => $server,
Listen => 1);
unless (defined $lsn) {
print "$0: $!\n";
exit 1;
}
print "Waiting for connection on port $server...\n";
undef $server;
$server=$lsn->accept;
$lsn->close;
unless (defined $server) {
print "$0: Unable to accept incoming connection: $!\n";
exit 1;
}
printf "Connection accepted from %s.\n",$server->peerhost;
select $server;
binmode $server;
$stdin=$server;
}
elsif ($Config{'osname'} eq 'MSWin32') {
iprint <<'winerr',1;
Sorry, Y to ICS cannot be run directly when on the Windows platform. Please have a look at http://ytoics.sourceforge.net/win32.html for details on Windows compatibility issues, and for directions on getting Y to ICS to run on Windows. (Yes, it is possible, and it's not too complicated either.)
winerr
exit 1;
} else {
$stdin=\*STDIN;
binmode STDOUT;
}
(select)->autoflush(1);
Down the road, the emulator connects to Yahoo
- Code: Select all
#$server and $port were previously extracted from an applet
$net=new IO::Socket::INET(Proto => 'tcp', PeerAddr => $server, PeerPort => $port);
unless (defined($net)) {
iprint "Can't connect!\n";
exit 1;
}
And to distinguish where the commands are coming from:
- Code: Select all
while (1) {
foreach my $i ($sel->can_read(0.05)) {
if ($i==$net) { #This is Yahoo commands
&handleop;
$net->flush;
} else { # This is WinBoard commands (both: from ICS Interaction W
sysread($i,$in,1) or exit;
if ($in eq "\n") {
handlecommand $buffer;
$buffer='';
$net->flush;
} elsif ($in ne "\r") {
$buffer.=$in;
}
}
}
}
Of course this just parts of the program...hope it helps.
PS I forgot:
- Code: Select all
my $sel=new IO::Select($stdin,$net);
I guess your best bet is to look at the code for yics which was written in "c"
Regards,
One that does not live to serve, does not deserve to live.