1
This commit is contained in:
parent
3ab4cd821b
commit
8eeeb199fc
@ -5,6 +5,7 @@ import (
|
|||||||
"f5"
|
"f5"
|
||||||
"main/common"
|
"main/common"
|
||||||
"main/constant"
|
"main/constant"
|
||||||
|
"main/model"
|
||||||
"fmt"
|
"fmt"
|
||||||
"mt"
|
"mt"
|
||||||
"strings"
|
"strings"
|
||||||
@ -181,63 +182,26 @@ func (this *guildMgr) isValidGuildJob(guildJob int32) bool {
|
|||||||
func (this *guildMgr) asyncCreateGuildTask(task *f5.LockAsyncTask,
|
func (this *guildMgr) asyncCreateGuildTask(task *f5.LockAsyncTask,
|
||||||
guildId string, accountId string, avatar int32, name string,
|
guildId string, accountId string, avatar int32, name string,
|
||||||
cb func(int32, string, string)) {
|
cb func(int32, string, string)) {
|
||||||
if this.internalGetGuildByAccountId(accountId) != nil {
|
|
||||||
task.SetFail()
|
|
||||||
cb(3, "You already have a cube", "")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if this.internalGetGuildByGuildName(name) != nil {
|
|
||||||
task.SetFail()
|
|
||||||
cb(4, "Cube name already exists", "")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if this.isUsingName(name) {
|
|
||||||
task.SetFail()
|
|
||||||
cb(4, "Cube name already exists", "")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.addUsingName(name)
|
this.addUsingName(name)
|
||||||
nowTime := f5.GetApp().GetNowSeconds()
|
nowTime := f5.GetApp().GetNowSeconds()
|
||||||
f5.GetJsStyleDb().Insert(
|
model.Guild.New(
|
||||||
constant.FRIEND_DB,
|
guildId,
|
||||||
"t_guild",
|
name,
|
||||||
[][]string{
|
accountId,
|
||||||
{"guild_id", guildId},
|
avatar,
|
||||||
{"guild_name", name},
|
nowTime,
|
||||||
{"owner_id", accountId},
|
|
||||||
{"creator_id", accountId},
|
|
||||||
{"badge", q5.ToString(avatar)},
|
|
||||||
{"max_members", q5.ToString(constant.GuildMaxMembers)},
|
|
||||||
{"createtime", q5.ToString(nowTime)},
|
|
||||||
{"modifytime", q5.ToString(nowTime)},
|
|
||||||
},
|
|
||||||
func (err error, lastInsertId int64, rowsAffected int64) {
|
func (err error, lastInsertId int64, rowsAffected int64) {
|
||||||
this.removeUsingName(name)
|
defer this.removeUsingName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
task.SetFail()
|
task.SetFail()
|
||||||
cb(500, "server internal error", "")
|
cb(500, "server internal error", "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
f5.GetJsStyleDb().Upsert(
|
model.GuildMember.Force(
|
||||||
constant.FRIEND_DB,
|
accountId,
|
||||||
"t_guild_member",
|
guildId,
|
||||||
[][]string{
|
constant.GuildMemberLevelLeader,
|
||||||
{"member_id", accountId},
|
nowTime,
|
||||||
},
|
|
||||||
[][]string{
|
|
||||||
{"guild_id", guildId},
|
|
||||||
{"guild_job", q5.ToString(constant.GuildMemberLevelLeader)},
|
|
||||||
{"deleted", q5.ToString(0)},
|
|
||||||
{"join_time", q5.ToString(nowTime)},
|
|
||||||
},
|
|
||||||
[][]string{
|
|
||||||
{"guild_id", guildId},
|
|
||||||
{"guild_job", q5.ToString(constant.GuildMemberLevelLeader)},
|
|
||||||
{"member_id", accountId},
|
|
||||||
{"join_time", q5.ToString(nowTime)},
|
|
||||||
{"createtime", q5.ToString(nowTime)},
|
|
||||||
{"modifytime", q5.ToString(nowTime)},
|
|
||||||
},
|
|
||||||
func (err error, lastInsertId int64, rowsAffected int64) {
|
func (err error, lastInsertId int64, rowsAffected int64) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
task.SetFail()
|
task.SetFail()
|
||||||
@ -276,35 +240,41 @@ func (this *guildMgr) asyncCreateGuildTask(task *f5.LockAsyncTask,
|
|||||||
func (this *guildMgr) AsyncCreateGuild(accountId string, sessionId string, avatar int32, name string,
|
func (this *guildMgr) AsyncCreateGuild(accountId string, sessionId string, avatar int32, name string,
|
||||||
cb func(int32, string, string)) {
|
cb func(int32, string, string)) {
|
||||||
guildId := q5.ToString(f5.GetApp().NewNodeUuid())
|
guildId := q5.ToString(f5.GetApp().NewNodeUuid())
|
||||||
|
verifyFunc := func (task *f5.LockAsyncTask, cb func(int32, string, string)) bool {
|
||||||
|
if len(name) <= 0 {
|
||||||
|
task.SetFail()
|
||||||
|
cb(1, "Name cantnot be empty", "")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if this.isNameTooLong(name) {
|
||||||
|
task.SetFail()
|
||||||
|
cb(2, "Name is to long", "")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if !this.isValidName(name) {
|
||||||
|
task.SetFail()
|
||||||
|
cb(2, "Name is invalid", "")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if this.GetGuildByAccountId(accountId) != nil {
|
||||||
|
task.SetFail()
|
||||||
|
cb(3, "You already have a cube", "")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if this.GetGuildByGuildName(name) != nil {
|
||||||
|
task.SetFail()
|
||||||
|
cb(4, "Cube name already exists", "")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
f5.NewLockAsyncTask([][]string{
|
f5.NewLockAsyncTask([][]string{
|
||||||
{constant.GUILD_ID_LOCK_KEY, guildId},
|
{constant.GUILD_ID_LOCK_KEY, guildId},
|
||||||
{constant.GUILD_NAME_LOCK_KEY, name},
|
{constant.GUILD_NAME_LOCK_KEY, name},
|
||||||
{constant.GUILD_MEMBER_LOCK_KEY, accountId},
|
{constant.GUILD_MEMBER_LOCK_KEY, accountId},
|
||||||
},
|
},
|
||||||
func (task *f5.LockAsyncTask) {
|
func (task *f5.LockAsyncTask) {
|
||||||
if len(name) <= 0 {
|
if !verifyFunc(task, cb) {
|
||||||
task.SetFail()
|
|
||||||
cb(1, "Name cantnot be empty", "")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if this.isNameTooLong(name) {
|
|
||||||
task.SetFail()
|
|
||||||
cb(2, "Name is to long", "")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !this.isValidName(name) {
|
|
||||||
task.SetFail()
|
|
||||||
cb(2, "Name is invalid", "")
|
|
||||||
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
|
return
|
||||||
}
|
}
|
||||||
params := map[string]string{
|
params := map[string]string{
|
||||||
@ -327,6 +297,9 @@ func (this *guildMgr) AsyncCreateGuild(accountId string, sessionId string, avata
|
|||||||
cb(4, "item not enough", "")
|
cb(4, "item not enough", "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if !verifyFunc(task, cb) {
|
||||||
|
return
|
||||||
|
}
|
||||||
this.asyncCreateGuildTask(task, guildId, accountId, avatar, name, cb)
|
this.asyncCreateGuildTask(task, guildId, accountId, avatar, name, cb)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
30
server/imserver_new/model/guild.go
Normal file
30
server/imserver_new/model/guild.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"q5"
|
||||||
|
"f5"
|
||||||
|
"main/constant"
|
||||||
|
)
|
||||||
|
|
||||||
|
type guild struct {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var Guild = new (guild)
|
||||||
|
|
||||||
|
func (this *guild) New(guildId string, guildName string, creatorId string, avatar int32, nowTime int64,
|
||||||
|
cb func (error, int64, int64)) {
|
||||||
|
f5.GetJsStyleDb().Insert(
|
||||||
|
constant.FRIEND_DB,
|
||||||
|
"t_guild",
|
||||||
|
[][]string{
|
||||||
|
{"guild_id", guildId},
|
||||||
|
{"guild_name", guildName},
|
||||||
|
{"creator_id", creatorId},
|
||||||
|
{"badge", q5.ToString(avatar)},
|
||||||
|
{"max_members", q5.ToString(constant.GuildMaxMembers)},
|
||||||
|
{"createtime", q5.ToString(nowTime)},
|
||||||
|
{"modifytime", q5.ToString(nowTime)},
|
||||||
|
},
|
||||||
|
cb)
|
||||||
|
}
|
38
server/imserver_new/model/guild_member.go
Normal file
38
server/imserver_new/model/guild_member.go
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"q5"
|
||||||
|
"f5"
|
||||||
|
"main/constant"
|
||||||
|
)
|
||||||
|
|
||||||
|
type guildMember struct {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var GuildMember = new (guildMember)
|
||||||
|
|
||||||
|
func (this *guildMember) Force(memberId string, guildId string, guildJob int32, nowTime int64,
|
||||||
|
cb func (error, int64, int64)) {
|
||||||
|
f5.GetJsStyleDb().Upsert(
|
||||||
|
constant.FRIEND_DB,
|
||||||
|
"t_guild_member",
|
||||||
|
[][]string{
|
||||||
|
{"member_id", memberId},
|
||||||
|
},
|
||||||
|
[][]string{
|
||||||
|
{"guild_id", guildId},
|
||||||
|
{"guild_job", q5.ToString(guildJob)},
|
||||||
|
{"deleted", q5.ToString(0)},
|
||||||
|
{"join_time", q5.ToString(nowTime)},
|
||||||
|
},
|
||||||
|
[][]string{
|
||||||
|
{"guild_id", guildId},
|
||||||
|
{"guild_job", q5.ToString(guildJob)},
|
||||||
|
{"member_id", memberId},
|
||||||
|
{"join_time", q5.ToString(nowTime)},
|
||||||
|
{"createtime", q5.ToString(nowTime)},
|
||||||
|
{"modifytime", q5.ToString(nowTime)},
|
||||||
|
},
|
||||||
|
cb)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user