/// <summary> /// Sends the packed data to the receiver to be executed. /// </summary> /// <param name="method">The method to execute on the receiver corresponding to the same event id used in the packed data</param> /// <param name="data">The packed data of the method to execute</param> /// <param name="receiver">The optional receiver, if the method is a client method</param> private void SendData(MethodInfo method, byte[] data, ulong?receiver = null) { foreach (var attr in method.CustomAttributes) { if (attr.AttributeType == typeof(ServerAttribute)) { MyNetUtil.SendPacketToServer(HANDLER_ID, data); } else if (attr.AttributeType == typeof(ClientAttribute)) { if (receiver.HasValue) { MyNetUtil.SendPacket(HANDLER_ID, data, receiver.Value); } else { MyNetUtil.SendPacketToClients(HANDLER_ID, data); } } else if (attr.AttributeType == typeof(BroadcastAttribute)) { MyNetUtil.SendPacketToClients(HANDLER_ID, data); } } }
/// <summary> /// Unloads all data used by this session component /// </summary> protected override void UnloadData() { m_registeredMethods.Clear(); m_registeredMethods = null; Static = null; MyNetUtil.UnregisterMessageHandlers(HANDLER_ID); }
/// <summary> /// Initializes the network message handler, by registering it in SpaceEngineers and /// registering all networking methods using the networking attributes. /// </summary> public override void LoadData() { m_registeredMethods = new Dictionary <ulong, MethodInfo>(); Static = this; MyNetUtil.RegisterMessageHandler(HANDLER_ID, MessageHandler); RegisterAll(); }
/// <summary> /// Checks if the plugin is installed on the server /// </summary> private void CheckPluginInstalledOnServer() { if (!m_pluginInstalled) { MyNetUtil.PingServer(delegate { m_pluginInstalled = true; RecreateControls(false); }); } }
void Start() { versionText.text = kAppName + " " + kVersion; myipText.text = MyNetUtil.getMyIPAddress() + " (" + port.ToString() + ")"; startTread(); }