Adds option to remember leave positions. Change to true in config.json
This commit is contained in:
parent
f790d9378c
commit
df1cbab1f5
6 changed files with 162 additions and 3 deletions
|
|
@ -54,5 +54,7 @@ namespace TShockAPI
|
||||||
|
|
||||||
public int spawnTileX;
|
public int spawnTileX;
|
||||||
public int spawnTileY;
|
public int spawnTileY;
|
||||||
|
|
||||||
|
public bool RememberLeavePos = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -54,6 +54,7 @@ namespace TShockAPI
|
||||||
public static bool DisableBuild = false;
|
public static bool DisableBuild = false;
|
||||||
public static float[] AdminChatRGB = {255, 0, 0};
|
public static float[] AdminChatRGB = {255, 0, 0};
|
||||||
public static string AdminChatPrefix = "(Admin) ";
|
public static string AdminChatPrefix = "(Admin) ";
|
||||||
|
public static bool RememberLeavePos = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Don't allow pvp changing for x seconds.
|
/// Don't allow pvp changing for x seconds.
|
||||||
|
|
@ -112,6 +113,7 @@ namespace TShockAPI
|
||||||
ListServer = cfg.ListServer;
|
ListServer = cfg.ListServer;
|
||||||
Main.spawnTileX = cfg.spawnTileX;
|
Main.spawnTileX = cfg.spawnTileX;
|
||||||
Main.spawnTileY = cfg.spawnTileY;
|
Main.spawnTileY = cfg.spawnTileY;
|
||||||
|
RememberLeavePos = cfg.RememberLeavePos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void WriteJsonConfiguration()
|
public static void WriteJsonConfiguration()
|
||||||
|
|
@ -146,6 +148,7 @@ namespace TShockAPI
|
||||||
cfg.ListServer = ListServer;
|
cfg.ListServer = ListServer;
|
||||||
cfg.spawnTileX = Main.spawnTileX;
|
cfg.spawnTileX = Main.spawnTileX;
|
||||||
cfg.spawnTileY = Main.spawnTileY;
|
cfg.spawnTileY = Main.spawnTileY;
|
||||||
|
cfg.RememberLeavePos = RememberLeavePos;
|
||||||
|
|
||||||
string json = JsonConvert.SerializeObject(cfg, Formatting.Indented);
|
string json = JsonConvert.SerializeObject(cfg, Formatting.Indented);
|
||||||
TextWriter tr = new StreamWriter(FileTools.ConfigPath);
|
TextWriter tr = new StreamWriter(FileTools.ConfigPath);
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ namespace TShockAPI
|
||||||
public static readonly string GroupsPath = Path.Combine(TShock.SavePath, "groups.txt");
|
public static readonly string GroupsPath = Path.Combine(TShock.SavePath, "groups.txt");
|
||||||
public static readonly string UsersPath = Path.Combine(TShock.SavePath, "users.txt");
|
public static readonly string UsersPath = Path.Combine(TShock.SavePath, "users.txt");
|
||||||
public static readonly string ItemBansPath = Path.Combine(TShock.SavePath, "itembans.txt");
|
public static readonly string ItemBansPath = Path.Combine(TShock.SavePath, "itembans.txt");
|
||||||
|
public static readonly string RememberedPosPath = Path.Combine(TShock.SavePath, "oldpos.xml");
|
||||||
public static readonly string ConfigPath = Path.Combine(TShock.SavePath, "config.json");
|
public static readonly string ConfigPath = Path.Combine(TShock.SavePath, "config.json");
|
||||||
|
|
||||||
public static void CreateFile(string file)
|
public static void CreateFile(string file)
|
||||||
|
|
|
||||||
136
TShockAPI/RememberPosManager.cs
Normal file
136
TShockAPI/RememberPosManager.cs
Normal file
|
|
@ -0,0 +1,136 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
using Terraria;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using System.Xml;
|
||||||
|
|
||||||
|
namespace TShockAPI
|
||||||
|
{
|
||||||
|
class RemeberedPosManager
|
||||||
|
{
|
||||||
|
public static List<RemeberedPos> RemeberedPosistions = new List<RemeberedPos>();
|
||||||
|
|
||||||
|
public static void LoadPos()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
|
||||||
|
xmlReaderSettings.IgnoreWhitespace = true;
|
||||||
|
|
||||||
|
using (XmlReader settingr = XmlReader.Create(FileTools.RememberedPosPath, xmlReaderSettings))
|
||||||
|
{
|
||||||
|
while (settingr.Read())
|
||||||
|
{
|
||||||
|
if (settingr.IsStartElement())
|
||||||
|
{
|
||||||
|
switch (settingr.Name)
|
||||||
|
{
|
||||||
|
case "Positions":
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "Player":
|
||||||
|
{
|
||||||
|
if (settingr.Read())
|
||||||
|
{
|
||||||
|
string IP = null;
|
||||||
|
float X = 0;
|
||||||
|
float Y = 0;
|
||||||
|
|
||||||
|
settingr.Read();
|
||||||
|
if (settingr.Value != "" || settingr.Value != null)
|
||||||
|
IP = settingr.Value;
|
||||||
|
else
|
||||||
|
Log.Warn("IP is empty");
|
||||||
|
|
||||||
|
|
||||||
|
settingr.Read();
|
||||||
|
settingr.Read();
|
||||||
|
settingr.Read();
|
||||||
|
if (settingr.Value != "" || settingr.Value != null)
|
||||||
|
float.TryParse(settingr.Value, out X);
|
||||||
|
else
|
||||||
|
Log.Warn("X for IP " + IP + " is empty");
|
||||||
|
|
||||||
|
settingr.Read();
|
||||||
|
settingr.Read();
|
||||||
|
settingr.Read();
|
||||||
|
if (settingr.Value != "" || settingr.Value != null)
|
||||||
|
float.TryParse(settingr.Value, out Y);
|
||||||
|
else
|
||||||
|
Log.Warn("Y for IP " + IP + " is empty");
|
||||||
|
|
||||||
|
if (X != 0 && Y != 0)
|
||||||
|
RemeberedPosistions.Add(new RemeberedPos(IP, new Vector2(X, Y)));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Log.Info("Read Remembered Positions");
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Log.Warn("Could not read Remembered Positions");
|
||||||
|
WriteSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void WriteSettings()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
|
||||||
|
xmlWriterSettings.Indent = true;
|
||||||
|
xmlWriterSettings.NewLineChars = Environment.NewLine;
|
||||||
|
|
||||||
|
using (XmlWriter settingsw = XmlWriter.Create(FileTools.RememberedPosPath, xmlWriterSettings))
|
||||||
|
{
|
||||||
|
settingsw.WriteStartDocument();
|
||||||
|
settingsw.WriteStartElement("Positions");
|
||||||
|
|
||||||
|
foreach (RemeberedPos player in RemeberedPosistions)
|
||||||
|
{
|
||||||
|
settingsw.WriteStartElement("Player");
|
||||||
|
settingsw.WriteElementString("IP", player.IP);
|
||||||
|
settingsw.WriteElementString("X", player.Pos.X.ToString());
|
||||||
|
settingsw.WriteElementString("Y", player.Pos.Y.ToString());
|
||||||
|
settingsw.WriteEndElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
settingsw.WriteEndElement();
|
||||||
|
settingsw.WriteEndDocument();
|
||||||
|
}
|
||||||
|
Log.Info("Wrote Remembered Positions");
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Log.Warn("Could not write Remembered Positions");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class RemeberedPos
|
||||||
|
{
|
||||||
|
public string IP { get; set; }
|
||||||
|
public Vector2 Pos { get; set; }
|
||||||
|
|
||||||
|
public RemeberedPos(string ip, Vector2 pos)
|
||||||
|
{
|
||||||
|
IP = ip;
|
||||||
|
Pos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RemeberedPos()
|
||||||
|
{
|
||||||
|
IP = string.Empty;
|
||||||
|
Pos = Vector2.Zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -102,11 +102,11 @@ namespace TShockAPI
|
||||||
Log.Info("Commands initialized");
|
Log.Info("Commands initialized");
|
||||||
|
|
||||||
RegionManager.ReadAllSettings();
|
RegionManager.ReadAllSettings();
|
||||||
|
|
||||||
WarpsManager.ReadAllSettings();
|
WarpsManager.ReadAllSettings();
|
||||||
|
|
||||||
ItemManager.LoadBans();
|
ItemManager.LoadBans();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Backups.KeepFor = ConfigurationManager.BackupKeepFor;
|
Backups.KeepFor = ConfigurationManager.BackupKeepFor;
|
||||||
Backups.Interval = ConfigurationManager.BackupInterval;
|
Backups.Interval = ConfigurationManager.BackupInterval;
|
||||||
|
|
||||||
|
|
@ -270,6 +270,12 @@ namespace TShockAPI
|
||||||
if (tsplr != null && tsplr.ReceivedInfo)
|
if (tsplr != null && tsplr.ReceivedInfo)
|
||||||
Log.Info(string.Format("{0} left.", tsplr.Name));
|
Log.Info(string.Format("{0} left.", tsplr.Name));
|
||||||
|
|
||||||
|
if (ConfigurationManager.RememberLeavePos)
|
||||||
|
{
|
||||||
|
RemeberedPosManager.RemeberedPosistions.Add(new RemeberedPos(Players[ply].IP, new Vector2(Players[ply].X / 16, (Players[ply].Y / 16) + 3)));
|
||||||
|
RemeberedPosManager.WriteSettings();
|
||||||
|
}
|
||||||
|
|
||||||
Players[ply] = null;
|
Players[ply] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -416,6 +422,16 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
StartInvasion();
|
StartInvasion();
|
||||||
}
|
}
|
||||||
|
if (ConfigurationManager.RememberLeavePos)
|
||||||
|
{
|
||||||
|
foreach (RemeberedPos playerIP in RemeberedPosManager.RemeberedPosistions)
|
||||||
|
{
|
||||||
|
if (playerIP.IP == Players[who].IP)
|
||||||
|
{
|
||||||
|
Players[who].Teleport((int)playerIP.Pos.X, (int)playerIP.Pos.Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,7 @@
|
||||||
<Compile Include="Group.cs" />
|
<Compile Include="Group.cs" />
|
||||||
<Compile Include="Log.cs" />
|
<Compile Include="Log.cs" />
|
||||||
<Compile Include="RegionManager.cs" />
|
<Compile Include="RegionManager.cs" />
|
||||||
|
<Compile Include="RememberPosManager.cs" />
|
||||||
<Compile Include="Resources.Designer.cs">
|
<Compile Include="Resources.Designer.cs">
|
||||||
<AutoGen>True</AutoGen>
|
<AutoGen>True</AutoGen>
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
|
|
@ -144,7 +145,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ProjectExtensions>
|
<ProjectExtensions>
|
||||||
<VisualStudio>
|
<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>
|
</VisualStudio>
|
||||||
</ProjectExtensions>
|
</ProjectExtensions>
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue