protected void RemoveCommand(MessageProtocols protocol) { if (commands.ContainsKey(protocol)) { commands.Remove(protocol); } }
public void Send(MessageProtocols protocol, object obj = null, bool encrypt = true) { if (writer == null || writer.BaseStream == null) { return; } string line = ""; if (obj != null) { line = JsonConvert.SerializeObject(obj); } if (encrypt && cipher != null) { line = NetworkUtil.InsertEscape(cipher.Encrypt(protocol.ToString())) + "," + NetworkUtil.InsertEscape(cipher.Encrypt(line)); } else { line = NetworkUtil.InsertEscape(protocol.ToString()) + "," + NetworkUtil.InsertEscape(line); } try { writer.WriteLine(line); writer.Flush(); } catch (Exception) { } }
public void Broadcast(MessageProtocols protocol, Worker worker, object obj) { lock (workersLock) foreach (Worker w in workers) { if (worker == null || worker != w) { w.Send(protocol, obj); } } }
/// <summary> /// Sends a message to all connected clients except the given worker. /// </summary> /// <param name="message">The message to sent to the users</param> /// <param name="worker">The work that does not receive the message</param> public void Broadcast(MessageProtocols protocol, object obj) { Broadcast(protocol, null, obj); }
protected void AddCommand(MessageProtocols protocol, Action <NetworkMessage> func) { commands[protocol] = func; }