Skip to content

Commit

Permalink
更新开发分支进度 (汉化v1.5.3)
Browse files Browse the repository at this point in the history
* 加入更新公告颜色格式功能
* 服务器关闭可以用`stop`和`stop-nosave`了
* 移除旧REST模型
* 修复了IPs为空时, Linq执行失败的处理问题
* 玩家可上传存档了
  • Loading branch information
mistzzt committed Oct 26, 2016
2 parents b2d168b + bccf292 commit a53b32b
Show file tree
Hide file tree
Showing 20 changed files with 346 additions and 739 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ obj/*

# OS generated files #
######################
.DS_Store?
.DS_Store
ehthumbs.db
Icon?
Thumbs.db
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
* Removed TShock color parsing from MOTDs (@WhiteXZ).
* Fixed butterfly statues spawning catchable butterflies (@DogooFalchion).
* Implemented some missing balance changes lost in prior version patches (@DogooFalchion).
* Added alias for server shutdown command: stop (@nicatronTg).
* Removed the old REST model. This includes the following endpoints:
* `/status`
* `/v2/players/read`
* `/v2/server/rawcmd` (@WhiteXZ).
* Fixed `/user group` always giving an unhelpful error messaging telling you to check the console, even if we knew exactly why it failed (@nicatronTg).
* Removed _all obsolete methods in TShock marked obsolete prior to this version (all of them)_ (@nicatronTg).
* Fixed issue where registration + login would fail because KnownIps had 0 items and .Last() doesn't work on collections with 0 items (@DogooFalchion, @nicatronTg, @Simon311).
* Added `/uploadssc [player]` which allows someone to upload SSC data for [player] and store it on the server. Adds `tshock.ssc.upload` and `tshock.ssc.upload.others` permission nodes to match (@DogooFalchion).
* Added hardened stone to the whitelist of tiles editable by players (@DogooFalchion).
* Added conversion system to send convert old MOTD format into smart text, while preserving initial line starting values to keep byte optimization for background colors Thanks to (@WhiteXZ, @Simon311, and especially @DogooFalchion) for the hard work on this issue.

## TShock 4.3.20
* Security improvement: The auth system is now automatically disabled if a superadmin exists in the database (@Enerdy).
Expand Down
74 changes: 65 additions & 9 deletions TShockAPI/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ public static void InitCommands()
{
HelpText = "保存所有玩家的云存档."
});
add(new Command(Permissions.uploaddata, UploadJoinData, "uploadssc", "上传云存档")
{
HelpText = "加入游戏时上传存档数据作为SSC数据."
});
add(new Command(Permissions.settempgroup, TempGroup, "tempgroup", "临时组")
{
HelpText = "暂时更改用户组."
Expand Down Expand Up @@ -330,11 +334,11 @@ public static void InitCommands()
{
HelpText = "检查TShock更新."
});
add(new Command(Permissions.maintenance, Off, "off", "关服","exit")
add(new Command(Permissions.maintenance, Off, "off", "关服", "exit", "stop")
{
HelpText = "关闭服务器."
});
add(new Command(Permissions.maintenance, OffNoSave, "off-nosave", "不保存关服","exit-nosave")
add(new Command(Permissions.maintenance, OffNoSave, "off-nosave", "不保存关服", "exit-nosave", "stop-nosave")
{
HelpText = "不保存地图的情况下关闭服务器."
});
Expand All @@ -354,11 +358,6 @@ public static void InitCommands()
{
HelpText = "查看TShock版本."
});
/* Does nothing atm.
*
* add(new Command(Permissions.updateplugins, UpdatePlugins, "updateplugins")
{
});*/
add(new Command(Permissions.whitelist, Whitelist, "whitelist", "白名单")
{
HelpText = "更改服务器白名单."
Expand Down Expand Up @@ -1699,6 +1698,63 @@ private static void OverrideSSC(CommandArgs args)
args.Player.SendSuccessMessage("玩家 {0} 的云存档已被覆盖保存.", matchedPlayer.Name);
}

private static void UploadJoinData(CommandArgs args)
{
TSPlayer targetPlayer = args.Player;
if (args.Parameters.Count == 1 && args.Player.HasPermission(Permissions.uploadothersdata))
{
List<TSPlayer> players = TShock.Utils.FindPlayer(args.Parameters[0]);
if (players.Count > 1)
{
TShock.Utils.SendMultipleMatchError(args.Player, players.Select(p => p.Name));
return;
}
else if (players.Count == 0)
{
args.Player.SendErrorMessage("找不到玩家 '{0}'", args.Parameters[0]);
return;
}
else
{
targetPlayer = players[0];
}
}
else if (args.Parameters.Count == 1)
{
args.Player.SendErrorMessage("缺少权限: 无法上传其他玩家人物存档.");
return;
}
else if (args.Parameters.Count > 0)
{
args.Player.SendErrorMessage("语法无效! 正确用法: /uploadssc [玩家名]");
return;
}
else if (args.Parameters.Count == 0 && args.Player is TSServerPlayer)
{
args.Player.SendErrorMessage("控制台无法上传数据.");
args.Player.SendErrorMessage("语法无效! 正确用法: /uploadssc [玩家名]");
return;
}

if (targetPlayer.IsLoggedIn)
{
if (TShock.CharacterDB.InsertSpecificPlayerData(targetPlayer, targetPlayer.DataWhenJoined))
{
targetPlayer.DataWhenJoined.RestoreCharacter(targetPlayer);
targetPlayer.SendSuccessMessage("你的本地存档数据已被上传至服务器.");
args.Player.SendSuccessMessage("玩家本地存档数据已被上传至服务器.");
}
else
{
args.Player.SendErrorMessage("上传存档数据失败, 确定你登录游戏了?");
}
}
else
{
args.Player.SendErrorMessage("目标玩家还未登录.");
}
}

private static void ForceHalloween(CommandArgs args)
{
TShock.Config.ForceHalloween = !TShock.Config.ForceHalloween;
Expand Down Expand Up @@ -4817,12 +4873,12 @@ private static void Mute(CommandArgs args)

private static void Motd(CommandArgs args)
{
TShock.Utils.ShowFileToUser(args.Player, "motd.txt");
TShock.Utils.ShowFileToUser(args.Player, FileTools.MotdPath);
}

private static void Rules(CommandArgs args)
{
TShock.Utils.ShowFileToUser(args.Player, "rules.txt");
TShock.Utils.ShowFileToUser(args.Player, FileTools.RulesPath);
}

private static void Whisper(CommandArgs args)
Expand Down
31 changes: 4 additions & 27 deletions TShockAPI/ConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ public class ConfigFile
[Description("Sends ServerName in place of the world name to clients.")]
[JsonProperty("使用服务器名")]
public bool UseServerName = false;
[Description("未完成功能.")]
[JsonProperty("主服IP")]
public string MasterServer = "127.0.0.1";

[Description("Valid types are \"sqlite\" and \"mysql\"")]
[JsonProperty("数据库类型")]
Expand All @@ -194,10 +191,7 @@ public class ConfigFile
[JsonProperty("中等难度玩家驱逐原因")]
public string MediumcoreKickReason = "玩家死亡后驱逐";

[Description("Enables DNS resolution of incoming connections with GetGroupForIPExpensive.")]
[JsonProperty("启用DNS解析")]
public bool EnableDNSHostResolution;

/// <summary>EnableIPBans - Whether or not to kick players on join that match a banned IP address.</summary>
[Description("Enables kicking of banned users by matching their IP Address.")]
[JsonProperty("启用IP封禁")]
public bool EnableIPBans = true;
Expand Down Expand Up @@ -230,11 +224,7 @@ public class ConfigFile
[JsonProperty("哈希算法")]
public string HashAlgorithm = "sha512";

[Obsolete("PacketBuffered is no longer used")]
[Description("Buffers up the packets and sends them out at the end of each frame.")]
[JsonProperty("缓冲包")]
public bool BufferPackets = true;

/// <summary>ServerFullReason - The reason given when kicking players when the server is full.</summary>
[Description("String that is used when kicking people when the server is full.")]
[JsonProperty("服务器人满驱逐原因")]
public string ServerFullReason = "服务器已满! 请稍后再进入.";
Expand Down Expand Up @@ -477,13 +467,7 @@ public class ConfigFile
[JsonProperty("服务器通知颜色")]
public int[] BroadcastRGB = { 127, 255, 212 };

// TODO: Get rid of this when the old REST permission model is removed.
[Description(
"Whether the REST API should use the new permission model. Note: The old permission model will become depracted in the future."
)]
[JsonProperty("启用REST新权限方式")]
public bool RestUseNewPermissionModel = true;

/// <summary>ApplicationRestTokens - A dictionary of REST tokens that external applications may use to make queries to your server.</summary>
[Description("A dictionary of REST tokens that external applications may use to make queries to your server.")]
[JsonProperty("应用的REST密钥")]
public Dictionary<string, SecureRest.TokenData> ApplicationRestTokens = new Dictionary<string, SecureRest.TokenData>();
Expand All @@ -508,14 +492,7 @@ public class ConfigFile
[JsonProperty("物块上色速率上限")]
public int TilePaintThreshold = 15;

[Description("Enables max packet bufferer size.")]
[JsonProperty("启用包内最大字节数")]
public bool EnableMaxBytesInBuffer = false;

[Description("Number of bytes in the packet buffer before we disconnect the player.")]
[JsonProperty("包内最大字节数")]
public int MaxBytesInBuffer = 5242880;

/// <summary>ForceHalloween - Forces Halloween-only events to occur all year.</summary>
[Description("Forces your world to be in Halloween mode regardless of the data.")]
[JsonProperty("强制万圣节模式")]
public bool ForceHalloween = false;
Expand Down
102 changes: 96 additions & 6 deletions TShockAPI/DB/CharacterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ public bool SeedInitialData(User user)
string initialItems = String.Join("~", items.Take(NetItem.MaxInventory));
try
{
database.Query("INSERT INTO tsCharacter (Account, Health, MaxHealth, Mana, MaxMana, Inventory, spawnX, spawnY, questsCompleted) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8);",
database.Query("INSERT INTO tsCharacter (Account, Health, MaxHealth, Mana, MaxMana, Inventory, spawnX, spawnY, questsCompleted) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8);",
user.ID,
TShock.ServerSideCharacterConfig.StartingHealth,
TShock.ServerSideCharacterConfig.StartingHealth,
TShock.ServerSideCharacterConfig.StartingMana,
TShock.ServerSideCharacterConfig.StartingMana,
initialItems,
-1,
-1,
TShock.ServerSideCharacterConfig.StartingMana,
initialItems,
-1,
-1,
0);
return true;
}
Expand All @@ -159,7 +159,7 @@ public bool SeedInitialData(User user)
public bool InsertPlayerData(TSPlayer player)
{
PlayerData playerData = player.PlayerData;

if (!player.IsLoggedIn)
return false;

Expand Down Expand Up @@ -219,5 +219,95 @@ public bool RemovePlayer(int userid)

return false;
}

/// <summary>
/// Inserts a specific PlayerData into the SSC table for a player.
/// </summary>
/// <param name="player">The player to store the data for.</param>
/// <param name="data">The player data to store.</param>
/// <returns>If the command succeeds.</returns>
public bool InsertSpecificPlayerData(TSPlayer player, PlayerData data)
{
PlayerData playerData = data;

if (!player.IsLoggedIn)
return false;

if (player.HasPermission(Permissions.bypassssc))
{
TShock.Log.ConsoleInfo("跳过用户 " + player.User.Name + " 的云存档保存"); // Debug code
return true;
}

if (!GetPlayerData(player, player.User.ID).exists)
{
try
{
database.Query(
"INSERT INTO tsCharacter (Account, Health, MaxHealth, Mana, MaxMana, Inventory, extraSlot, spawnX, spawnY, skinVariant, hair, hairDye, hairColor, pantsColor, shirtColor, underShirtColor, shoeColor, hideVisuals, skinColor, eyeColor, questsCompleted) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17, @18, @19, @20);",
player.User.ID,
playerData.health,
playerData.maxHealth,
playerData.mana,
playerData.maxMana,
String.Join("~", playerData.inventory),
playerData.extraSlot,
playerData.spawnX,
playerData.spawnX,
playerData.skinVariant,
playerData.hair,
playerData.hairDye,
TShock.Utils.EncodeColor(playerData.hairColor),
TShock.Utils.EncodeColor(playerData.pantsColor),
TShock.Utils.EncodeColor(playerData.shirtColor),
TShock.Utils.EncodeColor(playerData.underShirtColor),
TShock.Utils.EncodeColor(playerData.shoeColor),
TShock.Utils.EncodeBoolArray(playerData.hideVisuals),
TShock.Utils.EncodeColor(playerData.skinColor),
TShock.Utils.EncodeColor(playerData.eyeColor),
playerData.questsCompleted);
return true;
}
catch (Exception ex)
{
TShock.Log.Error(ex.ToString());
}
}
else
{
try
{
database.Query(
"UPDATE tsCharacter SET Health = @0, MaxHealth = @1, Mana = @2, MaxMana = @3, Inventory = @4, spawnX = @6, spawnY = @7, hair = @8, hairDye = @9, hairColor = @10, pantsColor = @11, shirtColor = @12, underShirtColor = @13, shoeColor = @14, hideVisuals = @15, skinColor = @16, eyeColor = @17, questsCompleted = @18, skinVariant = @19, extraSlot = @20 WHERE Account = @5;",
playerData.health,
playerData.maxHealth,
playerData.mana,
playerData.maxMana,
String.Join("~", playerData.inventory),
player.User.ID,
playerData.spawnX,
playerData.spawnX,
playerData.skinVariant,
playerData.hair,
playerData.hairDye,
TShock.Utils.EncodeColor(playerData.hairColor),
TShock.Utils.EncodeColor(playerData.pantsColor),
TShock.Utils.EncodeColor(playerData.shirtColor),
TShock.Utils.EncodeColor(playerData.underShirtColor),
TShock.Utils.EncodeColor(playerData.shoeColor),
TShock.Utils.EncodeBoolArray(playerData.hideVisuals),
TShock.Utils.EncodeColor(playerData.skinColor),
TShock.Utils.EncodeColor(playerData.eyeColor),
playerData.questsCompleted,
playerData.extraSlot ?? 0);
return true;
}
catch (Exception ex)
{
TShock.Log.Error(ex.ToString());
}
}
return false;
}
}
}
54 changes: 0 additions & 54 deletions TShockAPI/DB/GroupManager.cs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -149,60 +149,6 @@ public void AddGroup(String name, string parentname, String permissions, String
throw new GroupManagerException("无法添加组 " + name + ".");
}

/// <summary>
/// Adds group with name and permissions if it does not exist.
/// </summary>
/// <param name="name">name of group</param>
/// <param name="parentname">parent of group</param>
/// <param name="permissions">permissions</param>
/// <param name="chatcolor">chatcolor</param>
/// <param name="exceptions">exceptions true indicates use exceptions for errors false otherwise</param>
[Obsolete("Use AddGroup(name, parentname, permissions, chatcolor) instead.")]
public String AddGroup(String name, string parentname, String permissions, String chatcolor = Group.defaultChatColor, bool exceptions = false)
{
if (GroupExists(name))
{
if (exceptions)
throw new GroupExistsException(name);
return "错误: 已存在; 故无法添加.";
}

var group = new Group(name, null, chatcolor);
group.Permissions = permissions;
if (!string.IsNullOrWhiteSpace(parentname))
{
var parent = groups.FirstOrDefault(gp => gp.Name == parentname);
if (parent == null || name == parentname)
{
var error = "组 {1} 的父组 {0} 无效.".SFormat(parentname, group.Name);
if (exceptions)
throw new GroupManagerException(error);
TShock.Log.ConsoleError(error);
return error;
}
group.Parent = parent;
}

string query = (TShock.Config.StorageType.ToLower() == "sqlite")
? "INSERT OR IGNORE INTO GroupList (GroupName, Parent, Commands, ChatColor) VALUES (@0, @1, @2, @3);"
: "INSERT IGNORE INTO GroupList SET GroupName=@0, Parent=@1, Commands=@2, ChatColor=@3";
if (database.Query(query, name, parentname, permissions, chatcolor) == 1)
{
groups.Add(group);
return "创建组 " + name + " 成功!";
}
else if (exceptions)
throw new GroupManagerException("无法添加组 " + name + ".");

return "";
}

[Obsolete("Use AddGroup(name, parentname, permissions, chatcolor) instead.")]
public String AddGroup(String name, String permissions)
{
return AddGroup(name, null, permissions, Group.defaultChatColor, false);
}

/// <summary>
/// Updates a group including permissions
/// </summary>
Expand Down
Loading

0 comments on commit a53b32b

Please sign in to comment.