PtokaX forum

PtokaX => Feature Proposals => Topic started by: PPK on 06 August, 2011, 23:42:11

Title: MyINFO modification from Lua API
Post by: PPK on 06 August, 2011, 23:42:11
In PtokaX Lua API is MyINFO processing not blockable. This thing don't allow to change user MyINFO without high upload usage caused by manual MyINFO broadcasting from Lua script. I want to change that, so i have proposal how it should be done. Of course as easy way looks to make MyINFO blockable, but that don't give scipt way how to send changed MyINFO in smart (and cpu/memory friendly) way...

So here is my proposal. API will get some call that will allow changes to MyINFO and PtokaX will use them on next MyINFO broadcast.

It can be something simple like Core.SetUserValue(tUser, nValueId, sNewValue) to allow change of description, tag, connection, email and maybe sharesize.
Example script adding country code to user description can looks like this:

function MyINFOArrival(tUser, sData)
    sCountryCode = IP2Country.GetCountryCode(tUser.sIP)
    if sCountryCode ~= nil then
        Core.SetUserValue(tUser, 2, sCountryCode.." "..Core.GetUserValue(tUser, 2)) -- 2 is sDescription
    end
end


This should be good enough, but maybe little improvement should be done.. so maybe improve previous call like Core.SetUserValue(tUser, nValueId, sNewFullMyinfoValue, sNewStripedMyInfoValue, bPermanent). We have here 2 more call params for good reason. This way script can handle what will be shown in full MyINFO and what will be shown in striped MyINFO. And more, we get bPermanent to make changes permanent so we don't need to do changes everytime user sends new MyINFO.
So again here is example script adding country code to user description:

function UserConnected(tUser)
    sCountryCode = IP2Country.GetCountryCode(tUser.sIP)
    if sCountryCode ~= nil then
        if SetMan.GetBool(13) then -- 13 is Strip user description
            Core.SetUserValue(tUser, 2, sCountryCode.." "..Core.GetUserValue(tUser, 2), sCountryCode, true) -- 2 is sDescription
        else
            Core.SetUserValue(tUser, 2, sCountryCode.." "..Core.GetUserValue(tUser, 2), sCountryCode.." "..Core.GetUserValue(tUser, 2), true) -- 2 is sDescription
        end
    end
end


So now my example script will add country code to user description on login permanently, script don't need to process MyINFO everytime is new one received...  8)

Please post opinions below.
Title: Re: MyINFO modification from Lua API
Post by: KillerInstinct on 07 August, 2011, 14:58:25
sounds like a plan ;)
Title: Re: MyINFO modification from Lua API
Post by: pHaTTy on 08 August, 2011, 14:14:05
Quote from: PPK on 06 August, 2011, 23:42:11
So now my example script will add country code to user description on login permanently, script don't need to process MyINFO everytime is new one received...  8)

but if a user changes his/her description or tag whilst already logged in, it would be a useful feature since it could be used to modify badwords and so on, however what you would need to do is keep a copy of the original *unmodified* myinfo string, then when ptokax receives a new myinfo from the user, if it is the same as the original -> do nothing, if it is different to the original -> re-call lua function.

-pHaTTy
Title: Re: MyINFO modification from Lua API
Post by: PPK on 08 August, 2011, 14:50:21
Quote from: pH?tt? on 08 August, 2011, 14:14:05
however what you would need to do is keep a copy of the original *unmodified* myinfo string, then when ptokax receives a new myinfo from the user, if it is the same as the original -> do nothing, if it is different to the original -> re-call lua function.
PtokaX already doing that, and it will not change  ::)
Title: Re: MyINFO modification from Lua API
Post by: bastya_elvtars on 09 August, 2011, 18:17:30
Nice idea.
Title: Re: MyINFO modification from Lua API
Post by: WAJIM on 10 August, 2011, 10:37:05
Great idea, PPK!  ;D

Now I do the postponed sending $MyINFO (~100 ms after MyINFOArrival/UserConnected) myinfo for correction of the information on users. It adds superfluous commands. Core. SetUserValue - excellent replacement with mine hacks!  :D
Title: Re: MyINFO modification from Lua API
Post by: Dessamator on 11 August, 2011, 15:40:40
Excellent idea, would be useful for many MyInfo related scripts, which currently fight with the data the server sends them.
Title: Re: MyINFO modification from Lua API
Post by: Hamachi on 28 August, 2011, 21:07:10
Nice ide what version will it be add ?
Title: Re: MyINFO modification from Lua API
Post by: PPK on 28 August, 2011, 21:36:30
In release after 0.4.2.0  :P
Title: Re: MyINFO modification from Lua API
Post by: PPK on 14 September, 2011, 00:21:01
Added http://forum.ptokax.org/index.php?topic=8857.0 :P