write_socket(client, sendBuf, len);
}
len = sprintf(sendBuf, "USER %s 0 0 :%s\n", client->user->ident, client->user->realname);
- write_socket(client, &sendBuf, len);
+ write_socket(client, sendBuf, len);
len = sprintf(sendBuf, "NICK %s\n", client->user->nick);
- write_socket(client, &sendBuf, len);
+ write_socket(client, sendBuf, len);
client->sock = sock;
client->flags |= SOCKET_FLAG_CONNECTED;
//error
sock->flags &= ~(SOCKET_FLAG_CONNECTED | SOCKET_FLAG_READY);
} else {
- int used = parse_lines(sock->buffer, sock->bufferpos);
+ int used = parse_lines(sock, sock->buffer, sock->bufferpos);
if(used == sock->bufferpos + 1) {
//used all bytes so just reset the bufferpos
sock->bufferpos = 0;
#include "main.h"
-#define SOCKET_FLAG_DEAD 0x01;
-#define SOCKET_FLAG_CONNECTED 0x02;
-#define SOCKET_FLAG_READY 0x04;
+#define SOCKET_FLAG_DEAD 0x01
+#define SOCKET_FLAG_CONNECTED 0x02
+#define SOCKET_FLAG_READY 0x04
#define BUF_SIZ 512
int parse_lines(struct ClientSocket *client, char *lines, int len) {
int i, startpos = 0;
for(i = 0; i < len; i++) {
- if(*lines[i] == "\r") //just zero it out :D
+ if(lines[i] == '\r') //just zero it out :D
lines[i] = 0;
- if(*lines[i] == "\n") {
+ if(lines[i] == '\n') {
lines[i] = 0;
parse_line(client, lines);
startpos = i+1;
static IRC_CMD(raw_001) {
client->flags |= SOCKET_FLAG_READY;
write_socket(client, "PRIVMSG Watchcat :hi\n", 21);
+ return 1;
}
void parser_init() {
#define MAXNUMPARAMS 200 /* maximum number of parameters in one line */
-#define IRC_CMD(NAME) int NAME(UNUSED_ARG(const char *from), UNUSED_ARG(char **argv), UNUSED_ARG(unsigned int argc))
+#define IRC_CMD(NAME) int NAME(ClientSocket *client, UNUSED_ARG(const char *from), UNUSED_ARG(char **argv), UNUSED_ARG(unsigned int argc))
typedef IRC_CMD(irc_cmd_t);
struct irc_cmd {
#define UNUSED_ARG(ARG) ARG
#endif
+int stricmp (const char *s1, const char *s2)
+{
+ if (s1 == NULL) return s2 == NULL ? 0 : -(*s2);
+ if (s2 == NULL) return *s1;
+ char c1, c2;
+ while ((c1 = tolower (*s1)) == (c2 = tolower (*s2)))
+ {
+ if (*s1 == '\0') break;
+ ++s1; ++s2;
+ }
+ return c1 - c2;
+}
+
#define NICKLEN 30
#define USERLEN 10