1 /** 2 * Replay an IRC session from an IrcClient log file. 3 * 4 * License: 5 * This Source Code Form is subject to the terms of 6 * the Mozilla Public License, v. 2.0. If a copy of 7 * the MPL was not distributed with this file, You 8 * can obtain one at http://mozilla.org/MPL/2.0/. 9 * 10 * Authors: 11 * Stéphan Kochen <stephan@kochen.nl> 12 * Vladimir Panteleev <vladimir@thecybershadow.net> 13 * Vincent Povirk <madewokherd@gmail.com> 14 * Simon Arlott 15 */ 16 17 module ae.net.irc.clientreplay; 18 19 import ae.net.asockets; 20 21 class IrcClientLogSource : IConnection 22 { 23 bool isConnected; 24 @property ConnectionState state() { return isConnected ? ConnectionState.connected : ConnectionState.disconnected; } 25 26 void send(Data[] data, int priority) {} 27 alias send = IConnection.send; 28 29 void disconnect(string reason = defaultDisconnectReason, DisconnectType type = DisconnectType.requested) {} 30 31 @property void handleConnect(ConnectHandler value) { connectHandler = value; } 32 private ConnectHandler connectHandler; 33 34 @property void handleReadData(ReadDataHandler value) 35 { 36 readDataHandler = value; 37 } 38 private ReadDataHandler readDataHandler; 39 40 @property void handleDisconnect(DisconnectHandler value) {} 41 @property void handleBufferFlushed(BufferFlushedHandler value) {} 42 43 void recv(Data data) 44 { 45 if (readDataHandler) 46 readDataHandler(data); 47 } 48 49 void run(string fn) 50 { 51 import std.algorithm; 52 import std.stdio; 53 54 isConnected = true; 55 connectHandler(); 56 57 foreach (line; File(fn).byLine(KeepTerminator.yes)) 58 { 59 if (line[0] != '[') 60 continue; 61 line = line.findSplit("] ")[2]; 62 if (line[0] == '<') 63 recv(Data(line[2..$])); 64 } 65 } 66 }