/// <summary>家族公告推送</summary> /// <param name="uid">玩家ID</param> /// <param name="fid">玩家家族ID</param> /// <param name="name">玩家名称</param> /// <param name="data">推送的文本</param> public void FamilyPush(Int64 uid, Int64 fid, string name, string data) { var list = Variable.OnlinePlayer.Select(m => m.Value as TGGSession) .Where(m => m.Player.Family.fid == fid).ToList();//同家族 foreach (var item in list) { var token = new CancellationTokenSource(); var obj = new FamilyPushObject { session = item, user_id = uid, player_name = name, data = data, }; Task.Factory.StartNew(m => { var _obj = m as FamilyPushObject; if (_obj == null) { return; } CHATS_PUSH.GetInstance().CommandStart(_obj.session, (int)ChatsType.CHATS_FAMILY, _obj.user_id, _obj.player_name, (int)ChatsPushType.NO_PRIVATE, _obj.data, null); }, obj, token.Token); } }
/// <summary>世界聊天</summary> private void CHATS_WORLD(Player player, int type, object[] goods, string data) { var _data = goods.Any() ? AnalyticalGoods(goods) : null; var list = Variable.OnlinePlayer.Select(m => m.Key).Where(m => !player.BlackList.Contains(m)).ToList(); //查询在线玩家且不是黑名单的玩家集合 foreach (var item in list) { var token = new CancellationTokenSource(); Task.Factory.StartNew(m => { CHATS_PUSH.GetInstance().CommandStart(Convert.ToInt64(m), type, player.User.id, player.User.player_name, (int)ChatsPushType.NO_PRIVATE, data, _data); //全世界 }, item, token.Token); } }
/// <summary>家族聊天</summary> private void CHATS_PARTY(Player player, int type, string data, object[] goods) { var _data = goods.Any() ? AnalyticalGoods(goods) : null; var list = Variable.OnlinePlayer.Select(m => m.Value as TGGSession) .Where(m => m.Player.Family.fid == player.Family.fid && !player.BlackList.Contains(m.Player.User.id) && !m.Player.BlackList.Contains(player.User.id)).Select(m => m.Player.User.id).ToList();//同家族且相互间不是黑名单的用户Id foreach (var m in list) { var token = new CancellationTokenSource(); Task.Factory.StartNew(n => { CHATS_PUSH.GetInstance().CommandStart(Convert.ToInt64(n), type, player.User.id, player.User.player_name, (int)ChatsPushType.NO_PRIVATE, data, _data); }, m, token.Token); } }
/// <summary>个人聊天</summary> private ResultType CHATS_ONE(TGGSession session, int type, string data, string receive, object[] goods) { var user = session.Player.User; string t = receive.Split('_')[0]; int n = receive.IndexOf('_') + 1; string value = receive.Substring(n, receive.Length - n); TGGSession rivalsession; switch (t) { case "id": { if (session.Player.User.id == Convert.ToInt64(value)) { return(ResultType.CHAT_NO_MY); } var userid = Convert.ToInt64(value); if (!tg_user.UserIdIsContains(userid)) { return(ResultType.CHAT_NO_EXIST); } if (!Variable.OnlinePlayer.ContainsKey(userid)) { return(ResultType.CHAT_NO_ONLINE); } rivalsession = Variable.OnlinePlayer[userid] as TGGSession; break; } case "name": { if (session.Player.User.player_name == value) { return(ResultType.CHAT_NO_MY); } if (!tg_user.PlayNameIsContains(value)) { return(ResultType.CHAT_NO_EXIST); } rivalsession = Variable.OnlinePlayer.Select(m => m.Value as TGGSession).FirstOrDefault(m => m.Player.User.player_name == value); break; } default: { return(ResultType.FRONT_DATA_ERROR); } } if (rivalsession == null) { return(ResultType.CHAT_NO_ONLINE); } var uid = rivalsession.Player.User.id; //对方用户Id if (session.Player.BlackList.Contains(uid)) { return(ResultType.CHAT_BLACK); //验证对方是否在己方黑名单 } if (rivalsession.Player.BlackList.Contains(user.id)) { return(ResultType.CHAT_RIVAL_BLACK); //验证己方是否在对方黑名单 } var _data = goods.Any() ? AnalyticalGoods(goods) : null; CHATS_PUSH.GetInstance().CommandStart(session, type, rivalsession.Player.User.id, rivalsession.Player.User.player_name, (int)ChatsPushType.ME_SAID_PLAYER, data, _data); CHATS_PUSH.GetInstance().CommandStart(rivalsession, type, user.id, user.player_name, (int)ChatsPushType.PLAYERME_SAID_ME, data, _data); return(ResultType.SUCCESS); }
/// <summary>CHATS_PUSH单体模式</summary> public static CHATS_PUSH GetInstance() { return(ObjInstance ?? (ObjInstance = new CHATS_PUSH())); }