Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. <?php
  2. /*********************************************************************************
  3. Plugin loadmaplist.php v2
  4. Lists the maplists in the MatchSettings folder in a manialink
  5. Loads the clicked maplist
  6.  
  7. @author aca
  8. some code taken and adapted from plugin.rasp_jukebox.php
  9.  
  10. *********************************************************************************/
  11.  
  12.  
  13. Aseco::addChatCommand('listml', 'list maplists');
  14. Aseco::registerEvent('onPlayerManialinkPageAnswer', 'event_lml');
  15.  
  16. //triggered, when someone clicks in the displayed maplist-manialink
  17. function event_lml($aseco, $answer){
  18. $login = $answer[1];
  19. $action = $answer[2];
  20.  
  21. if(substr($action, -4, 4) == ".txt"){//only if a matchsettings-file is clicked
  22. $rtn = $aseco->client->query('LoadMatchSettings', "/home/NFS/GameData/Tracks/MatchSettings/$action");
  23. if(!$rtn){
  24. trigger_error('[' . $aseco->client->getErrorCode() . '] ' . $aseco->client->getErrorMessage(), E_USER_WARNING);
  25. $aseco->console($aseco->client->getErrorMessage());
  26. $aseco->client->query('ChatSendServerMessageToLogin', $aseco->client->getErrorMessage(), $login);
  27. }
  28. else{
  29. $aseco->console("".$action." loaded by $login");
  30. $aseco->client->query('ChatSendServerMessage', "MatchSettings $action loaded by $login");
  31. }
  32. }
  33. elseif(substr($action, -1, 1) == '/'){//if a directory is clicked
  34. $player = $aseco->server->players->getPlayer($login);
  35. $command = array();
  36. $command['author'] = $player;
  37. $command['params'] = $action;
  38. chat_listml($aseco, $command);
  39. }
  40. }
  41.  
  42.  
  43. //returns all files in directory MatchSettings as an array
  44. function lml_fetchMatchsettings($aseco, $dir){
  45. $msArray = array();
  46. $mapsDir = $aseco->server->mapdir;
  47.  
  48. //specified a subfolder
  49. $msDir = $mapsDir.'/home/NFS/GameData/Tracks/MatchSettings/'.$dir;
  50.  
  51. $msDirHandle = opendir($msDir);
  52. while($file = readdir($msDirHandle)){
  53. if($file != '.'){
  54. if(substr($file, -4, 4) != ".txt"){//is it a directory
  55. $file = $file."/";
  56. }
  57. //only show directory up, when not on toplevel
  58. if(!($dir == '' && $file == '../')){
  59. array_push($msArray, $file);
  60. }
  61.  
  62. }
  63. }
  64. closedir($msDirHandle);
  65.  
  66. //sort the maplists alphabetically
  67. sort($msArray);
  68. return $msArray;
  69. }
  70.  
  71.  
  72.  
  73. //called, when "/listml" ist typed in chat by a (Master)Admin
  74. function chat_listml($aseco, $command) {
  75.  
  76. $player = $command['author'];
  77.  
  78. if ($aseco->isAnyAdminL($player->login)) {
  79.  
  80. $folder = '';
  81. $params = $command['params'];
  82.  
  83.  
  84.  
  85. if($params != ''){
  86. $folder = $params;
  87. if(substr($folder, -3, 3) == '../'){//when directory-up
  88. $pathArray = explode('/', $folder);
  89. $folder = '';
  90. $count = count($pathArray);
  91. for($i = 0; $i < $count-3; $i++){
  92. $folder .= $pathArray[$i].'/';
  93. }
  94. }
  95. }
  96.  
  97. $msFileArray = lml_fetchMatchsettings($aseco, $folder);
  98.  
  99. $head = "Maplists in MatchSettings/$folder";
  100. $page = array();
  101. if ($aseco->settings['clickable_lists'])
  102. $page[] = array('$i$oId', '$i$oName $f00(click to load)');
  103. else
  104. $page[] = array('Id', 'Name');
  105.  
  106. $tid = 1;
  107. $lines = 0;
  108. $player->msgs = array();
  109. $player->msgs[0] = array(1, $head, array(1.10, 0.1, 0.6), array('Icons128x128_1', 'Load', 0.02));
  110.  
  111. foreach ($msFileArray as $item) {
  112. $page[] = array(str_pad($tid, 2, '0', STR_PAD_LEFT), array($item, $folder.$item));//action
  113. $tid++;
  114.  
  115. if (++$lines > 14) {
  116. $player->msgs[] = $page;
  117. $lines = 0;
  118. $page = array();
  119. if ($aseco->settings['clickable_lists'])
  120. $page[] = array('$i$oId', '$i$oName $f00(click to load)');
  121. else
  122. $page[] = array('Id', 'Name');
  123. }
  124. }
  125. if (count($page) > 1) {
  126. $player->msgs[] = $page;
  127. }
  128. // display
  129. display_manialink_multi($player);
  130. }
  131. }
  132.  
  133.  
  134. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement