Automatically read chat text from Minecraft

In Minecraft, I was hoping to find a way to automatically read chat, as shown below.

minecraft chat screenshot

To write transactions made in the virtual store to the PostgreSQL database. It is preferable to use Python. I do not own a Minecraft server.

My plan is to find a way to directly read the packets sent from the Minecraft server (preferable for reliability, but with unknown difficulty), or as a backup plan, maybe figure out how to escape the text. I found some resources that would allow me to change the font to a monospaced font, which would provide a more reliable way of reading in the font, and I believe that creating perfectly consistent places on the screen for each character. I might encounter something that is close to black, but not quite, but would prefer not to. As shown in the image above, you see that there are many different font colors to compete with too.

Even after decreasing it as described above, I'm still not sure how to turn it into text using python.

Any tips on my approach? Any hints on how I can read packets coming from the server? Any tips on clearing text from my screen?

+6
source share
2 answers

Firstly, as Kuyan suggested, see http://wiki.vg/Main_Page , which has links to various programs that may be useful, either directly or for the source, see.

For example, in the Utilities section, the first thing that appears is a proxy server.

And a little down, there is mc3p , a program proposed by Joran Beasley - a Python proxy with plugin support. It only works until 1.2.5, but sadimusi/mc3p claims to be a 1.4.2 compatible plug. As J.F. Sebastian says, mc3p has an interface for log plugins, so you can just write the one that logs into postgres.

If you want to read the packages yourself, this is not difficult. You can write a generic TCP proxy in dozens of Python lines or write one in 2 shellscript lines around netcat that maps the data to your Python script.

The hard part does not intercept data; he analyzes the protocol. Minecraft probably doesn't send "Nightbane: 1 tnt for $ 100,000 each," but something like "offer: Nightbane: 1: tnt: 100" or "\ x13 \ x09Nightbane \ x00 \ x01 \ x72 \ x00 \ x64 " From what the wiki says, the protocol is documented, but bad and sometimes inaccurate, and the wiki is sometimes wrong too, and the official code is very ugly and hard to read. This means that the best way to understand the protocol is probably to read sadimusi / mc3p or one of the other projects like McPacketSniffer or ProtoProxy, after which you need to ask if it will be easier to just use this project and not to redefine it.

In any case, cleaning the screen should be your last resort.

+2
source

Theres is actually an even better way to read Minecraft chat, and it does not require screen scripting or packet decoding.

Minecraft automatically writes chat messages (and much more) to the log files, in both single and multi-user mode. On Windows, they are located in %appdata%/.minecraft/logs . Previous logs are compressed with gzip, but the log of recent sessions is written to the last.log text file in real time. Chat messages contain the text [Client thread/INFO]: [CHAT] . You can open it in the same way as with a regular file using:

 import os with open(os.getenv("APPDATA")+"/.minecraft/logs/latest.log", "r") as logfile: for line in logfile: if "[Client thread/INFO]: [CHAT]" in line: print line, 

Or, if you want to read the chat in real time, you can use the code below, slightly modified from the code for this:

 import time, os def follow(thefile): thefile.seek(0,2) while True: line = thefile.readline() if not line: time.sleep(0.1) continue yield line if __name__ == "__main__": logfile = open(os.getenv("APPDATA")+"/.minecraft/logs/latest.log", "r") loglines = follow(logfile) for line in loglines: if "[Client thread/INFO]: [CHAT]" in line: print line, 
+1
source

All Articles