// 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)
Utils::make_wildcard (std::string mask)
{
StringTokenizer st (mask);
+ std::cerr << "make_wildcard: \"" << mask << "\"\n";
st.next_token('!', true);
std::string nick = "*";
{
if (host == "") host = "*";
}
-
- std::cout << nick + "!" + user + "@" + host << std::endl;
-
+
return nick + "!" + user + "@" + host;
}
#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++)
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);
}
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);
SCM
Utils::str2scm (std::string s)
{
- return gh_str02scm (s.c_str ());
+ return scm_from_locale_string (s.c_str ());
}
#endif