IRC & Minecraft

From Unallocated Space
Jump to navigation Jump to search

Why build a communication bridge between IRC and Minecraft? Why not.


Running the Minecraft Server

tail -f mcpipe | java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui |& python mc2irc.py


mc2irc.py

import time,sys,os,string

while True:
        tmp=sys.stdin.readline().strip()
        if tmp != "" and "!irc" in tmp and "[CONSOLE]" not in tmp:
                tmp=string.replace(tmp,"!irc","")
                os.system("echo 'From MineCraft: "+tmp[27:]+" (!mc to reply)' > /uas/irc/irc")
        time.sleep(1)

Talking to people inside the Minecraft server through IRC is done using the !mc command on the IRC Bot. Inside Minecraft chat using !irc will send messages to the IRC channel through the bot.

Strangely, the Minecraft server writes most of its data out through stderr and not stdout, hence having to use |&.