public void SendWhisper(PublishingEvent ev) { if (ev.Cancel) { return; } AuthenticatedClient sender = (AuthenticatedClient)clientRepository.GetByID(ev.Message.clientId); Whisper whisper = Whisper.FromMessage(ev.Message); if (whisper == null) { ev.Cancel = true; ev.CancellationReason = "Format error"; SendInfoToClient(sender, "Usage: /whisper <nickname> message"); return; } AuthenticatedClient receiver = clientRepository.WhereSubscribedTo("/chat") .Cast <AuthenticatedClient>() .FirstOrDefault(user => user.HasUsername(whisper.Username)); if (receiver == null) { SendInfoToClient(sender, "User " + whisper.Username + " is not connected to the chat"); return; } SendInfoToClient(sender, "To " + whisper.Username + ": " + whisper.Message); SendInfoToClient(receiver, sender.Username + " whispers: " + whisper.Message); }
public void CheckHandshake(HandshakingEvent ev) { // Based on the (client side) authentication Howto at http://cometd.org/documentation/howtos/authentication // If we have credentials, then they are transferred via "ext" // ext will be a Dictionary<string,object> with a key, "authentication" // authentication will be a Dictionary<string,object> with two keys, "user" and "credentials" var authenticationDictionary = ev.Handshake.GetExt <Dictionary <string, object> >("authentication"); object user; object credentials; if (authenticationDictionary != null && authenticationDictionary.TryGetValue("user", out user) && authenticationDictionary.TryGetValue("credentials", out credentials)) { if (user is string && credentials.Equals("password")) { AuthenticatedClient authenticatedClient = (AuthenticatedClient)ev.Client; authenticatedClient.Username = (string)user; authenticatedClient.Password = (string)credentials; return; } ev.CancellationReason = "Incorrect username or password"; } else { ev.CancellationReason = "Credentials not supplied"; } ev.Cancel = true; ev.Retry = false; }
public void SendInfoToUser( AuthenticatedClient i_user, string i_text ) { Message message = new Message { channel = "/chat", clientId = i_user.ID }; message.SetData( "message", i_text ); i_user.Enqueue( message ); i_user.FlushQueue(); }