Ejemplo n.º 1
0
        public static System.Data.DataRow checkSession(uint userId, ulong sessionId)
        {
            if (sessionId < 1 || userId < 1000)
            {
                return(null);
            }

            using (IQueryAdapter dbClient = manager.getQueryreactor())
            {
                System.Data.DataTable data = (System.Data.DataTable)dbClient.query("SELECT users.ID, users.Email, users.Name, server_1_players.playerID, server_1_players.shipId, server_1_players.factionId, server_1_players.mapId, server_1_players.x, server_1_players.y, server_1_players.settings FROM server_1_players, users WHERE server_1_players.tokenId = @sessionId AND server_1_players.playerID = @ID AND users.ID = server_1_players.userID", (new string[] { "sessionId", "ID" }), (new string[] { sessionId.ToString(), userId.ToString() }));

                if (data.Rows.Count == 1)
                {
                    return(data.Rows[0]);
                }

                return(null);
            }
        }
Ejemplo n.º 2
0
        static async void Server()
        {
            Out.WriteLine("Started pararell task.", "Azure.Boot");
            checkUpdates();

            Out.WriteLine("Checking for app.ini...", "Azure.Boot");

            if (!System.IO.File.Exists("app.ini"))
            {
                Out.WriteLine("Error #1 loading app.ini: File not exists", "Azure.Boot", ConsoleColor.Red);
                Console.ReadKey();
                Environment.Exit(0);
            }
            Settings = await ReadSettings(System.IO.File.ReadAllText("app.ini"));

            if (!Settings.ContainsKey("server") || !Settings.ContainsKey("mport") || !Settings.ContainsKey("username") || !Settings.ContainsKey("password") || !Settings.ContainsKey("dbName") || !Settings.ContainsKey("port") || !Settings.ContainsKey("flushPackets"))
            {
                Out.WriteLine("Error #3 loading app.ini: Configuration file is invalid", "Azure.Boot", ConsoleColor.Red);
                Console.ReadKey();
                Environment.Exit(0);
            }
            Out.WriteLine("app.ini loaded.", "Azure.Boot");
            Console.WriteLine();

            try
            {
                Out.WriteLine("Connecting to " + Settings["dbName"] + " at " + Settings["server"] + ":" + Settings["mport"] + " for user " + Settings["username"], "MySQL.Connect");
                manager = new DatabaseManager(30, 10, DatabaseType.MySQL);
                manager.setServerDetails(Settings["server"], uint.Parse(Settings["mport"]), Settings["username"], Settings["password"], Settings["dbName"]);
                manager.init();
                Out.WriteLine("Connection to database successfull.", "MySQL.Connect");
            }
            catch (Exception e)
            {
                Out.WriteLine("Error #4 connecting to MySQL: " + e.Message, "MySQL.Connect", ConsoleColor.Red);
                Console.ReadKey();
                Environment.Exit(0);
            }

            Console.WriteLine();
            Users = new Dictionary <uint, game.User>();
            Out.WriteLine("Initializing game maps ...", "Server.Game.Maps");
            Maps = new Dictionary <ushort, serverGame.Map>();
            using (IQueryAdapter dbClient = manager.getQueryreactor())
            {
                NPCS = new Dictionary <ushort, Ships>();
                var data = (System.Data.DataTable)dbClient.query("SELECT * FROM ships");
                foreach (System.Data.DataRow Row in data.Rows)
                {
                    Ships alien = new Ships();
                    alien.Id           = Convert.ToUInt16(Row["Id"]);
                    alien.Name         = Row["Name"].ToString();
                    alien.HP           = Convert.ToUInt32(Row["HP"]);
                    alien.Shield       = Convert.ToUInt32(Row["Shield"]);
                    alien.Damage       = Convert.ToUInt32(Row["Damage"]);
                    alien.Speed        = Convert.ToUInt16(Row["Speed"]);
                    alien.isNeutral    = ToBool(Row["isNeutral"].ToString());
                    alien.shieldAbsorb = Convert.ToUInt16(Row["shieldAbsorb"]);
                    alien.LaserId      = Convert.ToUInt16(Row["LaserId"]);
                    NPCS.Add(alien.Id, alien);

                    var data2 = (System.Data.DataTable)dbClient.query("SELECT * FROM ships_designs WHERE ShipId = " + alien.Id + "");
                    if (data2.Rows.Count > 0)
                    {
                        foreach (System.Data.DataRow _Row in data2.Rows)
                        {
                            Ships ship = new Ships();
                            ship.Id           = Convert.ToUInt16(_Row["Id"]);
                            ship.Name         = _Row["Name"].ToString();
                            ship.HP           = Convert.ToUInt32(Row["HP"]);
                            ship.Shield       = Convert.ToUInt32(Row["Shield"]);
                            ship.Damage       = Convert.ToUInt32(Row["Damage"]);
                            ship.Speed        = Convert.ToUInt16(Row["Speed"]);
                            ship.isNeutral    = ToBool(Row["isNeutral"].ToString());
                            ship.shieldAbsorb = Convert.ToUInt16(Row["shieldAbsorb"]);
                            ship.LaserId      = Convert.ToUInt16(Row["LaserId"]);
                            NPCS.Add(ship.Id, ship);
                        }
                    }
                }

                data = (System.Data.DataTable)dbClient.query("SELECT * FROM maps");
                foreach (System.Data.DataRow Row in data.Rows)
                {
                    Maps.Add(Convert.ToUInt16(Row["id"]), new serverGame.Map(Convert.ToUInt16(Row["id"]), Row["Name"].ToString(), Row["Portals"].ToString(), Row["NPCS"].ToString(), Program.ToBool(Row["isStarterMap"].ToString()), Convert.ToUInt16(Row["factionId"])));
                }
            }
            Out.WriteLine("Loaded " + Maps.Count + " maps.", "Server.Game.Maps");
            Out.WriteLine("Loaded " + NPCS.Count + " ships.", "Server.Game.Ships");
            Console.WriteLine();

            Out.WriteLine("Starting up asynchronous sockets server for game connections for port " + Settings["port"], "Server.AsyncSocketListener");
            Core.AsynchronousSocketListener.SetPort(Convert.ToInt32(Settings["port"]));
            Task.Factory.StartNew(Core.AsynchronousSocketListener.StartListening);
            Out.WriteLine("Asynchronous sockets server for game connections running on port " + Settings["port"], "Server.AsyncSocketListener");
            Out.WriteLine("DarkOrbit Emulator ready. Status: idle", "Azure.Boot");
            Console.WriteLine();
            Console.Beep();
        }