public MyObjectBuilder_Checkpoint.PlayerItem GetPlayerItemFromPlayerId(long playerId) { MyObjectBuilder_Checkpoint.PlayerItem playerItem = new MyObjectBuilder_Checkpoint.PlayerItem(); try { Dictionary <long, Object> allPlayers = InternalGetPlayerItemMappping(); if (!allPlayers.ContainsKey(playerId)) { return(playerItem); } Object item = allPlayers[playerId]; InternalPlayerItem internalPlayerItem = new InternalPlayerItem(item); playerItem.PlayerId = playerId; playerItem.SteamId = internalPlayerItem.steamId; playerItem.Name = internalPlayerItem.name; playerItem.Model = internalPlayerItem.model; playerItem.IsDead = internalPlayerItem.isDead; } catch (Exception ex) { LogManager.ErrorLog.WriteLine(ex); } return(playerItem); }
public MyObjectBuilder_Checkpoint.PlayerItem GetPlayerItemFromPlayerId(long playerId) { MyObjectBuilder_Checkpoint.PlayerItem playerItem = new MyObjectBuilder_Checkpoint.PlayerItem(); try { Dictionary <long, InternalPlayerItem> playerDictionary = InternalGetPlayerDictionary(); if (!playerDictionary.ContainsKey(playerId)) { return(playerItem); } InternalPlayerItem item = playerDictionary[playerId]; playerItem.PlayerId = item.PlayerId; playerItem.SteamId = item.SteamId; playerItem.Name = item.Name; playerItem.Model = item.Model; playerItem.IsDead = item.IsDead; } catch (Exception ex) { ApplicationLog.BaseLog.Error(ex); } return(playerItem); }
public ulong GetSteamIdFromPlayerName(string playerName) { ulong steamId = 0; foreach (var entry in InternalGetPlayerItemMappping().Keys) { MyObjectBuilder_Checkpoint.PlayerItem playerItem = PlayerMap.Instance.GetPlayerItemFromPlayerId(entry); if (!playerItem.Name.Equals(playerName)) { continue; } steamId = playerItem.SteamId; } if (steamId == 0) { try { steamId = ulong.Parse(playerName); } catch (Exception ex) { LogManager.ErrorLog.WriteLine(ex); } } return(steamId); }
public string GetPlayerNameFromSteamId(ulong steamId) { string playerName = steamId.ToString(); List <long> playerIds = PlayerMap.Instance.GetPlayerIdsFromSteamId(steamId); foreach (var entry in playerIds) { MyObjectBuilder_Checkpoint.PlayerItem playerItem = PlayerMap.Instance.GetPlayerItemFromPlayerId(entry); playerName = playerItem.Name; } return(playerName); }
public override bool HandleCommand(ulong userId, string[] words) { var board = Conquest.Instance.Leaderboard; string leaderResult = ""; /* * foreach (var p in board) * { * leaderResult += string.Format("Here: {0} - {1}", p.Key, p.Value); * } * leaderResult += "\r\n"; */ var leaders = Conquest.Instance.Leaderboard.GroupBy(x => x.Value).Select(group => new { group.Key, Total = group.Count() }).OrderByDescending(x => x.Total); int position = 1; foreach (var p in leaders) { if (leaderResult != "") { leaderResult += "\r\n"; } MyObjectBuilder_Checkpoint.PlayerItem item = PlayerMap.Instance.GetPlayerItemFromPlayerId(p.Key); leaderResult += string.Format("#{0}: {1} with {2} asteroids", position, item.Name, p.Total); position++; } leaderResult += "\r\n\r\n"; long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(userId); int playerCount = 0; var playerItem = leaders.FirstOrDefault(x => x.Key == playerId); if (playerItem != null) { playerCount = playerItem.Total; } leaderResult += string.Format("You currently have {0} owned asteroids.", playerCount); //Communication.SendPrivateInformation(userId, leaderResult); Communication.DisplayDialog(userId, "Conquest Leaderboard", "Current Leaders", leaderResult); return(true); }
// /admin movefrom x y z x y z radius public override bool HandleCommand(ulong userId, string command) { string[] words = command.Split(' '); if (words.Count( ) != 1 && words.Count( ) != 0) { return(false); } if (words.Count() != 1) { Communication.SendPrivateInformation(userId, GetHelp()); return(true); } int days = -1; if (!int.TryParse(words[0], out days) || days < 0) { Communication.SendPrivateInformation(userId, string.Format("Invalid argument. Days argument must be an integer that is 0 or greater.")); return(true); } List <PlayerItem> players = Players.Instance.GetPlayers(x => x.LastLogin < DateTime.Now.AddDays(days * -1) && PlayerMap.Instance.GetPlayerIdsFromSteamId(x.SteamId).FirstOrDefault() > 0); try { foreach (PlayerItem player in players.OrderByDescending(x => x.LastLogin).ToList()) { long playerId = PlayerMap.Instance.GetPlayerIdsFromSteamId(player.SteamId).FirstOrDefault(); if (playerId > 0) { MyObjectBuilder_Checkpoint.PlayerItem item = PlayerMap.Instance.GetPlayerItemFromPlayerId(playerId); Communication.SendPrivateInformation(userId, string.Format("{0} ({1}) last logged in {2}", item.Name, item.PlayerId, player.LastLogin.ToString("g"))); } } } catch (Exception ex) { Console.WriteLine(string.Format("Error: {0}", ex.ToString())); } Communication.SendPrivateInformation(userId, string.Format("Found {0} players that have not logged in within the last {1} days", players.Count, days)); return(true); }
public long GetServerVirtualPlayerId() { ulong serverSteamId = 0; foreach (var entry in WorldManager.Instance.Checkpoint.Players.Dictionary) { if (entry.Value.PlayerId == 0L) { serverSteamId = entry.Value.SteamID; } } long serverVirtualPlayerId = 0; List <long> playerIds = GetPlayerIdsFromSteamId(serverSteamId); if (playerIds.Count == 0) { serverVirtualPlayerId = BaseEntity.GenerateEntityId(); if (serverVirtualPlayerId < 0) { serverVirtualPlayerId = -serverVirtualPlayerId; } MyObjectBuilder_Checkpoint.PlayerItem playerItem = new MyObjectBuilder_Checkpoint.PlayerItem(); playerItem.Name = "Server"; playerItem.IsDead = false; playerItem.Model = ""; playerItem.PlayerId = serverVirtualPlayerId; playerItem.SteamId = serverSteamId; List <MyObjectBuilder_Checkpoint.PlayerItem> dummyList = new List <MyObjectBuilder_Checkpoint.PlayerItem>(); dummyList.Add(playerItem); BaseObject.InvokeEntityMethod(BackingObject, PlayerMapAddPlayerItemMappingMethod, new object[] { dummyList }); } else { serverVirtualPlayerId = playerIds[0]; } return(serverVirtualPlayerId); }
// admin deletearea x y z radius public override bool HandleCommand(ulong userId, string command) { string[] words = command.Split(' '); if (words.Length > 3) { return(false); } if (!words.Any()) { Communication.SendPrivateInformation(userId, GetHelp()); return(true); } int days = -1; if (!int.TryParse(words[0], out days) || days < 0) { Communication.SendPrivateInformation(userId, string.Format("Invalid argument. Days argument must be an integer that is 0 or greater.")); return(true); } // Just assume that anything after the days is going to "ignorenologin" bool removeNoLoginInformation = true; bool removeOwnerless = true; if (words.Count() > 1) { foreach (string word in words) { if (word.ToLower() == "ignorenologin") { removeNoLoginInformation = false; } if (word.ToLower() == "ignoreownerless") { removeOwnerless = false; } } } Communication.SendPrivateInformation(userId, string.Format("Scanning for grids with owners that haven't logged in {0} days. (Must Have Login Info={1})", days, removeNoLoginInformation)); HashSet <IMyEntity> entities = new HashSet <IMyEntity>(); Wrapper.GameAction(() => { MyAPIGateway.Entities.GetEntities(entities, x => x is IMyCubeGrid); }); HashSet <IMyEntity> entitiesFound = new HashSet <IMyEntity>(); foreach (IMyEntity entity in entities) { if (!(entity is IMyCubeGrid)) { continue; } IMyCubeGrid grid = (IMyCubeGrid)entity; CubeGridEntity gridEntity = (CubeGridEntity)GameEntityManager.GetEntity(grid.EntityId); MyObjectBuilder_CubeGrid gridBuilder = CubeGrids.SafeGetObjectBuilder(grid); if (gridBuilder == null) { continue; } // This entity is protected by whitelist if (PluginSettings.Instance.LoginEntityWhitelist.Length > 0 && PluginSettings.Instance.LoginEntityWhitelist.Contains(grid.EntityId.ToString())) { continue; } if (CubeGrids.GetAllOwners(gridBuilder).Count < 1 && removeOwnerless) { Communication.SendPrivateInformation(userId, string.Format("Found entity '{0}' ({1}) not owned by anyone.", gridEntity.Name, entity.EntityId)); entitiesFound.Add(entity); continue; } foreach (long player in CubeGrids.GetBigOwners(gridBuilder)) { // This playerId is protected by whitelist if (PluginSettings.Instance.LoginPlayerIdWhitelist.Length > 0 && PluginSettings.Instance.LoginPlayerIdWhitelist.Contains(player.ToString())) { continue; } MyObjectBuilder_Checkpoint.PlayerItem checkItem = PlayerMap.Instance.GetPlayerItemFromPlayerId(player); if (checkItem.IsDead || checkItem.Name == "") { Communication.SendPrivateInformation(userId, string.Format("Found entity '{0}' ({1}) owned by dead player - ID: {2}", gridEntity.Name, entity.EntityId, player)); entitiesFound.Add(entity); continue; } PlayerItem item = Players.Instance.GetPlayerById(player); if (item == null) { if (removeNoLoginInformation) { Communication.SendPrivateInformation(userId, string.Format("Found entity '{0}' ({1}) owned by a player with no login info: {2}", gridEntity.Name, entity.EntityId, checkItem.Name)); entitiesFound.Add(entity); } } else if (item.LastLogin < DateTime.Now.AddDays(days * -1)) { Communication.SendPrivateInformation(userId, string.Format("Found entity '{0}' ({1}) owned by inactive player: {2}", gridEntity.Name, entity.EntityId, PlayerMap.Instance.GetPlayerItemFromPlayerId(player).Name)); entitiesFound.Add(entity); } } } Communication.SendPrivateInformation(userId, string.Format("Found {0} grids owned by inactive users", entitiesFound.Count)); foreach (IMyEntity entity in entitiesFound) { if (!(entity is IMyCubeGrid)) { continue; } CubeGridEntity gridEntity = new CubeGridEntity((MyObjectBuilder_CubeGrid)entity.GetObjectBuilder(), entity); gridEntity.Dispose(); } Communication.SendPrivateInformation(userId, string.Format("Removed {0} grids owned by inactive users", entitiesFound.Count)); return(true); }
public static void Process(bool reload = false) { Dictionary <long, long> ownership = ProcessAsteroidOwnership(); long owner = 0; int count = 0; foreach (KeyValuePair <long, long> p in ownership) { if (!Instance.Leaderboard.ContainsKey(p.Key)) { if (owner == 0) { owner = p.Value; } count++; } else if (Instance.Leaderboard[p.Key] != ownership[p.Key]) { if (owner == 0) { owner = p.Value; } count++; } } if (count == 1) { MyObjectBuilder_Checkpoint.PlayerItem item = PlayerMap.Instance.GetPlayerItemFromPlayerId(owner); string name = ""; if (item.Name != null) { name = item.Name; } if (!reload) { ChatUtil.SendPublicChat(string.Format("[CONQUEST]: {0} has conquered an asteroid.", name)); } } else if (count > 1) { if (!reload) { ChatUtil.SendPublicChat(string.Format("[CONQUEST]: Multiple asteroids have been conquered. {0} asteroids have been claimed or changed ownership.", count)); } } bool change = false; foreach (KeyValuePair <long, long> L in Instance.Leaderboard) // Find if any asteroids are lost { if (!ownership.ContainsKey(L.Key)) { Instance.Leaderboard.Remove(L.Key); MyObjectBuilder_Checkpoint.PlayerItem player = PlayerMap.Instance.GetPlayerItemFromPlayerId(L.Value); ChatUtil.SendPublicChat(string.Format("[CONQUEST]: {0} has lost an asteroid.", player.Name)); change = true; return; } } foreach (KeyValuePair <long, long> p in ownership) { if (!Instance.Leaderboard.ContainsKey(p.Key)) { Instance.Leaderboard.Add(p.Key, p.Value); change = true; } else if (Instance.Leaderboard.ContainsKey(p.Key) && Instance.Leaderboard[p.Key] != p.Value) { Instance.Leaderboard[p.Key] = p.Value; change = true; } } if (change) { Save(); } }
private static Dictionary <long, long> ProcessAsteroidOwnership() { Dictionary <long, long> result = new Dictionary <long, long>(); HashSet <IMyEntity> entities = new HashSet <IMyEntity>(); MyAPIGateway.Entities.GetEntities(entities); foreach (IMyEntity entity in entities) { if (!(entity is IMyVoxelMap)) { continue; } if (!entity.Save) { continue; } IMyVoxelMap voxel = (IMyVoxelMap)entity; BoundingSphereD sphere = new BoundingSphereD(entity.GetPosition(), 500); // Size of sphere around Roid List <IMyEntity> blocks = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere); Dictionary <long, int> asteroidScore = new Dictionary <long, int>(); foreach (IMyEntity block in blocks) { if (block is IMyCubeBlock) { IMyCubeBlock cube = (IMyCubeBlock)block; if (!(cube.GetTopMostParent() is IMyCubeGrid)) { continue; } IMyCubeGrid parent = (IMyCubeGrid)cube.GetTopMostParent(); if (!parent.IsStatic) { continue; } if (cube.OwnerId != 0 && TestBeacon(cube)) // Test Valid Beacon. { if (!asteroidScore.ContainsKey(cube.OwnerId)) { asteroidScore.Add(cube.OwnerId, 0); } asteroidScore[cube.OwnerId] = asteroidScore[cube.OwnerId] + 1; } } } long asteroidOwner = asteroidScore.OrderBy(x => x.Value).Where(x => x.Value > 0).Select(x => x.Key).FirstOrDefault(); if (asteroidOwner != 0) { MyObjectBuilder_Checkpoint.PlayerItem item = PlayerMap.Instance.GetPlayerItemFromPlayerId(asteroidOwner); //Console.WriteLine(string.Format("Owner of asteroid at: {0} is {1}", General.Vector3DToString(entity.GetPosition()), item.Name)); result.Add(entity.EntityId, asteroidOwner); } } return(result); }
// /admin movefrom x y z x y z radius public override bool HandleCommand(ulong userId, string command) { string[] words = command.Split(' '); HashSet <IMyEntity> entities = new HashSet <IMyEntity>( ); Wrapper.GameAction(() => { MyAPIGateway.Entities.GetEntities(entities, x => x is IMyCubeGrid); }); HashSet <long> playerOwners = new HashSet <long>(); foreach (IMyEntity entity in entities) { IMyCubeGrid grid = (IMyCubeGrid)entity; MyObjectBuilder_CubeGrid gridBlock = (MyObjectBuilder_CubeGrid)grid.GetObjectBuilder(); foreach (MyObjectBuilder_CubeBlock block in gridBlock.CubeBlocks) { if (block.Owner == 0) { continue; } if (!playerOwners.Contains(block.Owner)) { playerOwners.Add(block.Owner); } } } Communication.SendPrivateInformation(userId, string.Format("Total block owners: {0}", playerOwners.Count)); int count = 0; foreach (long owner in playerOwners) { ulong steamId = PlayerMap.Instance.GetPlayerItemFromPlayerId(owner).SteamId; if (steamId == 0) { count++; } } Communication.SendPrivateInformation(userId, string.Format("Total owners without a steam Id: {0}", count)); HashSet <long> badPlayers = new HashSet <long>(); HashSet <long> noLogin = new HashSet <long>(); foreach (long owner in playerOwners) { MyObjectBuilder_Checkpoint.PlayerItem item = PlayerMap.Instance.GetPlayerItemFromPlayerId(owner); if (item.SteamId == 0) { continue; } if (!Players.Instance.PlayerLogins.ContainsKey(item.SteamId)) { Communication.SendPrivateInformation(userId, string.Format("No login information: {0}", item.Name)); noLogin.Add(owner); continue; } PlayerItem playerItem = Players.Instance.PlayerLogins[item.SteamId]; if (DateTime.Now - playerItem.LastLogin > TimeSpan.FromDays(20)) { Communication.SendPrivateInformation(userId, string.Format("Player hasn't logged in 20 days: {0}", item.Name)); badPlayers.Add(owner); } } Communication.SendPrivateInformation(userId, string.Format("Users not logged in the last 20 days: {0}", badPlayers.Count)); Communication.SendPrivateInformation(userId, string.Format("Users with no login information: {0}", noLogin.Count)); /* * count = 0; * List<CubeGridEntity> grids = SectorObjectManager.Instance.GetTypedInternalData<CubeGridEntity>(); * foreach(CubeGridEntity grid in grids) * { * Thread.Sleep(100); * foreach (CubeBlockEntity block in grid.CubeBlocks) * { * MyObjectBuilder_CubeBlock blockBuilder = (MyObjectBuilder_CubeBlock)block.Export(); * if (badPlayers.Contains(blockBuilder.Owner) || noLogin.Contains(blockBuilder.Owner)) * { * //grid.DeleteCubeBlock(block); * block.Dispose(); * count++; * } * } * } */ Wrapper.GameAction(() => { MyAPIGateway.Entities.GetEntities(entities, x => x is IMyCubeGrid); foreach (IMyEntity entity in entities) { IMyCubeGrid grid = (IMyCubeGrid)entity; List <IMySlimBlock> blocks = new List <IMySlimBlock>(); grid.GetBlocks(blocks, x => x.FatBlock != null && x.FatBlock.OwnerId != 0); foreach (IMySlimBlock block in blocks) { IMyCubeBlock cubeBlock = (IMyCubeBlock)block.FatBlock; if (badPlayers.Contains(cubeBlock.OwnerId) || noLogin.Contains(cubeBlock.OwnerId)) { grid.RazeBlock(cubeBlock.Min); count++; } } } }); Communication.SendPrivateInformation(userId, string.Format("Blocks disposed: {0}", count)); return(true); }
public long GetServerVirtualPlayerId() { ulong serverSteamId = 0; foreach (var entry in WorldManager.Instance.Checkpoint.Players.Dictionary) { if (entry.Value.PlayerId == 0L) { serverSteamId = entry.Value.SteamID; } } long serverVirtualPlayerId = 0; List<long> playerIds = GetPlayerIdsFromSteamId(serverSteamId); if (playerIds.Count == 0) { serverVirtualPlayerId = BaseEntity.GenerateEntityId(); if (serverVirtualPlayerId < 0) serverVirtualPlayerId = -serverVirtualPlayerId; MyObjectBuilder_Checkpoint.PlayerItem playerItem = new MyObjectBuilder_Checkpoint.PlayerItem(); playerItem.Name = "Server"; playerItem.IsDead = false; playerItem.Model = ""; playerItem.PlayerId = serverVirtualPlayerId; playerItem.SteamId = serverSteamId; List<MyObjectBuilder_Checkpoint.PlayerItem> dummyList = new List<MyObjectBuilder_Checkpoint.PlayerItem>(); dummyList.Add(playerItem); BaseObject.InvokeEntityMethod(BackingObject, PlayerMapAddPlayerItemMappingMethod, new object[] { dummyList }); } else { serverVirtualPlayerId = playerIds[0]; } return serverVirtualPlayerId; }
public MyObjectBuilder_Checkpoint.PlayerItem GetPlayerItemFromPlayerId(long playerId) { MyObjectBuilder_Checkpoint.PlayerItem playerItem = new MyObjectBuilder_Checkpoint.PlayerItem(); try { Dictionary<long, Object> allPlayers = InternalGetPlayerItemMappping(); if (!allPlayers.ContainsKey(playerId)) return playerItem; Object item = allPlayers[playerId]; InternalPlayerItem internalPlayerItem = new InternalPlayerItem(item); playerItem.PlayerId = playerId; playerItem.SteamId = internalPlayerItem.steamId; playerItem.Name = internalPlayerItem.name; playerItem.Model = internalPlayerItem.model; playerItem.IsDead = internalPlayerItem.isDead; } catch (Exception ex) { LogManager.ErrorLog.WriteLine(ex); } return playerItem; }