public static void ShowTab(NetTabType type, GameObject tabProvider, ElementValue[] elementValues) { if (tabProvider == null) { return; } var openedTab = new NetTabDescriptor(tabProvider, type); //try to dig out a hidden tab with matching parameters and enable it: if (Instance.HiddenNetTabs.ContainsKey(openedTab)) { // Debug.Log( $"Yay, found an old hidden {openedTab} tab. Unhiding it" ); Instance.UnhideTab(Instance.HiddenNetTabs[openedTab]); } if (!Instance.OpenedNetTabs.ContainsKey(openedTab)) { var rightPanelParent = Instance.transform.GetChild(1); NetTab tabInfo = openedTab.Spawn(rightPanelParent); GameObject tabObject = tabInfo.gameObject; //putting into the right place tabObject.transform.localScale = Vector3.one; var rect = tabObject.GetComponent <RectTransform>(); rect.offsetMin = new Vector2(15, 15); rect.offsetMax = -new Vector2(15, 50); Instance.RefreshTabHeaders(); } NetTab tab = Instance.OpenedNetTabs[openedTab]; tab.ImportValues(elementValues); Instance.SelectTab(tab.gameObject, false); }
public override void Deserialize(NetworkReader reader) { base.Deserialize(reader); TabProvider = reader.ReadUInt32(); NetTabType = (NetTabType)reader.ReadInt32(); ElementId = reader.ReadString(); ElementValue = reader.ReadBytesAndSize(); }
public bool CanOpenNetTab(GameObject playerObject, NetTabType netTabType) { if (!hasPower) { Chat.AddExamineMsgFromServer(playerObject, $"{gameObject.ExpensiveName()} is unpowered"); return(false); } return(true); }
public static void SendToPeepers(GameObject provider, NetTabType type, TabAction tabAction, ElementValue[] values = null) { //Notify all peeping players of the change var list = NetworkTabManager.Instance.GetPeepers(provider, type); foreach (var connectedPlayer in list) { Send(connectedPlayer.GameObject, provider, type, tabAction, null, values); } }
public static void CloseTab(NetTabType type, GameObject tabProvider) { var tabDesc = new NetTabDescriptor(tabProvider, type); if (Instance.OpenedNetTabs.ContainsKey(tabDesc)) { var openedTab = Instance.OpenedNetTabs[tabDesc]; Instance.HideTab(openedTab); } }
public NetTabDescriptor(GameObject provider, NetTabType type) { this.provider = provider; this.type = type; if (type == NetTabType.None && this.provider != null) { Logger.LogError("You forgot to set a proper NetTabType in your new tab!\n" + "Go to Prefabs/GUI/Resources and see if any prefabs starting with Tab has Type=None", Category.NetUI); } }
public NetTabDescriptor(GameObject provider, NetTabType type) { this.provider = provider != null?provider.GetComponent <NetworkTabTrigger>() : null; this.type = type; if (type == NetTabType.None && this.provider != null) { Debug.LogError("You forgot to set a proper NetTabType in your new tab!\n" + "Go to Prefabs/GUI/Resources and see if any prefabs starting with Tab has Type=None"); } }
public static TabInteractMessage Send(GameObject tabProvider, NetTabType netTabType, string elementId, string elementValue = "-1") { TabInteractMessage msg = new TabInteractMessage { TabProvider = tabProvider.NetId(), NetTabType = netTabType, ElementId = elementId, ElementValue = elementValue }; msg.Send(); return(msg); }
//Called when player wants to open nettab, so we can validate access public bool CanOpenNetTab(GameObject playerObject, NetTabType netTabType) { if (accessRestrictions != null && restricted) { //Ai always allowed through, check other players access if (playerObject.GetComponent <PlayerScript>().PlayerState != PlayerScript.PlayerStates.Ai && accessRestrictions.CheckAccess(playerObject) == false) { Chat.AddExamineMsgFromServer(playerObject, "Higher Access Level Needed"); return(false); } } return(true); }
public static void UpdateTab(NetTabType type, GameObject tabProvider, ElementValue[] values, bool touched = false) { var lookupTab = new NetTabDescriptor(tabProvider, type); if (Instance.OpenedNetTabs.ContainsKey(lookupTab)) { var tabInfo = Instance.OpenedNetTabs[lookupTab]; var touchedElement = tabInfo.ImportValues(values); if (touched && touchedElement != null) { Instance.ShowFinger(tabInfo.gameObject, touchedElement.gameObject); } } }
public List <ConnectedPlayer> GetPeepers(GameObject provider, NetTabType type) { var descriptor = Tab(provider, type); if (!openTabs.ContainsKey(descriptor)) { return(new List <ConnectedPlayer>()); } var info = openTabs[descriptor]; if (info.IsUnobserved) { return(new List <ConnectedPlayer>()); } return(info.Peepers.ToList()); }
public static void SendToPeepers(GameObject provider, NetTabType type, TabAction tabAction, ElementValue[] values = null) { //Notify all peeping players of the change List <ConnectedPlayer> list = NetworkTabManager.Instance.GetPeepers(provider, type); // TabUpdateMessage logMessage = null; for (var i = 0; i < list.Count; i++) { var connectedPlayer = list[i]; // logMessage = Send(connectedPlayer.GameObject, provider, type, tabAction, null, values); } // if ( logMessage != null ) { // Logger.Log( $"Sending {logMessage}" ); // } }
public static NetMessage Send( GameObject tabProvider, NetTabType netTabType, string elementId, byte[] elementValue = null) { NetMessage msg = new NetMessage { TabProvider = tabProvider.NetId(), NetTabType = netTabType, ElementId = elementId, ElementValue = elementValue }; Send(msg); return(msg); }
public static TabUpdateMessage Send(GameObject recipient, GameObject provider, NetTabType type, TabAction tabAction, GameObject changedBy = null, ElementValue[] values = null) { // if ( changedBy ) { // //body = human_33, hands, uniform, suit // } var msg = new TabUpdateMessage { Provider = provider.NetId(), Type = type, Action = tabAction, ElementValues = values, Touched = changedBy != null }; switch (tabAction) { case TabAction.Open: NetworkTabManager.Instance.Add(provider, type, recipient); //!! resetting ElementValues msg.ElementValues = NetworkTabManager.Instance.Get(provider, type).ElementValues; //!! break; case TabAction.Close: NetworkTabManager.Instance.Remove(provider, type, recipient); break; case TabAction.Update: var playerScript = recipient.Player()?.Script; //fixme: duplication of NetTab.ValidatePeepers //Not sending updates and closing tab for players that don't pass the validation anymore bool validate = playerScript && !playerScript.canNotInteract() && playerScript.IsInReach(provider, true); if (!validate) { Send(recipient, provider, type, TabAction.Close); return(msg); } break; } msg.SendTo(recipient); Logger.LogTrace(msg.ToString(), Category.NetUI); return(msg); }
public static TabUpdateMessage Send(GameObject recipient, GameObject provider, NetTabType type, TabAction tabAction, GameObject changedBy = null, ElementValue[] values = null) { var msg = new TabUpdateMessage { Provider = provider.NetId(), Type = type, Action = tabAction, ElementValues = values, Touched = changedBy != null }; switch (tabAction) { case TabAction.Open: NetworkTabManager.Instance.Add(provider, type, recipient); //!! resetting ElementValues msg.ElementValues = NetworkTabManager.Instance.Get(provider, type).ElementValues; //!! break; case TabAction.Close: NetworkTabManager.Instance.Remove(provider, type, recipient); break; case TabAction.Update: //fixme: duplication of NetTab.ValidatePeepers //Not sending updates and closing tab for players that don't pass the validation anymore var validate = Validations.CanApply(recipient, provider, NetworkSide.Server); if (!validate) { Send(recipient, provider, type, TabAction.Close); return(msg); } break; } msg.SendTo(recipient); Logger.LogTraceFormat("{0}", Category.NetUI, msg); return(msg); }
/// <summary> /// Completely remove the nettab from existence, removing all players from it. /// </summary> /// <param name="provider"></param> /// <param name="type"></param> public void RemoveTab(GameObject provider, NetTabType type) { var ntd = Tab(provider, type); openTabs.TryGetValue(ntd, out var netTab); if (netTab != null) { //remove all peepers //safe copy so we can concurrently modify it var peepers = netTab.Peepers.Select(cp => cp.GameObject).ToList(); foreach (var peeper in peepers) { Remove(provider, type, peeper); TabUpdateMessage.Send(peeper, provider, type, TabAction.Close); } // completely get rid of the tab openTabs.Remove(ntd); Destroy(netTab.gameObject); } }
public static TabUpdateMessage Send(GameObject recipient, GameObject provider, NetTabType type, TabAction tabAction, GameObject changedBy = null, ElementValue[] values = null) { switch (tabAction) { case TabAction.Open: NetworkTabManager.Instance.Add(provider, type, recipient); values = NetworkTabManager.Instance.Get(provider, type).ElementValues; break; case TabAction.Close: NetworkTabManager.Instance.Remove(provider, type, recipient); break; case TabAction.Update: //fixme: duplication of NetTab.ValidatePeepers //Not sending updates and closing tab for players that don't pass the validation anymore var validate = Validations.CanApply(recipient, provider, NetworkSide.Server); if (!validate) { Send(recipient, provider, type, TabAction.Close); return(null); } break; } // SingleMessage, MoreIncoming, EndOfMessage var id = TabMessageType.SingleMessage; Counter++; var uniqueID = Counter; if (Counter > 10000) { Counter = 0; } var elementValuesLists = new Dictionary <List <ElementValue>, TabMessageType>(); if (values != null && tabAction != TabAction.Close) { // get max possible packet size from current transform var maxPacketSize = Transport.activeTransport.GetMaxPacketSize(0); // set currentSize start value to max TCP header size (60b) var currentSize = 100; //Stores the current cycle of ElementValues var elementValues = new List <ElementValue>(); //How many values are being sent var length = values.Length; //Total packet size if all values sent together var totalSize = 0; //Work out totalSize foreach (var value in values) { var size = value.GetSize(); //If a single value is bigger than max packet size cannot proceed if (size + 60 >= maxPacketSize) { Debug.LogError($"This value is above the max mirror packet limit, and cannot be split. Is {size + 60} bytes"); return(null); } totalSize += size; } //Rounds up to the max number of divisions of the max packet size will be needed for values var divisions = (int)Math.Ceiling((float)totalSize / maxPacketSize); //Counter for which division is currently being made var currentDivision = 0; //The loop for making the messages from the values for (var i = 0; i < length; i++) { //Keep adding values until bigger than packet size currentSize += values[i].GetSize(); if (currentSize > maxPacketSize) { currentDivision++; currentSize = 100; //Id MoreIncoming, means it is a multimessage but not the end. id = TabMessageType.MoreIncoming; //If last division then this will be the end, set to end Id of EndOfMessage if (currentDivision == divisions) { id = TabMessageType.EndOfMessage; } //Add value list to the message list elementValuesLists.Add(elementValues, id); elementValues = new List <ElementValue>(); } elementValues.Add(values[i]); } //Single message if (elementValuesLists.Count == 0) { values = elementValues.ToArray(); } //Multimessage, if end division hasnt been reached yet then this last list must be end. else if (currentDivision != divisions) { elementValuesLists.Add(elementValues, TabMessageType.EndOfMessage); } } var count = elementValuesLists.Count; //Single message if (count == 0) { var msg = new TabUpdateMessage { Provider = provider.NetId(), Type = type, Action = tabAction, ElementValues = values, Touched = changedBy != null, ID = id, UniqueID = uniqueID }; msg.SendTo(recipient); Logger.LogTraceFormat("{0}", Category.NetUI, msg); return(null); } foreach (var value in elementValuesLists) { var msg = new TabUpdateMessage { Provider = provider.NetId(), Type = type, Action = tabAction, ElementValues = value.Key.ToArray(), Touched = changedBy != null, ID = value.Value, UniqueID = uniqueID, NumOfMessages = count }; msg.SendTo(recipient); Logger.LogTraceFormat("{0}", Category.NetUI, msg); } return(null); }
public static void ShowTab(NetTabType type, GameObject tabProvider, ElementValue[] elementValues) { if (tabProvider == null) { return; } // Need to spawn a local instance of the NetTab to obtain its isPopOut property first. Parent is changed later. var openedTab = new NetTabDescriptor(tabProvider, type); NetTab tabInfo = openedTab.Spawn(tabProvider.transform); //Make use of NetTab's fancy isPopOut bool instead of depending on the NetTabType. bool isPopOut = tabInfo.isPopOut; if (!Instance.rolledOut && !isPopOut) { Instance.StartCoroutine(Instance.AnimTabRoll()); } //try to dig out a hidden tab with matching parameters and enable it: if (Instance.HiddenNetTabs.ContainsKey(openedTab)) { // Logger.Log( $"Yay, found an old hidden {openedTab} tab. Unhiding it" ); Instance.UnhideTab(Instance.HiddenNetTabs[openedTab]); } if (!Instance.OpenedNetTabs.ContainsKey(openedTab)) { Transform newParent = !isPopOut ? Instance.TabStorage : Instance.TabStoragePopOut; tabInfo.transform.SetParent(newParent, false); GameObject tabObject = tabInfo.gameObject; //putting into the right place tabObject.transform.localScale = Vector3.one; var rect = tabObject.GetComponent <RectTransform>(); if (!isPopOut) { rect.offsetMin = new Vector2(15, 15); rect.offsetMax = -new Vector2(15, 50); } else { //Center it: var localPos = Vector3.zero; localPos.y += 20f; rect.transform.localPosition = localPos; tabInfo.isPopOut = true; } Instance.RefreshTabHeaders(); } NetTab tab = Instance.OpenedNetTabs[openedTab]; tab.ImportValues(elementValues); if (!isPopOut) { Instance.SelectTab(tab.gameObject, false); } }
public static TabUpdateMessage Send(GameObject recipient, GameObject provider, NetTabType type, TabAction tabAction, GameObject changedBy = null, ElementValue[] values = null) { switch (tabAction) { case TabAction.Open: NetworkTabManager.Instance.Add(provider, type, recipient); var instance = NetworkTabManager.Instance.Get(provider, type); if (instance == null) { Logger.LogError($"Couldn't find NetTab to send for {provider.OrNull()?.ExpensiveName()} " + $"Does the tab prefab match the type '{type}'? Make sure that 'Tab{type}' is listed inside the NetTabs SO."); return(default); } values = instance.ElementValues; break;
public NetTab Get(GameObject provider, NetTabType type) { return(Get(Tab(provider, type))); }
public void Remove(GameObject provider, NetTabType type, GameObject player) { Remove(Tab(provider, type), player); }
public void Add(GameObject provider, NetTabType type, GameObject player) { Add(Tab(provider, type), player); }
private static NetTabDescriptor Tab(GameObject provider, NetTabType type) { return(provider == null ? NetTabDescriptor.Invalid : new NetTabDescriptor(provider, type)); }
public static void ShowTab(NetTabType type, GameObject tabProvider, ElementValue[] elementValues) { if (tabProvider == null) { return; } bool isPopOut = false; //Add the popout types here: if ((type == NetTabType.Paper) || (type == NetTabType.ChemistryDispenser)) { isPopOut = true; } if (!Instance.rolledOut && !isPopOut) { Instance.StartCoroutine(Instance.AnimTabRoll()); } var openedTab = new NetTabDescriptor(tabProvider, type); //try to dig out a hidden tab with matching parameters and enable it: if (Instance.HiddenNetTabs.ContainsKey(openedTab)) { // Logger.Log( $"Yay, found an old hidden {openedTab} tab. Unhiding it" ); Instance.UnhideTab(Instance.HiddenNetTabs[openedTab]); } if (!Instance.OpenedNetTabs.ContainsKey(openedTab)) { Transform newParent = !isPopOut ? Instance.TabStorage : Instance.TabStoragePopOut; NetTab tabInfo = openedTab.Spawn(newParent); GameObject tabObject = tabInfo.gameObject; //putting into the right place tabObject.transform.localScale = Vector3.one; var rect = tabObject.GetComponent <RectTransform>(); if (!isPopOut) { rect.offsetMin = new Vector2(15, 15); rect.offsetMax = -new Vector2(15, 50); } else { //Center it: var localPos = Vector3.zero; localPos.y += 20f; rect.transform.localPosition = localPos; tabInfo.isPopOut = true; } Instance.RefreshTabHeaders(); } NetTab tab = Instance.OpenedNetTabs[openedTab]; tab.ImportValues(elementValues); if (!isPopOut) { Instance.SelectTab(tab.gameObject, false); } }