예제 #1
1
		/// <summary>
		/// The constructor is private: loading screens should
		/// be activated via the static Load method instead.
		/// </summary>
		private LoadingScreen (ScreenManager screenManager,bool loadingIsSlow, 
				GameScreen[] screensToLoad)
			{
			this.loadingIsSlow = loadingIsSlow;
			this.screensToLoad = screensToLoad;

			TransitionOnTime = TimeSpan.FromSeconds (0.5);

			// If this is going to be a slow load operation, create a background
			// thread that will update the network session and draw the load screen
			// animation while the load is taking place.
			if (loadingIsSlow) {
				backgroundThread = new Thread (BackgroundWorkerThread);
				backgroundThreadExit = new ManualResetEvent (false);

				graphicsDevice = screenManager.GraphicsDevice;

				// Look up some services that will be used by the background thread.
				IServiceProvider services = screenManager.Game.Services;

				networkSession = (NetworkSession)services.GetService (
							typeof(NetworkSession));

				messageDisplay = (IMessageDisplay)services.GetService (
							typeof(IMessageDisplay));
			}
		}
예제 #2
0
 public ParticleManager(GameManager gameManager, Game game, Camera camera, NetworkSession networkSession)
 {
     this.game = game;
     this.camera = camera;
     this.networkSession = networkSession;
     this.gameManager = gameManager;
 }
        public LocalNetworkGameMenu(PlayerIndex enteringPlayer, NetworkSession nSession)
            : base("Local Network Game Lobby")
        {
            netSession = nSession;
            currentPlayerIndex = enteringPlayer;
            currentGamer = SignedInGamer.SignedInGamers[currentPlayerIndex];
            netSession.GameStarted += new EventHandler<GameStartedEventArgs>(loadNetworkGameScreen);

            // Create our menu entries.
            gameTypeOption = new MenuEntry("Game Type: " + GameType());
            highScoreOption = new MenuEntry("Score to Win: " + WinningScore());
            opt2 = new MenuEntry("Host: " + nSession.Host.ToString());
            opt3 = new MenuEntry("Ready?");
            opt4 = new MenuEntry("Waiting for opponent");
            opt5 = new MenuEntry("Go Back");

            netSession.GameStarted += new EventHandler<GameStartedEventArgs>(StartGame);

            gameTypeOption.Selected += changeGameType;
            highScoreOption.Selected += changeWinningScore;
            opt3.Selected += setReady;
            opt4.Selected += startGame;
            opt5.Selected += OnCancel;

            // Add entries to the menu.
            MenuEntries.Add(gameTypeOption);
            MenuEntries.Add(highScoreOption);
            MenuEntries.Add(opt2);
            MenuEntries.Add(opt3);
            MenuEntries.Add(opt4);
            MenuEntries.Add(opt5);

            SetMenuEntryText();
        }
예제 #4
0
 private void CreateSession()
 {
     netSession = NetworkSession.Create(NetworkSessionType.SystemLink, maxNumPlayers, maxNumPlayers);
     isHost = true;
     isNetworked = true;
     Game1.state = gameState.game;
 }
예제 #5
0
파일: networker.cs 프로젝트: SeaHarg/Snake
 public void CreateSession()
 {
     if (session == null)
     {
         session = NetworkSession.Create(NetworkSessionType.SystemLink,
         maximumLocalPlayers,
         maximumGamers);
     }
     // If the host goes out, another machine will assume as a new host
     session.AllowHostMigration = true;
     // Allow players to join a game in progress
     session.AllowJoinInProgress = true;
     session.GamerJoined +=
     new EventHandler<GamerJoinedEventArgs>(session_GamerJoined);
     session.GamerLeft +=
     new EventHandler<GamerLeftEventArgs>(session_GamerLeft);
     session.GameStarted +=
     new EventHandler<GameStartedEventArgs>(session_GameStarted);
     session.GameEnded +=
     new EventHandler<GameEndedEventArgs>(session_GameEnded);
     session.SessionEnded +=
     new EventHandler<NetworkSessionEndedEventArgs>(session_SessionEnded);
     session.HostChanged +=
     new EventHandler<HostChangedEventArgs>(session_HostChanged);
 }
예제 #6
0
 public MultiplayerManager(Game game, Camera camera, GameManager gameManager, NetworkSession networkSession)
 {
     _game = game;
     _camera = camera;
     _gameManager = gameManager;
     _networkSession = networkSession;
 }
예제 #7
0
        /// <summary>
        /// Constructs a new LobbyScreen object.
        /// </summary>
        public LobbyScreen(NetworkSession networkSession)
            : base()
        {
            // safety-check the parameter
            if (networkSession == null)
            {
                throw new ArgumentNullException("networkSession");
            }

            // apply the parameters
            this.networkSession = networkSession;

            // add the single menu entry
            MenuEntries.Add("");

            // set the transition time
            TransitionOnTime = TimeSpan.FromSeconds(1.0);
            TransitionOffTime = TimeSpan.FromSeconds(0.0);

            gamerJoinedHandler = new EventHandler<GamerJoinedEventArgs>(
                networkSession_GamerJoined);
            gameStartedHandler = new EventHandler<GameStartedEventArgs>(
                networkSession_GameStarted);
            sessionEndedHandler = new EventHandler<NetworkSessionEndedEventArgs>(
                networkSession_SessionEnded);

            networkSession.LocalGamers[0].IsReady = true; //DRD
        }
예제 #8
0
        public bool CreateSession()
        {
            try
            {
                int maxLocalGamers = 1;
                int maxGamers = 10;
                int privateGamerSlots = 2;
                networkSession = NetworkSession.Create(NetworkSessionType.SystemLink, maxLocalGamers, maxGamers, privateGamerSlots, null);
                networkSession.AllowHostMigration = true;
                networkSession.AllowJoinInProgress = false;

                HookSessionEvents();
                networkDebug = "";
            }
            catch (NetworkNotAvailableException)
            {
                //networkEnabled = false;
                networkDebug = "Could not create session through Windows Live. Ensure you are on a network.";
                return false;
            }
            catch (InvalidOperationException)
            {
                disposeNetworkSession();
                networkDebug = "Old session still exists. Disposing. please try again.";
                return false;
            }

            return true;
        }
예제 #9
0
		/// <summary>
		/// Constructor.
		/// </summary>
		public PauseMenuScreen (NetworkSession networkSession)
		: base(Resources.Paused)
			{
			this.networkSession = networkSession;

			// Add the Resume Game menu entry.
			MenuEntry resumeGameMenuEntry = new MenuEntry (Resources.ResumeGame);
			resumeGameMenuEntry.Selected += OnCancel;
			MenuEntries.Add (resumeGameMenuEntry);

			if (networkSession == null) {
				// If this is a single player game, add the Quit menu entry.
				MenuEntry quitGameMenuEntry = new MenuEntry (Resources.QuitGame);
				quitGameMenuEntry.Selected += QuitGameMenuEntrySelected;
				MenuEntries.Add (quitGameMenuEntry);
			} else {
				// If we are hosting a network game, add the Return to Lobby menu entry.
				if (networkSession.IsHost) {
					MenuEntry lobbyMenuEntry = new MenuEntry (Resources.ReturnToLobby);
					lobbyMenuEntry.Selected += ReturnToLobbyMenuEntrySelected;
					MenuEntries.Add (lobbyMenuEntry);
				}

				// Add the End/Leave Session menu entry.
				string leaveEntryText = networkSession.IsHost ? Resources.EndSession : 
								Resources.LeaveSession;

				MenuEntry leaveSessionMenuEntry = new MenuEntry (leaveEntryText);
				leaveSessionMenuEntry.Selected += LeaveSessionMenuEntrySelected;
				MenuEntries.Add (leaveSessionMenuEntry);
			}
		}
예제 #10
0
        /// <summary>
        /// Constructs a new lobby screen.
        /// </summary>
        public LobbyScreen(NetworkSession networkSession)
        {
            this.networkSession = networkSession;

            TransitionOnTime = TimeSpan.FromSeconds(0.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);
        }
예제 #11
0
파일: LiveSession.cs 프로젝트: rc183/igf
 /// <summary>
 /// Creates a new instance
 /// </summary>
 /// <param name="networkSession">the newly created or joined NetworkSession instance</param>
 internal LiveSession(NetworkSession networkSession)
 {
     _networkSession = networkSession;
     _networkSession.GamerLeft += OnLivePlayerLeft;
     _networkSession.GamerJoined += OnLivePlayerJoined;
     _networkSession.GameStarted += OnLiveSessionStarted;
     _networkSession.GameEnded += OnLiveSessionEnded;
 }
예제 #12
0
파일: LobbyScreen.cs 프로젝트: Nesokas/hs
 public LobbyScreen(NetworkSession networkSession)
 {
     _networkSession = networkSession;
     TransitionOnTime = TimeSpan.FromSeconds(0.5);
     TransitionOffTime = TimeSpan.FromSeconds(0.5);
     _packetReader = new PacketReader();
     _packetWriter = new PacketWriter();
 }
예제 #13
0
 /** Takes a RemoteGame and connects to it. */
 public void connectToGame(RemoteGame game)
 {
     session = NetworkSession.Join(game.getSession());
     session.GameStarted += new EventHandler<GameStartedEventArgs>(GameStarted);
     session.GameEnded += new EventHandler<GameEndedEventArgs>(GameEnded);
     session.SessionEnded += new EventHandler<NetworkSessionEndedEventArgs>(NetworkSessionEnded);
     session.GamerJoined += new EventHandler<GamerJoinedEventArgs>(GamerJoined);
     session.GamerLeft += new EventHandler<GamerLeftEventArgs>(GamerLeft);
     //Console.WriteLine("Connected to game: " + game.getDescription());
 }
예제 #14
0
 public MonoGamerPeer(NetworkSession session, AvailableNetworkSession availableSession)
 {
   this.session = session;
   this.online = this.session.SessionType == NetworkSessionType.PlayerMatch;
   this.availableSession = availableSession;
   this.MGServerWorker.WorkerSupportsCancellation = true;
   this.MGServerWorker.DoWork += new DoWorkEventHandler(this.MGServer_DoWork);
   this.MGServerWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.MGServer_RunWorkerCompleted);
   this.MGServerWorker.RunWorkerAsync();
   this.HookEvents();
 }
예제 #15
0
 protected void CriaSessao()
 {
     estado_atual = EstadoDeJogo.Loading;
     try {
         rede = NetworkSession.Create (NetworkSessionType.SystemLink, 2, 2);
         estado_atual = EstadoDeJogo.Lobby;
         ManipulaEventos ();
     } catch (Exception ex) {
         Console.WriteLine ("Erro: " + ex.Message);
     }
 }
예제 #16
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public GameplayScreen(Microsoft.Xna.Framework.Net.NetworkSession networkSession)
        {
            networkHelper       = new NetworkHelper();
            this.networkSession = networkSession;
            this.currentLevel   = currentLevel;
            networkHelper.NetworkGameSession = networkSession;

            GetVariables();

            TransitionOnTime  = TimeSpan.FromSeconds(1.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);
        }
        /// <summary>
        /// The constructor is private: external callers should use the Create method.
        /// </summary>
        NetworkSessionComponent(ScreenManager screenManager,
                                NetworkSession networkSession)
            : base(screenManager.Game)
        {
            this.screenManager = screenManager;
            this.networkSession = networkSession;

            // Hook up our session event handlers.
            networkSession.GamerJoined += GamerJoined;
            networkSession.GamerLeft += GamerLeft;
            networkSession.SessionEnded += NetworkSessionEnded;
        }
		/// <summary>
		/// Creates a new NetworkSessionComponent.
		/// </summary>
		public static void Create (ScreenManager screenManager,
				NetworkSession networkSession)
		{
			Game game = screenManager.Game;

			// Register this network session as a service.
			game.Services.AddService (typeof(NetworkSession), networkSession);

			// Create a NetworkSessionComponent, and add it to the Game.
			game.Components.Add (new NetworkSessionComponent (screenManager,
							networkSession));
		}
예제 #19
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public RespawnScreen(NetworkSession networkSession)
            : base(Resources.Respawn, true)
        {
            this.networkSession = networkSession;

            // Flag that there is no need for the game to transition
            // off when the pause menu is on top of it.
            IsPopup = true;

            // Add the Resume Game menu entry.
            MenuEntry resumeGameMenuEntry = new MenuEntry(Resources.ResumeGame);
            resumeGameMenuEntry.Selected += OnCancel;
        }
예제 #20
0
 public void CreateSession()
 {
     if (session == null)
     {
         session = NetworkSession.Create(NetworkSessionType.SystemLink, maximumLocalPlayers, maximumGamers);
         session.AllowHostMigration = true;  // Switch hosts if the original goes out
         session.AllowJoinInProgress = true; // Allow players to join a game in progress
         session.GamerJoined += new EventHandler<GamerJoinedEventArgs>(session_GamerJoined);
         session.GamerLeft += new EventHandler<GamerLeftEventArgs>(session_GamerLeft);
         session.GameStarted += new EventHandler<GameStartedEventArgs>(session_GameStarted);
         session.GameEnded += new EventHandler<GameEndedEventArgs>(session_GameEnded);
         session.HostChanged += new EventHandler<HostChangedEventArgs>(session_HostChanged);
     }
 }
예제 #21
0
파일: Lobby.cs 프로젝트: doanhtdpl/karts
        public override void Enter()
        {
            menu = new Screen();
            Gui.GetInstance().AddComponent(menu);

            session = NetworkManager.GetInstance().GetSession();
            if (session != null)
            {
                //session.GamerJoined += new EventHandler<GamerJoinedEventArgs>(session_GamerJoined);
                //session.GamerLeft += new EventHandler<GamerLeftEventArgs>(session_GamerLeft);
            }

            base.Enter();
        }
예제 #22
0
파일: Network.cs 프로젝트: narfman0/ERMotA
 public void CreateGame()
 {
     try
     {
         ShutDown();
         Session = NetworkSession.Create(NetworkSessionType.SystemLink, 1, MaxPlayers);
         Session.AllowHostMigration = true;
         Session.AllowJoinInProgress = true;
         Session.GamerJoined += new EventHandler<GamerJoinedEventArgs>(Session_GamerJoined);
         Session.StartGame();
     }
     catch (Exception e)
     {
         e.ToString();
     }
 }
        /// <summary>
        /// Constructor.
        /// </summary>
        public PauseMenuScreen(NetworkSession networkSession)
            : base(Resources.Paused)
        {
            this.networkSession = networkSession;

            // Flag that there is no need for the game to transition
            // off when the pause menu is on top of it.
            IsPopup = true;

            // Add the Resume Game menu entry.
            MenuEntry resumeGameMenuEntry = new MenuEntry(Resources.ResumeGame);
            resumeGameMenuEntry.Selected += OnCancel;
            MenuEntries.Add(resumeGameMenuEntry);

            // MODIFIED : Only allow exit to windows option once game has begun.
            MenuEntry exitToWindowsEntry = new MenuEntry(Resources.ExitToWindows);
            exitToWindowsEntry.Selected += ExitToWindowsSelected;
            MenuEntries.Add(exitToWindowsEntry);

            //if (networkSession == null)
            //{
            //    // If this is a single player game, add the Quit menu entry.
            //    MenuEntry quitGameMenuEntry = new MenuEntry(Resources.QuitGame);
            //    quitGameMenuEntry.Selected += QuitGameMenuEntrySelected;
            //    MenuEntries.Add(quitGameMenuEntry);
            //}
            //else
            //{
            //    // If we are hosting a network game, add the Return to Lobby menu entry.
            //    if (networkSession.IsHost)
            //    {
            //        MenuEntry lobbyMenuEntry = new MenuEntry(Resources.ReturnToLobby);
            //        lobbyMenuEntry.Selected += ReturnToLobbyMenuEntrySelected;
            //        MenuEntries.Add(lobbyMenuEntry);
            //    }

            //    // Add the End/Leave Session menu entry.
            //    string leaveEntryText = networkSession.IsHost ? Resources.EndSession :
            //                                                    Resources.LeaveSession;

            //    MenuEntry leaveSessionMenuEntry = new MenuEntry(leaveEntryText);
            //    leaveSessionMenuEntry.Selected += LeaveSessionMenuEntrySelected;
            //    MenuEntries.Add(leaveSessionMenuEntry);
            //}
        }
예제 #24
0
        internal void UpdateLiveSession(NetworkSession networkSession)
        {
            if (peer != null && m_masterServer != null && networkSession.IsHost)
            {
                NetOutgoingMessage om = peer.CreateMessage();

                om.Write((byte)0);
                om.Write(session.AllGamers.Count);
                om.Write(session.LocalGamers [0].Gamertag);
                om.Write(session.PrivateGamerSlots);
                om.Write(session.MaxGamers);
                om.Write(session.LocalGamers [0].IsHost);
                IPAddress adr = IPAddress.Parse(GetMyLocalIpAddress());
                om.Write(new IPEndPoint(adr, port));
                om.Write(peer.Configuration.AppIdentifier);
                peer.SendUnconnectedMessage(om, m_masterServer);                  // send message to peer
            }
        }
예제 #25
0
        private static NetworkSession JoinSession(AvailableNetworkSession availableSession)
        {
            NetworkSession networkSession = (NetworkSession)null;

            try
            {
                NetworkSessionType sessionType = availableSession.SessionType;
                int  maxGamers         = 32;
                int  privateGamerSlots = 0;
                bool isHost            = false;
                int  hostGamer         = -1;
                NetworkSessionProperties sessionProperties = availableSession.SessionProperties ?? new NetworkSessionProperties();
                networkSession = new NetworkSession(sessionType, maxGamers, privateGamerSlots, sessionProperties, isHost, hostGamer, availableSession);
            }
            finally
            {
            }
            return(networkSession);
        }
예제 #26
0
        public static NetworkSession EndJoinInvited(IAsyncResult result)
        {
            NetworkSession networkSession = (NetworkSession)null;

            try
            {
                AsyncResult asyncResult = (AsyncResult)result;
                result.AsyncWaitHandle.WaitOne();
                if (asyncResult.AsyncDelegate is NetworkSessionAsynchronousJoinInvited)
                {
                    networkSession = ((NetworkSessionAsynchronousJoinInvited)asyncResult.AsyncDelegate).EndInvoke(result);
                }
            }
            finally
            {
                result.AsyncWaitHandle.Close();
            }
            return(networkSession);
        }
예제 #27
0
        public NetworkGamer(NetworkSession session, byte id, GamerStates state)
        {
            this.id         = id;
            this.session    = session;
            this.gamerState = state;
            // We will modify these HasFlags to inline code because MonoTouch does not support
            // the HasFlag method.  Also after reading this : http://msdn.microsoft.com/en-us/library/system.enum.hasflag.aspx#2
            // it just might be better to inline it anyway.
            //this.isHost = (state & GamerStates.Host) != 0; // state.HasFlag(GamerStates.Host);
            //this.isLocal = (state & GamerStates.Local) != 0; // state.HasFlag(GamerStates.Local);
            //this.hasVoice = (state & GamerStates.HasVoice) != 0; //state.HasFlag(GamerStates.HasVoice);

            // *** NOTE TODO **
            // This whole state stuff need to be looked at again.  Maybe we should not be using local
            //  variables here and instead just use the flags within the gamerState.

            this.gamerState    = state;
            this.oldGamerState = state;
        }
예제 #28
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public PauseMenuScreen(NetworkSession networkSession)
            : base(Resources.Paused, false)
        {
            this.networkSession = networkSession;

            // Flag that there is no need for the game to transition
            // off when the pause menu is on top of it.
            IsPopup = true;

            // Add the Resume Game menu entry.
            MenuEntry resumeGameMenuEntry = new MenuEntry(Resources.ResumeGame);
            resumeGameMenuEntry.Selected += OnCancel;
            MenuEntry optionsMenuEntry = new MenuEntry(Resources.Options);
            optionsMenuEntry.Selected += OptionsMenuEntrySelected;
            MenuEntries.Add(resumeGameMenuEntry);
            MenuEntries.Add(optionsMenuEntry);

            if (networkSession == null)
            {
                // If this is a single player game, add the Quit menu entry.
                MenuEntry quitGameMenuEntry = new MenuEntry(Resources.QuitGame);
                quitGameMenuEntry.Selected += QuitGameMenuEntrySelected;
                MenuEntries.Add(quitGameMenuEntry);
            }
            else
            {
                // If we are hosting a network game, add the Return to Lobby menu entry.
                if (networkSession.IsHost)
                {
                    MenuEntry lobbyMenuEntry = new MenuEntry(Resources.ReturnToLobby);
                    lobbyMenuEntry.Selected += ReturnToLobbyMenuEntrySelected;
                    MenuEntries.Add(lobbyMenuEntry);
                }

                // Add the End/Leave Session menu entry.
                string leaveEntryText = networkSession.IsHost ? Resources.EndSession :
                                                                Resources.LeaveSession;

                MenuEntry leaveSessionMenuEntry = new MenuEntry(leaveEntryText);
                leaveSessionMenuEntry.Selected += LeaveSessionMenuEntrySelected;
                MenuEntries.Add(leaveSessionMenuEntry);
            }
        }
예제 #29
0
		public NetworkGamer ( NetworkSession session, byte id, GamerStates state)
		{
			this.id = id;
			this.session = session;
			this.gamerState = state;
			// We will modify these HasFlags to inline code because MonoTouch does not support
			// the HasFlag method.  Also after reading this : http://msdn.microsoft.com/en-us/library/system.enum.hasflag.aspx#2
			// it just might be better to inline it anyway.
			//this.isHost = (state & GamerStates.Host) != 0; // state.HasFlag(GamerStates.Host);
			//this.isLocal = (state & GamerStates.Local) != 0; // state.HasFlag(GamerStates.Local);
			//this.hasVoice = (state & GamerStates.HasVoice) != 0; //state.HasFlag(GamerStates.HasVoice);
			
			// *** NOTE TODO **
			// This whole state stuff need to be looked at again.  Maybe we should not be using local
			//  variables here and instead just use the flags within the gamerState.
			
			this.gamerState = state;
			this.oldGamerState = state;
		}
예제 #30
0
        public static NetworkSession EndCreate(IAsyncResult result)
        {
            if (result != activeAction)
            {
                throw new ArgumentException("result");
            }

            activeSession = new NetworkSession(
                activeAction.SessionProperties,
                activeAction.SessionType,
                69,
                activeAction.MaxPrivateSlots,
                activeAction.MaxLocalGamers,
                activeAction.LocalGamers
                );

            activeAction = null;
            return(activeSession);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        public GameplayScreen(NetworkSession networkSession)
        {
            this.networkSession = networkSession;

            TransitionOnTime = TimeSpan.FromSeconds(1.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);

            // setup keyboard configs:
            List<KeyConfig> keyConfigs = new List<KeyConfig>();
            keyConfigs.Add(new KeyConfig(Keys.W, Keys.S, Keys.A, Keys.D, Keys.C, Keys.Space));
            keyConfigs.Add(new KeyConfig(Keys.Up, Keys.Down, Keys.Left, Keys.Right, Keys.RightControl, Keys.End));
            //keyConfigs.Add(new KeyConfig(Keys.Q, Keys.E, Keys.R, Keys.T, Keys.Y, Keys.U));

            gameEngine = (networkSession == null) ?
                Engine.CreateLocalEngine(NetworkStateManagementGame.MainGame, keyConfigs) :
                Engine.CreateNetworkedEngine(NetworkStateManagementGame.MainGame, keyConfigs, networkSession);

            gameEngine.Initialize();
        }
예제 #32
0
        internal NetworkGamer(
            NetworkSession session
            ) : base(
                "Stub Gamer",
                "Stub Gamer"
                )
        {
            Session = session;

            // TODO: Everything below
            HasLeftSession     = false;
            HasVoice           = false;
            IsGuest            = false;
            IsMutedByLocalUser = false;
            IsPrivateSlot      = false;
            IsReady            = false;
            IsTalking          = false;
            Machine            = new NetworkMachine();
            RoundtripTime      = TimeSpan.Zero;
        }
예제 #33
0
        internal void UpdateLiveSession(NetworkSession networkSession)
        {
            if (this.peer == null || MonoGamerPeer.m_masterServer == null || !networkSession.IsHost)
            {
                return;
            }
            NetOutgoingMessage message = ((NetPeer)this.peer).CreateMessage();

            message.Write((byte)0);
            message.Write(this.session.AllGamers.Count);
            message.Write(this.session.LocalGamers[0].Gamertag);
            message.Write(this.session.PrivateGamerSlots);
            message.Write(this.session.MaxGamers);
            message.Write(this.session.LocalGamers[0].IsHost);
            IPAddress address = IPAddress.Parse(MonoGamerPeer.GetMyLocalIpAddress());

            message.Write(new IPEndPoint(address, MonoGamerPeer.port));
            message.Write(((NetPeer)this.peer).get_Configuration().get_AppIdentifier());
            ((NetPeer)this.peer).SendUnconnectedMessage(message, MonoGamerPeer.m_masterServer);
        }
예제 #34
0
        public GameplayScreen(NetworkSession networkSession)
        {
            TransitionOnTime = TimeSpan.FromSeconds(1.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);

            _pauseAction = new InputAction(
                new Buttons[] { Buttons.Start, Buttons.Back },
                new Keys[] { Keys.Escape },
                true);

            _propertiesAction = new InputAction(
                new Buttons[] { Buttons.Y },
                new Keys[] { Keys.F1 },
                true);

            _gameManager = null;
            _networkSession = networkSession;

            _isPropertiesWindow = false;
        }
예제 #35
0
        public NetworkSession CreateSession()
        {
            session = NetworkSession.Create(NetworkSessionType.SystemLink, MAX_LOCAL_PLAYERS, MAX_TOTAL_PLAYERS);

            session.AllowHostMigration = true;
            session.AllowJoinInProgress = true;

            session.GamerJoined += new EventHandler<GamerJoinedEventArgs>(session_GamerJoined);
            session.GamerLeft += new EventHandler<GamerLeftEventArgs>(session_GamerLeft);
            session.GameStarted += new EventHandler<GameStartedEventArgs>(session_GameStarted);
            session.GameEnded += new EventHandler<GameEndedEventArgs>(session_GameEnded);
            session.SessionEnded += new EventHandler<NetworkSessionEndedEventArgs>(session_SessionEnded);

            pr = new PacketReader();
            pw = new PacketWriter();

            sender = session.LocalGamers[0];

            return session;
        }
예제 #36
0
        /// <summary>
        /// Construct a new GameplayScreen object.
        /// </summary>
        /// <param name="networkSession">The network session for this game.</param>
        /// <param name="world">The primary gameplay object.</param>
        public GameplayScreen(NetworkSession networkSession, World world)
        {
            // safety-check the parameters
            if (networkSession == null)
            {
                throw new ArgumentNullException("networkSession");
            }
            if (world == null)
            {
                throw new ArgumentNullException("world");
            }

            // apply the parameters
            this.networkSession = networkSession;
            this.world = world;

            // set up the network events
            sessionEndedHandler = new EventHandler<NetworkSessionEndedEventArgs>(
                networkSession_SessionEnded);
            networkSession.SessionEnded += sessionEndedHandler;
            gameEndedHandler = new EventHandler<GameEndedEventArgs>(
                networkSession_GameEnded);
            networkSession.GameEnded += gameEndedHandler;
            gamerLeftHandler = new EventHandler<GamerLeftEventArgs>(
                networkSession_GamerLeft);
            networkSession.GamerLeft += gamerLeftHandler;

            // cache the local player's ship object
            //if (networkSession.LocalGamers.Count > 0)
            //{
            //    PlayerData playerData = networkSession.LocalGamers[0].Tag as PlayerData;
            //    if (playerData != null)
            //    {
            //        localShip = playerData.Ship;
            //    }
            //}

            // set the transition times
            TransitionOnTime = TimeSpan.FromSeconds(1.0);
            TransitionOffTime = TimeSpan.FromSeconds(1.0);
        }
예제 #37
0
        public static NetworkSession EndJoinInvited(IAsyncResult result)
        {
            NetworkSession returnValue = null;

            try {
                // Retrieve the delegate.
                AsyncResult asyncResult = (AsyncResult)result;

                // Wait for the WaitHandle to become signaled.
                result.AsyncWaitHandle.WaitOne();

                // Call EndInvoke to retrieve the results.
                if (asyncResult.AsyncDelegate is NetworkSessionAsynchronousJoinInvited)
                {
                    returnValue = ((NetworkSessionAsynchronousJoinInvited)asyncResult.AsyncDelegate).EndInvoke(result);
                }
            } finally {
                // Close the wait handle.
                result.AsyncWaitHandle.Close();
            }
            return(returnValue);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        public SessionPropertiesPopUpScreen(NetworkSession networkSession)
            : base(Resources.Paused, false)
        {
            this.networkSession = networkSession;
            GetVariables();

            // Flag that there is no need for the game to transition
            // off when the pause menu is on top of it.
            IsPopup = true;

            MenuEntry levelMenuEntry = new MenuEntry(Resources.Level);
            MenuEntry gameModeMenuEntry = new MenuEntry(Resources.GameMode);
            MenuEntry weaponsMenuEntry = new MenuEntry(Resources.Weapons);
            MenuEntry scoreToWinMenuEntry = new MenuEntry(Resources.ScoreToWin);
            MenuEntry noofbotsMenuEntry = new MenuEntry(Resources.NumberOfBots);
            MenuEntry lobbyMenuEntry = new MenuEntry(Resources.ReturnToLobby);

            levelMenuEntry.Selected += LevelMenuEntrySelected;
            gameModeMenuEntry.Selected += GameModeMenuEntrySelected;
            weaponsMenuEntry.Selected += WeaponsMenuEntrySelected;
            scoreToWinMenuEntry.Selected += ScoreToWinMenuEntrySelected;
            noofbotsMenuEntry.Selected += NoOfBotsMenuEntrySelected;
            lobbyMenuEntry.Selected += ReturnToLobbyMenuEntrySelected;

            MenuEntries.Add(levelMenuEntry);
            MenuEntries.Add(gameModeMenuEntry);
            MenuEntries.Add(weaponsMenuEntry);
            MenuEntries.Add(scoreToWinMenuEntry);
            MenuEntries.Add(noofbotsMenuEntry);
            //MenuEntries.Add(lobbyMenuEntry);

            // Add the Resume Game menu entry.
            MenuEntry resumeGameMenuEntry = new MenuEntry(Resources.ResumeGame);
            resumeGameMenuEntry.Selected += OnCancel;
            MenuEntry optionsMenuEntry = new MenuEntry(Resources.Options);
            optionsMenuEntry.Selected += OptionsMenuEntrySelected;
            MenuEntries.Add(resumeGameMenuEntry);
            MenuEntries.Add(optionsMenuEntry);
        }
        internal NetworkGamer(
            Steamworks.CSteamID id,
            NetworkSession session
            ) : base(
                id,
                Steamworks.SteamFriends.GetFriendPersonaName(id),
                Steamworks.SteamFriends.GetPlayerNickname(id)
                )
        {
            Session = session;

            // TODO: Everything below
            HasLeftSession     = false;
            HasVoice           = false;
            IsGuest            = false;
            IsMutedByLocalUser = false;
            IsPrivateSlot      = false;
            IsReady            = false;
            IsTalking          = false;
            Machine            = new NetworkMachine();
            RoundtripTime      = TimeSpan.Zero;
        }
예제 #40
0
        private static NetworkSession Create(
            NetworkSessionType sessionType,
            int maxLocalGamers,
            int maxGamers,
            int privateGamerSlots,
            NetworkSessionProperties sessionProperties,
            int hostGamer,
            bool isHost)
        {
            NetworkSession session = null;

            try {
                if (sessionProperties == null)
                {
                    sessionProperties = new NetworkSessionProperties();
                }
                session = new NetworkSession(sessionType, maxGamers, privateGamerSlots, sessionProperties, isHost, hostGamer);
            } finally {
            }

            return(session);
        }
예제 #41
0
        public static NetworkSession EndJoin(IAsyncResult result)
        {
            if (result != activeAction)
            {
                throw new ArgumentException("result");
            }

            int actionMaxLocalGamers = activeAction.MaxLocalGamers;
            IEnumerable <SignedInGamer> actionLocalGamers = activeAction.LocalGamers;

            activeAction = null;

            activeSession = new NetworkSession(
                null,                           // FIXME
                NetworkSessionType.PlayerMatch, // FIXME
                MaxSupportedGamers,             // FIXME
                4,                              // FIXME
                actionMaxLocalGamers,
                actionLocalGamers
                );
            return(activeSession);
        }
예제 #42
0
        /// <summary>
        /// Constructs a new lobby screen.
        /// </summary>
        public LobbyScreen(NetworkSession networkSession)
        {
            this.networkSession = networkSession;

            networkSession.GamerJoined += GamerJoined;

            networkHelper = new NetworkHelper();

            GetVariables();

            if (networkSession.LocalGamers.Count > 0)
            {
                localPlayer = networkSession.LocalGamers[0].Tag as Player;
            }

            // Adds a simple message to tell the user what to do.
            // Since we will be using the guide to get commands,
            // we need to tell them how to open it up!
            messages.Add(new string[] { "System", "Press [Tab] to send a message " });

            /*
            if (audioHelper == null)
                this.audioHelper = new Audio("Content\\TRA_Game.xgs");
            else
                this.audioHelper = audioHelper;
            if (audio_on == false)
            {
                mystery = this.audioHelper.GetCue("mystery");
                this.audioHelper.Play(mystery, false, new AudioListener(), new AudioEmitter());
            }
            else
                mystery = this.audioHelper.GetCue("mystery");

            this.audioHelper.Update();*/
            TransitionOnTime = TimeSpan.FromSeconds(0.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);
        }
예제 #43
0
 public static NetworkSession Create(NetworkSessionType sessionType, int maxLocalGamers, int maxGamers)
 {
   return NetworkSession.EndCreate(NetworkSession.BeginCreate(sessionType, maxLocalGamers, maxGamers, (AsyncCallback) null, (object) null));
 }
예제 #44
0
 public LocalNetworkGamer(NetworkSession session, byte id, GamerStates state)
     : base(session, id, state | GamerStates.Local)
 {
     sig          = new SignedInGamer();
     receivedData = new Queue <CommandReceiveData>();
 }
예제 #45
0
 public static IAsyncResult BeginFind(NetworkSessionType sessionType, int maxLocalGamers, NetworkSessionProperties searchProperties, AsyncCallback callback, object asyncState)
 {
   return NetworkSession.BeginFind(sessionType, -1, 4, searchProperties, callback, asyncState);
 }
예제 #46
0
 public static NetworkSession Create(NetworkSessionType sessionType, int maxLocalGamers, int maxGamers, int privateGamerSlots, NetworkSessionProperties sessionProperties)
 {
   return NetworkSession.EndCreate(NetworkSession.BeginCreate(sessionType, maxLocalGamers, maxGamers, privateGamerSlots, sessionProperties, (AsyncCallback) null, (object) null));
 }
예제 #47
0
 public static IAsyncResult BeginFind(NetworkSessionType sessionType, IEnumerable<SignedInGamer> localGamers, NetworkSessionProperties searchProperties, AsyncCallback callback, object asyncState)
 {
   int hostingGamerIndex = NetworkSession.GetHostingGamerIndex(localGamers);
   return NetworkSession.BeginFind(sessionType, hostingGamerIndex, 4, searchProperties, callback, asyncState);
 }
예제 #48
0
 public static IAsyncResult BeginCreate(NetworkSessionType sessionType, IEnumerable<SignedInGamer> localGamers, int maxGamers, int privateGamerSlots, NetworkSessionProperties sessionProperties, AsyncCallback callback, object asyncState)
 {
   int hostingGamerIndex = NetworkSession.GetHostingGamerIndex(localGamers);
   return NetworkSession.BeginCreate(sessionType, hostingGamerIndex, 4, maxGamers, privateGamerSlots, sessionProperties, callback, asyncState);
 }
예제 #49
0
 public static AvailableNetworkSessionCollection Find(NetworkSessionType sessionType, IEnumerable<SignedInGamer> localGamers, NetworkSessionProperties searchProperties)
 {
   int hostingGamerIndex = NetworkSession.GetHostingGamerIndex(localGamers);
   return NetworkSession.EndFind(NetworkSession.BeginFind(sessionType, hostingGamerIndex, 4, searchProperties, (AsyncCallback) null, (object) null));
 }
예제 #50
0
 public static NetworkSession Join(AvailableNetworkSession availableSession)
 {
   return NetworkSession.EndJoin(NetworkSession.BeginJoin(availableSession, (AsyncCallback) null, (object) null));
 }
예제 #51
0
 public static AvailableNetworkSessionCollection Find(NetworkSessionType sessionType, int maxLocalGamers, NetworkSessionProperties searchProperties)
 {
   return NetworkSession.EndFind(NetworkSession.BeginFind(sessionType, -1, maxLocalGamers, searchProperties, (AsyncCallback) null, (object) null));
 }
예제 #52
0
 public static IAsyncResult BeginCreate(NetworkSessionType sessionType, int maxLocalGamers, int maxGamers, AsyncCallback callback, object asyncState)
 {
     return(NetworkSession.BeginCreate(sessionType, -1, maxLocalGamers, maxGamers, 0, (NetworkSessionProperties)null, callback, asyncState));
 }
예제 #53
0
 public static IAsyncResult BeginCreate(NetworkSessionType sessionType, int maxLocalGamers, int maxGamers, int privateGamerSlots, NetworkSessionProperties sessionProperties, AsyncCallback callback, object asyncState)
 {
   return NetworkSession.BeginCreate(sessionType, -1, maxLocalGamers, maxGamers, privateGamerSlots, sessionProperties, callback, asyncState);
 }