+ if (crlf == std::string::npos)
+ {
+ DoCommand(a->ReplaceFormat, user, c, safe);
+ return 1;
+ }
+ else
+ {
+ irc::sepstream commands(a->ReplaceFormat, '\n');
+ std::string scommand;
+ while (commands.GetToken(scommand))
+ {
+ DoCommand(scommand, user, c, safe);
+ }
+ return 1;
+ }
+ }
+
+ void DoCommand(const std::string& newline, User* user, Channel *chan, const std::string &original_line)
+ {
+ std::string result;
+ result.reserve(newline.length());
+ for (unsigned int i = 0; i < newline.length(); i++)
+ {
+ char c = newline[i];
+ if ((c == '$') && (i + 1 < newline.length()))
+ {
+ if (isdigit(newline[i+1]))
+ {
+ int len = ((i + 2 < newline.length()) && (newline[i+2] == '-')) ? 3 : 2;
+ std::string var = newline.substr(i, len);
+ result.append(GetVar(var, original_line));
+ i += len - 1;
+ }
+ else if (newline.substr(i, 5) == "$nick")
+ {
+ result.append(user->nick);
+ i += 4;
+ }
+ else if (newline.substr(i, 5) == "$host")
+ {
+ result.append(user->host);
+ i += 4;
+ }
+ else if (newline.substr(i, 5) == "$chan")
+ {
+ if (chan)
+ result.append(chan->name);
+ i += 4;
+ }
+ else if (newline.substr(i, 6) == "$ident")
+ {
+ result.append(user->ident);
+ i += 5;
+ }
+ else if (newline.substr(i, 6) == "$vhost")
+ {
+ result.append(user->dhost);
+ i += 5;
+ }
+ else
+ result.push_back(c);
+ }
+ else
+ result.push_back(c);
+ }
+
+ irc::tokenstream ss(result);
+ std::vector<std::string> pars;