This commit is contained in:
aozhiwei 2024-03-23 15:34:27 +08:00
parent 630042d758
commit 1c0eff8711
10 changed files with 119 additions and 51 deletions

View File

@ -5,33 +5,33 @@ import (
"main/common"
)
type CacheMgr struct {
type cacheMgr struct {
lock sync.Mutex
userHash map[string]*userProfile
}
func (this *CacheMgr) init() {
func (this *cacheMgr) Init() {
this.userHash = make(map[string]*userProfile)
}
func (this *CacheMgr) UnInit() {
func (this *cacheMgr) UnInit() {
}
func (this *CacheMgr) AsyncGetUsers(accountIds []string, cb func(int32, string)) {
func (this *cacheMgr) AsyncGetUsers(accountIds []string, cb func(int32, string)) {
}
func (this *CacheMgr) GetUserProfile(accountId string) common.UserProfile {
func (this *cacheMgr) GetUserProfile(accountId string) common.UserProfile {
if user, ok := this.userHash[accountId]; ok {
return user
}
return nil
}
func (this *CacheMgr) PreLoad(accountIds []string) {
func (this *cacheMgr) PreLoad(accountIds []string) {
}
func (this *CacheMgr) AsyncSearch(sinceId int64, q string,
func (this *cacheMgr) AsyncSearch(sinceId int64, q string,
cb func(int32, string, int64, []string)) {
}

12
server/imserver_new/cache/export.go vendored Normal file
View File

@ -0,0 +1,12 @@
package cache
import (
"main/constant"
"main/global"
)
var _cacheMgr = new(cacheMgr)
func init() {
global.RegModule(constant.CACHE_MGR_MODULE_IDX, _cacheMgr)
}

View File

@ -3,17 +3,17 @@ package chat
import (
)
type ChatMgr struct {
type chatMgr struct {
}
func NewChatMgr() *ChatMgr {
return new(ChatMgr)
func NewChatMgr() *chatMgr {
return new(chatMgr)
}
func (this *ChatMgr) Init() {
func (this *chatMgr) Init() {
}
func (this *ChatMgr) UnInit() {
func (this *chatMgr) UnInit() {
}

View File

@ -0,0 +1,12 @@
package chat
import (
"main/constant"
"main/global"
)
var _chatMgr = new(chatMgr)
func init() {
global.RegModule(constant.CHAT_MGR_MODULE_IDX, _chatMgr)
}

View File

@ -9,6 +9,10 @@ const (
WSPLISTENER_MODULE_IDX
HANDLER_MGR_MODULE_IDX
PLAYER_MGR_MODULE_IDX
FRIEND_MGR_MODULE_IDX
GUILD_MGR_MODULE_IDX
CHAT_MGR_MODULE_IDX
CACHE_MGR_MODULE_IDX
MAX_MODULE_IDX
)

View File

@ -0,0 +1,12 @@
package friend
import (
"main/constant"
"main/global"
)
var _friendMgr = new(friendMgr)
func init() {
global.RegModule(constant.FRIEND_MGR_MODULE_IDX, _friendMgr)
}

View File

@ -4,27 +4,27 @@ import (
"q5"
)
type FriendMgr struct {
type friendMgr struct {
friendHash map[string]*map[string]int32
blackHash map[string]*map[string]int32
byBlackHash map[string]*map[string]int32
}
func (this *FriendMgr) Init() {
func (this *friendMgr) Init() {
this.friendHash = make(map[string]*map[string]int32)
this.blackHash = make(map[string]*map[string]int32)
this.byBlackHash = make(map[string]*map[string]int32)
}
func (this *FriendMgr) UnInit() {
func (this *friendMgr) UnInit() {
}
func (this *FriendMgr) loadFromDB() {
func (this *friendMgr) loadFromDB() {
//this.loadFriendships()
//this.loadBlacklist()
}
func (this *FriendMgr) IsFriend(accountId1 string, accountId2 string) bool {
func (this *friendMgr) IsFriend(accountId1 string, accountId2 string) bool {
myFriends := this.getFriends(accountId1)
if myFriends != nil {
if _, ok := (*myFriends)[accountId2]; ok {
@ -34,11 +34,11 @@ func (this *FriendMgr) IsFriend(accountId1 string, accountId2 string) bool {
return false
}
func (this *FriendMgr) HasFriend(accountId string) bool {
func (this *friendMgr) HasFriend(accountId string) bool {
return this.GetFriendNum(accountId) > 0
}
func (this *FriendMgr) GetFriendNum(accountId string) int32 {
func (this *friendMgr) GetFriendNum(accountId string) int32 {
myFriends := this.getFriends(accountId)
if myFriends != nil {
return int32(len(*myFriends))
@ -46,7 +46,7 @@ func (this *FriendMgr) GetFriendNum(accountId string) int32 {
return 0
}
func (this *FriendMgr) TraverseFriend(accountId string, cb func(string, int32) bool) {
func (this *friendMgr) TraverseFriend(accountId string, cb func(string, int32) bool) {
myFriends := this.getFriends(accountId)
if myFriends != nil {
for a, t := range *myFriends {
@ -57,7 +57,7 @@ func (this *FriendMgr) TraverseFriend(accountId string, cb func(string, int32) b
}
}
func (this *FriendMgr) GetFriendList(accountId string) []string {
func (this *friendMgr) GetFriendList(accountId string) []string {
friendList := []string{}
this.TraverseFriend(
accountId,
@ -69,7 +69,7 @@ func (this *FriendMgr) GetFriendList(accountId string) []string {
return friendList
}
func (this *FriendMgr) GetBlackList(accountId string) []string {
func (this *friendMgr) GetBlackList(accountId string) []string {
blackList := []string{}
/*
this.TraverseFriend(
@ -83,37 +83,37 @@ func (this *FriendMgr) GetBlackList(accountId string) []string {
return blackList
}
func (this *FriendMgr) getFriends(accountId string) *map[string]int32 {
func (this *friendMgr) getFriends(accountId string) *map[string]int32 {
if friends, ok := this.friendHash[accountId]; ok {
return friends
}
return nil
}
func (this *FriendMgr) AsyncGetApplyList(int64, string, func(int32, string, int64, []string)) {
func (this *friendMgr) AsyncGetApplyList(int64, string, func(int32, string, int64, []string)) {
}
func (this *FriendMgr) AsyncAddFriend(senderId string, targetId string, cb func(int32, string)) {
func (this *friendMgr) AsyncAddFriend(senderId string, targetId string, cb func(int32, string)) {
}
func (this *FriendMgr) AsyncAccpetApply(senderId string, targetId string, cb func(int32, string)) {
func (this *friendMgr) AsyncAccpetApply(senderId string, targetId string, cb func(int32, string)) {
}
func (this *FriendMgr) AsyncRejectApply(senderId string, targetId string, cb func(int32, string)) {
func (this *friendMgr) AsyncRejectApply(senderId string, targetId string, cb func(int32, string)) {
}
func (this *FriendMgr) AsynDeleteFriend(senderId string, targetId string, cb func(int32, string)) {
func (this *friendMgr) AsynDeleteFriend(senderId string, targetId string, cb func(int32, string)) {
}
func (this *FriendMgr) AsyncAddBlack(senderId string, targetId string, cb func(int32, string)) {
func (this *friendMgr) AsyncAddBlack(senderId string, targetId string, cb func(int32, string)) {
}
func (this *FriendMgr) AsyncRemoveBlack(senderId string, targetId string, cb func(int32, string)) {
func (this *friendMgr) AsyncRemoveBlack(senderId string, targetId string, cb func(int32, string)) {
}

View File

@ -70,6 +70,22 @@ func RegModule(idx int32, m q5.Module) {
{
playerMgr = m.(common.PlayerMgr)
}
case constant.FRIEND_MGR_MODULE_IDX:
{
friendMgr = m.(common.FriendMgr)
}
case constant.GUILD_MGR_MODULE_IDX:
{
guildMgr = m.(common.GuildMgr)
}
case constant.CHAT_MGR_MODULE_IDX:
{
chatMgr = m.(common.ChatMgr)
}
case constant.CACHE_MGR_MODULE_IDX:
{
cacheMgr = m.(common.CacheMgr)
}
default:
{
panic("unknow module")

View File

@ -0,0 +1,12 @@
package guild
import (
"main/constant"
"main/global"
)
var _guildMgr = new(guildMgr)
func init() {
global.RegModule(constant.GUILD_MGR_MODULE_IDX, _guildMgr)
}

View File

@ -11,88 +11,88 @@ const (
LoadGuildLogFlag
)
type GuildMgr struct {
type guildMgr struct {
guilds map[int64]*Guild // 公会ID -> 公会
guildLogs map[int64][]*GuildLog // 公会ID -> []公会日志列表
userGuilds map[string]int64 // accountId -> 公会ID
loadedFlags int64
}
func (this *GuildMgr) Init() {
func (this *guildMgr) Init() {
}
func (this *GuildMgr) UnInit() {
func (this *guildMgr) UnInit() {
}
func (this *GuildMgr) isNameTooLong(name string, maxNum int) bool {
func (this *guildMgr) isNameTooLong(name string, maxNum int) bool {
return len(name) > maxNum
}
func (this *GuildMgr) GetGuildByAccountId(string) common.Guild {
func (this *guildMgr) GetGuildByAccountId(string) common.Guild {
return nil
}
func (this *GuildMgr) GetRecommendGuilds(string) []Guild {
func (this *guildMgr) GetRecommendGuilds(string) []Guild {
guilds := []Guild{}
return guilds
}
func (this *GuildMgr) GetGuildRank() []Guild {
func (this *guildMgr) GetGuildRank() []Guild {
guilds := []Guild{}
return guilds
}
func (this *GuildMgr) AsyncCreateGuild(string, string, func(int32, string, int64)) {
func (this *guildMgr) AsyncCreateGuild(string, string, func(int32, string, int64)) {
}
func (this *GuildMgr) AsyncGetApplyList(int64, string, func(int32, string, int64, []string)) {
func (this *guildMgr) AsyncGetApplyList(int64, string, func(int32, string, int64, []string)) {
}
func (this *GuildMgr) AsyncApplyJoin(string, string, func(int32, string)) {
func (this *guildMgr) AsyncApplyJoin(string, string, func(int32, string)) {
}
func (this *GuildMgr) AsyncAcceptApply(string, string, func(int32, string)) {
func (this *guildMgr) AsyncAcceptApply(string, string, func(int32, string)) {
}
func (this *GuildMgr) AsyncRejectApply(string, string, func(int32, string)) {
func (this *guildMgr) AsyncRejectApply(string, string, func(int32, string)) {
}
func (this *GuildMgr) AsyncLeave(string, string, func(int32, string)) {
func (this *guildMgr) AsyncLeave(string, string, func(int32, string)) {
}
func (this *GuildMgr) AsyncKickout(string, string, func(int32, string)) {
func (this *guildMgr) AsyncKickout(string, string, func(int32, string)) {
}
func (this *GuildMgr) AsyncDisband(string, string, func(int32, string)) {
func (this *guildMgr) AsyncDisband(string, string, func(int32, string)) {
}
func (this *GuildMgr) AsyncSetNotice(string, string, func(int32, string)) {
func (this *guildMgr) AsyncSetNotice(string, string, func(int32, string)) {
}
func (this *GuildMgr) AsyncSetAvatar(string, string, func(int32, string)) {
func (this *guildMgr) AsyncSetAvatar(string, string, func(int32, string)) {
}
func (this *GuildMgr) AsyncSetName(string, string, func(int32, string)) {
func (this *guildMgr) AsyncSetName(string, string, func(int32, string)) {
}
func (this *GuildMgr) AsyncSetJoinCond(string, string, func(int32, string)) {
func (this *guildMgr) AsyncSetJoinCond(string, string, func(int32, string)) {
}
func (this *GuildMgr) AsyncSearch(string, string, func(int32, string)) {
func (this *guildMgr) AsyncSearch(string, string, func(int32, string)) {
}
func (this *GuildMgr) AsyncGetGuildLogs(string, string, func(int32, string)) {
func (this *guildMgr) AsyncGetGuildLogs(string, string, func(int32, string)) {
}