Removed lua, because it shouldnt be here.

Attempted hotfix of trashcan abuse.  User's inventory shouldn't be saved if they are being nagged about logging out.
This commit is contained in:
Zack Piispanen 2012-01-12 18:00:05 -05:00
parent 491eafd484
commit 4c4cd4027d
6 changed files with 153 additions and 285 deletions

View file

@ -134,6 +134,7 @@ namespace TShockAPI
add(Permissions.maintenance, CheckUpdates, "checkupdates");
add(Permissions.causeevents, DropMeteor, "dropmeteor");
add(Permissions.causeevents, Star, "star");
add(Permissions.causeevents, Ore, "genore");
add(Permissions.causeevents, Fullmoon, "fullmoon");
add(Permissions.causeevents, Bloodmoon, "bloodmoon");
add(Permissions.causeevents, Invade, "invade");
@ -211,10 +212,6 @@ namespace TShockAPI
add(Permissions.cfg, ServerInfo, "stats");
add(Permissions.converthardmode, ConvertCorruption, "convertcorruption");
add(Permissions.converthardmode, ConvertHallow, "converthallow");
add(Permissions.runlua, RunLuaFile, "luarun");
add(Permissions.runlua, RunLuaString, "lua");
add(Permissions.runlua, ReloadLua, "luareload");
add(Permissions.runlua, TestLuaHook, "testhook");
}
public static bool HandleCommand(TSPlayer player, string text)
@ -332,43 +329,6 @@ namespace TShockAPI
return c == ' ' || c == '\t' || c == '\n';
}
#region Lua Commands
public static void TestLuaHook(CommandArgs args)
{
TShock.LuaLoader.HookCalls.OnHookTest();
}
public static void ReloadLua(CommandArgs args)
{
TShock.LuaLoader.LoadServerAutoruns();
args.Player.SendMessage("Lua reloaded.");
}
public static void RunLuaString(CommandArgs args)
{
if (args.Parameters.Count < 1)
{
args.Player.SendMessage("Syntax: /lua <lua>");
return;
}
TShock.LuaLoader.RunLuaString(args.Parameters[0]);
args.Player.SendMessage("Lua run: " + args.Parameters[0]);
}
public static void RunLuaFile(CommandArgs args)
{
if (args.Parameters.Count != 1)
{
args.Player.SendMessage("Syntax: /luarun <file>");
return;
}
TShock.LuaLoader.RunLuaFile(args.Parameters[0]);
}
#endregion
#region Account commands
public static void AttemptLogin(CommandArgs args)
@ -437,10 +397,12 @@ namespace TShockAPI
args.Player.IsLoggedIn = true;
args.Player.IgnoreActionsForInventory = "none";
args.Player.PlayerData.CopyInventory(args.Player);
TShock.InventoryDB.InsertPlayerData(args.Player);
args.Player.SendMessage("Authenticated as " + user.Name + " successfully.", Color.LimeGreen);
if (!args.Player.IgnoreActionsForClearingTrashCan)
{
args.Player.PlayerData.CopyInventory(args.Player);
TShock.InventoryDB.InsertPlayerData(args.Player);
}
args.Player.SendMessage("Authenticated as " + user.Name + " successfully.", Color.LimeGreen);
Log.ConsoleInfo(args.Player.Name + " authenticated successfully as user: " + user.Name);
}
else
@ -1023,6 +985,114 @@ namespace TShockAPI
Projectile.NewProjectile(vector.X, vector.Y, speedX, speedY, 12, 0x3e8, 10f, Main.myPlayer);
}
private static void Ore(CommandArgs args)
{
if (WorldGen.genRand == null)
WorldGen.genRand = new Random();
TSPlayer ply = args.Player;
int num = WorldGen.altarCount % 3;
int num2 = WorldGen.altarCount / 3 + 1;
float num3 = (float)(Main.maxTilesX / 4200);
int num4 = 1 - num;
num3 = num3 * 310f - (float)(85 * num);
num3 *= 0.85f;
num3 /= (float)num2;
if (args.Parameters.Count < 1)
{
ply.SendMessage("Picking a random ore!", Color.Green);
num = WorldGen.genRand.Next(2);
}
else if (args.Parameters[0] == "cobalt")
{
num = 0;
}
else if (args.Parameters[0] == "mythril")
{
num = 1;
}
else if (args.Parameters[0] == "cobalt")
{
num = 0;
}
else
{
num = 2;
}
if (num == 0)
{
num = 107;
num3 *= 1.05f;
}
else if (num == 1)
{
num = 108;
}
else
{
num = 111;
}
if (args.Parameters[0] == "iron")
{
num = 11;
}
else if (args.Parameters[0] == "gold")
{
num = 13;
}
else if (args.Parameters[0] == "silver")
{
num = 14;
}
else if (args.Parameters[0] == "copper")
{
num = 12;
}
else if (args.Parameters[0] == "demonite")
{
num = 22;
}
else if (args.Parameters[0] == "meteorite")
{
num = 116;
}
else if (args.Parameters[0] == "hellstone")
{
num = 58;
}
if (args.Parameters.Count > 1)
{
float.TryParse(args.Parameters[1], out num3);
//num3 = Math.Min(num3, 1000f);
}
int num5 = 0;
while ((float)num5 < num3)
{
int i2 = WorldGen.genRand.Next(100, Main.maxTilesX - 100);
double num6 = Main.worldSurface;
if (num == 108)
{
num6 = Main.rockLayer;
}
if (num == 111)
{
num6 = (Main.rockLayer + Main.rockLayer + (double)Main.maxTilesY) / 3.0;
}
int j2 = WorldGen.genRand.Next((int)num6, Main.maxTilesY - 150);
WorldGen.OreRunner(i2, j2, 20.0, 20, num);
num5++;
}
ply.SendMessage(String.Format("Spawned {0} tiles of {1}", Math.Floor(num3), num), Color.Green );
}
private static void Fullmoon(CommandArgs args)
{
TSPlayer.Server.SetFullMoon(true);

View file

@ -891,45 +891,47 @@ namespace TShockAPI
string encrPass = TShock.Utils.HashPassword(password);
if (user.Password.ToUpper() == encrPass.ToUpper())
{
args.Player.RequiresPassword = false;
args.Player.PlayerData = TShock.InventoryDB.GetPlayerData(args.Player, TShock.Users.GetUserID(args.Player.Name));
args.Player.RequiresPassword = false;
args.Player.PlayerData = TShock.InventoryDB.GetPlayerData(args.Player, TShock.Users.GetUserID(args.Player.Name));
if (args.Player.State == 1)
args.Player.State = 2;
NetMessage.SendData((int) PacketTypes.WorldInfo, args.Player.Index);
if (args.Player.State == 1)
args.Player.State = 2;
NetMessage.SendData((int) PacketTypes.WorldInfo, args.Player.Index);
var group = TShock.Utils.GetGroup(user.Group);
var group = TShock.Utils.GetGroup(user.Group);
if (TShock.Config.ServerSideInventory)
{
if (group.HasPermission(Permissions.bypassinventorychecks))
{
args.Player.IgnoreActionsForClearingTrashCan = false;
}
else if (!TShock.CheckInventory(args.Player))
{
args.Player.SendMessage("Login Failed, Please fix the above errors then /login again.", Color.Cyan);
args.Player.IgnoreActionsForClearingTrashCan = true;
return true;
}
}
if (TShock.Config.ServerSideInventory)
{
if (group.HasPermission(Permissions.bypassinventorychecks))
{
args.Player.IgnoreActionsForClearingTrashCan = false;
}
else if (!TShock.CheckInventory(args.Player))
{
args.Player.SendMessage("Login Failed, Please fix the above errors then /login again.", Color.Cyan);
args.Player.IgnoreActionsForClearingTrashCan = true;
return true;
}
}
if (group.HasPermission(Permissions.ignorestackhackdetection))
args.Player.IgnoreActionsForCheating = "none";
if (group.HasPermission(Permissions.ignorestackhackdetection))
args.Player.IgnoreActionsForCheating = "none";
if (group.HasPermission(Permissions.usebanneditem))
args.Player.IgnoreActionsForDisabledArmor = "none";
if (group.HasPermission(Permissions.usebanneditem))
args.Player.IgnoreActionsForDisabledArmor = "none";
args.Player.Group = group;
args.Player.UserAccountName = args.Player.Name;
args.Player.UserID = TShock.Users.GetUserID(args.Player.UserAccountName);
args.Player.IsLoggedIn = true;
args.Player.IgnoreActionsForInventory = "none";
args.Player.Group = group;
args.Player.UserAccountName = args.Player.Name;
args.Player.UserID = TShock.Users.GetUserID(args.Player.UserAccountName);
args.Player.IsLoggedIn = true;
args.Player.IgnoreActionsForInventory = "none";
args.Player.PlayerData.CopyInventory(args.Player);
TShock.InventoryDB.InsertPlayerData(args.Player);
args.Player.SendMessage("Authenticated as " + args.Player.Name + " successfully.", Color.LimeGreen);
if (!args.Player.IgnoreActionsForClearingTrashCan)
{
args.Player.PlayerData.CopyInventory(args.Player);
TShock.InventoryDB.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);
return true;
}

View file

@ -1,191 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.ComponentModel;
using LuaInterface;
namespace TShockAPI.LuaSystem
{
public class LuaLoader
{
private readonly Lua _lua = null;
public string LuaPath = "";
public string LuaAutorunPath = "";
public LuaHookBackend HookBackend = new LuaHookBackend();
public LuaHooks HookCalls = new LuaHooks();
public Dictionary<string, KeyValuePair<string, LuaFunction>> Hooks = new Dictionary
<string, KeyValuePair<string, LuaFunction>>();
public LuaLoader(string path)
{
_lua = new Lua();
LuaPath = path;
LuaAutorunPath = Path.Combine(LuaPath, "autorun");
SendLuaDebugMsg("Lua 5.1 (serverside) initialized.");
if (!string.IsNullOrEmpty(LuaPath) && !Directory.Exists(LuaPath))
{
Directory.CreateDirectory(LuaPath);
}
if (!string.IsNullOrEmpty(LuaAutorunPath) && !Directory.Exists(LuaAutorunPath))
{
Directory.CreateDirectory(LuaAutorunPath);
}
RegisterLuaFunctions();
LoadServerAutoruns();
}
public void LoadServerAutoruns()
{
try
{
foreach (string s in Directory.GetFiles(LuaAutorunPath))
{
SendLuaDebugMsg("Loading: " + s);
RunLuaFile(s);
}
}
catch (Exception e)
{
SendLuaDebugMsg(e.Message);
SendLuaDebugMsg(e.StackTrace);
}
}
public void RunLuaString(string s)
{
try
{
_lua.DoString(s);
}
catch (LuaException e)
{
SendLuaDebugMsg(e.Message);
}
}
public void RunLuaFile(string s)
{
try
{
_lua.DoFile(s);
}
catch (LuaException e)
{
SendLuaDebugMsg(e.Message);
}
}
public void SendLuaDebugMsg(string s)
{
ConsoleColor previousColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("Lua: " + s);
Console.ForegroundColor = previousColor;
}
public void RegisterLuaFunctions()
{
//I just added all the managers for Plugin Development. :)
//Feel free to remove any if you dont feel they are necessay
_lua["Players"] = TShock.Players;
_lua["Bans"] = TShock.Bans;
_lua["Warps"] = TShock.Warps;
_lua["Regions"] = TShock.Regions;
_lua["Backups"] = TShock.Backups;
_lua["Groups"] = TShock.Groups;
_lua["Users"] = TShock.Users;
_lua["Itembans"] = TShock.Users;
LuaFunctions LuaFuncs = new LuaFunctions(this);
var LuaFuncMethods = LuaFuncs.GetType().GetMethods();
foreach (System.Reflection.MethodInfo method in LuaFuncMethods)
{
_lua.RegisterFunction(method.Name, LuaFuncs, method);
}
//Utils
Utils LuaUtils = new Utils(this);
var LuaUtilMethods = LuaUtils.GetType().GetMethods();
foreach (System.Reflection.MethodInfo method in LuaUtilMethods)
{
_lua.RegisterFunction(method.Name, LuaUtils, method);
}
}
}
public class LuaFunctions
{
LuaLoader Parent;
public LuaFunctions(LuaLoader parent)
{
Parent = parent;
}
[Description("Prints a message to the console from the Lua debugger.")]
public void Print(string s)
{
ConsoleColor previousColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(s);
Console.ForegroundColor = previousColor;
}
[Description("Adds a hook that will trigger a function callback when activated.")]
public void HookAdd(string hook, string key, LuaFunction callback)
{
KeyValuePair<string, LuaFunction> internalhook = new KeyValuePair<string, LuaFunction>(hook, callback);
Parent.Hooks.Add(key, internalhook);
}
[Description("Removes a hook from the hook table. Good for reloading stuff.")]
public void HookRemove(string key)
{
Parent.Hooks.Remove(key);
}
}
public class LuaHookBackend
{
public void HookRun(string call, object parameters)
{
foreach (KeyValuePair<string, KeyValuePair<string, LuaFunction>> kv in TShock.LuaLoader.Hooks)
{
KeyValuePair<string, LuaFunction> hook = kv.Value;
if (call == hook.Key)
{
LuaFunction lf = hook.Value;
if (lf != null)
{
try
{
lf.Call(parameters);
}
catch (LuaException e)
{
TShock.LuaLoader.SendLuaDebugMsg(e.Message);
}
}
}
}
}
}
public class LuaHooks
{
[Description("Called on debug hook test.")]
public void OnHookTest()
{
object[] response = new object[2];
response[0] = true;
response[1] = "Hook win!";
TShock.LuaLoader.HookBackend.HookRun("HookTest", response);
}
}
}

View file

@ -31,7 +31,6 @@ using MaxMind;
using Mono.Data.Sqlite;
using MySql.Data.MySqlClient;
using Rests;
using TShockAPI.LuaSystem;
using Terraria;
using TShockAPI.DB;
using TShockAPI.Net;
@ -65,7 +64,6 @@ namespace TShockAPI
public static RestManager RestManager;
public static Utils Utils = new Utils();
public static StatTracker StatTracker = new StatTracker();
public static LuaLoader LuaLoader;
/// <summary>
/// Called after TShock is initialized. Useful for plugins that needs hooks before tshock but also depend on tshock being loaded.
@ -422,7 +420,6 @@ namespace TShockAPI
StatTracker.CheckIn();
FixChestStacks();
LuaLoader = new LuaLoader(Path.Combine(".", "lua"));
}
private void FixChestStacks()
@ -462,8 +459,9 @@ namespace TShockAPI
foreach (TSPlayer player in Players)
{
// prevent null point exceptions
if (player != null && player.IsLoggedIn)
if (player != null && player.IsLoggedIn && !player.IgnoreActionsForClearingTrashCan)
{
InventoryDB.InsertPlayerData(player);
}
}
@ -666,7 +664,7 @@ namespace TShockAPI
}
Log.Info(string.Format("{0} left.", tsplr.Name));
if (tsplr.IsLoggedIn)
if (tsplr.IsLoggedIn && !tsplr.IgnoreActionsForClearingTrashCan)
{
tsplr.PlayerData.CopyInventory(tsplr);
InventoryDB.InsertPlayerData(tsplr);

View file

@ -53,9 +53,6 @@
<Reference Include="HttpServer">
<HintPath>..\HttpBins\HttpServer.dll</HintPath>
</Reference>
<Reference Include="LuaInterface">
<HintPath>..\LuaBins\LuaInterface.dll</HintPath>
</Reference>
<Reference Include="Mono.Data.Sqlite">
<HintPath>..\SqlBins\Mono.Data.Sqlite.dll</HintPath>
</Reference>
@ -110,7 +107,6 @@
<Compile Include="Group.cs" />
<Compile Include="Extensions\LinqExt.cs" />
<Compile Include="Log.cs" />
<Compile Include="LuaSystem\LuaLoader.cs" />
<Compile Include="Net\BaseMsg.cs" />
<Compile Include="Net\DisconnectMsg.cs" />
<Compile Include="Net\NetTile.cs" />
@ -191,7 +187,7 @@
</PropertyGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" BuildVersion_BuildAction="Both" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_StartDate="2011/6/17" BuildVersion_IncrementBeforeBuild="False" />
<UserProperties BuildVersion_IncrementBeforeBuild="False" BuildVersion_StartDate="2011/6/17" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_BuildAction="Both" BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" />
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View file

@ -24,22 +24,15 @@ using System.Net.Sockets;
using System.Security.Cryptography;
using System.Text;
using Terraria;
using TShockAPI.LuaSystem;
namespace TShockAPI
{
public class Utils
{
LuaLoader Parent; //For Lua Functions that require the LuaLoader
public Utils()
{
}
public Utils(LuaLoader parent)
{
Parent = parent;
}
public Random Random = new Random();
//private static List<Group> groups = new List<Group>();