using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Sog; using ProtoCSStruct; namespace Game { public class FriendOpHandler : BasePacketHandler { public override int GetServiceType() { return GameServiceType.FriendOpHandler; } //销毁的时候置空 public override void Dispose() { } public FriendOpHandler() { } public override void HandlerClientPacket(PlayerSession playerSession, StructPacket packet) { PlayerOnGame player = playerSession.Player; if (player == null) { player.Error("FriendHandler.HandlerClientPacket can not find PlayerOnGame sessionid {0}" , playerSession.SessionID); return; } switch (packet.MsgID) { case (int)CSGameMsgID.QueryFriendOpReq: OnCliQueryFriendOpReq(player, packet); break; case (int)CSGameMsgID.FriendOpReq: OnCliFriendOpReq(player, packet); break; case (int)CSGameMsgID.FriendQueryInfoByUidReq: OnCliFriendQueryInfoByUidReq(player, packet); break; case (int)CSGameMsgID.FriendGetRecommenderReq: OnCliFriendGetRecommenderReq(player, packet); break; case (int)CSGameMsgID.FriendQueryStrangerReq: OnCliFriendQueryStrangerReq(player, packet); break; default: break; } } public override void HandlerServerPacket(uint serverID, StructPacket packet) { switch (packet.MsgID) { case (int)CSGameMsgID.QueryFriendOpRes: OnSvrQueryFriendOpRes(serverID, packet); break; case (int)CSGameMsgID.FriendOpRes: OnSvrFriendOpRes(serverID, packet); break; case (int)CSGameMsgID.FriendStrangerListChgNotify: OnSvrFriendStrangerListChgNotify(serverID, packet); break; case (int)CSGameMsgID.FriendStrangerListDeleteNotify: OnSvrFriendStrangerListDeleteNotify(serverID, packet); break; case (int)CSGameMsgID.FriendOpListChgNotify: OnSvrFriendOpListChgNotify(serverID, packet); break; //case (int)CSGameMsgID.FriendOpListDeleteNotify: // OnSvrFriendOpListDeleteNotify(serverID, packet); // break; case (int)CSGameMsgID.FriendQueryInfoByUidRes: OnSvrFriendQueryInfoByUidRes(serverID, packet); break; case (int)CSGameMsgID.FriendGetRecommenderRes: OnSvrFriendGetRecommenderRes(serverID, packet); break; case (int)CSGameMsgID.FriendQueryStrangerRes: OnSvrFriendQueryStrangerRes(serverID, packet); break; default: break; } } private void OnCliQueryFriendOpReq(PlayerOnGame player, StructPacket packet) { GameServerUtils.GetPacketSender().SendToWorldServer(packet, player.UserID); } private void OnSvrQueryFriendOpRes(uint serverID, StructPacket packet) { PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID); if (player == null) { player.Error("FriendOpHandler.OnSvrQueryFriendOpRes no player object uid {0}", packet.ObjectID); return; } player.SendToClient(packet); } private void OnCliFriendOpReq(PlayerOnGame player, StructPacket packet) { ref CSFriendOpReq req = ref packet.GetMessage(); player.Trace("FriendOpHandler.OnCliFriendOpReq uid {0} friendOp type {1} seq {2} targetUid {3}" , player.UserID, req.OpType, req.OpSeq, req.TargetUid); if(FriendOpSvc.CheckValidCliFriendOpReq(player, ref req) != 0) { player.Error("FriendOpHandler.OnCliFriendOpReq uid {0} friendOp type {1} CheckValidFriendOpReq check failed" , player.UserID, req.OpType); return; } GameServerUtils.GetPacketSender().SendToWorldServer(packet, player.UserID); } private void OnSvrFriendOpRes(uint serverID, StructPacket packet) { PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID); if (player == null) { player.Error("FriendOpHandler.OnSvrFriendOpRes no player object uid {0}", packet.ObjectID); return; } player.SendToClient(packet); } private void OnSvrFriendStrangerListChgNotify(uint serverID, StructPacket packet) { PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID); if (player == null) { player.Error("FriendOpHandler.OnSvrFriendStrangerListChgNotify no player object uid {0}", packet.ObjectID); return; } player.SendToClient(packet); } private void OnSvrFriendStrangerListDeleteNotify(uint serverID, StructPacket packet) { PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID); if (player == null) { player.Error("FriendOpHandler.OnSvrFriendStrangerListDeleteNotify no player object uid {0}", packet.ObjectID); return; } player.SendToClient(packet); } private void OnSvrFriendOpListChgNotify(uint serverID, StructPacket packet) { PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID); if (player == null) { player.Error("FriendOpHandler.OnSvrFriendOpListChgNotify no player object uid {0}", packet.ObjectID); return; } player.SendToClient(packet); } //private void OnSvrFriendOpListDeleteNotify(uint serverID, StructPacket packet) //{ // PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID); // if (player == null) // { // player.Error("FriendOpHandler.OnSvrFriendOpListDeleteNotify no player object uid {0}", packet.ObjectID); // return; // } // player.SendToClient(packet); //} private void OnCliFriendQueryInfoByUidReq(PlayerOnGame player, StructPacket packet) { GameServerUtils.GetPacketSender().SendToWorldServer(packet, player.UserID); } private void OnSvrFriendQueryInfoByUidRes(uint serverID, StructPacket packet) { PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID); if (player == null) { player.Error("FriendOpHandler.OnSvrFriendQueryInfoByUidRes no player object uid {0}", packet.ObjectID); return; } player.SendToClient(packet); } private void OnCliFriendGetRecommenderReq(PlayerOnGame player, StructPacket packet) { GameServerUtils.GetPacketSender().SendToWorldServer(packet, player.UserID); } private void OnSvrFriendGetRecommenderRes(uint serverID, StructPacket packet) { PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID); if (player == null) { player.Error("FriendOpHandler.OnSvrFriendGetRecommenderRes no player object uid {0}", packet.ObjectID); return; } //过滤下GM账号 ref var res = ref packet.GetMessage(); for (int i = res.List.Count - 1; i >= 0; i--) { if (GmCmdSvc.IsGMFilter(res.List[i].Uid)) { res.List.RemoveAt(i); } } var csres = new CSFriendGetRecommenderRes(); csres.CopyFrom(ref res); SendToPlayer(player, (int) CSGameMsgID.FriendGetRecommenderRes, ref csres); } private void OnCliFriendQueryStrangerReq(PlayerOnGame player, StructPacket packet) { GameServerUtils.GetPacketSender().SendToWorldServer(packet, player.UserID); } private void OnSvrFriendQueryStrangerRes(uint serverID, StructPacket packet) { PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID); if (player == null) { player.Error("FriendOpHandler.OnSvrFriendQueryStrangerRes no player object uid {0}", packet.ObjectID); return; } player.SendToClient(packet); } } }