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); }
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); }
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(); }
protected override void OnExiting(object sender, EventArgs args) { Networking.Cleanup(); SteamCore.Shutdown(); Environment.Exit(0); base.OnExiting(sender, args); }
public void FindLobbies() { InTrainingLobby = false; if (!SteamCore.SteamIsConnected()) { Offline(); } SteamMatches.FindLobbies(OnFindLobbies); }
public string PlayerName() { if (SteamAvailable) { return(SteamCore.PlayerName()); } else { return("Me"); } }
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); }
public void FindFriendLobbies() { InTrainingLobby = false; if (!SteamCore.SteamIsConnected()) { Offline(); } SteamMatches.SetLobbyCallbacks(null, null, null, () => OnFindLobbies(false)); SteamMatches.FindFriendLobbies(OnFindLobbies); }
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); }
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)); }
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(); } }
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(); }
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(); }