/* Thor Server 2.0 Project - Codenamed "Stockholm" Copyright 2008 - 2009 Joe Hegarty This file is part of The Thor Server 2.0 Project - Codenamed "Stockholm". The Thor Server 2.0 Project - Codenamed "Stockholm" is free software: you can redistribute it and/or modify it under the terms of the Microsoft Public License The Thor Server Project is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Microsoft Public License for more details. You should have received a copy of the Microsoft Public License along with The Thor Server Project. If not, see http://www.opensource.org/licenses/ms-pl.html */ using System; using System.Collections.Generic; using StockholmLibrary.Net; namespace StockholmLibrary.Game.Packets.Server { //------------------------------------ public class FlatListPacket : ServerPacket { private bool _hideFullCategories; StockholmLibrary.Data.RoomCategory _category; List _subcategoryList; List _roomList; //********************************************** public FlatListPacket(bool hideFullCategories, StockholmLibrary.Data.RoomCategory category, List subcategoryList, List roomList) { _packetType = EServerPacket.FLAT_LIST; _hideFullCategories = hideFullCategories; _category = category; _subcategoryList = subcategoryList; _roomList = roomList; } //********************************************** protected override void SerialiseBody() { SerialiseCategory(); SerialiseRooms(); SerialiseSubcategories(); } //********************************************** private void SerialiseRooms() { if (_category.SystemCategory == true) { SerialisePublicRooms(); } else { SerialisePrivateRooms(); } } //********************************************** private void SerialisePrivateRooms() { foreach (var room in _roomList) { WriteIntWired(room.RoomID); WriteStringRaw(room.RoomName); WriteListDelimiter(); if (room.ShowOwner != null && (bool) room.ShowOwner) { WriteStringRaw(room.User.Username); } WriteListDelimiter(); WriteStringRaw(room.RoomState.StatusName); WriteListDelimiter(); WriteIntWired(0); // TODO: Current Users WriteIntWired(room.MaxGuests); WriteStringRaw(room.RoomDescription); WriteListDelimiter(); } } //********************************************** private void SerialisePublicRooms() { foreach (var room in _roomList) { WriteIntWired(room.RoomID); WriteIntWired(1); // ? WriteStringRaw(room.RoomName); WriteListDelimiter(); WriteIntWired(0); // TODO: Current Users WriteIntWired(room.MaxGuests); WriteIntWired(room.CategoryID); WriteStringRaw(room.RoomDescription); WriteListDelimiter(); WriteIntWired(room.RoomID); WriteIntWired(0); // ? WriteStringRaw(room.RoomModel.CCTList); WriteListDelimiter(); WriteIntWired(0); // ? WriteIntWired(1); // ? } } //********************************************** private void SerialiseCategory() { WriteBoolWired(_hideFullCategories); WriteIntWired(_category.RoomCategoryID); if (_category.SystemCategory == true) { WriteIntWired(0); // Public } else { WriteIntWired(2); // Private } WriteStringRaw(_category.RoomCategoryName); WriteListDelimiter(); WriteIntWired(0); // ? WriteIntWired(10000); // ? int? nullableParentId = _category.RoomCategoryParent; int parentId = nullableParentId == null ? 0 : (int)nullableParentId; WriteIntWired(parentId); if (_category.SystemCategory == false) { WriteIntWired(_roomList.Count); } } //********************************************** private void SerialiseSubcategories() { foreach (var category in _subcategoryList) { WriteIntWired(category.RoomCategoryID); WriteIntWired(0); // ? WriteStringRaw(category.RoomCategoryName); WriteListDelimiter(); WriteIntWired(0); // TODO: Current number of users WriteIntWired(0); // TODO: Max number of users WriteIntWired((int)category.RoomCategoryParent); } } } }