This repository has been archived by the owner on May 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
util.c
173 lines (167 loc) · 3.8 KB
/
util.c
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include "AntiQubick.h"
#include "util.h"
#include "time.h"
#include <stdio.h>
#include <stdarg.h>
void
error(const char *msg)
{
fprintf(stderr,msg);
puts("");
exit(-1);
}
void
noSpoof(char*buffer,char*ping)
{
while(*buffer != ':' && *buffer) buffer++;
if(*buffer == ':')
while(*buffer)
*ping++=*buffer++;
else
*ping='\0';
}
void
grepPing(char * buffer,char*ping)
{
while(*buffer != 'P'
|| *(buffer+1) != 'I'
|| *(buffer+2) != 'N'
|| *(buffer+3) != 'G'
&& *buffer) //shitcode :o
{
printf("%c",*buffer);
*buffer++;
}
buffer=buffer+5;
if(*buffer == ':')
while(*buffer!='\n')
*ping++=*buffer++;
else
*ping='\0';
}//end
unsigned int
CountString(FILE*file)
{
unsigned int count=0;
char ch;
if(file == NULL) error("CRITICAL_ERROR: Not readable file");
while( (ch=fgetc(file)) != EOF)
if(ch=='\n') count++;
return count;
}
void
getRandomStringFromFie(char*file,char*buffer)
{
FILE*trollFile=fopen(file,"r");
if(trollFile == NULL) error("CRITICAL_ERROR: No can find this file troll.txt in the directory");
srand ( time(NULL) );
unsigned auto strings = CountString(trollFile);
unsigned auto randomString = rand() % strings;
unsigned auto count=0;
char ch;
rewind(trollFile);
while((ch=fgetc(trollFile)) !=EOF)
{
if(ch=='\n')count++;
if(count == randomString)
{
while((ch=fgetc(trollFile)) !='\n')*buffer++=ch;
*buffer++='\0';
break;
}
}
close(trollFile);
}
void
Troll(int socket)
{
if(FORFUCKOFF < NEEDFORFUCKOFF)
{
char tmp[SIZEBUFFER];
char buffer[SIZEBUFFER/2];
bzero(tmp,SIZEBUFFER);
bzero(buffer,SIZEBUFFER/2);
getRandomStringFromFie("troll.txt",buffer);
sprintf(tmp,"PRIVMSG %s %s", DEFAULT_CHANNEL,buffer );
writeTo(socket,tmp);
}
}
void
QUIT(int socket)
{
writeTo(socket, "QUIT leaving");
raise(9);
}
void
_setSetting(char*setting,char*set)
{
if(strcmp(setting,"CHANNEL") == 0)
strcpy(DEFAULT_CHANNEL,set);
if(strcmp(setting,"owner") == 0)
strcpy(OWNER,set);
if(strcmp(setting,"OWNER_NICK") == 0)
strcpy(OWNER_NICK,set);
if(strcmp(setting,"NEEDFORDISABLE") == 0)
NEEDFORFUCKOFF=(unsigned long long)atoi(set);
if(strcmp(setting,"TIMETROLL") == 0)
TIMETROLL=(unsigned int)atoi(set);
if(strcmp(setting,"TIMEDW") == 0)
TIMEDW=(unsigned int)atoi(set);
if(strcmp(setting,"MAXPOWN") == 0)
MAXPOWN=(unsigned long long)atoi(set);
if(strcmp(setting,"MAXNUM") == 0)
MAXNUM=(unsigned long long)atoi(set);
if(strcmp(setting,"PINGTIME") == 0)
PINGTIME=(unsigned long long)atoi(set);
if(strcmp(setting,"WAITMESSAGES") == 0 && atoi(set) == 1)
WAITMESSAGE=true;
bzero(setting,SIZEBUFFER);
bzero(set,SIZEBUFFER);
}
void
InitConfig( char*ConfigFile )
{
FILE * config = fopen(ConfigFile,"r");;
if(config == NULL) error("CRITICAL_ERROR: No can read config.ini");
unsigned int counter=0;
char setting[SIZEBUFFER];
char set[SIZEBUFFER];
char ch;
bool _thisSet=false;
while ( (ch = fgetc( config )) != EOF)
{
if(ch=='='){_thisSet=true;setting[counter++]='\0';counter=0;}
if(ch=='\n'){_thisSet=false;set[counter++]='\0';counter=0;_setSetting(setting,set);}
if(_thisSet==false && ch != '\n' && ch != '=') setting[ counter++ ]=ch;
if(_thisSet==true && ch != '\n' && ch != '=') set[ counter++ ]=ch;
}
fclose(config);
}
void PingPong(char*buffer,int * socket)
{
char ping[SMALLBUFFER];
bzero(ping,SMALLBUFFER);
if(strstr(buffer,"PING") != NULL)
{
printf("INFO: Try get Ping-Pong\n");
grepPing(buffer,ping);
if(!*ping)
printf("WARNING: This IRC server?\n");
else
{
printf("INFO: Okey write PONG %s\n",ping);
sprintf(buffer,"PONG %s",ping);
printf("INFO: Write this %s to server\n",buffer);
writeTo(*socket,buffer);
printf("INFO: Pong pong..\n");
}
}//if
if(strstr(buffer,"nospoof") != NULL)
{
printf("INFO: No spoof..\n");
noSpoof(buffer,ping);
sprintf(buffer,"PONG %s",ping);
if(ping != '\0') writeTo(*socket,buffer);
else printf("ERROR: all bad?\n");
}
}