diff --git a/CaiBotLiteMod/CaiBotCommands.cs b/CaiBotLiteMod/CaiBotCommands.cs
index 30735ad..6e092b6 100644
--- a/CaiBotLiteMod/CaiBotCommands.cs
+++ b/CaiBotLiteMod/CaiBotCommands.cs
@@ -12,7 +12,7 @@ public override CommandType Type
public override string Command
=> "生成绑定码";
-
+
public override string Description
=> "生成一个CaiBot绑定码";
@@ -29,16 +29,16 @@ public override CommandType Type
public override string Command
=> "t";
-
+
public override string Description
=> "Test";
public override void Action(CommandCaller caller, string input, string[] args)
{
- Console.WriteLine(JsonConvert.SerializeObject(ModLoader.Mods.Where(i=> i!=null).Select(i=> i.Name)));
+ Console.WriteLine(JsonConvert.SerializeObject(ModLoader.Mods.Where(i => i != null).Select(i => i.Name)));
var mod = ModLoader.GetMod("MagicStorage");
var asset = mod.Assets.GetLoadedAssets();
-
+
Console.WriteLine(asset.Length);
}
}
\ No newline at end of file
diff --git a/CaiBotLiteMod/CaiBotLiteMod.cs b/CaiBotLiteMod/CaiBotLiteMod.cs
index dd8a95e..4ed455a 100644
--- a/CaiBotLiteMod/CaiBotLiteMod.cs
+++ b/CaiBotLiteMod/CaiBotLiteMod.cs
@@ -12,7 +12,7 @@ public class CaiBotLiteMod : Mod
{
internal static int InitCode = -1;
internal static bool DebugMode;
-
+
public static readonly Version PluginVersion = ModLoader.GetMod("CaiBotLiteMod").Version;
public static readonly TSPlayer?[] Players = new TSPlayer[256];
@@ -23,6 +23,7 @@ public override void Load()
{
return;
}
+
DebugMode = Program.LaunchParameters.ContainsKey("-caidebug");
Config.Settings.Read();
Config.Settings.Write();
@@ -40,7 +41,7 @@ public override void Unload()
WebsocketManager.WebSocket.Dispose();
ExecuteCommandHook.Dispose();
}
-
+
public static void GenCode()
{
diff --git a/CaiBotLiteMod/CaiBotLiteMod.csproj b/CaiBotLiteMod/CaiBotLiteMod.csproj
index fb70ea2..af370bf 100644
--- a/CaiBotLiteMod/CaiBotLiteMod.csproj
+++ b/CaiBotLiteMod/CaiBotLiteMod.csproj
@@ -15,6 +15,9 @@
lib\SixLabors.ImageSharp.dll
+
+
+
diff --git a/CaiBotLiteMod/Moudles/Package.cs b/CaiBotLiteMod/Moudles/Package.cs
index ffa4204..f496d62 100644
--- a/CaiBotLiteMod/Moudles/Package.cs
+++ b/CaiBotLiteMod/Moudles/Package.cs
@@ -51,9 +51,9 @@ public T Read(string key)
{
if (Enum.GetNames(typeof(T)).Any(name => string.Equals(name, "Unknown", StringComparison.OrdinalIgnoreCase)))
{
- return (T)Enum.Parse(typeof(T), "Unknown", true);
+ return (T) Enum.Parse(typeof(T), "Unknown", true);
}
-
+
throw new InvalidCastException($"Cannot convert string '{stringValue}' to enum {typeof(T).Name}", ex);
}
}
diff --git a/CaiBotLiteMod/Moudles/TSPlayer.cs b/CaiBotLiteMod/Moudles/TSPlayer.cs
index ee607a6..b88a010 100644
--- a/CaiBotLiteMod/Moudles/TSPlayer.cs
+++ b/CaiBotLiteMod/Moudles/TSPlayer.cs
@@ -16,55 +16,21 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
-using CaiBotLiteMod.Services;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
-using System.Text.RegularExpressions;
-using System.Threading;
-using System.Timers;
using Terraria;
using Terraria.Chat;
using Terraria.DataStructures;
-using Terraria.GameContent.Creative;
using Terraria.ID;
using Terraria.Localization;
-using Timer = System.Timers.Timer;
using Color = System.Drawing.Color;
-using Point = System.Drawing.Point;
using Rectangle = System.Drawing.Rectangle;
namespace CaiBotLiteMod.Moudles;
-///
-/// Bitflags used with the method
-///
-[Flags]
-public enum DisableFlags
-{
- ///
- /// Disable the player and leave no messages
- ///
- None,
-
- ///
- /// Write the Disable message to the console
- ///
- WriteToConsole,
-
- ///
- /// Write the Disable message to the log
- ///
- WriteToLog,
-
- ///
- /// Equivalent to WriteToConsole | WriteToLog
- ///
- WriteToLogAndConsole
-}
-
public class TSPlayer
{
///
@@ -83,18 +49,6 @@ public class TSPlayer
private readonly Player FakePlayer = null!;
- private int _respawnTimer;
-
- ///
- /// Whether the player is accepting whispers from other users
- ///
- public bool AcceptingWhispers = true;
-
- ///
- /// Represents the ID of the chest that the player is viewing.
- ///
- public int ActiveChest = -1;
-
///
/// A list of command callbacks indexed by the command they need to do.
@@ -103,146 +57,17 @@ public class TSPlayer
private string CacheIP = null!;
- ///
- /// Players controls are inverted if using SSC
- ///
- public bool Confused = false;
-
- public string Country = "??";
-
///
/// Contains data stored by plugins
///
protected ConcurrentDictionary data = new ();
- ///
- /// Whether the player should see logs.
- ///
- public bool DisplayLogs = true;
-
-
- ///
- /// Whether the player has been nagged about logging in.
- ///
- public bool HasBeenNaggedAboutLoggingIn;
///
/// Whether the player is logged in or not.
///
public bool IsLoggedIn;
- ///
- /// Represents the current item the player is holding.
- ///
- public Item ItemInHand = new ();
-
- private DateTime LastDisableNotification = DateTime.UtcNow;
-
- ///
- /// The last projectile type this player tried to kill.
- ///
- public int LastKilledProjectile = 0;
-
- ///
- /// The player's last known position from PlayerUpdate packet.
- ///
- public Vector2 LastNetPosition = Vector2.Zero;
-
-
- ///
- /// The last time the player was warned for build permissions.
- /// In MS, defaults to 1 (so it will warn on the first attempt).
- ///
- public long lastPermissionWarning = 1;
-
- ///
- /// The last time the player changed their team or pvp status.
- ///
- public DateTime LastPvPTeamChange;
-
- ///
- /// The last player that the player whispered with (to or from).
- ///
- public TSPlayer LastWhisper = null!;
-
- ///
- /// Whether the player has been harrassed about logging in due to server side inventory or forced login.
- ///
- public bool LoginHarassed = false;
-
- ///
- /// The time in ms when the player has logged in.
- ///
- public long LoginMS;
-
- ///
- /// Whether the player is muted or not.
- ///
- public bool mute;
-
- ///
- /// A timer to keep track of whether or not the player has recently thrown an explosive
- ///
- public int RecentFuse = 0;
-
- public bool RequestedSection;
-
- ///
- /// Easy check if a player has any of IsDisabledForSSC, IsDisabledForStackDetection, IsDisabledForBannedWearable,
- /// or IsDisabledPendingTrashRemoval set. Or if they're not logged in and a login is required.
- ///
- ///
- /// If any of the checks that warrant disabling are set on this player. If true, Disable() is repeatedly called on
- /// them.
- ///
- ///
- /// Whether the player needs to specify a password upon connection( either server or user account ).
- ///
- public bool RequiresPassword;
-
- ///
- /// A system to delay Remembered Position Teleports a few seconds
- ///
- public int RPPending = 0;
-
- public bool SilentJoinInProgress;
-
- public bool SilentKickInProgress;
-
- public bool SscLogin = false;
-
- public int sX = -1;
- public int sY = -1;
-
- ///
- /// Unused.
- ///
- public Vector2 TeleportCoords = new (-1, -1);
-
- ///
- /// The player's temporary group. This overrides the user's actual group.
- ///
- public Group tempGroup = null!;
-
- public Timer tempGroupTimer = null!;
-
- ///
- /// Temp points for use in regions and other plugins.
- ///
- public Point[] TempPoints = new Point[2];
-
- ///
- /// Whether other players can teleport to the player.
- ///
- public bool TPAllow = true;
-
- ///
- /// Logs the player out of an account.
- ///
- ///
- /// Initializes a new instance of the class.
- ///
- /// The player's index in the.
public TSPlayer(int index)
{
this.Index = index;
@@ -255,109 +80,28 @@ public TSPlayer(int index)
/// Initializes a new instance of the class.
///
/// The player's name.
- protected TSPlayer(string playerName)
+ private TSPlayer(string playerName)
{
this.Index = -1;
this.FakePlayer = new Player { name = playerName, whoAmI = -1 };
this.AwaitingResponse = new Dictionary>();
}
- ///
- /// Used in preventing players from seeing the npc spawnrate permission error on join.
- ///
- internal bool HasReceivedNPCPermissionError { get; set; }
-
- ///
- /// The amount of tiles that the player has killed in the last second.
- ///
- public int TileKillThreshold { get; set; }
-
- ///
- /// The amount of tiles the player has placed in the last second.
- ///
- public int TilePlaceThreshold { get; set; }
-
- ///
- /// The amount of liquid (in tiles) that the player has placed in the last second.
- ///
- public int TileLiquidThreshold { get; set; }
-
- ///
- /// The amount of tiles that the player has painted in the last second.
- ///
- public int PaintThreshold { get; set; }
+ public bool LoginQueue { get; set; }
- ///
- /// The number of projectiles created by the player in the last second.
- ///
- public int ProjectileThreshold { get; set; }
+ public bool SSCLogin { get; set; }
///
- /// The number of HealOtherPlayer packets sent by the player in the last second.
+ /// The players index in the player array.
///
- public int HealOtherThreshold { get; set; }
+ public int Index { get; }
- ///
- /// Whether to ignore packets that are SSC-relevant.
- ///
- public bool IgnoreSSCPackets { get; set; }
-
- ///
- /// A queue of tiles destroyed by the player for reverting.
- ///
- ///
- /// The player's group.
- ///
-
- public bool ReceivedInfo { get; set; }
-
- ///
- /// The players index in the player array( Main.players[] ).
- ///
- public int Index { get; protected set; }
-
- ///
- /// Whether the player is waiting to place/break a tile to set as a temp point.
- ///
- public int AwaitingTempPoint { get; set; }
-
- public bool AwaitingName { get; set; }
-
- public string[] AwaitingNameParameters { get; set; } = null!;
///
/// The last time a player broke a grief check.
///
public DateTime LastThreat { get; set; }
- ///
- /// The number of unsuccessful login attempts.
- ///
- public int LoginAttempts { get; set; }
-
- ///
- /// UserAccount object associated with the player.
- /// Set when the player logs in.
- ///
- ///
- /// Whether the player performed a valid login attempt (i.e. entered valid user name and password) but is still blocked
- /// from logging in because of SSI.
- ///
- public bool LoginFailsBySsi { get; set; }
-
- ///
- /// Whether the player has sent their whole inventory to the server while connecting.
- ///
- public bool HasSentInventory { get; set; }
-
- ///
- /// The player's respawn timer.
- ///
- public int RespawnTimer
- {
- get => this._respawnTimer;
- set => this.TPlayer.respawnTimer = (this._respawnTimer = value) * 60;
- }
///
/// Whether the player is dead or not.
@@ -370,37 +114,9 @@ public string UUID
set => UUIDs[this.Index] = value;
}
- ///
- /// The players difficulty( normal[softcore], mediumcore, hardcore ).
- ///
- public int Difficulty => this.TPlayer.difficulty;
-
- ///
- /// Controls the journey godmode
- ///
- public bool GodMode
- {
- get =>
- CreativePowerManager.Instance.GetPower().IsEnabledForPlayer(this.Index);
- set =>
- CreativePowerManager.Instance.GetPower().SetEnabledState(this.Index, value);
- }
- ///
- /// Whether the player is a real, human, player on the server.
- ///
public bool RealPlayer => this.Index >= 0 && this.Index < Main.maxNetPlayers && Main.player[this.Index] != null;
- ///
- /// Checks if the player is active and not pending termination.
- ///
- public bool ConnectionAlive =>
- this.RealPlayer && this.Client is { IsActive: true, PendingTermination: false };
-
- ///
- /// Gets the item that the player is currently holding.
- ///
- public Item SelectedItem => this.TPlayer.inventory[this.TPlayer.selectedItem];
///
/// Gets the player's Client State.
@@ -419,16 +135,13 @@ public string IP
{
get
{
- if (string.IsNullOrEmpty(this.CacheIP))
- {
- return this.CacheIP = (this.RealPlayer
+ return string.IsNullOrEmpty(this.CacheIP)
+ ? this.CacheIP = this.RealPlayer
? this.Client.Socket.IsConnected()
? this.Client.Socket.GetRemoteAddress().ToString()!.Split(':')[0]
: ""
- : "127.0.0.1")!;
- }
-
- return this.CacheIP;
+ : "127.0.0.1"
+ : this.CacheIP;
}
}
@@ -693,23 +406,11 @@ public object RemoveData(string key)
/// Disconnects the player from the server.
///
/// The reason why the player was disconnected.
- public virtual void Disconnect(string reason)
+ public void Disconnect(string reason)
{
this.SendData(MessageID.Kick, reason);
}
- ///
- /// Fired when the player's temporary group access expires.
- ///
- ///
- ///
- public void TempGroupTimerElapsed(object sender, ElapsedEventArgs args)
- {
- this.SendWarningMessage("Your temporary group access has expired.");
-
- this.tempGroup = null!;
- ((Timer) sender)?.Stop();
- }
///
/// Teleports the player to the given coordinates in the world.
@@ -771,7 +472,7 @@ public void Heal(int health = 600)
[Obsolete(
"This method may not send tiles the way you would expect it to. The (x,y) coordinates are the top left corner of the tile square, switch to " +
nameof(SendTileSquareCentered) + " if you wish for the coordindates to be the center of the square.")]
- public virtual bool SendTileSquare(int x, int y, int size = 10)
+ public bool SendTileSquare(int x, int y, int size = 10)
{
return this.SendTileRect((short) x, (short) y, (byte) size, (byte) size);
}
@@ -786,7 +487,7 @@ public virtual bool SendTileSquare(int x, int y, int size = 10)
/// The y coordinates of the center of the square.
/// The size square set of tiles to send.
/// true if the tile square was sent successfully, else false
- public virtual bool SendTileSquareCentered(int x, int y, byte size = 10)
+ public bool SendTileSquareCentered(int x, int y, byte size = 10)
{
return this.SendTileRect((short) (x - (size / 2)), (short) (y - (size / 2)), size, size);
}
@@ -800,7 +501,7 @@ public virtual bool SendTileSquareCentered(int x, int y, byte size = 10)
/// The length of the rectangle
/// Optional change type. Default None
///
- public virtual bool SendTileRect(short x, short y, byte width = 10, byte length = 10,
+ public bool SendTileRect(short x, short y, byte width = 10, byte length = 10,
TileChangeType changeType = TileChangeType.None)
{
try
@@ -860,7 +561,7 @@ public void UpdateSection(Rectangle? rectangle = null, bool isLoaded = false)
/// The item ID.
/// The item stack.
/// The item prefix.
- public virtual void GiveItem(int type, int stack, int prefix = 0)
+ public void GiveItem(int type, int stack, int prefix = 0)
{
this.GiveItemByDrop(type, stack, prefix);
}
@@ -904,7 +605,7 @@ private void GiveItemByDrop(int type, int stack, int prefix)
/// Sends an information message to the player.
///
/// The message.
- public virtual void SendInfoMessage(string? msg)
+ public void SendInfoMessage(string? msg)
{
this.SendMessage(msg, Color.Yellow);
}
@@ -924,7 +625,7 @@ public void SendInfoMessage(string format, params object[] args)
/// Sends a success message to the player.
///
/// The message.
- public virtual void SendSuccessMessage(string? msg)
+ public void SendSuccessMessage(string? msg)
{
this.SendMessage(msg, Color.LimeGreen);
}
@@ -944,7 +645,7 @@ public void SendSuccessMessage(string format, params object[] args)
/// Sends a warning message to the player.
///
/// The message.
- public virtual void SendWarningMessage(string? msg)
+ public void SendWarningMessage(string? msg)
{
this.SendMessage(msg, Color.OrangeRed);
}
@@ -964,7 +665,7 @@ public void SendWarningMessage(string format, params object[] args)
/// Sends an error message to the player.
///
/// The message.
- public virtual void SendErrorMessage(string? msg)
+ public void SendErrorMessage(string? msg)
{
this.SendMessage(msg, Color.Red);
}
@@ -985,7 +686,7 @@ public void SendErrorMessage(string format, params object[] args)
///
/// The message.
/// The message color.
- public virtual void SendMessage(string? msg, Color color)
+ public void SendMessage(string? msg, Color color)
{
this.SendMessage(msg!, color.R, color.G, color.B);
}
@@ -997,7 +698,7 @@ public virtual void SendMessage(string? msg, Color color)
/// The amount of red color to factor in. Max: 255.
/// The amount of green color to factor in. Max: 255
/// The amount of blue color to factor in. Max: 255
- public virtual void SendMessage(string msg, byte red, byte green, byte blue)
+ public void SendMessage(string msg, byte red, byte green, byte blue)
{
if (msg.Contains("\n"))
{
@@ -1030,7 +731,7 @@ public virtual void SendMessage(string msg, byte red, byte green, byte blue)
/// The amount of green color to factor in. Max: 255.
/// The amount of blue color to factor in. Max: 255.
/// The player who receives the message.
- public virtual void SendMessageFromPlayer(string msg, byte red, byte green, byte blue, int ply)
+ public void SendMessageFromPlayer(string msg, byte red, byte green, byte blue, int ply)
{
if (msg.Contains("\n"))
{
@@ -1052,7 +753,7 @@ public virtual void SendMessageFromPlayer(string msg, byte red, byte green, byte
/// Wounds the player with the given damage.
///
/// The amount of damage the player will take.
- public virtual void DamagePlayer(int damage)
+ public void DamagePlayer(int damage)
{
this.DamagePlayer(damage, PlayerDeathReason.LegacyDefault());
}
@@ -1062,7 +763,7 @@ public virtual void DamagePlayer(int damage)
///
/// The amount of damage the player will take.
/// The reason for causing damage to player.
- public virtual void DamagePlayer(int damage, PlayerDeathReason reason)
+ public void DamagePlayer(int damage, PlayerDeathReason reason)
{
NetMessage.SendPlayerHurt(this.Index, new Player.HurtInfo { Damage = damage, DamageSource = reason });
}
@@ -1070,7 +771,7 @@ public virtual void DamagePlayer(int damage, PlayerDeathReason reason)
///
/// Kills the player.
///
- public virtual void KillPlayer()
+ public void KillPlayer()
{
this.KillPlayer(PlayerDeathReason.LegacyDefault());
}
@@ -1079,7 +780,7 @@ public virtual void KillPlayer()
/// Kills the player.
///
/// Reason for killing a player.
- public virtual void KillPlayer(PlayerDeathReason reason)
+ public void KillPlayer(PlayerDeathReason reason)
{
NetMessage.SendPlayerDeath(this.Index, reason, 99999, new Random().Next(-1, 1), false);
}
@@ -1088,7 +789,7 @@ public virtual void KillPlayer(PlayerDeathReason reason)
/// Sets the player's team.
///
/// The team color index.
- public virtual void SetTeam(int team)
+ public void SetTeam(int team)
{
if (team < 0 || team >= Main.teamColor.Length)
{
@@ -1104,7 +805,7 @@ public virtual void SetTeam(int team)
///
/// The state of the pvp mode.
/// Whether a chat message about the change should be sent.
- public virtual void SetPvP(bool mode, bool withMsg = false)
+ public void SetPvP(bool mode, bool withMsg = false)
{
Main.player[this.Index].hostile = mode;
NetMessage.SendData(MessageID.TogglePVP, -1, -1, NetworkText.Empty, this.Index);
@@ -1133,29 +834,13 @@ public void SendMultipleMatchError(IEnumerable