Exemplo n.º 1
0
def gettribesplayers(tribeid, fmt="steamids"):
    players = dbquery(
        f"SELECT players FROM tribes WHERE tribeid = '{tribeid}'",
        fetch="one",
        single=True,
    )
    if players[0] is not None:
        if fmt == "steamids":
            return players[0]
        elif fmt == "names" or fmt == "playernames":
            playerlist = ""
            for player in players[0]:
                playername = dbquery(
                    f"SELECT playername FROM players WHERE steamid = '{player}'",
                    fetch="one",
                    single=True,
                )
                if playerlist == "":
                    playerlist = playername[0]
                else:
                    playerlist = playerlist + f", {playername[0]}"
            return playerlist
        else:
            return None
    else:
        return None
Exemplo n.º 2
0
def getmessages(steamid, sent=False, fmt="dict"):
    if sent:
        return dbquery("SELECT * FROM messages WHERE from_player = '%s'" %
                       (steamid, ),
                       fmt=fmt)
    else:
        return dbquery("SELECT * FROM messages WHERE to_player = '%s'" %
                       (steamid, ),
                       fmt=fmt)
Exemplo n.º 3
0
 def ui_getmessages(steamid, fmt, sent=False):
     if not sent:
         return dbquery(
             "SELECT * FROM messages WHERE to_player = '%s'" % (steamid,), fmt=fmt
         )
     else:
         return dbquery(
             "SELECT * FROM messages WHERE from_player = '%s'" % (steamid,), fmt=fmt
         )
Exemplo n.º 4
0
 def ui_getplayer(playername, steamid=False):
     if not steamid:
         return dbquery(
             "SELECT * FROM players WHERE playername = '%s'" % (playername,),
             fmt="dict",
             fetch="one",
         )
     else:
         return dbquery(
             "SELECT * FROM players WHERE steamid = '%s'" % (playername,),
             fmt="dict",
             fetch="one",
         )
Exemplo n.º 5
0
 def format(self, value):
     linfo = dbquery(
         "SELECT date FROM %s WHERE value != 0 ORDER BY date DESC LIMIT 1" %
         (value, ),
         db="statsdb",
     )
     return elapsedTime(time.time(), int(linfo[0]))
Exemplo n.º 6
0
 def format(self, value):
     linfo = dbquery(
         "SELECT timestamp, lengthdays from lotteryinfo WHERE id = '%s'" %
         (value, ))
     endtime = float(linfo[0]) + (3600 * linfo[1])
     endtime = datetime.fromtimestamp(endtime)
     return estshift(endtime).strftime("%a %b %-d %-I:%M %p")
Exemplo n.º 7
0
def getallhighest(length, statsinst):
    if length == "daily":
        ilength = 86400
    elif length == "weekly":
        ilength = 604800
    elif length == "monthly":
        ilength = 2592000
    elif length == "hourly":
        ilength = 3600
    elif length == "eighthour":
        ilength = 28800
    avglist = []
    ntime = int(time.time())
    for each in statsinst:
        slist = []
        navglist = []
        dlist = []
        datelist = []
        nlist = dbquery(
            "SELECT value, date FROM %s WHERE date > '%s'" %
            (each, ntime - ilength),
            db="statsdb",
        )
        for y, x in nlist:
            slist.append(y)
            dlist.append(x)
        if avglist == []:
            avglist = slist
            datelist = dlist
        else:
            navglist = [sum(pair) for pair in zip(slist, avglist)]
            avglist = navglist
            datelist = dlist
    nt = datetime.fromtimestamp(datelist[avglist.index(max(avglist))])
    return max(avglist), estshift(nt).strftime("%a %b %-d %-I:%M %p")
Exemplo n.º 8
0
def serverstatus(inst):
    nlist = dbquery("SELECT isup FROM instances WHERE name = '%s'" % (inst, ),
                    fetch="one")
    if nlist[0] == 1:
        return "Online"
    elif nlist[0] == 0:
        return "Offline"
Exemplo n.º 9
0
def getplayer(steamid="", discordid="", playername="", fmt="tuple"):
    if steamid != "":
        dbdata = dbquery("SELECT * FROM players WHERE steamid = '%s'" %
                         (steamid, ),
                         fetch="one")
    elif playername != "":
        dbdata = dbquery(
            "SELECT * FROM players WHERE playername = '%s' or alias = '%s'" %
            (playername, playername),
            fetch="one",
        )
    elif discordid != "":
        dbdata = dbquery("SELECT * FROM players WHERE discordid = '%s'" %
                         (discordid, ),
                         fetch="one")
    return formatdbdata(dbdata, "players", qtype=fmt, single=True)
Exemplo n.º 10
0
def getexpiredplayers():
    return dbquery(
        "SELECT playername FROM players WHERE banned = '' AND lastseen < '%s' ORDER BY playername ASC"
        % (Now() - Secs["month"], ),
        fmt="list",
        single=True,
    )
Exemplo n.º 11
0
def getactiveplayers(atime):
    return dbquery(
        "SELECT playername FROM players WHERE banned = '' AND lastseen >= '%s' and playedtime > 15 and connects > 1 ORDER BY playername ASC"
        % (Now() - atime, ),
        fmt="list",
        single=True,
    )
Exemplo n.º 12
0
def getnewplayers(atime):
    return dbquery(
        "SELECT steamid, playername FROM players WHERE banned = '' AND firstseen >= '%s' ORDER BY playername ASC"
        % (Now() - atime, ),
        fmt="tuple",
        single=True,
    )
Exemplo n.º 13
0
def gethitnruns(atime):
    return dbquery(
        "SELECT playername FROM players WHERE banned = '' AND lastseen >= '%s' and playedtime < 15 and connects = 1 ORDER BY playername ASC"
        % (Now() - Secs["week"], ),
        fmt="list",
        single=True,
    )
Exemplo n.º 14
0
    def get(self):
        global apilog
        instr = dbquery("SELECT name from instances")
        cluster = {}
        statsinst = []
        np, oplayers = howmanyonline()
        cluster["numberonline"] = np
        cluster["lastplayeronline"] = whenlastplayerall()
        cluster["playersonline"] = oplayers
        cluster["newplayers"] = {
            "lastday": newplayers("daily"),
            "lastweek": newplayers("weekly"),
            "lastmonth": newplayers("monthly"),
        }
        cluster["inlottery"] = isinlottery()
        for each in instr:
            nap = {}
            nt, ny = howmanyonlinesvr(each[0])
            nap = {
                "name": each[0],
                "status": serverstatus(each[0]),
                "numberonline": nt,
                "lastplayeronline": whenlastplayersvr(each[0]),
                "playersonline": ny,
            }
            statsinst.append(nap)
        if not iseventtime():
            cluster["inevent"] = "false"
        else:
            eventinfo = getcurrenteventinfo()
            cluster["inevent"] = "true"
            cluster["eventtitle"] = eventinfo[4]
        cluster["instances"] = statsinst

        return (cluster), 201
Exemplo n.º 15
0
def startevent():
    if request.method == "POST":
        eventname = request.form["eventname"]
        startdate = request.form["startdate"].split(" GMT")[0]
        enddate = request.form["enddate"].split(" GMT")[0]
        edate = datetime.strptime(enddate, "%a %b %d %Y %H:%M:%S").date()
        sdate = datetime.strptime(startdate, "%a %b %d %Y %H:%M:%S").date()
        einfo = dbquery(
            "SELECT * FROM autoevents WHERE title = '%s'" % (eventname,),
            fmt="dict",
            fetch="one",
        )
        dbupdate(
            "INSERT INTO events (completed, starttime, endtime, title, description, cfgfilesuffix) VALUES (0, '%s', '%s', '%s', '%s', '%s')"
            % (
                sdate,
                edate,
                einfo["title"],
                einfo["description"],
                einfo["cfgfilesuffix"],
            )
        )
        flash("New Event Added")
        return redirect(url_for("webui._events"))
    return render_template("startevent.html", autoevents=getautoevents())
Exemplo n.º 16
0
def getfutureevent():
    return dbquery(
        "SELECT * FROM events WHERE completed = 0 AND (starttime > '%s' OR starttime = '%s') ORDER BY endtime ASC"
        % (Now(fmt="dtd"), Now(fmt="dtd")),
        fmt="dict",
        fetch="one",
    )
Exemplo n.º 17
0
 def ui_getinstcp(inst):
     return dbquery(
         "SELECT connectingplayers FROM instances WHERE name = '%s'"
         % (inst.lower(),),
         fmt="string",
         fetch="one",
     )
Exemplo n.º 18
0
def getcurrentevent():
    return dbquery(
        "SELECT * FROM events WHERE completed = 0 AND starttime <= '%s'"
        % (Now(fmt="dtd"),),
        fmt="dict",
        fetch="one",
    )
Exemplo n.º 19
0
 def post(self):
     afetch = dbquery(
         "SELECT * FROM lotteryinfo WHERE winner == 'Incomplete'")
     if not afetch:
         try:
             bip = api.payload["buyinpoints"] * 10
             lottoends = datetime.fromtimestamp(time.time() + (
                 3600 *
                 int(api.payload["length"]))).strftime("%a, %b %d %I:%M%p")
             dbupdate(
                 "INSERT INTO lotteryinfo (type,payoutitem,timestamp,buyinpoints,lengthdays,players,winner) VALUES ('%s','%s','%s','%s','%s',0,'Incomplete')"
                 % (
                     "points",
                     bip,
                     time.time(),
                     api.payload["buyinpoints"],
                     api.payload["length"],
                 ))
             return {
                 "message": "Lottery Started",
                 "payout": bip,
                 "buyinpoints": api.payload["buyinpoints"],
                 "lotterylength": api.payload["length"],
                 "lotteryends": lottoends,
             }
         except:
             return {"message": "Error starting lottery"}
     else:
         return {
             "message":
             "Error starting lottery. A lottery is already running"
         }
Exemplo n.º 20
0
 def ui_getrestartleft(inst):
     return dbquery(
         "SELECT restartcountdown FROM instances WHERE name = '%s'"
         % (inst.lower(),),
         fmt="string",
         fetch="one",
     )
Exemplo n.º 21
0
def getallavg(length, statsinst):
    if length == "daily":
        ilength = 86400
    elif length == "weekly":
        ilength = 604800
    elif length == "monthly":
        ilength = 2592000
    elif length == "hourly":
        ilength = 3600
    elif length == "eighthour":
        ilength = 28800
    avglist = []
    ntime = int(time.time())
    for each in statsinst:
        slist = []
        navglist = []
        nlist = dbquery(
            "SELECT value FROM %s WHERE date > '%s'" % (each, ntime - ilength),
            db="statsdb",
        )
        for y in nlist:
            slist.append(y[0])
        if avglist == []:
            avglist = slist
        else:
            navglist = [sum(pair) for pair in zip(slist, avglist)]
            avglist = navglist
    return f2dec(mean(avglist))
Exemplo n.º 22
0
 def post(self):
     pname = api.payload["playername"]
     steamid = api.payload["steamid"]
     if pname is not None or pname != "string":
         q_player = dbquery(
             "SELECT * FROM players WHERE playername = '%s'" % (pname, ))
     elif steamid is not None or steamid != 0:
         q_player = dbquery("SELECT * FROM players WHERE steamid = '%s'" %
                            (steamid, ))
     else:
         return {"message": "Must specify player name or steamid"}, 400
     if q_player is None:
         return {"message": "Player does not exist"}, 400
     else:
         nap = dict(zip(listcolums("players"), q_player))
         return (nap), 201
Exemplo n.º 23
0
def isplayeronline(playername="", steamid=""):
    if steamid != "":
        dbdata = dbquery(
            "SELECT playername FROM players WHERE steamid = '%s' AND online = True"
            % (steamid, ),
            fetch="one",
        )
    elif playername != "":
        dbdata = dbquery(
            "SELECT playername FROM players WHERE playername = '%s' AND online = True"
            % (playername, ),
            fetch="one",
        )
    if dbdata:
        return True
    else:
        return False
Exemplo n.º 24
0
def isplayerbanned(steamid="", playername=""):
    if steamid == "":
        isbanned = dbquery(
            "SELECT * FROM players WHERE banned != '' AND playername = '%s'" %
            (playername.lower(), ),
            fetch="one",
        )
    else:
        isbanned = dbquery(
            "SELECT * FROM players WHERE banned != '' AND steamid = '%s'" %
            (steamid, ),
            fetch="one",
        )
    if isbanned:
        return True
    else:
        return False
Exemplo n.º 25
0
def whenlastplayersvr(inst):
    linfo = dbquery(
        "SELECT date FROM %s WHERE value != 0 ORDER BY date DESC LIMIT 1" %
        (inst, ),
        db="statsdb",
        fetch="one",
    )
    return elapsedTime(time.time(), int(linfo[0]))
Exemplo n.º 26
0
 def get(self):
     nap = []
     pcnt = 0
     pps = dbquery("SELECT playername FROM players ORDER BY playername")
     for each in pps:
         pcnt += 1
         nap.append(each[0])
     return {"players": pcnt, "names": nap}
Exemplo n.º 27
0
def gettribes():
    tribes = dbquery(
        f"SELECT * FROM tribes ORDER BY tribename DESC",
        fetch="all",
        fmt="dict",
        single=True,
    )
    return tribes
Exemplo n.º 28
0
def gettribe(tribeid):
    tribe = dbquery(
        f"SELECT * FROM tribes WHERE tribeid = '{tribeid}'",
        fetch="one",
        fmt="dict",
        single=True,
    )
    return tribe
Exemplo n.º 29
0
 def get(self):
     nap = []
     qinst = dbquery("SELECT name FROM instances")
     scnt = 0
     for each in qinst:
         scnt += 1
         nap.append(each[0])
     return {"servers": scnt, "names": nap}
Exemplo n.º 30
0
def isplayerold(playername="", steamid=""):
    if steamid != "":
        dbdata = dbquery(
            "SELECT playername FROM players WHERE steamid = '%s' AND lastseen > '%s'"
            % (steamid, Now() - Secs["month"]),
            fetch="one",
        )
    elif playername != "":
        dbdata = dbquery(
            "SELECT playername FROM players WHERE playername = '%s' AND lastseen > '%s'"
            % (playername, Now() - Secs["month"]),
            fetch="one",
        )
    if dbdata:
        return False
    else:
        return True