Hooking to the Session Events in Microsoft Word

Generation ECC200 in Microsoft Word Hooking to the Session Events

Hooking to the Session Events
DataMatrix Drawer In None
Using Barcode creation for Word Control to generate, create DataMatrix image in Microsoft Word applications.
www.OnBarcode.com
GTIN - 128 Encoder In None
Using Barcode encoder for Word Control to generate, create EAN128 image in Microsoft Word applications.
www.OnBarcode.com
Now that your machine is hosting a network session, it would be nice to know when other people have joined the session. You can do this by hooking a self-defined method to the GamerJoined event of the network session. Whenever a player joins the session, the session will automatically raise this GamerJoined event. As a result, all methods hooked to the event will be called. This line will cause the self-defined GamerJoinedEventHandler method to be hooked to the GamerJoined event: networkSession.GamerJoined += GamerJoinedEventHandler; In the GamerJoinedEventHandler method, you can put all code that should be executed whenever a new player joins the session. This following simple example will cause a line of text containing the name of the player to be printed to the screen: void GamerJoinedEventHandler(object sender, GamerJoinedEventArgs e) { log.Add(e.Gamer.Gamertag + " joined the current session"); } As with all event-handling methods, this method will receive the object that raised the event (in this case, the network session), as well as a second argument containing specific
EAN 13 Creation In None
Using Barcode encoder for Microsoft Word Control to generate, create GTIN - 13 image in Microsoft Word applications.
www.OnBarcode.com
Barcode Encoder In None
Using Barcode drawer for Word Control to generate, create Barcode image in Office Word applications.
www.OnBarcode.com
CH A PT ER 8 N ETWO RKI NG I N XN A 2.0
Code 39 Creator In None
Using Barcode creator for Office Word Control to generate, create USS Code 39 image in Word applications.
www.OnBarcode.com
Printing USS Code 128 In None
Using Barcode creator for Office Word Control to generate, create Code 128 Code Set C image in Office Word applications.
www.OnBarcode.com
information that comes with this type of event. In this case, the GamerJoinedEventArgs contains the Gamer object corresponding to the player who just joined the session. The network session can raise other events that you might want to listen for. These include the GamerLeft event and the GameStarted and GameEnded events that indicate when the session switches from lobby to game mode (see recipe 8-6), as well as the SessionEnded and HostChanged events. The SessionEnded event is fired when the host quits the session while AllowHostMigration was set to false or when the host calls the Dispose method on the network session. The HostChanged event is fired when the host quits the session while AllowHostMigration was set to true. The following code will listen for the GamerJoined, GamerLeft, and HostChanged events fired by the network session and will print a corresponding line to the screen: void HookSessionEvents() { log.Add("Listening for session events"); networkSession.GamerJoined += GamerJoinedEventHandler; networkSession.GamerLeft += GamerLeftEventHandler; networkSession.HostChanged += HostChangedEventHandler; } void GamerJoinedEventHandler(object sender, GamerJoinedEventArgs e) { log.Add(e.Gamer.Gamertag + " joined the current session"); } void GamerLeftEventHandler(object sender, GamerLeftEventArgs e) { log.Add(e.Gamer.Gamertag + " left the current session"); } void HostChangedEventHandler(object sender, HostChangedEventArgs e) { log.Add("Host migration detected"); NetworkSession eventRaisingSession = (NetworkSession)sender; if (eventRaisingSession.IsHost) log.Add("This machine has become the new Host!"); } In the case of a host migration, the sender object (which you know is a network session) is first cast to a NetworkSession object so you can query its properties. Amongst them is the IsHost property, which you can use to detect whether this machine has become the new host of the session. Make sure you call the HookSessionEvents method immediately after you ve created your session. This is what the CreateSession state in the Update method should look like:
QR Code 2d Barcode Generation In None
Using Barcode printer for Word Control to generate, create Denso QR Bar Code image in Word applications.
www.OnBarcode.com
Creating Identcode In None
Using Barcode maker for Office Word Control to generate, create Identcode image in Word applications.
www.OnBarcode.com
CHAPTER 8 NETWORKING IN XNA 2.0
DataMatrix Creator In None
Using Barcode printer for Software Control to generate, create Data Matrix image in Software applications.
www.OnBarcode.com
DataMatrix Decoder In VB.NET
Using Barcode decoder for .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
case GameState.CreateSession: { networkSession = NetworkSession.Create(NetworkSessionType.SystemLink, 4, 16); networkSession.AllowHostMigration = true; networkSession.AllowJoinInProgress = false; log.Add("New session created"); HookSessionEvents(); currentGameState = GameState.InSession; } The session is created, the AllowHostMigration and AllowJoinInProgress values are set, and the program is listening for any events raised by the session.
Encoding UCC - 12 In C#
Using Barcode creation for .NET framework Control to generate, create UPC Symbol image in Visual Studio .NET applications.
www.OnBarcode.com
Printing Code 39 Full ASCII In Java
Using Barcode generator for Android Control to generate, create Code 39 Full ASCII image in Android applications.
www.OnBarcode.com
Updating the Network Session
Encode Code39 In None
Using Barcode generation for Microsoft Excel Control to generate, create USS Code 39 image in Excel applications.
www.OnBarcode.com
Denso QR Bar Code Drawer In Java
Using Barcode generator for Android Control to generate, create QR image in Android applications.
www.OnBarcode.com
Once you are connected to a session, you should update it at regular intervals. An obvious spot to do this is during the update cycle of your game. For now, this is the only thing that s being done during the InSession state: case GameState.InSession: { networkSession.Update(); } break;
Barcode Creator In Java
Using Barcode creator for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
UPC-A Supplement 2 Encoder In Visual Studio .NET
Using Barcode creator for Reporting Service Control to generate, create UPC-A Supplement 5 image in Reporting Service applications.
www.OnBarcode.com
The Code
Making Barcode In VB.NET
Using Barcode drawer for .NET Control to generate, create Barcode image in .NET framework applications.
www.OnBarcode.com
Make QR Code ISO/IEC18004 In Java
Using Barcode drawer for Eclipse BIRT Control to generate, create QR Code image in BIRT reports applications.
www.OnBarcode.com
Here you can find the resulting Update method. The program will start in the SignIn state, after which a session will be created in the CreateSession state. The program ends in the InSession state. protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); if (this.IsActive) { switch (currentGameState) { case GameState.SignIn: { if (Gamer.SignedInGamers.Count < 1) { Guide.ShowSignIn(1, false); log.Add("Opened User SignIn Interface"); }
Print EAN / UCC - 13 In Visual Studio .NET
Using Barcode encoder for Reporting Service Control to generate, create EAN / UCC - 13 image in Reporting Service applications.
www.OnBarcode.com
Scanning Barcode In VS .NET
Using Barcode Control SDK for ASP.NET Control to generate, create, read, scan barcode image in ASP.NET applications.
www.OnBarcode.com
Copyright © OnBarcode.com . All rights reserved.