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