private void SendMessage(MUSServerMessage message) { this.SendData(message.GetBytes()); }
private void HandleMessage(MUSClientMessage message) { int errorCode = message.ReadInt32(); int timestamp = message.ReadInt32(); string subject = message.ReadEvenPaddedString(); string senderId = message.ReadEvenPaddedString(); string[] receivers = new string[message.ReadInt32()]; for (int i = 0; i < receivers.Length; i++) { receivers[i] = message.ReadEvenPaddedString(); } if (subject != "Logon") { short contentType = message.ReadShort(); } switch (subject) { case "Logon": { MUSServerMessage message_ = new MUSServerMessage("Logon", MUSType.String); message_.WriteEvenPaddedString("Skylight: The best emulator around"); this.SendMessage(message_); MUSServerMessage message_2 = new MUSServerMessage("HELLO", MUSType.String); message_2.WriteEvenPaddedString(""); this.SendMessage(message_2); } break; case "LOGIN": { string[] credentials = message.ReadEvenPaddedString().Split(new char[] { ' ' }, 2); GameClient gameClient = Skylight.GetGame().GetGameClientManager().GetGameClientById(uint.Parse(credentials[0])); if (gameClient != null && gameClient.MachineID == credentials[1]) { this.UserID = gameClient.GetHabbo().ID; } else { this.Dispose(); } } break; case "PHOTOTXT": { if (this.UserID > 0) { this.PhotoText = message.ReadEvenPaddedString().Substring(1); } } break; case "BINDATA": { if (this.UserID > 0 && this.PhotoText != null) { Dictionary <string, MUSPropListItem> props = message.ReadPropList(); Photo photo = new Photo(); photo.CS = MUSUtils.BytesToInt(props["cs"].Data); photo.Image = props["image"].Data; photo.Text = this.PhotoText; photo.Time = TimeUtilies.GetUnixTimestamp(); this.PhotoText = null; using (DatabaseClient dbClient = Skylight.GetDatabaseManager().GetClient()) { dbClient.AddParamWithValue("userId", this.UserID); uint itemId = (uint)dbClient.ExecuteQuery("INSERT INTO items(user_id, room_id, base_item, extra_data, wall_pos) VALUES(@userId, 0, 2268736439, '', '')"); if (itemId > 0) { string data = JsonConvert.SerializeObject(photo); dbClient.AddParamWithValue("itemId", itemId); dbClient.AddParamWithValue("data", data); dbClient.ExecuteQuery("INSERT INTO items_data(item_id, data) VALUES(@itemId, @data)"); } MUSServerMessage message_ = new MUSServerMessage("BINDATA_SAVED", MUSType.String); message_.WriteEvenPaddedString(itemId.ToString()); this.SendMessage(message_); Skylight.GetGame().GetGameClientManager().GetGameClientById(this.UserID).GetHabbo().GetInventoryManager().AddInventoryItemToHand(new InventoryItem(itemId, 2268736439, "")); Skylight.GetGame().GetGameClientManager().GetGameClientById(this.UserID).SendMessage(Skylight.GetGame().GetGameClientManager().GetGameClientById(this.UserID).GetHabbo().GetInventoryManager().OldSchoolGetHand("last")); } } } break; case "GETBINDATA": { uint itemId = uint.Parse(message.ReadEvenPaddedString().Split(' ')[0]); RoomItemPhoto roomItem = (RoomItemPhoto)Skylight.GetGame().GetGameClientManager().GetGameClientById(this.UserID).GetHabbo().GetRoomSession().GetRoom().RoomItemManager.TryGetWallItem(itemId); if (roomItem != null) { Dictionary <string, MUSPropListItem> data = new Dictionary <string, MUSPropListItem>(); data.Add("image", new MUSPropListItem(MUSType.Media, roomItem.Photo.Image)); data.Add("time", new MUSPropListItem(MUSType.String, Skylight.GetDefaultEncoding().GetBytes(TimeUtilies.UnixTimestampToDateTime(roomItem.Photo.Time).ToString()))); data.Add("cs", new MUSPropListItem(MUSType.Integer, MUSUtils.IntToBytes(roomItem.Photo.CS))); MUSServerMessage message_ = new MUSServerMessage("BINARYDATA", MUSType.PropList); message_.WritePropList(data); this.SendMessage(message_); } } break; } }