Dedicated server API

Discussion in 'Community Workshop' started by J-F Chardon, Apr 23, 2018.

  1. ACX_Com

    ACX_Com New Member

    Joined:
    May 18, 2020
    Ratings:
    +2 / 0 / -0
    I think it's good that we are in agreement here and therefore everything is good.

    That's always my speech - the forums would be much less full if there were proper documentation - my recommendation is a well-maintained wiki.

    Regarding routers (with me FritzBox 7590) to reconnect via batch, I have a solution that works:

    curl -k -m 5 --anyauth --user USER:pASSWORD "http://ROUTER_IP:49000/igdupnp/control/WANIPConn1" -H "Content-Type: text/xml; charset="utf-8"" -H "SoapAction:urn:schemas-upnp-org:service:WANIPConnection:1#ForceTermination" -d "<?xml version='1.0' encoding='utf-8'?> <s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'> <s:Body> <u:ForceTermination xmlns:u='urn:schemas-upnp-org:service:WANIPConnection:1' /> </s:Body> </s:Envelope>" -s

    (Only change USER, PASSWORD and ROUTER_IP)
    ROUTER_IP ist the internal not the external WAN-IP! ;)

    ...is here in the forum no possibility to mark <code>? :oops:
     
  2. LaundroMat

    LaundroMat Member

    Joined:
    Nov 28, 2020
    Ratings:
    +15 / 0 / -0
    Cool, thanks for sharing! I'll add it to the wiki :)

    Yes, there is -- click on the + sign in the formatting menu.

    upload_2021-2-14_17-58-8.png
     
    • Like Like x 1
  3. ACX_Com

    ACX_Com New Member

    Joined:
    May 18, 2020
    Ratings:
    +2 / 0 / -0
    Great, you're getting started that fast! :)

    I'll also make my other scripts available to you as soon as I get around to it.

    Why did I not find the marking for codes myself!?!?!? o_O

    Beautiful evening :)
     
  4. LaundroMat

    LaundroMat Member

    Joined:
    Nov 28, 2020
    Ratings:
    +15 / 0 / -0
    Haha, yes, I told you I was an eager type of person :)

    Now, although Notion.so is a great tool to document stuff, it's only open to three editors in the free plan. It's good for the time being, but I'd like to set up a "real" wiki (with history & discussion) to make sure everyone can contribute and that we can see what changes over the course of time. I'll have a look around if there's anything suitable.
     
  5. ACX_Com

    ACX_Com New Member

    Joined:
    May 18, 2020
    Ratings:
    +2 / 0 / -0
    Yes you really are! ;)

    Sounds like a lot will improve in the future, I think it's great.

    So that you have good content, here are the PowerShell scripts as promised:

    RaceRoomDedicatedServer_DelAllSessions.ps1

    Code:
    CLS # nice to have, to clear screen if you use it in the PowerShell ISE
    "Löschen aller Server-Sessions..."
    $GameSettingsIDs = @()
    
    # User and Password only needed, if you use the file "access" in the folder...
    # C:\Program Files (x86)\Steam\steamapps\common\RaceRoom Dedicated Server
    # ...for protecting Dedicated Server Website
    $user = 'YOUR_USERNAME_IN_FILE_ACCESS'
    $pass = 'YOUR_USERNAME_IN_FILE_ACCESS'
    $pair = "$($user):$($pass)"
    $encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
    $basicAuthValue = "Basic $encodedCreds"
    
    # header only needed if you use upper Authentication
    $Headers = @{
        Authorization = $basicAuthValue
    }
    
    # it think (not tested), the header below is not needed if you do not use Authentication (filde "access" - see above)
    $GameSettingsIDs = (Invoke-RestMethod -Uri 'http://localhost:8088/dedi' -Headers $Headers).GameSetting.Id
    
    if($GameSettingsIDs.Count -lt 1)
    {
        "Es bestehen keine Server-Sessions!"
        exit
    }
    
    for($i=0; $i -lt $GameSettingsIDs.Count; $i++)
    {
    
    # If you do not use upper Authentication, you can delete Authorisation Part in the header...
    $Headers = @{
        Authorization = $basicAuthValue
        'Content-Type' = 'application/json; charset=utf-8'
        }
    
        [System.Environment]::NewLine + "Lösche Session " + $GameSettingsIDs[$i] + "... " +`
        (Invoke-WebRequest -Method 'DELETE' -Uri "http://localhost:8088/dedi/$($GameSettingsIDs[$i])" -Headers $Headers).StatusDescription
       
    }
    [System.Environment]::NewLine
    #pause

    RaceRoomDedicatedServer_StartSessions.ps1

    Code:
    CLS
    "Starten der Server-Sessions..."
    $GameSettingsIDs = @()
    
    # User and Password only needed, if you use the file "access" in the folder...
    # C:\Program Files (x86)\Steam\steamapps\common\RaceRoom Dedicated Server
    # ...for protecting Dedicated Server Website
    $user = 'YOUR_USERNAME_IN_FILE_ACCESS'
    $pass = 'YOUR_PASSWORD_IN_FILE_ACCESS'
    $pair = "$($user):$($pass)"
    $encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
    $basicAuthValue = "Basic $encodedCreds"
    
    # header only needed if you use upper Authentication
    $Headers = @{
        Authorization = $basicAuthValue
    }
    
    # it think (not tested), the header below is not needed if you do not use Authentication (filde "access" - see above)
    $GameSettingsIDs = (Invoke-RestMethod -Uri 'http://localhost:8088/dedi' -Headers $Headers).GameSetting.Id
    
    for($i=0; $i -lt $GameSettingsIDs.Count; $i++)
    {
    
        $Headers = @{
            Authorization = $basicAuthValue
            'Content-Type' = 'application/json; charset=utf-8'
            }
    
        #if($GameSettingsIDs[$i] -ne 152272) # lässt diese Session aus
        #if($i -lt 5) # nur die ersten 5 starten, da nicht mehr erlaubt sind
        if($i -ne 2) # lässt diese Session aus
        {
            [System.Environment]::NewLine + "Starte Session " + $GameSettingsIDs[$i] + "... " + `
            (Invoke-WebRequest -Method 'POST' -Uri 'http://localhost:8088/dedi/start' -Headers $Headers -Body "{""ProcessId"":$($GameSettingsIDs[$i])}").StatusDescription
        }
        else
        {
            [System.Environment]::NewLine + "Session " + $GameSettingsIDs[$i] + " wird nicht gestartet!"
        }
    }
    [System.Environment]::NewLine + [System.Environment]::NewLine
    #pause
    RaceRoomDedicatedServer_RestoreSettings.ps1

    Code:
    CLS # nice to have, to clear screen if you use it in the PowerShell ISE
    
    $Body = '{
      "BackupTime": 161...CONTENT_OF_YOUR_BACKUP_FILE...
    }'
    
    "Restore Server-Sessions..."
    
    # User and Password only needed, if you use the file "access" in the folder...
    # C:\Program Files (x86)\Steam\steamapps\common\RaceRoom Dedicated Server
    # ...for protecting Dedicated Server Website
    $user = 'YOUR_USERNAME_IN_FILE_ACCESS'
    $pass = 'YOUR_PASSWORD_IN_FILE_ACCESS'
    $pair = "$($user):$($pass)"
    $encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
    $basicAuthValue = "Basic $encodedCreds"
    
    
    # If you do not use upper Authentication, you can delete Authorisation Part in the header...
    $Headers = @{
        Authorization = $basicAuthValue
        'Content-Type' = 'application/json; charset=utf-8'
        }
    
    (Invoke-WebRequest -Method 'POST' -Uri 'http://localhost:8088/dedi' -Headers $Headers -Body $($Body)).Content
    
    [System.Environment]::NewLine + [System.Environment]::NewLine
    #pause # unkomment for controlling
     
    • Like Like x 1
  6. LaundroMat

    LaundroMat Member

    Joined:
    Nov 28, 2020
    Ratings:
    +15 / 0 / -0
    • Like Like x 1
  7. Balrog

    Balrog Well-Known Member

    Joined:
    Apr 10, 2015
    Ratings:
    +451 / 0 / -0
    Excuse my ignorance, but where does the processId parameter come from in these api calls?
    Edit: Nevermind, I've found it (a session must be created via the API to obtain the processId)
     
    Last edited: Jun 1, 2021
  8. CaptainCoffee

    CaptainCoffee Moderator Beta tester

    Joined:
    Oct 11, 2020
    Ratings:
    +74 / 0 / -0
    Missing data from the API:
    - What car/class does the driver have?
    - Live timings of the users

    Preferably, that data would be available from a public, read only API instead of the API where you can control the dedi. This way, it can be used to read data from other servers without having to ask for access.

    The timings are missing in the dedi API which would be useful, because right now the only workaround is through the spectator overlay which requires a windows computer to run 24/7 instead of a linux based server
     
  9. fried_eggz

    fried_eggz New Member

    Joined:
    Jul 29, 2021
    Ratings:
    +0 / 0 / -0
    New member here. Love RaceRoom. Have my own dedicated server.

    Is it possible to use the api to send post request when someone joins my server (in JSON format or other)

    So that I can build a simple app that can print:

    "User John Doe joined Server 1 at 14.34
    The server currently has 5 users"
     
  10. Koenvh

    Koenvh Member

    Joined:
    Feb 3, 2020
    Ratings:
    +8 / 0 / -0
    @fried_eggz No, there are no events, but you can of course poll the current users and create a diff.
     
  11. fried_eggz

    fried_eggz New Member

    Joined:
    Jul 29, 2021
    Ratings:
    +0 / 0 / -0
    Thanks. Can you give an example on how to pull current users from my dedicated server?

    PHP or js. Pseudo code is enough
     
    Last edited: Jul 30, 2021
  12. fried_eggz

    fried_eggz New Member

    Joined:
    Jul 29, 2021
    Ratings:
    +0 / 0 / -0
    I cant seem to find the api-endpoint that returns the current users on a spcific server. Any hints?
     
  13. Koenvh

    Koenvh Member

    Joined:
    Feb 3, 2020
    Ratings:
    +8 / 0 / -0
  14. fried_eggz

    fried_eggz New Member

    Joined:
    Jul 29, 2021
    Ratings:
    +0 / 0 / -0
  15. Koenvh

    Koenvh Member

    Joined:
    Feb 3, 2020
    Ratings:
    +8 / 0 / -0
    Yes, that call can be found as dedi/{processId}, which returns a JSON object that also contains the players. It's not as straight forward as you think, hence I gave you the code for RR Commander as an example. (E.g. you need to set the right header for the request, plus you need to first get the right processId, and then get the user info based on the ID).
     
    Last edited: Aug 5, 2021
  16. fried_eggz

    fried_eggz New Member

    Joined:
    Jul 29, 2021
    Ratings:
    +0 / 0 / -0
    Thanks a alot! The variable however only contains the id of the user. How can this be converted into the players name?
     
  17. Koenvh

    Koenvh Member

    Joined:
    Feb 3, 2020
    Ratings:
    +8 / 0 / -0
    Just look at the source code I sent earlier, it contains a function get_name_by_id. Or look at the code the Raceroom dedicated server web interface uses.
     
  18. fried_eggz

    fried_eggz New Member

    Joined:
    Jul 29, 2021
    Ratings:
    +0 / 0 / -0
    Thanks, youve been very helpfull. Ive been looking for the code the Raceroom dedicated server web interface uses but I cant find the source code. I just have the RRRE_Dedicated.exe
     
  19. axxis278

    axxis278 Well-Known Member

    Joined:
    Jan 29, 2015
    Ratings:
    +54 / 0 / -0
    Hi,
    is there something wrong with swaggerui ? Seems I can't use it anymore
    upload_2021-11-27_21-15-56.png
     
  20. HowTo

    HowTo New Member

    Joined:
    Jan 25, 2022
    Ratings:
    +0 / 0 / -0
    Can someone help me to connect with the API in php? I can't get it to work. The code i now have:

    PHP:
    // SERVER = actual url to server, same goes for PROCESSID //
    $url 'SERVER:8088/chat/PROCESSID';
    $username 'user';
    $password 'pass';
    $headers = array(
        
    'Method: GET',
        
    'Authorization: Basic 'base64_encode($username.':'.$password),
        
    'X-Requested-With: XMLHttpRequest',
        
    'Content-Type: application/json; charset=utf-8'
    );
       
    $ch curl_init();
    curl_setopt($chCURLOPT_URL$url);
    curl_setopt($chCURLOPT_HEADER1);
    curl_setopt($chCURLOPT_PORT8088);
    curl_setopt($chCURLOPT_HTTPHEADER$headers);
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);

    $output curl_exec($ch);
    $info curl_getinfo($ch);
    curl_close($ch);

    var_dump($output);
    var_dump($info);