Author Topic: [done] Headless: Please allow retrieving game state from command line  (Read 822 times)

tomreyn

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 2,764
    • View Profile
    • MegaGlest - the free and open source cross platform 3D real-time strategy game
It would be nice if it was possible to determine, for a local headless server, whether network players are currently connected to it. While this can usually be done by querying the masterserver, that's not as ideal as being able to determine this locally. Currently, if the gameserver fails, for any reason, to report / get listed on to the masterserver, then you cannot determine its current game state (waiting for network players, game full, game in progress, # of network players connected).

Some use cases:
You may want to restart the server in regular intervals or based on system indicators but only if no network players are currently connected (you may want to postpone otherwise), if, for example:
  • the process has been running for > 24 hours, but you want to restart it every 24 hours to rotate the log files
  • the process' memory consumption has reached xxx MB but no network players are connected,
So it would be nice to be able to do one of the following:
  • Inspect presence of a lock file which indicates that >=1 network players are connected
  • Run megaglest with a special command line option to determine the game state of the previously started (and still running) MegaGlest process
  • There may be other ways/interfaces I cannot currently think of which would serve this purpose even better
I guess I'm asking for two things: an indicator which allows to determine whether network players are connected (this would be really nice to have from a server admin point of view - sure you can use netstat/lsof for this purpose but it's not as clean) and a way to locally query the current game state of a running headless server. The latter is actually not so important to me, I'm merely listing it here because it is somehow related and might be of use to others (and would include the first request).
« Last Edit: 26 March 2012, 02:35:50 by tomreyn »
atibox: Ryzen 1800X (8 cores @3.6GHz), 32 GB RAM, MSI Radeon RX 580 Gaming X 8G, PCI subsystem ID [1462:3417], (Radeon RX 580 chipset, POLARIS10) @3440x1440; latest stable Ubuntu release, (open source) radeon (amdgpu) / mesa video driver
atibox (old): Core2Quad Q9400 (4 cores @2.66GHz), 8 GB RAM, XFX HD-467X-DDF2, PCI subsystem ID [1682:2931], (Radeon HD 4670, RV730 XT) @1680x1050; latest stable Ubuntu release, (open source) radeon / mesa video driver
notebook: HP envy13d020ng
internet access: VDSL2+

· · · How YOU can contribute to MG · Latest development snapshot · How to build yourself · Megapack techtree · Currently hosted MG games · · ·

softcoder

  • MegaGlest Team
  • Battle Machine
  • ********
  • Posts: 2,239
    • View Profile
Re: Headless: Please allow retrieving game state from command line
« Reply #1 on: 25 March 2012, 06:56:44 »
In svn you may run this on the ame box as the headless:

Code: [Select]
./megaglest --headless-server-status
To get the status of all network slots.

tomreyn

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 2,764
    • View Profile
    • MegaGlest - the free and open source cross platform 3D real-time strategy game
Re: Headless: Please allow retrieving game state from command line
« Reply #2 on: 26 March 2012, 02:08:49 »
Code: [Select]
tomreyn@atibox:~/SCM/megaglest-trunk/mk/linux$ tempfile=`mktemp`; ./megaglest --headless-server-status > $tempfile; line=`grep -n '^=========================================$' $tempfile | head -n1 | cut -d':' -f1`; tail -n +$line $tempfile; rm $tempfile
=========================================
Headless Server Current Game information:
=========================================
Network connection for index: 0
------------------------------
Connected: 0
Handshake received: 0
Network connection for index: 1
------------------------------
Connected: 1
Handshake received: 1
Connected at: 2012-03-26 04:05:19
Connection duration: 0 hours 0 minutes 7 seconds.
Player Index: 1
IP Address: 127.0.0.1
Player name: tomreyn
Language: english
Game Version: v3.6.1-dev-GNUC: 40601 [64bit]-Rev: 3174M
Session id: 485983
Socket id: 10
Network connection for index: 2
------------------------------
Connected: 0
Handshake received: 0
Network connection for index: 3
------------------------------
Connected: 0
Handshake received: 0
Total Slot Count: 4
=========================================

tomreyn@atibox:~/SCM/megaglest-trunk/mk/linux$

Thanks for the quick implementation!

Will this also work well if you have multiple headless servers on a single system?
« Last Edit: 26 March 2012, 02:36:54 by tomreyn »
atibox: Ryzen 1800X (8 cores @3.6GHz), 32 GB RAM, MSI Radeon RX 580 Gaming X 8G, PCI subsystem ID [1462:3417], (Radeon RX 580 chipset, POLARIS10) @3440x1440; latest stable Ubuntu release, (open source) radeon (amdgpu) / mesa video driver
atibox (old): Core2Quad Q9400 (4 cores @2.66GHz), 8 GB RAM, XFX HD-467X-DDF2, PCI subsystem ID [1682:2931], (Radeon HD 4670, RV730 XT) @1680x1050; latest stable Ubuntu release, (open source) radeon / mesa video driver
notebook: HP envy13d020ng
internet access: VDSL2+

· · · How YOU can contribute to MG · Latest development snapshot · How to build yourself · Megapack techtree · Currently hosted MG games · · ·

softcoder

  • MegaGlest Team
  • Battle Machine
  • ********
  • Posts: 2,239
    • View Profile
If you use commandline, you may add a third port # override ofr the port # used for network status requests:

Example for Masterserver:

Code: [Select]
./megaglest --headless-server-mode --use-ports=10000,20000,30000
Example from client:

Code: [Select]
./megaglest --headless-server-status --use-ports=10000,20000,30000
The Server / Client can also optionally read the status port from ini:

Code: [Select]
ServerAdminPort=x
Thanks

 

anything