Advertisement
Clamped2Clamp

Untitled

Oct 19th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. if SERVER then AddCSLuaFile() end
  2.  
  3.  
  4.  
  5. local L = translation and translation.L or function(s) return s end
  6.  
  7.  
  8.  
  9. local DEBUG=false
  10.  
  11.  
  12.  
  13. local Tag="pmail"
  14.  
  15. if SERVER then
  16.  
  17. util.AddNetworkString(Tag)
  18.  
  19. end
  20.  
  21.  
  22.  
  23. module(Tag,package.seeall)
  24.  
  25.  
  26.  
  27. local Dbg=DEBUG and function(...) Msg("["..Tag.."] ")print(...)end or function()end
  28.  
  29.  
  30.  
  31. net.Receive(Tag,function( len,pl )
  32.  
  33. local tbl = {}
  34.  
  35. if CLIENT then
  36.  
  37. tbl.msg = net.ReadString()
  38.  
  39. tbl.sender = net.ReadString()
  40.  
  41. else
  42.  
  43. tbl.msg = net.ReadString()
  44.  
  45. tbl.receiver = net.ReadString()
  46.  
  47. end
  48.  
  49.  
  50.  
  51. if SERVER then
  52.  
  53. tbl.sender = pl:SteamID()
  54.  
  55. local msg = tbl.msg
  56.  
  57.  
  58.  
  59. if not chatbox.ValidMessage ( msg ) then return end
  60.  
  61.  
  62.  
  63. if pl.raybans and pl.raybans.chat then
  64.  
  65. return
  66.  
  67. end
  68.  
  69.  
  70.  
  71. if msg:len()>64*1024-128 then
  72.  
  73. ErrorNoHalt("[ChatPM] IGNORING TOO LONG MESSAGE: len="..msg:len().." from "..tostring(pl))
  74.  
  75. return
  76.  
  77. end
  78.  
  79.  
  80.  
  81. -- Anti spam
  82.  
  83. if chatbox.SpamWatch( pl, msg ) then
  84.  
  85. Send{
  86.  
  87. msg=L"Spam protection triggered. You're sending too fast!",
  88.  
  89. sender="",
  90.  
  91. receiver=pl:SteamID(),
  92.  
  93. }
  94.  
  95. return
  96.  
  97. end
  98.  
  99.  
  100.  
  101. end
  102.  
  103.  
  104.  
  105. OnReceive( tbl )
  106.  
  107.  
  108.  
  109. end )
  110.  
  111.  
  112.  
  113. function toplayer(steamid)
  114.  
  115. Dbg("Finding",steamid)
  116.  
  117. for k,v in pairs(player.GetAll()) do
  118.  
  119. if v:SteamID()==steamid then
  120.  
  121. return v
  122.  
  123. end
  124.  
  125. end
  126.  
  127. end
  128.  
  129.  
  130.  
  131. function Send(tbl)
  132.  
  133. net.Start(Tag)
  134.  
  135.  
  136.  
  137. net.WriteString(tbl.msg) -- message first
  138.  
  139.  
  140.  
  141. if SERVER then -- pl->pl
  142.  
  143. net.WriteString(tbl.sender)
  144.  
  145. local pl = toplayer(tbl.receiver)
  146.  
  147. if not pl then return false,"Player not found" end
  148.  
  149. local sender = toplayer(tbl.sender)
  150.  
  151.  
  152.  
  153. local blockmsg = pl:GetInfo("chat_pm_friendsonly")
  154.  
  155. if blockmsg and #blockmsg>0 and blockmsg~="0" then
  156.  
  157. if sender and pl.AreFriends and not pl:AreFriends(sender) then
  158.  
  159. return false,(L"player only receives friends chat")..(blockmsg and #blockmsg>1 and (": "..tostring(blockmsg)) or "" )
  160.  
  161. end
  162.  
  163. end
  164.  
  165.  
  166.  
  167. local blockmsg = sender and sender:GetInfo("chat_pm_friendsonly")
  168.  
  169. if blockmsg and #blockmsg>0 and blockmsg~="0" then
  170.  
  171. if sender and sender.AreFriends and not sender:AreFriends(pl) then
  172.  
  173. return false,L"this player is not your friend"
  174.  
  175. end
  176.  
  177. end
  178.  
  179.  
  180.  
  181.  
  182.  
  183. local blockmsg = pl:GetInfo("chat_pm_disable")
  184.  
  185. if blockmsg and #blockmsg>0 and blockmsg~="0" and sender then
  186.  
  187. return false,(L"player has disabled PM")..(blockmsg and #blockmsg>1 and (": "..tostring(blockmsg)) or "" )
  188.  
  189. end
  190.  
  191.  
  192.  
  193. local blockmsg = sender and sender:GetInfo("chat_pm_disable")
  194.  
  195. if blockmsg and #blockmsg>0 and blockmsg~="0" then
  196.  
  197. return false,L"You have disabled PM"
  198.  
  199. end
  200.  
  201.  
  202.  
  203. net.Send(pl)
  204.  
  205. else
  206.  
  207. net.WriteString(tbl.receiver)
  208.  
  209. net.SendToServer()
  210.  
  211.  
  212.  
  213. hook.Call(Tag,nil,tbl.msg,tbl.receiver,tbl,true)
  214.  
  215. end
  216.  
  217. return true
  218.  
  219. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement