Esempio n. 1
0
    private void SaveData(int model, Vector3 offset, Vector3 size)
    {
        if (_trunks == null)
        {
            _trunks = API.loadConfig("trunks.xml");
        }

        var       bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
        FieldInfo field     = typeof(XmlGroup).GetField("_mapDocument", bindFlags);
        dynamic   doc       = field.GetValue(_trunks);

        var n = doc.CreateNode(XmlNodeType.Element, "TrunkInfo", null);

        {
            var attr = doc.CreateAttribute("model");
            attr.Value = model.ToString();
            n.Attributes.Append(attr);
        }

        {
            var attr = doc.CreateAttribute("offsetX");
            attr.Value = offset.X.ToString("F6", CultureInfo.InvariantCulture);
            n.Attributes.Append(attr);
        }

        {
            var attr = doc.CreateAttribute("offsetY");
            attr.Value = offset.Y.ToString("F6", CultureInfo.InvariantCulture);
            n.Attributes.Append(attr);
        }

        {
            var attr = doc.CreateAttribute("offsetZ");
            attr.Value = offset.Z.ToString("F6", CultureInfo.InvariantCulture);
            n.Attributes.Append(attr);
        }

        {
            var attr = doc.CreateAttribute("sizeX");
            attr.Value = size.X.ToString("F6", CultureInfo.InvariantCulture);
            n.Attributes.Append(attr);
        }

        {
            var attr = doc.CreateAttribute("sizeY");
            attr.Value = size.Y.ToString("F6", CultureInfo.InvariantCulture);
            n.Attributes.Append(attr);
        }

        {
            var attr = doc.CreateAttribute("sizeZ");
            attr.Value = size.Z.ToString("F6", CultureInfo.InvariantCulture);
            n.Attributes.Append(attr);
        }

        doc.FirstChild.AppendChild(n);

        doc.Save(API.getResourceFolder() + Path.DirectorySeparatorChar + "trunks.xml");
    }
Esempio n. 2
0
        public bool LoadServers(string file)
        {
            XmlDocument XmlDoc = new XmlDocument();

            try
            {
                XmlDoc.Load(System.IO.Path.GetFullPath(file));
            }
            catch
            {
                return(false);
            }

            if (XmlDoc.DocumentElement == null)
            {
                return(false);
            }

            if (XmlDoc.DocumentElement.Name == "servergroups")
            {
                foreach (XmlNode XmlGroup in XmlDoc.SelectNodes("servergroups/servergroup"))
                {
                    ServerGroup servergroup = AddServerGroup();

                    foreach (XmlNode XmlServer in XmlGroup.SelectNodes("servers/server"))
                    {
                        string Address       = XmlServer.SelectSingleNode("address").InnerText;
                        int    Port          = int.Parse(XmlServer.SelectSingleNode("port").InnerText);
                        int    Connections   = int.Parse(XmlServer.SelectSingleNode("connections").InnerText);
                        bool   RequiresLogin = XmlServer.SelectSingleNode("login").HasChildNodes;
                        string Username      = "";
                        string Password      = "";
                        if (RequiresLogin)
                        {
                            Username = XmlServer.SelectSingleNode("login/username").InnerText;
                            Password = XmlServer.SelectSingleNode("login/password").InnerText;
                        }

                        bool NeedsGroup = true;
                        if (XmlServer.SelectSingleNode("needsgroup") != null)
                        {
                            NeedsGroup = (XmlServer.SelectSingleNode("needsgroup").InnerText.ToLower() == "true");
                        }

                        Server server = servergroup.AddServer(new Server(Address, Port, Connections, RequiresLogin, Username, Password, NeedsGroup));
                        if (XmlServer.Attributes.GetNamedItem("enabled") != null)
                        {
                            if (!bool.Parse(XmlServer.Attributes.GetNamedItem("enabled").InnerText))
                            {
                                DisableServer(server);
                            }
                        }
                    }
                }
            }
            return(true);
        }
Esempio n. 3
0
    public void MapChange(string mapName, XmlGroup map)
    {
        EndRace();

        API.consoleOutput("Parsing map...");
        var race = new Race(parseRace(mapName, map));

        API.consoleOutput("Map parse done! Race null? " + (race == null));

        CurrentRace = race;

        Opponents.ForEach(op =>
        {
            op.HasFinished       = false;
            op.CheckpointsPassed = 0;
            op.TimeFinished      = "";
            if (!op.Vehicle.IsNull)
            {
                API.deleteEntity(op.Vehicle);
            }

            API.freezePlayer(op.Client, true);
        });

        if (Objects != null)
        {
            foreach (var ent in Objects)
            {
                API.deleteEntity(ent);
            }

            Objects.Clear();
        }
        else
        {
            Objects = new List <NetHandle>();
        }

        var clients = API.getAllPlayers();

        for (int i = 0; i < clients.Count; i++)
        {
            API.freezePlayer(clients[i], false);

            SetUpPlayerForRace(clients[i], CurrentRace, true, i);
        }

        CurrentRaceCheckpoints = race.Checkpoints.ToList();
        RaceStart = DateTime.UtcNow;

        API.consoleOutput("RACE: Starting race " + race.Name);

        RaceStartCountdown = 13;
    }
Esempio n. 4
0
    private Race parseRace(string mapName, XmlGroup map)
    {
        var output = new Race();

        output.Name        = API.getResourceName(mapName);
        output.Description = API.getResourceDescription(mapName);
        output.Filename    = mapName;

        var meta = map.getElementByType("laps");

        if (meta != null)
        {
            output.LapsAvailable = meta.getElementData <bool>("value");
        }

        var checkpoints = new List <Vector3>();

        foreach (var chk in map.getElementsByType("checkpoint"))
        {
            checkpoints.Add(
                new Vector3(chk.getElementData <float>("posX"),
                            chk.getElementData <float>("posY"),
                            chk.getElementData <float>("posZ")));
        }

        output.Checkpoints = checkpoints.ToArray();

        var sp = new List <SpawnPoint>();

        foreach (var chk in map.getElementsByType("spawnpoint"))
        {
            sp.Add(new SpawnPoint()
            {
                Position = new Vector3(chk.getElementData <float>("posX"),
                                       chk.getElementData <float>("posY"),
                                       chk.getElementData <float>("posZ")),
                Heading = chk.getElementData <float>("heading"),
            });
        }

        output.SpawnPoints = sp.ToArray();

        var vehs = new List <VehicleHash>();

        foreach (var chk in map.getElementsByType("availablecar"))
        {
            vehs.Add((VehicleHash)chk.getElementData <int>("model"));
        }

        output.AvailableVehicles = vehs.ToArray();

        return(output);
    }
Esempio n. 5
0
        public void onResourceStart()
        {
            databaseConfiguration = API.loadConfig("database.xml");

            string host     = null;
            string port     = null;
            string user     = null;
            string password = null;
            string database = null;

            foreach (xmlElement element in databaseConfiguration.getElementsByType("setting"))
            {
                string settingName    = element.getElementData <string>("name");
                string settingContent = element.getElementData <string>("content");

                if (settingName.ToLower().Equals("host"))
                {
                    host = settingContent;
                }
                else if (settingName.ToLower().Equals("port"))
                {
                    port = settingContent;
                }
                else if (settingName.ToLower().Equals("user"))
                {
                    user = settingContent;
                }
                else if (settingName.ToLower().Equals("password"))
                {
                    password = settingContent;
                }
                else if (settingName.ToLower().Equals("database"))
                {
                    database = settingContent;
                }
            }

            if (port == null)
            {
                connection = new MysqlConnection(host, user, password, database);
            }
            else
            {
                connection = new MysqlConnection(host, port, user, password, database);
            }
        }
Esempio n. 6
0
    private void onMapChange(string mapName, XmlGroup map)
    {
        spawns.Clear();
        weapons.Clear();
        Killstreaks.Clear();
        var spawnpoints = map.getElementsByType("spawnpoint");

        foreach (var point in spawnpoints)
        {
            spawns.Add(new Vector3(point.getElementData <float>("posX"),
                                   point.getElementData <float>("posY"),
                                   point.getElementData <float>("posZ")));
        }

        var availableGuns = map.getElementsByType("weapon");

        foreach (var point in availableGuns)
        {
            weapons.Add(API.weaponNameToModel(point.getElementData <string>("model")));
        }

        API.resetIplList();

        var neededInteriors = map.getElementsByType("ipl");

        foreach (var point in neededInteriors)
        {
            API.requestIpl(point.getElementData <string>("name"));
        }

        var players = API.getAllPlayers();

        foreach (var player in players)
        {
            var pBlip = API.exported.playerblips.getPlayerBlip(player);

            API.setBlipSprite(pBlip, 1);
            API.setBlipColor(pBlip, 0);
            Respawn(player);
        }
    }
Esempio n. 7
0
    public void OnMapChange(string mapName, XmlGroup map)
    {
        Console.WriteLine("OnMapChange");
        Spawns.Clear();
        Weapons.Clear();
        Killstreaks.Clear();
        var spawnpoints = map.getElementsByType("spawnpoint");

        foreach (var point in spawnpoints)
        {
            Spawns.Add(new Vector3(point.getElementData <float>("posX"), point.getElementData <float>("posY"), point.getElementData <float>("posZ")));
        }

        var availableGuns = map.getElementsByType("weapon");

        foreach (var point in availableGuns)
        {
            Weapons.Add(NAPI.Util.WeaponNameToModel(point.getElementData <string>("model")));
        }

        NAPI.World.ResetIplList();

        var neededInteriors = map.getElementsByType("ipl");

        foreach (var point in neededInteriors)
        {
            NAPI.World.RequestIpl(point.getElementData <string>("name"));
        }

        foreach (var player in NAPI.Pools.GetAllPlayers())
        {
            var pBlip = NAPI.Exported.playerblips.getPlayerBlip(player);
            NAPI.Blip.SetBlipSprite(pBlip, 1);
            NAPI.Blip.SetBlipColor(pBlip, 0);

            Spawn(player);
        }
    }
Esempio n. 8
0
    public void MapChange(string name, XmlGroup map)
    {
        EndRound();

        var round = new Round();

        #region Objectives
        foreach (var element in map.getElementsByType("objective"))
        {
            var obj = new Objective();

            if (element.hasElementData("id"))
            {
                obj.Id = element.getElementData <int>("id");
            }

            obj.Position = new Vector3(element.getElementData <float>("posX"),
                                       element.getElementData <float>("posY"),
                                       element.getElementData <float>("posZ"));

            if (element.hasElementData("range"))
            {
                obj.Range = element.getElementData <float>("range");
            }

            obj.name = element.getElementData <string>("name");

            if (element.hasElementData("timer"))
            {
                obj.Timer = element.getElementData <int>("timer");
            }

            if (element.hasElementData("required"))
            {
                var listStr = element.getElementData <string>("required");
                obj.RequiredObjectives =
                    listStr.Split(',').Select(id => int.Parse(id, CultureInfo.InvariantCulture)).ToList();
            }

            round.Objectives.Add(obj);
        }
        #endregion

        #region Spawnpoints

        foreach (var element in map.getElementsByType("spawnpoint"))
        {
            var sp = new Spawnpoint();

            sp.Team    = element.getElementData <int>("team");
            sp.Heading = element.getElementData <float>("heading");

            sp.Position = new Vector3(element.getElementData <float>("posX"),
                                      element.getElementData <float>("posY"),
                                      element.getElementData <float>("posZ"));

            sp.Skins =
                element.getElementData <string>("skins")
                .Split(',')
                .Select(s => API.pedNameToModel(s))
                .ToArray();

            var guns =
                element.getElementData <string>("weapons")
                .Split(',')
                .Select(w => API.weaponNameToModel(w));
            var ammos =
                element.getElementData <string>("ammo")
                .Split(',')
                .Select(w => int.Parse(w, CultureInfo.InvariantCulture));

            sp.Weapons = guns.ToArray();
            sp.Ammo    = ammos.ToArray();

            if (element.hasElementData("objectives"))
            {
                var objectives =
                    element.getElementData <string>("objectives")
                    .Split(',')
                    .Select(w => int.Parse(w, CultureInfo.InvariantCulture));

                sp.RequiredObjectives = objectives.ToArray();
            }

            round.Spawnpoints.Add(sp);
        }
        #endregion

        StartRound(round);
    }
Esempio n. 9
0
 private void MapChange_Event(string mapName, XmlGroup map)
 {
     OnMapChange?.Invoke(mapName, map);
 }