public static byte[] EnvMapUrl(string url) { byte[] buffer = new byte[65]; buffer[0] = Opcode.CpeSetMapEnvUrl; NetUtils.WriteAscii(url, buffer, 1); return(buffer); }
public void SendCpeMessage(CpeMessageType id, string message, bool colorParse = true) { if (id != CpeMessageType.Normal && !HasCpeExt(CpeExt.MessageTypes)) { if (id == CpeMessageType.Announcement) { id = CpeMessageType.Normal; } else { return; } } message = ConvertMessage(message, colorParse); byte[] buffer = new byte[66]; buffer[0] = Opcode.Message; buffer[1] = (byte)id; if (HasCpeExt(CpeExt.FullCP437)) { NetUtils.WriteCP437(message, buffer, 2); } else { NetUtils.WriteAscii(message, buffer, 2); } SendRaw(buffer); }
static void MakeDefineBlockStart(BlockDefinition def, byte[] buffer, ref int index, bool uniqueSideTexs) { // speed = 2^((raw - 128) / 64); // therefore raw = 64log2(speed) + 128 byte rawSpeed = (byte)(64 * Math.Log(def.Speed, 2) + 128); buffer[index++] = def.BlockID; NetUtils.WriteAscii(def.Name, buffer, index); index += NetUtils.StringSize; buffer[index++] = def.CollideType; buffer[index++] = rawSpeed; buffer[index++] = def.TopTex; if (uniqueSideTexs) { buffer[index++] = def.LeftTex; buffer[index++] = def.RightTex; buffer[index++] = def.FrontTex; buffer[index++] = def.BackTex; } else { buffer[index++] = def.SideTex; } buffer[index++] = def.BottomTex; buffer[index++] = (byte)(def.BlocksLight ? 0 : 1); buffer[index++] = def.WalkSound; buffer[index++] = (byte)(def.FullBright ? 1 : 0); }
public void SendBlankMessage() { byte[] buffer = new byte[66]; buffer[0] = Opcode.Message; NetUtils.WriteAscii("", buffer, 2); SendRaw(buffer); }
public void SendMotd() { byte[] buffer = new byte[131]; buffer[0] = Opcode.Handshake; buffer[1] = (byte)8; NetUtils.WriteAscii(Server.name, buffer, 2); if (!String.IsNullOrEmpty(group.MOTD)) { NetUtils.WriteAscii(group.MOTD, buffer, 66); } else { NetUtils.WriteAscii(Server.motd, buffer, 66); } bool canPlace = Block.canPlace(this, Block.blackrock); buffer[130] = canPlace ? (byte)100 : (byte)0; if (OnSendMOTD != null) { OnSendMOTD(this, buffer); } SendRaw(buffer); }
public void SendExtAddEntity2(byte id, string skinName, string displayName, ushort x, ushort y, ushort z, byte rotx, byte roty) { // NOTE: Fix for standard clients if (id == Entities.SelfID) { y -= 22; } byte[] buffer = new byte[138]; buffer[0] = Opcode.CpeExtAddEntity2; buffer[1] = id; NetUtils.WriteAscii(displayName.TrimEnd('+'), buffer, 2); NetUtils.WriteAscii(skinName.TrimEnd('+'), buffer, 66); NetUtils.WriteU16(x, buffer, 130); NetUtils.WriteU16(y, buffer, 132); NetUtils.WriteU16(z, buffer, 134); buffer[136] = rotx; buffer[137] = roty; Send(buffer); if (hasChangeModel) { UpdateModels(); } }
void SendKick(string message, bool sync) { byte[] buffer = new byte[65]; buffer[0] = Opcode.Kick; NetUtils.WriteAscii(message, buffer, 1); SendRaw(buffer, sync); }
public void SendUserMOTD() { byte[] buffer = new byte[131]; buffer[0] = Opcode.Handshake; buffer[1] = Server.version; if (level.motd == "ignore") { NetUtils.WriteAscii(Server.name, buffer, 2); if (!String.IsNullOrEmpty(group.MOTD)) { NetUtils.WriteAscii(group.MOTD, buffer, 66); } else { NetUtils.WriteAscii(Server.motd, buffer, 66); } } else { NetUtils.WriteAscii(level.motd, buffer, 2); if (level.motd.Length > 64) { NetUtils.WriteAscii(level.motd.Substring(64), buffer, 66); } } bool canPlace = Block.canPlace(this, Block.blackrock); buffer[130] = canPlace ? (byte)100 : (byte)0; SendRaw(buffer); }
public static byte[] ExtInfo(byte count) { byte[] buffer = new byte[67]; buffer[0] = Opcode.CpeExtInfo; NetUtils.WriteAscii("MCGalaxy " + Server.Version, buffer, 1); NetUtils.WriteI16((short)count, buffer, 65); return(buffer); }
public static byte[] ExtEntry(string name, int version) { byte[] buffer = new byte[69]; buffer[0] = Opcode.CpeExtEntry; NetUtils.WriteAscii(name, buffer, 1); NetUtils.WriteI32(version, buffer, 65); return(buffer); }
static void WriteMapAppearance(byte[] buffer, string url, byte side, byte edge, int sideLevel) { buffer[0] = Opcode.CpeEnvSetMapApperance; NetUtils.WriteAscii(url, buffer, 1); buffer[65] = side; buffer[66] = edge; NetUtils.WriteI16((short)sideLevel, buffer, 67); }
public void SendChangeModel(byte id, string model) { byte[] buffer = new byte[66]; buffer[0] = Opcode.CpeChangeModel; buffer[1] = id; NetUtils.WriteAscii(model, buffer, 2); SendRaw(buffer); }
void SendExtEntry(string name, int version) { byte[] buffer = new byte[69]; buffer[0] = Opcode.CpeExtEntry; NetUtils.WriteAscii(name, buffer, 1); NetUtils.WriteI32(version, buffer, 65); SendRaw(buffer, true); }
void SendExtInfo(byte count) { byte[] buffer = new byte[67]; buffer[0] = Opcode.CpeExtInfo; NetUtils.WriteAscii("MCGalaxy " + Server.Version, buffer, 1); NetUtils.WriteI16((short)count, buffer, 65); SendRaw(buffer, true); }
public void SendMessage(byte id, string message, bool colorParse = true) { message = ConvertMessage(message, colorParse); int totalTries = 0; if (MessageRecieve != null) { MessageRecieve(this, message); } if (OnMessageRecieve != null) { OnMessageRecieve(this, message); } OnMessageRecieveEvent.Call(this, message); if (cancelmessage) { cancelmessage = false; return; } retryTag : try { foreach (string line in Wordwrap(message)) { string newLine = line; if (newLine.TrimEnd(' ')[newLine.TrimEnd(' ').Length - 1] < '!') { if (!HasCpeExt(CpeExt.EmoteFix)) { newLine += '\''; } } byte[] buffer = new byte[66]; buffer[0] = Opcode.Message; buffer[1] = (byte)id; if (HasCpeExt(CpeExt.FullCP437)) { NetUtils.WriteCP437(newLine, buffer, 2); } else { NetUtils.WriteAscii(newLine, buffer, 2); } SendRaw(buffer); } } catch (Exception e) { message = "&f" + message; totalTries++; if (totalTries < 10) { goto retryTag; } else { Server.ErrorLog(e); } } }
void SendTextHotKey(string label, string command, int keycode, byte mods) { byte[] buffer = new byte[134]; buffer[0] = Opcode.CpeSetTextHotkey; NetUtils.WriteAscii(label, buffer, 1); NetUtils.WriteAscii(command, buffer, 65); NetUtils.WriteI32(keycode, buffer, 129); buffer[133] = mods; SendRaw(buffer); }
public static byte[] TextHotKey(string label, string input, int keycode, byte mods) { byte[] buffer = new byte[134]; buffer[0] = Opcode.CpeSetTextHotkey; NetUtils.WriteAscii(label, buffer, 1); NetUtils.WriteAscii(input, buffer, 65); NetUtils.WriteI32(keycode, buffer, 129); buffer[133] = mods; return(buffer); }
public void SendSetMapAppearance(string url, byte sideblock, byte edgeblock, short sidelevel) { byte[] buffer = new byte[69]; buffer[0] = Opcode.CpeEnvSetMapApperance; NetUtils.WriteAscii(url, buffer, 1); buffer[65] = sideblock; buffer[66] = edgeblock; NetUtils.WriteI16(sidelevel, buffer, 67); SendRaw(buffer); }
public void SendExtAddPlayerName(byte id, string listName, string displayName, string grp, byte grpRank) { byte[] buffer = new byte[196]; buffer[0] = Opcode.CpeExtAddPlayerName; NetUtils.WriteI16(id, buffer, 1); NetUtils.WriteAscii(listName, buffer, 3); NetUtils.WriteAscii(displayName, buffer, 67); NetUtils.WriteAscii(grp, buffer, 131); buffer[195] = grpRank; SendRaw(buffer); }
public void WriteHeader(Stream stream, Level lvl) { byte[] header = new byte[4 * entrySize]; NetUtils.WriteAscii("CBDB", header, 0); header[4] = version; header[5] = 0; // ref year WriteU16(lvl.Width, header, 6); WriteU16(lvl.Height, header, 8); WriteU16(lvl.Length, header, 10); NetUtils.WriteAscii("MCGalaxy", header, entrySize); stream.Write(header, 0, header.Length); }
public void SendSetMapAppearanceV2(string url, byte sideblock, byte edgeblock, short sidelevel, short cloudHeight, short maxFog) { byte[] buffer = new byte[73]; buffer[0] = Opcode.CpeEnvSetMapApperance; NetUtils.WriteAscii(url, buffer, 1); buffer[65] = sideblock; buffer[66] = edgeblock; NetUtils.WriteI16(sidelevel, buffer, 67); NetUtils.WriteI16(cloudHeight, buffer, 69); NetUtils.WriteI16(maxFog, buffer, 71); SendRaw(buffer); }
public void SendExtAddEntity(byte id, string name, string displayname = "") { byte[] buffer = new byte[130]; buffer[0] = Opcode.CpeExtAddEntity; buffer[1] = id; NetUtils.WriteAscii(name, buffer, 2); if (displayname == "") { displayname = name; } NetUtils.WriteAscii(displayname, buffer, 66); SendRaw(buffer); }
/// <summary> Sends a raw message without performing any token resolving, emoticon parsing, or color parsing. </summary> public void SendRawMessage(CpeMessageType id, string message) { byte[] buffer = new byte[66]; buffer[0] = Opcode.Message; buffer[1] = (byte)id; if (HasCpeExt(CpeExt.FullCP437)) { NetUtils.WriteCP437(message, buffer, 2); } else { NetUtils.WriteAscii(message, buffer, 2); } SendRaw(buffer); }
public void SendMakeSelection(byte id, string label, short smallx, short smally, short smallz, short bigx, short bigy, short bigz, short r, short g, short b, short opacity) { byte[] buffer = new byte[86]; buffer[0] = Opcode.CpeMakeSelection; buffer[1] = id; NetUtils.WriteAscii(label, buffer, 2); NetUtils.WriteI16(smallx, buffer, 66); NetUtils.WriteI16(smally, buffer, 68); NetUtils.WriteI16(smallz, buffer, 70); NetUtils.WriteI16(bigx, buffer, 72); NetUtils.WriteI16(bigy, buffer, 74); NetUtils.WriteI16(bigz, buffer, 76); NetUtils.WriteI16(r, buffer, 78); NetUtils.WriteI16(g, buffer, 80); NetUtils.WriteI16(b, buffer, 82); NetUtils.WriteI16(opacity, buffer, 84); SendRaw(buffer); }
public void SendSpawn(byte id, string name, ushort x, ushort y, ushort z, byte rotx, byte roty) { byte[] buffer = new byte[74]; buffer[0] = Opcode.AddEntity; buffer[1] = id; NetUtils.WriteAscii(name.TrimEnd('+'), buffer, 2); NetUtils.WriteU16(x, buffer, 66); NetUtils.WriteU16(y, buffer, 68); NetUtils.WriteU16(z, buffer, 70); buffer[72] = rotx; buffer[73] = roty; SendRaw(buffer); if (hasChangeModel) { UpdateModels(); } }
public void SendChangeModel(byte id, string model) { // Fallback block models for clients that don't support block definitions byte block; bool fallback = byte.TryParse(model, out block) && block >= Block.CpeCount; block = level == null ? block : level.GetFallback(block); if (fallback && !hasBlockDefs && block != Block.air) { model = block.ToString(); } byte[] buffer = new byte[66]; buffer[0] = Opcode.CpeChangeModel; buffer[1] = id; NetUtils.WriteAscii(model, buffer, 2); Send(buffer); }
public void SendExtAddEntity2(byte id, string skinName, string displayName, ushort x, ushort y, ushort z, byte rotx, byte roty) { byte[] buffer = new byte[138]; buffer[0] = Opcode.CpeExtAddEntity2; buffer[1] = id; NetUtils.WriteAscii(displayName.TrimEnd('+'), buffer, 2); NetUtils.WriteAscii(skinName.TrimEnd('+'), buffer, 66); NetUtils.WriteU16(x, buffer, 130); NetUtils.WriteU16(y, buffer, 132); NetUtils.WriteU16(z, buffer, 134); buffer[136] = rotx; buffer[137] = roty; SendRaw(buffer); if (hasChangeModel) { UpdateModels(); } }
public static byte[] MakeSelection(byte id, string label, Vec3U16 p1, Vec3U16 p2, short r, short g, short b, short opacity) { byte[] buffer = new byte[86]; buffer[0] = Opcode.CpeMakeSelection; buffer[1] = id; NetUtils.WriteAscii(label, buffer, 2); NetUtils.WriteU16(p1.X, buffer, 66); NetUtils.WriteU16(p1.Y, buffer, 68); NetUtils.WriteU16(p1.Z, buffer, 70); NetUtils.WriteU16(p2.X, buffer, 72); NetUtils.WriteU16(p2.Y, buffer, 74); NetUtils.WriteU16(p2.Z, buffer, 76); NetUtils.WriteI16(r, buffer, 78); NetUtils.WriteI16(g, buffer, 80); NetUtils.WriteI16(b, buffer, 82); NetUtils.WriteI16(opacity, buffer, 84); return(buffer); }
/// <summary> Sends a packet indicating an entity was spawned in the current map /// at the given absolute position + coordinates </summary> public void SendSpawn(byte id, string name, ushort x, ushort y, ushort z, byte rotx, byte roty) { // NOTE: Fix for standard clients if (id == Entities.SelfID) { y -= 22; } byte[] buffer = new byte[74]; buffer[0] = Opcode.AddEntity; buffer[1] = id; NetUtils.WriteAscii(name.TrimEnd('+'), buffer, 2); NetUtils.WriteU16(x, buffer, 66); NetUtils.WriteU16(y, buffer, 68); NetUtils.WriteU16(z, buffer, 70); buffer[72] = rotx; buffer[73] = roty; Send(buffer); if (hasChangeModel) { UpdateModels(); } }