login  Naam:   Wachtwoord: 
Registreer je!
 Forum

fsockopen

Offline alexb - 06/02/2006 16:58
Avatar van alexbNieuw lid ik probeer een gameserver status te maken dus udp connectie
maar ik krijg alleen maar dat die online is terwijl die offline is :S
de ip + poort krijgt die uit db
dit is het script:

<?php
$fp = fsockopen("udp://$gameip",$gamepoort, &$errno, &$errstr, 2);
if($fp){
echo 'Gameserver is online';
fclose($fp);
}
else{
echo 'Gameserver is offline';
}
?>

kan iemand zeggen wat er nou fout aan is ?:$

7 antwoorden

Gesponsorde links
Offline Ontani - 06/02/2006 17:07
Avatar van Ontani Gouden medailleGouden medailleGouden medailleGouden medaille

-1
ik zou $fp eens echoeen wat dit teruggeeft.
Offline alexb - 06/02/2006 17:16 (laatste wijziging 06/02/2006 17:16)
Avatar van alexb Nieuw lid Resource id #6 krijg ik dan:s
Offline ikkedikke - 07/02/2006 10:14
Avatar van ikkedikke PHP expert udp werkt op een andere manier dan tcp..
bij tcp is het bij alles wat je stuurt zo dat je terug krijgt of het aangekomen is.. zo gaat dat ook met verbinden: je host maakt gewoon de verbinding en gaat er vanuit dat die er is.. je krijgt dan altijd true..
(Ik dacht dat het zo zat in ieder geval)
Offline alexb - 07/02/2006 13:48 (laatste wijziging 07/02/2006 13:55)
Avatar van alexb Nieuw lid
  1. <?
  2.  
  3. $ip = '12.34.56.78';
  4. $port = 27015;
  5. $rconpwd = 'hard2guess';
  6. $ping = 25;//miliseconds
  7.  
  8.  
  9. class SlincherWebRCON
  10. {
  11. var $_pings = array();
  12. var $_handle;
  13. var $_rconpassword;
  14. var $_challenge;
  15. var $_status = array('hostname'=>'','version'=>'','VAC'=>'','host'=>'','port'=>'','map'=>'','password'=>'','players'=>'');
  16. var $_players = array();
  17. var $_timeout = 50;//50 ms waiting is really long
  18. function raw_rcon($string)
  19. {
  20. return $this->rcon_to_string($this->write_data('rcon '.$this->_challenge.' "'.$this->_rconpassword.'" '.$string));
  21. // most output is chr 108 , hex = 6c , that means that something has been executed
  22. }
  23. function connect($host,$port,$rconpassword,$timeout=50)
  24. {
  25. $this->_handle=fsockopen('udp://'.$host,$port);
  26. stream_set_timeout($this->_handle,0,$this->_timeout);
  27. $this->_rconpassword=$rconpassword;
  28. $this->_timeout=$timeout;
  29. $this->_challenge=$this->challengercon_to_rcon($this->rcon_to_string($this->write_data('challenge rcon')));
  30. }
  31. function rcon_to_string($string)
  32. {
  33. return trim(substr($string,4,-1));
  34. }
  35. function challengercon_to_rcon($string)
  36. {
  37. return substr($string,15);
  38. }
  39. function write_data($string )
  40. {
  41. $string=str_replace(chr(0),'',$string);$string=str_replace(chr(255),'',$string);
  42. fwrite($this->_handle,chr(255).chr(255).chr(255).chr(255).$string.chr(0));
  43.  
  44. $i=0;$gets.='';
  45. while(strlen($gets)==0)
  46. {
  47. if($i<$this->_timeout)
  48. {
  49. $gets.=fgets($this->_handle,2);
  50. usleep(1);
  51. $i++;
  52. }
  53. else
  54. {
  55. return 0;
  56. }
  57. }
  58. $this->_pings[] = $i;
  59. $strlen=0;
  60. while($strlen<strlen($gets))
  61. {
  62. $togo=socket_get_status($this->_handle);
  63. $strlen=strlen($gets);
  64. $gets.=fgets($this->_handle,$togo['unread_bytes']+1);
  65. }
  66. return $gets;
  67. }
  68. function get_status()
  69. {
  70. preg_match('@^l"sv_password" is "([^"]*)"$@',$this->rcon_to_string($this->write_data('rcon '.$this->_challenge.' "'.$this->_rconpassword.'" sv_password')),$pass);$this->_status['password']=$pass[1];unset($pass);
  71.  
  72. $raw = explode("\n",$this->rcon_to_string($this->write_data('rcon '.$this->_challenge.' "'.$this->_rconpassword.'" status')));
  73.  
  74. foreach($raw as $num=>$temp)
  75. {
  76. if(preg_match('#^lhostname[ ]*: (.*)$#',$temp,$temp))
  77. {
  78. $this->_status['hostname'] = $temp[1];
  79. unset($raw[$num]);
  80. }
  81. unset($temp);
  82. }
  83.  
  84. foreach($raw as $num=>$temp)
  85. {
  86. if(preg_match('#^version[ ]*: ([^ ]+ [0-9]+) (.+)$#',$temp,$temp))
  87. {
  88. $this->_status['version'] = $temp[1];
  89. $this->_status['VAC'] = $temp[2];
  90. unset($raw[$num]);
  91. }
  92. unset($temp);
  93. }
  94.  
  95. foreach($raw as $num=>$temp)
  96. {
  97. if(preg_match('#^tcp/ip[ ]*: (.+):(.+)$#',$temp,$temp))
  98. {
  99. $this->_status['host'] = $temp[1];
  100. $this->_status['port'] = $temp[2];
  101. unset($raw[$num]);
  102. }
  103. unset($temp);
  104. }
  105.  
  106. foreach($raw as $num=>$temp)
  107. {
  108. if(preg_match('#^map[ ]*: (.+) at: [0-9\.]+ x, [0-9\.]+ y, [0-9\.]+ z$#',$temp,$temp))
  109. {
  110. $this->_status['map'] = $temp[1];
  111. unset($raw[$num]);
  112. }
  113. unset($temp);
  114. }
  115.  
  116. foreach($raw as $num=>$temp)
  117. {
  118. if(preg_match('#^players[ ]*: ([0-9]+) active \(([0-9]+) max\)$#',$temp,$temp))
  119. {
  120. $this->_status['players'] = array('online'=>$temp[1],'max'=>$temp[2]);
  121. unset($raw[$num]);
  122. }
  123. unset($temp);
  124. }
  125.  
  126. foreach($raw as $num=>$temp)
  127. {
  128. if(preg_match('@^#[ ]*[0-9]+[ ]+"([^"]+)"[ ]*([0-9]+)[ ]+([^ ]+)[ ]+[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]+([^ ]+)$@',$temp,$matches))
  129. {
  130. $matches[4] = explode(':',$matches[4]);$matches[4] = $matches[4][0];
  131. $this->_players[]=array('name'=>$matches[1],'kick_id'=>'#'.$matches[2],'ban_id'=>$matches[3],'ip'=>$matches[4]);
  132. unset($raw[$num]);
  133. }
  134. }
  135. }
  136. }
  137.  
  138. $RCON = new SlincherWebRCON();
  139. $RCON->connect($ip,$port,$rconpwd,$ping);
  140.  
  141. if($RCON->_challenge)
  142. {
  143. if($_FILES['postconfig'])
  144. {
  145. $contents = explode("\n",file_get_contents($_FILES['postconfig']['tmp_name']));
  146. $clean=array();
  147. foreach($contents as $n=>$row)
  148. {
  149. $row=trim($row," \t\n\r\0\x0B;");
  150. $i=0;
  151. $open=2;
  152. while($i<strlen($row))
  153. {
  154. if($row{$i} == '"')
  155. {
  156. if($open==1)
  157. {
  158. $open=2;
  159. }
  160. elseif($open==2)
  161. {
  162. $open=1;
  163. }
  164. }
  165. elseif($row{$i} == ';')
  166. {
  167. if($open==2)
  168. {
  169. $row{$i} = "\n";
  170. }
  171. }
  172. $i++;
  173. }
  174. if(strlen($row)>0)
  175. {
  176. foreach(explode("\n",$row) as $cmd)
  177. {
  178. if(preg_match('@^rcon(.+)$@i',$row,$match))
  179. {
  180. $cmd = ltrim($match[1]);
  181. }
  182. $clean[] = $cmd;
  183. unset($match);
  184. }
  185. }
  186. unset($cmd);
  187. }
  188. unset($row);unset($n);
  189. foreach($clean as $exec)
  190. {
  191. $q = $RCON->raw_rcon($exec);
  192. if($q)
  193. {
  194. echo '<LI> '.htmlspecialchars($exec).' is succesvol uitgevoerd.';
  195. }
  196. unset($q);
  197. }
  198. echo '<BR><BR>Config is uitgevoerd.';
  199. }
  200. if($_POST['say'])
  201. {
  202. $q = $RCON->raw_rcon('say '.stripslashes($_POST['say']));
  203. if($q{0} == 'l')
  204. {
  205. echo '<LI> Chat is uitgevoerd.<BR><BR>';
  206. }
  207. else
  208. {
  209. echo '<LI> Chat is <B>niet</B> uitgevoerd.<BR><BR>';
  210. }
  211. unset($q);
  212. }
  213. if($_POST['rawrcon'])
  214. {
  215. $q = $RCON->raw_rcon(stripslashes($_POST['rawrcon']));
  216. if($q{0} == 'l')
  217. {
  218. echo '<LI> RCON Commando is uitgevoerd.<BR><BR>';
  219. }
  220. else
  221. {
  222. echo '<LI> RCON Commando is <B>niet</B> uitgevoerd.<BR><BR>';
  223. }
  224. unset($q);
  225. }
  226. if($_POST['restartround'] == '1')
  227. {
  228. $q = $RCON->raw_rcon('sv_restartround 1');
  229. if($q{0} == 'l')
  230. {
  231. echo '<LI> RestartRound is uitgevoerd.<BR><BR>';
  232. }
  233. else
  234. {
  235. echo '<LI> RestartRound is <B>niet</B> uitgevoerd.<BR><BR>';
  236. }
  237. unset($q);
  238. }
  239. if($_POST['hostname'])
  240. {
  241. $q = $RCON->raw_rcon('hostname "'.stripslashes($_POST['hostname'].'"'));
  242. if($q{0} == 'l')
  243. {
  244. echo '<LI> Hostname is veranderd.<BR><BR>';
  245. }
  246. else
  247. {
  248. echo '<LI> Hostname is <B>niet</B> veranderd.<BR><BR>';
  249. }
  250. unset($q);
  251. }
  252. if($_POST['password'])
  253. {
  254. $q = $RCON->raw_rcon('sv_password "'.stripslashes($_POST['password'].'"'));
  255. if($q{0} == 'l')
  256. {
  257. echo '<LI> Wachtwoord is veranderd.<BR><BR>';
  258. }
  259. else
  260. {
  261. echo '<LI> Wachtwoord is <B>niet</B> veranderd.<BR><BR>';
  262. }
  263. unset($q);
  264. }
  265. if($_POST['changelevel'])
  266. {
  267. $q = $RCON->raw_rcon('changelevel '.stripslashes($_POST['changelevel']));
  268. echo 'De server zal niet reageren, omdat de map gewisseld word.';
  269. }
  270. if(($_POST['player_action'] == 'kick') AND $_POST['kick_id'])
  271. {
  272. $q = $RCON->raw_rcon('kick '.stripslashes($_POST['kick_id']));
  273. if($q{0} == 'l')
  274. {
  275. echo '<LI> Kick is uitgevoerd.<BR><BR>';
  276. }
  277. else
  278. {
  279. echo '<LI> Kick is <B>niet</B> veranderd.<BR><BR>';
  280. }
  281. unset($q);
  282. }
  283. elseif(($_POST['player_action'] == 'id_ip_ban') AND $_POST['ban_id'] AND $_POST['ban_ip'])
  284. {
  285. $q = $RCON->raw_rcon('banid '.stripslashes($_POST['ban_time']).' '.stripslashes($_POST['ban_id']).' kick');
  286. $RCON->raw_rcon('addip '.stripslashes($_POST['ban_time']).' '.stripslashes($_POST['ban_ip']));
  287. $RCON->raw_rcon('writeid');
  288. $RCON->raw_rcon('writeip');
  289. if($q{0} == 'l')
  290. {
  291. echo '<LI> SteamID&IP-Ban is uitgevoerd.<BR><BR>';
  292. }
  293. else
  294. {
  295. echo '<LI> SteamID&IP-Ban is <B>niet</B> veranderd.<BR><BR>';
  296. }
  297. unset($q);
  298. }
  299. elseif(($_POST['player_action'] == 'id_ban') AND $_POST['ban_id'])
  300. {
  301. $q = $RCON->raw_rcon('banid '.stripslashes($_POST['ban_time']).' '.stripslashes($_POST['ban_id']).' kick');
  302. $RCON->raw_rcon('writeid');
  303. if($q{0} == 'l')
  304. {
  305. echo '<LI> SteamID-Ban is uitgevoerd.<BR><BR>';
  306. }
  307. else
  308. {
  309. echo '<LI> SteamID-Ban is <B>niet</B> veranderd.<BR><BR>';
  310. }
  311. unset($q);
  312. }
  313. elseif(($_POST['player_action'] == 'ip_ban') AND $_POST['ban_ip'])
  314. {
  315. $RCON->raw_rcon('addip '.stripslashes($_POST['ban_time']).' '.stripslashes($_POST['ban_ip']));
  316. $RCON->raw_rcon('writeip');
  317. if($q{0} == 'l')
  318. {
  319. echo '<LI> IP-Ban is uitgevoerd.<BR><BR>';
  320. }
  321. else
  322. {
  323. echo '<LI> IP-Ban is <B>niet</B> veranderd.<BR><BR>';
  324. }
  325. unset($q);
  326. }
  327.  
  328. $RCON->get_status();
  329.  
  330. echo '<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 STYLE="font-family:verdana;font-size:12"><TR><TD>#Info</TD><TD>&nbsp;</TD></TR>';
  331. echo '<TR><TD>protocol-versie</TD><TD>&nbsp;'.$RCON->_status['version'].'</TD></TR>';
  332. echo '<TR><TD>VALVe Anti Cheat</TD><TD>&nbsp;'.$RCON->_status['VAC'].'</TD></TR>';
  333. echo '<TR><TD>Hostname:Port</TD><TD>&nbsp;'.$RCON->_status['host'].':'.$RCON->_status['port'].'</TD></TR>';
  334. echo '<TR><TD>Map</TD><TD>&nbsp;'.$RCON->_status['map'].'</TD></TR>';
  335. echo '<TR><TD>Players</TD><TD>&nbsp;'.$RCON->_status['players']['online'].'/'.$RCON->_status['players']['max'].'</TD></TR>';
  336. echo '<TR><TD>Latency</TD><TD>&nbsp;'.round(array_sum($RCON->_pings)/count($RCON->_pings),0).' ms</TD></TR>';
  337. echo '</TABLE></FONT><BR>';
  338.  
  339. echo '<FORM ACTION="'.$_SERVER['PHP_SELF'].'" METHOD=POST><INPUT TYPE=SUBMIT VALUE="Refresh" STYLE="width:125;font-size:11;font-family:verdana;"></FORM>';
  340.  
  341. echo '<FORM ACTION="'.$_SERVER['PHP_SELF'].'" METHOD=POST><INPUT TYPE=HIDDEN NAME="restartround" VALUE=1><INPUT TYPE=SUBMIT VALUE="Restart Round" STYLE="width:125;font-size:11;font-family:verdana;"></FORM>';
  342.  
  343. echo '<FORM enctype="multipart/form-data" ACTION="'.$_SERVER['PHP_SELF'].'" METHOD=POST><INPUT TYPE=FILE NAME="postconfig" VALUE=1><INPUT TYPE=SUBMIT VALUE="Upload Config!" STYLE="width:125;font-size:11;font-family:verdana;"></FORM>';
  344.  
  345. echo '<FORM ACTION="'.$_SERVER['PHP_SELF'].'" METHOD=POST><INPUT TYPE=TEXT VALUE="say [WEB-RCON door Slincher!]" STYLE="width:125;font-size:11;font-family:verdana;" NAME="rawrcon"><INPUT TYPE=SUBMIT VALUE="RCON Commando" STYLE="width:125;font-size:11;font-family:verdana;"></FORM>';
  346.  
  347. echo '<FORM ACTION="'.$_SERVER['PHP_SELF'].'" METHOD=POST><INPUT TYPE=TEXT STYLE="width:125;font-size:11;font-family:verdana;" NAME="say"><INPUT TYPE=SUBMIT VALUE="Chat!" STYLE="width:125;font-size:11;font-family:verdana;"></FORM>';
  348.  
  349. echo '<FORM ACTION="'.$_SERVER['PHP_SELF'].'" METHOD=POST><INPUT TYPE=TEXT VALUE="'.$RCON->_status['hostname'].'" STYLE="width:125;font-size:11;font-family:verdana;" NAME="hostname"><INPUT TYPE=SUBMIT VALUE="Verander Hostname" STYLE="width:125;font-size:11;font-family:verdana;"></FORM>';
  350.  
  351. echo '<FORM ACTION="'.$_SERVER['PHP_SELF'].'" METHOD=POST><INPUT TYPE=TEXT VALUE="'.$RCON->_status['password'].'" STYLE="width:125;font-size:11;font-family:verdana;" NAME="password"><INPUT TYPE=SUBMIT VALUE="Password" STYLE="width:125;font-size:11;font-family:verdana;"></FORM>';
  352.  
  353. echo '<FORM ACTION="'.$_SERVER['PHP_SELF'].'" METHOD=POST><SELECT NAME=changelevel STYLE="width:125;font-size:11;font-family:verdana;">';
  354. $maps=array('de_nuke','de_dust2','de_inferno','de_cpl_mill','de_cbble','de_dust','aim_ak-colt');
  355. sort($maps);
  356. foreach($maps as $map)
  357. {
  358. echo '<OPTION VALUE="'.$map.'">'.$map.'</OPTION>';
  359. }
  360. unset($maps);unset($map);
  361. echo '</SELECT><INPUT TYPE=SUBMIT VALUE="Verander Map" STYLE="width:125;font-size:11;font-family:verdana;"></FORM>';
  362.  
  363. echo '<BR><B>Spelers:</B><BR>';
  364. foreach($RCON->_players as $player)
  365. {
  366. echo "\r\n".'<FORM ACTION="'.$_SERVER['PHP_SELF'].'" METHOD=POST><NOBR><INPUT TYPE=HIDDEN NAME=kick_id VALUE="'.$player['kick_id'].'"><INPUT TYPE=HIDDEN NAME=ban_id VALUE="'.$player['ban_id'].'"><INPUT TYPE=HIDDEN NAME=ban_ip VALUE="'.$player['ip'].'"><SELECT STYLE="width:125;font-size:11;font-family:verdana;" NAME="player_action"><OPTION VALUE="kick">Kick</OPTION><OPTION VALUE="id_ip_ban">SteamID&IP Ban</OPTION><OPTION VALUE="id_ban">SteamID Ban</OPTION><OPTION VALUE="ip_ban">IP Ban</OPTION></SELECT><SELECT STYLE="width:125;font-size:11;font-family:verdana;" NAME="ban_time"><OPTION VALUE="0">permanent (Ban Only)</OPTION><OPTION VALUE="1">1 minuut (Ban Only)</OPTION><OPTION VALUE="5">5 minuten (Ban Only)</OPTION><OPTION VALUE="30">half-uur (Ban Only)</OPTION><OPTION VALUE="60">1 uur (Ban Only)</OPTION><OPTION VALUE="240">4 uur (Ban Only)</OPTION><OPTION VALUE="1440">1 dag (Ban Only)</OPTION><OPTION VALUE="4320">3 dagen (Ban Only)</OPTION><OPTION VALUE="10080">1 week (Ban Only)</OPTION><OPTION VALUE="43200">1 maand (Ban Only)</OPTION><OPTION VALUE="525600">1 jaar (Ban Only)</OPTION></SELECT><INPUT TYPE=SUBMIT VALUE="'.htmlspecialchars($player['name']).'" STYLE="width:125;font-size:11;font-family:verdana;"></NOBR></FORM>';
  367. }
  368. }
  369. else
  370. {
  371. echo 'Kan niet met de server verbinden.';
  372. }
  373. ?>

heb ik gevonden bij script site maar die werkt wel gewoon met die udp functie dus ik vind het behoorlijk vaag
Offline Stijn - 07/02/2006 18:07
Avatar van Stijn PHP expert line 141: $RCON->_challenge

Ik heb gelezen dat $_varname nooit van buitenaf aangeroepen kan worden....
Offline alexb - 07/02/2006 22:19
Avatar van alexb Nieuw lid hoe moet ik het dan doen ?
Offline bdeh_af - 07/02/2006 22:41
Avatar van bdeh_af PHP interesse UDP maakt nooit een verbinding met iets. Het werpt boodschappen naar een server en ontvangt boodschappen op een bepaalde poort.

De enige manier is denk ik een packet sturen naar de server en wachten op een reactie?
Gesponsorde links
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.266s