本文整理汇总了Golang中github.com/funny/link.Session.Id方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.Id方法的具体用法?Golang Session.Id怎么用?Golang Session.Id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/funny/link.Session
的用法示例。
在下文中一共展示了Session.Id方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Login
//登录
func (this UserModule) Login(userName string, session *link.Session) {
onlineUser := module.Cache.GetOnlineUserByUserName(userName)
if onlineUser != nil {
if onlineUser.Session.Id() != session.Id() {
//当前在线,但是连接不同,其他客户端连接,需通知当前客户端下线
module.SendOtherLogin(onlineUser.Session)
//替换Session
module.Cache.RemoveOnlineUser(onlineUser.Session.Id())
//登录成功处理
success := loginSuccess(session, onlineUser.UserName, onlineUser.UserID)
if success {
module.SendLoginResult(onlineUser.UserID, session)
} else {
module.SendLoginResult(0, session)
}
}
} else {
cacheDbUser := redisProxy.GetDBUserByUserName(userName)
if cacheDbUser != nil {
this.UserLoginHandle(session, cacheDbUser.Name, cacheDbUser.ID)
} else {
dbProxy.UserLogin(session.Id(), userName)
}
}
}
示例2: AddSession
func AddSession(session *link.Session) {
sessionMutex.Lock()
defer sessionMutex.Unlock()
sessions[session.Id()] = session
session.AddCloseCallback(session, func() {
RemoveSession(session.Id())
})
}
示例3: SetClientSessionOnline
//LoginServer用户上线
func SetClientSessionOnline(userSession *link.Session) {
//发送用户上线消息到serverName
protoMsg := &systemProto.System_ClientSessionOnlineC2S{
SessionID: protos.Uint64(userSession.Id()),
Network: protos.String(userSession.Conn().RemoteAddr().Network()),
Addr: protos.String(userSession.Conn().RemoteAddr().String()),
}
send_msg := protos.MarshalProtoMsg(protoMsg)
sendSystemMsg2("LoginServer", 0, send_msg)
}
示例4: SetClientLoginSuccess
//通知GameServer用户登录成功
func SetClientLoginSuccess(userName string, userID uint64, session *link.Session) {
send_msg := protos.MarshalProtoMsg(&systemProto.System_ClientLoginSuccessC2S{
UserID: protos.Uint64(userID),
UserName: protos.String(userName),
SessionID: protos.Uint64(session.Id()),
GameServerID: protos.Uint32(0),
Network: protos.String(session.Conn().RemoteAddr().Network()),
Addr: protos.String(session.Conn().RemoteAddr().String()),
})
sendSystemMsgToServer(send_msg)
}
示例5: LoginSuccess
//用户登录成功处理
func (this UserModule) LoginSuccess(session *link.Session, userName string, userID uint64, gameServerID uint32) bool {
cacheSuccess := module.Cache.AddOnlineUser(userName, userID, session, gameServerID)
if cacheSuccess {
session.AddCloseCallback(session, func() {
module.Cache.RemoveOnlineUser(session.Id())
DEBUG("用户下线:当前在线人数", module.Cache.GetOnlineUsersNum())
})
DEBUG("用户上线:当前在线人数", module.Cache.GetOnlineUsersNum())
return true
} else {
ERR("what????", userName)
return false
}
}
示例6: SendToGameServer
//发送消息到TransferServer, 网关调用
func SendToGameServer(userSession *link.Session, msg []byte) {
send_msg := make([]byte, 8+len(msg))
copy(send_msg[:2], msg[:2])
binary.PutUint64LE(send_msg[2:10], userSession.Id())
copy(send_msg[10:], msg[2:])
//C2S消息,发送到GameServer或者LoginServer
msgID := binary.GetUint16LE(send_msg[:2])
if gameProto.IsValidLoginID(msgID) {
sendGameMsg("LoginServer", send_msg)
} else {
sendGameMsg("GameServer", send_msg)
}
}
示例7: SendGetUserInfoResult
func SendGetUserInfoResult(errorCode int32, u *UserModel, session *link.Session) {
if errorCode != 0 {
SendErrorMsg(errorCode, session)
} else {
send_msg := MarshalProtoMsg(&GetUserInfoS2C{
UserInfo: &Person{
ID: protos.Uint64(u.DBUser.ID),
Name: protos.String(u.DBUser.Name),
Money: protos.Int32(u.DBUser.Money),
SessionID: protos.Uint64(session.Id()),
},
})
Send(send_msg, session)
}
}
示例8: loginSuccess
func loginSuccess(session *link.Session, userName string, userID uint64) bool {
cacheSuccess := module.Cache.AddOnlineUser(userName, userID, session)
if cacheSuccess {
session.AddCloseCallback(session, func() {
module.Cache.RemoveOnlineUser(session.Id())
DEBUG("下线:在线人数", module.Cache.GetOnlineUsersNum())
})
DEBUG("上线:在线人数", module.Cache.GetOnlineUsersNum())
//通知游戏服务器登录成功
transferProxy.SendClientLoginSuccess(userName, userID, session.Id())
return true
}
return false
}
示例9: GetUserInfo
//获取用户详细信息
func (this UserModule) GetUserInfo(userID uint64, session *link.Session) {
onlineUser := module.Cache.GetOnlineUserByUserID(userID)
if onlineUser != nil {
dbUser := redisProxy.GetDBUser(userID)
if dbUser != nil {
userModel := NewUserModel(dbUser)
module.SendGetUserInfoResult(0, userModel, session)
//更新用户最后上线时间,更新内存和数据库
nowTime := time.Now().Unix()
redisProxy.UpdateUserLastLoginTime(userID, nowTime)
dbProxy.UpdateUserLastLoginTime(session.Id(), userID, nowTime)
} else {
module.SendGetUserInfoResult(gameProto.User_Not_Exists, nil, session)
}
} else {
module.SendGetUserInfoResult(gameProto.User_Login_Fail, nil, session)
}
}
示例10: Login
//登录
func (this UserModule) Login(userName string, session *link.Session) {
onlineUser := module.Cache.GetOnlineUserByUserName(userName)
if onlineUser != nil {
if onlineUser.Session.Id() != session.Id() {
//当前在线,但是连接不同,其他客户端连接,需通知当前客户端下线
gameProxy.SendOtherLogin(onlineUser.Session)
//替换Session
module.Cache.RemoveOnlineUser(onlineUser.Session.Id())
//登录成功处理
success := this.LoginSuccess(session, onlineUser.UserName, onlineUser.UserID, 0)
if success {
//登录成功后处理
this.dealLoginSuccess(session, userName, onlineUser.UserID)
} else {
gameProxy.SendLoginResult(session, 0)
}
}
} else {
dbProxy.UserLogin(session.Id(), userName)
}
}
示例11: AddOnlineUser
//添加在线用户缓存
func (this *CacheModule) AddOnlineUser(userName string, userID uint64, session *link.Session) bool {
this.onlineUsersMutex.Lock()
defer this.onlineUsersMutex.Unlock()
//同一账号只能对应一个Session
//同一SessionID只能登陆一个账号
_, exists1 := this.onlineUsers[userName]
_, exists2 := this.onlineUsersSession[session.Id()]
if !exists1 && !exists2 {
model := &OnlineUserModel{
Session: session,
UserID: userID,
UserName: userName,
}
this.onlineUsers[userName] = model
this.onlineUsersID[userID] = userName
this.onlineUsersSession[session.Id()] = userName
this.onlineUsersNum += 1
return true
} else {
return false
}
}
示例12: AddSession
func (m *VFMap) AddSession(s *link.Session) {
m.c_sessions[s.Id()] = s
}
示例13: RemoveSession
func RemoveSession(session *link.Session) {
sessionMutex.Lock()
defer sessionMutex.Unlock()
delete(sessions, session.Id())
}