Debian Codegraph @

netcon/mtclient/mt_net.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/mtclient/mt_net.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003-08-26 03:58:40 $
23 * $Author: kevinb $
24 *
25 * Mastertracker network code
26 *
27 * $Log: not supported by cvs2svn $
28 *
29 * 13 10/03/01 12:44a Kevin
30 * Smaller version of pxo packets
31 *
32 * 12 9/02/99 3:16p Kevin
33 * Macintosh byte ordering fixes
34 *
35 * 11 8/24/99 5:47p Kevin
36 * Macintosh crap
37 *
38 * 10 4/19/99 8:36p Jeff
39 * Compile under Linux
40 *
41 * 9 4/19/99 7:56p Kevin
42 * ifdef'd out some win32 specific stuff
43 *
44 * 8 3/02/99 5:50p Kevin
45 * Ouch. Duplicate structures existed and were conflicting.
46 *
47 * 7 12/23/98 6:38p Kevin
48 * All UDP data (except gamespy) now uses one (registered) port number
49 *
50 * 6 10/01/98 11:37a Kevin
51 * UI fixes and stuff
52 *
53 * 5 9/16/98 8:06p Jason
54 * got mastertracker working with the dedicated server
55 *
56 * 4 9/04/98 1:51p Kevin
57 * implemented asyncronous gethostbyname
58 *
59 * 3 8/25/98 6:33p Kevin
60 * PXO screens
61 *
62 * 2 6/01/98 10:10a Kevin
63 * Added DLL connection interface and auto update DLL
64 *
65 * 1 5/21/98 11:21a Kevin
66 *
67 * $NoKeywords: $
68 */
69
70 #ifdef WIN32
71 #include <windows.h>
72 #include <winsock.h>
73 #include <wsipx.h>
74 #endif
75
76 #include <memory.h>
77 #include "pstypes.h"cxx . . $ `<file>/lib/pstypes.h`/
78 #include "networking.h"cxx . . $ `<file>/lib/networking.h`/
79 #include "mtgametrack.h"cxx . . $ `<file>/netcon/mtclient/mtgametrack.h`/
80 #include "mt_net.h"cxx . . $ `<file>/netcon/mtclient/mt_net.h`/
81 #include "byteswap.h"cxx . . $ `<file>/lib/byteswap.h`/
82
83 #define LOGIN_LENcxx . . $ `netcon/mtclient/mt_net.cpp:83:9`! 33
84 #define REAL_NAME_LENcxx . . $ `netcon/mtclient/mt_net.cpp:84:9`! 66
85 #define PASSWORD_LENcxx . . $ `netcon/mtclient/mt_net.cpp:85:9`! 17
86 #define EMAIL_LENcxx . . $ `netcon/mtclient/mt_net.cpp:86:9`! 100
87 #define TRACKER_ID_LENcxx . . $ `netcon/mtclient/mt_net.cpp:87:9`! 10
88 #define PILOT_NAME_LENcxx . . $ `netcon/mtclient/mt_net.cpp:88:9`! 20
89
90 #ifdef WIN32
91 #pragma pack(push, pxo)
92 #endif
93 #pragma pack(1) // Single byte alignment!
94 struct vmt_descent3_structcxx . . $ vmt_descent3_struct# {
95 char tracker_idcxx . . $ vmt_descent3_struct#tracker_id.[TRACKER_ID_LENcxx . . $ `netcon/mtclient/mt_net.cpp:87:9`!];
96 char pilot_namecxx . . $ vmt_descent3_struct#pilot_name.[PILOT_NAME_LENcxx . . $ `netcon/mtclient/mt_net.cpp:88:9`!];
97 int rankcxx . . $ vmt_descent3_struct#rank.;
98
99 int killscxx . . $ vmt_descent3_struct#kills.;
100 int deathscxx . . $ vmt_descent3_struct#deaths.;
101 int suicidescxx . . $ vmt_descent3_struct#suicides.;
102 int online_timecxx . . $ vmt_descent3_struct#online_time.;
103 int games_playedcxx . . $ vmt_descent3_struct#games_played.;
104 uint32_tcxx . . $ uint32_t# securitycxx . . $ vmt_descent3_struct#security.;
105 uint8_tcxx . . $ uint8_t# virgin_pilotcxx . . $ vmt_descent3_struct#virgin_pilot.; // This pilot was just created if TRUE
106 uint32_tcxx . . $ uint32_t# lateral_thrustcxx . . $ vmt_descent3_struct#lateral_thrust.;
107 uint32_tcxx . . $ uint32_t# rotational_thrustcxx . . $ vmt_descent3_struct#rotational_thrust.;
108 uint32_tcxx . . $ uint32_t# sliding_pctcxx . . $ vmt_descent3_struct#sliding_pct.; // Percentage of the time you were sliding
109 uint32_tcxx . . $ uint32_t# checksumcxx . . $ vmt_descent3_struct#checksum.; // This value needs to be equal to whatever the checksum is once the packet is decoded
110 uint32_tcxx . . $ uint32_t# padcxx . . $ vmt_descent3_struct#pad.; // just to provide room for out 4 byte encryption boundry only needed on the client side for now
111 };
112 #define DESCENT3_BLOCK_SIZEcxx . . $ `netcon/mtclient/mt_net.cpp:112:9`! (sizeof(vmt_descent3_struct) - 4)
113 #ifdef WIN32
114 #pragma pack(pop, pxo)
115 #else
116 #pragma pack()
117 #endif
118
119 #include "mtpilottrack.h"cxx . . $ `<file>/netcon/mtclient/mtpilottrack.h`/
120
121 extern int MT_Initializedcxx . . $ MT_Initialized.;
122 // Mastertracker sockets
123 SOCKETcxx . . $ `lib/networking.h:217:9`! TCP_game_tracker_socketcxx . . $ TCP_game_tracker_socket.;
124 SOCKETcxx . . $ `lib/networking.h:217:9`! TCP_pilot_tracker_socketcxx . . $ TCP_pilot_tracker_socket.;
125 SOCKETcxx . . $ `lib/networking.h:217:9`! TCP_chat_server_socketcxx . . $ TCP_chat_server_socket.;
126
127 // Mastertracker addresses (we resolve them on init, and don't want to have to do it again)
128 SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! gtrackaddrcxx . . $ gtrackaddr.;
129 SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! ptrackaddrcxx . . $ ptrackaddr.;
130 SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! ctrackaddrcxx . . $ ctrackaddr.;
131 SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! sockaddrcxx . . $ sockaddr.;
132
133 #define DLLmprintfcxx . . $ `netcon/mtclient/mt_net.cpp:133:9`!(...) DLLDebug_ConsolePrintf(__VA_ARGS__)
134
135 #define NW_AGHBN_CANCELcxx . . $ `netcon/mtclient/mt_net.cpp:135:9`! 1
136 #define NW_AGHBN_LOOKUPcxx . . $ `netcon/mtclient/mt_net.cpp:136:9`! 2
137 #define NW_AGHBN_READcxx . . $ `netcon/mtclient/mt_net.cpp:137:9`! 3
138
139 // extern void DLLDebug_ConsolePrintf (int n, const char *format, ... );
140 typedef void (*Debug_ConsolePrintf_fpcxx . . $ Debug_ConsolePrintf_fp#)(int n, const char *format, ...);
141
142 extern Debug_ConsolePrintf_fpcxx . . $ Debug_ConsolePrintf_fp# DLLDebug_ConsolePrintfcxx . . $ DLLDebug_ConsolePrintf.;
143
144 typedef int (*nw_Asyncgethostbyname_fpcxx . . $ nw_Asyncgethostbyname_fp#)(uint32_tcxx . . $ uint32_t# *ip, int command, const char *hostname);
145 extern nw_Asyncgethostbyname_fpcxx . . $ nw_Asyncgethostbyname_fp# DLLnw_Asyncgethostbynamecxx . . $ DLLnw_Asyncgethostbyname.;
146
147 typedef int (*nw_SendWithID_fpcxx . . $ nw_SendWithID_fp#)(uint8_tcxx . . $ uint8_t# id, uint8_tcxx . . $ uint8_t# *data, int len, network_addresscxx . . $ network_address# *who_to);
148 extern nw_SendWithID_fpcxx . . $ nw_SendWithID_fp# DLLnw_SendWithIDcxx . . $ DLLnw_SendWithID.;
149 typedef int (*PollUI_fpcxx . . $ PollUI_fp#)();
150 extern PollUI_fpcxx . . $ PollUI_fp# DLLPollUIcxx . . $ DLLPollUI.;
151 extern bool *DLLDedicated_servercxx . . $ DLLDedicated_server.;
152
153 int SendGameTrackerPackercxx . . $ SendGameTrackerPacker(dedf1e9b1c614a07).(void *packet) {
154 game_packet_headercxx . . $ game_packet_header# *g_pack = (game_packet_headercxx . . $ game_packet_header# *)packet;
155
156 network_addresscxx . . $ network_address# send_address;
157 memset(&send_address, 0, sizeof(network_addresscxx . . $ network_address#));
158 SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *inaddr = (SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *)&gtrackaddrcxx . . $ gtrackaddr.;
159 memcpy(send_address.addresscxx . . $ network_address#address., &inaddr->sin_addr, 4);
160 send_address.portcxx . . $ network_address#port. = htons(inaddr->sin_port);
161 send_address.connection_typecxx . . $ network_address#connection_type. = NP_TCPcxx . . $ NP_TCP.;
162
163 return DLLnw_SendWithIDcxx . . $ DLLnw_SendWithID.(PXO_NETID_GAME_TRACKERcxx . . $ `netcon/mtclient/mt_net.h:52:9`!, (uint8_tcxx . . $ uint8_t# *)g_pack, INTEL_INTcxx . . $ `lib/byteswap.h:107:9`!(g_pack->len), &send_address);
164 }
165
166 void InitMTSocketscxx . . $ InitMTSockets(49f6e7a06ebc5aa8).() {
167 #ifdef WIN32
168 WSADATA ws_data;
169 WORD ver = MAKEWORD(1, 1);
170 #endif
171 int rcode;
172 uint32_tcxx . . $ uint32_t# ip;
173 #ifdef WIN32
174 int error = WSAStartup(ver, &ws_data);
175 if (error != 0) {
176 DLLmprintf(0, "There was an error initializing networking! Error=%d\n", error);
177 return;
178 } else
179 #endif
180 {
181 DLLmprintfcxx . . $ `netcon/mtclient/mt_net.cpp:133:9`!(0, "Network initted successfully!\n");
182 }
183
184 {
185 static HOSTENTcxx . . $ `lib/networking.h:232:9`! lhe;
186 memset(&sockaddrcxx . . $ sockaddr., 0, sizeof(SOCKADDR_INcxx . . $ `lib/networking.h:219:9`!));
187 gtrackaddrcxx . . $ gtrackaddr..sin_family = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
188 gtrackaddrcxx . . $ gtrackaddr..sin_addr.s_addr = INADDR_ANYcxx . . $ `<external>/9581057695539925927/in.h:198:9`!;
189 gtrackaddrcxx . . $ gtrackaddr..sin_port = 0;
190
191 gtrackaddrcxx . . $ gtrackaddr..sin_family = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
192 // This would be a good place to resolve the IP based on a domain name
193 DLLmprintfcxx . . $ `netcon/mtclient/mt_net.cpp:133:9`!(0, "Looking up hostname: %s.\n", GAMETRACKERNAMEcxx . . $ `netcon/mtclient/mtgametrack.h:99:9`!);
194
195 DLLnw_Asyncgethostbynamecxx . . $ DLLnw_Asyncgethostbyname.(&ip, NW_AGHBN_LOOKUPcxx . . $ `netcon/mtclient/mt_net.cpp:136:9`!, GAMETRACKERNAMEcxx . . $ `netcon/mtclient/mtgametrack.h:99:9`!);
196
197 do {
198 rcode = DLLnw_Asyncgethostbynamecxx . . $ DLLnw_Asyncgethostbyname.(&ip, NW_AGHBN_READcxx . . $ `netcon/mtclient/mt_net.cpp:137:9`!, GAMETRACKERNAMEcxx . . $ `netcon/mtclient/mtgametrack.h:99:9`!);
199
200 if (!*DLLDedicated_servercxx . . $ DLLDedicated_server.) {
201 if (99 == DLLPollUIcxx . . $ DLLPollUI.()) {
202 return;
203 }
204 }
205 } while (rcode == 0);
206
207 if (rcode != 1) {
208 DLLmprintfcxx . . $ `netcon/mtclient/mt_net.cpp:133:9`!(0, "Unable to gethostbyname(\"%s\").\n", GAMETRACKERNAMEcxx . . $ `netcon/mtclient/mtgametrack.h:99:9`!);
209 DLLmprintfcxx . . $ `netcon/mtclient/mt_net.cpp:133:9`!(0, "WSAGetLastError() returned %d.\n", WSAGetLastErrorcxx . . $ `lib/networking.h:241:9`!());
210 DLLnw_Asyncgethostbynamecxx . . $ DLLnw_Asyncgethostbyname.(nullptr, NW_AGHBN_CANCELcxx . . $ `netcon/mtclient/mt_net.cpp:135:9`!, nullptr);
211 return;
212 }
213
214 memcpy(&gtrackaddrcxx . . $ gtrackaddr..sin_addr.s_addr, &ip, 4); //&iaddr, 4);
215 gtrackaddrcxx . . $ gtrackaddr..sin_port = htons(GAMEPORTcxx . . $ `netcon/mtclient/mtgametrack.h:100:9`!);
216 InitGameTrackerClientcxx . . $ InitGameTrackerClient(7864480464b09eea).(GT_D3TNGcxx . . $ `netcon/mtclient/mtgametrack.h:141:9`!);
217 }
218 {
219
220 memset(&sockaddrcxx . . $ sockaddr., 0, sizeof(SOCKADDR_INcxx . . $ `lib/networking.h:219:9`!));
221 sockaddrcxx . . $ sockaddr..sin_family = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
222 sockaddrcxx . . $ sockaddr..sin_addr.s_addr = INADDR_ANYcxx . . $ `<external>/9581057695539925927/in.h:198:9`!;
223 sockaddrcxx . . $ sockaddr..sin_port = 0; // htons(REGPORT);
224 DLLmprintfcxx . . $ `netcon/mtclient/mt_net.cpp:133:9`!(0, "Looking up hostname: %s.\n", PILOTTRACKERNAMEcxx . . $ `netcon/mtclient/mtpilottrack.h:123:9`!);
225 DLLnw_Asyncgethostbynamecxx . . $ DLLnw_Asyncgethostbyname.(&ip, NW_AGHBN_LOOKUPcxx . . $ `netcon/mtclient/mt_net.cpp:136:9`!, PILOTTRACKERNAMEcxx . . $ `netcon/mtclient/mtpilottrack.h:123:9`!);
226 do {
227 rcode = DLLnw_Asyncgethostbynamecxx . . $ DLLnw_Asyncgethostbyname.(&ip, NW_AGHBN_READcxx . . $ `netcon/mtclient/mt_net.cpp:137:9`!, PILOTTRACKERNAMEcxx . . $ `netcon/mtclient/mtpilottrack.h:123:9`!);
228 if (!*DLLDedicated_servercxx . . $ DLLDedicated_server.) {
229 if (99 == DLLPollUIcxx . . $ DLLPollUI.()) {
230 return;
231 }
232 }
233 } while (rcode == 0);
234
235 if (rcode != 1) {
236 DLLmprintfcxx . . $ `netcon/mtclient/mt_net.cpp:133:9`!(0, "Unable to gethostbyname(\"%s\").\n", PILOTTRACKERNAMEcxx . . $ `netcon/mtclient/mtpilottrack.h:123:9`!);
237 DLLmprintfcxx . . $ `netcon/mtclient/mt_net.cpp:133:9`!(0, "WSAGetLastError() returned %d.\n", WSAGetLastErrorcxx . . $ `lib/networking.h:241:9`!());
238 DLLnw_Asyncgethostbynamecxx . . $ DLLnw_Asyncgethostbyname.(nullptr, NW_AGHBN_CANCELcxx . . $ `netcon/mtclient/mt_net.cpp:135:9`!, nullptr);
239 return;
240 }
241 ptrackaddrcxx . . $ ptrackaddr..sin_family = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
242 memcpy(&ptrackaddrcxx . . $ ptrackaddr..sin_addr.s_addr, &ip, 4);
243 ptrackaddrcxx . . $ ptrackaddr..sin_port = htons(REGPORTcxx . . $ `netcon/mtclient/mtpilottrack.h:122:9`!);
244 InitPilotTrackerClientcxx . . $ InitPilotTrackerClient(b126dc7c1de90089).();
245 }
246 MT_Initializedcxx . . $ MT_Initialized. = 1;
247 }
248
249 void CloseMTSocketscxx . . $ CloseMTSockets(49f6e7a06ebc5aa8).() {
250 #ifdef WIN32
251 if (WSACleanup()) {
252 DLLmprintf(0, "Error closing wsock!\n");
253 }
254 #endif
255 }
256
257 int SendPilotTrackerPacketcxx . . $ SendPilotTrackerPacket(dedf1e9b1c614a07).(void *packet) {
258 udp_packet_headercxx . . $ udp_packet_header# *p_pack = (udp_packet_headercxx . . $ udp_packet_header# *)packet;
259
260 network_addresscxx . . $ network_address# send_address;
261 memset(&send_address, 0, sizeof(network_addresscxx . . $ network_address#));
262 SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *inaddr = (SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *)&ptrackaddrcxx . . $ ptrackaddr.;
263 memcpy(send_address.addresscxx . . $ network_address#address., &inaddr->sin_addr, 4);
264 send_address.portcxx . . $ network_address#port. = htons(inaddr->sin_port);
265 send_address.connection_typecxx . . $ network_address#connection_type. = NP_TCPcxx . . $ NP_TCP.;
266 return DLLnw_SendWithIDcxx . . $ DLLnw_SendWithID.(PXO_NETID_USER_TRACKERcxx . . $ `netcon/mtclient/mt_net.h:53:9`!, (uint8_tcxx . . $ uint8_t# *)p_pack, INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!(p_pack->len), &send_address);
267 }