# Ban management system V1.00 25-02-2017 -Initial release # ################################################################################################# CatchEvent OnMSO( $userName, $text ) # Player event $idxOfFirtsSpace = indexOf( $text, " "); IF( $idxOfFirtsSpace == -1 ) THEN $command = $text; $argv = ""; ELSE $command = subStr( $text,0,$idxOfFirtsSpace ); $argv = trim( subStr( $text,$idxOfFirtsSpace ) ); ENDIF SWITCH( $command ) CASE "!banply": IF( UserInGroup( "admin", $userName ) == 1 ) THEN Ban_player( $KeyFlags,$id ); ELSE PrivMsg( "^1You are not allowed to do that"); ENDIF BREAK; CASE "!unbanply": IF( UserInGroup( "admin", $userName ) == 1 ) THEN Unban_player( $KeyFlags,$id ); ELSE PrivMsg( "^1You are not allowed to do that"); ENDIF BREAK; ENDSWITCH EndCatchEvent Sub Ban_player( $KeyFlags,$id ) ### Set initial values for left/right and top/bottom coordinates ### $left_right_ban = 29; $top_bottom_ban = 50; ### End ### $mList = GetListOfPlayers("N"); $mCount = arrayCount( $mList ); $plyNum=0; ### Close previously opened buttons during automatic refresh, otherwise changed names or people who left aren't shown ### FOR ($i=0;$i<=40;$i=$i+1) closePrivButton ("player_".$i."_number&player_".$i."_nickname&player_".$i."_status&player_".$i."_ban"); ENDFOR openPrivButton( "ban_screen_bg",$left_right_ban,$top_bottom_ban,142,125,5,-1,16,""); openPrivButton( "ban_screen_title",$left_right_ban+1,$top_bottom_ban+1,140,5,5,-1,32,"^7Connected players" ); WHILE ($plyNum < $mCount) $uName = $mList[$plyNum]; openPrivButton ("player_".$plyNum."_number",$left_right_ban+1,$top_bottom_ban+10,5,5,5,-1,32,$plyNum+1); openPrivButton ("player_".$plyNum."_nickname",$left_right_ban+7,$top_bottom_ban+10,25,5,5,-1,32,GetPlayerVar($uName,"NickName") ); openPrivButton ("player_".$plyNum."_ban",$left_right_ban+33,$top_bottom_ban+10,15,5,5,-1,32,"^1Ban",execute_ban); ### Raise $top_bottom_ban with 5 before drawing next button $top_bottom_ban=$top_bottom_ban+5; ### End ### $plyNum=$plyNum+1; ### When player 20 is reached, change value of $left_right_connected to start next colum. Set $top_bottom_connected to initial value ### IF ($plyNum == 20) THEN $left_right_ban = 100; $top_bottom_ban = 50; ENDIF ### End ### ENDWHILE openPrivButton( "refresh_ban",69,164,20,5,10,30,32,"^3Refresh (%cpt%)",Ban_player ); openPrivButton( "close_ban",90,164,20,5,10,-1,32,"^3Close",close_ban_player ); EndSub Sub close_ban_player ( $KeyFlags,$id ) closePrivButton ("ban_screen_bg&ban_screen_title&refresh_ban&close_ban"); FOR ($i=0;$i<=40;$i=$i+1) closePrivButton ("player_".$i."_number&player_".$i."_nickname&player_".$i."_status&player_".$i."_ban"); ENDFOR EndSub Sub execute_ban ( $KeyFlags, $id ) $id = Substr($id,7); $mList = GetListOfPlayers("N"); $uName = $mList[$id+0]; ### Place banned user into group 'banned' , write group to file , kick (to avoid a registration in the LFS ban-file) user ### MoveUserToGroup("banned",GetPlayerVar ( $uName,"UserName") ); UserGroupToFile( "banned", "./banned.txt" ); PrivMsg( GetPlayerVar ( $uName,"UserName"),"^1WARNING: ^7You have received a ban from this server"); cmdLFS( "/kick " . GetPlayerVar ( $uName,"UserName") ); ### End ### Ban_player( 0,0 ); EndSub Sub Unban_player( $KeyFlags,$id ) ### Load usernames of people specified in banned.txt , put them in an array and count the number of values in that array (reduced by 1, because arrays start with position 0 ### UserGroupFromFile( "banned", "./banned.txt" ); $ListOfUsers = GetListOfUsersGroup("banned"); $number_in_array = arrayCount($ListOfUsers ) - 1; ### End ### ### Set initial values for left/right and top/bottom coordinates ### $left_right_unban = 29; $top_bottom_unban = 50; ### End ### ### See if $id is set and fill $start and $limit accordingly ### IF ( $id != "") THEN $start = ToNum( $id ); $limit = ToNum( $id ) + 40; ELSE $limit=40; $start=0; ENDIF ### End ### ### Set nex_button value to 'yes' ### $next_button="yes"; ### End ### ### Check is value for limit is bigger then the number of values in the array ### ### If that's the case, set limit to match the number of values in the array and set next_button value to 'no' ### IF ( $limit > $number_in_array ) THEN $limit = ToNum( $number_in_array ); $next_button="no"; ENDIF ### End ### ### Close previously opened buttons ### $close_start=$start-40; IF ( $close_start < 0 ) THEN $close_start=0; ENDIF $close_limit=$close_start+40; FOR ($i=$close_start;$i<$close_limit;$i=$i+1) closePrivButton ("player_".$i."_number&player_".$i."_username&player_".$i."_status"); closePrivButton ("".$ListOfUsers[$i]); closePrivButton ("close_unban_".$start); ENDFOR ### End ### openPrivButton( "unban_screen_bg",$left_right_unban,$top_bottom_unban,142,125,5,-1,16,""); openPrivButton( "unban_screen_title",$left_right_unban+1,$top_bottom_unban+1,140,5,5,-1,32,"^7Banned players" ); FOR ($i=$start;$i<$limit;$i=$i+1) openPrivButton ("player_".$i."_number",$left_right_unban+1,$top_bottom_unban+10,5,5,5,-1,32,$i+1); openPrivButton ("player_".$i."_username",$left_right_unban+7,$top_bottom_unban+10,25,5,5,-1,32,$ListOfUsers[$i] ); openPrivButton ("".$ListOfUsers[$i],$left_right_unban+33,$top_bottom_unban+10,15,5,5,-1,32,"^1Unban",execute_unban); ### Raise $top_bottom_unban with 5 before drawing next button $top_bottom_unban=$top_bottom_unban+5; ### End ### ### When player 19 is reached, change value of $left_right_connected to start next colum. Set $top_bottom_connected to initial value ### IF ($i == 19 || $i == 59 || $i == 99 || $i == 139 || $i == 179 || $i == 219 || $i == 259 || $i == 299) THEN $left_right_unban = 100; $top_bottom_unban = 50; ENDIF ### End ### ENDFOR IF ( $next_button == "yes") THEN openPrivButton( "next_unban_".$i,69,164,20,5,10,-1,32,"^3Next from ".$i,Unban_next ); ENDIF openPrivButton( "close_unban_".$limit,90,164,20,5,10,-1,32,"^3Close",close_unban_player ); EndSub Sub Unban_next ( $KeyFlags,$id ) $id = ToNum( Substr($id,11) ); closePrivButton ("next_unban_".$id); Unban_player( 0,$id ); EndSub Sub close_unban_player ( $KeyFlags,$id ) $id = ToNum( Substr($id,12) ); closePrivButton ("unban_screen_bg&unban_screen_title&next_unban_".$id."&close_unban_".$id); ### Load usernames of people specified in banned.txt ### $ListOfUsers = GetListOfUsersGroup("banned"); ### End ### FOR ($i=0;$i<=$id;$i=$i+1) closePrivButton ("player_".$i."_number&player_".$i."_username&player_".$i."_status"); closePrivButton ("".$ListOfUsers[$i]); ENDFOR EndSub Sub execute_unban ( $KeyFlags,$id ) ### Load usernames of people specified in banned.txt and put them in an array ### UserGroupFromFile( "banned", "./banned.txt" ); $ListOfUsers = GetListOfUsersGroup("banned"); ### End ### ### Remove the unbanned user from the group and write a new banned.txt file ### RemoveUserFromGroup("banned",$id); UserGroupToFile( "banned", "./banned.txt" ); ### End ### ### Close Unban button of the person who has just been unbanned ### closePrivButton ("".$id); ### End ### EndSub