public static void Join(string id, string ip = "localhost")
 {
     if (DuckNetwork.core.status != DuckNetStatus.Disconnected)
     {
         return;
     }
     DuckNetwork.Reset();
     foreach (Profile universalProfile in Profiles.universalProfileList)
     {
         universalProfile.team = null;
     }
     for (int index = 0; index < 8; ++index)
     {
         Teams.all[index].customData = null;
     }
     foreach (Profile profile in DuckNetwork.profiles)
     {
         profile.slotType = SlotType.Open;
     }
     DuckNetwork.core.error          = null;
     DuckNetwork.core.localDuckIndex = -1;
     TeamSelect2.DefaultSettings();
     Network.JoinServer(id, 1337, ip);
     DuckNetwork.localConnection.AttemptConnection();
     DuckNetwork.core.attemptTimeout = 15f;
     DuckNetwork.core.status         = DuckNetStatus.EstablishingCommunication;
 }
Пример #2
0
        public override void Initialize()
        {
            TeamSelect2.DefaultSettings();
            base.Initialize();
            this.UpdateDefault();
            bool flag = true;

            foreach (Profile prof in Profiles.active)
            {
                if (flag)
                {
                    flag = false;
                }
                else
                {
                    if (prof.team != null)
                    {
                        prof.team.Leave(prof);
                    }
                    prof.inputProfile = (InputProfile)null;
                }
            }
            this._pendingSpawns = new Deathmatch((Level)this).SpawnPlayers();
            this._pendingSpawns = this._pendingSpawns.OrderBy <Duck, float>((Func <Duck, float>)(sp => sp.x)).ToList <Duck>();
            foreach (Duck pendingSpawn in this._pendingSpawns)
            {
                this.followCam.Add((Thing)pendingSpawn);
                ((ArcadeHatConsole)Level.First <ArcadeHatConsole>())?.MakeHatSelector(pendingSpawn);
            }
            this.followCam.Adjust();
            foreach (ArcadeMachine arcadeMachine in this.things[typeof(ArcadeMachine)])
            {
                this._challenges.Add(arcadeMachine);
            }
            Profiles.active[0].ticketCount = Challenges.GetTicketCount(Profiles.active[0]);
            if (Profiles.active[0].ticketCount < 0)
            {
                Profiles.active[0].ticketCount = 0;
            }
            foreach (ArcadeFrame arcadeFrame in this.things[typeof(ArcadeFrame)])
            {
                this._frames.Add(arcadeFrame);
            }
            foreach (ChallengeSaveData challengeSaveData in Challenges.GetAllSaveData())
            {
                if (challengeSaveData.frameID != "")
                {
                    ArcadeFrame frame = this.GetFrame(challengeSaveData.frameID);
                    if (frame != null)
                    {
                        frame.saveData = challengeSaveData;
                    }
                }
            }
            foreach (ArcadeMachine challenge in this._challenges)
            {
                challenge.unlocked = challenge.CheckUnlocked(false);
            }
            this._hud       = new ArcadeHUD();
            this._hud.alpha = 0.0f;
            Level.Add((Thing)this._hud);
            this._unlockScreen       = new UnlockScreen();
            this._unlockScreen.alpha = 0.0f;
            Level.Add((Thing)this._unlockScreen);
            this._pauseGroup  = new UIComponent(Layer.HUD.camera.width / 2f, Layer.HUD.camera.height / 2f, 0.0f, 0.0f);
            this._pauseMenu   = new UIMenu("@LWING@CHALLENGE MODE@RWING@", Layer.HUD.camera.width / 2f, Layer.HUD.camera.height / 2f, 160f, conString: "@DPAD@MOVE  @SELECT@SELECT");
            this._confirmMenu = new UIMenu("REALLY QUIT?", Layer.HUD.camera.width / 2f, Layer.HUD.camera.height / 2f, 160f, conString: "@SELECT@SELECT");
            UIDivider uiDivider = new UIDivider(true, 0.8f);

            uiDivider.leftSection.Add((UIComponent) new UIMenuItem("RESUME", (UIMenuAction) new UIMenuActionCloseMenu(this._pauseGroup), UIAlign.Left), true);
            uiDivider.leftSection.Add((UIComponent) new UIMenuItem("OPTIONS", (UIMenuAction) new UIMenuActionOpenMenu((UIComponent)this._pauseMenu, (UIComponent)Options.optionsMenu), UIAlign.Left), true);
            uiDivider.leftSection.Add((UIComponent) new UIMenuItem("QUIT", (UIMenuAction) new UIMenuActionOpenMenu((UIComponent)this._pauseMenu, (UIComponent)this._confirmMenu), UIAlign.Left), true);
            uiDivider.rightSection.Add((UIComponent) new UIImage("pauseIcons", UIAlign.Right), true);
            this._pauseMenu.Add((UIComponent)uiDivider, true);
            this._pauseMenu.Close();
            this._pauseGroup.Add((UIComponent)this._pauseMenu, false);
            this._pauseGroup.Add((UIComponent)Options.optionsMenu, false);
            Options.openOnClose = this._pauseMenu;
            this._confirmMenu.Add((UIComponent) new UIMenuItem("NO!", (UIMenuAction) new UIMenuActionOpenMenu((UIComponent)this._confirmMenu, (UIComponent)this._pauseMenu)), true);
            this._confirmMenu.Add((UIComponent) new UIMenuItem("YES!", (UIMenuAction) new UIMenuActionCloseMenuSetBoolean(this._pauseGroup, this._quit)), true);
            this._confirmMenu.Close();
            this._pauseGroup.Add((UIComponent)this._confirmMenu, false);
            this._pauseGroup.Close();
            Level.Add((Thing)this._pauseGroup);
            this._prizeTable = this.things[typeof(PrizeTable)].FirstOrDefault <Thing>() as PrizeTable;
            if (this._prizeTable == null)
            {
                this._prizeTable = new PrizeTable(730f, 124f);
            }
            Chancy.activeChallenge    = (ChallengeData)null;
            Chancy.atCounter          = true;
            Chancy.lookingAtChallenge = false;
            Graphics.fade             = 1f;
            this.basementWasUnlocked  = Unlocks.IsUnlocked("BASEMENTKEY", Profiles.active[0]);
            Level.Add((Thing)this._prizeTable);
            Music.Play("Arcade");
        }
        public static void Host(int maxPlayers, NetworkLobbyType lobbyType)
        {
            if (_core.status != DuckNetStatus.Disconnected)
            {
                return;
            }
            //            DevConsole.Log(DCSection.DuckNet, "|LIME|Hosting new server. ", -1);

            // Rubbish fix for Update calling host with 4 max players. Need better way
            if (maxPlayers == 4 && lobbyType == NetworkLobbyType.FriendsOnly)
            {
                maxPlayers = 8;
            }

            DuckNetwork.Reset();
            foreach (Profile universalProfile in Profiles.universalProfileList)
            {
                universalProfile.team = (Team)null;
            }
            _core.error = (DuckNetErrorInfo)null;
            TeamSelect2.DefaultSettings();
            Network.HostServer(lobbyType, maxPlayers, "duckGameServer", 1337);
            DuckNetwork.localConnection.AttemptConnection();
            foreach (Profile profile in DuckNetwork.profiles)
            {
                profile.slotType = lobbyType != NetworkLobbyType.Private ? (lobbyType != NetworkLobbyType.FriendsOnly ? SlotType.Open : SlotType.Friend) : SlotType.Invite;
                if ((int)profile.networkIndex >= maxPlayers)
                {
                    profile.slotType = SlotType.Closed;
                }
            }
            int num = 1;

            _core.localDuckIndex = -1;
            foreach (MatchmakingPlayer matchmakingProfile in UIMatchmakingBox.matchmakingProfiles)
            {
                string name = Network.activeNetwork.core.GetLocalName();
                if (num > 1)
                {
                    name = name + "(" + num.ToString() + ")";
                }
                if (_core.localDuckIndex == -1)
                {
                    _core.localDuckIndex = (int)matchmakingProfile.duckIndex;
                    _core.hostDuckIndex  = (int)matchmakingProfile.duckIndex;
                }
                Profile profile = (Profile)createProfile.Invoke(null, new object[] { _core.localConnection, name, (int)matchmakingProfile.duckIndex, matchmakingProfile.inputProfile, false, false, false });
                if (num > 1)
                {
                    profile.slotType = SlotType.Local;
                }
                profile.networkStatus = DuckNetStatus.Connected;
                if (matchmakingProfile.team != null)
                {
                    if (matchmakingProfile.team.customData != null)
                    {
                        profile.team = Teams.all[(int)matchmakingProfile.duckIndex];
                        Team.MapFacade(profile.steamID, matchmakingProfile.team);
                    }
                    else
                    {
                        profile.team = matchmakingProfile.team;
                    }
                }
                ++num;
            }
            _core.localConnection.isHost = true;
            _core.status = DuckNetStatus.Connecting;
        }