Archive for January, 2006

January 31st 2006

Instant Bot

I was bored, result: Low-byte-count lua-bot, to meet the specs on http://www.we11er.co.uk/ircbots/.

This could be made shorter by removing quite a lot of the whitespace, including, possibly the \rs. It could be made even shorter by shortening the variables names. It could be made faster by nesting the if-end blocks. It could (quickly) be made more flexible by not hardcoding the command and it’s response.

Possibly the easiest way to make it shorter would be to export some of the code to a library (such as perl’s MNet::IRC), which is, imho, cheating.

Etc.

Anyway, the code:

socket=require("socket")
tcp=socket.tcp()
tcp:connect("irc.uwcs.co.uk", 6667)
tcp:send("USER luabot 8 * :Faux's LuaBOT\r\nNICK LuaBOT\r\nPRIVMSG NickServ IDENTIFY password")

while true do
line = tcp:receive()
if line == nil then break end

_,_, pongkey = line:find("^PING(.*)$")
if pongkey ~= nil then tcp:send("PONG" .. pongkey .. "\r\n") end

_,_, code = line:find("^[^ ]+ ([0-9]+) ")
if code == "376" then tcp:send("JOIN #luabot\r\n") end

_,_, channel, args = line:find("^:[^ ]+ [A-Z0-9]+( [^ ]+ ):?!say (.*)$")
if (args ~= nil) then tcp:send("PRIVMSG" .. channel .. ":" .. args .. "\r\n") end
end

Have fun.

No Comments yet »

January 31st 2006

Jjtree, Javacc and Javac.

I created a new branch of Choob today, so we could start work on implementing some form of loopback.

Anyway, Choob’s build script includes calling jjtree and javacc to generate some of the ObjectDB parser. Just for fun, I decided to check if a new version had been released, it turns out one was released on the 2nd of January this year; version 4.0.

I upgraded, and ran it. JJTree runs through fine, but there’s a problem with the files it generates: they all have the path at the top, like:

/* Generated By:JJTree: Do not edit this line. uk\co\uwcs\choob\support\ObjectDBClauseParserTreeConstants.java */

Note the \u in the above fragment of code.. also notice the /* ... */, marking it as a comment.

This \u in a comment is, according to javac, a syntax error, which strikes me as very, very wrong. Some examples:


>sha1sum Test.java
fef20ace9697444325456db03715f4628449ae3c *Test.java

>cat Test.java
// \uwcs

>c:\java\jdk1.6.0\bin\javac.exe Test.java
Test.java:1: illegal unicode escape
// \uwcs
^
1 error

>c:\java\jdk1.5.0_06\bin\javac.exe Test.java
Test.java:1: illegal unicode escape
// \uwcs
^
1 error

>cp Test.java Test.cpp

>echo int main() { return 0; } >> Test.cpp

>sha1sum Test.cpp
cd994f7c35b84acdb882f5ddc738aeadc1511396 *Test.cpp

>gcc -v 2>&1 | grep version
gcc version 3.4.2 (mingw-special)

>gcc Test.cpp

>cl Test.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.

Test.cpp
Microsoft (R) Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.

/out:Test.exe
Test.obj

Both c++ compilers are perfectly happy with this code, neither of Sun’s javac’s are.

Hmm..

Update:

My patch of JavaCC/JJTree 4.0 to make it not break the java compiler on Windows platforms: diff of src/org/javacc/parser/JavaCCGlobals.java, binary (sig).

1 Comment »

January 25th 2006

OpenTTDIRC

I updated my patch for OpenTTD to add a simplistic IRC client today, it now builds fine against r3426, assuming you can add a single c file to your build scripts (I’ve only got it for Visual Studio 2005 (for which there isn’t a project file in svn yet), so no matter what build system/os you’re using it will need updating).

I belive it’s cross platform, although I’m yet to check that as yet.

The current one is written in a MUD-style, with all the channels going into one window. For low-traffic channels this is equally, if not more effective than having multiple windows (especially with the cunning context-logging, so you don’t have to /msg the same channel/person more than once in a row).

Mutliple windows really isn’t practical, as far as I know no pure-IRC clients do non-MDI multi-windowing. A tabstrip could work, it’d also be resonably effective in other areas of OpenTTD (load/scenario/create-game dialog is effectively the same thing anyway, it just has a few different views, etc.), definitely worth looking into at some point.

No Comments yet »

January 23rd 2006

Remote backups.

I was trying today to think of an effective way to securely copy files to another, restricted machine.

The idea of this being that no matter what happens to the source machine, the backups will always still exist (unless something nasty happens to the remote machine, too).

The simple way to do this securely against interception and the source machine having a physical faliure of some kind is to use an ssh-key+scp to copy archives across from a cron job.

This, however, means you have an ssh key lying around on the source machine; it doesn’t even protect the backups against accidental overwriting, let alone intentional.

Firewalling and lack of access on the target machine means that running a server would be challenging, I’m yet to think of a good, safe solution.

No Comments yet »

January 15th 2006

Ministry of Sound: The Annual 2006

Having previewed the new Annual from the Ministry of Sound, and christmas having passed, I thought it was time to go buy it.

Unfortunately, thanks to the Ministry of Sound’s infinite wisdom, the box that looks like this contains completely different cds to the box that looks like this.

Can’t spot the difference? Have a look at the track list, according to DreamUniverse against Amazon’s attempt. Ah.

I was after the version DreamUniverse are selling, for it’s version of Hi Tack – Say Say Say, but I’m not paying for a company I’ve never heard of to ship me a cd that they probably don’t even have a reliable track list for.

Back to ‘sampling’ it is for me, congratulations, Ministry of Sound, you just lost yourself another sale.

No Comments yet »

January 11th 2006

GetWindowLongPtr and friends.

As mentioned in
this bugslayer post, GetWindowLongPtr and SetWindowLongPtr are defined incorrectly when doing 32-bit compiles, meaning that my code is destined to create warnings until a fix is released. #pragma warnings do not count as fixes, sorry.

The warning (or error, if you’re trying to build with treat warnings as errors) you get is:

warning C4244: 'argument' : conversion from 'LONG_PTR' to 'LONG', possible loss of data

No Comments yet »

Next »