Beispiel #1
0
        public override void Process(NPHandler client)
        {
            var fileName = Message.fileName;
            var npid     = (long)Message.npid;
            var fsFile   = StorageUtils.GetFilename(fileName, npid);

            if (!File.Exists(fsFile))
            {
                fsFile = "data/priv/" + npid.ToString("x16") + "/" + fileName.Replace("\\", "/").Replace("/", "");
            }

            _client   = client;
            _fileName = fileName;
            _npid     = npid;

            if (!client.Authenticated)
            {
                ReplyWithError(2);
                return;
            }

            if (client.NPID != (long)npid)
            {
                ReplyWithError(2);
                return;
            }

            Log.Info("Got a request for file " + fileName + " for user " + npid.ToString("x16"));

            if (File.Exists(fsFile))
            {
                try
                {
                    var stream = File.OpenRead(fsFile);

                    _readBuffer = new byte[(int)stream.Length];
                    stream.BeginRead(_readBuffer, 0, _readBuffer.Length, ReadCompleted, stream);
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                    ReplyWithError(3);
                }
            }
            else
            {
                ReplyWithError(1);
            }
        }
Beispiel #2
0
        public string GetStats(string userID, string titleID)
        {
            var filename = "";

            if (titleID == "iw4")
            {
                filename = "iw4.stat";
            }
            else if (titleID == "iw5")
            {
                filename = "mpdata";
            }

            var npid   = (uint.Parse(userID) | 0x110000100000000);
            var fsFile = StorageUtils.GetFilename(filename, npid);

            if (!File.Exists(fsFile))
            {
                return("");
            }

            return(Convert.ToBase64String(File.ReadAllBytes(fsFile)));
        }
Beispiel #3
0
        public override void Process(NPHandler client)
        {
            var fileName = Message.fileName;
            var fileData = Message.fileData;
            var npid     = (long)Message.npid;
            var fsFile   = StorageUtils.GetFilename(fileName, npid);

            _client   = client;
            _fileName = fileName;
            _npid     = npid;

            if (!client.Authenticated)
            {
                ReplyWithError(1);
                return;
            }

            if (client.NPID != (long)npid)
            {
                ReplyWithError(1);
                return;
            }

            if (!Directory.Exists(Path.GetDirectoryName(fsFile)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(fsFile));
            }

            // are we allowed to write this type of file?
            if (!_fileHooks.ContainsKey(fileName))
            {
                ReplyWithError(1);
                return;
            }

            string backupFile = null;

            int result = _fileHooks[fileName](fileData, fsFile, out backupFile);

            if (result > 0)
            {
                ReplyWithError(result);
                return;
            }

            Log.Info(string.Format("Got a request for writing {0} bytes to file {1} for user {2}.", fileData.Length, fileName, npid.ToString("X16")));

            try
            {
                var stream = File.Open(fsFile, FileMode.Create, FileAccess.Write);

                stream.BeginWrite(fileData, 0, fileData.Length, WriteCompleted, stream);

                if (backupFile != null)
                {
                    var backupStream = File.Open(backupFile, FileMode.Create, FileAccess.Write);

                    backupStream.BeginWrite(fileData, 0, fileData.Length, BackupWriteCompleted, backupStream);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                ReplyWithError(2);
            }
        }