Add 公会日志
This commit is contained in:
parent
449e9f9df3
commit
3f1efa3ee4
@ -27,4 +27,11 @@ const (
|
|||||||
// im server guild
|
// im server guild
|
||||||
const (
|
const (
|
||||||
MaxPendingReqs = 10
|
MaxPendingReqs = 10
|
||||||
|
DefaultLogs = 20
|
||||||
|
LogTypeApprove = 1
|
||||||
|
LogTypeLeave = 2
|
||||||
|
LogTypeDismiss = 3
|
||||||
|
LogTypePromote = 4
|
||||||
|
LogTypeDemote = 5
|
||||||
|
LogTypeDisband = 6
|
||||||
)
|
)
|
||||||
|
@ -260,7 +260,6 @@ func (gm *GuildMgr) updateGuildMembers(g *Guild, fields [][]string) {
|
|||||||
fmt.Printf("rowsAffected:%d\n", rowsAffected)
|
fmt.Printf("rowsAffected:%d\n", rowsAffected)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateGuildMember 更新成员信息
|
// updateGuildMember 更新成员信息
|
||||||
@ -284,3 +283,24 @@ func (gm *GuildMgr) updateGuildMember(g *Guild, accountId string, fields [][]str
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// insertGuildLog 添加公会日志
|
||||||
|
func (gm *GuildMgr) insertGuildLog(log *GuildLog) {
|
||||||
|
fields := [][]string{
|
||||||
|
{"guild_id", q5.ToString(log.GuildId)},
|
||||||
|
{"account_id", log.AccountId},
|
||||||
|
{"log_type", q5.ToString(int(log.LogType))},
|
||||||
|
{"content", log.Content}}
|
||||||
|
|
||||||
|
f5.GetJsStyleDb().Insert(
|
||||||
|
FRIEND_DB,
|
||||||
|
"t_guild_logs",
|
||||||
|
fields,
|
||||||
|
func(err error, lastInsertId int64, rowsAffected int64) {
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("error:%v\n", err)
|
||||||
|
}
|
||||||
|
fmt.Printf("lastInsertId:%d\n", lastInsertId)
|
||||||
|
fmt.Printf("rowsAffected:%d\n", rowsAffected)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -19,7 +19,7 @@ func NewGuildMgr() *GuildMgr {
|
|||||||
return &GuildMgr{
|
return &GuildMgr{
|
||||||
Guilds: make(map[int64]*Guild),
|
Guilds: make(map[int64]*Guild),
|
||||||
pendingReqs: make(map[int64]map[string]bool),
|
pendingReqs: make(map[int64]map[string]bool),
|
||||||
Logs: make(map[int64][]*GuildLog),
|
Logs: make(map[int64][]*GuildLog, DefaultLogs),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +121,9 @@ func (gm *GuildMgr) Approve(guildId int64, operatorAccountId, accountId string)
|
|||||||
delete(gm.pendingReqs[guildId], accountId)
|
delete(gm.pendingReqs[guildId], accountId)
|
||||||
gm.updatePendingReqs(guildId, accountId, 1)
|
gm.updatePendingReqs(guildId, accountId, 1)
|
||||||
|
|
||||||
|
logContent := fmt.Sprintf("Approve[%d-%s-%s]", guildId, operatorAccountId, accountId)
|
||||||
|
gm.WriteLog(guildId, accountId, LogTypeApprove, logContent)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,6 +177,9 @@ func (gm *GuildMgr) LeaveGuild(guildId int64, accountId string) error {
|
|||||||
fields := [][]string{{"is_leave_guild", q5.ToString(1)}}
|
fields := [][]string{{"is_leave_guild", q5.ToString(1)}}
|
||||||
gm.updateGuildMember(guild, member.AccountId, fields)
|
gm.updateGuildMember(guild, member.AccountId, fields)
|
||||||
|
|
||||||
|
logContent := fmt.Sprintf("LeaveGuild[%d-%s]", guildId, accountId)
|
||||||
|
gm.WriteLog(guildId, accountId, LogTypeLeave, logContent)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,6 +217,9 @@ func (gm *GuildMgr) DismissMember(guildId int64, operatorAccountId, accountId st
|
|||||||
fields := [][]string{{"is_leave_guild", q5.ToString(1)}}
|
fields := [][]string{{"is_leave_guild", q5.ToString(1)}}
|
||||||
gm.updateGuildMember(guild, dismissMember.AccountId, fields)
|
gm.updateGuildMember(guild, dismissMember.AccountId, fields)
|
||||||
|
|
||||||
|
logContent := fmt.Sprintf("DismissMember[%d-%s-%s]", guildId, operatorAccountId, accountId)
|
||||||
|
gm.WriteLog(guildId, accountId, LogTypeDismiss, logContent)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,6 +254,9 @@ func (gm *GuildMgr) PromoteMember(guildId int64, operatorAccountId, accountId st
|
|||||||
fields := [][]string{{"level", q5.ToString(newLevel)}}
|
fields := [][]string{{"level", q5.ToString(newLevel)}}
|
||||||
gm.updateGuildMember(guild, member.AccountId, fields)
|
gm.updateGuildMember(guild, member.AccountId, fields)
|
||||||
|
|
||||||
|
logContent := fmt.Sprintf("PromoteMember[%d-%s-%s]", guildId, operatorAccountId, accountId)
|
||||||
|
gm.WriteLog(guildId, accountId, LogTypePromote, logContent)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,22 +291,10 @@ func (gm *GuildMgr) DemoteMember(guildId int64, operatorAccountId, accountId str
|
|||||||
fields := [][]string{{"level", q5.ToString(newLevel)}}
|
fields := [][]string{{"level", q5.ToString(newLevel)}}
|
||||||
gm.updateGuildMember(guild, member.AccountId, fields)
|
gm.updateGuildMember(guild, member.AccountId, fields)
|
||||||
|
|
||||||
return nil
|
logContent := fmt.Sprintf("DemoteMember[%d-%s-%s]", guildId, operatorAccountId, accountId)
|
||||||
}
|
gm.WriteLog(guildId, accountId, LogTypeDemote, logContent)
|
||||||
|
|
||||||
// WriteLog 记录公会日志
|
return nil
|
||||||
func (gm *GuildMgr) WriteLog(guildId int64, accountId string, logType uint16, content string) {
|
|
||||||
_, exists := gm.Logs[guildId]
|
|
||||||
if !exists {
|
|
||||||
gm.Logs[guildId] = make([]*GuildLog, 0)
|
|
||||||
}
|
|
||||||
log := &GuildLog{
|
|
||||||
GuildId: guildId,
|
|
||||||
AccountId: accountId,
|
|
||||||
LogType: logType,
|
|
||||||
Content: content,
|
|
||||||
}
|
|
||||||
gm.Logs[guildId] = append(gm.Logs[guildId], log)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disband 解散公会
|
// Disband 解散公会
|
||||||
@ -331,11 +331,32 @@ func (gm *GuildMgr) Disband(guildId int64, accountId string) error {
|
|||||||
delete(gm.pendingReqs, guildId)
|
delete(gm.pendingReqs, guildId)
|
||||||
delete(gm.Logs, guildId)
|
delete(gm.Logs, guildId)
|
||||||
|
|
||||||
gm.WriteLog(guildId, accountId, 1, "Guild disbanded: "+guildName)
|
logContent := fmt.Sprintf("GuildDisbanded[%d-%s]", guildId, guildName)
|
||||||
|
gm.WriteLog(guildId, accountId, LogTypeDisband, logContent)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WriteLog 记录公会日志
|
||||||
|
func (gm *GuildMgr) WriteLog(guildId int64, accountId string, logType uint16, content string) {
|
||||||
|
_, exists := gm.Logs[guildId]
|
||||||
|
if !exists {
|
||||||
|
gm.Logs[guildId] = make([]*GuildLog, DefaultLogs)
|
||||||
|
}
|
||||||
|
log := &GuildLog{
|
||||||
|
GuildId: guildId,
|
||||||
|
AccountId: accountId,
|
||||||
|
LogType: logType,
|
||||||
|
Content: content,
|
||||||
|
}
|
||||||
|
gm.Logs[guildId] = append(gm.Logs[guildId], log)
|
||||||
|
gm.insertGuildLog(log)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gm *GuildMgr) GetLogs(guildID int64) []*GuildLog {
|
||||||
|
return gm.Logs[guildID]
|
||||||
|
}
|
||||||
|
|
||||||
// SearchGuilds 根据关键字搜索公会
|
// SearchGuilds 根据关键字搜索公会
|
||||||
func (gm *GuildMgr) SearchGuilds(keyword string) []Guild {
|
func (gm *GuildMgr) SearchGuilds(keyword string) []Guild {
|
||||||
var results []Guild
|
var results []Guild
|
||||||
@ -402,10 +423,6 @@ func (gm *GuildMgr) Info(accountId string) (*Guild, map[string]bool, []*GuildLog
|
|||||||
return guild, pendingReqs, guildLogs
|
return guild, pendingReqs, guildLogs
|
||||||
}
|
}
|
||||||
|
|
||||||
func containsSubstring(s, substr string) bool {
|
|
||||||
return len(s) >= len(substr) && s[len(s)-len(substr):] == substr
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gm *GuildMgr) checkOperatorPerm(guild *Guild, operatorAccountId string, level int) error {
|
func (gm *GuildMgr) checkOperatorPerm(guild *Guild, operatorAccountId string, level int) error {
|
||||||
operatorMember, err := guild.GetMember(operatorAccountId)
|
operatorMember, err := guild.GetMember(operatorAccountId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -428,3 +445,7 @@ func (gm *GuildMgr) checkJoinGuild(accountId string) (int64, bool) {
|
|||||||
}
|
}
|
||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func containsSubstring(s, substr string) bool {
|
||||||
|
return len(s) >= len(substr) && s[len(s)-len(substr):] == substr
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user