mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-17 13:53:45 +03:00
Upload
This commit is contained in:
43
lua/vyhub/shared/sh_01_config.lua
Normal file
43
lua/vyhub/shared/sh_01_config.lua
Normal file
@@ -0,0 +1,43 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
-- DEFAULTS
|
||||
VyHub.Config.date_format = VyHub.Config.date_format or "%Y-%m-%d %H:%M:%S %z"
|
||||
|
||||
if SERVER then
|
||||
VyHub.Config.advert_interval = VyHub.Config.advert_interval or 180
|
||||
VyHub.Config.advert_prefix = VyHub.Config.advert_prefix or "[★] "
|
||||
|
||||
-- Do not allow too small refresh intervals
|
||||
if VyHub.Config.player_refresh_time < 5 then
|
||||
VyHub.Config.player_refresh_time = 5
|
||||
end
|
||||
if VyHub.Config.group_refresh_time < 5 then
|
||||
VyHub.Config.group_refresh_time = 5
|
||||
end
|
||||
|
||||
VyHub.Config.ban_message = VyHub.Config.ban_message or ">>> Ban Message <<<" .. "\n\n"
|
||||
.. VyHub.lang.other.reason .. ": %reason%" .. "\n"
|
||||
.. VyHub.lang.other.ban_date .. ": %ban_date%" .. "\n"
|
||||
.. VyHub.lang.other.unban_date .. ": %unban_date%" .. "\n"
|
||||
.. VyHub.lang.other.admin .. ": %admin%" .. "\n"
|
||||
.. VyHub.lang.other.id .. ": %id%" .. "\n\n"
|
||||
.. VyHub.lang.other.unban_url .. ": %unban_url%" .. "\n\n"
|
||||
|
||||
VyHub.Config.commands_shop = VyHub.Config.commands_shop or { '!shop' }
|
||||
VyHub.Config.commands_bans = VyHub.Config.commands_bans or { '!bans' }
|
||||
VyHub.Config.commands_warnings = VyHub.Config.commands_warnings or { '!warnings' }
|
||||
VyHub.Config.commands_news = VyHub.Config.commands_news or { '!news' }
|
||||
VyHub.Config.commands_profile = VyHub.Config.commands_profile or { '!user' }
|
||||
VyHub.Config.commands_warn = VyHub.Config.commands_warn or { '!warn' }
|
||||
VyHub.Config.commands_dashboard = VyHub.Config.commands_dashboard or { '!dashboard' }
|
||||
|
||||
VyHub.Config.strict_group_sync = VyHub.Config.strict_group_sync or false
|
||||
end
|
||||
19
lua/vyhub/shared/sh_group.lua
Normal file
19
lua/vyhub/shared/sh_group.lua
Normal file
@@ -0,0 +1,19 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
VyHub.Group = VyHub.Group or {}
|
||||
|
||||
function VyHub.Group:get(groupname)
|
||||
if VyHub.groups_mapped == nil then
|
||||
return nil
|
||||
end
|
||||
|
||||
return VyHub.groups_mapped[groupname]
|
||||
end
|
||||
110
lua/vyhub/shared/sh_lang.lua
Normal file
110
lua/vyhub/shared/sh_lang.lua
Normal file
@@ -0,0 +1,110 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local f = string.format
|
||||
local json = VyHub.Lib.json
|
||||
|
||||
VyHub.Lang = VyHub.Lang or {}
|
||||
VyHub.lang = VyHub.lang or nil
|
||||
|
||||
if SERVER then
|
||||
util.AddNetworkString("vyhub_lang")
|
||||
|
||||
VyHub.Lang.compressed = VyHub.Lang.compressed or nil
|
||||
|
||||
function VyHub.Lang:load()
|
||||
local f_en = file.Open("vyhub/lang/en.json", "r", "LUA")
|
||||
|
||||
if f_en == nil then
|
||||
VyHub:msg("Missing language file en.json!!! PLEASE MAKE SURE TO DOWNLOAD VYHUB-GMOD ON THE GITHUB RELESES PAGE! https://github.com/matbyte-com/vyhub-gmod/releases", "error")
|
||||
return
|
||||
end
|
||||
|
||||
local en = json.decode(f_en:Read())
|
||||
f_en:Close()
|
||||
|
||||
if not istable(en) then
|
||||
VyHub:msg("Could not load language file en.json!", "error")
|
||||
return
|
||||
end
|
||||
|
||||
VyHub.lang = en
|
||||
|
||||
VyHub:msg("Loaded language en.")
|
||||
|
||||
if VyHub.Config.lang != 'en' then
|
||||
local f_custom = file.Open(f("vyhub/lang/%s.json", VyHub.Config.lang), "r", "LUA")
|
||||
|
||||
if f_custom != nil then
|
||||
local custom = json.decode(f_custom:Read())
|
||||
f_custom:Close()
|
||||
|
||||
if istable(custom) then
|
||||
table.Merge(VyHub.lang, custom)
|
||||
VyHub:msg(f("Loaded language %s.", VyHub.Config.lang))
|
||||
else
|
||||
VyHub:msg(f("Could not load language file %s.json!", VyHub.Config.lang), "warning")
|
||||
end
|
||||
else
|
||||
VyHub:msg(f("Missing language file %s.json.", VyHub.Config.lang), "warning")
|
||||
end
|
||||
end
|
||||
|
||||
VyHub.Lang.compressed = util.Compress(json.encode(VyHub.lang))
|
||||
end
|
||||
|
||||
if VyHub.lang == nil then
|
||||
VyHub.Lang:load()
|
||||
end
|
||||
|
||||
net.Receive("vyhub_lang", function(_, ply)
|
||||
if not IsValid(ply) then return end
|
||||
if not VyHub.Lang.compressed then return end
|
||||
|
||||
local len = #VyHub.Lang.compressed
|
||||
|
||||
net.Start("vyhub_lang")
|
||||
net.WriteUInt(len, 16)
|
||||
net.WriteData(VyHub.Lang.compressed, len)
|
||||
net.Send(ply)
|
||||
end)
|
||||
end
|
||||
|
||||
if CLIENT then
|
||||
function VyHub.Lang:load()
|
||||
net.Start("vyhub_lang")
|
||||
net.SendToServer()
|
||||
end
|
||||
|
||||
net.Receive("vyhub_lang", function()
|
||||
timer.Remove("vyhub_lang_load")
|
||||
|
||||
local len = net.ReadUInt(16)
|
||||
local lang_compr = net.ReadData(len)
|
||||
|
||||
VyHub.lang = json.decode(util.Decompress(lang_compr))
|
||||
|
||||
VyHub:msg("Loaded language.")
|
||||
|
||||
hook.Run("vyhub_lang_loaded")
|
||||
end)
|
||||
|
||||
hook.Add("Initialize", "vyhub_lang_Initialize", function ()
|
||||
VyHub.Lang:load()
|
||||
|
||||
timer.Create("vyhub_lang_load", 5, 5, function ()
|
||||
if VyHub.lang == nil then
|
||||
VyHub.Lang:load()
|
||||
else
|
||||
timer.Remove("vyhub_lang_load")
|
||||
end
|
||||
end)
|
||||
end)
|
||||
end
|
||||
322
lua/vyhub/shared/sh_util.lua
Normal file
322
lua/vyhub/shared/sh_util.lua
Normal file
@@ -0,0 +1,322 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local f = string.format
|
||||
local date = VyHub.Lib.date
|
||||
|
||||
VyHub.Util = VyHub.Util or {}
|
||||
VyHub.Util.chat_commands = VyHub.Util.chat_commands or {}
|
||||
|
||||
if SERVER then
|
||||
util.AddNetworkString("vyhub_print_chat")
|
||||
util.AddNetworkString("vyhub_play_sound")
|
||||
util.AddNetworkString("vyhub_open_url")
|
||||
end
|
||||
|
||||
function VyHub.Util:format_datetime(unix_timestamp)
|
||||
unix_timestamp = unix_timestamp or os.time()
|
||||
|
||||
local tz_wrong = os.date("%z", unix_timestamp)
|
||||
local timezone = f("%s:%s", string.sub(tz_wrong, 1, 3), string.sub(tz_wrong, 4, 5))
|
||||
|
||||
return os.date("%Y-%m-%dT%H:%M:%S" .. timezone, unix_timestamp)
|
||||
end
|
||||
|
||||
function VyHub.Util:is_server(obj)
|
||||
if type(obj) == "Entity" and (obj.EntIndex and obj:EntIndex() == 0) and !IsValid(obj) then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function VyHub.Util:iso_to_unix_timestamp(datetime)
|
||||
if datetime == nil then return nil end
|
||||
|
||||
local pd = date(datetime)
|
||||
|
||||
if pd == nil then return nil end
|
||||
|
||||
local time = os.time(
|
||||
{
|
||||
year = pd:getyear(),
|
||||
month = pd:getmonth(),
|
||||
day = pd:getday(),
|
||||
hour = pd:gethours(),
|
||||
minute = pd:getminutes(),
|
||||
second = pd:getseconds(),
|
||||
}
|
||||
)
|
||||
|
||||
return time
|
||||
end
|
||||
|
||||
function VyHub.Util:get_ply_by_nick(nick)
|
||||
nick = string.lower(nick);
|
||||
|
||||
for _, v in ipairs(player.GetHumans()) do
|
||||
if(string.find(string.lower(v:Name()), nick, 1, true) != nil)
|
||||
then return v;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function VyHub.Util:register_chat_command(strCommand, Func)
|
||||
if !strCommand || !Func then return end
|
||||
|
||||
for k, v in pairs( VyHub.Util.chat_commands ) do
|
||||
if( strCommand == k ) then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
VyHub.Util.chat_commands[ tostring( strCommand ) ] = Func;
|
||||
end
|
||||
|
||||
function VyHub.Util:concat_args(args, pos)
|
||||
local toconcat = {}
|
||||
|
||||
if pos > 1 then
|
||||
for i = pos, #args, 1 do
|
||||
toconcat[#toconcat+1] = args[i]
|
||||
end
|
||||
end
|
||||
|
||||
return string.Implode(" ", toconcat)
|
||||
end
|
||||
|
||||
|
||||
if SERVER then
|
||||
hook.Add("PlayerSay", "vyhub_util_PlayerSay", function(ply, message)
|
||||
if VyHub.ready then
|
||||
local chat_string = string.Explode(" ", message)
|
||||
local ret = nil
|
||||
|
||||
for k, v in pairs( VyHub.Util.chat_commands ) do
|
||||
if( string.lower(chat_string[1]) == string.lower(k) ) then
|
||||
table.remove(chat_string, 1)
|
||||
ret = v(ply, chat_string)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if ret != nil then
|
||||
return ret
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local colors = {
|
||||
red = Color(255, 24, 35),
|
||||
green = Color(45, 170, 0),
|
||||
blue = Color(0, 115, 204),
|
||||
yellow = Color(229, 221, 0),
|
||||
pink = Color(229, 0, 218),
|
||||
}
|
||||
|
||||
-- Takes a str message with colors and returns a table
|
||||
function VyHub.Util:replace_colors(message, no_color)
|
||||
local resultTable = {}
|
||||
local currentIndex = 1
|
||||
|
||||
local function getColor(colorName)
|
||||
if colors[colorName] then
|
||||
return colors[colorName]
|
||||
else
|
||||
return no_color
|
||||
end
|
||||
end
|
||||
|
||||
local function addStringToTable(str, color)
|
||||
table.insert(resultTable, color)
|
||||
table.insert(resultTable, str)
|
||||
end
|
||||
|
||||
local tags = {}
|
||||
|
||||
-- Extract all color tags and their corresponding content
|
||||
for tag, content in string.gmatch(message, "<([%l]+)>([^<]+)</%1>") do
|
||||
table.insert(tags, {tag = tag, content = content})
|
||||
end
|
||||
|
||||
-- Process the string, splitting it based on the color tags
|
||||
for _, tagData in ipairs(tags) do
|
||||
local startIndex, endIndex = string.find(message, f("<(%s)>[^<]+</%s>", string.PatternSafe(tagData.tag), string.PatternSafe(tagData.tag)), currentIndex, false)
|
||||
|
||||
if startIndex then
|
||||
local str = string.sub(message, currentIndex, startIndex - 1)
|
||||
|
||||
addStringToTable(str, no_color)
|
||||
addStringToTable(tagData.content, getColor(tagData.tag))
|
||||
|
||||
currentIndex = endIndex + 1
|
||||
end
|
||||
end
|
||||
|
||||
-- Append any remaining part of the string
|
||||
local str = string.sub(message, currentIndex)
|
||||
if str != "" then
|
||||
addStringToTable(str, no_color)
|
||||
end
|
||||
|
||||
return resultTable
|
||||
end
|
||||
|
||||
local color_tag = Color(0, 187, 255)
|
||||
|
||||
function VyHub.Util:print_chat(ply, message, tag, color)
|
||||
color = color or color_white
|
||||
|
||||
if SERVER then
|
||||
if IsValid(ply) then
|
||||
if not VyHub.Config.chat_tag then
|
||||
VyHub.Config.chat_tag = "[VyHub] "
|
||||
end
|
||||
|
||||
if not tag then
|
||||
tag = VyHub.Config.chat_tag
|
||||
end
|
||||
|
||||
message = string.Replace(message, '\r', '')
|
||||
message = string.Replace(message, '\n', '')
|
||||
|
||||
net.Start("vyhub_print_chat")
|
||||
net.WriteString(message)
|
||||
net.WriteString(tag)
|
||||
net.WriteColor(color)
|
||||
net.Send(ply)
|
||||
end
|
||||
elseif CLIENT then
|
||||
msg_table = VyHub.Util:replace_colors(message, color)
|
||||
|
||||
chat.AddText(color_tag, tag, color_white, unpack(msg_table))
|
||||
end
|
||||
end
|
||||
|
||||
function VyHub.Util:print_chat_steamid(steamid, message, tag, color)
|
||||
if steamid != nil and steamid != false then
|
||||
local ply = player.GetBySteamID64(steamid)
|
||||
|
||||
if IsValid(ply) then
|
||||
VyHub.Util:print_chat(ply, message, tag, color)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function VyHub.Util:play_sound_steamid(steamid, url)
|
||||
if steamid then
|
||||
local ply = player.GetBySteamID64(steamid)
|
||||
|
||||
if IsValid(ply) then
|
||||
return VyHub.Util:play_sound(ply, url)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function VyHub.Util:play_sound(ply, url)
|
||||
if SERVER then
|
||||
if IsValid(ply) then
|
||||
net.Start("vyhub_play_sound")
|
||||
net.WriteString(url)
|
||||
net.Send(ply)
|
||||
end
|
||||
elseif CLIENT then
|
||||
sound.PlayURL ( url, "", function() end)
|
||||
end
|
||||
end
|
||||
|
||||
function VyHub.Util:open_url(ply, url)
|
||||
if SERVER then
|
||||
if IsValid(ply) then
|
||||
net.Start("vyhub_open_url")
|
||||
net.WriteString(url)
|
||||
net.Send(ply)
|
||||
end
|
||||
elseif CLIENT then
|
||||
gui.OpenURL(url)
|
||||
end
|
||||
end
|
||||
|
||||
function VyHub.Util:print_chat_all(message, tag, color)
|
||||
for _, ply in ipairs(player.GetHumans()) do
|
||||
VyHub.Util:print_chat(ply, message, tag, color)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function VyHub.Util:get_player_by_nick(nick)
|
||||
nick = string.lower(nick);
|
||||
|
||||
for _,v in ipairs(player.GetHumans()) do
|
||||
if(string.find(string.lower(v:Name()), nick, 1, true) != nil)
|
||||
then return v;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function VyHub.Util:hex2rgb(hex)
|
||||
hex = hex:gsub("#","")
|
||||
if(string.len(hex) == 3) then
|
||||
return Color(tonumber("0x"..hex:sub(1,1)) * 17, tonumber("0x"..hex:sub(2,2)) * 17, tonumber("0x"..hex:sub(3,3)) * 17)
|
||||
elseif(string.len(hex) == 6) then
|
||||
return Color(tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6)))
|
||||
else
|
||||
return color_white
|
||||
end
|
||||
end
|
||||
|
||||
function VyHub.Util:iso_ts_to_local_str(iso_ts)
|
||||
local bias = VyHub.Config.time_offset != nil and -math.Round(VyHub.Config.time_offset * 60 * 60) or nil
|
||||
|
||||
return date(iso_ts):setbias(bias):tolocal():fmt(VyHub.Config.date_format)
|
||||
end
|
||||
|
||||
|
||||
function VyHub.Util:invalid_str(str_list)
|
||||
for _, str in ipairs(str_list) do
|
||||
if str == nil or string.Trim(str) == "" then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function VyHub.Util:escape_concommand_str(str)
|
||||
str = string.Replace(str, '"', "'")
|
||||
|
||||
return str
|
||||
end
|
||||
|
||||
|
||||
|
||||
if CLIENT then
|
||||
net.Receive("vyhub_print_chat", function ()
|
||||
local message = net.ReadString()
|
||||
local tag = net.ReadString()
|
||||
local color = net.ReadColor()
|
||||
|
||||
VyHub.Util:print_chat(nil, message, tag, color)
|
||||
end)
|
||||
|
||||
net.Receive("vyhub_play_sound", function ()
|
||||
local url = net.ReadString()
|
||||
|
||||
VyHub.Util:play_sound(nil, url)
|
||||
end)
|
||||
|
||||
net.Receive("vyhub_open_url", function ()
|
||||
local url = net.ReadString()
|
||||
|
||||
VyHub.Util:open_url(nil, url)
|
||||
end)
|
||||
end
|
||||
Reference in New Issue
Block a user