This repository has been archived by the owner on Apr 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
sendinittoserver.c
149 lines (123 loc) · 4.12 KB
/
sendinittoserver.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
/*******************************************************************************
*
* lightweight - a minimalistic chanserv for ircu's p10-protocol
*
* copyright 2002 by Rasmus Have & David Mansell
*
* $Id: sendinittoserver.c,v 1.17 2003/09/08 01:19:25 zarjazz Exp $
*
*******************************************************************************/
/*
This file is part of lightweight.
lightweight 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; either version 2 of the License, or
(at your option) any later version.
lightweight 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 lightweight; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <lightweight.h>
#include <globalexterns.h>
/* Local function, only used here. */
int GetLine(char *buffer)
{
/* Reads one byte at a time from serverfd until it has gotten a whole line.
* Buffer must be atleast 513 bytes long.
*/
return (1);
}
int ErrorCheck(void)
{
/* check for errors */
if (!strncmp(currentline, "ERROR", 5)) {
Error(ERR_FATAL | ERR_PROTOCOL, currentline);
return (1);
}
return (0);
}
int SendInitToServer(void)
{
/* Initialises the connection with the server. */
char buf[512];
int starttime = time(NULL);
int blanksfound = 0;
char *mypos;
int i;
char maxuserstr[4];
char MyServerName[SERVERNAMELENGTH];
/* Send pass-string. */
sprintf(buf, "PASS :%s\r\n", server_pass);
SendLine(buf);
/* Send server-string. */
sprintf(buf, "SERVER %s 1 %d %d J10 %sAAD +s :%s\r\n", my_servername, starttime, starttime, my_numeric,
my_description);
SendLine(buf);
/* Send our nick string */
sprintf(buf, "%s N %s 1 %d TheLBot %s +odkr L B]AAAB %sAAA :%s\r\n", my_numeric, my_nick, starttime, my_servername,
my_numeric, my_description);
SendLine(buf);
/* End of burst is removed from here now -- splidge */
for (i = 0; i <= 1; i++) {
while (!GetLineFromChunk()) {
ReadChunk(); /* First pass will get the PASS line, second pass will get the SERVER line */
}
ErrorCheck(); /* check for errors on each pass */
}
/* Server response will be: */
/* SERVER (name) 1 (starttime) (linktime) J10 (num,maxclients) 0 :(description) */
/* skip over "SERVER" */
mypos = currentline;
while (*mypos != ' ') {
if (mypos == '\0')
Error(ERR_FATAL | ERR_PROTOCOL, "Invalid SERVER line");
mypos++;
}
/* Copy server name */
i = 0;
mypos++;
while (*mypos != ' ') {
if (mypos == '\0') {
Error(ERR_FATAL | ERR_PROTOCOL, "Invalid SERVER line");
}
MyServerName[i] = *mypos;
i++;
if (i == (SERVERNAMELENGTH - 1)) {
Error(ERR_ERROR | ERR_PROTOCOL, "Server name too long");
break;
}
mypos++;
}
MyServerName[i] = '\0';
/* Now look for the section with numeric and maxusers... */
for (;; mypos++) {
if (*mypos == '\0') {
/* Erk. We ran out of line :( */
Error(ERR_ERROR | ERR_PROTOCOL, "Invalid SERVER line");
} else if (*mypos == ' ') {
/* Got a space.. */
if (++blanksfound == 5)
break;
}
}
MyServer[0] = *(++mypos);
MyServer[1] = *(++mypos);
MyServer[2] = '\0';
maxuserstr[0] = *(++mypos);
maxuserstr[1] = *(++mypos);
maxuserstr[2] = *(++mypos);
maxuserstr[3] = '\0';
AddServer(NumericToLong(MyServer, 2), MyServerName, NumericToLong(maxuserstr, 3) + 1, NumericToLong(my_numeric, 2));
Error(ERR_DEBUG | ERR_PROTOCOL, "Got SERVER response: %s", currentline);
printf("I am connected to: %s\n", MyServer);
/* Get pass-string with GetLine(). */
/* Get server-string with GetLine(). */
/* (These calls are necessary as the two first lines from the server
* does not follow the standard)
*/
return (1);
}