방장 종료 처리
This commit is contained in:
@ -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,8 +383,16 @@ func (gp *groupParty) ConditionalClearPartyMember(w http.ResponseWriter, r *http
|
||||
id: gid,
|
||||
rh: gp.rh,
|
||||
}
|
||||
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{
|
||||
@ -382,6 +401,7 @@ func (gp *groupParty) ConditionalClearPartyMember(w http.ResponseWriter, r *http
|
||||
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,6 +889,15 @@ func (gp *groupParty) LeaveParty(ctx wshandler.ApiCallContext) {
|
||||
return
|
||||
}
|
||||
|
||||
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(),
|
||||
@ -871,6 +913,7 @@ func (gp *groupParty) LeaveParty(ctx wshandler.ApiCallContext) {
|
||||
},
|
||||
Tag: []string{"MemberDocFull"},
|
||||
})
|
||||
}
|
||||
|
||||
gp.leaveRoom(gid, mid)
|
||||
}
|
||||
@ -894,4 +937,3 @@ func (gp *groupParty) DenyPartyInvitation(ctx wshandler.ApiCallContext) {
|
||||
Tag: []string{"MemberDocFull"},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user