Jump to content

Help with financial reporting of stations (possible mod)


CMDR Edu

Recommended Posts

Hi, I'm a beginner on programming and I have poor experience with the lua, so I've come to ask for help here for you. I would like to make a kind of database with profitability report for each station or mine of the player. My debt consists of what would be the best way to "intercept" the messages that pass in the economy tab and store them in a simple text file or even a database. The storage I would study the best way to do but, I still have no idea how to intercept these financial movements of the stations. Another detail is that I would like to do this on the server side so that it could be queried by the player via website.

Link to comment
Share on other sites

As far as I can see, trading with stations uses following functions:

"data/scripts/lib/tradingmanager.lua"

line 860 - "TradingManager:buyFromShip(shipIndex, goodName, amount, noDockCheck)"

line 968 - "TradingManager:sellToShip(shipIndex, goodName, amount, noDockCheck)"

line 1054 - "TradingManager:buyGoods(good, amount, otherFactionIndex, monetaryTransactionOnly)"

line 1096 - "TradingManager:sellGoods(good, amount, otherFactionIndex, monetaryTransactionOnly)"

 

In all of them "this object" is always a station.

local stationFaction = Faction()

And "other object" is a ship, that can be player or npc.

local otherFaction = Faction(otherFactionIndex)

 

So you need to check if 'stationFaction' is a player faction:

if stationFaction.isPlayer then ..

 

And then do some stuff

Link to comment
Share on other sites

Can you describe more clearly wich data you want to save?

Is it every trade thats done with a station that you get a trading history? If so you should mod the tradingmanager.lua as Rinart73 mentioned.

Or is it what goods your stations produces and consumes?
Link to comment
Share on other sites

My idea is to have an hourly earnings report for each factory. Thus the player can have control of their winnings and what is interesting to keep active in the game. I may be wrong but, I had the impression that the server does not receive these values at the time of the transactions because I changed the script on the server side to show these values in the log but they appear blank. So maybe I change the plans to a small hub that displays those returns in the period the player is logged describing how much each factory is yielding for x period.

Link to comment
Share on other sites

Another detail is that I would like to do this on the server side so that it could be queried by the player via website.

 

Since you want these information on a website, saving it in sql database may be a good way.

 

Not sure if it is good, its just the first google hit: https://keplerproject.github.io/luasql/manual.html

 

Then you just have to save every trade in the database (Rinart gave good suggestions, ask again if you need more help there) and create a gui, either in lua, webbased or both, to access the data.

 

Link to comment
Share on other sites

Hi,

 

My debt consists of what would be the best way to "intercept" the messages that pass in the economy tab and store them in a simple text file or even a database. The storage I would study the best way to do but, I still have no idea how to intercept these financial movements of the stations. Another detail is that I would like to do this on the server side so that it could be queried by the player via website.

 

the information you want is allready in a file:

 

torsten@debian:~/.avorion$ cat clientlog\ 2018-07-30\ 08-48-38.txt | grep Silizium
2018-07-30 09-07-08| <> (114:-164) Solar Cell Factory M kaufte 2657 Silizium für 2.348.788 Credits.
2018-07-30 09-07-08| (114:-164) Solar Cell Factory M kaufte 2657 Silizium für 2.348.788 Credits.
2018-07-30 10-05-58| <> (114:-164) Transformator Factory S kaufte 845 Silizium für 746.980 Credits.
2018-07-30 10-05-58| (114:-164) Transformator Factory S kaufte 845 Silizium für 746.980 Credits.
2018-07-30 11-00-45| <> (114:-164) Solar Cell Factory M kaufte 2779 Silizium für 2.462.194 Credits.
2018-07-30 11-00-45| (114:-164) Solar Cell Factory M kaufte 2779 Silizium für 2.462.194 Credits.

torsten@debian:~/.avorion$ cat clientlog\ 2018-07-30\ 08-48-38.txt | grep Solarpanels
2018-07-30 08-55-17| <> (114:-164) Solarpanel verkaufte 81 Solarpanels für 650.187 Credits.
2018-07-30 08-55-17| (114:-164) Solarpanel verkaufte 81 Solarpanels für 650.187 Credits.
2018-07-30 09-07-25| <> (114:-164) Solarpanel verkaufte 74 Solarpanels für 594.812 Credits.
2018-07-30 09-07-25| (114:-164) Solarpanel verkaufte 74 Solarpanels für 594.812 Credits.
2018-07-30 09-14-27| <> (114:-164) Solarpanel verkaufte 65 Solarpanels für 523.315 Credits.
2018-07-30 09-14-27| (114:-164) Solarpanel verkaufte 65 Solarpanels für 523.315 Credits.
2018-07-30 09-26-53| <> (114:-164) Solarpanel verkaufte 114 Solarpanels für 909.492 Credits.
2018-07-30 09-26-53| (114:-164) Solarpanel verkaufte 114 Solarpanels für 909.492 Credits.
2018-07-30 09-37-21| <> (114:-164) Solarpanel verkaufte 89 Solarpanels für 713.335 Credits.
2018-07-30 09-37-21| (114:-164) Solarpanel verkaufte 89 Solarpanels für 713.335 Credits.
2018-07-30 09-53-36| <> (114:-164) Solarpanel verkaufte 147 Solarpanels für 1.165.710 Credits.
2018-07-30 09-53-36| (114:-164) Solarpanel verkaufte 147 Solarpanels für 1.165.710 Credits.
2018-07-30 10-00-33| <> (114:-164) Solarpanel verkaufte 63 Solarpanels für 507.402 Credits.
2018-07-30 10-00-33| (114:-164) Solarpanel verkaufte 63 Solarpanels für 507.402 Credits.
2018-07-30 10-07-22| <> (114:-164) Solarpanel verkaufte 62 Solarpanels für 499.410 Credits.
2018-07-30 10-07-22| (114:-164) Solarpanel verkaufte 62 Solarpanels für 499.410 Credits.
2018-07-30 10-19-05| <> (114:-164) Solarpanel verkaufte 75 Solarpanels für 602.700 Credits.
2018-07-30 10-19-05| (114:-164) Solarpanel verkaufte 75 Solarpanels für 602.700 Credits.
2018-07-30 10-27-31| <> (114:-164) Solarpanel verkaufte 76 Solarpanels für 610.660 Credits.
2018-07-30 10-27-31| (114:-164) Solarpanel verkaufte 76 Solarpanels für 610.660 Credits.
2018-07-30 10-33-41| <> (114:-164) Solarpanel verkaufte 56 Solarpanels für 451.584 Credits.
2018-07-30 10-33-41| (114:-164) Solarpanel verkaufte 56 Solarpanels für 451.584 Credits.
2018-07-30 10-34-17| <${good} Factory ${size}> Diese Station hat kein Solarpanels mehr.
2018-07-30 10-34-17| Diese Station hat kein Solarpanels mehr.
2018-07-30 10-34-27| <${good} Factory ${size}> Diese Station hat kein Solarpanels mehr.
2018-07-30 10-34-27| Diese Station hat kein Solarpanels mehr.
2018-07-30 10-34-53| <${good} Factory ${size}> Diese Station hat kein Solarpanels mehr.
2018-07-30 10-34-53| Diese Station hat kein Solarpanels mehr.
2018-07-30 10-48-06| <> (114:-164) Solarpanel verkaufte 120 Solarpanels für 956.400 Credits.
2018-07-30 10-48-06| (114:-164) Solarpanel verkaufte 120 Solarpanels für 956.400 Credits.
2018-07-30 11-05-24| <> (114:-164) Solarpanel verkaufte 137 Solarpanels für 1.088.328 Credits.
2018-07-30 11-05-24| (114:-164) Solarpanel verkaufte 137 Solarpanels für 1.088.328 Credits.
2018-07-30 11-20-20| <> (114:-164) Solarpanel verkaufte 121 Solarpanels für 964.128 Credits.
2018-07-30 11-20-20| (114:-164) Solarpanel verkaufte 121 Solarpanels für 964.128 Credits.
2018-07-30 11-32-12| <> (114:-164) Solarpanel verkaufte 76 Solarpanels für 610.660 Credits.
2018-07-30 11-32-12| (114:-164) Solarpanel verkaufte 76 Solarpanels für 610.660 Credits.
2018-07-30 11-39-13| <> (114:-164) Solarpanel verkaufte 64 Solarpanels für 515.328 Credits.
2018-07-30 11-39-13| (114:-164) Solarpanel verkaufte 64 Solarpanels für 515.328 Credits.
2018-07-30 11-44-36| <> (114:-164) Solarpanel verkaufte 24 Solarpanels für 194.688 Credits.
2018-07-30 11-44-36| (114:-164) Solarpanel verkaufte 24 Solarpanels für 194.688 Credits.
2018-07-30 11-52-45| <> (114:-164) Solarpanel verkaufte 75 Solarpanels für 602.700 Credits.
2018-07-30 11-52-45| (114:-164) Solarpanel verkaufte 75 Solarpanels für 602.700 Credits.
2018-07-30 11-58-09| <> (114:-164) Solarpanel verkaufte 49 Solarpanels für 395.675 Credits.
2018-07-30 11-58-09| (114:-164) Solarpanel verkaufte 49 Solarpanels für 395.675 Credits.

 

All that you need is a Parser for the serverlog, it doesn't need to be lua...

 

EDIT: Clientlog - not Serverlog...

So, you'd just need a Clientside Mod that reads the file(s) and parses its' contents... Wasn't there a findstation-plugin that did reading and parsing sector-files some time ago? Find that plugin and half of your work is done...

Parsing the logs might be a lot of work, you wouldn't want that to slow down your server :)

Link to comment
Share on other sites

All that you need is a Parser for the serverlog, it doesn't need to be lua...

 

EDIT: Clientlog - not Serverlog...

So, you'd just need a Clientside Mod that reads the file(s) and parses its' contents... Wasn't there a findstation-plugin that did reading and parsing sector-files some time ago? Find that plugin and half of your work is done...

Parsing the logs might be a lot of work, you wouldn't want that to slow down your server :)

 

Parsing the client logs is very slow, just as the findstation mod was also very slow. I would prefer to do this via lua scripts and save results in a database wich is much faster and by saving all raw data from scripts you can do much more stuff with it. You could even do it on server side and create an ingame gui to show results.

 

If you want to try that way though you may try on client side:

os.open("clientlog 2018-07-24 20-36-52.txt", r)

 

Replace the date by the latest logfile (not sure how you should get the right name). `os.open("filename", r)` on client side reads the Avorion folder in the userdata, on server side the game folder.

Link to comment
Share on other sites

Parsing the client logs is very slow, just as the findstation mod was also very slow.

It is slow - that's the point... That's why you don't want to do it for a whole server. If somebody uses a Clientside Mod and his/her PC needs a few seconds, that's ok, but you don't want hundreds of players to suffer from high CPU-load on the server.

 

Well, how much data is in one of those clientlogs?

torsten@debian:~/.avorion$ cat clientlog\ 2018-07-30\ 08-48-38.txt | wc -l
2915

Half of that is duplicates, then some weird stuff... And it is filled with data of about 8 hours. That's not too much to use a parser :P

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...