diff --git a/client/events.lua b/client/events.lua index 13eb73e..48ea7c3 100644 --- a/client/events.lua +++ b/client/events.lua @@ -1,3 +1,7 @@ +RegisterNetEvent("ND:notifyClient", function(...) + NDCore.notify(...) +end) + -- updates the money on the client. RegisterNetEvent("ND:updateMoney", function(cash, bank) if not NDCore.player then return end diff --git a/server/player.lua b/server/player.lua index 0cc481b..bb578bd 100644 --- a/server/player.lua +++ b/server/player.lua @@ -434,6 +434,35 @@ local function createCharacterTable(info) return self end +function NDCore.avoidSavingLocation(coords, dist) + avoidSavingLastLocations[#avoidSavingLastLocations+1] = { coords = coords, dist = dist} +end + +function NDCore.validateCharacterData(charInfo) + local errors = {} + + local function checkLength(field, value, maxLength) + if type(value) ~= "string" then return end + if #value > maxLength then + table.insert(errors, string.format("%s is too long (max %d, got %d)", field, maxLength, #value)) + end + end + + if charInfo.name then checkLength("game name", charInfo.name, 50) end + if charInfo.firstname then checkLength("firstname", charInfo.firstname, 50) end + if charInfo.lastname then checkLength("lastname", charInfo.lastname, 50) end + if charInfo.dob then checkLength("dob", charInfo.dob, 50) end + if charInfo.gender then checkLength("gender", charInfo.gender, 50) end + if type(charInfo.cash) ~= "number" then table.insert(errors, "cash must be a number") end + if type(charInfo.bank) ~= "number" then table.insert(errors, "bank must be a number") end + + if #errors > 0 then + return false, errors + else + return true, {} + end +end + ---@param src number ---@param info table ---@return table @@ -457,6 +486,18 @@ function NDCore.newCharacter(src, info) inventory = info.inventory or {} } + local valid, issues = NDCore.validateCharacterData(charInfo) + if not valid then + for _, err in ipairs(issues) do + Wait(100) + TriggerClientEvent("ND:notifyClient", src, { + description = err, + type = "error" + }) + end + return + end + charInfo.id = MySQL.insert.await("INSERT INTO nd_characters (identifier, name, firstname, lastname, dob, gender, cash, bank, phonenumber, `groups`, metadata, inventory) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", { identifier, charInfo.name,