Last active
December 18, 2015 19:18
-
-
Save blam23/5831624 to your computer and use it in GitHub Desktop.
Enables you to watch any toribash server that isn't password protected, while keeping your name out of the bout list. Note: The only people that can tell you are on the server are those that have access to the servers themselves. To use: First launch the .py file, type in the name of the server you want to join, in Toribash type '/co 127.0.0.1:9…
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
| import socket | |
| import threading | |
| # Shamelessly stolen from: http://stackoverflow.com/questions/5179467/equivalent-of-setinterval-in-python | |
| def setInterval(interval): | |
| def decorator(function): | |
| def wrapper(*args, **kwargs): | |
| stopped = threading.Event() | |
| def loop(): # executed in another thread | |
| while not stopped.wait(interval): # until stopped | |
| function(*args, **kwargs) | |
| t = threading.Thread(target=loop) | |
| t.daemon = True # stop if the program exits | |
| t.start() | |
| return stopped | |
| return wrapper | |
| return decorator | |
| class In(threading.Thread): | |
| def __init__(self, listen_port): | |
| threading.Thread.__init__ (self) | |
| self.insocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| self.listen_port = listen_port | |
| def listen(self): | |
| self.insocket.bind(("", self.listen_port)) | |
| self.insocket.listen(1) | |
| self.client, addr = self.insocket.accept() | |
| print "Connection found" | |
| self.out.connect(self.client) | |
| class Out(threading.Thread): | |
| def __init__(self, server, port): | |
| threading.Thread.__init__ (self) | |
| self.server = server | |
| self.port = port | |
| self.outsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| def connect(self, out): | |
| self.outsocket.connect((self.server,self.port)) | |
| self.outsocket.send("TORIBASH 30\n") | |
| self.outsocket.send("PING\n") | |
| self.stopPing = self.ping() | |
| self.loop(out) | |
| @setInterval(30) | |
| def ping(self): | |
| self.outsocket.send("PING\n") | |
| def loop(self, out): | |
| while 1: | |
| data = self.outsocket.recv(256) | |
| if not data: break | |
| out.sendall(data) | |
| def removeColors(line): | |
| from cStringIO import StringIO | |
| nline = StringIO() | |
| characters = enumerate(line) | |
| for i, c in characters: | |
| if c == '^' and i < line.__len__()-2: | |
| characters.next() | |
| characters.next() | |
| else: | |
| nline.write(c) | |
| return nline.getvalue() | |
| def get_info(name): | |
| bsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| bsocket.connect(("176.9.64.22", 22000)) | |
| buffer = bsocket.recv(4096) | |
| done = False | |
| inserver = False | |
| ip = "" | |
| lastCount = 0 | |
| clients = None | |
| while not done: | |
| if "\n" in buffer: | |
| (line, buffer) = buffer.split("\n", 1) | |
| if(line[:4] == "INFO"): | |
| s = line.find(" ",9) | |
| lastCount = int(line[8:s]) | |
| if(line[:10] == "SERVER 0; "): | |
| s = line.find(" ", 12) | |
| room = line[s:].strip() | |
| ip = line[10:s] | |
| if(room == name): | |
| inserver = True | |
| if(inserver and line[:8] == "DESC 0; "): | |
| desc = removeColors(line[8:]) | |
| return (lastCount, ip, clients, desc) | |
| if(inserver and line[:11] == "CLIENTS 2; "): | |
| clients = line[11:].split("\t") | |
| else: | |
| more = bsocket.recv(4096) | |
| if not more: | |
| return (-1, None, None) | |
| else: | |
| buffer = buffer+more | |
| def main(): | |
| print "Please enter server you wish to watch: " | |
| while 1: | |
| inp = raw_input() | |
| info = get_info(inp) | |
| if(info[0] != -1): | |
| break; | |
| print "Server not found, please try again: " | |
| listen = In(9000) | |
| ip, port = info[1].split(":") | |
| print "You will be connected to: ", ip, port | |
| print "Please /co 127.0.0.1:9000" | |
| out = Out(ip, int(port)) | |
| listen.out = out | |
| listen.listen() | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment