The International Simutrans Forum

 

Author Topic: Access to statistics data of game  (Read 413 times)

0 Members and 1 Guest are viewing this topic.

Offline Chargeotto

  • *
  • Posts: 2
  • Languages: EN, NL
Access to statistics data of game
« on: February 25, 2019, 06:22:05 PM »
I'm a software developer and although I don't have much experience with C++ I was thinking about ways to pull statistics data from the game while playing to enhance gameplay with real-time statistics in a modern way.

For instance, when I'm playing the game on my main screen I would love to use a 2nd monitor and open the browser to access a dashboard with all the statistics information of the game.
I do have some (very basic) understanding of C++, but I was hoping someone would know what part of the code would be best to start looking at to find a way to access the data of the number of trains, passenger numbers, and all kinds of info that would be cool to show on a 2nd screen while playing the game.

I don't know to what degree historical data of the game is stored within the game. But I can think of a lot of features that would be interesting to see from a statistics viewpoint. I'm very curious about people's thoughts about something like this and how doable this would be. Basically, the game would expose a small REST API to access data. Not sure how hard this is, but I guess a good way to get more info C++ coding for me.

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 5447
  • Languages: EN, NO
Re: Access to statistics data of game
« Reply #1 on: February 25, 2019, 09:23:03 PM »
It has been discussed before, and I think there was some agreement that using scripting to do something was the most achievable solution. That would either mean some scripted GUI within Simutrans, or perhaps writing out to a file.

Adding a HTTP server to the game is not trivial. Open HTTP ports is perhaps the number one weakness hackers will be looking to exploit these days, and even well maintained HTTP server software has security holes discovered on a regular basis. Given the frequency of Simutrans releases, any such hole, whether custom made or from third-party solution, will take time to plug at our users. SImutrans' own multiplayer port is probably only reasonably safe due to it not being a common protocol, which hackers don't find too interesting due to high cost, low gain.

Offline DrSuperGood

  • Dev Team
  • Devotee
  • *
  • Posts: 2592
  • Languages: EN
Re: Access to statistics data of game
« Reply #2 on: February 26, 2019, 08:45:48 AM »
There are also platform specific inter process communication methods. These might be more secure since they are not directly exposed to network based attacks.

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 5447
  • Languages: EN, NO
Re: Access to statistics data of game
« Reply #3 on: February 26, 2019, 03:53:09 PM »
Perhaps, but also either very platform specific, or much more difficult to work with due to being much lower level.

Offline Chargeotto

  • *
  • Posts: 2
  • Languages: EN, NL
Re: Access to statistics data of game
« Reply #4 on: February 26, 2019, 07:49:14 PM »
It has been discussed before, and I think there was some agreement that using scripting to do something was the most achievable solution. That would either mean some scripted GUI within Simutrans, or perhaps writing out to a file.

Adding a HTTP server to the game is not trivial. Open HTTP ports is perhaps the number one weakness hackers will be looking to exploit these days, and even well maintained HTTP server software has security holes discovered on a regular basis. Given the frequency of Simutrans releases, any such hole, whether custom made or from third-party solution, will take time to plug at our users. SImutrans' own multiplayer port is probably only reasonably safe due to it not being a common protocol, which hackers don't find too interesting due to high cost, low gain.

I agree with this, I didn't even realized how big of a security issue this would be. But actually, that 2nd monitor app could be completely standalone as long as there is a way to read state/data of the game.
I'm not that familiar with multiplayer, but does that protocol share a lot of game data that you could listen onto to get an idea what's all going on within the game?
Let's say a train is on the way to destination A for player X,  how does player Y know that that train is heading to destination A?
Maybe my idea would work better while playing a multiplayer game? (if there is a way to listen to a game without being an actual player)

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 5447
  • Languages: EN, NO
Re: Access to statistics data of game
« Reply #5 on: February 26, 2019, 08:44:35 PM »
Let's say a train is on the way to destination A for player X,  how does player Y know that that train is heading to destination A?
Player Y knows that because they are playing the same game.

Both players have loaded the same game, and from the initial state, the game develops the same on all systems because they are running the same code. The players just need to send information to each other as to which actions they perform, such as buy vehicle, build road, demolish building. And there are some messages that check that no instance of the game runs ahead of or lags behind the others, or that something else has caused desynchronization.

It is not a very usual way of doing multiplayer, but Simutrans wasn't designed for multiplayer originally, so the solution is a hack.

Offline DrSuperGood

  • Dev Team
  • Devotee
  • *
  • Posts: 2592
  • Languages: EN
Re: Access to statistics data of game
« Reply #6 on: February 26, 2019, 11:50:13 PM »
Quote
It is not a very usual way of doing multiplayer
It is extremely usual. Practically every RTS game does it this way, including competitor games like OpenTTD.

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 5447
  • Languages: EN, NO
Re: Access to statistics data of game
« Reply #7 on: February 27, 2019, 05:20:15 PM »
It is extremely usual. Practically every RTS game does it this way, including competitor games like OpenTTD.
I wasn't aware that most, or the most played, games were RTSes. My impression from whatever filters down to me was that it was something in the range from first person shooter to role playing games.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9417
  • Languages: De,EN,JP
Re: Access to statistics data of game
« Reply #8 on: March 08, 2019, 01:25:31 PM »
That is the way a world simulation is built. If a factories 1000 tiles away sends some cargo into your direction, then you must know this. The amount of data to synchronise grows quadratically with map size. Hence a deterministic map from an initial state is an easy way to reduce data, since the information is encoded in the world algorithm.

With a first person shooter, you do not care who dies 100 km away from you ... So it can be more local.