예제 #1
0
        public static void Handle(Player account, byte[] buffer)
        {
            MsgRemoteMaintenance packet = buffer;

            packet.Success = true;
            switch (packet.Type)
            {
            case MsgRemoteMaintenanceType.StartBackup:
                //if (!YiCore.BackupInProgress)
                //    Db.Backup();
                //else
                //    packet.Success = false;
                break;

            case MsgRemoteMaintenanceType.OptimizeMemory:
                YiCore.CompactLoh();
                break;

            case MsgRemoteMaintenanceType.Shutdown:
                packet.Success = false;
                break;

            case MsgRemoteMaintenanceType.DownloadDatabase:
                Task.Run(() =>
                {
                    YiCore.BackupInProgress = true;
                    using (var reader = new FileStream("Db.json", FileMode.Open))
                    {
                        while (reader.Position < reader.Length)
                        {
                            var filebuffer = new byte[1490];
                            var bytes      = reader.Read(filebuffer, 0, filebuffer.Length);

                            var data = new byte[bytes];

                            Buffer.BlockCopy(filebuffer, 0, data, 0, bytes);
                            if (bytes < 1490)
                            {
                                Debugger.Break();
                            }
                            account.SendRaw(MsgFileTransfer.Create(data, (int)reader.Length));
                            Thread.Sleep(1);
                        }
                    }
                    account.SendRaw(MsgFileTransfer.Create(new byte[1], 0));
                    YiCore.BackupInProgress = true;
                });
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            account.SendRaw(packet);
        }
예제 #2
0
        public static unsafe byte[] Create(byte[] chunk, int totalLen)
        {
            var packet = new MsgFileTransfer
            {
                Size      = (ushort)(chunk.Length + 8),
                Id        = 5,
                TotalLen  = totalLen,
                ChunkSize = chunk.Length
            };

            for (var i = 0; i < 1490; i++)
            {
                packet.Chunk[i] = chunk[i];
            }
            return(packet);
        }