Last active
March 16, 2018 03:38
-
-
Save pich4ya/902bb6708b0cb9260b1c69f22a7385fa to your computer and use it in GitHub Desktop.
WebSockets Game Bot
This file contains hidden or 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
#!/usr/bin/python3 | |
# pip3 install websocket-client | |
import urllib | |
from urllib.request import urlopen, Request | |
from urllib.parse import urlencode | |
import string | |
import json | |
import websocket | |
import _thread | |
import time | |
def pwn_creep(ws,idz): | |
global wolfz | |
try: | |
ws.send("{\"type\":\"HIT_CREEP\",\"data\":{\"creepID\":\""+idz+"\"}}") | |
# time.sleep(1) | |
wolfz+=1 | |
print('pwn wolf '+str(wolfz)) | |
except: | |
print('Error: in pwn_creep') | |
def on_message(ws, message): | |
# ws.send("{\"type\":\"UPDATE_SCORE\",\"data\":{\"score\":999}}") | |
print(message) | |
if 'wolf' in message: | |
m = json.loads(message)['enemy'] | |
for i in m: | |
if i!=None and str(i['type']) == 'wolf': | |
try: | |
_thread.start_new_thread( pwn_creep, (ws,i['id']) ) | |
except: | |
print ("Error: unable to start thread") | |
def on_error(ws, error): | |
print('error function called') | |
# raise error | |
print(error) | |
def on_close(ws): | |
print ("### closed ###") | |
def on_open(ws): | |
time.sleep(1) | |
join_msg=("{\"type\":\"INITIAL_STATE\",\"data\":{\"centerX\":682,\"centerY\":379,\"username\":\"LongCat\"}}") | |
ws.send(join_msg) | |
time.sleep(1) | |
if __name__ == "__main__": | |
global wolfz | |
wolfz=0 | |
socketstring = ("wss://www.firstmotions.com:6004/") | |
websocket.enableTrace(True) | |
ws = websocket.WebSocketApp(socketstring, | |
on_message = on_message, | |
on_error = on_error, | |
on_close = on_close) | |
ws.on_open = on_open | |
ws.run_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment