xy 4 ngày trước cách đây
mục cha
commit
3383df4a97

+ 8 - 0
bin/client_msg/common.proto

@@ -382,3 +382,11 @@ message ResDeleteFriend{
 }
 
 
+
+//好友上线/下线响应
+message ResFriendOnLineStatus{
+  bool success = 1;
+  MsgError err_msg = 2;
+  UserInfo info = 3;
+}
+

+ 10 - 0
src/server/common/user_common.go

@@ -3,10 +3,20 @@ package common
 import (
 	"server/console"
 	usercenter "server/datacenter"
+	"server/hall/friends"
+
+	"github.com/name5566/leaf/gate"
 )
 
+type GetAgentByUserID func(userID string) gate.Agent
+
 // 更新玩家在线状态
 func UpdateUserOnlineStatus(online_status int32, userId string) {
 	console.Log("UpdateUserOnlineStatus:", online_status, userId)
 	usercenter.UpdateOnlineStatusToDB(userId, online_status)
 }
+
+func RpcCloseAgent(user_id string, getAgentFunc GetAgentByUserID) {
+	usercenter.UpdateOnlineStatusToDB(user_id, 0)
+	friends.NotifyFriendOnlineStatus(user_id, 0)
+}

+ 5 - 4
src/server/game/agentManager/agentManager.go

@@ -1,7 +1,6 @@
 package agentmanager
 
 import (
-	"server/common"
 	"time"
 
 	"github.com/name5566/leaf/gate"
@@ -38,7 +37,7 @@ func NewAgent(args []interface{}) {
 	go checkTimeout(agent)
 }
 
-func CloseAgent(args []interface{}) {
+func CloseAgent(args []interface{}) string {
 	agent := args[0].(gate.Agent)
 	// 清理未认证连接
 	_, exists := pendingConns[agent]
@@ -49,16 +48,18 @@ func CloseAgent(args []interface{}) {
 	for userID, a := range authedUsers {
 		//设置为离线状态
 		if a == agent {
-			common.UpdateUserOnlineStatus(0, userID)
+			// common.UpdateUserOnlineStatus(0, userID)
+
 			// a.SetUserData(&common.UserData{
 			// 	Id:       userID,
 			// 	Nickname: userID,
 			// 	Status:   0,
 			// })
 			delete(authedUsers, userID)
-			break
+			return userID
 		}
 	}
+	return ""
 }
 
 // 定时检查超时连接

+ 1 - 3
src/server/game/external.go

@@ -1,8 +1,6 @@
 package game
 
-import (
-	"server/game/internal"
-)
+import "server/game/internal"
 
 var (
 	Module  = new(internal.Module)

+ 5 - 3
src/server/game/internal/chanrpc.go

@@ -1,7 +1,7 @@
 package internal
 
 import (
-	"server/console"
+	"server/common"
 	agentmanager "server/game/agentManager"
 )
 
@@ -15,6 +15,8 @@ func rpcNewAgent(args []interface{}) {
 }
 
 func rpcCloseAgent(args []interface{}) {
-	console.Log("rpcCloseAgent")
-	agentmanager.CloseAgent(args)
+	user_id := agentmanager.CloseAgent(args)
+	if user_id != "" {
+		common.RpcCloseAgent(user_id, agentmanager.GetAgentByUserID)
+	}
 }

+ 31 - 2
src/server/hall/friends/friends.go

@@ -204,9 +204,38 @@ func SearchUser(args []interface{}) {
 	}
 }
 
-// 通知给在线的好友自己上线
+// 通知给在线的好友自己上线/下线
+func NotifyFriendOnlineStatus(UserId string, OnlineStatus int32) {
+	mysql_user_data, err := usercenter.GetUserByID(UserId)
+	if err != nil {
+		console.Log("NotifyFriendOnline error:", err.Error())
+		return
+	}
+	users, err := mysql_user_data.GetAllFriend()
+	user_data := &msg.UserInfo{
+		UserId:       mysql_user_data.UserID,
+		MHead:        mysql_user_data.Head,
+		Name:         mysql_user_data.Name,
+		OnlineStatus: OnlineStatus,
+	}
+	if err == nil {
+		for _, v := range users {
+			ag := agentmanager.GetAgentByUserID(v.UserID)
+			if ag != nil {
+				ag.WriteMsg(&msg.ResFriendOnLineStatus{
+					Success: true,
+					ErrMsg:  nil,
+					Info:    user_data,
+				})
+
+			}
+
+		}
 
-// 通知给在线的好友自己下线
+	} else {
+		console.Log("NotifyFriendOnline error:", err.Error())
+	}
+}
 
 // 发送好友聊天消息
 

+ 6 - 3
src/server/hall/internal/handler.go

@@ -70,6 +70,8 @@ func enterHall(args []interface{}) {
 	//设置为在线状态
 	user.UpdateUserOnlineStatus(1, user_info.UserId)
 
+	friends.NotifyFriendOnlineStatus(user_info.UserId, 1)
+
 	room_id := user_info.RoomId
 	var user_room *msg.RoomInfo = nil
 	//如果玩家在某个游戏里,就进行重连
@@ -100,9 +102,10 @@ func enterHall(args []interface{}) {
 
 func leaveHall(args []interface{}) {
 	m := args[0].(*msg.LeaveHall)
-	a := args[1].(gate.Agent)
+	// a := args[1].(gate.Agent)
 
 	//设置为离线状态
-	user.UpdateUserOnlineStatus(0, m.UserId)
-	log.Debug("leaveHallHandler, msg: %v, agent: %v", m, a)
+	agentmanager.KickAgent(m.UserId)
+	friends.NotifyFriendOnlineStatus(m.UserId, 0)
+	log.Debug("leaveHallHandler, msg: %v, agent: %v", m)
 }

+ 135 - 67
src/server/msg/common.pb.go

@@ -3418,6 +3418,67 @@ func (x *ResDeleteFriend) GetErrMsg() *MsgError {
 	return nil
 }
 
+// 好友上线/下线响应
+type ResFriendOnLineStatus struct {
+	state         protoimpl.MessageState `protogen:"open.v1"`
+	Success       bool                   `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"`
+	ErrMsg        *MsgError              `protobuf:"bytes,2,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"`
+	Info          *UserInfo              `protobuf:"bytes,3,opt,name=info,proto3" json:"info,omitempty"`
+	unknownFields protoimpl.UnknownFields
+	sizeCache     protoimpl.SizeCache
+}
+
+func (x *ResFriendOnLineStatus) Reset() {
+	*x = ResFriendOnLineStatus{}
+	mi := &file_common_proto_msgTypes[52]
+	ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+	ms.StoreMessageInfo(mi)
+}
+
+func (x *ResFriendOnLineStatus) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*ResFriendOnLineStatus) ProtoMessage() {}
+
+func (x *ResFriendOnLineStatus) ProtoReflect() protoreflect.Message {
+	mi := &file_common_proto_msgTypes[52]
+	if x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use ResFriendOnLineStatus.ProtoReflect.Descriptor instead.
+func (*ResFriendOnLineStatus) Descriptor() ([]byte, []int) {
+	return file_common_proto_rawDescGZIP(), []int{52}
+}
+
+func (x *ResFriendOnLineStatus) GetSuccess() bool {
+	if x != nil {
+		return x.Success
+	}
+	return false
+}
+
+func (x *ResFriendOnLineStatus) GetErrMsg() *MsgError {
+	if x != nil {
+		return x.ErrMsg
+	}
+	return nil
+}
+
+func (x *ResFriendOnLineStatus) GetInfo() *UserInfo {
+	if x != nil {
+		return x.Info
+	}
+	return nil
+}
+
 var File_common_proto protoreflect.FileDescriptor
 
 const file_common_proto_rawDesc = "" +
@@ -3637,7 +3698,11 @@ const file_common_proto_rawDesc = "" +
 	"\bToUserID\x18\x01 \x01(\tR\bToUserID\"O\n" +
 	"\x0fResDeleteFriend\x12\x18\n" +
 	"\asuccess\x18\x01 \x01(\bR\asuccess\x12\"\n" +
-	"\aerr_msg\x18\x02 \x01(\v2\t.MsgErrorR\x06errMsg*K\n" +
+	"\aerr_msg\x18\x02 \x01(\v2\t.MsgErrorR\x06errMsg\"t\n" +
+	"\x15ResFriendOnLineStatus\x12\x18\n" +
+	"\asuccess\x18\x01 \x01(\bR\asuccess\x12\"\n" +
+	"\aerr_msg\x18\x02 \x01(\v2\t.MsgErrorR\x06errMsg\x12\x1d\n" +
+	"\x04info\x18\x03 \x01(\v2\t.UserInfoR\x04info*K\n" +
 	"\broleType\x12\x15\n" +
 	"\x11ROLE_TYPE_UNKNOWN\x10\x00\x12\a\n" +
 	"\x03RED\x10\x01\x12\b\n" +
@@ -3688,67 +3753,68 @@ func file_common_proto_rawDescGZIP() []byte {
 }
 
 var file_common_proto_enumTypes = make([]protoimpl.EnumInfo, 7)
-var file_common_proto_msgTypes = make([]protoimpl.MessageInfo, 52)
+var file_common_proto_msgTypes = make([]protoimpl.MessageInfo, 53)
 var file_common_proto_goTypes = []any{
-	(RoleType)(0),                // 0: roleType
-	(OptType)(0),                 // 1: OptType
-	(RoomType)(0),                // 2: roomType
-	(RoomMode)(0),                // 3: roomMode
-	(RoadType)(0),                // 4: roadType
-	(PlayerStatus)(0),            // 5: playerStatus
-	(RoomStatus)(0),              // 6: roomStatus
-	(*Round)(nil),                // 7: round
-	(*RoomInfo)(nil),             // 8: RoomInfo
-	(*RoleData)(nil),             // 9: RoleData
-	(*ColorData)(nil),            // 10: ColorData
-	(*MoveStepData)(nil),         // 11: MoveStepData
-	(*SendColorSz)(nil),          // 12: SendColorSz
-	(*SendRoleMove)(nil),         // 13: SendRoleMove
-	(*SendQuitRoom)(nil),         // 14: SendQuitRoom
-	(*NotifyPlayerSzNumber)(nil), // 15: NotifyPlayerSzNumber
-	(*NotifyPlayerMove)(nil),     // 16: NotifyPlayerMove
-	(*NotifyPlayerOpt)(nil),      // 17: NotifyPlayerOpt
-	(*NotifyPlayerStatus)(nil),   // 18: NotifyPlayerStatus
-	(*NotifySettlement)(nil),     // 19: NotifySettlement
-	(*NotifyUpdateRoomInfo)(nil), // 20: NotifyUpdateRoomInfo
-	(*UserInfo)(nil),             // 21: UserInfo
-	(*ReqLogin)(nil),             // 22: ReqLogin
-	(*ResLogin)(nil),             // 23: ResLogin
-	(*ReqRegister)(nil),          // 24: ReqRegister
-	(*ResRegister)(nil),          // 25: ResRegister
-	(*EnterHall)(nil),            // 26: EnterHall
-	(*ResEnterHall)(nil),         // 27: ResEnterHall
-	(*LeaveHall)(nil),            // 28: LeaveHall
-	(*MatchLudo)(nil),            // 29: MatchLudo
-	(*ResMatchLudo)(nil),         // 30: ResMatchLudo
-	(*MsgError)(nil),             // 31: MsgError
-	(*UpdateUserInfo)(nil),       // 32: UpdateUserInfo
-	(*ResHeartBeat)(nil),         // 33: ResHeartBeat
-	(*ReqHeartBeat)(nil),         // 34: ReqHeartBeat
-	(*ShopItem)(nil),             // 35: ShopItem
-	(*BeKickLogin)(nil),          // 36: BeKickLogin
-	(*ReqShop)(nil),              // 37: ReqShop
-	(*ResShop)(nil),              // 38: ResShop
-	(*HistoryRecord)(nil),        // 39: HistoryRecord
-	(*ReqLudoHistory)(nil),       // 40: ReqLudoHistory
-	(*ResLudoHistory)(nil),       // 41: ResLudoHistory
-	(*ReqLudoRoomInfo)(nil),      // 42: ReqLudoRoomInfo
-	(*ResLudoRoomInfo)(nil),      // 43: ResLudoRoomInfo
-	(*BuyShopItem)(nil),          // 44: BuyShopItem
-	(*RequestAddFriendItem)(nil), // 45: RequestAddFriendItem
-	(*ReqFriendList)(nil),        // 46: ReqFriendList
-	(*ResFriendList)(nil),        // 47: ResFriendList
-	(*FriendRequestItem)(nil),    // 48: FriendRequestItem
-	(*ReqFriendRequestList)(nil), // 49: ReqFriendRequestList
-	(*ResFriendRequestList)(nil), // 50: ResFriendRequestList
-	(*ReqAddFriend)(nil),         // 51: ReqAddFriend
-	(*RecvAddFriendRequest)(nil), // 52: RecvAddFriendRequest
-	(*OptAddFriendRequest)(nil),  // 53: OptAddFriendRequest
-	(*NotifyOptFriend)(nil),      // 54: NotifyOptFriend
-	(*SearchUser)(nil),           // 55: SearchUser
-	(*ResSearchUser)(nil),        // 56: ResSearchUser
-	(*ReqDeleteFriend)(nil),      // 57: ReqDeleteFriend
-	(*ResDeleteFriend)(nil),      // 58: ResDeleteFriend
+	(RoleType)(0),                 // 0: roleType
+	(OptType)(0),                  // 1: OptType
+	(RoomType)(0),                 // 2: roomType
+	(RoomMode)(0),                 // 3: roomMode
+	(RoadType)(0),                 // 4: roadType
+	(PlayerStatus)(0),             // 5: playerStatus
+	(RoomStatus)(0),               // 6: roomStatus
+	(*Round)(nil),                 // 7: round
+	(*RoomInfo)(nil),              // 8: RoomInfo
+	(*RoleData)(nil),              // 9: RoleData
+	(*ColorData)(nil),             // 10: ColorData
+	(*MoveStepData)(nil),          // 11: MoveStepData
+	(*SendColorSz)(nil),           // 12: SendColorSz
+	(*SendRoleMove)(nil),          // 13: SendRoleMove
+	(*SendQuitRoom)(nil),          // 14: SendQuitRoom
+	(*NotifyPlayerSzNumber)(nil),  // 15: NotifyPlayerSzNumber
+	(*NotifyPlayerMove)(nil),      // 16: NotifyPlayerMove
+	(*NotifyPlayerOpt)(nil),       // 17: NotifyPlayerOpt
+	(*NotifyPlayerStatus)(nil),    // 18: NotifyPlayerStatus
+	(*NotifySettlement)(nil),      // 19: NotifySettlement
+	(*NotifyUpdateRoomInfo)(nil),  // 20: NotifyUpdateRoomInfo
+	(*UserInfo)(nil),              // 21: UserInfo
+	(*ReqLogin)(nil),              // 22: ReqLogin
+	(*ResLogin)(nil),              // 23: ResLogin
+	(*ReqRegister)(nil),           // 24: ReqRegister
+	(*ResRegister)(nil),           // 25: ResRegister
+	(*EnterHall)(nil),             // 26: EnterHall
+	(*ResEnterHall)(nil),          // 27: ResEnterHall
+	(*LeaveHall)(nil),             // 28: LeaveHall
+	(*MatchLudo)(nil),             // 29: MatchLudo
+	(*ResMatchLudo)(nil),          // 30: ResMatchLudo
+	(*MsgError)(nil),              // 31: MsgError
+	(*UpdateUserInfo)(nil),        // 32: UpdateUserInfo
+	(*ResHeartBeat)(nil),          // 33: ResHeartBeat
+	(*ReqHeartBeat)(nil),          // 34: ReqHeartBeat
+	(*ShopItem)(nil),              // 35: ShopItem
+	(*BeKickLogin)(nil),           // 36: BeKickLogin
+	(*ReqShop)(nil),               // 37: ReqShop
+	(*ResShop)(nil),               // 38: ResShop
+	(*HistoryRecord)(nil),         // 39: HistoryRecord
+	(*ReqLudoHistory)(nil),        // 40: ReqLudoHistory
+	(*ResLudoHistory)(nil),        // 41: ResLudoHistory
+	(*ReqLudoRoomInfo)(nil),       // 42: ReqLudoRoomInfo
+	(*ResLudoRoomInfo)(nil),       // 43: ResLudoRoomInfo
+	(*BuyShopItem)(nil),           // 44: BuyShopItem
+	(*RequestAddFriendItem)(nil),  // 45: RequestAddFriendItem
+	(*ReqFriendList)(nil),         // 46: ReqFriendList
+	(*ResFriendList)(nil),         // 47: ResFriendList
+	(*FriendRequestItem)(nil),     // 48: FriendRequestItem
+	(*ReqFriendRequestList)(nil),  // 49: ReqFriendRequestList
+	(*ResFriendRequestList)(nil),  // 50: ResFriendRequestList
+	(*ReqAddFriend)(nil),          // 51: ReqAddFriend
+	(*RecvAddFriendRequest)(nil),  // 52: RecvAddFriendRequest
+	(*OptAddFriendRequest)(nil),   // 53: OptAddFriendRequest
+	(*NotifyOptFriend)(nil),       // 54: NotifyOptFriend
+	(*SearchUser)(nil),            // 55: SearchUser
+	(*ResSearchUser)(nil),         // 56: ResSearchUser
+	(*ReqDeleteFriend)(nil),       // 57: ReqDeleteFriend
+	(*ResDeleteFriend)(nil),       // 58: ResDeleteFriend
+	(*ResFriendOnLineStatus)(nil), // 59: ResFriendOnLineStatus
 }
 var file_common_proto_depIdxs = []int32{
 	0,  // 0: round.m_color:type_name -> roleType
@@ -3812,11 +3878,13 @@ var file_common_proto_depIdxs = []int32{
 	31, // 58: ResSearchUser.err_msg:type_name -> MsgError
 	21, // 59: ResSearchUser.info:type_name -> UserInfo
 	31, // 60: ResDeleteFriend.err_msg:type_name -> MsgError
-	61, // [61:61] is the sub-list for method output_type
-	61, // [61:61] is the sub-list for method input_type
-	61, // [61:61] is the sub-list for extension type_name
-	61, // [61:61] is the sub-list for extension extendee
-	0,  // [0:61] is the sub-list for field type_name
+	31, // 61: ResFriendOnLineStatus.err_msg:type_name -> MsgError
+	21, // 62: ResFriendOnLineStatus.info:type_name -> UserInfo
+	63, // [63:63] is the sub-list for method output_type
+	63, // [63:63] is the sub-list for method input_type
+	63, // [63:63] is the sub-list for extension type_name
+	63, // [63:63] is the sub-list for extension extendee
+	0,  // [0:63] is the sub-list for field type_name
 }
 
 func init() { file_common_proto_init() }
@@ -3830,7 +3898,7 @@ func file_common_proto_init() {
 			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
 			RawDescriptor: unsafe.Slice(unsafe.StringData(file_common_proto_rawDesc), len(file_common_proto_rawDesc)),
 			NumEnums:      7,
-			NumMessages:   52,
+			NumMessages:   53,
 			NumExtensions: 0,
 			NumServices:   0,
 		},

+ 2 - 0
src/server/msg/msg.go

@@ -71,6 +71,8 @@ func init() {
 	Processor.Register(&ReqDeleteFriend{})
 	Processor.Register(&ResDeleteFriend{})
 
+	Processor.Register(&ResFriendOnLineStatus{})
+
 	Processor.Range(func(id uint16, t reflect.Type) {
 		log.Debug("消息ID: %d, 消息类型: %s\n", id, t.Elem().Name())
 		msgList = append(msgList, MsgInfo{