Guest User

Untitled

a guest
Jan 13th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.22 KB | None | 0 0
  1. AWarn.DefaultValues = { awarn_kick = 1, awarn_kick_threshold = 3, awarn_kick_time = 120, awarn_ban = 1, awarn_ban_threshold = 5, awarn_ban_time = 30, awarn_decay = 1, awarn_decay_rate = 30, awarn_reasonrequired = 1 }
  2.  
  3.  
  4. util.AddNetworkString("SendPlayerWarns")
  5. util.AddNetworkString("SendOwnWarns")
  6. util.AddNetworkString("AWarnMenu")
  7. util.AddNetworkString("AWarnClientMenu")
  8. util.AddNetworkString("AWarnOptionsMenu")
  9. util.AddNetworkString("AWarnNotification")
  10. util.AddNetworkString("AWarnNotification2")
  11. util.AddNetworkString("AWarnChatMessage")
  12. util.AddNetworkString("awarn_openoptions")
  13. util.AddNetworkString("awarn_openmenu")
  14. util.AddNetworkString("awarn_fetchwarnings")
  15. util.AddNetworkString("awarn_fetchownwarnings")
  16. util.AddNetworkString("awarn_deletesinglewarn")
  17. util.AddNetworkString("awarn_deletewarningsid")
  18. util.AddNetworkString("awarn_deletewarnings")
  19. util.AddNetworkString("awarn_removewarningsid")
  20. util.AddNetworkString("awarn_removewarnings")
  21. util.AddNetworkString("awarn_removewarn")
  22. util.AddNetworkString("awarn_warn")
  23. util.AddNetworkString("awarn_warnid")
  24. util.AddNetworkString("awarn_changeconvarbool")
  25. util.AddNetworkString("awarn_changeconvar")
  26.  
  27.  
  28. function awarn_loadscript()
  29. awarn_tbl_exist()
  30. end
  31. hook.Add( "Initialize", "Awarn_Initialize", awarn_loadscript )
  32.  
  33.  
  34. function awarn_kick( ply, time)
  35. if ulx then
  36. ULib.jail( ply, time)
  37. else
  38. ply:Jail( time )
  39. end
  40. end
  41.  
  42. function awarn_ban( ply, time )
  43. if ulx then
  44. ULib.kickban( ply, time, "AWarn: Ban Threshold Met" )
  45. else
  46. ply:Ban( time, "AWarn: Ban Threshold Met" )
  47. end
  48. end
  49.  
  50. function awarn_playerdisconnected( ply )
  51. timer.Remove( ply:SteamID64() .. "_awarn_decay" )
  52. end
  53. hook.Add( "PlayerDisconnected", "awarn_playerdisconnected", awarn_playerdisconnected )
  54.  
  55. net.Receive( "awarn_fetchwarnings", function( l, ply )
  56.  
  57. if not awarn_checkadmin_view( ply ) then
  58. AWSendMessage( ply, "AWarn: You do not have access to this command.")
  59. return
  60. end
  61.  
  62. local target_ply = awarn_getUser( net.ReadString() )
  63.  
  64. if target_ply then
  65. awarn_sendwarnings( ply, target_ply )
  66. else
  67. AWSendMessage( ply, "AWarn: Player not found!")
  68. end
  69.  
  70. end )
  71.  
  72. net.Receive( "awarn_fetchownwarnings", function( l, ply )
  73.  
  74. awarn_sendownwarnings( ply )
  75.  
  76. end )
  77.  
  78. net.Receive( "awarn_changeconvarbool", function( l, ply )
  79.  
  80. local allowed = { "awarn_kick", "awarn_ban", "awarn_decay", "awarn_reasonrequired" }
  81. local convar = net.ReadString()
  82. local val = net.ReadString()
  83.  
  84. if not awarn_checkadmin_options( ply ) then
  85. AWSendMessage( ply, "AWarn: You do not have access to this command.")
  86. return
  87. end
  88.  
  89. if not table.HasValue( allowed, convar ) then
  90. AWSendMessage( ply, "AWarn: You can not set this CVar with this command.")
  91. return
  92. end
  93.  
  94. if val == "true" then
  95. GetConVar( convar ):SetBool( false )
  96. return
  97. end
  98. GetConVar( convar ):SetBool( true )
  99.  
  100. end )
  101.  
  102. net.Receive( "awarn_changeconvar", function( l, ply )
  103.  
  104. local allowed = { "awarn_kick_threshold", "awarn_kick_time", "awarn_ban_threshold", "awarn_ban_time", "awarn_decay_rate" }
  105. local convar = net.ReadString()
  106. local val = net.ReadInt(32)
  107.  
  108. if not awarn_checkadmin_options( ply ) then
  109. AWSendMessage( ply, "AWarn: You do not have access to this command.")
  110. return
  111. end
  112.  
  113. if not table.HasValue( allowed, convar ) then
  114. AWSendMessage( ply, "AWarn: You can not set this CVar with this command.")
  115. return
  116. end
  117.  
  118. if val < 0 then
  119. AWSendMessage( ply, "AWarn: You must pass this ConVar a positive value.")
  120. return
  121. end
  122.  
  123. GetConVar( convar ):SetInt( val )
  124.  
  125. end )
  126.  
  127. function AWSendMessage( ply, message )
  128. if IsValid(ply) then
  129. ply:PrintMessage( HUD_PRINTTALK, message )
  130. else
  131. print( message )
  132. end
  133. end
  134.  
  135. function AWarn_ChatWarn( ply, text, public )
  136. if (string.sub(string.lower(text), 1, 5) == "!warn") then
  137. local args = string.Explode( " ", text )
  138. if #args == 1 then
  139. ply:ConCommand( "awarn_menu" )
  140. else
  141. table.remove( args, 1 )
  142. awarn_con_warn( ply, _, args )
  143. --ply:ConCommand( "awarn_warn " .. table.concat( args, " ", 2 ) )
  144. end
  145. return false
  146. end
  147. end
  148. hook.Add( "PlayerSay", "AWarn_ChatWarn", AWarn_ChatWarn )
  149.  
  150. function awarn_con_warn( ply, _, args )
  151.  
  152. if not ( #args >= 1 ) then return end
  153. local tar = awarn_getUser( args[1] )
  154. local reason = table.concat( args, " ", 2 )
  155.  
  156. if (string.sub(string.lower(args[1]), 1, 5) == "steam") then
  157. if string.len(args[1]) == 7 then
  158. AWSendMessage( ply, "AWarn: Make sure you wrap the steamID in quotes!" )
  159. return
  160. end
  161. tid = AWarn_ConvertSteamID( args[1] )
  162. awarn_warnplayerid( ply, tid, reason )
  163. return
  164. end
  165.  
  166. if not (IsValid(tar)) then return end
  167. print("DEBUG =-=-= Reason: " .. reason)
  168. awarn_warnplayer( ply, tar, reason )
  169.  
  170. end
  171. concommand.Add( "awarn_warn", awarn_con_warn )
  172.  
  173.  
  174. net.Receive( "awarn_warn", function( l, ply )
  175.  
  176. awarn_warnplayer( ply, net.ReadEntity(), net.ReadString() )
  177.  
  178. end )
  179.  
  180. net.Receive( "awarn_warnid", function( l, ply )
  181.  
  182. awarn_warnplayerid( ply, net.ReadString(), net.ReadString() )
  183.  
  184. end )
  185.  
  186.  
  187. function awarn_warnplayer( ply, tar, reason )
  188.  
  189. if not awarn_checkadmin_warn( ply ) then
  190. AWSendMessage( ply, "AWarn: You do not have access to this command.")
  191. return
  192. end
  193.  
  194. target_ply = tar
  195. if reason == nil then reason = "" end
  196.  
  197. if not IsValid(target_ply) then return end
  198. if not target_ply:IsPlayer() then return end
  199.  
  200. --if tobool(GetGlobalInt( "awarn_reasonrequired", 1 )) then
  201. if GetConVar("awarn_reasonrequired"):GetBool() then
  202. if not reason then
  203. AWSendMessage( ply, "AWarn: You MUST include a reason. Disable this in the options.")
  204. return
  205. end
  206. if reason == "" then
  207. AWSendMessage( ply, "AWarn: You MUST include a reason. Disable this in the options.")
  208. return
  209. end
  210. end
  211.  
  212. if not reason then reason = "NONE GIVEN" end
  213. if reason == "" then reason = "NONE GIVEN" end
  214.  
  215. if target_ply then
  216. for k, v in pairs(player.GetAll()) do
  217. if v ~= target_ply then
  218. net.Start("AWarnNotification")
  219. net.WriteEntity( ply )
  220. net.WriteEntity( target_ply )
  221. net.WriteString( reason )
  222. net.Send( v )
  223. end
  224. end
  225.  
  226.  
  227. if IsValid(ply) then
  228. awarn_addwarning( target_ply:SteamID64(), reason, ply:Nick() )
  229. ServerLog( "[AWarn] " .. ply:Nick() .. " warned " .. target_ply:Nick() .. " for reason: " .. reason.. "\n" )
  230. else
  231. awarn_addwarning( target_ply:SteamID64(), reason, "[CONSOLE]" )
  232. ServerLog( "[AWarn] [CONSOLE] warned " .. target_ply:Nick() .. " for reason: " .. reason.. "\n" )
  233. end
  234. awarn_incwarnings( target_ply )
  235.  
  236. local t1 = {}
  237. if IsValid( ply ) then
  238. t1 = { Color(60,60,60), "[", Color(30,90,150), "AWarn", Color(60,60,60), "] ", Color(255,255,255), "You have been warned by ", ply, " for ", Color(150,40,40), reason, Color(255,255,255), "." }
  239. else
  240. t1 = { Color(60,60,60), "[", Color(30,90,150), "AWarn", Color(60,60,60), "] ", Color(255,255,255), "You have been warned by ", Color(100,100,100), "[CONSOLE]", Color(255,255,255), " for ", Color(150,40,40), reason, Color(255,255,255), "." }
  241. end
  242. net.Start("AWarnChatMessage") net.WriteTable(t1) net.Send( target_ply )
  243.  
  244. if GetConVar("awarn_kick"):GetBool() then
  245. local t3 = { Color(60,60,60), "[", Color(30,90,150), "AWarn", Color(60,60,60), "] ", Color(255,255,255), "You will be kicked after: ", Color(255,0,0), tostring(GetConVar("awarn_kick_threshold"):GetInt()), Color(255,255,255), " total active warnings." }
  246. net.Start("AWarnChatMessage") net.WriteTable(t3) net.Send( target_ply )
  247. end
  248.  
  249. if GetConVar("awarn_ban"):GetBool() then
  250. local t4 = { Color(60,60,60), "[", Color(30,90,150), "AWarn", Color(60,60,60), "] ", Color(255,255,255), "You will be banned after: ", Color(255,0,0), tostring(GetConVar("awarn_ban_threshold"):GetInt()), Color(255,255,255), " total active warnings." }
  251. net.Start("AWarnChatMessage") net.WriteTable(t4) net.Send( target_ply )
  252. end
  253.  
  254. local t5 = { Color(60,60,60), "[", Color(30,90,150), "AWarn", Color(60,60,60), "] ", Color(255,255,255), "Type !warn to see a list of your warnings." }
  255. net.Start("AWarnChatMessage") net.WriteTable(t5) net.Send( target_ply )
  256.  
  257. if IsValid( ply ) then
  258. awarn_sendwarnings( ply, target_ply )
  259. end
  260.  
  261. local AWarnPlayerWarned = hook.Call( "AWarnPlayerWarned", GAMEMODE, target_ply, ply, reason )
  262.  
  263. else
  264. AWSendMessage( ply, "AWarn: Player not found!")
  265. end
  266.  
  267. end
  268.  
  269. function awarn_warnplayerid( ply, tarid, reason )
  270.  
  271. if not awarn_checkadmin_warn( ply ) then
  272. AWSendMessage( ply, "AWarn: You do not have access to this command.")
  273. return
  274. end
  275.  
  276. --if tobool(GetGlobalInt( "awarn_reasonrequired", 1 )) then
  277. if GetConVar("awarn_reasonrequired"):GetBool() then
  278. if not reason then
  279. AWSendMessage( ply, "AWarn: You MUST include a reason. Disable this in the options.")
  280. return
  281. end
  282. if reason == "" then
  283. AWSendMessage( ply, "AWarn: You MUST include a reason. Disable this in the options.")
  284. return
  285. end
  286. end
  287.  
  288. if not reason then reason = "NONE GIVEN" end
  289. if reason == "" then reason = "NONE GIVEN" end
  290.  
  291. net.Start("AWarnNotification2")
  292. net.WriteEntity( ply )
  293. net.WriteString( tarid )
  294. net.WriteString( reason )
  295. net.Broadcast()
  296.  
  297.  
  298. if IsValid(ply) then
  299. awarn_addwarning( tarid, reason, ply:Nick() )
  300. ServerLog( "[AWarn] " .. ply:Nick() .. " warned " .. tostring(tarid) .. " for reason: " .. reason.. "\n" )
  301. else
  302. awarn_addwarning( tarid, reason, "[CONSOLE]" )
  303. ServerLog( "[AWarn] [CONSOLE] warned " .. tostring(tarid) .. " for reason: " .. reason.. "\n" )
  304. end
  305. awarn_incwarningsid( tarid )
  306.  
  307. local AWarnPlayerIDWarned = hook.Call( "AWarnPlayerIDWarned", GAMEMODE, tarid, ply, reason )
  308. end
  309.  
  310. function awarn_remwarn( ply, tar )
  311.  
  312. if not awarn_checkadmin_remove( ply ) then
  313. AWSendMessage( ply, "AWarn: You do not have access to this command.")
  314. return
  315. end
  316.  
  317. local target_ply = awarn_getUser( tar )
  318.  
  319. if target_ply then
  320. awarn_decwarnings( target_ply, ply )
  321. if IsValid( ply ) then
  322. awarn_sendwarnings( ply, target_ply )
  323. end
  324. else
  325. AWSendMessage( ply, "AWarn: Player not found!")
  326. end
  327.  
  328. end
  329.  
  330. net.Receive( "awarn_removewarnid", function( l, ply )
  331.  
  332. if not awarn_checkadmin_remove( ply ) then
  333. AWSendMessage( ply, "AWarn: You do not have access to this command.")
  334. return
  335. end
  336.  
  337. local uid = net.ReadString()
  338. awarn_decwarningsid( uid, ply )
  339.  
  340. end )
  341.  
  342. net.Receive( "awarn_removewarn", function( l, ply )
  343. if not IsValid( ply ) then return end
  344. local p_id = net.ReadString()
  345.  
  346. if (string.sub(string.lower( p_id ), 1, 5) == "steam") then
  347. if string.len(args[1]) == 7 then
  348. AWSendMessage( ply, "AWarn: Make sure you wrap the steamID in quotes!" )
  349. return
  350. end
  351. id = AWarn_ConvertSteamID( p_id )
  352. awarn_decwarningsid( id, ply )
  353. return
  354. end
  355. awarn_remwarn( ply, p_id )
  356.  
  357. end )
  358.  
  359. net.Receive( "awarn_deletewarnings", function( l, ply )
  360.  
  361. if not awarn_checkadmin_delete( ply ) then
  362. AWSendMessage( ply, "AWarn: You do not have access to this command.")
  363. return
  364. end
  365.  
  366. local target_ply = awarn_getUser( net.ReadString() )
  367.  
  368. if target_ply then
  369. awarn_delwarnings( target_ply, ply )
  370. else
  371. AWSendMessage( ply, "AWarn: Player not found!")
  372. end
  373.  
  374. end )
  375.  
  376. concommand.Add( "awarn_deletewarnings", function( ply, _, args )
  377. if IsValid(ply) then return end
  378. if #args ~= 1 then return end
  379. local target_ply = awarn_getUser( args[1] )
  380.  
  381. if target_ply then
  382. awarn_delwarnings( target_ply, ply )
  383. else
  384. AWSendMessage( ply, "AWarn: Player not found!")
  385. end
  386. end )
  387.  
  388. net.Receive( "awarn_deletewarningsid", function( l, ply )
  389. if not awarn_checkadmin_delete( ply ) then
  390. AWSendMessage( ply, "AWarn: You do not have access to this command.")
  391. return
  392. end
  393.  
  394. local uid = net.ReadString()
  395.  
  396. awarn_delwarningsid( uid, ply )
  397. end )
  398.  
  399. concommand.Add( "awarn_deletewarningsid", function( ply, _, args )
  400. if IsValid(ply) then return end
  401. if #args ~= 1 then return end
  402.  
  403. local uid = args[1]
  404. awarn_delwarningsid( uid, ply )
  405. end )
  406.  
  407. net.Receive( "awarn_openmenu", function( l, ply )
  408.  
  409. if not IsValid( ply ) then
  410. AWSendMessage( ply, "AWarn: This command can not be run from the server's console!")
  411. return
  412. end
  413.  
  414. if not awarn_checkadmin_view( ply ) then
  415. net.Start("AWarnClientMenu")
  416. net.Send( ply )
  417. return
  418. end
  419.  
  420.  
  421. net.Start("AWarnMenu")
  422. net.Send( ply )
  423.  
  424. end )
  425.  
  426. net.Receive( "awarn_openoptions", function( l, ply )
  427.  
  428. if not IsValid( ply ) then
  429. AWSendMessage( ply, "AWarn: This command can not be run from the server's console!")
  430. return
  431. end
  432.  
  433. if not awarn_checkadmin_options( ply ) then
  434. AWSendMessage( ply, "AWarn: You do not have access to this command.")
  435. return
  436. end
  437.  
  438.  
  439. net.Start("AWarnOptionsMenu")
  440. net.Send( ply )
  441.  
  442. end )
  443.  
  444. net.Receive( "awarn_deletesinglewarn", function( l, ply )
  445.  
  446. if not awarn_checkadmin_delete( ply ) then
  447. AWSendMessage( ply, "AWarn: You do not have access to this command.")
  448. return
  449. end
  450.  
  451. local warningid = net.ReadInt(16)
  452.  
  453. awarn_delsinglewarning( ply, warningid )
  454.  
  455. end )
  456.  
  457. local files, dirs = file.Find("awarn/modules/*.lua", "LUA")
  458. for k, v in pairs( files ) do
  459. ServerLog("AWarn: Loading module (" .. v .. ")\n")
  460. include( "awarn/modules/" .. v )
  461. end
Advertisement
Add Comment
Please, Sign In to add comment