summaryrefslogtreecommitdiff
path: root/replay.h
blob: de0f3ded6fd1648858eec43f712457d8add63e80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * This file is part of blabouncer (https://www.blatech.co.uk/l_bratch/blabouncer).
 * Copyright (C) 2019 Luke Bratch <luke@bratch.co.uk>.
 *
 * Blabouncer is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3.
 *
 * Blabouncer 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 GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with blabouncer. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef REPLAY_H_INCLUDED
#define REPLAY_H_INCLUDED

#define _XOPEN_SOURCE
#define _XOPEN_SOURCE_EXTENDED
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include <limits.h>

#include "functions.h"

#define DEBUG_CRIT 0
#define DEBUG_SOME 1
#define DEBUG_FULL 2

#define MAXCHAR 1000
#define TIMELEN 11 // 32-bit unixtime is up to 10 characters (+1 for null char) // TODO - Make this Year 2038 proof
#define TIMELENF 11 // [HH:MM:SS] = 10 characters + 1 for null char
#define DATETIMELEN 50 // Should be enough for a full datetime string // TODO - Is it!?  I think it will only ever be as long as [DD/MM/YY HH:MM:SS] (20 including null)

// Return the number of lines in the replay log since 'seconds' seconds ago, or -1 if there a problem.
// 'basedir' is the directory in which to find 'replay.log'.
int replaylinestime(int seconds, char *basedir);

int readreplayline(int seconds, int linenum, char *str, int *origtimestamp, struct settings *settings, struct ircdstate *ircdstate);

// Returns the line number in the replay log file on which 'nick' last spoke, or -1 if there is a problem.
// 'basedir' is the directory in which to find 'replay.log'.
long lastspokelinenumber(char *nick, char *basedir);

// Send the requested number of seconds worth of replay log lines to the requested client.
// 'sourcefd' is the client to send to, and 'replayseconds' is the number of
// seconds of replay log to replay.
// Returns 1 for success or 0 for failure.
int doreplaytime(int sourcefd, int replayseconds, struct client *clients, struct settings *settings, struct ircdstate *ircdstate, struct channel *channels);

// Send replay log lines from line number 'linenumber' onwards, to client 'sourcefd'.
// Returns 1 for success or 0 for failure.
int doreplaylastspoke(int sourcefd, long linenumber, struct client *clients, struct settings *settings, struct ircdstate *ircdstate, struct channel *channels);

// Write the line 'str' to the replay log file after prepending it with
// the current unixtime timestamp.  'basedir' is the directory in which
// to write to 'replay.log'.
// Expects a string in the format:
// :from!bar@baz PRIVMSG to :hello world
// With the ":foo!bar@baz "prefix being important.
// Returns the number of bytes written on success, or 0 on failure.
int writereplayline(char *str, char *basedir);

#endif