Ejemplo n.º 1
0
        public ActionResult Chat()
        {
            // Meta Tags
            ViewBag.Title           = "Chatfunky: Live Chat";
            ViewBag.MetaDescription = "Chatfunky allows you to live chat, communicate with people and make friends online.";
            ViewBag.MetaKeywords    = "online, chat, online chat, live, live chat, chat room, public chat, common, common chat, chatfunky";
            // Meta Tags

            ChatUser user = TempData["user"] as ChatUser;

            if (user != null)
            {
                if (DBSupport.GetUser(user) != null)
                {
                    if (SharedSupport.GetCookieUser() == null || (SharedSupport.GetCookieUser() != null &&
                                                                  SharedSupport.GetCookieUser().Id != DBSupport.GetUser(user).Id))
                    {
                        TempData["error"] = usernameExists.Replace("username", user.Username);
                        return(RedirectToAction("Home", new { logout = "true" }));
                    }
                }
                ViewBag.TotalUsers = DBSupport.GetUsersCount();
                if (SharedSupport.GetCookieUser() != null && DBSupport.GetUser(user) != null)
                {
                    ViewBag.DuplicateTab = SharedSupport.GetCookieUser().Id == DBSupport.GetUser(user).Id ? true : false;
                }
                SharedSupport.SetCookieUser(user);
                return(View(user));
            }

            TempData["error"] = Request.UrlReferrer != null ? (HttpContext.Session["usernameError"] != null ?
                                                               HttpContext.Session["usernameError"].ToString() : sessionExpired) : sessionExpired;
            HttpContext.Session.Remove("usernameError");
            return(RedirectToAction("Home"));
        }
Ejemplo n.º 2
0
        public void NewMessage(string msgMarkup)
        {
            ChatUser chatClient = DBSupport.GetUser(new ChatUser {
                ConnectionId = Context.ConnectionId
            });

            string[] exceptUsers = null;
            if (chatClient == null)
            {
                string username = Context.RequestCookies["FunkyUser"].Value.Substring(0, Context.RequestCookies["FunkyUser"].Value.IndexOf('&'));
                username   = username.Substring(username.IndexOf('=') + 1);
                chatClient = DBSupport.GetUser(new ChatUser {
                    Username = username
                });
                exceptUsers = SharedSupport.ExceptUsers(chatClient);
                exceptUsers = exceptUsers.Concat(new string[] { Context.ConnectionId }).ToArray();
                exceptUsers = exceptUsers.ToList().Where(x => !x.Equals(chatClient.ConnectionId)).ToArray();
            }
            else
            {
                exceptUsers = SharedSupport.ExceptUsers(chatClient);
            }

            //For updating context user connect time
            DBSupport.UpdateUser(chatClient);

            Clients.AllExcept(exceptUsers).newUserMessage(msgMarkup);
        }
Ejemplo n.º 3
0
        public override void OnOpen()
        {
            if (DBSupport.GetUser(user) == null)
            {
                DBSupport.AddNewUser(user);
            }

            SocketMessage socMsg = new SocketMessage()
            {
                Type       = SocketMessage.MessageType.JoinedPub,
                Packetizer = new SocketMessage.DataGram
                {
                    User       = user,
                    UsersCount = DBSupport.GetUsersCount()
                }
            };

            chatClients.BroadcastExcept(chatClients, this.user, JsonConvert.SerializeObject(socMsg));

            socMsg = new SocketMessage()
            {
                Type       = SocketMessage.MessageType.JoinedPvt,
                Packetizer = new SocketMessage.DataGram
                {
                    User       = null,
                    Users      = DBSupport.GetAllUsers(),
                    UsersCount = DBSupport.GetUsersCount()
                }
            };
            this.Send(JsonConvert.SerializeObject(socMsg));
            chatClients.Add(this);
        }
Ejemplo n.º 4
0
        public void UserBlocked(string username)
        {
            ChatUser currentUser = DBSupport.GetUser(new ChatUser {
                ConnectionId = Context.ConnectionId
            });

            currentUser.Blocks += username + ";";

            DBSupport.BlockUser(currentUser);
        }
Ejemplo n.º 5
0
        public void userKicked(string username)
        {
            ChatUser currentUser = DBSupport.GetUser(new ChatUser {
                Username = username
            });

            DBSupport.DeleteUser(currentUser.Username);
            Clients.AllExcept(currentUser.ConnectionId).userLeft(currentUser.Username);
            Clients.Client(currentUser.ConnectionId).forceDisconnect();
            Clients.All.totalUsers(DBSupport.GetUsersCount());
            Clients.All.dcUserSessions(currentUser.Username);
        }
Ejemplo n.º 6
0
 public void UserTyping(bool isUserTyping, string username)
 {
     try
     {
         ChatUser pvtChatClient = DBSupport.GetUser(new ChatUser {
             ConnectionId = Context.ConnectionId
         });
         ChatUser pvtChatRecipent = DBSupport.GetUser(new ChatUser {
             Username = username
         });
         if (!pvtChatClient.Blocks.Contains(pvtChatRecipent.Username) && !pvtChatRecipent.Blocks.Contains(pvtChatClient.Username))
         {
             Clients.Client(pvtChatRecipent.ConnectionId).userIsTyping(isUserTyping, pvtChatClient.Username);
         }
     }
     catch { }
 }
Ejemplo n.º 7
0
        public void DeleteReconnectingUser(string username)
        {
            ChatUser currentUser = DBSupport.GetUser(new ChatUser {
                Username = username
            });

            if (currentUser == null)
            {
                username    = HttpContext.Request.Cookies["FunkyUser"].Value.Substring(0, HttpContext.Request.Cookies["FunkyUser"].Value.IndexOf('&'));
                username    = username.Substring(username.IndexOf('=') + 1);
                currentUser = DBSupport.GetUser(new ChatUser {
                    Username = username
                });
            }
            DBSupport.DeleteUser(username);
            IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <Chat>();

            hubContext.Clients.All.userLeft(currentUser.Username);
            hubContext.Clients.All.totalUsers(DBSupport.GetUsersCount());
            hubContext.Clients.All.dcUserSessions(currentUser.Username);
        }
Ejemplo n.º 8
0
        //Depreciated Method
        private string UserForm(User data)
        {
            string webpath = string.Empty;

            if (!string.IsNullOrEmpty(data.SocialProfilePicture))
            {
                byte[] binaryData = Convert.FromBase64String(data.SocialProfilePicture
                                                             .Replace("data:image/jpg;base64,", "")
                                                             .Replace("data:image/jpeg;base64,", "")
                                                             .Replace("data:image/gif;base64,", "")
                                                             .Replace("data:image/png;base64,", "")
                                                             .Replace("data:image/bmp;base64,", "")
                                                             );

                string slashSubStr   = data.SocialProfilePicture.Substring(data.SocialProfilePicture.IndexOf('/') + 1);
                string fileExtension = slashSubStr.Substring(0, slashSubStr.IndexOf(';'));
                webpath = SharedSupport.SharedImagesPath + data.Username + "." + fileExtension;
                string fileSystemPath = SharedSupport.GetImageFolderPath() + data.Username + "." + fileExtension;
                Stream sampleStream   = new MemoryStream(binaryData);
                using (FileStream writerStream = File.Open(fileSystemPath, FileMode.Append))
                {
                    Byte[] byteData = new Byte[binaryData.Count()];
                    for (byte i = 0; i < 100; i++)
                    {
                        Int32 readeDataLength = sampleStream.Read(byteData, 0, byteData.Count());
                        writerStream.Write(byteData, 0, readeDataLength);
                    }
                }
            }

            ChatUser filteredUser = SharedSupport.FilterUser(data, webpath);

            if (DBSupport.GetUser(filteredUser) != null)
            {
                return(usernameExists.Replace("username", data.Username));
            }

            return(JsonConvert.SerializeObject(filteredUser));
        }
Ejemplo n.º 9
0
 public void Stop()
 {
     try
     {
         ChatUser currentUser = DBSupport.GetUser(new ChatUser {
             ConnectionId = Context.ConnectionId
         });
         if (currentUser == null)
         {
             string username = Context.RequestCookies["FunkyUser"].Value.Substring(0, Context.RequestCookies["FunkyUser"].Value.IndexOf('&'));
             username    = username.Substring(username.IndexOf('=') + 1);
             currentUser = DBSupport.GetUser(new ChatUser {
                 Username = username
             });
         }
         DBSupport.DeleteUser(currentUser.Username);
         Clients.Others.userLeft(currentUser.Username);
         Clients.All.totalUsers(DBSupport.GetUsersCount());
         Clients.All.dcUserSessions(currentUser.Username);
     }
     catch { }
 }
Ejemplo n.º 10
0
        public void NewPrivateMessage(string msgMarkup, string username)
        {
            if (DBSupport.GetUser(new ChatUser {
                Username = username
            }) == null)
            {
                return;
            }

            ChatUser pvtChatClient = DBSupport.GetUser(new ChatUser {
                ConnectionId = Context.ConnectionId
            });
            ChatUser pvtChatRecipent = DBSupport.GetUser(new ChatUser {
                Username = username
            });

            //For updating context user connect time
            DBSupport.UpdateUser(pvtChatClient);

            if (!pvtChatClient.Blocks.Contains(pvtChatRecipent.Username) && !pvtChatRecipent.Blocks.Contains(pvtChatClient.Username))
            {
                Clients.Client(pvtChatRecipent.ConnectionId).newUserPrivateMessage(msgMarkup, pvtChatClient.Username);
            }
        }