Skip to content

Commit

Permalink
srv shutdown hook and close sockets (request becuase it lagged server…
Browse files Browse the repository at this point in the history
… when changelevel)
  • Loading branch information
troit5ky committed Sep 13, 2024
1 parent 38b9735 commit 620e597
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
2 changes: 2 additions & 0 deletions lua/relay/sv_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Discord = {

["srvStarted"] = true,

["srvShutdown"] = true,

["hideBots"] = false,

["language"] = "ru",
Expand Down
5 changes: 5 additions & 0 deletions lua/relay/sv_msgGet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,8 @@ timer.Simple( 3, function()
socket:open()
Discord.isSocketReloaded = false
end )

-- request (lag when changelevel)
hook.Add("ShutDown", "!!discord_srvShutdown_socketdown", function()
socket:closeNow()
end)
41 changes: 28 additions & 13 deletions lua/relay/sv_msgSend.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,32 @@ gameevent.Listen( "player_disconnect" )
hook.Add("player_disconnect", "!!discord_onDisconnect", plyDisconnect)

if Discord.srvStarted then
hook.Add("Initialize", "!!discord_srvStarted", function()
local form = {
["username"] = Discord.hookname,
["embeds"] = {{
["title"] = DiscordString.serverStarted,
["description"] = DiscordString.currentMapAlt .. game.GetMap(),
["color"] = 5793266
}}
}

Discord.send(form)
hook.Remove("Initialize", "!!discord_srvStarted")
end)
hook.Add("Initialize", "!!discord_srvStarted", function()
local form = {
["username"] = Discord.hookname,
["embeds"] = {{
["title"] = DiscordString.serverStarted,
["description"] = DiscordString.currentMapAlt .. game.GetMap(),
["color"] = 5793266
}}
}

Discord.send(form)
hook.Remove("Initialize", "!!discord_srvStarted")
end)
end
if Discord.srvShutdown then
hook.Add("ShutDown", "!!discord_srvShutdown", function()
local form = {
["username"] = Discord.hookname,
["embeds"] = {{
["title"] = DiscordString.serverShutdown,
["description"] = '',
["color"] = 16730698
}}
}

Discord.send(form)
hook.Remove("Initialize", "!!discord_srvShutdown")
end)
end
1 change: 1 addition & 0 deletions lua/relay/translations/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ DiscordString = {
["connected"] = " connected",
["disconnected"] = " disconnected",
["serverStarted"] = "Server Started!",
["serverShutdown"] = "The server has shut down",
["currentMapAlt"] = "Current Map - "
}
1 change: 1 addition & 0 deletions lua/relay/translations/ru.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ DiscordString = {
["connected"] = " подключился",
["disconnected"] = " отключился",
["serverStarted"] = "Сервер запущен!",
["serverShutdown"] = "Сервер выключился",
["currentMapAlt"] = "Карта сейчас - "
}

0 comments on commit 620e597

Please sign in to comment.