Skip to content

Instantly share code, notes, and snippets.

@Python1320
Created August 14, 2014 20:48
Show Gist options
  • Save Python1320/7ec9062cfa173378089e to your computer and use it in GitHub Desktop.
Save Python1320/7ec9062cfa173378089e to your computer and use it in GitHub Desktop.
import json
import os
import sys
import re
parse_steamid = re.compile(r"^STEAM_(?P<X>\d+):(?P<Y>\d+):(?P<Z>\d+)$")
import struct
json_data=open("hac_db_all.json").read()
data = json.loads(json_data)
i=0
a={}
l=[]
lsid=[]
def filterbanreason(s):
s=s.strip()
s=s.lower()
s=s.replace("alt of ","^")
s=s.replace("steam_0","0")
s=s.strip()
return s
for k in data:
v=data[k]
v=filterbanreason(v)
idx = a.get(v,None)
if idx == None:
l.append(v)
idx=len(l)-1
assert(v==l[idx])
a[v] = idx
l.sort(key=lambda s: len(s))
for i,val in enumerate(l):
#print(val)
q=a[val]
a[val]=i
for k in data:
v=data[k]
k=k.strip()
v=filterbanreason(v)
idx = a.get(v,None)
if idx == None:
l.append(v)
idx=len(l)-1
assert(v==l[idx])
a[v] = idx
match = parse_steamid.match(k)
if not match:
raise Exception("Fuck that")
X=int(match.group("X"))
Y=int(match.group("Y"))
Z=int(match.group("Z"))
if X!=0:
raise Exception(k)
assert(Y==1 or Y==0)
accountid= ( Z << 1 ) + Y
lsid.append((accountid,idx))
lsid.sort(key=lambda tup: tup[1])
print(len(data),len(l),len(a),len(lsid),len(lsid))
fSid = open('hac_sids.dat', 'wb')
fReason = open('hac_reason.dat', 'wb')
for dat in lsid:
sid=dat[0]
idx=dat[1]
assert(idx<65530)
assert(sid<4294967295)
string = struct.pack('IH', sid,idx)
fSid.write(string)
for reason in l:
reason = reason.encode('utf-8')
fReason.write(reason)
fReason.write(struct.pack('B', 0))
fSid.close()
fReason.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment