реконнект

who?.

Участник
Автор темы
56
2
ищу реконнект где после частых реконнектов не блокирует сервер айпи адресс
(или исправьте что я накосячил..
Lua:
local ev = require 'lib.samp.events'

require 'moonloader'

disconnected = false
rec_sec = 120
joinCount = 0

del_players = false

function ev.onRemoveBuilding()
    if joinCount > 1 then return false end
end

function ev.onSendClientJoin()
    joinCount = joinCount + 1
end

function main()
    while not isSampAvailable() do wait(0) end wait(1)



    while true do wait(0)

        if isKeyDown(VK_LMENU) and isKeyDown(VK_LSHIFT)
            then

            if isKeyJustPressed(VK_D) and isKeyCheckAvailable() then CloseConnect() end
            if isKeyJustPressed(VK_C) and isKeyCheckAvailable() then sampSetGamestate(1)  end

            if isKeyJustPressed(VK_R) then
                -- sampSetGamestate(5) --disconnect
                CloseConnect()
                -- sampDisconnectWithReason(0)
                for i = 1,3 do
                    printStringNow('~w~reconnect > ~y~ '..i..'~w~!',850)
                    wait(1050)
                    if i == 3 then
                        sampSetGamestate(1)
                    end
                end
            end

        end

        if disconnected then
            if sampIsLocalPlayerSpawned() then
                disconnected = false
            end
            if isKeyJustPressed(VK_H) then
                disconnected = false
                printStringNow('~w~ auto-reconnect ~r~OFF~w~!',5000)
                print('{FFFFFF}auto-reconnect {FF0000}OFF{FFFFFF}!')
            end
        end

    end
end

function onReceivePacket(id, bs)
    lua_thread.create(function()
        if id == 32 or id == 33 or id == 36 or id == 37 and disconnected == false --[[шоб не флудило~]]
         then
            disconnected = true
            -- sampDisconnectWithReason(quit)
            for i = 1,rec_sec do
                 -- if disconnected ~= false then
                    if i == rec_sec and disconnected then sampSetGamestate(1)  end
                    addOneOffSound(0.0, 0.0, 0.0, 1085)
                    printStringNow('~w~recconect!wait - ~y~'..i..'~w~.. to~g~' ..rec_sec..'.',900)
                    print('recconect!wait - '..i..'.. to' ..rec_sec..'.')
                    wait(1000)
                 end
            -- end
        end
    end)
end

function onSendRpc(id, bitStream, priority, reliability, orderingChannel, shiftTs)
    if id == 25 and disconnected then -- RPC_CLIENTJOIN
        disconnected = false

    end
end 

function isKeyCheckAvailable()
    if not isSampLoaded() then
        return true
    end
    if not isSampfuncsLoaded() then
        return not sampIsChatInputActive() and not sampIsDialogActive()
    end
    return not sampIsChatInputActive() and not sampIsDialogActive() and not isSampfuncsConsoleActive()
end


function CloseConnect()

    -- sampSetGamestate(5)
    -- sampDisconnectWithReason(0)

--[[        for _, handle in ipairs(getAllChars()) do
          if doesCharExist(handle) then
            local _, id = sampGetPlayerIdByCharHandle(handle)
                if id ~= myid then
                    emul_rpc('onPlayerStreamOut', { id })
                end
          end
        end--]]

        raknetEmulPacketReceiveBitStream(PACKET_DISCONNECTION_NOTIFICATION, raknetNewBitStream())
        raknetDeleteBitStream(raknetNewBitStream())
end
)