ItsMods

Full Version: Player mute
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Is it possible to have any type of player mute for a server? (!mute XXX)

(02-01-2012, 19:41)kraze1994 Wrote: [ -> ]Is it possible to have any type of player mute for a server? (!mute XXX)
What do you mean with mute? Chat or voice chat?

Both would be possible for an admin plugin.
I would love to see both with different commands to be honest, but I would prefer voice over anything.
Voice probably wouldn't be possible, chat would be possible for sure
I will code a mute plugin for chat somewhere tomorrow
I already made one but its in the itsmodders section, Didn't test it thats why its not public

edit: Source
CSHARP Code
  1. using System;
  2. using Addon;
  3.  
  4. namespace MW3_TextChatMute
  5. {
  6. public class TextChatMute : CPlugin
  7. {
  8. System.Collections.Generic.List<Player> MuteDb = new System.Collections.Generic.List<Player>();
  9. System.Timers.Timer Timer = new System.Timers.Timer();
  10.  
  11. // Start the timer and show the server owner that the plugin is loaded
  12. public override void OnServerLoad()
  13. {
  14. Timer.Interval = 10000;
  15. Timer.Elapsed += new System.Timers.ElapsedEventHandler( Timer_Elapsed );
  16. Timer.Enabled = true;
  17. Timer.Start();
  18.  
  19. ServerLog( LogType.LogData, "TextChatMute v1 loaded" );
  20. ServerPrint( "TextChatMute v1 loaded" );
  21. }
  22.  
  23. // Check every 10 seconds if the player is still ingame, if not then delete him from the database
  24. void Timer_Elapsed( object sender, System.Timers.ElapsedEventArgs e )
  25. {
  26. foreach ( Player player in MuteDb )
  27. if ( !IsStillIngame( player.Client ) )
  28. DeletePlayer( player );
  29. }
  30.  
  31. // Fix for removing players because I cannot delete them in a foreach loop o_O
  32. void DeletePlayer( Player player )
  33. {
  34. MuteDb.Remove( player );
  35. ServerLog( LogType.LogData, "DEBUG: Removed mutelist for: " + player.Client.Name );
  36. player.Client = null;
  37. player.Muted = null;
  38. player = null;
  39. }
  40.  
  41. // Check if the player is still ingame
  42. bool IsStillIngame( ServerClient client )
  43. {
  44. foreach ( ServerClient player in GetClients() )
  45. if ( client == player )
  46. return true;
  47.  
  48. return false;
  49. }
  50.  
  51. // Add the player to the mute database
  52. public override void OnPlayerConnect( ServerClient Client )
  53. {
  54. MuteDb.Add( new Player( Client ) );
  55. ServerLog( LogType.LogData, "DEBUG: Added mutelist for: " + Client.Name );
  56. }
  57.  
  58.  
  59. public override ChatType OnSay( string Message, ServerClient Client )
  60. {
  61. // Mute a player
  62. if ( Message.StartsWith( "!mute" ) )
  63. {
  64. if ( Message.Length <= 6 )
  65. TellClient( Client.ClientNum, "^3Usage: !mute [Playername]", true );
  66. else if ( GetClientByName( Message.Substring( 6 ) ) != null )
  67. GetPlayerMute( Client ).AddMute( GetClientByName( Message.Substring( 6 ) ) );
  68. else
  69. TellClient( Client.ClientNum, "^3There was no player found!", true );
  70. return ChatType.ChatContinue;
  71. }
  72. // Unmute a player
  73. else if ( Message.StartsWith( "!unmute" ) )
  74. {
  75. if ( Message.Length <= 6 )
  76. TellClient( Client.ClientNum, "^3Usage: !unmute [Playername]", true );
  77. else if ( GetClientByName( Message.Substring( 6 ) ) != null )
  78. GetPlayerMute( Client ).RemoveMute( GetClientByName( Message.Substring( 6 ) ) );
  79. else
  80. TellClient( Client.ClientNum, "^3There was no player found!", true );
  81. return ChatType.ChatContinue;
  82. }
  83. // Show muted players
  84. else if ( Message.StartsWith( "!mutelist" ) )
  85. {
  86. string s = "^3Muted: ";
  87. foreach ( Player player in MuteDb )
  88. if ( player.Client == Client )
  89. foreach ( ServerClient client in player.Muted )
  90. s += client.Name + ", ";
  91. TellClient( Client.ClientNum, s, true );
  92. return ChatType.ChatContinue;
  93. }
  94.  
  95. // Show the text to everyone that didn't mute this Client
  96. foreach ( Player player in MuteDb )
  97. if ( !player.IsMuted( Client ) )
  98. TellClient( player.Client.ClientNum, Message, true );
  99.  
  100. return ChatType.ChatContinue;
  101. }
  102.  
  103. // Get the 'Player' class for this client
  104. Player GetPlayerMute( ServerClient client )
  105. {
  106. foreach ( Player player in MuteDb )
  107. if ( player.Client == client )
  108. return player;
  109. return null;
  110. }
  111.  
  112. // Get the 'ServerClient' for this player(name)
  113. ServerClient GetClientByName( string name )
  114. {
  115. foreach ( ServerClient client in GetClients() )
  116. if ( client.Name.StartsWith( name, StringComparison.InvariantCultureIgnoreCase )
  117. || client.Name.EndsWith( name, StringComparison.InvariantCultureIgnoreCase ) )
  118. return client;
  119. return null;
  120. }
  121. }
  122.  
  123. public class Player
  124. {
  125. public ServerClient Client;
  126. public System.Collections.Generic.List<ServerClient> Muted = new System.Collections.Generic.List<ServerClient>();
  127. public Player( ServerClient client ) { Client = client; }
  128. public bool IsMuted( ServerClient client ) { return Muted.Contains( client ); }
  129. public void AddMute( ServerClient client ) { Muted.Add( client ); }
  130. public void RemoveMute( ServerClient client ) { Muted.Remove( client ); }
  131. }
  132. }
Ah nice, won't code one tomorrow then Tongue
-Bonemind
(02-02-2012, 00:06)bonemind Wrote: [ -> ]Ah nice, won't code one tomorrow then Tongue
-Bonemind

Can you compile, test and debug it for me since I can't do this? Smile
(02-02-2012, 00:11)iAegle Wrote: [ -> ]
(02-02-2012, 00:06)bonemind Wrote: [ -> ]Ah nice, won't code one tomorrow then Tongue
-Bonemind

Can you compile, test and debug it for me since I can't do this? Smile

Will do that tomorrow, atm i'm not a great bugtester/coder/anything elseTongue
I'll post my results here ASAP though
Ive compiled and tested

Bugs:
I tried unmuting my self and does not work crashed my server
!mutelist and !mute work


only thing i havent tested is muting and unmuting another person

You may test if u like.
Pages: 1 2