Esempio n. 1
0
        public void RequestPatches(AutoUpdateRequestType mode, PatchServer server)
        {
            if (!Kernel.HasAgreedPrivacy)
            {
                NoDownload(UpdateReturnMessage.PrivacyNotAccepted, false);
                return;
            }

            MsgRequestInfo msg = new MsgRequestInfo
            {
                Mode = mode
            };

            switch (mode)
            {
            case AutoUpdateRequestType.CheckForLauncherUpdates:
                msg.CurrentVersion = m_usClientVersion;
                break;

            case AutoUpdateRequestType.CheckForGameUpdates:
                msg.CurrentVersion = m_usCurrentVersion;
                break;
            }

            server.Send(msg);
        }
        public void ProcessDownloadInfo(PatchServer server, byte[] buffer)
        {
            MsgDownloadInfo msg = new MsgDownloadInfo(buffer);

            switch (msg.Mode)
            {
            case UpdateDownloadType.UpdaterPatch:
                if (Kernel.Stage != AutoPatchStage.WaitingForUpdaterPatchs)
                {
                    return;
                }

                Program.FrmMain.PrepareToDownload(msg.Mode, msg.GetStrings(), server);
                break;

            case UpdateDownloadType.GameClientPatch:
                if (Kernel.Stage != AutoPatchStage.WaitingForGamePatchs)
                {
                    return;
                }

                Program.FrmMain.PrepareToDownload(msg.Mode, msg.GetStrings(), server);
                break;
            }
        }
        public void ProcessRequestInfo(PatchServer server, byte[] buffer)
        {
            MsgRequestInfo msg = new MsgRequestInfo(buffer);

            switch (msg.Mode)
            {
            case AutoUpdateRequestType.LauncherUpdatesOk:
                Kernel.Stage = AutoPatchStage.WaitingForGamePatchs;
                Program.FrmMain.RequestPatches(AutoUpdateRequestType.CheckForGameUpdates, server);
                break;

            case AutoUpdateRequestType.GameUpdatesOk:
                Program.FrmMain.NoDownload(UpdateReturnMessage.Success);
                break;

            case AutoUpdateRequestType.CheckForGameUpdates:
            case AutoUpdateRequestType.CheckForLauncherUpdates:
                if (msg.CurrentVersion == 0)
                {
                    Program.FrmMain.NoDownload(UpdateReturnMessage.DoubleClient, false);
                }
                else
                {
                    Program.FrmMain.NoDownload(UpdateReturnMessage.LoginNotAllowed, false);
                }
                break;
            }
        }
Esempio n. 4
0
 private bool Connect(string ip, string port)
 {
     try
     {
         m_pSocket = new ClientSocket();
         m_pSocket.ConnectTo(ip, int.Parse(port));
         m_patchServer = new PatchServer(m_pSocket, m_pSocket);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 5
0
        public void ProcessPacket(PatchServer server, byte[] buffer)
        {
            if (InvokeRequired)
            {
                Invoke(new Action <PatchServer, byte[]>(ProcessPacket), server, buffer);
                return;
            }

            if (buffer.Length < 4)
            {
                return;
            }

            PacketType type = (PacketType)BitConverter.ToUInt32(buffer, 2);

            switch (type)
            {
            case PacketType.MsgClientInfo:
                MsgClientInfo msg  = new MsgClientInfo(buffer);
                List <string> list = msg.GetStrings();
                if (list.Count <= 0)
                {
                    Kernel.HasAgreedPrivacy = true;
                    RequestPatches(AutoUpdateRequestType.CheckForLauncherUpdates, server);
                    return;
                }

                string strPrivacyDate = m_ifConfig.GetEntryValue("Config", "TermsOfPrivacy").ToString();
                if (!DateTime.TryParse(strPrivacyDate, out DateTime date) ||
                    !DateTime.TryParse(list[0], out DateTime serverTime) ||
                    serverTime > date)
                {
                    if (new FrmTermsOfPrivacy(m_szPrivacyTerms).ShowDialog(this) != DialogResult.OK)
                    {
                        NoDownload(UpdateReturnMessage.PrivacyNotAccepted, false);
                        return;
                    }

                    m_ifConfig.SetValue("Config", "TermsOfPrivacy", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                }

                Kernel.HasAgreedPrivacy = true;
                Kernel.Stage            = AutoPatchStage.WaitingForUpdaterPatchs;
                RequestPatches(AutoUpdateRequestType.CheckForLauncherUpdates, server);
                break;
            }
        }
Esempio n. 6
0
        /// <summary>
        ///     This method is invoked when the client has been approved of connecting to the server. The client should
        ///     be constructed in this method, and cipher algorithms should be initialized. If any packets need to be
        ///     sent in the connection state, they should be sent here.
        /// </summary>
        /// <param name="pState">Represents the status of an asynchronous operation.</param>
        public void Connect(AsynchronousState pState)
        {
            var pServer = new PatchServer(this, pState.Socket);

            pState.Client = pServer;

            Program.FrmMain.Edit(Program.FrmMain.lblCenterStatus, LabelAsyncOperation.Text, LanguageManager.GetString("StrCheckingPrivacyTerms"));

            MsgClientInfo msg = new MsgClientInfo();

            msg.MacAddress = Program.FrmMain.GetMacAddress();
            msg.Append(SystemProperties.GetObjects(MsgClientInfo.OPERATING_SYSTEM, MsgClientInfo.OperatingSystem).Values.ToArray());
            msg.Append(SystemProperties.GetObjects(MsgClientInfo.BASE_BOARD, MsgClientInfo.BaseBoard).Values.ToArray());
            msg.Append(SystemProperties.GetObjects(MsgClientInfo.PROCESSOR, MsgClientInfo.Processor).Values.ToArray());
            msg.Append(SystemProperties.GetObjects(MsgClientInfo.PHYSICAL_MEMORY, MsgClientInfo.PhysicalMemory).Values.ToArray());
            msg.Append(SystemProperties.GetObjects(MsgClientInfo.VIDEO_CONTROLLER, MsgClientInfo.VideoController).Values.ToArray());
            pServer.Send(msg);
        }
Esempio n. 7
0
        public void PrepareToDownload(UpdateDownloadType type, List <string> strs, PatchServer server)
        {
            HideDownloadBar();
            if (strs.Count < 2)
            {
                if (type == UpdateDownloadType.UpdaterPatch)
                {
                    MsgRequestInfo mri = new MsgRequestInfo();
                    mri.CurrentVersion = m_usCurrentVersion;
                    server.Send(mri);

                    Kernel.Stage = AutoPatchStage.WaitingForGamePatchs;
                    Edit(lblCenterStatus, LabelAsyncOperation.Text,
                         LanguageManager.GetString("StrLookingForGameUpdates"));
                }
                else
                {
                    NoDownload(UpdateReturnMessage.Success);
                }

                return;
            }

            m_actuallyDownloading = type;
            Edit(lblCenterStatus, LabelAsyncOperation.Text, LanguageManager.GetString("StrCalculatingDownloadSize"));

            string domain = strs[0];

            if (!domain.EndsWith("/"))
            {
                domain += "/";
            }

            m_nTotalDownloadSize  = 0;
            m_nCurrentDownloading = 0;
            m_nTotalDownloads     = 0;

            Edit(lblDownloadStatus, LabelAsyncOperation.Text,
                 LanguageManager.GetString("StrLabelCalculatingDownloadAmount", m_nTotalDownloads,
                                           ParseFileSize(m_nTotalDownloadSize)));
            Edit(lblDownloadStatus, LabelAsyncOperation.Visible, true);

            for (int i = 1; i < strs.Count; i++)
            {
                if (!strs[i].EndsWith(".exe"))
                {
                    strs[i] += ".exe";
                }

                if (!RemoteFileExists($"{domain}{strs[i]}"))
                {
                    continue;
                }

                m_nTotalDownloadSize += FetchFileSize($"{domain}{strs[i]}");
                m_nTotalDownloads++;
                m_queueNextDownloads.Enqueue($"{domain}{strs[i]}");
                Edit(lblDownloadStatus, LabelAsyncOperation.Text,
                     LanguageManager.GetString("StrLabelCalculatingDownloadAmount", m_nTotalDownloads,
                                               ParseFileSize(m_nTotalDownloadSize)));
            }

            Edit(lblDownloadStatus, LabelAsyncOperation.Text,
                 LanguageManager.GetString("StrLabelCalculatingDownloadAmount", m_nTotalDownloads,
                                           ParseFileSize(m_nTotalDownloadSize)));
            Edit(pbDownload, ProgressBarAsyncOperation.Value, 0);
            Edit(pbDownload, ProgressBarAsyncOperation.Max, m_nTotalDownloadSize);
            ShowDownloadBar();
            StartDownloading();
        }
 public void ProcessClientInfo(PatchServer server, byte[] buffer)
 {
     Program.FrmMain.ProcessPacket(server, buffer);
 }