Beispiel #1
0
        public void Reorganize()
        {
            var count  = 0;
            var items2 = items;

            items = new Dictionary <int, LoadOutItem>(30);
            foreach (LoadOutItem item in items2.Values)
            {
                if (item != null)
                {
                    items.Add(count, item);
                    count++;
                }
            }
            count++;
            if (count != itemCount)
            {
                Logger.LogDebug("[LoadOut] An error accoured while reorganizing the items?");
                itemCount = count;
            }
            if (Server.GetServer().LoadOuts.ContainsKey(Name))
            {
                Server.GetServer().LoadOuts.Remove(Name);
            }
            Server.GetServer().LoadOuts.Add(Name, this);
        }
Beispiel #2
0
 public static void Advertise()
 {
     foreach (string arg in Config.PlutonConfig.EnumSection("BroadcastMessages"))
     {
         Server.GetServer().Broadcast(Config.GetValue("BroadcastMessages", arg));
     }
 }
Beispiel #3
0
        public static void kick(ConsoleSystem.Arg arg)
        {
            Player player = Player.Find(arg.ArgsStr);

            if (player != null)
            {
                string nameFrom;
                if (arg.connection != null && arg.connection.username != null)
                {
                    nameFrom = arg.connection.username;
                }
                else
                {
                    nameFrom = "RCON";
                }

                player.Kick("Kicked by: " + nameFrom);
                Server.GetServer().Broadcast(arg.ArgsStr + " is kicked from the server by " + nameFrom + "!");
                arg.ReplyWith(arg.ArgsStr + " is kicked!");
            }
            else
            {
                arg.ReplyWith("Couldn't find player: " + arg.ArgsStr);
            }
        }
Beispiel #4
0
        public static OfflinePlayer Get(ulong steamID)
        {
            OfflinePlayer op = Server.GetServer().OfflinePlayers[steamID];

            if (op == null)
            {
                Logger.LogDebug("[OfflinePlayer] Couldn't find OfflinePlayer: " + steamID.ToString());
                return(null);
            }
            return(op);
        }
Beispiel #5
0
        // chat.say().Hooks.Chat()
        public static void Command(ConsoleSystem.Arg arg)
        {
            Player player = new Player(arg.Player());

            string[] args = arg.ArgsStr.Substring(2, arg.ArgsStr.Length - 3).Replace("\\", "").Split(new string[] { " " }, StringSplitOptions.None);

            Command cmd = new Command(player, args);

            if (cmd.cmd == "")
            {
                return;
            }

            if (Config.GetBoolValue("Commands", "enabled"))
            {
                if (cmd.cmd == Config.GetValue("Commands", "ShowMyStats"))
                {
                    PlayerStats stats = player.Stats;
                    player.Message(String.Format("You have {0} kills and {1} deaths!", stats.Kills, stats.Deaths));
                    player.Message(String.Format("You have taken {0} dmg, and caused {1} in total!", stats.TotalDamageTaken, stats.TotalDamageDone));
                    return;
                }
                if (cmd.cmd == Config.GetValue("Commands", "ShowStatsOther"))
                {
                    Player pOther = Player.Find(String.Join(" ", cmd.args));
                    if (pOther != null)
                    {
                        PlayerStats stats2 = pOther.Stats;
                        player.Message(String.Format("You have {0} kills and {1} deaths!", stats2.Kills, stats2.Deaths));
                        player.Message(String.Format("You have taken {0} dmg, and caused {1} in total!", stats2.TotalDamageTaken, stats2.TotalDamageDone));
                        return;
                    }
                    player.Message("Can't find player: " + String.Join(" ", cmd.args));
                    return;
                }
                if (cmd.cmd == Config.GetValue("Commands", "ShowLocation"))
                {
                    player.Message(player.Location.ToString());
                    return;
                }
                if (cmd.cmd == Config.GetValue("Commands", "ShowOnlinePlayers"))
                {
                    string msg = Server.GetServer().Players.Count == 1 ? "You are alone!" : String.Format("There are: {0} players online!", Server.GetServer().Players.Count);
                    player.Message(msg);
                    return;
                }
            }
            OnCommand.OnNext(cmd);

            if (cmd.ReplyWith != "")
            {
                arg.ReplyWith(cmd.ReplyWith);
            }
        }
Beispiel #6
0
 public static void SaveAll(object x = null)
 {
     try {
         Server.GetServer().Save();
         DataStore.GetInstance().Save();
         Logger.LogDebug("[Bootstrap] Server saved successfully!");
     } catch (Exception ex) {
         Logger.LogDebug("[Bootstrap] Failed to save the server!");
         Logger.LogException(ex);
     }
 }
Beispiel #7
0
        public LoadOut(string name)
        {
            path = Path.Combine(Util.GetLoadoutFolder(), name + ".ini");
            bool nu = false;

            if (!File.Exists(path))
            {
                File.AppendAllText(path, "");
                nu = true;
            }
            var ini = new IniParser(path);

            Name = ini.Name;
            if (!nu)
            {
                itemCount    = Int32.Parse(ini.GetSetting("Def", "itemCount"));
                OwnerUse     = ini.GetBoolSetting("Def", "ownerCanUse");
                ModeratorUse = ini.GetBoolSetting("Def", "modCanUse");
                NormalUse    = ini.GetBoolSetting("Def", "normalCanUse");
            }
            else
            {
                itemCount    = 0;
                OwnerUse     = true;
                NormalUse    = true;
                ModeratorUse = true;
            }
            items = new Dictionary <int, LoadOutItem>(30);

            if (itemCount != 0)
            {
                LoadOutItem current;
                for (var i = 0; i < itemCount; i++)
                {
                    string namee  = ini.GetSetting(i.ToString(), "Name");
                    int    amount = Int32.Parse(ini.GetSetting(i.ToString(), "Amount"));
                    current = new LoadOutItem(namee, amount);
                    items.Add(i, current);
                }
            }
            ini = null;
            if (Server.GetServer().LoadOuts.ContainsKey(Name))
            {
                Server.GetServer().LoadOuts.Remove(Name);
            }
            Server.GetServer().LoadOuts.Add(Name, this);
        }
Beispiel #8
0
        public bool Add(LoadOutItem item)
        {
            if (itemCount >= 30)
            {
                Logger.LogDebug("[LoadOut] You may not add more then 30 items to one loadout.");
                return(false);
            }
            items.Add(itemCount, item);
            itemCount++;

            if (Server.GetServer().LoadOuts.ContainsKey(Name))
            {
                Server.GetServer().LoadOuts.Remove(Name);
            }
            Server.GetServer().LoadOuts.Add(Name, this);
            return(true);
        }
Beispiel #9
0
        public static void Init()
        {
            if (!Directory.Exists(Util.GetPublicFolder()))
            {
                Directory.CreateDirectory(Util.GetPublicFolder());
            }

            Logger.Init();
            Server.GetServer();
            PluginLoader.GetInstance().Init();

            server.official = false;

            if (!server.hostname.ToLower().Contains("pluton"))
            {
                server.hostname = String.Format("{0} [Pluton v.{1}]", server.hostname, Version);
            }
        }
Beispiel #10
0
        // BasePlayer.OnAttacked()
        public static void PlayerHurt(BasePlayer player, HitInfo info)
        {
            // not tested
            var p = new Player(player);

            if (info == null)   // it should never accour, but just in case
            {
                info = new HitInfo();
                info.damageAmount = 0.0f;
                info.damageType   = player.metabolism.lastDamage;
                info.Initiator    = player as BaseEntity;
            }

            bool        fromPlayer = (info.Initiator is BasePlayer);
            PlayerStats statV      = p.Stats;

            statV.AddDamageFrom(info.damageAmount, fromPlayer, !fromPlayer, false);
            p.Stats = statV;

            if (fromPlayer)
            {
                string      sid   = info.Initiator.ToPlayer().userID.ToString();
                PlayerStats statA = new PlayerStats(sid);
                statA.AddDamageTo(info.damageAmount, true, false, false);
                Server.GetServer().serverData.Add("PlayerStats", sid, statA);
            }

            if (!player.TestAttack(info) || !Realm.Server() || (info.damageAmount <= 0.0f))
            {
                return;
            }
            player.metabolism.bleeding.Add(Mathf.InverseLerp(0.0f, 100f, info.damageAmount));
            player.metabolism.SubtractHealth(info.damageAmount);
            player.TakeDamageIndicator(info.damageAmount, player.transform.position - info.PointStart);
            player.CheckDeathCondition(info);

            if (!player.IsDead())
            {
                OnPlayerHurt.OnNext(new Events.PlayerHurtEvent(p, info));
            }

            player.SendEffect("takedamage_hit");
        }
Beispiel #11
0
        // BasePlayer.PlayerInit()
        public static void PlayerConnected(Network.Connection connection)
        {
            var player = connection.player as BasePlayer;
            var p      = new Player(player);

            if (Server.GetServer().OfflinePlayers.ContainsKey(player.userID))
            {
                Server.GetServer().OfflinePlayers.Remove(player.userID);
            }
            if (!Server.GetServer().Players.ContainsKey(player.userID))
            {
                Server.GetServer().Players.Add(player.userID, p);
            }

            OnPlayerConnected.OnNext(p);
            p.Message("Welcome " + p.Name + "!");
            p.Message(String.Format("This server is powered by Pluton[v{0}]!", Bootstrap.Version));
            p.Message("Visit fougerite.com for more information or to report bugs!");
        }
Beispiel #12
0
        public Plugin(string name, string code, DirectoryInfo path, PluginType type)
        {
            Name    = name;
            Code    = code;
            RootDir = path;
            Type    = type;
            Timers  = new Dictionary <string, TimedEvent>();

            if (type == PluginType.Python)
            {
                PyEngine = IronPython.Hosting.Python.CreateEngine();
                Scope    = PyEngine.CreateScope();
                Scope.SetVariable("Plugin", this);
                Scope.SetVariable("Server", Pluton.Server.GetServer());
                Scope.SetVariable("DataStore", DataStore.GetInstance());
                Scope.SetVariable("Util", Util.GetUtil());
                Scope.SetVariable("World", World.GetWorld());
                Scope.SetVariable("Commands", PluginCommands.GetInstance());
                PyEngine.Execute(code, Scope);
                Class   = PyEngine.Operations.Invoke(Scope.GetVariable(name));
                Globals = PyEngine.Operations.GetMemberNames(Class);
            }
            else
            {
                JSEngine = new Engine(cfg => cfg.AllowClr(typeof(UnityEngine.GameObject).Assembly,
                                                          typeof(PlayerInventory).Assembly))
                           .SetValue("Server", Server.GetServer())
                           .SetValue("DataStore", DataStore.GetInstance())
                           .SetValue("Util", Util.GetUtil())
                           .SetValue("World", World.GetWorld())
                           .SetValue("Plugin", this)
                           .SetValue("Commands", PluginCommands.GetInstance())
                           .Execute(code);
                JavaScriptParser parser = new JavaScriptParser();
                Globals = (from function in parser.Parse(Code).FunctionDeclarations
                           where (function.Id.Name.StartsWith("On_") || function.Id.Name.EndsWith("Callback"))
                           select function.Id.Name).ToList <string>();
            }
        }
Beispiel #13
0
 public PlayerStats(string steamid)
 {
     if (!Server.GetServer().serverData.ContainsKey("PlayerStats", steamid))
     {
         Kills             = 0;
         Deaths            = 0;
         PlayerKills       = 0;
         PlayerDeaths      = 0;
         NPCKills          = 0;
         NPCDeaths         = 0;
         TotalDamageTaken  = 0;
         TotalDamageDone   = 0;
         DamageToPlayers   = 0;
         DamageFromPlayers = 0;
         DamageToNPCs      = 0;
         DamageFromNPCs    = 0;
         DamageToEntities  = 0;
         FallDamage        = 0;
         Server.GetServer().serverData.Add("PlayerStats", steamid, this);
     }
     else
     {
         var stats = Server.GetServer().serverData.Get("PlayerStats", steamid) as PlayerStats;
         Kills             = stats.Kills;
         Deaths            = stats.Deaths;
         PlayerKills       = stats.PlayerKills;
         PlayerDeaths      = stats.PlayerDeaths;
         NPCKills          = stats.NPCKills;
         NPCDeaths         = stats.NPCDeaths;
         TotalDamageTaken  = stats.TotalDamageTaken;
         TotalDamageDone   = stats.TotalDamageDone;
         DamageToPlayers   = stats.DamageToPlayers;
         DamageFromPlayers = stats.DamageFromPlayers;
         DamageToNPCs      = stats.DamageToNPCs;
         DamageFromNPCs    = stats.DamageFromNPCs;
         DamageToEntities  = stats.DamageToEntities;
         FallDamage        = stats.FallDamage;
     }
 }
Beispiel #14
0
        // BasePlayer.OnDisconnected()
        public static void PlayerDisconnected(BasePlayer player)
        {
            // works
            var p = new Player(player);

            if (Server.GetServer().serverData.ContainsKey("OfflinePlayers", p.SteamID))
            {
                OfflinePlayer op = (Server.GetServer().serverData.Get("OfflinePlayers", p.SteamID) as OfflinePlayer);
                op.Update(p);
                Server.GetServer().OfflinePlayers[player.userID] = op;
            }
            else
            {
                OfflinePlayer op = new OfflinePlayer(p);
                Server.GetServer().OfflinePlayers.Add(player.userID, op);
            }

            if (Server.GetServer().Players.ContainsKey(player.userID))
            {
                Server.GetServer().Players.Remove(player.userID);
            }

            OnPlayerDisconnected.OnNext(p);
        }
Beispiel #15
0
        public void LoadPlugin(string name, Plugin.PluginType type)
        {
            Logger.LogDebug("[PluginLoader] Loading plugin " + name + ".");

            if (plugins.ContainsKey(name))
            {
                Logger.LogError("[PluginLoader] " + name + " plugin is already loaded.");
                throw new InvalidOperationException("[PluginLoader] " + name + " plugin is already loaded.");
            }

            try {
                string        code   = GetPluginScriptText(name, type);
                DirectoryInfo path   = new DirectoryInfo(Path.Combine(pluginDirectory.FullName, name));
                Plugin        plugin = new Plugin(name, code, path, type);

                InstallHooks(plugin);
                plugins.Add(name, plugin);

                Logger.Log("[PluginLoader] " + name + " plugin was loaded successfuly.");
            } catch (Exception ex) {
                Server.GetServer().Broadcast(name + " plugin could not be loaded.");
                Logger.LogException(ex);
            }
        }