def handleMsg(self, connection, cmd, msg): if(connection.status == 2 and cmd != 40): self.connections.sendPM(CC_Server.chatServer(3), connection, "Access denied.", 1) elif(cmd == 40): # announce connection.version = int(msg) if(connection.status == 2): banMsg = ["This ip address[/%s] is blocked from using CyanChat until tomorrow." % connection.addr[0]] self.connections.sendWelcome(connection, banMsg) return elif(cmd == 10): # set name connection.lastAttemptedName = msg else: if(self.prefs["enable_admin_extensions"]): self.handleExt(connection, cmd, msg) if(self.prefs["enable_bouncer"]): self.handleBounce(connection, cmd, msg) if(cmd in [50, 51, 53]): self.sendShadowUserList() elif(cmd in [10, 40] or (cmd in [15, 20, 30, 70] and connection.named)): if(self.prefs["shadow_users"] and cmd in [20, 70]): # If a PM or ignore message is directed at a client of the relay, we bypass the main server msglist = msg.split("|", 1) user = msglist[0].split(",", 1) target = self.connections.findByName(user[0]) if(target): if(cmd == 20): self.connections.sendPM(connection, target, msglist[1][2:]) elif(cmd == 70): self.connections.sendIgnore(connection, target) self.sendShadowUserList() return log(self, "forwarding %s to server" % "%d|%s" % (cmd, msg), 2) connection.forward("%d|%s" % (cmd, msg)) if(cmd == 15): # logout (must be done after forward, or the above will block it) connection.named = 0
def insert(self, connection): CC_Server.connectionList.insert(self, connection) connection.relaySock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: connection.relaySock.connect((self.parent.prefs["relay_addr"], self.parent.prefs["relay_port"])) connection.connectEvent.set() relayRecvThread = threading.Thread(None, self.parent.relayRecvLoop, "relayRecvLoop", (connection,)) relayRecvThread.setDaemon(1) relayRecvThread.start() except: #except Exception as error: #print error log(self, "error connecting to relay target %s" % self.parent.prefs["relay_addr"], 2) self.sendPM(CC_Server.chatServer(3), connection, "Error connecting to relay target", 1) connection.connectEvent.set() #allow the loop to run, but it will throw errors on every forward