--[[ SERVER DIAGNOSTIC TOOL Pune acest resource in folderul [resources] si adauga "ensure server-diagnostic" in server.cfg Rezultatele apar in consola serverului (TxAdmin / terminal) ]] local LINE = string.rep('=', 70) local LINE_SM = string.rep('-', 70) -- ══════════════════════════════════════════════════════════════ -- HELPERS -- ══════════════════════════════════════════════════════════════ local function header(title) print('') print(LINE) print(' ' .. title) print(LINE) end local function ok(msg) print(' [OK] ' .. msg) end local function warn(msg) print(' [WARN] ' .. msg) end local function fail(msg) print(' [FAIL] ' .. msg) end local function info(msg) print(' [INFO] ' .. msg) end local totalChecks = 0 local totalWarnings = 0 local totalFails = 0 local function track(level) totalChecks = totalChecks + 1 if level == 'warn' then totalWarnings = totalWarnings + 1 end if level == 'fail' then totalFails = totalFails + 1 end end -- ══════════════════════════════════════════════════════════════ -- 1. INFORMATII GENERALE SERVER -- ══════════════════════════════════════════════════════════════ local function checkServerInfo() header('1. INFORMATII GENERALE SERVER') local maxPlayers = GetConvarInt('sv_maxclients', 0) info('Max players (sv_maxclients): ' .. tostring(maxPlayers)) local hostname = GetConvar('sv_hostname', 'NECONFIGURAT') info('Hostname: ' .. hostname) if hostname == 'NECONFIGURAT' or hostname == '' then warn('sv_hostname nu este setat in server.cfg') track('warn') else track('ok') end local gametype = GetConvar('gametype', '') local mapname = GetConvar('mapname', '') info('Game type: ' .. (gametype ~= '' and gametype or 'nesetat')) info('Map name: ' .. (mapname ~= '' and mapname or 'nesetat')) local endpoint = GetConvar('sv_listingHostOverride', '') if endpoint ~= '' then info('Listing host override: ' .. endpoint) end local svLicenseKey = GetConvar('sv_licenseKey', '') if svLicenseKey == '' then fail('sv_licenseKey NU este setat! Serverul nu va aparea in lista Cfx.re.') track('fail') else ok('sv_licenseKey este setat.') track('ok') end end -- ══════════════════════════════════════════════════════════════ -- 2. VERIFICARE RESURSE (started / stopped / erori) -- ══════════════════════════════════════════════════════════════ local function checkResources() header('2. VERIFICARE RESURSE') local totalRes = GetNumResources() local started = 0 local stopped = 0 local stoppedList = {} local startedList = {} for i = 0, totalRes - 1 do local resName = GetResourceByFindIndex(i) local resState = GetResourceState(resName) if resState == 'started' then started = started + 1 startedList[#startedList + 1] = resName elseif resState == 'stopped' then stopped = stopped + 1 stoppedList[#stoppedList + 1] = resName elseif resState == 'starting' or resState == 'stopping' then warn('Resursa "' .. resName .. '" este in starea: ' .. resState) track('warn') else fail('Resursa "' .. resName .. '" are stare neasteptata: ' .. tostring(resState)) track('fail') end end info('Total resurse: ' .. totalRes) ok(tostring(started) .. ' resurse pornite') if stopped > 0 then warn(tostring(stopped) .. ' resurse oprite:') for _, name in ipairs(stoppedList) do print(' -> ' .. name) end track('warn') else ok('Nicio resursa oprita.') track('ok') end -- Verificare resurse critice comune print('') print(' ' .. LINE_SM) info('Verificare resurse critice...') local criticalResources = { 'mysql-async', 'oxmysql', 'ghmattimysql', 'es_extended', 'esx_identity', 'esx_skin', 'esx_multicharacter', 'spawnmanager', 'sessionmanager', 'mapmanager', 'hardcap', 'chat', } local foundDb = false local dbResources = { 'mysql-async', 'oxmysql', 'ghmattimysql' } for _, dbRes in ipairs(dbResources) do local state = GetResourceState(dbRes) if state == 'started' then foundDb = true ok('Database driver: "' .. dbRes .. '" este pornit.') track('ok') break end end if not foundDb then fail('NICIUN database driver gasit (mysql-async / oxmysql / ghmattimysql)!') fail('Fara database, serverul NU poate incarca playeri sau date.') track('fail') end for _, resName in ipairs(criticalResources) do -- Skip DB resources (already checked) local isDb = false for _, dbRes in ipairs(dbResources) do if resName == dbRes then isDb = true break end end if not isDb then local state = GetResourceState(resName) if state == 'started' then ok('"' .. resName .. '" - pornit') track('ok') elseif state == 'stopped' then warn('"' .. resName .. '" - OPRIT (poate cauza probleme)') track('warn') elseif state == 'missing' then -- nu toate sunt obligatorii, info doar info('"' .. resName .. '" - nu exista (poate nu e necesar)') else warn('"' .. resName .. '" - stare: ' .. tostring(state)) track('warn') end end end end -- ══════════════════════════════════════════════════════════════ -- 3. VERIFICARE CONEXIUNE DATABASE -- ══════════════════════════════════════════════════════════════ local function checkDatabase() header('3. VERIFICARE CONEXIUNE DATABASE') local connectionString = GetConvar('mysql_connection_string', '') if connectionString == '' then fail('mysql_connection_string NU este setat in server.cfg!') fail('Adauga: set mysql_connection_string "mysql://user:pass@host/database?charset=utf8mb4"') track('fail') return end ok('mysql_connection_string este setat.') track('ok') -- Verifica format de baza (fara a expune date sensibile) if string.find(connectionString, 'mysql://') or string.find(connectionString, 'host=') then ok('Formatul connection string pare valid.') track('ok') else warn('Formatul connection string pare neobisnuit. Verifica documentatia driverului.') track('warn') end -- Verifica daca driverul DB este pornit si incearca un query simplu local oxState = GetResourceState('oxmysql') local mysqlState = GetResourceState('mysql-async') local ghState = GetResourceState('ghmattimysql') if oxState == 'started' then info('Se testeaza conexiunea cu oxmysql...') local success, result = pcall(function() exports['oxmysql']:scalar_async('SELECT 1', {}, function(res) if res then ok('Conexiune database OK (oxmysql SELECT 1 = ' .. tostring(res) .. ')') track('ok') else fail('Query-ul a returnat nil. Conexiunea la database a esuat!') track('fail') end end) end) if not success then fail('Eroare la testarea database: ' .. tostring(result)) track('fail') end elseif mysqlState == 'started' then info('Se testeaza conexiunea cu mysql-async...') local success, result = pcall(function() MySQL.Async.fetchScalar('SELECT 1', {}, function(res) if res then ok('Conexiune database OK (mysql-async SELECT 1 = ' .. tostring(res) .. ')') track('ok') else fail('Query-ul a returnat nil. Conexiunea la database a esuat!') track('fail') end end) end) if not success then fail('Eroare la testarea database: ' .. tostring(result)) track('fail') end elseif ghState == 'started' then info('Driver ghmattimysql detectat, nu se poate testa automat.') else fail('Niciun driver DB pornit - nu se poate testa conexiunea.') track('fail') end end -- ══════════════════════════════════════════════════════════════ -- 4. VERIFICARE CONFIGURARE SERVER.CFG -- ══════════════════════════════════════════════════════════════ local function checkServerCfg() header('4. VERIFICARE CONFIGURARE (convars)') -- OneSync local onesync = GetConvar('onesync', '') if onesync == '' then local onesyncEnabled = GetConvar('onesync_enabled', '') if onesyncEnabled == 'true' then ok('OneSync este activat (onesync_enabled true)') track('ok') else warn('OneSync nu pare activat. Fara OneSync, unele scripturi nu functioneaza.') track('warn') end else ok('OneSync setat la: ' .. onesync) track('ok') end -- Steam Web API Key local steamKey = GetConvar('steam_webApiKey', '') if steamKey == '' then warn('steam_webApiKey nu este setat. Unele sisteme de identifiers pot avea probleme.') track('warn') else ok('steam_webApiKey este setat.') track('ok') end -- sv_endpointPrivacy local endpointPrivacy = GetConvar('sv_endpointPrivacy', '') if endpointPrivacy == 'true' then ok('sv_endpointPrivacy activat (IP-urile playerilor sunt ascunse)') track('ok') else info('sv_endpointPrivacy nu este activat (IP-urile playerilor sunt vizibile)') end -- Locale local locale = GetConvar('esx:locale', GetConvar('ox:locale', '')) if locale ~= '' then info('Limba framework: ' .. locale) end end -- ══════════════════════════════════════════════════════════════ -- 5. VERIFICARE PLAYERI CONECTATI -- ══════════════════════════════════════════════════════════════ local function checkPlayers() header('5. PLAYERI CONECTATI') local players = GetPlayers() local numPlayers = #players info('Playeri online: ' .. numPlayers) if numPlayers > 0 then for _, playerId in ipairs(players) do local name = GetPlayerName(playerId) local ping = GetPlayerPing(playerId) local endpoint = GetPlayerEndpoint(playerId) info(' ID: ' .. playerId .. ' | Nume: ' .. (name or 'necunoscut') .. ' | Ping: ' .. tostring(ping) .. 'ms') if ping > 200 then warn(' -> Playerul ' .. (name or playerId) .. ' are ping ridicat (' .. ping .. 'ms)') track('warn') end end else info('Niciun player conectat momentan.') end end -- ══════════════════════════════════════════════════════════════ -- 6. VERIFICARE PERFORMANTA -- ══════════════════════════════════════════════════════════════ local function checkPerformance() header('6. PERFORMANTA RESURSE (top consumatoare)') info('Se colecteaza date de performanta...') info('(Verifica in TxAdmin -> Resources pentru timpi detaliati)') info('(Sau foloseste comanda "resmon true" in consola pentru monitor live)') -- Gather resource metadata local totalRes = GetNumResources() local resCount = 0 for i = 0, totalRes - 1 do local resName = GetResourceByFindIndex(i) local resState = GetResourceState(resName) if resState == 'started' then resCount = resCount + 1 end end if resCount > 150 then warn('Ai ' .. resCount .. ' resurse pornite. Multe resurse = performanta redusa.') warn('Incearca sa dezactivezi resursele pe care nu le folosesti.') track('warn') elseif resCount > 100 then info('Ai ' .. resCount .. ' resurse pornite. E un numar mare, dar acceptabil.') else ok(resCount .. ' resurse pornite. Numar acceptabil.') track('ok') end end -- ══════════════════════════════════════════════════════════════ -- 7. VERIFICARE PORTURI SI RETEA -- ══════════════════════════════════════════════════════════════ local function checkNetwork() header('7. RETEA SI PORTURI') local endpoint = GetConvar('endpoint_add_tcp', '') local udp = GetConvar('endpoint_add_udp', '') if endpoint ~= '' then info('TCP endpoint: ' .. endpoint) else info('TCP endpoint: default (0.0.0.0:30120)') end if udp ~= '' then info('UDP endpoint: ' .. udp) else info('UDP endpoint: default (0.0.0.0:30120)') end info('Daca playerii nu se pot conecta:') info(' 1. Verifica ca portul 30120 (TCP + UDP) este deschis in firewall') info(' 2. Verifica port forwarding pe router (daca hostezi acasa)') info(' 3. Verifica ca hostul nu blocheaza portul') info(' 4. Incearca sa te conectezi direct cu IP-ul: connect :30120') end -- ══════════════════════════════════════════════════════════════ -- 8. VERIFICARE ESX (daca exista) -- ══════════════════════════════════════════════════════════════ local function checkESX() local esxState = GetResourceState('es_extended') if esxState ~= 'started' and esxState ~= 'stopped' then return -- ESX nu e instalat, skip end header('8. VERIFICARE ESX FRAMEWORK') if esxState == 'started' then ok('es_extended este pornit.') track('ok') else fail('es_extended este OPRIT! Framework-ul nu functioneaza.') track('fail') return end -- Verificare resurse ESX comune local esxResources = { { name = 'esx_identity', required = true }, { name = 'esx_skin', required = false }, { name = 'skinchanger', required = false }, { name = 'esx_multicharacter', required = false }, { name = 'esx_society', required = false }, { name = 'esx_addonaccount', required = false }, { name = 'esx_menu_default', required = false }, { name = 'esx_menu_dialog', required = false }, } for _, res in ipairs(esxResources) do local state = GetResourceState(res.name) if state == 'started' then ok('"' .. res.name .. '" - pornit') track('ok') elseif state == 'stopped' then if res.required then fail('"' .. res.name .. '" - OPRIT (necesar!)') track('fail') else warn('"' .. res.name .. '" - oprit') track('warn') end end end end -- ══════════════════════════════════════════════════════════════ -- RAPORT FINAL -- ══════════════════════════════════════════════════════════════ local function printSummary() print('') print('') print(LINE) print(' RAPORT FINAL DIAGNOSTICARE') print(LINE) print('') if totalFails > 0 then fail('ERORI CRITICE: ' .. totalFails .. ' -- Acestea trebuie rezolvate!') else ok('Nicio eroare critica gasita.') end if totalWarnings > 0 then warn('Avertismente: ' .. totalWarnings .. ' -- Verifica-le pentru siguranta.') else ok('Niciun avertisment.') end info('Total verificari efectuate: ' .. totalChecks) print('') if totalFails > 0 then print(' >>> RECOMANDARE: Rezolva mai intai erorile [FAIL] de mai sus.') print(' >>> Cele mai comune cauze: database down, resursa critica oprita,') print(' >>> connection string gresit, sau port blocat.') elseif totalWarnings > 0 then print(' >>> RECOMANDARE: Serverul pare functional, dar verifica avertismentele.') else print(' >>> Serverul pare configurat corect din punct de vedere al scripturilor.') print(' >>> Daca tot nu functioneaza, problema poate fi de la host/retea.') print(' >>> Incearca: restart server, contacteaza hosting provider-ul.') end print('') print(' TIP: Deschide F8 in joc pentru erori client-side.') print(' TIP: Foloseste "resmon true" in consola pentru monitorizare live.') print(LINE) print('') end -- ══════════════════════════════════════════════════════════════ -- RUN ALL CHECKS -- ══════════════════════════════════════════════════════════════ CreateThread(function() -- Asteptam cateva secunde ca toate resursele sa porneasca Wait(5000) print('') print('') print(LINE) print(' SERVER DIAGNOSTIC TOOL - START') print(' ' .. os.date('%Y-%m-%d %H:%M:%S')) print(LINE) checkServerInfo() checkResources() checkDatabase() checkServerCfg() checkPlayers() checkPerformance() checkNetwork() checkESX() printSummary() end) -- ══════════════════════════════════════════════════════════════ -- COMANDA MANUALA: /diag (in consola sau in chat ca admin) -- ══════════════════════════════════════════════════════════════ RegisterCommand('diag', function(source) if source ~= 0 then -- Executat de un player - verificam daca e admin local playerName = GetPlayerName(source) print('[DIAG] Playerul ' .. (playerName or source) .. ' a rulat diagnosticarea.') end -- Reset counters totalChecks = 0 totalWarnings = 0 totalFails = 0 checkServerInfo() checkResources() checkDatabase() checkServerCfg() checkPlayers() checkPerformance() checkNetwork() checkESX() printSummary() end, true) -- restricted = true (doar admin / consola) print('[DIAGNOSTIC] Resource pornit. Diagnosticarea ruleaza in 5 secunde...') print('[DIAGNOSTIC] Poti rula oricand comanda "diag" in consola.')