//通知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)
}
Exemplo n.º 2
0
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)
	}
}
//用户登录
func userLogin(session *link.Session, protoMsg protos.ProtoMsg) {
	rev_msg := protoMsg.Body.(*dbProto.DB_User_LoginC2S)
	userName := rev_msg.GetName()

	//先从缓存中读取
	dbUser := redisProxy.GetDBUserByUserName(userName)
	if dbUser == nil {
		//从数据库中获取
		dbUser, _ = dao.GetUserByUserName(userName)
		//将数据缓存到Redis
		redisProxy.SetDBUser(dbUser)
	}

	//返回消息
	sendProtoMsg := &dbProto.DB_User_LoginS2C{}
	if dbUser != nil {
		sendProtoMsg.ID = protos.Uint64(dbUser.ID)
		sendProtoMsg.Name = protos.String(dbUser.Name)
	}
	send_msg := dbProto.MarshalProtoMsg(protoMsg.Identification, sendProtoMsg)
	sendDBMsgToClient(session, send_msg)

	//更新最后登录时间
	if dbUser != nil {
		dbUser.LastLoginTime = time.Now().Unix()
		redisProxy.UpdateUserLastLoginTime(dbUser)
	}
}
Exemplo n.º 4
0
//更新用户最后登录时间
func UpdateUserLastLoginTime(identification uint64, userID uint64, time int64) {
	msg := dbProto.MarshalProtoMsg(identification, &dbProto.DB_User_UpdateLastLoginTimeC2S{
		UserID: protos.Uint64(userID),
		Time:   protos.Int64(time),
	})
	sendDBMsgToServer(msg)
}
//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)
}
Exemplo n.º 6
0
//重新连接
func againConnect(session *link.Session, msg protos.ProtoMsg) {
	rev_msg := msg.Body.(*gameProto.AgainConnectC2S)

	newSessionID := module.User.AgainConnect(rev_msg.GetSessionID(), session)
	if newSessionID != 0 {
		send_msg := protos.MarshalProtoMsg(&gameProto.AgainConnectS2C{
			SessionID: protos.Uint64(newSessionID),
		})
		protos.Send(session, send_msg)
	}
}
Exemplo n.º 7
0
//重新连接
func againConnect(msg ProtoMsg, session *link.Session) {
	rev_msg := msg.Body.(*AgainConnectC2S)

	newSessionID := User.AgainConnect(rev_msg.GetSessionID(), session)
	if newSessionID != 0 {
		send_msg := MarshalProtoMsg(&AgainConnectS2C{
			SessionID: protos.Uint64(newSessionID),
		})
		Send(send_msg, session)
	}
}
Exemplo n.º 8
0
//用户登录
func userLogin(session *link.Session, protoMsg dbProto.ProtoMsg) {
	rev_msg := protoMsg.Body.(*dbProto.DB_User_LoginC2S)

	sendProtoMsg := &dbProto.DB_User_LoginS2C{}
	dbUser, _ := module_db.GetUserByUserName(rev_msg.GetName())
	if dbUser != nil {
		redisProxy.SetDBUser(dbUser)

		sendProtoMsg.ID = protos.Uint64(dbUser.ID)
		sendProtoMsg.Name = protos.String(dbUser.Name)
	}

	send_msg := dbProto.MarshalProtoMsg(protoMsg.Identification, sendProtoMsg)
	sendDBMsgToClient(session, send_msg)
}
//通知GameServer、LoginServer用户下线, 网关调用
func SetClientSessionOffline(sessionID uint64) {
	//给该用户所分配的GameServerID
	gameServerID := getUserGameServerID(sessionID)

	//发送消息到GameServer和LoginServer
	protoMsg := &systemProto.System_ClientSessionOfflineC2S{
		SessionID: protos.Uint64(sessionID),
	}
	send_msg := protos.MarshalProtoMsg(protoMsg)

	sendSystemMsg2("GameServer", gameServerID, send_msg)
	sendSystemMsg2("LoginServer", 0, send_msg)

	//给该用户不再分配游戏服务器
	noAllotGameServer(sessionID)
}
//更新用户最后登录时间
func UpdateUserLastLoginTime(dbUser *DBUserModel) {
	userIDStr := strconv.FormatUint(dbUser.ID, 10)
	userLastLoginTime := strconv.FormatInt(dbUser.LastLoginTime, 10)

	//更新内存
	userKey := DB_User_Key + userIDStr
	data, _ := json.Marshal(dbUser)
	client.Set(userKey, data)

	//单独设置用户的最后登录时间,清理用户缓存数据使用
	client.Hset(DB_UserLastLoginTime_Key, userIDStr, []byte(userLastLoginTime))

	//更新DB
	msg := dbProto.MarshalProtoMsg(0, &dbProto.DB_User_UpdateLastLoginTimeC2S{
		UserID: protos.Uint64(dbUser.ID),
		Time:   protos.Int64(dbUser.LastLoginTime),
	})
	PushDBWriteMsg(msg)
}
Exemplo n.º 11
0
//发送登录结果
func SendLoginResult(userID uint64, session *link.Session) {
	send_msg := MarshalProtoMsg(&UserLoginS2C{
		UserID: protos.Uint64(userID),
	})
	Send(send_msg, session)
}
Exemplo n.º 12
0
//发送登录结果
func SendLoginResult(session *link.Session, userID uint64) {
	send_msg := protos.MarshalProtoMsg(&gameProto.UserLoginS2C{
		UserID: protos.Uint64(userID),
	})
	protos.Send(session, send_msg)
}