# Banter plugin for Deathrun Mod v 1.5
# Visit our DeathRun Server 188.134.21.171:27015
# Visit our site www.tk-portal.ru

import es, gamethread, random

player = {}

deathrun_timeban = es.ServerVar("deathrun_timeban")

def load():
    es.server.cmd("es_xmexec ../addons/eventscripts/deathrun/deathrun.cfg")
    for userid in es.getUseridList():
        player[str(userid)] = 0

def unload():
    player.clear()

def es_map_start(event_var): 
    es.server.cmd("es_xmexec ../addons/eventscripts/deathrun/deathrun.cfg")

def player_activate(ev):
    userid = ev['userid']
    if userid not in player:
        player[userid] = 0

def player_team(ev):
    player[ev['userid']] = int(ev['team'])

def player_disconnect(ev):
    userid = ev['userid']
    if player[userid] == 2 and ev['reason'] == 'Disconnect by user.':
        if es.getplayercount() > 1:
            steam = ev['networkid']
            if steam != 'BOT':
                es.server.queuecmd('banid %s %s ;writeid' %(str(deathrun_timeban),steam))
    del player[userid]

def round_start(event_var):
    gamethread.delayedname(20, 'noexit', noexit)

def noexit():
    if random.randint(1,5) == 5:
        es.msg('#multi','#greenPlease do not leave the server, playing for the terrorists, or you will be banned for %s minutes!'%str(deathrun_timeban))

def round_end(event_var):
    gamethread.cancelDelayed('noexit')

