CIRCServer.messageTo Member

Takes care not to let more than MAX_LINES_PER_SEND lines out per cycle. Cycle's are defined as the time between onPoll calls.

Syntax

object.messageTo(code, target, msg, ctcpCode);

Arguments

ArgumentSummary
code
target
msg
ctcpCode

Returns

Remarks

See Also

Source Code

function serv_messto (code, target, msg, ctcpCode)
{
var lines = String(msg).split ("\n");
var sendable = 0, i;
var pfx = "", sfx = "";
if (this.MAX_LINES_PER_SEND &&
this.sendsThisRound > this.MAX_LINES_PER_SEND)
return false;
if (ctcpCode)
{
pfx = "\01" + ctcpCode;
sfx = "\01";
}
for (i in lines)
{
if (lines[i])
{
while (lines[i].length > this.maxLineLength)
{
var extraLine = lines[i].substr(0, this.maxLineLength - 5);
var pos = extraLine.lastIndexOf(" ");
if ((pos >= 0) && (pos >= this.maxLineLength - 15))
{
// Smart-split.
extraLine = lines[i].substr(0, pos) + "...";
lines[i] = "..." + lines[i].substr(extraLine.length - 2);
}
else
{
// Dump-split.
extraLine = lines[i].substr(0, this.maxLineLength);
lines[i] = lines[i].substr(extraLine.length);
}
if (!this.messageTo(code, target, extraLine, ctcpCode))
return false;
}
}
}
// Check this again, since we may have actually sent stuff in the loop above.
if (this.MAX_LINES_PER_SEND &&
this.sendsThisRound > this.MAX_LINES_PER_SEND)
return false;
for (i in lines)
if ((lines[i] != "") || ctcpCode) sendable++;
for (i in lines)
{
if (this.MAX_LINES_PER_SEND && (
((this.sendsThisRound == this.MAX_LINES_PER_SEND - 1) &&
(sendable > this.MAX_LINES_PER_SEND)) ||
this.sendsThisRound == this.MAX_LINES_PER_SEND))
{
this.sendData ("PRIVMSG " + target + " :" +
this.TOO_MANY_LINES_MSG + "\n");
this.sendsThisRound++;
return true;
}
if ((lines[i] != "") || ctcpCode)
{
var line = code + " " + target + " :" + pfx;
this.sendsThisRound++;
if (lines[i] != "")
{
if (ctcpCode)
line += " ";
line += lines[i] + sfx;
}
else
line += sfx;
//dd ("-*- irc sending '" + line + "'");
this.sendData(line + "\n");
}
}
return true;
}