function Connect ($server="", $port=-1, $nick="", $user="", $rname="", $pass="")
{
if($server!="") $this->_server=$server;
if($port !="") $this->_port=$port;
if($nick !="") $this->_nick=$nick;
if($user !="") $this->_user=strtolower($user);
if($rname !="") $this->_rname=$rname;
$this->_svrpass=$pass;
if($this->_server == "") return $this->doerr("No server was specified!");
if($this->_port == -1) return $this->doerr("No port was specified!");
if($this->_nick=="") return $this->doerr("No nick was specified!");
if($this->_user=="") return $this->doerr("No user was specified!");
if($this->_rname=="") return $this->doerr("No realname was specified!");
if(!preg_match("/^[-a-zA-Z.0-9]{5,}$/",$this->_server)) return $this->doerr("Server is malformed!");
if(!is_numeric($this->_port) || $this->_port!=(int)$this->_port || $this->_port<1024 || $this->_port>65535) return $this->doerr("Specified port is out of range!");
if(!preg_match("/^[-_a-zA-Z0-9\[\]\|\\]]{1,30}$/",$this->_nick)) return $this->doerr("Nick is invalid!");
if(!preg_match("/^[_a-z]+$/",$this->_user)) return $this->doerr("User is invalid!");
if($this->_rname=="") $this->_rname="Web Integration Bot";
$this->dodebug("Connecting now...");
if(!($tsk=socket_create(AF_INET,SOCK_STREAM,SOL_TCP))) return $this->doerr("Socket error (".socket_strerror(socket_last_error()).")");
if(!(socket_bind($tsk,"0.0.0.0",0))) return $this->doerr("Bind error (".socket_strerror(socket_last_error()).")");
if(!(socket_connect($tsk,$this->_server,$this->_port))) return $this->doerr("Connect error (".socket_strerror(socket_last_error()).")");
$this->_sock=$tsk; unset($tsk);
if($e=socket_last_error($this->_sock) > 0)
{
return $this->doerr("Socket creation was successful, but an error has occured now: ".socket_strerror($e));
}
//socket_set_nonblock($this->_sock);
if($this->_svrpass != "")
$this->send_raw("PASS ".$this->_svrpass);
$this->send_raw("NICK ".$this->_nick);
$this->send_raw(sprintf("USER %s %s %s :%s",$this->_user,"gordo.ehpg.net",$this->_server,$this->_rname));
sleep(1);
return 1;
}