public LobbyMenu(bool isHost, MatchSettings settings = null) : base("Lobby") { if (isHost && settings == null) { throw new ArgumentNullException("settings must not be null when isHost is true"); } IsHost = isHost; MatchSettings = settings; Close += (s, e) => { if (isHost) { Lobby?.CloseHostedGameAsync(); Lobby?.Dispose(); Lobby = null; } Ballz.The().Network.PlayerListChanged -= UpdatePlayerList; }; Open += (s, e) => { Ballz.The().Network.PlayerListChanged += UpdatePlayerList; UpdatePlayerList(this, Ballz.The().Network.PlayerList); if (isHost) { Lobby = new LobbyClient(); var gameInfo = Lobby.MakeGameInfo(MatchSettings.GameName, MatchSettings.IsPrivate); Ballz.The().Network.StartServer(gameInfo); Lobby.OpenGame(gameInfo, Ballz.The().Network.NetworkPeer); } }; AddItem(new Label("Players in Lobby:")); PlayerList = new SelectList(); PlayerList.LockSelection = true; AddItem(PlayerList); if (isHost) { var startGameBtn = new Button("Start Game"); startGameBtn.OnClick += (e) => { Ballz.The().Network.StartNetworkGame(MatchSettings, 0); }; AddItem(startGameBtn); } else { AddItem(new Label("Waiting for Host to start the Game")); } AddItem(new BackButton(text: "Leave Game")); }
static void Main(string[] args) { string read = string.Empty; LobbyClient client = new LobbyClient(); while (client.Socket.IsBound) { read = Console.ReadLine().ToLower(); if (read == "s" || read == "stop") { lock (client) { Console.WriteLine("Server stopped."); client.Dispose(); } } } }
public GameListMenu() : base("Join Game") { Size = new Vector2(800, 0); Open += (s, e) => { Lobby = new LobbyClient(); Lobby.UpdatedOnlineGameList += UpdateOnlineGameList; Lobby.UpdatedLocalGameList += UpdateLocalGameList; Lobby.StartLocalDiscovery(); }; Close += (s, e) => { Lobby?.Dispose(); Lobby = null; }; var panel = new Panel(new Vector2(0, -1), PanelSkin.None); var onlineTab = OnlineLocalTabs.AddTab("Online", PanelSkin.None); onlineTab.panel.AddChild(new Header("Join Online Game")); onlineTab.panel.AddChild(OnlineGameList); onlineTab.panel.AddChild(StatusLabel); JoinOnlineButton.OnClick += (e) => JoinSelectedGame(online: true); onlineTab.panel.AddChild(JoinOnlineButton); onlineTab.panel.AddChild(new Gui.BackButton()); var localTab = OnlineLocalTabs.AddTab("Local", PanelSkin.None); localTab.panel.AddChild(new Header("Join Local Game")); localTab.panel.AddChild(LocalGameList); JoinLocalButton.OnClick += (e) => JoinSelectedGame(online: false); localTab.panel.AddChild(JoinLocalButton); localTab.panel.AddChild(new Gui.BackButton()); panel.AddChild(OnlineLocalTabs); AddChild(panel); }