Beispiel #1
0
		public void GameStateChanged(GameServer server, GameServer.ServiceState originalState, GameServer.ServiceState newState)
		{
            GameServer.ServerEventType eventType = GameServer.ServerEventType.UnknownEvent;

            switch (originalState)
                {
                    case GameServer.ServiceState.Starting:
                        {
                            if (newState == GameServer.ServiceState.Running)
                            {
                                //游戏正常启动
                                server.AppendMessage("Start", GameServer.MessageInfo.Type.Success);

                                AutomationContext context = new AutomationContext();
                                context.Message = string.Format("{0} Start", server.ToString()); ;
                                context.Server = server;
                                AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.GameStart, context);

                                eventType = GameServer.ServerEventType.GameStart;
                            }
                            else if (newState == GameServer.ServiceState.ErrorStopped)
                            {
                                //游戏启动失败
                                server.AppendMessage("StartFail", GameServer.MessageInfo.Type.Failure);

                                AutomationContext context = new AutomationContext();
                                context.Message = string.Format("{0} StartFail", server.ToString()); ;
                                context.Server = server;
                                AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.StartGameFail, context);

                                eventType = GameServer.ServerEventType.GameStartFail;
                            }
                        } break;
                    case GameServer.ServiceState.Stopping:
                        {
                            if (newState == GameServer.ServiceState.OKStopped || newState == GameServer.ServiceState.ErrorStopped)
                            {
                                //停止,指web主动关闭服务器程序
                                //游戏正常关闭
                                server.AppendMessage("Stop", GameServer.MessageInfo.Type.Alert);

                                AutomationContext context = new AutomationContext();
                                context.Message = string.Format("{0} Stop", server.ToString()); ;
                                context.Server = server;
                                AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.GameStop, context);

                                eventType = GameServer.ServerEventType.GameStop;
                            }
                        } break;
                    case GameServer.ServiceState.ErrorStopped:
                    case GameServer.ServiceState.OKStopped :
                        {
                            if (newState == GameServer.ServiceState.Running)
                            {
                                //游戏意外启动
                                server.AppendMessage("StartByAccident", GameServer.MessageInfo.Type.Failure);

                                AutomationContext context = new AutomationContext();
                                context.Message = string.Format("{0} StartByAccident", server.ToString()); ;
                                context.Server = server;
                                AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.GameStartByAccident, context);

                                eventType = GameServer.ServerEventType.GameStartByAccident;
                            }
                        } break;
                    case GameServer.ServiceState.Running:
                        {
                            if (newState == GameServer.ServiceState.ErrorStopped)
                            {
                                //游戏崩溃
                                server.AppendMessage("StopByAccident", GameServer.MessageInfo.Type.Failure);

                                AutomationContext context = new AutomationContext();
                                context.Message = string.Format("{0} StopByAccident", server.ToString()); ;
                                context.Server = server;
                                AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.GameStopByAccident, context);

                                eventType = GameServer.ServerEventType.GameStopByAccident;
                            }
                        } break;
                }

                if (eventType != GameServer.ServerEventType.UnknownEvent)
                {
                    DateTime eventTime = DateTime.Now;

                    using (IBlazeDatabase db = DbFactory.GetDatabase())
                    {
                        IBlazeTable table = db.GetTable(TableString.ServerEventTableName);

                        string[] fieldNames = {
					TableString.ServerEventFieldServerId,
					TableString.ServerEventFieldEventTime,
					TableString.ServerEventFieldEventType
				    };

                        object[] fieldValues = {
					server.Id,
					eventTime,
					(Int16)eventType
				    };

                        table.Add(fieldNames, fieldValues);
                    }
                }
            
		}