This commit is contained in:
UnknownShadow200 2017-02-28 23:15:20 +11:00
parent b6debbd8e9
commit 27b3b0950d
6 changed files with 29 additions and 27 deletions

View File

@ -84,8 +84,8 @@ namespace MCGalaxy {
public static Dictionary<string, string> CustomTokens = new Dictionary<string, string>(); public static Dictionary<string, string> CustomTokens = new Dictionary<string, string>();
internal static void LoadCustom() { internal static void LoadCustom() {
CustomTokens.Clear(); CustomTokens.Clear();
if (File.Exists("text/custom$s.txt")) { if (File.Exists(Paths.CustomTokensFile)) {
using (StreamReader r = new StreamReader("text/custom$s.txt")) { using (StreamReader r = new StreamReader(Paths.CustomTokensFile)) {
string line; string line;
while ((line = r.ReadLine()) != null) { while ((line = r.ReadLine()) != null) {
if (line.StartsWith("//")) continue; if (line.StartsWith("//")) continue;
@ -96,7 +96,7 @@ namespace MCGalaxy {
} }
} else { } else {
Server.s.Log("custom$s.txt does not exist, creating"); Server.s.Log("custom$s.txt does not exist, creating");
using (StreamWriter w = new StreamWriter("text/custom$s.txt")) { using (StreamWriter w = new StreamWriter(Paths.CustomTokensFile)) {
w.WriteLine("// This is used to create custom $s"); w.WriteLine("// This is used to create custom $s");
w.WriteLine("// If you start the line with a // it wont be used"); w.WriteLine("// If you start the line with a // it wont be used");
w.WriteLine("// It should be formatted like this:"); w.WriteLine("// It should be formatted like this:");

View File

@ -228,19 +228,11 @@ namespace MCGalaxy {
Player[] players = PlayerInfo.Online.Items; Player[] players = PlayerInfo.Online.Items;
foreach (Player p in players) { foreach (Player p in players) {
if (!p.HasCpeExt(CpeExt.TextColors)) continue; if (!p.HasCpeExt(CpeExt.TextColors)) continue;
SendSetTextColor(p, col); p.Send(Packet.SetTextColor(col));
} }
SaveExtColors(); SaveExtColors();
} }
internal static void SendSetTextColor(Player p, CustomColor col) {
byte[] buffer = new byte[6];
buffer[0] = Opcode.CpeSetTextColor;
buffer[1] = col.R; buffer[2] = col.G; buffer[3] = col.B; buffer[4] = col.A;
buffer[5] = (byte)col.Code;
p.Send(buffer);
}
internal static void SaveExtColors() { internal static void SaveExtColors() {
using (StreamWriter w = new StreamWriter(Paths.CustomColorsFile)) { using (StreamWriter w = new StreamWriter(Paths.CustomColorsFile)) {
foreach (CustomColor col in ExtColors) { foreach (CustomColor col in ExtColors) {

View File

@ -66,15 +66,15 @@ namespace MCGalaxy {
} }
static void LoadBadWords() { static void LoadBadWords() {
if (!File.Exists("text/badwords.txt")) { if (!File.Exists(Paths.BadWordsFile)) {
// No file exists yet, so let's create one // No file exists yet, so let's create one
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.AppendLine("# This file contains a list of bad words to remove via the profanity filter"); sb.AppendLine("# This file contains a list of bad words to remove via the profanity filter");
sb.AppendLine("# Each bad word should be on a new line all by itself"); sb.AppendLine("# Each bad word should be on a new line all by itself");
File.WriteAllText("text/badwords.txt", sb.ToString()); File.WriteAllText(Paths.BadWordsFile, sb.ToString());
} }
string[] lines = File.ReadAllLines("text/badwords.txt"); string[] lines = File.ReadAllLines(Paths.BadWordsFile);
// Run the badwords through the reducer to ensure things like Ls become Is and everything is lowercase // Run the badwords through the reducer to ensure things like Ls become Is and everything is lowercase
filters = new List<string>(); filters = new List<string>();
foreach (string line in lines) { foreach (string line in lines) {

View File

@ -53,7 +53,7 @@ namespace MCGalaxy {
} }
public static byte[] TextHotKey(string label, string input, int keycode, public static byte[] TextHotKey(string label, string input, int keycode,
byte mods, bool hasCP437) { byte mods, bool hasCP437) {
byte[] buffer = new byte[134]; byte[] buffer = new byte[134];
buffer[0] = Opcode.CpeSetTextHotkey; buffer[0] = Opcode.CpeSetTextHotkey;
NetUtils.Write(label, buffer, 1, hasCP437); NetUtils.Write(label, buffer, 1, hasCP437);
@ -62,8 +62,8 @@ namespace MCGalaxy {
buffer[133] = mods; buffer[133] = mods;
return buffer; return buffer;
} }
public static byte[] ExtAddEntity(byte id, string name, string displayname, bool hasCP437) { public static byte[] ExtAddEntity(byte id, string name, string displayname, bool hasCP437) {
byte[] buffer = new byte[130]; byte[] buffer = new byte[130];
buffer[0] = Opcode.CpeExtAddEntity; buffer[0] = Opcode.CpeExtAddEntity;
buffer[1] = id; buffer[1] = id;
@ -73,7 +73,7 @@ namespace MCGalaxy {
} }
public static byte[] ExtAddPlayerName(byte id, string listName, string displayName, public static byte[] ExtAddPlayerName(byte id, string listName, string displayName,
string grp, byte grpRank, bool hasCP437) { string grp, byte grpRank, bool hasCP437) {
byte[] buffer = new byte[196]; byte[] buffer = new byte[196];
buffer[0] = Opcode.CpeExtAddPlayerName; buffer[0] = Opcode.CpeExtAddPlayerName;
NetUtils.WriteI16(id, buffer, 1); NetUtils.WriteI16(id, buffer, 1);
@ -151,7 +151,7 @@ namespace MCGalaxy {
} }
public static byte[] MapAppearance(string url, byte side, byte edge, int sideLevel, public static byte[] MapAppearance(string url, byte side, byte edge, int sideLevel,
bool hasCP437) { bool hasCP437) {
byte[] buffer = new byte[69]; byte[] buffer = new byte[69];
WriteMapAppearance(buffer, url, side, edge, sideLevel, hasCP437); WriteMapAppearance(buffer, url, side, edge, sideLevel, hasCP437);
return buffer; return buffer;
@ -167,7 +167,7 @@ namespace MCGalaxy {
} }
static void WriteMapAppearance(byte[] buffer, string url, byte side, byte edge, static void WriteMapAppearance(byte[] buffer, string url, byte side, byte edge,
int sideLevel, bool hasCP437) { int sideLevel, bool hasCP437) {
buffer[0] = Opcode.CpeEnvSetMapApperance; buffer[0] = Opcode.CpeEnvSetMapApperance;
NetUtils.Write(url, buffer, 1, hasCP437); NetUtils.Write(url, buffer, 1, hasCP437);
buffer[65] = side; buffer[65] = side;
@ -210,6 +210,14 @@ namespace MCGalaxy {
buffer[137] = roty; buffer[137] = roty;
return buffer; return buffer;
} }
public static byte[] SetTextColor(CustomColor col) {
byte[] buffer = new byte[6];
buffer[0] = Opcode.CpeSetTextColor;
buffer[1] = col.R; buffer[2] = col.G; buffer[3] = col.B; buffer[4] = col.A;
buffer[5] = (byte)col.Code;
return buffer;
}
public static byte[] EnvMapUrl(string url, bool hasCP437) { public static byte[] EnvMapUrl(string url, bool hasCP437) {

View File

@ -82,8 +82,9 @@ namespace MCGalaxy {
for (int i = 0; i < Colors.ExtColors.Length; i++) { for (int i = 0; i < Colors.ExtColors.Length; i++) {
if (Colors.ExtColors[i].Undefined) continue; if (Colors.ExtColors[i].Undefined) continue;
Colors.SendSetTextColor(this, Colors.ExtColors[i]); Send(Packet.SetTextColor(Colors.ExtColors[i]));
} break; }
break;
case CpeExt.BulkBlockUpdate: case CpeExt.BulkBlockUpdate:
BulkBlockUpdate = version; break; BulkBlockUpdate = version; break;
case CpeExt.EnvMapAspect: case CpeExt.EnvMapAspect:

View File

@ -16,9 +16,6 @@
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using System; using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace MCGalaxy { namespace MCGalaxy {
@ -29,5 +26,9 @@ namespace MCGalaxy {
public const string BlockPermsFile = "properties/block.properties"; public const string BlockPermsFile = "properties/block.properties";
public const string TempRanksFile = "text/tempranks.txt"; public const string TempRanksFile = "text/tempranks.txt";
public const string CustomTokensFile = "text/custom$s.txt";
public const string BadWordsFile = "text/badwords.txt";
} }
} }