Implementation details:
If client is executed with "-p FILE" switch, current player position relative to the centre of tile_0_0 will be written roughly every 500ms to the specified memory mapped file (it will be automatically created by the client). The position is written as two 32-bit signed integers representing the relative xy coordinates.
Client uses
exclusive file lock for writing therefore consumers should handle locking on their end as well.
Note that the file is not deleted when client terminates so if mapping app is started before the client it will need to handle possible case of old coordinates.
Also, the file shouldn't be opened with DELETE_ON_CLOSE or similar options since it has different and sometimes undefined behaviour on different OSes.
Java snipped on how to utilize this:
- Code: Select all
File f = new File("/home/rom/projects/amber/build/playercoord");
FileChannel channel = FileChannel.open(f.toPath(), StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE);
MappedByteBuffer map = channel.map(FileChannel.MapMode.READ_ONLY, 0, 8);
IntBuffer buf = map.asIntBuffer();
while (true) {
Thread.sleep(500);
FileLock lock = channel.lock(0, 8, false);
buf.position(0);
int x = buf.get();
int y = buf.get();
System.out.println(x + "x" + y);
lock.release();
}