public static Packet MakeExtAddPlayerName(short nameId, string playerName, string listName, string groupName, byte groupRank, bool useFallbacks, bool hasCP437) { if (playerName == null) { throw new ArgumentNullException("playerName"); } if (listName == null) { throw new ArgumentNullException("listName"); } if (groupName == null) { throw new ArgumentNullException("groupName"); } Packet packet = new Packet(OpCode.ExtAddPlayerName); //Logger.Log(LogType.Debug, "Send: MakeExtAddPlayerName({0}, {1}, {2}, {3}, {4})", nameId, playerName, listName, groupName, groupRank); WriteI16(nameId, packet.Bytes, 1); PacketWriter.WriteString(Color.SubstituteSpecialColors(playerName, useFallbacks), packet.Bytes, 3, hasCP437); PacketWriter.WriteString(Color.SubstituteSpecialColors(listName, useFallbacks), packet.Bytes, 67, hasCP437); PacketWriter.WriteString(Color.SubstituteSpecialColors(groupName, useFallbacks), packet.Bytes, 131, hasCP437); packet.Bytes[195] = groupRank; return(packet); }
/// <summary> Creates a new AddEntity (0x07) packet. </summary> /// <param name="id"> Entity ID. Negative values refer to "self". </param> /// <param name="name"> Entity name. May not be null. </param> /// <param name="spawn"> Spawning position for the player. </param> /// <param name="hasCP437"> If packet contains characters from CodePage 437 </param> /// <param name="extPos"> If player supports Extended Positions </param> /// <exception cref="ArgumentNullException"> name is null </exception> public static Packet MakeAddEntity(sbyte id, [NotNull] string name, Position spawn, bool hasCP437, bool extPos) { if (name == null) { throw new ArgumentNullException("name"); } int size = PacketSizes[(byte)OpCode.AddEntity]; if (extPos) { size += 6; } Packet packet = new Packet(OpCode.AddEntity, size); //Logger.Log(LogType.Debug, "Send: MakeAddEntity({0}, {1}, {2})", id, name, spawnPosition); packet.Bytes[1] = (byte)id; PacketWriter.WriteString(name, packet.Bytes, 2, hasCP437); int posSize = WritePos(spawn, packet.Bytes, 66, extPos); packet.Bytes[66 + posSize] = spawn.R; packet.Bytes[67 + posSize] = spawn.L; return(packet); }
public static Packet MakeExtAddEntity2(sbyte entityId, string inGameName, string skin, Position spawn, bool hasCP437, bool extPos) { if (inGameName == null) { inGameName = entityId.ToString(); } if (skin == null) { skin = inGameName; } int size = PacketSizes[(byte)OpCode.ExtAddEntity2]; if (extPos) { size += 6; } Packet packet = new Packet(OpCode.ExtAddEntity2, size); packet.Bytes[1] = (byte)entityId; PacketWriter.WriteString(inGameName, packet.Bytes, 2, hasCP437); PacketWriter.WriteString(skin, packet.Bytes, 66, hasCP437); int posSize = WritePos(spawn, packet.Bytes, 130, extPos); packet.Bytes[130 + posSize] = spawn.R; packet.Bytes[131 + posSize] = spawn.L; return(packet); }
static void MakeDefineBlockStart(BlockDefinition def, ref int index, ref Packet packet, bool uniqueSideTexs, bool hasCP437) { // speed = 2^((raw - 128) / 64); // therefore raw = 64log2(speed) + 128 byte rawSpeed = (byte)(64 * Math.Log(def.Speed, 2) + 128); packet.Bytes[index++] = def.BlockID; PacketWriter.WriteString(def.Name, packet.Bytes, index, hasCP437); index += 64; packet.Bytes[index++] = def.CollideType; packet.Bytes[index++] = rawSpeed; packet.Bytes[index++] = def.TopTex; if (uniqueSideTexs) { packet.Bytes[index++] = def.LeftTex; packet.Bytes[index++] = def.RightTex; packet.Bytes[index++] = def.FrontTex; packet.Bytes[index++] = def.BackTex; } else { packet.Bytes[index++] = def.RightTex; } packet.Bytes[index++] = def.BottomTex; packet.Bytes[index++] = (byte)(def.BlocksLight ? 0 : 1); packet.Bytes[index++] = def.WalkSound; packet.Bytes[index++] = (byte)(def.FullBright ? 1 : 0); }
public static Packet MakeMakeSelection(byte selectionId, [NotNull] string label, [NotNull] BoundingBox bounds, string color, short opacity, bool hasCP437) { if (label == null) { throw new ArgumentNullException("label"); } if (bounds == null) { throw new ArgumentNullException("bounds"); } Packet packet = new Packet(OpCode.MakeSelection); packet.Bytes[1] = selectionId; PacketWriter.WriteString(label, packet.Bytes, 2, hasCP437); WriteI16((short)bounds.XMin, packet.Bytes, 66); WriteI16((short)bounds.ZMin, packet.Bytes, 68); WriteI16((short)bounds.YMin, packet.Bytes, 70); WriteI16((short)(bounds.XMax + 1), packet.Bytes, 72); WriteI16((short)(bounds.ZMax + 1), packet.Bytes, 74); WriteI16((short)(bounds.YMax + 1), packet.Bytes, 76); CustomColor c = Color.ParseHex(color); WriteI16(c.R, packet.Bytes, 78); WriteI16(c.G, packet.Bytes, 80); WriteI16(c.B, packet.Bytes, 82); WriteI16(opacity, packet.Bytes, 84); return(packet); }
/// <summary> Creates a new Message (0x0D) packet. </summary> /// <param name="type"> Message type. </param> /// <param name="message"> Message. </param> /// <param name="useFallbacks"> whether or not to use color fallback codes. </param> /// <param name="hasCP437"> Whether client supports extended code page 437 characters. </param> public static Packet Message(byte type, string message, bool useFallbacks, bool hasCP437) { Packet packet = new Packet(OpCode.Message); packet.Bytes[1] = type; message = Color.Sys + Color.SubstituteSpecialColors(message, useFallbacks); PacketWriter.WriteString(message, packet.Bytes, 2, hasCP437); return(packet); }
public static Packet MakeExtInfo(string sname, short extCount) { //Logger.Log(LogType.Debug, "Send: ExtInfo({0} {1})", sname, extCount); Packet packet = new Packet(OpCode.ExtInfo); PacketWriter.WriteString(sname, packet.Bytes, 1, false); WriteI16(extCount, packet.Bytes, 65); return(packet); }
public static Packet MakeEnvSetMapUrl([NotNull] string textureUrl, bool hasCP437) { if (textureUrl == null) { throw new ArgumentNullException("textureUrl"); } Packet packet = new Packet(OpCode.SetEnvMapUrl); PacketWriter.WriteString(textureUrl, packet.Bytes, 1, hasCP437); return(packet); }
/// <summary> Creates a new Kick (0x0E) packet. </summary> /// <param name="reason"> Given reason. Only first 64 characters will be sent. May not be null. </param> /// <param name="hasCP437"> Whether client supports extended code page 437 characters. </param> /// <exception cref="ArgumentNullException"> reason is null </exception> public static Packet MakeKick([NotNull] string reason, bool hasCP437) { if (reason == null) { throw new ArgumentNullException("reason"); } reason = Color.SubstituteSpecialColors(reason, true); Packet packet = new Packet(OpCode.Kick); PacketWriter.WriteString(reason, packet.Bytes, 1, hasCP437); return(packet); }
public static Packet MakeChangeModel(sbyte id, [NotNull] string modelName, bool hasCP437) { if (modelName == null) { throw new ArgumentNullException("modelName"); } //Logger.Log(LogType.Debug, "Send: MakeChangeModel({0}, {1})", entityId, modelName); Packet packet = new Packet(OpCode.ChangeModel); packet.Bytes[1] = (byte)id; PacketWriter.WriteString(modelName, packet.Bytes, 2, hasCP437); return(packet); }
public static Packet MakeExtEntry([NotNull] string name, int version) { //Logger.Log(LogType.Debug, "Send: ExtEntry({0}, {1})", name, version); if (name == null) { throw new ArgumentNullException("name"); } Packet packet = new Packet(OpCode.ExtEntry); PacketWriter.WriteString(name, packet.Bytes, 1, false); WriteI32(version, packet.Bytes, 65); return(packet); }
public static Packet MakeEnvSetMapAppearance([NotNull] string textureUrl, byte sideBlock, byte edgeBlock, short sideLevel, bool hasCP437) { if (textureUrl == null) { throw new ArgumentNullException("textureUrl"); } Packet packet = new Packet(OpCode.EnvMapAppearance); PacketWriter.WriteString(textureUrl, packet.Bytes, 1, hasCP437); packet.Bytes[65] = sideBlock; packet.Bytes[66] = edgeBlock; WriteI16(sideLevel, packet.Bytes, 67); return(packet); }
public static Packet MakeEnvSetMapAppearance2([NotNull] string textureUrl, byte sideBlock, byte edgeBlock, short sideLevel, short cloudsHeight, short maxFog, bool hasCP437) { if (textureUrl == null) { throw new ArgumentNullException("textureUrl"); } int size = PacketSizes[(byte)OpCode.EnvMapAppearance] + 4; Packet packet = new Packet(OpCode.EnvMapAppearance, size); PacketWriter.WriteString(textureUrl, packet.Bytes, 1, hasCP437); packet.Bytes[65] = sideBlock; packet.Bytes[66] = edgeBlock; WriteI16(sideLevel, packet.Bytes, 67); WriteI16(cloudsHeight, packet.Bytes, 69); WriteI16(maxFog, packet.Bytes, 71); return(packet); }
public static Packet MakeExtAddEntity(byte entityId, [NotNull] string inGameName, [NotNull] string skinName, bool hasCP437) { if (inGameName == null) { throw new ArgumentNullException("inGameName"); } if (skinName == null) { throw new ArgumentNullException("skinName"); } Packet packet = new Packet(OpCode.ExtAddEntity); //Logger.Log(LogType.Debug, "Send: MakeExtAddEntity({0}, {1}, {2})", entityId, inGameName, skinName); packet.Bytes[1] = entityId; PacketWriter.WriteString(inGameName, packet.Bytes, 2, hasCP437); PacketWriter.WriteString(skinName, packet.Bytes, 66, hasCP437); return(packet); }
public static Packet MakeSetTextHotKey([NotNull] string label, [NotNull] string action, int keyCode, byte keyMods, bool hasCP437) { if (label == null) { throw new ArgumentNullException("label"); } if (action == null) { throw new ArgumentNullException("action"); } Packet packet = new Packet(OpCode.SetTextHotKey); PacketWriter.WriteString(label, packet.Bytes, 1, hasCP437); PacketWriter.WriteString(action, packet.Bytes, 65, hasCP437); WriteI32(keyCode, packet.Bytes, 129); packet.Bytes[133] = keyMods; return(packet); }