internal virtual void OnPlayerJoining(RoomPlayerEventArgs e) { if (Disposed) { return; } PlayerJoining?.Invoke(this, e); RoomManager.Channel.BroadcastCencored(new RoomChangeRoomInfoAck2Message(GetRoomInfo())); }
internal virtual void OnPlayerJoining(RoomPlayerEventArgs e) { PlayerJoining?.Invoke(this, e); RoomDto roomDto = new RoomDto(); roomDto.RoomId = (byte)this.Id; roomDto.PlayerCount = (byte)this.Players.Count; roomDto.PlayerLimit = this.Options.PlayerLimit; roomDto.State = (byte)this.GameRuleManager.GameRule.StateMachine.State; roomDto.State2 = (byte)this.GameRuleManager.GameRule.StateMachine.State; roomDto.GameRule = (int)this.Options.GameRule; roomDto.Map = (byte)this.Options.MapID; roomDto.WeaponLimit = this.Options.ItemLimit; roomDto.Name = this.Options.Name; roomDto.Password = this.Options.Password; roomDto.FMBURNMode = GetFMBurnModeInfo(); RoomManager.Channel.Broadcast(new RoomChangeRoomInfoAck2Message(roomDto)); //RoomManager.Channel.Broadcast(new RoomChangeRoomInfoAckMessage(this.Map<Room, RoomDto>())); //RoomManager.Channel.Broadcast(new SUserDataAckMessage(e.Player.Map<Player, UserDataDto>())); }
//void OnTriggerEnter(Collider other) //{ // if (other.gameObject.name == "Spine01") // { // count++; // } //} //private void OnTriggerExit(Collider other) //{ // if(other.gameObject.name == "Spine01") // { // count--; // } //} private void Start() { joining = transform.parent.GetComponent <PlayerJoining>(); }
protected virtual void OnPlayerJoining(RoomPlayerEventArgs e) { PlayerJoining?.Invoke(this, e); RoomManager.Channel.Broadcast(new SChangeGameRoomAckMessage(this.Map <Room, RoomDto>())); RoomManager.Channel.Broadcast(new SUserDataAckMessage(e.Player.Map <Player, UserDataDto>())); }
public void ProcessPacket(HandshakeRequest packet, NebulaConnection conn) { Player player; using (playerManager.GetPendingPlayers(out var pendingPlayers)) { if (!pendingPlayers.TryGetValue(conn, out player)) { conn.Disconnect(DisconnectionReason.InvalidData); Log.Warn("WARNING: Player tried to handshake without being in the pending list"); return; } pendingPlayers.Remove(conn); } if (packet.ModVersion != Config.ModVersion) { conn.Disconnect(DisconnectionReason.ModVersionMismatch, $"{ packet.ModVersion };{ Config.ModVersion }"); return; } if (packet.GameVersionSig != GameConfig.gameVersion.sig) { conn.Disconnect(DisconnectionReason.GameVersionMismatch, $"{ packet.GameVersionSig };{ GameConfig.gameVersion.sig }"); return; } if (packet.HasGS2 != (LocalPlayer.GS2_GSSettings != null)) { conn.Disconnect(DisconnectionReason.GalacticScaleMissmatch, "Either the client or the host did or did not have Galactic Scale installed. Please make sure both have it or dont have it."); return; } SimulatedWorld.OnPlayerJoining(); //TODO: some validation of client cert / generating auth challenge for the client // Load old data of the client string clientCertHash = CryptoUtils.Hash(packet.ClientCert); using (playerManager.GetSavedPlayerData(out var savedPlayerData)) { if (savedPlayerData.TryGetValue(clientCertHash, out var value)) { player.LoadUserData(value); } else { savedPlayerData.Add(clientCertHash, player.Data); } } // Add the username to the player data player.Data.Username = !string.IsNullOrWhiteSpace(packet.Username) ? packet.Username : $"Player {player.Id}"; // Add the Mecha Color to the player data player.Data.MechaColor = packet.MechaColor; // Make sure that each player that is currently in the game receives that a new player as join so they can create its RemotePlayerCharacter PlayerJoining pdata = new PlayerJoining(player.Data.CreateCopyWithoutMechaData()); // Remove inventory from mecha data using (playerManager.GetConnectedPlayers(out var connectedPlayers)) { foreach (var kvp in connectedPlayers) { kvp.Value.SendPacket(pdata); } } // Add the new player to the list using (playerManager.GetSyncingPlayers(out var syncingPlayers)) { syncingPlayers.Add(conn, player); } //Add current tech bonuses to the connecting player based on the Host's mecha player.Data.Mecha.TechBonuses = new PlayerTechBonuses(GameMain.mainPlayer.mecha); var gameDesc = GameMain.data.gameDesc; player.SendPacket(new HandshakeResponse(gameDesc.galaxyAlgo, gameDesc.galaxySeed, gameDesc.starCount, gameDesc.resourceMultiplier, player.Data, (LocalPlayer.GS2_GSSettings != null) ? LocalPlayer.GS2GetSettings() : null)); }
public override void ProcessPacket(LobbyRequest packet, NebulaConnection conn) { if (IsClient) { return; } INebulaPlayer player; using (playerManager.GetPendingPlayers(out Dictionary <INebulaConnection, INebulaPlayer> pendingPlayers)) { if (!pendingPlayers.TryGetValue(conn, out player)) { conn.Disconnect(DisconnectionReason.InvalidData); Log.Warn("WARNING: Player tried to enter lobby without being in the pending list"); return; } if (GameMain.isFullscreenPaused) { conn.Disconnect(DisconnectionReason.HostStillLoading); pendingPlayers.Remove(conn); return; } Dictionary <string, string> clientMods = new Dictionary <string, string>(); using (BinaryUtils.Reader reader = new BinaryUtils.Reader(packet.ModsVersion)) { for (int i = 0; i < packet.ModsCount; i++) { string guid = reader.BinaryReader.ReadString(); string version = reader.BinaryReader.ReadString(); if (!BepInEx.Bootstrap.Chainloader.PluginInfos.ContainsKey(guid)) { conn.Disconnect(DisconnectionReason.ModIsMissingOnServer, guid); pendingPlayers.Remove(conn); return; } clientMods.Add(guid, version); } } foreach (KeyValuePair <string, BepInEx.PluginInfo> pluginInfo in BepInEx.Bootstrap.Chainloader.PluginInfos) { if (pluginInfo.Value.Instance is IMultiplayerMod mod) { if (!clientMods.ContainsKey(pluginInfo.Key)) { conn.Disconnect(DisconnectionReason.ModIsMissing, pluginInfo.Key); pendingPlayers.Remove(conn); return; } string version = clientMods[pluginInfo.Key]; if (mod.CheckVersion(mod.Version, version)) { continue; } conn.Disconnect(DisconnectionReason.ModVersionMismatch, $"{pluginInfo.Key};{version};{mod.Version}"); pendingPlayers.Remove(conn); return; } else { foreach (BepInEx.BepInDependency dependency in pluginInfo.Value.Dependencies) { if (dependency.DependencyGUID == NebulaModAPI.API_GUID) { string hostVersion = pluginInfo.Value.Metadata.Version.ToString(); if (!clientMods.ContainsKey(pluginInfo.Key)) { conn.Disconnect(DisconnectionReason.ModIsMissing, pluginInfo.Key); pendingPlayers.Remove(conn); return; } if (clientMods[pluginInfo.Key] != hostVersion) { conn.Disconnect(DisconnectionReason.ModVersionMismatch, $"{pluginInfo.Key};{clientMods[pluginInfo.Key]};{hostVersion}"); pendingPlayers.Remove(conn); return; } } } } } if (packet.GameVersionSig != GameConfig.gameVersion.sig) { conn.Disconnect(DisconnectionReason.GameVersionMismatch, $"{ packet.GameVersionSig };{ GameConfig.gameVersion.sig }"); pendingPlayers.Remove(conn); return; } } bool isNewUser = false; //TODO: some validation of client cert / generating auth challenge for the client // Load old data of the client string clientCertHash = CryptoUtils.Hash(packet.ClientCert); using (playerManager.GetSavedPlayerData(out Dictionary <string, IPlayerData> savedPlayerData)) { if (savedPlayerData.TryGetValue(clientCertHash, out IPlayerData value)) { using (playerManager.GetConnectedPlayers(out Dictionary <INebulaConnection, INebulaPlayer> connectedPlayers)) { IPlayerData playerData = value; foreach (INebulaPlayer connectedPlayer in connectedPlayers.Values) { if (connectedPlayer.Data == playerData) { playerData = value.CreateCopyWithoutMechaData(); Log.Warn($"Copy playerData for duplicated player{playerData.PlayerId} {playerData.Username}"); } } player.LoadUserData(playerData); } } else { // store player data once he fully loaded into the game (SyncCompleteProcessor) isNewUser = true; } } // Add the username to the player data player.Data.Username = !string.IsNullOrWhiteSpace(packet.Username) ? packet.Username : $"Player {player.Id}"; // Add the Mecha Color to the player data player.Data.MechaColors = packet.MechaColors; Multiplayer.Session.NumPlayers += 1; DiscordManager.UpdateRichPresence(); // if user is known and host is ingame dont put him into lobby but let him join the game if (!isNewUser && Multiplayer.Session.IsGameLoaded) { // Remove the new player from pending list using (playerManager.GetPendingPlayers(out Dictionary <INebulaConnection, INebulaPlayer> pendingPlayers)) { pendingPlayers.Remove(conn); } // Add the new player to the list using (playerManager.GetSyncingPlayers(out Dictionary <INebulaConnection, INebulaPlayer> syncingPlayers)) { syncingPlayers.Add(conn, player); } Multiplayer.Session.World.OnPlayerJoining(player.Data.Username); NebulaModAPI.OnPlayerJoinedGame?.Invoke(player.Data); // Make sure that each player that is currently in the game receives that a new player as join so they can create its RemotePlayerCharacter PlayerJoining pdata = new PlayerJoining((PlayerData)player.Data.CreateCopyWithoutMechaData(), Multiplayer.Session.NumPlayers); // Remove inventory from mecha data using (playerManager.GetConnectedPlayers(out Dictionary <INebulaConnection, INebulaPlayer> connectedPlayers)) { foreach (KeyValuePair <INebulaConnection, INebulaPlayer> kvp in connectedPlayers) { kvp.Value.SendPacket(pdata); } } //Add current tech bonuses to the connecting player based on the Host's mecha ((MechaData)player.Data.Mecha).TechBonuses = new PlayerTechBonuses(GameMain.mainPlayer.mecha); using (BinaryUtils.Writer p = new BinaryUtils.Writer()) { int count = 0; foreach (KeyValuePair <string, BepInEx.PluginInfo> pluginInfo in BepInEx.Bootstrap.Chainloader.PluginInfos) { if (pluginInfo.Value.Instance is IMultiplayerModWithSettings mod) { p.BinaryWriter.Write(pluginInfo.Key); mod.Export(p.BinaryWriter); count++; } } GameDesc gameDesc = GameMain.data.gameDesc; player.SendPacket(new HandshakeResponse(gameDesc.galaxyAlgo, gameDesc.galaxySeed, gameDesc.starCount, gameDesc.resourceMultiplier, gameDesc.savedThemeIds, isNewUser, (PlayerData)player.Data, p.CloseAndGetBytes(), count, Config.Options.SyncSoil, Multiplayer.Session.NumPlayers, DiscordManager.GetPartyId())); } } else { GameDesc gameDesc = Multiplayer.Session.IsGameLoaded ? GameMain.data.gameDesc : UIRoot.instance.galaxySelect.gameDesc; using (BinaryUtils.Writer p = new BinaryUtils.Writer()) { int count = 0; foreach (KeyValuePair <string, BepInEx.PluginInfo> pluginInfo in BepInEx.Bootstrap.Chainloader.PluginInfos) { if (pluginInfo.Value.Instance is IMultiplayerModWithSettings mod) { p.BinaryWriter.Write(pluginInfo.Key); mod.Export(p.BinaryWriter); count++; } } player.SendPacket(new LobbyResponse(gameDesc.galaxyAlgo, gameDesc.galaxySeed, gameDesc.starCount, gameDesc.resourceMultiplier, gameDesc.savedThemeIds, p.CloseAndGetBytes(), count, Multiplayer.Session.NumPlayers, DiscordManager.GetPartyId())); } // Send overriden Planet and Star names player.SendPacket(new NameInputPacket(GameMain.galaxy, Multiplayer.Session.LocalPlayer.Id)); } }
public override void ProcessPacket(StartGameMessage packet, NebulaConnection conn) { if (IsHost) { if (Multiplayer.Session.IsGameLoaded && !GameMain.isFullscreenPaused) { INebulaPlayer player; using (playerManager.GetPendingPlayers(out Dictionary <INebulaConnection, INebulaPlayer> pendingPlayers)) { if (!pendingPlayers.TryGetValue(conn, out player)) { conn.Disconnect(DisconnectionReason.InvalidData); Log.Warn("WARNING: Player tried to enter the game without being in the pending list"); return; } pendingPlayers.Remove(conn); } // Add the new player to the list using (playerManager.GetSyncingPlayers(out Dictionary <INebulaConnection, INebulaPlayer> syncingPlayers)) { syncingPlayers.Add(conn, player); } Multiplayer.Session.World.OnPlayerJoining(player.Data.Username); NebulaModAPI.OnPlayerJoinedGame?.Invoke(player.Data); // Make sure that each player that is currently in the game receives that a new player as join so they can create its RemotePlayerCharacter PlayerJoining pdata = new PlayerJoining((PlayerData)player.Data.CreateCopyWithoutMechaData(), Multiplayer.Session.NumPlayers); // Remove inventory from mecha data using (playerManager.GetConnectedPlayers(out Dictionary <INebulaConnection, INebulaPlayer> connectedPlayers)) { foreach (KeyValuePair <INebulaConnection, INebulaPlayer> kvp in connectedPlayers) { kvp.Value.SendPacket(pdata); } } //Add current tech bonuses to the connecting player based on the Host's mecha ((MechaData)player.Data.Mecha).TechBonuses = new PlayerTechBonuses(GameMain.mainPlayer.mecha); conn.SendPacket(new StartGameMessage(true, (PlayerData)player.Data, Config.Options.SyncSoil)); } else { conn.SendPacket(new StartGameMessage(false, null, false)); } } else if (packet.IsAllowedToStart) { // overwrite local setting with host setting, but dont save it as its a temp setting for this session Config.Options.SyncSoil = packet.SyncSoil; ((LocalPlayer)Multiplayer.Session.LocalPlayer).IsHost = false; ((LocalPlayer)Multiplayer.Session.LocalPlayer).SetPlayerData(packet.LocalPlayerData, true); UIRoot.instance.uiGame.planetDetail.gameObject.SetActive(false); Multiplayer.Session.IsInLobby = false; Multiplayer.ShouldReturnToJoinMenu = false; DSPGame.StartGameSkipPrologue(UIRoot.instance.galaxySelect.gameDesc); InGamePopup.ShowInfo("Loading", "Loading state from server, please wait", null); } else { InGamePopup.ShowInfo("Please Wait", "The host is not ready to let you in, please wait!", "Okay"); } }