This commit is contained in:
aozhiwei 2024-04-08 13:34:20 +08:00
parent 00db6f45fc
commit 2e6e26cb30
3 changed files with 28 additions and 35 deletions

View File

@ -88,7 +88,7 @@ type GuildMgr interface {
GetGuildByGuildName(string) Guild
GetRecommendGuilds(string) []Guild
GetGuildRank() []Guild
AsyncCreateGuild(string, int32, string, func(int32, string, string))
AsyncCreateGuild(string, string, int32, string, func(int32, string, string))
AsyncGetApplyList(int64, string, func(int32, string, int64, []string))
AsyncApplyJoin(string, string, func(int32, string))
AsyncAcceptApply(string, string, func(int32, string))

View File

@ -6,6 +6,7 @@ import (
"main/common"
"main/constant"
"fmt"
"mt"
)
const (
@ -247,7 +248,7 @@ func (this *guildMgr) asyncCreateGuildTask(task *f5.AsyncTask,
})
}
func (this *guildMgr) AsyncCreateGuild(accountId string, avatar int32, name string,
func (this *guildMgr) AsyncCreateGuild(accountId string, sessionId string, avatar int32, name string,
cb func(int32, string, string)) {
guildId := q5.ToString(f5.GetApp().NewNodeUuid())
f5.NewLockAsyncTask([][]string{
@ -257,22 +258,45 @@ func (this *guildMgr) AsyncCreateGuild(accountId string, avatar int32, name stri
},
func (task *f5.LockAsyncTask) {
if len(name) <= 0 {
task.SetFail()
cb(1, "Name cantnot be empty", "")
return
}
if this.isNameTooLong(name) {
task.SetFail()
cb(2, "Name is to long", "")
return
}
if this.GetGuildByAccountId(accountId) != nil {
task.SetFail()
cb(3, "You already have a cube", "")
return
}
if this.GetGuildByGuildName(name) != nil {
task.SetFail()
cb(4, "Cube name already exists", "")
return
}
this.asyncCreateGuildTask(task, guildId, accountId, avatar, name, cb)
params := map[string]string{
"c": "Bag",
"a": "createGuildConsume",
"account_id": accountId,
"session_id": sessionId,
}
url := fmt.Sprintf("%s/webapp/index.php", mt.Table.Config.GetById(0).GetGameapiUrl())
rspObj := new(common.HeadRsp)
f5.GetHttpCliMgr().SendJsStyleJsonRspRequest(
url,
params,
&rspObj,
func(rsp f5.HttpCliResponse) {
if rspObj.Errcode != 0 {
task.SetFail()
cb(4, "item not enough", "")
return
}
this.asyncCreateGuildTask(task, guildId, accountId, avatar, name, cb)
})
})
}

View File

@ -4,8 +4,6 @@ import (
"cs"
"q5"
"f5"
"fmt"
"mt"
"github.com/golang/protobuf/proto"
"main/common"
"main/constant"
@ -385,6 +383,7 @@ func (this *player) CMCreateGuild(hdr *f5.MsgHdr, msg *cs.CMCreateGuild) {
rspMsg := new(cs.SMCreateGuild)
GetGuildMgr().AsyncCreateGuild(
this.GetAccountId(),
this.GetSessionId(),
msg.GetAvatar(),
msg.GetName(),
func (errCode int32, errMsg string, guildId string) {
@ -409,36 +408,6 @@ func (this *player) CMCreateGuild(hdr *f5.MsgHdr, msg *cs.CMCreateGuild) {
return
}
})
f5.NewLockAsyncTask(
[][]string{
{constant.GUILD_NAME_LOCK_KEY, msg.GetName()},
{constant.GUILD_MEMBER_LOCK_KEY, this.GetAccountId()},
},
func (task *f5.LockAsyncTask) {
if GetGuildMgr().GetGuildByAccountId(this.GetAccountId()) != nil {
this.SendMsg(rspMsg.Err(3, "You already have a cube"))
return
}
if GetGuildMgr().GetGuildByGuildName(msg.GetName()) != nil {
this.SendMsg(rspMsg.Err(4, "Cube name already exists"))
return
}
params := map[string]string{
"c": "Bag",
"a": "createGuildConsume",
"account_id": this.GetAccountId(),
"session_id": this.GetSessionId(),
}
url := fmt.Sprintf("%s/webapp/index.php", mt.Table.Config.GetById(0).GetGameapiUrl())
rspObj := new(common.HeadRsp)
f5.GetHttpCliMgr().SendJsStyleJsonRspRequest(
url,
params,
&rspObj,
func(rsp f5.HttpCliResponse) {
})
})
}
func (this *player) CMApplyToGuild(hdr *f5.MsgHdr, msg *cs.CMApplyToGuild) {