コード例 #1
0
ファイル: arkupdater.py プロジェクト: cosmicc/pyark
async def asynccheckwipe(instances):
    global dwtimer
    for inst in instances:
        log.trace(f"running checkwipe for {inst}")
        lastwipe = await asyncgetlastwipe(inst)
        if Now() - lastwipe > Secs["12hour"] and await instancevar.getbool(
                inst, "islistening"):
            oplayers = await asyncgetliveplayersonline(inst)
            if oplayers["activeplayers"] == 0 and await asyncgetplayersonline(
                    inst, fmt="count") == 0:
                log.log(
                    "WIPE",
                    f"Dino wipe needed for [{inst.title()}], server is empty, wiping now",
                )
                await asyncwritechat(
                    inst,
                    "ALERT",
                    f"### Empty server is over 12 hours since wild dino wipe. Wiping now.",
                    wcstamp(),
                )
                asyncio.create_task(asyncwipeit(inst))
                await instancevar.set(inst, "last12hourannounce", Now())
            else:
                if Now() - await instancevar.getint(
                        inst, "last12hourannounce") > 3600:
                    await instancevar.set(inst, "last12hourannounce", Now())
                    log.log(
                        "WIPE",
                        f"12 Hour dino wipe needed for [{inst.title()}], but players are online. Waiting...",
                    )
                    bcast = f"""<RichColor Color="0.0.0.0.0.0"> </>\n\n<RichColor Color="1,0.65,0,1">         It has been 12 hours since this server has had a wild dino wipe</>\n\n<RichColor Color="1,1,0,1">               Consider doing a</><RichColor Color="0,1,0,1">!vote </><RichColor Color="1,1,0,1">for fresh new dino selection</>\n\n<RichColor Color="0.65,0.65,0.65,1">     A wild dino wipe does not affect tame dinos that are already knocked out</>"""
                    await asyncserverbcast(inst, bcast)
        elif Now() - lastwipe > Secs["day"] and await instancevar.getbool(
                inst, "islistening"):
            log.log(
                "WIPE",
                f"Dino wipe needed for [{inst.title()}], players online but forced, wiping now",
            )
            bcast = f"""<RichColor Color="0.0.0.0.0.0"> </>\n\n<RichColor Color="1,0.65,0,1">         It has been 24 hours since this server has had a wild dino wipe</>\n\n<RichColor Color="1,1,0,1">               Forcing a maintenance wild dino wipe in 10 seconds</>\n\n<RichColor Color="0.65,0.65,0.65,1">     A wild dino wipe does not affect tame dinos that are already knocked out</>"""
            await asyncserverbcast(inst, bcast)
            await asyncio.sleep(10)
            await asyncwritechat(
                inst,
                "ALERT",
                f"### Server is over 24 hours since wild dino wipe. Forcing wipe now.",
                wcstamp(),
            )
            asyncio.create_task(asyncwipeit(inst))
            dwtimer = 0
        else:
            log.trace(f"no dino wipe is needed for {inst}")
コード例 #2
0
async def asyncleavingplayerwatch(player, inst):
    log.debug(
        f'Player [{player["playername"].title()}] Waiting on transfer from [{inst.title()}]'
    )
    starttime = time()
    stop_watch = False
    transferred = False
    while time() - starttime < 250 and not stop_watch:
        queryplayer = await db.fetchone(
            f"SELECT * FROM players WHERE steamid = '{player['steamid']}'"
        )
        if queryplayer["server"] != inst:
            fromtxt = f'{player["playername"].title()} has transferred here from {inst.title()}'
            totxt = f'{player["playername"].title()} has transferred to {queryplayer["server"].title()}'
            await asyncserverchat(inst, totxt)
            await asyncwriteglobal(queryplayer["server"].lower(), "ALERT", fromtxt)
            await asyncwritechat(
                inst,
                "ALERT",
                f'>><< {player["playername"].title()} has transferred from {inst.title()} to {queryplayer["server"].title()}',
                wcstamp(),
            )
            log.log(
                "XFER",
                f'Player [{player["playername"].title()}] has transfered from [{inst.title()}] to [{queryplayer["server"].title()}]',
            )
            transferred = True
            stop_watch = True
            await globalvar.remlist(f"{inst}-leaving", player["steamid"])
        await asyncio.sleep(2)

    if not transferred and time() - int(queryplayer["lastseen"]) >= 250:
        steamid = player["steamid"]
        await db.update(
            f"UPDATE players SET online = False, welcomeannounce = True, refreshsteam = True, refreshauctions = True WHERE steamid = '{steamid}'"
        )
        log.log(
            "LEAVE",
            f'Player [{player["playername"].title()}] left the cluster from [{inst.title()}]',
        )
        mtxt = f'{player["playername"].title()} has logged off the cluster'
        await asyncserverchat(inst, mtxt)
        await globalvar.remlist(f"{inst}-leaving", player["steamid"])
    nplayer = await db.fetchone(
        f"""SELECT * FROM players where steamid = '{player["steamid"]}'"""
    )
    if player["homeserver"] != inst:
        if not nplayer["online"] or (nplayer["online"] and nplayer["server"] != inst):
            command = f'tcsar setarctotal {player["steamid"]} 0'
            await asyncserverscriptcmd(inst, command)
    return True
コード例 #3
0
async def asyncwipeprep(inst):
    yesvoters = howmanyvotes()
    totvoters = len(globvars.votertable)
    log.log(
        "VOTE",
        f"YES has won ({yesvoters}/{totvoters}), wild dinos are wiping on [{inst.title()}] in 10 seconds",
    )
    bcast = f"""<RichColor Color="0.0.0.0.0.0"> </>\r\r<RichColor Color="1,0.65,0,1">                     A Wild dino wipe vote has finished</>\n<RichColor Color="0,1,0,1">                     YES votes have won! ('{yesvoters}' of '{totvoters}' Players)</>\n\n  <RichColor Color="1,1,0,1">               !! WIPING ALL WILD DINOS IN 10 SECONDS !!</>"""
    await asyncserverbcast(inst, bcast)
    await asyncwritechat(
        inst,
        "ALERT",
        f"A wild dino wipe vote has won by YES vote ({yesvoters}/{totvoters}). Wiping wild dinos now.",
        wcstamp(),
    )
    await asyncio.sleep(5)
    asyncio.create_task(asyncwipeit(inst))
    await asyncresetlastwipe(inst)
    return True
コード例 #4
0
async def asynccastedvote(inst, whoasked, myvote):
    if not globvars.isvoting:
        message = f"No vote is taking place now"
        await asyncserverchat(inst, message)
    else:
        steamid = await asyncgetsteamid(whoasked)
        if await asyncgetvote(whoasked) == 99:
            message = "Sorry, you are not eligible to vote in this round"
            await asyncserverchatto(inst, steamid, message)
        elif not steamid:
            message = "Sorry, you are not eligible to vote. Tell an admin they need to update your name!"
            await asyncserverchatto(inst, steamid, message)
        elif await asyncgetvote(whoasked) == 2:
            message = "You started the vote. you're assumed a YES vote."
            await asyncserverchatto(inst, steamid, message)
        elif await asyncgetvote(whoasked) == 1:
            message = "You have already voted YES. you can only vote once."
            await asyncserverchatto(inst, steamid, message)
        else:
            if myvote:
                await asyncsetvote(whoasked, 1)
                message = "Your YES vote has been cast"
                await asyncserverchatto(inst, steamid, message)
            else:
                await asyncsetvote(whoasked, 0)
                message = "Your NO vote has been cast"
                await asyncserverchatto(inst, steamid, message)
                log.log(
                    "VOTE",
                    f"Voting NO has won, NO wild dino wipe will be performed for {inst}",
                )
                globvars.isvoting = False
                bcast = f"""<RichColor Color="0.0.0.0.0.0"> </>\r<RichColor Color="1,0.65,0,1">                     A Wild dino wipe vote has finished</>\n\n<RichColor Color="1,1,0,1">                            NO votes have won!</>\n  <RichColor Color="1,0,0,1">                      Wild dinos will NOT be wiped</>\n\n           You must wait 10 minutes before you can start another vote"""
                await asyncserverbcast(inst, bcast)
                await asyncwritechat(
                    inst,
                    "ALERT",
                    f"### A wild dino wipe vote has failed with a NO vote from \
{whoasked.capitalize()}",
                    wcstamp(),
                )
コード例 #5
0
ファイル: players.py プロジェクト: cosmicc/pyark
async def asyncnewplayer(steamid: str, playername: str, inst: str):
    if steamid not in globvars.welcomes:
        globvars.welcomes.add(steamid)
        added = await db.update(
            f"INSERT INTO players (steamid, playername, lastseen, server, playedtime, rewardpoints, firstseen, connects, discordid, banned, totalauctions, itemauctions, dinoauctions, restartbit, primordialbit, homeserver, transferpoints, lastpointtimestamp, lottowins, welcomeannounce, online, steamlastlogoff, steamcreated, refreshauctions, refreshsteam, homemovepoints, lotterywinnings) VALUES ('{steamid}', '{playername.lower()}', '{Now()}', '{inst}', '0', '0', '{Now()}', '1', '', '', '0', '0', '0', '0', '0', '{inst}', '0', '{Now()}', '0', 'True', 'True', '0', '0', False, True, 0, 0)"
        )
        if added:
            log.log(
                "NEW",
                f"Player [{playername.title()}] on [{inst.title()}] was not found. Adding new player!",
            )
            log.debug(
                f"Sending welcome message to [{playername.title()}] on [{inst.title()}]"
            )
            await asyncio.sleep(3)
            message = "Welcome to the Ultimate Extinction Core Galaxy Server Cluster!"
            await asyncserverchatto(inst, steamid, message)
            await asyncio.sleep(3)
            message = "Rewards points earned as you play (and many other ways), Public teleporters, many public resource areas."
            await asyncserverchatto(inst, steamid, message)
            await asyncio.sleep(3)
            message = "Build a rewards vault, free starter items inside, thats where all the kits are"
            await asyncserverchatto(inst, steamid, message)
            await asyncio.sleep(3)
            message = "Press F1 or Discord at anytime for help. Careful out there, its a challenge. Have fun!"
            await asyncserverchatto(inst, steamid, message)
            await asyncio.sleep(3)
            message = (
                f"Everyone welcome new player {playername.title()} to the cluster!"
            )
            await asyncserverchat(inst, message)
            log.debug(
                f"welcome message complete for new player {steamid} on {inst}")
            await asyncwritechat(inst, "ALERT",
                                 f"<<< A New player has joined the cluster!",
                                 wcstamp())
            globvars.welcomes.remove(steamid)
    else:
        log.debug(f"welcome message already running for [{playername}]")
コード例 #6
0
async def asyncvoter(inst, whoasked):
    log.log(
        "VOTE",
        f"A wild dino wipe vote has started for [{inst.title()}] by [{whoasked.title()}]",
    )
    votercount = await asyncpopulatevoters(inst)
    await asyncsetvote(whoasked, 2)
    bcast = f"""<RichColor Color="0.0.0.0.0.0"> </>\r<RichColor Color="1,0.65,0,1">             A Wild dino wipe vote has started with {votercount} online players</>\n\n<RichColor Color="1,1,0,1">                 Vote now by typing</><RichColor Color="0,1,0,1"> !yes or !no</><RichColor Color="1,1,0,1"> in global chat</>\n\n         A wild dino wipe does not affect tame dinos already knocked out\n                    A single NO vote will cancel the wipe\n                           Voting lasts 3 minutes"""
    await asyncserverbcast(inst, bcast)
    asyncloop = asyncio.get_running_loop()
    globvars.votestarttime = asyncloop.time()
    await asyncwritechat(
        inst,
        "ALERT",
        f"### A wild dino wipe vote has been started by {whoasked.capitalize()}",
        wcstamp(),
    )
    warned = False
    while globvars.isvoting:
        await asyncio.sleep(5)
        if votingpassed() and globvars.isvoting:
            globvars.isvoting = False
            asyncio.create_task(asyncwipeprep(inst))
        elif asyncloop.time() - globvars.votestarttime > Secs["2min"]:
            if globvars.isvoting:
                globvars.isvoting = False
                asyncio.create_task(asyncwipeprep(inst))
        elif asyncloop.time() - globvars.votestarttime > 60 and not warned:
            warned = True
            log.log(
                "VOTE", f"Sending voting waiting message to vote on [{inst.title()}]"
            )
            bcast = f"""<RichColor Color="0.0.0.0.0.0"> </>\r\r<RichColor Color="1,0.65,0,1">         A Wild dino wipe vote is waiting for votes! ({howmanyvotes()} of {len(globvars.votertable)})</>\n\n<RichColor Color="1,1,0,1">                 Vote now by typing</><RichColor Color="0,1,0,1"> !yes or !no</><RichColor Color="1,1,0,1"> in global chat</>\n\n         A wild dino wipe does not affect tame dinos already knocked out\n                    A single NO vote will cancel the wipe"""
            await asyncserverbcast(inst, bcast)
    globvars.lastvoter = time()
    await asyncresetlastvote(inst)
    log.debug(f"voting task has ended on {inst}")
    return True
コード例 #7
0
async def playerjoin(line, inst):
    newline = line[:-17].split(":")
    player = await db.fetchone(
        f"SELECT * FROM players WHERE steamname = '{cleanstring(newline[1].strip())}'"
    )
    if player:
        if player["homeserver"] != inst:
            xferpointsdata = await db.fetchone(
                f"""SELECT * FROM transferpoints WHERE steamid = '{player["steamid"]}' and server = '{inst}'"""
            )
            if xferpointsdata:
                log.trace(f"xferpointsdata: {xferpointsdata}")
                command = (
                    f'tcsar setarctotal {player["steamid"]} {xferpointsdata["points"]}'
                )
                await asyncserverscriptcmd(inst, command)
        steamid = player["steamid"]
        await db.update(
            f"""UPDATE players SET online = True, refreshsteam = True, lastlogin = '******', lastseen = '{Now()}', refreshauctions = True, server = '{inst}', connects = {player["connects"] + 1} WHERE steamid = '{steamid}'"""
        )
        if Now() - player["lastseen"] > 250:
            log.log(
                "JOIN",
                f'Player [{player["playername"].title()}] joined the cluster on [{inst.title()}] Connections: {player["connects"] + 1}',
            )
            message = f'{player["playername"].title()} has joined the server'
            await asyncserverchat(inst, message)
            await asyncwritechat(
                inst,
                "ALERT",
                f'<<< {player["playername"].title()} has joined the server',
                wcstamp(),
            )
    else:
        log.debug(
            f"player [{cleanstring(newline[1].strip())}] joined that is not found in database"
        )
コード例 #8
0
ファイル: timehelper_test.py プロジェクト: cosmicc/pyark
def test_wcstamp():
    assert type(timehelper.wcstamp()) is str
コード例 #9
0
ファイル: arkupdater.py プロジェクト: cosmicc/pyark
async def asyncrestartloop(inst, startonly=False):
    checkdirs(inst)
    if not await instancestate.check(
            inst, "restartwaiting") and not await instancestate.check(
                inst, "restarting"):
        log.debug(f"{inst} restart loop has started")
        if startonly:
            asyncio.create_task(asyncrestartinstnow(inst, startonly=True))
        asyncio.sleep(1)
        if not await instancestate.check(
                inst, "restartwaiting") and not await instancestate.check(
                    inst, "restarting"):
            instdata = await db.fetchone(
                f"SELECT * from instances WHERE name = '{inst}'")
            timeleft = int(instdata["restartcountdown"])
            reason = instdata["restartreason"]
            if (await instancevar.getint(inst, "playersconnected") == 0
                    and await instancevar.getint(inst, "playersactive") == 0
                    and await instancevar.getint(inst, "playersonline") == 0):
                await instancestate.set(inst, "restartwaiting")
                await asyncsetrestartbit(inst)
                log.log(
                    "UPDATE",
                    f"Server [{inst.title()}] is empty and restarting now for a [{reason}]",
                )
                await asyncwritechat(
                    inst,
                    "ALERT",
                    f"!!! Empty server restarting now for a {reason.capitalize()}",
                    wcstamp(),
                )
                message = f"server {inst.capitalize()} is restarting now for a {reason}"
                await asyncserverexec(
                    ["arkmanager", f'notify "{message}"', f"@{inst}"])
                await pushoversend("Instance Restart", message)
                asyncio.create_task(asyncrestartinstnow(inst))
                await asyncio.sleep(1)
            if (reason != "configuration update"
                    and not await instancestate.check(inst, "restartwaiting")
                    and not await instancestate.check(inst, "restarting")):
                await asyncsetrestartbit(inst)
                if timeleft == 30:
                    log.log(
                        "UPDATE",
                        f"Starting 30 min restart countdown for [{inst.title()}] for a [{reason}]",
                    )
                    await asyncwritechat(
                        inst,
                        "ALERT",
                        f"!!! Server will restart in 30 minutes for a {reason.capitalize()}",
                        wcstamp(),
                    )
                else:
                    log.log(
                        "UPDATE",
                        f"Resuming {timeleft} min retart countdown for [{inst.title()}] for a [{reason}]",
                    )
                await instancestate.set(inst, "restartwaiting")
                while (await asyncstillneedsrestart(inst)
                       and await instancevar.getint(inst, "playersactive") != 0
                       and timeleft != 0 and
                       await instancevar.getint(inst, "playersonline") != 0):
                    if (timeleft == 30 or timeleft == 15 or timeleft == 10
                            or timeleft == 5 or timeleft == 1):
                        log.log(
                            "UPDATE",
                            f"{timeleft} min broadcast message sent to [{inst.title()}]",
                        )
                        bcast = f"""<RichColor Color="0.0.0.0.0.0"> </>\n<RichColor Color="1,0,0,1">                 The server has an update and needs to restart</>\n                       Restart reason: <RichColor Color="0,1,0,1">{reason}</>\n\n<RichColor Color="1,1,0,1">                   The server will be restarting in</><RichColor Color="1,0,0,1">{timeleft}</><RichColor Color="1,1,0,1"> minutes</>"""
                        await asyncserverbcast(inst, bcast)
                    await asyncio.sleep(Secs["1min"])
                    timeleft = timeleft - 1
                    if (await instancevar.getint(inst, "playersonline") == 0
                            and await instancevar.getint(
                                inst, "playersactive") == 0):
                        timeleft = 0
                    await asyncupdatetimer(inst, timeleft)
                if await asyncstillneedsrestart(inst):
                    log.log(
                        "UPDATE",
                        f"Server [{inst.title()}] is restarting now for a [{reason}]",
                    )
                    message = (
                        f"server {inst.capitalize()} is restarting now for a {reason}"
                    )
                    bcast = f"""<RichColor Color="0.0.0.0.0.0"> </>\n<RichColor Color="1,0,0,1">                 The server has an update and needs to restart</>\n                       Restart reason: <RichColor Color="0,1,0,1">Ark Game Update</>\n\n<RichColor Color="1,1,0,1">                     !! THE SERVER IS RESTARTING</><RichColor Color="1,0,0,1">NOW</><RichColor Color="1,1,0,1"> !!</>\n\n     The server will be back up in 10 minutes, you can check status in Discord"""
                    await asyncserverbcast(inst, bcast)
                    await asyncwritechat(
                        inst,
                        "ALERT",
                        f"!!! Server restarting now for {reason.capitalize()}",
                        wcstamp(),
                    )
                    await asyncservernotify(inst, message)
                    await pushoversend("Instance Restart", message)
                    await asyncio.sleep(10)
                    asyncio.create_task(asyncrestartinstnow(inst))
                else:
                    log.warning(
                        f"server restart on {inst} has been canceled from forced cancel"
                    )
                    bcast = f"""<RichColor Color="0.0.0.0.0.0"> </>\n\n\n<RichColor Color="1,1,0,1">                    The server restart has been cancelled!</>"""
                    await instancestate.unset(inst, "restartwaiting")
                    await asyncserverbcast(inst, bcast)
                    await asyncwritechat(
                        inst,
                        "ALERT",
                        f"!!! Server restart for {reason.capitalize()} has been canceled",
                        wcstamp(),
                    )
            elif (reason == "configuration update"
                  and not await instancestate.check(inst, "restartwaiting")
                  and not await instancestate.check(inst, "restarting")):
                log.debug(
                    f"configuration restart skipped because of active players")