The online racing simulator
External ingame chat-window
(4 posts, started )
External ingame chat-window
Hi all!

This is a short post to show you an small InSim program to export all ingame chat messages outside the game. It's simple, connect the program, read the cache file and printf()!

You can see the result in my team's page (bottom page): http://mch.lfsteam.es/forum

You need Pyinsim >= 1.6.3 . This is a simple adaptation from the author's examples.

import sys
import os
import time

VERSION = '1.6.3'
try:
import pyinsim
if not pyinsim.version(VERSION):
raise ImportError
except ImportError:
print 'You must install pyinsim %s or better' % VERSION
sys.exit(1)


HEARTBEAT_INTERVAL = 10
PATH_CACHE = './cache.txt'


insim = pyinsim.InSim()
insim.message_cache = []


def heartbeat(insim):
save_cache(insim)
insim.timer(heartbeat, HEARTBEAT_INTERVAL)


def load_cache(insim):
if not os.path.isfile(PATH_CACHE):
open(PATH_CACHE, 'a').close()

p = open(PATH_CACHE, 'r')
lines = p.readlines()
for line in lines:
if len(line.strip()) > 0:
insim.message_cache.append(line.strip())
p.close()


def save_cache(insim):
lines = insim.message_cache[-100:]
p = open(PATH_CACHE, 'w')
for line in lines:
p.write("%s\n" % line.strip().replace("\r", "").replace("\n", ""))
p.close()


def message_out(insim, mso):
insim.message_cache.append(str(int(time.time())) +";"+ mso.Msg.strip())


if __name__ == '__main__':
try:
insim.bind(pyinsim.ISP_MSO, message_out)
insim.init('localhost', 29999, Admin='admin', IName='logexport', Flags=pyinsim.ISF_MSO_COLS, Interval=500)
insim.timer(load_cache, 1)
insim.timer(heartbeat, HEARTBEAT_INTERVAL)

except pyinsim.InSimError as err:
print 'InSim Error:', err
sys.exit(1)

except:
print 'Unexpected error:', sys.exc_info()[0]
sys.exit(1)

The format of the cache file is a line per message, in the form:
timestamp;message

You can parse it with PHP with something like:


<?php 
$logexport_lines 
file("cache.txt");

foreach (
$logexport_lines as $logexport_line) {
  list(
$timestamp$message) = split(";"$logexport_line2);
  
// do something here
}
?>

In my case, I use phpBB to show the messages, but you can use any system that you like.

Yes, my english is bad... sorry. And yes, I'm bored... I'm looking for ideas to make something more usefull with InSim, any suggestion?
That's pretty cool! Two thumbs up for that.
Nice one.

Only thing is you might want to turn off the ISF_MCI flag to save some resources, as you're not using any MCI packets.
Quote from DarkTimes :Only thing is you might want to turn off the ISF_MCI flag to save some resources, as you're not using any MCI packets.

done

External ingame chat-window
(4 posts, started )
FGED GREDG RDFGDR GSFDG