Пример #1
0
 /// <summary>
 /// Adds a chat macro to the account.
 /// </summary>
 /// <param name="character"></param>
 public void AddChatMacro(ChatMacro macro)
 {
     lock (_chatMacros)
     {
         var oldMacro = _chatMacros.FirstOrDefault(x => x.Index == macro.Index);
         if (oldMacro == null)
         {
             _chatMacros.Add(macro);
         }
         else
         {
             oldMacro.Update(macro.Message, macro.Pose);
         }
     }
 }
Пример #2
0
        /// <summary>
        /// Loads default chat macros from data.
        /// </summary>
        private void LoadDefaultChatMacros()
        {
            // Get all and add a maximum of 10
            var macroData = ChannelServer.Instance.Data.ChatMacroDb.OrderBy(x => x.Id);

            var i = 1;

            foreach (var data in macroData)
            {
                var macro = new ChatMacro(i, data.Text, data.Pose);
                this.AddChatMacro(macro);

                if (++i > 10)
                {
                    break;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Adds a chat macro to the account.
        /// </summary>
        /// <param name="macro"></param>
        public virtual void AddChatMacro(ChatMacro macro)
        {
            lock (this._key)
            {
                if (macro.Slot > 10)
                {
                    return;
                }

                var old = this.ChatMacros.FirstOrDefault(x => x.Slot == macro.Slot);
                if (old != null)
                {
                    old.Update(macro.Message, macro.Pose);
                    return;
                }

                this.ChatMacros.Add(macro);
            }
        }
Пример #4
0
        /// <summary>
        /// Loads chat macros from the database.
        /// </summary>
        /// <param name="account"></param>
        private void LoadChatMacros(Account account)
        {
            using (var conn = this.GetConnection())
                using (var mc = new MySqlCommand("SELECT * FROM `chatMacros` WHERE `accountId` = @accountId ORDER BY `index` DESC", conn))
                {
                    mc.Parameters.AddWithValue("@accountId", account.Id);

                    using (var reader = mc.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var index   = reader.GetInt32("index");
                            var message = reader.GetString("message");
                            var pose    = reader.GetInt32("pose");

                            var macro = new ChatMacro(index, message, pose);
                            account.AddChatMacro(macro);
                        }
                    }
                }
        }