} //main ends public static RoomInfoDatum ByteToRoomInfoDatum(byte[] input) { RoomInfoDatum ro = new RoomInfoDatum(); ro.roomNumber = input[0]; byte[] temp = new byte[Marshal.SizeOf(typeof(RoomInfoDatum)) - 2]; Array.ConstrainedCopy(input, 1, temp, 0, temp.Length); ro.roomTitle = Encoding.UTF8.GetString(temp); ro.userCount = input[input.Length - 1]; return(ro); }
public static void GetList() { ChatProtocol roomListInfo; ushort dataLength; byte part = 0; byte numberPart = 0; byte[] temp = new byte[22]; RoomInfoDatum roomInfoTemp = new RoomInfoDatum(); do { roomListInfo = Connection.ServerToClient(Connection.cliSocket); if (roomListInfo.command == PacketMaker.CommandCode.ROOM_LIST_REQUEST) { dataLength = roomListInfo.fixedLengthField; byte[] roomData = roomListInfo.variableLengthField; part = roomData[0]; numberPart = roomData[1]; for (int i = 2; i <= (dataLength + 2); i++) { if (i < (dataLength + 2)) { temp[(i - 2) / 22] = roomData[i]; } if ((i - 2) % 22 == 0) { if (i != 2) { roomInfoTemp = ByteToRoomInfoDatum(temp); Console.Write("Room: " + roomInfoTemp.roomNumber + "\t" + roomInfoTemp.roomTitle + "\t" + roomInfoTemp.userCount + " user(s)."); } } } } else { //error } } while (part != numberPart); }