Beispiel #1
0
 private void API_onResourceStart()
 {
     API.requestIpl("SP1_10_real_interior");
     MySqlInsightDbProvider.RegisterProvider();
     _database       = new MySqlConnectionStringBuilder("server=localhost;user=root;database=gtanserver;port=3306;password=;");
     _userRepository = _database.Connection().As <IUserRepository>();
 }
Beispiel #2
0
        public Instructor InsertInstructor(Instructor instructor)
        {
            IList <UInt64> res = db.Connection().QuerySql <UInt64>(
                string.Format("INSERT INTO `instructor` (name, birth_date, graduation_date, subject, bio) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}');SELECT LAST_INSERT_ID();",
                              instructor.name,
                              instructor.birth_date.ToString("yyyy-MM-dd"),
                              instructor.graduation_date.ToString("yyyy-MM-dd"),
                              instructor.subject,
                              instructor.bio.Replace("'", "\\'")
                              )
                );

            // Converting New ID to the instructor Int ID
            instructor.id = Convert.ToInt32(res[0]);
            return(instructor);
        }
Beispiel #3
0
        public Veh(string name, int ownerId)
        {
            Random r = new Random();

            _database          = new MySqlConnectionStringBuilder("server=localhost;user=root;database=gtanserver;port=3306;password=;");
            _vehicleRepository = _database.Connection().As <IVehicleRepository>();

            int        vin  = r.Next(100000, 1000000);
            List <Veh> temp = _vehicleRepository.GetVehicleByVin(vin);

            while (temp.Count > 0)
            {
                vin  = r.Next(100000, 1000000);
                temp = _vehicleRepository.GetVehicleByVin(vin);
            }

            // create a plate with 3 random numbers and 3 random letters and make sure it isnt already taken
            string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            string plate   = r.Next(0, 10).ToString() + r.Next(0, 10).ToString() + r.Next(0, 10).ToString() + " " + letters[r.Next(0, 26)].ToString() + letters[r.Next(0, 26)].ToString() + letters[r.Next(0, 26)].ToString();

            temp = _vehicleRepository.GetVehicleByPlate(plate);
            while (temp.Count > 0)
            {
                plate = r.Next(0, 10).ToString() + r.Next(0, 10).ToString() + r.Next(0, 10).ToString() + " " + letters[r.Next(0, 26)].ToString() + letters[r.Next(0, 26)].ToString() + letters[r.Next(0, 26)].ToString();
                temp  = _vehicleRepository.GetVehicleByPlate(plate);
            }

            this.Plate     = plate;
            this.Vin       = vin;
            this.Inventory = "{}";
            this.Name      = name;
            this.OwnerId   = ownerId;
            this.Handle    = 0;
        }
Beispiel #4
0
        public bool playerHasAccessToVehicle(int charId, string plate)
        {
            _database          = new MySqlConnectionStringBuilder("server=localhost;user=root;database=gtanserver;port=3306;password=;");
            _vehicleRepository = _database.Connection().As <IVehicleRepository>();

            List <Veh> vehs = _vehicleRepository.GetVehicleByPlate(plate);

            return(charId == vehs[0].OwnerId);
        }
Beispiel #5
0
        private void ResourceStart()
        {
            MySqlInsightDbProvider.RegisterProvider();

            _database = new MySqlConnectionStringBuilder(
                "server=localhost;user=root;database=newserver;port=3306;password=;"
                );

            _userRepository = _database.Connection().As <IUserRepository>();
        }
Beispiel #6
0
        private void myResourceStart()
        {
            API.consoleOutput("[------------------------------------------]");
            API.consoleOutput("[            Frosty Cops n Robbers         ]");
            API.consoleOutput("[                Version 0.0.1             ]");
            API.consoleOutput("[           Created by VirtualFrost        ]");
            API.consoleOutput("[------------------------------------------]");

            MySqlInsightDbProvider.RegisterProvider();
            _database       = new MySqlConnectionStringBuilder("server=localhost;user=root;database=frosty-cnr;port=3306;password=;");
            _userRepository = _database.Connection().As <IUserRepository>();
        }
Beispiel #7
0
        public User InsertUser(User user)
        {
            string student    = "null";
            string instructor = "null";

            if (user.student != null)
            {
                user.student = Global.studentRepo.InsertStudent(user.student);
                student      = user.student.id + ""; // Creating New Student and converting his ID to String
            }
            else if (user.instructor != null)
            {
                user.instructor = Global.instructorRepo.InsertInstructor(user.instructor);
                instructor      = user.instructor.id + ""; // Creating New Instructor and converting his ID to String
            }
            IList <UInt64> res = db.Connection().QuerySql <UInt64>(
                string.Format("INSERT INTO `user` (username, email, password, create_date, citizen_id, image_url, student_id, instructor_id) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', {6}, {7});SELECT LAST_INSERT_ID();",
                              user.username,
                              user.email,
                              user.getEncryptedPassword(),
                              user.create_date.ToString("yyyy-MM-dd"),
                              user.citizen_id,
                              user.image_url,
                              student,
                              instructor
                              )
                );

            // Converting New ID to the user Int ID
            user.id = Convert.ToInt32(res[0]);
            return(user);
        }
Beispiel #8
0
        public void API_onResourceStart()
        {
            MySqlInsightDbProvider.RegisterProvider();
            _database       = new MySqlConnectionStringBuilder("server=localhost;user=root;database=gamemode;port=3306;password=;");
            _userRepository = _database.Connection().As <IUserRepository>();
            ContextFactory.SetConnectionParameters("127.0.0.1", "root", "", "gamemode");
            var uniqueUsers = ContextFactory.Instance.Users.Count();

            API.consoleOutput("Unique Accounts: " + uniqueUsers);
            var uniqueChars = ContextFactory.Instance.Characters.Count();

            API.consoleOutput("Character Count: " + uniqueChars);
        }
Beispiel #9
0
        public void OnResourceStart()
        {
            // set up database connection
            MySqlInsightDbProvider.RegisterProvider();
            _database           = new MySqlConnectionStringBuilder("server=localhost;user=root;database=gtanserver;port=3306;password="******"GAS_STATION");

            // get delivery locations, convert to Vector3's, and create col shapes
            // also save id in colshape entity data
            foreach (var station in gasStations)
            {
                dynamic d     = API.fromJson(station.DeliverLocation);
                Vector3 pos   = new Vector3((float)d.X, (float)d.Y, (float)(d.Z - 1));
                var     shape = API.createCylinderColShape(pos, 4, 8);
                shape.setData("ID", station.Id);

                // add shapes to list
                deliveryColShapes.Add(shape);
            }

            // initailize list of tanker models
            tankerModels.Add(-730904777);
            tankerModels.Add(1956216962);
            tankerModels.Add(-1207431159);

            // synchronize list of contracts
            contracts = ArrayList.Synchronized(contractsAsync);

            // set up start job start blip, shape, etc...
            var jobStartPos     = new Vector3(1383.331, -2079.071, 51.99853 + 1);
            var jobStartTextPos = new Vector3(1383.331, -2079.071, 51.99853 + 1.5);

            jobStartShape = API.createSphereColShape(jobStartPos, 3f);

            var jobStartMarker    = API.createMarker(20, jobStartPos, new Vector3(), new Vector3(180, 0, -25), new Vector3(1, 1, 1), 150, 0, 0, 255, 0);
            var jobStartTextLabel = API.createTextLabel("~b~ Trucking Job: Gas", jobStartTextPos, 100f, 0.3f, true);

            var jobStartBlip = API.createBlip(jobStartMarker);

            API.setBlipSprite(jobStartBlip, 477);
            API.setBlipColor(jobStartBlip, 26);
            API.setBlipName(jobStartBlip, "Trucking Job: Gas");

            // create job return shape
            jobEndPos   = new Vector3(1361, -2066, 52);
            jobEndShape = API.createSphereColShape(jobEndPos, 4f);
        }
Beispiel #10
0
        public Student InsertStudent(Student student)
        {
            IList <UInt64> res = db.Connection().QuerySql <UInt64>(
                string.Format("INSERT INTO `student` (name, gpa, status, level) VALUES ('{0}', {1}, '{2}', {3});SELECT LAST_INSERT_ID();",
                              student.name,
                              student.gpa,
                              student.status,
                              student.level
                              )
                );

            // Converting New ID to the student Int ID
            student.id = Convert.ToInt32(res[0]);
            return(student);
        }
Beispiel #11
0
        public Vehicle createVehicleHelper(VehicleHash model, Vector3 pos, Vector3 rot, int ownerId = 0)
        {
            Random  r       = new Random();
            int     color   = r.Next(0, 160);
            Vehicle vehicle = API.createVehicle(model, pos, rot, color, color);
            Veh     veh     = new Veh(API.getVehicleDisplayName(model), ownerId);

            veh.Handle = vehicle.handle.Value;

            // trigger client event to stream number plate info
            API.setVehicleNumberPlate(vehicle, veh.Plate);
            API.setVehicleEngineStatus(vehicle, false);
            API.sendNativeToAllPlayers(Hash.SET_VEHICLE_DOORS_LOCKED, API.getEntityFromHandle <Vehicle>(vehicle), 2);
            API.setEntityData(vehicle, "JSON_DATA", API.toJson(veh));
            API.setEntitySyncedData(vehicle, "PLATE", veh.Plate);

            _database          = new MySqlConnectionStringBuilder("server=localhost;user=root;database=gtanserver;port=3306;password=;");
            _vehicleRepository = _database.Connection().As <IVehicleRepository>();
            _vehicleRepository.AddNewVehicle(veh);



            return(vehicle);
        }
Beispiel #12
0
 private void API_onResourceStart()
 {
     MySqlInsightDbProvider.RegisterProvider();
     _database       = new MySqlConnectionStringBuilder("server=x;user=x;database=x;password=x");
     _userRepository = _database.Connection().As <IUserRepository>();
 }
Beispiel #13
0
 public void OnResourceStart()
 {
     MySqlInsightDbProvider.RegisterProvider();
     _database          = new MySqlConnectionStringBuilder("server=localhost;user=root;database=gtanserver;port=3306;password=;");
     _vehicleRepository = _database.Connection().As <IVehicleRepository>();
 }
Beispiel #14
0
 private void ResourceStop()
 {
     _database.Connection().Close();
 }
Beispiel #15
0
        private void API_onClientEventTrigger(Client player, string eventName, params object[] args)
        {
            if (eventName == "log_in")
            {
                string username = args[0].ToString();
                string password = args[1].ToString();

                UserAccount account = _userRepository.GetAccount(username);
                if (account == null)
                {
                    API.triggerClientEvent(player, "invalid_username_or_password");
                    return;
                }

                bool isPasswordCorrect = BCr.BCrypt.Verify(password, account.Hash);
                if (isPasswordCorrect)
                {
                    // get users characters
                    _characterRepository = _database.Connection().As <ICharacterRepository>();
                    charList             = _characterRepository.GetAllCharactersWithOwnerId(account.Id);

                    // move player to char select location
                    API.setEntityPositionFrozen(player, false);
                    API.setEntityCollisionless(player, false);
                    API.setEntityTransparency(player, 255);
                    API.setEntityRotation(player, new Vector3(0, 0, -15));
                    API.setEntityPosition(player, new Vector3(-235.4913, -2002.9574, 24.6));
                    API.triggerClientEvent(player, "login_successful", API.toJson(charList));
                }
                else
                {
                    API.triggerClientEvent(player, "invalid_username_or_password");
                }
            }

            else if (eventName == "register")
            {
                string username = args[0].ToString();
                string password = args[1].ToString();

                // check to see if username already exists
                UserAccount account = _userRepository.GetAccount(username);
                if (account != null)
                {
                    API.triggerClientEvent(player, "register_username_taken");
                }
                else
                {
                    var hash = BCr.BCrypt.HashPassword(password, BCr.BCrypt.GenerateSalt(12));

                    account = new UserAccount
                    {
                        Username = username,
                        Hash     = hash
                    };

                    _userRepository.RegisterAccount(account);
                    API.triggerClientEvent(player, "registration_successful");
                }
            }

            else if (eventName == "choose_existing_character")
            {
                dynamic c = charList[(int)args[0]];
                API.setEntityData(player.handle, "CHAR_ID", c.Id);
                API.setEntitySyncedData(player.handle, "LOGGED_IN", true);
                API.setEntityPosition(player, new Vector3(-45.70197, -1680.367, 29.4101));
                API.sendChatMessageToPlayer(player, "Logged in as " + c.Name + " with ID: " + c.Id.ToString());
            }
        }