X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmode.cpp;h=3538052b7a3e4d4310527366853aa659bdcf7530;hb=b4a174ee9c32d62ea6bf010e837e8c5b1c3d36a3;hp=159474985b1daec0a0e2f7dd17bbb7de83030545;hpb=9433e34b2133d8f1e77fea15447ba4d0259a5fb0;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/mode.cpp b/src/mode.cpp index 159474985..3538052b7 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -1,13 +1,18 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2012 Shawn Smith + * Copyright (C) 2019 Matt Schatz + * Copyright (C) 2017 B00mX0r + * Copyright (C) 2016-2019, 2021 Sadie Powell + * Copyright (C) 2012-2016, 2018 Attila Molnar + * Copyright (C) 2012, 2019 Robby + * Copyright (C) 2012 Shawn Smith * Copyright (C) 2009-2010 Daniel De Graaf - * Copyright (C) 2007, 2009 Dennis Friis - * Copyright (C) 2006-2008 Robin Burchell + * Copyright (C) 2009 Uli Schlachter * Copyright (C) 2008 Thomas Stagner - * Copyright (C) 2004-2008 Craig Edwards - * Copyright (C) 2006 Oliver Lupton + * Copyright (C) 2008 Robin Burchell + * Copyright (C) 2007 Dennis Friis + * Copyright (C) 2006-2008, 2010 Craig Edwards * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public @@ -99,6 +104,14 @@ void ModeHandler::OnParameterMissing(User* user, User* dest, Channel* channel) user->WriteNumeric(Numerics::InvalidModeParameter(dest, this, "*", message)); } +void ModeHandler::OnParameterInvalid(User* user, Channel* targetchannel, User* targetuser, const std::string& parameter) +{ + if (targetchannel) + user->WriteNumeric(Numerics::InvalidModeParameter(targetchannel, this, "*")); + else + user->WriteNumeric(Numerics::InvalidModeParameter(targetuser, this, "*")); +} + bool ModeHandler::ResolveModeConflict(std::string& theirs, const std::string& ours, Channel*) { return (theirs < ours); @@ -249,9 +262,9 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, Mode const bool needs_param = mh->NeedsParam(adding); std::string& parameter = mcitem.param; - // crop mode parameter size to 250 characters - if (parameter.length() > 250 && adding) - parameter.erase(250); + // crop mode parameter size to MODE_PARAM_MAX characters + if (parameter.length() > MODE_PARAM_MAX && adding) + parameter.erase(MODE_PARAM_MAX); ModResult MOD_RESULT; FIRST_MOD_RESULT(OnRawMode, MOD_RESULT, (user, chan, mh, parameter, adding)); @@ -375,7 +388,9 @@ void ModeParser::ModeParamsToChangeList(User* user, ModeType type, const std::ve if (!mh) { /* No mode handler? Unknown mode character then. */ - user->WriteNumeric(type == MODETYPE_CHANNEL ? ERR_UNKNOWNMODE : ERR_UNKNOWNSNOMASK, modechar, "is an unknown mode character"); + int numeric = (type == MODETYPE_CHANNEL ? ERR_UNKNOWNMODE : ERR_UNKNOWNSNOMASK); + const char* typestr = (type == MODETYPE_CHANNEL ? "channel" : "user"); + user->WriteNumeric(numeric, modechar, InspIRCd::Format("is not a recognised %s mode.", typestr)); continue; } @@ -398,7 +413,10 @@ static bool IsModeParamValid(User* user, Channel* targetchannel, User* targetuse // The parameter cannot begin with a ':' character or contain a space if ((item.param[0] == ':') || (item.param.find(' ') != std::string::npos)) + { + item.mh->OnParameterInvalid(user, targetchannel, targetuser, item.param); return false; + } return true; } @@ -557,7 +575,7 @@ void ModeParser::CleanMask(std::string &mask) else if ((pos_of_pling == std::string::npos) && (pos_of_at != std::string::npos)) { /* Has an @ but no !, its a user@host */ - mask = "*!" + mask; + mask = "*!" + mask; } else if ((pos_of_pling != std::string::npos) && (pos_of_at == std::string::npos)) { @@ -741,9 +759,9 @@ std::string ModeParser::GiveModeList(ModeType mt) for (unsigned char mode = 'A'; mode <= 'z'; mode++) { ModeHandler* mh = modehandlers[mt][mode-65]; - /* One parameter when adding */ if (mh) { + /* One parameter when adding */ if (mh->NeedsParam(true)) { PrefixMode* pm = mh->IsPrefixMode();