[WIP] System Sharing

Discussion in 'Mod Discussions' started by cptconundrum, January 30, 2014.

  1. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    If any part of this dies to stress it will be the PA UI when trying to display a few k systems, long before the backend has trouble.
  2. cptconundrum

    cptconundrum Post Master General

    Messages:
    4,186
    Likes Received:
    4,900
    Which is why I'm going to paginate. I'm also really happy with how well this integrates with the rest of the client. You barely even notice that it is downloading from a server because everything just works the same.
  3. cptconundrum

    cptconundrum Post Master General

    Messages:
    4,186
    Likes Received:
    4,900
    Making some progress on pagination!
    system-sharing.jpg
    LavaSnake likes this.
  4. cptconundrum

    cptconundrum Post Master General

    Messages:
    4,186
    Likes Received:
    4,900
    The version I'm uploading is for testing only. I'm just running the server as a couple php scripts on my own webserver, but I can't keep it here for long. Please try it out and let me know if you can find any bugs. I don't want this up on PAMM or anything because it will break as soon as I shut off my server.

    Right now everything just gets thrown into one list without any options to sort or filter. Pages are hard-coded at 10 systems per page, so you can test this by uploading a few more systems or changing the client to ask for less than 10 at a time. Using a shared system is really easy, because you just have to go to new game > load > PA stats systems > load. That part works exactly the same as your local systems.

    Attached Files:

    LavaSnake likes this.
  5. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    Why does it require PA Stats?

    EDIT:
    seems to work fine for me
  6. cptconundrum

    cptconundrum Post Master General

    Messages:
    4,186
    Likes Received:
    4,900
    I guess because I originally thought I would be more closely integrated with PA stats. It works fine as a standalone mod though so I'll be removing the requirement even if we end up hosting the server on PA Stats.
  7. cptconundrum

    cptconundrum Post Master General

    Messages:
    4,186
    Likes Received:
    4,900
    Fixed an Uber bug that was bothering me. system thumbnails are now showing correctly. (FS#3011)

    Attached Files:

    Last edited: January 31, 2014
    emraldis and LavaSnake like this.
  8. cptconundrum

    cptconundrum Post Master General

    Messages:
    4,186
    Likes Received:
    4,900
    Filtering is done on the client side, so I think I have everything ready on the client. We now have to decide where this will be hosted and then write the server for it. I am still really hoping this can get integrated into PA Stats. I would like to eventually add an option to look at the automatch systems so that you can load them and get some practice in. It would also be good to improve the PA Stats web pages so that we can get stats about each system. I would love to be able to see average game length, average number of units made by type, etc.

    As long as the server responds correctly to the client's API calls, this mod can actually be directed to any server you want. It shouldn't be hard for clans to run their own private system sharing servers.

    [​IMG]
    mishtakashi, LavaSnake and cola_colin like this.
  9. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    Looks pretty cool.
    I however won't have time to work on anything before the weekend and even then I most likely will not have the time to do the really cool parts of integration. If you try it yourself I can give you directions and all, but my time is limited currently. :/
  10. cptconundrum

    cptconundrum Post Master General

    Messages:
    4,186
    Likes Received:
    4,900
    I plan to take a look at your Scala file for the ladder and matchmaking services and just copy that. Setting up the database is a bigger issue, I guess. I suppose I can just keep using my php scripts as the server, host it myself, and copy over the database as soon as we have something better available. PAMM users would just need to update and they would be able to connect to the new server.
  11. cptconundrum

    cptconundrum Post Master General

    Messages:
    4,186
    Likes Received:
    4,900
    If I do that, should I keep the PA Stats branding or change it?
  12. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    One option is to write a server for it in Google App Engine. It has a powerful and easy to use database system and it would probably fill your need without having to pay anything. (The free level of resources is usually enough for projects of this size.) I've done a fair amount with it and I'd be happy to write it but it will take me awhile to find the time.
  13. cptconundrum

    cptconundrum Post Master General

    Messages:
    4,186
    Likes Received:
    4,900
    That could work, but the long term goal would still be closer integration with PA Stats. Ideally PA Stats would create a system entry if it sees a game that is being played on a system it has never encountered before. The client would request those to be filtered out by default, but you could still copy+paste a system id from PA Stats to get it.
  14. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    I was suggesting it as more of a backup option if the PA Stats integration didn't work out.
    cptconundrum likes this.
  15. cptconundrum

    cptconundrum Post Master General

    Messages:
    4,186
    Likes Received:
    4,900
    Someone might do that eventually. I would be surprised if clans didn't start running their own servers.
  16. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    Careful with the MatchMaker webservice, it is utterly horrible code. The general how to for a json based webservice can be found in it though or read here:

    PA Stats has a database setup and all why not use that? Any real integration would obviously do that I think.
    PA Stats runs on a postgres database and uses http://www.jooq.org/ for interaction with it, it is pretty easy to learn if your know SQL. Have a look at some of the database access classes (private DbLayer stuff is pretty much build by pure database methods) here:

    https://github.com/pamods/PA-Stats-...orting/running/RunningGameStatsReporter.scala

    https://github.com/pamods/PA-Stats-.../collectors/gameinfo/ArmyEventCollector.scala

    https://github.com/pamods/PA-Stats-.../gameinfo/loader/UpdatingGameInfoLoader.scala

    and the general helper class here:
    https://github.com/pamods/PA-Stats-...in/scala/info/nanodesu/lib/db/CookieBox.scala

    as well as the sql file for a database reset here:
    https://github.com/pamods/PA-Stats-Server/blob/master/db_definition/tablesv2.sql

    and at the folde jooq_code_generation. There is a script that generates the necessary java classes for typesafe interaction with the code. You just modify the database and run the script.


    Generally I am super amazed by how awesome jooq is. It's like writing SQL for the most part, but typesafe and composable and with a few ease of use functions. Even though the last part can be a bit tricky because jooq is meant for java and only "works" in scala.
    LavaSnake and cptconundrum like this.
  17. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    Maybe I should just go ahead and write it and then open source the code on GitHub so they can use it to spin up their own system hosts. Could you post the docs of what sever calls I would need to support sometime so I can look into writing it?
  18. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
  19. cptconundrum

    cptconundrum Post Master General

    Messages:
    4,186
    Likes Received:
    4,900
    Sure. There are two urls that I call, for save and search.

    Save is pretty simple. I get the current system spec, add a 'creator' attribute at the top level, and send it off to the server as a variable called 'system'. The server has to extract system.creator, count the number of planets in system.planets, and save it all to the database. Currently I print out "true" directly (not a json response) if there was no error. This part really needs to change.

    Search is a little more complicated. Attributes with a * are optional or an empty string (Example: ""). Empty string should be treated as a missing attribute.

    Request:
    Code:
    * name: string
    * creator: string
    minPlanets: Number(1:16)
    maxPlanets: Number(1:16)
    start: Number(>= 0)
    limit: Number
    request_time: Number
    sort_field: string("system_id" | "num_planets")
    sort_direction: string("ASC" | "DESC")
    
    The 'request_time' is just a timestamp so the client can throw away stale responses. The server just needs to send that back as a top-level attribute in the response json object. 'total' is the total number of rows that match this filter. This is usually a lot higher than 'limit' and is used for client pagination. The 'systems' attribute is an array of system specs, all containing the extra 'creator' attribute.

    Response:

    Code:
    request_time: Number
    total: Number
    systems: Array()
    
    *Edit*

    'start' and 'limit' are for pagination. Page one will request {start: 0, limit: 10}, page two will be {start:10, limit:10}, etc.

    Sample response json:

    Code:
    { "request_time": 123456789, "total": 13, "systems": [{"name":"Demo System","planets":[{"name":"desert template","mass":"1800","position_x":"23828.2","position_y":"-9645.85","velocity_x":"52.3311","velocity_y":"129.274","planet":{"seed":"3348","radius":"804","heightRange":"50","waterHeight":"38","temperature":"100","metalDensity":"50","metalClusters":"50","biomeScale":"50","biome":"earth"}},{"name":"Hoth","mass":"2000","position_x":"21444.6","position_y":"-22702.2","velocity_x":"91.984","velocity_y":"86.8885","planet":{"seed":"14451","radius":"1010","heightRange":"50","waterHeight":"55","temperature":"0","metalDensity":"50","metalClusters":"50","biomeScale":"50","biome":"earth"}},{"name":"Kessel","mass":"1000","position_x":"9216.49","position_y":"-31389.7","velocity_x":"106.938","velocity_y":"65.8399","planet":{"seed":"78462","radius":"400","heightRange":"75","waterHeight":"0","temperature":"0","metalDensity":"50","metalClusters":"50","biomeScale":"50","biome":"moon"}},{"name":"Mustafar","mass":"2500","position_x":"38218.3","position_y":"-5854.21","velocity_x":"17.2184","velocity_y":"112.407","planet":{"seed":"7846","radius":"700","heightRange":"60","waterHeight":"40","temperature":"100","metalDensity":"50","metalClusters":"50","biomeScale":"50","biome":"lava"}}],"creator":"Captain Conundrum"}] }
    
    *Edit 2*

    Attaching the current client code for reference. It was broken.

    *Edit 3*

    save uses a POST request and search uses GET. I forgot to mention that.

    * Edit 4* (That's a lot of revisions!)

    You also need to extract the system name during a save operation so that it can be searched for later on.
    Last edited: September 17, 2014
  20. cptconundrum

    cptconundrum Post Master General

    Messages:
    4,186
    Likes Received:
    4,900
    Uploading a version of the client that I hope works this time. It's connected to my own server, so this is actually a working mod. Just don't try any sql injection or anything, because you'll explode the database.

    Attached Files:

Share This Page