Esempio n. 1
0
        public override bool Stop(GameServer gameServer)
        {
            if (_taskState == TaskState.Processing || _taskState == TaskState.Paused)
            {
                if (_fileStream != null)
                {
                    _fileStream.Close();
                }

                KProtocolHead protocol = new KProtocolHead();
                protocol.ProtocolId = (ushort)ProtocolDef.e2g_closefile_def;
                gameServer.SendMessage(protocol);
                _taskState = TaskState.Aborting;

                return(true);
            }
            else
            {
                if (_fileDownloadAutomation != null)
                {
                    _fileDownloadAutomation.FinishUnit(gameServer, false);
                }
                return(false);
            }
        }
Esempio n. 2
0
        bool UpdateGuard(int userId)
        {
            if (_server.IsConnected)
            {
                if (_server.GameServerState != GameServer.ServerState.Updating)
                {
                    KProtocolHead protocol = new KProtocolHead();
                    protocol.ProtocolId = (ushort)ProtocolDef.e2g_UpdateGuard_def;
                    if (_server.SendMessage(protocol))
                    {
                        _server.GameServerState = GameServer.ServerState.Updating;
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 3
0
        private void Connected(GameServer server)
        {
            KProtocolHead protocol = new KProtocolHead();

            protocol.ProtocolId = (ushort)ProtocolDef.e2g_GetGuardDir_def;
            server.SendMessage(protocol);

            _guardTask        = GuardTask.Idle;
            _GameProcessState = GameProcessState.Unknown;

            switch (server.ConfigState)
            {
            case GameServer.ConfigGuardState.Configuring:
                SwitchGuardMode();
                //2008-3 huangbiao 只有在传输完配置文件后才更换状态
                //server.ConfigState = GameServer.ConfigGuardState.WaitResponse;
                //SetServerTime(0, DateTime.Now, GetLinuxZoneInfoFile());
                break;

            case GameServer.ConfigGuardState.None:
                SwitchGuardMode();
                server.ConfigState = GameServer.ConfigGuardState.WaitResponse;
                //SetServerTime(0, DateTime.Now, GetLinuxZoneInfoFile());
                break;

            case GameServer.ConfigGuardState.WaitResponse:
                SwitchGuardMode();
                break;

            case GameServer.ConfigGuardState.Configured:
                //得到服务器时间
                ////2008-3 huangbiao
                ////GetServerTime(1);
                break;
            }
        }
Esempio n. 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);
        }
Esempio n. 5
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)
                            {
                                try
                                {
                                    if (_fileDownloadAutomation != null)
                                    {
                                        //如果有Automation关联的话,则给下载文件的名字加前缀。
                                        string fileName = SystemConfig.Current.AdminServerUploadFileRootPath + gameServer.Id + "_" + gameServer.Name + "_" + _targetFileName;
                                        _fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);                                        
                                    }
                                    else
                                    {
                                        _fileStream = new FileStream(SystemConfig.Current.AdminServerUploadFileRootPath + _targetFileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
                                    }
                                }
                                catch (Exception)
                                {
                                    if (_fileDownloadAutomation != null)
                                        _fileDownloadAutomation.FinishUnit(gameServer,false);
                                    return false;
                                }
                            }
                            //得到文件长度
                            _fileTotalLength = ((g2e_openfile)message).nFileLen;

                            if ((uint)_fileStream.Length > _fileTotalLength)
                            {
                                //错误 现有文件长度大于源文件 覆盖现有文件
                                _fileStream.SetLength(0);
                                _offset = 0;
                            }
                            if (_overWrite)
                            {
                                //覆盖
                                _fileStream.SetLength(0);
                                _offset = 0;
                            }
                            else
                            {
                                //续传
                                if (_fileStream.Length == _fileTotalLength)
                                {
                                    //文件已经存在且完成
                                    KProtocolHead protocol = new KProtocolHead();
                                    protocol.ProtocolId = (ushort)ProtocolDef.e2g_closefile_def;
                                    gameServer.SendMessage(protocol);
                                    return true;
                                }
                                else
                                {
                                    _offset = (uint)_fileStream.Length;
                                    _fileStream.Position = _fileStream.Length;
                                }                                
                            }
                            
                            e2g_seekfile seekfile = new e2g_seekfile();
                            seekfile.bKeep = 1;
                            seekfile.nOffset = _offset;

                            //TODO 没有处理发包失败的情况
                            gameServer.SendMessage(seekfile);
                            return true;
                        }
                        else 
                        {
                            //文件不存在?!
                            Stop(gameServer);
                            if (_fileDownloadAutomation != null)
                                _fileDownloadAutomation.FinishUnit(gameServer,false);
                            return false;
                        }
                    case (UInt16)ProtocolDef.g2e_seekfile_def:
                        result = (FSEyeResult)((g2e_seekfile)message).nRetCode;
                        if (result == FSEyeResult.fseye_success)
                        {
                            e2g_readfile protocol = new e2g_readfile();
                            protocol.nDataLen = 4000;
                            gameServer.SendMessage(protocol);
                            return true;
                        }
                        else
                        {
                            //FSEyeResult.filetran_seek_err
                            //还有其他未知的错误
                            Stop(gameServer);
                            if (_fileDownloadAutomation != null)
                                _fileDownloadAutomation.FinishUnit(gameServer,false);
                            return false;
                        }
                    case (UInt16)ProtocolDef.g2e_readfile_def:
                        result = (FSEyeResult)((g2e_readfile)message).nRetCode;
                        if (result == FSEyeResult.fseye_success)
                        {
                            g2e_readfile receivedProtocol = message as g2e_readfile;

                            _fileStream.Write(receivedProtocol.szBuf, 0, (int)receivedProtocol.szBuf.Length);
                            _offset += (uint)receivedProtocol.szBuf.Length;
                            
                            CompletePercentage = (float)_fileStream.Length / (float)_fileTotalLength;

                            if (CompletePercentage < 1)
                            {
                                if (_offset != _fileStream.Length)
                                {
                                    //Guard端读文件偏移和本地写文件的偏移不同
                                    e2g_seekfile seekProtocol = new e2g_seekfile();
                                    seekProtocol.nOffset = (uint)_fileStream.Length;
                                    gameServer.SendMessage(seekProtocol);
                                }
                                else
                                {
                                    e2g_readfile readProtocol = new e2g_readfile();
                                    readProtocol.nDataLen = 4000;
                                    gameServer.SendMessage(readProtocol);
                                }
                            }
                            else
                            {
                                KProtocolHead protocol = new KProtocolHead();
                                protocol.ProtocolId = (ushort)ProtocolDef.e2g_closefile_def;
                                //TODO 没有处理发包失败的情况
                                gameServer.SendMessage(protocol);
                            }

                            return true;
                        }
                        else
                        {
                            Stop(gameServer);
                            if (_fileDownloadAutomation != null)
                                _fileDownloadAutomation.FinishUnit(gameServer,false);
                            return false;
                        }
                    case (UInt16)ProtocolDef.g2e_closefile_def:
                        result = (FSEyeResult)((g2e_closefile)message).nRetCode;
                        if (result == FSEyeResult.fseye_success)
                        {
                            //TODO 添加关闭成功代码
                            Complete(gameServer);
                            return true;
                        }
                        else
                        {
                            if (_fileDownloadAutomation != null)
                                _fileDownloadAutomation.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;
        }
Esempio n. 6
0
        public override bool Stop(GameServer gameServer)
        {
            if (_taskState == TaskState.Processing || _taskState == TaskState.Paused)
            {
                if (_fileStream != null)
                {
                    _fileStream.Close();
                }

                KProtocolHead protocol = new KProtocolHead();
                protocol.ProtocolId = (ushort)ProtocolDef.e2g_closefile_def;
                gameServer.SendMessage(protocol);
                _taskState = TaskState.Aborting;

                return true;
            }
            else
            {
                if (_fileDownloadAutomation != null)
                    _fileDownloadAutomation.FinishUnit(gameServer,false);
                return false;
            }
        }
Esempio n. 7
0
		/// <summary>
		/// 消息处理
		/// </summary>
		private void MessageProcess()
		{
			while (_state != EngineState.Quit)
			{
				if (_state == EngineState.Running)
				{
					IList servers = AdminServer.TheInstance.GameServerManager.Servers;
					lock (servers.SyncRoot)
					{
						for (int i = 0; i < servers.Count; i++)
						{
                            
							GameServer server = servers[i] as GameServer;
							if (server.IsConnected)
                            {
                               
									byte[] msg = AdminServer.TheInstance.ConnectionManager.ReciveFrom(server.ConnectionId);
                                    try
                                    {
									if (msg != null && msg.Length >= 2)
									{
                                        KProtocolHead prohead = new KProtocolHead();
                                        prohead.FromBytes(msg);
                                        if (prohead.ServerID == 0)
                                        {
                                            //Dispatch(server, msg);//romandouUtilDllWrap.RC4Encrypt(msg, server.CommunicationKey));

                                            for (int j = 0; j < servers.Count; j++)
                                            {
                                                GameServer tmpserver = servers[j] as GameServer;
                                                if (tmpserver.ConnectionId == server.ConnectionId)
                                                {
                                                    Dispatch(tmpserver, msg);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            for (int j = 0; j < servers.Count; j++)
                                            {
                                                GameServer tmpserver = servers[j] as GameServer;
                                                if (tmpserver.Id == prohead.ServerID)
                                                {
                                                    Dispatch(tmpserver, msg);
                                                    break;
                                                }
                                            }
                                        }
									}
								}
                                catch (Exception ex)
                                {
                                    Util.DebugLog("Normal protocol parse exception: " + ex.StackTrace);
                                    //AdminServer.TheInstance.ConnectionManager.Disconnect(server.ConnectionId);
                                }
							}
						}
					}

					IList authenticationList = AdminServer.TheInstance.GameServerManager.AuthenticationList;
					lock (authenticationList.SyncRoot)
					{
						if (authenticationList.Count > 0)
						{
							ArrayList invalidList = new ArrayList();
							foreach (GameServerAuthentication authentication in authenticationList)
							{
								authentication.Tick();
								if (authentication.Valid)
								{
									try
									{
										byte[] msg = AdminServer.TheInstance.ConnectionManager.ReciveFrom(authentication.ConnectionId);
										if (msg != null && msg.Length >= 2)
										{
											DispatchAuthentication(authentication, msg);//romandou UtilDllWrap.RC4Encrypt(msg, authentication.CommunicationKey));
										}
									}
									catch (Exception ex)
									{
										Util.DebugLog("Authentication protocol parse exception: " + ex.StackTrace);
										AdminServer.TheInstance.ConnectionManager.Disconnect(authentication.ConnectionId);
									}
								}
								else
								{
									invalidList.Add(authentication);
								}
							}

							if (invalidList.Count > 0)
							{
								foreach (GameServerAuthentication authentication in invalidList)
								{
									authentication.Dispose();
									authenticationList.Remove(authentication);
								}
							}
						}
					}
				}
				Thread.Sleep(1);
			}
		}
Esempio n. 8
0
        /// <summary>
        /// 分发消息
        /// </summary>
        /// <param name="msgBuff">消息</param>
        private void Dispatch(GameServer server, byte[] msgBuff)
        {
            if (server == null || msgBuff == null)
            {
                return;
            }

            if (msgBuff.Length <= 2)
            {
                return;
            }


            ProtocolDef protocalId = (ProtocolDef)BitConverter.ToUInt16(msgBuff, 0);
            IProtocol   message    = null;

            switch (protocalId)
            {
                #region 文件管理
            case ProtocolDef.g2e_openfile_def:                    //打开文件
                message = new g2e_openfile();
                message.FromBytes(msgBuff);
                break;

            case ProtocolDef.g2e_seekfile_def:                    //移动到文件中的位置
                message = new g2e_seekfile();
                break;

            case ProtocolDef.g2e_writefile_def:                    //写入文件
                message = new g2e_writefile();
                break;

            case ProtocolDef.g2e_closefile_def:                    //关闭文件
                message = new g2e_closefile();
                break;

            case ProtocolDef.g2e_readfile_def:     //读文件
                message = new g2e_readfile();
                break;
                #endregion

                #region 游戏服务器信息
            case ProtocolDef.g2e_getcpubaseinfo_def:                    //取得CPU基本信息
                message = new g2e_getcpubaseinfo();
                break;

            case ProtocolDef.g2e_getcpuload_def:                    //取得CPU负载
                message = new g2e_getcpuload();
                break;

            case ProtocolDef.g2e_getdiskinfo_def:                    //取得磁盘信息
                message = new g2e_getdiskinfo();
                break;

            case ProtocolDef.g2e_getmeminfo_def:                    //取得内存信息
                message = new g2e_getmeminfo();
                break;

            case ProtocolDef.g2e_getprocinfo_def:                    //取得进程信息
                message = new g2e_getprocinfo();
                break;

            case ProtocolDef.g2e_getcardload_def:                    //取得网卡负载
                message = new g2e_getcardload();
                break;

            case ProtocolDef.g2e_getnetinfo_def:                    //取得网卡信息
                message = new g2e_getnetinfo();
                break;

            case ProtocolDef.g2e_getpluginfo_def:    //取得插件信息
                message = new g2e_getpluginfo();
                break;
                #endregion

                #region 其他
            case ProtocolDef.g2e_ping_def:                    //Ping
                message = new KProtocolHead();
                break;

            case ProtocolDef.g2e_exesql_def:
                message = new g2e_exesql();
                break;

            case ProtocolDef.g2e_exesyscmd_def:
                message = new g2e_exesyscmd();
                break;

            case ProtocolDef.g2e_GetGuardDir_def:
                message = new g2e_GetGuardDir();
                break;

            case ProtocolDef.g2e_switchmode_def:
                message = new KProtocolHead();
                break;

            case ProtocolDef.g2e_config_def:
                message = new KProtocolHead();
                break;

            case ProtocolDef.g2e_updateserver_def:
                message = new g2e_updateserver();
                break;

            case ProtocolDef.g2e_ftpdownload_def:
                message = new g2e_ftpdownload();
                break;

            case ProtocolDef.g2e_serverpid_def:
                message = new g2e_server_pid();
                break;
                #endregion

                #region 与游戏的通讯

            case ProtocolDef.l2e_header_def:
            {
                if (msgBuff.Length <= 4)
                {
                    return;
                }
                ProtocolDef subProtocolId = (ProtocolDef)BitConverter.ToUInt16(msgBuff, 4);

                switch (subProtocolId)
                {
                // ahpho
                case ProtocolDef.l2e_update_custom_info_def:
                    message = new l2e_update_custom_info();
                    break;

                case ProtocolDef.l2e_PlayerCount_def:
                    message = new l2e_PlayerCount();
                    break;

                case ProtocolDef.l2e_ExeGMCmd_def:
                    message = new l2e_ExeGMCmd();
                    break;

                case ProtocolDef.l2e_GetBasicInfo_def:
                    message = new l2e_GetBasicInfo();
                    break;

                case ProtocolDef.l2e_Who_def:
                    message = new l2e_Who();
                    break;

                case ProtocolDef.l2e_GetGlobalVariable_def:
                    message = new l2e_GetGlobalVariable();
                    break;

                case ProtocolDef.l2e_GetGameStartTime_def:
                    message = new l2e_GetGameStartTime();
                    break;

                case ProtocolDef.l2e_ReportError_def:
                    message = new l2e_ReportError();
                    break;

                case ProtocolDef.l2e_info_def:
                    message = new l2e_info();
                    break;

                case ProtocolDef.l2e_info_large_def:
                    message = new l2e_info_large();
                    break;

                case ProtocolDef.l2e_ping_def:
                    message = new KSubProtocolHead();
                    break;

                default:
                    throw new Exception("收到未在MessageEngine中注册的协议包");
                }
            }
            break;
                #endregion

            default:
                //TODO 记录没有出现过的协议包,开发阶段抛出异常
                throw new Exception("收到未在MessageEngine中注册的协议包");
            }

            if (server != null && message != null)
            {
                message.FromBytes(msgBuff);
                AdminServer.TheInstance.GameServerManager.ProcessMessage(server, message);
            }
        }
Esempio n. 9
0
		private void Connected(GameServer server)
		{
            KProtocolHead protocol = new KProtocolHead();
            protocol.ProtocolId = (ushort)ProtocolDef.e2g_GetGuardDir_def;
            server.SendMessage(protocol);

			_guardTask = GuardTask.Idle;
			_GameProcessState = GameProcessState.Unknown;

            switch (server.ConfigState)
            {
                case GameServer.ConfigGuardState.Configuring:
                    SwitchGuardMode();
                    //2008-3 huangbiao 只有在传输完配置文件后才更换状态
                    //server.ConfigState = GameServer.ConfigGuardState.WaitResponse;
                    //SetServerTime(0, DateTime.Now, GetLinuxZoneInfoFile());
                    break;
                case GameServer.ConfigGuardState.None:
                    SwitchGuardMode();
                    server.ConfigState = GameServer.ConfigGuardState.WaitResponse;
                    //SetServerTime(0, DateTime.Now, GetLinuxZoneInfoFile());
                    break;
                case GameServer.ConfigGuardState.WaitResponse:
                    SwitchGuardMode();
                    break;
                case GameServer.ConfigGuardState.Configured:
                    //得到服务器时间
                    ////2008-3 huangbiao
                    ////GetServerTime(1);
                    break;
            }
		}
Esempio n. 10
0
		private void DoPing(GameServer server)
		{
			KProtocolHead protocol = new KProtocolHead();
            protocol.ProtocolId = (ushort)ProtocolDef.e2g_ping_def;
			server.SendMessage(protocol);
		}
Esempio n. 11
0
		private void Tick(GameServer server)
		{
			if (server != null)
			{
				if (server.IsConnected)
				{
					_updateDiskInfoTickCurrent++;
					if (_updateDiskInfoTickCurrent >= _updateDiskInfoTickDo)
					{
                        KProtocolHead protocol = new KProtocolHead();
                        protocol.ProtocolId = (ushort)ProtocolDef.e2g_getdiskinfo_def;
 						if (server.SendMessage(protocol))
						{
							_updateDiskInfoTickCurrent = 0;
						}
					}
				}
				else
				{
					_updateDiskInfoTickCurrent = 0;
				}
			}
		}
Esempio n. 12
0
		private void Connected(GameServer server)
		{
            KProtocolHead protocol = new KProtocolHead();
            protocol.ProtocolId = (ushort)ProtocolDef.e2g_getcpubaseinfo_def;
			server.SendMessage(protocol);
		}
Esempio n. 13
0
 public override bool DoAction(int userId, string actionKey, ref object outArg, params object[] args)
 {
     KProtocolHead protocol = new KProtocolHead();
     protocol.ServerID = UInt16.Parse(args[0].ToString());
     protocol.ProtocolId = (UInt16)ProtocolDef.e2l_exit_def;
     return _server.SendMessage(protocol); 
 }
Esempio n. 14
0
		private void Tick(GameServer server)
		{
			if (server != null)
			{
				if (server.IsConnected)
				{
					_updateNetworkLoadTickCurrent++;
					if (_updateNetworkLoadTickCurrent >= _updateNetworkLoadTickDo)
					{
                        KProtocolHead protocol = new KProtocolHead();
                        protocol.ProtocolId = (ushort)ProtocolDef.e2g_getcardload_def;
						if (server.SendMessage(protocol))
						{
							_updateNetworkLoadTickCurrent = 0;
						}
					}
				}
			}
		}
Esempio n. 15
0
		bool UpdateGuard(int userId)
		{
			if (_server.IsConnected)
			{
				if (_server.GameServerState != GameServer.ServerState.Updating)
				{
                    KProtocolHead protocol = new KProtocolHead();
                    protocol.ProtocolId = (ushort)ProtocolDef.e2g_UpdateGuard_def;
					if (_server.SendMessage(protocol))
					{
						_server.GameServerState = GameServer.ServerState.Updating;
						return true;
					}
				}
			}

			return false;
		}
Esempio n. 16
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)
                        {
                            try
                            {
                                if (_fileDownloadAutomation != null)
                                {
                                    //如果有Automation关联的话,则给下载文件的名字加前缀。
                                    string fileName = SystemConfig.Current.AdminServerUploadFileRootPath + gameServer.Id + "_" + gameServer.Name + "_" + _targetFileName;
                                    _fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
                                }
                                else
                                {
                                    _fileStream = new FileStream(SystemConfig.Current.AdminServerUploadFileRootPath + _targetFileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
                                }
                            }
                            catch (Exception)
                            {
                                if (_fileDownloadAutomation != null)
                                {
                                    _fileDownloadAutomation.FinishUnit(gameServer, false);
                                }
                                return(false);
                            }
                        }
                        //得到文件长度
                        _fileTotalLength = ((g2e_openfile)message).nFileLen;

                        if ((uint)_fileStream.Length > _fileTotalLength)
                        {
                            //错误 现有文件长度大于源文件 覆盖现有文件
                            _fileStream.SetLength(0);
                            _offset = 0;
                        }
                        if (_overWrite)
                        {
                            //覆盖
                            _fileStream.SetLength(0);
                            _offset = 0;
                        }
                        else
                        {
                            //续传
                            if (_fileStream.Length == _fileTotalLength)
                            {
                                //文件已经存在且完成
                                KProtocolHead protocol = new KProtocolHead();
                                protocol.ProtocolId = (ushort)ProtocolDef.e2g_closefile_def;
                                gameServer.SendMessage(protocol);
                                return(true);
                            }
                            else
                            {
                                _offset = (uint)_fileStream.Length;
                                _fileStream.Position = _fileStream.Length;
                            }
                        }

                        e2g_seekfile seekfile = new e2g_seekfile();
                        seekfile.bKeep   = 1;
                        seekfile.nOffset = _offset;

                        //TODO 没有处理发包失败的情况
                        gameServer.SendMessage(seekfile);
                        return(true);
                    }
                    else
                    {
                        //文件不存在?!
                        Stop(gameServer);
                        if (_fileDownloadAutomation != null)
                        {
                            _fileDownloadAutomation.FinishUnit(gameServer, false);
                        }
                        return(false);
                    }

                case (UInt16)ProtocolDef.g2e_seekfile_def:
                    result = (FSEyeResult)((g2e_seekfile)message).nRetCode;
                    if (result == FSEyeResult.fseye_success)
                    {
                        e2g_readfile protocol = new e2g_readfile();
                        protocol.nDataLen = 4000;
                        gameServer.SendMessage(protocol);
                        return(true);
                    }
                    else
                    {
                        //FSEyeResult.filetran_seek_err
                        //还有其他未知的错误
                        Stop(gameServer);
                        if (_fileDownloadAutomation != null)
                        {
                            _fileDownloadAutomation.FinishUnit(gameServer, false);
                        }
                        return(false);
                    }

                case (UInt16)ProtocolDef.g2e_readfile_def:
                    result = (FSEyeResult)((g2e_readfile)message).nRetCode;
                    if (result == FSEyeResult.fseye_success)
                    {
                        g2e_readfile receivedProtocol = message as g2e_readfile;

                        _fileStream.Write(receivedProtocol.szBuf, 0, (int)receivedProtocol.szBuf.Length);
                        _offset += (uint)receivedProtocol.szBuf.Length;

                        CompletePercentage = (float)_fileStream.Length / (float)_fileTotalLength;

                        if (CompletePercentage < 1)
                        {
                            if (_offset != _fileStream.Length)
                            {
                                //Guard端读文件偏移和本地写文件的偏移不同
                                e2g_seekfile seekProtocol = new e2g_seekfile();
                                seekProtocol.nOffset = (uint)_fileStream.Length;
                                gameServer.SendMessage(seekProtocol);
                            }
                            else
                            {
                                e2g_readfile readProtocol = new e2g_readfile();
                                readProtocol.nDataLen = 4000;
                                gameServer.SendMessage(readProtocol);
                            }
                        }
                        else
                        {
                            KProtocolHead protocol = new KProtocolHead();
                            protocol.ProtocolId = (ushort)ProtocolDef.e2g_closefile_def;
                            //TODO 没有处理发包失败的情况
                            gameServer.SendMessage(protocol);
                        }

                        return(true);
                    }
                    else
                    {
                        Stop(gameServer);
                        if (_fileDownloadAutomation != null)
                        {
                            _fileDownloadAutomation.FinishUnit(gameServer, false);
                        }
                        return(false);
                    }

                case (UInt16)ProtocolDef.g2e_closefile_def:
                    result = (FSEyeResult)((g2e_closefile)message).nRetCode;
                    if (result == FSEyeResult.fseye_success)
                    {
                        //TODO 添加关闭成功代码
                        Complete(gameServer);
                        return(true);
                    }
                    else
                    {
                        if (_fileDownloadAutomation != null)
                        {
                            _fileDownloadAutomation.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);
        }
Esempio n. 17
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;
		}
Esempio n. 18
0
        /// <summary>
        /// 消息处理
        /// </summary>
        private void MessageProcess()
        {
            while (_state != EngineState.Quit)
            {
                if (_state == EngineState.Running)
                {
                    IList servers = AdminServer.TheInstance.GameServerManager.Servers;
                    lock (servers.SyncRoot)
                    {
                        for (int i = 0; i < servers.Count; i++)
                        {
                            GameServer server = servers[i] as GameServer;
                            if (server.IsConnected)
                            {
                                byte[] msg = AdminServer.TheInstance.ConnectionManager.ReciveFrom(server.ConnectionId);
                                try
                                {
                                    if (msg != null && msg.Length >= 2)
                                    {
                                        KProtocolHead prohead = new KProtocolHead();
                                        prohead.FromBytes(msg);
                                        if (prohead.ServerID == 0)
                                        {
                                            //Dispatch(server, msg);//romandouUtilDllWrap.RC4Encrypt(msg, server.CommunicationKey));

                                            for (int j = 0; j < servers.Count; j++)
                                            {
                                                GameServer tmpserver = servers[j] as GameServer;
                                                if (tmpserver.ConnectionId == server.ConnectionId)
                                                {
                                                    Dispatch(tmpserver, msg);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            for (int j = 0; j < servers.Count; j++)
                                            {
                                                GameServer tmpserver = servers[j] as GameServer;
                                                if (tmpserver.Id == prohead.ServerID)
                                                {
                                                    Dispatch(tmpserver, msg);
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Util.DebugLog("Normal protocol parse exception: " + ex.StackTrace);
                                    //AdminServer.TheInstance.ConnectionManager.Disconnect(server.ConnectionId);
                                }
                            }
                        }
                    }

                    IList authenticationList = AdminServer.TheInstance.GameServerManager.AuthenticationList;
                    lock (authenticationList.SyncRoot)
                    {
                        if (authenticationList.Count > 0)
                        {
                            ArrayList invalidList = new ArrayList();
                            foreach (GameServerAuthentication authentication in authenticationList)
                            {
                                authentication.Tick();
                                if (authentication.Valid)
                                {
                                    try
                                    {
                                        byte[] msg = AdminServer.TheInstance.ConnectionManager.ReciveFrom(authentication.ConnectionId);
                                        if (msg != null && msg.Length >= 2)
                                        {
                                            DispatchAuthentication(authentication, msg);                                            //romandou UtilDllWrap.RC4Encrypt(msg, authentication.CommunicationKey));
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Util.DebugLog("Authentication protocol parse exception: " + ex.StackTrace);
                                        AdminServer.TheInstance.ConnectionManager.Disconnect(authentication.ConnectionId);
                                    }
                                }
                                else
                                {
                                    invalidList.Add(authentication);
                                }
                            }

                            if (invalidList.Count > 0)
                            {
                                foreach (GameServerAuthentication authentication in invalidList)
                                {
                                    authentication.Dispose();
                                    authenticationList.Remove(authentication);
                                }
                            }
                        }
                    }
                }
                Thread.Sleep(1);
            }
        }
Esempio n. 19
0
		/// <summary>
		/// 分发消息
		/// </summary>
		/// <param name="msgBuff">消息</param>
		private void Dispatch(GameServer server, byte[] msgBuff)
		{
			if (server == null || msgBuff == null)
				return;

            if (msgBuff.Length <= 2)
            {
                return;
            }


			ProtocolDef protocalId = (ProtocolDef)BitConverter.ToUInt16(msgBuff, 0);
			IProtocol message = null;
			switch (protocalId)
			{
				#region 文件管理
				case ProtocolDef.g2e_openfile_def://打开文件
                    message = new g2e_openfile();
                    message.FromBytes(msgBuff);
					break;
				case ProtocolDef.g2e_seekfile_def://移动到文件中的位置
					message = new g2e_seekfile();
					break;
				case ProtocolDef.g2e_writefile_def://写入文件
					message = new g2e_writefile();
					break;
				case ProtocolDef.g2e_closefile_def://关闭文件
					message = new g2e_closefile();
					break;
                case ProtocolDef.g2e_readfile_def: //读文件
                    message = new g2e_readfile();
                    break;
				#endregion

				#region 游戏服务器信息
				case ProtocolDef.g2e_getcpubaseinfo_def://取得CPU基本信息
					message = new g2e_getcpubaseinfo();
					break;
				case ProtocolDef.g2e_getcpuload_def://取得CPU负载
					message = new g2e_getcpuload();
					break;
				case ProtocolDef.g2e_getdiskinfo_def://取得磁盘信息
                    message = new g2e_getdiskinfo();
					break;
				case ProtocolDef.g2e_getmeminfo_def://取得内存信息
                    message = new g2e_getmeminfo();
					break;
				case ProtocolDef.g2e_getprocinfo_def://取得进程信息
                    message = new g2e_getprocinfo();
					break;
				case ProtocolDef.g2e_getcardload_def://取得网卡负载
                    message = new g2e_getcardload();					
					break;
				case ProtocolDef.g2e_getnetinfo_def://取得网卡信息
                    message = new g2e_getnetinfo();
					break;
                case ProtocolDef.g2e_getpluginfo_def://取得插件信息
                    message = new g2e_getpluginfo();
                    break;				
				#endregion

				#region 其他
				case ProtocolDef.g2e_ping_def://Ping
                    message = new KProtocolHead();
                    break;
				case ProtocolDef.g2e_exesql_def:
					message = new g2e_exesql();
					break;
				case ProtocolDef.g2e_exesyscmd_def:
					message = new g2e_exesyscmd();
					break;
				case ProtocolDef.g2e_GetGuardDir_def:
					message = new g2e_GetGuardDir();
					break;
				case ProtocolDef.g2e_switchmode_def:
					message = new KProtocolHead();
					break;
				case ProtocolDef.g2e_config_def:
					message = new KProtocolHead();
					break;
                case ProtocolDef.g2e_updateserver_def:
                    message = new g2e_updateserver();
                    break;
                case ProtocolDef.g2e_ftpdownload_def:
                    message = new g2e_ftpdownload();
                    break;
                case ProtocolDef.g2e_serverpid_def:
                    message = new g2e_server_pid();
                    break;                        
				#endregion

				#region 与游戏的通讯
			
                case ProtocolDef.l2e_header_def:
                    {
                        if (msgBuff.Length <= 4)
                            return;
                        ProtocolDef subProtocolId = (ProtocolDef)BitConverter.ToUInt16(msgBuff, 4);

                        switch (subProtocolId)
                        {
                            // ahpho
                            case ProtocolDef.l2e_update_custom_info_def:
                                message = new l2e_update_custom_info();
                                break;
                            case ProtocolDef.l2e_PlayerCount_def:
                                message = new l2e_PlayerCount();
                                break;
                            case ProtocolDef.l2e_ExeGMCmd_def:
                                message = new l2e_ExeGMCmd();
                                break;
                            case ProtocolDef.l2e_GetBasicInfo_def:
                                message = new l2e_GetBasicInfo();
                                break;
                            case ProtocolDef.l2e_Who_def:
                                message = new l2e_Who();
                                break;
                            case ProtocolDef.l2e_GetGlobalVariable_def:
                                message = new l2e_GetGlobalVariable();
                                break;
                            case ProtocolDef.l2e_GetGameStartTime_def:
                                message = new l2e_GetGameStartTime();
                                break;
                            case ProtocolDef.l2e_ReportError_def:
                                message = new l2e_ReportError();
                                break;
                            case ProtocolDef.l2e_info_def:
                                message = new l2e_info();
                                break;
                            case ProtocolDef.l2e_info_large_def:
                                message = new l2e_info_large();
                                break;
                            case ProtocolDef.l2e_ping_def:
                                message = new KSubProtocolHead();
                                break;
                            default:
                                throw new Exception("收到未在MessageEngine中注册的协议包");
                        }
                    }
                    break;
				#endregion

				default:
					//TODO 记录没有出现过的协议包,开发阶段抛出异常
					throw new Exception("收到未在MessageEngine中注册的协议包");
			}

			if (server != null && message != null)
			{
                message.FromBytes(msgBuff);
				AdminServer.TheInstance.GameServerManager.ProcessMessage(server, message);
			}
		}