Esempio n. 1
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    _mailSender?.Dispose();
                }

                disposedValue = true;
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Dispose of the underlying MailSender when this controller is destroyed.
        /// </summary>
        /// <param name="disposing">Whether we are disposing or not.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (MailSender != null)
                {
                    MailSender.Dispose();
                    MailSender = null;
                }
            }

            base.Dispose(disposing);
        }
Esempio n. 3
0
 public void Dispose()
 {
     _mailer.Dispose();
 }
Esempio n. 4
0
        public void PlayerGMCommand(GPlayer player, Packet packet)
        {
            GameBase   Game;
            MailSender AddMail;
            Channel    PLobby;
            uint       ItemTypeID, Quantity, PlayerConnectionID;
            string     Nick;
            byte       Arg1;

            if (!(player.GetCapability == 4))
            {
                WriteConsole.WriteLine("HandleGMCommands: Player has requested gm command but he is not an admin");
                return;
            }

            if (!packet.ReadUInt16(out ushort CommandId))
            {
                return;
            }

            PLobby = player.Lobby;

            if (PLobby == null)
            {
                return;
            }
            switch ((GM_COMMAND)CommandId)
            {
            case GM_COMMAND.GM_Visibility:     //command /visible [on/off] (Ficar Visivel Ou Invisivel)
            {
                packet.ReadByte(out Arg1);
                switch ((TVISIBLE_ACTION)Arg1)
                {
                case TVISIBLE_ACTION.Enable:             //visibilidade: on
                {
                    player.Visible = 4;
                }
                break;

                case TVISIBLE_ACTION.Disable:            //visibilidade: off
                {
                    player.Visible = 0;
                }
                break;
                }
                PLobby.UpdatePlayerLobbyInfo(player);
                break;
            }

            case GM_COMMAND.Player_Whisper:     //command /whisper  [on/off]
            {
                packet.ReadByte(out Arg1);
                switch ((TWHISPER_ACTION)Arg1)
                {
                case TWHISPER_ACTION.Disable:             //whisper: off
                {
                }
                break;

                case TWHISPER_ACTION.Enable:            //whiper: on
                {
                }
                break;
                }
                player.SendResponse(new byte[] { 0x0F, 0x00 });
            }
            break;

            case GM_COMMAND.Player_Lobby:     //command /TLobby  [on/off]
            {
                packet.ReadByte(out Arg1);
                switch (Arg1)
                {
                case 0:             //lobby: off
                {
                }
                break;

                case 2:            //lobby: on
                {
                }
                break;
                }
                player.SendResponse(new byte[] { 0x0F, 0x00 });
            }
            break;

            case GM_COMMAND.Player_Open:     //command /open [nick]
            {
                packet.ReadPStr(out Nick);
                WriteConsole.WriteLine("test =>" + Nick);
            }
            break;

            case GM_COMMAND.Player_Close:     //command /close [nick]
            {
                packet.ReadPStr(out Nick);
                WriteConsole.WriteLine("test =>" + Nick);
            }
            break;

            case GM_COMMAND.Player_Kick:     //command /kick [nick] [op]
            {
                if (!packet.ReadUInt32(out PlayerConnectionID))
                {
                    return;
                }

                var client = PLobby.GetPlayerByConnectionId(PlayerConnectionID);

                if (client == null)
                {
                    return;
                }

                player.SendResponse(new byte[] { 0x0F, 0x00 });

                client.Close();
            }
            break;

            case GM_COMMAND.Player_Disconnect_By_UID:     //command /discon_uid [uid]
            {
                if (!packet.ReadUInt32(out PlayerConnectionID))
                {
                    return;
                }

                var client = PLobby.GetPlayerByConnectionId(PlayerConnectionID);

                if (client == null)
                {
                    return;
                }

                client.SendResponse(new byte[] { 0x76, 0x02, 0xFA, 0x00, 0x00, 0x00 });

                client.Close();
            }
            break;

            case GM_COMMAND.Player_Change_GameWind:     //Command /wind [spd] [dir]
            {
                packet.ReadByte(out byte WP);

                packet.ReadByte(out byte WD);

                Game = PLobby.GetGameHandle(player);

                if (Game == null)
                {
                    return;
                }

                if (Game != null && Game.GameType != GAME_TYPE.CHAT_ROOM)
                {
                    Game.Send(ShowWind(WP, WD));
                }
            }
            break;

            case GM_COMMAND.Player_Change_GameWeather:     //Command /weather [type] 'fine', 'rain', 'snow', 'cloud' (Chuva, Neve ...)
            {
                packet.ReadByte(out Arg1);

                Game = PLobby.GetGameHandle(player);

                if (Game == null)
                {
                    return;
                }

                Game.Send(ShowWeather(Arg1));
            }
            break;

            case GM_COMMAND.Player_GiveItem:               //giveitem: /giveitem [nick][typeid][num]
            {
                packet.ReadUInt32(out PlayerConnectionID); //meu id de conexão ou do client
                packet.ReadUInt32(out ItemTypeID);         //id do item enviado
                packet.ReadUInt32(out Quantity);           //quantidade de itens enviado

                if (!IffEntry.IsExist(ItemTypeID))
                {
                    return;
                }

                var Client = (GPlayer)(player.Server).GetClientByConnectionId(PlayerConnectionID);

                if (null == Client)
                {
                    return;
                }
                AddMail = new MailSender();

                try
                {
                    AddMail.Sender = "@GM";
                    AddMail.AddText("GM presents you");
                    AddMail.AddItem(ItemTypeID, Quantity, true);
                    // Add to db
                    AddMail.Send(Client.GetUID);
                    Client.SendMailPopup();

                    player.SendResponse(new byte[] { 0x0F, 0x00 });
                }
                finally
                {
                    AddMail.Dispose();
                }
            }
            break;

            case GM_COMMAND.Player_GoldenBell:     //Command goldenbell ID (enviar item para todos da sala)
            {
                //id do item enviado
                if (!packet.ReadUInt32(out ItemTypeID))
                {
                    return;
                }
                //quantidade de itens enviado
                if (!packet.ReadUInt32(out Quantity))
                {
                    return;
                }
                //Checagem do item
                if (!IffEntry.IsExist(ItemTypeID))
                {
                    return;
                }

                Game = PLobby.GetGameHandle(player);

                if (Game == null)
                {
                    return;
                }
                AddMail = new MailSender();

                try
                {
                    foreach (var Client in Game.Players)
                    {
                        AddMail.Sender = "@GM";
                        AddMail.AddText("GM presents you");
                        AddMail.AddItem(ItemTypeID, Quantity, true);
                        // Add to db
                        AddMail.Send(Client.GetUID);
                        Client.SendMailPopup();
                    }
                }
                finally
                {
                    AddMail.Dispose();
                }
            }
            break;

            case GM_COMMAND.HioHoleCupScale:
            {
            }
            break;

            case GM_COMMAND.SetMission:     //Command /setmission [MISSION_NUM]
            {
                packet.ReadByte(out byte MissionID);

                WriteConsole.WriteLine("SetMission => " + MissionID);
            }
            break;

            case GM_COMMAND.MatchMap:    //Command /matchmap [mapcount]
            {
                packet.ReadUInt32(out uint MapCount);

                WriteConsole.WriteLine("MatchMap => " + MapCount);
            }
            break;

            case GM_COMMAND.Notice_Prize:
            {
                //List<TNoticePrize> itens;
                if (!packet.ReadByte(out Arg1))
                {
                    return;
                }
                switch (Arg1)
                {
                case 0:             //lobby: off
                {
                    if (!packet.ReadUInt32(out uint Count))
                    {
                        return;
                    }
                    for (int i = 0; i < Count; i++)
                    {
                        var item = (TNoticePrize)packet.Read(new TNoticePrize());
                    }
                }
                break;

                case 2:            //lobby: on
                {
                }
                break;
                }
                player.SendResponse(new byte[] { 0x0F, 0x00 });
            }
            break;

            default:
            {
                WriteConsole.WriteLine("Command ID UNK => " + CommandId);
                packet.Save();
            }
            break;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Пересылка с почты oit на пользователей Lotus
        /// </summary>
        /// <param name="parameters"></param>
        public void StartMessageOit(ConfigFile.ConfigFile parameters)
        {
            try
            {
                int            count = 0;
                ZipAttachments zip   = new ZipAttachments();
                using (Pop3Client client = new Pop3Client())
                {
                    client.CheckCertificateRevocation = false;
                    client.Connect(parameters.Pop3Address, 995, true);
                    MailSender mail = new MailSender();
                    Loggers.Log4NetLogger.Info(new Exception($"Соединение с сервером eups.tax.nalog.ru установлено (OIT)"));
                    client.Authenticate(parameters.LoginOit, parameters.PasswordOit);
                    Loggers.Log4NetLogger.Info(new Exception($"Пользователь проверен (OIT)"));
                    if (client.IsConnected)
                    {
                        MailLogicLotus mailSave       = new MailLogicLotus();
                        SelectSql      select         = new SelectSql();
                        UserLotus      userSqlDefault = select.FindUserGroup(7);
                        int            messageCount   = client.GetMessageCount();

                        for (int i = 0; i < messageCount; i++)
                        {
                            MimeMessage message             = client.GetMessage(i);
                            var         messageAttaches     = message.Attachments as List <MimeEntity> ?? new List <MimeEntity>();
                            var         messageBodyAttaches = new List <MimeEntity>();
                            messageBodyAttaches.AddRange(message.BodyParts);
                            var calendar = messageBodyAttaches.Where(x => x.ContentType.MimeType == "text/calendar").ToList();
                            var file     = messageBodyAttaches.Where(x =>
                                                                     x.ContentType.MediaType == "image" ||
                                                                     x.ContentType.MediaType == "application").ToList();

                            if (file.Count > 0)
                            {
                                messageAttaches.AddRange(file);
                            }
                            string body;
                            var    isHtmlMime = false;
                            if (string.IsNullOrWhiteSpace(message.TextBody))
                            {
                                body       = message.HtmlBody;
                                isHtmlMime = true;
                            }
                            else
                            {
                                body = message.TextBody;
                            }
                            var date = message.Date;
                            if (date.Date >= DateTime.Now.Date)
                            {
                                if (!mailSave.IsExistsBdMail(message.MessageId))
                                {
                                    if (calendar.Count > 0)
                                    {
                                        var calendarVks = new CalendarVks();
                                        body = calendarVks.CalendarParser(calendar, message);
                                    }
                                    var address    = (MailboxAddress)message.From[0];
                                    var mailSender = address.Address;
                                    var nameFile   = date.ToString("dd.MM.yyyy_HH.mm.ss") + "_" + mailSender.Split('@')[0] + ".zip";
                                    var fullPath   = Path.Combine(parameters.PathSaveArchive, nameFile);
                                    MailLotusOutlookIn mailMessage = new MailLotusOutlookIn()
                                    {
                                        IdMail          = message.MessageId,
                                        MailAdressSend  = parameters.LoginOit,
                                        SubjectMail     = message.Subject,
                                        Body            = body,
                                        MailAdress      = mailSender,
                                        DateInputServer = date.DateTime,
                                        NameFile        = nameFile,
                                        FullPathFile    = fullPath,
                                        FileMail        = zip.StartZipArchive(messageAttaches, fullPath)
                                    };
                                    mailSave.AddModelMailIn(mailMessage);
                                    var mailUsers = mail.FindUserLotusMail(select.FindUserOnUserGroup(userSqlDefault, mailMessage.SubjectMail), "(OIT)");
                                    if (!string.IsNullOrWhiteSpace(message.HtmlBody))
                                    {
                                        var math = Regex.Match(body, @"CN=(.+)МНС");
                                        if (!string.IsNullOrWhiteSpace(math.Value))
                                        {
                                            mailUsers.Add(math.Value);
                                        }
                                    }
                                    if (isHtmlMime)
                                    {
                                        mail.SendMailMimeHtml(mailMessage, mailUsers);
                                    }
                                    else
                                    {
                                        mail.SendMailIn(mailMessage, mailUsers);
                                    }
                                    count++;
                                    Loggers.Log4NetLogger.Info(new Exception($"УН: {mailMessage.IdMail} Дата/Время: {date} От кого: {mailMessage.MailAdress}"));
                                }
                            }
                            else
                            {
                                //Удаление сообщения/письма
                                client.DeleteMessage(i);
                            }
                        }
                        mailSave.Dispose();
                        Loggers.Log4NetLogger.Info(new Exception("Количество пришедшей (OIT) почты:" + count));
                    }
                    mail.Dispose();
                    client.Disconnect(true);
                }
                //Очистить временную папку с файлами
                zip.DropAllFileToPath(parameters.PathSaveArchive);
                foreach (FileInfo file in new DirectoryInfo(parameters.PathSaveArchive).GetFiles())
                {
                    Loggers.Log4NetLogger.Info(new Exception($"Наименование удаленных файлов: {file.FullName}"));
                    file.Delete();
                }
                Loggers.Log4NetLogger.Info(new Exception("Очистили папку от файлов (OIT)!"));
                Loggers.Log4NetLogger.Info(new Exception("Перерыв 5 минут (OIT)"));
            }
            catch (Exception x)
            {
                Loggers.Log4NetLogger.Debug(x);
            }
        }
Esempio n. 6
0
        protected void PlayerGetEXP(GPlayer player, uint Total)
        {
            PangyaBinaryWriter Resp;
            bool       IsUpdate = false;
            MailSender MailSender;

            Resp = new PangyaBinaryWriter();
            if (player.Level >= 70)
            {
                player.SendResponse(new byte[] { 0x0F, 0x00, 0x01, 0x00, 0x00, 0x00 });
                return;
            }
            player.Exp = player.Exp += Total;

            while (true)
            {
                if (player.Level >= 70)
                {
                    break;
                }
                EXPList.TryGetValue(player.Level, out uint EXPTotal);
                if (player.Exp >= EXPTotal)
                {
                    player.Level = Convert.ToByte(player.Level + 1);
                    MailSender   = new MailSender();
                    try
                    {
                        MailSender.Sender = "@GM";
                        MailSender.AddItemLevel((TLEVEL)player.Level);
                        MailSender.Send(player.GetUID);
                    }
                    finally
                    {
                        MailSender.Dispose();
                    }
                    player.Exp = player.Exp -= EXPTotal;
                    IsUpdate   = true;
                }
                else
                {
                    break;
                }
            }
            var _db = new PangyaEntities();

            try
            {
                if (IsUpdate)
                {
                    var table1 = $"UPDATE Pangya_User_Statistics SET Game_Point = '{player.Exp}', Game_Level = '{player.Level}'  WHERE UID = '{player.GetUID}'";
                    _db.Database.SqlQuery <PangyaEntities>(table1).FirstOrDefault();
                    player.SendLevelUp();
                }
            }
            finally
            {
                if (Resp != null)
                {
                    Resp.Dispose();
                }
                else if (_db != null)
                {
                    _db.Dispose();
                }
            }

            player.LoadStatistic();
        }
Esempio n. 7
0
        /// <summary>
        /// Отправка писем абоненту внешней почты
        /// </summary>
        /// <param name="parameters">Параметры конфигурации</param>
        public void SendSmtpMessage(ConfigFile.ConfigFile parameters)
        {
            try
            {
                Mail = new MailSender();
                ZipAttachments zipAttach = new ZipAttachments();
                MailLogicLotus mailSave  = new MailLogicLotus();
                var            dbSend    = Mail.SendMailOut(parameters.PathSaveArchive);
                foreach (var mailLotusOutlookOut in dbSend)
                {
                    //Сначала манипуляции с файлами и архивами а потом отправка

                    var builder = new BodyBuilder()
                    {
                        TextBody = mailLotusOutlookOut.Body
                    };
                    if (mailLotusOutlookOut.FullPathListFile != null)
                    {
                        foreach (var fullFileName in mailLotusOutlookOut.FullPathListFile.Split(';'))
                        {
                            builder.Attachments.Add(fullFileName);
                        }
                        var nameFile    = DateTime.Today.ToString("dd.MM.yyyy_HH.mm.ss") + ".zip";
                        var fullPathZip = Path.Combine(parameters.PathSaveArchive, nameFile);
                        mailLotusOutlookOut.FileMailZip = zipAttach.StartZipArchiveOut(mailLotusOutlookOut.FullPathListFile.Split(';'), fullPathZip);
                        mailLotusOutlookOut.NameFileZip = nameFile;
                    }
                    //Проверка почты
                    var user = new List <string>()
                    {
                        mailLotusOutlookOut.MailAdressIn
                    };
                    var arrayMail = MailArraySubject(mailLotusOutlookOut.MailAdressOut);
                    if (arrayMail.Length > 0)
                    {
                        mailLotusOutlookOut.ErrorMail = $"Письмо отправлено адресатам {string.Join("/", arrayMail)}";
                        foreach (var mail in arrayMail)
                        {
                            MimeMessage mailToClient = new MimeMessage();
                            mailToClient.To.Add(new MailboxAddress(mail));
                            mailToClient.Subject = string.IsNullOrWhiteSpace(mailLotusOutlookOut.SubjectMail) ? "" : mailLotusOutlookOut.SubjectMail;
                            mailToClient.From.Add(new MailboxAddress(mailLotusOutlookOut.MailAdressIn, parameters.LoginR7751)); //Сюда идентификатор
                            mailToClient.Headers[HeaderId.MessageId]                 = mailToClient.MessageId;
                            mailToClient.Headers[HeaderId.ResentMessageId]           = mailToClient.MessageId;
                            mailToClient.Headers[HeaderId.DispositionNotificationTo] = parameters.LoginR7751;
                            mailToClient.Headers[HeaderId.ReturnReceiptTo]           = parameters.LoginR7751;
                            mailToClient.Body = builder.ToMessageBody();
                            try
                            {
                                using (var smtp = new SmtpCustomClient.SmtpCustomClient())
                                {
                                    smtp.DeliveryStatusNotificationType = DeliveryStatusNotificationType.Full;
                                    smtp.CheckCertificateRevocation     = false;
                                    smtp.Connect(parameters.Pop3Address, 465, true);
                                    smtp.Authenticate(parameters.LoginR7751, parameters.PasswordR7751);
                                    smtp.Send(mailToClient);
                                    smtp.Disconnect(true);
                                }
                                Loggers.Log4NetLogger.Info(new Exception($"Отправка письма {mailLotusOutlookOut.IdMail} на адрес {mail}"));
                            }
                            catch (Exception ex)
                            {
                                Loggers.Log4NetLogger.Error(ex);
                                mailLotusOutlookOut.ErrorMail = $"Письмо не отправлено адресату возникли ошибки во время отправки";
                            }
                        }
                        Mail.SendMailAutoOutput(user, $"Отправка писем произведена!!!", $"Адреса участники рассылки \r\n {string.Join("\r\n", arrayMail)}");
                    }
                    else
                    {
                        Mail.SendMailAutoOutput(user, $"Отправка писем на адрес(а) не возможна {mailLotusOutlookOut.MailAdressOut} !!!", $"Ошибка почты {mailLotusOutlookOut.MailAdressOut} !!!");
                        mailLotusOutlookOut.ErrorMail = $"Почтовый ящик(и) не прошел(и) проверку отправка не возможна!";
                        Loggers.Log4NetLogger.Error(new Exception($"Отправка письма {mailLotusOutlookOut.IdMail} не прошла проверку внешних адресов"));
                    }
                    mailSave.AddModelMailOut(mailLotusOutlookOut);
                }
                //Очистить временную папку с файлами
                zipAttach.DropAllFileToPath(parameters.PathSaveArchive);
                Loggers.Log4NetLogger.Info(new Exception("Отправка почты внешнем абонентам закончена!"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            finally
            {
                Mail.Dispose();
            }
        }