예제 #1
0
파일: Lobby.cs 프로젝트: JordanFisher/WAL
        public void SendLobbyData()
        {
            var obj = new Dict();

            obj["SteamID"] = SteamCore.PlayerId();
            obj["Maps"]    = Maps;

            string lobby_name = SteamMatches.GetLobbyData("name");
            //string lobby_info = SteamMatches.GetLobbyData("LobbyInfo");
            string lobby_info = Jsonify(GetLobbyInfo());

            if (lobby_info != null && lobby_info.Length > 0 && lobby_name.Length > 0)
            {
                obj["LobbyInfo"]        = lobby_info;
                obj["LobbyName"]        = lobby_name;
                obj["LobbyLoading"]     = false;
                obj["CountDownStarted"] = SteamMatches.GetLobbyData("CountDownStarted");
            }
            else
            {
                obj["LobbyLoading"] = true;
            }

            Send("lobby", obj);
        }
예제 #2
0
        void _Draw(GameTime gameTime)
        {
            DeltaT = gameTime.ElapsedGameTime.TotalSeconds;
            T      = gameTime.TotalGameTime.TotalSeconds;

            GameOverLogic();

            if (NeedsApplication)
            {
                DoActivation();
            }

            if (SteamAvailable)
            {
                SteamCore.Update();
                SteamHtml.Update();
            }

            GameClass.Time = gameTime;
            DrawCount++;
            TimeSinceLoad += gameTime.ElapsedGameTime.TotalSeconds;

            // Update songs
            if (SongWad.Wad != null)
            {
                SongWad.Wad.PhsxStep();
            }

            if (GameClass.GameActive)
            {
                if (ActivateFakeFullScreen)
                {
                    ApplyConfigToForm();
                }

                Input.Update();
            }
            else
            {
                // Normally we would pause the game if we don't have focus.
                // Since this is multiplayer, and since we don't want to give up
                // our GPU resources, we keep rendering as usual.
                // Hopefully nothing awful happens.
                //Graphics.SetRenderTarget(null);
                //Graphics.Clear(Color.Black);

                //base.Draw(gameTime);
                //return;

                Input.Update();
            }

            if (World == null)
            {
                World = new World(Skeleton: true);
            }
            GameLogic(gameTime);

            base.Draw(gameTime);
        }
예제 #3
0
        protected override void Initialize()
        {
            if (UsingSteam)
            {
                Console.WriteLine("Using Steam, checking if restart is needed.");

                if (SteamCore.RestartViaSteamIfNecessary(354560))
                {
                    Console.WriteLine("Restart is needed.");

                    Exit();
                    return;
                }

                Console.WriteLine("Initializing Steam.");
                SteamInitialized = SteamCore.Initialize();
                Console.WriteLine("Steam initialization: {0}", SteamInitialized ? "Success" : "Failed");

                //

                //Test_P2P();
                //Test_CreateLobby();
            }

#if DEBUG
            if (Assets.HotSwap)
            {
                SetupHotswap();
            }
#endif

            EnsureFormPosition();

            FragSharp.Initialize(Content, GraphicsDevice);
            GridHelper.Initialize(GraphicsDevice);

            Assets.Initialize();

            //Test_SaveLoad();

            Sounds.Initialize();
            Render.Initialize();
            Spells.Initialize();
            Networking.Start();

            SteamWrapper.SteamHtml.Initialize((uint)CurrentConfig.Width, (uint)CurrentConfig.Height);
            //SteamWrapper.SteamHtml.Initialize(2880, 1800);
            //SteamWrapper.SteamHtml.Initialize(1280, 720);

            Activated   += ActivatedEvent;
            Deactivated += DeactivatedEvent;

            SetFormOptions();

            BlankWorld = new World();

            base.Initialize();
        }
예제 #4
0
        protected override void OnExiting(object sender, EventArgs args)
        {
            Networking.Cleanup();

            SteamCore.Shutdown();

            Environment.Exit(0);
            base.OnExiting(sender, args);
        }
예제 #5
0
        public void FindLobbies()
        {
            InTrainingLobby = false;

            if (!SteamCore.SteamIsConnected())
            {
                Offline();
            }

            SteamMatches.FindLobbies(OnFindLobbies);
        }
예제 #6
0
 public string PlayerName()
 {
     if (SteamAvailable)
     {
         return(SteamCore.PlayerName());
     }
     else
     {
         return("Me");
     }
 }
예제 #7
0
        void Test_OnCreateLobby(bool result)
        {
            Console.WriteLine(result);

            string player_name = SteamCore.PlayerName();
            string lobby_name  = string.Format("{0}'s lobby", player_name);

            SteamMatches.SetLobbyData("name", lobby_name);

            SteamMatches.FindLobbies(Test_OnFindLobbies);
        }
예제 #8
0
        public void FindFriendLobbies()
        {
            InTrainingLobby = false;

            if (!SteamCore.SteamIsConnected())
            {
                Offline();
            }

            SteamMatches.SetLobbyCallbacks(null, null, null, () => OnFindLobbies(false));
            SteamMatches.FindFriendLobbies(OnFindLobbies);
        }
예제 #9
0
        public static void SetLobbyName()
        {
            string lobby_name = "";

            if (SteamCore.InOfflineMode())
            {
                lobby_name = "Local lobby. Offline.";
            }
            else
            {
                lobby_name = string.Format("{0}'s lobby", SteamCore.PlayerName());
            }

            SteamMatches.SetLobbyData("name", lobby_name);
        }
예제 #10
0
        public void CreateLobby(string lobbyType, bool trainingLobby)
        {
            InTrainingLobby     = trainingLobby;
            Program.GameStarted = false;

            if (!SteamCore.SteamIsConnected())
            {
                SteamCore.SetOfflineMode(true);
            }

            if (SteamMatches.InLobby())
            {
                try { SteamMatches.LeaveLobby(); } catch { }
            }
            ;
            SteamMatches.CreateLobby(OnCreateLobby, StringToLobbyType(lobbyType));
        }
예제 #11
0
파일: Lobby.cs 프로젝트: JordanFisher/WAL
        public void OnJoinLobby(bool result)
        {
            LobbyInfo = new LobbyInfo(Program.MaxPlayers);

            if (result)
            {
                Console.WriteLine("Failure joining the lobby.");

                Send("joinFailed");
                SteamMatches.SetLobbyCallbacks(null, null, null, null);

                return;
            }

            BuildMapList();

            if (SteamMatches.IsLobbyOwner())
            {
                GameMapName = null;
                MapLoading  = true;
                SetMap(Maps[0]);
            }

            string lobbyName = SteamMatches.GetLobbyData("name");

            Console.WriteLine("joined lobby {0}", lobbyName);

            IsHost = SteamMatches.IsLobbyOwner();

            SendLobbyData();
            BuildLobbyInfo(joining_player_id: SteamCore.PlayerId());

            SteamP2P.SetOnP2PSessionRequest(OnP2PSessionRequest);
            SteamP2P.SetOnP2PSessionConnectFail(OnP2PSessionConnectFail);

            string game_started = SteamMatches.GetLobbyData("GameStarted");

            if (game_started == "true")
            {
                _StartGame();
            }
        }
예제 #12
0
        private void NewWorldEditor(string path = null)
        {
            InTrainingLobby = false;

            if (Networking._Server != null)
            {
                Console.WriteLine("Ending previous server.");
                Networking._Server.TemporaryJoin();
                Networking.FinalSend();
            }

            Program.Server          = true;
            Program.Client          = false;
            Program.SteamNetworking = true;
            Program.SteamUsers      = new ulong[] { SteamCore.PlayerId(), 0, 0, 0 };
            Program.SteamServer     = SteamCore.PlayerId();
            Program.SteamSpectators = new List <ulong>();
            Program.Spectate        = false;
            Networking.Start();

            World = new World();

            if (path != null)
            {
                World.Load(path, Retries: 5);
            }

            World.MapEditor = true;

            Console.WriteLine("Making new map editor level.");

            Send("setMode", "in-game");
            Send("setScreen", "editor-ui");

            UpdateEditorJsData();
        }
예제 #13
0
파일: Lobby.cs 프로젝트: JordanFisher/WAL
        public void BuildLobbyInfo(ulong joining_player_id = 0)
        {
            if (!SteamMatches.IsLobbyOwner())
            {
                return;
            }

            PlayerLobbyInfo joining_player = null;

            var PrevInfo = LobbyInfo;

            LobbyInfo = new LobbyInfo(Program.MaxPlayers);

            int members = SteamMatches.GetLobbyMemberCount();

            for (int i = 0; i < members; i++)
            {
                ulong           SteamID = SteamMatches.GetMemberId(i);
                PlayerLobbyInfo player  = new PlayerLobbyInfo();
                player.Spectator = true;

                int index = 0;
                foreach (var prev_player in PrevInfo.Players)
                {
                    if (prev_player.SteamID == SteamID)
                    {
                        player           = LobbyInfo.Players[index] = prev_player;
                        player.Spectator = false;
                    }

                    index++;
                }

                player.Name = SteamMatches.GetMemberName(i);

                if (player.Spectator)
                {
                    player.SteamID = SteamMatches.GetMemberId(i);
                    LobbyInfo.Spectators.Add(player);
                }

                if (player.SteamID == joining_player_id)
                {
                    joining_player = player;
                }
            }

            // For every player that doesn't have a kingdom/team set,
            // choose an available initial value.
            foreach (var player in LobbyInfo.Players)
            {
                if (player.GamePlayer <= 0 || player.GamePlayer > Program.MaxPlayers)
                {
                    player.GamePlayer = FirstKingdomAvailableTo(player);
                }

                if (player.GameTeam <= 0 || player.GameTeam > Program.MaxTeams)
                {
                    player.GameTeam      = FirstTeamAvailableTo(player);
                    player.HasPickedTeam = true;
                }
            }

            // Set the current player to be the host.
            LobbyInfo.Players.ForEach(player => player.Host    = player.SteamID == SteamCore.PlayerId());
            LobbyInfo.Spectators.ForEach(player => player.Host = player.SteamID == SteamCore.PlayerId());

            // If there is a joinging player try to add them and then rebuild.
            if (joining_player_id != 0 && joining_player != null)
            {
                TryToJoin(joining_player.Name, joining_player);
                BuildLobbyInfo();
                return;
            }

            BuildArgs();
            SetLobbyInfo();
        }