public List <string> GetUserData(TSPlayer p) // May return an empty list if data is not found. { List <string> ret = new List <string> { }; bool checkeddb = false; foreach (string field in fields) { if (p.GetData <bool>("dbhas" + field)) { ret.Add(p.GetData <string>(field)); } else if (!checkeddb) { QueryResult result = db.QueryReader("SELECT * FROM " + table + " WHERE UserID=@0;", p.UUID); if (result.Read()) { foreach (string f in fields) { p.SetData <bool>("dbhas" + field, true); p.SetData <string>(field, result.Get <string>(f)); } ret.Add(p.GetData <string>(field)); } checkeddb = true; } } return(ret); }
public string GetUserData(TSPlayer p, string field, string defaultval = null) { if (p == null) { TShock.Log.ConsoleError("DB.GetUserData() called with a null player!"); return(defaultval); } if (!p.IsLoggedIn) { TShock.Log.ConsoleError("DB.GetUserData() called before player was logged in!"); return(defaultval); } if (p.UUID == "") { TShock.Log.ConsoleError("DB.GetUserData() called with a null UID for unknown reasons!"); return(defaultval); } if (p.GetData <bool>("dbhas" + field)) { return((string)p.GetData <string>(field)); } else { //string ret = ReadUserData(p.UUID, field, defaultval); /* wait, why would this be here exactly? * if( ret != defaultval ) * { * WriteUserData(p.UUID, field, ret); * } */ //return ret; return(ReadUserData(p.UUID, field, defaultval)); } }
public static NetItem GetChestItem([NotNull] this TSPlayer player, int index) { Debug.Assert(player != null, "Player must not be null."); Debug.Assert(0 <= index && index < Chest.maxItems, "Index must be valid."); return(player.GetData <NetItem>(ChestItemKey + index)); }
public static PlayerInfo GetPlayerInfo(this TSPlayer player) { if (!player.ContainsData(PlayerInfo.Key)) { player.SetData <PlayerInfo>(PlayerInfo.Key, new PlayerInfo()); } return(player.GetData <PlayerInfo>(PlayerInfo.Key)); }
public static RecipeData GetRecipeData(this TSPlayer player, bool createIfNotExists = false) { if (!player.ContainsData(RecipeData.KEY) && createIfNotExists) { player.SetData(RecipeData.KEY, new RecipeData()); } return(player.GetData <RecipeData>(RecipeData.KEY)); }
public static PlayerInfo GetPlayerInfo(this TSPlayer tsplayer) { if (!tsplayer.ContainsData(PlayerInfo.KEY)) { tsplayer.SetData(PlayerInfo.KEY, new PlayerInfo()); } return(tsplayer.GetData <PlayerInfo>(PlayerInfo.KEY)); }
public async static void SendSignDataInCircle(this TSPlayer plr, int radius) { await Task.Run(() => { var psp = plr.GetData <PSPlayer>("PSPlayer"); psp.LastSignIndex = psp.VisitingSign == null ? -1 : 0; //从第一个开始, 第零个一般是当前正在看的 PSPlugin.SignList.Where(s => IsPointInCircle(s.X, s.Y, plr.TileX, plr.TileY, radius) && psp.VisitingSign != s).ForEach(s => plr.SendSignData(s)); }); }
private void WriteUserData(TSPlayer p) { List <string> values = new List <string> { }; foreach (string field in fields) { if (p.GetData <bool>("dbhas" + field)) { values.Add(p.GetData <string>(field)); } else { values.Add(""); } } WriteUserData(p.UUID, values); }
public static WarpbackData Get(TSPlayer plr) { WarpbackData ret = plr.GetData <WarpbackData>("warpback"); if (ret == null) { ret = new WarpbackData(plr); plr.SetData <WarpbackData>("warpback", ret); } return(ret); }
public static RtPlayer GetPlayerInfo(TSPlayer player) { var info = player.GetData <RtPlayer>(Rtdataname); if (info == null) { info = new RtPlayer(); player.SetData(Rtdataname, info); } return(info); }
private Session GetOrCreateSession(TSPlayer player) { var session = player.GetData <Session>(SessionKey); if (session == null) { session = new Session(player); player.SetData(SessionKey, session); } return(session); }
/// <summary> /// Gets or creates the session associated with the specified player. /// </summary> /// <param name="player">The player, which must not be <c>null</c>.</param> /// <returns>The session.</returns> public static Session GetOrCreateSession([NotNull] this TSPlayer player) { Debug.Assert(player != null, "Player must not be null."); var session = player.GetData <Session>(SessionKey); if (session == null) { session = Session.Load(player); player.SetData(SessionKey, session); } return(session); }
/// <summary> /// Gets the session associated with the specified player. /// </summary> /// <param name="player">The player, which must not be <c>null</c>.</param> /// <returns>The session.</returns> public static Session GetSession(this TSPlayer player) { Debug.Assert(player != null, "Player must not be null."); var session = player.GetData <Session>(SessionKey); if (session == null) { session = new Session(); player.SetData(SessionKey, session); } return(session); }
public static BalanceSheet GetOrCreateBalanceSheet([NotNull] this TSPlayer player) { Debug.Assert(player != null, "Player must not be null."); var balanceSheet = player.GetData <BalanceSheet>(BalanceSheetKey); if (balanceSheet == null) { balanceSheet = new BalanceSheet(player); player.SetData(BalanceSheetKey, balanceSheet); } return(balanceSheet); }
/// <summary> /// Gets the player's info. /// </summary> /// <param name="player">The player.</param> /// <returns>The player info.</returns> public static PlayerInfo GetOrCreatePlayerInfo(this TSPlayer player) { var playerInfo = player.GetData <PlayerInfo>(PlayerInfoKey); if (playerInfo == null) { playerInfo = new PlayerInfo { PreviousGroup = player.Group }; player.SetData(PlayerInfoKey, playerInfo); } return(playerInfo); }
public static SwitchCmdPlayerInfo GetInfo(TSPlayer player) { if (player == null) { throw new ArgumentNullException(nameof(player)); } var info = player.GetData <SwitchCmdPlayerInfo>(Key); if (info == null) { info = new SwitchCmdPlayerInfo(); player.SetData(Key, info); } return(info); }
public static PlayerInfo GetInfo(TSPlayer player) { if (player == null) { return(null); } var info = player.GetData <PlayerInfo>(Key); if (info == null) { info = new PlayerInfo(); player.SetData(Key, info); } return(info); }
internal Session GetOrCreateSession(TSPlayer player) { var session = player.GetData <Session>(SessionKey); if (session == null) { var username = player.User?.Name ?? player.Name; //first try the database SessionDefinition definition = SessionRepository.Load(username); //otherwise we need to create if (definition == null) { definition = new SessionDefinition(); definition.Initialize(); } session = new Session(player, definition); session.Resolve(_classes); player.SetData(SessionKey, session); } return(session); }
private void OnGetData(GetDataEventArgs args) { using (MemoryStream data = new MemoryStream(args.Msg.readBuffer, 3, args.Length - 1)) { if (args.MsgID == PacketTypes.LoadNetModule) { if (data.ReadByte() == 2) { TSPlayer player = TShock.Players[args.Msg.whoAmI]; if (player.GetData <bool>("mapteleport") && player.HasPermission("mapteleport.use")) { data.Position++; int X = Math.Min(Main.maxTilesX, Math.Max(0, (int)data.ReadSingle())); int Y = Math.Min(Main.maxTilesY, Math.Max(0, (int)data.ReadSingle())); if (player.HasPermission("mapteleport.solid")) { player.Teleport(X * 16, Y * 16); player.SendSuccessMessage($"Teleported to ({X}, {Y})"); } else { if ((Main.tile[X, Y] == null || !Main.tile[X, Y].active() || (!Main.tileSolid[Main.tile[X, Y].type] && Main.tile[X, Y].liquid == 0)) && (Main.tile[X + 1, Y] == null || !Main.tile[X + 1, Y].active() || (!Main.tileSolid[Main.tile[X + 1, Y].type] && Main.tile[X + 1, Y].liquid == 0)) && (Main.tile[X + 1, Y + 1] == null || !Main.tile[X + 1, Y + 1].active() || (!Main.tileSolid[Main.tile[X + 1, Y + 1].type] && Main.tile[X + 1, Y + 1].liquid == 0)) && (Main.tile[X, Y + 1] == null || !Main.tile[X, Y + 1].active() || (!Main.tileSolid[Main.tile[X, Y + 1].type] && Main.tile[X, Y + 1].liquid == 0)) && (Main.tile[X + 1, Y + 2] == null || !Main.tile[X + 1, Y + 2].active() || (!Main.tileSolid[Main.tile[X + 1, Y + 2].type] && Main.tile[X + 1, Y + 2].liquid == 0)) && (Main.tile[X, Y + 2] == null || !Main.tile[X, Y + 2].active() || (!Main.tileSolid[Main.tile[X, Y + 2].type] && Main.tile[X, Y + 2].liquid == 0))) { player.Teleport(X * 16, Y * 16); player.SendSuccessMessage($"Teleported to ({X}, {Y})"); } else { player.SendErrorMessage("You do not have permission to teleport into solid tiles."); } } } } } } }
private void OnGetData(GetDataEventArgs args) { if (args.Handled) { return; } if (!usingInfChests) { return; } int index = args.Msg.whoAmI; using (var reader = new BinaryReader(new MemoryStream(args.Msg.readBuffer, args.Index, args.Length))) { switch (args.MsgID) { case PacketTypes.ChestGetContents: if (lockChests) { TShock.Players[args.Msg.whoAmI].SendWarningMessage("Chests are currently being converted. Please wait for a few moments."); return; } var tilex = reader.ReadInt16(); var tiley = reader.ReadInt16(); #if DEBUG File.AppendAllText("debug.txt", $"[IN] 31 ChestGetContents: Tile X = {tilex} | Tile Y = {tiley}\n"); #endif args.Handled = true; #region GetChest InfChest gchest = DB.GetChest(tilex, tiley); TSPlayer gplayer = TShock.Players[index]; if (gchest == null) { gplayer.SendErrorMessage("This chest is corrupted."); WorldGen.KillTile(tilex, tiley); TSPlayer.All.SendData(PacketTypes.Tile, "", 0, tilex, tiley + 1); return; } PlayerInfo info = gplayer.GetData <PlayerInfo>(PIString); switch (info.Action) { case ChestAction.GetInfo: gplayer.SendInfoMessage($"X: {gchest.x} | Y: {gchest.y}"); string owner = gchest.userid == -1 ? "(None)" : TShock.Users.GetUserByID(gchest.userid) == null ? "(Deleted User)" : TShock.Users.GetUserByID(gchest.userid).Name; string ispublic = gchest.isPublic ? " (Public)" : ""; string isrefill = gchest.refill > -1 ? $" (Refill: {gchest.refill})" : ""; gplayer.SendInfoMessage($"Chest Owner: {owner}{ispublic}{isrefill}"); if (gchest.groups.Count > 0 && !string.IsNullOrWhiteSpace(gchest.groups[0])) { string tinfo = string.Join(", ", gchest.groups); gplayer.SendInfoMessage($"Groups Allowed: {tinfo}"); } else { gplayer.SendInfoMessage("Groups Allowed: (None)"); } if (gchest.users.Count > 0) { string tinfo = string.Join(", ", gchest.users.Select(p => TShock.Users.GetUserByID(p) == null ? "(Deleted User)" : TShock.Users.GetUserByID(p).Name)); gplayer.SendInfoMessage($"Users Allowed: {tinfo}"); } else { gplayer.SendInfoMessage("Users Allowed: (None)"); } break; case ChestAction.Protect: if (gchest.userid == gplayer.User.ID) { gplayer.SendErrorMessage("This chest is already claimed by you!"); } else if (gchest.userid != -1 && !gplayer.HasPermission("ic.edit")) { gplayer.SendErrorMessage("This chest is already claimed by someone else!"); } else { gchest.userid = gplayer.User.ID; DB.UpdateUser(gchest); gplayer.SendSuccessMessage("This chest is now claimed by you!"); } break; case ChestAction.Unprotect: if (gchest.userid != gplayer.User.ID && !gplayer.HasPermission("ic.edit")) { gplayer.SendErrorMessage("This chest is not yours!"); } else if (gchest.userid == -1) { gplayer.SendErrorMessage("This chest is not claimed!"); } else { gchest.userid = -1; DB.UpdateUser(gchest); gplayer.SendSuccessMessage("This chest is no longer claimed."); } break; case ChestAction.SetGroup: if (gchest.userid != gplayer.User.ID && !gplayer.HasPermission("ic.edit")) { gplayer.SendErrorMessage("This chest is not yours!"); } else if (gchest.userid == -1) { gplayer.SendErrorMessage("This chest is not claimed!"); } else { if (gchest.groups.Contains(info.ExtraInfo)) { gchest.groups.Remove(info.ExtraInfo); gplayer.SendSuccessMessage($"Successfully removed group access from chest."); DB.UpdateGroups(gchest); } else { gchest.groups.Add(info.ExtraInfo); gplayer.SendSuccessMessage($"Successfully added group access to chest."); DB.UpdateGroups(gchest); } } break; case ChestAction.SetRefill: if (gchest.userid != gplayer.User.ID && !gplayer.HasPermission("ic.edit")) { gplayer.SendErrorMessage("This chest is not yours!"); } else if (gchest.userid == -1) { gplayer.SendErrorMessage("This chest is not claimed!"); } else { int refilltime = int.Parse(info.ExtraInfo); gchest.refill = refilltime; DB.UpdateRefill(gchest); gplayer.SendSuccessMessage("Successfull set refill time to " + (refilltime == -1 ? "(none)." : refilltime.ToString() + ".")); } break; case ChestAction.SetUser: if (gchest.userid != gplayer.User.ID && !gplayer.HasPermission("ic.edit")) { gplayer.SendErrorMessage("This chest is not yours!"); } else if (gchest.userid == -1) { gplayer.SendErrorMessage("This chest is not claimed!"); } else { int userid = int.Parse(info.ExtraInfo); if (gchest.users.Contains(userid)) { gchest.users.Remove(userid); DB.UpdateUsers(gchest); gplayer.SendSuccessMessage("Successfully removed user access from chest."); } else { gchest.users.Add(userid); DB.UpdateUsers(gchest); gplayer.SendSuccessMessage("Successfully added user access to chest."); } } break; case ChestAction.TogglePublic: if (gchest.userid != gplayer.User.ID && !gplayer.HasPermission("ic.edit")) { gplayer.SendErrorMessage("This chest is not yours!"); } else if (gchest.userid == -1) { gplayer.SendErrorMessage("This chest is not claimed!"); } else { if (gchest.isPublic) { gchest.isPublic = false; DB.UpdatePublic(gchest); gplayer.SendSuccessMessage("Successfully set chest as private."); } else { gchest.isPublic = true; DB.UpdatePublic(gchest); gplayer.SendSuccessMessage("Successfully set chest as public."); } } break; case ChestAction.None: //check for perms if (!gplayer.HasPermission("ic.edit") && ((TShock.Config.RegionProtectChests && !TShock.Regions.CanBuild(gchest.x, gchest.y, gplayer)) || (gchest.userid != -1 && !gchest.isPublic && !gchest.groups.Contains(gplayer.Group.Name) && (!gplayer.IsLoggedIn || (gchest.userid != gplayer.User.ID && !gchest.users.Contains(gplayer.User.ID)))))) { gplayer.SendErrorMessage("This chest is protected."); break; } info.ChestIdInUse = gchest.id; Item[] items; RefillChestInfo rcinfo = GetRCInfo(!gplayer.IsLoggedIn ? -1 : gplayer.User.ID, gchest.id); //use refill items if exists, or create new refill entry, or use items directly if (gchest.isRefill && rcinfo != null && (DateTime.Now - rcinfo.TimeOpened).TotalSeconds < gchest.refill) { items = rcinfo.CurrentItems; } else if (gchest.isRefill) { if (rcinfo != null) { DeleteOldRCInfo(!gplayer.IsLoggedIn ? -1 : gplayer.User.ID, gchest.id); } RefillChestInfo newrcinfo = new RefillChestInfo() { ChestID = gchest.id, CurrentItems = gchest.items, PlayerID = !gplayer.IsLoggedIn ? -1 : gplayer.User.ID, TimeOpened = DateTime.Now }; RCInfos.Add(newrcinfo); items = newrcinfo.CurrentItems; } else { items = gchest.items; } int tempchest = GetNextChestId(); Main.chest[tempchest] = new Chest() { item = items, x = gchest.x, y = gchest.y }; for (int i = 0; i < 40; i++) { gplayer.SendData(PacketTypes.ChestItem, "", tempchest, i, gchest.items[i].stack, gchest.items[i].prefix, gchest.items[i].netID); } gplayer.SendData(PacketTypes.ChestOpen, "", tempchest, gchest.x, gchest.y); NetMessage.SendData((int)PacketTypes.SyncPlayerChestIndex, -1, index, NetworkText.Empty, index, tempchest); Main.chest[tempchest] = null; break; } info.Action = ChestAction.None; info.ExtraInfo = ""; gplayer.SetData(PIString, info); #endregion break; case PacketTypes.ChestItem: if (lockChests) { TShock.Players[args.Msg.whoAmI].SendWarningMessage("Chests are currently being converted. Please wait for a few moments."); return; } var chestid = reader.ReadInt16(); var itemslot = reader.ReadByte(); var stack = reader.ReadInt16(); var prefix = reader.ReadByte(); var netid = reader.ReadInt16(); #if DEBUG if (itemslot == 0 || itemslot == 39) { File.AppendAllText("debug.txt", $"[IN] 32 ChestItem: Chest ID = {chestid} | Item Slot = {itemslot} | Stack = {stack} | Prefix = {prefix} | Net ID = {netid}\n"); } #endif TSPlayer ciplayer = TShock.Players[index]; PlayerInfo piinfo = ciplayer.GetData <PlayerInfo>(PIString); if (piinfo.ChestIdInUse == -1) { return; } InfChest cichest = DB.GetChest(piinfo.ChestIdInUse); RefillChestInfo circinfo = GetRCInfo(!TShock.Players[index].IsLoggedIn ? -1 : TShock.Players[index].User.ID, cichest.id); if (cichest == null) { ciplayer.SendWarningMessage("This chest is corrupted. Please remove it."); return; } Item item = new Item(); item.SetDefaults(netid); item.stack = stack; item.prefix = prefix; if (ciplayer.HasPermission(Permissions.spawnmob) && Main.hardMode && (item.netID == 3092 && ciplayer.TPlayer.ZoneHoly) || (item.netID == 3091 && (ciplayer.TPlayer.ZoneCrimson || ciplayer.TPlayer.ZoneCorrupt))) { bool empty = true; foreach (var initem in cichest.items) { if (initem?.netID != 0) { empty = false; } } if (empty) { //kick player out of chest, kill chest, spawn appropriate mimic piinfo.ChestIdInUse = -1; ciplayer.SetData(PIString, piinfo); NetMessage.SendData((int)PacketTypes.SyncPlayerChestIndex, -1, index, NetworkText.Empty, index, -1); DB.DeleteChest(cichest.id); WorldGen.KillTile(cichest.x, cichest.y, noItem: true); NetMessage.SendTileSquare(ciplayer.Index, cichest.x, cichest.y, 3); int type; if (netid == 3092) { type = 475; } else if (netid == 3091 && ciplayer.TPlayer.ZoneCrimson) { type = 474; } else //if (netid == 3091 && ciplayer.TPlayer.ZoneCorrupt) { type = 473; } var npc = TShock.Utils.GetNPCById(type); TSPlayer.Server.SpawnNPC(npc.type, npc.FullName, 1, ciplayer.TileX, ciplayer.TileY, 10, 10); } } if (cichest.isRefill) { circinfo.CurrentItems[itemslot] = item; } else { cichest.items[itemslot] = item; DB.UpdateItems(cichest); } break; case PacketTypes.ChestOpen: chestid = reader.ReadInt16(); var chestx = reader.ReadInt16(); var chesty = reader.ReadInt16(); var namelength = reader.ReadByte(); string chestname = null; if (namelength > 0) { chestname = reader.ReadString(); return; } #if DEBUG File.AppendAllText("debug.txt", $"[IN] 33 ChestName: Chest ID = {chestid} | Chest X = {chestx} | Chest Y = {chesty} | Name Length = {namelength} | Chest Name = {chestname}\n"); #endif if (chestid == -1) { PlayerInfo coinfo = TShock.Players[index].GetData <PlayerInfo>(PIString); coinfo.ChestIdInUse = -1; TShock.Players[index].SetData(PIString, coinfo); NetMessage.SendData((int)PacketTypes.SyncPlayerChestIndex, -1, index, NetworkText.Empty, index, -1); } break; case PacketTypes.TileKill: if (lockChests) { TShock.Players[args.Msg.whoAmI].SendWarningMessage("Chests are currently being converted. Please wait for a few moments."); return; } args.Handled = true; var action = reader.ReadByte(); //0 placec 1 killc 2 placed 3 killd 4 placegc tilex = reader.ReadInt16(); tiley = reader.ReadInt16(); var style = reader.ReadInt16(); //21 chest //88 dresser //467 golden/crystal chest int chesttype; if (action == 0 || action == 1) { chesttype = 21; } else if (action == 2 || action == 3) { chesttype = 88; } else if (action == 4 || action == 5) { chesttype = 467; } else { throw new Exception(); } if (action == 0 || action == 2 || action == 4) { if (TShock.Regions.CanBuild(tilex, tiley, TShock.Players[index])) { Task.Factory.StartNew(() => { if (action == 2) { tilex--; } InfChest newChest = new InfChest(TShock.Players[index].HasPermission("ic.protect") ? TShock.Players[index].User.ID : -1, tilex, tiley - 1, Main.worldID); DB.AddChest(newChest); if (action == 2) { tilex++; } }); WorldGen.PlaceChest(tilex, tiley, (ushort)(chesttype), false, style); Main.chest[0] = null; NetMessage.SendData((int)PacketTypes.TileKill, -1, -1, NetworkText.Empty, action, tilex, tiley, style); } } else { if (Main.tile[tilex, tiley].type != 21 && Main.tile[tilex, tiley].type != 88 && Main.tile[tilex, tiley].type != 467) { return; } if (TShock.Regions.CanBuild(tilex, tiley, TShock.Players[index])) { if (Main.tile[tilex, tiley].frameY % 36 != 0) { tiley--; } if (Main.tile[tilex, tiley].frameX % 36 != 0) { tilex--; } #region Kill Chest Task.Factory.StartNew(() => { InfChest chest = DB.GetChest(tilex, tiley); TSPlayer player = TShock.Players[index]; //If chest exists in map but not db, something went wrong if (chest == null) { player.SendWarningMessage("This chest is corrupted."); WorldGen.KillTile(tilex, tiley); TSPlayer.All.SendData(PacketTypes.Tile, "", 0, tilex, tiley + 1); } //check for perms - chest owner, claim, edit perm else if (chest.userid != player.User.ID && chest.userid != -1 && !player.HasPermission("ic.edit")) { player.SendErrorMessage("This chest is protected."); player.SendTileSquare(tilex, tiley, 3); } //check for empty chest else if (!chest.isEmpty) { player.SendTileSquare(tilex, tiley, 3); } else { WorldGen.KillTile(tilex, tiley); DB.DeleteChest(chest.id); TSPlayer.All.SendData(PacketTypes.Tile, "", 0, tilex, tiley + 1); } }); #endregion } } #if DEBUG File.AppendAllText("debug.txt", $"[IN] 34 PlaceChest: Action = {action} | Tile X = {tilex} | Tile Y = {tiley} | Style = {style}\n"); #endif break; case PacketTypes.ChestName: chestid = reader.ReadInt16(); chestx = reader.ReadInt16(); chesty = reader.ReadInt16(); #if DEBUG File.AppendAllText("debug.txt", $"[IN] 69 GetChestName: Chest ID = {chestid} | Chest X = {chestx} | Chest Y = {chesty}\n"); #endif break; } } }
void OnSendBytes(SendBytesEventArgs e) { if (TShock.Players[e.Socket.Id] == null) { return; } bool build = TShock.Players[e.Socket.Id].GetData <bool>("buildmode"); switch (e.Buffer[2]) { case (byte)PacketTypes.WorldInfo: //7 using (var writer = new BinaryWriter(new MemoryStream(e.Buffer, 3, e.Count - 3))) { writer.Write(build ? 27000 : (int)Main.time); BitsByte bb = 0; bb[0] = build ? true : Main.dayTime; bb[1] = build ? false : Main.bloodMoon; bb[2] = build ? false : Main.eclipse; writer.Write(bb); writer.BaseStream.Position += 9; writer.Write(build ? (short)Main.maxTilesY : (short)Main.worldSurface); writer.Write(build ? (short)Main.maxTilesY : (short)Main.rockLayer); writer.BaseStream.Position += 4; writer.Write(Main.worldName); writer.Write(Main.ActiveWorldFileData.UniqueId.ToString()); writer.BaseStream.Position += 49; writer.Write(build ? 0f : Main.maxRaining); } break; case (byte)PacketTypes.TimeSet: //18 using (var writer = new BinaryWriter(new MemoryStream(e.Buffer, 3, e.Count - 3))) { writer.Write(build ? true : Main.dayTime); writer.Write(build ? 27000 : (int)Main.time); } break; case (byte)PacketTypes.MassWireOperationPay: TSPlayer tsplr = TShock.Players[e.Buffer[7]]; if (tsplr.GetData <bool>("buildmode")) { e.Handled = true; //Will never decrement wires/actuators in inventory } break; case (byte)PacketTypes.NpcUpdate: //23 NPC npc = Main.npc[BitConverter.ToInt16(e.Buffer, 3)]; if (!npc.friendly) { Buffer.BlockCopy(BitConverter.GetBytes(build ? 0f : npc.position.X), 0, e.Buffer, 5, 4); Buffer.BlockCopy(BitConverter.GetBytes(build ? 0f : npc.position.Y), 0, e.Buffer, 9, 4); } break; case (byte)PacketTypes.ProjectileNew: //27 short id = BitConverter.ToInt16(e.Buffer, 3); int owner = e.Buffer[21]; Projectile proj = Main.projectile[TShock.Utils.SearchProjectile(id, owner)]; if (!proj.friendly) { Buffer.BlockCopy(BitConverter.GetBytes((short)(build ? 0 : proj.type)), 0, e.Buffer, 22, 2); } break; } }
public async void CAdmin(CommandArgs args) { var cmds = new Dictionary <char, string> { ['T'] = "force-tier-upgrade" }; if (args.Parameters.Count < 1) { args.Player.SendInfoMessage("CTRS Administrative Actions:"); foreach (var kvp in cmds) { args.Player.SendInfoMessage($"-{kvp.Key} --{kvp.Value}"); } return; } // This is the first administrative command. Should probably make proper regex if more are to come // NOTE: Do not use {Tag} for those, seeing as they are often ran from the console if (args.Parameters[0] == "-T" || args.Parameters[0].Equals("--force-tier-upgrade", StringComparison.OrdinalIgnoreCase)) { args.Parameters.RemoveAt(0); User user; string id = String.Join(" ", args.Parameters).Trim(); int uID; if (Int32.TryParse(id, out uID)) { user = TShock.Users.GetUserByID(uID); } else { user = TShock.Users.GetUserByName(id); } if (user == null) { args.Player.SendErrorMessage("Invalid user!"); } else { Contributor target; // Check if the player is online TSPlayer player = TShock.Players.FirstOrDefault(p => p.User == user); if (player != null) { target = player.GetData <Contributor>(Contributor.DataKey); } else { target = await _main.Contributors.GetAsync(user.ID); } if (target == null) { args.Player.SendErrorMessage($"User '{user.Name}' is not a contributor."); } else { target.Notifications |= Notifications.TierUpdate; await _main.Tiers.UpgradeTier(target, player != null); args.Player.SendSuccessMessage($"Forced a tier upgrade on contributor '{user.Name}'."); } } } }
public static Vector2 GetOldPosition(this TSPlayer player) { return(player.GetData <Vector2>("OldPosition")); }
public static string GetGamemode(this TSPlayer player) { return(player.GetData <string>("Gamemode")); }
public static Vector2 GetGamemodeSpawnPoint(this TSPlayer player) { return(player.GetData <Vector2>("GamemodeSpawnPoint")); }
public static PlayerPvpData GetPlayerData(TSPlayer player) { return(player?.GetData <PlayerPvpData>(Key)); }
public static Chest GetShop([NotNull] this TSPlayer player) { Debug.Assert(player != null, "Player must not be null."); return(player.GetData <Chest>(ShopKey)); }
/// <summary> /// Gets the weapon rack item ID for the specified player. /// </summary> /// <param name="player">The player, which must not be <c>null</c>.</param> /// <returns>The weapon rack item ID.</returns> public static int GetWeaponRackItemId([NotNull] this TSPlayer player) { Debug.Assert(player != null, "Player must not be null."); return(player.GetData <int>(WeaponRackItemIdKey)); }
/// <summary> /// Gets the destroyed projectile ID for the specified player. /// </summary> /// <param name="player">The player, which must not be <c>null</c>.</param> /// <returns>The destroyed projectile ID.</returns> public static int GetDestroyedProjectileId([NotNull] this TSPlayer player) { Debug.Assert(player != null, "Player must not be null."); return(player.GetData <int>(DestroyedProjectileIdKey)); }
/// <summary> /// Gets the last updated item sent by the specified player. /// </summary> /// <param name="player">The player, which must not be <c>null</c>.</param> /// <returns>The last updated item.</returns> public static NetItem GetLastUpdatedItem([NotNull] this TSPlayer player) { Debug.Assert(player != null, "Player must not be null."); return(player.GetData <NetItem>(LastUpdatedItemKey)); }