Exemple #1
0
        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult messageBoxResult = MessageBox.Show($"Do you want to exit?", "Exit Confirmation", MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                foreach (var key in ClientInstances.Instance.GameList.Keys.ToList())
                {
                    if (ClientInstances.Instance.GameList.ContainsKey(key))
                    {
                        ClientInstances.Instance.GameList[key].Close();
                        ClientInstances.Instance.GameList.Remove(key);
                        GameHost.UserLeftGameAsync(User, key);
                    }
                }
                foreach (var key in ClientInstances.Instance.PrivateChats.Keys.ToList())
                {
                    ClientInstances.Instance.PrivateChats[key].Close();
                    ClientInstances.Instance.PrivateChats.Remove(key);//remove from private chats list
                    ChatHost.ExitPrivateChatAsync(User, key);
                }
                ChatHost.LogoutAsync(User);

                Application.Current.Shutdown();
            }
        }
Exemple #2
0
 public void Start()
 {
     chatHost = new ChatHost(localEndPoint.Address);
     chatHost.Start();
     chatHost.MessageReceived += chatHost_MessageReceived;
     chatSessions              = new ChatSessionCollection();
 }
Exemple #3
0
 private ActivitySession(Guid chatSessionId, ChatHost chatHost, ISquiggleEndPoint localUser, ISquiggleEndPoint remoteUser, Guid Id, bool selfInitiated)
 {
     this.chatSessionId = chatSessionId;
     this.ChatHost      = chatHost;
     this.localUser     = localUser;
     this.remoteUser    = remoteUser;
     this.Id            = Id;
     this.SelfInitiated = selfInitiated;
 }
Exemple #4
0
        public bool Accept()
        {
            bool success = ExceptionMonster.EatTheException(() =>
            {
                ChatHost.AcceptActivityInvite(Id, localUser, remoteUser);
            }, "accepting activity invite from " + remoteUser);

            return(success);
        }
        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            ChatHost.BackToChat(User, Opponent);

            if (ClientInstances.Instance.HowFirstsList.ContainsKey(Opponent))
            {
                ClientInstances.Instance.HowFirstsList[Opponent].Close();
                ClientInstances.Instance.HowFirstsList.Remove(Opponent);
            }
        }
Exemple #6
0
 //Send Button Click
 private void SendButton_Click(object sender, RoutedEventArgs e)
 {
     if (sendTextBox.Text != string.Empty)
     {
         var userName = User;
         var content  = sendTextBox.Text;
         ChatHost.SendMessageAsync(userName, content);
         sendTextBox.Text = string.Empty;
     }
 }
Exemple #7
0
 public void Stop()
 {
     if (chatHost != null)
     {
         chatHost.MessageReceived -= chatHost_MessageReceived;
         chatHost.Dispose();
         chatHost = null;
         chatSessions.Clear();
     }
 }
Exemple #8
0
        public void SendData(byte[] chunk, Action <Exception> onError)
        {
            Exception ex;

            if (!ExceptionMonster.EatTheException(() =>
            {
                ChatHost.ReceiveActivityData(Id, localUser, remoteUser, chunk);
            }, "sending data to " + remoteUser.ToString(), out ex))
            {
                onError(ex);
            }
        }
        //Custom X button and log out
        public void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            if (ClientInstances.Instance.PrivateChats.ContainsKey(Opponent))
            {
                ClientInstances.Instance.PrivateChats.Remove(Opponent);
            }
            ClientInstances.Instance.Chat.UpdateUserList();

            ChatHost.ExitPrivateChatAsync(User, Opponent);

            Close();
        }
        //Send Button Event
        private void SendButton_Click(object sender, RoutedEventArgs e)
        {
            var msg = sendTextBox.Text;

            if (msg != string.Empty && User != string.Empty && Opponent != string.Empty)
            {
                ChatHost.SendPrivateMsgAsync(User, Opponent, msg);
            }
            else
            {
                ChatHost.SendPrivateMsgAsync("ghost", "ghost", msg);
            }

            sendTextBox.Text = string.Empty;
        }
Exemple #11
0
        public ChatSession(Guid sessionID, ChatHost localHost, ISquiggleEndPoint localUser, ISquiggleEndPoint remoteUser)
        {
            this.Id        = sessionID;
            this.chatHost  = localHost;
            this.localUser = localUser;

            localHost.ChatInviteReceived         += chatHost_ChatInviteReceived;
            localHost.ActivityInvitationReceived += chatHost_ActivityInvitationReceived;
            localHost.TextMessageReceived        += chatHost_MessageReceived;
            localHost.TextMessageUpdated         += chatHost_MessageUpdated;
            localHost.UserTyping           += chatHost_UserTyping;
            localHost.BuzzReceived         += chatHost_BuzzReceived;
            localHost.UserJoined           += chatHost_UserJoined;
            localHost.UserLeft             += chatHost_UserLeft;
            localHost.SessionInfoRequested += chatHost_SessionInfoRequested;
            localHost.SessionInfoReceived  += chatHost_SessionInfoReceived;

            remoteUsers = new Dictionary <string, ISquiggleEndPoint>();
            CreateRemoteUsers(Enumerable.Repeat(remoteUser, 1));
        }
Exemple #12
0
        private void PrivateChatButton_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult messageBoxResult;

            if (userOnlineList.SelectedIndex >= 0)
            {
                var opponent = ((TextBlock)userOnlineList.SelectedItem).Text;

                if (opponent == User)
                {
                    messageBoxResult = MessageBox.Show("Do you want to chat with your self? Ah ah ah!!!");
                }
                else if (ClientInstances.Instance.PrivateChats.ContainsKey(opponent))
                {
                    ChatHost.SendErrorMessageAsync(opponent, "This type really wants to talk to you, write to him urgently!");
                    messageBoxResult = MessageBox.Show("You have already open private chat with this user.");
                }
                else if (opponent == Player.autoPlayer.ToString())
                {
                    messageBoxResult = MessageBox.Show("Do you want to chat with computer? Ah ah ah!!!");
                }
                else if (ClientInstances.Instance.PrivateChats.ContainsKey(opponent))
                {
                    var window = ClientInstances.Instance.PrivateChats[opponent];
                    window.Topmost   = true;
                    messageBoxResult = MessageBox.Show($"Private chat with {opponent} is open");
                }
                else
                {
                    ChatHost.PrivateChat(User, opponent);
                }

                userOnlineList.SelectedIndex = -1;
            }
            else
            {
                messageBoxResult = MessageBox.Show("Please select a user for the private chat ");
            }
            userOnlineList.SelectedIndex = -1;
        }
        protected override async Task OnInitializedAsync()
        {
            Log.LogTrace("-> ManageChats.OnInitializedAsync");
            Log.LogDebug($"SessionId: {SessionId}");

            UiVisibility = VisibilityVisible;

            Handler = new ChatHost(
                Config,
                LocalStorage,
                Log,
                Http,
                Nav,
                Session,
                SessionId);

            Handler.ChatProxy.SetNewChat();

            Log.LogTrace("Check authorization");
            await Handler.CheckAuthorize();

            if (Handler.IsAuthorized != null &&
                !Handler.IsAuthorized.Value)
            {
                Log.LogError("No authorization");
                return;
            }
            else if (!Handler.IsConnected &&
                     Handler.IsInError)
            {
                Log.LogError("Offline");
                return;
            }

            Handler.UpdateUi       += HandlerUpdateUi;
            Handler.RequestRefresh += HandlerRequestRefresh;
            await Handler.Connect();
        }
Exemple #14
0
        public bool SendInvite(Guid activityId, IEnumerable <KeyValuePair <string, string> > metadata)
        {
            bool success = ExceptionMonster.EatTheException(() => ChatHost.ReceiveActivityInvite(chatSessionId, localUser, remoteUser, activityId, Id, metadata), "Sending app invite to " + remoteUser.ToString());

            return(success);
        }
Exemple #15
0
 public void Cancel()
 {
     ExceptionMonster.EatTheException(() => ChatHost.CancelActivitySession(Id, localUser, remoteUser), "cancelling activity session with user" + remoteUser);
 }
Exemple #16
0
        public static ActivitySession Create(Guid sessionId, ChatHost chatHost, ISquiggleEndPoint localUser, ISquiggleEndPoint remoteUser)
        {
            var session = new ActivitySession(sessionId, chatHost, localUser, remoteUser, Guid.NewGuid(), true);

            return(session);
        }
Exemple #17
0
        public static ActivitySession FromInvite(Guid sessionId, ChatHost chatHost, ISquiggleEndPoint localUser, ISquiggleEndPoint remoteUser, Guid activitySessionId)
        {
            var session = new ActivitySession(sessionId, chatHost, localUser, remoteUser, activitySessionId, false);

            return(session);
        }