Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if SERVER then AddCSLuaFile() end
- local L = translation and translation.L or function(s) return s end
- local DEBUG=false
- local Tag="pmail"
- if SERVER then
- util.AddNetworkString(Tag)
- end
- module(Tag,package.seeall)
- local Dbg=DEBUG and function(...) Msg("["..Tag.."] ")print(...)end or function()end
- net.Receive(Tag,function( len,pl )
- local tbl = {}
- if CLIENT then
- tbl.msg = net.ReadString()
- tbl.sender = net.ReadString()
- else
- tbl.msg = net.ReadString()
- tbl.receiver = net.ReadString()
- end
- if SERVER then
- tbl.sender = pl:SteamID()
- local msg = tbl.msg
- if not chatbox.ValidMessage ( msg ) then return end
- if pl.raybans and pl.raybans.chat then
- return
- end
- if msg:len()>64*1024-128 then
- ErrorNoHalt("[ChatPM] IGNORING TOO LONG MESSAGE: len="..msg:len().." from "..tostring(pl))
- return
- end
- -- Anti spam
- if chatbox.SpamWatch( pl, msg ) then
- Send{
- msg=L"Spam protection triggered. You're sending too fast!",
- sender="",
- receiver=pl:SteamID(),
- }
- return
- end
- end
- OnReceive( tbl )
- end )
- function toplayer(steamid)
- Dbg("Finding",steamid)
- for k,v in pairs(player.GetAll()) do
- if v:SteamID()==steamid then
- return v
- end
- end
- end
- function Send(tbl)
- net.Start(Tag)
- net.WriteString(tbl.msg) -- message first
- if SERVER then -- pl->pl
- net.WriteString(tbl.sender)
- local pl = toplayer(tbl.receiver)
- if not pl then return false,"Player not found" end
- local sender = toplayer(tbl.sender)
- local blockmsg = pl:GetInfo("chat_pm_friendsonly")
- if blockmsg and #blockmsg>0 and blockmsg~="0" then
- if sender and pl.AreFriends and not pl:AreFriends(sender) then
- return false,(L"player only receives friends chat")..(blockmsg and #blockmsg>1 and (": "..tostring(blockmsg)) or "" )
- end
- end
- local blockmsg = sender and sender:GetInfo("chat_pm_friendsonly")
- if blockmsg and #blockmsg>0 and blockmsg~="0" then
- if sender and sender.AreFriends and not sender:AreFriends(pl) then
- return false,L"this player is not your friend"
- end
- end
- local blockmsg = pl:GetInfo("chat_pm_disable")
- if blockmsg and #blockmsg>0 and blockmsg~="0" and sender then
- return false,(L"player has disabled PM")..(blockmsg and #blockmsg>1 and (": "..tostring(blockmsg)) or "" )
- end
- local blockmsg = sender and sender:GetInfo("chat_pm_disable")
- if blockmsg and #blockmsg>0 and blockmsg~="0" then
- return false,L"You have disabled PM"
- end
- net.Send(pl)
- else
- net.WriteString(tbl.receiver)
- net.SendToServer()
- hook.Call(Tag,nil,tbl.msg,tbl.receiver,tbl,true)
- end
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement