예제 #1
0
// Set the user's nick.
func (u *User) SetNick(nick string) os.Error {
	if !parser.ValidNick(nick) {
		return parser.NewNumeric(parser.ERR_ERRONEUSNICKNAME, nick)
	}

	lownick := parser.ToLower(nick)

	userMutex.Lock()
	defer userMutex.Unlock()

	if id, used := userNicks[lownick]; used {
		if id == u.ID() {
			return nil
		}
		return parser.NewNumeric(parser.ERR_NICKNAMEINUSE, nick)
	}
	userNicks[lownick] = u.ID()

	lownick = parser.ToLower(u.nick)
	userNicks[lownick] = "", false

	u.mutex.Lock()
	defer u.mutex.Unlock()

	u.nick = nick
	u.ts = time.Nanoseconds()
	return nil
}
예제 #2
0
// Set the user and gecos (immutable once set).
func (u *User) SetUser(user, name string) os.Error {
	if len(u.user) > 0 {
		return parser.NewNumeric(parser.ERR_ALREADYREGISTRED)
	}

	if !parser.ValidNick(user) || len(name) == 0 {
		// BUG(kevlar): Document this behavior
		return parser.NewNumeric(parser.ERR_NEEDMOREPARAMS)
	}

	u.mutex.Lock()
	defer u.mutex.Unlock()

	u.user, u.name = user, name
	u.ts = time.Nanoseconds()
	return nil
}