diff --git a/server/imserver_new/common/types.go b/server/imserver_new/common/types.go index 4c16b88d..f12e5539 100644 --- a/server/imserver_new/common/types.go +++ b/server/imserver_new/common/types.go @@ -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)) diff --git a/server/imserver_new/guild/guildmgr.go b/server/imserver_new/guild/guildmgr.go index 1354d5fa..71977c8d 100644 --- a/server/imserver_new/guild/guildmgr.go +++ b/server/imserver_new/guild/guildmgr.go @@ -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) + }) }) } diff --git a/server/imserver_new/player/player.go b/server/imserver_new/player/player.go index f30bcabf..a941f536 100644 --- a/server/imserver_new/player/player.go +++ b/server/imserver_new/player/player.go @@ -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) {