1 /*************************************************************************/ 2 /* godot_net.h */ 3 /*************************************************************************/ 4 /* This file is part of: */ 5 /* GODOT ENGINE */ 6 /* https://godotengine.org */ 7 /*************************************************************************/ 8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 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 31 #ifndef GODOT_NATIVENET_H 32 #define GODOT_NATIVENET_H 33 34 #include <gdnative/gdnative.h> 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 // For future versions of the API we should only add new functions at the end of the structure and use the 41 // version info to detect whether a call is available 42 43 // Use these to populate version in your plugin 44 #define GODOT_NET_API_MAJOR 3 45 #define GODOT_NET_API_MINOR 1 46 47 typedef struct { 48 49 godot_gdnative_api_version version; /* version of our API */ 50 godot_object *data; /* User reference */ 51 52 /* This is StreamPeer */ 53 godot_error (*get_data)(void *user, uint8_t *p_buffer, int p_bytes); 54 godot_error (*get_partial_data)(void *user, uint8_t *p_buffer, int p_bytes, int *r_received); 55 godot_error (*put_data)(void *user, const uint8_t *p_data, int p_bytes); 56 godot_error (*put_partial_data)(void *user, const uint8_t *p_data, int p_bytes, int *r_sent); 57 58 int (*get_available_bytes)(const void *user); 59 60 void *next; /* For extension? */ 61 } godot_net_stream_peer; 62 63 /* Binds a StreamPeerGDNative to the provided interface */ 64 void godot_net_bind_stream_peer(godot_object *p_obj, const godot_net_stream_peer *p_interface); 65 66 typedef struct { 67 godot_gdnative_api_version version; /* version of our API */ 68 69 godot_object *data; /* User reference */ 70 71 /* This is PacketPeer */ 72 godot_error (*get_packet)(void *, const uint8_t **, int *); 73 godot_error (*put_packet)(void *, const uint8_t *, int); 74 godot_int (*get_available_packet_count)(const void *); 75 godot_int (*get_max_packet_size)(const void *); 76 77 void *next; /* For extension? */ 78 } godot_net_packet_peer; 79 80 /* Binds a PacketPeerGDNative to the provided interface */ 81 void GDAPI godot_net_bind_packet_peer(godot_object *p_obj, const godot_net_packet_peer *); 82 83 typedef struct { 84 godot_gdnative_api_version version; /* version of our API */ 85 86 godot_object *data; /* User reference */ 87 88 /* This is PacketPeer */ 89 godot_error (*get_packet)(void *, const uint8_t **, int *); 90 godot_error (*put_packet)(void *, const uint8_t *, int); 91 godot_int (*get_available_packet_count)(const void *); 92 godot_int (*get_max_packet_size)(const void *); 93 94 /* This is NetworkedMultiplayerPeer */ 95 void (*set_transfer_mode)(void *, godot_int); 96 godot_int (*get_transfer_mode)(const void *); 97 // 0 = broadcast, 1 = server, <0 = all but abs(value) 98 void (*set_target_peer)(void *, godot_int); 99 godot_int (*get_packet_peer)(const void *); 100 godot_bool (*is_server)(const void *); 101 void (*poll)(void *); 102 // Must be > 0, 1 is for server 103 int32_t (*get_unique_id)(const void *); 104 void (*set_refuse_new_connections)(void *, godot_bool); 105 godot_bool (*is_refusing_new_connections)(const void *); 106 godot_int (*get_connection_status)(const void *); 107 108 void *next; /* For extension? Or maybe not... */ 109 } godot_net_multiplayer_peer; 110 111 /* Binds a MultiplayerPeerGDNative to the provided interface */ 112 void GDAPI godot_net_bind_multiplayer_peer(godot_object *p_obj, const godot_net_multiplayer_peer *); 113 114 #ifdef __cplusplus 115 } 116 #endif 117 118 // WebRTC Bindings 119 #include "net/godot_webrtc.h" 120 121 #endif /* GODOT_NATIVENET_H */ 122