Split user list from Channel into ChannelUserList
[clinton/bobotpp.git] / source / Utils.C
index bdddb59..c94c388 100644 (file)
@@ -1,6 +1,6 @@
 // Utils.C  -*- C++ -*-
 // Copyright (c) 1997, 1998 Etienne BERNARD
-// Copyright (c) 2005 Clinton Ebadi
+// Copyright (c) 2005,2008 Clinton Ebadi
 
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
 #include "config.h"
 #endif
 
-#include <cctype>
-#include <cstdlib>
+#include "Utils.H"
+
 #include <string>
 #include <sstream>
 
-#include "Utils.H"
+#include <cctype>
+#include <cstdlib>
+
+#include "Bot.H"
+#include "ChannelList.H"
 #include "StringTokenizer.H"
+#include "User.H"
+#include "UserList.H"
 
 std::string
 Utils::get_nick (std::string nuh)
@@ -62,6 +68,7 @@ std::string
 Utils::make_wildcard (std::string mask)
 {
   StringTokenizer st (mask);
+  std::cerr << "make_wildcard: \"" << mask << "\"\n";
 
   st.next_token('!', true);
   std::string nick = "*";
@@ -96,9 +103,7 @@ Utils::make_wildcard (std::string mask)
     {
       if (host == "") host = "*";
     }
-
-  std::cout << nick + "!" + user + "@" + host << std::endl;
-  
   return nick + "!" + user + "@" + host;
 }
 
@@ -123,10 +128,10 @@ Utils::valid_channel_name_p (std::string c)
 #define isvalid(c) (((c) >= 'A' && (c) <= '~') || std::isdigit(c) || (c) == '-')
 
 bool
-Utils::valid_nickname_p (std::string n)
+Utils::valid_nickname_p (const Bot *b, std::string n)
 {
   // FIXME: make max nick length configurable
-  if (n[0] == '-' || std::isdigit(n[0]) || n.length() > 9)
+  if (n[0] == '-' || std::isdigit(n[0]) || n.length() > b->MAX_NICKLENGTH)
     return false;
 
   for (std::string::size_type i = 0; i < n.length(); i++)
@@ -148,15 +153,11 @@ Utils::get_level (Bot * b, std::string nuh, std::string channel)
   if (!channel_p (channel))
     return get_level(b, nuh);
 
-  if (Channel * c =  b->channelList->getChannel(channel))
-    {
-      User * u = c->getUser(get_nick (nuh));
-      if (u)
-       return u->getLevel();
-    } 
-  else {
+  Channel * c =  b->channelList->getChannel(channel);
+  if (c && c->hasNick (get_nick (nuh)))
+    return  c->getUser(get_nick (nuh)).getLevel ();
+  else 
     return -1;
-  }
 
   return b->userList->getLevel(nuh, channel);
 }
@@ -306,7 +307,7 @@ std::string
 Utils::scm2str (SCM s)
 {
   // FIXME: uses gh_, replace with scm_
-  char *tmp = gh_scm2newstr(s, 0);
+  char *tmp = scm_to_locale_string (s);
   std::string temp (tmp);
 
   free(tmp);
@@ -318,6 +319,6 @@ Utils::scm2str (SCM s)
 SCM
 Utils::str2scm (std::string s)
 {
-  return gh_str02scm (s.c_str ());
+  return scm_from_locale_string (s.c_str ());
 }
 #endif