Last active
May 10, 2016 08:53
-
-
Save aa989190f363e46d/cd6992147825a4baf7df50bdaf474796 to your computer and use it in GitHub Desktop.
godvile game authorizer for R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
''' | |
source: http://p.jugregator.org/45e4612a-e851-11e1-b718-001c14011f11 | |
''' | |
import json | |
import random | |
import string | |
from twisted.internet import reactor | |
from autobahn.websocket import connectWS, WebSocketClientFactory, WebSocketClientProtocol | |
URL = "http://godville.net/fbh/feed" | |
{"action": "punish"} # сделать плохо | |
action = {"action": "encourage"} | |
data = {"a": "VALUE_FROM_KEYS", "b": prepare_args(json.dumps(action))} | |
def gcv_encode(a): | |
a = a.decode('utf-8') | |
for char in a: | |
c = | |
# TODO: | |
""" | |
while (j < a.length) | |
c = a.charCodeAt(j++), d = a.charCodeAt(j++), e = a.charCodeAt(j++), f = c >> 2, g = (c & 3) << 4 | d >> 4, h = (d & 15) << 2 | e >> 6, i = e & 63, isNaN(d) ? h = i = 64 : isNaN(e) && (i = 64), b = b + this._keyStr.charAt(f) + this._keyStr.charAt(g) + this._keyStr.charAt(h) + this._keyStr.charAt(i); | |
return b | |
""" | |
def randomstring(n): | |
return "".join([random.choice(string.letters) for _ in xrange(n)]) | |
def prepare_args(arg): | |
return randomstring(5) + gcv_encode(arg) + randomstring(3) | |
KEYS = {u'3hOqa3hA2Gjh7tEWSD5T': u'9W1f6FIbcM8jgpgaKZy5', | |
u'54pcE5UCp82zxcEQcBwj': u'Vy0FUsHs0T6sqqDFobCW', | |
u'5JgMUahE1BYdtf7quoWz': u'YFQT8EtYAQwiIgmiUA2V', # сделать хорошо | |
u'66LpWTKQaNrTqvRxNCvW': u'bYadpk6N29nhUVojiH34', | |
u'7Ub7bq4b4fKpsydXuVOm': u'3GGcSQqPm4DC1ynsBr8l', | |
u'AJ53peA1Kl3eoRv1fnbW': u'ywCvjEbxoW9YSaLT7vKD', | |
u'ARKYteoAvq5ne3JfYpcV': u'UZayz1EYe6TLXl5Xbyxa', | |
u'Bja2XQ1F4t9uo9YNkrTH': u'ulcZnxiDtNpgwrFSHHYC', | |
u'G4LFOuNINtvAFR1pJXTy': u'GDz5mXXypczssAYGjAty', | |
u'GJyYqhQtKRYCWFp1UwM5': u'm7q8iLgRil1tzkjfG0x5', | |
u'IPzdqJ1FIhISEEKnlYrl': u'77b3f1WgtjPlNfuyUAjN', | |
u'KztXWDej9YxdBu0LCMUf': u'SO9ibG1N6FlxSvmZpUjt', | |
u'QBx5eknHRruO94WLhxCR': u'LGyLLcJCYKHurUUgtNQN', | |
u'QCFRPkOrNhNB5tAZhEy5': u'pkZ8dUzy0spUvy5XyYs4', | |
u'QfW08b8BVphsw65Adv5D': u'dp9iHgnA8OonwksM1I88', | |
u'R2jD74ywz4d7QXjcQ75r': u'QPxZTriOpbZ2uQ220Y2a', | |
u'VLL6RhIsTFlKlHly3rUb': u'F3fmZRhSir9QJJe8PPHn', | |
u'W9jcR9yqvGlLvyfCi12v': u'l3SMK7bFCCy2XnbOnFrt', | |
u'WzCGcLhzgkHj35wake2c': u'OcRy0XlLkHJVL16opNws', | |
u'agQHqM4rCoT0CaDvq44I': u'2ahcM6oMrfS4DfuMyv1g', | |
u'bk1yXKUzxwWKvsQOtpt5': u'wEUvcdWI5QM29n74dMkT', | |
u'dg3yOKCzGwdKvsTOtdt4': u'iNCaDWOi15wJs4uFJJvI', | |
u'fjQtRFHERdTEvAbY3p2m': u'A33kQDcbmpBC39ocBMVU', | |
u'lvBuKwP7tQetJZNXXQx7': u'9tUdvaq6kWLAKOMcadwv', | |
u'm5S1KBfBxKhNWuu61EjC': u'OZGK7ior8w2omUIsNhZ6', | |
u'nYrBGlddZVxNgxJLFffQ': u'MRsaFLGpTaPol6FFhAtS', | |
u'oTSzzK6ZYFu0a4N7lDu1': u'PH36fkU0nUsrs0e8LiF5', | |
u'u2iZlzPPsST6a7jhFg4y': u'jka7nYaMz1ZIhYwQ2Pge', | |
u'vS9Mnm48PCKUaKPuwod6': u'KwkC3rjUcffkbpCIaxfO', | |
u'xAZqO7epAERoAsmUTDFj': u'15d2cp5A2iv5YLX55d0Q', | |
u'z0uVDOyRiCLKIBhDnnVw': u'f7dbXWvYXCCPfQLIfvmt'} | |
class GodvilleProtocol(WebSocketClientProtocol): | |
def onOpen(self): | |
"""docstring for onOpen""" | |
print "Connection opened" | |
def onMessage(self, msg, binary): | |
"""docstring for onMessage""" | |
print msg | |
try: | |
someid, js = msg.split("{", 1) | |
js = "{" + js | |
js = json.loads(js) | |
with open("reversegodville", 'a') as f: | |
json.dump(js, f) | |
f.write("\n") | |
except Exception, e: | |
print e | |
def onClose(self, wsaClean, code, reason): | |
"""docstring for onClose""" | |
print "closed" | |
SESSION_ID = "СОДЕРЖИМОЕ cookie god_session_id" | |
cookies = {'god_session_id': SESSION_ID} | |
factory = WebSocketClientFactory("ws://ws.godville.net:82/hero", useragent="Mozilla", | |
cookies=cookies, debug=True, debugCodePaths=True) | |
factory.protocol = GodvilleProtocol | |
factory.setProtocolOptions(version=13) | |
if __name__ == '__main__': | |
connectWS(factory) | |
reactor.run() | |
else: | |
from twisted.application import internet, service | |
wsclient = internet.TCPClient("ws.godville.net", 82, factory) | |
application = service.Application("GodvilleClient") | |
wsclient.setServiceParent(application) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment