--- app_meetme.c.original       2004-04-29 19:18:10.000000000 +0200
+++ app_meetme.c        2004-05-03 11:09:14.000000000 +0200
@@ -58,6 +58,8 @@
 "      'v' -- video mode\n"
 "      'q' -- quiet mode (don't play enter/leave sounds)\n"
 "      'M' -- enable music on hold when the conference has a single caller\n"
+"      'x' -- exit the conference if there are no admins left but not till the first admin joins\n"
+"      'X' -- exit the conference if you are the only user or only monitor users are left\n"
 "      'b' -- run AGI script specified in ${MEETME_AGI_BACKGROUND}\n"
 "            Default: conf-background.agi\n"
 "             (Note: This does not work with non-Zap channels in the same conference)\n"
@@ -80,6 +82,9 @@
        int fd;                         /* Announcements fd */
        int zapconf;                    /* Zaptel Conf # */
        int users;                      /* Number of active users */
+        int talkers;                    /* Number of talking only users */
+        int listeners;                  /* Number of listening only users */
+        int admins;                    /* Number of currently active admins */
        time_t start;                   /* Start time (s) */
        int isdynamic;                  /* Created on the fly? */
        char pin[AST_MAX_EXTENSION];                    /* If protected by a PIN */
@@ -105,6 +110,8 @@
 #define CONFFLAG_VIDEO (1 << 7)                /* Set to enable video mode */
 #define CONFFLAG_AGI (1 << 8)          /* Set to run AGI Script in Background */
 #define CONFFLAG_MOH (1 << 9)          /* Set to have music on hold when */
+#define CONFFLAG_ADMINEXIT (1 << 10)   /* If set the MeetMe will return if all admins left */
+#define CONFFLAG_EXITMONITOR (1 << 11)  /* If set the MeetMe will return if you're the only user or only monitor users are left */


 static int careful_write(int fd, unsigned char *data, int len)
@@ -188,6 +195,7 @@
                        cnf->start = time(NULL);
                        cnf->zapconf = ztc.confno;
                        cnf->isdynamic = dynamic;
+                       cnf->admins = -1;
                        if (option_verbose > 2)
                                ast_verbose(VERBOSE_PREFIX_3 "Created ZapTel conference %d for conference '%s'\n", cnf->zapconf, cnf->confno);
                        cnf->next = confs;
@@ -270,6 +278,18 @@
        char *buf = __buf + AST_FRIENDLY_OFFSET;

        conf->users++;
+        if (confflags & CONFFLAG_MONITOR) {
+               conf->listeners++;
+        } else if (confflags & CONFFLAG_TALKER) {
+               conf->talkers++;
+        }
+        if (confflags & CONFFLAG_ADMIN) {
+               if (conf->admins == -1)
+                       conf->admins = 1;
+               else
+                       conf->admins++;
+        }
+
        if (!(confflags & CONFFLAG_QUIET) && conf->users == 1) {
                if (!ast_streamfile(chan, "conf-onlyperson", chan->language))
                        ast_waitstream(chan, "");
@@ -417,6 +437,24 @@
                outfd = -1;
                ms = -1;
                c = ast_waitfor_nandfds(&chan, 1, &fd, nfds, NULL, &outfd, &ms);
+                /* Exit if no admins are in here */
+                if ((confflags & CONFFLAG_ADMINEXIT) && (conf->admins == 0)) {
+                       ret = 0;
+                       break;
+                }
+
+                /* Exit if you're the only person in the conf */
+                if ((confflags & CONFFLAG_EXITMONITOR) && (conf->users == 1)) {
+                       ret = 0;
+                       break;
+                }
+
+                /* Exit if there are just listeners left */
+                if ((confflags & CONFFLAG_EXITMONITOR) && (conf->listeners == conf->users)) {
+                       ret = 0;
+                       break;
+                }
+
                /* trying to add moh for single person conf */
                if (confflags & CONFFLAG_MOH) {
                        if (conf->users == 1) {
@@ -505,6 +543,14 @@
        ast_mutex_lock(&conflock);
        /* Clean up */
        conf->users--;
+        if (confflags & CONFFLAG_MONITOR) {
+               conf->listeners--;
+        } else if (confflags & CONFFLAG_TALKER) {
+               conf->talkers--;
+        }
+        if (confflags & CONFFLAG_ADMIN) {
+               conf->admins--;
+        }
        if (!conf->users) {
                /* No more users -- close this one out */
                cur = confs;
@@ -681,6 +727,10 @@
                        confflags |= CONFFLAG_QUIET;
                if (strchr(inflags, 'M'))
                        confflags |= CONFFLAG_MOH;
+                if (strchr(inflags, 'x'))
+                        confflags |= CONFFLAG_ADMINEXIT;
+                if (strchr(inflags, 'X'))
+                       confflags |= CONFFLAG_EXITMONITOR;
                if (strchr(inflags, 'b'))
                        confflags |= CONFFLAG_AGI;
                if (strchr(inflags, 'd'))