server_browser.js

Discussion in 'Support!' started by maxpowerz, October 2, 2013.

  1. maxpowerz

    maxpowerz Post Master General

    Messages:
    2,208
    Likes Received:
    885
    not sure how this works as im not that good with Java script.
    I'll attempt to help anyway if not it may be a useful suggestion!!

    I'm "Guessing" that server_browser.js is the script that handles looking for games on the uberent server.
    For me it refreshed the list fast as it possibly can, This is ok i have no real issue with it but it uses a lot of bandwidth/data.

    maybe adding a :
    "self.setInterval()" or "self.setTimeout()"
    around this function
    "self.updateServerData"
    may slow things down a little and maybe an addition of a refresh button could be in order :)

    also i noticed some coding typo's, not sure if they are meant to be like that :) in example, in the server_browser.js file the 4/5 th line has this code
    "function ServerBrowerViewModel() {"
    and further down in the same file
    "model = new ServerBrowerViewModel();"

    should this instead be :
    "function ServerBrowserViewModel() {"
    and
    "model = new ServerBrowserViewModel();"

    or was it intentionally spelled that way?
    Last edited: October 2, 2013
  2. maxpowerz

    maxpowerz Post Master General

    Messages:
    2,208
    Likes Received:
    885
    I also understand that coding for hours on end wears ones fingers out and mentally fatigues a person, so errors and typo's should be expected, (i break lots of code when trying to hack / implement new features to games and softwares while sleepy or already worn out)
  3. Fishrock123

    Fishrock123 New Member

    Messages:
    4
    Likes Received:
    1
    Where did you find this 'server_browser.js' file?
  4. maxpowerz

    maxpowerz Post Master General

    Messages:
    2,208
    Likes Received:
    885
    its a part of the PA game files, it resides in this directory,
    C:\Program Files (x86)\Planetary Annihilation\PA\media\ui\alpha\server_browser
  5. maxpowerz

    maxpowerz Post Master General

    Messages:
    2,208
    Likes Received:
    885
    i have limited internet at the moment so im having more fun and spending more time reverse engineering the game code than i am playing it,
    this will inevitably help me make my own QUALITY mods :) as i will under stand the inner workings of the game engine better.
    Last edited: October 2, 2013
  6. Fishrock123

    Fishrock123 New Member

    Messages:
    4
    Likes Received:
    1
    Seems like it. This looks awesome for modding. JS UI FTW.
    You seem to be wrong on the refreshing part. How did you know it was refreshing as fast as it could?

    Refer to line 348:
    Code:
        if (!model.showingLanGames()) {
            // start periodic update
            setInterval(model.updateServerData, 1000);
        }
    It only calls the update every 1000ms, i.e. 1 second.
  7. maxpowerz

    maxpowerz Post Master General

    Messages:
    2,208
    Likes Received:
    885
    in the lobby when looking for a game my internet connection goes spastic, in task manager and in my monitoring apps it spikes over and over again, but since the latest update its been better.

    Cheers for finding that setInterval for me :)
    now i can change it myself and lower the amount of refreshes it does myself ,,
    i had overlooked that one and i thought it was missing :)
  8. darac

    darac Active Member

    Messages:
    261
    Likes Received:
    128
    It'll be a mistake and thanks to the wonders of copy and paste and autocomplete these sort of mistakes get duplicated across the code base! That's what happens to me anyway. Haha.
  9. maxpowerz

    maxpowerz Post Master General

    Messages:
    2,208
    Likes Received:
    885
    This is why i wanted to point it out now for jon or other engine techs to see.

    At some later point someone might want add more code that will call upon this function, and write code in only to have it fail because the function was incorrectly spelt the first time.
  10. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    Hmm, I've seen that interval call before and I am pretty positive that in an earlier version of PA it was at once every 3 seconds. So if it changed at all it went down, not up. But seriously how would a little webservice call like this create any noteable traffic? It's understandable that you thought something was wrong, as it indeed creates ~50kb/s traffic currently for me. However es previously mentioned it does only refresh once every second.

    ... is what I asked myself so I looked into this.

    The "problem" is that it sends a crazy amount of data:

    http://pastebin.com/nS5EZh18

    That's ~50kbyte of json data. Sent once per second it matches up with the observed traffic.

    That is a list of all games currently running with all players and some other player data.

    So I guess somebody at Uber has a TODO on his list to create a specific call to only query for the games that are open to be joined. That would drastically reduce the bandwidth usage.
  11. maxpowerz

    maxpowerz Post Master General

    Messages:
    2,208
    Likes Received:
    885
    I have FIXED the spelling errors in server_browser.js
    I have joined games with the FIXED file too,
    so the function that was mis-spelled is only being called upon from inside this script and nowhere else.

    FIXED ITEMS:

    "function ServerBrowerViewModel() {"
    and further down in the same file
    "model = new ServerBrowerViewModel();"

    these lines are now

    "function ServerBrowserViewModel() {"
    and
    "model = new ServerBrowserViewModel();"

    no other coding has been touched!!!
    I only fixed the spelling of the function and the spelling of the call of the function :)

    the fixed files are in the server_browser.zip i have attached to this post.
    hopefully this helps save an uber employee 2 mins of their time on a trivial spelling error :)

    Inside the zip are 2 file's :
    server_browser.js (this is the one i have fixed the typo's in)
    server_browser.js-orig (this is the original file before i edited it)

    Attached Files:

  12. maxpowerz

    maxpowerz Post Master General

    Messages:
    2,208
    Likes Received:
    885
    @cola_colin :) i thought i was goin outta my mind, i even started virus scanning my PC assuming that if it wasn't PA i may have had a Trojan or something .. lol
    I was pretty sure it was PA tho because it was only happening when i was in the server browser
  13. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    I regret to inform you that computers dont care about spelling of function names. As long as they match up they work.
    You could write sioudfhsiuhdsiu instead of ServerBrowser and it would keep working. The only reason why the names are used is to make it readable for humans. Also the typo had no effect because the js is probably written in an Editor with Autocompletion, so whoever wrote it missspelled it when he defined the class name and later used auto complete to get the missspelled function name, probably without even noticing that it is missspelled.
    So basically the typo is so extremely trivial that thanks to modern IDE's the developers dont notice the mistake and it has no effect xD
  14. maxpowerz

    maxpowerz Post Master General

    Messages:
    2,208
    Likes Received:
    885
    @cola_colin,, yes i know it doesn't matter how you spell a function,
    but if i spell a function like "BrowseServer" as "BrewsServer" the next coder who want's to call upon that function needs to make sure they spell it with my dyslexic spelling,
    In the end this slows coding down heaps when people need to go back through their code and review how they spelt some of their functions instead of making them easy to remember and spell.
    I don't think jon and his team need those kind of delays, so i thought it may be good to point out typo's
  15. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    No, judging by the fact that the misspell was used through all of the code they use a pretty good IDE.
    So there is a high change that the developers actually only type something like BS and press space or the like to get the IDE to suggest BrowserServer, or BroweServer or however it is misspelled.
    So a good IDE basically prevents you from ever wasting time on typos like that.
  16. maxpowerz

    maxpowerz Post Master General

    Messages:
    2,208
    Likes Received:
    885
    Cool,
    I'm not used to using any of the newer kinds of development environments, i usually just hack others code using good old notepad .. hahaha.

    Honestly, my programming skills haven't been updated since i learned Turbo Pascal . LMFAO
    I was too lazy to learn about programming in windows using either Delphi or C+ IDE's.
    and there's no fun feature like Autofill in DOS

    Eventually i gave up on programming all together,
    Programming in DOS it wasn't as fun as demo coding on the amiga.
    and learning Assembly was a headache as Desktop PC had billions of different things to change with the flags register and addresses, unlike my amiga wich was much easier to DEMO code on, simpler hardware had a smaller flags register and was only 16bit.
    Last edited: October 2, 2013
  17. Fishrock123

    Fishrock123 New Member

    Messages:
    4
    Likes Received:
    1

    Ouch. That's very bad.

    For that size, ideally a hash of the data would be made and sent to see if the data has even changed, and only send new data if it has.
    EDIT: The games report runtime. That wouldn't work without that being removed from the hash.

    However, the cause of the data size appears to be a server bug. These games are reporting 'stopping' rather than 'running'.
    If this state representation is accurate, i'm guessing there's some sort of object / state leak somewhere when games have ended that they still retain that state once all players have left. That's bad.

    Code:
    {"Region":"USCentral","LobbyID":"1250313504122160789","BuildVersion":"54497","GameMode":"TeamArmies4","Map":"default","MaxPlayers":4,"PlayerUberNames":["marookletor","jetgrey"],"RunTime":"20:00:42.8185722","GameServerState":"Stopping"},
    EDIT: Holy crap I am right. That game is reporting a run-time of a whopping 20 hours.

    This qualifies for the bug tracker, right?

    EDIT2: The 'running' functionality is definitely implemented. If you look through the list you'll find a couple games that are. (esp near the bottom).
    Last edited: October 2, 2013
  18. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    My guess is that the server state is either incorrect or just not finished.

    I dont think it is that bad, I've tested it, this is a game I am playing right now:

    ,"MaxPlayers":4,"PlayerUberNames":["cola_colin"],"RunTime":"00:01:39.9457181","GameServerState":"Stopping"},

    So it says "Stopping" even though I am playing.

    And now I stop it.... after maybe 2 or 3 minutes the game was removed from the list.
    Considering that the game count in the server browser is calculated from the amount of games and how the game count went way up with beta (more players) and goes down around certain times (work/sleeptime) I dont think there is a sever leak. That 20h game is weird, but here have been players like that before.

    EDIT:
    About running, see this code from the server_browser.js:

    Code:
                        if (games[i].PlayerUberNames.length != hacky_max_players
                            && games[i].GameServerState === "Running"
                            && games[i].BuildVersion === self.buildVersion()
                            && games[i].GameMode !== 'QuickMatch4'
                            && games[i].GameMode !== 'QuickMatch2') {
    
                            lobby_players += games[i].PlayerUberNames.length;
                            self.currentGames.push([games[i].Region,
                                                    users,
                                                    'owner',
                                                    games[i].GameMode,
                                                    '' + games[i].PlayerUberNames.length + '/' + hacky_max_players,
                                                    games[i].LobbyID]);
                        }
    Running means that the game can be joined right now. So Running and Stopping might be more about the process of accepting new players into the game than the game itself.
  19. maxpowerz

    maxpowerz Post Master General

    Messages:
    2,208
    Likes Received:
    885
    It could be a stuck game, the players may have dropped out of game but the game is running on the server still waiting for them to join again.

    Not too sure but if both players drop out and leave their armies in an idle state (not warring) and both commanders are just sitting there doing nothing, will the server wait till they rejoin?? and how long does it wait before terminating the game if both teams don't rejoin ??

    that 20h match could just be a match thats in theory on pause because both players haven't rejoined and both commanders are intact.
  20. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    Pretty sure that the guys at Uber did consider this already. ;)

    Also hey, there are people who really do play long games, see here:

    http://www.nanodesu.info/pastats/chart?gameId=2529

Share This Page