Can't find error
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Can't find error

Started by sphinx_spb, 04 June, 2007, 07:19:11

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

sphinx_spb

I have a script, it's parsing rss feed and work fine, but today i add another command and this second command not work.
That is, !ps1 work fine, !ps2 not. Ptokax don't find syntax errors, and no errors after !ps2 - this command simply do nothing.
Please help me find the error!

-- options
bot = frmHub:GetHubBotName()
rHost = "some url"
SCmd = "ps1"
MCmd = "ps2"
rPort = 80


-- Init lib
libinit = package.loadlib("pxwsa_l51.dll", "_libinit")
libinit()

function Main()
  WSA.Init()
end

OpConnected = NewUserConnected

ChatArrival = function(user, data)
	return RssParcer(user, data)
end

function RssParcer(user,data)
	local data = string.sub(data,1,-2)
	local _,_,cmd = string.find(data, "%b<>%s+%p(%w+)")
	local difftime = os.difftime(os.time(), iLastTime)
	    	if (difftime > iExpireTime) then
	    		table.insert(tReqUsers, user)
			if cmd and cmd==SCmd then
				local i = 26063 
				local r = "/rss/"..i..".xml"
				rFile = r
			elseif cmd and cmd==MCmd then
				local k = 27612 
				local s = "/rss/"..k..".xml"
				rFile = s
	end
	user:SendPM(bot, "Please wait ...")
  	sIncomingBuffer = ""
	errorCode, errorStr, curSocket = WSA.NewSocket(0)
	if errorCode then
		user:SendPM(bot, "Error: "..errorCode.." "..errorStr)
	else
		errorCode, errorStr = WSA.Connect(curSocket, rHost, rPort)
		if errorCode then
			user:SendPM(bot, "Error: "..errorCode.." "..errorStr)
		else
			errorCode, errorStr = WSA.MarkNonBlocking(curSocket)
			if errorCode then
				user:SendPM(bot, "Error: "..errorCode.." "..errorStr)
			else
				local data = "GET "..rFile.." HTTP/1.1\r\nHost: "..rHost.."\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n"..string.char(13,10)
				errorCode, errorStr, bytesSent = WSA.Send(curSocket, data)
				if errorCode then
					user:SendPM(bot, "Error: "..errorCode.." "..errorStr)
				else
				  	SetTimer(1000) -- 1 sec
  					StartTimer()
				end
			end
		end
	end

iLastTime = os.time()
	
end
return 1	
end
			
OnExit = function()
	local errorCode, errorStr = WSA.Dispose()
end

OnTimer = function()
	GetResponse()
end

GetResponse = function ()

..some code..

end

CrazyGuy

Are you sure the file /rss/27612.xml exists ? Can you get it when using for example ftp ?

sphinx_spb

#2
Yes, it exists for sure. The page is available, and if I replace 26063 with 27612 in script, it works. Something is wrong with script...

CrazyGuy

I take it the user does see the "Please wait...." line ?
So the problem might be in the GetResponse() function. Can you attach the full script and libs please ?

sphinx_spb


CrazyGuy

#5
hmm, the only thing that may cause a problem without throwing an error is in function GetResponse() in this line

local _,_,i1,i2,i3,i4 = string.find(sIncomingBuffer,"<item>(.*)</item>.*<item>(.*)</item>.*<item>(.*)</item>.*<item>(.*)</item>")


The function checks if i1 is not nil, and likewise for the other i's, but there is no else in that function.
So in case of i1, i2,i3 and i4 all being nil, you will not see an error but you won't get an outcome either.

Try this function instead to see if any of these conditions is true.

GetResponse = function ()
	errorCode, errorStr, sData, bytesRead = WSA.Receive(curSocket)
	if errorCode == nil then
   		-- Receive done - but there can still be data on the socket you need to read.
		sIncomingBuffer = sIncomingBuffer..sData
	elseif errorCode == 0 then
	  	-- the connection has been gracefully closed by remotehost.
   	    sMsg = "===============================??????? ??????================================\n"
   	    local _,_,i1,i2,i3,i4 = string.find(sIncomingBuffer,"<item>(.*)</item>.*<item>(.*)</item>.*<item>(.*)</item>.*<item>(.*)</item>")
   	    if (i1 ~= nil) then
   	        local _,_,t1,d1 = string.find(i1,"<title>(.*)</title>.*<description>(.*)</description>")
   	        if (t1 ~= nil and d1 ~= nil) then
   	            sMsg = sMsg..t1.."\t"..d1.."\n"
   	        end
		else
			SendToAll(frmHub:GetHubBotName(), "i1 is nil")
   	    end
   	    sMsg = sMsg.."-----------------------------------------------------------------------------------------------------------------------------------------------------------------\n"
   	    if (i2 ~= nil) then
   	        local _,_,t2,d2 = string.find(i2,"<title>(.*)</title>.*<description>(.*)</description>")
   	        if (t2 ~= nil and d2 ~= nil) then
   	            sMsg = sMsg..t2.."\t"..d2.."\n"
   	        end
		else
			SendToAll(frmHub:GetHubBotName(), "i2 is nil")
   	    end
   	    sMsg = sMsg.."-----------------------------------------------------------------------------------------------------------------------------------------------------------------\n"
   	    if (i3 ~= nil) then
   	        local _,_,t3,d3 = string.find(i3,"<title>(.*)</title>.*<description>(.*)</description>")
   	        if (t3 ~= nil and d3 ~= nil) then
   	            sMsg = sMsg..t3.."\t"..d3.."\n"
   	        end
		else
			SendToAll(frmHub:GetHubBotName(), "i3 is nil")
   	    end
   	    sMsg = sMsg.."-----------------------------------------------------------------------------------------------------------------------------------------------------------------\n"
   	    if (i4 ~= nil) then
   	        local _,_,t4,d4 = string.find(i4,"<title>(.*)</title>.*<description>(.*)</description>")
   	        if (t4 ~= nil and d4 ~= nil) then
   	            sMsg = sMsg..t4.."\t"..d4.."\n"
   	        end
		else
			SendToAll(frmHub:GetHubBotName(), "i1 is nil")
   	    end
   	    sMsg = sMsg.."=================================================================================\n"
   	    sMsg = sMsg.."??... ?????? ?? ??????, ?? ??? ??? :))\n??????????: ??? ????? ????????????? ???????? ???????? ???? http://www.gismeteo.ru/towns/"..City..".htm\n"
for i, user in pairs(tReqUsers) do
			user:SendPM(bot, "\n"..sMsg)
        end
        WSA.Close(curSocket)
        StopTimer()
        tReqUsers = {}
	elseif errorCode == 10035 then
        -- Receive call is blocked. Do nothing and wait.
	else
		-- error
   	    for i, user in pairs(tReqUsers) do
			user:SendPM(bot, "??????: "..errorCode.." "..errorStr)
        end
        WSA.Close(curSocket)
        StopTimer()
        tReqUsers = {}
	end
end


Edit: due to unknown chars, this paste looks crap. Download the attached modded lua file instead.


sphinx_spb

Well, now the error appears:

Quote[22:39] Syntax C:\ptokax\scripts\Weather2.lua:61: attempt to concatenate global 'rFile' (a nil value)

but command !ps1 still works, and !ps2 still nothing...

CrazyGuy

Quote from: sphinx_spb on 05 June, 2007, 20:51:13
Well, now the error appears:

but command !ps1 still works, and !ps2 still nothing...

That is funny, because I never changed something about that  :-\ Only thing I added was a message in mainchat if parts of the downloaded xml were not present.
Will check some more.....

SMF spam blocked by CleanTalk