private void SendMessage(string command) { string id; string userName; string roomName; string message; string[] cmd_parts = command.Split(Config.SEPERATOR); //0 = command name id = cmd_parts[1]; userName = cmd_parts[2]; roomName = cmd_parts[3]; //int paramLength = userName.Length + roomName.Length + id.Length + 3; message = cmd_parts[4]; User sender = allUsers[allUsers.IndexOf(new User(userName))]; Room[] rooms = userRooms[sender].ToArray(); foreach (Room room in rooms) { foreach (User roomUser in room.Users) { IChatConnection chatCon = roomUser.ChatConnection; if (chatCon != null) { string chatMsg = String.Format("{0}|{1}|{2}", roomName, userName, message); chatCon.SendMessage(chatMsg); } } } }
protected override async Task OnInitializedAsync() { _chatConnection = await this.ChatService.ConnectToChatAsync(this.NavigationManager.BaseUri); _chatConnection.MessageReceived += (sender, eArgs) => { this.ChatHistory.Insert(0, eArgs.Message); this.StateHasChanged(); }; }
public void DestroyLoungeChat() { if (loungeChat != null) { IChatConnection connection = loungeChat.connection; loungeChat.Disconnect(null); if (this.OnDestroyLoungeChat != null) { this.OnDestroyLoungeChat(loungeChat); } loungeChat = null; } }
private void SwitchRoomChatConnection(IChatConnection connection) { if (roomChat != null) { IChatConnection conn = roomChat.connection; roomChat.Disconnect(delegate { ChatWebSocketConnection chatWebSocketConnection = conn as ChatWebSocketConnection; if (chatWebSocketConnection != null) { Object.Destroy(chatWebSocketConnection); } roomChat.SetConnection(connection); roomChat.JoinRoom(0); }); } }
public void CreateLoungeChat(IChatConnection conn) { if (loungeChat != null) { loungeChat.Disconnect(null); if (this.OnDestroyLoungeChat != null) { this.OnDestroyLoungeChat(loungeChat); } loungeChat = null; } loungeChat = new ChatRoom(); loungeChat.SetConnection(conn); if (this.OnCreateLoungeChat != null) { this.OnCreateLoungeChat(loungeChat); } }
private void CreateRoomChat(IChatConnection conn) { if (roomChat != null) { roomChat.Disconnect(null); if (this.OnDestroyRoomChat != null) { this.OnDestroyRoomChat(roomChat); } roomChat = null; } roomChat = new ChatRoom(); roomChat.SetConnection(conn); if (this.OnCreateRoomChat != null) { this.OnCreateRoomChat(); } }
public void SetConnection(IChatConnection connection) { if (this.connection != null) { if (this.connection.isEstablished) { this.connection.Disconnect(null); } connection.onReceiveText -= _OnReceiveText; connection.onReceiveStamp -= _OnReceiveStamp; connection.onReceiveNotification -= _OnReceiveNotification; } this.connection = connection; connection.onJoin += _OnJoin; connection.onReceiveText += _OnReceiveText; connection.onReceiveStamp += _OnReceiveStamp; connection.onReceiveNotification += _OnReceiveNotification; connection.onDisconnect += _OnDisconnect; }
public void DestroyRoomChat() { if (roomChat != null) { IChatConnection conn = roomChat.connection; roomChat.Disconnect(delegate { ChatWebSocketConnection chatWebSocketConnection = conn as ChatWebSocketConnection; if (chatWebSocketConnection != null) { Object.Destroy(chatWebSocketConnection); } }); if (this.OnDestroyRoomChat != null) { this.OnDestroyRoomChat(roomChat); } roomChat = null; } }
public CommandService( IChatModel cm, IChatConnection conn, IChannelManager manager, IUnityContainer contain, IRegionManager regman, IEventAggregator eventagg, ICharacterManager characterManager, IAutomationService automation) : base(contain, regman, eventagg, cm, characterManager) { connection = conn; this.manager = manager; this.automation = automation; Events.GetEvent<CharacterSelectedLoginEvent>() .Subscribe(GetCharacter, ThreadOption.BackgroundThread, true); Events.GetEvent<ChatCommandEvent>().Subscribe(EnqueAction, ThreadOption.BackgroundThread, true); Events.GetEvent<ConnectionClosedEvent>().Subscribe(WipeState, ThreadOption.PublisherThread, true); ChatModel.CurrentAccount = connection.Account; }
public static IObservable <string> ToObservable(this IChatConnection connection) { return(Observable.Create <string>( observer => { Action <string> OnReceive = message => { observer.OnNext(message); }; connection.Received += OnReceive; Action OnComplete = () => { observer.OnCompleted(); }; connection.Closed += OnComplete; Action <Exception> OnError = ex => { observer.OnError(ex); }; connection.Error += OnError; return () => { connection.Received -= OnReceive; connection.Closed -= OnComplete; connection.Error -= OnError; }; //return Disposable.Create(() => //{ // connection.Received -= OnReceive; // connection.Closed -= OnComplete; // connection.Error -= OnError; //}); })); }
//TO DO:ChatSocket private void LoginRequest(string command) { string id; string userName; string serverIP; string clientIP; string message; string[] cmd_parts = command.Split(Config.SEPERATOR); id = cmd_parts[1]; userName = cmd_parts[2]; serverIP = cmd_parts[3]; clientIP = cmd_parts[4]; if (Dns.GetHostEntry(Dns.GetHostName()).AddressList.Contains(IPAddress.Parse(serverIP)) || serverIP.Contains("127.0.0.1") || serverIP.Contains("localhost")) { User user = new User(userName, clientIP); //TODO: Open socket so user can connect. ConnectionManager conMan = ConnectionManager.GetInstance(); IChatConnection chatCon = conMan.Listen(clientIP); user.ChatConnection = chatCon; IList <Room> defaultRooms = new List <Room>(); defaultRooms.Add(lobby); userRooms.Add(user, defaultRooms); message = Config.GenerateCommand(Config.CMD.LOGIN_RESPONSE, id, "OK"); queueManager.SendToResponseQueue(message); } }
public ObservableConnection(IChatConnection chatConnection) { _chatConnection = chatConnection; }
public MessageService( IRegionManager regman, IUnityContainer contain, IEventAggregator events, IChatModel model, IChatConnection connection, IListConnection api, ICharacterManager manager, ILoggingService logger, IAutomationService automation) { this.logger = logger; this.automation = automation; try { region = regman.ThrowIfNull("regman"); container = contain.ThrowIfNull("contain"); this.events = events.ThrowIfNull("events"); this.model = model.ThrowIfNull("model"); this.connection = connection.ThrowIfNull("connection"); this.api = api.ThrowIfNull("api"); characterManager = manager.ThrowIfNull("characterManager"); this.model.SelectedChannelChanged += (s, e) => RequestNavigate(this.model.CurrentChannel.Id); this.events.GetEvent<ChatOnDisplayEvent>() .Subscribe(BuildHomeChannel, ThreadOption.UIThread, true); this.events.GetEvent<RequestChangeTabEvent>() .Subscribe(RequestNavigate, ThreadOption.UIThread, true); this.events.GetEvent<UserCommandEvent>().Subscribe(CommandRecieved, ThreadOption.UIThread, true); commands = new Dictionary<string, CommandHandler> { {"priv", OnPrivRequested}, {Commands.UserMessage, OnPriRequested}, {Commands.ChannelMessage, OnMsgRequested}, {Commands.ChannelAd, OnLrpRequested}, {Commands.UserStatus, OnStatusChangeRequested}, {"close", OnCloseRequested}, {"join", OnJoinRequested}, {Commands.UserIgnore, OnIgnoreRequested}, {"clear", OnClearRequested}, {"clearall", OnClearAllRequested}, {"_logger_open_log", OnOpenLogRequested}, {"_logger_open_folder", OnOpenLogFolderRequested}, {"code", OnChannelCodeRequested}, {"_snap_to_last_update", OnNotificationFocusRequested}, {Commands.UserInvite, OnInviteToChannelRequested}, {"who", OnWhoInformationRequested}, {"getdescription", OnChannelDescripionRequested}, {"interesting", OnMarkInterestedRequested}, {"notinteresting", OnMarkNotInterestedRequested}, {"ignoreUpdates", OnIgnoreUpdatesRequested}, {Commands.AdminAlert, OnReportRequested}, {"tempignore", OnTemporaryIgnoreRequested}, {"tempunignore", OnTemporaryIgnoreRequested}, {"tempinteresting", OnTemporaryInterestingRequested}, {"tempnotinteresting", OnTemporaryInterestingRequested}, {"handlelatest", OnHandleLatestReportRequested}, {"handlereport", OnHandleLatestReportByUserRequested} }; } catch (Exception ex) { ex.Source = "Message Daemon, init"; Exceptions.HandleException(ex); } }
public static IObservable <string> ToObservable(this IChatConnection connection) { return(new ObservableConnection(connection)); }