4651
static bool se_enableChatCommands = true;
4652
static tSettingItem<bool> se_enableChatCommandsConf( "CHAT_LOCAL_COMMANDS", se_enableChatCommands );
4654
//our local commands (should always be lowercase)
4655
static char const * const se_localChatCommands[] = {
4662
#endif //if not dedicated
4664
4650
void ePlayerNetID::Chat(const tString &s_orig)
4666
4652
tColoredString s( s_orig );
4669
4655
#ifndef DEDICATED
4671
std::string chatString(s_orig);
4672
std::istringstream passedString(chatString);
4676
passedString >> command;
4677
tToLower( command );
4678
tConfItemBase::EatWhitespace(passedString);
4680
bool isLocalCommand = false;
4682
for (int i = sizeof(se_localChatCommands)/sizeof(se_localChatCommands[0]) - 1; i >= 0; --i)
4684
if (command.StartsWith(se_localChatCommands[i]))
4686
isLocalCommand = true;
4690
if (isLocalCommand && se_enableChatCommands && (s_orig.StartsWith("/")))
4692
// check for direct console commands
4693
if (command == "/console")
4695
// direct commands are executed at owner level
4696
tCurrentAccessLevel level( tAccessLevel_Owner, true );
4699
if (s_orig.StrPos(" ") == -1)
4702
params = s_orig.SubStr(s_orig.StrPos(" ") + 1);
4704
if ( tRecorder::IsPlayingBack() )
4706
tConfItemBase::LoadPlayback();
4710
std::stringstream s(static_cast< char const * >( params ) );
4711
tConfItemBase::LoadAll(s);
4714
//Short handle for grabbing player colors.
4715
else if ((command == "/listcolors") || (command == "/colors"))
4717
listPlayerColors(tString(s_orig));
4719
//Short handle for grabbing player information.
4720
else if (command == "/info")
4722
listPlayerInfo(tString(s_orig));
4724
//Short handle for changing our RGB values.
4725
else if (command == "/rgb")
4727
currentPlayerRGB(tString(s_orig));
4656
// check for direct console commands
4657
if( s_orig.StartsWith("/console") )
4659
// direct commands are executed at owner level
4660
tCurrentAccessLevel level( tAccessLevel_Owner, true );
4663
if (s_orig.StrPos(" ") == -1)
4666
params = s_orig.SubStr(s_orig.StrPos(" ") + 1);
4668
if ( tRecorder::IsPlayingBack() )
4670
tConfItemBase::LoadPlayback();
4674
std::stringstream s(static_cast< char const * >( params ) );
4675
tConfItemBase::LoadAll(s);
4678
//Not sure if this is a good short handle. Maybe something like /colors? Then introduce the basic list if no parameters are sent, but if a players name is sent give that players colors alone.
4679
else if( s_orig.StartsWith("/listcolors") || s_orig.StartsWith("/colors") )
4683
else if(s_orig.StartsWith("/info") )
4685
listPlayerInfo(tString(s_orig));
4731
#endif //if not dedicated
4733
4690
tString retStr(s);
4734
4691
if (eBannedWords::BadWordTrigger(this, retStr))
8462
static int se_RandomizeColorRange = 32;
8463
static tSettingItem<int> se_RandomizeColorRangeConf("PLAYER_RANDOM_COLOR_RANGE", se_RandomizeColorRange);
8465
//This seems more random. Stolen from the old randomize color, but no comparing.
8409
//This seems more random. Stolen from the old randomize color, but no comparing. Also another bonus, generates multi colored cycle / tails with the limit increase to 32.
8466
8410
static void se_RandomizeColor(ePlayer * l)
8468
8412
int currentRGB[3];
8471
8415
static tReproducibleRandomizer randomizer;
8473
8417
for( int i = 2; i >= 0; --i )
8475
currentRGB[i] = l->rgb[i];
8476
newRGB[i] = randomizer.Get(se_RandomizeColorRange+1);
8419
currentRGB[i] = l->rgb[i];
8420
newRGB[i] = randomizer.Get(32);
8479
8423
for( int i = 2; i >= 0; --i )
8481
l->rgb[i] = newRGB[i];
8425
l->rgb[i] = newRGB[i];
8486
8429
//This didnt seem to be too random, more like picking a unique color no one else currently has.
8487
8430
static void se_UniqueColor( ePlayer * l, ePlayerNetID * p )
8534
//Gather all the rgb colors and put them in a nice list.
8535
//Usage /colors with no parameters returns all players and their colors.
8536
// /colors playername returns that specific players color or more depending if the search term is found in other player names
8537
void ePlayerNetID::listPlayerColors(tString s_orig)
8477
void ePlayerNetID::listPlayerColors()
8540
if (se_PlayerNetIDs.Len()>0)
8479
con << tOutput("$player_colors_text");
8480
for ( int i = 0; i <= se_PlayerNetIDs.Len()-1; i++ )
8542
if (s_orig.StrPos(" ") == -1)
8544
con << tOutput("$player_colors_text");
8546
for ( int i = 0; i <= se_PlayerNetIDs.Len()-1; i++ )
8548
ePlayerNetID *p=se_PlayerNetIDs(i);
8549
con << (i+1) << ": " << gatherPlayerColor(p);
8555
tArray<tString> msgsExt = s_orig.Split(" ");
8556
bool playerFound = false;
8558
con << tOutput("$player_colors_text");
8560
for(int i = 0; i < msgsExt.Len(); i++)
8562
tString word = msgsExt[i];
8564
for ( int i = 0; i <= se_PlayerNetIDs.Len()-1; i++ )
8566
ePlayerNetID *p=se_PlayerNetIDs(i);
8568
if (p->GetName().Filter().Contains(word.Filter()))
8572
con << (j+1) << ": " << gatherPlayerColor(p);
8581
con << tOutput("$player_not_found_text", msgsExt[1]);
8482
tColoredString listColors;
8483
ePlayerNetID * otherPlayers = se_PlayerNetIDs(i);
8485
listColors << (i+1) << ": " << otherPlayers->GetColoredName() << "0xRESETT (" << otherPlayers->r << ", " << otherPlayers->g << ", " << otherPlayers->b << ")\n";
8589
//Not sure if this is better / faster but better looking I guess?
8590
tColoredString ePlayerNetID::gatherPlayerColor(ePlayerNetID * p)
8592
tColoredString listColors;
8593
return listColors << p->GetColoredName() << "0xRESETT (" << p->r << ", " << p->g << ", " << p->b << ")\n";
8599
8493
List player information.
8618
8512
if (s_orig.StrPos(" ") == -1)
8620
8514
con << tOutput("$player_info_text");
8621
ePlayerNetID *p = se_GetLocalPlayer();
8622
con << gatherPlayerInfo(p);
8516
for(int i=0; i < se_PlayerNetIDs.Len(); i++)
8519
ePlayerNetID *p=se_PlayerNetIDs(i);
8520
if (p->Owner() == sn_myNetID)
8522
con << gatherPlayerInfo(p);
8626
8530
tArray<tString> msgsExt = s_orig.Split(" ");
8627
8531
tArray<ePlayerNetID *> foundPlayers;
8628
8533
bool playerFound = false;
8629
8535
con << tOutput("$player_info_text");
8630
8537
for(int i = 0; i < msgsExt.Len(); i++)
8632
8539
tString word = msgsExt[i];
8696
8605
return listinfo << "\n";
8699
// Allow us to change our current RGB easily.
8700
// Usage: /rgb with no parameters displays current rgb.
8701
// /rgb 15 3 3 Would set player 1's RGB to R15 G3 B3.
8702
// /rgb unique gives all players unique colors.
8703
// /rgb random gives all players random colors.
8704
// /rgb 2 15 3 3 Will change player 2's colors to 15 3 3.
8705
void ePlayerNetID::currentPlayerRGB(tString s_orig)
8707
if (s_orig.StrPos(" ") == -1)
8709
con << tOutput("$player_colors_current_text");
8710
for(int i=0; i<MAX_PLAYERS; ++i )
8712
bool in_game=ePlayer::PlayerIsInGame(i);
8713
ePlayer *me=ePlayer::PlayerConfig(i);
8715
tCONTROLLED_PTR(ePlayerNetID) &p=me->netPlayer;
8716
if (bool(p) && in_game)
8718
tColoredString listColors;
8719
listColors << p->GetColoredName() << "0xRESETT (" << ePlayer::PlayerConfig(i)->rgb[0] << ", " << ePlayer::PlayerConfig(i)->rgb[1] << ", " << ePlayer::PlayerConfig(i)->rgb[2] << ")\n";
8726
tArray<tString> passedString = s_orig.Split(" ");
8727
bool correctParameters = false;
8728
bool random = false;
8729
bool unique = false;
8732
if (passedString[1] == "random")
8734
correctParameters = true;
8737
//For now everyone gets random colors.
8738
for(int i=0; i<MAX_PLAYERS; ++i )
8740
bool in_game = ePlayer::PlayerIsInGame(i);
8741
ePlayer *me = ePlayer::PlayerConfig(i);
8743
tCONTROLLED_PTR(ePlayerNetID) &p=me->netPlayer;
8745
if (bool(p) && in_game)
8747
se_RandomizeColor(me);
8752
else if(passedString[1] == "unique")
8754
correctParameters = true;
8756
//Also everyone gets unique colors if sent.
8757
for(int i=0; i<MAX_PLAYERS; ++i )
8759
bool in_game=ePlayer::PlayerIsInGame(i);
8760
ePlayer *me=ePlayer::PlayerConfig(i);
8762
tCONTROLLED_PTR(ePlayerNetID) &p=me->netPlayer;
8764
if (bool(p) && in_game)
8766
se_UniqueColor(me,p);
8771
//Not really checking if the strings passed parameters are numbers, but if someone did /rgb asd asd asd it would just make it 0 0 0.
8772
else if (passedString.Len() >= 4 && !(random || unique ))
8774
//Guess we must be ID 0?
8775
if (passedString.Len() == 4)
8777
correctParameters = true;
8779
unsigned short r = (unsigned short) strtoul(passedString[1], NULL, 0);
8780
unsigned short g = (unsigned short) strtoul(passedString[2], NULL, 0);
8781
unsigned short b = (unsigned short) strtoul(passedString[3], NULL, 0);
8783
ePlayer::PlayerConfig(0)->rgb[0] = r;
8784
ePlayer::PlayerConfig(0)->rgb[1] = g;
8785
ePlayer::PlayerConfig(0)->rgb[2] = b;
8788
else if (passedString.Len() == 5)
8790
ourID = (unsigned short) strtoul(passedString[1], NULL, 0);
8791
if ((ourID <= MAX_PLAYERS) && (ourID > 0))
8793
correctParameters = true;
8795
bool in_game=ePlayer::PlayerIsInGame(ourID-1);
8796
ePlayer *me=ePlayer::PlayerConfig(ourID-1);
8798
unsigned short r = (unsigned short) strtoul(passedString[2], NULL, 0);
8799
unsigned short g = (unsigned short) strtoul(passedString[3], NULL, 0);
8800
unsigned short b = (unsigned short) strtoul(passedString[4], NULL, 0);
8802
ePlayer::PlayerConfig(ourID-1)->rgb[0] = r;
8803
ePlayer::PlayerConfig(ourID-1)->rgb[1] = g;
8804
ePlayer::PlayerConfig(ourID-1)->rgb[2] = b;
8809
// If the correct parameters are passed, display the changes.
8810
if (correctParameters)
8812
con << tOutput("$player_colors_current_text");
8814
for(int i=0; i<MAX_PLAYERS; ++i )
8816
bool in_game=ePlayer::PlayerIsInGame(i);
8817
ePlayer *me=ePlayer::PlayerConfig(i);
8819
tCONTROLLED_PTR(ePlayerNetID) &p=me->netPlayer;
8820
if (bool(p) && in_game)
8821
{ tColoredString listColors;
8822
listColors << i+1 << ": " << p->GetColoredName() << "0xRESETT (" << ePlayer::PlayerConfig(i)->rgb[0] << ", " << ePlayer::PlayerConfig(i)->rgb[1] << ", " << ePlayer::PlayerConfig(i)->rgb[2] << ")\n";
8825
if(!(bool(p) && in_game) && ourID-1 == i)
8827
con << tOutput("$player_colors_changed_text", ourID, ePlayer::PlayerConfig(i)->rgb[0], ePlayer::PlayerConfig(i)->rgb[1], ePlayer::PlayerConfig(i)->rgb[2]);
8833
con << tOutput("$player_colors_changed_usage_error");
10670
10440
static void SilenceAll_conf(std::istream &s)
10672
if (se_PlayerNetIDs.Len() > 0)
10442
if ( se_NeedsServer( "SILENCE_ALL", s ) )
10447
if (se_PlayerNetIDs.Len()>0)
10674
10449
int max = se_PlayerNetIDs.Len();
10675
for (int i = 0; i < max; i++)
10677
ePlayerNetID *p = se_PlayerNetIDs(i);
10680
if ((sn_GetNetState() == nCLIENT) && (p && !p->IsSilenced()) && ((p->Owner() != ::sn_myNetID)))
10682
p->SetSilenced(true);
10687
if ((sn_GetNetState() == nSERVER) && (p && !p->IsSilenced()))
10689
p->SetSilenced(true);
10694
if (sn_GetNetState() == nCLIENT)
10696
sn_ConsoleOut(tOutput("$player_silenced_all_local"));
10699
if (sn_GetNetState() == nSERVER)
10701
sn_ConsoleOut(tOutput("$player_silenced_all"));
10450
for(int i=0; i<max; i++)
10452
ePlayerNetID *p=se_PlayerNetIDs(i);
10453
if ( p && !p->IsSilenced() )
10455
p->SetSilenced( true );
10458
sn_ConsoleOut( tOutput( "$player_silenced_all") );
10707
10462
static tConfItemFunc silenceall_conf("SILENCE_ALL",&SilenceAll_conf);
10708
10463
static tAccessLevelSetter se_silenceallConfLevel( silenceall_conf, tAccessLevel_Moderator );
10710
10465
static void Voice_conf(std::istream &s)
10467
if ( se_NeedsServer( "VOICE", s ) || se_NeedsServer( "UNSILENCE", s ))
10712
10472
ePlayerNetID * p = ReadPlayer( s );
10713
10473
if ( p && p->IsSilenced() )
10716
if ( sn_GetNetState() == nCLIENT )
10717
sn_ConsoleOut( tOutput( "$player_voiced_local", p->GetColoredName() ) );
10720
sn_ConsoleOut( tOutput( "$player_voiced", p->GetColoredName() ) );
10475
sn_ConsoleOut( tOutput( "$player_voiced", p->GetColoredName() ) );
10721
10476
p->SetSilenced( false );