Exemplo n.º 1
0
        internal void SC_SendFile(Client client, string filePath)
        {
            int chunkSize = 64000;

            string fileName = Path.GetFileName(filePath);

            byte[] buffer = (File.Exists(filePath)) ? File.ReadAllBytes(filePath) : null;
            if (buffer.Length > 0)
            {
                // Just incase file is smaller than initial chunkSize
                chunkSize = Math.Min(64000, buffer.Length);

                SC_SendFileInfo(client, buffer.Length);

                int i = 0;

                while (true)
                {
                    if (i == buffer.Length)
                    {
                        break;
                    }

                    PacketStream fStream = new PacketStream(0x0042);

                    fStream.Flush();

                    fStream.WriteInt32(chunkSize);
                    fStream.WriteInt32(i);

                    byte[] tempBuffer = new byte[chunkSize];
                    Array.Copy(buffer, i, tempBuffer, 0, chunkSize);

                    fStream.WriteBytes(tempBuffer);

                    ClientManager.Instance.Send(client, fStream);

                    // Increase the index position
                    i = i + chunkSize;

                    // Refresh the chunkSize
                    chunkSize = Math.Min(64000, buffer.Length - i);
                }

                SC_SendFileEOF(client, fileName);
            }
        }
Exemplo n.º 2
0
        internal void SU_SendLauncher(Client client, string filePath)
        {
            int chunkSize = 64000;

            byte[] buffer = File.ReadAllBytes(filePath);
            if (buffer.Length > 0)
            {
                // Just incase file is smaller than initial chunkSize
                chunkSize = Math.Min(64000, buffer.Length);

                int i = 0;

                while (true)
                {
                    if (i == buffer.Length)
                    {
                        break;
                    }

                    PacketStream fStream = new PacketStream(0x1101);

                    fStream.Flush();

                    fStream.WriteInt32(chunkSize);
                    fStream.WriteInt32(i);

                    byte[] tempBuffer = new byte[chunkSize];
                    Array.Copy(buffer, i, tempBuffer, 0, chunkSize);

                    fStream.WriteBytes(tempBuffer);

                    ClientManager.Instance.Send(client, fStream);

                    // Increase the index position
                    i = i + chunkSize;

                    // Refresh the chunkSize
                    chunkSize = Math.Min(64000, buffer.Length - i);
                }

                SU_SendLauncherEOF(client);
            }
        }