This commit is contained in:
殷勇 2023-08-25 15:02:15 +08:00
parent 79cd0a6592
commit 8d9bd6bc93
8 changed files with 350 additions and 270 deletions

View File

@ -26,6 +26,7 @@ const (
// im server guild
const (
MaxMembers = 10
MaxPendingReqs = 10
DefaultLogs = 20
LogTypeApprove = 1
@ -37,4 +38,8 @@ const (
GuildMemberLevelLeader = 1 // 成员等级, 会长
GuildMemberLevelCadre = 2 // 成员等级, 干部
GuildMemberLevelDefault = 3 // 成员等级, 普通成员
PendingReqIsJoinGuildStatusDefault = 0 // 等待验证请求状态, 0 等待审核
PendingReqIsJoinGuildStatusJoined = 1 // 等待验证请求状态, 1 已加入
PendingReqIsJoinGuildStatusReject = 2 // 等待验证请求状态, 2 拒绝
PendingReqIsJoinGuildStatusDisband = 3 // 等待验证请求状态, 3 公会已解散
)

View File

@ -1950,7 +1950,7 @@ type SMGuildInfo struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
CurrGuild *MFGuild `protobuf:"bytes,1,opt,name=curr_guild,json=currGuild" json:"curr_guild,omitempty"`
Guild *MFGuild `protobuf:"bytes,1,opt,name=guild" json:"guild,omitempty"`
RandomGuilds []*MFGuild `protobuf:"bytes,2,rep,name=random_guilds,json=randomGuilds" json:"random_guilds,omitempty"`
}
@ -1986,9 +1986,9 @@ func (*SMGuildInfo) Descriptor() ([]byte, []int) {
return file_cs_proto_proto_rawDescGZIP(), []int{35}
}
func (x *SMGuildInfo) GetCurrGuild() *MFGuild {
func (x *SMGuildInfo) GetGuild() *MFGuild {
if x != nil {
return x.CurrGuild
return x.Guild
}
return nil
}
@ -3244,94 +3244,94 @@ var file_cs_proto_proto_rawDesc = []byte{
0x75, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d,
0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d,
0x65, 0x22, 0x0d, 0x0a, 0x0b, 0x43, 0x4d, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x6e, 0x66, 0x6f,
0x22, 0x6b, 0x0a, 0x0b, 0x53, 0x4d, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x6e, 0x66, 0x6f, 0x12,
0x2a, 0x0a, 0x0a, 0x63, 0x75, 0x72, 0x72, 0x5f, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x18, 0x01, 0x20,
0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x63, 0x73, 0x2e, 0x4d, 0x46, 0x47, 0x75, 0x69, 0x6c, 0x64,
0x52, 0x09, 0x63, 0x75, 0x72, 0x72, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x12, 0x30, 0x0a, 0x0d, 0x72,
0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x5f, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x73, 0x18, 0x02, 0x20, 0x03,
0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x63, 0x73, 0x2e, 0x4d, 0x46, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x52,
0x0c, 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x73, 0x22, 0x23, 0x0a,
0x0d, 0x43, 0x4d, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x12, 0x12,
0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61,
0x6d, 0x65, 0x22, 0x43, 0x0a, 0x0d, 0x53, 0x4d, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x47, 0x75,
0x69, 0x6c, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x69, 0x64, 0x18,
0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x64, 0x12, 0x17,
0x0a, 0x07, 0x65, 0x72, 0x72, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x22, 0x2b, 0x0a, 0x0e, 0x43, 0x4d, 0x41, 0x70, 0x70,
0x6c, 0x79, 0x54, 0x6f, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x67, 0x75, 0x69,
0x6c, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x67, 0x75, 0x69,
0x6c, 0x64, 0x49, 0x64, 0x22, 0x29, 0x0a, 0x0e, 0x53, 0x4d, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x54,
0x6f, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x65, 0x72, 0x72, 0x5f, 0x6d, 0x73,
0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x22,
0x58, 0x0a, 0x09, 0x43, 0x4d, 0x41, 0x70, 0x70, 0x72, 0x6f, 0x76, 0x65, 0x12, 0x19, 0x0a, 0x08,
0x67, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07,
0x67, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x64, 0x12, 0x30, 0x0a, 0x14, 0x61, 0x70, 0x70, 0x6c, 0x69,
0x63, 0x61, 0x6e, 0x74, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18,
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x12, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x6e, 0x74,
0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x22, 0x24, 0x0a, 0x09, 0x53, 0x4d, 0x41,
0x70, 0x70, 0x72, 0x6f, 0x76, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x65, 0x72, 0x72, 0x5f, 0x6d, 0x73,
0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x22,
0x57, 0x0a, 0x08, 0x43, 0x4d, 0x52, 0x65, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x67,
0x75, 0x69, 0x6c, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x67,
0x75, 0x69, 0x6c, 0x64, 0x49, 0x64, 0x12, 0x30, 0x0a, 0x14, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63,
0x61, 0x6e, 0x74, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02,
0x20, 0x01, 0x28, 0x09, 0x52, 0x12, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x6e, 0x74, 0x41,
0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x22, 0x23, 0x0a, 0x08, 0x53, 0x4d, 0x52, 0x65,
0x6a, 0x65, 0x63, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x65, 0x72, 0x72, 0x5f, 0x6d, 0x73, 0x67, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x22, 0x29, 0x0a,
0x0c, 0x43, 0x4d, 0x4c, 0x65, 0x61, 0x76, 0x65, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x12, 0x19, 0x0a,
0x08, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52,
0x07, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x64, 0x22, 0x27, 0x0a, 0x0c, 0x53, 0x4d, 0x4c, 0x65,
0x61, 0x76, 0x65, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x65, 0x72, 0x72, 0x5f,
0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73,
0x67, 0x22, 0x58, 0x0a, 0x0f, 0x43, 0x4d, 0x44, 0x69, 0x73, 0x6d, 0x69, 0x73, 0x73, 0x4d, 0x65,
0x6d, 0x62, 0x65, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x69, 0x64,
0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x64, 0x12,
0x2a, 0x0a, 0x10, 0x64, 0x69, 0x73, 0x6d, 0x69, 0x73, 0x73, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e,
0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x64, 0x69, 0x73, 0x6d, 0x69,
0x73, 0x73, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x22, 0x2a, 0x0a, 0x0f, 0x53,
0x4d, 0x44, 0x69, 0x73, 0x6d, 0x69, 0x73, 0x73, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x17,
0x0a, 0x07, 0x65, 0x72, 0x72, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x22, 0x58, 0x0a, 0x0f, 0x43, 0x4d, 0x50, 0x72, 0x6f,
0x6d, 0x6f, 0x74, 0x65, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x67, 0x75,
0x22, 0x62, 0x0a, 0x0b, 0x53, 0x4d, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x6e, 0x66, 0x6f, 0x12,
0x21, 0x0a, 0x05, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b,
0x2e, 0x63, 0x73, 0x2e, 0x4d, 0x46, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x52, 0x05, 0x67, 0x75, 0x69,
0x6c, 0x64, 0x12, 0x30, 0x0a, 0x0d, 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x5f, 0x67, 0x75, 0x69,
0x6c, 0x64, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x63, 0x73, 0x2e, 0x4d,
0x46, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x52, 0x0c, 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x47, 0x75,
0x69, 0x6c, 0x64, 0x73, 0x22, 0x23, 0x0a, 0x0d, 0x43, 0x4d, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65,
0x47, 0x75, 0x69, 0x6c, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x43, 0x0a, 0x0d, 0x53, 0x4d, 0x43,
0x72, 0x65, 0x61, 0x74, 0x65, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x67, 0x75,
0x69, 0x6c, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x67, 0x75,
0x69, 0x6c, 0x64, 0x49, 0x64, 0x12, 0x2a, 0x0a, 0x10, 0x70, 0x72, 0x6f, 0x6d, 0x6f, 0x74, 0x65,
0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
0x10, 0x70, 0x72, 0x6f, 0x6d, 0x6f, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49,
0x64, 0x22, 0x2a, 0x0a, 0x0f, 0x53, 0x4d, 0x50, 0x72, 0x6f, 0x6d, 0x6f, 0x74, 0x65, 0x4d, 0x65,
0x6d, 0x62, 0x65, 0x72, 0x12, 0x17, 0x0a, 0x07, 0x65, 0x72, 0x72, 0x5f, 0x6d, 0x73, 0x67, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x22, 0x55, 0x0a,
0x0e, 0x43, 0x4d, 0x44, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x12,
0x19, 0x0a, 0x08, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
0x03, 0x52, 0x07, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x64, 0x12, 0x28, 0x0a, 0x0f, 0x64, 0x65,
0x6d, 0x6f, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x18, 0x02, 0x20,
0x01, 0x28, 0x09, 0x52, 0x0f, 0x64, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75,
0x6e, 0x74, 0x49, 0x64, 0x22, 0x29, 0x0a, 0x0e, 0x53, 0x4d, 0x44, 0x65, 0x6d, 0x6f, 0x74, 0x65,
0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x17, 0x0a, 0x07, 0x65, 0x72, 0x72, 0x5f, 0x6d, 0x73,
0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x22,
0x26, 0x0a, 0x09, 0x43, 0x4d, 0x44, 0x69, 0x73, 0x62, 0x61, 0x6e, 0x64, 0x12, 0x19, 0x0a, 0x08,
0x67, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07,
0x67, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x64, 0x22, 0x24, 0x0a, 0x09, 0x53, 0x4d, 0x44, 0x69, 0x73,
0x62, 0x61, 0x6e, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x65, 0x72, 0x72, 0x5f, 0x6d, 0x73, 0x67, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x22, 0x2a, 0x0a,
0x0e, 0x43, 0x4d, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x73, 0x12,
0x18, 0x0a, 0x07, 0x6b, 0x65, 0x79, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x07, 0x6b, 0x65, 0x79, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x35, 0x0a, 0x0e, 0x53, 0x4d, 0x53,
0x65, 0x61, 0x72, 0x63, 0x68, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x73, 0x12, 0x23, 0x0a, 0x06, 0x67,
0x75, 0x69, 0x6c, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x63, 0x73,
0x2e, 0x4d, 0x46, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x52, 0x06, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x73,
0x22, 0x90, 0x01, 0x0a, 0x07, 0x4d, 0x46, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x12, 0x19, 0x0a, 0x08,
0x67, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07,
0x67, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18,
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6c,
0x65, 0x61, 0x64, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08,
0x6c, 0x65, 0x61, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x6d, 0x62,
0x65, 0x72, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x6d, 0x65, 0x6d, 0x62, 0x65,
0x72, 0x73, 0x12, 0x1f, 0x0a, 0x0b, 0x6d, 0x61, 0x78, 0x5f, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72,
0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x6d, 0x61, 0x78, 0x4d, 0x65, 0x6d, 0x62,
0x65, 0x72, 0x73, 0x2a, 0x22, 0x0a, 0x0a, 0x43, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x5f,
0x65, 0x12, 0x14, 0x0a, 0x0c, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f,
0x6e, 0x10, 0xd1, 0xa2, 0xd5, 0xc4, 0x07, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x63, 0x73,
0x69, 0x6c, 0x64, 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x65, 0x72, 0x72, 0x5f, 0x6d, 0x73, 0x67,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x22, 0x2b,
0x0a, 0x0e, 0x43, 0x4d, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x54, 0x6f, 0x47, 0x75, 0x69, 0x6c, 0x64,
0x12, 0x19, 0x0a, 0x08, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01,
0x28, 0x03, 0x52, 0x07, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x64, 0x22, 0x29, 0x0a, 0x0e, 0x53,
0x4d, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x54, 0x6f, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x12, 0x17, 0x0a,
0x07, 0x65, 0x72, 0x72, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06,
0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x22, 0x58, 0x0a, 0x09, 0x43, 0x4d, 0x41, 0x70, 0x70, 0x72,
0x6f, 0x76, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x69, 0x64, 0x18,
0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x64, 0x12, 0x30,
0x0a, 0x14, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x6e, 0x74, 0x5f, 0x61, 0x63, 0x63, 0x6f,
0x75, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x12, 0x61, 0x70,
0x70, 0x6c, 0x69, 0x63, 0x61, 0x6e, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64,
0x22, 0x24, 0x0a, 0x09, 0x53, 0x4d, 0x41, 0x70, 0x70, 0x72, 0x6f, 0x76, 0x65, 0x12, 0x17, 0x0a,
0x07, 0x65, 0x72, 0x72, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06,
0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x22, 0x57, 0x0a, 0x08, 0x43, 0x4d, 0x52, 0x65, 0x6a, 0x65,
0x63, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x01,
0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x64, 0x12, 0x30, 0x0a,
0x14, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x6e, 0x74, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75,
0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x12, 0x61, 0x70, 0x70,
0x6c, 0x69, 0x63, 0x61, 0x6e, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x22,
0x23, 0x0a, 0x08, 0x53, 0x4d, 0x52, 0x65, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x65,
0x72, 0x72, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72,
0x72, 0x4d, 0x73, 0x67, 0x22, 0x29, 0x0a, 0x0c, 0x43, 0x4d, 0x4c, 0x65, 0x61, 0x76, 0x65, 0x47,
0x75, 0x69, 0x6c, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x69, 0x64,
0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x64, 0x22,
0x27, 0x0a, 0x0c, 0x53, 0x4d, 0x4c, 0x65, 0x61, 0x76, 0x65, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x12,
0x17, 0x0a, 0x07, 0x65, 0x72, 0x72, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x22, 0x58, 0x0a, 0x0f, 0x43, 0x4d, 0x44, 0x69,
0x73, 0x6d, 0x69, 0x73, 0x73, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x67,
0x75, 0x69, 0x6c, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x67,
0x75, 0x69, 0x6c, 0x64, 0x49, 0x64, 0x12, 0x2a, 0x0a, 0x10, 0x64, 0x69, 0x73, 0x6d, 0x69, 0x73,
0x73, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
0x52, 0x10, 0x64, 0x69, 0x73, 0x6d, 0x69, 0x73, 0x73, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74,
0x49, 0x64, 0x22, 0x2a, 0x0a, 0x0f, 0x53, 0x4d, 0x44, 0x69, 0x73, 0x6d, 0x69, 0x73, 0x73, 0x4d,
0x65, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x17, 0x0a, 0x07, 0x65, 0x72, 0x72, 0x5f, 0x6d, 0x73, 0x67,
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x22, 0x58,
0x0a, 0x0f, 0x43, 0x4d, 0x50, 0x72, 0x6f, 0x6d, 0x6f, 0x74, 0x65, 0x4d, 0x65, 0x6d, 0x62, 0x65,
0x72, 0x12, 0x19, 0x0a, 0x08, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20,
0x01, 0x28, 0x03, 0x52, 0x07, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x64, 0x12, 0x2a, 0x0a, 0x10,
0x70, 0x72, 0x6f, 0x6d, 0x6f, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x70, 0x72, 0x6f, 0x6d, 0x6f, 0x74, 0x65, 0x41,
0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x22, 0x2a, 0x0a, 0x0f, 0x53, 0x4d, 0x50, 0x72,
0x6f, 0x6d, 0x6f, 0x74, 0x65, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x17, 0x0a, 0x07, 0x65,
0x72, 0x72, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72,
0x72, 0x4d, 0x73, 0x67, 0x22, 0x55, 0x0a, 0x0e, 0x43, 0x4d, 0x44, 0x65, 0x6d, 0x6f, 0x74, 0x65,
0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x5f,
0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x49,
0x64, 0x12, 0x28, 0x0a, 0x0f, 0x64, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75,
0x6e, 0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x64, 0x65, 0x6d, 0x6f,
0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x22, 0x29, 0x0a, 0x0e, 0x53,
0x4d, 0x44, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x17, 0x0a,
0x07, 0x65, 0x72, 0x72, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06,
0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x22, 0x26, 0x0a, 0x09, 0x43, 0x4d, 0x44, 0x69, 0x73, 0x62,
0x61, 0x6e, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x69, 0x64, 0x18,
0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x64, 0x22, 0x24,
0x0a, 0x09, 0x53, 0x4d, 0x44, 0x69, 0x73, 0x62, 0x61, 0x6e, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x65,
0x72, 0x72, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72,
0x72, 0x4d, 0x73, 0x67, 0x22, 0x2a, 0x0a, 0x0e, 0x43, 0x4d, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68,
0x47, 0x75, 0x69, 0x6c, 0x64, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x6b, 0x65, 0x79, 0x77, 0x6f, 0x72,
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6b, 0x65, 0x79, 0x77, 0x6f, 0x72, 0x64,
0x22, 0x35, 0x0a, 0x0e, 0x53, 0x4d, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x47, 0x75, 0x69, 0x6c,
0x64, 0x73, 0x12, 0x23, 0x0a, 0x06, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03,
0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x63, 0x73, 0x2e, 0x4d, 0x46, 0x47, 0x75, 0x69, 0x6c, 0x64, 0x52,
0x06, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x73, 0x22, 0x90, 0x01, 0x0a, 0x07, 0x4d, 0x46, 0x47, 0x75,
0x69, 0x6c, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x69, 0x64, 0x18,
0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x64, 0x12, 0x12,
0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61,
0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6c, 0x65, 0x61, 0x64, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18,
0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6c, 0x65, 0x61, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12,
0x18, 0x0a, 0x07, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05,
0x52, 0x07, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x12, 0x1f, 0x0a, 0x0b, 0x6d, 0x61, 0x78,
0x5f, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a,
0x6d, 0x61, 0x78, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x2a, 0x22, 0x0a, 0x0a, 0x43, 0x6f,
0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x5f, 0x65, 0x12, 0x14, 0x0a, 0x0c, 0x50, 0x72, 0x6f, 0x74,
0x6f, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x10, 0xd1, 0xa2, 0xd5, 0xc4, 0x07, 0x42, 0x06,
0x5a, 0x04, 0x2e, 0x3b, 0x63, 0x73,
}
var (
@ -3411,7 +3411,7 @@ var file_cs_proto_proto_goTypes = []interface{}{
var file_cs_proto_proto_depIdxs = []int32{
34, // 0: cs.SMSearchUser.users:type_name -> cs.MFUser
34, // 1: cs.SMListFriend.users:type_name -> cs.MFUser
57, // 2: cs.SMGuildInfo.curr_guild:type_name -> cs.MFGuild
57, // 2: cs.SMGuildInfo.guild:type_name -> cs.MFGuild
57, // 3: cs.SMGuildInfo.random_guilds:type_name -> cs.MFGuild
57, // 4: cs.SMSearchGuilds.guilds:type_name -> cs.MFGuild
5, // [5:5] is the sub-list for method output_type

View File

@ -1,6 +1,8 @@
package main
import "errors"
import (
"fmt"
)
// GuildMember 公会成员
type GuildMember struct {
@ -38,7 +40,7 @@ func (g *Guild) findMemberIndex(AccountId string) int {
func (g *Guild) GetMember(accountId string) (*GuildMember, error) {
index := g.findMemberIndex(accountId)
if index == -1 {
return nil, errors.New("member not found")
return nil, fmt.Errorf("member[%s] not found", accountId)
}
return g.Members[index], nil
@ -53,7 +55,7 @@ func (g *Guild) isMember(accountId string) bool {
// AddMember 添加成员
func (g *Guild) AddMember(member *GuildMember) error {
if len(g.Members) >= g.MaxMembers {
return errors.New("guild is full")
return fmt.Errorf("guild is full")
}
g.Members = append(g.Members, member)
return nil
@ -62,12 +64,12 @@ func (g *Guild) AddMember(member *GuildMember) error {
// RemoveMember 移除成员
func (g *Guild) RemoveMember(accountId string) error {
if accountId == g.LeaderId {
return errors.New("cannot remove leader")
return fmt.Errorf("cannot remove leader")
}
index := g.findMemberIndex(accountId)
if index == -1 {
return errors.New("member not found")
return fmt.Errorf("member not found")
}
//g.Members = append(g.Members[:index], g.Members[index+1:]...)

View File

@ -2,7 +2,6 @@ package main
import (
"f5"
"fmt"
"q5"
)
@ -22,7 +21,7 @@ func (gm *GuildMgr) loadGuildFromDB() {
}
func (gm *GuildMgr) loadGuildFromDBResult(err error, rows *f5.DataSet) {
if err != nil {
fmt.Printf("loadGuildFromDBResult err:%v \n", err)
f5.GetSysLog().Info("loadGuildFromDBResult err:%v \n", err)
return
}
for rows.Next() {
@ -48,7 +47,6 @@ func (gm *GuildMgr) loadGuildFromDBResult(err error, rows *f5.DataSet) {
// init pendingReqs
gm.pendingReqs[guildId] = make(map[string]bool)
}
fmt.Printf("loadGuildFromDB finished guilds:%d\n", len(gm.Guilds))
}
// loadGuildMemberFromDB 加载公会成员
@ -67,7 +65,7 @@ func (gm *GuildMgr) loadGuildMemberFromDB() {
}
func (gm *GuildMgr) loadGuildMemberFromDBResult(err error, rows *f5.DataSet) {
if err != nil {
fmt.Printf("loadGuildFromDBResult err:%v \n", err)
f5.GetSysLog().Info("loadGuildMemberFromDBResult err:%v \n", err)
return
}
for rows.Next() {
@ -97,7 +95,7 @@ func (gm *GuildMgr) loadGuildMemberFromDBResult(err error, rows *f5.DataSet) {
func (gm *GuildMgr) loadPendingReqsFromDB() {
fields := []string{"guild_id", "account_id"}
where := [][]string{
{"is_join_guild", "0"},
{"is_join_guild", q5.ToString(PendingReqIsJoinGuildStatusDefault)},
}
f5.GetJsStyleDb().Select(
FRIEND_DB,
@ -109,7 +107,7 @@ func (gm *GuildMgr) loadPendingReqsFromDB() {
}
func (gm *GuildMgr) loadPendingReqsFromDBResult(err error, rows *f5.DataSet) {
if err != nil {
fmt.Printf("loadPendingReqsFromDBResult err:%v \n", err)
f5.GetSysLog().Info("loadPendingReqsFromDBResult err:%v \n", err)
return
}
for rows.Next() {
@ -123,6 +121,55 @@ func (gm *GuildMgr) loadPendingReqsFromDBResult(err error, rows *f5.DataSet) {
}
}
// loadGuildLogsFromDB 加载公会日志
func (gm *GuildMgr) loadGuildLogsFromDB() {
var perPage int32 = 10
var page int32 = 1
sql := "SELECT `guild_id`, `account_id`, `log_type`, `content` FROM `t_guild_logs`"
var params []string
var filter f5.DbQueryFilter
orderBy := "ORDER BY `createtime` DESC"
f5.GetJsStyleDb().PageQuery(
FRIEND_DB,
perPage,
page,
sql,
params,
filter,
orderBy,
gm.loadGuildLogsFromDBResult,
)
}
func (gm *GuildMgr) loadGuildLogsFromDBResult(err error, pagination *f5.Pagination) {
if err != nil {
f5.GetSysLog().Info("loadPendingReqsFromDBResult err:%v \n", err)
return
}
//total := pagination.Total
var (
guildId int64
accountId string
logType uint16
content string
)
gm.Logs[guildId] = make([]*GuildLog, DefaultLogs)
for pagination.Rows.Next() {
guildId = q5.ToInt64(*pagination.Rows.GetByIndex(0))
accountId = q5.ToString(*pagination.Rows.GetByIndex(1))
logType = uint16(q5.ToInt32(*pagination.Rows.GetByIndex(2)))
content = q5.ToString(*pagination.Rows.GetByIndex(3))
guildLog := &GuildLog{
GuildId: guildId,
AccountId: accountId,
LogType: logType,
Content: content,
}
gm.Logs[guildId] = append(gm.Logs[guildId], guildLog)
}
}
// createGuildDB 创建公会
func (gm *GuildMgr) createGuildDB(g *Guild) {
fields := [][]string{
@ -137,10 +184,10 @@ func (gm *GuildMgr) createGuildDB(g *Guild) {
fields,
func(err error, lastInsertId int64, rowsAffected int64) {
if err != nil {
fmt.Printf("error:%v\n", err)
f5.GetSysLog().Info("error:%v\n", err)
}
fmt.Printf("lastInsertId:%d\n", lastInsertId)
fmt.Printf("rowsAffected:%d\n", rowsAffected)
f5.GetSysLog().Info("lastInsertId:%d\n", lastInsertId)
f5.GetSysLog().Info("rowsAffected:%d\n", rowsAffected)
},
)
}
@ -160,7 +207,7 @@ func (gm *GuildMgr) updateGuild(g *Guild, fields [][]string) {
}
// insertPendingReqs 添加申请加入公会记录, 存在则更新记录
func (gm *GuildMgr) upsertPendingReqs(guildId int64, accountId string, isJoinGuild string) {
func (gm *GuildMgr) upsertPendingReqs(guildId int64, accountId string, isJoinGuild int) {
where := [][]string{
{"guild_id", q5.ToString(guildId)},
{"account_id", accountId},
@ -168,10 +215,10 @@ func (gm *GuildMgr) upsertPendingReqs(guildId int64, accountId string, isJoinGui
insertKv := [][]string{
{"guild_id", q5.ToString(guildId)},
{"account_id", accountId},
{"is_join_guild", "0"},
{"is_join_guild", q5.ToString(isJoinGuild)},
}
updateKv := [][]string{
{"is_join_guild", isJoinGuild},
{"is_join_guild", q5.ToString(isJoinGuild)},
}
f5.GetJsStyleDb().Upsert(
FRIEND_DB,
@ -181,10 +228,10 @@ func (gm *GuildMgr) upsertPendingReqs(guildId int64, accountId string, isJoinGui
insertKv,
func(err error, lastInsertId int64, rowsAffected int64) {
if err != nil {
fmt.Printf("error:%v\n", err)
f5.GetSysLog().Info("error:%v\n", err)
}
fmt.Printf("lastInsertId:%d\n", lastInsertId)
fmt.Printf("rowsAffected:%d\n", rowsAffected)
f5.GetSysLog().Info("lastInsertId:%d\n", lastInsertId)
f5.GetSysLog().Info("rowsAffected:%d\n", rowsAffected)
})
}
@ -203,18 +250,18 @@ func (gm *GuildMgr) updateAllPendingReqs(guildId int64, isJoinGuild int) {
where,
func(err error, lastInsertId int64, rowsAffected int64) {
if err != nil {
fmt.Printf("error:%v\n", err)
f5.GetSysLog().Info("error:%v\n", err)
}
fmt.Printf("lastInsertId:%d\n", lastInsertId)
fmt.Printf("rowsAffected:%d\n", rowsAffected)
f5.GetSysLog().Info("lastInsertId:%d\n", lastInsertId)
f5.GetSysLog().Info("rowsAffected:%d\n", rowsAffected)
},
)
}
// updatePendingReqs 更新申请加入公会记录
func (gm *GuildMgr) updatePendingReqs(guildId int64, accountId string, isJoinGuild string) {
func (gm *GuildMgr) updatePendingReqs(guildId int64, accountId string, isJoinGuild int) {
fields := [][]string{
{"is_join_guild", isJoinGuild},
{"is_join_guild", q5.ToString(isJoinGuild)},
}
where := [][]string{
{"guild_id", q5.ToString(guildId)},
@ -227,10 +274,10 @@ func (gm *GuildMgr) updatePendingReqs(guildId int64, accountId string, isJoinGui
where,
func(err error, lastInsertId int64, rowsAffected int64) {
if err != nil {
fmt.Printf("error:%v\n", err)
f5.GetSysLog().Info("error:%v\n", err)
}
fmt.Printf("lastInsertId:%d\n", lastInsertId)
fmt.Printf("rowsAffected:%d\n", rowsAffected)
f5.GetSysLog().Info("lastInsertId:%d\n", lastInsertId)
f5.GetSysLog().Info("rowsAffected:%d\n", rowsAffected)
},
)
}
@ -256,10 +303,10 @@ func (gm *GuildMgr) upsertGuildMember(guildId int64, member *GuildMember) {
insertKv,
func(err error, lastInsertId int64, rowsAffected int64) {
if err != nil {
fmt.Printf("error:%v\n", err)
f5.GetSysLog().Info("error:%v\n", err)
}
fmt.Printf("lastInsertId:%d\n", lastInsertId)
fmt.Printf("rowsAffected:%d\n", rowsAffected)
f5.GetSysLog().Info("lastInsertId:%d\n", lastInsertId)
f5.GetSysLog().Info("rowsAffected:%d\n", rowsAffected)
},
)
}
@ -275,10 +322,10 @@ func (gm *GuildMgr) updateGuildMembers(g *Guild, fields [][]string) {
where,
func(err error, lastInsertId int64, rowsAffected int64) {
if err != nil {
fmt.Printf("error:%v\n", err)
f5.GetSysLog().Info("error:%v\n", err)
}
fmt.Printf("lastInsertId:%d\n", lastInsertId)
fmt.Printf("rowsAffected:%d\n", rowsAffected)
f5.GetSysLog().Info("lastInsertId:%d\n", lastInsertId)
f5.GetSysLog().Info("rowsAffected:%d\n", rowsAffected)
},
)
}
@ -297,10 +344,10 @@ func (gm *GuildMgr) updateGuildMember(g *Guild, accountId string, fields [][]str
where,
func(err error, lastInsertId int64, rowsAffected int64) {
if err != nil {
fmt.Printf("error:%v\n", err)
f5.GetSysLog().Info("error:%v\n", err)
}
fmt.Printf("lastInsertId:%d\n", lastInsertId)
fmt.Printf("rowsAffected:%d\n", rowsAffected)
f5.GetSysLog().Info("lastInsertId:%d\n", lastInsertId)
f5.GetSysLog().Info("rowsAffected:%d\n", rowsAffected)
},
)
}
@ -318,9 +365,9 @@ func (gm *GuildMgr) insertGuildLog(log *GuildLog) {
fields,
func(err error, lastInsertId int64, rowsAffected int64) {
if err != nil {
fmt.Printf("error:%v\n", err)
f5.GetSysLog().Info("error:%v\n", err)
}
fmt.Printf("lastInsertId:%d\n", lastInsertId)
fmt.Printf("rowsAffected:%d\n", rowsAffected)
f5.GetSysLog().Info("lastInsertId:%d\n", lastInsertId)
f5.GetSysLog().Info("rowsAffected:%d\n", rowsAffected)
})
}

View File

@ -19,45 +19,53 @@ func NewGuildMgr() *GuildMgr {
return &GuildMgr{
Guilds: make(map[int64]*Guild),
pendingReqs: make(map[int64]map[string]bool),
Logs: make(map[int64][]*GuildLog, DefaultLogs),
Logs: make(map[int64][]*GuildLog),
}
}
func (gm *GuildMgr) init() {
gm.pendingReqs = make(map[int64]map[string]bool)
gm.loadFromDB()
}
func (gm *GuildMgr) loadFromDB() {
// 加载公会
gm.loadGuildFromDB()
// 加载公会成员
gm.loadGuildMemberFromDB()
// 加载公会申请者列表
gm.loadPendingReqsFromDB()
// 加载公会日志
gm.loadGuildLogsFromDB()
}
// CreateGuild 创建公会
func (gm *GuildMgr) CreateGuild(name string, leaderID string) (int64, error) {
// Check joined guild
otherGuildId, isJoined := gm.checkJoinGuild(leaderID)
if isJoined {
errMsg := fmt.Sprintf("Player:%s has joined other guild:%d", leaderID, otherGuildId)
return 0, fmt.Errorf(errMsg)
func (gm *GuildMgr) CreateGuild(name string, leaderId string) (int64, error) {
_, err := gm.checkJoinGuild(leaderId)
if err != nil {
return 0, err
}
guildId := f5.GetApp().NewUuid()
if _, exists := gm.Guilds[guildId]; exists {
return 0, fmt.Errorf("guild already exists")
return 0, fmt.Errorf("CreateGuild fail")
}
maxMembers := 10
guild := &Guild{
GuildId: guildId,
Name: name,
LeaderId: leaderID,
MaxMembers: maxMembers,
LeaderId: leaderId,
MaxMembers: MaxMembers,
}
gm.createGuildDB(guild)
newMember := GuildMember{AccountId: leaderID, Level: GuildMemberLevelLeader}
_ = guild.AddMember(&newMember)
newMember := GuildMember{AccountId: leaderId, Level: GuildMemberLevelLeader}
err = guild.AddMember(&newMember)
if err != nil {
return 0, err
}
gm.createGuildDB(guild)
gm.upsertGuildMember(guildId, &newMember)
gm.Guilds[guildId] = guild
return guildId, nil
@ -68,20 +76,26 @@ func (gm *GuildMgr) ApplyToGuild(guildId int64, applicantAccountId string) error
if _, exists := gm.Guilds[guildId]; !exists {
return fmt.Errorf("guild not found")
}
// check join guild
otherGuildId, isJoin := gm.checkJoinGuild(applicantAccountId)
if isJoin {
errMsg := fmt.Sprintf("Player:%s has joined other guild:%d", applicantAccountId, otherGuildId)
return fmt.Errorf(errMsg)
_, err := gm.checkJoinGuild(applicantAccountId)
if err != nil {
return err
}
guild := gm.Guilds[guildId]
if len(guild.Members) >= guild.MaxMembers {
return fmt.Errorf("guild is full")
}
// IF exists, then replace it
gm.upsertPendingReqs(guildId, applicantAccountId, "0")
gm.pendingReqs[guildId][applicantAccountId] = true
// IF exists, then replace it fields `isJoinGuild` is 0
gm.upsertPendingReqs(guildId, applicantAccountId, PendingReqIsJoinGuildStatusDefault)
pendReq, exists := gm.pendingReqs[guildId]
if !exists {
pendReq = make(map[string]bool)
}
pendReq[applicantAccountId] = true
return nil
}
@ -92,16 +106,20 @@ func (gm *GuildMgr) Approve(guildId int64, operatorAccountId, accountId string)
return fmt.Errorf("guild not found")
}
// 公会干部及以上仅可操作
err := gm.checkOperatorPerm(guild, operatorAccountId, GuildMemberLevelCadre)
operatorMember, err := guild.GetMember(operatorAccountId)
if err != nil {
return err
}
otherGuildId, isJoin := gm.checkJoinGuild(accountId)
if isJoin {
errMsg := fmt.Sprintf("Player:%s has joined other guild:%d", accountId, otherGuildId)
return fmt.Errorf(errMsg)
// 公会干部及以上仅可操作
err = gm.checkOperatorPerm(operatorMember, GuildMemberLevelCadre)
if err != nil {
return err
}
_, err = gm.checkJoinGuild(accountId)
if err != nil {
return err
}
_, exists = gm.pendingReqs[guildId][accountId]
@ -114,12 +132,13 @@ func (gm *GuildMgr) Approve(guildId int64, operatorAccountId, accountId string)
if err != nil {
return err
}
gm.upsertGuildMember(guildId, &newMember)
delete(gm.pendingReqs[guildId], accountId)
gm.updatePendingReqs(guildId, accountId, "1")
logContent := fmt.Sprintf("Approve[%d-%s-%s]", guildId, operatorAccountId, accountId)
gm.upsertGuildMember(guildId, &newMember)
gm.updatePendingReqs(guildId, accountId, PendingReqIsJoinGuildStatusJoined)
logContent := fmt.Sprintf("Approve[operator:%s]", operatorAccountId)
gm.WriteLog(guildId, accountId, LogTypeApprove, logContent)
delete(gm.pendingReqs[guildId], accountId)
return nil
}
@ -131,9 +150,8 @@ func (gm *GuildMgr) Reject(guildId int64, applicantAccountId string) error {
return fmt.Errorf("no pending applications for this guild")
}
//delete(gm.pendingReqs[guildId], applicantAccountId)
gm.pendingReqs[guildId][applicantAccountId] = false
gm.updatePendingReqs(guildId, applicantAccountId, "2")
gm.updatePendingReqs(guildId, applicantAccountId, PendingReqIsJoinGuildStatusReject)
delete(gm.pendingReqs[guildId], applicantAccountId)
return nil
}
@ -157,7 +175,7 @@ func (gm *GuildMgr) JoinGuild(guildId int64, accountId string) error {
gm.upsertGuildMember(guildId, &newMember)
delete(gm.pendingReqs[guildId], accountId)
gm.updatePendingReqs(guildId, accountId, "1")
gm.updatePendingReqs(guildId, accountId, PendingReqIsJoinGuildStatusJoined)
return nil
}
@ -199,21 +217,27 @@ func (gm *GuildMgr) DismissMember(guildId int64, operatorAccountId, accountId st
return fmt.Errorf("cannot dismiss the leader")
}
// 公会干部及以上仅可操作
err := gm.checkOperatorPerm(guild, operatorAccountId, GuildMemberLevelCadre)
if operatorAccountId == accountId {
return fmt.Errorf("cannot dismiss yourself")
}
operatorMember, err := guild.GetMember(operatorAccountId)
if err != nil {
return err
}
if operatorAccountId == accountId {
return fmt.Errorf("member not dismiss")
// 公会干部及以上仅可操作
err = gm.checkOperatorPerm(operatorMember, GuildMemberLevelCadre)
if err != nil {
return err
}
dismissMember, err := guild.GetMember(accountId)
if err != nil {
return fmt.Errorf("member not found in the guild")
}
if dismissMember.Level <= 2 {
if dismissMember.Level <= operatorMember.Level {
return fmt.Errorf("no permission")
}
@ -238,16 +262,25 @@ func (gm *GuildMgr) PromoteMember(guildId int64, operatorAccountId, accountId st
return fmt.Errorf("cannot promote the leader")
}
// 会长仅可操作
err := gm.checkOperatorPerm(guild, operatorAccountId, GuildMemberLevelLeader)
// 会长操作
operatorMember, err := guild.GetMember(operatorAccountId)
if err != nil {
return err
}
err = gm.checkOperatorPerm(operatorMember, GuildMemberLevelLeader)
if err != nil {
return err
}
if operatorAccountId != guild.LeaderId {
return fmt.Errorf("PromoteMember: No, leader")
}
member, err := guild.GetMember(accountId)
if err != nil {
return fmt.Errorf("member not found in the guild")
}
if member.Level == GuildMemberLevelCadre {
return nil
}
@ -273,11 +306,19 @@ func (gm *GuildMgr) DemoteMember(guildId int64, operatorAccountId, accountId str
return fmt.Errorf("cannot demote the leader")
}
// 会长仅可操作
err := gm.checkOperatorPerm(guild, operatorAccountId, GuildMemberLevelLeader)
// 会长操作
operatorMember, err := guild.GetMember(operatorAccountId)
if err != nil {
return err
}
err = gm.checkOperatorPerm(operatorMember, GuildMemberLevelLeader)
if err != nil {
return err
}
if operatorAccountId != guild.LeaderId {
return fmt.Errorf("PromoteMember: No, leader")
}
member, err := guild.GetMember(accountId)
if err != nil {
@ -287,6 +328,7 @@ func (gm *GuildMgr) DemoteMember(guildId int64, operatorAccountId, accountId str
if member.Level == GuildMemberLevelDefault {
return nil
}
member.Level = GuildMemberLevelDefault
fields := [][]string{{"level", q5.ToString(GuildMemberLevelDefault)}}
gm.updateGuildMember(guild, member.AccountId, fields)
@ -304,13 +346,11 @@ func (gm *GuildMgr) Disband(guildId int64, accountId string) error {
return fmt.Errorf("guild not found")
}
// 会长可操作
// 会长可操作
if accountId != guild.LeaderId {
return fmt.Errorf("cannot disband guild")
}
guildName := guild.Name
guild.Members = nil
updateFields := [][]string{
{"is_deleted", q5.ToString(1)},
@ -320,11 +360,11 @@ func (gm *GuildMgr) Disband(guildId int64, accountId string) error {
fields := [][]string{{"is_leave_guild", q5.ToString(1)}}
gm.updateGuildMembers(guild, fields)
isJoinGuild := 3
gm.updateAllPendingReqs(guildId, isJoinGuild)
gm.updateAllPendingReqs(guildId, PendingReqIsJoinGuildStatusDisband)
// 确保在删除之前没有其他地方引用了公会对象的指针, 以避免空指针异常
guild.Members = nil
gm.Guilds[guildId] = nil
gm.pendingReqs[guildId] = nil
gm.Logs[guildId] = nil
delete(gm.Guilds, guildId)
@ -409,6 +449,13 @@ func (gm *GuildMgr) GetGuildByAccountId(accountId string) *Guild {
return nil
}
func (gm *GuildMgr) getGuild(guildId int64) *Guild {
if guild, ok := gm.Guilds[guildId]; ok {
return guild
}
return nil
}
// Info 工会信息
func (gm *GuildMgr) Info(accountId string) (*Guild, map[string]bool, []*GuildLog) {
guild := gm.GetGuildByAccountId(accountId)
@ -423,27 +470,20 @@ func (gm *GuildMgr) Info(accountId string) (*Guild, map[string]bool, []*GuildLog
return guild, pendingReqs, guildLogs
}
func (gm *GuildMgr) checkOperatorPerm(guild *Guild, operatorAccountId string, level int) error {
operatorMember, err := guild.GetMember(operatorAccountId)
if err != nil {
//return fmt.Errorf("checkOperatorPerm: no member")
return fmt.Errorf("checkOperatorPerm: no member[%s]", operatorAccountId)
}
func (gm *GuildMgr) checkOperatorPerm(operatorMember *GuildMember, level int) error {
if operatorMember.Level > level {
return fmt.Errorf("checkOperatorPerm: no permission[%s-%d]", operatorAccountId, operatorMember.Level)
return fmt.Errorf("checkOperatorPerm: no permission[%s-%d]", operatorMember.AccountId, operatorMember.Level)
}
return nil
}
func (gm *GuildMgr) checkJoinGuild(accountId string) (int64, bool) {
for guildId, guild := range gm.Guilds {
for _, member := range guild.Members {
if accountId == member.AccountId {
return guildId, true
func (gm *GuildMgr) checkJoinGuild(accountId string) (bool, error) {
guild := gm.GetGuildByAccountId(accountId)
if guild != nil {
errMsg := fmt.Sprintf("Player:%s has joined other GuildId:%d", accountId, guild.GuildId)
return true, fmt.Errorf(errMsg)
}
}
}
return 0, false
return false, nil
}
func containsSubstring(s, substr string) bool {

View File

@ -1,56 +1,49 @@
package main
import (
"f5"
"fmt"
"q5"
"testing"
)
func TestGuild(t *testing.T) {
guildMgr := NewGuildMgr()
leaderID := "apple"
memberID := "sony"
var (
leaderId = "6513_2006_test134345"
member1Id = "6513_2006_111"
member2Id = "6513_2006_222"
)
guildID, err := guildMgr.CreateGuild("GuildWorld", leaderID)
var newGuildId int64 = 1148210928160867328
func TestCreateGuild(t *testing.T) {
f5.TestRun(app)
guildMgr := NewGuildMgr()
guildName := randomGuildName()
guildId, err := guildMgr.CreateGuild(guildName, leaderId)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Created guild:", guildID)
err = guildMgr.ApplyToGuild(guildID, memberID)
newGuildId = guildId
fmt.Println("Created guild:", guildId)
}
func TestGuildMember(t *testing.T) {
f5.TestRun(app)
if newGuildId <= 0 {
t.Errorf("guildId error: %v", newGuildId)
}
err := guildMgr.ApplyToGuild(newGuildId, member1Id)
if err != nil {
fmt.Println("Error:", err)
t.Errorf("Error:%s", err)
return
}
fmt.Println("Applied to guild")
err = guildMgr.Approve(guildID, memberID)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Approved application")
err = guildMgr.PromoteMember(guildID, memberID, memberID)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Promoted member")
err = guildMgr.LeaveGuild(guildID, memberID)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Left guild")
err = guildMgr.DismissMember(guildID, memberID, memberID)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Dismissed member")
fmt.Println("Guild logs:", guildMgr.Logs)
}
func randomGuildName() string {
return q5.RandomString(6)
}

View File

@ -3,7 +3,6 @@ package main
import (
"cs"
"f5"
"fmt"
"q5"
)
@ -230,7 +229,12 @@ func (p *Player) CMFriendInfo(hdr *f5.MsgHdr, msg *cs.CMFriendInfo) {
func (p *Player) CMGuildInfo(hdr *f5.MsgHdr, msg *cs.CMGuildInfo) {
rspMsg := new(cs.SMGuildInfo)
g := guildMgr.GetGuildByAccountId(p.accountId)
if g != nil {
if g == nil {
rspMsg.Guild = nil
rspMsg.RandomGuilds = p.FillGuild(guildMgr.RandomGuilds())
wspListener.sendProxyMsg(hdr.Conn, hdr.SocketHandle, rspMsg)
return
}
members := q5.ToInt32(len(g.Members))
maxMembers := q5.ToInt32(g.MaxMembers)
currGuild := &cs.MFGuild{
@ -240,33 +244,22 @@ func (p *Player) CMGuildInfo(hdr *f5.MsgHdr, msg *cs.CMGuildInfo) {
Members: &members,
MaxMembers: &maxMembers,
}
rspMsg.CurrGuild = currGuild
rspMsg.Guild = currGuild
rspMsg.RandomGuilds = nil
} else {
rspMsg.CurrGuild = nil
rspMsg.RandomGuilds = p.FillGuild(guildMgr.RandomGuilds())
}
wspListener.sendProxyMsg(hdr.Conn, hdr.SocketHandle, rspMsg)
}
// CMCreateGuild 创建公会
func (p *Player) CMCreateGuild(hdr *f5.MsgHdr, msg *cs.CMCreateGuild) {
rspMsg := new(cs.SMCreateGuild)
guildId, err := guildMgr.CreateGuild(
*msg.Name,
p.accountId,
)
fmt.Printf("new guildId:%v \n", guildId)
guildId, err := guildMgr.CreateGuild(*msg.Name, p.accountId)
if err != nil {
errMsg := err.Error()
rspMsg.ErrMsg = &errMsg
f5.GetSysLog().Info("CMCreateGuild err:%s\n", errMsg)
} else {
rspMsg.GuildId = &guildId
}
wspListener.sendProxyMsg(hdr.Conn, hdr.SocketHandle, rspMsg)
}

View File

@ -271,7 +271,7 @@ message CMGuildInfo
//
message SMGuildInfo
{
optional MFGuild curr_guild = 1;
optional MFGuild guild = 1;
repeated MFGuild random_guilds = 2;
}