Advertisement
MSWS

DEFY TTT Logs Manager

Nov 15th, 2019
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.90 KB | None | 0 0
  1. import time
  2. from enum import Enum, auto
  3.  
  4. users = {}
  5. storedUsers = {}
  6.  
  7. ROUND_TIME = 4*60 + 26
  8.  
  9.  
  10. def main():
  11.     lastGame = []
  12.     lastLines = []
  13.  
  14.     while True:
  15.         users.clear()
  16.  
  17.         lines = getLogLines()
  18.         if lines == lastLines:
  19.             continue
  20.         lastLines = lines
  21.  
  22.         game = getGame(lines)
  23.         if(game == lastGame):
  24.             continue
  25.         lastGame = game
  26.  
  27.         badActions = getBadActions(game)
  28.  
  29.         if len(badActions) == 0:
  30.             print("-"*10 + "[Expired]" + "-"*10)
  31.             continue
  32.  
  33.         for i in range(10):
  34.             print()
  35.  
  36.         for action in removeDuplicates(badActions):
  37.             print(action)
  38.         time.sleep(30)
  39.  
  40.  
  41. def getUser(name):
  42.     if name in users.keys():
  43.         return users[name]
  44.     user = User(name)
  45.     users[name] = user
  46.     return user
  47.  
  48.  
  49. def getLogLines():
  50.     lines = open(
  51.         "C:\Program Files (x86)\Steam\steamapps\common\Counter-Strike Global Offensive\csgo\output.log", encoding="utf8").readlines()
  52.     result = []
  53.     for line in lines:
  54.         result.append(line.strip())
  55.     return result
  56.  
  57.  
  58. def getGame(lines):
  59.     if "--------------------------------------" not in lines:
  60.         return []
  61.  
  62.     lines.reverse()
  63.  
  64.     end = lines.index("--------------------------------------")
  65.     start = lines.index("--------------------------------------", end+2)
  66.     lines = lines[start:end:-1]
  67.     return lines
  68.  
  69.  
  70. def getBadActions(lines):
  71.     users = {}
  72.  
  73.     flag = []
  74.     for line in lines:
  75.         if not line.startswith("["):
  76.             continue
  77.         if not line[1].isnumeric():
  78.             continue
  79.  
  80.         time = getTime(line)
  81.         timeLeft = ROUND_TIME - time
  82.  
  83.         atype = getActionType(line)
  84.  
  85.         name = getPlayerName(atype, line)
  86.         role = getPlayerRole(atype, line)
  87.  
  88.         user = getUser(name)
  89.         user.role = role
  90.  
  91.         if atype == ActionType.DAMAGE or atype == ActionType.KILL:
  92.             id = getPlayerID(line)
  93.             user.id = id
  94.  
  95.             key = " damaged " if atype == ActionType.DAMAGE else " killed "
  96.             dName = getTargetName(line, key)
  97.  
  98.             weapon = getWeapon(line)
  99.  
  100.             dId = getTargetID(line)
  101.  
  102.             dRole = Role[line[line.index("(", line.index("(", line.index(
  103.                 dName) + len(dName))+1)+1: line.index(")", line.index(")", line.index(dName) + len(dName))+1)].upper()]
  104.  
  105.             damaged = getUser(dName)
  106.             damaged.role = dRole
  107.             damaged.id = dId
  108.  
  109.             if damaged not in user.damaged:
  110.                 user.damaged.append(damaged)
  111.  
  112.             rLine = user.name + " ("+user.role.value + ")"+key + damaged.name + \
  113.                 " ("+damaged.role.value + ") with " + weapon
  114.  
  115.             if timeLeft < 60 * 2:
  116.                 rLine = "(AFTER 2) " + rLine
  117.  
  118.             if role == Role.INNOCENT and damaged.role == Role.TRAITOR:
  119.                 if (len(damaged.damaged) == 0):
  120.                     flag.append("[NOSHOT] " + rLine)
  121.  
  122.             if role != Role.TRAITOR:
  123.                 if time < 10 and user not in damaged.damaged:
  124.                     flag.append("[EARLY (00:0"+str(time % 60)+")] " + rLine)
  125.  
  126.             if "BAD ACTION" in line:
  127.                 flag.append("[BAD] " + rLine)
  128.  
  129.     return flag
  130.  
  131.  
  132. def removeDuplicates(lines):
  133.     result = []
  134.     lastline = ""
  135.     amo = 0
  136.     for line in lines:
  137.         if line == lastline:
  138.             amo += 1
  139.             continue
  140.         if amo >= 1:
  141.             result.append(lastline+" x"+str(amo+1))
  142.         else:
  143.             result.append(lastline)
  144.         amo = 0
  145.         lastline = line
  146.     if amo >= 1:
  147.         result.append(line+" x"+str(amo+1))
  148.     else:
  149.         result.append(line)
  150.  
  151.     return result
  152.  
  153.  
  154. def getActionType(line):
  155.     atype = ActionType.DAMAGE
  156.     if "killed" in line:
  157.         atype = ActionType.KILL
  158.     elif "identified body of" in line:
  159.         atype = ActionType.IDENTIFY
  160.     elif "purchased an item from the shop" in line:
  161.         atype = ActionType.BUY_ITEM
  162.     elif "pressed the button" in line:
  163.         atype = ActionType.BUTTON
  164.     elif "was tased by" in line:
  165.         atype = ActionType.TASER
  166.     return atype
  167.  
  168.  
  169. def getWeapon(line):
  170.     return line[line.index("with ")+len("with "):line.index("]", line.index("]")+1)].replace("weapon_", "").upper()
  171.  
  172.  
  173. def getTime(line):
  174.     return int(line[1:line.index(":")]) * 60 + \
  175.         int(line[line.index(":")+1:line.index("]")])
  176.  
  177.  
  178. def getPlayerRole(action, line):
  179.     if action == ActionType.IDENTIFY:
  180.         role = Role[line[line.index("(")+1: line.index(")")].upper()]
  181.     else:
  182.         role = Role[line[line.index(
  183.             "(", line.index("(") + 1)+1: line.index(")", line.index(")")+1)].upper()]
  184.     return role
  185.  
  186.  
  187. def getPlayerID(line):
  188.     return line[line.index("(")+1:line.index(") (")]
  189.  
  190.  
  191. def getTargetID(line):
  192.     return line[line.index("(", line.index("(", line.index("(")+1)+1)+1: line.index(")", line.index(")", line.index(")")+1)+1)]
  193.  
  194.  
  195. def getPlayerName(action, line):
  196.     if action == ActionType.IDENTIFY:
  197.         name = line[line.index("->")+3:line.index(" (")]
  198.     else:
  199.         name = line[line.index("[", 1)+1:line.index(" (")]
  200.     return name
  201.  
  202.  
  203. def getTargetName(line, key):
  204.     return line[line.index(key) + len(key):line.index(
  205.                 "(STEAM_", line.index("(STEAM_")+1) - 1]
  206.  
  207.  
  208. def printNames(players):
  209.     for i in range(len(players)):
  210.         print(players[i].name, end=", ")
  211.     print("")
  212.  
  213.  
  214. class Role(Enum):
  215.     TRAITOR = "T"
  216.     INNOCENT = "I"
  217.     DETECTIVE = "D"
  218.     UNKNOWN = "U"
  219.  
  220.  
  221. class User:
  222.     def __init__(self, name):
  223.         self.name = name
  224.         self.actions = {}
  225.         self.damaged = []
  226.         self.role = Role.UNKNOWN
  227.         self.id = ""
  228.  
  229.  
  230. class ActionType(Enum):
  231.     DAMAGE = auto()
  232.     KILL = auto()
  233.     BUY_ITEM = auto()
  234.     BUTTON = auto()
  235.     IDENTIFY = auto()
  236.     TASER = auto()
  237.  
  238. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement