Пример #1
0
        public IActionResult GameView()
        {
            string player_id = CookiesGetSet.getCookies("Player_Id", HttpContext);

            string checkres = _gs.CheckGameState(player_id);

            if (checkres != "~/Game/GameView")
            {
                return(Redirect(checkres));
            }



            StartGameData res = _gs.InitGame(player_id);

            ViewBag.player1name = res.player1name;
            ViewBag.player2name = res.player2name;
            ViewBag.p1field     = res.player1field;
            ViewBag.p2field     = res.player2field;
            //  ViewBag.waitreplay = Parameters.WaitReplayGame;
            int min = Parameters.WaitReplayGame / 60;
            int sec = Parameters.WaitReplayGame % 60;

            ViewBag.waitreplay = min + ":" + (sec < 10 ? "0" + sec.ToString() : sec.ToString());



            min = Parameters.MoveTime / 60;
            sec = Parameters.MoveTime % 60;
            ViewBag.movetime = min + ":" + (sec < 10 ? "0" + sec.ToString() : sec.ToString());
            return(View());
        }
Пример #2
0
        private static void ExecuteTaskOnThread(object state)
        {
            StartGameData data = (StartGameData)state;

            ExecuteTask(data);

            Application.Exit();
        }
Пример #3
0
        public void onConnected(ConnectData data) {
            this.ClientId = data.ClientId;
            _welcomeDiv.innerHTML = "Connected.";

            StartGameData startGameData = new StartGameData(this.ClientId);
            startGameData.ClientId = this.ClientId;
            Server.Send(startGameData);
        }
Пример #4
0
    // Use this for initialization
    void Start()
    {
        //data = GameObject.FindGameObjectWithTag("startGameData").GetComponent<StartGameData>();
        Destroy(GameObject.FindGameObjectWithTag("startGameData"));
        data = new StartGameData {
            StepTime = 40, CountField = 2, CountPlayer = 4, SpawnPlayer = true, SpawnPort = false
        };

        Ports             = new List <KeyValuePair <Teleport, Teleport> >();
        Mode              = Mode.none;
        RemainSpawnPlayer = data.CountPlayer;

        Fields = new Field[data.CountField];
        Camera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <CameraScr>();

        for (int i = 0; i < data.CountField; ++i)
        {
            var field = new GameObject();
            field.transform.position = new Vector3(-10000 + i * 10000, 0, 0);
            field.AddComponent <Field>();
            Fields[i] = field.GetComponent <Field>();
            Fields[i].Init(6, TypeField.square, MethodCreating.newField, this);
        }
        // preparing camera
        CurrentField = Fields[0];

        Camera.Field  = CurrentField;
        Camera.Fi     = 0;
        Camera.Psi    = Math.PI / 3;
        Camera.Radius = Math.Sqrt((CurrentField.Center - CurrentField.transform.position).sqrMagnitude) * 1.7;
        Camera.Transforming();


        // preparing dropdown for cutting, spawn
        var panel = transform.GetChild(4).GetComponent <Dropdown>();

        if (panel == null)
        {
            throw new Exception("incorrect child index");
        }
        var listOption = new List <Dropdown.OptionData>()
        {
            new Dropdown.OptionData("none"),
            new Dropdown.OptionData("cutting field")
        };

        if (!data.SpawnPlayer)
        {
            listOption.Add(new Dropdown.OptionData("spawn player"));
        }
        else
        {
            RemainSpawnPlayer = 0;
            next.interactable = true;
        }

        panel.AddOptions(listOption);
    }
Пример #5
0
        public void onStartGame(StartGameData data)
        {
            _turnClientId = "";
            _figure = EState.empty;

            _welcomeDiv.innerHTML = "";
            if (_welcomeDiv.parentNode != null)
            {
                _welcomeDiv.parentNode.removeChild(_welcomeDiv);
            }

            if (null != _tableCnt && _tableCnt.parentNode != null)
            {
                _tableCnt.parentNode.removeChild(_tableCnt);
            }

            if (null != _turn && _turn.parentNode != null)
            {
                _turn.parentNode.removeChild(_turn);
            }

            _turn = new HtmlDivElement();
            js.addClass(_turn, "turn");
            _div.appendChild(_turn);

            _tableCnt = new HtmlSpanElement();
            js.addClass(_tableCnt, "tableCnt");

            _table = new HtmlTableElement();
            _tableCnt.appendChild(_table);
            js.attach(_table, "click", onTableClick);
            js.attach(_table, "touchstart", onTableClick);
            js.addClass(_table, "table");
            for (int y = 0; y < 3; ++y)
            {
                var row = new HtmlTableRowElement();
                _table.appendChild(row);
                row.setAttribute("rowIdx", y.ToString());
                for (int x = 0; x < 3; ++x)
                {
                    var cell = new HtmlTableCellElement();
                    row.appendChild(cell);
                    js.addClass(cell, "tableCell");
                }
            }
            _div.appendChild(_tableCnt);


            //_div.innerHTML += "Start Game ID = " + response.GameId + "<br/>";
            _figure = (data.FirstClientId == ClientId) ? EState.blue : EState.red;
            //_div.innerHTML += "You are " + _figure + "<br/>";

            _turnClientId = data.FirstClientId;

            RefreshTurn();
        }
Пример #6
0
        public StartGameData InitGame(string player_id)
        {
            StartGameData res     = new StartGameData();
            Player        player  = _dm.Ps.GetPlayer(convertId(player_id), true);
            Room          r       = _dm.Rs.GetRoom(player.roomid);
            Player        player2 = _dm.Rs.GetPlayer2(player, r);

            res.player2name  = player2.login;
            res.player1name  = player.login;
            res.player1field = player.field;
            res.player2field = player2.field;

            return(res);
        }
Пример #7
0
    public void Next()
    {
        if (transform.childCount > 4)
        {
            Destroy(transform.GetChild(4).gameObject);
            Destroy(transform.GetChild(3).gameObject);
            Destroy(transform.GetChild(2).gameObject);
            Destroy(transform.GetChild(1).gameObject);
        }
        if (data.SpawnPort)
        {
            AutoSpawnPort();
        }
        else
        {
            if (Mode != Mode.spawnPort1)
            {
                Mode = Mode.spawnPort1;
                next.interactable = CheckingConnection();
                return;
            }
        }
        if (data.SpawnPlayer)
        {
            AutoSpawnPlayer();
        }
        var text = transform.GetChild(transform.childCount - 1).GetComponent <Text>();

        Destroy(next.gameObject);
        Mode  = Mode.playing;
        next  = null;
        Port  = null;
        Ports = null;
        data  = null;

        foreach (var item in Fields)
        {
            item.WhitePrintingNodes();
        }

        text.transform.position -= new Vector3(0, 70, 0);
        Main = new GameController(Fields, text);
    }
Пример #8
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Log.WriteLine("Invalid usage! Need arguments to proceed!", Palette.Error);
                return;
            }

            // We need this, else Windows will fake
            // all the data about monitors inside the application
            User32Util.SetProcessDpiAwareness(ProcessDPIAwareness.ProcessPerMonitorDPIAware);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            NotifyIcon  notifyIcon  = new NotifyIcon();
            ContextMenu contextMenu = new ContextMenu();

            MenuItem exitMenuItem = new MenuItem();

            contextMenu.MenuItems.AddRange(new MenuItem[] { exitMenuItem });
            exitMenuItem.Index  = 0;
            exitMenuItem.Text   = "Exit";
            exitMenuItem.Click += new EventHandler(exitClick);

            notifyIcon.Icon        = Resources.icon;
            notifyIcon.Text        = "Nucleus Coop GameTasks";
            notifyIcon.ContextMenu = contextMenu;
            notifyIcon.Visible     = true;

            string        base64 = Encoding.UTF8.GetString(Convert.FromBase64String(args[0]));
            StartGameData data   = JsonConvert.DeserializeObject <StartGameData>(base64);

            ThreadPool.QueueUserWorkItem(ExecuteTaskOnThread, data);

            Application.Run();
            notifyIcon.Visible = false;
        }
Пример #9
0
 private void SetGameState()
 {
     _startGameData = _gameStateModule.StartGameData.value;
     _gameStateModule.StartGameData = Option <StartGameData> .None;
 }
Пример #10
0
        public RequestResult <string> Play()
        {
            List <PlayerInfo> players = profile.PlayerData;

            for (int i = 0; i < players.Count; i++)
            {
                players[i].PlayerID = i;
            }
            RequestResult <String> result = new RequestResult <String>();

            List <HandlerContext> contexts = new List <HandlerContext>();

            for (int i = 0; i < players.Count; i++)
            {
                PlayerInfo player = players[i];

                HandlerContext context = handlerManager.HandlerData.CreateContext(profile, player, hasKeyboardPlayer);
                contexts.Add(context);

                context.PlayerID = player.PlayerID;

                List <HandlerModule> modules = player.Modules;
                for (int j = 0; j < modules.Count; j++)
                {
                    modules[j].PrePlayPlayer(i, context);
                }
            }

            // get all the SymlinkData from each players IOModule
            // and start the StartGame application to symlink them
            List <SymlinkGameData> symData = new List <SymlinkGameData>();

            for (int i = 0; i < players.Count; i++)
            {
                PlayerInfo      player = players[i];
                IOModule        mod    = GetModule <IOModule>(player);
                SymlinkGameData data   = mod.SymlinkData;
                symData.Add(data);
            }
            StartGameData symStartData = StartGameUtil.BuildSymlinkGameData(symData.ToArray());

            // check if we need to kill mutexes
            bool killingMutexes = false;

            if (handlerManager.HandlerData.KillMutex?.Length > 0)
            {
                // need to also kill mutexes
                killingMutexes = true;
                StartGameData scanKillData = StartGameUtil.BuildScanKillMutexData(Path.GetFileNameWithoutExtension(userGame.ExePath), players.Count, handlerManager.HandlerData.KillMutex);
                StartGameUtil.RunMultipleTasks(new StartGameData[] { symStartData, scanKillData }, true);

                // wait for confirmation file that the folders were symlinked
                // (RunMultipleTasks doesnt wait for process to finish)
                string dataFile = StartGameUtil.GetStartDataPath();
                for (; ;)
                {
                    if (File.Exists(dataFile))
                    {
                        try {
                            string txt = File.ReadAllText(dataFile);
                            bool   res;
                            if (bool.TryParse(txt, out res))
                            {
                                break;
                            }
                        } catch {
                        }
                    }
                    Thread.Sleep(250);
                }
                File.Delete(dataFile);
            }
            else
            {
                // just symlink the folders
                StartGameUtil.RunPreBuiltData(symStartData, true);
            }

            for (int i = 0; i < players.Count; i++)
            {
                PlayerInfo     player  = players[i];
                HandlerContext context = contexts[i];
                handlerManager.Play(context, player);

                List <HandlerModule> modules = player.Modules;
                for (int j = 0; j < modules.Count; j++)
                {
                    modules[j].PlayPlayer(i, context);
                }

                Thread.Sleep(TimeSpan.FromMilliseconds(handlerManager.HandlerData.PauseBetweenStarts));

                IGameProcessModule procModule = GetModule <IGameProcessModule>(player);
                if (handlerManager.HandlerData.WaitFullWindowLoad)
                {
                    for (; ;)
                    {
                        Thread.Sleep(100);

                        // check for window status
                        if (procModule.HasWindowSetup(player))
                        {
                            break;
                        }
                    }
                }

                if (killingMutexes)
                {
                    // wait for StartGame confirmation that mutexes were killed
                    string dataFile = StartGameUtil.GetStartDataPath();
                    for (; ;)
                    {
                        if (File.Exists(dataFile))
                        {
                            try {
                                string txt = File.ReadAllText(dataFile);
                                bool   res;
                                if (bool.TryParse(txt, out res))
                                {
                                    break;
                                }
                            } catch {
                            }
                        }
                        Thread.Sleep(250);
                    }
                    File.Delete(dataFile);
                }
            }

            return(result);
        }
Пример #11
0
        static void Main(string[] args)
        {
            // We need this, else Windows will fake
            // all the data about monitors inside the application
            User32Util.SetProcessDpiAwareness(ProcessDPIAwareness.ProcessPerMonitorDPIAware);

            if (args.Length == 0)
            {
                ConsoleU.WriteLine("Invalid usage! Need arguments to proceed!", Palette.Error);
                return;
            }

#if RELEASE
            try
#endif
            {
                string        base64 = Encoding.UTF8.GetString(Convert.FromBase64String(args[0]));
                StartGameData data   = JsonConvert.DeserializeObject <StartGameData>(base64);

                switch (data.Task)
                {
                case GameStarterTask.StartGame:
                {
                    string gamePath       = data.Parameters[0];
                    string gameArgs       = data.Parameters[1];
                    string gameWorkingDir = data.Parameters[2];

                    ConsoleU.WriteLine($"Start game: EXE: {gamePath} ARGS: {gameArgs} WORKDIR: {gameWorkingDir}", Palette.Feedback);
                    StartGame(gamePath, gameArgs, gameWorkingDir);
                }
                break;

                case GameStarterTask.KillMutex:
                {
                    string procId = data.Parameters[0];
                    ConsoleU.WriteLine($"Process ID {procId} request to kill mutexes", Palette.Wait);
                    proc = Process.GetProcessById(int.Parse(procId));

                    ConsoleU.WriteLine($"Trying to kill mutexes {data.Parameters.Length - 1} mutexes", Palette.Wait);
                    for (int j = 1; j < data.Parameters.Length; j++)
                    {
                        string m      = data.Parameters[j];
                        string prefix = $"({j}/{data.Parameters.Length - 1}) ";
                        ConsoleU.WriteLine(prefix + "Trying to kill mutex: " + m, Palette.Feedback);

                        if (!ProcessUtil.KillMutex(proc, m))
                        {
                            ConsoleU.WriteLine(prefix + "Mutex " + m + " could not be killed", Palette.Error);
                        }
                        else
                        {
                            ConsoleU.WriteLine(prefix + "Mutex killed " + m, Palette.Success);
                        }
                        Thread.Sleep(150);
                    }
                }
                break;

                case GameStarterTask.QueryMutex:
                {
                    string procId = data.Parameters[0];
                    ConsoleU.WriteLine($"Process ID {procId} request to be queried for mutexes", Palette.Wait);
                    proc = Process.GetProcessById(int.Parse(procId));

                    ConsoleU.WriteLine($"Trying to query for any mutex's existance", Palette.Wait);
                    for (int j = 0; j < data.Parameters.Length; j++)
                    {
                        string m      = data.Parameters[j];
                        string prefix = $"({j + 1}/{data.Parameters.Length}) ";
                        ConsoleU.WriteLine(prefix + "Trying to kill mutex: " + m, Palette.Feedback);

                        if (!ProcessUtil.KillMutex(proc, m))
                        {
                            ConsoleU.WriteLine(prefix + "Mutex " + m + " could not be killed", Palette.Error);
                        }
                        else
                        {
                            ConsoleU.WriteLine(prefix + "Mutex killed " + m, Palette.Success);
                        }
                        Thread.Sleep(150);
                    }
                }
                break;

                case GameStarterTask.FindProcessId:
                {
                    string procId = data.Parameters[0];
                    int    id     = int.Parse(procId);
                    try
                    {
                        proc = Process.GetProcessById(id);
                        ConsoleU.WriteLine($"Process ID {id} found!", Palette.Success);
                    }
                    catch
                    {
                        ConsoleU.WriteLine($"Process ID {id} not found", Palette.Error);
                    }
                }
                break;

                case GameStarterTask.ListMonitors:
                    break;
                }
            }
#if RELEASE
            catch (Exception ex)
            {
                ConsoleU.WriteLine(ex.Message);
            }
#endif
        }
Пример #12
0
        private static void ExecuteTask(StartGameData data)
        {
            switch (data.Task)
            {
            case GameStarterTask.StartGame: {
                string gamePath       = data.Parameters[0];
                string gameArgs       = data.Parameters[1];
                string gameWorkingDir = data.Parameters[2];

                ConsoleU.WriteLine($"Start game: EXE: {gamePath} ARGS: {gameArgs} WORKDIR: {gameWorkingDir}", Palette.Feedback);
                StartGame(gamePath, gameArgs, gameWorkingDir);
            }
            break;

            case GameStarterTask.KillMutex: {
                Log.WriteLine($"Kill Mutex Task");
                string   procId  = data.Parameters[0];
                string[] mutexes = new string[data.Parameters.Length - 1];
                for (int j = 1; j < data.Parameters.Length; j++)
                {
                    string m = data.Parameters[j];
                    mutexes[j - 1] = m;
                }
                KillMutex(procId, mutexes);
                WriteToDataFile(Assembly.GetEntryAssembly().Location, true.ToString());
            }
            break;

            case GameStarterTask.RenameMutex: {
                Log.WriteLine($"Rename Mutex Task");
                string   procId  = data.Parameters[0];
                string[] mutexes = new string[data.Parameters.Length - 1];
                for (int j = 1; j < data.Parameters.Length; j++)
                {
                    string m = data.Parameters[j];
                    mutexes[j - 1] = m;
                }
                KillMutex(procId, mutexes);
                WriteToDataFile(Assembly.GetEntryAssembly().Location, true.ToString());
            }
            break;

            case GameStarterTask.ScanKillMutex: {
                Log.WriteLine($"Scan Kill Mutex");

                List <int> processIds = new List <int>();

                for (int j = 0; j < data.Parameters.Length; j++)
                {
                    string        scanMutexDataRaw = data.Parameters[j];
                    ScanMutexData scanMutex        = JsonConvert.DeserializeObject <ScanMutexData>(scanMutexDataRaw);
                    Log.WriteLine($"Kill Mutex for process {scanMutex.ProcessName}");

                    for (; ;)
                    {
                        Process[] procs = Process.GetProcessesByName(scanMutex.ProcessName);
                        if (procs == null || procs.Length == 0)
                        {
                            Thread.Sleep(250);
                        }
                        else
                        {
                            // kill mutexes
                            bool killedMutexes = false;
                            for (int k = 0; k < procs.Length; k++)
                            {
                                Process p = procs[k];
                                if (processIds.Contains(p.Id))
                                {
                                    continue;
                                }

                                // start other process, as the mutexes are only truly killed
                                // when the process is ended
                                if (scanMutex.ShouldRename)
                                {
                                    StartGameUtil.RenameMutex(p, scanMutex.Mutexes);
                                }
                                else
                                {
                                    StartGameUtil.KillMutex(p, scanMutex.Mutexes);
                                }
                                //KillMutex(p.Id.ToString(), scanMutex.Mutexes);
                                processIds.Add(p.Id);
                                killedMutexes = true;
                                break;
                            }

                            if (killedMutexes)
                            {
                                Log.WriteLine($"Killed all mutexes for process {scanMutex.ProcessName}");
                                WriteToDataFile(Assembly.GetEntryAssembly().Location, true.ToString());
                                break;
                            }
                        }
                    }
                }
            }
            break;

            case GameStarterTask.MultipleTasks: {
                Log.WriteLine($"Multiple tasks");
                for (int j = 0; j < data.Parameters.Length; j++)
                {
                    string        taskDataRaw = data.Parameters[j];
                    StartGameData taskData    = JsonConvert.DeserializeObject <StartGameData>(taskDataRaw);

                    Log.WriteLine($"Executing task {j + 1}");
                    ExecuteTask(taskData);
                }
            }
            break;

            case GameStarterTask.QueryMutex: {
                string   procId  = data.Parameters[0];
                string[] mutexes = new string[data.Parameters.Length - 1];
                for (int j = 1; j < data.Parameters.Length; j++)
                {
                    string m = data.Parameters[j];
                    mutexes[j - 1] = m;
                }
            }
            break;

            case GameStarterTask.ListMonitors:
                break;

            case GameStarterTask.ScanGames: {
                // initialize game manager to read available handlers
                GameManager gameManager = new GameManager();

                List <string> games = new List <string>();
                for (int j = 0; j < data.Parameters.Length; j++)
                {
                    string driveName = data.Parameters[j];
                    //SearchStorageInfo info = JsonConvert.DeserializeObject<SearchStorageInfo>(storageData);
                    DriveInfo drive = new DriveInfo(driveName);

                    if (!drive.IsReady)
                    {
                        continue;
                    }

                    Log.WriteLine($"> Searching drive {drive.Name} for game executables");

                    Dictionary <ulong, FileNameAndParentFrn> allExes = new Dictionary <ulong, FileNameAndParentFrn>();
                    MFTReader mft = new MFTReader();
                    mft.Drive = drive.RootDirectory.FullName;

                    // TODO: search only for specific games?
                    mft.EnumerateVolume(out allExes, new string[] { ".exe" });

                    foreach (KeyValuePair <UInt64, FileNameAndParentFrn> entry in allExes)
                    {
                        FileNameAndParentFrn file = (FileNameAndParentFrn)entry.Value;

                        string name  = file.Name;
                        string lower = name.ToLower();

                        string path = mft.GetFullPath(file);
                        if (path.Contains("$Recycle.Bin") ||
                            path.Contains(@"\Instance"))
                        {
                            // noope
                            continue;
                        }

                        if (GameManager.Instance.AnyGame(lower))
                        {
                            Log.WriteLine($"Found game at path: {path}");
                            games.Add(path);
                        }
                    }
                }

                WriteToDataFile(Assembly.GetEntryAssembly().Location, JsonConvert.SerializeObject(games));
            }
            break;

            case GameStarterTask.SymlinkFolders:
                for (int j = 0; j < data.Parameters.Length; j++)
                {
                    string symData = data.Parameters[j];
                    Log.WriteLine($"Symlink game instance {j + 1}");

                    SymlinkGameData gameData = JsonConvert.DeserializeObject <SymlinkGameData>(symData);
                    int             exitCode;
                    WinDirectoryUtil.LinkDirectory(gameData.SourcePath, new DirectoryInfo(gameData.SourcePath), gameData.DestinationPath, out exitCode, gameData.DirExclusions, gameData.FileExclusions, gameData.FileCopies, true);
                }
                WriteToDataFile(Assembly.GetEntryAssembly().Location, true.ToString());
                break;
            }
        }
Пример #13
0
 public void StartGame(StartGameData data) {
     Client.inst.onStartGame(data);
 }
Пример #14
0
        public void onResetGame(ResetGameData resetGameData)
        {
            HtmlContext.console.log("reset game");

            StartGameData data = new StartGameData(ClientId);
            data.GameId = resetGameData.GameId;
            Server.Send(data);
        }