Author Topic: need help with this function...  (Read 1841 times)

0 Members and 1 Guest are viewing this topic.

Offline blackwings

  • Scripter
  • King
  • ******
  • Posts: 986
  • Karma: +12/-8
need help with this function...
« on: 11 September, 2005, 23:44:03 »
I have 2 problems with this client checker script =
1) if user's client version is above the minversion set by script and acces,
I get this error message, but only if there are 2 or more clients in tClient =
Code: [Select]
[23:17] Syntax C:\ptokax03321\scripts\clientchecker.lua:13: attempt to concatenate global `xTag2' (a nil value)2) if its a NewUserConnected instead MyINFOArrival, then pm from bots will be sent to user before
the user get disconnected, which I don't want it to.
Code: [Select]
Bot = "#clientCheck"

tClient = {
["zDC%+%+%[(%d)%.(%d+)"] = {0.666,"*** Please upgrade your client, min version for in this hub is <0.666>"},
[""] = {1.2,"*** Please upgrade your client, min version for in this hub is <1.3>"},
}

function MyINFOArrival(user)
if not user.bOperator then
if user.bHasTag then
for k,v in tClient do
s,e,xTag1,xTag2 = string.find(user.sDescription, k)
xTag =xTag1.."."..xTag2
if tonumber(xTag) user:SendData(Bot,v[2])
user:Disconnect()
end
end
else
user:SendData(Bot,"*** Use Original DC++, fulDC, or DCTC(for linux users)")
user:SendData(Bot,"*** Original DC++ Homepage: [URL]http://dcplusplus.sourceforge.net/[/URL]")
user:Disconnect()
end
end
end
« Last Edit: 11 September, 2005, 23:44:39 by blackwings »


PtokaX forum

need help with this function...
« on: 11 September, 2005, 23:44:03 »

Offline Corayzon

  • Lord
  • ***
  • Posts: 464
  • Karma: +1/-0
(No subject)
« Reply #1 on: 12 September, 2005, 01:47:18 »
Code: [Select]
sBot = "#ClientCheck"

tClient =
{
["%<%+%+%sV%:(%d)%.(%d+)"] = {1.100,"*** Please upgrade your client, min version for DC++ in this hub is 1.100"},
["%"] = {1.2,"*** Please upgrade your client, min version for in this hub is <1.2>"},
}

function MyINFOArrival(user)
if not user.bOperator then
if user.bHasTag then
for sSearchPattern,tData in tClient do
-- Search for client pattern
local _,_, xTag1, xTag2 = string.find(user.sTag, sSearchPattern)
-- Check if version was found in tag
if xTag1 and xTag2 then
local xTag = tonumber(xTag1 .. "." .. xTag2)
--user:SendData("xTag = " .. xTag)
--user:SendData("tData[1] = " .. tData[1])
-- Check if client version is to old
if xTag < tonumber(tData[1]) then
user:SendData(sBot,tData[2])
user:Disconnect()
return 1
end
end
end
else
user:SendData(sBot,"*** Use Original DC++, fulDC, or DCTC(for linux users)")
user:SendData(sBot,"*** Original DC++ Homepage: [URL]http://dcplusplus.sourceforge.net/[/URL] <<< Double Click To Open Page")
user:Disconnect()
end
end
end

Answers to your questions:

1 - Bad programming of course. These where what i fixed:

* Pattern seach was checking user.sDescription not user.sTag
* There was no check if client version was found or not! (giving u an error if the pattern wasnt matched!)
* Made local variables LOCAL!!!!!!!!!!!!!
* Changed some variable names to make it easier to read

2 - U dont want a disconnecting user to see why they have been kicked?

Offline blackwings

  • Scripter
  • King
  • ******
  • Posts: 986
  • Karma: +12/-8
(No subject)
« Reply #2 on: 12 September, 2005, 03:01:24 »
Quote
Originally posted by Corayzon
2 - U dont want a disconnecting user to see why they have been kicked?
yes I want them to see why they are kicked. What I meant is that for example I have in my hub a script that sends a login message in PM to user when the user connects. This login message sent to user before user gets disconnected, which doesn't happend with MyINFOArrival, because its faster. But I dont want it to check users all the time, just when they connect, but I dont want disconnected users to see the login msg pm.


Offline Corayzon

  • Lord
  • ***
  • Posts: 464
  • Karma: +1/-0
(No subject)
« Reply #3 on: 12 September, 2005, 04:39:07 »
Gotcha,

Well in the old versions of PtokaX, if u sent data in this function it would be before PtokaX's motd. Meaning u would need to add timers for sending things like welcome messages ontop of PtokaX's motd.

But this doesnt relate if its ur script sending the motd and not PtokaX. Soooo: ...

Make sure this function executes before ur welcome message is sent. And then ur problem will be solved.

Anyways:

I dont think u need to worry about this to much, because the $MyINFO string is only sent when a user connects or a user changes there settings. And the processing invloved in this script is very minor. So its not like ur gonna have cpu\packet lag because of it =]

PtokaX forum

(No subject)
« Reply #3 on: 12 September, 2005, 04:39:07 »