Exemplo n.º 1
0
 public void ReadPacket(PacketReader reader)
 {
     FailureReason = (LoginFailureReason)reader.ReadInt32();
     var fingerprintJson = reader.ReadString();
     if (fingerprintJson != null)
         Fingerprint = new Fingerprint(fingerprintJson);
     HostName = reader.ReadString();
     RackcdnUrl = reader.ReadString();
     iTunesUrl = reader.ReadString();
     Unknown1 = reader.ReadString();
     Unknown2 = reader.ReadString();
     Unknown3 = (byte)reader.ReadByte();
     CompressedFingerprintJson = reader.ReadByteArray();
     Unknown4 = reader.ReadString();
 }
Exemplo n.º 2
0
        public CoCClient()
        {
            Fingerprint = new Fingerprint();
            Home = new Village();
            Avatar = new Avatar();
            Connection = new Socket(SocketType.Stream, ProtocolType.Tcp);
            PacketHandlers = new Dictionary<ushort, PacketHandler>();
            KeepAliveManager = new KeepAliveManager(this);
            PacketLogger = new PacketLogger()
            {
                LogConsole = false
            };

            LoginPacketHandlers.RegisterLoginPacketHandlers(this);
            InGamePacketHandlers.RegisterInGamePacketHandler(this);
        }
Exemplo n.º 3
0
        public CoCClient()
        {
            Fingerprint = new Fingerprint();
            Home = new Village();
            Avatar = new Avatar();
            Connection = new Socket(SocketType.Stream, ProtocolType.Tcp);
            DefaultPacketHandlers = new Dictionary<ushort, PacketHandler>();
            PacketHandlers = new Dictionary<ushort, PacketHandler>();
            KeepAliveManager = new KeepAliveManager(this);
            PacketLog = new PacketLog("packets.log")
            {
                AutoSave = true
            };
            PluginManager = new PluginManager(this);

            LoginPacketHandlers.RegisterLoginPacketHandlers(this);
            InGamePacketHandlers.RegisterInGamePacketHandler(this);
            PluginManager.LoadPlugins();
            PluginManager.EnablePlugins();
        }
        private void InternalDownloadAssets(Uri remoteRootPath, Fingerprint fingerprint, string dstDir, bool checkHash)
        {
            //var localRootDir = Path.Combine(dstDir, _masterHash);
            var localRootDir = dstDir;

            // Create a new directory called as the value of _masterHash.
            if (!Directory.Exists(localRootDir))
            {
                Directory.CreateDirectory(localRootDir);
            }

            for (int i = 0; i < fingerprint.Count; i++)
            {
                var file = fingerprint[i];

                // Root directory's name of the file's path.
                var dirName = Path.GetDirectoryName(file.Path);
                // Local directory of the file's path
                var localDirPath = Path.Combine(localRootDir, dirName);

                // Make sure the directory exists first.
                if (!Directory.Exists(localDirPath))
                {
                    Directory.CreateDirectory(localDirPath);
                }

                var localFilePath = Path.Combine(localRootDir, file.Path);

                // Compute the SHA1 hashes of the files and check if the new files needs to downloaded
                if (checkHash)
                {
                    // If we're checking the SHA1 and if a file already exists with the same name/path.
                    if (File.Exists(localFilePath))
                    {
                        var existingFileBytes = File.ReadAllBytes(localFilePath);
                        var existingFileHash  = InternalUtils.BytesToString(_sha1.ComputeHash(existingFileBytes));

                        // If the existing file have the same SHA1 as the one in the fingerprint
                        // we continue and ignore it.
                        if (existingFileHash == file.Hash)
                        {
                            var e = new AssetDownloadProgressChangedEventArgs()
                            {
                                DownloadedCount    = i + 1,
                                FileDownloaded     = file,
                                WasDownloaded      = false,
                                NextDownload       = fingerprint[i],
                                ProgressPercentage = ((i + 1) / (double)fingerprint.Count) * 100,
                            };
                            OnDownloadProgressChanged(e);
                            continue;
                        }
                    }
                }

                var fileBytes = DownloadFile(remoteRootPath, file.Path);
                var args      = new AssetDownloadProgressChangedEventArgs()
                {
                    DownloadedCount    = i + 1,
                    FileDownloaded     = file,
                    WasDownloaded      = true,
                    NextDownload       = fingerprint[i],
                    ProgressPercentage = ((i + 1) / (double)fingerprint.Count) * 100,
                };
                OnDownloadProgressChanged(args);

                File.WriteAllBytes(localFilePath, fileBytes);
            }

            OnDownloadCompleted(new AssetDownloadCompletedEventArgs());
        }
        /// <summary>
        /// Returns a <see cref="Fingerprint"/> that will be deserialize from the specified
        /// JSON string.
        /// </summary>
        /// <param name="value">JSON string that represents the <see cref="Fingerprint"/>.</param>
        /// <returns>A <see cref="Fingerprint"/> object that is deserialized from the specified JSON string.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="value"/> is empty.</exception>
        public static Fingerprint FromJson(string value)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                throw new ArgumentNullException("value");
            }

            var fingerprint      = new Fingerprint();
            var fingerprintFiles = new List <FingerprintFile>();
            var file             = new FingerprintFile();

            // Determines if we're inside the "files" array.
            var inFilesArray = false;

            var txtReader = new StringReader(value);

            using (var jsonReader = new JsonTextReader(txtReader))
            {
                // Keep on reading the next JSON token.
                while (jsonReader.Read())
                {
                    switch (jsonReader.TokenType)
                    {
                    // If we hit a token of type PropertyName we read its value
                    // and determine where to assign it.
                    case JsonToken.PropertyName:
                        var propertyName = (string)jsonReader.Value;
                        switch (propertyName)
                        {
                        case "files":
                            if (jsonReader.Read())
                            {
                                if (jsonReader.TokenType != JsonToken.StartArray)
                                {
                                    // Throw an exception here maybe?
                                }
                                else
                                {
                                    inFilesArray = true;
                                }
                            }
                            else
                            {
                                // Throw an exception here maybe?
                                break;
                            }
                            break;

                        case "file":
                            if (!inFilesArray)
                            {
                                break;
                            }

                            file.Path = jsonReader.ReadAsString();
                            break;

                        case "sha":
                            // Convert the "sha" string into a byte array.
                            var hash = jsonReader.ReadAsString();

                            // If we're inside the "files" array assign it to the
                            // FingerprintFile.
                            if (inFilesArray)
                            {
                                file.Hash = hash;
                            }
                            // If not assign it to the Fingerprint itself.
                            else
                            {
                                fingerprint.MasterHash = hash;
                            }
                            break;

                        case "version":
                            fingerprint.Version = jsonReader.ReadAsString();
                            break;
                        }
                        break;

                    case JsonToken.EndObject:
                        // Reset the file object when we hit EndObject token
                        // to allow new creation of FingerprintFile.
                        if (inFilesArray)
                        {
                            fingerprintFiles.Add(file);
                            file = new FingerprintFile();
                        }
                        break;

                    case JsonToken.EndArray:
                        inFilesArray = false;
                        break;
                    }
                }
            }

            fingerprint._files = fingerprintFiles;
            return(fingerprint);
        }