public static bool AdminCheck(ClientInfo _cInfo, PlatformUserIdentifierAbs _platformId, PlatformUserIdentifierAbs _crossplatformId)
 {
     if (GameManager.Instance.adminTools.GetUserPermissionLevel(_platformId) <= Admin_Level ||
         GameManager.Instance.adminTools.GetUserPermissionLevel(_crossplatformId) <= Admin_Level)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 2
0
        public static PlayerDataFile GetPlayerDataFileFromUId(PlatformUserIdentifierAbs _uId)
        {
            PlayerDataFile playerDatafile = new PlayerDataFile();

            playerDatafile.Load(GameIO.GetPlayerDataDir(), _uId.CombinedString.Trim());
            if (playerDatafile != null)
            {
                return(playerDatafile);
            }
            return(null);
        }
Esempio n. 3
0
 public static bool GameManager_ChangeBlocks_Prefix(GameManager __instance, PlatformUserIdentifierAbs persistentPlayerId, List <BlockChangeInfo> _blocksToChange)
 {
     try
     {
         return(BlockChange.ProcessBlockChange(__instance, persistentPlayerId, _blocksToChange));
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in Injections.GameManager_ChangeBlocks_Prefix: {0}", e.Message));
     }
     return(true);
 }
Esempio n. 4
0
        public static EnumLandClaimOwner ClaimedByWho(PlatformUserIdentifierAbs _uId, Vector3i _position)
        {
            PersistentPlayerList persistentPlayerList = GetPersistentPlayerList();

            if (persistentPlayerList != null)
            {
                PersistentPlayerData persistentPlayerData = persistentPlayerList.GetPlayerData(_uId);
                if (persistentPlayerData != null)
                {
                    return(GameManager.Instance.World.GetLandClaimOwner(_position, persistentPlayerData));
                }
            }
            return(EnumLandClaimOwner.None);
        }
Esempio n. 5
0
        public static PersistentPlayerData GetPersistentPlayerDataFromUId(PlatformUserIdentifierAbs _uId)
        {
            PersistentPlayerList persistentPlayerList = GetPersistentPlayerList();

            if (persistentPlayerList != null)
            {
                PersistentPlayerData ppd = persistentPlayerList.GetPlayerData(_uId);
                if (ppd != null)
                {
                    return(ppd);
                }
            }
            return(null);
        }
Esempio n. 6
0
        public static void RemovePersistentPlayerData(string _id)
        {
            PersistentPlayerList persistentPlayerList = GetPersistentPlayerList();

            if (persistentPlayerList != null)
            {
                PlatformUserIdentifierAbs uId = GetPlatformUserFromNameOrId(_id);
                if (uId != null)
                {
                    if (persistentPlayerList.Players.ContainsKey(uId))
                    {
                        persistentPlayerList.Players.Remove(uId);
                        SavePersistentPlayerDataXML();
                    }
                }
            }
        }
Esempio n. 7
0
        public static PersistentPlayerData GetPersistentPlayerDataFromId(string _id)
        {
            PlatformUserIdentifierAbs uId = GetPlatformUserFromNameOrId(_id);

            if (uId != null)
            {
                PersistentPlayerList persistentPlayerList = GetPersistentPlayerList();
                if (persistentPlayerList != null)
                {
                    PersistentPlayerData ppd = persistentPlayerList.GetPlayerData(uId);
                    if (ppd != null)
                    {
                        return(ppd);
                    }
                }
            }
            return(null);
        }
 public static bool ReservedCheck(PlatformUserIdentifierAbs _platformId, PlatformUserIdentifierAbs _crossplatformId)
 {
     if (Dict.ContainsKey(_platformId.CombinedString))
     {
         Dict.TryGetValue(_platformId.CombinedString, out DateTime dt);
         if (DateTime.Now < dt)
         {
             return(true);
         }
     }
     if (Dict.ContainsKey(_crossplatformId.CombinedString))
     {
         Dict.TryGetValue(_crossplatformId.CombinedString, out DateTime dt);
         if (DateTime.Now < dt)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 9
0
 public static bool ClientInfoCollection_GetForNameOrId_Prefix(ref ClientInfo __result, string _nameOrId)
 {
     try
     {
         ClientInfo clientInfo = null;
         int        entityId;
         if (int.TryParse(_nameOrId, out entityId))
         {
             clientInfo = PersistentOperations.GetClientInfoFromEntityId(entityId);
             if (clientInfo != null)
             {
                 __result = clientInfo;
                 return(false);
             }
         }
         clientInfo = PersistentOperations.GetClientInfoFromName(_nameOrId);
         if (clientInfo != null)
         {
             __result = clientInfo;
             return(false);
         }
         if (_nameOrId.Contains("Local_") || _nameOrId.Contains("EOS_") || _nameOrId.Contains("Steam_") || _nameOrId.Contains("XBL_") || _nameOrId.Contains("PSN_") || _nameOrId.Contains("EGS_"))
         {
             PlatformUserIdentifierAbs userIdentifier;
             if (PlatformUserIdentifierAbs.TryFromCombinedString(_nameOrId, out userIdentifier))
             {
                 clientInfo = PersistentOperations.GetClientInfoFromUId(userIdentifier);
                 if (clientInfo != null)
                 {
                     __result = clientInfo;
                     return(false);
                 }
             }
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in Injections.ClientInfoCollection_GetForNameOrId_Prefix: {0}", e.Message));
     }
     return(false);
 }
Esempio n. 10
0
 public static void ReservedStatus(ClientInfo _cInfo, PlatformUserIdentifierAbs _platformId, PlatformUserIdentifierAbs _crossplatformId)
 {
     if (Dict.ContainsKey(_platformId.CombinedString))
     {
         Dict.TryGetValue(_platformId.CombinedString, out DateTime dt);
         if (DateTime.Now < dt)
         {
             Phrases.Dict.TryGetValue("Reserved4", out string phrase);
             phrase = phrase.Replace("{DateTime}", dt.ToString());
             ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + phrase + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
         }
         else
         {
             Phrases.Dict.TryGetValue("Reserved5", out string phrase);
             phrase = phrase.Replace("{DateTime}", dt.ToString());
             ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + phrase + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
         }
         return;
     }
     if (Dict.ContainsKey(_crossplatformId.CombinedString))
     {
         Dict.TryGetValue(_crossplatformId.CombinedString, out DateTime dt);
         if (DateTime.Now < dt)
         {
             Phrases.Dict.TryGetValue("Reserved4", out string phrase);
             phrase = phrase.Replace("{DateTime}", dt.ToString());
             ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + phrase + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
         }
         else
         {
             Phrases.Dict.TryGetValue("Reserved5", out string phrase);
             phrase = phrase.Replace("{DateTime}", dt.ToString());
             ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + phrase + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
         }
         return;
     }
     Phrases.Dict.TryGetValue("Reserved6", out string phrase1);
     ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + phrase1 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
 }
Esempio n. 11
0
        public static bool FullServer(ClientInfo _cInfo, PlatformUserIdentifierAbs _platformId, PlatformUserIdentifierAbs _crossplatformId)
        {
            try
            {
                List <ClientInfo> reserved   = new List <ClientInfo>();
                List <ClientInfo> normal     = new List <ClientInfo>();
                List <ClientInfo> clientList = PersistentOperations.ClientList();
                if (clientList != null)
                {
                    if (AdminCheck(_cInfo, _platformId, _crossplatformId))//admin is joining
                    {
                        for (int i = 0; i < clientList.Count; i++)
                        {
                            ClientInfo cInfo2 = clientList[i];
                            if (cInfo2 != null && cInfo2.PlatformId != null && cInfo2.CrossplatformId != null && cInfo2.entityId != _cInfo.entityId)
                            {
                                if (!AdminCheck(cInfo2, cInfo2.PlatformId, cInfo2.CrossplatformId)) //not admin
                                {
                                    if (ReservedCheck(cInfo2.PlatformId, cInfo2.CrossplatformId))   //reserved player
                                    {
                                        reserved.Add(cInfo2);
                                    }
                                    else
                                    {
                                        normal.Add(cInfo2);
                                    }
                                }
                            }
                        }
                    }
                    else if (ReservedCheck(_platformId, _crossplatformId))//reserved player is joining
                    {
                        for (int i = 0; i < clientList.Count; i++)
                        {
                            ClientInfo cInfo2 = clientList[i];
                            if (cInfo2 != null && cInfo2.PlatformId != null && cInfo2.CrossplatformId != null && cInfo2.entityId != _cInfo.entityId)
                            {
                                if (!AdminCheck(cInfo2, cInfo2.PlatformId, cInfo2.CrossplatformId) && !ReservedCheck(cInfo2.PlatformId, cInfo2.CrossplatformId))
                                {
                                    normal.Add(cInfo2);
                                }
                            }
                        }
                    }
                    if (normal.Count > 0)
                    {
                        if (normal.Count > 1)
                        {
                            normal.RandomizeList();
                        }
                        Phrases.Dict.TryGetValue("Reserved1", out string phrase);
                        phrase = phrase.Replace("{ServerResponseName}", Config.Server_Response_Name);
                        SingletonMonoBehaviour <SdtdConsole> .Instance.ExecuteSync(string.Format("kick {0} \"{1}\"", normal[0].CrossplatformId.CombinedString, phrase), null);

                        return(true);
                    }
                    else if (reserved.Count > 0)
                    {
                        if (reserved.Count > 1)
                        {
                            reserved.RandomizeList();
                        }
                        Phrases.Dict.TryGetValue("Reserved1", out string phrase);
                        phrase = phrase.Replace("{ServerResponseName}", Config.Server_Response_Name);
                        SingletonMonoBehaviour <SdtdConsole> .Instance.ExecuteSync(string.Format("kick {0} \"{1}\"", reserved[0].CrossplatformId.CombinedString, phrase), null);

                        return(true);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Out(string.Format("[SERVERTOOLS] Error in ReservedSlots.FullServer: {0}", e.Message));
            }
            return(false);
        }
Esempio n. 12
0
 public static ClientInfo GetClientInfoFromUId(PlatformUserIdentifierAbs _uId)
 {
     return(SingletonMonoBehaviour <ConnectionManager> .Instance.Clients.ForUserId(_uId));
 }
Esempio n. 13
0
 public static bool ProcessBlockChange(GameManager __instance, PlatformUserIdentifierAbs _persistentPlayerId, List <BlockChangeInfo> _blocksToChange)
 {
     try
     {
         if (__instance != null && _persistentPlayerId != null && _blocksToChange != null)
         {
             ClientInfo cInfo = PersistentOperations.GetClientInfoFromUId(_persistentPlayerId);
             if (cInfo != null)
             {
                 EntityPlayer player = PersistentOperations.GetEntityPlayer(cInfo.entityId);
                 if (player != null)
                 {
                     World world = __instance.World;
                     for (int i = 0; i < _blocksToChange.Count; i++)
                     {
                         BlockChangeInfo newBlockInfo  = _blocksToChange[i];                             //new block info
                         BlockValue      oldBlockValue = world.GetBlock(newBlockInfo.pos);               //old block value
                         Block           oldBlock      = oldBlockValue.Block;
                         if (newBlockInfo != null && oldBlock != null && newBlockInfo.bChangeBlockValue) //has new block value
                         {
                             Block newBlock = newBlockInfo.blockValue.Block;
                             if (newBlock != null)
                             {
                                 if (newBlock is BlockSleepingBag)//placed a sleeping bag
                                 {
                                     if (POIProtection.IsEnabled && POIProtection.Bed && world.IsPositionWithinPOI(newBlockInfo.pos.ToVector3(), 8))
                                     {
                                         GameManager.Instance.World.SetBlockRPC(newBlockInfo.pos, BlockValue.Air);
                                         PersistentOperations.ReturnBlock(cInfo, newBlock.GetBlockName(), 1);
                                         Phrases.Dict.TryGetValue("POI1", out string phrase);
                                         ChatHook.ChatMessage(cInfo, Config.Chat_Response_Color + phrase + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
                                         return(false);
                                     }
                                 }
                                 else if (newBlock is BlockLandClaim)//placed a land claim
                                 {
                                     if (POIProtection.IsEnabled && POIProtection.Claim && world.IsPositionWithinPOI(newBlockInfo.pos.ToVector3(), 5))
                                     {
                                         GameManager.Instance.World.SetBlockRPC(newBlockInfo.pos, BlockValue.Air);
                                         PersistentOperations.ReturnBlock(cInfo, newBlock.GetBlockName(), 1);
                                         Phrases.Dict.TryGetValue("POI2", out string _phrase);
                                         ChatHook.ChatMessage(cInfo, Config.Chat_Response_Color + _phrase + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null);
                                         return(false);
                                     }
                                 }
                                 if (BlockLogger.IsEnabled && !_blocksToChange[i].blockValue.Equals(BlockValue.Air))
                                 {
                                     BlockLogger.PlacedBlock(cInfo, newBlock, newBlockInfo.pos);
                                 }
                             }
                             if (oldBlockValue.Block is BlockTrapDoor)
                             {
                                 return(true);
                             }
                             else if (newBlockInfo.blockValue.Equals(BlockValue.Air.type))//new block is air
                             {
                                 if (oldBlockValue.Block is BlockLandClaim)
                                 {
                                     if (PersistentOperations.ClaimedByWho(_persistentPlayerId, newBlockInfo.pos) == EnumLandClaimOwner.None)
                                     {
                                         if (DamageDetector.IsEnabled)
                                         {
                                             int total = oldBlock.MaxDamage - oldBlockValue.damage;
                                             if (total >= DamageDetector.Block_Damage_Limit && (GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.PlatformId) > Admin_Level &&
                                                                                                GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.CrossplatformId) > Admin_Level))
                                             {
                                                 Penalty(total, player, cInfo);
                                                 return(false);
                                             }
                                         }
                                         if (BlockLogger.IsEnabled)
                                         {
                                             BlockLogger.BrokeBlock(cInfo, oldBlock, newBlockInfo.pos);
                                         }
                                         int       slot      = player.inventory.holdingItemIdx;
                                         ItemValue itemValue = cInfo.latestPlayerData.inventory[slot].itemValue;
                                         if (itemValue != null && InfiniteAmmo.IsEnabled && itemValue.ItemClass.IsGun() && InfiniteAmmo.Exec(cInfo, player, slot, itemValue))
                                         {
                                             return(false);
                                         }
                                     }
                                     else if (BlockLogger.IsEnabled)
                                     {
                                         BlockLogger.RemovedBlock(cInfo, oldBlock, newBlockInfo.pos);
                                     }
                                 }
                                 else if (!oldBlock.CanPickup)//old block can not be picked up
                                 {
                                     if (PersistentOperations.ClaimedByWho(_persistentPlayerId, newBlockInfo.pos) == EnumLandClaimOwner.None)
                                     {
                                         if (DamageDetector.IsEnabled)
                                         {
                                             int total = oldBlock.MaxDamage - oldBlockValue.damage;
                                             if (total >= DamageDetector.Block_Damage_Limit && (GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.PlatformId) > Admin_Level &&
                                                                                                GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.CrossplatformId) > Admin_Level))
                                             {
                                                 Penalty(total, player, cInfo);
                                                 return(false);
                                             }
                                         }
                                     }
                                     if (BlockLogger.IsEnabled)
                                     {
                                         BlockLogger.RemovedBlock(cInfo, oldBlock, newBlockInfo.pos);
                                     }
                                 }
                             }
                             else if (oldBlock.blockID == newBlock.blockID) //block is the same
                             {
                                 if (newBlockInfo.bChangeDamage)            //block took damage
                                 {
                                     if (DamageDetector.IsEnabled)
                                     {
                                         int total = newBlockInfo.blockValue.damage - oldBlockValue.damage;
                                         if (total >= DamageDetector.Block_Damage_Limit && (GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.PlatformId) > Admin_Level &&
                                                                                            GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.CrossplatformId) > Admin_Level))
                                         {
                                             Penalty(total, player, cInfo);
                                             return(false);
                                         }
                                     }
                                     int       slot      = player.inventory.holdingItemIdx;
                                     ItemValue itemValue = cInfo.latestPlayerData.inventory[slot].itemValue;
                                     if (itemValue != null && InfiniteAmmo.IsEnabled && itemValue.ItemClass.IsGun() && InfiniteAmmo.Exec(cInfo, player, slot, itemValue))
                                     {
                                         return(false);
                                     }
                                 }
                             }
                             else if (oldBlock.DowngradeBlock.Block.blockID == newBlock.blockID)//downgraded
                             {
                                 if (oldBlockValue.damage == newBlockInfo.blockValue.damage || newBlockInfo.blockValue.damage == 0)
                                 {
                                     if (BlockLogger.IsEnabled)
                                     {
                                         BlockLogger.DowngradedBlock(cInfo, oldBlock, newBlock, newBlockInfo.pos);
                                     }
                                     return(true);
                                 }
                                 if (DamageDetector.IsEnabled)
                                 {
                                     int total = oldBlock.MaxDamage - oldBlockValue.damage + newBlockInfo.blockValue.damage;
                                     if (total >= DamageDetector.Block_Damage_Limit && (GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.PlatformId) > Admin_Level &&
                                                                                        GameManager.Instance.adminTools.GetUserPermissionLevel(cInfo.CrossplatformId) > Admin_Level))
                                     {
                                         Penalty(total, player, cInfo);
                                         return(false);
                                     }
                                 }
                                 int       slot      = player.inventory.holdingItemIdx;
                                 ItemValue itemValue = cInfo.latestPlayerData.inventory[slot].itemValue;
                                 if (itemValue != null && InfiniteAmmo.IsEnabled && itemValue.ItemClass.IsGun() && InfiniteAmmo.Exec(cInfo, player, slot, itemValue))
                                 {
                                     return(false);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in BlockChange.ProcessBlockChange: {0}", e.Message));
     }
     return(true);
 }