Skip to content

Instantly share code, notes, and snippets.

@blam23
Last active December 18, 2015 16:08
Show Gist options
  • Select an option

  • Save blam23/5808806 to your computer and use it in GitHub Desktop.

Select an option

Save blam23/5808806 to your computer and use it in GitHub Desktop.
Gets all users in specified room, and the max count. Returns: * (maxCount, ip, [users], desc) * If it doesn't find anything it returns: * (-1, None, None, None) *
def getBouts(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, None)
else:
buffer = buffer+more
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment