Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.63 KB | None | 0 0
  1. <?php
  2.  
  3. function playerfix($parameter,$key){
  4.  
  5.  
  6.  
  7. if(!is_numeric($parameter)){// Between two values
  8. $split = strpos($parameter,"-");
  9. $low = substr($parameter, 0, strlen($parameter)-$split-1);
  10. $high = substr($parameter, $split+1);
  11.  
  12. if ($low > $high){
  13. $temp = $high;
  14. $high = $low;
  15. $low = $temp;
  16. }
  17.  
  18. $newlist = " ".$key." <=".$high." AND ".$key." >=".$low." ";
  19.  
  20. return $newlist;}
  21. else{
  22. if($parameter >= 0){ //One Positive Value
  23.  
  24. $newlist = " ".$key." >=".$parameter." ";
  25.  
  26. return $newlist;}
  27. else{ //One negative value
  28. $newlist = " ".$key." <=".abs($parameter)." ";
  29.  
  30. return $newlist;
  31. }
  32.  
  33. }
  34. }
  35.  
  36.  
  37. function renameup($input){
  38.  
  39. switch($input){
  40. default: $out = $input; break;
  41. case "Online": $out = 0; break;
  42. case "Queued for Upload": $out = 1; break;
  43. case "Queued for Archival": $out = 2; break;
  44. case "Archived": $out = 3; break;
  45. }
  46. return $out;
  47. }
  48.  
  49. function renamest($input){
  50. $out = array();
  51.  
  52. switch(strtolower($input[0])){
  53. default: $out[0] = $input[0]; break;
  54. case "isoladicapraia": $out[0] = "Capraia"; break;
  55. case "plr_mana": $out[0] = "Mana Island"; break;
  56. case "provinggrounds_pmc": $out[0] = "Proving Grounds"; break;
  57. case "desert_e": $out[0] = "Desert"; break;
  58. case "fallujah": $out[0] = "Fallujah"; break;
  59. case "namalsk": $out[0] = "Namalsk"; break;
  60. case "chernarus": $out[0] = "Chernarus"; break;
  61. case "fdf_isle1_a": $out[0] = "Podagorsk"; break;
  62. case "eden": $out[0] = "Everon"; break;
  63. case "afghan_village": $out[0] = "Afghan Village"; break;
  64. case "razani": $out[0] = "Razani"; break;
  65. case "schmalfelden": $out[0] = "Schmalfelden"; break;
  66. case "porto": $out[0] = "Porto"; break;
  67. case "intro": $out[0] = "Rahmadi"; break;
  68. case "sara": $out[0] = "Sahrani"; break;
  69. case "sara_dbe1": $out[0] = "United Sahrani"; break;
  70. case "saralite": $out[0] = "South Sahrani"; break;
  71. case "quishkibrul": $out[0] = "Quesh-Kibrul"; break;
  72. case "sbrodj": $out[0] = "Sbrodj"; break;
  73. case "aiaktalik": $out[0] = "Aiaktalik"; break;
  74. case "celle": $out[0] = "Celle"; break;
  75. case "thirskw": $out[0] = "Thirsk Winter"; break;
  76. case "mbg_kellu": $out[0] = "Kellu"; break;
  77. case "isladuala": $out[0] = "Isla Duala"; break;
  78. case "shapur_baf": $out[0] = "Shapur"; break;
  79. case "razoreniya": $out[0] = "Razoneniya"; break;
  80. case "utes": $out[0] = "Utes"; break;
  81. }
  82. switch($input[1]){
  83. default: $out[1] = $input[1]; break;
  84. case 0: $out[1] = "Online"; break;
  85. case 1: $out[1] = "Queued for Upload"; break;
  86. case 2: $out[1] = "Queued for Archival"; break;
  87. case 3: $out[1] = "Archived"; break;
  88. }
  89. return $out;
  90. }
  91.  
  92.  
  93. /*====================================
  94. SQL List Function
  95. ======================================*/
  96. function sql_list($u = NULL){
  97. $where = 'WHERE ';
  98. $end = 'DESC';
  99. if($u == NULL){
  100. $where = "WHERE up = 0";
  101. //$where = "WHERE island = 'plr_mana'";
  102. }else{
  103.  
  104.  
  105. $limit = count($u);
  106. $i = 1;
  107.  
  108. if(array_key_exists('count', $u)){
  109. $limit--;}
  110. if(array_key_exists('date', $u)){
  111. $limit--;}
  112.  
  113.  
  114.  
  115. foreach ($u as $key => $val){
  116.  
  117. if($key != 'players' AND $key != 'date' AND $key != 'count'){
  118. $where .= $key." = '".$val."'";
  119. if($i < $limit){
  120. $where .= " AND ";}
  121. $i++;}
  122.  
  123. elseif($key == 'players'){
  124. $where .= playerfix($val,$key);
  125. if($i < $limit){
  126. $where .= " AND ";}
  127. $i++;
  128. }
  129.  
  130. elseif($key == 'date'){
  131. $end = $val;}
  132. elseif($key == 'count'){
  133. $end .= ', count '.$val;}
  134.  
  135. }
  136. if(!array_key_exists('author', $u) AND !array_key_exists('type', $u) AND !array_key_exists('dac', $u) AND !array_key_exists('players', $u) AND !array_key_exists('up', $u) AND !array_key_exists('island', $u)){
  137. $where = '';
  138. }
  139.  
  140. }
  141.  
  142. $string = "SELECT * from st_mission ".$where." ORDER by island ASC, date ".$end;
  143.  
  144. $sql = mysql_query($string);
  145.  
  146. $last = '';
  147. $i = 0;
  148. $j = 0;
  149. $body = '';
  150.  
  151. /* $body .= '<br><br><center><div class="navbar" style="width: 818px; font-size: 1.25em; line-height: 1.5em;"><div class="inner" style="text-align: left;">';
  152. $body .= '<span class="corners-top"><span></span></span>'."\n";
  153. $body .= '<div>';
  154. $body .= '</div>';
  155. $body .= '<span class="corners-bottom"><span></span></span></div></div></center>'."\n"; */
  156.  
  157. while($result = mysql_fetch_assoc($sql)){
  158.  
  159. $fix = renamest(array($result['island'],$result['up']));
  160. $current = $fix[0];
  161.  
  162. $mission = str_replace('.pbo','',$result['filename']);
  163. $end = strrpos($mission,".");
  164. $mission = substr($mission,0,$end);
  165. //$body .= $mission;
  166. $counter = mysql_query("SELECT * FROM missionhistory WHERE mission = '".$mission."'");
  167. $count = mysql_num_rows($counter);
  168. if($current != $last){
  169. if($i != 0){
  170. $body .= '</table></div>';
  171. $body .= '<span class="corners-bottom"><span></span></span></div></div></center>'."\n";
  172. }
  173. $body .= '<br><br><center><div class="navbar" style="width: 818px;"><div class="inner" style="text-align: left;">';
  174. $body .= '<span class="corners-top"><span></span></span>'."\n";
  175. $body .= "<span style='width: 100%; font-size: 1.1em;'>";
  176. $body .= "<span style='color: #ffffff; float:right;'><strong>".$fix[1]."</strong></span>";
  177. $body .= "<span style='color: #ffffff;'><strong><a href=#".$result['island']." name=".$result['island'].">".$current."</a></strong></span><hr noshadow />";
  178. $body .= "</span>";
  179. $body .= '<div>';
  180. }
  181. $zebra = 'style="background: #524c43;" ';
  182. if ($j % 2 != 0) $zebra = 'style="background: #3f3d33;" ';
  183. $j++;
  184.  
  185. $body .= "<table cellpadding=0 cellspacing=0 style='font-size: 1.1em; width:100%;'>";
  186. $body .= "<tr $zebra>";
  187. $body .= "<td style='padding-right: 1em; width: 5%;' nowrap>" . date('Y-m-d h:i', $result['date']) . " " . "</td>";
  188. $body .= '<td style="padding-right: 1em; color:#aaaaaa;" width: 70%;><a class="playerList" href="/missions/Missions/'.$result['filename'].'">'.$result['framework'].'_'.$result['type'].'_'.$result['players'].'_'.str_replace(" ","_",trim($result['name']));
  189.  
  190. $body .= "<span><div style='color: #ffffff;'>\n";
  191. $body .= "<strong>" . $result['name'] . "</strong>, ";
  192. $body .= $fix[0]. "<br />\n";
  193.  
  194. $body .= $result['type'] . " - ";
  195.  
  196. $body .= " " . $result['players'] . "<br />\n";
  197. $body .= "<br /></div>";
  198. $body .= "<div style='color: #aaaaaa;'>". $result['description']. "</div><br />";
  199. $body .= $result['framework'];
  200. if($result['dac'] == 1){
  201. $body .= '<i> - DAC Enabled</i>';
  202. }
  203. $body .= "</span></a></td>";
  204.  
  205.  
  206.  
  207. $body .= "<td style='padding-right: 1em; width: 5%;' nowrap>Played " . $count . " time(s)" . "</td>";
  208. $body .= "<td style='padding-right: 1em; width: 20%;'>".$result['author']."</td>";
  209. $body .= "</tr>";
  210. $last = $current;
  211. $i++;
  212. }
  213. $body .= '</table>';
  214. $body .= '</div>';
  215. $body .= '<span class="corners-bottom"><span></span></span></div></div></center>'."\n";
  216.  
  217. //$body = $where;
  218.  
  219. return $body;
  220. //return $string;
  221. }
  222. /*====================================*/
  223.  
  224. /*====================================
  225. SQL Check Function
  226. ======================================*/
  227. function sql_check($name = NULL){
  228. if($name != NULL){
  229. $sql = mysql_query("SELECT * FROM st_mission WHERE filename = '".$name."'");}
  230. else{
  231. $sql = mysql_query("SELECT * FROM st_mission");}
  232. return mysql_num_rows($sql);
  233. }
  234. /*====================================*/
  235.  
  236. /*====================================
  237. SQL Check Function
  238. ======================================*/
  239. function sql_keycheck($key,$val){
  240. $sql = mysql_query("SELECT * FROM st_mission WHERE ".$key." = '".$val."'");
  241. return mysql_num_rows($sql);
  242. }
  243. /*====================================*/
  244.  
  245. /*====================================
  246. SQL Update Function
  247. ======================================*/
  248. function sql_update($file,$up,$info = NULL){
  249.  
  250. //echo $file.' '.$up.' '.$info;
  251. $page = $user->data['username'];
  252.  
  253. if(sql_check(basename($file)) == 0 or $info != NULL){
  254. //echo "I'm adding a new entry";
  255. //print_r($info);
  256. //Add entry to database
  257. if(mysql_query("
  258. INSERT INTO st_mission
  259. (
  260. author,
  261. filename,
  262. name,
  263. description,
  264. type,
  265. players,
  266. date,
  267. up,
  268. island,
  269. framework,
  270. dac,
  271. count)
  272. VALUES
  273. ('".addslashes($info['author'])."',
  274. '".basename($file)."',
  275. '".addslashes($info['name'])."',
  276. '".addslashes($info['description'])."',
  277. '".addslashes($info['type'])."',
  278. ".addslashes($info['players']).",
  279. '".time()."',
  280. '".$up."',
  281. '".addslashes($info['island'])."',
  282. '".addslashes($info['framework'])."',
  283. '".$info['dac']."',
  284. 0
  285. ) ")){
  286. }else{
  287. $page = "There was an error adding this entry to the database. Most likely the naming convention wasn't followed.<br><br>The mission has NOT been uploaded.";
  288. }}
  289. else{
  290. //echo "I should be updating an existing entry.";
  291. mysql_query("UPDATE st_mission SET up = '".$up."' WHERE filename = '".basename($file)."'");}
  292. return $page;
  293. }
  294. /*====================================*/
  295.  
  296.  
  297.  
  298. /*====================================
  299. Upload to webserver
  300. ======================================*/
  301. function upfile($gameState,$user_st,$np){
  302.  
  303. if(!empty($_FILES['uploadedfile'])){
  304. $page = '';
  305. $type = array("pbo");
  306. $info = pathinfo( $_FILES['uploadedfile']['name']);
  307. $name = basename( $_FILES['uploadedfile']['name']);
  308. if (!in_array($info['extension'],$type)){
  309. $page = "Invalid filetype. Only pbo are allowed";
  310. }
  311. else{
  312. // Valid filetype, check in sql database to see if the mission already exists
  313. $checker = sql_check($name);
  314. if($checker > 0){
  315. $page = "This mission has already been uploaded.";
  316. }else{
  317. $target_path = "./missions/Missions/"; //This is where the temporary directory will be.
  318. $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
  319.  
  320. if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
  321. //echo "The file ".basename( $_FILES['uploadedfile']['name'])." has been uploaded to the Temporary Missions directory.<br><br>";
  322. $pbo = de_pbo($target_path,$user_st);
  323. //print_r($pbo);
  324. $page = sql_update($target_path,3,$pbo);
  325. $page .= ftp_upload($target_path,$gameState,$np);
  326. }}}}
  327. else{
  328. $page = "No Files";
  329. }
  330. return $page;
  331. }
  332. /*====================================*/
  333.  
  334.  
  335.  
  336. /*====================================
  337. Upload to FTP
  338. ======================================*/
  339. function ftp_upload($file,$gameState,$np){
  340. $page = '';
  341. $ftp_server = "alabasterslim.bounceme.net";
  342. $ftp_user = "oamissions";
  343. $ftp_pass = "testing";
  344.  
  345. // set up a connection or die
  346. $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
  347. // try to login
  348. if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
  349. //echo "Connected as $ftp_user@$ftp_server\n";
  350. } else {
  351. //echo "Couldn't connect as $ftp_user\n";
  352. }
  353.  
  354.  
  355. // get contents of the current directory
  356. $contents = ftp_nlist($conn_id, ".");
  357. if(($gameState == 1 AND $np == 0) or $gameState == 7 or $gameState == 9){ // Upload file
  358. $check = basename($file);
  359. if(in_array("./".$check,$contents)){
  360. $page = 'The mission '.$check.' already exists on the server!';
  361. }
  362. else{
  363.  
  364. $fp = fopen($file, 'r');
  365. chdir(dirname($file));
  366. if (ftp_fput($conn_id, $check, $fp, FTP_ASCII)) {
  367. $page = 'Successfully uploaded '.basename($file).'<br>';
  368. } else {
  369. $page = 'There was a problem while uploading '.basename($file).'<br>The file has been queued for upload, you will be emailed when this is completed.<br>';
  370. // Set SQL flag as 2
  371. sql_update($check,1);
  372.  
  373. }
  374. chdir("../../");
  375. fclose($fp);
  376. }}
  377. else{ //Server is not in a good state, don't upload now.
  378. switch($gameState){
  379. case 1: $state = "Players are joining the server"; break;
  380. case 3: $state = "The server is currently at slot selection"; break;
  381. case 5: $state = "The server is currently loading a mission"; break;
  382. case 6: $state = "The server is currently at the mission briefing stage"; break;
  383. }
  384. $check = basename($file);
  385. $page = "$state. Your mission ($check) will be uploaded at the next available opportunity and an email notification will be sent when completed.<br>";
  386.  
  387. sql_update($check,1);
  388. //SQL Flag leave as 0
  389. }
  390.  
  391. //echo '<br><br><b>Missions:</b><br>';
  392. // output $contents
  393. $contents = ftp_nlist($conn_id, ".");
  394. foreach($contents as $key => $val){
  395. //echo $val.'<br>';
  396. sql_update(substr($val,2),0);//Update SQL Flags
  397. }
  398. // close the connection
  399. ftp_close($conn_id);
  400. return $page;
  401. }
  402. /*====================================*/
  403.  
  404.  
  405. function de_pbo($file,$user_st){
  406. //briefingName="STOACE_ADV_86_Tropico_Quickfight";
  407. //briefingDescription="Fight for your banana republic! At night, full moon, no NVGs";
  408. $pbo = file_get_contents($file);
  409.  
  410. if(substr_count($pbo, 'briefingName="')>0){
  411. $name = stcutter($pbo, 'briefingName="','";');
  412. $words = explode("_",$name);
  413. $length = count($words);
  414. $i = 3;
  415. $name = '';
  416. while($i < $length){
  417. $name .= $words[$i].' ';
  418. $i++;
  419. }
  420. //$name = str_replace("_", " ",$name);
  421. }
  422. else{
  423. $name = basename($file);}
  424. if(substr_count($pbo, 'briefingDescription="')>0){
  425. $description = stcutter($pbo, 'briefingDescription="', '";');}
  426. else{
  427. $description = "No description provided.";
  428. }
  429. $val = basename($file);
  430. $island = str_replace(".pbo", "", $val);
  431. $dot = strrpos(basename($island),'.') + 1;
  432. $island = substr(basename($island),$dot);
  433.  
  434.  
  435.  
  436. $words = explode("_",$val);
  437. //print_r($words);
  438. $length = count($words);
  439. //echo"<br><br>";
  440. $framework = strtoupper($words[0]);
  441. $type = strtoupper($words[1]);
  442. if($type == 'COOP'){
  443. $type = 'CO';
  444. }
  445. $players = $words[2];
  446.  
  447. $dac = 0;
  448. if(substr_count(strtolower($pbo),"dac_config_creator.sqf")>0){
  449. $dac = 1;}
  450.  
  451. $file_info = array("author" => $user_st, "name" => $name, "description" => $description, "island" => $island, "framework" => $framework, "type" => $type,"players" => $players, "dac" => $dac);
  452. //print_r($file_info);
  453. return $file_info;
  454.  
  455. //echo '<h1>'.$name.'</h1>';
  456. //echo '<h1>'.$description.'</h1>';
  457. }
  458.  
  459.  
  460. function stcutter($pContent, $pStartTag, $pEndTag){
  461. $content = trim($pContent);
  462. $startPos = strpos($content, $pStartTag) + strlen($pStartTag);
  463. $endPos = strpos(substr($content, $startPos), $pEndTag);
  464. $content = trim(substr($content, $startPos, $endPos));
  465. return $content;
  466. }
  467.  
  468. function getVar($name, $type = REQUEST)
  469. {
  470. $var = NULL;
  471.  
  472. switch($type)
  473. {
  474. case GET:
  475. if(isset($_GET[$name]))
  476. {
  477. $var = $_GET[$name];
  478. }
  479.  
  480. break;
  481.  
  482. case POST:
  483. if(isset($_POST[$name]))
  484. {
  485. $var = $_POST[$name];
  486. }
  487.  
  488. break;
  489.  
  490. case SESSION:
  491. if(isset($_SESSION[$name]))
  492. {
  493. $var = $_SESSION[$name];
  494. }
  495.  
  496. break;
  497.  
  498. case REQUEST:
  499. if(isset($_REQUEST[$name]))
  500. {
  501. $var = $_REQUEST[$name];
  502. }
  503.  
  504.  
  505. case COOKIE:
  506. if(isset($_COOKIE[$name]))
  507. {
  508. $var = $_COOKIE[$name];
  509. }
  510. }
  511.  
  512. if(is_string($var))
  513. {
  514. $var = trim(stripslashes($var));
  515. }
  516. elseif(is_array($var))
  517. {
  518. $var = r_stripSlashes($var);
  519. }
  520.  
  521. return $var;
  522. }
  523. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement