-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimplesocket.inc
More file actions
67 lines (57 loc) · 2.21 KB
/
simplesocket.inc
File metadata and controls
67 lines (57 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// vim: set filetype=c ts=8 noexpandtab:
#define INVALID_SOCKET (-1)
/// <summary>
/// Connects given socket to given address, port.
/// On success you can send using ssocket_send.
/// </summary>
/// <returns>0 on failure.</returns>
native ssocket_connect(ssocket:handle, address[], port);
/// <summary>
/// Creates a new socket.
/// On success you can use ssocket_connect to prepare sending or
/// ssocket_listen to listen.
/// </summary>
/// <remarks>Max amount of sockets is 10 when I wrote this line.</remarks>
/// <returns>A socket handle or -1 on error.</returns>
native ssocket:ssocket_create();
/// <summary>Destroys a socket.</summary>
/// <returns>0 on failure.</returns>
native ssocket_destroy(ssocket:handle);
/// <summary>Set a socket to listen to a port.</summary>
/// <returns>0 on failure.</returns>
native ssocket_listen(ssocket:handle, port);
/// <summary>
/// Send data through a socket that was setup with ssocket_connect.
/// </summary>
/// <param name="data">Data to send, use packed strings for text.</param>
/// <param name="len">The length of the data in bytes.</param>
/// <returns>0 on failure.</returns>
native ssocket_send(ssocket:handle, data[], len);
/// <summary>
/// Set the amount of server ticks to wait between each data receive check.
/// Defaults to 0.
/// </summary>
/// <remarks>
/// Your server tickrate is defined by the sleep setting in server.cfg
/// When invoked, the current wait is reset and the next server tick will
/// check for received data.
/// Limited to 1000 (but why would you).
/// </remarks>
native ssocket_set_recv_wait(wait);
/// <summary>
/// Unpacks a string that is packed in a different byte order than what
/// the normal strunpack uses.
/// </summary>
/// <remarks>
/// Will write maximum maxlength bytes (always zero terminated)
/// </remarks>
native ssocket_strunpack(dest[], source[], maxlength=sizeof(dest));
/// <summary>
/// Callback called when a socket configured with ssocket_listen
/// receives data.
/// </summary>
/// <param name="data">Received data, is NOT zero terminated.</param>
/// <remarks>
/// This is only called in the script that made the call to ssocket_listen.
/// </remarks>
forward SSocket_OnRecv(ssocket:handle, data[], len);