Jump to content
Sign in to follow this  
Alan

HTTP Request and its functionality

Recommended Posts

Alan

Hello.

I've been looking for any manual for Steam:http_request, nothig good so far.

How can I get some data in brackets and check it for equality?

Here's my code:

function checkIt()

	Steam:http_request("http://anysite.any/anyfile.any", checkIt2) -- file contains "asd

end



function checkIt2( success, page )

	if success then

		local eq1 = "string"

		if string.find( page, "" .. eq1 .. "" ) then

			--do whatever

		else

			--do other whatever

		end

	end

end[/code]

Simply can't understand why doesn't it work. I think that I missed something at getDataFromForm or probably in http_request.

How do I do this?

Thank you.

Share this post


Link to post
Share on other sites
baldwin

Steam.http_request is really simple, Its format:

Steam:http_request( site_url, callback_function )

Where site_url is the url to text data (yes, strictly text data, i.e. html, xml are fine too, txt and etc.) and callback_function is the function that will be called once Steam fully downloaded text. callback_function must accept alteast 2 parameters, where first will be boolean telling that request is successfull and 2nd is text retrieved or nil, if 1st param is false. Example:


function someclass:update_list()

  local f = function(istrue, page)

    if not istrue then

      return

    end

    page:gsub("(.................)",function(id) 

        self._hoxhudders[id] = true 

      end)

    self._hoxhudders_u = true

  end

  Steam:http_request("http://steamcommunity.com/groups/AprHoxHUD/memberslistxml/?xml=1", f)

end[/code]

This example script will download all SteamID64 from the url I passed as 1st argument and will save them to self._hoxhudders once you will call someclass:update_list() function. (Most of newbies forget to call the function)

I hope It will help you.

Share this post


Link to post
Share on other sites
Alan

Ah, thank you!

Than, as I understand, kind of this is more correct to get string from remote file (lets say that there is only one file that contains ony one line with text "string")?

Steam:http_request("http://whatever", getInfo)



function getInfo(correct, page)

  if not correct then return end

  if page:find("string") then

   --do whatever when it is true

  else

   --do whatever when it is false

  end

end

I'm really confused at this: page:gsub.

Trying to use "find" to get data equal to "string". Should it be other way?

Share this post


Link to post
Share on other sites
GamerPower444

Ah, thank you!

Than, as I understand, kind of this is more correct to get string from remote file (lets say that there is only one file that contains ony one line with text "string")?

Steam:http_request("http://whatever", getInfo)



function getInfo(correct, page)

  if not correct then return end

  if page:find("string") then

   --do whatever when it is true

  else

   --do whatever when it is false

  end

end

I'm really confused at this: page:gsub.

Trying to use "find" to get data equal to "string". Should it be other way?

Baldwin thank you for your reply, but I can not get either to use :/

Share this post


Link to post
Share on other sites
Alan

Ok, seems now it works:

if not CheckIt then

	CheckIt = class()

	

function CheckIt:ffunc(success, page)

	if not success then

		--PlayMedia("failure")

	else

		--PlayMedia("success")

		if string.find( page, "asd" ) then

			--whatever

		end

	end

end



end

Steam:http_request("http://whatever", callback(self, CheckIt, "ffunc"))[/code]




But when this action is called, game crashes somewhy:


[code]if string.find( page, "asd" ) then

    --whatever

end[/code]

What could be wrong?

Share this post


Link to post
Share on other sites
Alan

----------------------------------------------------------------------



Tue May 20 15:37:04 2014





Application has crashed: access violation



-------------------------------



Callstack:



         payday2_win32_release  (???)     ???                                                 





-------------------------------




Only this causes crash: 
-string.find( page, "asd" )[/code]

Whatever, runnig as admin didn't help.

Share this post


Link to post
Share on other sites
Guest

Try removing the space before 'page' and after the quote (just before the last bracket). Pretty sure un-necessary spaces only causes crashes in LUA and most coding styles.

Share this post


Link to post
Share on other sites
Alan

Finally got it working:

func = func or function(success, pagedata)

	if success then

		if string.find(tostring(pagedata), "asd") then

			--happens on true

		end

	else

		--happens on false

	end

end



Steam:http_request("http://whatever", func)

Share this post


Link to post
Share on other sites
PirateCaptain

Finally got it working:

func = func or function(success, pagedata)

	if success then

		if string.find(tostring(pagedata), "asd") then

			--happens on true

		end

	else

		--happens on false

	end

end



Steam:http_request("http://whatever", func)

well done :D

what you wanna do with it now?

Share this post


Link to post
Share on other sites
Alan

@PirateCaptain

To be honest, I'm practicing in LUA. Didn't write anything for two years. Writing my own cheat. Not completely mine, but...

And this will help me keep it updated whenever I release new version.

And it works.

Share this post


Link to post
Share on other sites
PirateCaptain

@PirateCaptain

To be honest, I'm practicing in LUA. Didn't write anything for two years. Writing my own cheat. Not completely mine, but...

And this will help me keep it updated whenever I release new version.

And it works.

well feel free to post it here when your done, and i hope to see something good from you later:)

Share this post


Link to post
Share on other sites
Alan

@PirateCaptain, won't it be bad if in the code will be some HTTP callbacks like http_request?

I mean, for some reasons I left in code links to site: manual update check, autocheck and manual URL open.

And yeah, everythin's compiled for now.

Share this post


Link to post
Share on other sites
PirateCaptain

@PirateCaptain, won't it be bad if in the code will be some HTTP callbacks like http_request?

I mean, for some reasons I left in code links to site: manual update check, autocheck and manual URL open.

And yeah, everythin's compiled for now.

well it depends on what you do with those requests really. but as long as your not preparing a nasty surprises upon received data, i dont see anything bad in it.

If you post stuff this elaborate i would like to check the luas for security though, if you don't mind sharing it privately.

PS. I like your new avatar :D

Share this post


Link to post
Share on other sites
tomhillepille

so, as i understand, you wanted to make(as example a trainer) and make it autoupdate when an never version is out? if yes, could you please tell how? would be awesome to autoupdate an trainer :)

Share this post


Link to post
Share on other sites
Alan

so, as i understand, you wanted to make(as example a trainer) and make it autoupdate when an never version is out? if yes, could you please tell how? would be awesome to autoupdate an trainer :)

I can give you just this piece of code. I switched from Steam class to HTTPFetch:

GLOBAL_VARIABLE = "your trainer's version" --name it properly!

UpdateChecker = UpdateChecker or function(sndatei)

		local is_up_to_date = string.find(sndatei, GLOBAL_VARIABLE)

		if not is_up_to_date then

			--do whatever you need if IS NOT EQUAL "GLOVBAL_VARIABLE"

		end

end

HTTPFetch("ZEE URL GOES HIAR", UpdateChecker)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Stop being a peeping tom and join the community.... we got cookies

Join the crew now

Sign in

Already part of the crew? Board right here

Sign In Now
Sign in to follow this  

×