Merge branch 'master' of github.com:TShock/TShock
This commit is contained in:
commit
8e9358a986
3 changed files with 130 additions and 96 deletions
|
|
@ -23,12 +23,8 @@ namespace TShockAPI
|
|||
|
||||
public static string VersionCodename = "UnrealIRCd ftw (irc.shankshock.com #terraria)";
|
||||
|
||||
public static bool shownVersion;
|
||||
|
||||
private static bool[] BlacklistTiles;
|
||||
|
||||
public static bool updateCmd;
|
||||
|
||||
public static BanManager Bans = new BanManager(Path.Combine(saveDir, "bans.txt"));
|
||||
|
||||
delegate bool HandleGetDataD(MemoryStream data, GetDataEventArgs e);
|
||||
|
|
@ -495,7 +491,6 @@ namespace TShockAPI
|
|||
{
|
||||
StartInvasion();
|
||||
}
|
||||
ShowUpdateReminder(who);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
|
|
@ -600,10 +595,7 @@ namespace TShockAPI
|
|||
|
||||
private void OnUpdate(GameTime time)
|
||||
{
|
||||
if (Main.netMode != 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
UpdateManager.UpdateProcedureCheck();
|
||||
for (int i = 0; i < Main.maxPlayers; i++)
|
||||
{
|
||||
if (Main.player[i].active == false)
|
||||
|
|
@ -638,45 +630,6 @@ namespace TShockAPI
|
|||
* Useful stuff:
|
||||
* */
|
||||
|
||||
public static void ShowUpdateReminder(int ply)
|
||||
{
|
||||
if (!shownVersion)
|
||||
{
|
||||
if (players[ply].group.HasPermission("maintenance"))
|
||||
{
|
||||
WebClient client = new WebClient();
|
||||
client.Headers.Add("user-agent",
|
||||
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705;)");
|
||||
try
|
||||
{
|
||||
string updateString = client.DownloadString("http://shankshock.com/tshock-update.txt");
|
||||
string[] changes = updateString.Split(',');
|
||||
Version updateVersion = new Version(Convert.ToInt32(changes[0]), Convert.ToInt32(changes[1]),
|
||||
Convert.ToInt32(changes[2]), Convert.ToInt32(changes[3]));
|
||||
float[] color = { 255, 255, 000 };
|
||||
if (VersionNum.CompareTo(updateVersion) < 0)
|
||||
{
|
||||
Tools.SendMessage(ply, "This server is out of date, to update now type /updatenow");
|
||||
if (!updateCmd)
|
||||
{
|
||||
Commands.commands.Add(new Commands.Command("updatenow", "maintenance", Commands.UpdateNow));
|
||||
updateCmd = true;
|
||||
}
|
||||
for (int i = 4; i <= changes.Length; i++)
|
||||
{
|
||||
Tools.SendMessage(ply, changes[i], color);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FileTools.WriteError(e.Message);
|
||||
}
|
||||
shownVersion = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Teleport(int ply, int x, int y)
|
||||
{
|
||||
Main.player[ply].position.X = x;
|
||||
|
|
@ -862,54 +815,54 @@ namespace TShockAPI
|
|||
|
||||
static readonly Dictionary<byte, string> MsgNames = new Dictionary<byte, string>()
|
||||
{
|
||||
{1, "Connect Request"},
|
||||
{2, "Disconnect"},
|
||||
{3, "Continue Connecting"},
|
||||
{4, "Player Info"},
|
||||
{5, "Player Slot"},
|
||||
{6, "Continue Connecting (2)"},
|
||||
{7, "World Info"},
|
||||
{8, "Tile Get Section"},
|
||||
{9, "Status"},
|
||||
{10, "Tile Send Section"},
|
||||
{11, "Tile Frame Section"},
|
||||
{12, "Player Spawn"},
|
||||
{13, "Player Update"},
|
||||
{14, "Player Active"},
|
||||
{15, "Sync Players"},
|
||||
{16, "Player HP"},
|
||||
{17, "Tile"},
|
||||
{18, "Time Set"},
|
||||
{19, "Door Use"},
|
||||
{20, "Tile Send Square"},
|
||||
{21, "Item Drop"},
|
||||
{22, "Item Owner"},
|
||||
{23, "Npc Update"},
|
||||
{24, "Npc Item Strike"},
|
||||
{25, "Chat Text"},
|
||||
{26, "Player Damage"},
|
||||
{27, "Projectile New"},
|
||||
{28, "Npc Strike"},
|
||||
{29, "Projectile Destroy"},
|
||||
{30, "Toggle PVP"},
|
||||
{31, "Chest Get Contents"},
|
||||
{32, "Chest Item"},
|
||||
{33, "Chest Open"},
|
||||
{34, "Tile Kill"},
|
||||
{35, "Effect Heal"},
|
||||
{36, "Zones"},
|
||||
{37, "Password Requied"},
|
||||
{38, "Password Send"},
|
||||
{39, "Item Unown"},
|
||||
{40, "Npc Talk"},
|
||||
{41, "Player Animation"},
|
||||
{42, "Player Mana"},
|
||||
{43, "Effect Mana"},
|
||||
{44, "Player Kill Me"},
|
||||
{45, "Player Team"},
|
||||
{46, "Sign Read"},
|
||||
{47, "Sign New"},
|
||||
{48, "Liquid Set"},
|
||||
{1, "Connect Request"},
|
||||
{2, "Disconnect"},
|
||||
{3, "Continue Connecting"},
|
||||
{4, "Player Info"},
|
||||
{5, "Player Slot"},
|
||||
{6, "Continue Connecting (2)"},
|
||||
{7, "World Info"},
|
||||
{8, "Tile Get Section"},
|
||||
{9, "Status"},
|
||||
{10, "Tile Send Section"},
|
||||
{11, "Tile Frame Section"},
|
||||
{12, "Player Spawn"},
|
||||
{13, "Player Update"},
|
||||
{14, "Player Active"},
|
||||
{15, "Sync Players"},
|
||||
{16, "Player HP"},
|
||||
{17, "Tile"},
|
||||
{18, "Time Set"},
|
||||
{19, "Door Use"},
|
||||
{20, "Tile Send Square"},
|
||||
{21, "Item Drop"},
|
||||
{22, "Item Owner"},
|
||||
{23, "Npc Update"},
|
||||
{24, "Npc Item Strike"},
|
||||
{25, "Chat Text"},
|
||||
{26, "Player Damage"},
|
||||
{27, "Projectile New"},
|
||||
{28, "Npc Strike"},
|
||||
{29, "Projectile Destroy"},
|
||||
{30, "Toggle PVP"},
|
||||
{31, "Chest Get Contents"},
|
||||
{32, "Chest Item"},
|
||||
{33, "Chest Open"},
|
||||
{34, "Tile Kill"},
|
||||
{35, "Effect Heal"},
|
||||
{36, "Zones"},
|
||||
{37, "Password Requied"},
|
||||
{38, "Password Send"},
|
||||
{39, "Item Unown"},
|
||||
{40, "Npc Talk"},
|
||||
{41, "Player Animation"},
|
||||
{42, "Player Mana"},
|
||||
{43, "Effect Mana"},
|
||||
{44, "Player Kill Me"},
|
||||
{45, "Player Team"},
|
||||
{46, "Sign Read"},
|
||||
{47, "Sign New"},
|
||||
{48, "Liquid Set"},
|
||||
{49, "Player Spawn Self"},
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@
|
|||
<Compile Include="TShock.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="TSPlayer.cs" />
|
||||
<Compile Include="UpdateManager.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="config\groups.txt" />
|
||||
|
|
|
|||
80
TShockAPI/UpdateManager.cs
Normal file
80
TShockAPI/UpdateManager.cs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
namespace TShockAPI
|
||||
{
|
||||
class UpdateManager
|
||||
{
|
||||
static string updateUrl = "http://shankshock.com/tshock-update.txt";
|
||||
public static bool updateCmd;
|
||||
public static long updateEpoch = 0;
|
||||
public static string[] globalChanges = {};
|
||||
/// <summary>
|
||||
/// Checks to see if the server is out of date.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static bool ServerIsOutOfDate()
|
||||
{
|
||||
WebClient client = new WebClient();
|
||||
client.Headers.Add("user-agent",
|
||||
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705;)");
|
||||
try
|
||||
{
|
||||
string updateString = client.DownloadString(updateUrl);
|
||||
string[] changes = updateString.Split(',');
|
||||
Version updateVersion = new Version(Convert.ToInt32(changes[0]), Convert.ToInt32(changes[1]),
|
||||
Convert.ToInt32(changes[2]), Convert.ToInt32(changes[3]));
|
||||
if (TShock.VersionNum.CompareTo(updateVersion) < 0)
|
||||
{
|
||||
globalChanges = changes;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FileTools.WriteError(e.Message);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void EnableUpdateCommand()
|
||||
{
|
||||
Commands.commands.Add(new Commands.Command("updatenow", "maintenance", Commands.UpdateNow));
|
||||
updateCmd = true;
|
||||
}
|
||||
|
||||
public static void NotifyAdministrators(string[] changes)
|
||||
{
|
||||
for (int i = 0; i < ConfigurationManager.maxSlots; i++)
|
||||
{
|
||||
if (Terraria.Main.player[i].active)
|
||||
{
|
||||
if (!TShock.players[i].group.HasPermission("maintenance"))
|
||||
return;
|
||||
Tools.SendMessage(i, "The server is out of date. To update, type /updatenow.");
|
||||
for (int j = 4; j <= changes.Length; j++)
|
||||
{
|
||||
Tools.SendMessage(i, changes[i], new float[] { 255, 0, 0 });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateProcedureCheck()
|
||||
{
|
||||
long currentEpoch = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
|
||||
if (currentEpoch > UpdateManager.updateEpoch)
|
||||
{
|
||||
if (ServerIsOutOfDate())
|
||||
{
|
||||
EnableUpdateCommand();
|
||||
NotifyAdministrators(globalChanges);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue