save
This commit is contained in:
parent
feba3f571d
commit
4af6594e8b
@ -134,4 +134,5 @@ const (
|
||||
ERR_CODE_GUILD_SETMEMBERLEVEL_VICE_LEADER_MAX_LIMIT = 12019
|
||||
ERR_CODE_GUILD_SETNAME_DUPLICATE_NAMES = 12020
|
||||
ERR_CODE_GUILD_SETNAME_API_ERROR = 12021
|
||||
ERR_CODE_GUILD_NAME_TOO_LONG = 12022
|
||||
)
|
||||
|
@ -57,19 +57,32 @@ func (gm *GuildMgr) loadFromDB() {
|
||||
//}
|
||||
}
|
||||
|
||||
func (gm *GuildMgr) IsTooLongGuildName(name string) bool {
|
||||
return len(name) > 15
|
||||
}
|
||||
|
||||
// CreateGuild 创建公会
|
||||
func (gm *GuildMgr) CreateGuild(p *Player, avatar int32, name *string, leaderId string,
|
||||
func (gm *GuildMgr) CreateGuild(p *Player, avatar int32, guildName string, leaderId string,
|
||||
cb func(errCode int32, errMsg string, guild *Guild)) {
|
||||
|
||||
if len(guildName) <= 0 {
|
||||
cb(ERR_CODE_REQUEST_PARAMS_ERROR, "params is null", nil)
|
||||
return
|
||||
}
|
||||
if gm.IsTooLongGuildName(guildName) {
|
||||
cb(ERR_CODE_GUILD_NAME_TOO_LONG, "Guild name is too long (max length: 15)", nil)
|
||||
}
|
||||
if gm.CheckJoinGuild(leaderId) {
|
||||
cb(ERR_CODE_JOINED_GUILD, "Joined guild", nil)
|
||||
return
|
||||
}
|
||||
|
||||
guildId := f5.GetApp().NewUuid()
|
||||
if gm.ExistsGuild(guildId) {
|
||||
cb(ERR_CODE_CREATE_GUILD_FAIL, "create error ", nil)
|
||||
return
|
||||
}
|
||||
if !gm.CheckGuildNameUnique(name) {
|
||||
if !gm.CheckGuildNameUnique(guildName) {
|
||||
cb(ERR_CODE_CREATE_GUILD_FAIL, "Duplicate guild names", nil)
|
||||
return
|
||||
}
|
||||
@ -86,17 +99,17 @@ func (gm *GuildMgr) CreateGuild(p *Player, avatar int32, name *string, leaderId
|
||||
return
|
||||
}
|
||||
// Bag.createGuildConsume 道具使用成功,继续创建公会
|
||||
gm.createGuildInternal(guildId, avatar, name, leaderId, cb)
|
||||
gm.createGuildInternal(guildId, avatar, guildName, leaderId, cb)
|
||||
})
|
||||
}
|
||||
|
||||
func (gm *GuildMgr) createGuildInternal(guildId int64, avatar int32, name *string, leaderId string,
|
||||
func (gm *GuildMgr) createGuildInternal(guildId int64, avatar int32, name string, leaderId string,
|
||||
cb func(errCode int32, errMsg string, guild *Guild)) {
|
||||
|
||||
unixSec := time.Now().Unix()
|
||||
fields := [][]string{
|
||||
{"guild_id", q5.ToString(guildId)},
|
||||
{"name", *name},
|
||||
{"name", name},
|
||||
{"leader_account_id", leaderId},
|
||||
{"avatar", q5.ToString(avatar)},
|
||||
{"max_members", q5.ToString(MaxMembers)},
|
||||
@ -126,7 +139,7 @@ func (gm *GuildMgr) createGuildInternal(guildId int64, avatar int32, name *strin
|
||||
guild := &Guild{
|
||||
AutoId: lastInsertId,
|
||||
GuildId: guildId,
|
||||
Name: *name,
|
||||
Name: name,
|
||||
LeaderId: leaderId,
|
||||
Avatar: avatar,
|
||||
Notice: "",
|
||||
@ -147,7 +160,7 @@ func (gm *GuildMgr) createGuildInternal(guildId int64, avatar int32, name *strin
|
||||
prop := make(map[string]string)
|
||||
prop["auto_id"] = q5.ToString(lastInsertId)
|
||||
prop["guild_id"] = q5.ToString(guildId)
|
||||
prop["guild_name"] = *name
|
||||
prop["guild_name"] = name
|
||||
prop["avatar"] = q5.ToString(avatar)
|
||||
f5.GetTgLog().AddTrackLog(
|
||||
GAME_ID,
|
||||
@ -695,9 +708,9 @@ func (gm *GuildMgr) CheckGuildAndPermission(operatorAccountId string) (*Guild, b
|
||||
return guild, true
|
||||
}
|
||||
|
||||
func (gm *GuildMgr) CheckGuildNameUnique(newName *string) bool {
|
||||
func (gm *GuildMgr) CheckGuildNameUnique(newName string) bool {
|
||||
for _, g := range gm.guilds {
|
||||
if g.Name == *newName {
|
||||
if g.Name == newName {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -725,17 +738,20 @@ func (gm *GuildMgr) SetAvatar(operatorAccountId string, avatar int32, cb func(er
|
||||
})
|
||||
}
|
||||
|
||||
func (gm *GuildMgr) SetName(player *Player, name *string, itemId, itemNum int32, cb func(errCode int32, errMsg string)) {
|
||||
func (gm *GuildMgr) SetName(player *Player, name string, itemId, itemNum int32, cb func(errCode int32, errMsg string)) {
|
||||
guild, ok := gm.CheckGuildAndPermission(player.GetAccountId())
|
||||
if !ok || name == nil {
|
||||
|
||||
if !ok || len(name) <= 0 {
|
||||
cb(ERR_CODE_REQUEST_PARAMS_ERROR, "params is null")
|
||||
return
|
||||
}
|
||||
if gm.IsTooLongGuildName(name) {
|
||||
cb(ERR_CODE_GUILD_NAME_TOO_LONG, "Guild name is too long (max length: 15)")
|
||||
}
|
||||
if !gm.CheckGuildNameUnique(name) {
|
||||
cb(ERR_CODE_GUILD_SETNAME_DUPLICATE_NAMES, "Duplicate guild names")
|
||||
return
|
||||
}
|
||||
|
||||
// 扣消耗
|
||||
params := map[string]string{
|
||||
"c": "Bag",
|
||||
@ -751,7 +767,7 @@ func (gm *GuildMgr) SetName(player *Player, name *string, itemId, itemNum int32,
|
||||
return
|
||||
}
|
||||
updateFields := [][]string{
|
||||
{"name", *name},
|
||||
{"name", name},
|
||||
}
|
||||
|
||||
gm.updateGuild(guild, updateFields, func(err error) {
|
||||
@ -765,7 +781,7 @@ func (gm *GuildMgr) SetName(player *Player, name *string, itemId, itemNum int32,
|
||||
"guild_id": q5.ToString(guild.GuildId),
|
||||
"accountId": q5.ToString(player.GetAccountId()),
|
||||
"before_guild_name": guild.Name,
|
||||
"after_guild_name": *name,
|
||||
"after_guild_name": name,
|
||||
}
|
||||
f5.GetTgLog().AddTrackLog(
|
||||
GAME_ID,
|
||||
@ -775,7 +791,7 @@ func (gm *GuildMgr) SetName(player *Player, name *string, itemId, itemNum int32,
|
||||
prop,
|
||||
)
|
||||
|
||||
guild.Name = *name
|
||||
guild.Name = name
|
||||
cb(ERR_CODE_OK, "SetName OK")
|
||||
})
|
||||
})
|
||||
|
@ -375,7 +375,7 @@ func (p *Player) CMGetTopGuildsByTotalStars(hdr *f5.MsgHdr, msg *cs.CMGetTopGuil
|
||||
func (p *Player) CMCreateGuild(hdr *f5.MsgHdr, msg *cs.CMCreateGuild) {
|
||||
avatar := msg.GetAvatar()
|
||||
guildMgr.CreateGuild(
|
||||
p, avatar, msg.Name, p.accountId,
|
||||
p, avatar, msg.GetName(), p.accountId,
|
||||
func(errCode int32, errMsg string, guild *Guild) {
|
||||
rspMsg := new(cs.SMCreateGuild)
|
||||
if errCode != 0 {
|
||||
@ -650,7 +650,7 @@ func (p *Player) CMSetAvatar(hdr *f5.MsgHdr, msg *cs.CMSetAvatar) {
|
||||
func (p *Player) CMSetName(hdr *f5.MsgHdr, msg *cs.CMSetName) {
|
||||
guildMgr.SetName(
|
||||
p,
|
||||
msg.Name,
|
||||
msg.GetName(),
|
||||
msg.GetItemId(),
|
||||
msg.GetItemNum(),
|
||||
func(errCode int32, errMsg string) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user