Code: Select all
use Socket;
Code: Select all
##
# $net->serverConnect(String host, int port)
# host: the host name/IP of the RO server to connect to.
# port: the port number of the RO server to connect to.
#
# Establish a connection to a Ragnarok Online server.
#
# This function is used internally by $net->checkConnection() and should not be used directly.
sub serverConnect {
my $self = shift;
my $host = shift;
my $port = shift;
my $return = 0;
Plugins::callHook('Network::connectTo', {
socket => \$self->{remote_socket},
return => \$return,
host => $host,
port => $port
});
return if ($return);
message TF("Connecting (%s:%s)... ", $host, $port), "connection";
$self->{remote_socket} = new IO::Socket::INET(
LocalAddr => $config{bindIp} || undef,
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp',
Timeout => 4);
setsockopt($self->{remote_socket}, &Socket::IPPROTO_TCP, &Socket::TCP_NODELAY, 1);
$self->{remote_socket}->setsockopt(&Socket::IPPROTO_TCP, &Socket::TCP_NODELAY, 1);
($self->{remote_socket} && inet_aton($self->{remote_socket}->peerhost()) eq inet_aton($host)) ?
message T("connected\n"), "connection" :
error(TF("couldn't connect: %s (error code %d)\n", "$!", int($!)), "connection");
if ($self->getState() != Network::NOT_CONNECTED) {
$incomingMessages->nextMessageMightBeAccountID();
}
}