Beispiel #1
0
 public bool AddFriends(FriendInfo info)
 {
     bool flag = false;
     try
     {
         flag = this.db.RunProcedure("SP_Users_Friends_Add", new SqlParameter[7]
     {
       new SqlParameter("@ID", (object) info.ID),
       new SqlParameter("@AddDate", (object) DateTime.Now),
       new SqlParameter("@FriendID", (object) info.FriendID),
       new SqlParameter("@IsExist", (object) true),
       new SqlParameter("@Remark", info.Remark == null ? (object) "" : (object) info.Remark),
       new SqlParameter("@UserID", (object) info.UserID),
       new SqlParameter("@Relation", (object) info.Relation)
     });
     }
     catch (Exception ex)
     {
         if (BaseBussiness.log.IsErrorEnabled)
             BaseBussiness.log.Error((object)"Init", ex);
     }
     return flag;
 }
 /// <summary>
 /// 批量获取用户好友信息
 /// </summary>
 /// <param name="condictArray">好友用户参数,以逗号切割</param>
 /// <returns>返回用户信息</returns>
 public FriendInfo[] GetFriendsBbs(string condictArray)
 {
     List<FriendInfo> infos = new List<FriendInfo>();
     SqlDataReader reader = null;
     try
     {
         SqlParameter[] para = new SqlParameter[1];
         para[0] = new SqlParameter("@SearchUserName", SqlDbType.NVarChar, 4000);
         para[0].Value = condictArray;
         db.GetReader(ref reader, "SP_Users_FriendsBbs", para);
         while (reader.Read())
         {
             FriendInfo info = new FriendInfo();
             info.NickName = reader["NickName"] == null ? "" : reader["NickName"].ToString();
             info.UserID = (int)reader["UserID"];
             info.UserName = reader["UserName"] == null ? "" : reader["UserName"].ToString();
             info.IsExist = (int)reader["UserID"] > 0 ? true : false;
             infos.Add(info);
         }
     }
     catch (Exception e)
     {
         if (log.IsErrorEnabled)
             log.Error("Init", e);
     }
     finally
     {
         if (reader != null && !reader.IsClosed)
             reader.Close();
     }
     return infos.ToArray();
 }
 public bool AddFriends(FriendInfo info)
 {
     bool result = false;
     try
     {
         SqlParameter[] para = new SqlParameter[7];
         para[0] = new SqlParameter("@ID", info.ID);
         para[1] = new SqlParameter("@AddDate", DateTime.Now);
         para[2] = new SqlParameter("@FriendID", info.FriendID);
         para[3] = new SqlParameter("@IsExist", true);
         para[4] = new SqlParameter("@Remark", info.Remark == null ? "" : info.Remark);
         para[5] = new SqlParameter("@UserID", info.UserID);
         para[6] = new SqlParameter("@Relation", info.Relation);
         result = db.RunProcedure("SP_Users_Friends_Add", para);
     }
     catch (Exception e)
     {
         if (log.IsErrorEnabled)
             log.Error("Init", e);
     }
     finally
     {
     }
     return result;
 }
        public FriendInfo[] GetFriendsAll(int UserID)
        {
            List<FriendInfo> infos = new List<FriendInfo>();
            SqlDataReader reader = null;
            try
            {
                SqlParameter[] para = new SqlParameter[1];
                para[0] = new SqlParameter("@UserID", SqlDbType.Int, 4);
                para[0].Value = UserID;
                db.GetReader(ref reader, "SP_Users_Friends", para);
                while (reader.Read())
                {
                    FriendInfo info = new FriendInfo();
                    info.AddDate = (DateTime)reader["AddDate"];
                    info.Colors = reader["Colors"] == null ? "" : reader["Colors"].ToString();
                    info.FriendID = (int)reader["FriendID"];
                    info.Grade = (int)reader["Grade"];
                    info.Hide = (int)reader["Hide"];
                    info.ID = (int)reader["ID"];
                    info.IsExist = (bool)reader["IsExist"];
                    info.NickName = reader["NickName"] == null ? "" : reader["NickName"].ToString();
                    info.Remark = reader["Remark"] == null ? "" : reader["Remark"].ToString();
                    info.Sex = ((bool)reader["Sex"]) ? 1 : 0;
                    info.State = (int)reader["State"];
                    info.Style = reader["Style"] == null ? "" : reader["Style"].ToString();
                    info.UserID = (int)reader["UserID"];
                    info.ConsortiaName = reader["ConsortiaName"] == null ? "" : reader["ConsortiaName"].ToString();
                    info.Offer = (int)reader["Offer"];
                    info.Win = (int)reader["Win"];
                    info.Total = (int)reader["Total"];
                    info.Escape = (int)reader["Escape"];
                    info.Relation = (int)reader["Relation"];
                    info.Repute = (int)reader["Repute"];
                    info.UserName = reader["UserName"] == null ? "" : reader["UserName"].ToString();
                    info.DutyName = reader["DutyName"] == null ? "" : reader["DutyName"].ToString();
                    info.Nimbus = (int)reader["Nimbus"];
                    infos.Add(info);
                }
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                    log.Error("Init", e);
            }
            finally
            {
                if (reader != null && !reader.IsClosed)
                    reader.Close();
            }
            return infos.ToArray();

        }
        //0友好,1黑名单
        public int HandlePacket(GameClient client, GSPacketIn packet)
        {
            GSPacketIn pkg = packet.Clone();
            pkg.ClearContext();

            string nickName = packet.ReadString();
            int relation = packet.ReadInt();
            if (relation < 0 || relation > 1)
                return 1;

            using (PlayerBussiness db = new PlayerBussiness())
            {
                PlayerInfo user = null;
                GamePlayer player = Managers.WorldMgr.GetClientByPlayerNickName(nickName);
                if (player != null)
                    user = player.PlayerCharacter;
                else
                    user = db.GetUserSingleByNickName(nickName);
                if (!string.IsNullOrEmpty(nickName) && user != null)
                {
                    if (!client.Player.Friends.ContainsKey(user.ID) || client.Player.Friends[user.ID] != relation)
                    {
                        FriendInfo friend = new FriendInfo();
                        friend.FriendID = user.ID;
                        friend.IsExist = true;
                        friend.Remark = "";
                        friend.UserID = client.Player.PlayerCharacter.ID;
                        friend.Relation = relation;
                        if (db.AddFriends(friend))
                        {
                            client.Player.FriendsAdd(user.ID, relation);
                            pkg.WriteInt(user.ID);
                            pkg.WriteString(user.NickName);
                            pkg.WriteBoolean(user.Sex);
                            pkg.WriteString(user.Style);
                            pkg.WriteString(user.Colors);
                            pkg.WriteString(user.Skin);
                            pkg.WriteInt(user.State == 1 ? 1 : 0);
                            pkg.WriteInt(user.Grade);
                            pkg.WriteInt(user.Hide);
                            pkg.WriteString(user.ConsortiaName);
                            pkg.WriteInt(user.Total);
                            pkg.WriteInt(user.Escape);
                            pkg.WriteInt(user.Win);
                            pkg.WriteInt(user.Offer);
                            pkg.WriteInt(user.Repute);
                            pkg.WriteInt(relation);
                            pkg.WriteString(user.UserName);
                            pkg.WriteInt(user.Nimbus);
                            pkg.WriteInt(user.FightPower);
                            pkg.WriteInt(500);
                            pkg.WriteString("Honor");
                            if (relation != 1 && user.State != 0)
                            {
                                GSPacketIn response = new GSPacketIn((byte)ePackageType.FRIEND_RESPONSE, client.Player.PlayerCharacter.ID);
                                response.WriteInt(user.ID);
                                response.WriteString(client.Player.PlayerCharacter.NickName);
                                if (player != null)
                                    player.Out.SendTCP(response);
                                else
                                    GameServer.Instance.LoginServer.SendPacket(response);
                            }
                            client.Out.SendTCP(pkg);
                        }
                    }
                    else
                    {
                        client.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("FriendAddHandler.Falied"));
                    }
                }
                else
                {
                    client.Out.SendMessage(eMessageType.ERROR, LanguageMgr.GetTranslation("FriendAddHandler.Success"));
                }
            }
            return 0;
        }