Esempio n. 1
0
        private static void RunServer([NotNull] IEnumerable <string> args)
        {
            var staticContentPath    = GetStaticContentDir();
            var settings             = GetSettingsFile(args);
            var httpListenerPrefix   = settings.HttpListenerPrefix;
            var warriorProgramParser = new WarriorParser();
            var playersRepo          = new PlayersRepo(new DirectoryInfo("../players"), warriorProgramParser);
            var gamesRepo            = new CachingGamesRepo(new GamesRepo(new DirectoryInfo("../games")));
            var sessionManager       = new SessionManager("../sessions");
            var gameServer           = new GameServer();
            var debuggerManager      = new DebuggerManager(gameServer);
            var battleRunner         = new BattleRunner();
            var countdownProvider    = new CountdownProvider(settings.ContestStartTimestamp, TimeSpan.FromHours(settings.ContestDurationInHours));
            var arenaState           = new ArenaState(playersRepo, gamesRepo, countdownProvider, settings.GodModeSecret, settings.GodAccessOnly, settings.SubmitIsAllowed, settings.EnableDeepNavigation);
            var tournamentRunner     = new TournamentRunner(arenaState, battleRunner, settings.BattlesPerPair);
            var httpServer           = new GameHttpServer(httpListenerPrefix, arenaState, sessionManager, debuggerManager, tournamentRunner, staticContentPath);

            Runtime.SetStopHandler(() =>
            {
                log.InfoFormat("Stopping...");
                httpServer.Stop();
                tournamentRunner.Stop();
            });
            tournamentRunner.Start();
            httpServer.Run();
            log.InfoFormat("Listening on: {0}", httpListenerPrefix);
            if (!settings.ProductionMode)
            {
                Process.Start(httpServer.DefaultUrl);
            }
            httpServer.WaitForTermination();
            tournamentRunner.WaitForTermination();
            log.InfoFormat("Stopped");
        }
Esempio n. 2
0
        /// <summary>
        /// Walks through the set of tasks for this target and processes them by handing them off to the TaskBuilder.
        /// </summary>
        /// <returns>
        /// The result of the tasks, based on the last task which ran.
        /// </returns>
        private async Task <WorkUnitResult> ProcessBucket(ITaskBuilder taskBuilder, TargetLoggingContext targetLoggingContext, TaskExecutionMode mode, Lookup lookupForInference, Lookup lookupForExecution)
        {
            WorkUnitResultCode aggregatedTaskResult = WorkUnitResultCode.Success;
            WorkUnitActionCode finalActionCode      = WorkUnitActionCode.Continue;
            WorkUnitResult     lastResult           = new WorkUnitResult(WorkUnitResultCode.Success, WorkUnitActionCode.Continue, null);

            try
            {
                // Grab the task builder so if cancel is called it will have something to operate on.
                _currentTaskBuilder = taskBuilder;

                int currentTask = 0;

                // Walk through all of the tasks and execute them in order.
                for (; (currentTask < _target.Children.Count) && !_cancellationToken.IsCancellationRequested; ++currentTask)
                {
                    ProjectTargetInstanceChild targetChildInstance = _target.Children[currentTask];

                    if (DebuggerManager.DebuggingEnabled)
                    {
                        DebuggerManager.EnterState(targetChildInstance.Location, lookupForExecution.GlobalsForDebugging /* does not matter which lookup we get this from */);
                    }

                    // Execute the task.
                    lastResult = await taskBuilder.ExecuteTask(targetLoggingContext, _requestEntry, _targetBuilderCallback, targetChildInstance, mode, lookupForInference, lookupForExecution, _cancellationToken);

                    if (DebuggerManager.DebuggingEnabled)
                    {
                        DebuggerManager.LeaveState(targetChildInstance.Location);
                    }

                    if (lastResult.ResultCode == WorkUnitResultCode.Failed)
                    {
                        aggregatedTaskResult = WorkUnitResultCode.Failed;
                    }
                    else if (lastResult.ResultCode == WorkUnitResultCode.Success && aggregatedTaskResult != WorkUnitResultCode.Failed)
                    {
                        aggregatedTaskResult = WorkUnitResultCode.Success;
                    }

                    if (lastResult.ActionCode == WorkUnitActionCode.Stop)
                    {
                        finalActionCode = WorkUnitActionCode.Stop;
                        break;
                    }
                }

                if (_cancellationToken.IsCancellationRequested)
                {
                    aggregatedTaskResult = WorkUnitResultCode.Canceled;
                    finalActionCode      = WorkUnitActionCode.Stop;
                }
            }
            finally
            {
                _currentTaskBuilder = null;
            }

            return(new WorkUnitResult(aggregatedTaskResult, finalActionCode, lastResult.Exception));
        }
Esempio n. 3
0
 private void EndRun(DebuggerManager obj)
 {
     Common.RunInUI(() => {
         m_view.m_leftLayoutAnchorablePane.Children.Remove(m_layoutAnchorable);
         m_layoutAnchorable = null;
     });
 }
Esempio n. 4
0
        public void UpdateElements()
        {
            treeControl.Tree.BeginUpdate();
            treeControl.Nodes.Clear();

            DebuggerManager debugManager = PluginMain.debugManager;

            foreach (String item in watches)
            {
                DataNode node = new DataNode(item);                 // todo, introduce new Node types.
                try
                {
                    Variable var = debugManager.EvaluateCurrent(item);
                    if (var != null)
                    {
                        node = new DataNode(var);
                    }
                }
                catch { }
                node.Text = item;
                treeControl.AddNode(node);
            }
            treeControl.Tree.EndUpdate();
            treeControl.Enabled = true;
        }
Esempio n. 5
0
 private void OnDestroy()
 {
     if (m_DebuggerManager != null)
     {
         m_DebuggerManager.Shutdown();
         m_DebuggerManager = null;
     }
 }
Esempio n. 6
0
 private void BeginRun(DebuggerManager obj)
 {
     m_layoutAnchorable          = new LayoutAnchorable();
     m_layoutAnchorable.CanClose = false;
     m_layoutAnchorable.CanHide  = false;
     m_layoutAnchorable.Title    = ResxIF.GetString("VariableTracking"); // 变量跟踪
     m_layoutAnchorable.IsActive = true;
     m_layoutAnchorable.Content  = new LocalsContent();
     m_view.m_leftLayoutAnchorablePane.Children.Add(m_layoutAnchorable);
 }
Esempio n. 7
0
 private void BeginRun(DebuggerManager obj)
 {
     m_layoutAnchorable          = new LayoutAnchorable();
     m_layoutAnchorable.CanClose = false;
     m_layoutAnchorable.CanHide  = false;
     m_layoutAnchorable.Title    = "变量跟踪";
     m_layoutAnchorable.IsActive = true;
     m_layoutAnchorable.Content  = new LocalsContent();
     m_view.m_leftLayoutAnchorablePane.Children.Add(m_layoutAnchorable);
 }
Esempio n. 8
0
        /// <summary>
        /// 游戏框架组件初始化。
        /// </summary>
        private void Awake()
        {
            DontDestroyOnLoad(gameObject);
            //Todo 默认窗口大小适配
            DefaultWindowScale = (float)Screen.height / DefaultWindowRect.height;

            m_DebuggerManager = new DebuggerManager();

            if (m_ActiveWindow == DebuggerActiveWindowType.Auto)
            {
                ActiveWindow = Debug.isDebugBuild;
            }
            else
            {
                ActiveWindow = (m_ActiveWindow == DebuggerActiveWindowType.Open);
            }

            m_FpsCounter = new FpsCounter(0.5f);
        }
Esempio n. 9
0
 public void Update()
 {
     if (_gameState == GameState.InGame && _uiState == InGameInterfaceDisplayState.Dialogue)
     {
         if ((Input.GetMouseButtonDown(0) && _needDisableClick == false) || Input.GetKeyDown(KeyCode.Space))
         {
             Next();
         }
     }
     if (Input.GetKeyDown(KeyCode.Escape))
     {
         if (_debuggerPanel.activeSelf == true)
         {
             _debuggerPanel.SetActive(false);
         }
         else
         {
             _debuggerPanel.SetActive(true);
             DebuggerManager.GetInstance().Init();
         }
     }
 }
Esempio n. 10
0
        internal static void Init()
        {
            Logger.Info("Game initializing.");

            DataModel.Workspace = Workspace = DataModel.GetService <Workspace>();
            Workspace.SetGame(DataModel);

            DataModel.GetService <RunService>();
            DataModel.GetService <ContentProvider>();
            DataModel.GetService <InputService>();
            DataModel.GetService <SoundService>();
            DataModel.GetService <ReplicatedStorage>();
            DataModel.GetService <ServerStorage>();
            DataModel.GetService <ServerScriptService>();
            DataModel.GetService <ReplayService>();
            DataModel.GetService <HistoryService>();
            DataModel.GetService <SocialService>();
            DataModel.GetService <ContextActionService>();

            Analytics       = DataModel.GetService <AnalyticsService>();
            Players         = DataModel.GetService <Players>();
            Lighting        = DataModel.GetService <Lighting>();
            Selection       = DataModel.GetService <SelectionService>();
            Selection.Name  = "Selection";
            CoreEnvironment = new CoreEnvironment();
            StarterGui      = new StarterGui {
                Parent = DataModel, ParentLocked = true
            };

            DebuggerManager = new DebuggerManager();


            DataModel.IsLoaded = true;
            DataModel.Loaded.Fire();
            IsInitialized = true;
            Initialized?.Invoke(null, null);
            Logger.Info("Game initialized.");
        }
Esempio n. 11
0
 public ushort invokeReadMemory16BitViaRegistryValue(string registryName)
 {
     return(readMemory16BitDelegate(DebuggerManager.getRegistryValueByName(a_Z80Registers, registryName)));
 }
Esempio n. 12
0
        public static Func <bool> EmitCondition(ref IDebuggable i_spectrum, BreakpointInfo i_breakpointInfo)
        {
            Func <bool> o_ILOut = null;

            if (i_breakpointInfo.AccessType == BreakPointConditionType.registryVsValue)
            {
                //e.g. PC == #0038
                Type[]        args          = { typeof(CpuRegs) };
                DynamicMethod dynamicMethod = new DynamicMethod(
                    "RegVsValue",
                    typeof(bool),            //return type
                    args,                    //arguments for the method
                    typeof(CpuRegs).Module); //module as input

                ILGenerator il = dynamicMethod.GetILGenerator();

                //1.Arg0 - registry
                il.Emit(OpCodes.Ldarg_0); // load m_spectrum.CPU.regs on stack
                FieldInfo testInfo1 = typeof(CpuRegs).GetField(i_breakpointInfo.LeftCondition, BindingFlags.Public | BindingFlags.Instance);
                il.Emit(OpCodes.Ldfld, testInfo1);

                //2.Arg1 - number
                il.Emit(OpCodes.Ldc_I4, (int)i_breakpointInfo.RightValue);

                //3.Compare
                EmitComparison(il, i_breakpointInfo.ConditionTypeSign);
                il.Emit(OpCodes.Ret); //Return: 1 => true(breakpoint is reached) otherwise 0 => false

                o_ILOut = (Func <bool>)dynamicMethod.CreateDelegate(typeof(Func <bool>), i_spectrum.CPU.regs);
            }
            else if (i_breakpointInfo.AccessType == BreakPointConditionType.flagVsValue)
            {
                //e.g.: fZ == 1
                Type[]        args          = { typeof(CpuRegs) };
                DynamicMethod dynamicMethod = new DynamicMethod(
                    "FlagVsValue",
                    typeof(bool),            //return type
                    args,                    //arguments for the method
                    typeof(CpuRegs).Module); //module as input

                ILGenerator il = dynamicMethod.GetILGenerator();

                //1.Arg0 - flag
                il.Emit(OpCodes.Ldarg_0);     // load m_spectrum.CPU.regs on stack
                FieldInfo testInfo1 = typeof(CpuRegs).GetField("AF", BindingFlags.Public | BindingFlags.Instance);
                il.Emit(OpCodes.Ldfld, testInfo1);

                //get flag value(0 or 1)
                switch (i_breakpointInfo.LeftCondition)
                {
                case "FS":
                    il.Emit(OpCodes.Ldc_I4, 0x80);
                    break;

                case "FZ":
                    il.Emit(OpCodes.Ldc_I4, 0x40);
                    break;

                case "FH":
                    il.Emit(OpCodes.Ldc_I4, 0x10);
                    break;

                case "FPV":
                    il.Emit(OpCodes.Ldc_I4, 0x04);
                    break;

                case "FN":
                    il.Emit(OpCodes.Ldc_I4, 0x02);
                    break;

                case "FC":
                    il.Emit(OpCodes.Ldc_I4, 0x01);
                    break;

                default:
                    throw new CommandParseException("Incorrect flag in condition emit...");
                }
                il.Emit(OpCodes.And);     //get flag value from F registry

                if (i_breakpointInfo.ConditionTypeSign == "==" && i_breakpointInfo.RightValue > 0)
                {
                    i_breakpointInfo.RightValue        = 0;
                    i_breakpointInfo.ConditionTypeSign = "!=";
                }

                //2. Arg1 - right condition(must a number)
                il.Emit(OpCodes.Ldc_I4, (int)i_breakpointInfo.RightValue);

                //3. Compare
                EmitComparison(il, i_breakpointInfo.ConditionTypeSign);
                il.Emit(OpCodes.Ret); //Return: 1 => true(breakpoint is reached) otherwise 0 => false

                o_ILOut = (Func <bool>)dynamicMethod.CreateDelegate(typeof(Func <bool>), i_spectrum.CPU.regs);
            }
            else if (i_breakpointInfo.AccessType == BreakPointConditionType.memoryVsValue)
            {
                //e.g. (16384) == #FF00
                //ToDo: Because it is not possible to dynamically emit code for interface method(IDebuggable.ReadMemory)
                //      I temporary wrapped it into custom wrapper.
                InterfaceWrapper middleMan = new InterfaceWrapper();
                middleMan.wrapInterface(i_spectrum);

                MethodInfo ReadMemoryMethod;
                if (i_breakpointInfo.RightValue > 0xFF)
                {
                    ReadMemoryMethod = typeof(InterfaceWrapper).GetMethod("invokeReadMemory16Bit",
                                                                          BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
                                                                          , null
                                                                          , new Type[] { typeof(ushort) }
                                                                          , null);
                }
                else
                {
                    ReadMemoryMethod = typeof(InterfaceWrapper).GetMethod("invokeReadMemory8Bit",
                                                                          BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
                                                                          , null
                                                                          , new Type[] { typeof(ushort) }
                                                                          , null);
                }

                DynamicMethod dynamicMethod = new DynamicMethod("ReadMemory"
                                                                , typeof(bool)
                                                                , new Type[] { typeof(InterfaceWrapper) }
                                                                , typeof(InterfaceWrapper).Module
                                                                );

                ILGenerator IL = dynamicMethod.GetILGenerator();

                //Arg0 - memory reference(static), e.g. (16384)
                IL.Emit(OpCodes.Ldarg_0);                            // load InterfaceWrapper on stack
                IL.Emit(OpCodes.Ldc_I4, i_breakpointInfo.LeftValue); // method parameter(for ReadMemoryMethod)
                IL.Emit(OpCodes.Call, ReadMemoryMethod);

                //Arg1
                IL.Emit(OpCodes.Ldc_I4, i_breakpointInfo.RightValue); // <- compare to 8 or 16bit

                EmitComparison(IL, i_breakpointInfo.ConditionTypeSign);
                IL.Emit(OpCodes.Ret); //Return: 1 => true(breakpoint is reached) otherwise 0 => false

                o_ILOut = (Func <bool>)dynamicMethod.CreateDelegate(typeof(Func <bool>), middleMan);
            }
            else if (i_breakpointInfo.AccessType == BreakPointConditionType.registryMemoryReferenceVsValue)
            {
                // e.g.: (PC) == #D155 - instruction breakpoint
                //ToDo: Because it is not possible to dynamically emit code for interface method(IDebuggable.ReadMemory)
                //      I temporary wrapped it into custom wrapper.
                InterfaceWrapper middleMan = new InterfaceWrapper();
                middleMan.wrapInterface(i_spectrum);
                middleMan.wrapFields(i_spectrum.CPU.regs);

                MethodInfo ReadMemoryMethod;
                //Type[] args = { typeof(REGS) };
                if (i_breakpointInfo.RightValue > 0xFF)
                {
                    ReadMemoryMethod = typeof(InterfaceWrapper).GetMethod("invokeReadMemory16BitViaRegistryValue",
                                                                          BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
                                                                          , null
                                                                          , new Type[] { typeof(string) }
                                                                          , null);
                }
                else
                {
                    ReadMemoryMethod = typeof(InterfaceWrapper).GetMethod("invokeReadMemory8BitViaRegistryValue",
                                                                          BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
                                                                          , null
                                                                          , new Type[] { typeof(string) }
                                                                          , null);
                }

                DynamicMethod dynamicMethod = new DynamicMethod("ReadMemoryViaRegistry", typeof(bool), new Type[] { typeof(InterfaceWrapper) });

                ILGenerator IL = dynamicMethod.GetILGenerator();

                //Arg0, e.g. (PC)
                IL.Emit(OpCodes.Ldarg_0); // load InterfaceWrapper on stack

                string registry = DebuggerManager.getRegistryFromReference(i_breakpointInfo.LeftCondition);
                IL.Emit(OpCodes.Ldstr, registry);
                IL.Emit(OpCodes.Call, ReadMemoryMethod);

                //Arg1, number(right condition)
                IL.Emit(OpCodes.Ldc_I4, i_breakpointInfo.RightValue); // <- compare to 8 or 16bit

                EmitComparison(IL, i_breakpointInfo.ConditionTypeSign);
                IL.Emit(OpCodes.Ret); //Return: 1 => true(breakpoint is reached) otherwise 0 => false

                o_ILOut = (Func <bool>)dynamicMethod.CreateDelegate(typeof(Func <bool>), middleMan);
            }

            return(o_ILOut);
        }