Member of the EVE Tweet Fleet
Oct 01

IRC Bots and Message Queues

By Xeross Posted in Developing, Tech Leave a Comment

As I have recently once again become frustrated by how my IRC bot evolved into a horrible mess of code and I have decided on yet another rewrite after seeing how hook.io (Written in NodeJS) handles IRC bots I decided to take a look at implementing something similar.

I recalled that I experimented with message queues before with various pieces of other software and that a message queue might just provide the functionality that’s similar to hook.io that I wanted.

So after some researching I decided to settle on RabbitMQ, it’s fast, simple to set-up and has a nice status/admin plugin that is helpful both during development and a live environment.

I also decided to use Gevent for this rewrite rather than Twisted which I’ve always used for my previous bots. Sure asynchronous code can be written clearly, but the clarity and ease-of-use of blocking/synchronous code is just way better in my opinion. And with Gevent I can write synchronous code (And use blocking libraries) and it’ll make them async in the background (Thanks to how Python generators work).

The basic functionality version of the new bot is finished, I currently have a few node types (Processes with a certain task) implemented:

  • A proxy: this just connects to an IRC server, registers and pushes any packets onto the message queue (And listens for packets to send too), so now rebooting the bot won’t make it close all connections.
  • A client: does the actual IRC interaction and hands the proxy packets to send to the server.
  • A logger: simply outputs all messages sent between the nodes
  • A command line interface: a simple command line application that implements some basic IRC commands (PRIVMSG, JOIN, PART) to send to the client manually

It’s all very basic, the proxy and client need to be changed so that they manage multiple IRC servers, a management node will be implemented that will orchestrate everything and plugins, etc. will also be their own nodes.

Some might say this is over-engineering, I’d call it flexibility and reliability. It does what I want and it does it in a clean effective fashion. Not to forget I learn more about using message queues which seem to be gaining popularity lately.

This is still long from being a working functional IRC bot but I already feel like I am making a cleaner and more organized start, and hopefully this will be the first one that actually runs in production fairly smoothly.

~Xeross

Tagged with:
Sep 16

Schemaverse: A space-based strategy game played in a PostgreSQL database

By Xeross Posted in Gaming, Tech Leave a Comment

What is Schemaverse?

Schemaverse is a space-based strategy game (SPAECSHIPZ!!) that runs completely in a PostgreSQL database. So when you create an account it gets created on the PostgreSQL server and you connect to that server to play.

Currently the actual gameplay is (in my opinion) quite limited, but still interesting enough and it gives you a chance to improve your SQL skills.

Tics

Schemaverse’s universe works on tics, each tic is roughly 60 seconds long and every tick the following things happen:

  • Every ship moves based on the ships direction, speed and destination coordinates.
  • All fleets run their fleetscript#() function if they have it enabled and have a runtime of at least 1 minute.
  • Mining happens for all ships who ran the mine() command this tic.
  • Some planets randomly have their fuel increased.
  • Any damage/repair that occurred during the tic is committed to the ship table.
  • Any ships that have been reduced to 0 health for the same amount of tics as the EXPLODED variable (currently 60 tics or approximately 1 hour) are set to destroyed.

Scripting

What makes this game (even more) interesting is that it actually allows and encourages you to write AI for fleets using PL/pgSQL code.

This allows you to for example write a script that automatically creates new ships, upgrades their mining capability and assigns them to a planet, repeating this every tick.

Open-source

Yep, Schemaverse is open source, and the entire source code is available on GitHub.

Security

Of course when you are running an entire game in an SQL server there’s the tricky task of preventing SQL injection.

A previous exploit for example was that you could execute any SQL query as a privileged user by injecting the SQL into the ship name, and then triggering a notification to be generated for that ship. Finding new exploits is encouraged, as there’s a trophy for SQL injections that you can only get by using such an exploit to add it to your list of trophies.

Okay where do I start?

You start by creating an account on schemaverse.com and then you can either use the basic webinterface to get you started, or you can use the command line PostgreSQL client and/or your favourite PostgreSQL utility (Navicat, etc.)

For more info on how to play currently the most up-to-date and complete guide is this PDF next to that there’s also the Schemaverse Wiki on GitHub.

NOTE: One small correction with regards to above guides, the event query should use READ_EVENT(id) not READ_EVENT(event_id).

Tagged with:
Aug 27

Bug Analysis

By Xeross Posted in Developing, Tech Leave a Comment

Recently there was a problem with a website that is still in development (That will remain unnamed). For some reason, when you logged in on the admin, everything worked, but when you refreshed the page the tabs that were loaded through ajax would somehow have you logged out (And another refresh after that you were completely logged out).

Someone else had already been trying to figure out this problem for more than a day and was breaking his head over it. Nowhere did the session get destroyed in the admin, or during the ajax requests, and the only location were it got destroyed was in the logout call and on the website when you tried to access a page that doesn’t exist.

I decided to take a look at it, with a mentality of, anything can happen, even if it doesn’t make sense. So first thing I tried was commenting out the session_destroy call in the index, which indeed seemed to resolve the problem.

But the index should never be loaded in the first place. So time to fire-up firebug and let it log all requests made by a single admin page load.

For some reason the admin was indeed loading the website for some odd reason. Now to my surprise as someone suggested, Internet Explorer (Yes you are reading that right) shows where the request originated. Turned out it was being requested through a <script> tag somehow. Coincidentally it seemed that that same script was also erroring.

So after commenting that out (And having the session_destroy enabled again) I tested it again, and yep you remained logged in. Now of course still not satisfied, I had to figure out why it was loading the front-page.

So opening the script there was nothing in there that did even attempt to make a request, so it couldn’t be in the script (This was an exception to the everything is possible rule because this really was too impossible). So then I tried opening the script in the browser, and hey I was redirected to the frontpage.

Okay, I’m getting redirected, but why. Ah yes perhaps the .htaccess will tell me. Upon opening the .htaccess file I found out that it would redirect requests to any folder or file that didn’t exist to the frontpage (With the path of the file as page to request).

So after disabling this rewrite rule the file did indeed not exist, for some reason it got deleted on the dev server. So upon re-upload it worked again. After this to prevent this in the future I also added an exception for js/css files into the htaccess so that those missing would be easier to detect.

Of course I could’ve made more rigorous changes to the project to make this problem impossible to happen, but I was asked to help debug and the way it was built was decided by a team that probably had reasons for why they did it the way they did it (I made suggestions and they’d discuss them).

Conclusion

  1. Go in with an ‘anything can happen’ mentality, even if it seems impossible it might just not be
  2. If you’ve been trying to figure out a bug for quite some time, ask someone else to take a look, he/she might have a different viewpoint that’ll help solve the issue
  3. Internet Explorer can actually be useful
  4. Why the fuck didn’t other browsers implement the request origin feature (Or why did they make them hard to find I might have overlooked them).

it was a fun challenge to solve this bug, and it made me learn a good deal about solving issues that you wouldn’t get if you were always working on projects you are the sole developer of.

~Xeross

Tagged with:
Aug 23

Customized Zenburn Palette For gnome-terminal

By Xeross Posted in Linux, Tech Leave a Comment

I’ve recently switched to using Zenburn for Vim, and I like it a lot. Though I also wanted my terminal to match, so after some searching I found this palette setting for gnome-terminal.

However the colours didn’t match with the original colours, for example what used to be green ended up being the same colour as regular text.

So I’ve made some modifications and you can use the following palette setting to get a more ‘compatible’ Zenburn palette.

#3F3F3F3F3F3F:#CCCC93939393:#7F7F9F9F7F7F:#E3E3CECEABAB:#DFDFAFAF8F8F:#CCCC93939393:#8C8CD0D0D3D3:#DCDCDCDCCCCC:#3F3F3F3F3F3F:#CCCC93939393:#7F7F9F9F7F7F:#E3E3CECEABAB:#DFDFAFAF8F8F:#CCCC93939393:#8C8CD0D0D3D3:#DCDCDCDCCCCC

To apply it follow the instructions from the thread (Mirrored below in the case the link goes dead).

  1. Make sure that your menu bar is showing. If it is not, right click on the terminal window and select “Show menubar”.
  2. In the Edit menu, select “Profiles…”
  3. Create a new profile with whatever name you like.
  4. In your terminal, start the program “gconf-editor”.
  5. Navigate to “/apps/gnome-terminal/profiles/” and then to whatever you called the profile. If it does not show up with name, it might be called something like “Profile0″. If the latter is the case for you, check the “visible_name” property, which should match your chosen name.
  6. Double click on the “palette” property.
  7. Remove the current contents, and paste the above color palette string
  8. Close everything related to gconf-editor.
  9. Switch to the profile you selected via the Terminal’s Edit menu, and (if you want) change it to the default profile in Edit -> “Profiles…”.

Colour Preview

Tagged with:
Aug 22

Download.com now installing bloatware on a PC near you

By Xeross Posted in News, Tech Comments (2)

It seems that download.com has decided to start making all their downloads use their own installer, which seems to come with an optional toolbar that gets installed by default, and optional homepage/search changes (Also set by default), unless you, of course uncheck them.

Why are they doing this you might wonder. Well according to their FAQ they are doing it to: “ensure a safe and improved download experience by making it easier for Download.com users to complete downloads and launch the software’s installer”. I don’t see how this would make this easier, the installers shipped with the software are usually just fine. And by the looks of it they are wrapping the actual installer, so you’ll have an installer that installs an installer that installs your software, yep brilliant.

Also, it seems that if you as a developer don’t want CNET to wrap your installer you have to get a premium subscription: “Yes. If you would like to opt out of the CNET Download.com Installer you can sign up for a Premium subscription or PPD promotion, both of which are being excluded at this time”. Which boils down to “We make a shitty wrapper around your software and if you don’t like it you can pay us to remove it”.

I’ve used download.com in the past, but with these kinds of shenanigans I highly doubt I’d want to use their service ever again, let’s hope they realize their mistake before everyone turns their back to them.

Further reading:

~Xeross

Tagged with:
Aug 20

How to turn GitHub into /b/ in 1 easy step

By Xeross Posted in Tech Leave a Comment

Just make a commit like this https://github.com/MrMEEE/bumblebee/commit/a047be85247755cdbe0acce6f1dafc8beb84f2ac#comments

Now it only happens on Ubuntu so at least it’s not that big of a problem.

~Xeross

Tagged with:
Aug 18

Framework Selection Madness

By Xeross Posted in Developing, Tech Comments (10)

We’re currently researching what framework to use for our new project at work. After having crossed a few of the list (CodeIgniter had some odd behaviour and all kinds of artifacts from PHP4 days, and FeulPHP is too new to use in a serious project), we are left with Kohana (Which was a CI derivative but 3.0 was a full rewrite), and Django (One of the most used web frameworks for Python).

Unfortunately after just barely scratching the surface of Kohana it became apparent that the lack of documentation will be a problem. Sure we can figure out stuff ourselves but that’s wasted time, and has no advantages over a well documented system.

Now there’s Django which I am really fond of, but as is understandable there is some hesitance to use a new language, which comes with all kinds of stuff that behave differently than PHP.

In my eyes Kohana is a no-go due to this lack of documentation, especially compared to how easy the same thing was in Django (While writing one of my own projects). There’s already been made use of Symfony so we might end up using that. So it’s back to research again, with new contestants.

~Xeross

Tagged with:
Aug 17

Blogging Clients

By Xeross Posted in Tech Comments (4)

So I’ve been recently trying out and searching for blogging clients, rather than the built-in editor that comes with WordPress.

Why? Well, to lower the barrier of entry when I want to write a blog post. rather than having to browse to my blog, login and click “New post” I can just simply hit a button and start writing.

This is currently being written from a Firefox plugin called ScribeFire, it’s a nice idea, having a blogging client in your browser while still being able to have the reference data you’re writing about right above your writing area (And you can still tab around).

I’ll probably try some other alternatives too, but this client is pretty nice. Only downside is that it doesn’t work particularly well with my dark Firefox theme.

~Xeross

P.S.: What a shame, seems it doesn’t do a hierarchical category listing, kind of a shame considering the amount of categories I have. Ah well it’s manageable.

Update: Oh, seems a newer version was released than I was using, definately looks prettier. Yet still no hierarchical categories. Ah well, still nice.

Tagged with:
Aug 08

Prepare for the worst, but don’t assume the worst

By Xeross Posted in SysAdmin, Tech Comments (4)

As I posted yesterday it seemed that one of the disks in the server died, so I immediately decided to first make back-ups. Well that finally finished today.

So after shutting the server down I decided to first check all the cables, push them in further where possible, in case it might have just been a loose cable.

So after doing that, and booting into the setup screen I checked the list of disks it detected. And presto it showed up. So now the following is running on the server:

Personalities : [raid1] [raid0]
md1 : active raid1 sda4[0] sdb4[1]
      19431356 blocks super 1.1 [2/1] [_U]
        resync=DELAYED
      bitmap: 1/1 pages [4KB], 65536KB chunk

md2 : active raid0 sda2[0] sdb2[1]
      3899392 blocks super 1.1 512k chunks

md0 : active raid1 sda1[0] sdb1[1]
      102388 blocks super 1.0 [2/1] [_U]
        resync=DELAYED

md3 : active raid1 sda3[1] sdb3[2]
      955271935 blocks super 1.2 [2/1] [U_]
      [=============>.......] recovery = 69.5%
      (664634304/955271935) finish=43.2min speed=112045K/sec

unused devices: <none>

So it turns out my assessment was wrong, I immediately assumed the worst, while it was just a loose cable.

Well at least it made it so there’s full back-ups of all virtual machines again (Well recent ones).

So basically. Be sure to prepare for the worst, but don’t assume the worst when shit hits the fan.

~Xeross

Tagged with:
Aug 07

Dead HDD

By Xeross Posted in SysAdmin, Tech Leave a Comment

I woke up this morning (Well actually afternoon but meh), and powered up my desktop. Only to see that my server cluster was down.

So I headed down, to see what happened, seems that it had crashed, seems to have been a kernel panic. However I also saw quite a few disk errors.

So after doing a `cat /proc/mdstat` I was greeted by the following:

[root@MasterChief xeross]# cat /proc/mdstat
Personalities : [raid1] [raid0]
md1 : active raid1 sda4[1]
19431356 blocks super 1.1 [2/1] [_U]
bitmap: 1/1 pages [4KB], 65536KB chunk

md2 : inactive sda2[1]
1949696 blocks super 1.1

md0 : active raid1 sda1[1]
102388 blocks super 1.0 [2/1] [_U]

md3 : active raid1 sda3[2]
955271935 blocks super 1.2 [2/1] [U_]

 

Seems one of my disks died, I’m currently running full back-ups of all VMs in case the 2nd one decides to give up too.

Luckily the disk still has warranty, so I’m going to swap it for a new one, and hopefully get everything mirrored again soon.

In the meantime I’ll just run part of the cluster so I can at least continue developing.

~Xeross

Tagged with: