Esempio n. 1
0
def setup():
    config = PluginConfig("banner")
    default_timeout = config.getOption("Config", "default_timeout", 180000)
    for option in config.getAllOptions("Banners"):
        msg = option[1]
        delay = config.getOption("Timeouts", option[0], default_timeout, False)
        banners.append(Banner(msg, int(delay)))
    info_msg[0] = string.Template(config.getOption("Config", "serverinfo", "XSBS Version 2.0")).substitute(colordict)
    del config
Esempio n. 2
0
def setup():
    config = PluginConfig('banner')
    default_timeout = config.getOption('Config', 'default_timeout', 180000)
    for option in config.getAllOptions('Banners'):
        msg = option[1]
        delay = config.getOption('Timeouts', option[0], default_timeout, False)
        banners.append(Banner(msg, int(delay)))
    info_msg[0] = string.Template(
        config.getOption('Config', 'serverinfo',
                         'XSBS Version 2.0')).substitute(colordict)
    del config
Esempio n. 3
0
File: motd.py Progetto: pguenth/xsbs
import sbserver
from xsbs.settings import PluginConfig
from xsbs.colors import colordict
from xsbs.events import registerServerEventHandler
import string


def greet(cn):
    sbserver.playerMessage(cn, motdstring)


config = PluginConfig('motd')
motdstring = config.getOption(
    'Config', 'template', '${orange}Welcome to a ${red}XSBS ${orange}server')
del config

motdstring = string.Template(motdstring).substitute(colordict)
registerServerEventHandler('player_connect_delayed', greet)
Esempio n. 4
0
from twisted.protocols.basic import LineReceiver
from twisted.internet import reactor, protocol
from twisted.internet.task import LoopingCall

from xsbs.settings import PluginConfig
from xsbs.events import triggerServerEvent, eventHandler
from xsbs.net import ipLongToString

import sbserver
import time
import logging

config = PluginConfig('masterclient')
claimstr = config.getOption('Config', 'auth_message', '${green}${name}${white} has authenticated as ${magenta}${authname}')
master_host = config.getOption('Config', 'master_host', 'sauerbraten.org')
master_port = config.getOption('Config', 'master_port', '28787')
allow_auth = config.getOption('Config', 'allow_auth', 'yes') == 'yes'
register_interval = config.getOption('Config', 'register_interval', '3600')
del config

class AuthRequest(object):
	def __init__(self, id, cn, name):
		self.id = id
		self.cn = cn
		self.name = name

class AuthIdNotFoundError(Exception):
	pass

class ResponseHandler(object):
	def __init__(self, factory):
Esempio n. 5
0
from xsbs.events import registerServerEventHandler
from xsbs.players import player, all as allPlayers
from xsbs.settings import PluginConfig
from xsbs.colors import colordict
from xsbs.server import message as serverMessage

import string

config = PluginConfig('gameawards')
awards_prefix = config.getOption('Config', 'awards_prefix', '${blue}Awards: ${white}')
mftemp = config.getOption('Config', 'most_frags', 'Most Frags: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')
mtktemp = config.getOption('Config', 'most_teamkills', 'Most TeamKills: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')
mdtemp = config.getOption('Config', 'most_deaths', 'Most Deaths: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')
matemp = config.getOption('Config', 'most_accurate', 'Most Accurate: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')

newawards_enabled = config.getOption('Config', 'Multikill_awards', 'enabled') == 'enabled'
most_doublekillstemp = config.getOption('Config', 'most_doublekills', 'Most Double Kills: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')
most_triplekillstemp = config.getOption('Config', 'most_triplekills', 'Most Triple Kills: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')
most_overkillstemp = config.getOption('Config', 'most_overkills', 'Most Overkills: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')
most_killtacularstemp = config.getOption('Config', 'most_killtaculars', 'Most Killtacular: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')
most_killotrocitiestemp = config.getOption('Config', 'most_killotrocities', 'Most Killotrocities: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')
most_killtastrophestemp = config.getOption('Config', 'most_killtastrophes', 'Most Killtastrophic: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')
most_killapocalypsestemp = config.getOption('Config', 'most_killapocalypses', 'Most Killapocalyptic: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')
most_killionairestemp = config.getOption('Config', 'most_killionaires', 'Best Killionaire ${orange}${name} ${blue}(${green}${count}${blue})${white} ')



del config
awards_prefix = string.Template(awards_prefix).substitute(colordict)
mftemp = string.Template(mftemp)
mtktemp = string.Template(mtktemp)
Esempio n. 6
0
from xsbs.events import registerServerEventHandler, triggerServerEvent
from xsbs.settings import PluginConfig
from xsbs.game import modes
from xsbs.ui import error, info
from xsbs.colors import colordict
from xsbs.commands import registerCommandHandler
import logging
import sbserver
import string

config = PluginConfig('maprotation')
preset_rotation = config.getOption('Config', 'use_preset_rotation',
                                   'yes') == 'yes'
start_mode = config.getOption('Config', 'start_mode', 'ffa')
nextmap_response = config.getOption('Config', 'nextmap_response',
                                    'The next map is ${blue}${mapname}')
map_modes = config.getAllOptions('Maps')
del config
nextmap_response = string.Template(nextmap_response)


class Map:
    def __init__(self, name, mode):
        self.name = name
        self.mode = mode


def getSuccessor(mode_num, map):
    try:
        maps = modeMapLists[modes[mode_num]]
        if map == '':
Esempio n. 7
0
import sbserver
from xsbs.timers import addTimer
from xsbs.ban import ban
from xsbs.settings import PluginConfig
from xsbs.ui import warning, notice
from xsbs.commands import commandHandler, UsageError
from xsbs import players
from xsbs.players import adminRequired

config = PluginConfig('pinglimiter')
enable = config.getOption('Config', 'enable', 'yes') == 'yes'
max_ping = config.getOption('Config', 'max_ping', '500')
action_interval = config.getOption('Config', 'action_interval', '5')
del config
max_ping = int(max_ping)
action_interval = int(action_interval)

class PingLimiter:
	def __init__(self, max_ping, action_interval):
		self.max_ping = max_ping
		self.action_interval = action_interval
		self.counter = action_interval
		self.warned_cns = []
		self.enabled = True
	def checkPlayers(self):
		addTimer(5000, self.checkPlayers, ())
		if not self.enabled:
			return
		self.update_averages()
		if self.counter == 0:
			laggers = []
Esempio n. 8
0
from twisted.protocols.basic import LineReceiver
from twisted.internet import reactor, protocol
from twisted.internet.task import LoopingCall

from xsbs.settings import PluginConfig
from xsbs.events import triggerServerEvent, eventHandler
from xsbs.net import ipLongToString

import sbserver
import time
import logging

config = PluginConfig('masterclient')
claimstr = config.getOption(
    'Config', 'auth_message',
    '${green}${name}${white} has authenticated as ${magenta}${authname}')
master_host = config.getOption('Config', 'master_host', 'sauerbraten.org')
master_port = config.getOption('Config', 'master_port', '28787')
allow_auth = config.getOption('Config', 'allow_auth', 'yes') == 'yes'
register_interval = config.getOption('Config', 'register_interval', '3600')
del config


class AuthRequest(object):
    def __init__(self, id, cn, name):
        self.id = id
        self.cn = cn
        self.name = name


class AuthIdNotFoundError(Exception):
Esempio n. 9
0
from xsbs.events import registerServerEventHandler
from xsbs.commands import commandHandler
from xsbs.players import player, all as allPlayers
from xsbs.ui import error, info
from xsbs.colors import colordict
from xsbs.settings import PluginConfig
from Bans.bans import ban
import sbserver
import string

config = PluginConfig('votekick')
vktemp = config.getOption(
    'Config', 'vote_message',
    '${green}${voter}${white} voted to ${red}kick ${orange}${victim}')
del config
vktemp = string.Template(vktemp)


def checkVotes(cn):
    players = allPlayers()
    needed = len(players) / 2
    if needed <= 1:
        needed += 1
    votes = 0
    for player in players:
        try:
            if player.votekick == cn:
                votes += 1
        except AttributeError:
            pass
    if votes >= needed:
Esempio n. 10
0
File: mute.py Progetto: pguenth/xsbs
import sbserver
from xsbs.colors import colordict
from xsbs.ui import info, notice, error
from xsbs.events import registerPolicyEventHandler, registerServerEventHandler
from xsbs.players import player, masterRequired
from xsbs.settings import PluginConfig
from xsbs.commands import commandHandler, UsageError, StateError, ArgumentValueError
import string

config = PluginConfig('mute')
muted_temp = config.getOption(
    'Messages', 'muted_message',
    '${green}${muted_name}${white} has been ${red}muted ${white}(by ${blue}${muter}${white})'
)
unmuted_temp = config.getOption(
    'Messages', 'unmuted_message',
    '${green}${muted_name}${white} has been ${red}unmuted ${white}(by ${blue}${muter}${white})'
)
del config
muted_temp = string.Template(muted_temp)
unmuted_temp = string.Template(unmuted_temp)
mute_spectators = [False]


def allowMsg(cn, text):
    try:
        p = player(cn)
        if mute_spectators[0] == True and p.isSpectator():
            p.message(
                notice(
                    'Spectators are currently muted.  No one will recieve your message'
Esempio n. 11
0
from twisted.web import server, resource
from twisted.internet import reactor

from xsbs.settings import PluginConfig
from xsbs.events import eventHandler

config = PluginConfig('httpserver')
port = config.getOption('Config', 'port', '8081')
enabled = config.getOption('Config', 'enable', 'yes') == 'yes'
port = int(port)
del config

class RootSite(resource.Resource):
		pass

class HttpServer(object):
	def __init__(self, address, port):
		self.address = address
		self.port = port
		self.root_site = RootSite()
		self.server_site = server.Site(self.root_site)
	def start(self):
		self.connection = reactor.listenTCP(port, self.server_site)
	def stop(self):
		self.connection.stopListening()

server = HttpServer('', port)
if enabled:
	server.start()

@eventHandler('reload')
Esempio n. 12
0
	def __init__(self, uri):
		self.uri = uri
		self.isConnected = False
	def connect(self):
		if not self.isConnected:
			self.engine = create_engine(self.uri, echo=False)
			self.isConnected = True
			self.m_session = sessionmaker(bind=self.engine, autocommit=False, autoflush=False)()
	def reconnect(self):
		self.isConnected = False
		del self.m_session
		del self.engine
		self.connect()
	def session(self):
		return self.m_session
	def query(self, *args, **kwargs):
		try:
			q = self.session().query(*args, **kwargs)
		except (OperationalError, InvalidRequestError):
			self.reconnect()
			q = self.session().query(*args, **kwargs)
		return q

config = PluginConfig('db')
uri = config.getOption('Config', 'uri', 'sqlite:///xsbs.db')
del config

dbmanager = DatabaseManager(uri)
dbmanager.connect()

Esempio n. 13
0
from xsbs.events import registerServerEventHandler
from xsbs.players import player, masterRequired
from xsbs.ui import warning, error, info
from xsbs.settings import PluginConfig
from xsbs.commands import registerCommandHandler

config = PluginConfig('cheatdetection')
spectate_map_modified = (config.getOption('Config', 'spectate_map_modified', 'yes') == 'yes')
del config

def onMapModified(cn):
	player(cn).gamevars['modified_map'] = True
	checkModified(cn)

def checkModified(cn):
	try:
		p = player(cn)
		if p.gamevars['modified_map'] and spectate_map_modified:
			p.message(warning('You cannot play with a modified map.'))
			p.spectate()
	except KeyError:
		pass
	except ValueError:
	 	pass

@masterRequired
def mapModifiedSpecCmd(cn, args):
	'''@description Enable or disable spectate clients with modified map
	   @usage enable/disable'''
	p = player(cn)
	if args == 'disable':
Esempio n. 14
0
File: bans.py Progetto: pguenth/xsbs
from xsbs.settings import PluginConfig
from xsbs.colors import red, colordict
from xsbs.ui import insufficientPermissions, error, info
from xsbs.db import dbmanager
from xsbs.commands import commandHandler, UsageError, ArgumentValueError
from xsbs.events import triggerServerEvent, eventHandler, policyHandler, execLater
from xsbs.ban import ban, isIpBanned, isNickBanned, Ban
from xsbs.net import ipLongToString, ipStringToLong
from xsbs.players import masterRequired, player
from xsbs.server import message as serverMessage
import time, string
import logging

config = PluginConfig('bans')
ban_command = config.getOption('Config', 'ban_command', 'ban')
default_ban_length = config.getOption('Config', 'default_ban_time', 3600)
default_reason = config.getOption('Config', 'default_reason',
                                  'unspecified reason')
kick_message = config.getOption(
    'Config', 'kick_message',
    '${green}${name}${white} was ${red}kicked${white} from server')
del config
kick_message = string.Template(kick_message)

session = dbmanager.session()


@commandHandler('ban')
@masterRequired
def onBanCmd(cn, text):
    '''@description Ban user from server
Esempio n. 15
0
import sbserver
from xsbs.players import player
from xsbs.settings import PluginConfig
from xsbs.events import registerServerEventHandler
from DB.db import dbmanager
from UserManager.usermanager import loggedInAs
from sqlalchemy import Column, Integer, String, Boolean, ForeignKey
from sqlalchemy.orm import relation
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.exc import NoResultFound
import time

config = PluginConfig('userstats')
statstable = config.getOption('Config', 'tablename', 'userstats')
tkill_fragval = int(config.getOption('Values', 'teamkill_fragval', '0'))
tkill_deathval = int(config.getOption('Values', 'teamkill_deathval', '0'))
suicide_fragval = int(config.getOption('Values', 'suicide_fragval', '0'))
suicide_deathval = int(config.getOption('Values', 'suicide_deathval', '1'))
del config

Base = declarative_base()
session = dbmanager.session()

class UserSessionStats(Base):
	'A session is at most a game length.'
	__tablename__ = statstable
	id = Column(Integer, primary_key=True)
	user_id = Column(Integer)
	end_time = Column(Integer)
	frags = Column(Integer)
	deaths = Column(Integer)
Esempio n. 16
0
from xsbs.events import eventHandler
from xsbs.colors import colordict
from xsbs.ui import error, info
from xsbs.players import player, all as allPlayers, isAtLeastMaster
from xsbs.settings import PluginConfig
from xsbs.server import message as serverMessage
from xsbs.game import setMap

import sbserver
import logging
import string

config = PluginConfig('mapvote')
allow_modevote = config.getOption('Config', 'allow_mode_vote', 'no') == 'yes'
lock_mode = config.getOption('Config', 'lock_game_mode', 'no') == 'yes'
request_temp = config.getOption(
    'Config', 'request_string',
    '${green}${user}${white} requested ${modename} on ${mapname}')
del config
request_temp = string.Template(request_temp)


def vote(candidates, vote):
    for cand in candidates:
        if cand[0] == vote[0] and cand[1] == vote[1]:
            cand[2] += 1
            return cand[2]
    candidates.append([vote[0], vote[1], 1])
    return 1

Esempio n. 17
0
from xsbs.events import eventHandler
from xsbs.players import player, playerCount, spectatorCount
from xsbs.settings import PluginConfig
from xsbs.server import maxClients, setMaxClients
import logging

config = PluginConfig('dynamicresize')
# For every n spectators add one to maxclients
spectatorsAddClient = config.getOption('Config', 'spectators_addclient_rate',
                                       '2')
del config

try:
    spectatorsAddClient = int(spectatorsAddClient)
except TypeError:
    logging.error('Non int value for spectator addclient rate.  Setting to 0')
    spectatorsAddClient = 0

adjsize = [0]


@eventHandler('player_spectated')
@eventHandler('player_connect')
@eventHandler('player_disconnect')
@eventHandler('player_unspectated')
def checkSize(cn):
    if spectatorsAddClient == 0:
        return
    newadj = spectatorCount() / spectatorsAddClient
    newsize = 0
    if adjsize[0] == newadj:
Esempio n. 18
0
from xsbs.events import registerServerEventHandler
from xsbs.players import player, all as allPlayers
from xsbs.settings import PluginConfig
from xsbs.colors import colordict
from xsbs.server import message as serverMessage

import string

config = PluginConfig('gameawards')
awards_prefix = config.getOption('Config', 'awards_prefix', '${blue}Awards: ${white}')
mftemp = config.getOption('Config', 'most_frags', 'Most Frags: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')
mtktemp = config.getOption('Config', 'most_teamkills', 'Most TeamKills: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')
mdtemp = config.getOption('Config', 'most_deaths', 'Most Deaths: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')
matemp = config.getOption('Config', 'most_accurate', 'Most Accurate: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')

newawards_enabled = config.getOption('Config', 'Multikill_awards', 'enabled') == 'enabled'
most_doublekillstemp = config.getOption('Config', 'most_doublekills', 'Most Double Kills: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')
most_triplekillstemp = config.getOption('Config', 'most_triplekills', 'Most Triple Kills: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')
most_overkillstemp = config.getOption('Config', 'most_overkills', 'Most Overkills: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')
most_killtacularstemp = config.getOption('Config', 'most_killtaculars', 'Most Killtacular: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')
most_killotrocitiestemp = config.getOption('Config', 'most_killotrocities', 'Most Killotrocities: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')
most_killtastrophestemp = config.getOption('Config', 'most_killtastrophes', 'Most Killtastrophic: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')
most_killapocalypsestemp = config.getOption('Config', 'most_killapocalypses', 'Most Killapocalyptic: ${orange}${name} ${blue}(${green}${count}${blue})${white} ')
most_killionairestemp = config.getOption('Config', 'most_killionaires', 'Best Killionaire ${orange}${name} ${blue}(${green}${count}${blue})${white} ')



del config
awards_prefix = string.Template(awards_prefix).substitute(colordict)
mftemp = string.Template(mftemp)
mtktemp = string.Template(mtktemp)
Esempio n. 19
0
import sbserver
from xsbs.commands import registerCommandHandler
from xsbs.settings import PluginConfig
from xsbs.colors import red, green, white
import socket, re, asyncore

cmd_name = 'translate'
fault_message = "Usage: #%s <word> or #%s <sentence/word> <from_lang> <to_lang> Language codes: en, sv, de, it and lots more." % (cmd_name, cmd_name)

player_fd_limit = 10

config = PluginConfig(cmd_name)
from_lang = config.getOption('Config', 'from_lang', 'en')
to_lang = config.getOption('Config', 'to_lang', 'sv')
del config

langslist = ['af','sq','am','ar','hy',
		'az','eu','be','bn','bh','bg','my',
		'ca','chr','zh','zh-CN','zh-TW',
		'hr','cs','da','dv','nl','en',
		'eo','et','tl','fi','fr','gl',
		'ka','de','el','gn','gu','iw',
		'hi','hu','is','id','iu','ga',
		'it','ja','kn','kk','km','ko',
		'ku','ky','lo','lv','lt','mk',
		'ms','ml','mt','mr','mn','ne',
		'no','or','ps','fa','pl','pt-PT',
		'pa','ro','ru','sa','sr','sd',
		'si','sk','sl','es','sw','sv',
		'tg','ta','tl','te','th','bo',
		'tr','uk','ur','uz','ug','vi',
Esempio n. 20
0
import sbserver

from sqlalchemy import Column, Integer, String, Boolean, ForeignKey
from sqlalchemy.orm import relation
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.exc import NoResultFound

from xsbs.events import registerServerEventHandler
from xsbs.ui import error, info, insufficientPermissions
from xsbs.colors import colordict
from xsbs.settings import PluginConfig
from xsbs.db import dbmanager
import string

config = PluginConfig('userprivilege')
tablename = config.getOption('Config', 'tablename', 'userprivileges')
authtemp = config.getOption(
    'Messages', 'authenticated',
    '${green}${name}${white} authenticated as ${magenta}${authname}')
gmtemp = config.getOption('Messages', 'gain_master',
                          '${green}${name}${white} claimed ${red}master')
gatemp = config.getOption('Messages', 'gain_admin',
                          '${green}${name}${white} claimed ${red}admin')
rmtemp = config.getOption('Messages', 'release_master',
                          '${green}${name}${white} relinquished ${red}master')
ratemp = config.getOption('Messages', 'release_admin',
                          '${green}${name}${white} relinquished ${red}admin')
del config
authtemp = string.Template(authtemp)
gmtemp = string.Template(gmtemp)
gatemp = string.Template(gatemp)
Esempio n. 21
0
from xsbs.colors import red
from xsbs.ui import info
from xsbs.colors import colordict
from xsbs.events import registerServerEventHandler
from xsbs.settings import PluginConfig
from xsbs.players import player
from xsbs.server import message as serverMessage

import string

config = PluginConfig('gamenotifications')
tktemp = config.getOption('Config', 'teamkill', '${green}${tker}${white} team killed (${tkcount}) ${orange}${victim}')
uptemp = config.getOption('Config', 'map_uploaded', '${green}${name}${white} uploaded a map. /getmap to receive it')
getmaptemp = config.getOption('Config', 'get_map', '${green}${name}${white} is downloading map')
del config

tktemp = string.Template(tktemp)
uptemp = string.Template(uptemp)
getmaptemp = string.Template(getmaptemp)

def teamkill_broadcast(cn, tcn):
	tker = player(cn)
	target = player(tcn)
	serverMessage(info(tktemp.substitute(colordict, tker=tker.name(), victim=target.name(), tkcount=tker.teamkills())))

def getmap(cn):
	p = player(cn)
	serverMessage(info(getmaptemp.substitute(colordict, name=p.name())))

def onUploadMap(cn):
	p = player(cn)
Esempio n. 22
0
from xsbs.events import eventHandler
from xsbs.settings import PluginConfig
from xsbs.ui import error, notice, warning, info
from xsbs.colors import colordict, green, orange
from xsbs.players import player, all as allPlayers, playerByName, playerByIpString
import sbserver
import time
import string

config = PluginConfig('ownage')
spreemessagesenable = config.getOption('Config', 'spreemessages', 'yes') == 'yes'
neomessagesenable = config.getOption('Config', 'neomessages', 'yes') == 'yes'
dommessagesenable = config.getOption('Config', 'dommessages', 'yes') == 'yes'
interval = int(config.getOption('Config', 'max_time_btwn_kills', '2'))
del config

spreemessages = {
	5: string.Template(green('$name') + ' is on a ' + orange('KILLING SPREE!')),
	10: string.Template(green('$name') + ' is ' + orange('UNSTOPPABLE!')),
	15: string.Template(green('$name') + ' is ' + orange('GODLIKE!'))
	}
endmsg = string.Template(orange('$victimname') + '\'s killing spree ended by ' + green('$killername'))
suicideendmsg = string.Template(orange('$victimname') + 'has ended his own killing spree!')

neomessages = {
	2: string.Template(orange('DOUBLE KILL!')),
	3: string.Template(orange('TRIPLE KILL!')),
	5: string.Template(orange('OVERKILL!')),
	7: string.Template(orange('KILLTACULAR!')),
	10: string.Template(orange('KILLOTROCITY!')),
	15: string.Template(orange('KILLTASTROPHE!')),
Esempio n. 23
0
from xsbs.settings import PluginConfig
from xsbs.colors import colordict
from xsbs.ui import info
from xsbs.events import eventHandler
from xsbs.net import ipLongToString
from xsbs.server import message as serverMessage
from xsbs.players import player

import string
import pygeoip

db = pygeoip.GeoIP('GeoIp/GeoIP.dat')

conf = PluginConfig('geoip')
template = '${green}${user}${white} connected from ${orange}${country}'
template = conf.getOption('Config', 'template', template)
del conf


def getCountry(ip):
    country = db.country_name_by_addr(ipLongToString(ip))
    if country == '':
        country = 'Unknown'
    return country


@eventHandler('player_connect_delayed')
def announce(cn):
    p = player(cn)
    msg = string.Template(template).substitute(colordict,
                                               user=p.name(),
Esempio n. 24
0
from sqlalchemy import Column, Integer, String, Boolean, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.exc import NoResultFound
from xsbs.settings import PluginConfig
from xsbs.events import registerServerEventHandler
from xsbs.ui import error, info, insufficientPermissions
from xsbs.commands import commandHandler, UsageError
from xsbs.db import dbmanager
from xsbs.players import isAtLeastMaster
import sbserver

config = PluginConfig('namesdb')
tablename = config.getOption('Config', 'tablename', 'ip_name')
master_required = config.getOption('Config', 'master_required', 'no') == 'yes'
del config

Base = declarative_base()
session = dbmanager.session()

class IpToNick(Base):
	__tablename__=tablename
	id = Column(Integer, primary_key=True)
	ip = Column(Integer, index=True)
	nick = Column(String)
	def __init__(self, ip, nick):
		self.ip = ip
		self.nick = nick

def onConnect(cn):
	try:
		same = dbmanager.query(IpToNick).filter(IpToNick.ip==sbserver.playerIpLong(cn)).filter(IpToNick.nick==sbserver.playerName(cn)).all()
Esempio n. 25
0
import sbserver
from xsbs.colors import red, green
from xsbs.settings import PluginConfig
from xsbs.commands import registerCommandHandler

cmd_name = 'sauerhelp'

config = PluginConfig('sauerhelp')
command = config.getOption('Config', 'command', 'newmap')
del config

commands = dict(newmap="Creates a blank map, arguments for this command are '/newmap size' where size is a number 10-16",
                sendmap="/sendmap uploads your map to the server so other players are able to see it this command has no arguments",
                getmap="downloads the map that has been uploaded to the server by another user, this command has no arguments",
                savemap="saves the map for later access, arguments for this command are '/savemap mapname'",
                calclight="calculates lightmaps for all light entities on the map use '/calclight -1' which calculates the lights faster",
                lightprecision="changes the precision of the shadows when you calclight, arguments for this command are '/lightprecision number' where number is the detail level",
                kill="causes player to commit suicide and takes away 1 point, there are no arguments for this command")

		
def onCommand(cn, command):
			sbserver.playerMessage(cn, green(command) + green(": ") + red(commands[command]))                    
			

registerCommandHandler(cmd_name, onCommand)
Esempio n. 26
0
File: db.py Progetto: pguenth/xsbs
            self.engine = create_engine(self.uri, echo=False)
            self.isConnected = True
            self.m_session = sessionmaker(bind=self.engine,
                                          autocommit=False,
                                          autoflush=False)()

    def reconnect(self):
        self.isConnected = False
        del self.m_session
        del self.engine
        self.connect()

    def session(self):
        return self.m_session

    def query(self, *args, **kwargs):
        try:
            q = self.session().query(*args, **kwargs)
        except (OperationalError, InvalidRequestError):
            self.reconnect()
            q = self.session().query(*args, **kwargs)
        return q


config = PluginConfig('db')
uri = config.getOption('Config', 'uri', 'sqlite:///xsbs.db')
del config

dbmanager = DatabaseManager(uri)
dbmanager.connect()
Esempio n. 27
0
File: log.py Progetto: pguenth/xsbs
from xsbs.settings import PluginConfig
import logging
import string

config = PluginConfig('logging')
path = config.getOption('Config', 'path', 'xsbs.log')
level = config.getOption('Config', 'level', 'error')
del config

LEVELS = {
    'debug': logging.DEBUG,
    'info': logging.INFO,
    'warning': logging.WARNING,
    'error': logging.ERROR,
    'critical': logging.CRITICAL
}

logging.basicConfig(
    filename=path,
    format='%(levelname)-10s %(asctime)s %(module)s: %(message)s',
    level=LEVELS[level])
Esempio n. 28
0
from xsbs.events import eventHandler
from xsbs.colors import colordict
from xsbs.ui import error, info
from xsbs.players import player, all as allPlayers, isAtLeastMaster
from xsbs.settings import PluginConfig
from xsbs.server import message as serverMessage
from xsbs.game import setMap

import sbserver
import logging
import string

config = PluginConfig('mapvote')
allow_modevote = config.getOption('Config', 'allow_mode_vote', 'no') == 'yes'
lock_mode = config.getOption('Config', 'lock_game_mode', 'no') == 'yes'
request_temp = config.getOption('Config', 'request_string', '${green}${user}${white} requested ${modename} on ${mapname}')
del config
request_temp = string.Template(request_temp)

def vote(candidates, vote):
	for cand in candidates:
		if cand[0] == vote[0] and cand[1] == vote[1]:
			cand[2] += 1
			return cand[2]
	candidates.append([vote[0], vote[1], 1])
	return 1

def countVotes():
	players = allPlayers()
	votes_needed = (len(players) / 2)
	bestmap = ''
Esempio n. 29
0
import string
from xsbs.commands import commandHandler
from xsbs.colors import colordict
from xsbs.settings import PluginConfig
from xsbs.ui import insufficientPermissions, error
from xsbs.players import player, isAtLeastMaster

config = PluginConfig('stats')
template = config.getOption('Config', 'template', '${white}Stats for ${orange}${name}\n${white}Frags: ${green}${frags} ${white}Deaths: ${red}${deaths} ${white}Teamkills: ${magenta}${teamkills} ${white}Accuracy: ${yellow}${accuracy}% ${white}KpD: ${orange}${ktd} ${white}Scores: ${blue}${score}')
require_master = config.getOption('Config', 'require_master', 'no') == 'yes'
del config
template = string.Template(template)

@commandHandler('stats')
def onCommand(cn, args):
	'''@description Stats for the current match
	   @usage (cn)
	   @public'''
	cp = player(cn)
	if args != '':
		if require_master and not isPlayerMaster(cn):
			insufficientPermissions(cn)
			return
		try:
			p = player(int(args))
		except ValueError:
			cp.message(error('Usage: #stats (cn)'))
			return
	else:
		p = cp
	if not p.name():
Esempio n. 30
0
from xsbs.events import eventHandler
from xsbs.players import player, playerCount, spectatorCount
from xsbs.settings import PluginConfig
from xsbs.server import maxClients, setMaxClients
import logging

config = PluginConfig('dynamicresize')
# For every n spectators add one to maxclients
spectatorsAddClient = config.getOption('Config', 'spectators_addclient_rate', '2')
del config

try:
	spectatorsAddClient = int(spectatorsAddClient)
except TypeError:
	logging.error('Non int value for spectator addclient rate.  Setting to 0')
	spectatorsAddClient = 0

adjsize = [0]

@eventHandler('player_spectated')
@eventHandler('player_connect')
@eventHandler('player_disconnect')
@eventHandler('player_unspectated')
def checkSize(cn):
	if spectatorsAddClient == 0:
		return
	newadj = spectatorCount() / spectatorsAddClient
	newsize = 0
	if adjsize[0] == newadj:
		return
	elif adjsize[0] > newadj:
Esempio n. 31
0
from twisted.web import server, resource
from twisted.internet import reactor

from xsbs.settings import PluginConfig
from xsbs.events import eventHandler

config = PluginConfig('httpserver')
port = config.getOption('Config', 'port', '8081')
enabled = config.getOption('Config', 'enable', 'yes') == 'yes'
port = int(port)
del config


class RootSite(resource.Resource):
    pass


class HttpServer(object):
    def __init__(self, address, port):
        self.address = address
        self.port = port
        self.root_site = RootSite()
        self.server_site = server.Site(self.root_site)

    def start(self):
        self.connection = reactor.listenTCP(port, self.server_site)

    def stop(self):
        self.connection.stopListening()

Esempio n. 32
0
from xsbs.players import masterRequired, player
from xsbs.events import eventHandler
from xsbs.commands import commandHandler, StateError
from xsbs.ui import notice
from xsbs.colors import colordict
from xsbs.settings import PluginConfig

import string
import sbserver

config = PluginConfig('server')
pause_message = config.getOption('Templates', 'pause_message', 'The game has been ${action} by ${orange}${name}')
del config
pause_message = string.Template(pause_message)

def isPaused():
	'''Is the game currently paused'''
	return sbserver.isPaused()

def setPaused(val, cn=-1):
	'''Pause or unpause the game'''
	if isFrozen():
		raise StateError('Server is currently frozen')
	if val == isPaused():
		return
	if val:
		action = 'paused'
	else:
		action = 'unpaused'
	try:
		p = player(cn)
Esempio n. 33
0
import sbserver
from xsbs.timers import addTimer
from xsbs.ban import ban
from xsbs.settings import PluginConfig
from xsbs.ui import warning, notice
from xsbs.commands import commandHandler, UsageError
from xsbs import players
from xsbs.players import adminRequired

config = PluginConfig('pinglimiter')
enable = config.getOption('Config', 'enable', 'yes') == 'yes'
max_ping = config.getOption('Config', 'max_ping', '500')
action_interval = config.getOption('Config', 'action_interval', '5')
del config
max_ping = int(max_ping)
action_interval = int(action_interval)


class PingLimiter:
    def __init__(self, max_ping, action_interval):
        self.max_ping = max_ping
        self.action_interval = action_interval
        self.counter = action_interval
        self.warned_cns = []
        self.enabled = True

    def checkPlayers(self):
        addTimer(5000, self.checkPlayers, ())
        if not self.enabled:
            return
        self.update_averages()
Esempio n. 34
0
import sbserver
from xsbs.colors import colordict
from xsbs.settings import PluginConfig
import string

config = PluginConfig('ui')
notice_pre = config.getOption('Prefixes', 'notice', '${blue}Notice:')
info_pre = config.getOption('Prefixes', 'info', '${yellow}Info:')
warning_pre = config.getOption('Prefixes', 'warning', '${red}Warning:')
error_pre = config.getOption('Prefixes', 'error', '${red}Error:')
del config

notice_pre = string.Template(notice_pre).substitute(colordict) + ' '
info_pre = string.Template(info_pre).substitute(colordict) + ' '
warning_pre = string.Template(warning_pre).substitute(colordict) + ' '
error_pre = string.Template(error_pre).substitute(colordict) + ' '


def notice(message):
    return notice_pre + message


def info(message):
    return info_pre + message


def warning(message):
    return warning_pre + message


def error(message):
Esempio n. 35
0
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
import sbserver
from xsbs.db import dbmanager
from xsbs.events import eventHandler, triggerServerEvent, registerServerEventHandler, registerPolicyEventHandler
from xsbs.commands import commandHandler, UsageError, StateError, ArgumentValueError
from xsbs.colors import red, green, orange
from xsbs.ui import info, error, warning
from xsbs.players import player
from xsbs.settings import PluginConfig
from xsbs.ban import ban
from xsbs.timers import addTimer
import re

config = PluginConfig('usermanager')
usertable = config.getOption('Config', 'users_tablename', 'usermanager_users')
nicktable = config.getOption('Config', 'linkednames_table', 'usermanager_nickaccounts')
blocked_names = config.getOption('Config', 'blocked_names', 'unnamed, admin')
del config

blocked_names = blocked_names.strip(' ').split(',')

Base = declarative_base()
session = dbmanager.session()

class User(Base):
	__tablename__ = usertable
	id = Column(Integer, primary_key=True)
	email = Column(String, index=True)
	password = Column(String, index=True)
	def __init__(self, email, password):
Esempio n. 36
0
from sqlalchemy import Column, Integer, String, Boolean, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.exc import NoResultFound
from xsbs.settings import PluginConfig
from xsbs.events import registerServerEventHandler
from xsbs.ui import error, info, insufficientPermissions
from xsbs.commands import commandHandler, UsageError
from xsbs.db import dbmanager
from xsbs.players import isAtLeastMaster
import sbserver

config = PluginConfig('namesdb')
tablename = config.getOption('Config', 'tablename', 'ip_name')
master_required = config.getOption('Config', 'master_required', 'no') == 'yes'
del config

Base = declarative_base()
session = dbmanager.session()


class IpToNick(Base):
    __tablename__ = tablename
    id = Column(Integer, primary_key=True)
    ip = Column(Integer, index=True)
    nick = Column(String)

    def __init__(self, ip, nick):
        self.ip = ip
        self.nick = nick

Esempio n. 37
0
from twisted.words.protocols.jabber import xmlstream
from twisted.words.protocols.jabber.xmlstream import XmlStreamFactory, XmlStream
from twisted.words.protocols.jabber import client, jid
from twisted.words.xish import domish
from twisted.internet import reactor

from xsbs.settings import PluginConfig
from xsbs.commands import commandHandler

import logging

config = PluginConfig('im')
jabber_enable = config.getOption('Jabber', 'enable', 'no') == 'yes'
jabber_server = config.getOption('Jabber', 'server', 'server.com')
jabber_port = config.getOption('Jabber', 'port', '5222')
jabber_id = config.getOption('Jabber', 'jid', '*****@*****.**')
jabber_pass = config.getOption('Jabber', 'password', 'pass')
jabber_alerts = config.getOption('Jabber', 'alert_accounts', '[email protected], [email protected]')
del config
jabber_port = int(jabber_port)
jabber_id += '/xsbs'
jabber_alerts = jabber_alerts.strip().split(',')

class JabberClient(XmlStream):
	def connectionMade(self):
		logging.debug('Connected')
		self.addObserver(
			xmlstream.STREAM_AUTHD_EVENT,
			self.authenticated
			)
		XmlStream.connectionMade(self)
Esempio n. 38
0
from xsbs.events import registerServerEventHandler
from xsbs.commands import commandHandler
from xsbs.players import player, all as allPlayers
from xsbs.ui import error, info
from xsbs.colors import colordict
from xsbs.settings import PluginConfig
from Bans.bans import ban
import sbserver
import string

config = PluginConfig('votekick')
vktemp = config.getOption('Config', 'vote_message', '${green}${voter}${white} voted to ${red}kick ${orange}${victim}')
del config
vktemp = string.Template(vktemp)

def checkVotes(cn):
	players = allPlayers()
	needed = len(players) / 2
	if needed <= 1:
		needed += 1
	votes = 0
	for player in players:
		try:
			if player.votekick == cn:
				votes += 1
		except AttributeError:
			pass
	if votes >= needed:
		ban(cn, 3600, 'Vote', -1)

@commandHandler('votekick')
Esempio n. 39
0
from xsbs.events import registerServerEventHandler
from xsbs.players import player, masterRequired
from xsbs.ui import warning, error, info
from xsbs.settings import PluginConfig
from xsbs.commands import registerCommandHandler

config = PluginConfig('cheatdetection')
spectate_map_modified = (config.getOption('Config', 'spectate_map_modified',
                                          'yes') == 'yes')
del config


def onMapModified(cn):
    player(cn).gamevars['modified_map'] = True
    checkModified(cn)


def checkModified(cn):
    try:
        p = player(cn)
        if p.gamevars['modified_map'] and spectate_map_modified:
            p.message(warning('You cannot play with a modified map.'))
            p.spectate()
    except KeyError:
        pass
    except ValueError:
        pass


@masterRequired
def mapModifiedSpecCmd(cn, args):
Esempio n. 40
0
from xsbs.events import eventHandler
from xsbs.timers import addTimer
from xsbs.settings import PluginConfig
from xsbs.ui import error, notice, warning
from Bans.bans import ban
from xsbs.colors import colordict
from xsbs.players import player, all as allPlayers, playerByName, playerByIpString
import sbserver
import time
import string

config = PluginConfig('nospam')
interval = int(config.getOption('Config', 'action_interval', '5'))
max_per_interval = int(config.getOption('Config', 'max_msgs', '6'))
max_per_second = int(config.getOption('Config', 'max_msgs_per_sec', '3'))
ban_duration = int(config.getOption('Config', 'ban_time', '3600'))
warnings = int(config.getOption('Config', 'warnings', '2'))
warn_spam_message = config.getOption(
    'Config', 'warn_spam_message',
    'Warning do not spam. This server is ${red}spam intolerant!${white} ')
del config
warn_spam_message = string.Template(warn_spam_message)


class ChatLog:
    def __init__(self):
        self.log = {}

    def add_chat(self, cn, text):
        speakin = player(cn)
        ip = speakin.ipString()
Esempio n. 41
0
from xsbs.settings import PluginConfig
import logging
import string

config = PluginConfig('logging')
path = config.getOption('Config', 'path', 'xsbs.log')
level = config.getOption('Config', 'level', 'error')
del config

LEVELS = {'debug': logging.DEBUG,
	'info': logging.INFO,
	'warning': logging.WARNING,
	'error': logging.ERROR,
	'critical': logging.CRITICAL}

logging.basicConfig(
	filename = path,
	format = '%(levelname)-10s %(asctime)s %(module)s: %(message)s',
	level = LEVELS[level])

Esempio n. 42
0
import sbserver
from xsbs.colors import colordict
from xsbs.settings import PluginConfig
import string

config = PluginConfig('ui')
notice_pre = config.getOption('Prefixes', 'notice', '${blue}Notice:')
info_pre = config.getOption('Prefixes', 'info', '${yellow}Info:')
warning_pre = config.getOption('Prefixes', 'warning', '${red}Warning:')
error_pre = config.getOption('Prefixes', 'error', '${red}Error:')
del config

notice_pre = string.Template(notice_pre).substitute(colordict) + ' '
info_pre = string.Template(info_pre).substitute(colordict) + ' '
warning_pre = string.Template(warning_pre).substitute(colordict) + ' '
error_pre = string.Template(error_pre).substitute(colordict) + ' '

def notice(message):
	return notice_pre + message

def info(message):
	return info_pre + message

def warning(message):
	return warning_pre + message

def error(message):
	return error_pre + message

def insufficientPermissions(cn):
	sbserver.playerMessage(cn, error('Insufficient permissions'))
Esempio n. 43
0
from xsbs.settings import PluginConfig
from xsbs.colors import red, colordict
from xsbs.ui import insufficientPermissions, error, info
from xsbs.db import dbmanager
from xsbs.commands import commandHandler, UsageError, ArgumentValueError
from xsbs.events import triggerServerEvent, eventHandler, policyHandler, execLater
from xsbs.ban import ban, isIpBanned, isNickBanned, Ban
from xsbs.net import ipLongToString, ipStringToLong
from xsbs.players import masterRequired, player
from xsbs.server import message as serverMessage
import time, string
import logging

config = PluginConfig('bans')
ban_command = config.getOption('Config', 'ban_command', 'ban')
default_ban_length = config.getOption('Config', 'default_ban_time', 3600)
default_reason = config.getOption('Config', 'default_reason', 'unspecified reason')
kick_message = config.getOption('Config', 'kick_message', '${green}${name}${white} was ${red}kicked${white} from server')
del config
kick_message = string.Template(kick_message)

session = dbmanager.session()

@commandHandler('ban')
@masterRequired
def onBanCmd(cn, text):
	'''@description Ban user from server
	   @usage <seconds> (reason)'''
	sp = text.split(' ')
	p = player(cn)
	try:
Esempio n. 44
0
from twisted.words.protocols import irc
from twisted.internet import reactor, protocol

from xsbs.settings import PluginConfig, NoOptionError
from xsbs.events import registerServerEventHandler
from xsbs.timers import addTimer
from xsbs.server import message
from xsbs.colors import colordict

import sbserver
import string

config = PluginConfig('ircbot')
enable = config.getOption('Config', 'enable', 'no') == 'yes'
channel = config.getOption('Config', 'channel', '#xsbs-newserver')
servername = config.getOption('Config', 'servername', 'irc.gamesurge.net')
nickname = config.getOption('Config', 'nickname', 'xsbs-newbot')
port = int(config.getOption('Config', 'port', '6667'))
part_message = config.getOption('Config', 'part_message',
                                'XSBS - eXtensible SauerBraten Server')
msg_gw = config.getOption('Abilities', 'message_gateway', 'yes') == 'yes'
irc_msg_temp = string.Template(
    config.getOption('Templates', 'irc_message',
                     '${grey}${channel} ${blue}${name}${white}: ${message}'))
status_message = config.getOption('Templates', 'status_message',
                                  '${num_clients} clients on map ${map_name}')
try:
    ipaddress = config.getOption('Config', 'ipaddress', None, False)
except NoOptionError:
    ipaddress = None
ircchannel = channel
Esempio n. 45
0
from xsbs.events import registerServerEventHandler, triggerServerEvent
from xsbs.settings import PluginConfig
from xsbs.game import modes
from xsbs.ui import error, info
from xsbs.colors import colordict
from xsbs.commands import registerCommandHandler
import logging
import sbserver
import string

config = PluginConfig('maprotation')
preset_rotation = config.getOption('Config', 'use_preset_rotation', 'yes') == 'yes'
start_mode = config.getOption('Config', 'start_mode', 'ffa')
nextmap_response = config.getOption('Config', 'nextmap_response', 'The next map is ${blue}${mapname}')
map_modes = config.getAllOptions('Maps')
del config
nextmap_response = string.Template(nextmap_response)

class Map:
	def __init__(self, name, mode):
		self.name = name
		self.mode = mode

def getSuccessor(mode_num, map):
	try:
		maps = modeMapLists[modes[mode_num]]
		if map == '':
			return maps[0]
		else:
			ndx = maps.index(map)
	except ValueError:
Esempio n. 46
0
import sbserver
from xsbs.commands import registerCommandHandler
from xsbs.settings import PluginConfig
from xsbs.colors import green, white
import urllib2

cmd_name = 'mytime'
config = PluginConfig(cmd_name)
timezone = config.getOption('Config', 'timezone', 'EST')

def onCommand(cn, command):
     for i in urllib2.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl'):
          if 'EST' in i:
               sbserver.playerMessage(cn, green('The Eastern Standard Time is: ') + white(i))

registerCommandHandler(cmd_name, onCommand)

Esempio n. 47
0
import sbserver

from sqlalchemy import Column, Integer, String, Boolean, ForeignKey
from sqlalchemy.orm import relation
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.exc import NoResultFound

from xsbs.events import registerServerEventHandler
from xsbs.ui import error, info, insufficientPermissions
from xsbs.colors import colordict
from xsbs.settings import PluginConfig
from xsbs.db import dbmanager
import string

config = PluginConfig('userprivilege')
tablename = config.getOption('Config', 'tablename', 'userprivileges')
authtemp = config.getOption('Messages', 'authenticated', '${green}${name}${white} authenticated as ${magenta}${authname}')
gmtemp = config.getOption('Messages', 'gain_master', '${green}${name}${white} claimed ${red}master')
gatemp = config.getOption('Messages', 'gain_admin', '${green}${name}${white} claimed ${red}admin')
rmtemp = config.getOption('Messages', 'release_master', '${green}${name}${white} relinquished ${red}master')
ratemp = config.getOption('Messages', 'release_admin', '${green}${name}${white} relinquished ${red}admin')
del config
authtemp = string.Template(authtemp)
gmtemp = string.Template(gmtemp)
gatemp = string.Template(gatemp)
rmtemp = string.Template(rmtemp)
ratemp = string.Template(ratemp)

Base = declarative_base()
session = dbmanager.session()
Esempio n. 48
0
File: notk.py Progetto: pguenth/xsbs
from Bans.bans import ban
from xsbs.settings import PluginConfig
from xsbs.events import registerServerEventHandler
from xsbs.players import player
from xsbs.ui import warning
from xsbs.colors import colordict
import string

config = PluginConfig('notk')
limit = int(config.getOption('Config', 'teamkill_limit', '5'))
duration = int(config.getOption('Config', 'ban_time', '3600'))
warn_tk_limit = config.getOption('Config', 'warn_tk_limit', 'no') == 'yes'
warn_tk_message = config.getOption(
    'Config', 'warn_tk_message',
    'This server does not allow more than ${red}${limit}${white} teamkills per game'
)
del config
warn_tk_message = string.Template(warn_tk_message)


def onTeamkill(cn, tcn):
    try:
        if player(cn).teamkills() >= limit:
            ban(cn, duration, 'killing teammates', -1)
        elif warn_tk_limit and player(cn).teamkills() == 1:
            player(cn).message(
                warning(warn_tk_message.substitute(colordict, limit=limit)))
    except KeyError:
        pass

Esempio n. 49
0
from twisted.words.protocols import irc
from twisted.internet import reactor, protocol

from xsbs.settings import PluginConfig, NoOptionError
from xsbs.events import registerServerEventHandler
from xsbs.timers import addTimer
from xsbs.server import message
from xsbs.colors import colordict

import sbserver
import string

config = PluginConfig('ircbot')
enable = config.getOption('Config', 'enable', 'no') == 'yes'
channel = config.getOption('Config', 'channel', '#xsbs-newserver')
servername = config.getOption('Config', 'servername', 'irc.gamesurge.net')
nickname = config.getOption('Config', 'nickname', 'xsbs-newbot')
port = int(config.getOption('Config', 'port', '6667'))
part_message = config.getOption('Config', 'part_message', 'XSBS - eXtensible SauerBraten Server')
msg_gw = config.getOption('Abilities', 'message_gateway', 'yes') == 'yes'
irc_msg_temp = string.Template(config.getOption('Templates', 'irc_message', '${grey}${channel} ${blue}${name}${white}: ${message}'))
status_message = config.getOption('Templates', 'status_message', '${num_clients} clients on map ${map_name}')
try:
	ipaddress = config.getOption('Config', 'ipaddress', None, False)
except NoOptionError:
	ipaddress = None
ircchannel = channel

class IrcBot(irc.IRCClient):
	def connectionMade(self):
		self.nickname = self.factory.nickname
Esempio n. 50
0
import sbserver
from xsbs.colors import colordict
from xsbs.ui import info, notice, error
from xsbs.events import registerPolicyEventHandler, registerServerEventHandler
from xsbs.players import player, masterRequired
from xsbs.settings import PluginConfig
from xsbs.commands import commandHandler, UsageError, StateError, ArgumentValueError
import string

config = PluginConfig('mute')
muted_temp = config.getOption('Messages', 'muted_message', '${green}${muted_name}${white} has been ${red}muted ${white}(by ${blue}${muter}${white})')
unmuted_temp = config.getOption('Messages', 'unmuted_message', '${green}${muted_name}${white} has been ${red}unmuted ${white}(by ${blue}${muter}${white})')
del config
muted_temp = string.Template(muted_temp)
unmuted_temp = string.Template(unmuted_temp)
mute_spectators = [False]

def allowMsg(cn, text):
	try:
		p = player(cn)
		if mute_spectators[0] == True and p.isSpectator():
			p.message(notice('Spectators are currently muted.  No one will recieve your message'))
			return False
		if p.is_muted:
			p.message(notice('You are currently muted.  No one will recieve your message'))
			return False
	except (AttributeError, ValueError):
		pass
	return True

@commandHandler('mutespectators')
Esempio n. 51
0
from xsbs.events import eventHandler
from xsbs.timers import addTimer
from xsbs.settings import PluginConfig
from xsbs.ui import error, notice, warning
from Bans.bans import ban
from xsbs.colors import colordict
from xsbs.players import player, all as allPlayers, playerByName, playerByIpString
import sbserver
import time
import string

config = PluginConfig('nospam')
interval = 			int(config.getOption('Config', 'action_interval', '5'))
max_per_interval = 	int(config.getOption('Config', 'max_msgs', '6'))
max_per_second = 	int(config.getOption('Config', 'max_msgs_per_sec', '3'))
ban_duration = 		int(config.getOption('Config', 'ban_time', '3600'))
warnings = 			int(config.getOption('Config', 'warnings', '2'))
warn_spam_message = config.getOption('Config', 'warn_spam_message', 'Warning do not spam. This server is ${red}spam intolerant!${white} ')
del config
warn_spam_message = string.Template(warn_spam_message)

class ChatLog:
	def __init__(self):
		self.log = {}
	
	def add_chat(self, cn, text):
		speakin = player(cn)
		ip = speakin.ipString()
		self.log[time.time()] = (cn, ip, text)
		
	def clean_chat(self):
Esempio n. 52
0
from xsbs.settings import PluginConfig
from xsbs.colors import colordict
from xsbs.ui import info
from xsbs.events import eventHandler
from xsbs.net import ipLongToString
from xsbs.server import message as serverMessage
from xsbs.players import player

import string
import pygeoip

db = pygeoip.GeoIP('GeoIp/GeoIP.dat')

conf = PluginConfig('geoip')
template = '${green}${user}${white} connected from ${orange}${country}'
template = conf.getOption('Config', 'template', template)
del conf

def getCountry(ip):
	country = db.country_name_by_addr(ipLongToString(ip))
	if country == '':
		country = 'Unknown'
	return country

@eventHandler('player_connect_delayed')
def announce(cn):
	p = player(cn)
	msg = string.Template(template).substitute(colordict, user=p.name(), country=getCountry(p.ipLong()))
	serverMessage(info(msg))

Esempio n. 53
0
from Bans.bans import ban
from xsbs.settings import PluginConfig
from xsbs.events import registerServerEventHandler
from xsbs.players import player
from xsbs.ui import warning
from xsbs.colors import colordict
import string

config = PluginConfig('notk')
limit = int(config.getOption('Config', 'teamkill_limit', '5'))
duration = int(config.getOption('Config', 'ban_time', '3600'))
warn_tk_limit = config.getOption('Config', 'warn_tk_limit', 'no') == 'yes'
warn_tk_message = config.getOption('Config', 'warn_tk_message', 'This server does not allow more than ${red}${limit}${white} teamkills per game')
del config
warn_tk_message = string.Template(warn_tk_message)

def onTeamkill(cn, tcn):
	try:
		if player(cn).teamkills() >= limit:
			ban(cn, duration, 'killing teammates', -1)
		elif warn_tk_limit and player(cn).teamkills() == 1:
			player(cn).message(warning(warn_tk_message.substitute(colordict, limit=limit)))
	except KeyError:
		pass

registerServerEventHandler('player_teamkill', onTeamkill)

Esempio n. 54
0
File: demo.py Progetto: pguenth/xsbs
import sbserver
from xsbs.commands import commandHandler, UsageError
from xsbs.events import eventHandler
from xsbs.ui import info, notice
from xsbs.settings import PluginConfig
from xsbs.colors import colordict
from xsbs.players import player, masterRequired, adminRequired, isUserAdmin, isUserAtLeastMaster
from xsbs.ui import insufficientPermissions
import string
import logging

config = PluginConfig('demorecord')
action_temp = config.getOption('Config', 'record_next_message', 'Demo recording is ${action} for next match (by ${orange}${user}${white}${white}${white}${white})')
persistent_recording = config.getOption('Config', 'persistent_recording', 'no') == 'yes'
required_permissions = config.getOption('Config', 'required_permissions', 'master')
del config
action_temp = string.Template(action_temp)
if required_permissions == 'user':
	required_permissions = 0
elif required_permissions == 'master':
	required_permissions = 1
elif required_permissions == 'admin':
	required_permissions = 2
else:
	logging.error('invalid required_permissions')
	required_permissions = 1

def permissions_ok(cn):
	if required_permissions == 0:
		return True
	p = player(cn)
Esempio n. 55
0
File: ctl.py Progetto: pguenth/xsbs
from xsbs.colors import red, yellow, blue, green, white, colordict
from xsbs.plugins import reloadPlugins
from xsbs.ui import error, info, notice, insufficientPermissions
from xsbs.net import ipLongToString
from xsbs.users import loggedInAs
from xsbs.users.privilege import isUserMaster, isUserAdmin, UserPrivilege
from xsbs.players import masterRequired, adminRequired, player, currentAdmin
from xsbs.server import setPaused, message as sendServerMessage
from xsbs.db import dbmanager
from xsbs.timers import addTimer

from Motd.motd import motdstring
import string

config = PluginConfig('servercommands')
servermsg_template = config.getOption('Templates', 'servermsg', '${orange}${sender}${white}: ${message}')
pm_template = config.getOption('Templates', 'pm', '${orange}${sender}${white}: ${message}')
smite_template = config.getOption('Templates', 'smite', '${green}${smited}${white} has been smited by ${orange}${smiter}')
resume_timeout = int(config.getOption('Config', 'resume_timeout', 5))
del config
servermsg_template = string.Template(servermsg_template)
pm_template = string.Template(pm_template)
smite_template = string.Template(smite_template)

session = dbmanager.session()

@commandHandler('pause')
@masterRequired
def onPauseCmd(cn, args):
	'''@description Pause the game
	   @usage'''