diff options
Diffstat (limited to 'ircd.h')
| -rw-r--r-- | ircd.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/ircd.h b/ircd.h new file mode 100644 index 0000000..5e787da --- /dev/null +++ b/ircd.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2026 Nakidai Perumenei <nakidai at disroot dot org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef __IRCD_H__ +#define __IRCD_H__ + +#include <stddef.h> + + +#define PARAM_MAX 15 +#define PEERS_MAX 512 +#define MESSAGE_MAX 512 + +#define BIT(x) x##_BIT, x = 1 << x##_BIT, x##_BIT_ = x##_BIT +#define lengthof(X) (sizeof(X) / sizeof(*(X))) + +struct Message +{ + char *nick, *user, *host, *command, *params[PARAM_MAX]; +}; + +struct Peer +{ + int fd; + enum ClientType { UNREGED, CLIENT, SERVER, SERVICE } type; + char nick[16], user[16], real[32], host[64]; + char **channels; + size_t channels_count; + char modes[52]; + char buf[MESSAGE_MAX]; + size_t recvd; +}; + +struct Channel +{ + enum { GLOBAL, LOCAL, MODELESS, SAFE } type; + char name[64]; + struct { + char mode; + char param[MESSAGE_MAX - 1]; + } *modes; + size_t modes_count; +}; + +typedef int Handler(struct Message *msg, struct Peer *peer); + +extern struct Peer peers[PEERS_MAX]; +extern const char *hostname; +extern const char *host; +extern int port; + +const char *getnick(const struct Peer *peer); +void user_reg(struct Peer *peer, const char *nick, const char *user, const char *real); + +int parse_message(char *buf, struct Message *msg); +int handle(struct Peer *peer); +Handler *find(const char *command); +int writef(int fd, const char *fmt, ...); +void ircd(void); + +#endif /* __IRCD_H__ */ |