Jump to content
Spiderswine

Accessing Player Data from API Endpoint

Recommended Posts

Hey Guys,

 

i love playing Arma, but there is one thing that always bothered the hell out me...

Why we have no way to save player data like custom weapon configs, player outfits etc with our account and access them on multiple multiplayer servers like "King of the Hill" or "Altis Life"?

 

Over the past months i've tried to figure out a way to make this happen.

 

I found the wonderful Add On https://github.com/playnet-public/ArmA3URLFetch, which gives us the possibility to access API Endpoints from your local machine in multiplayer missions.

 

The last days i developed an open django api endpoint, which can be requested by the player in the mission and there fore, there can be exchanged data, without the need of a local database.

 

Of course, there's the question on how to authenticate the unique player in the mission. I'm trying to rebuild an OAUTH like workflow, where the local server acts as an authentication provider, by calling the api endpoint as well.

 

Here's the workflow:

authentication_workflow.png

 

In my opinion, this new approach gives mission creators a very powerful tool...

 

Creators can now access every possible player information through one endpoint from multiple servers:

 

Here's a multiple server setup:

 

multiple_server_setup.png

 

This gives mission creators the ability to share player information across every server of their mission and maybe host a mission website to access player information outside of Arma.

 

 

At the moment i've developed a "proof of concept" iteration to ask for feedback if there is a need for such a system.

 

I'm looking forward to your feedback and i would love to implement such a system in an upcoming multiplayer scenario.

 

Here's an example example multiplayer mission.

Here's the open django api endpoint.

 

Best Regards,

 

Luke

 

PS: Sorry for the bad paint pictures, i'm broke 😉

 

 

Here is how its done: (authentication stuff is still in work...)

 

  • Call the authentication in the initPlayerLocal.sqf and give player action (just for testing purposes)
  • player addAction ["Handle Request", { [] spawn it_fnc_handleRequest }];
    
    // handle the authentication
    
    [] spawn it_fnc_handleAuthentication;

     

  • define the handleAuthentication function
  • _cliendid = [
        "http://192.168.0.102:8000/api/auth",
        "GET",
        ["uid=xyz"],
        true
    ] call a3uf_common_fnc_addClient;
    
    [
        _cliendid,
        ["Content-Type: application/json"]
    ] call a3uf_common_fnc_setClientHeaders;
    
    _response = [
        _cliendid
    ] call a3uf_common_fnc_clientRequest;
    
    _test = parseSimpleArray _response;
    _next = _test select 1;
    _u = _next select 0;
    _auth_token = _u select 1;
    
    diag_log "AUTH TOKEN";
    diag_log _auth_token;
    
    _token_string = format["token=%1", _auth_token];
    
    _cliendid = [
        "http://192.168.0.102:8000/api/check",
        "GET",
        ["uid=xyz", _token_string],
        true
    ] call a3uf_common_fnc_addClient;
    
    [
        _cliendid,
        ["Content-Type: application/json"]
    ] call a3uf_common_fnc_setClientHeaders;
    
    _response = [
        _cliendid
    ] call a3uf_common_fnc_clientRequest;
    
    _test = parseSimpleArray _response;
    _next = _test select 1;
    _u = _next select 0;
    access_token = _u select 1;
    
    diag_log "ACCESS TOKEN";
    diag_log access_token;

     

  • define the handleRequest function
  • _cliendid = ["http://192.168.0.102:8000/api/user", "GET", [], true] call a3uf_common_fnc_addClient;
    
    _auth_string = format ["Authorization: Bearer %1", access_token];
    
    [_cliendid, ["Content-Type: application/json", _auth_string]] call a3uf_common_fnc_setClientHeaders;
    
    _response = [_cliendid] call a3uf_common_fnc_clientRequest;
    
    _test = parseSimpleArray _response;
    _next = _test select 1;
    _u = _next select 0;
    _name = _u select 1;
    
    hint format["Hello %1", _name];
    
    diag_log "REQUEST";
    diag_log _auth_string ;
    diag_log _response;

     

  • define endpoints in views.py
  • # api endpoint for user to access saved informations
    @api_view(["GET"])
    def user(request):
    
        print(request.headers)
    
        token = request.headers.get("Authorization").split(" ")[1]
    
        # find the player by given access token
        try: 
            player = Player.objects.get(token=token) # get the player
        # except User.DoesNotExist:
        except:
            # player with given token not found, return error
            return Response({'error': 'Player with token not found'}, status=HTTP_400_BAD_REQUEST)
    
        return Response({"name": player.name})

     

 

 

 

 

 

 

 

 

  • Thanks 2

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×