Debian Codegraph @

src/cdogs/net_client.h

raw symbols SCIP
1 /*
2 C-Dogs SDL
3 A port of the legendary (and fun) action/arcade cdogs.
4
5 Copyright (c) 2014-2016, 2024 Cong Xu
6 All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10
11 Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
13 Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE.
28 */
29 #pragma once
30
31 #include <time.h>
32
33 #include "net_util.h"
34
35 // Stored information about game servers scanned
36 typedef struct
37 {
38 NServerInfo ServerInfo;
39 ENetAddress Addr;
40 int LatencyMS;
41 } ScanInfo;
42
43 typedef struct
44 {
45 ENetHost *client;
46 ENetPeer *peer;
47 int ClientId;
48 int FirstPlayerUID;
49 bool Ready;
50 // Socket used to scan for LAN servers
51 ENetSocket scanner;
52 uint16_t port;
53 // Only scan for a period; if > 0 then we are scanning
54 int ScanTicks;
55 // Addresses of scanned LAN servers
56 CArray ScannedAddrs; // of ScanInfo
57 // Buffer of scanned addresses - new ones will be scanned here
58 CArray scannedAddrBuf; // of ScanInfo
59 } NetClient;
60
61 extern NetClient gNetClient;
62
63 void NetClientInit(NetClient *n, const uint16_t port);
64 void NetClientTerminate(NetClient *n);
65
66 // Start searching for LAN servers; note that the result will be returned in
67 // NetClient's boolean
68 void NetClientFindLANServers(NetClient *n);
69 // Attempt to connect to a server
70 bool NetClientTryConnect(NetClient *n, const ENetAddress addr);
71 // Attempt to scan a host for a game server and connect
72 bool NetClientTryScanAndConnect(NetClient *n, const enet_uint32 host);
73 void NetClientDisconnect(NetClient *n);
74 void NetClientPoll(NetClient *n);
75 void NetClientFlush(NetClient *n);
76 // Send a command to the server
77 void NetClientSendMsg(NetClient *n, const GameEventType e, const void *data);
78
79 bool NetClientIsConnected(const NetClient *n);