Example #1
0
        public override bool Continue(GameServer gameServer)
        {
            if (_taskState == TaskState.Paused)
            {
                _overWrite = false;
                e2g_openfile protocol = new e2g_openfile();
                protocol.szFileName = _sourceFileName;
                protocol.bFlag      = (byte)0;                              //0-读,1-写,2-续传
                protocol.bFullPath  = (byte)1;                              //0-相对,1-绝对
                if (gameServer.SendMessage(protocol))
                {
                    _taskState = TaskState.Processing;
                    return(true);
                }
            }

            return(false);
        }
Example #2
0
 public override bool Continue(GameServer gameServer)
 {
     if (_taskState == TaskState.Paused)
     {
         e2g_openfile protocol = new e2g_openfile();
         protocol.szFileName = _targetFileName;
         protocol.bFlag      = (byte)1;
         if (gameServer.SendMessage(protocol))
         {
             _taskState = TaskState.Processing;
             return(true);
         }
     }
     if (_fileTranAutomation != null)
     {
         _fileTranAutomation.FinishUnit(gameServer, false);
     }
     return(false);
 }
Example #3
0
        public override bool Start(GameServer gameServer)
        {
            if (_taskState == TaskState.Created || _taskState == TaskState.Queuing)
            {
                e2g_openfile protocol = new e2g_openfile();
                protocol.szFileName = _sourceFileName;
                protocol.bFlag      = (byte)0;                             //0-读,1-写,2-续传
                protocol.bFullPath  = (byte)1;                             //0-相对,1-绝对
                if (gameServer.SendMessage(protocol))
                {
                    _startTime = DateTime.Now;
                    _taskState = TaskState.Processing;
                    return(true);
                }
            }

            if (_fileDownloadAutomation != null)
            {
                _fileDownloadAutomation.FinishUnit(gameServer, false);
            }
            return(false);
        }
Example #4
0
        public override bool DoTask(GameServer gameServer, IProtocol message)
        {
            if (gameServer == null || message == null)
            {
                throw new ArgumentException("gameServer & message can not be null.");
            }

            if (_taskState == TaskState.Processing)
            {
                FSEyeResult result;
                switch (message.ProtocolId)
                {
                case (UInt16)ProtocolDef.g2e_openfile_def:
                    result = (FSEyeResult)((g2e_openfile)message).nRetCode;
                    if (result == FSEyeResult.fseye_success)
                    {
                        if (_fileStream == null)
                        {
                            _fileStream = new FileStream(SystemConfig.Current.AdminServerUploadFileRootPath + SourceFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                        }
                        _fileTotalLength = (uint)_fileStream.Length;
                        e2g_seekfile protocol = new e2g_seekfile();
                        protocol.nOffset = _offset;

                        //TODO 没有处理发包失败的情况
                        gameServer.SendMessage(protocol);
                        return(true);
                    }
                    else if (result == FSEyeResult.filetran_app_err)                            //续传文件不存在
                    {
                        //TODO 任务重新开始
                        e2g_openfile protocol = new e2g_openfile();
                        protocol.szFileName = _targetFileName;
                        protocol.bFlag      = 1;

                        //TODO 没有处理发包失败的情况
                        gameServer.SendMessage(protocol);
                        return(true);
                    }
                    else
                    {
                        //FSEyeResult.filetran_opening_err//文件已经打开
                        //FSEyeResult.filetran_cre_err//文件创建失败
                        //还有其他未知的错误
                        //这些情况无法处理,只能终止操作
                        if (_fileTranAutomation != null)
                        {
                            _fileTranAutomation.FinishUnit(gameServer, false);
                        }

                        Stop(gameServer);
                        return(false);
                    }

                case (UInt16)ProtocolDef.g2e_seekfile_def:
                    result = (FSEyeResult)((g2e_seekfile)message).nRetCode;
                    if (result == FSEyeResult.fseye_success)
                    {
                        e2g_writefile protocol = new e2g_writefile((int)_fileStream.Length);
                        _fileStream.Seek(_offset, SeekOrigin.Begin);
                        _sendLength = (UInt16)_fileStream.Read(protocol.szBuf, 0, (int)_fileStream.Length);
                        Array.Resize(ref protocol.szBuf, _sendLength);

                        //TODO 没有处理发包失败的情况
                        gameServer.SendMessage(protocol);
                        return(true);
                    }
                    else
                    {
                        //FSEyeResult.filetran_seek_err
                        //还有其他未知的错误
                        //这些情况无法处理,只能终止操作

                        if (_fileTranAutomation != null)
                        {
                            _fileTranAutomation.FinishUnit(gameServer, false);
                        }

                        Stop(gameServer);
                        return(false);
                    }

                case (UInt16)ProtocolDef.g2e_writefile_def:
                    result = (FSEyeResult)((g2e_writefile)message).nRetCode;
                    if (result == FSEyeResult.fseye_success)
                    {
                        uint guardWriteLength = ((g2e_writefile)message).nWritedLen;
                        _offset += guardWriteLength;

                        CompletePercentage = (float)_offset / (float)_fileTotalLength;

                        if (CompletePercentage < 1)
                        {
                            if (guardWriteLength < _sendLength)
                            {
                                _fileStream.Seek(guardWriteLength - _sendLength, SeekOrigin.Current);
                            }
                            e2g_writefile protocol = new e2g_writefile((int)_fileStream.Length);
                            _sendLength = (UInt16)_fileStream.Read(protocol.szBuf, 0, (int)_fileStream.Length);
                            Array.Resize(ref protocol.szBuf, _sendLength);

                            //TODO 没有处理发包失败的情况
                            gameServer.SendMessage(protocol);
                        }
                        else
                        {
                            KProtocolHead protocol = new KProtocolHead();
                            protocol.ProtocolId = (ushort)ProtocolDef.e2g_closefile_def;

                            //TODO 没有处理发包失败的情况
                            gameServer.SendMessage(protocol);
                        }

                        return(true);
                    }
                    else
                    {
                        //还有其他未知的错误
                        //这些情况无法处理,只能终止操作

                        if (_fileTranAutomation != null)
                        {
                            _fileTranAutomation.FinishUnit(gameServer, false);
                        }

                        Stop(gameServer);
                        return(false);
                    }

                case (UInt16)ProtocolDef.g2e_closefile_def:
                    result = (FSEyeResult)((g2e_closefile)message).nRetCode;
                    if (result == FSEyeResult.fseye_success)
                    {
                        //通知绑定的Automation此文件传输完成
                        if (_fileTranAutomation != null)
                        {
                            _fileTranAutomation.FinishUnit(gameServer, true);
                        }

                        //TODO 添加关闭成功代码
                        Complete(gameServer);
                        return(true);
                    }
                    else
                    {
                        if (_fileTranAutomation != null)
                        {
                            _fileTranAutomation.FinishUnit(gameServer, false);
                        }
                        return(false);
                    }

                default:
                    break;
                }
            }
            else if (_taskState == TaskState.Aborting)
            {
                if (message.ProtocolId == (UInt16)ProtocolDef.g2e_closefile_def)
                {
                    _taskState = TaskState.Stopped;
                }

                return(true);
            }

            return(false);
        }
Example #5
0
        public override bool Continue(GameServer gameServer)
        {
            if (_taskState == TaskState.Paused)
            {
                _overWrite = false;
                e2g_openfile protocol = new e2g_openfile();
                protocol.szFileName = _sourceFileName;
                protocol.bFlag = (byte)0;                                   //0-读,1-写,2-续传
                protocol.bFullPath = (byte)1;                               //0-相对,1-绝对
                if (gameServer.SendMessage(protocol))
                {
                    _taskState = TaskState.Processing;
                    return true;
                }
            }

            return false;
        }
Example #6
0
        public override bool Start(GameServer gameServer)
        {
            if (_taskState == TaskState.Created || _taskState == TaskState.Queuing)
            {
                e2g_openfile protocol = new e2g_openfile();
                protocol.szFileName = _sourceFileName;
                protocol.bFlag = (byte)0;                                  //0-读,1-写,2-续传
                protocol.bFullPath = (byte)1;                              //0-相对,1-绝对
                if (gameServer.SendMessage(protocol))
                {
                    _startTime = DateTime.Now;
                    _taskState = TaskState.Processing;
                    return true;
                }
            }

            if (_fileDownloadAutomation != null)
                _fileDownloadAutomation.FinishUnit(gameServer,false);
            return false;
        }
Example #7
0
		public override bool DoTask(GameServer gameServer, IProtocol message)
		{
			if (gameServer == null || message == null)
			{
				throw new ArgumentException("gameServer & message can not be null.");
			}

			if (_taskState == TaskState.Processing)
			{
				FSEyeResult result;
				switch (message.ProtocolId)
				{
					case (UInt16)ProtocolDef.g2e_openfile_def:
						result = (FSEyeResult)((g2e_openfile)message).nRetCode;
						if (result == FSEyeResult.fseye_success)
						{
							if (_fileStream == null)
							{
								_fileStream = new FileStream(SystemConfig.Current.AdminServerUploadFileRootPath + SourceFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
							}
							_fileTotalLength = (uint)_fileStream.Length;
							e2g_seekfile protocol = new e2g_seekfile();
							protocol.nOffset = _offset;

							//TODO 没有处理发包失败的情况
							gameServer.SendMessage(protocol);
							return true;
						}
						else if (result == FSEyeResult.filetran_app_err)//续传文件不存在
						{
							//TODO 任务重新开始
							e2g_openfile protocol = new e2g_openfile();
							protocol.szFileName = _targetFileName;
							protocol.bFlag = 1;

							//TODO 没有处理发包失败的情况
							gameServer.SendMessage(protocol);
							return true;
						}
						else
						{
							//FSEyeResult.filetran_opening_err//文件已经打开
							//FSEyeResult.filetran_cre_err//文件创建失败
							//还有其他未知的错误
							//这些情况无法处理,只能终止操作
                            if (_fileTranAutomation != null)
                                _fileTranAutomation.FinishUnit(gameServer, false);

							Stop(gameServer);
							return false;
						}
					case (UInt16)ProtocolDef.g2e_seekfile_def:
						result = (FSEyeResult)((g2e_seekfile)message).nRetCode;
						if (result == FSEyeResult.fseye_success)
						{
                            e2g_writefile protocol = new e2g_writefile((int)_fileStream.Length);
							_fileStream.Seek(_offset, SeekOrigin.Begin);
                            _sendLength = (UInt16)_fileStream.Read(protocol.szBuf, 0, (int)_fileStream.Length);
                            Array.Resize(ref protocol.szBuf, _sendLength);

							//TODO 没有处理发包失败的情况
							gameServer.SendMessage(protocol);
							return true;
						}
						else
						{
							//FSEyeResult.filetran_seek_err
							//还有其他未知的错误
							//这些情况无法处理,只能终止操作

                            if (_fileTranAutomation != null)
                                _fileTranAutomation.FinishUnit(gameServer, false);

							Stop(gameServer);
							return false;
						}
					case (UInt16)ProtocolDef.g2e_writefile_def:
						result = (FSEyeResult)((g2e_writefile)message).nRetCode;
						if (result == FSEyeResult.fseye_success)
						{
							uint guardWriteLength = ((g2e_writefile)message).nWritedLen;
							_offset += guardWriteLength;

							CompletePercentage = (float)_offset / (float)_fileTotalLength;

							if (CompletePercentage < 1)
							{
								if (guardWriteLength < _sendLength)
								{
									_fileStream.Seek(guardWriteLength - _sendLength, SeekOrigin.Current);
								}
                                e2g_writefile protocol = new e2g_writefile((int)_fileStream.Length);
                                _sendLength = (UInt16)_fileStream.Read(protocol.szBuf, 0, (int)_fileStream.Length);
                                Array.Resize(ref protocol.szBuf, _sendLength);

								//TODO 没有处理发包失败的情况
								gameServer.SendMessage(protocol);
							}
							else
							{
                                KProtocolHead protocol = new KProtocolHead();
                                protocol.ProtocolId = (ushort)ProtocolDef.e2g_closefile_def;

								//TODO 没有处理发包失败的情况
								gameServer.SendMessage(protocol);
							}

							return true;
						}
						else
						{
							//还有其他未知的错误
							//这些情况无法处理,只能终止操作

                            if (_fileTranAutomation != null)
                                _fileTranAutomation.FinishUnit(gameServer, false);

							Stop(gameServer);
							return false;
						}
					case (UInt16)ProtocolDef.g2e_closefile_def:
						result = (FSEyeResult)((g2e_closefile)message).nRetCode;
						if (result == FSEyeResult.fseye_success)
						{
                            //通知绑定的Automation此文件传输完成
                            if (_fileTranAutomation != null)
                                _fileTranAutomation.FinishUnit(gameServer, true);

							//TODO 添加关闭成功代码
							Complete(gameServer);
							return true;
						}
						else
						{
                            if (_fileTranAutomation != null)
                                _fileTranAutomation.FinishUnit(gameServer, false);
							return false;
						}						
					default:
						break;
				}
			}
			else if (_taskState == TaskState.Aborting)
			{
				if (message.ProtocolId == (UInt16)ProtocolDef.g2e_closefile_def)
				{
					_taskState = TaskState.Stopped;					
				}

				return true;
			}

			return false;
		}
Example #8
0
		public override bool Continue(GameServer gameServer)
		{
			if (_taskState == TaskState.Paused)
			{				
				e2g_openfile protocol = new e2g_openfile();
				protocol.szFileName = _targetFileName;
				protocol.bFlag = (byte)1;
				if (gameServer.SendMessage(protocol))
				{
					_taskState = TaskState.Processing;
					return true;
				}
			}
            if (_fileTranAutomation != null)
                _fileTranAutomation.FinishUnit(gameServer, false);
			return false;
		}