Index: chatroom.forms.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/chatroom/chatroom.forms.inc,v
retrieving revision 1.2.2.17
diff -u -r1.2.2.17 chatroom.forms.inc
--- chatroom.forms.inc	11 Nov 2009 12:33:47 -0000	1.2.2.17
+++ chatroom.forms.inc	14 Nov 2009 17:08:03 -0000
@@ -352,6 +352,13 @@
     '#options' => drupal_map_assoc(array(20, 40, 60, 80, 100, 120, 140, 160, 180)),
     '#description' => t('How many seconds between each message before a last message time is shown in the chat.'),
   );
+  $form['chat_settings']['max_users'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Max users'),
+    '#default_value' => isset($node->chat) ? $node->chat->max_users : 0,
+    '#description' => t('The maximum amount of users for this chat. 0 is unlimited'),
+    '#size' => 5,
+  );
   $previous_msg_range = array();
   for ($i = 1; $i <= 25; $i++) {
     $previous_msg_range[$i] = $i * 10;
@@ -436,6 +443,7 @@
   $chat->crid = $chatroom->nid;
   $chat->idle_freq = $chatroom->chatroom->idle_freq;
   $chat->poll_freq = $chatroom->chatroom->poll_freq;
+  $chat->max_users = $chatroom->chatroom->max_users;
   $chat->kicked_out_message = $chatroom->chatroom->kicked_out_message;
   $chat->banned_message = $chatroom->chatroom->banned_message; 
   $chat->previous_messages_display_count = $chatroom->chatroo->previous_messages_display_count;
Index: chatroom.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/chatroom/chatroom.install,v
retrieving revision 1.25.4.9
diff -u -r1.25.4.9 chatroom.install
--- chatroom.install	11 Nov 2009 10:49:30 -0000	1.25.4.9
+++ chatroom.install	14 Nov 2009 17:08:19 -0000
@@ -60,6 +60,11 @@
         'length' => '255',
         'description' => t('Default imagecache preset for chats in this chatroom.'),
       ),
+      'max_users' => array(
+        'type' => 'int',
+        'default' => 0,
+        'description' => t('Max users for this chat.'),
+      ),
     ),
     'primary key' => array('nid'),
   );
@@ -236,6 +241,11 @@
         'length' => '255',
         'description' => t('Imagecache preset for this chat.'),
       ),
+      'max_users' => array(
+        'type' => 'int',
+        'default' => 0,
+        'description' => t('Max users for this chat.'),
+      ),
     ),
     'indexes' => array(
       'crid' => array('crid'),
@@ -448,7 +458,7 @@
 
   $roles = db_query("SELECT * FROM {permission}");
   require_once dirname(__FILE__) . '/chatroom.module';
-  $chatroom_perms = chatroom_perms();
+  //$chatroom_perms = chatroom_perms();
   while ($role = db_fetch_object($roles)) {
     $new_perms = array();
     foreach (explode(', ', $role->perm) as $perm) {
Index: chatroom.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/chatroom/chatroom.module,v
retrieving revision 1.63.2.44
diff -u -r1.63.2.44 chatroom.module
--- chatroom.module	12 Nov 2009 07:46:59 -0000	1.63.2.44
+++ chatroom.module	14 Nov 2009 17:08:11 -0000
@@ -221,6 +221,7 @@
     'nid' => $node->nid,
     'poll_freq' => $node->poll_freq,
     'idle_freq' => $node->idle_freq,
+    'max_users' => $node->max_users,
     'kicked_out_message' => $node->kicked_out_message,
     'banned_message' => $node->banned_message,
     'module' => isset($node->module) ? $node->module : 'chatroom',
@@ -240,6 +241,7 @@
     'nid' => $node->nid,
     'poll_freq' => $node->poll_freq,
     'idle_freq' => $node->idle_freq,
+    'max_users' => $node->max_users,
     'kicked_out_message' => $node->kicked_out_message,
     'banned_message' => $node->banned_message,
     'module' => isset($node->module) ? $node->module : 'chatroom',
@@ -345,6 +347,7 @@
     'crid' => isset($node->crid) ? $node->crid : 0,
     'poll_freq' => $node->poll_freq,
     'idle_freq' => $node->idle_freq,
+    'max_users' => $node->max_users,
     'kicked_out_message' => $node->kicked_out_message,
     'banned_message' => $node->banned_message,
     'module' => isset($node->module) ? $node->module : 'chatroom',
@@ -366,6 +369,7 @@
     'crid' => isset($node->crid) ? $node->crid : 0,
     'poll_freq' => $node->poll_freq,
     'idle_freq' => $node->idle_freq,
+    'max_users' => $node->max_users,
     'kicked_out_message' => $node->kicked_out_message,
     'banned_message' => $node->banned_message,
     'module' => isset($node->module) ? $node->module : 'chatroom',
@@ -536,9 +540,11 @@
     }
     $bc[] = l($node->title, "node/$node->nid");
     drupal_set_breadcrumb($bc);
-
-    // Display a message if the user is banned.
-    if (chatroom_is_banned_user($node)) {
+    
+    if(chatroom_is_max_users($node)) { // Display a message if the user maximum has been reached
+      $content = theme('chatroom_chat_max_users', $node);
+    }
+    elseif (chatroom_is_banned_user($node)) { // Display a message if the user is banned.
       $content = theme('chatroom_chat_banned_user', $node);
     }
     elseif (!isset($node->chat->when_archived)) {
@@ -565,6 +571,29 @@
 }
 
 /**
+ * Return true if the maximum of users is reached
+ */
+function chatroom_is_max_users($node) {
+  if($node->chat->max_users == 0)
+    return FALSE;
+  
+  global $user;
+  $users = chatroom_load_online_users($node);
+
+  if(count($users) < $node->chat->max_users) {
+    return FALSE;
+  }else{
+    foreach($users as $u) {
+      if($u->uid == $user->uid) {
+        return FALSE;
+      }
+    }
+  }
+  
+  return TRUE;
+}
+
+/**
  * Gets a list of banned users for a given chat room.
  */
 function chatroom_get_banned_users($room) {
@@ -782,7 +811,7 @@
     'cacheDirectory' => file_directory_temp(),
     'postMessagePath' => 'chatroom/chat/post/message',
     'chatPath' => 'node/' . $node->nid,
-		'successiveCacheHits' => 0,
+    'successiveCacheHits' => 0,
     'skipCacheCheckCount' => 5,
     'latestMsgId' => $node->chat->latest_msg ? $node->chat->latest_msg->cmid : 0,
     'accessDeniedPath' => 'chatroom/access-denied',
Index: chatroom.theme.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/chatroom/chatroom.theme.inc,v
retrieving revision 1.3.2.28
diff -u -r1.3.2.28 chatroom.theme.inc
--- chatroom.theme.inc	11 Nov 2009 12:14:22 -0000	1.3.2.28
+++ chatroom.theme.inc	14 Nov 2009 17:10:40 -0000
@@ -54,6 +54,11 @@
         'node',
       ),
     ),
+    'chatroom_chat_max_users' => array(
+      'arguments' => array(
+        'node',
+      ),
+    ),
     'chatroom_list' => array(
       'arguments' => array(
         'tree',
@@ -324,6 +329,16 @@
 }
 
 /**
+ * Get HTML for max users message.
+ *
+ * @ingroup themeable
+ */
+function theme_chatroom_chat_max_users($chat) {
+  $msg = t('The threshold for maximum users has been reached for this chat, please try again in a few minutes');
+  return '<div id="chatroom-banned-msg">'. $msg .'</div>';
+}
+
+/**
  * Theme a chat.
  *
  * @ingroup themeable

