示例#1
0
文件: Client.cs 项目: webconfig/Ballz
        private void HandleMatchStart(GameStartInfo startInfo)
        {
            var settings = MatchSettings.Deserialize(startInfo.Settings);

            Ballz.The().Network.StartNetworkGame(settings, startInfo.YourPlayerId);
            Ballz.The().Match.IsRemoteControlled = true;
        }
示例#2
0
    public GameStartInfo DoModal(GameStartInfo[] startInfos)
    {
        GameStartInfo gameInfo = null;

        this.WindowManager.InitializeText();

        if (this.WindowManager.MessageState.Active)
        {
            this.WindowManager.CloseWindow();
        }

        if (startInfos.Length > 0)
        {
            Array.Sort <GameStartInfo>(startInfos, new GameStartInfoComparer());

            gameInfo = this.SelectGame(startInfos);
        }
        else
        {
            this.Interpreter.Prompt(UserInterface.GameSelectionNoGameFound);
        }

        this.Interpreter.ShutdownText();

        return(gameInfo);
    }
示例#3
0
        private static void scanAndAppend(string directory)
        {
            activeScannings++;

            Task.Factory.StartNew(() => getGamesInFolder(directory)).ContinueWith(games =>
            {
                lock (games)
                {
                    foreach (var game in games.Result)
                    {
                        var name = gameChecker.getDisplayName(game);

                        if (!installedGames.ContainsKey(name))
                        {
                            GameStartInfo t = new GameStartInfo();
                            t.location      = game;
                            if (game.Contains("steamapps"))
                            {
                                t.platform = GameStartInfo.Platform.Steam;
                            }
                            else
                            {
                                t.platform = GameStartInfo.Platform.Unknown;
                            }

                            installedGames.Add(name, t);
                        }
                    }
                }

                activeScannings--;
            }).ConfigureAwait(true);
        }
        protected void StartGame(GameCommandArguments gameArgs, GameStartInfo gameStartInfo, string?iconFile = null)
        {
            if (!Exists())
            {
                throw new Exception("Game was not found");
            }
            var startingArguments = new GameStartingEventArgs(this, gameArgs, gameStartInfo.BuildType);

            OnGameStarting(startingArguments);
            if (startingArguments.Cancel)
            {
                return;
            }

            gameArgs.Validate();
            var processStartInfo = CreateGameProcess(gameArgs.ToArgs(), gameStartInfo.Executable);

            Process process;

            try
            {
                process = StartGameProcess(processStartInfo, iconFile);
            }
            catch (Exception e)
            {
                throw new GameStartException(e.Message, e);
            }

            OnGameStarted(new GameStartedEventArgs(this, gameArgs, gameStartInfo.BuildType, process));
        }
示例#5
0
    public static string GenerateServerAcceptJoinMessage(GameStartInfo gsi)
    {
        NetworkingMessageType msgType = NetworkingMessageType.SERVER_JOIN_RESPONSE;

        NetworkingMessage msg = new NetworkingMessage(msgType);

        msg.content = ToJson(gsi);
        return(ToJson(msg));
    }
示例#6
0
        private static GameStartInfo FindGame(GameDetector detector, IGameContainer container)
        {
            GameStartInfo startInfo = null;

            var result = detector.Detect(container);

            if (result.Detected)
            {
                string id = ResourceLoader.GetGameId(container);

                startInfo = new GameStartInfo(container, id, result.Platform, result.Interpreter, result.Name, result.Version);
            }

            return(startInfo);
        }
示例#7
0
        private int RunGame(string folder)
        {
            if (ResourceLoader.IsGameFolder(new GameFolder(folder)))
            {
                GameStartInfo startInfo = GameFinder.FindGame(folder);
                if (startInfo != null)
                {
                    this.interpreter.Start(startInfo, this.ReadPreferences());

                    return(0);
                }
            }

            return(-1);
        }
示例#8
0
    void HandleAcceptJoin(NetworkingMessage inmsg)
    {
        GameStartInfo gsi      = NetworkingMessageTranslator.ParseServerAcceptJoin(inmsg.content);
        int           playerID = gsi.playerID;

        if (playerID > -1)
        {
            this.state = ClientState.JOIN_ACCEPTED;
            Debug.Log("Client Joined Server. PlayerID is " + playerID + " ... Waiting for game to start");
            playerController.playerID = playerID;
            gr.UpdateTerrainSeed(gsi.terrainSeed);
        }
        else
        {
            Debug.Log("Client was not allowed to connect... Disconnecting");
            SendDisconnect();
            playerController.OnFailedToConnect();
        }
    }
        public void DebugGame(GameCommandArguments?args = null, string?iconFile = null, bool fallbackToNormal = true)
        {
            GameStartInfo startInfo;

            if (DebugBuildExists)
            {
                var exeFile = new FileInfo(DebugExePath);
                startInfo = new GameStartInfo(exeFile, GameBuildType.Debug);
            }
            else
            {
                if (!fallbackToNormal)
                {
                    throw new GameStartException($"Unable to find debug executable {DebugExeName}");
                }

                var exeFile = new FileInfo(Path.Combine(Directory.FullName, GameExeFileName));
                startInfo = new GameStartInfo(exeFile, GameBuildType.Release);
            }
            args ??= new GameCommandArguments();
            StartGame(args, startInfo, iconFile);
        }
示例#10
0
        private void DumpGameFrames()
        {
            var msg   = new Msg_RepMissFrame();
            int count = System.Math.Min((Tick - 1), allHistoryFrames.Count);

            if (count <= 0)
            {
                return;
            }
            var writer = new Serializer();

            GameStartInfo.Serialize(writer);
            var frames = new ServerFrame[count];

            for (int i = 0; i < count; i++)
            {
                frames[i] = allHistoryFrames[i];
                Logging.Debug.Assert(frames[i] != null, "!!!!!!!!!!!!!!!!!");
            }

            msg.startTick = frames[0].tick;
            msg.frames    = frames;
            msg.Serialize(writer);
            var bytes = Compressor.Compress(writer);
            var path  = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                     "../Record/" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + GameType + "_" + GameId +
                                     ".record");
            var dir = Path.GetDirectoryName(path);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            Log("Create Record " + path);
            File.WriteAllBytes(path, bytes);
        }
示例#11
0
        //Začátek hry
        private void GameStartInfoDelegatePointer(PacketHeader packetheader, Connection connection, GameStartInfo info)
        {
            _gameId = info.GameId;

            if (info.IsStarting)
            {
                MessageBox.Show("Hra začala, jste na řadě!");
                Invoke(new NextTurnDelegate(NextTurn), true);
            }
            else
            {
                MessageBox.Show("Hra začala, protihráč střílí první!");
            }
        }
示例#12
0
 public void StartGame(Update update, bool chaos = false)
 {
     var info = new GameStartInfo
     {
         Chat = update.Message.Chat,
         Chaos = chaos,
         User = update.Message.From
     };
     this.Broadcast(JsonConvert.SerializeObject(info));
     this.Games.Add(new GameInfo
     {
         ChatGroup = info.Chat.Title,
         Language = "English",
         GroupId = info.Chat.Id,
         NodeId = ClientId,
         Users = new HashSet<int> {update.Message.From.Id},
         State = GameState.Joining
     });
 }
示例#13
0
文件: Server.cs 项目: webconfig/Ballz
        public void StartNetworkGame(MatchSettings gameSettings)
        {
            gameSettings.Teams = new List <Team>();
            var idCounter = 0;

            foreach (var playerCon in PlayersByConnection.Values)
            {
                var team = new Team
                {
                    Id             = idCounter++,
                    Name           = playerCon.PlayerName,
                    ControlledByAI = false,
                    NumberOfBallz  = 1,
                };

                gameSettings.Teams.Add(team);

                playerCon.MatchPlayerId = team.Id;
                PlayersById[team.Id]    = playerCon;
            }

            gameSettings.Teams.Add(new Team
            {
                Id             = idCounter++,
                Name           = "None",
                ControlledByAI = false,
                NumberOfBallz  = 1,
            });

            // Create map etc.
            gameSettings.GameMode.InitializeSession(Ballz.The(), gameSettings);
            //// Broadcast gameSettings incl. map to clients
            var serializedSettings = gameSettings.Serialize();

            foreach (var playerCon in PlayersByConnection.Values)
            {
                var startInfo = new GameStartInfo
                {
                    YourPlayerId = playerCon.MatchPlayerId,
                    Settings     = serializedSettings
                };

                SendToPlayer(playerCon.MatchPlayerId, startInfo);
            }

            var localPlayer = PlayersByConnection[-1];

            // Start our game session
            Ballz.The().Logic.StartGame(gameSettings, isMultiplayer: true, localPlayerId: localPlayer.MatchPlayerId);

            Ballz.The().Match.World.StaticGeometry.TerrainModified += OnTerrainModified;
            Ballz.The().Match.World.EntityRemoved += OnEntityRemoved;

            foreach (var playerCon in PlayersByConnection.Values)
            {
                playerCon.MatchPlayer = Ballz.The().Match.PlayerById(playerCon.MatchPlayerId);
            }

            SendWorldState();
            WorldSyncTimer.Start();
            GameRunning = true;
        }
示例#14
0
        private void scanAndAppend(string directory)
        {
            activeScannings++;
            metroProgressBar1.ProgressBarStyle      = ProgressBarStyle.Marquee;
            metroProgressBar1.MarqueeAnimationSpeed = 10;
            lblScanProgress.Text    = $"scanning for games in {activeScannings} folder(s)";
            lblScanProgress.Visible = true;
            this.Refresh();

            Task.Factory.StartNew(() => getGamesInFolder(directory)).ContinueWith(games =>
            {
                listBox1.Invoke(new Action(() =>
                {
                    foreach (var game in games.Result)
                    {
                        var name = gameChecker.getDisplayName(game);

                        if (!listBox1.Items.Contains(name))
                        {
                            GameStartInfo t = new GameStartInfo();
                            t.location      = game;
                            if (game.Contains("steamapps"))
                            {
                                t.platform = GameStartInfo.Platform.Steam;
                            }
                            else
                            {
                                t.platform = GameStartInfo.Platform.Unknown;
                            }

                            listBox1.Items.Add(name);
                            installedGames.Add(name, t);
                        }
                    }
                }));

                activeScannings--;

                if (activeScannings == 0)
                {
                    metroProgressBar1.Invoke(new Action(() =>
                    {
                        metroProgressBar1.ProgressBarStyle = ProgressBarStyle.Continuous;
                        metroProgressBar1.Value            = 0;
                    }));

                    lblScanProgress.Invoke(new Action(() =>
                    {
                        lblScanProgress.Text    = $"finished!";
                        lblScanProgress.Visible = false;
                    }));
                }
                else
                {
                    lblScanProgress.Invoke(new Action(() =>
                    {
                        lblScanProgress.Text    = $"scanning for games in {activeScannings} folder(s)";
                        lblScanProgress.Visible = true;
                    }));
                }
            }).ConfigureAwait(true);
        }