Skip to content

Commit

Permalink
fix(server/events): locales issue and promise error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
D4isDAVID committed Jan 20, 2024
1 parent 87493f1 commit f1028fe
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion locales/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"on_duty": "Вече сте на дежурство!",
"off_duty": "Вече не сте на дежурство!",
"checking_ban": "Здравей %s. Проверяваме дали сте баннат.",
"join_server": "Добре дошъл %s в {Име на сървъра}.",
"join_server": "Добре дошъл %s в %s.",
"checking_whitelisted": "Здравей %s. Проверяваме вашето разрешение.",
"exploit_banned": "Бяхте баннат за измама. Проверете нашия Discord за повече информация: %s",
"exploit_dropped": "Бяхте изхвърлен за използване на експлоит"
Expand Down
2 changes: 1 addition & 1 deletion locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"on_duty": "Nyní jste v práci!",
"off_duty": "Nyní jste mimo službu!",
"checking_ban": "Ahoj %s. Kontrolujeme, zda jste zakázaný.",
"join_server": "Vítejte %s na {Název Serveru}.",
"join_server": "Vítejte %s na %s.",
"checking_whitelisted": "Ahoj %s. Kontrolujeme vaši povolenost.",
"exploit_banned": "Byli jste zakázáni za podvádění. Podívejte se na náš Discord pro více informací: %s",
"exploit_dropped": "Byli jste vyhoštěni za zneužívání",
Expand Down
2 changes: 1 addition & 1 deletion locales/is.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"on_duty": "Þú ert nú á vakt!",
"off_duty": "Þú ert nú á vakt!",
"checking_ban": "Halló %s. Við erum að athuga hvort þú sért bannaður.",
"join_server": "Velkominn %s til {Nafn netþjóns}.",
"join_server": "Velkominn %s til %s.",
"checking_whitelisted": "Halló %s. Við erum að athuga vasapeningana þína.",
"exploit_banned": "Þú hefur verið bannaður fyrir svindl. Athugaðu Discord okkar til að fá frekari upplýsingar: %s",
"exploit_dropped": "Þér hefur verið sparkað fyrir arðrán"
Expand Down
2 changes: 1 addition & 1 deletion locales/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"on_duty": "Du är nu i tjänst!",
"off_duty": "Du har gått ur tjänst!",
"checking_ban": "Hej %s. Vi kollar ifall du är bannad.",
"join_server": "Välkommen %s till Bygden RP.",
"join_server": "Välkommen %s till %s.",
"checking_whitelisted": "Hej %s. Vi kollar efter giltighet i ditt medlemskap."
}
}
17 changes: 10 additions & 7 deletions server/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ end)
---@field done fun(failureReason?: string) finalizes deferrals. If failureReason is present, user will be refused connection and shown reason. Need to wait 1 tick after calling other deferral methods before calling done.

-- Player Connecting
---@param name any
---@param name string
---@param _ any
---@param deferrals Deferrals
local function onPlayerConnecting(name, _, deferrals)
Expand Down Expand Up @@ -96,7 +96,7 @@ local function onPlayerConnecting(name, _, deferrals)
end)

if serverConfig.whitelist and success then
deferrals.update(string.format(locale('info.checking_whitelisted'), name))
deferrals.update(locale('info.checking_whitelisted', name))
success, err = pcall(function()
if not IsWhitelisted(src --[[@as Source]]) then
Wait(0) -- Mandatory wait
Expand All @@ -111,9 +111,15 @@ local function onPlayerConnecting(name, _, deferrals)
databasePromise:resolve()
end)

local onError = function(err)
deferrals.done(locale('error.connecting_error'))
lib.print.error(err)
end

-- wait for database to finish
databasePromise:next(function()
deferrals.update(locale('info.join_server', name))
local serverName = GetConvar('sv_projectName', GetConvar('sv_hostname', 'Server'))
deferrals.update(locale('info.join_server', name, serverName))

-- Mandatory wait
Wait(0)
Expand All @@ -123,10 +129,7 @@ local function onPlayerConnecting(name, _, deferrals)
else
deferrals.done()
end
end, function(err)
deferrals.done(locale('error.connecting_error'))
lib.print.error(err)
end)
end, onError):next(function() end, onError)

-- if conducting db checks for too long then raise error
while databasePromise.state == 0 do
Expand Down

0 comments on commit f1028fe

Please sign in to comment.