Add frienddb.sql
This commit is contained in:
parent
d6fd0137e9
commit
a5aa8a4be5
@ -18,3 +18,28 @@ CREATE TABLE `version` (
|
|||||||
UNIQUE KEY `version` (`version`)
|
UNIQUE KEY `version` (`version`)
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
||||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||||
|
|
||||||
|
drop table if exists `t_friend_ships`;
|
||||||
|
CREATE TABLE `t_friend_ships` (
|
||||||
|
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
|
||||||
|
`account1_id` varchar(60) NOT NULL,
|
||||||
|
`account2_id` varchar(60) NOT NULL,
|
||||||
|
`createtime` int NOT NULL DEFAULT '0' COMMENT '创建时间',
|
||||||
|
`modifytime` int NOT NULL DEFAULT '0' COMMENT '修改时间',
|
||||||
|
PRIMARY KEY (`idx`),
|
||||||
|
UNIQUE KEY `friendship` (`account1_id`,`account2_id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin
|
||||||
|
COMMENT "已经成为好友"
|
||||||
|
;
|
||||||
|
|
||||||
|
drop table if exists `t_pending_friend_requests`;
|
||||||
|
CREATE TABLE t_pending_friend_requests (
|
||||||
|
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
|
||||||
|
sender_account_id varchar(60) NOT NULL,
|
||||||
|
receiver_account_id varchar(60) NOT NULL,
|
||||||
|
request_time int DEFAULT '0',
|
||||||
|
`createtime` int NOT NULL DEFAULT '0' COMMENT '创建时间',
|
||||||
|
`modifytime` int NOT NULL DEFAULT '0' COMMENT '修改时间',
|
||||||
|
PRIMARY KEY (`idx`),
|
||||||
|
UNIQUE KEY `friend_req` (`sender_account_id`,`receiver_account_id`)
|
||||||
|
) COMMENT "等待验证的好友请求";
|
||||||
|
@ -9,8 +9,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ID int
|
AccountId string
|
||||||
Username string
|
UserName string
|
||||||
}
|
}
|
||||||
|
|
||||||
// user1, user2 构成一个好友关系
|
// user1, user2 构成一个好友关系
|
||||||
@ -21,12 +21,16 @@ type Friendship struct {
|
|||||||
|
|
||||||
type FriendsMgr struct {
|
type FriendsMgr struct {
|
||||||
cs.MsgHandlerImpl
|
cs.MsgHandlerImpl
|
||||||
users map[int]*User
|
users map[string]*User
|
||||||
friendships map[int][]*Friendship
|
friendships map[string][]*Friendship
|
||||||
pendingReqs map[int]map[int]bool
|
pendingReqs map[string]map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fm *FriendsMgr) init() {
|
func (fm *FriendsMgr) init() {
|
||||||
|
//dbSetting := struct {
|
||||||
|
// Host int `json:"errcode"`
|
||||||
|
//}
|
||||||
|
|
||||||
conn := q5.NewMysql(
|
conn := q5.NewMysql(
|
||||||
mt.Table.GameDb.GetById(0).GetHost(),
|
mt.Table.GameDb.GetById(0).GetHost(),
|
||||||
mt.Table.GameDb.GetById(0).GetPort(),
|
mt.Table.GameDb.GetById(0).GetPort(),
|
||||||
@ -37,29 +41,32 @@ func (fm *FriendsMgr) init() {
|
|||||||
conn.Open()
|
conn.Open()
|
||||||
|
|
||||||
// make members
|
// make members
|
||||||
fm.users = make(map[int]*User)
|
fm.users = make(map[string]*User)
|
||||||
fm.friendships = make(map[int][]*Friendship)
|
fm.friendships = make(map[string][]*Friendship)
|
||||||
fm.pendingReqs = make(map[int]map[int]bool)
|
fm.pendingReqs = make(map[string]map[string]bool)
|
||||||
|
|
||||||
// 1. Load DB,
|
// 1. Load DB,
|
||||||
// 2. DB Data Map to Struct
|
// 2. DB Data Map to Struct
|
||||||
// 3. RegisterUser
|
// 3. RegisterUser
|
||||||
}
|
}
|
||||||
|
func (fm *FriendsMgr) parseDBData() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (fm *FriendsMgr) unInit() {
|
func (fm *FriendsMgr) unInit() {
|
||||||
// 1. Loop struct data
|
// 1. Loop struct data
|
||||||
// 2. Struct Data Persist to DB
|
// 2. Struct Data Persist to DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fm *FriendsMgr) RegisterUser(id int, username string) {
|
func (fm *FriendsMgr) RegisterUser(accountId string, username string) {
|
||||||
fm.users[id] = &User{ID: id, Username: username}
|
fm.users[accountId] = &User{AccountId: accountId, UserName: username}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fm *FriendsMgr) SearchFriends(query string) []*User {
|
func (fm *FriendsMgr) SearchFriends(query string) []*User {
|
||||||
var results []*User
|
var results []*User
|
||||||
lowercaseQuery := strings.ToLower(query)
|
lowercaseQuery := strings.ToLower(query)
|
||||||
for _, user := range fm.users {
|
for _, user := range fm.users {
|
||||||
if strings.Contains(strings.ToLower(user.Username), lowercaseQuery) {
|
if strings.Contains(strings.ToLower(user.UserName), lowercaseQuery) {
|
||||||
results = append(results, user)
|
results = append(results, user)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,24 +75,24 @@ func (fm *FriendsMgr) SearchFriends(query string) []*User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddFriendRequest 发送好友请求
|
// AddFriendRequest 发送好友请求
|
||||||
func (fm *FriendsMgr) AddFriendRequest(user1ID, user2ID int) error {
|
func (fm *FriendsMgr) AddFriendRequest(user1ID, user2ID string) error {
|
||||||
//// Check if users exist
|
// Check if users exist
|
||||||
//user1, exists1 := fm.users[user1ID]
|
_, exists1 := fm.users[user1ID]
|
||||||
//user2, exists2 := fm.users[user2ID]
|
_, exists2 := fm.users[user2ID]
|
||||||
//if !exists1 || !exists2 {
|
if !exists1 || !exists2 {
|
||||||
// return errors.New("users not exist")
|
return errors.New("users not exist")
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//if fm.pendingReqs[user2ID] == nil {
|
if fm.pendingReqs[user2ID] == nil {
|
||||||
// fm.pendingReqs[user2ID] = make(map[int]bool)
|
fm.pendingReqs[user2ID] = make(map[string]bool)
|
||||||
//}
|
}
|
||||||
//fm.pendingReqs[user2ID][user1ID] = true
|
fm.pendingReqs[user2ID][user1ID] = true
|
||||||
//
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AcceptFriendRequest 接受好友请求
|
// AcceptFriendRequest 接受好友请求
|
||||||
func (fm *FriendsMgr) AcceptFriendRequest(user1ID, user2ID int) error {
|
func (fm *FriendsMgr) AcceptFriendRequest(user1ID, user2ID string) error {
|
||||||
if !fm.pendingReqs[user1ID][user2ID] {
|
if !fm.pendingReqs[user1ID][user2ID] {
|
||||||
return errors.New("no pending friend request from user1 to user2")
|
return errors.New("no pending friend request from user1 to user2")
|
||||||
}
|
}
|
||||||
@ -107,10 +114,10 @@ func (fm *FriendsMgr) AcceptFriendRequest(user1ID, user2ID int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetFriends 我的好友列表
|
// GetFriends 我的好友列表
|
||||||
func (fm *FriendsMgr) GetFriends(userID int) []*User {
|
func (fm *FriendsMgr) GetFriends(accountId string) []*User {
|
||||||
var friends []*User
|
var friends []*User
|
||||||
for _, friendship := range fm.friendships[userID] {
|
for _, friendship := range fm.friendships[accountId] {
|
||||||
if friendship.User1.ID != userID {
|
if friendship.User1.AccountId != accountId {
|
||||||
friends = append(friends, friendship.User1)
|
friends = append(friends, friendship.User1)
|
||||||
} else {
|
} else {
|
||||||
friends = append(friends, friendship.User2)
|
friends = append(friends, friendship.User2)
|
||||||
|
@ -136,6 +136,14 @@ func (this *PlayerMgr) addPlayer(p *Player) {
|
|||||||
this.accountIdHash[p.accountId] = p
|
this.accountIdHash[p.accountId] = p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *PlayerMgr) getPlayer(accountId string) *Player {
|
||||||
|
player, ok := this.accountIdHash[accountId]
|
||||||
|
if ok {
|
||||||
|
return player
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (this *PlayerMgr) addSocketHash(wsp f5.WspCliConn, p *Player) {
|
func (this *PlayerMgr) addSocketHash(wsp f5.WspCliConn, p *Player) {
|
||||||
this.socketHash[wsp] = p
|
this.socketHash[wsp] = p
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user