PtokaX forum

Development Section => Your Developing Problems => Topic started by: Xico on 15 August, 2004, 15:27:52

Title: Some help, plesae ( gsub(), strfind() )
Post by: Xico on 15 August, 2004, 15:27:52
Hello ppl

Well I'm trying to develop some kind of client check and I'm stuck (my skils with Lua are still very poor)

sVersion = "0.3.3cvs20040611"
sTempVer = ""
gsub(sVersion, "([0-9.])", function(x) sTempVer = sTempVer ..x end)
After this sTempVer = 0.3.3

The question is: how can I get sTemVer = 0.33 ?

(And thanks to NightLitch, from who I got some good ideas, and some pieces of code)
Title:
Post by: NightLitch on 15 August, 2004, 16:09:28
QuoteOriginally posted by Xico
Hello ppl

Well I'm trying to develop some kind of client check and I'm stuck (my skils with Lua are still very poor)

sVersion = "0.3.3cvs20040611"
sTempVer = ""
gsub(sVersion, "([0-9.])", function(x) sTempVer = sTempVer ..x end)
After this sTempVer = 0.3.3

The question is: how can I get sTemVer = 0.33 ?

(And thanks to NightLitch, from who I got some good ideas, and some pieces of code)

try:

gsub(sVersion, "(%d+%.([%d+%.]))", function(x) sTempVer = sTempVer ..x end)

Not sure at all, but I think it should something like that.

/NL
Title:
Post by: Xico on 15 August, 2004, 17:36:01
Well NightLitch you r my hero (don't take it wrong  :)  )but this time it doesn't work

From a sVersion= "0.3.3" I got a sTempVer = "0.3"
It laks the last digit

But tanks for the efort
(and sorry, but english is not my mother longuage)

Edited

and from sVersion= "0.3.020040508" I got sTempVer = "0.30.2".  
Title:
Post by: NightLitch on 15 August, 2004, 17:55:24
Try this one then:

function Main()
sVersion = "0.3.3cvs20040611"
sTempVer = ""
sTempC = 0
msg = gsub(sVersion, "(%.)", function(x) if x and sTempC ~= 1 then sTempC = 1 return x else return "" end end)
SendToAll(msg)
end

Outcome:

0.33cvs20040611

dunno if this is how u want it...

Cheers / NL
Title:
Post by: NightLitch on 15 August, 2004, 17:59:00
Added a strfind to fix it like this:

sVersion = "0.3.3cvs20040611"
sTempVer = ""
sTempC = 0
_,_,sVersion = strfind(sVersion, "([%.%d]+)")
msg = gsub(sVersion, "(%.)", function(x) if x and sTempC ~= 1 then sTempC = 1 return x else return "" end end)
SendToAll(msg)

Outcome:
0.33

NL
Title:
Post by: Xico on 15 August, 2004, 19:44:33
Thanks NightLitch

I'm beeing a lot daring and i'm posting your VersionCheck() with "your" mod (I'm using it on my hub, a litle 1 with 110/150 users)
function VersionCheck(curUser, sCliente, vTag)

local sDownload = tFazerDown[sCliente]
local nVersao
local nVersaoMin
local sTempVer
local msg

  sTempC = 0
  _,_,sTempVer = strfind(vTag["V"], "([%.%d]+)")
  msg = gsub(sTempVer, "(%.)", function(x) if x and sTempC ~= 1 then sTempC = 1 return x else return "" end end)
  nVersao = tonumber(msg)
  sTempC = 0
  _,_,sTempVer = strfind(tVersaoCliente[sCliente], "([%.%d]+)")
  msg = gsub(sTempVer, "(%.)", function(x) if x and sTempC ~= 1 then sTempC = 1 return x else return "" end end)
  nVersaoMin = tonumber(msg)
 
-- // debug Information
--local usr = GetItemByName("Xico")
--if usr then
--usr:SendPM("Debug", "Cliente: "..sCliente.."   Tag: "..vTag["V"].."   MinVersion: "..nVersaoMin.."   ActVersion: "..nVersao)
--end

if nVersao < nVersaoMin then
Counter["MinVer"] = Counter["MinVer"] + 1
curUser:SD(BotName,Arg(CC5, sCliente, "CLIENT", vTag["V"], "VERSION"))
curUser:SD(BotName,Arg(CC6, sCliente, "CLIENT", sVersao, "VERSION", sCliente, "CLI", sDownload, "DL"))
curUser:Disconnect()
end
end

Once more, many thanks for your help
Title:
Post by: NightLitch on 15 August, 2004, 19:57:06
Your welcome m8