Exemple #1
0
 private void LClientOnOnDataRecieved(object sender , Client.DataRecType type , object data)
 {
     if(type == Client.DataRecType.GameList)
         ReloadGameList();
     else if(type == Client.DataRecType.GamesNeedRefresh)
         Program.LClient.BeginGetGameList();
 }
Exemple #2
0
 public Chat(Client c, XmppClientConnection xmpp)
 {
     _client = c;
     Rooms = new ThreadSafeList<NewChatRoom>();
     _xmpp = xmpp;
     _xmpp.OnMessage += XmppOnOnMessage;
 }
 private void LobbyClientOnOnLoginComplete(object sender , Client.LoginResults results)
 {
     switch (results)
     {
         case Client.LoginResults.Success:
             Canceled = false;
             ReconnectTimer.Dispose();
             break;
         case Client.LoginResults.Failure:
             Canceled = true;
             ReconnectTimer.Dispose();
             break;
     }
     Dispatcher.Invoke(new Action(() =>
     {
         switch(results)
         {
             case Client.LoginResults.Success:
                 if (Program.LobbyClient.DisconnectedBecauseConnectionReplaced) Canceled = false;
                 Connected = true;
                 this.Close();
                 break;
             case Client.LoginResults.Failure:
                 this.Close();
                 break;
         }
     }));
 }
Exemple #4
0
 /// <summary>
 /// Whenever a chat message request comes in, it goes through here
 /// and gets filtered to the appropriate room.
 /// </summary>
 /// <param name="c">Client as the sender</param>
 /// <param name="sm">Data as the data.</param>
 public static void ChatMessage(Client c,SocketMessage sm)
 {
     Logger.TL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
     lock (Rooms)
     {
         long? rid = (long?)sm["roomid"];
         string mess = (string)sm["mess"];
         if (rid == null || mess == null)
         {
             Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
             return;
         }
         if (String.IsNullOrWhiteSpace(mess))
         {
             Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
             return;
         }
         long rid2 = (long)rid;
         ChatRoom cr = Rooms.FirstOrDefault(r => r.ID == rid2);
         if (cr != null)
         {
             LazyAsync.Invoke(()=>cr.ChatMessage(c.Me, mess));
         }
         Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
     }
 }
Exemple #5
0
 /// <summary>
 /// Add a user to a chat room
 /// </summary>
 /// <param name="c">Client adding a user</param>
 /// <param name="s">Socket message with the user data and stuff</param>
 public static void AddUserToChat(Client c, SocketMessage s)
 {
     Logger.TL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
     lock (Rooms)
     {
         var rid = (long?)s["roomid"];
         if (rid == null || rid == -1)
         {
             Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
             return;
         }
         var user = (User)s["user"];
         if (user == null)
         {
             Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
             return;
         }
         ChatRoom cr = Rooms.FirstOrDefault(r => r.ID == rid);
         if (cr != null)
         {
             if (cr.AddUser(user))
             {
                 Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
                 return;
             }
         }
     }
     Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
 }
Exemple #6
0
 private void LClientOnOnRegisterComplete(object sender, Client.RegisterResults results)
 {
     Program.LClient.OnRegisterComplete -= LClientOnOnRegisterComplete;
     Dispatcher.Invoke(new Action(()=>
         {
             progressBar1.Visibility = Visibility.Hidden;
             switch(results)
             {
                 case Client.RegisterResults.ConnectionError:
                     lblErrors.Content = "There was a connection error. Please try again.";
                     break;
                 case Client.RegisterResults.Success:
                     MessageBox.Show("Registration Success!", "Octgn", MessageBoxButton.OK,
                                     MessageBoxImage.Information);
                     var l = new Login();
                     l.textBox1.Text = Program.LClient.Username;
                     l.passwordBox1.Password = Program.LClient.Password;
                     Program.LauncherWindow.Navigate(l);
                     break;
                 case Client.RegisterResults.UsernameTaken:
                     lblErrors.Content = "That username is already taken.";
                     break;
                 case Client.RegisterResults.UsernameInvalid:
                     lblErrors.Content = "That username is invalid.";
                     break;
                 case Client.RegisterResults.PasswordFailure:
                     lblErrors.Content = "That password is invalid.";
                     break;
             }
         }
     ));
 }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Chat"/> class.
 /// </summary>
 /// <param name="c">
 /// The lobby client.
 /// </param>
 /// <param name="xmpp">
 /// The XMPP connection.
 /// </param>
 public Chat(Client c, XmppClientConnection xmpp)
 {
     this.client = c;
     this.Rooms = new ThreadSafeList<NewChatRoom>();
     this.xmpp = xmpp;
     this.xmpp.OnMessage += this.XmppOnMessage;
     this.xmpp.OnPresence += this.XmppOnPresence;
 }
Exemple #8
0
        public MatchmakingCog(Client c, XmppClientConnection xmpp)
        {
            _client = c;
            _xmpp = xmpp;
            _messanger = new Messanger();
            _messanger.OnResetXmpp(xmpp);

            _messanger.Map<MatchmakingInLineUpdateMessage>(OnMatchmakingInLineUpdateMessage);
            _messanger.Map<MatchmakingReadyRequest>(OnMatchmakingReadyRequest);
            _messanger.Map<MatchmakingReadyFail>(OnMatchmakingFail);

            xmpp.OnMessage += XmppOnOnMessage;
        }
Exemple #9
0
        private void LobbyClientOnOnDataRecieved(object sender , Client.DataRecType type , object data)
        {
            if(type == Client.DataRecType.GameList)
                ReloadGameList();
            else if (type == Client.DataRecType.GamesNeedRefresh)
            {
                Dispatcher.Invoke(new Action(() =>
                    {
                    bRefreshing.Visibility = Visibility.Visible;
                    Program.LobbyClient.BeginGetGameList();
                    }));

            }
        }
 public static void AddClient(Client c)
 {
     Clients.Add(c);
     int i = Clients.IndexOf(c);
     Clients[i].ID = i;
     for(i = 0; i < Clients.Count; ++i)
     {
         if(!Clients[i].Connected)
         {
             Clients.RemoveAt(i);
             i--;
         }
     }
 }
Exemple #11
0
 /// <summary>
 /// Join a chat room.
 /// </summary>
 /// <param name="c">Client that wants to join</param>
 /// <param name="s">Socket message stuffed with data.</param>
 public static void JoinChatRoom(Client c, SocketMessage s)
 {
     Logger.TL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
     lock (Rooms)
     {
         Logger.L(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
         var rid = (long?)s["roomid"];
         if (rid == null)
             return;
         if (rid == -1)
             MakeRoom(c);
         else
         {
             ChatRoom cr = Rooms.FirstOrDefault(r => r.ID == rid);
             if (cr != null)
                 cr.AddUser(c.Me);
             else
                 MakeRoom(c);
         }
         Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
     }
 }
 public FriendRequestNotification(Jid u, Client lc, int id)
     : base(lc, id)
 {
     User = u;
 }
 public static void UserEvent(UserEventType ue, Client c)
 {
     SocketMessage sm;
     switch(ue)
     {
         case Containers.UserEventType.LogIn:
             AllUserCommand(SocketMessages.UserOnlineBroadcast(c.User));
             break;
         case Containers.UserEventType.LogOut:
             AllUserCommand(SocketMessages.UserOfflineBroadcast(c.User));
             break;
     }
 }
Exemple #14
0
        private static void AcceptReceiveDataCallback(IAsyncResult ar)
        {
            // Logger.TL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "ClientLocker");
            lock (ClientLocker)
            {
                //Logger.L(System.Reflection.MethodInfo.GetCurrentMethod().Name, "ClientLocker");
                // Get the socket that handles the client request.

                try
                {
                    TcpListener listener = (TcpListener)ar.AsyncState;
                    SkySocket ss = new SkySocket(listener.EndAcceptTcpClient(ar));
                    Client c = new Client(ss, _nextId);
                    c.OnDisconnect += new EventHandler(c_OnDisconnect);
                    Clients.Add(c);
                    //Logger.log(MethodInfo.GetCurrentMethod().Name, "Client " + _nextId.ToString() + " connected.");
                    _nextId++;
                }
                catch (ObjectDisposedException)
                {
                    Console.WriteLine("AcceptReceiveDataCallback: ObjectDisposedException");
                }
                catch (SocketException)
                {

                }
                AcceptClients();
                //Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "ClientLocker");
            }
        }
Exemple #15
0
        private void RoomOnOnMessageRecieved(object sender , NewUser from , string message, DateTime rTime, Client.LobbyMessageType mType)
        {
            Dispatcher.Invoke(new Action(()=>
                {
                    switch(mType)
                    {
                        case Client.LobbyMessageType.Standard:
                        {
                            Brush b = _bOtherColor;

                            if (from.Equals(Program.LobbyClient.Me)) b = _bMeColor;
                            Run r = GetUserRun(from.User.User,
                                               "[" + from.User.User + "] : ", rTime);
                            r.Foreground = b;
                            AddChatText(r, message);
                            if (this.Visibility != Visibility.Visible
                               && Program.LobbyClient.Me.Status != UserStatus.DoNotDisturb && !IsLobbyChat) Show();
                            break;
                        }
                        case Client.LobbyMessageType.Topic:
                        {
                            Run r = new Run("");
                            r.Foreground = _bTopicColor;
                            r.Background = _bTopicBackColor;
                            AddChatText(r, message, _bTopicColor, _bTopicBackColor);
                            break;
                        }
                        case Client.LobbyMessageType.Error:
                        {
                            Run r = new Run("");
                            r.Foreground = _bErrorColor;
                            AddChatText(r, message, _bErrorColor);
                            break;
                        }
                    }

                }));
        }
Exemple #16
0
 /// <summary>
 /// Stops and removes all clients based on a uid.
 /// </summary>
 /// <param name="uid">UID</param>
 /// <returns>Tupple, where value1=number of users with UID who are logged in, and value2=Number of clients removed.</returns>
 public static Tuple<int, int> StopAndRemoveAllByUID(Client caller, int uid)
 {
     //Logger.TL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "ClientLocker");
     lock(ClientLocker)
     {
         //Logger.L(System.Reflection.MethodInfo.GetCurrentMethod().Name, "ClientLocker");
         int loggedInCount = 0;
         int removedCount = 0;
         int StartCount = Clients.Count;
         foreach (Client cl in Clients)
         {
             Client cl2 = cl;
             if (cl2 == null) continue;
             if (cl2.Id == caller.Id) continue;
             if (cl2.Me.Uid == uid)
             {
                 removedCount++;
                 if (cl2.LoggedIn)
                     loggedInCount++;
                 Trace.WriteLine(String.Format("#Try stop client[{0}]", cl2.Id));
                 LazyAsync.Invoke(() => cl2.Stop());
             }
         }
         //Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "ClientLocker");
         return new Tuple<int, int>(loggedInCount,removedCount);
     }
 }
Exemple #17
0
 /// <summary>
 /// If a user event happens, call this and it will broadcast it and update the necisary users.
 /// This gives you the option to supress a broadcast message.
 /// </summary>
 /// <param name="e">User status</param>
 /// <param name="client">The client that called</param>
 /// <param name="Supress">Should we supress a broadcast message</param>
 public static void OnUserEvent(UserStatus e, Client client, bool Supress)
 {
     Logger.TL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "ClientLocker");
     lock (ClientLocker)
     {
         Logger.L(System.Reflection.MethodInfo.GetCurrentMethod().Name, "ClientLocker");
         User me = (User) client.Me;
         if (e == UserStatus.Offline)
         {
             Clients.Remove(client);
             bool foundOne = false;
             foreach (Client c in Clients)
             {
                 if (c.Me.Uid == me.Uid)
                 {
                     foundOne = true;
                     break;
                 }
             }
             if (!foundOne)
             {
                 LazyAsync.Invoke(()=>Chatting.UserOffline((User)me.Clone()));
             }
         }
         if (!Supress)
         {
             foreach (Client c in Clients)
             {
                 Client cl2 = c;
                 LazyAsync.Invoke(() => cl2.OnUserEvent(e, me.Clone() as User));
             }
         }
         Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "ClientLocker");
     }
 }
Exemple #18
0
 /// <summary>
 /// This starts up a two person chat.
 /// </summary>
 /// <param name="c">Client starting the room</param>
 /// <param name="s">Socket message full of data</param>
 public static void TwoPersonChat(Client c, SocketMessage s)
 {
     var user = (User)s["user"];
     if (user == null)
         return;
     Logger.TL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
     long id = -1;
     lock(Rooms)
     {
         foreach (ChatRoom cr in Rooms)
         {
             User[] ul = cr.GetUserList();
             if (ul.Contains(user) && ul.Contains(c.Me) && ul.Length == 2)
             {
                 Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
                 return;
             }
         }
         id = MakeRoom(c);
     }
     Logger.UL(System.Reflection.MethodInfo.GetCurrentMethod().Name, "Rooms");
     s.AddData("roomid", id);
     AddUserToChat(c, s);
 }
Exemple #19
0
 /// <summary>
 /// Make a room, hosted by Client
 /// </summary>
 /// <param name="c">Client "hosting"</param>
 /// <returns>The unique chat room id.</returns>
 private static long MakeRoom(Client c)
 {
     long newID = DateTime.Now.Ticks;
     while (Rooms.Count(r => r.ID == newID) != 0)
     {
         newID = DateTime.Now.Ticks;
     }
     Rooms.Add(new ChatRoom(newID, c.Me));
     return newID;
 }
Exemple #20
0
 private void LobbyClientOnOnDataRecieved(object sender, Client.DataRecType type, object data)
 {
     if (type == Client.DataRecType.FriendList)
     {
         RefreshList();
     }
 }
Exemple #21
0
 /// <summary>
 /// If a user event happens, call this and it will broadcast it and update the necisary users.
 /// </summary>
 /// <param name="e">User status</param>
 /// <param name="client">The client that called</param>
 public static void OnUserEvent(UserStatus e, Client client)
 {
     OnUserEvent(e, client, false);
 }
Exemple #22
0
 public void Reconnect(Client c, XmppClientConnection xmpp)
 {
     this.client = c;
     if (this.xmpp != null)
     {
         this.xmpp.OnMessage -= this.XmppOnMessage;
         this.xmpp.OnPresence -= this.XmppOnPresence;
     }
     this.xmpp = xmpp;
     this.xmpp.OnMessage += this.XmppOnMessage;
     this.xmpp.OnPresence += this.XmppOnPresence;
 }