Announcement

Collapse
No announcement yet.

Code only works sometimes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Code only works sometimes

    I ported this over from 2003 and made some changes.

    It does work sometimes as I see the message being logged, but more than not the players with high pings are not being kicked.

    Can anyone see anything wrong with this code?

    Code:
    // =====================================================================
    // MutLimitByPing - Kicks players from a server if they do not meet the ping requirements
    // Created by OzForces Internet (http://www.ozforces.com/)
    // =====================================================================
    class LimitPing extends Mutator config;
    
    var int Violations[64];
    
    var string ClanName[5];
    var config string ClanName0;
    var config string ClanName1;
    var config string ClanName2;
    var config string ClanName3;
    var config string ClanName4;
    var config int MaximumPing;
    var config int MaxViolations;
    var config int WarningLevel;
    var config float CheckInterval;
    var config string ClientWarning;
    
    function PreBeginPlay()
    {
     Super.PreBeginPlay();
     saveconfig();
    }
    
    event PostBeginPlay() {
        ClanName[0] = ClanName0;
        ClanName[1] = ClanName1;
        ClanName[2] = ClanName2;
        ClanName[3] = ClanName3;
        ClanName[4] = ClanName4;
        SetTimer(CheckInterval,true);
        Super.PostBeginPlay();
    }
    
    function Timer() 
    {
       local Controller P, NextP;
       local int i, found, dokick, PlayerID;
       local string checkclan, playername;
    
       P = Level.ControllerList;
       if (P != None)
       {
          do 
          {
             NextP = P.NextController;
             if (PlayerController(P) != None && 
                 P.PlayerReplicationInfo != None &&
                 P.bIsPlayer &&
                 NetConnection(PlayerController(P).Player) != None) 
             {
                dokick = 0;
                for (i = 0;i < 5; i++) 
                {
                    checkclan = Caps(ClanName[i]);		// don't kick these clans
                    if (checkclan != "") 
                    {
                       playername = Caps(P.PlayerReplicationInfo.PlayerName);
                       found = InStr(playername, checkclan);
                       if (found != -1)
                          dokick = 1;
                    }
                } 
                if ( P.PlayerReplicationInfo.Ping > MaximumPing && dokick == 0) 
                {
                   PlayerID = P.PlayerReplicationInfo.PlayerID;
                   Violations[PlayerID]++;
                   if ((P.IsA('PlayerController')) && (Violations[PlayerID] > MaxViolations)) 
                   {
                      Log("-->LimitPing Kicking = " $P.PlayerReplicationInfo.PlayerName);
                      Log("-->LimitPing Kicking = " $PlayerController(P).GetPlayerNetworkAddress());
                      Level.Game.AccessControl.KickPlayer(PlayerController(P)); 
                   } 
                   else if (Violations[PlayerID] > WarningLevel) 
                     PlayerController(P).ClientMessage(ClientWarning);
                }
             }
             P = NextP;
          } until (P == None);
       }
    }
    
    static function FillPlayInfo(PlayInfo PlayInfo)
     {
       Super.FillPlayInfo(PlayInfo);
       
       PlayInfo.AddSetting("LimitPing", "ClanName0",     "Clan to Exclude", 0,1, "Text", "10",, True,True);
       PlayInfo.AddSetting("LimitPing", "ClanName1",     "Clan to Exclude", 0,1, "Text", "10",, True,True);
       PlayInfo.AddSetting("LimitPing", "ClanName2",     "Clan to Exclude", 0,1, "Text", "10",, True,True);
       PlayInfo.AddSetting("LimitPing", "ClanName3",     "Clan to Exclude", 0,1, "Text", "10",, True,True);
       PlayInfo.AddSetting("LimitPing", "ClanName4",     "Clan to Exclude", 0,1, "Text", "10",, True,True);
       PlayInfo.AddSetting("LimitPing", "MaximumPing",   "Maximum Ping",    0,1, "Text", "10;1:300",, True,True);
       PlayInfo.AddSetting("LimitPing", "MaxViolations", "Max Violations",  0,1, "Text", "3;1:5");
       PlayInfo.AddSetting("LimitPing", "WarningLevel",  "Warning Violations", 0,1, "Text", "3;1:5");
       PlayInfo.AddSetting("LimitPing", "CheckInterval", "Check Interval", 0,1, "Text", "10;30:300");
       PlayInfo.AddSetting("LimitPing", "ClientWarning", "Client Warning", 0,1, "Text", "90",, True,True);
    }
    
    
    
    static event string GetDescriptionText(string PropName)
    {
       switch (PropName)
       {
          case "ClanName0":	return "Clan to Exclude from being kicked:";
          case "ClanName1":	return "Clan to Exclude from being kicked";
          case "ClanName2":	return "Clan to Exclude from being kicked";
          case "ClanName3":	return "Clan to Exclude from being kicked";
          case "ClanName4":	return "Clan to Exclude from being kicked";
          case "MaximumPing": return "Maximum ping allowed before being kicked";
          case "MaxViolations": return "Ping Violations before being kicked";
          case "WarningLevel": return "How Many warnings (should be one less or equal to Max Violations)";
          case "CheckInterval": return "How Often to check in seconds";
          case "ClientWarning": return "Warning Message to Client";
       }
          return Super.GetDescriptionText(PropName);
    }
    
    defaultproperties
    {
         ClanName0="(Clan)"
         ClanName1=""
         ClanName2=""
         ClanName3=""
         ClanName4=""
         MaximumPing=200
         MaxViolations=4
         WarningLevel=3
         CheckInterval=60.000000
         ClientWarning="Your ping is too high, you will be kicked"
         GroupName="LimitPing"
         FriendlyName="LimitPing"
         Description="Will kick any players with a ping higher than a set level"
    }

    #2
    How about implementing a minimum ping limit too? That might be useful for anyone wishing to set up a nominally '56k-only' server.

    Comment


      #3
      min ping

      Originally posted by Mr Evil
      How about implementing a minimum ping limit too? That might be useful for anyone wishing to set up a nominally '56k-only' server.
      Well, that was in the original code, it would be easy enough to put it back, but since it only works sometimes no point at this time.

      Uadmin has a ping check also, but no way to exclude your own clan members. And of course they strip out the source code so no one else can see it.. Nothing wrong with that, I'm not trying to take credit for this code, just trying to get something to work for my servers.

      Comment


        #4
        Works now

        This version seems to be working fine now.

        Code:
        // =====================================================================
        // MutLimitByPing - Kicks players from a server if they do not meet the ping requirements
        // Created by OzForces Internet (http://www.ozforces.com/)
        // Modified for ODC Servers by Sargon - sargon@odclan.org
        // =====================================================================
        class ODCLimitPing extends Mutator config(ODCUtils);
        
        var int Violations[64];
        
        var string ClanName[5];
        var config string ClanName0;
        var config string ClanName1;
        var config string ClanName2;
        var config string ClanName3;
        var config string ClanName4;
        var config int MaximumPing;
        var config int MaxViolations;
        var config int WarningLevel;
        var config float CheckInterval;
        var config string ClientWarning;
        var int dokick;
        
        function PreBeginPlay()
        {
         Super.PreBeginPlay();
         saveconfig();
        }
        
        event PostBeginPlay() 
        {
        
           Initialize();
           SetTimer(CheckInterval,true);
           Super.PostBeginPlay();
        }
        
        function Initialize() 
        {
        
           log("ODCLimitPing - * ODCLimitPing");
           log("ODCLimitPing - * Version 1.04");
           log("ODCLimitPing - * MaximumPing   ="@MaximumPing);
           log("ODCLimitPing - * MaxViolations ="@MaxViolations);
           log("ODCLimitPing - * WarningLevel  ="@WarningLevel);
           log("ODCLimitPing - * CheckInterval ="@CheckInterval);
           ClanName[0] = ClanName0;
           ClanName[1] = ClanName1;
           ClanName[2] = ClanName2;
           ClanName[3] = ClanName3;
           ClanName[4] = ClanName4;
        }
        
        function Timer() 
        {
           local Controller P, NextP;
           local int i, found, PlayerID;
           local string checkclan, playername;
           local byte ping;
        
           P = Level.ControllerList;
           if (P != None)
           {
              do {
                 NextP = P.NextController;
                 if (PlayerController(P) != None && 
                     P.PlayerReplicationInfo != None &&
                     NetConnection(PlayerController(P).Player) != None) 
                 {
                    dokick = 0;
                    for (i = 0;i < 5; i++) 
                    {
                        checkclan = Caps(ClanName[i]);		// don't kick these clans
                        if (checkclan != "") 
                        {
                           playername = Caps(P.PlayerReplicationInfo.PlayerName);
                           found = InStr(playername, checkclan);
                           if (found != -1)
                              dokick = 1;
                        }
                    } 
                    ping = 4 * P.PlayerReplicationInfo.Ping;
                    if ( ping > MaximumPing && dokick == 0) 
                    {
                       PlayerID = P.PlayerReplicationInfo.PlayerID;
                       Violations[PlayerID]++;
                       if ((P.IsA('PlayerController')) && (Violations[PlayerID] > MaxViolations)) 
                       {
                          Log("-->ODCLimitPing Kicked Player Name = " $P.PlayerReplicationInfo.PlayerName);
                          Log("-->ODCLimitPing Kicked Player IP   = " $PlayerController(P).GetPlayerNetworkAddress());
                          Log("-->ODCLimitPing Kicked Player Ping = " $ping);
                          Level.Game.AccessControl.KickPlayer(PlayerController(P));
                       } 
                       else if (Violations[PlayerID] >= WarningLevel) 
                       {
                          PlayerController(P).ClientMessage("Your ping is: "$string(ping)$", "$ClientWarning);
                       }
                    }
                 }
                 P = NextP;
              } until (P == None);
           }
        }
        
        
        static function FillPlayInfo(PlayInfo PlayInfo)
        {
           Super.FillPlayInfo(PlayInfo);
           
           PlayInfo.AddSetting("ODCLimitPing", "ClanName0",     "Clan to Exclude", 0,1, "Text", "10",, True,True);
           PlayInfo.AddSetting("ODCLimitPing", "ClanName1",     "Clan to Exclude", 0,1, "Text", "10",, True,True);
           PlayInfo.AddSetting("ODCLimitPing", "ClanName2",     "Clan to Exclude", 0,1, "Text", "10",, True,True);
           PlayInfo.AddSetting("ODCLimitPing", "ClanName3",     "Clan to Exclude", 0,1, "Text", "10",, True,True);
           PlayInfo.AddSetting("ODCLimitPing", "ClanName4",     "Clan to Exclude", 0,1, "Text", "10",, True,True);
           PlayInfo.AddSetting("ODCLimitPing", "MaximumPing",   "Maximum Ping",    0,1, "Text", "10;1:300",, True,True);
           PlayInfo.AddSetting("ODCLimitPing", "MaxViolations", "Max Violations",  0,1, "Text", "3;1:5");
           PlayInfo.AddSetting("ODCLimitPing", "WarningLevel",  "Warning Violations", 0,1, "Text", "3;1:5");
           PlayInfo.AddSetting("ODCLimitPing", "CheckInterval", "Check Interval", 0,1, "Text", "10;30:300");
           PlayInfo.AddSetting("ODCLimitPing", "ClientWarning", "Client Warning", 0,1, "Text", "90",, True,True);
        }
        
        static event string GetDescriptionText(string PropName)
        {
           switch (PropName)
           {
              case "ClanName0":	return "Clan to Exclude from being kicked: (ODC)";
              case "ClanName1":	return "Clan to Exclude from being kicked";
              case "ClanName2":	return "Clan to Exclude from being kicked";
              case "ClanName3":	return "Clan to Exclude from being kicked";
              case "ClanName4":	return "Clan to Exclude from being kicked";
              case "MaximumPing": return "Maximum ping allowed before being kicked";
              case "MaxViolations": return "Ping Violations before being kicked";
              case "WarningLevel": return "How Many warnings (should be one less or equal to Max Violations)";
              case "CheckInterval": return "How Often to check in seconds";
              case "ClientWarning": return "Warning Message to Client";
           }
              return Super.GetDescriptionText(PropName);
        }
        
        defaultproperties
        {
             ClanName0=""
             ClanName1=""
             ClanName2=""
             ClanName3=""
             ClanName4=""
             MaximumPing=100
             MaxViolations=4
             WarningLevel=1
             CheckInterval=60.000000
             ClientWarning="Your ping is too high, you will be kicked soon "
             GroupName="ODCLimitPing"
             FriendlyName="ODCLimitPing"
             Description="(ODC) Will kick any players with a ping higher than a set level"
        }

        Comment

        Working...
        X