Exemplo n.º 1
0
        public static string SendMail(string charactername, string itemtospawn, int count, string mailcontent, string mailsender, string staffname = "Iset")
        {
            List <string> mailToList = null;
            string        retmsg     = "The item has been sent to ";

            if (charactername == "all")
            {
                mailToList = UserFunctions.playerList("id", "all");
                if (mailToList.Count() <= 0)
                {
                    return("error getting players!");
                }
                retmsg = retmsg + "all players (" + mailToList.Count().ToString() + ")";
            }
            else if (charactername == "allonline")
            {
                mailToList = UserFunctions.playerList("id", "online");
                if (mailToList.Count() <= 0)
                {
                    return("There are no players online!");
                }
                retmsg = retmsg + "all online players (" + mailToList.Count().ToString() + ")";
            }
            else
            {
                mailToList = new List <string>();
                mailToList.Add(UserFunctions.getCharacterIdFromName(charactername));
                retmsg = retmsg + charactername;
            }
            string itemCode = itemtospawn;

            if (itemCode != "gold")
            {
                if (itemCode.Contains("COMBINATION:"))
                {
                    if (!itemCode.Contains("ANTIBIND"))
                    {
                        itemCode = itemCode.Replace("]", ",") + "ANTIBIND:3]";
                    }
                    if (!itemCode.Contains("RESTORED"))
                    {
                        itemCode = itemCode.Replace("]", ",") + "RESTORED:1]";
                    }
                }
                else
                {
                    itemCode = itemCode + "[ANTIBIND:3][RESTORED:1]";
                }
            }
            try
            {
                foreach (string recipient in mailToList)
                {
                    using (conn = new SqlConnection())
                    {
                        conn.ConnectionString = "Server=" + ini.IniReadValue("mssql", "ipandport") + "; Database=heroes; User Id=" + ini.IniReadValue("mssql", "username") + "; password="******"mssql", "password");
                        string     oString = "INSERT INTO QueuedItem (CID, ItemClassEx, IsCharacterBinded, Count, MailContent, MailTitle, Color1, Color2, Color3, ReducedDurability, MaxDurabilityBonus)  " + "VALUES (@CID, @ItemClassEx, 1, @Count, @MailContent, @MailTitle,-1 ,-1 ,-1 ,0 ,0)";
                        SqlCommand oCmd    = new SqlCommand(oString, conn);
                        oCmd.Parameters.AddWithValue("@CID", recipient);
                        oCmd.Parameters.AddWithValue("@ItemClassEx", itemCode);
                        oCmd.Parameters.AddWithValue("@Count", count);
                        oCmd.Parameters.AddWithValue("@MailContent", mailcontent);
                        oCmd.Parameters.AddWithValue("@MailTitle", mailsender);
                        conn.Open();
                        oCmd.ExecuteNonQuery();
                        conn.Close();
                    }
                    logSpawn(staffname.Replace("()", ""), recipient, charactername, itemCode, count.ToString());
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            retmsg = retmsg + "! They will need to relog or run a quest to see the mail!";
            return(retmsg);
        }