aozhiwei 87489f09d3 1
2024-04-02 08:30:14 +08:00

216 lines
4.8 KiB
Go

package guild
import (
"q5"
"f5"
"main/common"
"main/constant"
"fmt"
)
const (
LoadGuildFlag = iota
LoadGuildMemberFlag
LoadGuildReqFlag
LoadGuildLogFlag
)
type guildMgr struct {
idHash map[string]*guild
nameHash map[string]*guild
accountIdHash map[string]*guild
}
func (this *guildMgr) Init() {
this.idHash = make(map[string]*guild)
this.nameHash = make(map[string]*guild)
this.accountIdHash = make(map[string]*guild)
this.loadFromDB()
}
func (this *guildMgr) UnInit() {
}
func (this *guildMgr) loadFromDB() {
/*
f5.GetSysLog().Info("friendMgr.loadFriendships begin")
lastIdx := f5.GetJsStyleDb().SyncBatchLoadFullTable(
constant.FRIEND_DB,
"SELECT * FROM t_guild idx > %d AND deleted = 0",
func (ds *f5.DataSet) {
guildId := ds.GetByName("guild_id")
guildName := ds.GetByName("guild_name")
ownerId := q5.ToInt32(ds.GetByName("owner_id"))
//this.addFriendShip(accountId1, accountId2, addTime)
},
func (err error) {
panic(fmt.Sprintf("friendMgr.loadFriendships dberror:%s", err))
})
*/
/*
f5.GetSysLog().Info("friendMgr.loadFriendships end lastIdx:%d friendNum:%d blackNum:%d",
lastIdx,
len(this.friendHash),
len(this.blackHash))
*/
}
func (this *guildMgr) isNameTooLong(name string, maxNum int) bool {
return len(name) > maxNum
}
func (this *guildMgr) GetGuildByAccountId(accountId string) common.Guild {
if guild, ok := this.accountIdHash[accountId]; ok {
return guild
}
return nil
}
func (this *guildMgr) GetRecommendGuilds(string) []common.Guild {
guilds := []common.Guild{}
return guilds
}
func (this *guildMgr) GetGuildRank() []common.Guild {
guilds := []common.Guild{}
return guilds
}
func (this *guildMgr) AsyncCreateGuild(string, string, func(int32, string, int64)) {
}
func (this *guildMgr) AsyncGetApplyList(lastIdx int64, accountId string,
cb func(int32, string, int64, []string)) {
guild := this.GetGuildByAccountId(accountId)
if guild != nil {
cb(0, "", 0, nil)
return
}
f5.GetJsStyleDb().PageQuery(
constant.FRIEND_DB,
50,
0,
"SELECT * FROM t_guild_apply",
[]string{},
f5.GetDbFilter().Comp(
f5.GetDbFilter().GT("idx", q5.ToString(lastIdx)).And(),
f5.GetDbFilter().EQ("guild_id", guild.GetGuildId()).And(),
f5.GetDbFilter().EQ("account_id", accountId).And(),
f5.GetDbFilter().EQ("status", "0"),
),
"",
func (err error, pg *f5.Pagination) {
var lastSinceId int64
if err != nil {
cb(500, "", lastSinceId, []string{})
}
if pg.Rows.Next() {
idx := q5.ToInt64(pg.Rows.GetByName("idx"))
if idx > lastSinceId {
lastSinceId = idx
} else {
panic(fmt.Sprintf("AsyncGetApply idx error:%s %s", idx, lastSinceId))
}
}
})
}
func (this *guildMgr) AsyncApplyJoin(accountId string, guildId string, cb func(int32, string)) {
guild := this.GetGuildByAccountId(accountId)
if guild != nil {
cb(0, "")
return
}
nowTime := f5.GetApp().GetNowSeconds()
f5.GetJsStyleDb().Upsert(
constant.FRIEND_DB,
"t_guild_apply",
[][]string{
{"guild_id", guildId},
{"account_id", accountId},
},
[][]string{
{"status", q5.ToString(0)},
{"last_apply_time", q5.ToString(nowTime)},
},
[][]string{
{"guild_id", guildId},
{"account_id", accountId},
{"status", q5.ToString(0)},
{"last_apply_time", q5.ToString(nowTime)},
{"createtime", q5.ToString(nowTime)},
{"modifytime", q5.ToString(nowTime)},
},
func (err error, lastInsertId int64, rowsAffected int64) {
if err != nil {
cb(1, "")
return
}
cb(0, "")
})
}
func (this *guildMgr) AsyncAcceptApply(string, string, func(int32, string)) {
}
func (this *guildMgr) AsyncRejectApply(accountId string, guildId string,
cb func(int32, string)) {
this.asyncSetApplyStatus(accountId, guildId, 2)
cb(0, "")
}
func (this *guildMgr) AsyncLeave(string, string, func(int32, string)) {
}
func (this *guildMgr) AsyncKickout(string, string, func(int32, string)) {
}
func (this *guildMgr) AsyncDisband(string, string, func(int32, string)) {
}
func (this *guildMgr) AsyncSetNotice(string, string, func(int32, string)) {
}
func (this *guildMgr) AsyncSetAvatar(string, string, func(int32, string)) {
}
func (this *guildMgr) AsyncSetName(string, string, func(int32, string)) {
}
func (this *guildMgr) AsyncSetJoinCond(string, string, func(int32, string)) {
}
func (this *guildMgr) AsyncSearch(string, string, func(int32, string)) {
}
func (this *guildMgr) AsyncGetGuildLogs(string, string, func(int32, string)) {
}
func (this *guildMgr) asyncSetApplyStatus(accountId string, guildId string, status int32) {
f5.GetJsStyleDb().Update(
constant.FRIEND_DB,
"t_guild_apply",
[][]string{
{"status", q5.ToString(status)},
{"modifytime", q5.ToString(f5.GetApp().GetNowSeconds())},
},
[][]string{
{"account_id", accountId},
{"guild_id", guildId},
},
func (err error, lastInsertId int64, rowsAffected int64) {
})
}