X-Git-Url: https://git.hcoop.net/clinton/bobotpp.git/blobdiff_plain/39b022cb3fcbbaf28bd35eaf7ad0af0b5161586f..71cf268829070ae57d695fbea11404bc04113aa9:/source/Utils.C diff --git a/source/Utils.C b/source/Utils.C index bdddb59..c94c388 100644 --- a/source/Utils.C +++ b/source/Utils.C @@ -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 @@ -20,13 +20,19 @@ #include "config.h" #endif -#include -#include +#include "Utils.H" + #include #include -#include "Utils.H" +#include +#include + +#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