using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace mmoRLserver { public class Object { public int id = 0; public bool custom = false; public int customType = 0; public string link = ""; public bool solid = false; public string text = ""; public Object(int id = 0) { this.id = id; //Check for solid objects switch (id) { case 1: case 2: case 4: case 5: case 10: case 12: case 14: case 16: case 18: case 19: case 20: case 21: case 23: case 25: case 30: solid = true; break; } } public Object(byte[] serialized) { custom = true; System.IO.BinaryReader br = new System.IO.BinaryReader(new System.IO.MemoryStream(serialized)); customType = br.ReadByte(); this.id = br.ReadByte(); //Base object switch (customType) { case 1: //Cave entrance case 2: //Stairs case 3: //Passage { int linkLength = br.ReadByte(); link = Encoding.ASCII.GetString(br.ReadBytes(linkLength)); } break; case 4: //Sign { int textLength = br.ReadByte(); text = Encoding.ASCII.GetString(br.ReadBytes(textLength)); } break; } } public byte[] ExportCustom() { List toSend = new List(); toSend.Add((byte)customType); toSend.Add((byte)id); //Base object switch (customType) { case 1: //Cave entrance case 2: //Stairs case 3: //Passage { byte[] linkBytes = Encoding.ASCII.GetBytes(link); toSend.Add((byte)linkBytes.Length); for (int i = 0; i < linkBytes.Length; i++) toSend.Add(linkBytes[i]); } break; case 4: //Sign { byte[] textBytes = Encoding.ASCII.GetBytes(text); toSend.Add((byte)textBytes.Length); for (int i = 0; i < textBytes.Length; i++) toSend.Add(textBytes[i]); } break; } byte[] finalSend = new byte[toSend.Count + 2]; finalSend[0] = 0xFF; finalSend[1] = (byte)toSend.Count; for (int i = 0; i < toSend.Count; i++) { finalSend[i + 2] = toSend[i]; } return finalSend; } } }