Пример #1
0
        /// <summary>
        /// Deletes the session with a given Session ID
        /// </summary>
        /// <param name="sessionid"></param>
        public static void DeleteSession(string sessionid)
        {
            List <Session> temp = Sessions;

            int index = 0;

            foreach (Session session in temp)
            {
                if (session.Id.ToLower() == sessionid.ToLower())
                {
                    if (session.isActive == false)
                    {
                        UserManager.RemoveUserFromSession(Sessions[index].Host.UserId, true);

                        User[] clone = new User[Sessions[index].Clients.Count];
                        Sessions[index].Clients.CopyTo(clone);

                        foreach (User user in clone)
                        {
                            UserManager.RemoveUserFromSession(user.UserId, false);
                        }

                        Sessions[index].Terminate();
                        Sessions.RemoveAt(index);

                        break;
                    }
                    else
                    {
                        LogConsole.ThrowException(session.Id, "Session cannot be deleted while not being stopped");
                        break;
                    }
                }
                else
                {
                    index++;
                }
            }
        }