network.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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.
  12. //
  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.
  20. //
  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.
  28. #pragma once
  29. #include <netinet/in.h>
  30. #include <pthread.h>
  31. #include <limits.h>
  32. #include "types.h"
  33. #include "table.h"
  34. // ID is the index you got this from
  35. struct server_info {
  36. uint64_t distance; // gl if you exceed this
  37. struct string address;
  38. struct string name;
  39. struct string via; // netsplit purposes
  40. // TODO: this v
  41. struct table user_list;
  42. // TODO: metadata
  43. };
  44. struct user_info {
  45. uint64_t nick_ts;
  46. uint64_t user_ts;
  47. struct string server;
  48. struct string nick;
  49. struct string hostname;
  50. struct string vhost;
  51. struct string ident;
  52. struct string ip;
  53. struct string realname;
  54. struct string opertype;
  55. // TODO: this v
  56. struct table channel_list;
  57. struct table metadata;
  58. };
  59. struct channel_info {
  60. uint64_t ts;
  61. struct string topic;
  62. uint64_t topic_ts;
  63. struct table modes; // TODO: Parse modes properly
  64. struct table user_list; // points to corresponding user_info struct (if available, currently not)
  65. struct table metadata;
  66. };
  67. extern struct table server_network_commands;
  68. extern struct table client_network_commands;
  69. extern struct table channel_list;
  70. extern struct table server_list;
  71. extern struct table user_list;
  72. extern pthread_mutex_t send_lock;
  73. extern int client_fd;
  74. extern int client_listen_fd;
  75. extern struct string client_nick;
  76. extern uint8_t client_connected;
  77. extern int resolve(char* address, char* port, struct sockaddr *server);
  78. extern int initservernetwork(void);
  79. extern int initclientnetwork(void);
  80. #define MODE_TYPE_UNKNOWN 0
  81. #define MODE_TYPE_NOARGS 1
  82. #define MODE_TYPE_REPLACE 2
  83. #define MODE_TYPE_MULTIPLE 3
  84. // Mode goes away when the user leaves the channel
  85. #define MODE_TYPE_USERS 4
  86. extern char channel_mode_types[UCHAR_MAX+1];
  87. #if LOGALL
  88. extern ssize_t SENDCLIENT(struct string msg);
  89. #else
  90. #define SENDCLIENT(x) write(client_fd, x.data, x.len)
  91. #endif
  92. extern int privmsg(struct string source, struct string target, size_t num_message_parts, struct string message[num_message_parts]);
  93. 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);
  94. extern int remove_user(struct string uid, struct string reason);