alias만으로도 메시지를 보낼 수 있다.
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user