1
This commit is contained in:
parent
dd3e25c78a
commit
00db6f45fc
@ -83,11 +83,12 @@ type GuildMember interface {
|
||||
}
|
||||
|
||||
type GuildMgr interface {
|
||||
GetGuildByGuildId(string) Guild
|
||||
GetGuildByAccountId(string) Guild
|
||||
GetGuildByGuildName(string) Guild
|
||||
GetRecommendGuilds(string) []Guild
|
||||
GetGuildRank() []Guild
|
||||
AsyncCreateGuild(string, int32, string, func(int32, string, int64))
|
||||
AsyncCreateGuild(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))
|
||||
|
@ -40,6 +40,7 @@ const (
|
||||
MEMBER_LOCK_KEY = "member:"
|
||||
GUILD_ID_LOCK_KEY = "guild_id:"
|
||||
GUILD_NAME_LOCK_KEY = "guild_name:"
|
||||
GUILD_MEMBER_LOCK_KEY = "guild_member:"
|
||||
CACHE_LOCK_KEY = "cache:"
|
||||
)
|
||||
|
||||
|
@ -82,8 +82,8 @@ func (this *guildMgr) loadGuildMember() {
|
||||
len(this.memberIdHash))
|
||||
}
|
||||
|
||||
func (this *guildMgr) isNameTooLong(name string, maxNum int) bool {
|
||||
return len(name) > maxNum
|
||||
func (this *guildMgr) isNameTooLong(name string) bool {
|
||||
return len(name) > 15
|
||||
}
|
||||
|
||||
func (this *guildMgr) GetGuildByGuildId(guildId string) common.Guild {
|
||||
@ -166,22 +166,21 @@ func (this* guildMgr) removeUsingName(name string) {
|
||||
}
|
||||
|
||||
func (this *guildMgr) asyncCreateGuildTask(task *f5.AsyncTask,
|
||||
guildId string,
|
||||
accountId string, avatar int32, name string,
|
||||
cb func(int32, string, int64)) {
|
||||
guildId string, accountId string, avatar int32, name string,
|
||||
cb func(int32, string, string)) {
|
||||
if this.internalGetGuildByAccountId(accountId) != nil {
|
||||
task.SetFail()
|
||||
cb(1, "", 0)
|
||||
cb(3, "You already have a cube", "")
|
||||
return
|
||||
}
|
||||
if this.internalGetGuildByGuildName(name) != nil {
|
||||
task.SetFail()
|
||||
cb(1, "", 0)
|
||||
cb(4, "Cube name already exists", "")
|
||||
return
|
||||
}
|
||||
if this.isUsingName(name) {
|
||||
task.SetFail()
|
||||
cb(1, "", 0)
|
||||
cb(4, "Cube name already exists", "")
|
||||
return
|
||||
}
|
||||
this.addUsingName(name)
|
||||
@ -202,7 +201,7 @@ func (this *guildMgr) asyncCreateGuildTask(task *f5.AsyncTask,
|
||||
this.removeUsingName(name)
|
||||
if err != nil {
|
||||
task.SetFail()
|
||||
cb(1, "", 0)
|
||||
cb(500, "server internal error", "")
|
||||
return
|
||||
}
|
||||
f5.GetJsStyleDb().Upsert(
|
||||
@ -226,7 +225,7 @@ func (this *guildMgr) asyncCreateGuildTask(task *f5.AsyncTask,
|
||||
func (err error, lastInsertId int64, rowsAffected int64) {
|
||||
if err != nil {
|
||||
task.SetFail()
|
||||
cb(1, "", 0)
|
||||
cb(500, "server internal error", "")
|
||||
return
|
||||
}
|
||||
guild := newGuild()
|
||||
@ -242,13 +241,14 @@ func (this *guildMgr) asyncCreateGuildTask(task *f5.AsyncTask,
|
||||
guild.addMember(m)
|
||||
this.memberIdHash[accountId] = m
|
||||
task.SetSucc()
|
||||
cb(0, "", guildId)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (this *guildMgr) AsyncCreateGuild(accountId string, avatar int32, name string,
|
||||
cb func(int32, string, int64)) {
|
||||
cb func(int32, string, string)) {
|
||||
guildId := q5.ToString(f5.GetApp().NewNodeUuid())
|
||||
f5.NewLockAsyncTask([][]string{
|
||||
{constant.MEMBER_LOCK_KEY, accountId},
|
||||
@ -256,6 +256,22 @@ func (this *guildMgr) AsyncCreateGuild(accountId string, avatar int32, name stri
|
||||
{constant.GUILD_NAME_LOCK_KEY, name},
|
||||
},
|
||||
func (task *f5.LockAsyncTask) {
|
||||
if len(name) <= 0 {
|
||||
cb(1, "Name cantnot be empty", "")
|
||||
return
|
||||
}
|
||||
if this.isNameTooLong(name) {
|
||||
cb(2, "Name is to long", "")
|
||||
return
|
||||
}
|
||||
if this.GetGuildByAccountId(accountId) != nil {
|
||||
cb(3, "You already have a cube", "")
|
||||
return
|
||||
}
|
||||
if this.GetGuildByGuildName(name) != nil {
|
||||
cb(4, "Cube name already exists", "")
|
||||
return
|
||||
}
|
||||
this.asyncCreateGuildTask(task, guildId, accountId, avatar, name, cb)
|
||||
})
|
||||
}
|
||||
|
@ -37,10 +37,6 @@ func (this *player) IsOnline() bool {
|
||||
return this.socket.IsValid()
|
||||
}
|
||||
|
||||
func (this *player) guildIsTooLong(guildName string) bool {
|
||||
return len(guildName) > 15
|
||||
}
|
||||
|
||||
func (this *player) SendMsg(rspMsg proto.Message) {
|
||||
GetWspListener().SendProxyMsg(this.socket.Conn, this.socket.SocketHandle, rspMsg)
|
||||
}
|
||||
@ -387,36 +383,61 @@ func (this *player) CMGetTopGuildsByTotalStars(hdr *f5.MsgHdr, msg *cs.CMGetTopG
|
||||
|
||||
func (this *player) CMCreateGuild(hdr *f5.MsgHdr, msg *cs.CMCreateGuild) {
|
||||
rspMsg := new(cs.SMCreateGuild)
|
||||
if len(msg.GetName()) <= 0 {
|
||||
this.SendMsg(rspMsg.Err(1, "Name cantnot be empty"))
|
||||
return
|
||||
}
|
||||
if this.guildIsTooLong(msg.GetName()) {
|
||||
this.SendMsg(rspMsg.Err(2, "Name is to long"))
|
||||
return
|
||||
}
|
||||
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) {
|
||||
GetGuildMgr().AsyncCreateGuild(
|
||||
this.GetAccountId(),
|
||||
msg.GetAvatar(),
|
||||
msg.GetName(),
|
||||
func (errCode int32, errMsg string, guildId string) {
|
||||
if errCode != 0 {
|
||||
this.SendMsg(rspMsg.Err(errCode, errMsg))
|
||||
return
|
||||
}
|
||||
guild := GetGuildMgr().GetGuildByGuildId(guildId)
|
||||
if guild != nil {
|
||||
rspMsg.Guild = new(cs.MFGuild)
|
||||
guild.AsyncFillMFGuild(rspMsg.Guild,
|
||||
func (errCode int32, errMsg string) {
|
||||
if errCode != 0 {
|
||||
this.SendMsg(rspMsg.Err(500, "server internal error"))
|
||||
return
|
||||
|
||||
}
|
||||
this.SendMsg(rspMsg)
|
||||
})
|
||||
} else {
|
||||
this.SendMsg(rspMsg.Err(500, "server internal error"))
|
||||
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) {
|
||||
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user