[WIP] dedicated servers

Discussion in 'Work-In-Progress Mods' started by cola_colin, October 10, 2014.

  1. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,080
    Likes Received:
    16,221
    So we just played this:
    http://pastats.com/chart?gameId=225629
    hosted on the server of pastats.com

    How to join a custom server:
    Simply install PA Stats or faster server browser. It adds custom servers to the browser.

    How to host a dedicated server on your own machine, assuming linux:

    Read the guide made by @Quitch from Exodusesports here: http://exodusesports.com/guides/planetary-annihilation-dedicated-server-setup/

    or continue with my version that's a little less organized and a little less friendly to the reader:

    First download the game via the gopatcher: https://bitbucket.org/papatcher/papatcher
    To be able to run the server you also need to install some opengl library, so on ubuntu I had to install this: sudo apt-get install libgl1-mesa-glx

    Then download the node js based pa dedicated server controller: http://nanodesu.info/stuff/pa/mods/NodePAMaster.zip (actually so far this isn't really very powerful, it is not ready to use for unattended dedicated servers)
    Install nodejs and configure the conf.json of the NodePAMaster. At minimum you need to change:
    serverip: external ip of your server
    serverport: port the server is running on
    server: needs to point at the server executable
    serverversion at the version.txt of the pa installation
    serverparams now needs to be ["--headless", "--game-mode", "Config", "--allow-lan","--server-name", "yourServerName"] to make it listen at 0.0.0.0

    Now modify the server itself:

    modifiy limits away in sim_utils.js
    the client that joins as host will also have to have them removed in new_game.js (just use this mod: https://forums.uberent.com/threads/rel-unlimited-players.65302/) to add more player slots

    in lobby.js there is a MAX_PLAYERS. You know what you want to do with that number ;)

    put this code block into lobby.js of the server (at the top after the first var definitions)

    Code:
    setInterval(function() {
        if (server.beacon) {
            console.log("<BACON>"+JSON.stringify(server.beacon)+"</BACON>");
        }
    }, 5000);
    
    
    Once you've configured NodePAMaster, configured the server, added the code into the lobby.js of the server-script start NodePAMaster with nodejs control.js
    This should start the server and quickly make it visible on
    http://pastats.com/servers
    That's where pastats gets the custom servers from to be added to the server browser.
    If the server exists NodePAMaster will automatically restart a new instance.

    Server performance
    So before it was said the server would only use 2 threads. This does not entirely seem to be the case. In the 17 players game linked above the server ended up at 300% cpu according to top. It also ate away so much memory that it started to swap on the 16gb machine.
    So my current recommendation would be: A heavily overclocked core i5 with at least 32gb of ram on a pretty fast network, pastats.com has 100mbit and it was not having bandwidth issues with the game linked above. It's quite possible that for bigger games more be required. Not sure.

    EDIT: So after a 32 player game on a 16 core amazon server it turns out that it in fact CAN use more than 3 cores. It topped at ~850% cpu. The sim speed still sucked with roughly 2fps at the worst time though. So I guess the sim is probably only one thread, but it does use more threads for stuff like managing per player data and whatever else it has to do.
    Guess a perfect setup would have 12 cores that are as fast as possible, as the per core speed will limit the sim speed. :/

    EDIT:
    Also see this post by @fuzzels with additional info: https://forums.uberent.com/threads/wip-dedicated-servers.65077/page-2#post-1019398
    Last edited: March 30, 2015
    Jaedrik, Quitch, mattyzero and 6 others like this.
  2. brianpurkiss

    brianpurkiss Post Master General

    Messages:
    7,879
    Likes Received:
    7,438
    Pretty exciting and promising stuff.

    A bit hackish for the time being, but still gets the job done among friends.

    Can't wait until we have official support for this stuff!
  3. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,080
    Likes Received:
    16,221
    This just got easier, the ssh tunnel is no longer required, see my added info about configuring the server parameters.
    With this it now should be possible to just start NodePAMaster via init.d or similar and have it stay all day.
  4. Pychnight

    Pychnight Member

    Messages:
    31
    Likes Received:
    8
    Interesting. There are occasional issues listed below

    Players unable to connect to the dedicated server (with ports correctly forwarded, Seems to happen with slots above 10+ max players.)

    Client Occasionally crashing during successful connect (not sure why this happens other then clicking the background during the connecting screen will cause crashing for the client)
  5. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,080
    Likes Received:
    16,221
    Dunno, have not seen such issues myself.
    Will do more tests this evening.
  6. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,080
    Likes Received:
    16,221
    a little help for many player games, color generating script, replace team_colors_table.js:

    Code:
    exports.data = (function() {
        var MAX_COLORS = 100;
       
       
    /**
    * HSV to RGB color conversion
    *
    * H runs from 0 to 360 degrees
    * S and V run from 0 to 100
    *
    * Ported from the excellent java algorithm by Eugene Vishnevsky at:
    * http://www.cs.rit.edu/~ncs/color/t_convert.html
    */
    function hsvToRgb(h, s, v) {
        var r, g, b;
        var i;
        var f, p, q, t;
       
        // Make sure our arguments stay in-range
        h = Math.max(0, Math.min(360, h));
        s = Math.max(0, Math.min(100, s));
        v = Math.max(0, Math.min(100, v));
       
        // We accept saturation and value arguments from 0 to 100 because that's
        // how Photoshop represents those values. Internally, however, the
        // saturation and value are calculated from a range of 0 to 1. We make
        // That conversion here.
        s /= 100;
        v /= 100;
       
        if(s == 0) {
            // Achromatic (grey)
            r = g = b = v;
            return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
        }
       
        h /= 60; // sector 0 to 5
        i = Math.floor(h);
        f = h - i; // factorial part of h
        p = v * (1 - s);
        q = v * (1 - s * f);
        t = v * (1 - s * (1 - f));
    
        switch(i) {
            case 0:
                r = v;
                g = t;
                b = p;
                break;
               
            case 1:
                r = q;
                g = v;
                b = p;
                break;
               
            case 2:
                r = p;
                g = v;
                b = t;
                break;
               
            case 3:
                r = p;
                g = q;
                b = v;
                break;
               
            case 4:
                r = t;
                g = p;
                b = v;
                break;
               
            default: // case 5:
                r = v;
                g = p;
                b = q;
        }
       
        return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
    }
    
    function randomColors(total) {
        var i = 360 / (total - 1); // distribute the colors evenly on the hue range
        var r = []; // hold the generated colors
        for (var x=0; x<total; x++)
        {
            r.push(hsvToRgb(i * x, 100, 100)); // you can also alternate the saturation and value for even more contrast between the colors
        }
        return r;
    }
    
    var p = randomColors(MAX_COLORS);
    
    var result = [];
    
    for (var i = 0; i < MAX_COLORS; i++) {
        result.push({
        primary: p[i],
        secondary: [p[p.length-1-i]]
        });
    }
    
    return result;
    
    }());
    
    
    
    
    nacs and stuart98 like this.
  7. burntcustard

    burntcustard Post Master General

    Messages:
    702
    Likes Received:
    1,317
    Last edited: February 6, 2015
  8. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,080
    Likes Received:
    16,221
    known bug: Servers are removed from the list if a player with utf-8 chars like Ħ joins the game.
    Working on a fix
  9. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,080
    Likes Received:
    16,221
    "Fix" released, people running server should download the new version of NodePAMaster from the OP. I admit all the "fix" does is filter out those pesky special chars. Something is wrong with how nodejs does a post request to pastats.com. No idea what though.

    Also note I massively simplified the required code for lobby.js. The new PA build makes that possible.
    proeleert likes this.
  10. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,080
    Likes Received:
    16,221
    note to self, maybe helpful to others, list of the more prominent commands to setup a server on an aws ubuntu instance:
    Code:
    wget https://bitbucket.org/papatcher/papatcher/raw/a7b8b4febb491d6fc6c45155b238fd42ee34fcc8/papatcher.go
    sudo add-apt-repository ppa:duh/golang
    sudo apt-get update
    sudo apt-get install golang
    chmod +x papatcher.go
    go run papatcher.go
    <login>
    <download>
    sudo apt-get install libgl1-mesa-glx
    <modify server: /media/server-script/states/lobby.js, /media/server-script/sim_utils.js, /media/server-script/team_color_table.js> (also don't forget to install the ui mod "Unlimited Players" in pamm to get rid of client side limits)
    wget http://nanodesu.info/stuff/pa/mods/NodePAMaster.zip
    sudo apt-get install unzip
    unzip NodePAMaster.zip
    sudo add-apt-repository ppa:chris-lea/node.js
    sudo apt-get update
    sudo apt-get install nodejs
    byobu
    nodejs control.js
    also for aws I think I had to modify the servers security settings on the aws control panel to open up ports. I went with simply disabling the whole firewall
    Last edited: October 19, 2014
  11. Dourel

    Dourel New Member

    Messages:
    4
    Likes Received:
    0
    Ugh... I still can't force client/server to increase the player limit. Got colors working, some other stuff that I wanted, but everything involved with player limit just simply doesn't work. Changed new_game.js and lobby.js and I am still unable to add more than 10 players. Any help?
  12. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,080
    Likes Received:
    16,221
    so a little less lazy hint is:
    /media/ui/main/new_game/new_game.js look for code that does comparisons with 10 and 5 and up those numbers as much as you want. That's the client side. Only the host needs this. If you made a mistake here the client will disable the "add slot" button when the limit is reached.

    /media/server-script/states/lobby.js has a value "MAX_PLAYERS". Change it to 9001. If you made a mistake here you will be able to click add slot, but nothing will happen as the server will refuse the request for more players
    /media/server-script/sim_utils has planet limitations
  13. FSN1977

    FSN1977 Active Member

    Messages:
    657
    Likes Received:
    232
    Well can't get this to work either :p
  14. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,080
    Likes Received:
    16,221
    If you want help you'll need to describe what you are doing ;)
  15. Chemdude8

    Chemdude8 New Member

    Messages:
    25
    Likes Received:
    8
    So I've been trying to get this to work, I'm able to get it to show up on pastats.com but when I try to connect I (slowly) get a failed to connect to server error. Using netstat -a I see that I am listening on port 6543 for 0.0.0.0 and I have set up port forwarding from my modem to my router to my pc. I have disabled/configured all firewalls and still no joy. I was able to connect to someone else's locally hosted online game just not my own. Any thoughts? I am simply running the PAManager which I presume runs the server automatically. Haven't had a chance to try and connect from a different computer yet though.
  16. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,080
    Likes Received:
    16,221
    If it is listing on pa stats the server is running 100%
    You yourself get a connection error as well when connecting to yourself? Weird. I've not had any such issues, though all servers I have run where on linux servers.
    As a test you can put in 127.0.0.1 as the ip of your server in the NodePAMaster config, will it connect to that (obviously that would only work for you)?
  17. Chemdude8

    Chemdude8 New Member

    Messages:
    25
    Likes Received:
    8
    Hmm, was able to give it a shot, was able to connect to the 127.0.0.1 (local_host) so maybe my dmz/portforwarding/firewalling is wrong. Can anyone else connect with the same pc as they are hosting the game on when using their global ip? Also do you always see two instances in the lobby browser? For me I see the local server as well as "custom: your moms house" for regions. (your moms house instead of the paStats by default).
  18. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,080
    Likes Received:
    16,221
    The two instances are because you have the server on your local machine. One of them is from PA Stats, the other is the normal lan one. For players not in your LAN the normal lan one won't be there.
  19. FSN1977

    FSN1977 Active Member

    Messages:
    657
    Likes Received:
    232
    I just want to play some larger AI games, I have changed the new_game.js like you said, also lobby.js but still dosent let me create more than 10 slots. So I must be missing something.
  20. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,080
    Likes Received:
    16,221
    No, those are the only 2 issues. Are you sure you modified the lobby.js of the server you are playing on? Is it not reacting to the add slot button or is it not allowing you to click it in the first place?

Share This Page