1 /**
2 UDP packet peer.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.packetpeerudp;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.meta;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.object;
22 import godot.classdb;
23 import godot.packetpeer;
24 import godot.reference;
25 /**
26 UDP packet peer.
27 
28 Can be used to send raw UDP packets as well as $(D Variant)s.
29 */
30 @GodotBaseClass struct PacketPeerUDP
31 {
32 	enum string _GODOT_internal_name = "PacketPeerUDP";
33 public:
34 @nogc nothrow:
35 	union { godot_object _godot_object; PacketPeer _GODOT_base; }
36 	alias _GODOT_base this;
37 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
38 	package(godot) __gshared bool _classBindingInitialized = false;
39 	package(godot) static struct _classBinding
40 	{
41 		__gshared:
42 		@GodotName("listen") GodotMethod!(GodotError, long, String, long) listen;
43 		@GodotName("close") GodotMethod!(void) close;
44 		@GodotName("wait") GodotMethod!(GodotError) wait;
45 		@GodotName("is_listening") GodotMethod!(bool) isListening;
46 		@GodotName("get_packet_ip") GodotMethod!(String) getPacketIp;
47 		@GodotName("get_packet_port") GodotMethod!(long) getPacketPort;
48 		@GodotName("set_dest_address") GodotMethod!(GodotError, String, long) setDestAddress;
49 	}
50 	bool opEquals(in PacketPeerUDP other) const { return _godot_object.ptr is other._godot_object.ptr; }
51 	PacketPeerUDP opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
52 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
53 	mixin baseCasts;
54 	static PacketPeerUDP _new()
55 	{
56 		static godot_class_constructor constructor;
57 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("PacketPeerUDP");
58 		if(constructor is null) return typeof(this).init;
59 		return cast(PacketPeerUDP)(constructor());
60 	}
61 	@disable new(size_t s);
62 	/**
63 	Make this `PacketPeerUDP` listen on the "port" binding to "bind_address" with a buffer size "recv_buf_size".
64 	If "bind_address" is set as "*" (default), the peer will listen on all available addresses (both IPv4 and IPv6).
65 	If "bind_address" is set as "0.0.0.0" (for IPv4) or "::" (for IPv6), the peer will listen on all available addresses matching that IP type.
66 	If "bind_address" is set to any valid address (e.g. "192.168.1.101", "::1", etc), the peer will only listen on the interface with that addresses (or fail if no interface with the given address exists).
67 	*/
68 	GodotError listen(StringArg1)(in long port, in StringArg1 bind_address = "*", in long recv_buf_size = 65536)
69 	{
70 		checkClassBinding!(typeof(this))();
71 		return ptrcall!(GodotError)(_classBinding.listen, _godot_object, port, bind_address, recv_buf_size);
72 	}
73 	/**
74 	Close the UDP socket the `PacketPeerUDP` is currently listening on.
75 	*/
76 	void close()
77 	{
78 		checkClassBinding!(typeof(this))();
79 		ptrcall!(void)(_classBinding.close, _godot_object);
80 	}
81 	/**
82 	Wait for a packet to arrive on the listening port, see $(D listen).
83 	*/
84 	GodotError wait()
85 	{
86 		checkClassBinding!(typeof(this))();
87 		return ptrcall!(GodotError)(_classBinding.wait, _godot_object);
88 	}
89 	/**
90 	Return whether this `PacketPeerUDP` is listening.
91 	*/
92 	bool isListening() const
93 	{
94 		checkClassBinding!(typeof(this))();
95 		return ptrcall!(bool)(_classBinding.isListening, _godot_object);
96 	}
97 	/**
98 	Return the IP of the remote peer that sent the last packet(that was received with $(D PacketPeer.getPacket) or $(D PacketPeer.getVar)).
99 	*/
100 	String getPacketIp() const
101 	{
102 		checkClassBinding!(typeof(this))();
103 		return ptrcall!(String)(_classBinding.getPacketIp, _godot_object);
104 	}
105 	/**
106 	Return the port of the remote peer that sent the last packet(that was received with $(D PacketPeer.getPacket) or $(D PacketPeer.getVar)).
107 	*/
108 	long getPacketPort() const
109 	{
110 		checkClassBinding!(typeof(this))();
111 		return ptrcall!(long)(_classBinding.getPacketPort, _godot_object);
112 	}
113 	/**
114 	Set the destination address and port for sending packets and variables, a hostname will be resolved using if valid.
115 	*/
116 	GodotError setDestAddress(StringArg0)(in StringArg0 host, in long port)
117 	{
118 		checkClassBinding!(typeof(this))();
119 		return ptrcall!(GodotError)(_classBinding.setDestAddress, _godot_object, host, port);
120 	}
121 }