示例#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;
            }
        }
示例#2
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;
			}
		}