Skip to content

Commit

Permalink
Merge pull request #545 from NyxStudios/1.2_terraria
Browse files Browse the repository at this point in the history
Update to Terraria Protocol 1.2
  • Loading branch information
hakusaro committed Oct 1, 2013
2 parents 3020295 + 2621774 commit 33e0627
Show file tree
Hide file tree
Showing 19 changed files with 993 additions and 673 deletions.
123 changes: 82 additions & 41 deletions TShockAPI/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ You should have received a copy of the GNU General Public License
using System.Linq;
using System.Text;
using System.Threading;
using TShockAPI.PluginUpdater;
using Terraria;
using TShockAPI.DB;

Expand Down Expand Up @@ -186,7 +185,9 @@ public static void InitCommands()
add(Permissions.causeevents, Star, "star");
add(Permissions.causeevents, Fullmoon, "fullmoon");
add(Permissions.causeevents, Bloodmoon, "bloodmoon");
add(Permissions.causeevents, Eclipse, "eclipse");
add(Permissions.causeevents, Invade, "invade");
add(Permissions.causeevents, Rain, "rain");
add(Permissions.spawnboss, Eater, "eater");
add(Permissions.spawnboss, Eye, "eye");
add(Permissions.spawnboss, King, "king");
Expand Down Expand Up @@ -483,7 +484,7 @@ private static void AttemptLogin(CommandArgs args)
if (TShock.RememberedPos.GetLeavePos(args.Player.Name, args.Player.IP) != Vector2.Zero)
{
Vector2 pos = TShock.RememberedPos.GetLeavePos(args.Player.Name, args.Player.IP);
args.Player.Teleport((int)pos.X, (int)pos.Y + 3);
args.Player.Teleport((int)pos.X*16, (int)pos.Y *16 + 48);
}
args.Player.LoginHarassed = false;

Expand Down Expand Up @@ -1259,7 +1260,6 @@ private static void UpdatePlugins(CommandArgs args)
{
args.Player.SendInfoMessage("Starting plugin update process:");
args.Player.SendInfoMessage("This may take a while, do not turn off the server!");
new PluginUpdaterThread(args.Player);
}

private static void ManageRest(CommandArgs args)
Expand Down Expand Up @@ -1354,6 +1354,12 @@ private static void Bloodmoon(CommandArgs args)
TShock.Utils.Broadcast(string.Format("{0} turned on the blood moon.", args.Player.Name), Color.Green);
}

private static void Eclipse(CommandArgs args)
{
TSPlayer.Server.SetEclipse(true);
TShock.Utils.Broadcast(string.Format("{0} has forced an Eclipse!", args.Player.Name), Color.Green);
}

private static void Invade(CommandArgs args)
{
if (Main.invasionSize <= 0)
Expand Down Expand Up @@ -1635,41 +1641,61 @@ private static void Home(CommandArgs args)

private static void Spawn(CommandArgs args)
{
if (args.Player.Teleport(Main.spawnTileX, Main.spawnTileY))
if (args.Player.Teleport(Main.spawnTileX*16, Main.spawnTileY*16))
args.Player.SendSuccessMessage("Teleported to the map's spawnpoint.");
}

private static void TP(CommandArgs args)
{
if (args.Parameters.Count < 1)
{
args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /tp <player> ");
args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /tp <player>");
args.Player.SendErrorMessage(" /tp <x> <y>");
return;
}

string plStr = String.Join(" ", args.Parameters);
var players = TShock.Utils.FindPlayer(plStr);
if (players.Count == 0)
args.Player.SendErrorMessage("Invalid player!");
else if (players.Count > 1)
TShock.Utils.SendMultipleMatchError(args.Player, players.Select(p => p.Name));
else if (!players[0].TPAllow && !args.Player.Group.HasPermission(Permissions.tpall))
if(args.Parameters.Count == 2)
{
var plr = players[0];
args.Player.SendErrorMessage(plr.Name + " has prevented users from teleporting to them.");
plr.SendInfoMessage(args.Player.Name + " attempted to teleport to you.");
float x, y;
if (float.TryParse(args.Parameters[0], out x) && float.TryParse(args.Parameters[1], out y))
{
args.Player.Teleport(x, y);
args.Player.SendSuccessMessage("Teleported!");
}
}
else
{
var plr = players[0];
if (args.Player.Teleport(plr.TileX, plr.TileY + 3))
string plStr = String.Join(" ", args.Parameters);
var players = TShock.Utils.FindPlayer(plStr);
if (players.Count == 0)
{
args.Player.SendErrorMessage("Invalid user name.");
args.Player.SendErrorMessage("Proper syntax: /tp <player>");
args.Player.SendErrorMessage(" /tp <x> <y>");
}

else if (players.Count > 1)
TShock.Utils.SendMultipleMatchError(args.Player, players.Select(p => p.Name));
else if (!players[0].TPAllow && !args.Player.Group.HasPermission(Permissions.tpall))
{
args.Player.SendSuccessMessage(string.Format("Teleported to {0}.", plr.Name));
if (!args.Player.Group.HasPermission(Permissions.tphide))
plr.SendInfoMessage(args.Player.Name + " teleported to you.");
var plr = players[0];
args.Player.SendErrorMessage(plr.Name + " has prevented users from teleporting to them.");
plr.SendInfoMessage(args.Player.Name + " attempted to teleport to you.");
}
else
{
var plr = players[0];
if (args.Player.Teleport(plr.TileX * 16, plr.TileY * 16 + 48))
{
args.Player.SendSuccessMessage(string.Format("Teleported to {0}.", plr.Name));
if (!args.Player.Group.HasPermission(Permissions.tphide))
plr.SendInfoMessage(args.Player.Name + " teleported to you.");
}
}
}
}


}

private static void TPHere(CommandArgs args)
{
Expand All @@ -1688,7 +1714,7 @@ private static void TPHere(CommandArgs args)
{
if (Main.player[i].active && (Main.player[i] != args.TPlayer))
{
if (TShock.Players[i].Teleport(args.Player.TileX, args.Player.TileY + 3))
if (TShock.Players[i].Teleport(args.Player.TileX*16, args.Player.TileY*16 + 48))
TShock.Players[i].SendSuccessMessage(string.Format("You were teleported to {0}.", args.Player.Name) + ".");
}
}
Expand All @@ -1707,7 +1733,7 @@ private static void TPHere(CommandArgs args)
else
{
var plr = players[0];
if (plr.Teleport(args.Player.TileX, args.Player.TileY + 3))
if (plr.Teleport(args.Player.TileX*16, args.Player.TileY*16 + 48))
{
plr.SendInfoMessage(string.Format("You were teleported to {0}.", args.Player.Name));
args.Player.SendSuccessMessage(string.Format("You brought {0} here.", plr.Name));
Expand Down Expand Up @@ -1851,7 +1877,7 @@ private static void Warp(CommandArgs args)
var plr = foundplr[0];
if (warp.WarpPos != Vector2.Zero)
{
if (plr.Teleport((int)warp.WarpPos.X, (int)warp.WarpPos.Y + 3))
if (plr.Teleport((int)warp.WarpPos.X*16, (int)warp.WarpPos.Y*16 + 48))
{
plr.SendSuccessMessage(string.Format("{0} warped you to {1}.", args.Player.Name, warpName));
args.Player.SendSuccessMessage(string.Format("You warped {0} to {1}.", plr.Name, warpName));
Expand All @@ -1869,7 +1895,7 @@ private static void Warp(CommandArgs args)
var warp = TShock.Warps.FindWarp(warpName);
if (warp.WarpPos != Vector2.Zero)
{
if (args.Player.Teleport((int)warp.WarpPos.X, (int)warp.WarpPos.Y + 3))
if (args.Player.Teleport((int)warp.WarpPos.X*16, (int)warp.WarpPos.Y*16 + 48))
args.Player.SendSuccessMessage("Warped to " + warpName + ".");
}
else
Expand Down Expand Up @@ -2484,7 +2510,27 @@ private static void Time(CommandArgs args)
}
}

//TODO: Come back here
private static void Rain(CommandArgs args)
{
if (args.Parameters.Count != 1)
{
args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /rain <stop/start>");
return;
}

switch (args.Parameters[0])
{
case "start":
Main.StartRain();
TSPlayer.All.SendInfoMessage(string.Format("{0} caused it to rain.", args.Player.Name));
break;
case "stop":
Main.StopRain();
TSPlayer.All.SendInfoMessage(string.Format("{0} ended the downpour.", args.Player.Name));
break;
}
}


private static void Slap(CommandArgs args)
{
Expand Down Expand Up @@ -2900,13 +2946,13 @@ private static void Region(CommandArgs args)
// worth the effort as chances are very low that overwriting the wire for a few
// nanoseconds will cause much trouble.
Tile tile = Main.tile[boundaryPoint.X, boundaryPoint.Y];
bool oldWireState = tile.wire;
tile.wire = true;
bool oldWireState = tile.wire();
tile.wire(true);

try {
args.Player.SendTileSquare(boundaryPoint.X, boundaryPoint.Y, 1);
} finally {
tile.wire = oldWireState;
tile.wire(oldWireState);
}
}
}
Expand Down Expand Up @@ -3027,7 +3073,7 @@ private static void Region(CommandArgs args)
break;
}

args.Player.Teleport(region.Area.Center.X, region.Area.Center.Y + 3);
args.Player.Teleport(region.Area.Center.X*16, region.Area.Center.Y*16 + 48);

break;
}
Expand Down Expand Up @@ -3703,12 +3749,7 @@ private static void Heal(CommandArgs args)
playerToHeal = args.Player;
}

Item heart = TShock.Utils.GetItemById(58);
Item star = TShock.Utils.GetItemById(184);
for (int i = 0; i < 20; i++)
playerToHeal.GiveItem(heart.type, heart.name, heart.width, heart.height, heart.maxStack);
for (int i = 0; i < 10; i++)
playerToHeal.GiveItem(star.type, star.name, star.width, star.height, star.maxStack);
playerToHeal.Heal();
if (playerToHeal == args.Player)
{
args.Player.SendSuccessMessage("You just got healed!");
Expand Down Expand Up @@ -3829,7 +3870,7 @@ private static void Grow(CommandArgs args)
case "tree":
for (int i = x - 1; i < x + 2; i++)
{
Main.tile[i, y].active = true;
Main.tile[i, y].active(true);
Main.tile[i, y].type = 2;
Main.tile[i, y].wall = 0;
}
Expand All @@ -3840,20 +3881,20 @@ private static void Grow(CommandArgs args)
case "epictree":
for (int i = x - 1; i < x + 2; i++)
{
Main.tile[i, y].active = true;
Main.tile[i, y].active(true);
Main.tile[i, y].type = 2;
Main.tile[i, y].wall = 0;
}
Main.tile[x, y - 1].wall = 0;
Main.tile[x, y - 1].liquid = 0;
Main.tile[x, y - 1].active = true;
Main.tile[x, y - 1].active(true);
WorldGen.GrowEpicTree(x, y);
name = "Epic Tree";
break;
case "mushroom":
for (int i = x - 1; i < x + 2; i++)
{
Main.tile[i, y].active = true;
Main.tile[i, y].active(true);
Main.tile[i, y].type = 70;
Main.tile[i, y].wall = 0;
}
Expand All @@ -3867,7 +3908,7 @@ private static void Grow(CommandArgs args)
name = "Cactus";
break;
case "herb":
Main.tile[x, y].active = true;
Main.tile[x, y].active(true);
Main.tile[x, y].frameX = 36;
Main.tile[x, y].type = 83;
WorldGen.GrowAlch(x, y);
Expand Down
2 changes: 1 addition & 1 deletion TShockAPI/DB/BanManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public bool AddBan(string ip, string name = "", string reason = "", bool excepti
{
try
{
return database.Query("INSERT INTO Bans (IP, Name, Reason, BanningUser, Date, Expiration) VALUES (@0, @1, @2, @3, @4, @5);", ip, name, reason, banner, DateTime.Now.ToString("G"), expiration) != 0;
return database.Query("INSERT INTO Bans (IP, Name, Reason, BanningUser, Date, Expiration) VALUES (@0, @1, @2, @3, @4, @5);", ip, name, reason, banner, DateTime.UtcNow.ToString("s"), expiration) != 0;
}
catch (Exception ex)
{
Expand Down
14 changes: 10 additions & 4 deletions TShockAPI/DB/UserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License
*/

using System;
using System.CodeDom.Compiler;
using System.Data;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -38,6 +39,7 @@ public UserManager(IDbConnection db)
new SqlColumn("Username", MySqlDbType.VarChar, 32) {Unique = true},
new SqlColumn("Password", MySqlDbType.VarChar, 128),
new SqlColumn("Usergroup", MySqlDbType.Text),
new SqlColumn("Registered", MySqlDbType.Text),
new SqlColumn("LastAccessed", MySqlDbType.Text),
new SqlColumn("KnownIPs", MySqlDbType.Text)
);
Expand All @@ -60,8 +62,8 @@ public void AddUser(User user)
int ret;
try
{
ret = database.Query("INSERT INTO Users (Username, Password, UserGroup) VALUES (@0, @1, @2);", user.Name,
TShock.Utils.HashPassword(user.Password), user.Group);
ret = database.Query("INSERT INTO Users (Username, Password, UserGroup, Registered) VALUES (@0, @1, @2, @3);", user.Name,
TShock.Utils.HashPassword(user.Password), user.Group, DateTime.UtcNow.ToString("s"));
}
catch (Exception ex)
{
Expand Down Expand Up @@ -146,7 +148,7 @@ public void UpdateLogin(User user)
{
try
{
if (database.Query("UPDATE Users SET LastAccessed = @0, KnownIps = @1 WHERE Username = @2;", DateTime.Now.ToString("G"), user.KnownIps, user.Name) == 0)
if (database.Query("UPDATE Users SET LastAccessed = @0, KnownIps = @1 WHERE Username = @2;", DateTime.UtcNow.ToString("s"), user.KnownIps, user.Name) == 0)
throw new UserNotExistException(user.Name);
}
catch (Exception ex)
Expand Down Expand Up @@ -268,6 +270,7 @@ private User LoadUserFromResult(User user, QueryResult result)
user.Group = result.Get<string>("Usergroup");
user.Password = result.Get<string>("Password");
user.Name = result.Get<string>("Username");
user.Registered = result.Get<string>("Registered");
user.LastAccessed = result.Get<string>("LastAccessed");
user.KnownIps = result.Get<string>("KnownIps");
return user;
Expand All @@ -280,14 +283,16 @@ public class User
public string Name { get; set; }
public string Password { get; set; }
public string Group { get; set; }
public string Registered { get; set; }
public string LastAccessed { get; set; }
public string KnownIps { get; set; }

public User(string name, string pass, string group, string last, string known)
public User(string name, string pass, string group, string registered, string last, string known)
{
Name = name;
Password = pass;
Group = group;
Registered = registered;
LastAccessed = last;
KnownIps = known;
}
Expand All @@ -297,6 +302,7 @@ public User()
Name = "";
Password = "";
Group = "";
Registered = "";
LastAccessed = "";
KnownIps = "";
}
Expand Down
Loading

0 comments on commit 33e0627

Please sign in to comment.