free bugs [fixed]
[coupserv.git] / network.h
bloba05503e8fe28c499338b82cbb5c9efb45313c413
1 // One of the headers for HaxServ
2 //
3 // Written by: Test_User <hax@andrewyu.org>
4 //
5 // This is free and unencumbered software released into the public
6 // domain.
7 //
8 // Anyone is free to copy, modify, publish, use, compile, sell, or
9 // distribute this software, either in source code form or as a compiled
10 // binary, for any purpose, commercial or non-commercial, and by any
11 // means.
13 // In jurisdictions that recognize copyright laws, the author or authors
14 // of this software dedicate any and all copyright interest in the
15 // software to the public domain. We make this dedication for the benefit
16 // of the public at large and to the detriment of our heirs and
17 // successors. We intend this dedication to be an overt act of
18 // relinquishment in perpetuity of all present and future rights to this
19 // software under copyright law.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 // IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 // OTHER DEALINGS IN THE SOFTWARE.
29 #pragma once
31 #include <netinet/in.h>
32 #include <pthread.h>
33 #include <limits.h>
35 #include "types.h"
36 #include "table.h"
38 // ID is the index you got this from
39 struct server_info {
40 uint64_t distance; // gl if you exceed this
42 struct string address;
43 struct string name;
44 struct string via; // netsplit purposes
46 // TODO: this v
47 struct table user_list;
48 // TODO: metadata
51 struct user_info {
52 uint64_t nick_ts;
53 uint64_t user_ts;
55 struct string server;
56 struct string nick;
57 struct string hostname;
58 struct string vhost;
59 struct string ident;
60 struct string ip;
61 struct string realname;
62 struct string opertype;
64 // TODO: this v
65 struct table channel_list;
67 struct table metadata;
70 struct channel_info {
71 uint64_t ts;
73 struct string topic;
74 uint64_t topic_ts;
76 struct table modes; // TODO: Parse modes properly
77 struct table user_list; // points to corresponding user_info struct (if available, currently not)
79 struct table metadata;
82 extern struct table server_network_commands;
83 extern struct table client_network_commands;
84 extern struct table channel_list;
85 extern struct table server_list;
86 extern struct table user_list;
88 extern pthread_mutex_t send_lock;
90 extern int client_fd;
91 extern int client_listen_fd;
92 extern struct string client_nick;
93 extern uint8_t client_connected;
95 extern int resolve(char* address, char* port, struct sockaddr *server);
97 extern int initservernetwork(void);
98 extern int initclientnetwork(void);
100 #define MODE_TYPE_UNKNOWN 0
101 #define MODE_TYPE_NOARGS 1
102 #define MODE_TYPE_REPLACE 2
103 #define MODE_TYPE_MULTIPLE 3
104 // Mode goes away when the user leaves the channel
105 #define MODE_TYPE_USERS 4
107 extern char channel_mode_types[UCHAR_MAX+1];
109 #if LOGALL
110 extern ssize_t SENDCLIENT(struct string msg);
111 #else
112 #define SENDCLIENT(x) write(client_fd, x.data, x.len)
113 #endif
115 extern int privmsg(struct string source, struct string target, size_t num_message_parts, struct string message[num_message_parts]);
116 extern int add_local_client(struct string uid, struct string nick_arg, struct string vhost_arg, struct string ident_arg, struct string realname_arg, time_t timestamp, char fake_cert);
117 extern int remove_user(struct string uid, struct string reason);