]> jfr.im git - irc/quakenet/lightweight.git/blame - sendinittoserver.c
Make L auth to the network when it connects
[irc/quakenet/lightweight.git] / sendinittoserver.c
CommitLineData
b23529fa 1/*******************************************************************************
2 *
3 * lightweight - a minimalistic chanserv for ircu's p10-protocol
4 *
5 * copyright 2002 by Rasmus Have & David Mansell
6 *
7 * $Id: sendinittoserver.c,v 1.17 2003/09/08 01:19:25 zarjazz Exp $
8 *
9 *******************************************************************************/
10
11/*
12 This file is part of lightweight.
13
14 lightweight is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 lightweight is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with lightweight; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27*/
28
29#include <lightweight.h>
30#include <globalexterns.h>
31
32/* Local function, only used here. */
33int GetLine(char *buffer)
34{
35 /* Reads one byte at a time from serverfd until it has gotten a whole line.
36 * Buffer must be atleast 513 bytes long.
37 */
38
39 return (1);
40}
41
42int ErrorCheck(void)
43{
44 /* check for errors */
45 if (!strncmp(currentline, "ERROR", 5)) {
46 Error(ERR_FATAL | ERR_PROTOCOL, currentline);
47 return (1);
48 }
49 return (0);
50}
51
52int SendInitToServer(void)
53{
54 /* Initialises the connection with the server. */
55 char buf[512];
56 int starttime = time(NULL);
57 int blanksfound = 0;
58 char *mypos;
59 int i;
60 char maxuserstr[4];
61 char MyServerName[SERVERNAMELENGTH];
62
63 /* Send pass-string. */
64
65 sprintf(buf, "PASS :%s\r\n", server_pass);
66 SendLine(buf);
67 /* Send server-string. */
68 sprintf(buf, "SERVER %s 1 %d %d J10 %sAAD +s :%s\r\n", my_servername, starttime, starttime, my_numeric,
69 my_description);
70 SendLine(buf);
71
72 /* Send our nick string */
97ea6b84 73 sprintf(buf, "%s N %s 1 %d TheLBot %s +odkr L B]AAAB %sAAA :%s\r\n", my_numeric, my_nick, starttime, my_servername,
b23529fa 74 my_numeric, my_description);
75 SendLine(buf);
76
77 /* End of burst is removed from here now -- splidge */
78
79 for (i = 0; i <= 1; i++) {
80 while (!GetLineFromChunk()) {
81 ReadChunk(); /* First pass will get the PASS line, second pass will get the SERVER line */
82 }
83 ErrorCheck(); /* check for errors on each pass */
84 }
85
86 /* Server response will be: */
87 /* SERVER (name) 1 (starttime) (linktime) J10 (num,maxclients) 0 :(description) */
88
89 /* skip over "SERVER" */
90 mypos = currentline;
91 while (*mypos != ' ') {
92 if (mypos == '\0')
93 Error(ERR_FATAL | ERR_PROTOCOL, "Invalid SERVER line");
94 mypos++;
95 }
96
97 /* Copy server name */
98 i = 0;
99 mypos++;
100 while (*mypos != ' ') {
101 if (mypos == '\0') {
102 Error(ERR_FATAL | ERR_PROTOCOL, "Invalid SERVER line");
103 }
104 MyServerName[i] = *mypos;
105 i++;
106 if (i == (SERVERNAMELENGTH - 1)) {
107 Error(ERR_ERROR | ERR_PROTOCOL, "Server name too long");
108 break;
109 }
110 mypos++;
111 }
112
113 MyServerName[i] = '\0';
114
115 /* Now look for the section with numeric and maxusers... */
116
117 for (;; mypos++) {
118 if (*mypos == '\0') {
119 /* Erk. We ran out of line :( */
120 Error(ERR_ERROR | ERR_PROTOCOL, "Invalid SERVER line");
121 } else if (*mypos == ' ') {
122 /* Got a space.. */
123 if (++blanksfound == 5)
124 break;
125 }
126 }
127
128 MyServer[0] = *(++mypos);
129 MyServer[1] = *(++mypos);
130 MyServer[2] = '\0';
131
132 maxuserstr[0] = *(++mypos);
133 maxuserstr[1] = *(++mypos);
134 maxuserstr[2] = *(++mypos);
135 maxuserstr[3] = '\0';
136
137 AddServer(NumericToLong(MyServer, 2), MyServerName, NumericToLong(maxuserstr, 3) + 1, NumericToLong(my_numeric, 2));
138
139 Error(ERR_DEBUG | ERR_PROTOCOL, "Got SERVER response: %s", currentline);
140 printf("I am connected to: %s\n", MyServer);
141
142 /* Get pass-string with GetLine(). */
143 /* Get server-string with GetLine(). */
144 /* (These calls are necessary as the two first lines from the server
145 * does not follow the standard)
146 */
147
148 return (1);
149}