1
This commit is contained in:
parent
86cd3c116f
commit
78c7625b9c
@ -2,23 +2,25 @@ package middleware
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"net/http"
|
// "net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Cors() gin.HandlerFunc {
|
func Cors() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
|
/*
|
||||||
method := c.Request.Method
|
method := c.Request.Method
|
||||||
//origin := c.Request.Header.Get("Origin")
|
//origin := c.Request.Header.Get("Origin")
|
||||||
//if origin != "" {
|
//if origin != "" {
|
||||||
c.Header("Access-Control-Allow-Origin", "*") // 可将将 * 替换为指定的域名
|
//c.Header("Access-Control-Allow-Origin", "*") // 可将将 * 替换为指定的域名
|
||||||
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
|
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
|
||||||
c.Header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization")
|
c.Header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization")
|
||||||
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Cache-Control, Content-Language, Content-Type")
|
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Cache-Control, Content-Language, Content-Type")
|
||||||
c.Header("Access-Control-Allow-Credentials", "true")
|
c.Header("Access-Control-Allow-Credentials", "true")
|
||||||
//}
|
//}
|
||||||
if method == "OPTIONS" {
|
if method == "OPTIONS" {
|
||||||
c.AbortWithStatus(http.StatusOK)
|
c.AbortWithStatus(200)
|
||||||
}
|
}
|
||||||
|
c.Next()*/
|
||||||
c.Next()
|
c.Next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
9
server/imserver_new/cache/cachemgr.go
vendored
9
server/imserver_new/cache/cachemgr.go
vendored
@ -4,6 +4,7 @@ import (
|
|||||||
"f5"
|
"f5"
|
||||||
"q5"
|
"q5"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"cs"
|
||||||
"main/common"
|
"main/common"
|
||||||
"main/constant"
|
"main/constant"
|
||||||
)
|
)
|
||||||
@ -138,6 +139,14 @@ func (this *cacheMgr) internalGetUsers(accountIds []string, cb func(int32, strin
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this* cacheMgr) AsyncGetUsersAndFillMFUser([]string, *[]*cs.MFUser, func(int32, string)) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this* cacheMgr) AsyncGetUsersAndFillMFGuildMember([]string, *[]*cs.MFGuildMember, func(int32, string)) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (this *cacheMgr) getUser(accountId string) *userProfile {
|
func (this *cacheMgr) getUser(accountId string) *userProfile {
|
||||||
if val, ok := this.userHash[accountId]; ok {
|
if val, ok := this.userHash[accountId]; ok {
|
||||||
return val
|
return val
|
||||||
|
@ -103,12 +103,11 @@ type GuildMgr interface {
|
|||||||
type CacheMgr interface {
|
type CacheMgr interface {
|
||||||
PreLoadUsers([]string)
|
PreLoadUsers([]string)
|
||||||
GetUserProfile(string) UserProfile
|
GetUserProfile(string) UserProfile
|
||||||
AsyncGetUsers([]string, func(int32, string))
|
AsyncGetUsersAndFillMFUser([]string, *[]*cs.MFUser, func(int32, string))
|
||||||
AsyncSearch(int64, string, func(int32, string, int64, []string))
|
AsyncGetUsersAndFillMFGuildMember([]string, *[]*cs.MFGuildMember, func(int32, string))
|
||||||
|
AsyncSearch(int64, string, *[]*cs.MFUser, func(int32, string, int64))
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserProfile interface {
|
type UserProfile interface {
|
||||||
GetAccountId() string
|
GetAccountId() string
|
||||||
FillMFUser(*cs.MFUser)
|
|
||||||
FillMFGuildMember(*cs.MFGuildMember)
|
|
||||||
}
|
}
|
||||||
|
@ -148,22 +148,15 @@ func (this *guild) AsyncFillMFGuild(pbGuild *cs.MFGuild, cb func(int32, string))
|
|||||||
for _, m := range(this.idHash) {
|
for _, m := range(this.idHash) {
|
||||||
q5.AppendSlice(&accountIds, m.memberId)
|
q5.AppendSlice(&accountIds, m.memberId)
|
||||||
}
|
}
|
||||||
GetCacheMgr().AsyncGetUsers(
|
q5.NewSlice(&pbGuild.Members, 0, int32(len(accountIds)))
|
||||||
|
GetCacheMgr().AsyncGetUsersAndFillMFGuildMember(
|
||||||
accountIds,
|
accountIds,
|
||||||
|
&pbGuild.Members,
|
||||||
func (errCode int32, errMsg string) {
|
func (errCode int32, errMsg string) {
|
||||||
if errCode != 0 {
|
if errCode != 0 {
|
||||||
cb(500, "server internal error")
|
cb(500, "server internal error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
q5.NewSlice(&pbGuild.Members, 0, int32(len(accountIds)))
|
|
||||||
for _, accountId := range(accountIds) {
|
|
||||||
u := GetCacheMgr().GetUserProfile(accountId)
|
|
||||||
if u != nil {
|
|
||||||
pbMember := new(cs.MFGuildMember)
|
|
||||||
u.FillMFGuildMember(pbMember)
|
|
||||||
q5.AppendSlice(&pbGuild.Members, pbMember)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cb(0, "")
|
cb(0, "")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -53,41 +53,33 @@ func (this *player) CMPing(hdr *f5.MsgHdr, msg *cs.CMPing) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *player) CMSearchUser(hdr *f5.MsgHdr, msg *cs.CMSearchUser) {
|
func (this *player) CMSearchUser(hdr *f5.MsgHdr, msg *cs.CMSearchUser) {
|
||||||
|
rspMsg := new(cs.SMSearchUser)
|
||||||
GetCacheMgr().AsyncSearch(
|
GetCacheMgr().AsyncSearch(
|
||||||
msg.GetSinceId(),
|
msg.GetSinceId(),
|
||||||
msg.GetUsername(),
|
msg.GetUsername(),
|
||||||
func (errCode int32, errMsg string, sinceId int64, accountIds []string) {
|
&rspMsg.Users,
|
||||||
rspMsg := new(cs.SMSearchUser)
|
func (errCode int32, errMsg string, sinceId int64) {
|
||||||
if errCode != 0 {
|
if errCode != 0 {
|
||||||
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rspMsg.SinceId = proto.Int64(sinceId)
|
rspMsg.SinceId = proto.Int64(sinceId)
|
||||||
q5.NewSlice(&rspMsg.Users, 0, int32(len(accountIds)))
|
|
||||||
for _, accountId := range(accountIds) {
|
|
||||||
userProfile := GetCacheMgr().GetUserProfile(accountId)
|
|
||||||
if userProfile != nil {
|
|
||||||
ele := new(cs.MFUser)
|
|
||||||
q5.AppendSlice(&rspMsg.Users, ele)
|
|
||||||
userProfile.FillMFUser(ele)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.SendMsg(rspMsg)
|
this.SendMsg(rspMsg)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *player) CMSearchUserByAccountId(hdr *f5.MsgHdr, msg *cs.CMSearchUserByAccountId) {
|
func (this *player) CMSearchUserByAccountId(hdr *f5.MsgHdr, msg *cs.CMSearchUserByAccountId) {
|
||||||
GetCacheMgr().AsyncGetUsers(
|
|
||||||
[]string{msg.GetAccountId()},
|
|
||||||
func (errCode int32, errMsg string) {
|
|
||||||
rspMsg := new(cs.SMSearchUserByAccountId)
|
rspMsg := new(cs.SMSearchUserByAccountId)
|
||||||
if errCode != 0 {
|
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"))
|
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rspMsg.Users = new(cs.MFUser)
|
rspMsg.Users = users[0]
|
||||||
userProfile := GetCacheMgr().GetUserProfile(msg.GetAccountId())
|
|
||||||
userProfile.FillMFUser(rspMsg.Users)
|
|
||||||
this.SendMsg(rspMsg)
|
this.SendMsg(rspMsg)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -102,65 +94,45 @@ func (this *player) CMListPendingFriendRequest(hdr *f5.MsgHdr, msg *cs.CMListPen
|
|||||||
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
GetCacheMgr().AsyncGetUsers(
|
GetCacheMgr().AsyncGetUsersAndFillMFUser(
|
||||||
accountIds,
|
accountIds,
|
||||||
|
&rspMsg.Users,
|
||||||
func (errCode int32, errMsg string) {
|
func (errCode int32, errMsg string) {
|
||||||
if errCode != 0 {
|
if errCode != 0 {
|
||||||
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, accountId := range(accountIds) {
|
|
||||||
userProfile := GetCacheMgr().GetUserProfile(accountId)
|
|
||||||
if userProfile != nil {
|
|
||||||
ele := new(cs.MFUser)
|
|
||||||
q5.AppendSlice(&rspMsg.Users, ele)
|
|
||||||
userProfile.FillMFUser(ele)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.SendMsg(rspMsg)
|
this.SendMsg(rspMsg)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *player) CMListFriend(hdr *f5.MsgHdr, msg *cs.CMListFriend) {
|
func (this *player) CMListFriend(hdr *f5.MsgHdr, msg *cs.CMListFriend) {
|
||||||
friendList := GetFriendMgr().GetFriendList(this.GetAccountId())
|
|
||||||
GetCacheMgr().AsyncGetUsers(
|
|
||||||
friendList,
|
|
||||||
func (errCode int32, errMsg string) {
|
|
||||||
rspMsg := new(cs.SMListFriend)
|
rspMsg := new(cs.SMListFriend)
|
||||||
|
friendList := GetFriendMgr().GetFriendList(this.GetAccountId())
|
||||||
|
GetCacheMgr().AsyncGetUsersAndFillMFUser(
|
||||||
|
friendList,
|
||||||
|
&rspMsg.Users,
|
||||||
|
func (errCode int32, errMsg string) {
|
||||||
if errCode != 0 {
|
if errCode != 0 {
|
||||||
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, accountId := range(friendList) {
|
|
||||||
userProfile := GetCacheMgr().GetUserProfile(accountId)
|
|
||||||
if userProfile != nil {
|
|
||||||
ele := new(cs.MFUser)
|
|
||||||
q5.AppendSlice(&rspMsg.Users, ele)
|
|
||||||
userProfile.FillMFUser(ele)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.SendMsg(rspMsg)
|
this.SendMsg(rspMsg)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *player) CMBlacklist(hdr *f5.MsgHdr, msg *cs.CMBlacklist) {
|
func (this *player) CMBlacklist(hdr *f5.MsgHdr, msg *cs.CMBlacklist) {
|
||||||
blackList := GetFriendMgr().GetBlackList(this.GetAccountId())
|
|
||||||
GetCacheMgr().AsyncGetUsers(
|
|
||||||
blackList,
|
|
||||||
func (errCode int32, errMsg string) {
|
|
||||||
rspMsg := new(cs.SMBlacklist)
|
rspMsg := new(cs.SMBlacklist)
|
||||||
|
blackList := GetFriendMgr().GetBlackList(this.GetAccountId())
|
||||||
|
GetCacheMgr().AsyncGetUsersAndFillMFUser(
|
||||||
|
blackList,
|
||||||
|
&rspMsg.Users,
|
||||||
|
func (errCode int32, errMsg string) {
|
||||||
if errCode != 0 {
|
if errCode != 0 {
|
||||||
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, accountId := range(blackList) {
|
|
||||||
userProfile := GetCacheMgr().GetUserProfile(accountId)
|
|
||||||
if userProfile != nil {
|
|
||||||
ele := q5.NewSliceElement(&rspMsg.Users)
|
|
||||||
userProfile.FillMFUser(*ele)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.SendMsg(rspMsg)
|
this.SendMsg(rspMsg)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -517,21 +489,14 @@ func (this *player) CMApplyList(hdr *f5.MsgHdr, msg *cs.CMApplyList) {
|
|||||||
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
GetCacheMgr().AsyncGetUsers(
|
GetCacheMgr().AsyncGetUsersAndFillMFGuildMember(
|
||||||
accountIds,
|
accountIds,
|
||||||
|
&rspMsg.Members,
|
||||||
func (errCode int32, errMsg string) {
|
func (errCode int32, errMsg string) {
|
||||||
if errCode != 0 {
|
if errCode != 0 {
|
||||||
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
this.SendMsg(rspMsg.Err(1, "internal server error"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, accountId := range(accountIds) {
|
|
||||||
userProfile := GetCacheMgr().GetUserProfile(accountId)
|
|
||||||
if userProfile != nil {
|
|
||||||
ele := new(cs.MFGuildMember)
|
|
||||||
q5.AppendSlice(&rspMsg.Members, ele)
|
|
||||||
userProfile.FillMFGuildMember(ele)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.SendMsg(rspMsg)
|
this.SendMsg(rspMsg)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user