def onRecv(conn, data, _): if conn in names: message = "<{}> {}".format(data["name"], data["message"]) else: if config["password"] is None or config["password"] == data["password"]: message = "{} joined".format(data["name"]) names[conn] = data["name"] ips[conn] = server.getClientAddr(conn) else: server.removeClient(conn) return eel.newMessage(addTimestamp(addIP(message, conn))) server.send(message)
def onReady(): eel.setTextColor(config["textcolor"]) eel.setBackgroundColor(config["backgroundcolor"]) eel.setLogColor(config["logcolor"]) loadLogfile() try: server.start(config["host"], config["port"]) except: eel.newMessage( addTimestamp("Unable to start server on {}:{}".format( config["host"], config["port"]))) else: eel.newMessage( addTimestamp("Server running on {}:{}".format(*server.getAddr())))
def onReady(): eel.setTextColor(config["textcolor"]) eel.setBackgroundColor(config["backgroundcolor"]) eel.setLogColor(config["logcolor"]) loadLogfile() try: client.connect(config["host"], config["port"]) except ConnectionRefusedError: eel.newMessage( addTimestamp("Unable to connect to {}:{}".format( config["host"], config["port"]))) else: client.send({"name": config["name"], "password": config["password"]}) eel.newMessage( addTimestamp("Connected to {}:{}".format(*client.getServerAddr()))) eel.enableInput() eel.selectInput()
def onDisconnected(): eel.newMessage(addTimestamp("Disconnected from server")) eel.disableInput()
def onRecv(message, _): eel.newMessage(addTimestamp(message))
def loadLogfile(): if config["logfile"] is not None: with open(config["logfile"], "r") as f: for line in f: eel.newMessage(line, False)
def onDisconnect(conn): message = "{} left".format(names[conn]) eel.newMessage(addTimestamp(addIP(message, conn))) server.send(message) names.pop(conn) ips.pop(conn)