message의 body를 any로 변경
This commit is contained in:
@ -10,7 +10,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -93,7 +92,7 @@ func (gd *groupDoc) updateBodyWithBson(src []byte) ([]byte, error) {
|
|||||||
return bson.Marshal(gd.Body)
|
return bson.Marshal(gd.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gd *groupDoc) updateBodyWithJson(src []byte) []byte {
|
func (gd *groupDoc) updateBodyWithJson(src []byte) GroupDocBody {
|
||||||
gd.Lock()
|
gd.Lock()
|
||||||
defer gd.Unlock()
|
defer gd.Unlock()
|
||||||
|
|
||||||
@ -102,10 +101,10 @@ func (gd *groupDoc) updateBodyWithJson(src []byte) []byte {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return makeTypeMessage(gd.Body)
|
return gd.Body
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gd *groupDoc) updateBodyBsonToJson(bsonSrc []byte) []byte {
|
func (gd *groupDoc) updateBodyBsonToJson(bsonSrc []byte) GroupDocBody {
|
||||||
gd.Lock()
|
gd.Lock()
|
||||||
defer gd.Unlock()
|
defer gd.Unlock()
|
||||||
|
|
||||||
@ -114,7 +113,7 @@ func (gd *groupDoc) updateBodyBsonToJson(bsonSrc []byte) []byte {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return makeTypeMessage(gd.Body)
|
return gd.Body
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gd *groupDoc) updateBody(bsonSrc []byte) error {
|
func (gd *groupDoc) updateBody(bsonSrc []byte) error {
|
||||||
@ -378,7 +377,7 @@ func (gd *groupDoc) iterateMembers(cb func(ticketID, *memberDoc)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gd *groupDoc) serializeFull(gid groupID) []byte {
|
func (gd *groupDoc) serializeFull(gid groupID) FullGroupDoc {
|
||||||
gd.Lock()
|
gd.Lock()
|
||||||
defer gd.Unlock()
|
defer gd.Unlock()
|
||||||
|
|
||||||
@ -395,11 +394,11 @@ func (gd *groupDoc) serializeFull(gid groupID) []byte {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return makeTypeMessage(FullGroupDoc{
|
return FullGroupDoc{
|
||||||
Gid: gid,
|
Gid: gid,
|
||||||
AllMembers: output,
|
AllMembers: output,
|
||||||
Body: gd.Body,
|
Body: gd.Body,
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type groupContainer struct {
|
type groupContainer struct {
|
||||||
@ -498,13 +497,6 @@ func (gm *groupInMemory) FindTicketID(gid groupID, mid groupID) ticketID {
|
|||||||
return primitive.NilObjectID
|
return primitive.NilObjectID
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeTypeMessage[T any](msg T) []byte {
|
|
||||||
var ptr *T
|
|
||||||
name := reflect.TypeOf(ptr).Elem().Name()
|
|
||||||
bt, _ := json.Marshal(bson.M{name: msg})
|
|
||||||
return bt
|
|
||||||
}
|
|
||||||
|
|
||||||
// func sendTypedMessageDirect[T any](rconn *wshandler.Richconn, msg T) {
|
// func sendTypedMessageDirect[T any](rconn *wshandler.Richconn, msg T) {
|
||||||
// bt, _ := json.Marshal(makeTypeMessage(msg))
|
// bt, _ := json.Marshal(makeTypeMessage(msg))
|
||||||
// rconn.WriteBytes(bt)
|
// rconn.WriteBytes(bt)
|
||||||
@ -559,7 +551,8 @@ func (gm *groupInMemory) InviteImplement(gid groupID, mid accountID, inviteeDoc
|
|||||||
// inviter한테 알려줘야 한다.
|
// inviter한테 알려줘야 한다.
|
||||||
gm.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
gm.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
||||||
Target: "@" + mid.Hex(),
|
Target: "@" + mid.Hex(),
|
||||||
Body: makeTypeMessage(InvitationFail(inviteeDoc)),
|
Body: inviteeDoc,
|
||||||
|
Tag: []string{"InvitationFail"},
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -577,12 +570,13 @@ func (gm *groupInMemory) InviteImplement(gid groupID, mid accountID, inviteeDoc
|
|||||||
gm.memberSync(gid, targetid, tid, newdoc, false)
|
gm.memberSync(gid, targetid, tid, newdoc, false)
|
||||||
gm.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
gm.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
||||||
Target: "@" + targetid.Hex(),
|
Target: "@" + targetid.Hex(),
|
||||||
Body: makeTypeMessage(Invitation{
|
Body: Invitation{
|
||||||
GroupID: gid,
|
GroupID: gid,
|
||||||
TicketID: tid,
|
TicketID: tid,
|
||||||
Inviter: inviterDoc,
|
Inviter: inviterDoc,
|
||||||
ExpireAtUTC: newdoc.InviteExpire.Unix(),
|
ExpireAtUTC: newdoc.InviteExpire.Unix(),
|
||||||
}),
|
},
|
||||||
|
Tag: []string{"Invitation"},
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -855,7 +849,8 @@ func (gm *groupInMemory) Leave(gid groupID, mid accountID, tid ticketID) error {
|
|||||||
// 나한테는 빈 FullGroupDoc을 보낸다.
|
// 나한테는 빈 FullGroupDoc을 보낸다.
|
||||||
gm.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
gm.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
||||||
Target: "@" + mid.Hex(),
|
Target: "@" + mid.Hex(),
|
||||||
Body: makeTypeMessage(FullGroupDoc{Gid: gid}),
|
Body: FullGroupDoc{Gid: gid},
|
||||||
|
Tag: []string{"FullGroupDoc", gid.Hex()},
|
||||||
})
|
})
|
||||||
gm.sendLeaveRoomMessage(gid, targetmid)
|
gm.sendLeaveRoomMessage(gid, targetmid)
|
||||||
|
|
||||||
@ -875,6 +870,7 @@ func (gm *groupInMemory) UpdateMemberDocument(gid groupID, mid accountID, doc bs
|
|||||||
gm.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
gm.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
||||||
Target: "#" + gid.Hex(),
|
Target: "#" + gid.Hex(),
|
||||||
Body: gd.updateBodyWithJson(personalized),
|
Body: gd.updateBodyWithJson(personalized),
|
||||||
|
Tag: []string{"GroupDocBody"},
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -1015,16 +1011,17 @@ func (cfg *groupConfig) prepareInMemory(ctx context.Context, typename string, su
|
|||||||
if len(remain) == 0 {
|
if len(remain) == 0 {
|
||||||
// gid 그룹 삭제
|
// gid 그룹 삭제
|
||||||
// 그룹 안에 있는 멤버에게 알림
|
// 그룹 안에 있는 멤버에게 알림
|
||||||
bt := makeTypeMessage(FullGroupDoc{Gid: gid})
|
|
||||||
gm.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
gm.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
||||||
Target: "#" + gid.Hex(),
|
Target: "#" + gid.Hex(),
|
||||||
Body: bt,
|
Body: FullGroupDoc{Gid: gid},
|
||||||
|
Tag: []string{"FullGroupDoc"},
|
||||||
})
|
})
|
||||||
gm.groups.delete(gid)
|
gm.groups.delete(gid)
|
||||||
} else if string(senderHost) != config.macAddr {
|
} else if string(senderHost) != config.macAddr {
|
||||||
gm.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
gm.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
||||||
Target: "#" + gid.Hex(),
|
Target: "#" + gid.Hex(),
|
||||||
Body: gd.updateBodyBsonToJson(remain),
|
Body: gd.updateBodyBsonToJson(remain),
|
||||||
|
Tag: []string{"GroupDocBody"},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else if string(senderHost) != config.macAddr {
|
} else if string(senderHost) != config.macAddr {
|
||||||
@ -1090,7 +1087,8 @@ func (cfg *groupConfig) prepareInMemory(ctx context.Context, typename string, su
|
|||||||
}
|
}
|
||||||
gm.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
gm.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
||||||
Target: "#" + gid.Hex(),
|
Target: "#" + gid.Hex(),
|
||||||
Body: makeTypeMessage(PublicMemberDoc{Tid: tid}),
|
Body: PublicMemberDoc{Tid: tid},
|
||||||
|
Tag: []string{"PublicMemberDoc"},
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
if isNewMember && updated.rconn == nil && rconn != nil {
|
if isNewMember && updated.rconn == nil && rconn != nil {
|
||||||
@ -1099,10 +1097,11 @@ func (cfg *groupConfig) prepareInMemory(ctx context.Context, typename string, su
|
|||||||
// 업데이트 된 플레이어(새로 들어온 플레이어 포함)를 모두에게 알려준다. 본인 포함, invitee 제외
|
// 업데이트 된 플레이어(새로 들어온 플레이어 포함)를 모두에게 알려준다. 본인 포함, invitee 제외
|
||||||
gm.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
gm.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
||||||
Target: "#" + gid.Hex(),
|
Target: "#" + gid.Hex(),
|
||||||
Body: makeTypeMessage(PublicMemberDoc{
|
Body: PublicMemberDoc{
|
||||||
Tid: tid,
|
Tid: tid,
|
||||||
memberDocCommon: updated.memberDocCommon,
|
memberDocCommon: updated.memberDocCommon,
|
||||||
}),
|
},
|
||||||
|
Tag: []string{"PublicMemberDoc"},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1113,6 +1112,7 @@ func (cfg *groupConfig) prepareInMemory(ctx context.Context, typename string, su
|
|||||||
gm.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
gm.sendUpstreamMessage(&wshandler.UpstreamMessage{
|
||||||
Target: "@" + mid.Hex(),
|
Target: "@" + mid.Hex(),
|
||||||
Body: gd.serializeFull(gid),
|
Body: gd.serializeFull(gid),
|
||||||
|
Tag: []string{"FullGroupDoc"},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.19
|
|||||||
require (
|
require (
|
||||||
github.com/go-redis/redis/v8 v8.11.5
|
github.com/go-redis/redis/v8 v8.11.5
|
||||||
go.mongodb.org/mongo-driver v1.11.7
|
go.mongodb.org/mongo-driver v1.11.7
|
||||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230711033135-d7b26608df94
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230711053010-4acb81a20d9c
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
|||||||
4
go.sum
4
go.sum
@ -110,3 +110,7 @@ repositories.action2quare.com/ayo/gocommon v0.0.0-20230711005604-a42eb2888e97 h1
|
|||||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230711005604-a42eb2888e97/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns=
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230711005604-a42eb2888e97/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns=
|
||||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230711033135-d7b26608df94 h1:VrNj5gBFFN9/roWCxyBCZ2gu5k58eremNHQvQNPrfrU=
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230711033135-d7b26608df94 h1:VrNj5gBFFN9/roWCxyBCZ2gu5k58eremNHQvQNPrfrU=
|
||||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230711033135-d7b26608df94/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns=
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230711033135-d7b26608df94/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns=
|
||||||
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230711035757-9fd0dd00cb7d h1:RdxKmMc7kHrTk+SvTYse2IGxmdDhbEDeM0fKAUW+G+w=
|
||||||
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230711035757-9fd0dd00cb7d/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns=
|
||||||
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230711053010-4acb81a20d9c h1:SktFqjnc/UOMjJrq/brSw5lQjW1IA+KkB5YgeovusmQ=
|
||||||
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230711053010-4acb81a20d9c/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns=
|
||||||
|
|||||||
Reference in New Issue
Block a user