From d6738b2b705a5a85471f03c536eddbc422eb13f4 Mon Sep 17 00:00:00 2001 From: mountain Date: Sun, 6 Aug 2023 11:49:17 +0900 Subject: [PATCH] =?UTF-8?q?alias=EB=A7=8C=EC=9C=BC=EB=A1=9C=EB=8F=84=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=EB=A5=BC=20=EB=B3=B4=EB=82=BC=20?= =?UTF-8?q?=EC=88=98=20=EC=9E=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wshandler/wshandler.go | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/wshandler/wshandler.go b/wshandler/wshandler.go index 6fb7a8e..d06d72a 100644 --- a/wshandler/wshandler.go +++ b/wshandler/wshandler.go @@ -149,21 +149,6 @@ func init() { } func NewWebsocketHandler() (*WebsocketHandler, error) { - // decoder := func(r io.Reader) *T { - // if r == nil { - // // 접속이 끊겼을 때. - // return nil - // } - // var m T - // dec := json.NewDecoder(r) - // if err := dec.Decode(&m); err != nil { - // logger.Println(err) - // } - - // // decoding 실패하더라도 빈 *T를 내보냄 - // return &m - // } - subhandlers := make(map[string]*subhandler) for region, cfg := range config.RegionStorage { redisSync, err := gocommon.NewRedisClient(cfg.Redis["wshandler"]) @@ -371,6 +356,7 @@ 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 { @@ -385,6 +371,7 @@ func (sh *subhandler) mainLoop(ctx context.Context) { } defer func() { + entireAlias = nil for _, conn := range entireConns { var roomnames []string for _, room := range conn.joinedRooms { @@ -410,7 +397,14 @@ func (sh *subhandler) mainLoop(ctx context.Context) { } else { accid = target } - conn := entireConns[accid] + + var conn *wsconn + if accid[0] == '@' { + conn = entireAlias[accid[1:]] + } else { + conn = entireConns[accid] + } + if conn == nil { return false, nil } @@ -556,6 +550,7 @@ 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) @@ -567,6 +562,7 @@ 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) } }