package chat import ( "fmt" "slices" ) // NewChannel creates a new channel instance func NewChannel(name string) *Channel { return &Channel{ name: name, members: make([]int32, 0), } } // SetName sets the channel name func (c *Channel) SetName(name string) { c.mu.Lock() defer c.mu.Unlock() c.name = name } // SetPassword sets the channel password func (c *Channel) SetPassword(password string) { c.mu.Lock() defer c.mu.Unlock() c.password = password } // SetType sets the channel type func (c *Channel) SetType(channelType int) { c.mu.Lock() defer c.mu.Unlock() c.channelType = channelType } // SetLevelRestriction sets the minimum level required to join func (c *Channel) SetLevelRestriction(level int32) { c.mu.Lock() defer c.mu.Unlock() c.levelRestriction = level } // SetRacesAllowed sets the race bitmask for allowed races func (c *Channel) SetRacesAllowed(races int32) { c.mu.Lock() defer c.mu.Unlock() c.raceRestriction = races } // SetClassesAllowed sets the class bitmask for allowed classes func (c *Channel) SetClassesAllowed(classes int32) { c.mu.Lock() defer c.mu.Unlock() c.classRestriction = classes } // GetName returns the channel name func (c *Channel) GetName() string { c.mu.RLock() defer c.mu.RUnlock() return c.name } // GetType returns the channel type func (c *Channel) GetType() int { c.mu.RLock() defer c.mu.RUnlock() return c.channelType } // GetNumClients returns the number of clients in the channel func (c *Channel) GetNumClients() int { c.mu.RLock() defer c.mu.RUnlock() return len(c.members) } // HasPassword returns true if the channel has a password func (c *Channel) HasPassword() bool { c.mu.RLock() defer c.mu.RUnlock() return c.password != "" } // PasswordMatches checks if the provided password matches the channel password func (c *Channel) PasswordMatches(password string) bool { c.mu.RLock() defer c.mu.RUnlock() return c.password == password } // CanJoinChannelByLevel checks if a player's level meets the channel requirements func (c *Channel) CanJoinChannelByLevel(level int32) bool { c.mu.RLock() defer c.mu.RUnlock() return level >= c.levelRestriction } // CanJoinChannelByRace checks if a player's race is allowed in the channel func (c *Channel) CanJoinChannelByRace(raceID int32) bool { c.mu.RLock() defer c.mu.RUnlock() return c.raceRestriction == NoRaceRestriction || (c.raceRestriction&(1<