Merge pull request #871 from Enerdy/general-devel

Update deprecated SendData code, a few log methods, add command specifier to possibly everything
This commit is contained in:
Lucas Nicodemus 2015-02-28 09:15:48 -07:00
commit b3d00fa8f5
4 changed files with 298 additions and 282 deletions

File diff suppressed because it is too large Load diff

View file

@ -1261,7 +1261,7 @@ namespace TShockAPI
}
catch (Exception ex)
{
Log.Error(ex.ToString());
TShock.Log.Error(ex.ToString());
return true;
}
}
@ -1469,7 +1469,7 @@ namespace TShockAPI
TShock.CharacterDB.InsertPlayerData(args.Player);
}
args.Player.SendMessage("Authenticated as " + args.Player.Name + " successfully.", Color.LimeGreen);
Log.ConsoleInfo(args.Player.Name + " authenticated successfully as user " + args.Player.Name + ".");
TShock.Log.ConsoleInfo(args.Player.Name + " authenticated successfully as user " + args.Player.Name + ".");
Hooks.PlayerHooks.OnPlayerPostLogin(args.Player);
return true;
}
@ -1547,7 +1547,7 @@ namespace TShockAPI
TShock.CharacterDB.InsertPlayerData(args.Player);
}
args.Player.SendMessage("Authenticated as " + args.Player.Name + " successfully.", Color.LimeGreen);
Log.ConsoleInfo(args.Player.Name + " authenticated successfully as user " + args.Player.Name + ".");
TShock.Log.ConsoleInfo(args.Player.Name + " authenticated successfully as user " + args.Player.Name + ".");
TShock.Users.SetUserUUID(user, args.Player.UUID);
Hooks.PlayerHooks.OnPlayerPostLogin(args.Player);
return true;
@ -2239,27 +2239,23 @@ namespace TShockAPI
{
if (args.Player.IgnoreActionsForCheating != "none")
{
args.Player.SendMessage("Disabled for cheating: " + args.Player.IgnoreActionsForCheating,
Color.Red);
args.Player.SendErrorMessage("Disabled for cheating: " + args.Player.IgnoreActionsForCheating);
}
else if (args.Player.IgnoreActionsForDisabledArmor != "none")
{
args.Player.SendMessage(
"Disabled for banned armor: " + args.Player.IgnoreActionsForDisabledArmor, Color.Red);
args.Player.SendErrorMessage("Disabled for banned armor: " + args.Player.IgnoreActionsForDisabledArmor);
}
else if (args.Player.IgnoreActionsForInventory != "none")
{
args.Player.SendMessage(
"Disabled for Server Side Inventory: " + args.Player.IgnoreActionsForInventory,
Color.Red);
args.Player.SendErrorMessage("Disabled for Server Side Inventory: " + args.Player.IgnoreActionsForInventory);
}
else if (TShock.Config.RequireLogin && !args.Player.IsLoggedIn)
{
args.Player.SendMessage("Please /register or /login to play!", Color.Red);
args.Player.SendErrorMessage("Please /register or /login to play!");
}
else if (args.Player.IgnoreActionsForClearingTrashCan)
{
args.Player.SendMessage("You need to rejoin to ensure your trash can is cleared!", Color.Red);
args.Player.SendErrorMessage("You need to rejoin to ensure your trash can is cleared!");
}
var lastTileX = args.Player.LastNetPosition.X;
var lastTileY = args.Player.LastNetPosition.Y - 48;
@ -2299,9 +2295,8 @@ namespace TShockAPI
{
control[5] = false;
args.Player.Disable("Using banned item");
args.Player.SendMessage(
string.Format("You cannot use {0} on this server. Your actions are being ignored.",
args.TPlayer.inventory[item].name), Color.Red);
args.Player.SendErrorMessage("You cannot use {0} on this server. Your actions are being ignored.",
args.TPlayer.inventory[item].name);
}
if (args.TPlayer.inventory[item].name == "Mana Crystal" && args.Player.TPlayer.statManaMax <= 180)
@ -2579,7 +2574,7 @@ namespace TShockAPI
if (dmg > 20000) //Abnormal values have the potential to cause infinite loops in the server.
{
TShock.Utils.ForceKick(args.Player, "Crash Exploit Attempt", true);
Log.ConsoleError("Death Exploit Attempt: Damage {0}", dmg);
TShock.Log.ConsoleError("Death Exploit Attempt: Damage {0}", dmg);
return false;
}
@ -2970,7 +2965,7 @@ namespace TShockAPI
if (!args.Player.Group.HasPermission(Permissions.movenpc))
{
args.Player.SendMessage("You do not have permission to relocate NPCs.", Color.Red);
args.Player.SendErrorMessage("You do not have permission to relocate NPCs.");
args.Player.SendData(PacketTypes.UpdateNPCHome, "", id, Main.npc[id].homeTileX, Main.npc[id].homeTileY,
Convert.ToByte(Main.npc[id].homeless));
return true;
@ -2978,7 +2973,7 @@ namespace TShockAPI
if (TShock.CheckTilePermission(args.Player, x, y))
{
args.Player.SendMessage( "You do not have access to modify this area.", Color.Red);
args.Player.SendErrorMessage( "You do not have access to modify this area.");
args.Player.SendData(PacketTypes.UpdateNPCHome, "", id, Main.npc[id].homeTileX, Main.npc[id].homeTileY,
Convert.ToByte(Main.npc[id].homeless));
return true;
@ -3099,7 +3094,7 @@ namespace TShockAPI
if ((Main.ServerSideCharacter) && (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond - args.Player.LoginMS < TShock.ServerSideCharacterConfig.LogonDiscardThreshold))
{
//Player is probably trying to sneak items onto the server in their hands!!!
Log.ConsoleInfo(string.Format("Player {0} tried to sneak {1} onto the server!", args.Player.Name, item.name));
TShock.Log.ConsoleInfo("Player {0} tried to sneak {1} onto the server!", args.Player.Name, item.name);
args.Player.SendData(PacketTypes.ItemDrop, "", id);
return true;
@ -3382,12 +3377,12 @@ namespace TShockAPI
}
if (spawnboss && !args.Player.Group.HasPermission(Permissions.summonboss))
{
args.Player.SendMessage("You don't have permission to summon a boss.", Color.Red);
args.Player.SendErrorMessage("You don't have permission to summon a boss.");
return true;
}
if (invasion && !args.Player.Group.HasPermission(Permissions.startinvasion))
{
args.Player.SendMessage("You don't have permission to start an invasion.", Color.Red);
args.Player.SendErrorMessage("You don't have permission to start an invasion.");
return true;
}
if (!spawnboss && !invasion)

View file

@ -372,28 +372,28 @@ namespace TShockAPI
}
}
/// <summary>
/// Saves the player's inventory to SSI
/// </summary>
/// <returns>bool - True/false if it saved successfully</returns>
public bool SaveServerCharacter()
{
if (!Main.ServerSideCharacter)
{
return false;
}
try
{
PlayerData.CopyCharacter(this);
TShock.CharacterDB.InsertPlayerData(this);
return true;
} catch (Exception e)
{
Log.Error(e.Message);
return false;
}
}
/// <summary>
/// Saves the player's inventory to SSI
/// </summary>
/// <returns>bool - True/false if it saved successfully</returns>
public bool SaveServerCharacter()
{
if (!Main.ServerSideCharacter)
{
return false;
}
try
{
PlayerData.CopyCharacter(this);
TShock.CharacterDB.InsertPlayerData(this);
return true;
}
catch (Exception e)
{
TShock.Log.Error(e.Message);
return false;
}
}
/// <summary>
/// Sends the players server side character to client
@ -412,7 +412,7 @@ namespace TShockAPI
}
catch (Exception e)
{
Log.Error(e.Message);
TShock.Log.Error(e.Message);
return false;
}
@ -707,7 +707,7 @@ namespace TShockAPI
}
catch (Exception ex)
{
Log.Error(ex.ToString());
TShock.Log.Error(ex.ToString());
}
return false;
}
@ -836,11 +836,11 @@ namespace TShockAPI
{
if (displayConsole)
{
Log.ConsoleInfo(string.Format("Player {0} has been disabled for {1}.", Name, reason));
TShock.Log.ConsoleInfo("Player {0} has been disabled for {1}.", Name, reason);
}
else
{
Log.Info("Player {0} has been disabled for {1}.", Name, reason);
TShock.Log.Info("Player {0} has been disabled for {1}.", Name, reason);
}
LastDisableNotification = DateTime.UtcNow;
}
@ -857,7 +857,7 @@ namespace TShockAPI
var time2 = (int) time;
var launch = DateTime.UtcNow;
var startname = Name;
SendMessage("You are now being annoyed.", Color.Red);
SendInfoMessage("You are now being annoyed.");
while ((DateTime.UtcNow - launch).TotalSeconds < time2 && startname == Name)
{
SendData(PacketTypes.NpcSpecial, number: Index, number2: 2f);

View file

@ -250,7 +250,7 @@ namespace TShockAPI
if (Config.EnableGeoIP && File.Exists(geoippath))
Geo = new GeoIPCountry(geoippath);
Log.ConsoleInfo(string.Format("TShock {0} ({1}) now running.", Version, VersionCodename));
Log.ConsoleInfo("TShock {0} ({1}) now running.", Version, VersionCodename);
ServerApi.Hooks.GamePostInitialize.Register(this, OnPostInit);
ServerApi.Hooks.GameUpdate.Register(this, OnUpdate);
@ -596,8 +596,8 @@ namespace TShockAPI
var r = new Random((int) DateTime.Now.ToBinary());
AuthToken = r.Next(100000, 10000000);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("TShock Notice: To become SuperAdmin, join the game and type /auth " + AuthToken);
Console.WriteLine("This token will display until disabled by verification. (/auth-verify)");
Console.WriteLine("TShock Notice: To become SuperAdmin, join the game and type {0}auth {1}", Commands.Specifier, AuthToken);
Console.WriteLine("This token will display until disabled by verification. ({0}auth-verify)", Commands.Specifier);
Console.ForegroundColor = ConsoleColor.Gray;
FileTools.CreateFile(Path.Combine(SavePath, "authcode.txt"));
using (var tw = new StreamWriter(Path.Combine(SavePath, "authcode.txt")))
@ -614,8 +614,8 @@ namespace TShockAPI
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(
"TShock Notice: authcode.txt is still present, and the AuthToken located in that file will be used.");
Console.WriteLine("To become superadmin, join the game and type /auth " + AuthToken);
Console.WriteLine("This token will display until disabled by verification. (/auth-verify)");
Console.WriteLine("To become superadmin, join the game and type {0}auth {1}", Commands.Specifier, AuthToken);
Console.WriteLine("This token will display until disabled by verification. ({0}auth-verify)", Commands.Specifier);
Console.ForegroundColor = ConsoleColor.Gray;
}
else
@ -829,7 +829,7 @@ namespace TShockAPI
player.SetBuff(36, 120); //Broken Armor
check = "Remove armor/accessory " + item.name;
player.SendErrorMessage(string.Format("You are wearing banned equipment. {0}", check));
player.SendErrorMessage("You are wearing banned equipment. {0}", check);
break;
}
}
@ -1015,7 +1015,7 @@ namespace TShockAPI
{
if (!tsplr.SilentKickInProgress && tsplr.State >= 3)
Utils.Broadcast(tsplr.Name + " has left.", Color.Yellow);
Log.Info(string.Format("{0} disconnected.", tsplr.Name));
Log.Info("{0} disconnected.", tsplr.Name);
if (tsplr.IsLoggedIn && !tsplr.IgnoreActionsForClearingTrashCan && Main.ServerSideCharacter && (!tsplr.Dead || tsplr.TPlayer.difficulty != 2))
{
@ -1114,7 +1114,7 @@ namespace TShockAPI
tsplr.SendMessage(msg, tsplr.Group.R, tsplr.Group.G, tsplr.Group.B);
TSPlayer.Server.SendMessage(msg, tsplr.Group.R, tsplr.Group.G, tsplr.Group.B);
Log.Info(string.Format("Broadcast: {0}", msg));
Log.Info("Broadcast: {0}", msg);
args.Handled = true;
}
}
@ -1140,7 +1140,7 @@ namespace TShockAPI
WorldGen.genRand = new Random();
}
if (args.Command.StartsWith("playing") || args.Command.StartsWith("/playing"))
if (args.Command.StartsWith("playing") || args.Command.StartsWith("{0}playing".SFormat(Commands.Specifier)))
{
int count = 0;
foreach (TSPlayer player in Players)
@ -1148,18 +1148,18 @@ namespace TShockAPI
if (player != null && player.Active)
{
count++;
TSPlayer.Server.SendInfoMessage(string.Format("{0} ({1}) [{2}] <{3}>", player.Name, player.IP,
player.Group.Name, player.UserAccountName));
TSPlayer.Server.SendInfoMessage("{0} ({1}) [{2}] <{3}>", player.Name, player.IP,
player.Group.Name, player.UserAccountName);
}
}
TSPlayer.Server.SendInfoMessage(string.Format("{0} players connected.", count));
TSPlayer.Server.SendInfoMessage("{0} players connected.", count);
}
else if (args.Command == "autosave")
{
Main.autoSave = Config.AutoSave = !Config.AutoSave;
Log.ConsoleInfo("AutoSave " + (Config.AutoSave ? "Enabled" : "Disabled"));
}
else if (args.Command.StartsWith("/"))
else if (args.Command.StartsWith(Commands.Specifier))
{
Commands.HandleCommand(TSPlayer.Server, args.Command);
}
@ -1219,16 +1219,16 @@ namespace TShockAPI
if (Config.EnableGeoIP && TShock.Geo != null)
{
Log.Info(string.Format("{0} ({1}) from '{2}' group from '{3}' joined. ({4}/{5})", player.Name, player.IP,
Log.Info("{0} ({1}) from '{2}' group from '{3}' joined. ({4}/{5})", player.Name, player.IP,
player.Group.Name, player.Country, TShock.Utils.ActivePlayers(),
TShock.Config.MaxSlots));
TShock.Config.MaxSlots);
if (!player.SilentJoinInProgress)
Utils.Broadcast(string.Format("{0} ({1}) has joined.", player.Name, player.Country), Color.Yellow);
}
else
{
Log.Info(string.Format("{0} ({1}) from '{2}' group joined. ({3}/{4})", player.Name, player.IP,
player.Group.Name, TShock.Utils.ActivePlayers(), TShock.Config.MaxSlots));
Log.Info("{0} ({1}) from '{2}' group joined. ({3}/{4})", player.Name, player.IP,
player.Group.Name, TShock.Utils.ActivePlayers(), TShock.Config.MaxSlots);
if (!player.SilentJoinInProgress)
Utils.Broadcast(player.Name + " has joined.", Color.Yellow);
}
@ -1250,14 +1250,13 @@ namespace TShockAPI
{
if (Main.ServerSideCharacter)
{
player.SendMessage(
player.IgnoreActionsForInventory = "Server side characters is enabled! Please /register or /login to play!",
Color.Red);
player.SendErrorMessage(
player.IgnoreActionsForInventory = "Server side characters is enabled! Please {0}register or {0}login to play!", Commands.Specifier);
player.LoginHarassed = true;
}
else if (Config.RequireLogin)
{
player.SendMessage("Please /register or /login to play!", Color.Red);
player.SendErrorMessage("Please {0}register or {0}login to play!", Commands.Specifier);
player.LoginHarassed = true;
}
}
@ -1267,7 +1266,7 @@ namespace TShockAPI
if (Config.RememberLeavePos && (RememberedPos.GetLeavePos(player.Name, player.IP) != Vector2.Zero) && !player.LoginHarassed)
{
player.RPPending = 3;
player.SendMessage("You will be teleported to your last known location...", Color.Red);
player.SendInfoMessage("You will be teleported to your last known location...");
}
args.Handled = true;
@ -1579,7 +1578,7 @@ namespace TShockAPI
if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.BPm) > 2000)
{
player.SendMessage("You do not have permission to build!", Color.Red);
player.SendErrorMessage("You do not have permission to build!");
player.BPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
}
return true;
@ -1593,7 +1592,7 @@ namespace TShockAPI
if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.BPm) > 2000)
{
player.SendMessage("You do not have permission to build!", Color.Red);
player.SendErrorMessage("You do not have permission to build!");
player.BPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
}
return true;
@ -1604,7 +1603,7 @@ namespace TShockAPI
{
if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.RPm) > 2000)
{
player.SendMessage("This region is protected from changes.", Color.Red);
player.SendErrorMessage("This region is protected from changes.");
player.RPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
}
return true;
@ -1616,7 +1615,7 @@ namespace TShockAPI
{
if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.WPm) > 2000)
{
player.SendMessage("The world is protected from changes.", Color.Red);
player.SendErrorMessage("The world is protected from changes.");
player.WPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
}
return true;
@ -1631,7 +1630,7 @@ namespace TShockAPI
{
if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.SPm) > 2000)
{
player.SendMessage("Spawn is protected from changes.", Color.Red);
player.SendErrorMessage("Spawn is protected from changes.");
player.SPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
}
return true;
@ -1648,7 +1647,7 @@ namespace TShockAPI
{
if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.BPm) > 2000)
{
player.SendMessage("You do not have permission to build!", Color.Red);
player.SendErrorMessage("You do not have permission to build!");
player.BPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
}
return true;
@ -1659,7 +1658,7 @@ namespace TShockAPI
{
if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.RPm) > 2000)
{
player.SendMessage("This region is protected from changes.", Color.Red);
player.SendErrorMessage("This region is protected from changes.");
player.RPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
}
return true;
@ -1671,7 +1670,7 @@ namespace TShockAPI
{
if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.WPm) > 2000)
{
player.SendMessage("The world is protected from changes.", Color.Red);
player.SendErrorMessage("The world is protected from changes.");
player.WPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
}
return true;
@ -1686,7 +1685,7 @@ namespace TShockAPI
{
if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.SPm) > 1000)
{
player.SendMessage("Spawn is protected from changes.", Color.Red);
player.SendErrorMessage("Spawn is protected from changes.");
player.SPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
}
return true;