~ubuntu-branches/ubuntu/raring/mumble/raring

« back to all changes in this revision

Viewing changes to src/murmur/Server.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Thorvald Natvig
  • Date: 2010-01-09 19:28:50 UTC
  • mfrom: (9.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100109192850-zs4g5vwrrpd71kob
Tags: 1.2.1-2
Fix upgrade failure when upgrading mumble-server directly from 1.1.x
to 1.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2005-2009, Thorvald Natvig <thorvald@natvig.com>
 
1
/* Copyright (C) 2005-2010, Thorvald Natvig <thorvald@natvig.com>
2
2
   Copyright (C) 2009, Stefan Hacker <dd0t@users.sourceforge.net>
3
3
 
4
4
   All rights reserved.
303
303
        iTimeout = Meta::mp.iTimeout;
304
304
        iMaxBandwidth = Meta::mp.iMaxBandwidth;
305
305
        iMaxUsers = Meta::mp.iMaxUsers;
 
306
        iMaxUsersPerChannel = Meta::mp.iMaxUsersPerChannel;
306
307
        iMaxTextMessageLength = Meta::mp.iMaxTextMessageLength;
307
308
        bAllowHTML = Meta::mp.bAllowHTML;
308
309
        iDefaultChan = Meta::mp.iDefaultChan;
350
351
        iTimeout = getConf("timeout", iTimeout).toInt();
351
352
        iMaxBandwidth = getConf("bandwidth", iMaxBandwidth).toInt();
352
353
        iMaxUsers = getConf("users", iMaxUsers).toInt();
 
354
        iMaxUsersPerChannel = getConf("usersperchannel", iMaxUsersPerChannel).toInt();
353
355
        iMaxTextMessageLength = getConf("textmessagelength", iMaxTextMessageLength).toInt();
354
356
        bAllowHTML = getConf("allowhtml", bAllowHTML).toBool();
355
357
        iDefaultChan = getConf("defaultchannel", iDefaultChan).toInt();
378
380
                iMaxBandwidth = i ? i : Meta::mp.iMaxBandwidth;
379
381
        else if (key == "users")
380
382
                iMaxUsers = i ? i : Meta::mp.iMaxUsers;
 
383
        else if (key == "usersperchannel")
 
384
                iMaxUsersPerChannel = i ? i : Meta::mp.iMaxUsersPerChannel;
381
385
        else if (key == "textmessagelength")
382
386
                iMaxTextMessageLength = i ? i : Meta::mp.iMaxTextMessageLength;
383
387
        else if (key == "allowhtml")
438
442
                a_iBW[i] = 0;
439
443
}
440
444
 
441
 
void BandwidthRecord::addFrame(int size) {
442
 
        iSum -= a_iBW[iRecNum];
443
 
        a_iBW[iRecNum] = static_cast<unsigned char>(size);
444
 
        iSum += a_iBW[iRecNum];
445
 
 
 
445
bool BandwidthRecord::addFrame(int size, int maxpersec) {
 
446
        quint64 elapsed = a_qtWhen[iRecNum].elapsed();
 
447
 
 
448
        if (elapsed == 0)
 
449
                return false;
 
450
 
 
451
        int nsum = iSum-a_iBW[iRecNum]+size;
 
452
        int bw = static_cast<int>((nsum * 1000000LL) / elapsed);
 
453
 
 
454
        if (bw > maxpersec)
 
455
                return false;
 
456
 
 
457
        a_iBW[iRecNum] = static_cast<unsigned short>(size);
446
458
        a_qtWhen[iRecNum].restart();
447
459
 
 
460
        iSum = nsum;
 
461
 
448
462
        iRecNum++;
449
463
        if (iRecNum == N_BANDWIDTH_SLOTS)
450
464
                iRecNum = 0;
451
 
}
452
465
 
453
 
int BandwidthRecord::bytesPerSec() const {
454
 
        quint64 elapsed = a_qtWhen[iRecNum].elapsed();
455
 
        return static_cast<int>((iSum * 1000000LL) / elapsed);
 
466
        return true;
456
467
}
457
468
 
458
469
int BandwidthRecord::onlineSeconds() const {
766
777
 
767
778
        // IP + UDP + Crypt + Data
768
779
        int packetsize = 20 + 8 + 4 + len;
769
 
        bw->addFrame(packetsize);
770
780
 
771
 
        if ((bw->bytesPerSec() * 8)> iMaxBandwidth) {
 
781
        if (! bw->addFrame(packetsize, iMaxBandwidth/8)) {
772
782
                // Suppress packet.
773
783
                return;
774
784
        }
1241
1251
                mpus.set_channel_id(dest->iId);
1242
1252
                sendAll(mpus);
1243
1253
 
1244
 
                userEnterChannel(p, dest, true);
 
1254
                userEnterChannel(p, dest);
1245
1255
        }
1246
1256
 
1247
1257
        MumbleProto::ChannelRemove mpcr;