public void ProcessPacket(StationUI packet, NebulaConnection conn) { Player player = playerManager.GetPlayer(conn); // if a user adds/removes a ship, drone or warper or changes max power input broadcast to everyone. if ((packet.settingIndex == StationUI.UIsettings.MaxChargePower || packet.settingIndex == StationUI.UIsettings.setDroneCount || packet.settingIndex == StationUI.UIsettings.setShipCount || packet.settingIndex == StationUI.UIsettings.setWarperCount) && player != null && StationUIManager.UpdateCooldown == 0) { playerManager.SendPacketToAllPlayers(packet); } else if (StationUIManager.UpdateCooldown == 0 || !packet.isStorageUI) { List <NebulaConnection> subscribers = StationUIManager.GetSubscribers(packet.stationGId); for (int i = 0; i < subscribers.Count; i++) { if (subscribers[i] != null) { if (subscribers[i] == conn) { /* * as we block the normal method for the client he must run it once he receives this packet. * but only the one issued the request should do it, we indicate this here */ packet.shouldMimick = true; } subscribers[i].SendPacket(packet); } } } // always update values for host SimulatedWorld.OnStationUIChange(packet); }
public void ProcessPacket(StationUI packet, NebulaConnection conn) { Player player = playerManager.GetPlayer(conn); // if a user adds/removes a ship, drone or warper broadcast to everyone. if ((packet.settingIndex == 0 || packet.settingIndex == 8 || packet.settingIndex == 9 || packet.settingIndex == 10) && player != null && StationUIManager.UpdateCooldown == 0) { playerManager.SendPacketToAllPlayers(packet); } else if (StationUIManager.UpdateCooldown == 0 || !packet.isStorageUI) { List <NebulaConnection> subscribers = StationUIManager.GetSubscribers(packet.stationGId); for (int i = 0; i < subscribers.Count; i++) { if (subscribers[i] != null) { if (subscribers[i] == conn) { packet.shouldMimick = true; } Debug.Log("sending packet to subscriber"); subscribers[i].SendPacket(packet); } } } SimulatedWorld.OnStationUIChange(packet); }
public override void ProcessPacket(StationUI packet, NebulaConnection conn) { if (IsHost) { // if a user adds/removes a ship, drone or warper or changes max power input broadcast to everyone. if (StationUIManager.UpdateCooldown == 0 && (packet.SettingIndex == StationUI.EUISettings.MaxChargePower || packet.SettingIndex == StationUI.EUISettings.SetDroneCount || packet.SettingIndex == StationUI.EUISettings.SetShipCount || packet.SettingIndex == StationUI.EUISettings.SetWarperCount) ) { // this is the SendPacketToAllPlayers() logic but we need to set the mimic flag here. using (playerManager.GetConnectedPlayers(out var connectedPlayers)) { foreach (var kvp in connectedPlayers) { Player p = kvp.Value; packet.ShouldMimic = p.Connection == conn; p.SendPacket(packet); } } } else if (packet.SettingIndex == StationUI.EUISettings.AddOrRemoveItemFromStorageResponse) { // if someone adds or removes items by hand broadcast to every player on that planet Player player = playerManager.GetPlayer(conn); if (player != null) { playerManager.SendPacketToPlanet(packet, player.Data.LocalPlanetId); } } else if (StationUIManager.UpdateCooldown == 0 || !packet.IsStorageUI) { List <NebulaConnection> subscribers = StationUIManager.GetSubscribers(packet.PlanetId, packet.StationId, packet.StationGId); for (int i = 0; i < subscribers.Count; i++) { if (subscribers[i] != null) { /* * as we block the normal method for the client he must run it once he receives this packet. * but only the one issued the request should do it, we indicate this here */ packet.ShouldMimic = subscribers[i] == conn; subscribers[i].SendPacket(packet); } } } // always update values for host, but he does not need to rely on the mimic flag (infact its bad for him) packet.ShouldMimic = false; SimulatedWorld.OnStationUIChange(packet); } if (IsClient) { SimulatedWorld.OnStationUIChange(packet); } }