Added key field to client
This commit is contained in:
parent
c8f62ae151
commit
70a13eec00
22
client.go
22
client.go
@ -11,23 +11,22 @@ import (
|
|||||||
|
|
||||||
func (c *Client) setNick(nick string) {
|
func (c *Client) setNick(nick string) {
|
||||||
if c.nick != "" {
|
if c.nick != "" {
|
||||||
oldNickKey := strings.ToLower(c.nick)
|
delete(c.server.clientMap, c.key)
|
||||||
delete(c.server.clientMap, oldNickKey)
|
|
||||||
for _, channel := range c.channelMap {
|
for _, channel := range c.channelMap {
|
||||||
delete(channel.clientMap, oldNickKey)
|
delete(channel.clientMap, c.key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Set up new nick
|
//Set up new nick
|
||||||
oldNick := c.nick
|
oldNick := c.nick
|
||||||
c.nick = nick
|
c.nick = nick
|
||||||
nickKey := strings.ToLower(c.nick)
|
c.key = strings.ToLower(c.nick)
|
||||||
c.server.clientMap[nickKey] = c
|
c.server.clientMap[c.key] = c
|
||||||
|
|
||||||
clients := make([]string, 0, 100)
|
clients := make([]string, 0, 100)
|
||||||
|
|
||||||
for _, channel := range c.channelMap {
|
for _, channel := range c.channelMap {
|
||||||
channel.clientMap[nickKey] = c
|
channel.clientMap[c.key] = c
|
||||||
|
|
||||||
//Collect list of client nicks who can see us
|
//Collect list of client nicks who can see us
|
||||||
for _, client := range channel.clientMap {
|
for _, client := range channel.clientMap {
|
||||||
@ -65,9 +64,7 @@ func (c *Client) joinChannel(channelName string) {
|
|||||||
newChannel = true
|
newChannel = true
|
||||||
}
|
}
|
||||||
|
|
||||||
nickKey := strings.ToLower(c.nick)
|
if _, inChannel := channel.clientMap[c.nick]; inChannel {
|
||||||
|
|
||||||
if _, inChannel := channel.clientMap[nickKey]; inChannel {
|
|
||||||
//Client is already in the channel, do nothing
|
//Client is already in the channel, do nothing
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -78,8 +75,8 @@ func (c *Client) joinChannel(channelName string) {
|
|||||||
mode.operator = true
|
mode.operator = true
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.clientMap[nickKey] = c
|
channel.clientMap[c.nick] = c
|
||||||
channel.modeMap[nickKey] = mode
|
channel.modeMap[c.nick] = mode
|
||||||
c.channelMap[channelKey] = channel
|
c.channelMap[channelKey] = channel
|
||||||
|
|
||||||
for _, client := range channel.clientMap {
|
for _, client := range channel.clientMap {
|
||||||
@ -96,8 +93,7 @@ func (c *Client) joinChannel(channelName string) {
|
|||||||
for _, client := range channel.clientMap {
|
for _, client := range channel.clientMap {
|
||||||
prefix := ""
|
prefix := ""
|
||||||
|
|
||||||
nickKey := strings.ToLower(client.nick)
|
if mode, exists := channel.modeMap[client.nick]; exists {
|
||||||
if mode, exists := channel.modeMap[nickKey]; exists {
|
|
||||||
prefix = mode.Prefix()
|
prefix = mode.Prefix()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ type Client struct {
|
|||||||
signalChan chan signalCode
|
signalChan chan signalCode
|
||||||
outputChan chan string
|
outputChan chan string
|
||||||
nick string
|
nick string
|
||||||
|
key string
|
||||||
registered bool
|
registered bool
|
||||||
connected bool
|
connected bool
|
||||||
operator bool
|
operator bool
|
||||||
|
Loading…
Reference in New Issue
Block a user