public static void DoInvite()
        {
            bool _attemptingToInvite = (bool)typeof(TeamSelect2).GetField("_attemptingToInvite", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public).GetValue(Level.current as TeamSelect2);

            if (!Network.isActive)
            {
                bool _didHost = (bool)typeof(TeamSelect2).GetField("_didHost", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public).GetValue(Level.current as TeamSelect2);

                TeamSelect2.FillMatchmakingProfiles();
                DuckNetwork.Host(8, NetworkLobbyType.FriendsOnly);
                (Level.current as TeamSelect2).PrepareForOnline();
                _didHost = true;
            }
            _attemptingToInvite = true;
        }
        public override void Update()
        {
            this._scroll += 0.1f;
            if ((double)this._scroll > 9.0)
            {
                this._scroll = 0.0f;
            }
            this._dots += 0.01f;
            if ((double)this._dots > 1.0)
            {
                this._dots = 0.0f;
            }
            if (this.open)
            {
                foreach (BlacklistServer failedAttempt in this._failedAttempts)
                {
                    failedAttempt.cooldown = Lerp.Float(failedAttempt.cooldown, 0.0f, Maths.IncFrameTimer());
                }
                if (this._signalCrossLocal.currentAnimation == "idle")
                {
                    if (UIMatchmakingBox.pulseLocal)
                    {
                        this._signalCrossLocal.SetAnimation("flicker");
                        UIMatchmakingBox.pulseLocal = false;
                    }
                }
                else if (this._signalCrossLocal.finished)
                {
                    this._signalCrossLocal.SetAnimation("idle");
                }
                if (this._signalCrossNetwork.currentAnimation == "idle")
                {
                    if (UIMatchmakingBox.pulseNetwork)
                    {
                        this._signalCrossNetwork.SetAnimation("flicker");
                        UIMatchmakingBox.pulseNetwork = false;
                    }
                }
                else if (this._signalCrossNetwork.finished)
                {
                    this._signalCrossNetwork.SetAnimation("idle");
                }
                if (Network.connections.Count > 0 && UIMatchmakingBox._state != MatchmakingState.Connecting)
                {
                    this.ChangeState(MatchmakingState.Connecting);
                    DevConsole.Log("|PURPLE|MATCHMAKING |DGGREEN|Network appears to be connecting...", Color.White);
                }
                if (DuckNetwork.status == DuckNetStatus.Connected)
                {
                    if (this._tryHostingLobby != null)
                    {
                        (Level.current as TeamSelect2).CloseAllDialogs();
                        Level.current = (Level) new TeamSelect2();
                        DevConsole.Log("|PURPLE|MATCHMAKING |DGGREEN|Finished! (HOST).", Color.White);
                        return;
                    }
                    if (Level.current is TeamSelect2)
                    {
                        (Level.current as TeamSelect2).CloseAllDialogs();
                        Level.current = (Level) new ConnectingScreen();
                        DevConsole.Log("|PURPLE|MATCHMAKING |DGGREEN|Finished! (CLIENT).", Color.White);
                        return;
                    }
                    Network.Disconnect();
                    this.ChangeState(MatchmakingState.SearchForLobbies);
                    DevConsole.Log("|PURPLE|MATCHMAKING |DGGREEN|Last minute connection error.", Color.White);
                    return;
                }
                switch (UIMatchmakingBox._state)
                {
                case MatchmakingState.ConnectToMoon:
                    Steam.AddLobbyStringFilter("started", "true", SteamLobbyComparison.Equal);
                    Steam.SearchForLobby((User)null);
                    Steam.RequestGlobalStats();
                    UIMatchmakingBox.pulseLocal = true;
                    this.ChangeState(MatchmakingState.ConnectingToMoon);
                    break;

                case MatchmakingState.ConnectingToMoon:
                    if (Steam.lobbySearchComplete)
                    {
                        if (this.searchTryIndex == 0)
                        {
                            this._totalInGameLobbies = Steam.lobbiesFound;
                            if (this._totalInGameLobbies < 0)
                            {
                                this._totalInGameLobbies = 0;
                            }
                            ++this.searchTryIndex;
                            Steam.AddLobbyStringFilter("started", "false", SteamLobbyComparison.Equal);
                            Steam.SearchForLobby((User)null);
                            break;
                        }
                        UIMatchmakingBox.pulseNetwork = true;
                        this._totalLobbiesFound       = Steam.lobbiesFound;
                        List <User> users = Steam.GetSearchLobbyAtIndex(0).users;
                        this._newStatusList.Add("|DGGREEN|Connected to Moon!");
                        this._newStatusList.Add("");
                        this._newStatusList.Add("|DGYELLOW|Searching for companions.");
                        this.ChangeState(MatchmakingState.SearchForLobbies);
                        break;
                    }
                    break;

                case MatchmakingState.SearchForLobbies:
                    if (this._triesSinceSearch == 3)
                    {
                        Steam.AddLobbyStringFilter("started", "true", SteamLobbyComparison.Equal);
                        Steam.SearchForLobby((User)null);
                        this.ChangeState(MatchmakingState.CheckingTotalGames);
                        return;
                    }
                    if (this._tries > 0 && this._tryHostingLobby == null)
                    {
                        DuckNetwork.Host(TeamSelect2.GetSettingInt("maxplayers"), NetworkLobbyType.Public);
                        this._tryHostingLobby = (Network.activeNetwork.core as NCSteam).lobby;
                        if (!this.triedHostingAlready)
                        {
                            this._newStatusList.Add("|DGYELLOW|Searching even harder.");
                        }
                        else
                        {
                            this._newStatusList.Add("|DGYELLOW|Searching.");
                        }
                        this.triedHostingAlready = true;
                        DevConsole.Log("|PURPLE|MATCHMAKING |DGYELLOW|Opened lobby while searching.", Color.White);
                        this._tryHostingWait = 5f + Rando.Float(2f);
                    }
                    foreach (MatchSetting matchSetting in TeamSelect2.matchSettings)
                    {
                        if (matchSetting.value is int)
                        {
                            if (matchSetting.filtered)
                            {
                                Steam.AddLobbyNumericalFilter(matchSetting.id, (int)matchSetting.value, (SteamLobbyComparison)matchSetting.filterMode);
                            }
                            else if (!matchSetting.filtered)
                            {
                                Steam.AddLobbyNearFilter(matchSetting.id, (int)matchSetting.defaultValue);
                            }
                        }
                        if (matchSetting.value is bool)
                        {
                            if (matchSetting.filtered)
                            {
                                Steam.AddLobbyNumericalFilter(matchSetting.id, (bool)matchSetting.value ? 1 : 0, (SteamLobbyComparison)matchSetting.filterMode);
                            }
                            else if (!matchSetting.filtered)
                            {
                                Steam.AddLobbyNearFilter(matchSetting.id, (bool)matchSetting.defaultValue ? 1 : 0);
                            }
                        }
                    }
                    foreach (MatchSetting onlineSetting in TeamSelect2.onlineSettings)
                    {
                        if (onlineSetting.value is int)
                        {
                            if (onlineSetting.filtered)
                            {
                                Steam.AddLobbyNumericalFilter(onlineSetting.id, (int)onlineSetting.value, (SteamLobbyComparison)onlineSetting.filterMode);
                            }
                            else if (!onlineSetting.filtered)
                            {
                                Steam.AddLobbyNearFilter(onlineSetting.id, (int)onlineSetting.defaultValue);
                            }
                        }
                        if (onlineSetting.value is bool)
                        {
                            if (onlineSetting.id == "modifiers")
                            {
                                if (onlineSetting.filtered)
                                {
                                    Steam.AddLobbyStringFilter(onlineSetting.id, (bool)onlineSetting.value ? "true" : "false", SteamLobbyComparison.Equal);
                                }
                            }
                            else if (onlineSetting.filtered)
                            {
                                Steam.AddLobbyNumericalFilter(onlineSetting.id, (bool)onlineSetting.value ? 1 : 0, (SteamLobbyComparison)onlineSetting.filterMode);
                            }
                            else if (!onlineSetting.filtered)
                            {
                                Steam.AddLobbyNearFilter(onlineSetting.id, (bool)onlineSetting.defaultValue ? 1 : 0);
                            }
                        }
                    }
                    Steam.AddLobbyStringFilter("started", "false", SteamLobbyComparison.Equal);
                    Steam.AddLobbyStringFilter("beta", "2.0", SteamLobbyComparison.Equal);
                    Steam.AddLobbyStringFilter("dev", DG.devBuild ? "true" : "false", SteamLobbyComparison.Equal);
                    Steam.AddLobbyStringFilter("modhash", ModLoader.modHash, SteamLobbyComparison.Equal);
                    if (!Steam.waitingForGlobalStats)
                    {
                        this._globalKills = (long)Steam.GetDailyGlobalStat("kills");
                    }
                    Steam.RequestGlobalStats();
                    UIMatchmakingBox.pulseLocal = true;
                    this.ChangeState(MatchmakingState.Searching);
                    ++this._triesSinceSearch;
                    ++this._tries;
                    break;

                case MatchmakingState.CheckingTotalGames:
                    if (Steam.lobbySearchComplete)
                    {
                        this._totalInGameLobbies = Steam.lobbiesFound;
                        if (this._totalInGameLobbies < 0)
                        {
                            this._totalInGameLobbies = 0;
                        }
                        this.ChangeState(MatchmakingState.SearchForLobbies);
                        this._triesSinceSearch = 0;
                        break;
                    }
                    break;

                case MatchmakingState.Searching:
                    if (Steam.lobbySearchComplete)
                    {
                        this._totalLobbiesFound = Steam.lobbiesFound;
                        if (this._tryHostingLobby != null)
                        {
                            --this._totalLobbiesFound;
                        }
                        List <Lobby> lobbyList = new List <Lobby>();
                        DevConsole.Log("|PURPLE|MATCHMAKING |LIME|found " + (object)Math.Max(this._totalLobbiesFound, 0) + " lobbies.", Color.White);
                        for (int index1 = 0; index1 < 2; ++index1)
                        {
                            int num1 = index1 != 0 ? lobbyList.Count : Steam.lobbiesFound;
                            for (int index2 = 0; index2 < num1; ++index2)
                            {
                                Lobby lobby = index1 != 0 ? lobbyList[index2] : Steam.GetSearchLobbyAtIndex(index2);
                                if (this._tryHostingLobby == null || (long)lobby.id != (long)this._tryHostingLobby.id)
                                {
                                    if (index2 == Steam.lobbiesFound - 1)
                                    {
                                        this._failedAttempts.RemoveAll((Predicate <BlacklistServer>)(x => (double)x.cooldown <= 0.0));
                                    }
                                    if (UIMatchmakingBox.nonPreferredServers.Contains(lobby.id) && index1 == 0)
                                    {
                                        lobbyList.Add(lobby);
                                        DevConsole.Log("|PURPLE|MATCHMAKING |DGRED|Skipping " + (object)lobby.id + " (NOT PREFERRED)", Color.White);
                                    }
                                    else if (this.IsBlacklisted(lobby.id))
                                    {
                                        DevConsole.Log("|PURPLE|MATCHMAKING |DGRED|Skipping " + (object)lobby.id + " (BLACKLISTED)", Color.White);
                                    }
                                    else
                                    {
                                        if (this._tryHostingLobby != null)
                                        {
                                            int num2 = -1;
                                            try
                                            {
                                                string lobbyData = lobby.GetLobbyData("randomID");
                                                if (lobbyData != "")
                                                {
                                                    num2 = Convert.ToInt32(lobbyData);
                                                }
                                            }
                                            catch
                                            {
                                            }
                                            if (num2 == -1)
                                            {
                                                DevConsole.Log("|PURPLE|MATCHMAKING |DGYELLOW|Bad lobby seed.", Color.White);
                                                num2 = Rando.Int(2147483646);
                                            }
                                            if (num2 >= this._tryHostingLobby.randomID)
                                            {
                                                DevConsole.Log("|PURPLE|MATCHMAKING |DGYELLOW|Lobby beats own lobby, Attempting join.", Color.White);
                                            }
                                            else
                                            {
                                                DevConsole.Log("|PURPLE|MATCHMAKING |DGYELLOW|Skipping lobby (Chose to keep hosting).", Color.White);
                                                NCSteam.UpdateRandomID(this._tryHostingLobby);
                                                continue;
                                            }
                                        }
                                        this._tryConnectLobby = lobby;
                                        if (lobby.owner != null)
                                        {
                                            this._newStatusList.Add("|LIME|Trying to join " + lobby.owner.name + ".");
                                        }
                                        else
                                        {
                                            this._newStatusList.Add("|LIME|Trying to join server.");
                                        }
                                        this.ChangeState(MatchmakingState.Disconnect);
                                        break;
                                    }
                                }
                            }
                        }
                        if (this._tryConnectLobby == null)
                        {
                            DevConsole.Log("|PURPLE|MATCHMAKING |DGYELLOW|Found no valid lobbies.", Color.White);
                            this.ChangeState(MatchmakingState.SearchForLobbies, 3f);
                            break;
                        }
                        break;
                    }
                    break;

                case MatchmakingState.Waiting:
                    this._stateWait -= Maths.IncFrameTimer();
                    if ((double)this._stateWait <= 0.0)
                    {
                        this._stateWait = 0.0f;
                        this.OnStateChange(this._pendingState);
                        break;
                    }
                    break;

                default:
                    int state = (int)UIMatchmakingBox._state;
                    break;
                }
                if (Input.Pressed("QUACK"))
                {
                    this._quit = true;
                    this.ChangeState(MatchmakingState.Disconnect);
                }
            }
            if (this._newStatusList.Count > 0)
            {
                this._newStatusWait -= 0.1f;
                if ((double)this._newStatusWait <= 0.0)
                {
                    this._newStatusWait = 1f;
                    while ((double)this._fancyFont.GetWidth(this._newStatusList[0]) > 98.0)
                    {
                        this._newStatusList[0] = this._newStatusList[0].Substring(0, this._newStatusList[0].Length - 1);
                    }
                    this._statusList.Add(this._newStatusList[0]);
                    if (this._statusList.Count > 7)
                    {
                        this._statusList.RemoveAt(0);
                    }
                    this._newStatusList.RemoveAt(0);
                }
            }
            base.Update();
        }
Ejemplo n.º 3
0
        public void CreateInstance(int init, bool isHost)
        {
            NetworkDebugger._networkDrawingIndex = init;
            NetworkInstance networkInstance = new NetworkInstance()
            {
                network = new Network(NetworkDebugger._networkDrawingIndex)
            };

            if (this._startLevel == null)
            {
                networkInstance.teamsCore = new TeamsCore();
                networkInstance.teamsCore.Initialize();
            }
            else
            {
                networkInstance.teamsCore = Teams.core;
                List <Team> teamList = new List <Team>((IEnumerable <Team>)Teams.core.extraTeams);
                Teams.core = new TeamsCore();
                Teams.core.Initialize();
                Teams.core.extraTeams = teamList;
            }
            if (this._startLayer != null)
            {
                networkInstance.layerCore = this._startLayer;
                this._startLayer          = (LayerCore)null;
            }
            else
            {
                networkInstance.layerCore = new LayerCore();
                networkInstance.layerCore.InitializeLayers();
            }
            networkInstance.virtualCore = new VirtualTransitionCore();
            networkInstance.virtualCore.Initialize();
            if (this._startLevel == null)
            {
                networkInstance.profileCore = new ProfilesCore();
                networkInstance.profileCore.Initialize();
                networkInstance.profileCore.DefaultPlayer2.team = (Team)null;
            }
            else
            {
                networkInstance.profileCore = Profiles.core;
                Profiles.core = new ProfilesCore();
                Profiles.core.Initialize();
            }
            networkInstance.inputProfile = new InputProfileCore();
            InputProfileCore core1 = InputProfile.core;

            InputProfile.core = networkInstance.inputProfile;
            Input.InitDefaultProfiles();
            networkInstance.levelCore = new LevelCore();
            LevelCore core2 = Level.core;

            Level.core = networkInstance.levelCore;
            networkInstance.crowdCore = new CrowdCore();
            CrowdCore core3 = Crowd.core;

            Crowd.core = networkInstance.crowdCore;
            TeamsCore core4 = Teams.core;

            networkInstance.teamsCore.extraTeams = new List <Team>((IEnumerable <Team>)Teams.core.extraTeams);
            Teams.core = networkInstance.teamsCore;
            ProfilesCore core5 = Profiles.core;

            Profiles.core = networkInstance.profileCore;
            LayerCore core6 = Layer.core;

            Layer.core = networkInstance.layerCore;
            VirtualTransitionCore core7 = VirtualTransition.core;

            VirtualTransition.core = networkInstance.virtualCore;
            Network activeNetwork = Network.activeNetwork;

            Network.activeNetwork = networkInstance.network;
            networkInstance.network.DoInitialize();
            networkInstance.duckNetworkCore = new DuckNetworkCore();
            GameModeCore gameModeCore = new GameModeCore();

            networkInstance.gameModeCore = gameModeCore;
            GameModeCore core8 = GameMode.core;

            GameMode.core = gameModeCore;
            networkInstance.connectionUICore = new ConnectionStatusUICore();
            ConnectionStatusUICore core9 = ConnectionStatusUI.core;

            ConnectionStatusUI.core     = networkInstance.connectionUICore;
            networkInstance.consoleCore = new DevConsoleCore();
            DevConsoleCore core10 = DevConsole.core;

            DevConsole.core = networkInstance.consoleCore;
            DuckNetworkCore core11 = DuckNetwork.core;

            DuckNetwork.core = networkInstance.duckNetworkCore;
            DuckNetwork.Initialize();
            networkInstance.monoCore = new MonoMainCore();
            MonoMainCore core12 = MonoMain.core;

            MonoMain.core = networkInstance.monoCore;
            if (isHost)
            {
                foreach (Profile profile in Profiles.all)
                {
                    if (profile.team != null)
                    {
                        NetworkDebugger.inputProfiles[Persona.Number(profile.persona)] = InputProfile.defaultProfiles[Persona.Number(profile.persona)];
                    }
                }
                DuckNetwork.Host(4, NetworkLobbyType.Public);
                if (this._startLevel != null)
                {
                    Level.current = this._startLevel;
                    this._startLevel.NetworkDebuggerPrepare();
                    this._startLevel = (Level)null;
                }
                else
                {
                    Level.current = (Level) new TeamSelect2();
                }
            }
            else
            {
                Level.current = (Level) new JoinServer(0UL);
            }
            networkInstance.joined = true;
            if (init >= NetworkDebugger._instances.Count)
            {
                NetworkDebugger._instances.Add(networkInstance);
            }
            else
            {
                NetworkDebugger._instances[init] = networkInstance;
            }
            base.Initialize();
            InputProfile.core       = core1;
            Network.activeNetwork   = activeNetwork;
            DuckNetwork.core        = core11;
            Teams.core              = core4;
            Profiles.core           = core5;
            Layer.core              = core6;
            VirtualTransition.core  = core7;
            Level.core              = core2;
            DevConsole.core         = core10;
            Crowd.core              = core3;
            GameMode.core           = core8;
            ConnectionStatusUI.core = core9;
            MonoMain.core           = core12;
        }