Exemple #1
0
        private static void AntiCheat()
        {
            Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Highest;
            R.Log("[RowAC] main thread initiated");

            while (true)
            {
                try
                {
                    var connections = RustAPI.GetConnections();
                    foreach (var p in connections)
                    {
                        var player = RustAPI.GetUser(p);
                        if (RustAPI.IsUserConnected(player) && RustAPI.GetUserConnectionTime(player) >= rconf.minConnectionTime)
                        {
                            CheckPlayer(player);
                        }
                    }

                    Thread.Sleep(rconf.threadSleepTime * 1000);
                }
                catch (Exception ex) { R.LogEx("LoopCrash", ex); }
            }
        }
Exemple #2
0
        private void takeCoordsEvent(object x, ElapsedEventArgs y)
        {
            var connections = RustAPI.GetConnections();

            foreach (var p in connections)
            {
                try
                {
                    var player = RustAPI.GetUser(p);
                    if (player == null)
                    {
                        R.Log("No user on join: " + p.id + " " + p.ipAddress);
                        continue;
                    }

                    if (RustAPI.IsUserConnected(player))
                    {
                        R.Log("NotConnected: " + RustAPI.GetUserName(player) + " - " + RustAPI.GetUserID(player));
                    }

                    if (aconf.adminCheck && RustAPI.IsUserAdmin(player))
                    {
                        continue;
                    }

                    Vector3 CurrentPosition     = RustAPI.GetUserTransform(player).position;
                    Vector2 CurrentPlayerCoords = new Vector2(CurrentPosition.x, CurrentPosition.z); // Ignore Y

                    ulong  playerID   = RustAPI.GetUserID(player);
                    string playerName = RustAPI.GetUserName(player);

                    if (!playerCoordinates.ContainsKey(playerID))
                    {
                        playerCoordinates[playerID] = CurrentPosition;
                        continue;
                    }
                    Vector3 OldPlayerCoordsVector3 = playerCoordinates[playerID];
                    playerCoordinates[playerID] = CurrentPosition;

                    Vector2 OldPlayerCoords = new Vector2(OldPlayerCoordsVector3.x, OldPlayerCoordsVector3.z);

#if DEBUG           // TODO: fix
                    /*
                     *  Log("=== Pos Control ===");
                     *  Log(CurrentPosition.x + " " + CurrentPosition.z);
                     *  Log(Player.GetNetworkPosition().x + " " + Player.GetNetworkPosition().z);
                     *  Log(Player.GetPositionForChecks().x + " " + Player.GetPositionForChecks().z);
                     *  Log("=== =========== ===");
                     */
#endif
                    if (OldPlayerCoords != Vector2.zero && OldPlayerCoords != CurrentPlayerCoords)
                    {
                        float distance = Math.Abs(Vector2.Distance(OldPlayerCoords, CurrentPlayerCoords));
                        float speed    = distance / (float)aconf.checkInterval;
                        R.Log("[Speed] " + playerName + " speed is " + speed.ToString());

                        if (!playerWarnings.ContainsKey(playerID))
                        {
                            playerWarnings[playerID] = 0;
                        }
                        int warnLevel = playerWarnings[playerID];

                        if (speed < aconf.sayChatSpeed) // decrease warning level for user
                        {
                            playerWarnings[playerID] = (warnLevel > 0 ? warnLevel - 1 : 0);
                        }
                        else if (warnLevel == aconf.warnLimit && // Time to ban
                                 (speed > aconf.teleportSpeed && !aconf.allowTP)) // Not allow to TP
                        {
                            if (speed > aconf.sayChatSpeed && aconf.sayChat)
                            {
                                RustAPI.SayToChat("Moved with speed" + speed.ToString("F2"));
                            }
                            else if (speed > aconf.banSpeed && aconf.ban)
                            {
                                BanCheater(player, "Moved with speed" + speed.ToString("F2"));
                            }
                            else if (speed > aconf.kickSpeed && aconf.kick)
                            {
                                R.Log("Kick: " + playerName + ". SpeedHack. Maybe lag (Ping " + RustAPI.GetUserPing(player) + ")");
                                RustAPI.KickUser(player, NetError.Facepunch_Kick_Ban, true);
                            }
                        }

                        // Turn player back
                        if (warnLevel < aconf.warnLimit && speed > aconf.sayChatSpeed)
                        {
                            RustAPI.GetUserTransform(player).position = OldPlayerCoordsVector3;
                            if (speed > aconf.kickSpeed)
                            {
                                playerWarnings[playerID]++;
                            }
                            R.Log("Warning: " + playerName + " moved with speed " + speed.ToString("F2") + ". Warnings: " + warnLevel + ". Ping: " + RustAPI.GetUserPing(player));
                        }
                    }
                }
                catch (Exception ex) { R.LogEx("TakeCoordsLoop", ex); }
            }
        }