private void Form1_Load(object sender, EventArgs e) { Connection.StartListening(ConnectionType.UDP, new IPEndPoint(IPAddress.Any, 10000)); NetworkComms.AppendGlobalIncomingPacketHandler <string>("RegisterServerAddress", (packetHeader, connection, incomingString) => { try { if (ServerEndPoint == null) { var serverEndPoint = (IPEndPoint)connection.ConnectionInfo.RemoteEndPoint; var clientEndPoint = (IPEndPoint)connection.ConnectionInfo.LocalEndPoint; //此端口tcp用 ServerEndPoint = new IPEndPoint(serverEndPoint.Address, 10012); button1.Enabled = true; button1.Text = $"TCP:{ServerEndPoint}"; textBox1.Text += $"{DateTime.Now}>> server {ServerEndPoint} request connect.\r\n>"; textBox1.Text += $"{DateTime.Now}>> {clientEndPoint.Address} to {ServerEndPoint.Address} port:10001.\r\n>"; //connection.SendObject<long>("SendClientAddress", clientip); UDPConnection.SendObject("RegisterClientAddress", clientEndPoint.Address.Address, new IPEndPoint(ServerEndPoint.Address, 10001)); } } catch (Exception ex) { textBox1.Text += $"client error:{ex.Message}"; } }); }
private static async void PingHandler(PacketHeader packetHeader, Connection connection, string incomingObject) { var ip = (IPEndPoint)connection.ConnectionInfo.RemoteEndPoint; var localEPs = Connection.AllExistingLocalListenEndPoints(); var lep = ""; foreach (var localEP in localEPs[ConnectionType.UDP]) { var lEp = (IPEndPoint)localEP; if (!ip.Address.IsInSameSubnet(lEp.Address)) { continue; } lep = lEp.Address.ToString(); break; } var sent = false; while (!sent) { try { UDPConnection.SendObject($"PONG{lep}", "https://github.com/awooo-ph", ip, NetworkComms.DefaultSendReceiveOptions, ApplicationLayerProtocolStatus.Enabled); sent = true; break; } catch (Exception) { await TaskEx.Delay(100); } } }
public static void RunExample() { //Ensure we use the null serializer for unmanaged connections SendReceiveOptions options = new SendReceiveOptions <NullSerializer>(); //Setup listening for incoming unmanaged UDP broadcasts UDPConnectionListener listener = new UDPConnectionListener(options, ApplicationLayerProtocolStatus.Disabled, UDPOptions.None); Connection.StartListening(listener, new IPEndPoint(IPAddress.Any, 10000)); //Add a packet handler for unmanaged connections NetworkComms.AppendGlobalIncomingUnmanagedPacketHandler((packetHeader, connection, incomingBytes) => { Console.WriteLine("Received {0} bytes from {1}", incomingBytes.Length, connection.ConnectionInfo.RemoteEndPoint); }); //Generate some test data to broadcast byte[] dataToSend = new byte[] { 1, 2, 3, 4 }; //Create an unmanaged packet manually and broadcast the test data //In future this part of the API could potentially be improved to make it clearer using (Packet sendPacket = new Packet("Unmanaged", dataToSend, options)) UDPConnection.SendObject <byte[]>(sendPacket, new IPEndPoint(IPAddress.Broadcast, 10000), options, ApplicationLayerProtocolStatus.Disabled); Console.WriteLine("Client done!"); Console.ReadKey(); }
public void Datasend(byte[] buff) { // NetworkComms.SendObject("VOICE", buff, newUDPConn); //newUDPConn.SendObject<byte[]>("icecream", buff); //UDPConnection.SendObject<byte[]>("icecream", buff, new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10000)); UDPConnection.SendObject("icecream", buff, new IPEndPoint(IPAddress.Parse(ip), 10000)); //Debug.WriteLine("sent"); }
public void SendBroadcast <T>(Node baseNode, T request) { var nodesInRange = _baseNodeRepository.GetAllInRange(baseNode); foreach (var node in nodesInRange) { var endPoint = new IPEndPoint(IPAddress.Broadcast, node.Id); // typeof(T).Name -> pobiera nazwe klasy UDPConnection.SendObject(typeof(T).Name, request, endPoint, new SendReceiveOptions <ProtobufSerializer>()); } }
/// <summary> /// Stops a plugin based on a method /// </summary> /// <param name="method">The method containing the information of the plugin to stop</param> private void StopPlugin(OSAEMethod method) { foreach (Plugin p in plugins) { if (p.PluginName == method.Parameter1) { OSAEObject obj = OSAEObjectManager.GetObjectByName(p.PluginName); if (obj != null) { disablePlugin(p); UDPConnection.SendObject("Plugin", p.PluginName + " | " + p.Enabled.ToString() + " | " + p.PluginVersion + " | Stopped | " + p.LatestAvailableVersion + " | " + p.PluginType + " | " + Common.ComputerName, new IPEndPoint(IPAddress.Broadcast, 10051)); } } } }
private void PluginMessageReceived(PacketHeader header, Connection connection, string message) { Log.Info("A message was recieved from " + connection.ToString() + " which said '" + message + "'."); string[] arguments = message.Split('|'); bool local = false; if (arguments[1] == "True") { OSAEObjectStateManager.ObjectStateSet(arguments[0], "ON", "SYSTEM"); } else if (arguments[1] == "False") { OSAEObjectStateManager.ObjectStateSet(arguments[0], "OFF", "SYSTEM"); } foreach (Plugin p in plugins) { if (p.PluginName == arguments[0]) { local = true; OSAEObject obj = OSAEObjectManager.GetObjectByName(p.PluginName); if (obj != null) { if (arguments[1] == "True") { // enablePlugin(p); // maybe this call should be enable/disable, not sure, moving on startPlugin("SYSTEM", p); UDPConnection.SendObject("Plugin", p.PluginName + " | " + p.Enabled.ToString() + " | " + p.PluginVersion + " | Running | " + p.LatestAvailableVersion + " | " + p.PluginType + " | " + Common.ComputerName, new IPEndPoint(IPAddress.Broadcast, 10051)); } else if (arguments[1] == "False") { stopPlugin("SYSTEM", p); UDPConnection.SendObject("Plugin", p.PluginName + " | " + p.Enabled.ToString() + " | " + p.PluginVersion + " | Stopped | " + p.LatestAvailableVersion + " | " + p.PluginType + " | " + Common.ComputerName, new IPEndPoint(IPAddress.Broadcast, 10051)); } } } } if (!local) { UDPConnection.SendObject("Plugin", message, new IPEndPoint(IPAddress.Broadcast, 10051)); } }
public static async Task <bool> Ping(IPEndPoint ep) { var head = $"PONG{ep.Address}"; var pong = false; NetworkComms.AppendGlobalIncomingPacketHandler <string>(head, (h, c, i) => { NetworkComms.RemoveGlobalIncomingPacketHandler(head); pong = true; }); var sent = false; while (!sent) { try { UDPConnection.SendObject("PING", "https://github.com/awooo-ph", ep, NetworkComms.DefaultSendReceiveOptions, ApplicationLayerProtocolStatus.Enabled); sent = true; break; } catch (Exception) { await TaskEx.Delay(100); } } var start = DateTime.Now; while ((DateTime.Now - start).TotalMilliseconds < 4710) { if (pong) { return(pong); } await TaskEx.Delay(TimeSpan.FromMilliseconds(100)); } return(pong); }
public bool Send <T>(string packetType, T message, IPAddress ip, int port) { if (_connection == null) { return(false); } try { _connection.SendObject <T>(packetType, message, new IPEndPoint(ip, port)); } catch (Exception ex) { Trace.TraceError("[ UDP ] SendToIPEndPoint, Error = {0}", ex.Message + ex.StackTrace); return(false); } return(true); }
protected static async Task Send(string msgType, T message, IPEndPoint ip) { var sent = false; while (!sent) { try { UDPConnection.SendObject(msgType, message, ip, NetworkComms.DefaultSendReceiveOptions, ApplicationLayerProtocolStatus.Enabled); sent = true; break; } catch (Exception ex) { #if __ANDROID__ await Task.Delay(100); #else await TaskEx.Delay(100); #endif } } }
// generic method to send command object to ManageSystem private Task SendCommandToPeer(ConnectionInfo connectionInfo, object cmdObj) { return(Task.Run(() => { try { if (connectionInfo.ConnectionType == ConnectionType.TCP) { TCPConnection conn = TCPConnection.GetConnection(connectionInfo); conn.SendObject("Command", cmdObj); } else if (connectionInfo.ConnectionType == ConnectionType.UDP) { UDPConnection conn = UDPConnection.GetConnection(connectionInfo, UDPOptions.None); conn.SendObject("Command", cmdObj); } } catch (Exception ex) { logger.Info("SendCommandToPeer: Remote[" + connectionInfo.RemoteEndPoint.ToString() + "] Local[" + connectionInfo.LocalEndPoint.ToString() + "] TypeofcmdObj[" + cmdObj.GetType().ToString() + "] Error:" + ex.ToString()); } })); }
public async Task Send(IPEndPoint ep) { if (ep == null) { return; } var sent = false; while (!sent) { try { UDPConnection.SendObject(Header, this, ep, NetworkComms.DefaultSendReceiveOptions, ApplicationLayerProtocolStatus.Enabled); sent = true; break; } catch (Exception) { await Task.Delay(100); } } }
public void PeerDiscovery() { // Announces IP address over UDP, expect nodes to respond with list of peers UDPConnection.SendObject("Announce", CurrentIPAddress(), new IPEndPoint(IPAddress.Broadcast, 10000)); }
private void Timer_Elapsed(object sender, ElapsedEventArgs e) { UDPConnection.SendObject("RegisterServerAddress", "client ip address", new IPEndPoint(IPAddress.Broadcast, 10000)); }
/// <summary> /// periodically checks the command queue to see if there is any commands that need to be processed by plugins /// </summary> private void QueryCommandQueue() { while (running) { try { foreach (OSAEMethod method in OSAEMethodManager.GetMethodsInQueue()) { Log.Debug("Method in queue for: " + method.Owner + " Method: " + method.ObjectName + "." + method.MethodName + "," + method.Parameter1 + "," + method.Parameter2); if (method.ObjectName == "SERVICE") // This Service { switch (method.MethodName) { case "BROADCAST": Log.Info("-> UDP: " + method.Parameter1 + ", " + method.Parameter2); UDPConnection.SendObject(method.Parameter1, method.Parameter2, new IPEndPoint(IPAddress.Broadcast, 10051)); break; case "EXECUTE": Log.Info("Received Execute Method"); UDPConnection.SendObject("Command", method.Parameter1 + " | " + method.Parameter2 + " | " + Common.ComputerName, new IPEndPoint(IPAddress.Broadcast, 10051)); break; case "START PLUGIN": StartPlugin(serviceObject, method); break; case "STOP PLUGIN": StopPlugin(serviceObject, method); break; case "RELOAD PLUGINS": LoadPlugins(serviceObject); break; } OSAEMethodManager.MethodQueueDelete(method.Id); } else if (method.ObjectName.Split('-')[0] == "SERVICE") // Client Services { Log.Debug("Method for client service. Sending Broadcast."); switch (method.MethodName) { case "ON": Log.Info("-> UDP " + method.ObjectName + " | ON"); UDPConnection.SendObject("Manager", method.ObjectName + " | ON", new IPEndPoint(IPAddress.Broadcast, 10052)); break; case "OFF": Log.Info("-> UDP " + method.ObjectName + " | OFF"); UDPConnection.SendObject("Manager", method.ObjectName + " | OFF", new IPEndPoint(IPAddress.Broadcast, 10052)); break; case "EXECUTE": Log.Info("Recieved Execute Method Name"); UDPConnection.SendObject("Command", method.Parameter1 + " | " + method.Parameter2 + " | " + method.ObjectName.Substring(8), new IPEndPoint(IPAddress.Broadcast, 10051)); break; case "START PLUGIN": UDPConnection.SendObject("Plugin", method.ObjectName + " | ON", new IPEndPoint(IPAddress.Broadcast, 10051)); Log.Info("-> UDP: Plugin, " + method.ObjectName + " | ON"); //object name | owner | method name | param1 | param 2 | address | from object //StartPlugin(method); break; case "STOP PLUGIN": UDPConnection.SendObject("Plugin", method.ObjectName + " | OFF", new IPEndPoint(IPAddress.Broadcast, 10051)); Log.Info("-> UDP: Plugin, " + method.ObjectName + " | OFF"); //StopPlugin(method); break; } OSAEMethodManager.MethodQueueDelete(method.Id); } else if (method.ObjectName.Split('-')[0] != "SERVICE") {// THIS IS NOT GOOD ENOUGH. it intercepts all plugins not just local service ones.... //Look up the basetype, if it is a plugin, THEN you can parse on and off for the intercept. //You must also look at the container and see if it is this service like above. OSAEObject tempObj = OSAEObjectManager.GetObjectByName(method.ObjectName); string isContainerService = tempObj.Container.Split('-')[0]; if (tempObj.BaseType == "PLUGIN" && tempObj.Container == ("SERVICE")) // Plugins on the localhost { switch (method.MethodName) { case "ON": OSAEMethodManager.MethodQueueDelete(method.Id); Log.Info("Recieved Start for: " + method.Owner); StartPlugin(serviceObject, method); break; case "OFF": OSAEMethodManager.MethodQueueDelete(method.Id); Log.Info("Recieved Stop for: " + method.Owner); StopPlugin(serviceObject, method); break; default: { foreach (Plugin plugin in plugins) { if (method.ObjectName == plugin.PluginName) { plugin.ExecuteCommand(method); break; } } break; } } OSAEMethodManager.MethodQueueDelete(method.Id); } else if (tempObj.BaseType == "PLUGIN" && isContainerService == "SERVICE") // Plugins on a remote Client Service { //We can translate the the Object from the method to a parameter and just tell the client service to start/stop the plugin switch (method.MethodName) { case "ON": Log.Info("Sending Remote Start for: " + method.Owner); UDPConnection.SendObject("Plugin", method.ObjectName + " | ON", new IPEndPoint(IPAddress.Broadcast, 10051)); Log.Info("-> UDP: Plugin, " + method.ObjectName + " | ON"); break; case "OFF": Log.Info("Sending Remote Stop for: " + method.Owner); UDPConnection.SendObject("Plugin", method.ObjectName + " | OFF", new IPEndPoint(IPAddress.Broadcast, 10051)); Log.Info("-> UDP: Plugin, " + method.ObjectName + " | OFF"); break; default: { Log.Debug("-> UDP: Command, " + method.ObjectName + " | " + method.Owner + " | " + method.MethodName + " | " + method.Parameter1 + " | " + method.Parameter2 + " | " + method.Address + " | " + method.Id); UDPConnection.SendObject("Method", method.ObjectName + " | " + method.MethodName + " | " + method.Parameter1 + " | " + method.Parameter2 + " | " + method.Address + " | " + method.Owner + " | " + method.FromObject, new IPEndPoint(IPAddress.Broadcast, 10051)); break; } } Log.Debug("Removing method from queue with ID: " + method.Id); OSAEMethodManager.MethodQueueDelete(method.Id); } else { bool processed = false; foreach (Plugin plugin in plugins) { if (string.IsNullOrEmpty(method.Owner) || method.Owner.ToLower() == plugin.PluginName.ToLower() || method.ObjectName.ToLower() == plugin.PluginName.ToLower()) { plugin.ExecuteCommand(method); processed = true; break; } } if (!processed) { Log.Debug("Method found for client service plugin. Sending Broadcast."); UDPConnection.SendObject("Plugin", method.ObjectName + " | ON", new IPEndPoint(IPAddress.Broadcast, 10051)); Log.Debug("-> UDP: Command, " + method.ObjectName + " | " + method.Owner + " | " + method.MethodName + " | " + method.Parameter1 + " | " + method.Parameter2 + " | " + method.Address + " | " + method.Id); UDPConnection.SendObject("Command", method.ObjectName + " | " + method.Owner + " | " + method.MethodName + " | " + method.Parameter1 + " | " + method.Parameter2 + " | " + method.Address + " | " + method.Id, new IPEndPoint(IPAddress.Broadcast, 10051)); UDPConnection.SendObject("Command", "Testing", new IPEndPoint(IPAddress.Broadcast, 10051)); UDPConnection.SendObject("Method", "Testing", new IPEndPoint(IPAddress.Broadcast, 10051)); UDPConnection.SendObject("Plugin", "Testing", new IPEndPoint(IPAddress.Broadcast, 10051)); Log.Debug("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"); } Log.Debug("Removing method from queue with ID: " + method.Id); OSAEMethodManager.MethodQueueDelete(method.Id); break; } } } } catch (Exception ex) { Log.Error("Error in QueryCommandQueue!", ex); } Thread.Sleep(100); } }
/// <summary> /// /// </summary> public void LoadPlugins() { this.Log.Info("Loading Plugins..."); OSAEPluginCollection newPlugins = new OSAEPluginCollection(); var pluginAssemblies = new List <OSAEPluginBase>(); var types = PluginFinder.FindPlugins(); foreach (var type in types) { this.Log.Debug("type.TypeName: " + type.TypeName); this.Log.Debug("type.AssemblyName: " + type.AssemblyName); var domain = Common.CreateSandboxDomain("Sandbox Domain", type.Location, SecurityZone.Internet, typeof(OSAEService)); domain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledPluginExceptions); Plugin p = new Plugin(type.AssemblyName, type.TypeName, domain, type.Location); if (!pluginLoaded(p.PluginType)) { newPlugins.Add(p); } } this.Log.Info("Found " + newPlugins.Count.ToString() + " Assemblies"); MySqlConnection connection = new MySqlConnection(Common.ConnectionString); foreach (Plugin plugin in newPlugins) { try { if (plugin.PluginName != "") { this.Log.Info("----------------------------------------------------"); if (!goodConnection) { try { connection.Open(); goodConnection = true; } catch { } } this.Log.Info(plugin.PluginName + ": Connection Passed (" + goodConnection + ")"); if (goodConnection) { if (plugin.PluginName != "") { OSAEObject obj = OSAEObjectManager.GetObjectByName(plugin.PluginName); if (obj == null) { OSAEObjectManager.ObjectAdd(plugin.PluginName, plugin.PluginName, plugin.PluginName + " plugin's Object", plugin.PluginType, "", "", true); obj = OSAEObjectManager.GetObjectByName(plugin.PluginName); } if (obj != null) { this.Log.Info(obj.Name + ": Plugin Object found. Plugin Object Enabled = " + obj.Enabled.ToString()); if (obj.Enabled == 1) { enablePlugin(plugin); } else { plugin.Enabled = false; } this.Log.Info(obj.Name + ": Plugin Enabled = " + plugin.Enabled.ToString()); this.Log.Info(obj.Name + ": Plugin Version = " + plugin.PluginVersion); } } else { //add code to create the object. We need the plugin to specify the type though MySqlDataAdapter adapter; DataSet dataset = new DataSet(); DataSet dataset2 = new DataSet(); MySqlCommand command = new MySqlCommand(); command.Connection = connection; command.CommandText = "SELECT * FROM osae_object_type_property p inner join osae_object_type t on p.object_type_id = t.object_type_id WHERE object_type=@type AND property_name='Computer Name'"; command.Parameters.AddWithValue("@type", plugin.PluginType); adapter = new MySqlDataAdapter(command); adapter.Fill(dataset); command.CommandText = "SELECT * FROM osae_v_object WHERE object_type=@type"; command.Parameters.AddWithValue("@type", plugin.PluginType); adapter = new MySqlDataAdapter(command); adapter.Fill(dataset2); if (dataset.Tables[0].Rows.Count > 0 && dataset2.Tables[0].Rows.Count > 0) { plugin.PluginName = plugin.PluginType + "-" + Common.ComputerName; } else { plugin.PluginName = plugin.PluginType; } this.Log.Info(plugin.PluginName + ": Plugin object does not exist in DB!"); OSAEObjectManager.ObjectAdd(plugin.PluginName, plugin.PluginName, plugin.PluginName, plugin.PluginType, "", "System", false); OSAEObjectPropertyManager.ObjectPropertySet(plugin.PluginName, "Computer Name", Common.ComputerName, sourceName); this.Log.Info(plugin.PluginName + ": Plugin added to DB."); UDPConnection.SendObject("Plugin", plugin.PluginName + " | " + plugin.Enabled.ToString() + " | " + plugin.PluginVersion + " | Stopped | " + plugin.LatestAvailableVersion + " | " + plugin.PluginType + " | " + Common.ComputerName, new IPEndPoint(IPAddress.Broadcast, 10051)); } plugins.Add(plugin); masterPlugins.Add(plugin); } } else { this.Log.Info(plugin.PluginType + " Skipped! (Not Loaded due to missing Object or other issue)"); } } catch (Exception ex) { this.Log.Error("Error loading plugin: " + ex.Message, ex); } } }
/// <summary> /// periodically checks the command queue to see if there is any commands that need to be processed by plugins /// </summary> private void QueryCommandQueue() { this.Log.Debug("QueryCommandQueue"); while (running) { try { foreach (OSAEMethod method in OSAEMethodManager.GetMethodsInQueue()) { this.Log.Debug("Method in Queue, ObjectName: " + method.ObjectName + " MethodLabel: " + method.MethodLabel + " MethodName: " + method.MethodName); LogMethodInformation(method); if (method.ObjectName == "SERVICE-" + Common.ComputerName) { switch (method.MethodName) { case "EXECUTE": this.Log.Info("Recieved Execute Method Name"); UDPConnection.SendObject("Command", method.Parameter1 + " | " + method.Parameter2 + " | " + Common.ComputerName, new IPEndPoint(IPAddress.Broadcast, 10051)); break; case "START PLUGIN": StartPlugin(method); break; case "STOP PLUGIN": StopPlugin(method); break; case "RELOAD PLUGINS": LoadPlugins(); break; } OSAEMethodManager.MethodQueueDelete(method.Id); } else if (method.ObjectName.Split('-')[0] == "SERVICE") { this.Log.Debug("Method for client service. Sending Broadcast."); if (method.MethodName == "EXECUTE") { UDPConnection.SendObject("Command", method.Parameter1 + " | " + method.Parameter2 + " | " + method.ObjectName.Substring(8), new IPEndPoint(IPAddress.Broadcast, 10051)); } OSAEMethodManager.MethodQueueDelete(method.Id); } else { bool processed = false; foreach (Plugin plugin in plugins) { if (plugin.Enabled == true && (method.Owner.ToLower() == plugin.PluginName.ToLower() || method.ObjectName.ToLower() == plugin.PluginName.ToLower())) { this.Log.Debug("Removing method from queue with ID: " + method.Id); plugin.ExecuteCommand(method); processed = true; break; } } if (!processed) { this.Log.Debug("Method found for client service plugin. Sending Broadcast."); UDPConnection.SendObject("Method", method.ObjectName + " | " + method.Owner + " | " + method.MethodName + " | " + method.Parameter1 + " | " + method.Parameter2 + " | " + method.Address + " | " + method.Id, new IPEndPoint(IPAddress.Broadcast, 10051)); this.Log.Debug("Removing method from queue with ID: " + method.Id); } OSAEMethodManager.MethodQueueDelete(method.Id); } } } catch (Exception ex) { this.Log.Error("Error in QueryCommandQueue: " + ex.Message, ex); } System.Threading.Thread.Sleep(100); } }
public void LoadPlugins(string name) { //Log.Info("Entered LoadPlugins"); var types = PluginFinder.FindPlugins(); Log.Info("Loading Plugins"); foreach (var type in types) { Log.Debug("type.TypeName: " + type.TypeName); Log.Debug("type.AssemblyName: " + type.AssemblyName); var domain = Common.CreateSandboxDomain("Sandbox Domain", type.Location, SecurityZone.Internet, typeof(ClientService)); plugins.Add(new Plugin(type.AssemblyName, type.TypeName, domain, type.Location, Common.ComputerName)); } Log.Info("Found " + plugins.Count.ToString() + " plugins"); foreach (Plugin plugin in plugins) { try { Log.Info("---------------------------------------"); Log.Info("plugin name: " + plugin.PluginName); Log.Info("plugin type: " + plugin.PluginType); if (plugin.PluginName != "") { OSAEObject obj = OSAEObjectManager.GetObjectByName(plugin.PluginName); if (obj == null) { OSAEObjectManager.ObjectAdd(plugin.PluginName, "", plugin.PluginName + " plugin's Object", plugin.PluginType, "", name, 50, true); Log.Info(obj.Name + ": Plugin Object Not found. Plugin Object Created."); obj = OSAEObjectManager.GetObjectByName(plugin.PluginName); if (obj == null) { Log.Info(obj.Name + ": I failed to create the Plugin Object!"); } } if (obj != null) { Log.Info("Plugin Object found: " + plugin.PluginName); bool isSystemPlugin = false; foreach (OSAEObjectProperty p in obj.Properties) { if (p.Name == "System Plugin") { if (p.Value == "TRUE") { isSystemPlugin = true; } break; } } Log.Info("isSystemPlugin?: " + isSystemPlugin.ToString()); if (!isSystemPlugin) { if (obj.Enabled == true) { try { startPlugin(plugin); } catch (Exception ex) { Log.Error("Error activating plugin (" + plugin.PluginName + ")", ex); } } else { plugin.Enabled = false; } Log.Info("status: " + plugin.Enabled.ToString()); Log.Info("PluginName: " + plugin.PluginName); Log.Info("PluginVersion: " + plugin.PluginVersion); OSAEObjectPropertyManager.ObjectPropertySet(obj.Name, "Version", plugin.PluginVersion, name); OSAEObjectPropertyManager.ObjectPropertySet(obj.Name, "Author", plugin.PluginAuthor, name); //NetworkComms.SendObject("Plugin", Common.WcfServer, 10051, plugin.PluginName + "|" + plugin.Status + "|" + plugin.PluginVersion + "|" + plugin.Enabled); UDPConnection.SendObject("Plugin", plugin.PluginName + " | " + plugin.Enabled.ToString() + " | " + plugin.PluginVersion + " | Stopped | " + plugin.LatestAvailableVersion + " | " + plugin.PluginType + " | " + Common.ComputerName, new IPEndPoint(IPAddress.Broadcast, 10051)); } } } else { Log.Info("Plugin object does not exist in DB: " + plugin.PluginName); OSAEObjectManager.ObjectAdd(plugin.PluginName, "", plugin.PluginName, plugin.PluginType, "", "System", 50, true); Log.Info("Plugin added to DB: " + plugin.PluginName); UDPConnection.SendObject("Plugin", plugin.PluginName + " | ON | " + plugin.PluginVersion + " | Started | " + plugin.LatestAvailableVersion + " | " + plugin.PluginType + " | " + Common.ComputerName, new IPEndPoint(IPAddress.Broadcast, 10051)); } } catch (Exception ex) { Log.Error("Error loading plugin!", ex); } } Log.Info("Done loading plugins"); }
private void button1_Click(object sender, EventArgs e) { UDPConnection.SendObject("ChatMessage", "This is the broadcast test message!", new IPEndPoint(IPAddress.Broadcast, 10000)); }
//P2PClient.GUID request P2P connection by P2PClient.IP and P2PClient.Port. private void HandleP2PSpecifiedClient(PacketHeader header, Connection connection, P2PClient p2pSourceClient) { var sourceClient = _clientInfoList.FirstOrDefault(client => client.Guid == p2pSourceClient.GUID); ServerMessageReceivedAction(string.Format("3. {0}:{1}({2}) request P2P connection with him", p2pSourceClient.IP, p2pSourceClient.Port, sourceClient.Name)); //stop local listening StopP2PListening(); ServerMessageReceivedAction(string.Format("4.Start P2P connection with {0}:{1}({2})", p2pSourceClient.IP, p2pSourceClient.Port, sourceClient.Name)); if (!_isP2PSource) { //UDPConnection.SendObject<string>("dddd", "TestTest", new IPEndPoint(IPAddress.Parse(p2pSourceClient.IP), p2pSourceClient.Port), NetworkComms.DefaultSendReceiveOptions, ApplicationLayerProtocolStatus.Enabled); UDPConnection.SendObject("dddd", "TestTest", p2pSourceClient.IP, p2pSourceClient.Port); InnerRequestP2PConnection(p2pSourceClient.GUID); } else { UDPConnection.SendObject <string>(PacketType.REQ_P2PEstablished, LocalClientInfo.Guid, new IPEndPoint(IPAddress.Parse(p2pSourceClient.IP), p2pSourceClient.Port), NetworkComms.DefaultSendReceiveOptions, ApplicationLayerProtocolStatus.Enabled); } //P2P to specified client /* * _p2pConnection = UDPConnection.GetConnection(new ConnectionInfo(p2pSourceClient.IP, p2pSourceClient.Port), UDPOptions.None); * _p2pConnection.AppendIncomingPacketHandler<string>(PacketType.REQ_P2PEstablished, HandleP2PEstablished); * * if (!_isP2PSource) * { * ServerMessageReceivedAction(string.Format("5.Send P2P connection try string to {0}:{1}({2})", p2pSourceClient.IP, p2pSourceClient.Port, sourceClient.Name)); * * //for show in server * //connection.SendObject<P2PRequest>(PacketType.REQ_P2PEstablished, new P2PRequest { SourceGuid = LocalClientInfo.Guid, TargetGuid = p2pSourceClient.GUID }); * * //test P2P connection * _p2pConnection.SendObject<string>("TestTest", LocalClientInfo.Guid); * * InnerRequestP2PConnection(p2pSourceClient.GUID); * } * else * { * if (_p2pConnection.ConnectionInfo.ConnectionState == ConnectionState.Established) * { * ServerMessageReceivedAction(string.Format("Established P2P connection with {0}:{1}({2})", p2pSourceClient.IP, p2pSourceClient.Port, sourceClient.Name)); * * _p2pConnection.SendObject<string>(PacketType.REQ_P2PEstablished, LocalClientInfo.Guid); * } * else * { * ServerMessageReceivedAction(string.Format("Fail P2P connection with {0}:{1}({2}) and quit P2P", p2pSourceClient.IP, p2pSourceClient.Port, sourceClient.Name)); * _isP2PSource = false; * * connection.SendObject<P2PRequest>(PacketType.REQ_P2PFailed, new P2PRequest { SourceGuid = LocalClientInfo.Guid, TargetGuid = p2pSourceClient.GUID }); * } * }*/ // else // { // //reset the failed P2P connection between A and B // _p2pConnection = null; // // if (_isP2PSource) // { // ServerMessageReceivedAction(string.Format("Fail P2P connection with {0}:{1}({2}) and quit P2P", p2pSourceClient.IP, p2pSourceClient.Port, sourceClient.Name)); // _isP2PSource = false; // // connection.SendObject<P2PRequest>(PacketType.REQ_P2PFailed, new P2PRequest { SourceGuid = LocalClientInfo.Guid, TargetGuid = p2pSourceClient.GUID }); // return; // } // else // { // ServerMessageReceivedAction(string.Format("Fail P2P connection with {0}:{1}({2}), let him try", p2pSourceClient.IP, p2pSourceClient.Port, sourceClient.Name)); // } // // InnerRequestP2PConnection(p2pSourceClient.GUID); // } }