MuhammadZeeshan

ban funcs

Dec 11th, 2016
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. function Ban( plr, duration, reason, player )
  2. {
  3. local g_bantime, duration_type;
  4. switch( duration.len() )
  5. {
  6. case 2: //this is for slicing the type of 1d
  7. g_bantime = duration.slice(0,1);
  8. duration_type = duration.slice(1,2);
  9. break;
  10.  
  11. case 3: //this is for slicing the type of 10d,10h,10m
  12. g_bantime = duration.slice(0,2);
  13. duration_type = duration.slice(2,3);
  14. break;
  15. }
  16.  
  17. local g_bantime_, g_duration_type_;
  18. switch( duration_type )
  19. {
  20. case "d":
  21. g_bantime_ = g_bantime.tointeger() * 86400;
  22. g_duration_type_ = "day(s)";
  23. break;
  24.  
  25. case "m":
  26. g_bantime_ = g_bantime.tointeger() * 2678400;
  27. g_duration_type_ = "month(s)";
  28. break;
  29.  
  30. case "h":
  31. g_bantime_ = g_bantime.tointeger() * 3600;
  32. g_duration_type_ = "hour(s)";
  33. break;
  34.  
  35. default:
  36. SendMessage( "Invalid format, the format you typed is wrong", player );
  37. }
  38. local dur = g_bantime + " " + g_duration_type_;
  39. ServerMessage( "Admin:[ " + player + " ] Banned: [ "+ plr +" ], for Reason: [ " + reason+ " ], Duration: [ " + dur + " ]" );
  40. EchoMessage( "[BAN] - "+ICOL_RED+"Admin:[ " + player + " ] Banned: [ "+ plr +" ], for Reason: [ " + reason+ " ], Duration: [ " + dur + " ]" );
  41. EchoMessage1( "[BAN] - "+ICOL_RED+"Admin:[ " + player + " ] Banned: [ "+ plr +" ], for Reason: [ " + reason+ " ], Duration: [ " + dur + " ]" );
  42. QuerySQL(db, "INSERT INTO Bans ( Name, g_bantime, g_banexp, Reason, Admin, UID, IP ) VALUES ( '"+plr+"', '"+time()+"', '"+g_bantime_+"', '"+reason+"', '"+player+"', '"+plr.UniqueID+"', '"+plr.IP+"' )" );
  43. plr.Kick();
  44. }
  45. function CheckBan( player )
  46. {
  47.  
  48. local q = QuerySQL( db, "SELECT * FROM Bans WHERE UID='" + player.UniqueID + "' COLLATE NOCASE" );
  49. local uid = GetSQLColumnData( q, 5 ), b_time =GetSQLColumnData( q, 1 ), b_exp = GetSQLColumnData(q, 2 );
  50.  
  51. if ( uid )
  52. {
  53. if ( time() - b_time >= b_exp )
  54. {
  55. QuerySQL( db, "DELETE FROM Bans WHERE UID=" + player.UniqueID + "'" );
  56. MessagePlayer("Your ban has been expired, stick to the rules.", player );
  57. }
  58. else
  59. {
  60. local t_left = time() - b_time;
  61. local t_left_ = b_exp - t_left;
  62.  
  63. ServerMessage( "Auto kicking "+player.Name+" as he is currently banned in server, Timeleft: "+Duration( t_left_ )+"." );
  64. EchoMessage( ICOL_RED+"Auto kicking "+player.Name+" as he is currently banned in server. Timeleft: "+Duration( t_left_ )+"." );
  65. EchoMessage1( ICOL_RED+"Auto kicking "+player.Name+" as he is currently banned in server. Timeleft: "+Duration( t_left_ )+"." );
  66. SendMessage( "Banned by: [ "+GetSQLColumnData(q, 4)+" ] Reason: [ "+GetSQLColumnData(q, 3)+" ] For unban appeals apply on forum, Forum: " +Forum+ ".", player );
  67. KickPlayer( player );
  68. }
  69. }
  70. FreeSQLQuery( q );
  71. }
  72. function Duration( secs )
  73. {
  74. local nDays, nHours, nMinutes, nMonths, nYears, nTime = "";
  75. nYears = secs/31536000;
  76. secs = secs%31536000;
  77. nMonths = secs/2678400;
  78. secs = secs%2678400;
  79. nDays = secs/86400;
  80. secs = secs%86400;
  81. nHours = secs/3600;
  82. secs = secs%3600;
  83. nMinutes = secs/60;
  84. secs = secs%60;
  85. if( nYears != 0 ) nTime = nTime + nYears + " Year" + (nYears > 1 ? "s":"");
  86. if( nMonths != 0 ) nTime = nTime + (nTime != "" ? ", ":"") + nMonths + " month" + (nMonths > 1 ? "s":"");
  87. if( nDays != 0 ) nTime = nTime + (nTime != "" ? ", ":"") + nDays + " day" + (nDays > 1 ? "s":"");
  88. if( nHours != 0 ) nTime = nTime + (nTime != "" ? ", ":"") + nHours + " hour" + (nHours > 1 ? "s":"");
  89. if( nMinutes != 0 ) nTime = nTime + (nTime != "" ? ", ":"") + nMinutes + " min" + (nMinutes > 1 ? "s":"");
  90. if( secs != 0 ) nTime = nTime + (nTime != "" ? " and ":"") + secs + " sec" + (secs > 1 ? "s":"");
  91. return nTime;
  92. }
Add Comment
Please, Sign In to add comment