March 28, 2017, 01:09:32 AM

Author Topic: Gnomoria Web Server  (Read 11122 times)

Rychard

  • Newbie
  • *
  • Posts: 25
    • View Profile
Gnomoria Web Server
« on: July 26, 2015, 01:20:13 AM »
After noticing that almost all of the utilities for Gnomoria required the user to exit the game before being able to utilize them, I decided that we needed a better way to do real-time communication between Gnomoria and external processes.

Because I recently worked on a mod for Cities: Skylines to do precisely that, I decided to simply repurpose a lot of the existing code to do a similar thing for Gnomoria.

After spending the better half of this weekend to produce a workable version, I wanted to join this community here and show it off.

This is a modification for Gnomoria (I've only verified its compatibility with the latest in-dev branch) that allows it to expose real-time data to external processes over a standard HTTP connection, and even consume information in the opposite direction.  The underlying framework is pluggable and the entire thing is open-source and on Github.  The write-up on the Github repository is substantially more involved, so I would encourage any interested parties to take a peek and let me know what they think.

https://github.com/Rychard/GnomeServer

Beta-Release: https://github.com/Rychard/GnomeServer/releases/tag/v0.0.1

Any and all feedback is appreciated.  :)



Here's some examples of things that I've created using this mod:

http://localhost:8081/Gnome
Retrieves a JSON representation of all your Gnomes.  Includes loads of information not currently exposed by the in-game interface.  The intent is for the server to expose a normal website, which would simply be a JavaScript application that would consume this information behind the scenes and present it in a user-friendly manner.

http://localhost:8081/Gnome/Add
Spawns a single Gnomad just as the game does.  Additionally, they are automatically assigned the most appropriate profession according to their skills.  This process is entirely dynamic and assigns professions based on how you've configured them in-game.  Also returns the JSON representation of the Gnome that was created for further consumption.


http://localhost:8081/Gnome/Assign
Automatically re-assigns your Gnomes to the most appropriate profession according to their current skill levels.

http://localhost:8081/Military/Assign
Automatically assigns your gnomes to existing Squads.  If all existing Squads are full, new Squads are created and filled until all Gnomes have been assigned a Squad.

http://localhost:8081/Game?speed=20
Changes the current speed of the game.  The parameter given for speed becomes the multiplier.  Currently, the in-game UI only supports Pause, 1x and 2x speeds, but while developing this mod, I routinely play at 20x to produce various scenarios for testing purposes.


To help put this into perspective, here's some images that showcase what I and rest of the modding community for Cities: Skylines were able to achieve with this approach:

Screenshot of the original version: http://i.imgur.com/fFkWVjw.png
A fork of the original project: https://github.com/Feanathiel/CityWebServer

This is exactly the type of thing that would allow the Gnomoria community to create the same type of extensions that are available for Dwarf Fortress: external utilities that run alongside the game that allow you to exercise substantially more control over the world.  I hope you guys are as excited about this as I am.
« Last Edit: August 02, 2015, 08:52:03 AM by Rychard »

lordkatana

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Re: Gnomoria Web Server
« Reply #1 on: July 26, 2015, 03:06:13 AM »
Don't know much about software writing, but i know this.... Awesome!!!! Would make editors a whole lot easier, and just having access to information for debugging purposes is great! We want more!  :P

Merry76

  • Moderator
  • Hero Member
  • *****
  • Posts: 3444
    • View Profile
Re: Gnomoria Web Server
« Reply #2 on: July 26, 2015, 03:07:15 AM »
This looks pretty dedicated... I guess you could use it to drag some extra information from combat and other systems you want to fine tune via the modding interface.

Rebalancing combat would be an awful time intense task without a tool like that.
Have a problem or a fortress so awesome it needs to be shared?

Well, go on, dont be shy! Use the GnomeworldPool Dropbox account!
How to share Savegames

dimion

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Gnomoria Web Server
« Reply #3 on: July 27, 2015, 03:35:52 AM »
Would love to try it. However, I don't know how to compile the files. Would it be possible to supply a link to the compiled version?

Roest

  • Jr. Member
  • **
  • Posts: 84
    • View Profile
Re: Gnomoria Web Server
« Reply #4 on: July 27, 2015, 09:16:04 AM »
Hmm, solution compiled, linqpad script runs successfully. However it just copies the Gnomoria.exe and the GnomoriaInjection.dll to Desktop but doesn't write the GnomoriaInjected.exe. 

Rychard

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Gnomoria Web Server
« Reply #5 on: July 27, 2015, 09:24:18 AM »
Seems there's a bug in the Linqpad script that's outputting the assembly to the wrong folder.

Check in your User folder ( e.g. C:\Users\YourName\ ), that's where it's outputting for me now, though I'm not sure how I could have overlooked this originally.

I'll push a fix for that at some point today.

Edit: I've just fixed the issue.  The script should now display the full path to the modified assembly.  Thanks again for reporting this.
« Last Edit: July 27, 2015, 09:33:01 AM by Rychard »

Roest

  • Jr. Member
  • **
  • Posts: 84
    • View Profile
Re: Gnomoria Web Server
« Reply #6 on: July 27, 2015, 09:38:35 AM »
Ok found the exe, the webserver runs, however it returns empty results.

Quote
No resource is available at the specified filepath: C:\Users\Ralph\Documents\My Games\Gnomoria\wwwroot\GnomeController

This is correct, that folder doesn't exist. Maybe it failed because my system language is german?

Rychard

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Gnomoria Web Server
« Reply #7 on: July 27, 2015, 09:40:29 AM »
Would love to try it. However, I don't know how to compile the files. Would it be possible to supply a link to the compiled version?

Unfortunately, this requires a modification to the Gnomoria.exe.  As a result, even if I provided the compiled binaries for the code you'd still need to patch Gnomoria.exe on your own.

At some point in the future I'll move the patching code into an executable itself so that the patching of the executable can be performed automatically. 

Ok found the exe, the webserver runs, however it returns empty results.

Quote
No resource is available at the specified filepath: C:\Users\Ralph\Documents\My Games\Gnomoria\wwwroot\GnomeController

This is correct, that folder doesn't exist. Maybe it failed because my system language is german?

The web server attempts to determine how to service each request.

For some reason, it seems to not correctly detect the endpoints that are present on the GnomeController class.

As you mentioned your system language is German, it's likely that I'm not performing a culture-independent string comparison somewhere along the line.  If you're interested in looking into it, I'd suggest checking out the code for the ConventionRoutingController class.  If not, that's fine too; I'll take a peek tonight after work.

Edit: Also, that path mentioned in the error is used to serve up static content (html, js, css files).  It's useful if you want to build a website that will be hosted by the game, but as currently a default website doesn't exist, the game relies exclusively on the controllers in the code to service requests.
« Last Edit: July 27, 2015, 09:47:59 AM by Rychard »

Roest

  • Jr. Member
  • **
  • Posts: 84
    • View Profile
Re: Gnomoria Web Server
« Reply #8 on: July 27, 2015, 10:01:46 AM »
I'll see what I can do. C# is just not my usual language of choice so it's all trial and error.

Another thing, I use the game.ini in the Gnomoria directory to redirect the location of my save files. However the GnomeServer.json and GnomeServer.log are created in C:\users\name\documents\my games\Gnomoria.

Rychard

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Gnomoria Web Server
« Reply #9 on: July 27, 2015, 10:06:36 AM »
I'll see what I can do. C# is just not my usual language of choice so it's all trial and error.

Don't worry too much about it; if you can't find the cause of the error, I'll find it eventually.  If you need to output log messages for debugging or anything, you can use the OnLogMessage(string) method for this purpose.

Another thing, I use the game.ini in the Gnomoria directory to redirect the location of my save files. However the GnomeServer.json and GnomeServer.log are created in C:\users\name\documents\my games\Gnomoria.

In the README on github, I mentioned this, but I never actually got around to creating an issue for it.

At any rate, I agree with you that I need to fix this.

Edit: I've just made a commit that should allow the mod to use the configured folder for the configuration/log files.

https://github.com/Rychard/GnomeServer/issues/4
« Last Edit: July 27, 2015, 10:05:26 PM by Rychard »

Roest

  • Jr. Member
  • **
  • Posts: 84
    • View Profile
Re: Gnomoria Web Server
« Reply #10 on: July 28, 2015, 08:56:12 AM »
game.ini save path works now, though I still get the same error .

Another thing, your build/install instructions on github seem to be targeted at programmers and the like but they could still use some clarification.

1. that's cool and interesting info but what you need to say is, create a new directory "Assemblies" in the root folder of the repository and copy the following files to it ...

2. building the solution should work out of the box, though if it's set to build for any cpu (vs2013 ultimate) i get some strange warnings about processor architecture
mismatch, maybe just set it to x86 per default. I just work with C++ so don't know anything about C# and if we can ever expect a x64 version here but for now that
should avoid confusion

3. As far as I can see there is only one path to set in the linq file. So saying "Once the paths are configured properly in the injection script," is confusing. Also it should
say where to set it to. It seems to be the Gnomoria dir in your steam folder. Funny, mine is in the same location. If I set it to the output folder of the solution it produces
an error that it can't verify the gnomorialib version. So I have to copy that output to the steam folder before I can run the the inject.linq.

4. Obviously here we only need to copy the injected exe. Why not place it directly into the Gnomoria folder?
« Last Edit: July 28, 2015, 11:18:46 AM by Roest »

Rychard

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Gnomoria Web Server
« Reply #11 on: July 28, 2015, 08:15:15 PM »
game.ini save path works now, though I still get the same error .

Another thing, your build/install instructions on github seem to be targeted at programmers and the like but they could still use some clarification.

1. that's cool and interesting info but what you need to say is, create a new directory "Assemblies" in the root folder of the repository and copy the following files to it ...

2. building the solution should work out of the box, though if it's set to build for any cpu (vs2013 ultimate) i get some strange warnings about processor architecture
mismatch, maybe just set it to x86 per default. I just work with C++ so don't know anything about C# and if we can ever expect a x64 version here but for now that
should avoid confusion

3. As far as I can see there is only one path to set in the linq file. So saying "Once the paths are configured properly in the injection script," is confusing. Also it should
say where to set it to. It seems to be the Gnomoria dir in your steam folder. Funny, mine is in the same location. If I set it to the output folder of the solution it produces
an error that it can't verify the gnomorialib version. So I have to copy that output to the steam folder before I can run the the inject.linq.

4. Obviously here we only need to copy the injected exe. Why not place it directly into the Gnomoria folder?

You're right; it seems there were some inaccuracies in the installation instructions.

I believe everything you mentioned is now resolved in the latest commit: https://github.com/Rychard/GnomeServer/commit/31bc05bb6fde35f56f584e9e870d7d2ce0983a10

Rychard

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Gnomoria Web Server
« Reply #12 on: July 31, 2015, 06:10:55 PM »
Just wanted to pop in and give a bit of a status update.

First of all, yes, this mod remains compatible with the latest update to the in-dev branch (RC31)

Secondly, I've been working on the web application that will process the data that the server spits out, and present it in a neat and orderly fashion.

Truth be told, there's still a lot left to do, but at least now there's a visual indication of progress.  :)

If any of you have any experience with RequireJS, Knockout, Durandal (or more generally, TypeScript/JavaScript) and more importantly, are interested, take a look at the code on Github and send me a pull-request!

Here's a link to the branch on Github where I'm working on this: https://github.com/Rychard/GnomeServer/tree/GnomeApp

In the meantime, here's a screenshot:


Roest

  • Jr. Member
  • **
  • Posts: 84
    • View Profile
Re: Gnomoria Web Server
« Reply #13 on: August 01, 2015, 03:16:59 AM »
Looks cool, but still isn't working for me :(

So I tried to install it on my laptop that has an english win7.  It compiles just fine but now when I run the linq file I get
the error. Failed to resolve assembly: 'gnomorialib, Version 0.9.18.0, Culture=neutral, PublicKeyToken=null'

On my desktop machine I got that error when I tried to run the linq on the bin dir in the solution folder. That was solved by copying
everything to the Gnomoria dir and run it there. So no clue why it doesn't work here.

Rychard

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Gnomoria Web Server
« Reply #14 on: August 01, 2015, 06:16:45 AM »
Looks cool, but still isn't working for me :(

So I tried to install it on my laptop that has an english win7.  It compiles just fine but now when I run the linq file I get
the error. Failed to resolve assembly: 'gnomorialib, Version 0.9.18.0, Culture=neutral, PublicKeyToken=null'

On my desktop machine I got that error when I tried to run the linq on the bin dir in the solution folder. That was solved by copying
everything to the Gnomoria dir and run it there. So no clue why it doesn't work here.

That error you mentioned from the linqpad script indicates that it can't find the gnomorialib.dll file.

The linqpad script can be ran from anywhere, the path just needs to be set to the gnomoria installation path.

I pushed an update to the Linqpad script here: https://github.com/Rychard/GnomeServer/blob/GnomeApp/Injector/inject.linq, and it may output some useful information.