Esempio n. 1
0
        /// <summary>
        /// Updates the network session from the background worker thread, to avoid
        /// disconnecting due to network timeouts even if loading takes a long time.
        /// </summary>
        void UpdateNetworkSession()
        {
            if ((networkSession == null) ||
                (networkSession.SessionState == NetworkSessionState.Ended))
            {
                return;
            }

            try                     {
                networkSession.Update();
            } catch {
                // If anything went wrong, we don't have a good way to report that
                // error while running on a background thread. Setting the session to
                // null will stop us from updating it, so the main game can deal with
                // the problem later on.
                networkSession = null;
            }
        }
Esempio n. 2
0
        public bool createSession()
        {
            currentState = CurrentState.Creating;
            try
            {
                networkSession = NetworkSession.Create(sessionType, Global.Constants.MAX_PLAYERS_LOCAL, Global.Constants.MAX_PLAYERS_TOTAL, 0, sessionProperties);
                hookEvents();
            }
            catch (Exception e)
            {
                currentState     = CurrentState.CreateFailed;
                lastErrorMessage = e.Message;
                return(false);
            }

            currentState = CurrentState.Running;
            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Handles "Exit" menu item selection
        /// </summary>
        ///
        protected override void OnCancel(PlayerIndex playerIndex)
        {
            // Tear down our network session
            NetworkSession session = ScreenManager.Game.Services.GetService(typeof(NetworkSession)) as NetworkSession;

            if (session != null)
            {
                if (session.AllGamers.Count == 1)
                {
                    session.EndGame();
                }
                session.Dispose();
                ScreenManager.Game.Services.RemoveService(typeof(NetworkSession));
            }
            AudioManager.StopSounds();
            ScreenManager.AddScreen(new MainMenuScreen(), null);
            ExitScreen();
        }
Esempio n. 4
0
 public void Init(float minX, float minY, float maxX, float maxY){
   NetworkSession netSes = Session.session.netSes;
   if(netSes.isServer){
     InitServerControls();
   }
   else{
     InitControls();
   } 
   
   InitNetwork();
   
   if(netSes.isServer){
     ScaleServerControls();
   }
   else{
     ScaleControls();
   }
 }
Esempio n. 5
0
        /// <summary>
        /// Starts hosting a new network session.
        /// </summary>
        void CreateSession()
        {
            DrawMessage("Creating game...");

            try
            {
                networkSession = NetworkSession.Create(NetworkSessionType.SystemLink,
                                                       maxLocalGamers, maxGamers);

                HookSessionEvents();
                state        = gameState.game;
                errorMessage = null;
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
            }
        }
Esempio n. 6
0
    void BuildPlayers()
    {
        NetworkSession netSes = Session.session.netSes;
        string         names  = "Players(" + netSes.playerData.Count + ")";

        if (countDownActive)
        {
            names += " Starting in " + countDown;
        }

        names += "\n";

        foreach (KeyValuePair <int, PlayerData> entry in netSes.playerData)
        {
            names += entry.Value.name + "\n";
        }
        playersBox.SetText(names);
    }
Esempio n. 7
0
    public void MultiplayerInit()
    {
        NetworkSession netSes = Session.session.netSes;

        playerWorldId = netSes.selfPeerId;
        foreach (KeyValuePair <int, PlayerData> entry in netSes.playerData)
        {
            int id = entry.Value.id;
            InitActor(Actor.Brains.Remote, id);
        }
        SpawnItem(Item.Types.HealthPack);
        SpawnItem(Item.Types.AmmoPack);

        if (Session.IsServer())
        {
            roundTimeRemaining = RoundDuration;
            roundTimerActive   = true;
        }
    }
Esempio n. 8
0
        public void BeginGameSearch()
        {
            if (networkSession == null)
            {
                IsSearching = true;

                SetString("Searching for Games...");

                try
                {
                    FindResult = NetworkSession.BeginFind(SessionType, 4, null, null, null);
                }
                catch (Exception e)
                {
                    // if (networkSession == null)
                    OnlineString = e.Message;
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Event handler called when the system delivers an invite notification.
        /// This can occur when the user accepts an invite that was sent to them by
        /// a friend (pull mode), or if they choose the "Join Session In Progress"
        /// option in their friends screen (push mode). The handler leaves the
        /// current session (if any), then joins the session referred to by the
        /// invite. It is not necessary to prompt the user before doing this, as
        /// the Guide will already have taken care of the necessary confirmations
        /// before the invite was delivered to you.
        /// </summary>
        public static void InviteAccepted(ScreenManager screenManager,
                                          InviteAcceptedEventArgs e)
        {
            // If we are already in a network session, leave it now.
            NetworkSessionComponent self = FindSessionComponent(screenManager.Game);

            if (self != null)
            {
                self.Dispose();
            }

            try
            {
                // Which local profiles should we include in this session?
                IEnumerable <SignedInGamer> localGamers =
                    ChooseGamers(NetworkSessionType.PlayerMatch, e.Gamer.PlayerIndex);

                // Begin an asynchronous join-from-invite operation.
                IAsyncResult asyncResult = NetworkSession.BeginJoin(null, null, localGamers);
                //                                                          null, null);

                // Use the loading screen to replace whatever screens were previously
                // active. This will completely reset the screen state, regardless of
                // whether we were in the menus or playing a game when the invite was
                // delivered. When the loading screen finishes, it will activate the
                // network busy screen, which displays an animation as it waits for
                // the join operation to complete.
                NetworkBusyScreen busyScreen = new NetworkBusyScreen(asyncResult);

                busyScreen.OperationCompleted += JoinInvitedOperationCompleted;

                LoadingScreen.Load(screenManager, false, null,
                                   busyScreen);
            }
            catch (Exception exception)
            {
                NetworkErrorScreen errorScreen = new NetworkErrorScreen(exception);

                LoadingScreen.Load(screenManager, false, null,
                                   new MainMenuScreen(),
                                   errorScreen);
            }
        }
 public static void CreateSession()
 {
     if (networkSession != null)
     {
         networkSession.Dispose();
     }
     SetStatus("Creating Session");
     try
     {
         networkSession = NetworkSession.Create(NetworkSessionType.SystemLink, 2, 2);
         HookSessionEvents();
         SetStatus("Successfully Created Session");
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         SetStatus(e.Message);
     }
 }
Esempio n. 11
0
        void CreateGameHandler(object sender, EventArgs e)
        {
            try
            {
                Session = NetworkSession.Create(NetworkSessionType.SystemLink, 2, 2);

                UnhookHomeStateEvents();

                GlobalState = new LobbyState();
                GlobalState.Initialize(null);
                GlobalState.LoadContent(Content);

                HookLobbyStateEvents();
                HookSessionEvents();
            }
            catch (Exception exception)
            {
            }
        }
        /// <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);
        }
        /// <summary>
        /// Responds to user menu selections.
        /// </summary>
        protected override void OnSelectEntry(int entryIndex)
        {
            if ((availableSessions != null) && (entryIndex >= 0) &&
                (entryIndex < availableSessions.Count))
            {
                // start to join
                try
                {
                    IAsyncResult asyncResult = NetworkSession.BeginJoin(
                        availableSessions[entryIndex], null, null);

                    // create the busy screen
                    NetworkBusyScreen busyScreen = new NetworkBusyScreen(
                        "Joining the session...", asyncResult);
                    busyScreen.OperationCompleted += LoadLobbyScreen;
                    ScreenManager.AddScreen(busyScreen);
                }
                catch (NetworkException ne)
                {
                    const string     message    = "Failed joining the session.";
                    MessageBoxScreen messageBox = new MessageBoxScreen(message);
                    messageBox.Accepted  += FailedMessageBox;
                    messageBox.Cancelled += FailedMessageBox;
                    ScreenManager.AddScreen(messageBox);

                    System.Console.WriteLine("Failed to join session:  " +
                                             ne.Message);
                }
                catch (GamerPrivilegeException gpe)
                {
                    const string message =
                        "You do not have permission to join a session.";
                    MessageBoxScreen messageBox = new MessageBoxScreen(message);
                    messageBox.Accepted  += FailedMessageBox;
                    messageBox.Cancelled += FailedMessageBox;
                    ScreenManager.AddScreen(messageBox);

                    System.Console.WriteLine(
                        "Insufficient privilege to join session:  " + gpe.Message);
                }
            }
        }
        /// <summary>
        /// Event handler for when the asynchronous create network session
        /// operation has completed.
        /// </summary>
        void CreateSessionOperationCompleted(object sender,
                                             OperationCompletedEventArgs e)
        {
            try {
                // End the asynchronous create network session operation.
                NetworkSession networkSession = NetworkSession.EndCreate(e.AsyncResult);

                // Create a component that will manage the session we just created.
                NetworkSessionComponent.Create(ScreenManager, networkSession);

                // Go to the lobby screen. We pass null as the controlling player,
                // because the lobby screen accepts input from all local players
                // who are in the session, not just a single controlling player.
                ScreenManager.AddScreen(new LobbyScreen(networkSession), null);
            } catch (Exception exception) {
                NetworkErrorScreen errorScreen = new NetworkErrorScreen(exception);

                ScreenManager.AddScreen(errorScreen, ControllingPlayer);
            }
        }
Esempio n. 15
0
        public void doSessionSearch()
        {
            if (_availableSessions == null)
            {
                if (_netSession != null)
                {
                    _netSession.Dispose();
                    _netSession = null;
                }
                _availableSessions = NetworkSession.Find(NetworkSessionType.SystemLink, 1, null);
            }

            if (_availableSessions != null)
            {
                foreach (AvailableNetworkSession session in _availableSessions)
                {
                    _sessionList.Add(session);
                }
            }
        }
        /// <summary>
        /// Attempt to join a session using an invite that was received.
        /// </summary>
        public void JoinInvitedGame()
        {
            try
            {
                // begin to join the game we were invited to
                IAsyncResult asyncResult = NetworkSession.BeginJoinInvited(1, null, null);

                // create the busy screen
                NetworkBusyScreen busyScreen = new NetworkBusyScreen("Joining the session...", asyncResult);
                busyScreen.OperationCompleted += InvitedSessionJoined;
                ScreenManager.AddScreen(busyScreen);
            }
            catch
            {
                // could not begin to join invited game, so default to the pre-existing MainMenuScreen
            }

            ScreenManager.invited = null;
            updateState           = true;
        }
Esempio n. 17
0
        public override void Initialize()
        {
            if (IsHost)
            {
                commandHost.RegisterEchoListner(this);

                // Create network session if NetworkSession is not set.
                if (NetworkSession == null)
                {
                    GamerServicesDispatcher.WindowHandle = Game.Window.Handle;
                    GamerServicesDispatcher.Initialize(Game.Services);
                    NetworkSession =
                        NetworkSession.Create(NetworkSessionType.SystemLink, 1, 2);

                    OwnsNetworkSession = true;
                }
            }

            base.Initialize();
        }
Esempio n. 18
0
        /// <summary>
        /// Event handler for when the asynchronous join-from-invite
        /// operation has completed.
        /// </summary>
        static void JoinInvitedOperationCompleted(object sender,
                                                  OperationCompletedEventArgs e)
        {
            ScreenManager screenManager = ((GameScreen)sender).ScreenManager;

            try                     {
                // End the asynchronous join-from-invite operation.
                NetworkSession networkSession =
                    NetworkSession.EndJoinInvited(e.AsyncResult);

                // Create a component that will manage the session we just created.
                NetworkSessionComponent.Create(screenManager, networkSession);

                // Go to the lobby screen.
                screenManager.AddScreen(new LobbyScreen(networkSession), null);
            } catch (Exception exception) {
                screenManager.AddScreen(new MainMenuScreen(), null);
                screenManager.AddScreen(new NetworkErrorScreen(exception), null);
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Shuts down the component.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Remove the NetworkSessionComponent.
                Game.Components.Remove(this);

                // Remove the NetworkSession service.
                Game.Services.RemoveService(typeof(NetworkSession));

                // Dispose the NetworkSession.
                if (networkSession != null)
                {
                    networkSession.Dispose();
                    networkSession = null;
                }
            }

            base.Dispose(disposing);
        }
Esempio n. 20
0
        /// <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);
        }
Esempio n. 21
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public PauseMenuScreen(NetworkSession networkSession)
            : base("")
        {
            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("Resume Game");

            resumeGameMenuEntry.Selected += ResumeGameMenuEntry_Selected;
            MenuEntries.Add(resumeGameMenuEntry);

            if (networkSession == null)
            {
                // If this is a single player game, add the Quit menu entry.
                MenuEntry quitGameMenuEntry = new MenuEntry("Quit Game");
                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("Return to Loby");
                    lobbyMenuEntry.Selected += ReturnToLobbyMenuEntrySelected;
                    MenuEntries.Add(lobbyMenuEntry);
                }

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

                MenuEntry leaveSessionMenuEntry = new MenuEntry(leaveEntryText);
                leaveSessionMenuEntry.Selected += LeaveSessionMenuEntrySelected;
                MenuEntries.Add(leaveSessionMenuEntry);
            }
        }
Esempio n. 22
0
        public static async Task <string> Test1(NetworkSession rSession)
        {
            var rTest2 = new HotfixNetworkTest2();
            await rTest2.Initialize();

            EventManager.Instance.Distribute(GameEvent.EVENT_TEST_1, "hahahahahaha...");

            // 设置热更新端的Session
            HotfixNetworkClient.Instance.Session = rSession;

            // Login
            R2C_Login r2CLogin = (R2C_Login)await HotfixNetworkClient.Instance.Call(new C2R_Login()
            {
                Account = "WinddyHe", Password = "******"
            });

            Debug.LogError("Address: " + r2CLogin.Address);
            LoginKey = r2CLogin.Key;

            return(r2CLogin.Address);
        }
        public void CreateSession()
        {
            if (_session != null)
            {
                _session.Dispose();
            }
            if (Gamer.SignedInGamers.Count == 0)
            {
                SignIn();
            }
            else
            {
                _session              = NetworkSession.Create(NetworkSessionType.SystemLink, 1, 2);
                _session.GamerJoined += new EventHandler <GamerJoinedEventArgs>(Host_GamerJoined);
                _session.GamerLeft   += new EventHandler <GamerLeftEventArgs>(Host_GamerLeft);

                GameMain.ChangeState(GameState.WaitingPlayers);

                IsHost = true;
            }
        }
Esempio n. 24
0
        public void Run(NetworkSession rSession, Packet rPacket)
        {
            if (this.mSession != rSession)
            {
                Debug.LogError("Network Session is not the same one.");
                return;
            }

            ushort nOpcode = rPacket.Opcode;
            byte   nFlag   = rPacket.Flag;

            NetworkOpcodeTypes rOpcodeTypeComponent = this.mSession.Parent.OpcodeTypes;
            Type   rResponseType = rOpcodeTypeComponent.GetType(nOpcode);
            object rMessage      = this.mMessagePacker.DeserializeFrom(rResponseType, rPacket.Bytes, Packet.Index, rPacket.Length - Packet.Index);

            Debug.LogError($"recv: {HotfixJsonParser.ToJsonNode(rMessage)}");

            // 非RPC消息走这里
            if ((nFlag & 0x01) == 0)
            {
                EventManager.Instance.Distribute(nOpcode, rMessage);
                return;
            }

            // Rpc回调消息
            IHotfixResponse rResponse = rMessage as IHotfixResponse;

            if (rResponse == null)
            {
                throw new Exception($"flag is response, but message is not! {nOpcode}");
            }
            Action <IHotfixResponse> rAction;

            if (!this.mRequestCallback.TryGetValue(rResponse.RpcId, out rAction))
            {
                return;
            }
            this.mRequestCallback.Remove(rResponse.RpcId);
            rAction(rResponse);
        }
        /// <summary>
        /// Finishes the asynchronous process of joining a game from an invitation,
        /// joining the lobby of a hosted game if the join was successful.
        /// </summary>
        void InvitedSessionJoined(object sender, OperationCompletedEventArgs e)
        {
            NetworkSession networkSession = null;

            try
            {
                networkSession = NetworkSession.EndJoinInvited(e.AsyncResult);
            }
            catch (NetworkSessionJoinException je)
            {
                const string     message    = "Failed joining the session (";
                MessageBoxScreen messageBox = new MessageBoxScreen(message + je.JoinError.ToString() + ").");
                messageBox.Accepted  += FailedMessageBox;
                messageBox.Cancelled += FailedMessageBox;
                ScreenManager.AddScreen(messageBox);

                System.Console.WriteLine("Failed to join session:  " +
                                         je.Message);
            }
            catch (Exception ge)
            {
                const string     message    = "Failed joining the session (";
                MessageBoxScreen messageBox = new MessageBoxScreen(message + ge.Message + ").");
                messageBox.Accepted  += FailedMessageBox;
                messageBox.Cancelled += FailedMessageBox;
                ScreenManager.AddScreen(messageBox);

                System.Console.WriteLine("Failed to join session:  " +
                                         ge.Message);
            }

            // Start the lobby if we got the session!
            // Otherwise the MainMenuScreen will be available.
            if (networkSession != null)
            {
                LobbyScreen lobbyScreen = new LobbyScreen(networkSession);
                lobbyScreen.ScreenManager = ScreenManager;
                ScreenManager.AddScreen(lobbyScreen);
            }
        }
Esempio n. 26
0
        void JoinGameHandler(object sender, EventArgs e)
        {
            AvailableNetworkSessionCollection sessions = NetworkSession.Find(NetworkSessionType.SystemLink, 2, null);

            if (sessions.Count < 1)
            {
                return;
            }
            Session = NetworkSession.Join(sessions[0]);
            if (Session != null)
            {
                HookSessionEvents();

                UnhookHomeStateEvents();

                GlobalState = new LobbyState();
                GlobalState.Initialize(null);
                GlobalState.LoadContent(Content);

                HookLobbyStateEvents();
            }
        }
Esempio n. 27
0
        public static void CreateSession()
        {
            NetworkSessionType sessionType = (Main.netMode != 0) ? NetworkSessionType.PlayerMatch : NetworkSessionType.Local;

            try
            {
                List <SignedInGamer> list = new List <SignedInGamer>(1);
                list.Add(UI.main.signedInGamer);
                NetworkSessionProperties networkSessionProperties = new NetworkSessionProperties();
                ulong xuid = UI.main.signedInGamer.GetXuid();
                if (UI.main.isInviteOnly)
                {
                    networkSessionProperties[2] = -559038737;
                }
                else
                {
                    networkSessionProperties[0] = (int)xuid;
                    networkSessionProperties[1] = (int)(xuid >> 32);
                }
                int maxGamers         = 8;
                int privateGamerSlots = 0;
                if (!Main.IsTutorial() && UI.main.isInviteOnly)
                {
                    privateGamerSlots = 7;
                }
                session = NetworkSession.Create(sessionType, list, maxGamers, privateGamerSlots, networkSessionProperties);
                session.AllowJoinInProgress = true;
                session.AllowHostMigration  = false;
                hookEvents = true;
                session.StartGame();
            }
            catch (Exception)
            {
                UI.Error(Lang.menu[5], Lang.inter[20]);
                UI.main.menuType = MenuType.MAIN;
                Main.netMode     = 0;
                disconnect       = true;
            }
        }
Esempio n. 28
0
    public void session_SessionFound(IAsyncResult result)
    {
        // All sessions found
        AvailableNetworkSessionCollection availableSessions;
        // The session we will join
        AvailableNetworkSession availableSession = null;

        if (AsyncSessionFind.IsCompleted)
        {
            Console.WriteLine("AsyncSessionFind.IsCompleted");
            availableSessions = NetworkSession.EndFind(result);

            // Look for a session with available gamer slots
            foreach (AvailableNetworkSession curSession in availableSessions)
            {
                Console.WriteLine("foreach");
                int TotalSessionSlots = curSession.OpenPublicGamerSlots + curSession.OpenPrivateGamerSlots;

                if (TotalSessionSlots > curSession.CurrentGamerCount)
                {
                    Console.WriteLine("TotalSessionSlots");
                    availableSession = curSession;
                }
            }

            // If a session was found, connect to it
            if (availableSession != null)
            {
                message = "Found an available session at host " + availableSession.HostGamertag;
                session = NetworkSession.Join(availableSession);
            }
            else
            {
                message = "No sessions found.";
            }
            // Reset the session finding result
            AsyncSessionFind = null;
        }
    }
Esempio n. 29
0
 public void JoinSession()
 {
     try
     {
         using (AvailableNetworkSessionCollection availableSessions = NetworkSession.Find(networkSessionType, maxLocalGamers, null))
         {
             if (availableSessions.Count == 0)
             {
                 errorMessage = "No network sessions found.";
             }
             else
             {
                 networkSession = NetworkSession.Join(availableSessions[0]);
                 HookSessionEvents();
             }
         }
     }
     catch (Exception e)
     {
         errorMessage = e.Message;
     }
 }
Esempio n. 30
0
        private async Task PollAsync(Socket socket, int microSeconds)
        {
            // TODO: this is garbage
#if false
            try {
                if (socket.Poll(microSeconds, SelectMode.SelectRead))
                {
                    Socket remote = await socket.AcceptFromAsync().ConfigureAwait(false);

                    if (manager.Contains(remote.RemoteEndPoint))
                    {
                        NetworkSession session = manager.Get(remote.RemoteEndPoint);
                        await session.PollAndReceiveAllAsync(microSeconds).ConfigureAwait(false);

                        return;
                    }

                    Logger.Info($"New connection from {remote.RemoteEndPoint}");

                    if (MaxConnections >= 0 && manager.Count >= MaxConnections)
                    {
                        Logger.Info("Max connections exceeded, denying new connection!");
                        remote.Close();
                    }
                    else
                    {
                        Logger.Debug("Allowing new connection...");
                        NetworkSession session = _factory.Create(remote);
                        await session.PollAndReceiveAllAsync(microSeconds).ConfigureAwait(false);

                        manager.Add(session);
                    } * /
                }
            } catch (SocketException e) {
                Logger.Error("Exception polling sockets!", e);
            }
#endif
            await Task.Delay(0).ConfigureAwait(false);
        }
Esempio n. 31
0
        public void Initialize()
        {
            SimulatorModules _Modules = new SimulatorModules();
            _Modules.Time_Available = false;             // The plug-in knows the session time.
            _Modules.Track_Coordinates = true;
            _Modules.Track_MapFile = false;
            _Modules.Times_LapsBasic = false;
            _Modules.Times_LastSectors = true;
            _Modules.Times_History_LapTimes = false;
            _Modules.Times_History_SectorTimes = false;
            _Modules.Engine_Power = false;
            _Modules.Engine_PowerCurve = false;
            _Modules.Aero_Drag = false;
            Modules = _Modules;

            Drivers = new NetworkDrivers();
            Player = new NetworkDriverPlayer();
            Session = new NetworkSession();
            Garage = new NetworkGarage();
            Memory = null;

            Telemetry.m.Net.Change += Net_Change;
        }