Beispiel #1
0
        private void MessageReceived(GameServer server, IProtocol message)
        {
            switch ((ProtocolDef)message.ProtocolId)
            {
            case ProtocolDef.g2e_exesyscmd_def:
            {
                g2e_exesyscmd protocol   = message as g2e_exesyscmd;
                FSEyeResult   returnCode = (FSEyeResult)protocol.ReturnCode;

                switch (_guardTask)
                {
                case GuardTask.Unknown:
                case GuardTask.Idle:
                //设置时间服务器断连后的回包处理
                //if (returnCode == FSEyeResult.g2e_ExeSysCmd_done) break;
                //throw new Exception("State Exception");
                case GuardTask.StartGameServer:
                    switch (returnCode)
                    {
                    case FSEyeResult.g2e_ExeSysCmd_done:
                        _guardTask = GuardTask.Idle;
                        break;

                    case FSEyeResult.g2e_ExeSysCmd_busy:
                        break;

                    case FSEyeResult.g2e_ExeSysCmd_result:
                        AppendSysCmdOutput(protocol.OutputBuff);
                        break;
                    }
                    break;

                case GuardTask.DoNormalSysCmd:
                    switch (returnCode)
                    {
                    case FSEyeResult.g2e_ExeSysCmd_done:
                        _guardTask = GuardTask.Idle;
                        break;

                    case FSEyeResult.g2e_ExeSysCmd_busy:
                        break;

                    case FSEyeResult.g2e_ExeSysCmd_result:
                        AppendSysCmdOutput(protocol.OutputBuff);
                        break;
                    }
                    break;

                case GuardTask.UpdateGameServer:
                    switch (returnCode)
                    {
                    case FSEyeResult.g2e_ExeSysCmd_done:
                    {
                        _guardTask = GuardTask.Idle;
                        if (_updateGameResult.ToString().Contains("fail"))
                        {
                            server.AppendMessage(string.Format("UpdateGameFail\nFailureMessage:\"{0}\"", _updateGameResult.ToString()), GameServer.MessageInfo.Type.Failure);

                            //触发UpdateGameFail事件
                            AutomationContext context = new AutomationContext();
                            context.Message = string.Format("{0} UpdateGameFail\nFailureMessage:\"{1}\"", server.ToString(), _updateGameResult.ToString());;
                            context.Server  = server;
                            AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.UpdateGameFail, context);
                        }
                        else
                        {
                            server.AppendMessage("UpdateGameSucceed", GameServer.MessageInfo.Type.Success);

                            //触发UpdateGameSucceed事件
                            AutomationContext context = new AutomationContext();
                            context.Message = string.Format("{0} UpdateGameSucceed", server.ToString());
                            context.Server  = server;
                            AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.UpdateGameSucceed, context);
                        }
                    }
                    break;

                    case FSEyeResult.g2e_ExeSysCmd_busy:
                        break;

                    case FSEyeResult.g2e_ExeSysCmd_result:
                        _updateGameResult.Append(protocol.OutputBuff);
                        break;
                    }
                    break;

                case GuardTask.RefreshUploadDirFileInfo:
                    switch (returnCode)
                    {
                    case FSEyeResult.g2e_ExeSysCmd_done:
                        _guardTask = GuardTask.Idle;
                        break;

                    case FSEyeResult.g2e_ExeSysCmd_busy:
                        break;

                    case FSEyeResult.g2e_ExeSysCmd_result:
                        _uploadDirInfo += protocol.OutputBuff;
                        break;
                    }
                    break;

                case GuardTask.CheckGame:
                    switch (returnCode)
                    {
                    case FSEyeResult.g2e_ExeSysCmd_done:
                        _guardTask        = GuardTask.Idle;
                        _GameProcessState = (protocol.OutputBuff.Length > 0) ? GameProcessState.Exist : GameProcessState.NotExist;
                        break;

                    case FSEyeResult.g2e_ExeSysCmd_busy:
                        break;

                    case FSEyeResult.g2e_ExeSysCmd_result:
                        break;
                    }
                    break;

                case GuardTask.GetStatckStrace:
                    switch (returnCode)
                    {
                    case FSEyeResult.g2e_ExeSysCmd_done:
                        _guardTask          = GuardTask.Idle;
                        _getStackTraceState = GetStackTraceState.Done;
                        break;

                    case FSEyeResult.g2e_ExeSysCmd_busy:
                        break;

                    case FSEyeResult.g2e_ExeSysCmd_result:
                        _stackTrace.Append(protocol.OutputBuff);
                        break;
                    }
                    break;

                ////2008-03 huangbiao 去掉getTime任务
                case GuardTask.GetServerTime:
                    ////    switch (returnCode)
                    ////    {
                    ////        case FSEyeResult.g2e_ExeSysCmd_done:
                    ////            _guardTask = GuardTask.Idle;
                    ////            break;
                    ////        case FSEyeResult.g2e_ExeSysCmd_busy:
                    ////            GetServerTime(1);
                    ////            break;
                    ////        case FSEyeResult.g2e_ExeSysCmd_result:
                    ////            try
                    ////            {
                    ////                string dateText = protocol.OutputBuff.TrimEnd('\n').Replace('_', ' ');
                    ////                _serverTimeSpan = DateTime.Now.Subtract(DateTime.Parse(dateText));
                    ////            }
                    ////            catch (Exception ex)
                    ////            {
                    ////                throw (ex);
                    ////            }
                    ////            break;
                    ////    }
                    break;

                default:
                    throw new Exception("State Exception");
                }

                switch (returnCode)
                {
                case FSEyeResult.g2e_ExeSysCmd_done:
                    if (_exeSysCmdComplete != null)
                    {
                        _exeSysCmdComplete(_server, true, _sysCmdOutput.ToString());
                        _exeSysCmdComplete = null;
                    }
                    break;

                case FSEyeResult.g2e_ExeSysCmd_busy:
                    if (_exeSysCmdComplete != null)
                    {
                        _exeSysCmdComplete(_server, false, "busy");
                        _exeSysCmdComplete = null;
                    }
                    break;

                case FSEyeResult.g2e_ExeSysCmd_result:
                    break;
                }
            }
            break;

            case ProtocolDef.g2e_GetGuardDir_def:
            {
                g2e_GetGuardDir protocol = message as g2e_GetGuardDir;
                server.GuardDir = protocol.GuardDir;
            }
            break;

            case ProtocolDef.g2e_switchmode_def:
            {
                server.AppendMessage(StringDef.StopConfigGuard, GameServer.MessageInfo.Type.Normal);

                AdminServer.TheInstance.GameServerManager.SendServerConfigFile(server);

                foreach (GameServer svr in AdminServer.TheInstance.GameServerManager._gameServerList)
                {
                    if (svr.IpAddress == server.IpAddress)
                    {
                        svr.ConfigState = GameServer.ConfigGuardState.Configured;
                        AdminServer.TheInstance.GameServerManager.ModifyGameServer(svr, svr.Name, svr.Comment, svr.IpAddress, svr.GameDir, svr.Group, svr.LordConfig, svr.ConfigState, svr.ConfigContent, svr.Type, svr.FtpServer);
                    }
                }
            }
            break;

            case ProtocolDef.g2e_config_def:
            {
                //TODO 提示重新配置Guard成功
                UpdateGuard(0);
            }
            break;

            default:
                break;
            }
        }
Beispiel #2
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);
            }
        }
Beispiel #3
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);
			}
		}