public ActionProcessor(ILog log, IDatabase data, ISubscriber sub, ConnectionToClient con) { logger = log; database = data; subscriber = sub; // sub should only be used to subscribe and unsubscribe from things, otherwise it just receives messages. connection = con; }
static void listener_NewConnection(ConnectionToClient conn) { Console.WriteLine("New connection {0}", conn.ClientName); conn.RouteMessage += conn_RouteMessage; conn.AddHandler("bye", HandleDisconnect); conn.AddHandler("ping", Pong); conn.AddHandler("get_uptime", GetUptime); conn.AddHandler("get_modules", GetModules); Clients.Add(conn); }
public void AddSubscriber(ConnectionToClient subscriber) { if (subscriber == null) { Console.WriteLine("Subscriber was null, returning from game element AddSubscriber"); return; } if (subscribers == null) { subscribers = new List <ConnectionToClient>(); } subscribers.Add(subscriber); }
static void conn_RouteMessage(ConnectionToClient conn, Message msg) { Console.WriteLine("Routing message \"{0}\" from \"{1}\" to \"{2}\"", Encoding.Unicode.GetString(msg.Data), msg.Source, msg.Destination); string dest = msg.Destination; if (Clients.Any(c => c.ClientName == dest)) { Clients.First(c => c.ClientName == dest).SendMessage(msg); } else { Console.WriteLine("SHIT"); } }
private void ReceiveHubDisconnectClientRequest(dynamic jsonData) { if (!Authentication.Current.Keys.Any(x => x.Key == jsonData["HubKey"]?.Trim()?.ToLower())) { ConnectionToClient.Close(); return; } foreach (var clientID in jsonData["Clients"]) { var client = AditServer.ClientList.Find(x => x.ID == clientID); if (client != null) { AditServer.ClientList.Remove(client); client.Socket.Close(); } } SendHubDataRequest(jsonData["HubKey"]); }
private void ReceiveHubDeleteClientRequest(dynamic jsonData) { if (!Authentication.Current.Keys.Any(x => x.Key == jsonData["HubKey"]?.Trim()?.ToLower())) { ConnectionToClient.Close(); return; } MainWindow.Current.Dispatcher.Invoke(() => { foreach (var client in jsonData["Clients"]) { var computer = AditHub.Current.ComputerList.FirstOrDefault(x => x.ID == client); if (computer != null) { AditHub.Current.ComputerList.Remove(computer); } } SendHubDataRequest(jsonData["HubKey"]); }); }
public void RemoveSubscriber(ConnectionToClient subscriber) { subscribers.Remove(subscriber); }