diff options
| author | Mistivia <i@mistivia.com> | 2025-11-02 15:29:28 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-11-02 15:29:28 +0800 |
| commit | 9f42c2d5f911cb4e215d7873221e642ce7df4d61 (patch) | |
| tree | 6dac90a889a7402a9556d3d1bcc5cb53cdb9f123 /deprecated-webircgateway/pkg/irc/state.go | |
| parent | fb2d9de539b660a261af19b1cbcceb7ee7980cb1 (diff) | |
deprecate webircdateway and ngircd
Diffstat (limited to 'deprecated-webircgateway/pkg/irc/state.go')
| -rw-r--r-- | deprecated-webircgateway/pkg/irc/state.go | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/deprecated-webircgateway/pkg/irc/state.go b/deprecated-webircgateway/pkg/irc/state.go new file mode 100644 index 0000000..69480fc --- /dev/null +++ b/deprecated-webircgateway/pkg/irc/state.go @@ -0,0 +1,79 @@ +package irc + +import ( + "strings" + "sync" + "time" +) + +type State struct { + LocalPort int + RemotePort int + Username string + Nick string + RealName string + Password string + Account string + Modes map[string]string + + channelsMutex sync.Mutex + Channels map[string]*StateChannel + ISupport *ISupport +} + +type StateChannel struct { + Name string + Modes map[string]string + Joined time.Time +} + +func NewState() *State { + return &State{ + Channels: make(map[string]*StateChannel), + ISupport: &ISupport{ + tokens: make(map[string]string), + }, + } +} + +func NewStateChannel(name string) *StateChannel { + return &StateChannel{ + Name: name, + Modes: make(map[string]string), + Joined: time.Now(), + } +} + +func (m *State) HasChannel(name string) (ok bool) { + m.channelsMutex.Lock() + _, ok = m.Channels[strings.ToLower(name)] + m.channelsMutex.Unlock() + return +} + +func (m *State) GetChannel(name string) (channel *StateChannel) { + m.channelsMutex.Lock() + channel = m.Channels[strings.ToLower(name)] + m.channelsMutex.Unlock() + return +} + +func (m *State) SetChannel(channel *StateChannel) { + m.channelsMutex.Lock() + m.Channels[strings.ToLower(channel.Name)] = channel + m.channelsMutex.Unlock() +} + +func (m *State) RemoveChannel(name string) { + m.channelsMutex.Lock() + delete(m.Channels, strings.ToLower(name)) + m.channelsMutex.Unlock() +} + +func (m *State) ClearChannels() { + m.channelsMutex.Lock() + for i := range m.Channels { + delete(m.Channels, i) + } + m.channelsMutex.Unlock() +} |
