mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Add token, allow using in bot names and skin names.
This commit is contained in:
parent
9fb1cdfd09
commit
a928ed94c8
@ -105,7 +105,7 @@ namespace MCGalaxy.Gui
|
||||
if (File.Exists("Changelog.txt"))
|
||||
{
|
||||
txtChangelog.Text = "Changelog for " + Server.Version + ":";
|
||||
foreach (string line in File.ReadAllLines(("Changelog.txt")))
|
||||
foreach (string line in File.ReadAllLines("Changelog.txt"))
|
||||
{
|
||||
txtChangelog.AppendText("\r\n " + line);
|
||||
}
|
||||
|
@ -264,9 +264,9 @@ namespace MCGalaxy.Games {
|
||||
|
||||
string msg = "&bInvisibility for &a" + left;
|
||||
if (p.HasCpeExt(CpeExt.MessageTypes))
|
||||
p.SendCpeMessage(CpeMessageType.BottomRight2, msg, true);
|
||||
p.SendCpeMessage(CpeMessageType.BottomRight2, msg);
|
||||
else
|
||||
p.SendMessage(msg, true);
|
||||
p.SendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -556,11 +556,11 @@ namespace MCGalaxy.Games {
|
||||
const string line1 = "&eLevel vote - type &a1&e, &c2&e or &93";
|
||||
string line2 = "&a" + lvl1 + "&e, &c" + lvl2 + "&e, &9random";
|
||||
if (p.HasCpeExt(CpeExt.MessageTypes)) {
|
||||
p.SendCpeMessage(CpeMessageType.BottomRight2, line1, true);
|
||||
p.SendCpeMessage(CpeMessageType.BottomRight1, line2, true);
|
||||
p.SendCpeMessage(CpeMessageType.BottomRight2, line1);
|
||||
p.SendCpeMessage(CpeMessageType.BottomRight1, line2);
|
||||
} else {
|
||||
p.SendMessage(line1, true);
|
||||
p.SendMessage(line2, true);
|
||||
p.SendMessage(line1);
|
||||
p.SendMessage(line2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ namespace MCGalaxy.Games {
|
||||
void UpdatePlayerStatus(Player p) {
|
||||
int seconds = (int)(RoundEnd - DateTime.UtcNow).TotalSeconds;
|
||||
string status = GetStatusMessage(GetTimespan(seconds));
|
||||
p.SendCpeMessage(CpeMessageType.Status1, status, true);
|
||||
p.SendCpeMessage(CpeMessageType.Status1, status);
|
||||
}
|
||||
|
||||
internal void UpdateAllPlayerStatus() {
|
||||
@ -178,7 +178,7 @@ namespace MCGalaxy.Games {
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player p in players) {
|
||||
if (p.level != CurLevel) continue;
|
||||
p.SendCpeMessage(CpeMessageType.Status1, message, true);
|
||||
p.SendCpeMessage(CpeMessageType.Status1, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -257,13 +257,11 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
string ConvertMessage(string message, bool colorParse) {
|
||||
if (colorParse)
|
||||
message = Colors.EscapeColors(message);
|
||||
if (colorParse) message = Colors.EscapeColors(message);
|
||||
StringBuilder sb = new StringBuilder(message);
|
||||
if (colorParse)
|
||||
ParseColors(sb);
|
||||
if (colorParse) ParseColors(sb);
|
||||
|
||||
Chat.ApplyTokens(sb, this, colorParse);
|
||||
Chat.ApplyTokens(sb, this);
|
||||
if ( Server.parseSmiley && parseSmiley ) {
|
||||
sb.Replace(":)", "(darksmile)");
|
||||
sb.Replace(":D", "(smile)");
|
||||
|
@ -17,7 +17,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using TokenParser = System.Func<bool, MCGalaxy.Player, string>;
|
||||
using TokenParser = System.Func<MCGalaxy.Player, string>;
|
||||
|
||||
namespace MCGalaxy {
|
||||
|
||||
@ -98,14 +98,21 @@ namespace MCGalaxy {
|
||||
Player.Message(p, Server.DefaultColor + message);
|
||||
}
|
||||
|
||||
public static void ApplyTokens(StringBuilder sb, Player p, bool colorParse) {
|
||||
public static string ApplyTokens(string text, Player p) {
|
||||
if (text.IndexOf('$') == -1) return text;
|
||||
StringBuilder sb = new StringBuilder(text);
|
||||
ApplyTokens(sb, p);
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static void ApplyTokens(StringBuilder sb, Player p) {
|
||||
// only apply standard $tokens when necessary
|
||||
for (int i = 0; i < sb.Length; i++) {
|
||||
if (sb[i] != '$') continue;
|
||||
|
||||
foreach (var token in standardTokens) {
|
||||
if (Server.disabledChatTokens.Contains(token.Key)) continue;
|
||||
string value = token.Value(colorParse, p);
|
||||
string value = token.Value(p);
|
||||
if (value == null) continue;
|
||||
sb.Replace(token.Key, value);
|
||||
}
|
||||
@ -116,28 +123,30 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
internal static Dictionary<string, TokenParser> standardTokens = new Dictionary<string, TokenParser> {
|
||||
{ "$name", (c, p) => p.DisplayName == null ? null :
|
||||
{ "$name", p => p.DisplayName == null ? null :
|
||||
(Server.dollarNames ? "$" : "") + Colors.StripColours(p.DisplayName) },
|
||||
{ "$date", (c, p) => DateTime.Now.ToString("yyyy-MM-dd") },
|
||||
{ "$time", (c, p) => DateTime.Now.ToString("HH:mm:ss") },
|
||||
{ "$ip", (c, p) => p.ip },
|
||||
{ "$serverip", (c, p) => Player.IsLocalIpAddress(p.ip) ? p.ip : Server.IP },
|
||||
{ "$color", (c, p) => c ? p.color : null },
|
||||
{ "$rank", (c, p) => p.group == null ? null : p.group.name },
|
||||
{ "$level", (c, p) => p.level == null ? null : p.level.name },
|
||||
{ "$truename", p => p.truename == null ? null :
|
||||
(Server.dollarNames ? "$" : "") + p.truename },
|
||||
{ "$date", p => DateTime.Now.ToString("yyyy-MM-dd") },
|
||||
{ "$time", p => DateTime.Now.ToString("HH:mm:ss") },
|
||||
{ "$ip", p => p.ip },
|
||||
{ "$serverip", p => Player.IsLocalIpAddress(p.ip) ? p.ip : Server.IP },
|
||||
{ "$color", p => p.color },
|
||||
{ "$rank", p => p.group == null ? null : p.group.name },
|
||||
{ "$level", p => p.level == null ? null : p.level.name },
|
||||
|
||||
{ "$deaths", (c, p) => p.overallDeath.ToString() },
|
||||
{ "$money", (c, p) => p.money.ToString() },
|
||||
{ "$blocks", (c, p) => p.overallBlocks.ToString() },
|
||||
{ "$first", (c, p) => p.firstLogin.ToString() },
|
||||
{ "$kicked", (c, p) => p.totalKicked.ToString() },
|
||||
{ "$server", (c, p) => Server.name },
|
||||
{ "$motd", (c, p) => Server.motd },
|
||||
{ "$banned", (c, p) => Player.GetBannedCount().ToString() },
|
||||
{ "$irc", (c, p) => Server.ircServer + " > " + Server.ircChannel },
|
||||
{ "$deaths", p => p.overallDeath.ToString() },
|
||||
{ "$money", p => p.money.ToString() },
|
||||
{ "$blocks", p => p.overallBlocks.ToString() },
|
||||
{ "$first", p => p.firstLogin.ToString() },
|
||||
{ "$kicked", p => p.totalKicked.ToString() },
|
||||
{ "$server", p => Server.name },
|
||||
{ "$motd", p => Server.motd },
|
||||
{ "$banned", p => Player.GetBannedCount().ToString() },
|
||||
{ "$irc", p => Server.ircServer + " > " + Server.ircChannel },
|
||||
|
||||
{ "$infected", (c, p) => p.Game.TotalInfected.ToString() },
|
||||
{ "$survived", (c, p) => p.Game.TotalRoundsSurvived.ToString() },
|
||||
{ "$infected", p => p.Game.TotalInfected.ToString() },
|
||||
{ "$survived", p => p.Game.TotalRoundsSurvived.ToString() },
|
||||
};
|
||||
public static Dictionary<string, string> CustomTokens = new Dictionary<string, string>();
|
||||
|
||||
|
@ -13,6 +13,7 @@ or implied. See the Licenses for the specific language governing
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
using System.Text;
|
||||
using MCGalaxy.Games;
|
||||
|
||||
namespace MCGalaxy {
|
||||
@ -132,10 +133,13 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
internal static void Spawn(Player dst, PlayerBot b) {
|
||||
string name = Chat.ApplyTokens(b.name, dst);
|
||||
string skin = Chat.ApplyTokens(b.skinName, dst);
|
||||
|
||||
if (dst.hasExtList) {
|
||||
dst.SendExtAddEntity2(b.id, b.skinName, b.color + b.name, b.pos[0], b.pos[1], b.pos[2], b.rot[0], b.rot[1]);
|
||||
dst.SendExtAddEntity2(b.id, skin, b.color + name, b.pos[0], b.pos[1], b.pos[2], b.rot[0], b.rot[1]);
|
||||
} else {
|
||||
dst.SendSpawn(b.id, b.color + b.skinName, b.pos[0], b.pos[1], b.pos[2], b.rot[0], b.rot[1]);
|
||||
dst.SendSpawn(b.id, b.color + skin, b.pos[0], b.pos[1], b.pos[2], b.rot[0], b.rot[1]);
|
||||
}
|
||||
if (Server.TablistBots)
|
||||
TabList.Add(dst, b);
|
||||
@ -198,7 +202,7 @@ namespace MCGalaxy {
|
||||
#region Position updates
|
||||
|
||||
public static byte[] GetPositionPacket(PlayerBot bot) {
|
||||
// TODO: not sure why this bots only work with absolute packets
|
||||
// TODO: not sure why bots only work with absolute packets
|
||||
byte[] buffer = new byte[10];
|
||||
buffer[0] = Opcode.EntityTeleport;
|
||||
buffer[1] = bot.id;
|
||||
|
@ -478,7 +478,7 @@ namespace MCGalaxy {
|
||||
if (p.ignoreAll || p.ignoreIRC) continue;
|
||||
|
||||
if (p.level.worldChat && p.Chatroom == null)
|
||||
p.SendMessage(message, true);
|
||||
p.SendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user