godot_net.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**************************************************************************/
  2. /* godot_net.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef GODOT_NET_H
  31. #define GODOT_NET_H
  32. #include <gdnative/gdnative.h>
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. // For future versions of the API we should only add new functions at the end of the structure and use the
  37. // version info to detect whether a call is available
  38. // Use these to populate version in your plugin
  39. #define GODOT_NET_API_MAJOR 3
  40. #define GODOT_NET_API_MINOR 1
  41. typedef struct {
  42. godot_gdnative_api_version version; /* version of our API */
  43. godot_object *data; /* User reference */
  44. /* This is StreamPeer */
  45. godot_error (*get_data)(void *user, uint8_t *p_buffer, int p_bytes);
  46. godot_error (*get_partial_data)(void *user, uint8_t *p_buffer, int p_bytes, int *r_received);
  47. godot_error (*put_data)(void *user, const uint8_t *p_data, int p_bytes);
  48. godot_error (*put_partial_data)(void *user, const uint8_t *p_data, int p_bytes, int *r_sent);
  49. int (*get_available_bytes)(const void *user);
  50. void *next; /* For extension? */
  51. } godot_net_stream_peer;
  52. /* Binds a StreamPeerGDNative to the provided interface */
  53. void godot_net_bind_stream_peer(godot_object *p_obj, const godot_net_stream_peer *p_interface);
  54. typedef struct {
  55. godot_gdnative_api_version version; /* version of our API */
  56. godot_object *data; /* User reference */
  57. /* This is PacketPeer */
  58. godot_error (*get_packet)(void *, const uint8_t **, int *);
  59. godot_error (*put_packet)(void *, const uint8_t *, int);
  60. godot_int (*get_available_packet_count)(const void *);
  61. godot_int (*get_max_packet_size)(const void *);
  62. void *next; /* For extension? */
  63. } godot_net_packet_peer;
  64. /* Binds a PacketPeerGDNative to the provided interface */
  65. void GDAPI godot_net_bind_packet_peer(godot_object *p_obj, const godot_net_packet_peer *);
  66. typedef struct {
  67. godot_gdnative_api_version version; /* version of our API */
  68. godot_object *data; /* User reference */
  69. /* This is PacketPeer */
  70. godot_error (*get_packet)(void *, const uint8_t **, int *);
  71. godot_error (*put_packet)(void *, const uint8_t *, int);
  72. godot_int (*get_available_packet_count)(const void *);
  73. godot_int (*get_max_packet_size)(const void *);
  74. /* This is NetworkedMultiplayerPeer */
  75. void (*set_transfer_mode)(void *, godot_int);
  76. godot_int (*get_transfer_mode)(const void *);
  77. // 0 = broadcast, 1 = server, <0 = all but abs(value)
  78. void (*set_target_peer)(void *, godot_int);
  79. godot_int (*get_packet_peer)(const void *);
  80. godot_bool (*is_server)(const void *);
  81. void (*poll)(void *);
  82. // Must be > 0, 1 is for server
  83. int32_t (*get_unique_id)(const void *);
  84. void (*set_refuse_new_connections)(void *, godot_bool);
  85. godot_bool (*is_refusing_new_connections)(const void *);
  86. godot_int (*get_connection_status)(const void *);
  87. void *next; /* For extension? Or maybe not... */
  88. } godot_net_multiplayer_peer;
  89. /* Binds a MultiplayerPeerGDNative to the provided interface */
  90. void GDAPI godot_net_bind_multiplayer_peer(godot_object *p_obj, const godot_net_multiplayer_peer *);
  91. #ifdef __cplusplus
  92. }
  93. #endif
  94. // WebRTC Bindings
  95. #include "net/godot_webrtc.h"
  96. #endif // GODOT_NET_H