3 //The following class was created June 30th 2004 by Jeremy(pickle)
4 //This class is designed to handle a direct connection
17 function Dconnect($ip,$port)
19 if(!$this->connect($ip,$port))
21 sEcho("Connection failed constructor");
22 $this->connected=false;
25 $this->connected=true;
27 $this->lastMessage="";
28 $this->lastReceived="";
34 if(!$this->stuffToRead())
36 sEcho("Nothing to read");
37 $this->lastMessage=$this->lastReceived="";
41 $head=fread($this->sock,6);
44 sEcho("The direct connection has been closed");
47 $minihead=unpack("a4ver/nsize",$head);
48 if($minihead['size'] <=0)
50 $headerinfo=unpack("nchan/nsix/nzero/a6cookie/Npt1/Npt2/npt3/Nlen/Npt/npt0/ntype/Nzerom/a*sn",fread($this->sock,($minihead['size']-6)));
51 $allheader=array_merge($minihead,$headerinfo);
53 if($allheader['len']>0 && $allheader['len'] <= MAX_DIM_SIZE)
55 $left=$allheader['len'];
58 while(strlen($stuff) < $allheader['len'] && $nonin<3)
60 $stuffg=fread($this->sock,$left);
66 $left=$left - strlen($stuffg);
69 $data=unpack("a*decoded",$stuff);
72 else if($allheader['len'] > MAX_DIM_SIZE)
74 $data['decoded']="too big";
79 $all=array_merge($allheader,$data);
81 $this->lastReceived=$all;
82 $this->lastMessage=$all['decoded'];
84 //$function=$this->DimInf . "(\$all);";
90 function sendMessage($message,$sn)
92 //Make the "mini header"
93 $minihead=pack("a4n","ODC2",76);
94 $header=pack("nnna6NNnNNnnNa*",1,6,0,$this->cookie,0,0,0,strlen($message),0,0,96,0,$sn);
95 $bighead=$minihead . $header;
96 while(strlen($bighead)<76)
97 $bighead.=pack("c",0);
99 $tosend=$bighead . pack("a*",$message);
100 $w=array($this->sock);
101 stream_select($r=NULL,$w,$e=NULL,NULL);
103 fputs($this->sock,$tosend,strlen($tosend));
105 function stuffToRead()
107 //$info=stream_get_meta_data($this->sock);
109 $s=array($this->sock);
110 $changed=stream_select($s,$fds=NULL,$m=NULL,0,20000);
116 $this->connected=false;
117 return fclose($this->sock);
120 function connect($ip,$port)
122 $this->sock=fsockopen($ip,$port,$en,$es,3);
124 { sEcho("Connection failed");
133 class FileSendConnect
143 function FileSendConnect($ip,$port)
145 if(!$this->connect($ip,$port))
147 sEcho("Connection failed constructor");
148 $this->connected=false;
151 $this->connected=true;
153 $this->lastMessage="";
154 $this->lastReceived="";
160 if(!$this->stuffToRead())
162 sEcho("Nothing to read");
163 $this->lastMessage=$this->lastReceived="";
167 $minihead=unpack("a4ver/nsize",fread($this->sock,6));
168 if($minihead['size'] <=0)
170 $headerinfo=unpack("nchan/nsix/nzero/a6cookie/Npt1/Npt2/npt3/Nlen/Npt/npt0/ntype/Nzerom/a*sn",fread($this->sock,($minihead['size']-6)));
171 $allheader=array_merge($minihead,$headerinfo);
173 if($allheader['len']>0)
174 $data=unpack("a*decoded",fread($this->sock,$allheader['len']));
177 $all=array_merge($allheader,$data);
179 $this->lastReceived=$all;
180 $this->lastMessage=$all['decoded'];
182 //$function=$this->DimInf . "(\$all);";
188 function sendMessage($message,$sn)
190 //Make the "mini header"
191 $minihead=pack("a4n","ODC2",76);
192 $header=pack("nnna6NNnNNnnNa*",1,6,0,$this->cookie,0,0,0,strlen($message),0,0,96,0,$sn);
193 $bighead=$minihead . $header;
194 while(strlen($bighead)<76)
195 $bighead.=pack("c",0);
197 $tosend=$bighead . pack("a*",$message);
200 fwrite($this->sock,$tosend,strlen($tosend));
202 function stuffToRead()
204 //$info=stream_get_meta_data($this->sock);
206 $s=array($this->sock);
207 $changed=stream_select($s,$fds=NULL,$m=NULL,1);
213 $this->connected=false;
219 function connect($ip,$port)
221 $this->sock=fsockopen($ip,$port,$en,$es,3);
223 { sEcho("Connection failed to" . $ip . ":" . $port);