Author Topic: MyINFO modification from Lua API  (Read 3911 times)

0 Members and 1 Guest are viewing this topic.

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 478
  • Karma: +209/-22
  • PtokaX developer
MyINFO modification from Lua API
« 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:
Code: [Select]
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:
Code: [Select]
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.
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

PtokaX forum

MyINFO modification from Lua API
« on: 06 August, 2011, 23:42:11 »

Offline KillerInstinct

  • Member
  • ***
  • Posts: 32
  • Karma: +0/-3
Re: MyINFO modification from Lua API
« Reply #1 on: 07 August, 2011, 14:58:25 »
sounds like a plan ;)

Offline pHaTTy

  • Forum Legend
  • ***
  • Posts: 1 916
  • Karma: +5/-1
Re: MyINFO modification from Lua API
« Reply #2 on: 08 August, 2011, 14:14:05 »
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
Resistance is futile!

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 478
  • Karma: +209/-22
  • PtokaX developer
Re: MyINFO modification from Lua API
« Reply #3 on: 08 August, 2011, 14:50:21 »
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  ::)
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 730
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: MyINFO modification from Lua API
« Reply #4 on: 09 August, 2011, 18:17:30 »
Nice idea.
Everything could have been anything else and it would have just as much meaning.

Offline WAJIM

  • Member
  • ***
  • Posts: 41
  • Karma: +3/-5
Re: MyINFO modification from Lua API
« Reply #5 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

Offline Dessamator

  • Scripter
  • Emperor
  • ******
  • Posts: 1 262
  • Karma: +13/-9
Re: MyINFO modification from Lua API
« Reply #6 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.
Ignorance is Bliss.

Offline Hamachi

  • Forum Ace
  • *****
  • Posts: 88
  • Karma: +0/-7
Re: MyINFO modification from Lua API
« Reply #7 on: 28 August, 2011, 21:07:10 »
Nice ide what version will it be add ?

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 478
  • Karma: +209/-22
  • PtokaX developer
Re: MyINFO modification from Lua API
« Reply #8 on: 28 August, 2011, 21:36:30 »
In release after 0.4.2.0  :P
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 478
  • Karma: +209/-22
  • PtokaX developer
Re: MyINFO modification from Lua API
« Reply #9 on: 14 September, 2011, 00:21:01 »
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

PtokaX forum

Re: MyINFO modification from Lua API
« Reply #9 on: 14 September, 2011, 00:21:01 »