Page 2 of 5 FirstFirst 1 2 3 4 ... LastLast
Results 11 to 20 of 42

Thread: anyone managed to use CreateHTTPRequest?

  1. #11
    Basic Member
    Join Date
    Dec 2016
    Posts
    598
    Okay, I managed to get the webserver to see the POST messages... but the Send( callbackArg ) which I expect to be a function ptr doesn't seem to work.

  2. #12
    Quote Originally Posted by nostrademous View Post
    I believe that's for modding only, not available via the bot-scripting API. The Bot Scripting API is CreateHTTPRequest( sParam ) that only takes 1 parameter as @ChrisC wanted to force only allowing a "POST" and only to "http://localhost". Perhaps he added the second parameter as "http://localhost/" with the extra "/" at end prevent us from specifying port of our choosing, not sure.
    I was indeed quoting from the modding API, as google brought me into this thread as my own Bot framework broke due to the signature change. I didn't look much into the bot scripting as the lack of the HTTP calls made it uninteresting for me. Guess that change it's what this is all about. Thanks for making me aware of this.

  3. #13
    Basic Member
    Join Date
    Dec 2016
    Posts
    598
    Here is my super simple bot code that "almost" works..

    bot_<heroName>.lua:
    Code:
    local lastUpdate = -1000.0
    local data = {}
    
    function Think()
        local bot = GetBot()
    
        data["test"] = {Health = bot:GetHealth(), MaxHealth = bot:GetMaxHealth()}
        
        if GameTime() - lastUpdate > 2.0 then
            lastUpdate = GameTime()
            
            local json = '{"data":{'
            local count = 1
            for key, value in pairs(data["test"]) do
                if count > 1 then json = json..',' end
                json = json .. '"' .. key .. '": ' .. value
                count = count + 1
            end
            json = json..'}}'
            
            print(tostring(json))
            
            local req = CreateHTTPRequest( "" )
            req:SetHTTPRequestRawPostBody("application/json", json)
            req:Send( function( result )
                print( "GET response:\n" )
                for k,v in pairs( result ) do
                    print( string.format( "%s : %s\n", k, v ) )
                end
                print( "Done." )
            end )
        end
    end
    Printout in console:
    Code:
    [VScript] {"data":{"MaxHealth": 640,"Health": 640}}                       <-- the JSON data we send
    [VScript] Script Runtime Error: attempt to call a table value             <-- the asynchronous callback from :Send() that has an error in it
    stack traceback:
    The Cherrypy Simple python WebServer Code:
    Note you "might" need to: "pip install cherrypy simplejson" if you don't have those modules
    Note: this code is for Python 2.7.x, should work with Python 3.x with minor tweaks
    Code:
    import cherrypy
    import simplejson
    
    @cherrypy.expose
    @cherrypy.tools.json_out()
    @cherrypy.tools.json_in()
    class Root:
    
        @cherrypy.tools.accept(media='application/json')
        def GET(self):
            print "GET"
            return {"operation": "GET", "result": "success"}
    
        @cherrypy.tools.accept(media='application/json')
        def POST(self):
            print "POST"
            
            input_json = cherrypy.request.json
            value = input_json["data"]
            print value
            
            return {"operation": "POST", "result": "success"}
        
    
    def web_server():
        conf = {
            'global' : {
                'server.socket_host' : '127.0.0.1',
                'server.socket_port' : 80,
                'server.thread_pool' : 8
            },
            '/': {
                'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
                'tools.sessions.on': True,
            }
        }
        cherrypy.quickstart(Root(), '/', conf)
    
    if __name__ == "__main__":
        print 'starting web server'
        web_server()
        print 'done'
    Printout in the Python Console running the webserver:
    Code:
    starting web server
    [06/Apr/2017:09:41:48] ENGINE Listening for SIGTERM.
    [06/Apr/2017:09:41:48] ENGINE Bus STARTING
    [06/Apr/2017:09:41:48] ENGINE Set handler for console events.
    [06/Apr/2017:09:41:48] ENGINE Started monitor thread 'Autoreloader'.
    [06/Apr/2017:09:41:48] ENGINE Started monitor thread '_TimeoutMonitor'.
    [06/Apr/2017:09:41:49] ENGINE Serving on http://127.0.0.1
    [06/Apr/2017:09:41:49] ENGINE Bus STARTED
    POST
    {u'Health': 640, u'MaxHealth': 640}                                                           <--- MY JSON ARRIVED
    127.0.0.1 - - [06/Apr/2017:09:42:47] "POST / HTTP/1.1" 200 42 "" "Valve/Steam HTTP Client 1.0 (570)"
    Last edited by nostrademous; 04-06-2017 at 06:54 AM.

  4. #14
    Can confirm. It's borked. The data gets send out, but the callback is treated incorrectly inside the runtime (hence no stacktrace). The behaviour of the same call in the modding API seems to be unaffected though.

  5. #15
    Basic Member
    Join Date
    Mar 2012
    Posts
    1,652
    Quote Originally Posted by Lightbringer View Post
    I I didn't look much into the bot scripting as the lack of the HTTP calls made it uninteresting for me. Guess that change it's what this is all about. Thanks for making me aware of this.
    What does HTTP have to do with bot scripting?

    I think the others are mostly doing debugging or stats collection.
    Explanations on the normal, high and very high brackets in replays: here, here & here
    Why maphacks won't work in D2: here

  6. #16
    I use HTTP to control the bot. The best you can do with the bot API resp. the LUA runtime is if-else statements or state-machines at best - very uninteresting for AI research.

  7. #17
    Basic Member
    Join Date
    Mar 2012
    Posts
    1,652
    Ah, I see. Well if that gets implemented deeper in, I'm curious of the result if you manage to make it work
    Still, I'd expect that the logic part controlled, say, on a web server to be if-else statements too with some sort of common hivemind or something similar to a state machine. So whether the logic is in LUA or some other language, C, Java, PHP or whatnot seems to be similar. Or am I missing the point? (not being sarcastic, I do find a different approach fascinating, but I am not sure I see how it'd work that is why I ask)
    Explanations on the normal, high and very high brackets in replays: here, here & here
    Why maphacks won't work in D2: here

  8. #18
    Basic Member
    Join Date
    Dec 2016
    Posts
    598
    Quote Originally Posted by The Nomad View Post
    Ah, I see. Well if that gets implemented deeper in, I'm curious of the result if you manage to make it work
    Still, I'd expect that the logic part controlled, say, on a web server to be if-else statements too with some sort of common hivemind or something similar to a state machine. So whether the logic is in LUA or some other language, C, Java, PHP or whatnot seems to be similar. Or am I missing the point? (not being sarcastic, I do find a different approach fascinating, but I am not sure I see how it'd work that is why I ask)
    The other logic can be Reinforcement Learning (QDN, A3C, etc.) and when run on Java/C/Python it can be multi-threaded.... making learning a lot easier.

  9. #19
    If-else state machines (or more commonly called "expert systems") are the simplest form of ai. In fact - it's not even machine learning, as the system doesn't actually learn anything, i.e. has adaptive behaviour.

    Besides what nostrademous brought up, there's also the aspect of availability: there exist a multitude of ai/machine learning libraries in various languages, which people already use in projects. And those people might like to apply their approach to Dota2. Furthermore, LUA is really just a niche language, but popular among game developers due to its simplistic syntax - I guess. Personally, I think this language is a nightmare for anything more complex than simple scripts.

    If this topic intesrest you, I can recommend you a paper by a colleague as a starting point: http://julian.togelius.com/Yannakakis2014Panorama.pdf
    Or just google courses/literature on "modern ai".

  10. #20
    Basic Member
    Join Date
    Mar 2012
    Posts
    1,652
    Thank you both for the info
    Explanations on the normal, high and very high brackets in replays: here, here & here
    Why maphacks won't work in D2: here

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •