ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/pxys-hybrid/trunk/pxyservd/src/irc_client.c
Revision: 3416
Committed: Tue Apr 29 00:19:39 2014 UTC (9 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 4497 byte(s)
Log Message:
- irc_client.c:irc_client_register(): properly send UID message

File Contents

# Content
1 /* Copyright (C) 2003, 2004 Stephane Thiell
2 *
3 * This file is part of pxyservd (from pxys)
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *
19 */
20 #define RCSID "$Id: irc_client.c,v 1.6 2004/01/17 19:44:29 mbuna Exp $"
21
22 #include "irc_client.h"
23 #include <assert.h>
24 #include <stdlib.h>
25 #include <sys/types.h>
26 #include <sys/socket.h>
27 #include <netinet/in.h>
28 #include <arpa/inet.h>
29 #include <stdio.h>
30 #include <string.h>
31
32 #include <peak/peak.h>
33
34 #include "cfgloader.h"
35 #include "debug.h"
36 #include "irc_cmd.h"
37 #include "irc_msg.h"
38 #include "irc_network.h"
39 #include "irc_numnicks.h"
40 #include "irc_send.h"
41 #include "irc_struct.h"
42 #include "irc_userbase.h"
43 #include "pxyservd_log.h"
44
45 extern time_t gBirthTime;
46
47 peak_dict cmds_map;
48
49 static char my_netnum[6];
50
51 static const peak_dict_init_entry my_commands[] =
52 {
53 { "evreg", cmd_evreg },
54 { "evshow", cmd_evshow },
55 { "grem", cmd_grem },
56 { "help", cmd_help },
57 { "info", cmd_info },
58 { "noscan", cmd_noscan },
59 { "proxytop", cmd_proxytop },
60 { "pxstats", cmd_pxstats },
61 { "recheck", cmd_recheck },
62 { "servers", cmd_servers },
63 { "showcmds", cmd_showcmds },
64 { "stats", cmd_stats },
65 { "status", cmd_status }
66 };
67
68 void
69 irc_client_init()
70 {
71 cmds_map = peak_dict_create(&peak_dict_stringcase_key_ops,
72 &peak_dict_null_value_ops,
73 my_commands,
74 PEAK_DICT_INIT_ENTRY_COUNT(my_commands));
75 assert(cmds_map != NULL);
76 }
77
78 void
79 irc_client_register(void)
80 {
81
82 /* XXX */
83 /* 0 1 2 3 4 5 6 7 8 9 10 11 */
84 /* :0MC UID Steve 1 1350157102 +oi ~steve resolved.host 10.0.0.1 0MCAAAAAB 1350157108 :Mining all the time */
85 send_raw(":%s UID %s 1 %lu %s %s 0 %s 0 :%s" CRLF, gMe.sid,
86 gConfig->client.nickname, gBirthTime,
87 gConfig->client.usermode
88 gConfig->client.username, gConfig->client.hostname,
89 gConfig->client.usermode, pseudo_uid, gConfig->client.realname);
90
91 caddr.ip4 = gConfig->client.userip;
92
93 irc_userbase_add(gConfig->client.nickname,
94 gConfig->client.username,
95 gBirthTime,
96 gConfig->client.usermode,
97 0,
98 caddr,
99 my_netnum);
100 }
101
102 void
103 irc_client_unregister()
104 {
105 irc_userbase_remove(my_netnum);
106 }
107
108 void
109 irc_client_handle_private(toktabptr ttab)
110 {
111 cmd_func f;
112 struct Client *cptr;
113 const char *dst = ttab->tok[0];
114 const char *cmd = ttab->tok[3];
115 char ipbuf[32];
116
117 assert(cmd != NULL && ttab->size >= 4);
118 if (*cmd == ':')
119 cmd++;
120
121 if (!*cmd)
122 return;
123
124 if ((cptr = irc_network_find_client(yxx_to_int(dst))) == NULL)
125 return; /* doh */
126
127 if (!(cptr->flags & CLIENT_FLAG_OPER))
128 return; /* Non opers go play balls. */
129
130 if (!inet_ntop(cptr->flags & CLIENT_FLAG_IPV6 ? AF_INET6 : AF_INET,
131 &cptr->addr, ipbuf, sizeof(ipbuf)))
132 return;
133
134 switch (ttab->size)
135 {
136 case 4:
137 log_write(LOGID_OPERCMDS, "<%s!%s@%s> %s", cptr->nick, cptr->user,
138 ipbuf, cmd);
139 break;
140 case 5:
141 log_write(LOGID_OPERCMDS, "<%s!%s@%s> %s %s", cptr->nick, cptr->user,
142 ipbuf, cmd, ttab->tok[4]);
143 break;
144 case 6:
145 log_write(LOGID_OPERCMDS, "<%s!%s@%s> %s %s %s", cptr->nick, cptr->user,
146 ipbuf, cmd, ttab->tok[4], ttab->tok[5]);
147 break;
148 default:
149 log_write(LOGID_OPERCMDS, "<%s!%s@%s> %s %s %s (...)", cptr->nick,
150 cptr->user, ipbuf, cmd, ttab->tok[4], ttab->tok[5]);
151 break;
152 }
153
154 /* Get client pointer here instead of in every cmd handlers.. */
155 if ((f = (cmd_func)peak_dict_get_value(cmds_map, cmd)))
156 (*f)(cptr, ttab);
157 else
158 send_client_to_one(dst, "Sorry, command not found.");
159 }