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 42 void recv(Data data) 43 { 44 if (readDataHandler) 45 readDataHandler(data); 46 } 47 48 void run(string fn) 49 { 50 import std.algorithm; 51 import std.stdio; 52 53 isConnected = true; 54 connectHandler(); 55 56 foreach (line; File(fn).byLine(KeepTerminator.yes)) 57 { 58 if (line[0] != '[') 59 continue; 60 line = line.findSplit("] ")[2]; 61 if (line[0] == '<') 62 recv(Data(line[2..$])); 63 } 64 } 65 }