// TokenBucket to avaid sending too much at once
_messagesPerSecond(1),
_burstSize(5),
- _tokenBucket(5), // init with a full bucket
-
- // TODO:
- // should be 510 (2 bytes are added when writing to the socket)
- // maxMsgSize is 510 minus the hostmask which will be added by the server
- _maxMsgSize(450)
+ _tokenBucket(5) // init with a full bucket
{
_autoReconnectTimer.setSingleShot(true);
_socketCloseTimer.setSingleShot(true);
// that means that the last message can be as long as:
// 512 - nicklen - userlen - hostlen - commandlen - sum(param[0]..param[n-1])) - 2 (for CRLF) - 4 (":!@" + 1space between prefix and command) - max(paramcount - 1, 0) (space for simple params) - 2 (space and colon for last param)
IrcUser *me = network()->me();
- int maxLen = 512 - serverEncode(me->nick()).count() - serverEncode(me->user()).count() - serverEncode(me->host()).count() - cmd.toAscii().count() - 6;
+ int maxLen = 480 - cmd.toAscii().count(); // educated guess in case we don't know us (yet?)
+
+ if(me)
+ maxLen = 512 - serverEncode(me->nick()).count() - serverEncode(me->user()).count() - serverEncode(me->host()).count() - cmd.toAscii().count() - 6;
if(!params.isEmpty()) {
for(int i = 0; i < params.count() - 1; i++) {
if(!params.isEmpty())
msg += " :" + params.last();
- if(cmd == "PRIVMSG" && params.count() > 1) {
- QByteArray msghead = "PRIVMSG " + params[0].toByteArray() + " :";
-
- while (msg.size() > _maxMsgSize) {
- QByteArray splitter(" .,-");
- int splitPosition = 0;
- for(int i = 0; i < splitter.size(); i++) {
- splitPosition = qMax(splitPosition, msg.lastIndexOf(splitter[i], _maxMsgSize));
- }
- if(splitPosition < 300) {
- splitPosition = _maxMsgSize;
- }
- putRawLine(msg.left(splitPosition));
- msg = msghead + msg.mid(splitPosition);
- }
- }
-
putRawLine(msg);
}