def startWebserver(self, event, command): if config.getboolean("main", "productive") and not event.isByOp(): return if not config.getboolean("webserver", "enable") or not self.webserverthread is None: return LOG.debug("starting webserver ...") self.webserverthread = WebserverThread(self.client) self.webserverthread.start() Broadcast("webserver started on port %d"% self.webserverthread.port, parentclient=self.client, parent=event)
def startWebserver(self, event, command): if config.getboolean("main", "productive") and not event.isByOp(): return if not config.getboolean("webserver", "enable") or not self.webserverthread is None: return LOG.debug("starting webserver ...") self.webserverthread = WebserverThread(self.client) self.webserverthread.start() Broadcast("webserver started on port %d" % self.webserverthread.port, parentclient=self.client, parent=event)
def stopWebserver(self, event, command): if self.webserverthread is None or (config.getboolean("main", "productive") and not event.isByOp()): return LOG.debug("stopping webserver ...") self.webserverthread.stop() self.webserverthread = None Broadcast("webserver stopped", parentclient=self.client, parent=event)
def savestatstofile(filename="serverstats.bin", servers=[]): if not config.getboolean("serverstats", "savehistory"): return t = time.time() try: try: import cPickle as pickle except: import pickle except ImportError: LOG.error("error while loading the pickle module...") return try: f = open(filename, 'rb') oldstats = pickle.load(f) f.close() except IOError: oldstats = {} oldstats[t] = servers try: f = open(filename, 'wb') pickle.dump(oldstats, f) f.close() except IoError: LOG.error("error while saving history file!")
def clearStats(self): if not config.getboolean('stats', 'enable'): return fn = config.get("stats", "cachefilename") try: os.remove(fn) LOG.debug("stats cleared") except: pass
def stopWebserver(self, event, command): if self.webserverthread is None or (config.getboolean( "main", "productive") and not event.isByOp()): return LOG.debug("stopping webserver ...") self.webserverthread.stop() self.webserverthread = None Broadcast("webserver stopped", parentclient=self.client, parent=event)
def init(self): self.updateConfig() self.doTimeWarning = config.getboolean('timewarning', 'warnings') self.last_timewarning = 0 self.readTimeFile() self.interval = config.getint('timewarning', 'warning_interval') self.registerCallback("on_mainloop", self.onMainLoop) self.registerChatCommand("timeleft", self.timeLeft) self.registerChatCommand("uptime", self.upTime)
def init(self): LOG.debug("PlayerInfoPlugin started") self.updateConfig() self.enabled = config.getboolean('playerinfos', 'enable') self.idletime = config.getint ('playerinfos', 'idletime') self.registerCallback("on_receive_command", self.commandReceived) self.registerCallback("on_mainloop", self.onMainLoop) self.registerChatCommand("stopinfo", self.stopInfo) self.registerChatCommand("idleinfo", self.idleInfo)
def rconCommand(self, event, commandstr): if not config.getboolean("rcon", "enable"): return argv = commandstr.split() if event.isByOp() and len(config.get("rcon", "password")) > 0: msg = commandstr[len(argv[0]) + 1:] password = config.get("rcon", "password") elif len(argv) < 3: event.respond("Usage: rcon <password> <msg>") return else: msg = commandstr[len(argv[0]) + len(argv[1]) + 1:] password = argv[1] self.lastevent = event payload = openttd.structz.pack('zz', password, msg) self.client.sendMsg_TCP(const.PACKET_CLIENT_RCON, payload)
def savetofile(self, filename): """ Save the grf database from a file @type filename: string @param filename: the filename to save to """ if not self.canSaveLoad or not self.listchanged or not config.getboolean("serverstats", "savenewgrfs"): return import pickle try: f = open(filename, 'wb') pickle.dump(self.__database, f, 1) f.close() except IOError: LOG.error("error while saving newgrf cache file!")
def savetofile(self, filename): """ Save the grf database from a file @type filename: string @param filename: the filename to save to """ if not self.canSaveLoad or not self.listchanged or not config.getboolean( "serverstats", "savenewgrfs"): return import pickle try: f = open(filename, 'wb') pickle.dump(self.__database, f, 1) f.close() except IOError: LOG.error("error while saving newgrf cache file!")
def updateStats(self): self.last = time.time() if not config.getboolean('stats', 'enable'): return LOG.debug("updating stats...") tstart = time.time() fn = config.get("stats", "cachefilename") obj = [] firstSave = False try: f = open(fn, 'rb') obj = pickle.load(f) f.close() except IOError: firstSave = True value = [ self.client.getGameInfo(encode_grfs=True, short=not firstSave), self.client.getCompanyInfo().companies, tstart ] obj.append(value) try: f = open(fn, 'wb') #if you use python < 2.3 use this line: #pickle.dump(obj, f) pickle.dump(obj, f, 1) f.close() except IOError: LOG.error("error while saving stats cache file!") tdiff = time.time() - tstart fs = float(os.path.getsize(fn)) / float(1024) LOG.debug( "stats updated in %0.5f seconds. File is %.2fKB big (%d lines)" % (tdiff, fs, len(obj)))
def updateStats(self): self.last = time.time() if not config.getboolean('stats', 'enable'): return LOG.debug("updating stats...") tstart = time.time() fn = config.get("stats", "cachefilename") obj = [] firstSave = False try: f = open(fn, 'rb') obj = pickle.load(f) f.close() except IOError: firstSave=True value = [ self.client.getGameInfo(encode_grfs=True, short=not firstSave), self.client.getCompanyInfo().companies, tstart ] obj.append(value) try: f = open(fn, 'wb') #if you use python < 2.3 use this line: #pickle.dump(obj, f) pickle.dump(obj, f, 1) f.close() except IOError: LOG.error("error while saving stats cache file!") tdiff = time.time() - tstart fs = float(os.path.getsize(fn)) / float(1024) LOG.debug("stats updated in %0.5f seconds. File is %.2fKB big (%d lines)"%(tdiff, fs, len(obj)))
#!/usr/bin/env python # made by thomas {AT} thomasfischer {DOT} biz import time, sys from operator import itemgetter from openttd.client import M_UDP, Client from ottd_config import config from openttd.grfdb import GrfDB import openttd.constants as const import socket from log import LOG VERBOSE = config.getboolean("serverstats", "verbose") SERVERS = {} GRFS = GrfDB() SVNREVISION = "$Rev$" class Grf: def __init__(self, id, md5, name): self.grfid = id self.usedcount = 0 self.totalclients = 0 self.name = name self.md5sum = md5 self.servers = [] def addServer(self, server): self.usedcount += 1 self.totalclients += server.clients_on self.servers.append(server) def getUsedPercent(self, totalcount): return float(self.usedcount)/float(totalcount)*100 def __cmp__(self, other):
def init(self): self.updateConfig() self.enable = config.getboolean('stats', 'enable') self.registerCallback("on_map_done", self.clearStats) self.registerCallback("on_mainloop", self.checkupdatestats)
#!/usr/bin/env python # made by thomas {AT} thomasfischer {DOT} biz import time, sys from operator import itemgetter from openttd.client import M_UDP, Client from ottd_config import config from openttd.grfdb import GrfDB import openttd.constants as const import socket from log import LOG VERBOSE = config.getboolean("serverstats", "verbose") SERVERS = {} GRFS = GrfDB() SVNREVISION = "$Rev$" class Grf: def __init__(self, id, md5, name): self.grfid = id self.usedcount = 0 self.totalclients = 0 self.name = name self.md5sum = md5 self.servers = [] def addServer(self, server): self.usedcount += 1 self.totalclients += server.clients_on self.servers.append(server)
def autoStart(self): if config.getboolean("webserver", "enable") and config.getboolean( "webserver", "autostart"): InternalCommand("startwebserver", self.client)
def autoStart(self): if config.getboolean("webserver", "enable") and config.getboolean("webserver", "autostart"): InternalCommand("startwebserver", self.client)