~armagetronad-dev/armagetronad/0.2.8-armagetronad-sty

« back to all changes in this revision

Viewing changes to src/engine/eVoter.cpp

Merge with 0.2.8-armagetronad-work

Show diffs side-by-side

added added

removed removed

Lines of Context:
1152
1152
 
1153
1153
        double time = tSysTimeFloat();
1154
1154
 
 
1155
        // get the oldest player from the sending client
 
1156
        double timeCreated = time;
 
1157
        for ( int i = se_PlayerNetIDs.Len()-1; i>=0; --i )
 
1158
        {
 
1159
            ePlayerNetID * senderPlayer = se_PlayerNetIDs(i);
 
1160
            if( senderPlayer->Owner() == senderID && senderPlayer->GetTimeCreated() < timeCreated )
 
1161
            {
 
1162
                timeCreated = senderPlayer->GetTimeCreated();
 
1163
            }
 
1164
        }
 
1165
 
 
1166
        // don't let the player call a vote if s/he is silenced.
 
1167
        if ( player_->IsSilenced() )
 
1168
        {
 
1169
            tOutput message("$vote_silenced");
 
1170
            sn_ConsoleOut( message, player_->Owner() );
 
1171
            return false;
 
1172
        }
 
1173
 
1155
1174
        // check whether the issuer is allowed to start a vote
1156
 
        if ( sender && player_ && player_->GetTimeCreated() + se_votingMaturity > time )
 
1175
        if ( sender && player_ && timeCreated + se_votingMaturity > time )
1157
1176
        {
1158
 
            REAL timeLeft = player_->GetTimeCreated() + se_votingMaturity - time;
 
1177
            REAL timeLeft = timeCreated + se_votingMaturity - time;
1159
1178
            tOutput message( "$vote_maturity", timeLeft );
1160
1179
            sn_ConsoleOut( message, senderID );
1161
1180
            return false;
1201
1220
        return eVoteItem::DoCheckValid( senderID );
1202
1221
    }
1203
1222
 
 
1223
    virtual void DoExecute()
 
1224
    {
 
1225
        // Don't prevent name changes if the vote passes
 
1226
        eVoter *suggestor = GetSuggestor();
 
1227
        if ( suggestor )
 
1228
        {
 
1229
            suggestor->lastNameChangePreventor_ = -1E30;
 
1230
        }
 
1231
        DoExecuteHarm();
 
1232
    }
 
1233
 
1204
1234
    virtual void DoFillToMessage( nMessage& m  ) const
1205
1235
    {
1206
1236
        if ( player_ )
1212
1242
    }
1213
1243
 
1214
1244
protected:
 
1245
    virtual void DoExecuteHarm() = 0;               // Called when the vote passes. Do the harmful action.
 
1246
    
1215
1247
    virtual nDescriptor& DoGetDescriptor() const;       // returns the creation descriptor
1216
1248
 
1217
1249
    // get the language string prefix
1310
1342
        return eVoteItemHarm::DoCheckValid( senderID );
1311
1343
    }
1312
1344
 
1313
 
    virtual void DoExecute()                                            // called when the voting was successful
 
1345
    virtual void DoExecuteHarm()                                                // called when the voting was successful
1314
1346
    {
1315
1347
        ePlayerNetID * player = GetPlayer();
1316
1348
        nMachine * machine = GetMachine();
1375
1407
 
1376
1408
        eVoteItemServerControlled::DoFillToMessage( m );
1377
1409
    }
 
1410
    
 
1411
    virtual void DoExecute()
 
1412
    {
 
1413
        eVoteItemHarm::DoExecute();
 
1414
    }
1378
1415
private:
1379
1416
    virtual void Update() //!< update description and details
1380
1417
    {
1427
1464
        return se_votingBiasSuspend;
1428
1465
    }
1429
1466
 
1430
 
    virtual void DoExecute()                                            // called when the voting was successful
 
1467
    virtual void DoExecuteHarm()                                                // called when the voting was successful
1431
1468
    {
1432
1469
        ePlayerNetID * player = GetPlayer();
1433
1470
        if ( player )
1451
1488
protected:
1452
1489
    virtual bool DoCheckValid( int senderID )
1453
1490
    {
 
1491
        
1454
1492
        // check whether enough harmful votes were collected already
1455
1493
        ePlayerNetID * p = GetPlayer();
1456
 
        if ( p && !p->GetVoter() )
1457
 
        {
1458
 
            p->CreateVoter();
1459
 
        }
1460
 
 
1461
 
        if ( fromMenu_ && p && p->GetVoter() && p->GetVoter()->HarmCount() < se_kickMinHarm )
1462
 
        {
1463
 
            // try to transfor the vote to a suspension
1464
 
            eVoteItem * item = tNEW ( eVoteItemSuspend )( p );
 
1494
        if ( fromMenu_ && p )
 
1495
        {
 
1496
            eVoter *voter = eVoter::GetVoter( p->Owner() );
 
1497
            if ( voter && voter->HarmCount() < se_kickMinHarm )
 
1498
            {
 
1499
                // try to transfor the vote to a suspension
 
1500
                eVoteItem * item = tNEW ( eVoteItemSuspend )( p );
1465
1501
            
1466
 
            // let item check its validity
1467
 
            if ( !item->CheckValid( senderID ) )
1468
 
            {
1469
 
                delete item;
1470
 
            }
1471
 
            else
1472
 
            {
1473
 
                // no objection? Broadcast it to everyone.
1474
 
                item->Update();
1475
 
                item->ReBroadcast( senderID );
1476
 
            }
 
1502
                // let item check its validity
 
1503
                if ( !item->CheckValid( senderID ) )
 
1504
                {
 
1505
                    delete item;
 
1506
                }
 
1507
                else
 
1508
                {
 
1509
                    // no objection? Broadcast it to everyone.
 
1510
                    item->Update();
 
1511
                    item->ReBroadcast( senderID );
 
1512
                }
1477
1513
 
1478
 
            // and cancel this item here.
1479
 
            return false;
 
1514
                // and cancel this item here.
 
1515
                return false;
 
1516
            }
1480
1517
        }
1481
1518
 
1482
1519
        // no transformation needed or transformation failed. Proceed as usual.
1483
1520
        return eVoteItemHarm::DoCheckValid( senderID );
1484
1521
    }
1485
1522
 
1486
 
    virtual void DoExecute()                                            // called when the voting was successful
 
1523
    virtual void DoExecuteHarm()                                                // called when the voting was successful
1487
1524
    {
1488
 
        eVoteItemKick::DoExecute();
 
1525
        eVoteItemKick::DoExecuteHarm();
1489
1526
    }
1490
1527
private:
1491
1528
    bool fromMenu_; // flag set if the vote came from the menu
1720
1757
// **************************************************************************************
1721
1758
 
1722
1759
 
1723
 
// menu item to silence selected players
 
1760
// menu item to kick selected players
1724
1761
class eMenuItemKick: public uMenuItemAction
1725
1762
{
1726
1763
public:
1959
1996
    return eVoteItem::GetItems().Len() > 0;
1960
1997
}
1961
1998
 
1962
 
eVoter* eVoter::GetVoter( int ID, bool complain )                       // find or create the voter for the specified ID
 
1999
eVoter* eVoter::GetVoter( int ID, bool complain )
1963
2000
{
1964
2001
    // the server has no voter
1965
2002
#ifdef DEDICATED
1988
2025
        }
1989
2026
    }
1990
2027
 
 
2028
    return GetPersistentVoter( ID );
 
2029
}
 
2030
 
 
2031
eVoter* eVoter::GetPersistentVoter( int ID )
 
2032
{
1991
2033
    // get machine from network subsystem
1992
2034
    nMachine & machine = nMachine::GetMachine( ID );
1993
 
 
1994
 
    return GetVoter( machine );
 
2035
    return GetPersistentVoter( machine );
1995
2036
}
1996
2037
 
1997
 
eVoter* eVoter::GetVoter( nMachine & machine )                  // find or create the voter for the specified machine
 
2038
eVoter* eVoter::GetPersistentVoter( nMachine & machine )
1998
2039
{
1999
2040
    // iterate through the machine's decorators, find a voter
2000
2041
    nMachineDecorator * run = machine.GetDecorators();
2154
2195
        return;
2155
2196
    }
2156
2197
 
 
2198
    // don't let the player call a vote if s/he is silenced.
 
2199
    if ( p->IsSilenced() )
 
2200
    {
 
2201
        tOutput message("$vote_silenced");
 
2202
        sn_ConsoleOut( message, p->Owner() );
 
2203
        return;
 
2204
    }
 
2205
 
2157
2206
    // read command part (kick, remove, include)
2158
2207
    tString command;
2159
2208
    message >> command;