From a81549863a42785a3e55ff723604a70780d4574e Mon Sep 17 00:00:00 2001 From: mountain Date: Thu, 18 Jan 2024 14:40:39 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B0=A9=EC=9E=A5=20=EC=A2=85=EB=A3=8C=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/group_party.go | 92 +++++++++++++++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 25 deletions(-) diff --git a/core/group_party.go b/core/group_party.go index 5be9853..cb7eccb 100644 --- a/core/group_party.go +++ b/core/group_party.go @@ -186,6 +186,17 @@ func (gd *partyDoc) addMember(mid accountID, character bson.M) (bson.M, error) { return gd.loadMemberFull(tid) } +func (gd *partyDoc) getIncharge() string { + if len(gd.InCharge) == 0 { + incharge, err := gd.rh.JSONGet(gd.strid(), "$._incharge") + if err == nil && incharge != nil { + gd.InCharge = strings.Trim(incharge.(string), "[]\"") + } + } + + return gd.InCharge +} + func (gd *partyDoc) removeMemberByTid(tid string) error { _, err := gd.rh.JSONDel(gd.strid(), "$._members."+tid) if err != nil { @@ -372,15 +383,24 @@ func (gp *groupParty) ConditionalClearPartyMember(w http.ResponseWriter, r *http id: gid, rh: gp.rh, } - gd.removeMember(mid) - - gp.sendUpstreamMessage(&wshandler.UpstreamMessage{ - Target: "#" + doc.Gid, - Body: bson.M{ - gd.tid(mid): bson.M{}, - }, - Tag: []string{"MemberDocFull"}, - }) + if gd.getIncharge() == gd.tid(mid) { + // 방장이 나갔다. + gp.sendUpstreamMessage(&wshandler.UpstreamMessage{ + Target: "#" + doc.Gid, + Body: bson.M{"gid": gid}, + Tag: []string{"GroupDocFull", gid.Hex()}, + }) + gd.rh.Del(gd.rh.Context(), gd.strid()).Result() + } else { + gd.removeMember(mid) + gp.sendUpstreamMessage(&wshandler.UpstreamMessage{ + Target: "#" + doc.Gid, + Body: bson.M{ + gd.tid(mid): bson.M{}, + }, + Tag: []string{"MemberDocFull"}, + }) + } } if len(pids) == 0 { @@ -784,7 +804,20 @@ func (gp *groupParty) ClientDisconnected(msg string, callby *wshandler.Sender) { // 나를 먼저 룸에서 빼야 나한테 메시지가 안감 gp.leaveRoom(gid, callby.Accid) - if msg != "pending" { + gd := &partyDoc{ + rh: gp.rh, + id: gid, + } + + if gd.getIncharge() == gd.tid(callby.Accid) { + // 방장이 나감. 방 폭파 + gp.sendUpstreamMessage(&wshandler.UpstreamMessage{ + Target: "#" + gidstr, + Body: bson.M{"gid": gid}, + Tag: []string{"GroupDocFull", gidstr}, + }) + gd.rh.Del(gd.rh.Context(), gd.strid()).Result() + } else if msg != "pending" { // gid에는 제거 메시지 보냄 gp.sendUpstreamMessage(&wshandler.UpstreamMessage{ Target: "#" + gidstr, @@ -856,21 +889,31 @@ func (gp *groupParty) LeaveParty(ctx wshandler.ApiCallContext) { return } - // mid한테는 빈 GroupDocFull을 보낸다. 그러면 지워짐 - gp.sendUpstreamMessage(&wshandler.UpstreamMessage{ - Target: mid.Hex(), - Body: bson.M{"gid": gid}, - Tag: []string{"GroupDocFull", gid.Hex()}, - }) + if gd.getIncharge() == gd.tid(mid) { + // 방장이 나감. 방 폭파 + gp.sendUpstreamMessage(&wshandler.UpstreamMessage{ + Target: "#" + gidstr, + Body: bson.M{"gid": gid}, + Tag: []string{"GroupDocFull", gidstr}, + }) + gd.rh.Del(gd.rh.Context(), gd.strid()).Result() + } else { + // mid한테는 빈 GroupDocFull을 보낸다. 그러면 지워짐 + gp.sendUpstreamMessage(&wshandler.UpstreamMessage{ + Target: mid.Hex(), + Body: bson.M{"gid": gid}, + Tag: []string{"GroupDocFull", gid.Hex()}, + }) - // gid에는 제거 메시지 보냄 - gp.sendUpstreamMessage(&wshandler.UpstreamMessage{ - Target: "#" + gd.strid(), - Body: bson.M{ - tid: bson.M{}, - }, - Tag: []string{"MemberDocFull"}, - }) + // gid에는 제거 메시지 보냄 + gp.sendUpstreamMessage(&wshandler.UpstreamMessage{ + Target: "#" + gd.strid(), + Body: bson.M{ + tid: bson.M{}, + }, + Tag: []string{"MemberDocFull"}, + }) + } gp.leaveRoom(gid, mid) } @@ -894,4 +937,3 @@ func (gp *groupParty) DenyPartyInvitation(ctx wshandler.ApiCallContext) { Tag: []string{"MemberDocFull"}, }) } -