if c:getState() == adchpp.STATE_NORMAL then --// TODO: onINF listener must be called before saving the changed nick --// TODO2: onINF listener shoud exist :P if #cmd:getParam("NI", 0) > 0 then -- Changing nick local user = adch:getUser( c:getSID() ) if user then local oldnick = user:getNick() local newnick = cmd:getParam("NI", 0) -- Testing if the user is registered local cid = c:getCID():toBase32() local isregistered = get_user( cid, oldnick ) if isregistered then -- user is registered, update his registration. update_user verifies if the new nick is taken local fine, msg = update_user(isregistered, cid, newnick) if fine then -- also update the userinfo table stored in the memory user:setNick(newnick) else -- dump(c, adchpp.ERROR_PROTOCOL_GENERIC, msg) user:sendSta( msg, "1", "22") return command_processed end else -- user is not registered, allow him to take only non-regged nicks local nicktaken = get_user( nil, newnick ) if nicktaken then --dump(c, adchpp.ERROR_PROTOCOL_GENERIC, "You supplied a nick which is already registered. Please choose another one.") user:sendSta( "You supplied a nick which is already registered. Please choose another one", "1", "21" ) return command_processed else user:setNick(newnick) end end end end return 0 end