예제 #1
0
파일: User.cs 프로젝트: Supermale/OpenSMO
        public User( MainClass mainClass, TcpClient tcpClient )
        {
            this.mainClass = mainClass;
            this.tcpClient = tcpClient;

            this.User_IP = tcpClient.Client.RemoteEndPoint.ToString().Split( ':' )[ 0 ];

            NetworkStream stream = tcpClient.GetStream();
            stream.ReadTimeout = int.Parse( mainClass.ServerConfig.Get( "Server_ReadTimeout" ) );
            this.tcpWriter = new BinaryWriter( stream );
            this.tcpReader = new BinaryReader( stream );

            ez = new Ez( this );
        }
예제 #2
0
파일: Main.cs 프로젝트: Wayfur/OpenSMO
        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"));

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

              Hashtable[] fixedRooms = MySql.Query("SELECT * FROM fixedrooms;");

              if (fixedRooms == null) {
            AddLog("It appears there's no \"fixedrooms\" table, creating one now.");
            MySql.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);
            }
              }
        }
예제 #3
0
파일: Main.cs 프로젝트: SandonV/OpenSMO
        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();
                        }
                    }
                }
            }
            }
        }
예제 #4
0
파일: Room.cs 프로젝트: SandonV/OpenSMO
 public Room(MainClass mainClass, User Owner)
 {
     this.mainClass = mainClass;
     this.Owner = Owner;
     this.ID = MainClass.RandomString(5);
 }
예제 #5
0
파일: Main.cs 프로젝트: gifgn/OpenSMO
        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();
                            }
                        }
                    }
                }
            }
        }
예제 #6
0
파일: Room.cs 프로젝트: gifgn/OpenSMO
 public Room(MainClass mainClass, User Owner)
 {
     this.mainClass = mainClass;
     this.Owner     = Owner;
     this.ID        = MainClass.RandomString(5);
 }
예제 #7
0
 private static void CloseHandler()
 {
     MainClass.AddLog("Connection closed during StreamHelper byte reading", true);
 }
예제 #8
0
 private static void ErrorHandler()
 {
     MainClass.AddLog("Error in StreamHelper", true);
 }
예제 #9
0
파일: Main.cs 프로젝트: Supermale/OpenSMO
        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);

            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);
                }
            }
        }