local base = _G module("redirect") -- Rev: 1.0.6 base.require("luadchpp") local adchpp = base.luadchpp local autil = base.require('autil') local cm = adchpp.getCM() local sm = adchpp.getSM() -- WARNING !!!!!!!!!! This script will not work if the NMDC client connects to a secure listning port as the communication is only allowed after the TLS handshake. -- When the script does not use a timer the redirect is instantaneous, advantage is no extra timers creation or pending sockets, disadvantage is a litle tx band as you send the redirect to all users. -- Script needs ADCH++ (rev 527) or above. -- Settings: -- Fully ADC qualified hub address. local Redirect = "adcs://redirect.no-ip.info:411" -- Seconds you want the script to wait before the redirect (must be < the hubs logtimeout), 0 = redirect instantaneous. local Time = 4 -- Bot name used for the msg's. local Bot = "Redirect_Bot" -- Hubname as you want it's shown in the msg. local Hubname = "ADCH_HUB" -- Reason that you want to be send in PM to the redirected user, if "" no reason will be send. local Reason = "You should update your favorits for " .. Hubname .. " with the new address !" -- Send message in a PM or mainchat local PM = true -- Array test NMDC to ADC(S) redirect local nmdc_t = {} local function nmdc_redirect(c) if #Reason > 0 then c:send(adchpp.Buffer_create((PM and "$To: Guest From: " .. Bot .. " $<<" .. Bot .. ">>" or "<" .. Bot ..">") .. " You are being redirected to " .. Redirect .. ": " .. Reason .. "|")) end c:send(adchpp.Buffer_create("$ForceMove " .. Redirect .. "|\n")) if adchpp.versionString:match('Debug$') then base.print(adchpp.AdcCommand_fromSID(c:getSID()), " redirected on timer !!!") end end local function nmdc_redirect_verify() for k, data in base.pairs(nmdc_t) do if data.victim:getState() == adchpp.Entity_STATE_PROTOCOL then rev = nmdc_redirect(data.victim) end nmdc_t[k] = nil end end add_redirect_nmdc_to_adc = cm:signalReady():connect(function(entity) -- Sending a NMDC redirect to all connecting users after x time or instant. local c = entity:asClient() if c and c:getState() == adchpp.Entity_STATE_PROTOCOL then if Time > 0 then nmdc_t[c:getSID()] = { victim = c } return end nmdc = nmdc_redirect(c) end end) rem_redirect_nmdc_to_adc = cm:signalDisconnected():connect(function(entity) local c = entity:asClient() if nmdc_t[c:getSID()] then nmdc_t[c:getSID()] = nil return end end) nmdc_redirect_timer = sm:addTimedJob(Time * 1000, nmdc_redirect_verify) autil.on_unloading(_NAME, nmdc_redirect_timer)