entireAlias 다시 제거
This commit is contained in:
@ -356,7 +356,6 @@ func (sh *subhandler) mainLoop(ctx context.Context) {
|
||||
}()
|
||||
|
||||
entireConns := make(map[string]*wsconn)
|
||||
entireAlias := make(map[string]*wsconn)
|
||||
rooms := make(map[string]*room)
|
||||
roomDestroyChan := make(chan string, 1000)
|
||||
findRoom := func(name string, create bool) *room {
|
||||
@ -371,7 +370,6 @@ func (sh *subhandler) mainLoop(ctx context.Context) {
|
||||
}
|
||||
|
||||
defer func() {
|
||||
entireAlias = nil
|
||||
for _, conn := range entireConns {
|
||||
var roomnames []string
|
||||
for _, room := range conn.joinedRooms {
|
||||
@ -383,10 +381,10 @@ func (sh *subhandler) mainLoop(ctx context.Context) {
|
||||
}()
|
||||
|
||||
errProcessFailed_NotInRoom := errors.New("not in room")
|
||||
processPrivateUpstreamMessage := func(usermsg *UpstreamMessage) (bool, error) {
|
||||
processPrivateUpstreamMessage := func(usermsg *UpstreamMessage) bool {
|
||||
target := usermsg.Target
|
||||
if target[0] == '#' {
|
||||
return false, nil
|
||||
return false
|
||||
}
|
||||
roomindex := strings.IndexByte(target, '@')
|
||||
var accid string
|
||||
@ -398,20 +396,14 @@ func (sh *subhandler) mainLoop(ctx context.Context) {
|
||||
accid = target
|
||||
}
|
||||
|
||||
var conn *wsconn
|
||||
if accid[0] == '@' {
|
||||
conn = entireAlias[accid[1:]]
|
||||
} else {
|
||||
conn = entireConns[accid]
|
||||
}
|
||||
|
||||
conn := entireConns[accid]
|
||||
if conn == nil {
|
||||
return false, nil
|
||||
return false
|
||||
}
|
||||
|
||||
if len(roomid) > 0 {
|
||||
if !conn.isInRoom(roomid) {
|
||||
return false, errProcessFailed_NotInRoom
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@ -427,7 +419,7 @@ func (sh *subhandler) mainLoop(ctx context.Context) {
|
||||
msg: ds,
|
||||
}
|
||||
|
||||
return true, nil
|
||||
return true
|
||||
}
|
||||
errCommandArgumentNotCorrect := errors.New("command arguments are not correct")
|
||||
processCommandMessage := func(usermsg *commandMessage) (bool, error) {
|
||||
@ -486,21 +478,17 @@ func (sh *subhandler) mainLoop(ctx context.Context) {
|
||||
// 없으면 publish한다.
|
||||
switch usermsg := usermsg.(type) {
|
||||
case *UpstreamMessage:
|
||||
processed, err := processPrivateUpstreamMessage(usermsg)
|
||||
if err != nil {
|
||||
logger.Println("processUpstreamMessage returns err :", err)
|
||||
}
|
||||
|
||||
if !processed {
|
||||
if !processPrivateUpstreamMessage(usermsg) {
|
||||
// private메시지가 처리가 안됐으므로 publish
|
||||
enc := gob.NewEncoder(buffer)
|
||||
var err error
|
||||
if err = enc.Encode(usermsg); err == nil {
|
||||
_, err = sh.redisSync.Publish(context.Background(), sh.redisMsgChanName, buffer.Bytes()).Result()
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
logger.Println("gob.Encode or publish failed :", err)
|
||||
if err != nil {
|
||||
logger.Println("gob.Encode or publish failed :", err)
|
||||
}
|
||||
}
|
||||
|
||||
case *commandMessage:
|
||||
@ -532,8 +520,8 @@ func (sh *subhandler) mainLoop(ctx context.Context) {
|
||||
if room := findRoom(roomName, false); room != nil {
|
||||
room.broadcast(usermsg)
|
||||
}
|
||||
} else if _, err := processPrivateUpstreamMessage(usermsg); err != nil {
|
||||
logger.Println("processPrivateUpstreamMessage returns err :", err)
|
||||
} else {
|
||||
processPrivateUpstreamMessage(usermsg)
|
||||
}
|
||||
|
||||
case *commandMessage:
|
||||
@ -550,7 +538,6 @@ func (sh *subhandler) mainLoop(ctx context.Context) {
|
||||
case c := <-sh.connInOutChan:
|
||||
if c.Conn == nil {
|
||||
delete(entireConns, c.sender.Accid.Hex())
|
||||
delete(entireAlias, c.sender.Alias)
|
||||
var roomnames []string
|
||||
for _, room := range c.joinedRooms {
|
||||
roomnames = append(roomnames, room.name)
|
||||
@ -562,7 +549,6 @@ func (sh *subhandler) mainLoop(ctx context.Context) {
|
||||
go sh.callReceiver.OnClientMessageReceived(c.sender, Disconnected, bytes.NewBuffer(bt))
|
||||
} else {
|
||||
entireConns[c.sender.Accid.Hex()] = c
|
||||
entireAlias[c.sender.Alias] = c
|
||||
go sh.callReceiver.OnClientMessageReceived(c.sender, Connected, nil)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user