The Castle Doctrine Forums

Discuss the massively-multiplayer home defense game.

You are not logged in.

#1 2014-01-25 21:07:27

agentme
Member
Registered: 2014-01-24
Posts: 6

Automatic Robbery Notification feature with source code (Linux)

I found myself leaving Castle Doctrine open all the time, and manually bringing it forward to hit the filter button frequently to check for new tapes of people robbing my place. I decided on automating this. It would be great if I got a notification pop-up whenever my house was robbed.

My first thought was to make a separate program that would check this, however, Castle Doctrine's server requires all communications to include an increasing sequence number, so if I ran my robbery-watcher program at the same time as my client, they would get each other disconnected (which could have fatal effects for me depending on what I was doing in-game). I decided to modify my game to watch my tapes list. Also, it looks like the server code might kill you if you make a request to check your tapes list while you're in a house, so one can only make it check your tapes list automatically while you're already sitting in the menu.

(I'd love it if there was some way to check your tapes list outside of the game without possibly interrupting your client's sequence number -- maybe HTTPS could be used to secure the server communications fully, without relying on a sequence number? -- and without risking booting or killing the player from a house -- the server could just reject giving the tapes list in that case. With these two things, anyone could make a lightweight program that checks their tapes list safely, independently of the game.)

So I modded the client's source code so whenever you're sitting in the tapes or houses list, every 45 seconds in the background it reloads the tapes list, and if there are any new tapes (that are unwatched, and it hasn't already notified for before) it triggers a desktop notification and sets the urgency flag on the window, so the window's icon flashes or is highlighted until you click on it. Now I can leave the game window open behind my other stuff, and I'll get alerted whenever there's new robberies against my house. (If you minimize the window, it goes into sleep mode, so it won't alert when like that.) Note that this is Linux only since I used libnotify and X11 stuff, but it wouldn't be hard too adapt for other platforms (CastleDoctrine's notify.cpp and minorGem's ScreenGL_SDL.cpp's setWindowUrgency() parts are what would need to be extended).

M4BlIEP.png
(The pop-up notification is at the top right. Also, if you look closely at the bottom of the taskbar on the left, you can see that CastleDoctrine's icon, the lowest [?] box, is lit up waiting for me to click on it.)

The modified Castle Doctrine source code is on sourceforge, and it relies on some modifications in my fork of minorGems too. To compile, checkout both of these in the same directory, make sure minorGem's directory is just named "minorGems", go into CastleDoctrine's directory, read build/source/HowToConnectToMainServer.txt, run ./configure, and then run make inside of gameSource/. Make sure you have the usual stuff needed for compiling CastleDoctrine, and then you also need the libnotify-dev package.

Nothing at all is changed in online play; it fully works with the main server fine. Note that the text files in the recordedGames/ directory made by this version can't be played by the official version of CastleDoctrine, though I made sure that the reverse works.

Last edited by agentme (2014-01-25 23:42:41)

Offline

#2 2014-01-25 21:18:33

jasonrohrer
Administrator
Registered: 2013-04-01
Posts: 1,235

Re: Automatic Robbery Notification feature with source code (Linux)

Cool stuff!  I do worry about extra server load if everyone was doing this, though...

Currently, when you're active in the game (like robbing or editing), the game only talks to the server once every 4 minutes.

I imagine that any humans "checking" their tape list while doing something else tend to do it less frequently than every 45 seconds.  They probably forget, and many minutes end up passing in between checks.


At at least one point today, we had 25 simultaneous MySQL queries in parallel, which swamped the server and cut a bunch of people off.  I've upped the limit to 100... but 25 is a lot!

Offline

#3 2014-01-25 22:21:31

agentme
Member
Registered: 2014-01-24
Posts: 6

Re: Automatic Robbery Notification feature with source code (Linux)

Yeah, I could see this being a bit much if everyone did it as it is now. I don't think pushing this as-is into the mainline would be great, but I'd hope it could maybe inspire future features and help out other tinkerers too.

Is your server able to have memcached (or redis) installed on it? I think I'll go through the server source code and add some caching so that many requests to read data don't ever have to hit MySQL. It helps a ton in my experience.

Last edited by agentme (2014-01-25 23:02:43)

Offline

Board footer

Powered by FluxBB 1.5.8