Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/dll/autocycle/autocycle.c
1069 views
1
/*
2
* dll/autocycle/autocycle.c - Auto-cycle plugin for BitchX
3
* Copyright (c) David Walluck 1999
4
*/
5
6
#include "irc.h"
7
#include "struct.h"
8
#include "server.h"
9
#include "vars.h"
10
#include "misc.h"
11
#include "module.h"
12
#include "hook.h"
13
#ifndef INIT_MODULE
14
#define INIT_MODULE
15
#endif
16
#include "modval.h"
17
18
#define MODULE_NAME "Autocycle"
19
#define _MODULE_VERSION "0.01"
20
21
int auto_cycle(IrcCommandDll *interp, char *command, char *args, char *subargs)
22
{
23
char * channel = current_window->current_channel;
24
int netsplit = (int)next_arg(args, &args);
25
int this_server = current_window->server;
26
ChannelList * chan = lookup_channel(channel, this_server, 0);
27
NickList * tmp = NULL;
28
int counter = 0;
29
30
/*
31
* This may look a little odd, but I had a hard time assuring otherwise
32
* that there's only one person left on the channel
33
*/
34
for (tmp = next_nicklist(chan, NULL); tmp && counter != 2; tmp = next_nicklist(chan, tmp), counter++);
35
36
if (get_dllint_var("AUTO_CYCLE"))
37
{
38
if (counter == 1 && (!netsplit || get_dllint_var("AUTO_CYCLE") > 1) && !is_chanop(channel, get_server_nickname(from_server)) && channel[0] != '+')
39
{
40
put_it("%s", convert_output_format("$G Auto-cycling $0 to gain ops", "%s", channel));
41
my_send_to_server(from_server, "PART %s\nJOIN %s%s%s",chan->channel, chan->channel, chan->key ? " " : "", chan->key ? chan->key : "");
42
return 1;
43
}
44
}
45
return 0;
46
}
47
48
int Autocycle_Cleanup(IrcCommandDll **interp, Function_ptr *global_table)
49
{
50
remove_module_proc(VAR_PROC, MODULE_NAME, NULL, NULL);
51
remove_module_proc(HOOK_PROC, MODULE_NAME, NULL, NULL);
52
put_it("%s", convert_output_format("$G $0 $1 by DavidW2 unloaded","%s %s", MODULE_NAME, _MODULE_VERSION));
53
return 2;
54
}
55
56
int Autocycle_Init(IrcCommandDll **interp, Function_ptr *global_table)
57
{
58
initialize_module(MODULE_NAME);
59
add_module_proc(VAR_PROC, MODULE_NAME, "AUTO_CYCLE", NULL, INT_TYPE_VAR, 0, NULL, NULL);
60
add_module_proc(HOOK_PROC, MODULE_NAME, NULL, "*", NETSPLIT_LIST, 1, NULL, auto_cycle);
61
put_it("%s", convert_output_format("$G $0 $1 by DavidW2 loaded", "%s %s", MODULE_NAME, _MODULE_VERSION));
62
return 0;
63
}
64
65