#!/usr/bin/env python3 # Protocol: # Server sends type, length, username # 1 byte type is one byte # 2 bytes username length is two bytes # length bytes Actual username # Types: 0 - existing login, 1 - new login, 2 - logout from subprocess import getoutput from _thread import start_new_thread from socket import * from struct import * from time import sleep clients = [] def updater(): user_string = getoutput('who | cut -d " " -f 1 | sort -u') while True: sleep(1) new_user_string = getoutput('who | cut -d " " -f 1 | sort -u') if(new_user_string != user_string): old_users = user_string.split() user_string = new_user_string users = user_string.split() new_users = [u for u in users if u not in old_users] loggedout_users = [u for u in old_users if u not in users] if len(new_users): for nu in new_users: print("New user: ", nu) nu_bytes = nu.encode("utf-8") user_message = pack("