Exemplo n.º 1
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// LoadSettings loads the settings from the Database and displays them
        /// </summary>
        /// -----------------------------------------------------------------------------
        public override void LoadSettings()
        {
            try
            {
                if (Page.IsPostBack == false)
                {
                    //Check for existing settings and use those on this page
                    //Settings["SettingName"]

                    txtStartMessage.Text = Settings.Contains("StartMessage") ? Settings["StartMessage"].ToString() : Localization.GetString("DefaultStartMessage", "/DesktopModules/DnnChat/App_LocalResources/SharedResources.resx");

                    txtDefaultAvatarUrl.Text = Settings.Contains("DefaultAvatarUrl") ? Settings["DefaultAvatarUrl"].ToString() : Localization.GetString("DefaultAvatarUrl", "/DesktopModules/DnnChat/App_LocalResources/SharedResources.resx");

                    var rc = new RoomController();

                    ddlDefaultRoom.DataSource = rc.GetRooms(ModuleId);
                    ddlDefaultRoom.DataBind();

                    if (Settings.Contains("DefaultRoomId"))
                    {
                        ddlDefaultRoom.Items.FindByValue(Settings["DefaultRoomId"].ToString()).Selected = true;
                    }

                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Exemplo n.º 2
0
        //This method is to populate/join room
        public Task LeaveRoom(Guid roomId, int moduleId)
        {
            var crc  = new ConnectionRecordController();
            var crrc = new ConnectionRecordRoomController();
            var rc   = new RoomController();

            var c = crc.GetConnectionRecordByConnectionId(Context.ConnectionId) ?? SetupConnectionRecord();

            //lookup client room connection record, if there don't add
            var connectionRoom = crrc.GetConnectionRecordRoomByConnectionRecordId(c.ConnectionRecordId, roomId);

            if (connectionRoom != null)
            {
                connectionRoom.DepartedDate = DateTime.UtcNow;
                crrc.UpdateConnectionRecordRoom(connectionRoom);

                var removeUser = Users.Find(conRec => (conRec.Id == connectionRoom.Id));
                Users.Remove(removeUser);
            }

            //Remove the user from the SignalR Group (broadcast)
            Groups.Remove(Context.ConnectionId, roomId.ToString());

            return(Clients.Group(roomId.ToString()).updateUserList(Users.FindAll(cc => (cc.RoomId == roomId)), roomId));
        }
Exemplo n.º 3
0
        public Task GetRoomInfo(Guid roomId, int moduleId)
        {
            var rc = new RoomController();
            //Lookup existing Rooms
            var r = rc.GetRoom(roomId, moduleId);

            return(Clients.Caller.joinRoom(r));
        }
Exemplo n.º 4
0
        public void GetRoomList()
        {
            int moduleId = Convert.ToInt32(Clients.Caller.moduleid);
            var rc       = new RoomController();

            var allRooms = rc.GetRooms(moduleId);

            Clients.Caller.FillLobby(allRooms);
        }
Exemplo n.º 5
0
        //TODO: on connection, reload rooms for user?
        public Task Join()
        {
            int moduleId = Convert.ToInt32(Clients.Caller.moduleid);

            var settingsDefault = new Guid(Clients.Caller.defaultRoomId);

            if (DefaultRoomId != settingsDefault)
            {
                DefaultRoomId = settingsDefault;
            }

            //get list of previously connected (not departed) rooms
            var crrc = new ConnectionRecordRoomController();
            var rc   = new RoomController();

            IEnumerable <Room> myRooms = null;

            //don't do this if we've got a private room loaded.
            if (Convert.ToInt32(Clients.Caller.userid) > 0)
            {
                myRooms = crrc.GetConnectionRecordRoomsByUserId((int)Clients.Caller.userid);
            }

            //TODO: the default room doesn't have a moduleid associated with it
            //if myRooms is empty, what to do (pass default room)
            if (myRooms == null)
            {
                //load the default room
                var r = rc.GetRoom(DefaultRoomId, moduleId);
                myRooms = new List <Room>();
                myRooms = myRooms.Concat(new[] { r });
            }
            else
            {
                //load the current default room to see if it is in the queue
                var r = rc.GetRoom(DefaultRoomId, moduleId);
                if (!myRooms.Contains(r))
                {
                    myRooms = myRooms.Concat(new[] { r });
                }
            }

            //get all the active rooms and send it back for the Lobby
            var allRooms = rc.GetRooms(moduleId);

            //we are passing in a list of All rooms, and the current user's rooms
            Clients.Caller.PopulateUser(allRooms, myRooms);
            return(base.OnConnected());
        }
Exemplo n.º 6
0
        public Task GetRoomInfo(Guid roomId, int moduleId, string password)
        {
            var rc = new RoomController();
            //Lookup existing Rooms
            var r = rc.GetRoom(roomId, moduleId);

            if (r.RoomPassword == password)
            {
                return(Clients.Caller.joinRoom(r));
            }

            var badPasswordResponse = Localization.GetString("BadPassword.Text",
                                                             "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile);

            return(Clients.Caller.badPassword(badPasswordResponse));
        }
Exemplo n.º 7
0
 protected void ddlRooms_OnSelectedIndexChanged(object sender, EventArgs e)
 {
     divRoomSettings.Visible = true;
     //TODO: load the room into the edit interface.
     var rc = new RoomController();
     if (ddlRooms.SelectedValue != "-1")
     {
         var r = rc.GetRoom(new Guid(ddlRooms.SelectedValue), ModuleId);
         if (r != null)
         {
             txtRoomId.Text = r.RoomId.ToString();
             txtRoomName.Text = r.RoomName;
             txtRoomDescription.Text = r.RoomDescription;
             txtRoomPassword.Text = r.RoomPassword;
             txtRoomWelcome.Text = r.RoomWelcome;
             chkPrivateRoom.Checked = r.Private;
             chkEnabled.Checked = r.Enabled;
         }
     }
 }
Exemplo n.º 8
0
        protected void lbSubmit_Click(object sender, EventArgs e)
        {
            //save the room
            var rc = new RoomController();
            if (txtRoomId.Text.Any())
            {
                var r = rc.GetRoom(new Guid(txtRoomId.Text), ModuleId);
                r.RoomName = txtRoomName.Text.Trim();
                r.RoomDescription = txtRoomDescription.Text.Trim();
                r.RoomPassword = txtRoomPassword.Text.Trim();
                r.RoomWelcome = txtRoomWelcome.Text.Trim();
                r.Private = chkPrivateRoom.Checked;
                r.Enabled = chkEnabled.Checked;
                r.LastUpdatedByUserId = UserId;
                r.LastUpdatedDate = DateTime.UtcNow;

                rc.UpdateRoom(r);

            }
            else
            {
                var r = new Room
                {
                    RoomId = Guid.NewGuid(),
                    RoomName = txtRoomName.Text.Trim(),
                    RoomDescription = txtRoomDescription.Text.Trim(),
                    RoomPassword = txtRoomPassword.Text.Trim(),
                    RoomWelcome = txtRoomWelcome.Text.Trim(),
                    Private = chkPrivateRoom.Checked,
                    Enabled = chkEnabled.Checked,
                    CreatedByUserId = UserId,
                    CreatedDate =  DateTime.UtcNow,
                    LastUpdatedByUserId = UserId,
                    LastUpdatedDate =  DateTime.UtcNow,
                    ModuleId =  ModuleId

                };
                rc.CreateRoom(r);
            }
            Response.Redirect(DotNetNuke.Common.Globals.NavigateURL());
        }
Exemplo n.º 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!Page.IsPostBack)
                {
                    var rc = new RoomController();
                    ddlRooms.DataSource = rc.GetAllRooms(ModuleId);
                    ddlRooms.DataBind();

                    var li = new ListItem();
                    li.Value = "-1";
                    li.Text = Localization.GetString("ChooseRoom.Text", LocalResourceFile);
                    ddlRooms.Items.Insert(0, li);

                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Exemplo n.º 10
0
        //check to see if there is a string in the message that is too many characters put together
        private string ParseMessage(string message, Guid roomId)
        {
            //not using REGEX for now, maybe in the future
            //Regex nameChangeRegex = new Regex(@"/nick[^/]+", RegexOptions.IgnoreCase);

            //var nameChangeMatch = nameChangeRegex.Match(message);
            ////clean out all "scope" parameters from DNN Forum urls
            //if (nameChangeMatch.Success)
            //{
            //    //change the name
            //    string newName = message.Split(':')[1];
            //    message = UpdateName(newName.Trim());
            //}

            //TODO: allow command for Updating room description/properties
            //http://www.irchelp.org/irchelp/changuide.html

            //allow for Room creation/joining
            if (message.ToLower().StartsWith("/join"))
            {
                var userId = -1;
                if (Convert.ToInt32(Clients.Caller.userid) > 0)
                {
                    userId = Convert.ToInt32(Clients.Caller.userid);
                }

                if (userId > 0)
                {
                    string roomName = message.Remove(0, 5).Trim();
                    if (roomName.Length > 25)
                    {
                        Clients.Caller.newMessageNoParse(new Message {
                            AuthorName = Localization.GetString("SystemName.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile), ConnectionId = "0", MessageDate = DateTime.UtcNow, MessageId = -1, MessageText = Localization.GetString("RoomNameTooLong.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile), AuthorUserId = -1, RoomId = roomId
                        });
                        return(string.Empty);
                    }
                    //create room
                    else
                    {
                        var rc = new RoomController();
                        //Lookup existing Rooms
                        var r = rc.GetRoom(roomName);
                        //int.TryParse(Clients.Caller.moduleid, out moduleId);
                        int moduleId = Convert.ToInt32(Clients.Caller.moduleid);

                        if (r != null)
                        {
                            //todo: anything to do here? the room exists already
                            if (r.Enabled == false)
                            {
                                //what if the room has been disabled?
                            }
                        }
                        else
                        {
                            r = new Room
                            {
                                RoomId      = Guid.NewGuid(),
                                RoomName    = roomName,
                                RoomWelcome = Localization.GetString("DefaultRoomWelcome.Text", "~/desktopmodules/DnnChat/app_localresources/" +
                                                                     Localization.LocalSharedResourceFile),
                                RoomDescription = Localization.GetString("DefaultRoomDescription.Text",
                                                                         "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile),
                                ModuleId            = moduleId,
                                CreatedDate         = DateTime.UtcNow,
                                CreatedByUserId     = userId,
                                LastUpdatedByUserId = userId,
                                LastUpdatedDate     = DateTime.UtcNow,
                                Enabled             = true
                            };
                            rc.CreateRoom(r);
                        }

                        //make a call to the client to add the room to their model, and join
                        Clients.Caller.messageJoin(r);
                    }
                }
                else
                {
                    // if there is no username for the user don't let them post
                    var m = new Message
                    {
                        ConnectionId = Context.ConnectionId,
                        MessageDate  = DateTime.UtcNow,
                        MessageText  = Localization.GetString("AnonymousJoinDenied.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile),
                        AuthorName   = Localization.GetString("SystemName.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile),
                        AuthorUserId = -1,
                        RoomId       = roomId
                    };
                    Clients.Caller.newMessage(m);
                }
                message = string.Empty;
            }

            message = message.Replace("&nbsp;", " ").Replace("&nbsp", " ").Trim();

            //for name change, using starts with to see if they typed /nick in
            if (message.ToLower().StartsWith("/nick"))
            {
                string newName = message.Remove(0, 5);
                if (newName.Length > 25)
                {
                    Clients.Caller.newMessageNoParse(new Message {
                        AuthorName = Localization.GetString("SystemName.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile), ConnectionId = "0", MessageDate = DateTime.UtcNow, MessageId = -1, MessageText = Localization.GetString("NameToolong.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile), AuthorUserId = -1, RoomId = roomId
                    });
                    newName = newName.Remove(25);
                }

                if (newName.Trim().Length > 0)
                {
                    message = UpdateName(newName.Trim());
                }
            }

            if (message.ToLower().Trim() == Localization.GetString("Test.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile))
            {
                message = Localization.GetString("Test.Response", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile);
            }

            return(message);
        }
Exemplo n.º 11
0
        public void Send(string message, Guid roomId)
        {
            //if no valid connectionrecord don't let the message go through
            var crc = new ConnectionRecordController();
            var cr  = crc.GetConnectionRecordByConnectionId(Context.ConnectionId);

            //if the user (connectionrecord) isn't in a room don't let message go through

            var rc = new RoomController();

            if (cr != null && rc.UserInRoom(roomId, cr))
            {
                // parse message before use
                if (Clients.Caller.username != null && Clients.Caller.username.Trim() != "phantom")
                {
                    var parsedMessage = ParseMessage(message, roomId);
                    if (parsedMessage != string.Empty)
                    {
                        int moduleId;
                        int authorUserId;
                        //int.TryParse(Clients.Caller.moduleid, out moduleId);
                        moduleId     = Convert.ToInt32(Clients.Caller.moduleid);
                        authorUserId = Convert.ToInt32(Clients.Caller.userid);

                        var m = new Message
                        {
                            ConnectionId = Context.ConnectionId,
                            MessageDate  = DateTime.UtcNow,
                            MessageText  = parsedMessage,
                            AuthorName   = Clients.Caller.username,
                            AuthorUserId = authorUserId,
                            ModuleId     = moduleId,
                            RoomId       = roomId
                        };

                        new MessageController().CreateMessage(m);
                        Clients.Group(roomId.ToString()).newMessage(m);
                    }
                }
                else
                {
                    // if there is no username for the user don't let them post
                    var m = new Message
                    {
                        ConnectionId = Context.ConnectionId,
                        MessageDate  = DateTime.UtcNow,
                        MessageText  = Localization.GetString("FailedUnknown.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile),
                        AuthorName   = Localization.GetString("SystemName.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile),
                        AuthorUserId = -1,
                        RoomId       = DefaultRoomId
                    };
                    Clients.Caller.newMessage(m);
                }
            }
            else
            {
                // if there is no username for the user don't let them post
                var m = new Message
                {
                    ConnectionId = Context.ConnectionId,
                    MessageDate  = DateTime.UtcNow,
                    MessageText  = Localization.GetString("FailedUnknown.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile),
                    AuthorName   = Localization.GetString("SystemName.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile),
                    AuthorUserId = -1,
                    RoomId       = DefaultRoomId
                };
                Clients.Caller.newMessage(m);
            }
        }
Exemplo n.º 12
0
        /*
         * When a user connects we need to populate their user information, we default the username to be Anonymous + a #
         */

        //This method is to populate/join room
        public Task JoinRoom(Guid roomId, int moduleId)
        {
            //TODO: don't allow connecting to the same room twice
            var crc  = new ConnectionRecordController();
            var crrc = new ConnectionRecordRoomController();
            var rc   = new RoomController();

            var r = rc.GetRoom(roomId, moduleId);

            if (r.Enabled)
            {
                if (r.Private)
                {
                    //check the password
                }

                var c  = crc.GetConnectionRecordByConnectionId(Context.ConnectionId) ?? SetupConnectionRecord();
                var cr = crrc.GetConnectionRecordRoomByConnectionRecordId(c.ConnectionRecordId, roomId);



                if (cr == null)
                {
                    var crr = new ConnectionRecordRoom
                    {
                        ConnectionRecordId = c.ConnectionRecordId,
                        JoinDate           = DateTime.UtcNow,
                        DepartedDate       = null,
                        RoomId             = roomId
                    };

                    //join the room
                    crrc.CreateConnectionRecordRoom(crr);

                    var ulr = new UserListRecords(c, crr);

                    //add the user to the List of users that will be later filtered by RoomId
                    Users.Add(ulr);
                }

                Groups.Add(Context.ConnectionId, roomId.ToString());

                //populate history for all previous rooms
                RestoreHistory(roomId);

                //lookup the Room to get the Welcome Message
                Clients.Caller.newMessageNoParse(new Message
                {
                    AuthorName   = Localization.GetString("SystemName.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile),
                    ConnectionId = "0",
                    MessageDate  = DateTime.UtcNow,
                    MessageId    = -1,
                    MessageText  = r.RoomWelcome,
                    AuthorUserId = -1,
                    RoomId       = roomId
                });
                Clients.Group(roomId.ToString()).newMessageNoParse(new Message
                {
                    AuthorName = Localization.GetString("SystemName.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile)
                    ,
                    AuthorUserId = -1
                    ,
                    ConnectionId = "0",
                    MessageDate  = DateTime.UtcNow,
                    MessageId    = -1,
                    MessageText  = string.Format(Localization.GetString("Connected.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile), c.UserName),
                    RoomId       = roomId
                });

                Clients.Caller.scrollBottom(r.RoomId);

                return(Clients.Group(roomId.ToString()).updateUserList(Users.FindAll(uc => (uc.RoomId == r.RoomId)), roomId));
            }
            else
            {
                //if the room was no longer enabled, return nothing
                return(null);
            }
        }
Exemplo n.º 13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {

                //TODO: be sure to check for permissions when enabled
                if (!Page.IsPostBack)
                {
                    var sd = Request.QueryString["sd"];
                    var ed = Request.QueryString["ed"];

                    var startDate = DateTime.UtcNow.Date;
                    var endDate = DateTime.UtcNow;
                    if (sd != null)
                    {
                        startDate = Convert.ToDateTime(sd);
                    }
                    if (ed != null)
                    {
                        endDate = Convert.ToDateTime(ed);
                    }

                    txtStartDate.Text = startDate.ToString(CultureInfo.InvariantCulture);
                    txtEndDate.Text = endDate.ToString(CultureInfo.InvariantCulture);
                    var mc = new MessageController();
                    rptMessages.DataSource = mc.GetMessagesByDate(ModuleId, startDate, endDate, RoomId);
                    rptMessages.DataBind();

                    //if we have any items, don't display the "no results found" message
                    if (rptMessages.Items.Count > 0)
                    {
                        lblNoResults.Visible = false;
                    }
                    BuildArchiveLinks(RoomId);

                    var rc = new RoomController();
                    var r = rc.GetRoom(RoomId, ModuleId);
                    var tp = (CDefault)Page;
                    var t = new TabController().GetTab(TabId, PortalId, false);
                    tp.Title += string.Format(Localization.GetString("ChatArchiveTitle.Text", LocalResourceFile), t.TabName, r.RoomName, startDate.ToShortDateString(), endDate.ToShortDateString());
                    lblArchiveTitle.Text = string.Format(Localization.GetString("ChatArchiveContentTitle.Text", LocalResourceFile), r.RoomName, startDate.ToShortDateString(), endDate.ToShortDateString());
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Exemplo n.º 14
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //link for the Chat Archives
                //hlArchive.NavigateUrl = EditUrl("Archive",);

                StartMessage = Settings.Contains("StartMessage") ? Settings["StartMessage"].ToString() : Localization.GetString("DefaultStartMessage", LocalResourceFile);

                DefaultAvatarUrl = Settings.Contains("DefaultAvatarUrl") ? Settings["DefaultAvatarUrl"].ToString() : Localization.GetString("DefaultAvatarUrl", LocalResourceFile);

                var directRoom = string.Empty;

                var qs = Request.QueryString["rmid"];
                if (qs != null)
                {
                    directRoom = qs.ToString();}

                if (Settings.Contains("DefaultRoomId") && directRoom == string.Empty)
                {
                    DefaultRoomId = Settings["DefaultRoomId"].ToString();
                }
                else if (directRoom != string.Empty)
                { //if a guid came in, let's put the user in that room.
                    DefaultRoomId = directRoom;
                }
                else
                {
                    //if we don't have a setting. go get the default room from the database.
                    var rc = new RoomController();
                    var r = rc.GetRoom("Lobby");
                    if (r == null || (r.ModuleId > 0 && r.ModuleId != ModuleId))
                    {
                        //todo: if there isn't a room we need display a message about creating one
                    }
                    else
                    {
                        //if the default room doesn't have a moduleid on it, set the module id
                        if (r.ModuleId < 0)
                        {
                            r.ModuleId = ModuleId;
                        }
                        rc.UpdateRoom(r);
                    }
                    if (r != null) DefaultRoomId = r.RoomId.ToString();
                }

                //encrypt the user's roles so we can ensure security
                var curRoles = UserInfo.Roles;

                var section = (MachineKeySection)ConfigurationManager.GetSection("system.web/machineKey");

                var pc = new PortalSecurity();
                foreach (var c in curRoles)
                {
                    EncryptedRoles += pc.Encrypt(section.ValidationKey, c) + ",";
                }
                if (UserInfo.IsSuperUser)
                {
                    EncryptedRoles += pc.Encrypt(section.ValidationKey, "SuperUser");
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }