IsBanned() public static méthode

public static IsBanned ( string IP ) : bool
IP string
Résultat bool
Exemple #1
0
        public MainClass(string[] args)
        {
            Instance  = this;
            StartTime = DateTime.Now;

            string argConfigFile = "Config.ini";

            try {
                for (int i = 0; i < args.Length; i++)
                {
                    switch (args[i])
                    {
                    case "--help":
                    case "-h":
                    case "-?":
                    default:
                        this.ShowHelp();
                        return;

                    case "--version":
                    case "-v":
                        Console.WriteLine("OpenSMO build " + Build);
                        return;

                    case "--config":
                    case "-c":
                        argConfigFile = args[++i];
                        break;
                    }
                }
            } catch {
                this.ShowHelp();
            }

            ServerConfig = new Config(argConfigFile);

            Console.Title = ServerConfig.Get("Server_Name");

            AddLog("Server starting at " + StartTime);

            if (bool.Parse(ServerConfig.Get("Server_HigherPriority")))
            {
                AddLog("Setting priority to above normal");
                Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;
            }

            FPS = int.Parse(ServerConfig.Get("Server_FPS"));

            // Get optional advanced settings
            if (ServerConfig.Contains("Server_Offset"))
            {
                ServerOffset = (byte)int.Parse(ServerConfig.Get("Server_Offset"));
            }
            if (ServerConfig.Contains("Server_Version"))
            {
                ServerVersion = (byte)int.Parse(ServerConfig.Get("Server_Version"));
            }
            if (ServerConfig.Contains("Server_MaxPlayers"))
            {
                ServerMaxPlayers = (byte)int.Parse(ServerConfig.Get("Server_MaxPlayers"));
            }

            Sql.Filename = ServerConfig.Get("Database_File");
            Sql.Version  = int.Parse(ServerConfig.Get("Database_Version"));
            Sql.Compress = bool.Parse(ServerConfig.Get("Database_Compressed"));
            Sql.Connect();

            if (!Sql.Connected)
            {
                AddLog("Please check your SQLite database.", true);
            }

            Sql.ReportErrors = false;
            Hashtable[] fixedRooms = Sql.Query("SELECT * FROM fixedrooms;");
            Sql.ReportErrors = true;

            if (fixedRooms == null)
            {
                AddLog("It appears there's no \"fixedrooms\" table, creating one now.");
                Sql.Query(@"CREATE TABLE ""main"".""fixedrooms"" (
          ""ID""  INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
          ""Name""  TEXT(255) NOT NULL,
          ""Description""  TEXT(255),
          ""Password""  TEXT(255),
          ""Free""  INTEGER,
          ""MOTD""  TEXT(255),
          ""Operators""  TEXT(255));");
            }
            else
            {
                foreach (Hashtable room in fixedRooms)
                {
                    Room newRoom = new Room(this, null);
                    newRoom.Fixed       = true;
                    newRoom.Name        = room["Name"].ToString();
                    newRoom.Description = room["Description"].ToString();
                    newRoom.Password    = room["Password"].ToString();
                    newRoom.Free        = room["Free"].ToString() == "1";
                    newRoom.FixedMotd   = room["MOTD"].ToString();

                    string[]   strOps = room["Operators"].ToString().Split(',');
                    List <int> ops    = new List <int>();
                    foreach (string op in strOps)
                    {
                        if (op == "")
                        {
                            continue;
                        }

                        int opID = 0;
                        if (int.TryParse(op, out opID))
                        {
                            ops.Add(opID);
                        }
                        else
                        {
                            AddLog("Invalid op ID '" + op + "'");
                        }
                    }
                    newRoom.FixedOperators = ops.ToArray();
                    Rooms.Add(newRoom);

                    AddLog("Added fixed room '" + newRoom.Name + "'");
                }
            }

            ReloadScripts();

            tcpListener = new TcpListener(IPAddress.Parse(ServerConfig.Get("Server_IP")), int.Parse(ServerConfig.Get("Server_Port")));
            tcpListener.Start();

            AddLog("Server started on port " + ServerConfig.Get("Server_Port"));

            new Thread(new ThreadStart(UserThread)).Start();

            if (bool.Parse(ServerConfig.Get("RTS_Enabled")))
            {
                tcpListenerRTS = new TcpListener(IPAddress.Parse(ServerConfig.Get("RTS_IP")), int.Parse(ServerConfig.Get("RTS_Port")));
                tcpListenerRTS.Start();

                AddLog("RTS server started on port " + ServerConfig.Get("RTS_Port"));

                new Thread(new ThreadStart(RTSThread)).Start();
            }

            AddLog("Server running.");

            while (true)
            {
                TcpClient newTcpClient = tcpListener.AcceptTcpClient();

                string IP = newTcpClient.Client.RemoteEndPoint.ToString().Split(':')[0];
                if (Data.IsBanned(IP))
                {
                    if (bool.Parse(ServerConfig.Get("Game_ShadowBan")))
                    {
                        AddLog("Shadowbanned client connected: " + IP, true);

                        User newUser = new User(this, newTcpClient);
                        newUser.ShadowBanned = true;
                        Users.Add(newUser);
                    }
                    else
                    {
                        AddLog("Banned client kicked: " + IP, true);
                        newTcpClient.Close();
                    }
                }
                else
                {
                    AddLog("Client connected: " + IP);

                    User newUser = new User(this, newTcpClient);
                    Users.Add(newUser);
                }
            }
        }
Exemple #2
0
        public MainClass(string[] args)
        {
            Instance  = this;
            StartTime = DateTime.Now;

            string argConfigFile = "Config.ini";

            try
            {
                for (int i = 0; i < args.Length; i++)
                {
                    switch (args[i])
                    {
                    case "--help":
                    case "-h":
                    case "-?":
                    default:
                        this.ShowHelp();
                        return;

                    case "--version":
                    case "-v":
                        Console.WriteLine("OpenSMO build " + Build);
                        return;

                    case "--config":
                    case "-c":
                        argConfigFile = args[++i];
                        break;
                    }
                }
            }
            catch
            {
                this.ShowHelp();
            }

            ServerConfig = new Config(argConfigFile);

            Console.Title = ServerConfig.Get("Server_Name");
            string builddate = RetrieveLinkerTimestamp().ToString("MM/dd/yy HH:mm:ss");

            AddLog("Server starting at " + StartTime + " Build Date: " + builddate);
            if (bool.Parse(ServerConfig.Get("Server_HigherPriority")))
            {
                AddLog("Setting priority to above normal");
                Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;
            }

            FPS = int.Parse(ServerConfig.Get("Server_FPS"));

            // Get optional advanced settings
            if (ServerConfig.Contains("Server_Offset"))
            {
                ServerOffset = (byte)int.Parse(ServerConfig.Get("Server_Offset"));
            }
            if (ServerConfig.Contains("Server_Version"))
            {
                ServerVersion = (byte)int.Parse(ServerConfig.Get("Server_Version"));
            }
            if (ServerConfig.Contains("Server_MaxPlayers"))
            {
                ServerMaxPlayers = (byte)int.Parse(ServerConfig.Get("Server_MaxPlayers"));
            }

            MySql.Host     = ServerConfig.Get("MySql_Host");
            MySql.User     = ServerConfig.Get("MySql_User");
            MySql.Password = ServerConfig.Get("MySql_Password");
            MySql.Database = ServerConfig.Get("MySql_Database");
            MySql.Timeout  = ServerConfig.Get("MySql_Timeout");

            ReloadScripts();

            tcpListener = new TcpListener(IPAddress.Parse(ServerConfig.Get("Server_IP")), int.Parse(ServerConfig.Get("Server_Port")));
            tcpListener.Start();

            AddLog("Server started on port " + ServerConfig.Get("Server_Port"));

            new Thread(new ThreadStart(UserThread)).Start();

            if (bool.Parse(ServerConfig.Get("RTS_Enabled")))
            {
                tcpListenerRTS = new TcpListener(IPAddress.Parse(ServerConfig.Get("RTS_IP")), int.Parse(ServerConfig.Get("RTS_Port")));
                tcpListenerRTS.Start();

                AddLog("RTS server started on port " + ServerConfig.Get("RTS_Port"));

                new Thread(new ThreadStart(RTSThread)).Start();
            }

            AddLog("Server running.");

            while (true)
            {
                TcpClient newTcpClient = tcpListener.AcceptTcpClient();

                string IP = newTcpClient.Client.RemoteEndPoint.ToString().Split(':')[0];
                if (Data.IsBanned(IP))
                {
                    if (bool.Parse(ServerConfig.Get("Game_ShadowBan")))
                    {
                        AddLog("Shadowbanned client connected: " + IP, true);

                        User newUser = new User(this, newTcpClient);
                        newUser.ShadowBanned = true;
                        lock (Users)
                        {
                            Users.Add(newUser);
                        }
                    }
                    else
                    {
                        AddLog("Banned client kicked: " + IP, true);
                        newTcpClient.Close();
                    }
                }
                else
                {
                    AddLog("Client connected: " + IP);

                    User newUser = new User(this, newTcpClient);
                    lock (Users)
                    {
                        Users.Add(newUser);
                    }
                    lock (Users)
                    {
                        foreach (User user in Users)
                        {
                            if (user.CurrentRoom == null)
                            {
                                user.SendRoomPlayers();
                            }
                        }
                    }
                }
            }
        }