Ejemplo n.º 1
0
def duel_end(id, current_players):
    p1 = id
    p2 = 0
    for x in current_players:
        if current_players[p1].opponent == x.name:
            break
        p2 += 1

    current_players[
        p1].opponent = "%%#"  #using this as an "empty" opponent since oone in-game can have "%" character in their name (game restriction)
    current_players[p1].in_duel = False
    difference = elo(current_players[p2].mmr, current_players[p1].mmr)
    loser_elo = current_players[p1].mmr - difference
    current_players[p1].mmr = round(loser_elo, 2)
    current_players[p1].losses += 1

    current_players[p2].opponent = "%%#"
    current_players[p2].in_duel = False
    old_mmr2 = current_players[p2].mmr
    winner_elo = current_players[p2].mmr + difference
    current_players[p2].mmr = round(winner_elo, 2)
    current_players[p2].wins += 1
    print(difference)

    #network.send_cmd("[" + current_players[p2].name +"^7(^2+" + str(difference) + "^7)"+ " has won the duel against " + current_players[p1].name+ "^7(^1-" + str(difference) + "^7)")
    network.send_cmd("svtell %s ^1-%s" %
                     (str(current_players[p1].id), str(round(difference, 2))))
    network.send_cmd("svtell %s ^2+%s" %
                     (str(current_players[p2].id), str(round(difference, 2))))
Ejemplo n.º 2
0
def say_duel(
    event_content, name, current_players
):  #custom "!duel [OPPONENT]" chat command, searches the current_players list for an opponent, duel is only started when two players have a matching opponent, this is obsolete now.
    pindex = searchby_name(name, current_players)
    if pindex == -1:
        network.send_cmd("svsay Client with \"" + str(name) +
                         "\" name is not initialized, please reconnect.")
        #cleanup
        del (pindex)
        return False
    try:
        query = event_content.split(
            "!duel ", 1
        )[1]  #Splits the chat event_content so you can get the name to search with
    except:
        print("Error processing [DUEL] chat command.")

    if not current_players[pindex].in_duel:
        print("Challenging to duel..")
        MMR.challenge_to_duel(current_players, pindex, query)

        #cleanup
        del (name, pindex, query)
        return True

    else:
        print("Challenger already in a duel.")

        #cleanup
        del (name, pindex, query)
        return False
Ejemplo n.º 3
0
def send_FCMD(name, tree):

    # FIXME: remove this quickfix
    if json.dumps(tree).find('DS_Store') != -1:
        return

    network.send_cmd('{} {}'.format(name, json.dumps(tree)))
Ejemplo n.º 4
0
def send_FCMD(name, tree):

    # FIXME: remove this quickfix
    if json.dumps(tree).find('DS_Store') != -1:
        return

    network.send_cmd('{} {}'.format(name, json.dumps(tree)))
Ejemplo n.º 5
0
def duel_start(p1, p2):

    current_players[p1].in_duel = True
    current_players[p2].in_duel = True
    network.send_cmd("svsay " + current_players[p1].name + "^7[^3" +
                     str(current_players[p1].mmr) + "^7]" + "  VS. " +
                     current_players[p2].name + "^7[^3" +
                     str(current_players[p2].mmr) + "^7]")
Ejemplo n.º 6
0
def duel_start_broadcast(p1, p2, current_players):

    current_players[p1].in_duel = True
    current_players[p2].in_duel = True
    network.send_cmd("svsay " + current_players[p1].name + "^7[^3" +
                     str(int(current_players[p1].mmr)) + "^7]" + "  VS. " +
                     current_players[p2].name + "^7[^3" +
                     str(int(current_players[p2].mmr)) + "^7]")
Ejemplo n.º 7
0
def say_chill(
    i
):  #custom !chill command, disables ranked dueling for the player that executes the command.
    current_players[i].chill = not current_players[i].chill
    if current_players[i].chill:
        network.send_cmd("svsay %s's ranked mode: ^1OFF" %
                         (current_players[i].name))
    else:
        network.send_cmd("svsay %s's ranked mode: ^2ON" %
                         (current_players[i].name))
Ejemplo n.º 8
0
def event_broadcast(
    event, event_content
):  #There's two useful things in the broadcast event. Player changing names, and the private duels are triggered through it.
    if "broadcast" in event:
        templine = event_content.strip().split("print ", 1)[1][
            0:
            -3]  #the broadcast event is formatted differently from all the others, containing 2 event descriptions as seen above
        if "@@@PLDUELACCEPT" in templine:  #Private duels
            print("Starting duel..")
            try:
                name1 = templine.split(" @@@PLDUELACCEPT ", 1)[0][1:].strip()
                name2 = templine.split(" @@@PLDUELACCEPT ",
                                       1)[1].strip().split("\\", 1)[0][:-1]
            except:
                print("Error getting the names, returning...")
                return True

            pindex1 = searchby_name(name1, current_players)
            pindex2 = searchby_name(name2, current_players)

            if pindex1 < 0 or pindex2 < 0:
                print(
                    "One or more players not found in current playerlist, returning..",
                    name1, name2)
                return True
            if current_players[pindex1].chill or current_players[pindex2].chill:
                network.send_cmd("svtell %s ^3Unranked duel." %
                                 (current_players[pindex1].id))
                network.send_cmd("svtell %s ^3Unranked duel." %
                                 (current_players[pindex2].id))
                return True

            if not current_players[pindex1].in_duel:
                if not current_players[pindex2].in_duel:
                    current_players[pindex1].opponent = name2
                    current_players[pindex2].opponent = name1
                    MMR.duel_start_broadcast(pindex1, pindex2, current_players)
                    return True
            return True

        if "@@@PLRENAME" in templine:  #Players changing names.
            try:
                name1 = templine.split(" @@@PLRENAME ",
                                       1)[0][1:-2].split("\\n", 1)[0]
                name2 = templine.split(" @@@PLRENAME ", 1)[1].strip()
                pindex = searchby_name(name1, current_players)
                current_players[pindex].name = name2
                print("success in changing name, [%s][%s]" % (name1, name2))
                return True
            except:
                print("Error in name change, returning..")
                return True
    return False
Ejemplo n.º 9
0
def event_userinfo(
    event, event_content
):  #finally initializes the client from the queue, now obsolete as i am using the "Player" event for the OpenJK GUID integration.
    if "Userinfo" in event:
        print("Userinfo...")
        #CLIENTUSERINFO CHANGED: 1  NAME, CLASS, COLOR, TEAM
        pid = int(event_content.split(" ", 1)[0])
        pindex = searchby_id(pid, player_queue)
        if pindex != -1:
            print("found player in queue\n")
            try:
                name = event_content.split("\\", 2)[1]
            except:
                print("error processing userinfo.")
                return True
        else:
            print("Player not found in queue: ", pid)
            return True

        for x in current_players:  #since there is no "Changed name to" event, i'm using userinfo to manage changed names in-game
            if x.id == pid:
                print("Client ", x.id, " already initialized.")
                return
                return True

        if name == "Server":
            network.send_cmd("kick " + name)
            return True
        try:  #if player is existing in playerlist, load that client into current_players
            for x in playerlist:
                if x.ip == player_queue[pindex].ip:
                    print(x.mmr, "\n")
                    current_players.append(
                        Player(pid, x.ip, x.mmr, name, "%%#", None, False,
                               None, x.wins, x.losses))
                    print("loaded existing player")
                    player_queue.pop(pindex)
                    return True
        except:
            print("Player not found in playerlist, creating new...")
        current_players.append(
            Player(pid, player_queue[pindex].ip, 1500, name, "%%#", True,
                   False, None, 0, 0))
        playerlist.append(
            Player(pid, player_queue[pindex].ip, 1500, name, "%%#", True,
                   False, None, 0, 0))
        player_queue.pop(pindex)
        print("New player created!")
        del (pid, pindex, event, event_content, name)
        return True
    else:
        del (event, event_content)
        return False
Ejemplo n.º 10
0
def say_elo(
    event_content, name, current_players
):  #custom !elo command that prints out the player's ELO points in-game
    pindex = searchby_name(
        name, current_players
    )  #this searchby_name method returns -1 if no players are found in a given list
    #say [NAME] : CHAT
    if pindex != -1:
        network.send_cmd("svsay " + name + "^7's ELO: [^3" +
                         str(current_players[pindex].mmr) + "^7]")

        #Cleanup
        del (pindex)
        return True
    else:  #!ELO
        return True
Ejemplo n.º 11
0
def login(client):

    json_tree = tree.usertree
    my_chks = list(chunk.my_chunks.keys())
    my_store = []  # TODO: later read the content of .store

    hashes = 'None' if len(my_chks) == 0 else ':'.join(my_chks + my_store)

    try:
        network.send_cmd('JOIN {} {} {} {}'.format(client.username,
                                                   client.port, hashes,
                                                   json.dumps(json_tree)))
    except Exception as e:
        logger.error('2: {} was raised'.format(log.nomore(e)))
        for l in traceback.format_tb(e.__traceback__):
            logger.debug(l)
        raise e
Ejemplo n.º 12
0
def login(client):

    json_tree = tree.usertree
    my_chks = list(chunk.my_chunks.keys())
    my_store = []  # TODO: later read the content of .store

    hashes = 'None' if len(my_chks) == 0 else ':'.join(my_chks + my_store)
  
    try:
      network.send_cmd('JOIN {} {} {} {}'
          .format(client.username, client.port,
            hashes, json.dumps(json_tree)))
    except Exception as e:
        logger.error('2: {} was raised'.format(log.nomore(e)))
        for l in traceback.format_tb(e.__traceback__):
            logger.debug(l)
        raise e
Ejemplo n.º 13
0
def challenge_to_duel(current_players, pid, line2=""):
    p1 = pid
    p2 = 0
    it = 0
    flag = 0
    try:
        print("THIS NAME" + current_players[pid].name)
    except:
        print(1)

    for x in current_players:

        if flag > 1:
            network.send_cmd(
                "There are too many players matching that argument.")
            p1 = pid
            p2 = 0
            it = 0
            flag = 0
            return
        if remove_colorcode(line2.lower()) in remove_colorcode(x.name.lower()):
            p2 = it
            flag += 1
        it += 1
    print(p1, p2, it, flag)
    if flag == 0:
        network.send_cmd("No players match that argument.")
        return

    print("point1")
    print(p1, p2)
    if flag == 1:
        try:
            print(current_players[p2].name)
        except:
            print(2)
        current_players[p1].opponent = current_players[p2].name
        print("point2")
        if current_players[p2].opponent == current_players[p1].name:
            if not current_players[p2].in_duel:
                print("point3")
                if not current_players[p1].in_duel:
                    print("point4")
                    duel_start(p1, p2)
                    del (p1, p2, it, flag)
Ejemplo n.º 14
0
    def getChangeTime(self):
        return os.stat(self.serverLogPath).st_mtime

    def isChanged(self):
        stamp = self.getChangeTime()
        if stamp != self._lastChangeTime:
            self._lastChangeTime = stamp
            self.lastLineNumber = self.readAndGetLastLineNumber()
            return True
        else:
            return False


if __name__ == "__main__":
    time.sleep(5)
    network.send_cmd("svsay ELO Script just restarted, please reconnect.")

    logFile = LogFile(config.logname)

    lastReadedLineNumber = logFile.lastLineNumber

    while True:
        time.sleep(1)

        if logFile.isChanged():

            text = logFile.readAsArray()

            for i in range(lastReadedLineNumber, logFile.lastLineNumber):
                line1 = text[i]
                print("new line:" + line1.rstrip())
Ejemplo n.º 15
0
def send_FDEL(path):
    network.send_cmd('FDEL {}'.format(path))
Ejemplo n.º 16
0
def send_FDEL(path):
    network.send_cmd('FDEL {}'.format(path))