Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. <?php
  2. /*=================con=======================*/
  3. $max_users = (int)2;
  4.  
  5. //--------------------------------------------
  6. $accessArray = array();
  7. $timeCodeArray = array();
  8.  
  9. $order = array("\r\n", "\n", "\r");
  10. $replace = '';
  11.  
  12.  
  13. /*=================fig=======================*/
  14.  
  15.  
  16. $action = $_POST['action'];
  17.  
  18.  
  19.  
  20. if($action != NULL)
  21. {
  22. $file = "users.txt";
  23. $thisFile = file($file);
  24. $accessCode = $_POST['accessCode'];
  25. $write_text = $_POST['sendText'];
  26.  
  27.  
  28. $i = 0;
  29. while ($i <= (count($thisFile))-1) {
  30.  
  31. if($i%2 == 0)
  32. {
  33. array_push($accessArray, str_replace($order, $replace, $thisFile[$i]));
  34. }
  35. else
  36. {
  37. array_push($timeCodeArray, str_replace($order, $replace, $thisFile[$i]));
  38. }
  39.  
  40. $i++;
  41.  
  42. }
  43.  
  44.  
  45.  
  46.  
  47. /*========================================================*/
  48.  
  49. if($action == "establish")
  50. {
  51. $file = "users.txt";
  52. $thisFile = file($file);
  53.  
  54. /*if statement, returning true or false*/
  55.  
  56. if(checkIfUsersGone($accessArray, $timeCodeArray,$thisFile,$max_users) == "true")
  57. {
  58. echo "joining";
  59.  
  60. $today = getdate();
  61. $now = ($today["hours"]*3600)+($today["minutes"]*60)+$today["seconds"]."\n";
  62.  
  63. $userJoin = $accessCode."\n".$now;
  64. $fp = fopen('users.txt', 'a+');
  65. fwrite($fp, $userJoin);
  66. fclose($fp);
  67.  
  68.  
  69.  
  70. }
  71. else
  72. {
  73. echo "full";
  74. }
  75.  
  76. }
  77.  
  78. if($action == "ping")
  79. {
  80.  
  81.  
  82. userPinged($thisFile,$accessCode);
  83.  
  84.  
  85. /*$order = array("\r\n", "\n", "\r");
  86. $replace = '';
  87. $today = getdate();
  88. $now = ($today["hours"]*3600)+($today["minutes"]*60)+$today["seconds"]."\n";*/
  89.  
  90. /*$fp = fopen('users.txt', 'w');
  91. fwrite($fp, $thisFile[0].$thisFile[1].$thisFile[2].$thisFile[3]);
  92. fclose($fp);*/
  93.  
  94.  
  95.  
  96. }
  97.  
  98. /*========================================================*/
  99.  
  100. }
  101. else
  102. {
  103. echo "urdoingitwrong";
  104. //echo $accessCode;
  105. }
  106.  
  107.  
  108.  
  109. function checkIfUsersGone($aaa, $ttt, $mmm, $max)
  110. {
  111.  
  112.  
  113. $i = 0;
  114. $today = getdate();
  115. $now = (int)($today["hours"]*3600)+($today["minutes"]*60)+$today["seconds"];
  116. $saveString;
  117. $activeUsers = 0;
  118.  
  119. while ($i <= (count($mmm))-1) {
  120.  
  121.  
  122.  
  123. if($i%2 == 0)
  124. {
  125.  
  126. if($now-$ttt[($i/2)] > 10){}
  127. elseif($now-$ttt[($i/2)] < -100) {}
  128. else{$saveString .= $mmm[$i].$mmm[$i+1];$activeUsers .= 1;};
  129.  
  130.  
  131. }
  132. else
  133. {
  134. }
  135.  
  136. $i++;
  137.  
  138. }
  139.  
  140.  
  141. $fp = fopen('users.txt', 'w+');
  142. fwrite($fp, $saveString);
  143. fclose($fp);
  144.  
  145.  
  146. if((int)$activeUsers < (int)$max)
  147. {
  148. return "true";
  149. }
  150.  
  151. else
  152. {
  153. return "false";
  154. }
  155.  
  156. }
  157.  
  158. function userPinged($mmm, $aaa)
  159. {
  160.  
  161. $order = array("\r\n", "\n", "\r");
  162. $replace = '';
  163.  
  164. //--------
  165. $i = 0;
  166. $saveString;
  167.  
  168. $today = getdate();
  169. $now = ($today["hours"]*3600)+($today["minutes"]*60)+$today["seconds"]."\n";
  170.  
  171.  
  172.  
  173. while ($i <= (count($mmm))-1) {
  174.  
  175.  
  176.  
  177. if($i%2 == 0)
  178. {
  179.  
  180. if(str_replace($order, $replace, $mmm[$i]) == $aaa)
  181. {
  182. $saveString .= $mmm[$i].$now;};
  183. }
  184.  
  185. else
  186. {
  187. $saveString .= $mmm[$i].$mmm[$i+1];};
  188. }
  189.  
  190. }
  191.  
  192.  
  193.  
  194.  
  195.  
  196. $i++;
  197.  
  198. }
  199.  
  200. echo "\n".$saveString;
  201.  
  202. }
  203.  
  204.  
  205.  
  206. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement