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