Example #1
0
        /// <summary>
        /// 添加好友的操作
        /// </summary>
        /// <returns>返回执行结果</returns>
        public string AddFriend(string data, Client client, Server server)
        {
            string[] strs     = data.Split(',');
            int      id       = int.Parse(strs[0]);
            int      friendId = int.Parse(strs[1]);

            if (id == friendId)
            {
                return(((int)ReturnCode.Fail).ToString() + "," + "不能添加自己");
            }

            if (friendDAO.HasAdded(client.MySqlConnection, id, friendId))
            {
                return(((int)ReturnCode.Fail).ToString() + "," + "已添加对方为好友");
            }
            else
            {
                string result = friendDAO.AddFriendRequest(client.MySqlConnection, id, friendId);
                if (result == " ")
                {
                    // 给好友发送一份
                    if (server.GetChatReceive(friendId) != null)
                    {
                        server.RequestHander(RequestCode.Message, ActionCode.GetUnreadMessage, friendId.ToString(), server.GetChatReceive(friendId));
                    }

                    return(((int)ReturnCode.Success).ToString());
                }
                else
                {
                    return(((int)ReturnCode.Fail).ToString() + "," + result);
                }
            }
        }
Example #2
0
        /// <summary>
        /// 添加好友的操作
        /// </summary>
        /// <returns>返回执行结果</returns>
        public string AddFriend(string data, Client client, Server server)
        {
            string[] strs     = data.Split(',');
            int      id       = int.Parse(strs[0]);
            int      friendId = int.Parse(strs[1]);

            if (friendDAO.HasAdded(client.MySqlConnection, id, friendId))
            {
                return(((int)ReturnCode.Fail).ToString() + "," + "已添加对方为好友");
            }
            else
            {
                string result = friendDAO.AddFriendRequest(client.MySqlConnection, id, friendId);
                if (result == " ")
                {
                    return(((int)ReturnCode.Success).ToString());
                }
                else
                {
                    return(((int)ReturnCode.Fail).ToString() + "," + result);
                }
            }
        }