Added Disconnect, SendTileSquare, SetPvP to TSPlayer
Added SetBloodMoon, SetTime, StrikeNPC to TSServerPlayer
This commit is contained in:
parent
5a0b00b398
commit
7bccfbe441
5 changed files with 87 additions and 70 deletions
|
|
@ -490,12 +490,8 @@ namespace TShockAPI
|
||||||
|
|
||||||
private static void Bloodmoon(CommandArgs args)
|
private static void Bloodmoon(CommandArgs args)
|
||||||
{
|
{
|
||||||
|
TSPlayer.Server.SetBloodMoon(true);
|
||||||
Tools.Broadcast(string.Format("{0} turned on blood moon.", args.Player.Name));
|
Tools.Broadcast(string.Format("{0} turned on blood moon.", args.Player.Name));
|
||||||
Main.bloodMoon = true;
|
|
||||||
Main.time = 0;
|
|
||||||
Main.dayTime = false;
|
|
||||||
NetMessage.SendData(18, -1, -1, "", 0, 0, Main.sunModY, Main.moonModY);
|
|
||||||
NetMessage.syncPlayers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Invade(CommandArgs args)
|
private static void Invade(CommandArgs args)
|
||||||
|
|
@ -728,38 +724,23 @@ namespace TShockAPI
|
||||||
switch (args.Parameters[0])
|
switch (args.Parameters[0])
|
||||||
{
|
{
|
||||||
case "day":
|
case "day":
|
||||||
Main.time = 0;
|
TSPlayer.Server.SetTime(true, 0.0);
|
||||||
Main.dayTime = true;
|
|
||||||
NetMessage.SendData(18, -1, -1, "", 0, 0, Main.sunModY, Main.moonModY);
|
|
||||||
NetMessage.syncPlayers();
|
|
||||||
Tools.Broadcast(string.Format("{0} set time to day.", args.Player.Name));
|
Tools.Broadcast(string.Format("{0} set time to day.", args.Player.Name));
|
||||||
break;
|
break;
|
||||||
case "night":
|
case "night":
|
||||||
Main.time = 0;
|
TSPlayer.Server.SetTime(false, 0.0);
|
||||||
Main.dayTime = false;
|
|
||||||
NetMessage.SendData(18, -1, -1, "", 0, 0, Main.sunModY, Main.moonModY);
|
|
||||||
NetMessage.syncPlayers();
|
|
||||||
Tools.Broadcast(string.Format("{0} set time to night.", args.Player.Name));
|
Tools.Broadcast(string.Format("{0} set time to night.", args.Player.Name));
|
||||||
break;
|
break;
|
||||||
case "dusk":
|
case "dusk":
|
||||||
Main.dayTime = false;
|
TSPlayer.Server.SetTime(false, 0.0);
|
||||||
Main.time = 0.0;
|
|
||||||
NetMessage.SendData(18, -1, -1, "", 0, 0, Main.sunModY, Main.moonModY);
|
|
||||||
NetMessage.syncPlayers();
|
|
||||||
Tools.Broadcast(string.Format("{0} set time to dusk.", args.Player.Name));
|
Tools.Broadcast(string.Format("{0} set time to dusk.", args.Player.Name));
|
||||||
break;
|
break;
|
||||||
case "noon":
|
case "noon":
|
||||||
Main.dayTime = true;
|
TSPlayer.Server.SetTime(true, 27000.0);
|
||||||
Main.time = 27000.0;
|
|
||||||
NetMessage.SendData(18, -1, -1, "", 0, 0, Main.sunModY, Main.moonModY);
|
|
||||||
NetMessage.syncPlayers();
|
|
||||||
Tools.Broadcast(string.Format("{0} set time to noon.", args.Player.Name));
|
Tools.Broadcast(string.Format("{0} set time to noon.", args.Player.Name));
|
||||||
break;
|
break;
|
||||||
case "midnight":
|
case "midnight":
|
||||||
Main.dayTime = false;
|
TSPlayer.Server.SetTime(false, 16200.0);
|
||||||
Main.time = 16200.0;
|
|
||||||
NetMessage.SendData(18, -1, -1, "", 0, 0, Main.sunModY, Main.moonModY);
|
|
||||||
NetMessage.syncPlayers();
|
|
||||||
Tools.Broadcast(string.Format("{0} set time to midnight.", args.Player.Name));
|
Tools.Broadcast(string.Format("{0} set time to midnight.", args.Player.Name));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
@ -914,7 +895,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
int.TryParse(args.Parameters[1], out damage);
|
int.TryParse(args.Parameters[1], out damage);
|
||||||
}
|
}
|
||||||
TShock.PlayerDamage(plr, damage);
|
plr.DamagePlayer(damage);
|
||||||
Tools.Broadcast(string.Format("{0} slapped {1} for {2} damage.",
|
Tools.Broadcast(string.Format("{0} slapped {1} for {2} damage.",
|
||||||
args.Player.Name, plr.Name, damage));
|
args.Player.Name, plr.Name, damage));
|
||||||
}
|
}
|
||||||
|
|
@ -941,9 +922,9 @@ namespace TShockAPI
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var plr = player[0];
|
var plr = player[0];
|
||||||
|
plr.DamagePlayer(999999);
|
||||||
args.Player.SendMessage(string.Format("You just killed {0}!", plr.Name));
|
args.Player.SendMessage(string.Format("You just killed {0}!", plr.Name));
|
||||||
plr.SendMessage(string.Format("{0} just killed you!", args.Player.Name));
|
plr.SendMessage(string.Format("{0} just killed you!", args.Player.Name));
|
||||||
TShock.PlayerDamage(plr, 999999);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -954,8 +935,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
if (!Main.npc[i].townNPC && Main.npc[i].active)
|
if (!Main.npc[i].townNPC && Main.npc[i].active)
|
||||||
{
|
{
|
||||||
Main.npc[i].StrikeNPC(99999, 90f, 1);
|
TSPlayer.Server.StrikeNPC(i, 99999, 90f, 1);
|
||||||
NetMessage.SendData(28, -1, -1, "", i, 99999, 90f, 1);
|
|
||||||
killcount++;
|
killcount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,6 @@ namespace TShockAPI
|
||||||
Tools.ForceKick(args.Player, "Hair crash exploit.");
|
Tools.ForceKick(args.Player, "Hair crash exploit.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name.Length > 32)
|
if (name.Length > 32)
|
||||||
{
|
{
|
||||||
Tools.ForceKick(args.Player, "Name exceeded 32 characters.");
|
Tools.ForceKick(args.Player, "Name exceeded 32 characters.");
|
||||||
|
|
@ -215,7 +214,7 @@ namespace TShockAPI
|
||||||
if (!args.Player.Group.HasPermission("editspawn"))
|
if (!args.Player.Group.HasPermission("editspawn"))
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("World protected from changes.", Color.Red);
|
args.Player.SendMessage("World protected from changes.", Color.Red);
|
||||||
TShock.SendTileSquare(args.Player, x, y);
|
args.Player.SendTileSquare(x, y);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -227,7 +226,7 @@ namespace TShockAPI
|
||||||
if (flag)
|
if (flag)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("Spawn protected from changes.", Color.Red);
|
args.Player.SendMessage("Spawn protected from changes.", Color.Red);
|
||||||
TShock.SendTileSquare(args.Player, x, y);
|
args.Player.SendTileSquare(x, y);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -248,12 +247,7 @@ namespace TShockAPI
|
||||||
int id = args.Data.ReadByte();
|
int id = args.Data.ReadByte();
|
||||||
bool pvp = args.Data.ReadBoolean();
|
bool pvp = args.Data.ReadBoolean();
|
||||||
|
|
||||||
args.TPlayer.hostile = pvp;
|
args.Player.SetPvP(id != args.Player.Index || ConfigurationManager.PermaPvp ? true : pvp);
|
||||||
if (id != args.Player.Index)
|
|
||||||
args.TPlayer.hostile = true;
|
|
||||||
if (ConfigurationManager.PermaPvp)
|
|
||||||
args.TPlayer.hostile = true;
|
|
||||||
NetMessage.SendData(30, -1, -1, "", args.Player.Index);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -382,11 +376,7 @@ namespace TShockAPI
|
||||||
if (ConfigurationManager.RangeChecks && ((Math.Abs(plyX - tileX) > 32) || (Math.Abs(plyY - tileY) > 32)))
|
if (ConfigurationManager.RangeChecks && ((Math.Abs(plyX - tileX) > 32) || (Math.Abs(plyY - tileY) > 32)))
|
||||||
{
|
{
|
||||||
Log.Debug(string.Format("Liquid(PlyXY:{0}_{1}, TileXY:{2}_{3}, Result:{4}_{5}, Amount:{6})",
|
Log.Debug(string.Format("Liquid(PlyXY:{0}_{1}, TileXY:{2}_{3}, Result:{4}_{5}, Amount:{6})",
|
||||||
plyX, plyY,
|
plyX, plyY, tileX, tileY, Math.Abs(plyX - tileX), Math.Abs(plyY - tileY), liquid));
|
||||||
tileX, tileY,
|
|
||||||
Math.Abs(plyX - tileX), Math.Abs(plyY - tileY),
|
|
||||||
liquid
|
|
||||||
));
|
|
||||||
return Tools.HandleGriefer(args.Player, "Placing impossible to place liquid."); ;
|
return Tools.HandleGriefer(args.Player, "Placing impossible to place liquid."); ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,13 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Terraria;
|
using Terraria;
|
||||||
|
using TerrariaAPI;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
public class TSPlayer
|
public class TSPlayer
|
||||||
{
|
{
|
||||||
public static readonly TSPlayer Server = new ServerPlayer();
|
public static readonly TSServerPlayer Server = new TSServerPlayer();
|
||||||
public static readonly TSPlayer All = new TSPlayer("All");
|
public static readonly TSPlayer All = new TSPlayer("All");
|
||||||
public uint TileThreshold { get; set; }
|
public uint TileThreshold { get; set; }
|
||||||
public Dictionary<Vector2, Tile> TilesDestroyed { get; set; }
|
public Dictionary<Vector2, Tile> TilesDestroyed { get; set; }
|
||||||
|
|
@ -104,6 +105,22 @@ namespace TShockAPI
|
||||||
Group = new Group("null");
|
Group = new Group("null");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void Disconnect(string reason)
|
||||||
|
{
|
||||||
|
if (Index == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
NetMessage.SendData((int)PacketTypes.Disconnect, Index, -1, reason, 0x0, 0f, 0f, 0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void SendTileSquare(int x, int y, int size = 10)
|
||||||
|
{
|
||||||
|
if (Index == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
NetMessage.SendData((int)PacketTypes.TileSendSquare, Index, -1, "", size, (float)(x - (size / 2)), (float)(y - (size / 2)), 0f);
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void SendMessage(string msg)
|
public virtual void SendMessage(string msg)
|
||||||
{
|
{
|
||||||
SendMessage(msg, 0, 255, 0);
|
SendMessage(msg, 0, 255, 0);
|
||||||
|
|
@ -116,30 +133,72 @@ namespace TShockAPI
|
||||||
|
|
||||||
public virtual void SendMessage(string msg, byte red, byte green, byte blue)
|
public virtual void SendMessage(string msg, byte red, byte green, byte blue)
|
||||||
{
|
{
|
||||||
NetMessage.SendData(0x19, Index, -1, msg, 255, red, green, blue);
|
NetMessage.SendData((int)PacketTypes.ChatText, Index, -1, msg, 255, red, green, blue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void DamagePlayer(int damage)
|
||||||
|
{
|
||||||
|
if (Index == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
NetMessage.SendData((int)PacketTypes.PlayerDamage, -1, -1, "", Index, ((new Random()).Next(-1, 1)), damage, (float)0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void SetPvP(bool pvp)
|
||||||
|
{
|
||||||
|
if (Index == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (TPlayer.hostile != pvp)
|
||||||
|
{
|
||||||
|
TPlayer.hostile = pvp;
|
||||||
|
NetMessage.SendData((int)PacketTypes.TogglePVP, -1, -1, "", Index);
|
||||||
|
All.SendMessage(string.Format("{0} has {1} PvP!", Name, pvp ? "enabled" : "disabled"), Main.teamColor[Team]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class TSServerPlayer : TSPlayer
|
||||||
public class ServerPlayer : TSPlayer
|
|
||||||
{
|
{
|
||||||
public ServerPlayer() : base("Server")
|
public TSServerPlayer() : base("Server")
|
||||||
{
|
{
|
||||||
Group = new SuperAdminGroup();
|
Group = new SuperAdminGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SendMessage(string msg)
|
public override void SendMessage(string msg)
|
||||||
{
|
{
|
||||||
Console.WriteLine(msg);
|
SendMessage(msg, 0, 255, 0);
|
||||||
}
|
|
||||||
public override void SendMessage(string msg, byte red, byte green, byte blue)
|
|
||||||
{
|
|
||||||
SendMessage(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SendMessage(string msg, Color color)
|
public override void SendMessage(string msg, Color color)
|
||||||
{
|
{
|
||||||
SendMessage(msg);
|
SendMessage(msg, color.R, color.G, color.B);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SendMessage(string msg, byte red, byte green, byte blue)
|
||||||
|
{
|
||||||
|
Console.WriteLine(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetBloodMoon(bool bloodMoon)
|
||||||
|
{
|
||||||
|
Main.bloodMoon = bloodMoon;
|
||||||
|
SetTime(false, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetTime(bool dayTime, double time)
|
||||||
|
{
|
||||||
|
Main.dayTime = dayTime;
|
||||||
|
Main.time = time;
|
||||||
|
NetMessage.SendData((int)PacketTypes.TimeSet, -1, -1, "", 0, 0, Main.sunModY, Main.moonModY);
|
||||||
|
NetMessage.syncPlayers();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StrikeNPC(int npcid, int damage, float knockBack, int hitDirection)
|
||||||
|
{
|
||||||
|
Main.npc[npcid].StrikeNPC(damage, knockBack, hitDirection);
|
||||||
|
NetMessage.SendData((int)PacketTypes.NPCStrike, -1, -1, "", npcid, damage, knockBack, hitDirection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -367,8 +367,7 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
if (ConfigurationManager.PermaPvp)
|
if (ConfigurationManager.PermaPvp)
|
||||||
{
|
{
|
||||||
Main.player[who].hostile = true;
|
player.SetPvP(true);
|
||||||
NetMessage.SendData(30, -1, -1, "", who);
|
|
||||||
}
|
}
|
||||||
if (Players[who].Group.HasPermission("causeevents") && ConfigurationManager.InfiniteInvasion)
|
if (Players[who].Group.HasPermission("causeevents") && ConfigurationManager.InfiniteInvasion)
|
||||||
{
|
{
|
||||||
|
|
@ -465,17 +464,6 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void PlayerDamage(TSPlayer player, int damage)
|
|
||||||
{
|
|
||||||
NetMessage.SendData(26, -1, -1, "", player.Index, ((new Random()).Next(-1, 1)), damage, (float)0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SendTileSquare(TSPlayer player, int x, int y, int size = 10)
|
|
||||||
{
|
|
||||||
NetMessage.SendData(20, player.Index, -1, "", size, (float)(x - (size / 2)), (float)(y - (size / 2)), 0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO : Notify the player if there is more than one match. (or do we want a First() kinda thing?)
|
//TODO : Notify the player if there is more than one match. (or do we want a First() kinda thing?)
|
||||||
public static int GetNPCID(string name, bool exact = false)
|
public static int GetNPCID(string name, bool exact = false)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -215,7 +215,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
if (!player.ConnectionAlive)
|
if (!player.ConnectionAlive)
|
||||||
return;
|
return;
|
||||||
NetMessage.SendData(0x2, player.Index, -1, reason, 0x0, 0f, 0f, 0f);
|
player.Disconnect(reason);
|
||||||
Log.Info(string.Format("{0} was force kicked for : {1}", player.IP, reason));
|
Log.Info(string.Format("{0} was force kicked for : {1}", player.IP, reason));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -231,7 +231,7 @@ namespace TShockAPI
|
||||||
if (!player.Group.HasPermission("immunetokick"))
|
if (!player.Group.HasPermission("immunetokick"))
|
||||||
{
|
{
|
||||||
string playerName = player.Name;
|
string playerName = player.Name;
|
||||||
NetMessage.SendData(0x2, player.Index, -1, string.Format("Kicked: {0}", reason), 0x0, 0f, 0f, 0f);
|
player.Disconnect(string.Format("Kicked: {0}", reason));
|
||||||
Log.Info(string.Format("Kicked {0} for : {1}", playerName, reason));
|
Log.Info(string.Format("Kicked {0} for : {1}", playerName, reason));
|
||||||
if (adminUserName.Length == 0)
|
if (adminUserName.Length == 0)
|
||||||
Broadcast(string.Format("{0} was kicked for {1}", playerName, reason.ToLower()));
|
Broadcast(string.Format("{0} was kicked for {1}", playerName, reason.ToLower()));
|
||||||
|
|
@ -256,7 +256,7 @@ namespace TShockAPI
|
||||||
string ip = player.IP;
|
string ip = player.IP;
|
||||||
string playerName = player.Name;
|
string playerName = player.Name;
|
||||||
TShock.Bans.AddBan(ip, playerName, reason);
|
TShock.Bans.AddBan(ip, playerName, reason);
|
||||||
NetMessage.SendData(0x2, player.Index, -1, string.Format("Banned: {0}", reason), 0x0, 0f, 0f, 0f);
|
player.Disconnect(string.Format("Banned: {0}", reason));
|
||||||
Log.Info(string.Format("Banned {0} for : {1}", playerName, reason));
|
Log.Info(string.Format("Banned {0} for : {1}", playerName, reason));
|
||||||
if (adminUserName.Length == 0)
|
if (adminUserName.Length == 0)
|
||||||
Broadcast(string.Format("{0} was banned for {1}", playerName, reason.ToLower()));
|
Broadcast(string.Format("{0} was banned for {1}", playerName, reason.ToLower()));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue