Ejemplo n.º 1
0
 /// <summary>
 /// Save the type file but only if has been loaded before
 /// </summary>
 private void SaveTypeFile()
 {
     if (m_TypeFile != null)
     {
         // Replace value
         m_TypeFile = Regex.Replace(m_TypeFile, "Language[ ]{0,1}=[ ]{0,1}[\"]{0,1}([a-zA-Z]*)[\"]{0,1}", "Language = \"" + m_Language + "\"");
         // Import to Pk2
         if (Pk2Writer.Initialize("GFXFileManager.dll"))
         {
             if (Pk2Writer.Open(LauncherSettings.PATH_PK2_MEDIA, LauncherSettings.CLIENT_BLOWFISH_KEY))
             {
                 // Create a temporary file
                 if (!Directory.Exists("Temp"))
                 {
                     Directory.CreateDirectory("Temp");
                 }
                 File.WriteAllText("Temp\\Type.txt", m_TypeFile);
                 // Edit Pk2
                 Pk2Writer.ImportFile("Type.txt", "Temp\\Type.txt");
                 // Delete temporary file
                 File.Delete("Temp\\Type.txt");
                 // Close Pk2
                 Pk2Writer.Close();
                 Pk2Writer.Deinitialize();
             }
         }
     }
 }
Ejemplo n.º 2
0
        public static void Server_PatchResponse(Packet p, Session s)
        {
            System.Diagnostics.Debug.WriteLine("Server_PatchResponse");
            LauncherViewModel.Instance.IsCheckingUpdates = false;

            // Analyze the patch
            switch (p.ReadByte())
            {
            case 1:
                LauncherViewModel.Instance.CanStartGame = true;
                break;

            case 2:
                byte errorCode = p.ReadByte();
                switch (errorCode)
                {
                case 2:
                {
                    string DownloadServerIP   = p.ReadAscii();
                    ushort DownloadServerPort = p.ReadUShort();
                    DownloadModule.DownloadVersion = p.ReadUInt();

                    System.Diagnostics.Debug.WriteLine("Version outdate. New version available (v" + DownloadModule.DownloadVersion + ")");
                    ulong bytesToDownload = 0;

                    while (p.ReadByte() == 1)
                    {
                        FileEntry file = new FileEntry()
                        {
                            ID          = p.ReadUInt(),
                            Name        = p.ReadAscii(),
                            Path        = p.ReadAscii(),
                            Size        = p.ReadUInt(),
                            ImportToPk2 = p.ReadByte() == 1
                        };

                        DownloadModule.DownloadFiles.Add(file);

                        bytesToDownload += file.Size;
                    }

                    // Set progress bar values
                    LauncherViewModel.Instance.UpdatingBytesMaxDownloading = bytesToDownload;
                    LauncherViewModel.Instance.UpdatingBytesDownloading    = 0;

                    // Start downloader protocol
                    if (DownloadModule.DownloadFiles.Count > 0)
                    {
                        // Try to load the GFXFileManager
                        if (Pk2Writer.Initialize("GFXFileManager.dll"))
                        {
                            // Start downloading patch
                            LauncherViewModel.Instance.IsUpdating = true;
                            System.Diagnostics.Debug.WriteLine("Downloading updates...");

                            Session downloaderSession = new Session();
                            downloaderSession.AddHandler(Opcode.GLOBAL_IDENTIFICATION, new PacketHandler(Server_GlobalIdentification));
                            downloaderSession.AddHandler(DownloadModule.Opcode.SERVER_READY, new PacketHandler(DownloadModule.Server_Ready));
                            downloaderSession.AddHandler(DownloadModule.Opcode.SERVER_FILE_CHUNK, new PacketHandler(DownloadModule.Server_FileChunk));
                            downloaderSession.AddHandler(DownloadModule.Opcode.SERVER_FILE_COMPLETED, new PacketHandler(DownloadModule.Server_FileCompleted));

                            downloaderSession.Disconnect += new System.EventHandler((_Session, _Event) => {
                                    System.Diagnostics.Debug.WriteLine("Download: Session disconnected");
                                });

                            System.Threading.Tasks.Task.Run(() => downloaderSession.Start(DownloadServerIP, DownloadServerPort, 10000));
                        }
                        else
                        {
                            LauncherViewModel.Instance.ShowMessage("GFXFileManager not found!");
                        }
                    }
                }
                break;

                case 4:
                    LauncherViewModel.Instance.ShowMessage(LauncherSettings.MSG_PATCH_UNABLE);
                    break;

                case 5:
                    LauncherViewModel.Instance.ShowMessage(LauncherSettings.MSG_PATCH_TOO_OLD);
                    break;

                case 1:
                    LauncherViewModel.Instance.ShowMessage(LauncherSettings.MSG_PATCH_TOO_NEW);
                    break;

                default:
                    LauncherViewModel.Instance.ShowMessage("Patch Error: [" + errorCode + "]");
                    break;
                }
                break;
            }

            // Request shard list just for fun c:
            System.Diagnostics.Debug.WriteLine("CLIENT_SHARD_LIST_REQUEST");
            s.Send(new Packet(Opcode.CLIENT_SHARD_LIST_REQUEST, true));
            s.Send(new Packet(Opcode.CLIENT_SHARD_LIST_PING_REQUEST, true)); // Not even sure what is this..
            // Request notice
            System.Diagnostics.Debug.WriteLine("CLIENT_WEB_NOTICE_REQUEST");
            Packet packet = new Packet(Opcode.CLIENT_WEB_NOTICE_REQUEST);

            packet.WriteByte(LauncherViewModel.Instance.Locale);
            s.Send(packet);
        }