910 lines
24 KiB
Go
910 lines
24 KiB
Go
package player
|
|
|
|
import (
|
|
"cs"
|
|
"q5"
|
|
"f5"
|
|
"github.com/golang/protobuf/proto"
|
|
"main/common"
|
|
"main/constant"
|
|
. "main/global"
|
|
)
|
|
|
|
type player struct {
|
|
cs.MsgHandlerImpl
|
|
socket f5.WspCliConn
|
|
accountId string
|
|
sessionId string
|
|
battling bool
|
|
lastRefreshCacheTime int64
|
|
}
|
|
|
|
func (this *player) init(req *pendingLoginRequest, rspObj *common.LoginRsp){
|
|
this.socket = req.hdr.GetSocket()
|
|
this.accountId = req.msg.GetAccountId()
|
|
this.sessionId = req.msg.GetSessionId()
|
|
this.refreshCache()
|
|
}
|
|
|
|
func (this *player) GetAccountId() string {
|
|
return this.accountId
|
|
}
|
|
|
|
func (this *player) GetSessionId() string {
|
|
return this.sessionId
|
|
}
|
|
|
|
func (this *player) IsOnline() bool {
|
|
return this.socket.IsValid()
|
|
}
|
|
|
|
func (this *player) IsBattling() bool {
|
|
return this.battling
|
|
}
|
|
|
|
func (this *player) SendMsg(rspMsg proto.Message) {
|
|
if this.socket.IsValid() {
|
|
GetWspListener().SendProxyMsg(this.socket.Conn, this.socket.SocketHandle, rspMsg)
|
|
}
|
|
}
|
|
|
|
func (this *player) reBind(socket f5.WspCliConn, sessionId string) {
|
|
if this.socket.IsValid() {
|
|
delete(_playerMgr.socketHash, this.socket)
|
|
}
|
|
this.socket = socket
|
|
this.sessionId = sessionId
|
|
_playerMgr.socketHash[this.socket] = this
|
|
this.refreshCache()
|
|
}
|
|
|
|
func (this *player) CMPing(hdr *f5.MsgHdr, msg *cs.CMPing) {
|
|
rspMsg := new(cs.SMPing)
|
|
this.SendMsg(rspMsg)
|
|
}
|
|
|
|
func (this *player) CMSearchUser(hdr *f5.MsgHdr, msg *cs.CMSearchUser) {
|
|
rspMsg := new(cs.SMSearchUser)
|
|
GetCacheMgr().AsyncSearch(
|
|
msg.GetSinceId(),
|
|
msg.GetUsername(),
|
|
&rspMsg.Users,
|
|
func (errCode int32, errMsg string, sinceId int64) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
|
return
|
|
}
|
|
rspMsg.SinceId = proto.Int64(sinceId)
|
|
this.SendMsg(rspMsg)
|
|
})
|
|
}
|
|
|
|
func (this *player) CMSearchUserByAccountId(hdr *f5.MsgHdr, msg *cs.CMSearchUserByAccountId) {
|
|
rspMsg := new(cs.SMSearchUserByAccountId)
|
|
users := []*cs.MFUser{}
|
|
GetCacheMgr().AsyncGetUsersAndFillMFUser(
|
|
[]string{msg.GetAccountId()},
|
|
&users,
|
|
func (errCode int32, errMsg string) {
|
|
if errCode != 0 || len(users) <= 0{
|
|
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
|
return
|
|
}
|
|
rspMsg.Users = users[0]
|
|
this.SendMsg(rspMsg)
|
|
})
|
|
}
|
|
|
|
func (this *player) CMListPendingFriendRequest(hdr *f5.MsgHdr, msg *cs.CMListPendingFriendRequest) {
|
|
GetFriendMgr().AsyncGetApplyList(
|
|
0,
|
|
this.GetAccountId(),
|
|
func (errCode int32, errMsg string, sinceId int64, accountIds []string) {
|
|
rspMsg := new(cs.SMListPendingFriendRequest)
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
|
return
|
|
}
|
|
GetCacheMgr().AsyncGetUsersAndFillMFUser(
|
|
accountIds,
|
|
&rspMsg.Users,
|
|
func (errCode int32, errMsg string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
|
return
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
})
|
|
})
|
|
}
|
|
|
|
func (this *player) CMListFriend(hdr *f5.MsgHdr, msg *cs.CMListFriend) {
|
|
rspMsg := new(cs.SMListFriend)
|
|
friendList := GetFriendMgr().GetFriendList(this.GetAccountId())
|
|
GetCacheMgr().AsyncGetUsersAndFillMFUser(
|
|
friendList,
|
|
&rspMsg.Users,
|
|
func (errCode int32, errMsg string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
|
return
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
})
|
|
}
|
|
|
|
func (this *player) CMBlacklist(hdr *f5.MsgHdr, msg *cs.CMBlacklist) {
|
|
rspMsg := new(cs.SMBlacklist)
|
|
blackList := GetFriendMgr().GetBlackList(this.GetAccountId())
|
|
GetCacheMgr().AsyncGetUsersAndFillMFUser(
|
|
blackList,
|
|
&rspMsg.Users,
|
|
func (errCode int32, errMsg string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
|
return
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
})
|
|
}
|
|
|
|
func (this *player) CMAddFriendRequest(hdr *f5.MsgHdr, msg *cs.CMAddFriendRequest) {
|
|
rspMsg := new(cs.SMAddFriendRequest)
|
|
if GetFriendMgr().IsFriend(this.GetAccountId(), msg.GetTargetAccountId()) {
|
|
rspMsg.IsFriendship = proto.Int32(1)
|
|
this.SendMsg(rspMsg)
|
|
return
|
|
}
|
|
if this.GetAccountId() == msg.GetTargetAccountId() {
|
|
this.SendMsg(rspMsg.Err(2, "Cannot invite oneself"))
|
|
return
|
|
}
|
|
GetFriendMgr().AsyncApplyFriend(
|
|
this.GetAccountId(),
|
|
msg.GetTargetAccountId(),
|
|
func (errCode int32, errMsg string) {
|
|
this.SendMsg(rspMsg.Err(errCode, errMsg))
|
|
return
|
|
})
|
|
}
|
|
|
|
func (this *player) CMAcceptFriendRequest(hdr *f5.MsgHdr, msg *cs.CMAcceptFriendRequest) {
|
|
rspMsg := new(cs.SMAcceptFriendRequest)
|
|
if this.GetAccountId() == msg.GetTargetAccountId() {
|
|
this.SendMsg(rspMsg.Err(2, "Cannot add oneself"))
|
|
return
|
|
}
|
|
if GetFriendMgr().IsFriend(this.GetAccountId(), msg.GetTargetAccountId()) {
|
|
this.SendMsg(rspMsg)
|
|
return
|
|
}
|
|
doFunc := func () {
|
|
f5.NewLockAsyncTask(
|
|
[][]string{
|
|
{constant.MEMBER_LOCK_KEY, this.GetAccountId()},
|
|
{constant.MEMBER_LOCK_KEY, msg.GetTargetAccountId()},
|
|
},
|
|
func (task *f5.LockAsyncTask) {
|
|
GetFriendMgr().AsyncAcceptApply(
|
|
this.GetAccountId(),
|
|
msg.GetTargetAccountId(),
|
|
func (errCode int32, errMsg string) {
|
|
if errCode != 0 {
|
|
task.SetFail()
|
|
this.SendMsg(rspMsg.Err(500, "server internal error"))
|
|
return
|
|
}
|
|
task.SetSucc()
|
|
this.SendMsg(rspMsg)
|
|
})
|
|
})
|
|
}
|
|
f5.GetJsStyleDb().OrmSelectOne(
|
|
constant.FRIEND_DB,
|
|
"t_friend_apply",
|
|
[][]string{
|
|
{"sender_id", msg.GetTargetAccountId()},
|
|
{"target_id", this.GetAccountId()},
|
|
{"status", q5.ToString(constant.FRIEND_APPLY_STATUS_NONE)},
|
|
},
|
|
func (err error, ds *f5.DataSet) {
|
|
if err != nil {
|
|
this.SendMsg(rspMsg.Err(500, "server internal error"))
|
|
return
|
|
}
|
|
if ds.Next() {
|
|
doFunc()
|
|
} else {
|
|
this.SendMsg(rspMsg.Err(500, "server internal error"))
|
|
return
|
|
}
|
|
})
|
|
}
|
|
|
|
func (this *player) CMRejectFriendRequest(hdr *f5.MsgHdr, msg *cs.CMRejectFriendRequest) {
|
|
rspMsg := new(cs.SMRejectFriendRequest)
|
|
if GetFriendMgr().IsFriend(this.GetAccountId(), msg.GetTargetAccountId()) {
|
|
this.SendMsg(rspMsg)
|
|
return
|
|
}
|
|
doFunc := func () {
|
|
f5.NewLockAsyncTask(
|
|
[][]string{
|
|
{constant.MEMBER_LOCK_KEY, this.GetAccountId()},
|
|
{constant.MEMBER_LOCK_KEY, msg.GetTargetAccountId()},
|
|
},
|
|
func (task *f5.LockAsyncTask) {
|
|
GetFriendMgr().AsyncRejectApply(
|
|
msg.GetTargetAccountId(),
|
|
this.GetAccountId(),
|
|
func (errCode int32, errMsg string) {
|
|
if errCode != 0 {
|
|
task.SetFail()
|
|
this.SendMsg(rspMsg.Err(500, "server internal error"))
|
|
return
|
|
}
|
|
task.SetSucc()
|
|
this.SendMsg(rspMsg)
|
|
})
|
|
})
|
|
}
|
|
f5.GetJsStyleDb().OrmSelectOne(
|
|
constant.FRIEND_DB,
|
|
"t_friend_apply",
|
|
[][]string{
|
|
{"sender_id", msg.GetTargetAccountId()},
|
|
{"target_id", this.GetAccountId()},
|
|
{"status", q5.ToString(constant.FRIEND_APPLY_STATUS_NONE)},
|
|
},
|
|
func (err error, ds *f5.DataSet) {
|
|
if err != nil {
|
|
this.SendMsg(rspMsg.Err(500, "server internal error"))
|
|
return
|
|
}
|
|
if ds.Next() {
|
|
doFunc()
|
|
} else {
|
|
this.SendMsg(rspMsg.Err(500, "server internal error"))
|
|
return
|
|
}
|
|
})
|
|
}
|
|
|
|
func (this *player) CMDeleteFriendShip(hdr *f5.MsgHdr, msg *cs.CMDeleteFriendShip) {
|
|
rspMsg := new(cs.SMDeleteFriendShip)
|
|
f5.NewLockAsyncTask(
|
|
[][]string{
|
|
{constant.MEMBER_LOCK_KEY, this.GetAccountId()},
|
|
{constant.MEMBER_LOCK_KEY, msg.GetTargetAccountId()},
|
|
},
|
|
func (task *f5.LockAsyncTask) {
|
|
GetFriendMgr().AsyncDeleteFriend(
|
|
this.GetAccountId(),
|
|
msg.GetTargetAccountId(),
|
|
func (errCode int32, errMsg string) {
|
|
if errCode != 0 {
|
|
task.SetFail()
|
|
this.SendMsg(rspMsg.Err(500, "server internal error"))
|
|
return
|
|
}
|
|
task.SetSucc()
|
|
this.SendMsg(rspMsg)
|
|
})
|
|
})
|
|
}
|
|
|
|
func (this *player) CMAddBlacklist(hdr *f5.MsgHdr, msg *cs.CMAddBlacklist) {
|
|
rspMsg := new(cs.SMAddBlacklist)
|
|
GetFriendMgr().AsyncAddBlack(
|
|
this.GetAccountId(),
|
|
msg.GetTargetAccountId(),
|
|
func (errCode int32, errMsg string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(500, "server internal error"))
|
|
return
|
|
}
|
|
this.SendMsg(rspMsg.Err(errCode, errMsg))
|
|
})
|
|
}
|
|
|
|
func (this *player) CMRemoveBlacklist(hdr *f5.MsgHdr, msg *cs.CMRemoveBlacklist) {
|
|
rspMsg := new(cs.SMRemoveBlacklist)
|
|
f5.NewLockAsyncTask(
|
|
[][]string{
|
|
{constant.MEMBER_LOCK_KEY, this.GetAccountId()},
|
|
{constant.MEMBER_LOCK_KEY, msg.GetTargetAccountId()},
|
|
},
|
|
func (task *f5.LockAsyncTask) {
|
|
GetFriendMgr().AsyncRemoveBlack(
|
|
this.GetAccountId(),
|
|
msg.GetTargetAccountId(),
|
|
func (errCode int32, errMsg string) {
|
|
if errCode != 0 {
|
|
task.SetFail()
|
|
this.SendMsg(rspMsg.Err(500, "server internal error"))
|
|
return
|
|
}
|
|
task.SetSucc()
|
|
this.SendMsg(rspMsg)
|
|
})
|
|
})
|
|
}
|
|
|
|
func (this *player) CMInviteFriendMsg(hdr *f5.MsgHdr, msg *cs.CMInviteFriendMsg) {
|
|
}
|
|
|
|
func (this *player) CMRecommendList(hdr *f5.MsgHdr, msg *cs.CMRecommendList) {
|
|
rspMsg := new(cs.SMRecommendList)
|
|
rspMsg.Type = proto.Int32(msg.GetType())
|
|
rspMsg.Users = []*cs.MFUser{}
|
|
GetCacheMgr().AsyncRecommendList(
|
|
msg.GetType(),
|
|
this.GetAccountId(),
|
|
&rspMsg.Users,
|
|
func (errCode int32, errMsg string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(500, "server internal error"))
|
|
return
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
})
|
|
}
|
|
|
|
func (this *player) CMSetStatus(hdr *f5.MsgHdr, msg *cs.CMSetStatus) {
|
|
rspMsg := new(cs.SMSetStatus)
|
|
this.battling = msg.GetBattling() > 0
|
|
this.SendMsg(rspMsg)
|
|
}
|
|
|
|
func (this *player) CMSendChatMsg(hdr *f5.MsgHdr, msg *cs.CMSendChatMsg) {
|
|
}
|
|
|
|
func (this *player) CMReadMsgAndOpenChatNotify(hdr *f5.MsgHdr, msg *cs.CMReadMsgAndOpenChatNotify) {
|
|
}
|
|
|
|
func (this *player) CMSetCurrPrivateChatTarget(hdr *f5.MsgHdr, msg *cs.CMSetCurrPrivateChatTarget) {
|
|
}
|
|
|
|
func (this *player) CMGuildInfo(hdr *f5.MsgHdr, msg *cs.CMGuildInfo) {
|
|
rspMsg := new(cs.SMGuildInfo)
|
|
guild := GetGuildMgr().GetGuildByAccountId(msg.GetAccountId())
|
|
if guild == nil {
|
|
//this.SendMsg(rspMsg.Err(1, "guild not exists"))
|
|
this.SendMsg(rspMsg)
|
|
return
|
|
}
|
|
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)
|
|
})
|
|
}
|
|
|
|
func (this *player) CMRecommendGuildList(hdr *f5.MsgHdr, msg *cs.CMRecommendGuildList) {
|
|
rspMsg := new(cs.SMRecommendGuildList)
|
|
q5.NewSlice(&rspMsg.RecommendGuilds, 0, 50)
|
|
GetGuildMgr().AsyncGetRecommendGuild(
|
|
0,
|
|
func (errCode int32, errMsg string, guildIds []string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(1, "server internal error"))
|
|
return
|
|
}
|
|
if len(guildIds) <= 0 {
|
|
this.SendMsg(rspMsg)
|
|
return
|
|
}
|
|
i := 0
|
|
f5.NewAsyncTask(
|
|
func (task* f5.AsyncTask) {
|
|
doNextFunc := func() {
|
|
if i + 1 < len(guildIds) {
|
|
i++
|
|
task.Continue()
|
|
} else {
|
|
this.SendMsg(rspMsg)
|
|
}
|
|
}
|
|
guild := GetGuildMgr().GetGuildByGuildId(guildIds[i])
|
|
if guild == nil {
|
|
doNextFunc()
|
|
} else {
|
|
pbGuild := new(cs.MFGuild)
|
|
guild.AsyncFillMFGuild(
|
|
pbGuild,
|
|
func (errCode int32, errMsg string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(1, "server internal error"))
|
|
return
|
|
}
|
|
q5.AppendSlice(&rspMsg.RecommendGuilds, pbGuild)
|
|
doNextFunc()
|
|
})
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
func (this *player) CMGetTopGuildsByTotalStars(hdr *f5.MsgHdr, msg *cs.CMGetTopGuildsByTotalStars) {
|
|
rspMsg := new(cs.SMGetTopGuildsByTotalStars)
|
|
q5.NewSlice(&rspMsg.Guilds, 0, 50)
|
|
GetGuildMgr().AsyncGetGuildRank(
|
|
0,
|
|
func (errCode int32, errMsg string, guildIds []string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(1, "server internal error"))
|
|
return
|
|
}
|
|
if len(guildIds) <= 0 {
|
|
this.SendMsg(rspMsg)
|
|
return
|
|
}
|
|
i := 0
|
|
f5.NewAsyncTask(
|
|
func (task* f5.AsyncTask) {
|
|
doNextFunc := func() {
|
|
if i + 1 < len(guildIds) {
|
|
i++
|
|
task.Continue()
|
|
} else {
|
|
this.SendMsg(rspMsg)
|
|
}
|
|
}
|
|
guild := GetGuildMgr().GetGuildByGuildId(guildIds[i])
|
|
if guild == nil {
|
|
doNextFunc()
|
|
} else {
|
|
pbGuild := new(cs.MFGuild)
|
|
guild.AsyncFillMFGuild(
|
|
pbGuild,
|
|
func (errCode int32, errMsg string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(1, "server internal error"))
|
|
return
|
|
}
|
|
q5.AppendSlice(&rspMsg.Guilds, pbGuild)
|
|
doNextFunc()
|
|
})
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
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) {
|
|
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
|
|
}
|
|
})
|
|
}
|
|
|
|
func (this *player) CMApplyToGuild(hdr *f5.MsgHdr, msg *cs.CMApplyToGuild) {
|
|
rspMsg := new(cs.SMApplyToGuild)
|
|
GetGuildMgr().AsyncApplyJoin(
|
|
this.GetAccountId(),
|
|
q5.ToString(msg.GetGuildId()),
|
|
func (errCode int32, errMsg string, okGuild common.Guild) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(errCode, errMsg))
|
|
return
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
if okGuild != nil {
|
|
pbGuilds := []*cs.MFGuildMember{}
|
|
GetCacheMgr().AsyncGetUsersAndFillMFGuildMember(
|
|
[]string{
|
|
this.GetAccountId(),
|
|
},
|
|
&pbGuilds,
|
|
func (errCode int32, errMsg string) {
|
|
if errCode == 0 && len(pbGuilds) > 0 {
|
|
notifyMsg := new(cs.SMApproveJoinGuildNotify)
|
|
notifyMsg.GuildId = proto.Int64(q5.ToInt64(okGuild.GetGuildId()))
|
|
notifyMsg.Name = proto.String(okGuild.GetGuildName())
|
|
notifyMsg.AccountId = proto.String(pbGuilds[0].GetAccountId())
|
|
notifyMsg.Username = proto.String(pbGuilds[0].GetUsername())
|
|
GetGuildMgr().NotifyGuildMsg(q5.ToString(msg.GetGuildId()), notifyMsg)
|
|
}
|
|
})
|
|
}
|
|
return
|
|
})
|
|
}
|
|
|
|
func (this *player) CMApplyList(hdr *f5.MsgHdr, msg *cs.CMApplyList) {
|
|
GetGuildMgr().AsyncGetApplyList(
|
|
0,
|
|
this.GetAccountId(),
|
|
func (errCode int32, errMsg string, sinceId int64, accountIds []string) {
|
|
rspMsg := new(cs.SMApplyList)
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
|
return
|
|
}
|
|
GetCacheMgr().AsyncGetUsersAndFillMFGuildMember(
|
|
accountIds,
|
|
&rspMsg.Members,
|
|
func (errCode int32, errMsg string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
|
return
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
})
|
|
})
|
|
}
|
|
|
|
func (this *player) CMApprove(hdr *f5.MsgHdr, msg *cs.CMApprove) {
|
|
rspMsg := new(cs.SMApprove)
|
|
GetGuildMgr().AsyncAcceptApply(
|
|
this.GetAccountId(),
|
|
msg.GetApplicantAccountId(),
|
|
func (errCode int32, errMsg string, guildId string, guildName string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(errCode, errMsg))
|
|
return
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
{
|
|
pbGuilds := []*cs.MFGuildMember{}
|
|
GetCacheMgr().AsyncGetUsersAndFillMFGuildMember(
|
|
[]string{
|
|
msg.GetApplicantAccountId(),
|
|
},
|
|
&pbGuilds,
|
|
func (errCode int32, errMsg string) {
|
|
if errCode == 0 && len(pbGuilds) > 0 {
|
|
notifyMsg := new(cs.SMApproveJoinGuildNotify)
|
|
notifyMsg.GuildId = proto.Int64(q5.ToInt64(guildId))
|
|
notifyMsg.Name = proto.String(guildName)
|
|
notifyMsg.AccountId = proto.String(pbGuilds[0].GetAccountId())
|
|
notifyMsg.Username = proto.String(pbGuilds[0].GetUsername())
|
|
GetGuildMgr().NotifyGuildMsg(guildId, notifyMsg)
|
|
}
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
func (this *player) CMReject(hdr *f5.MsgHdr, msg *cs.CMReject) {
|
|
rspMsg := new(cs.SMReject)
|
|
GetGuildMgr().AsyncRejectApply(
|
|
this.GetAccountId(),
|
|
msg.GetApplicantAccountId(),
|
|
func (errCode int32, errMsg string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(errCode, errMsg))
|
|
return
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
})
|
|
}
|
|
|
|
func (this *player) CMLeaveGuild(hdr *f5.MsgHdr, msg *cs.CMLeaveGuild) {
|
|
rspMsg := new(cs.SMLeaveGuild)
|
|
GetGuildMgr().AsyncLeave(
|
|
this.GetAccountId(),
|
|
func (errCode int32, errMsg string, guildId string, guildName string, members []string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(errCode, errMsg))
|
|
return
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
{
|
|
{
|
|
pbGuilds := []*cs.MFGuildMember{}
|
|
GetCacheMgr().AsyncGetUsersAndFillMFGuildMember(
|
|
[]string{
|
|
this.GetAccountId(),
|
|
},
|
|
&pbGuilds,
|
|
func (errCode int32, errMsg string) {
|
|
if errCode == 0 && len(pbGuilds) > 0 {
|
|
notifyMsg := new(cs.SMLeaveGuildNotify)
|
|
notifyMsg.GuildId = proto.Int64(q5.ToInt64(guildId))
|
|
notifyMsg.Name = proto.String(guildName)
|
|
notifyMsg.AccountId = proto.String(pbGuilds[0].GetAccountId())
|
|
notifyMsg.Username = proto.String(pbGuilds[0].GetUsername())
|
|
GetGuildMgr().NotifyGuildMsg(guildId, notifyMsg)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
func (this *player) CMDismissMember(hdr *f5.MsgHdr, msg *cs.CMDismissMember) {
|
|
rspMsg := new(cs.SMDismissMember)
|
|
GetGuildMgr().AsyncKickout(
|
|
this.GetAccountId(),
|
|
msg.GetDismissAccountId(),
|
|
func (errCode int32, errMsg string, guildId string, guildName string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(errCode, errMsg))
|
|
return
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
{
|
|
pbUsers := []*cs.MFUser{}
|
|
GetCacheMgr().AsyncGetUsersAndFillMFUser(
|
|
[]string{
|
|
msg.GetDismissAccountId(),
|
|
},
|
|
&pbUsers,
|
|
func (errCode int32, errMsg string) {
|
|
if errCode == 0 && len(pbUsers) > 0 {
|
|
notifyMsg := new(cs.SMDismissMemberNotify)
|
|
notifyMsg.GuildId = proto.Int64(q5.ToInt64(guildId))
|
|
notifyMsg.Name = proto.String(guildName)
|
|
notifyMsg.AccountId = proto.String(pbUsers[0].GetAccountId())
|
|
notifyMsg.Username = proto.String(pbUsers[0].GetUsername())
|
|
GetGuildMgr().NotifyGuildMsg(guildId, notifyMsg)
|
|
{
|
|
hum := GetPlayerMgr().GetPlayerByAccountId(msg.GetDismissAccountId())
|
|
if hum != nil {
|
|
hum.SendMsg(notifyMsg)
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
func (this *player) CMSetMemberLevel(hdr *f5.MsgHdr, msg *cs.CMSetMemberLevel) {
|
|
rspMsg := new(cs.SMSetMemberLevel)
|
|
GetGuildMgr().AsyncSetGuildJob(
|
|
this.GetAccountId(),
|
|
msg.GetMemberAccountId(),
|
|
msg.GetMemberLevel(),
|
|
func (errCode int32, errMsg string, guildId string, guildName string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(errCode, errMsg))
|
|
return
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
{
|
|
pbGuilds := []*cs.MFGuildMember{}
|
|
GetCacheMgr().AsyncGetUsersAndFillMFGuildMember(
|
|
[]string{
|
|
this.GetAccountId(),
|
|
msg.GetMemberAccountId(),
|
|
},
|
|
&pbGuilds,
|
|
func (errCode int32, errMsg string) {
|
|
if errCode == 0 && len(pbGuilds) > 1 {
|
|
{
|
|
if pbGuilds[0].GetLevel() == constant.GuildMemberLevelLeader {
|
|
notifyMsg := new(cs.SMSetMemberLevelNotify)
|
|
notifyMsg.GuildId = proto.Int64(q5.ToInt64(guildId))
|
|
notifyMsg.Name = proto.String(guildName)
|
|
notifyMsg.MemberLevel = proto.Int32(pbGuilds[0].GetLevel())
|
|
notifyMsg.AccountId = proto.String(pbGuilds[0].GetAccountId())
|
|
notifyMsg.Username = proto.String(pbGuilds[0].GetUsername())
|
|
GetGuildMgr().NotifyGuildMsg(guildId, notifyMsg)
|
|
}
|
|
}
|
|
{
|
|
notifyMsg := new(cs.SMSetMemberLevelNotify)
|
|
notifyMsg.GuildId = proto.Int64(q5.ToInt64(guildId))
|
|
notifyMsg.Name = proto.String(guildName)
|
|
notifyMsg.MemberLevel = proto.Int32(pbGuilds[1].GetLevel())
|
|
notifyMsg.AccountId = proto.String(pbGuilds[1].GetAccountId())
|
|
notifyMsg.Username = proto.String(pbGuilds[1].GetUsername())
|
|
GetGuildMgr().NotifyGuildMsg(guildId, notifyMsg)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
func (this *player) CMDisband(hdr *f5.MsgHdr, msg *cs.CMDisband) {
|
|
rspMsg := new(cs.SMDisband)
|
|
this.SendMsg(rspMsg)
|
|
/*
|
|
GetGuildMgr().AsyncDisband(
|
|
this.GetAccountId(),
|
|
func (errCode int32, errMsg string, members []string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(errCode, errMsg))
|
|
return
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
})*/
|
|
}
|
|
|
|
func (this *player) CMSetNotice(hdr *f5.MsgHdr, msg *cs.CMSetNotice) {
|
|
rspMsg := new(cs.SMSetNotice)
|
|
GetGuildMgr().AsyncUpdateGuild(
|
|
this.GetAccountId(),
|
|
this.GetSessionId(),
|
|
map[int32]string{
|
|
constant.GUILD_UPDATE_FIELD_NOTICE: msg.GetContent(),
|
|
},
|
|
func (errCode int32, errMsg string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(errCode, errMsg))
|
|
return
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
})
|
|
}
|
|
|
|
func (this *player) CMSetAvatar(hdr *f5.MsgHdr, msg *cs.CMSetAvatar) {
|
|
rspMsg := new(cs.SMSetAvatar)
|
|
GetGuildMgr().AsyncUpdateGuild(
|
|
this.GetAccountId(),
|
|
this.GetSessionId(),
|
|
map[int32]string{
|
|
constant.GUILD_UPDATE_FIELD_AVATAR: q5.ToString(msg.GetAvatar()),
|
|
},
|
|
func (errCode int32, errMsg string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(errCode, errMsg))
|
|
return
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
})
|
|
}
|
|
|
|
func (this *player) CMSetName(hdr *f5.MsgHdr, msg *cs.CMSetName) {
|
|
rspMsg := new(cs.SMSetName)
|
|
GetGuildMgr().AsyncUpdateGuild(
|
|
this.GetAccountId(),
|
|
this.GetSessionId(),
|
|
map[int32]string{
|
|
constant.GUILD_UPDATE_FIELD_NAME: q5.ToString(msg.GetName()),
|
|
},
|
|
func (errCode int32, errMsg string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(errCode, errMsg))
|
|
return
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
})
|
|
}
|
|
|
|
func (this *player) CMSetJoinCond(hdr *f5.MsgHdr, msg *cs.CMSetJoinCond) {
|
|
rspMsg := new(cs.SMSetJoinCond)
|
|
GetGuildMgr().AsyncUpdateGuild(
|
|
this.GetAccountId(),
|
|
this.GetSessionId(),
|
|
map[int32]string{
|
|
constant.GUILD_UPDATE_FIELD_COND_TYPE: q5.ToString(msg.GetJoinCond()),
|
|
constant.GUILD_UPDATE_FIELD_COND_VALUE: q5.ToString(msg.GetJoinCondValue()),
|
|
},
|
|
func (errCode int32, errMsg string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(errCode, errMsg))
|
|
return
|
|
}
|
|
this.SendMsg(rspMsg)
|
|
})
|
|
}
|
|
|
|
func (this *player) CMGuildMembersList(hdr *f5.MsgHdr, msg *cs.CMGuildMembersList) {
|
|
//not implements
|
|
}
|
|
|
|
func (this *player) CMSearchGuilds(hdr *f5.MsgHdr, msg *cs.CMSearchGuilds) {
|
|
rspMsg := new(cs.SMSearchGuilds)
|
|
q5.NewSlice(&rspMsg.Guilds, 0, 50)
|
|
GetGuildMgr().AsyncSearch(
|
|
msg.GetSinceId(),
|
|
msg.GetName(),
|
|
func (errCode int32, errMsg string, sinceId int64, guildIds []string) {
|
|
rspMsg.SinceId = proto.Int64(sinceId)
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(1, "server internal error"))
|
|
return
|
|
}
|
|
if len(guildIds) <= 0 {
|
|
this.SendMsg(rspMsg)
|
|
return
|
|
}
|
|
i := 0
|
|
f5.NewAsyncTask(
|
|
func (task* f5.AsyncTask) {
|
|
doNextFunc := func() {
|
|
if i + 1 < len(guildIds) {
|
|
i++
|
|
task.Continue()
|
|
} else {
|
|
this.SendMsg(rspMsg)
|
|
}
|
|
}
|
|
guild := GetGuildMgr().GetGuildByGuildId(guildIds[i])
|
|
if guild == nil {
|
|
doNextFunc()
|
|
} else {
|
|
pbGuild := new(cs.MFGuild)
|
|
guild.AsyncFillMFGuild(
|
|
pbGuild,
|
|
func (errCode int32, errMsg string) {
|
|
if errCode != 0 {
|
|
this.SendMsg(rspMsg.Err(1, "server internal error"))
|
|
return
|
|
}
|
|
q5.AppendSlice(&rspMsg.Guilds, pbGuild)
|
|
doNextFunc()
|
|
})
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
func (this *player) CMGuildLogs(hdr *f5.MsgHdr, msg *cs.CMGuildLogs) {
|
|
//not implements
|
|
}
|
|
|
|
func (this *player) CMRedDot(hdr *f5.MsgHdr, msg *cs.CMRedDot) {
|
|
rspMsg := new(cs.SMRedDot)
|
|
var flags int64
|
|
GetFriendMgr().AsyncHasApply(this.GetAccountId(),
|
|
func (errCode int32, errMsg string, num int32) {
|
|
if num > 0 {
|
|
q5.SetBitFlag(&flags, 0)
|
|
}
|
|
GetGuildMgr().AsyncHasApply(this.GetAccountId(),
|
|
func (errCode int32, errMsg string, num int32) {
|
|
if num > 0 {
|
|
q5.SetBitFlag(&flags, 1)
|
|
}
|
|
rspMsg.Flags = proto.Int32(int32(flags))
|
|
this.SendMsg(rspMsg)
|
|
})
|
|
})
|
|
}
|
|
|
|
func (this *player) onOffline() {
|
|
this.socket.Reset()
|
|
f5.GetSysLog().Info("onOffline %s", this.GetAccountId())
|
|
}
|
|
|
|
func (this *player) refreshCache() {
|
|
if f5.GetApp().GetNowSeconds() - this.lastRefreshCacheTime > 5 {
|
|
this.lastRefreshCacheTime = f5.GetApp().GetNowSeconds()
|
|
f5.GetTimer().SetTimeout(
|
|
1000 * 5,
|
|
func(e int32, args *q5.Args) {
|
|
if e == q5.TIMER_EXEC_EVENT {
|
|
GetCacheMgr().PreLoadUsers([]string{this.GetAccountId()})
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func newPlayer() *player {
|
|
p := new(player)
|
|
return p
|
|
}
|