def do_incoming_auth(event, message):
    global is_authed, connected_protoctl
    if (message.command == "PROTOCTL"):
        connected_protoctl = message
    elif (message.command == "PASS"):
        if (message.parameters[0] != config.get("Network/Password")):
            log.critical("Password mismatch!  Expected '%s', got '%s'",
                         config.get("Network/Password"), message.parameters[0])
            Network.sendMsg(
                IRCMessage(':', config.get("Server/Name"), "ERROR",
                           "Closing link: password mismatch"))
            #Network.disconnect() #this is done in the main file
            ffservices.shutdown(1)
    elif (message.command == "SERVER"):
        if (is_authed): return
        is_authed = True
        Server.addServer(
            Server.createServerFromMessage(message, connected_protoctl))
        Event.trigger("Network/LinkEstablished")
        Network.isAuthed = True
        #anything that watches for this event should do things like send user info (NICK),
        #channel membership, channel info, modes, etc at this point
        Network.sendMsg(
            IRCMessage(None, None, "netinfo", 0, int(time.time()),
                       ffservices.unrealProtocol, "*", 0, 0, 0,
                       config.get("Network/Name")))
        #TODO: keep track of my max known global users?
        Network.sendMsg(IRCMessage(None, None, "eos"))
        event.stop()
def handle_new_server(event, message):
	if(ffservices.protoctl["NS"]):
		source=Server.findByNumeric(message.source)
		server=Server(message.parameters[0], message.parameters[1], message.parameters[-1], message.parameters[2])
	else:
		source=Server.findByName(message.source)
		server=Server(message.parameters[0], message.parameters[1], message.parameters[-1])
	
	Server.addServer(server)
	log.info("Server connecting at %s: %s (numeric %d, %d hops): %s", source.name if source is not None else "[None]", server.name, server.numeric, server.hopcount, server.description)
def do_incoming_auth(event, message):
	global is_authed, connected_protoctl
	if(message.command=="PROTOCTL"):
		connected_protoctl=message
	elif(message.command=="PASS"):
		if(message.parameters[0]!=config.get("Network/Password")):
			log.critical("Password mismatch!  Expected '%s', got '%s'", config.get("Network/Password"), message.parameters[0])
			Network.sendMsg(IRCMessage(':', config.get("Server/Name"), "ERROR", "Closing link: password mismatch"))
			#Network.disconnect() #this is done in the main file
			ffservices.shutdown(1)
	elif(message.command=="SERVER"):
		if(is_authed): return
		is_authed=True
		Server.addServer(Server.createServerFromMessage(message, connected_protoctl))
		Event.trigger("Network/LinkEstablished")
		Network.isAuthed=True
		#anything that watches for this event should do things like send user info (NICK),
		#channel membership, channel info, modes, etc at this point
		Network.sendMsg(IRCMessage(None, None, "netinfo", 0, int(time.time()), ffservices.unrealProtocol, "*", 0, 0, 0, config.get("Network/Name")))
		#TODO: keep track of my max known global users?
		Network.sendMsg(IRCMessage(None, None, "eos"))
		event.stop()