Skip to content

Commit bc03897

Browse files
tjrileywiscjnmartin84phoboslabGirianSeed
authored
Connect client (#12)
* clear weapon_target in ship_init (fixes phoboslab#141) * clear `expected` state in `input_bind` so remapped controls actually work (fixes phoboslab#132) * `vec3_is_on_face` angle value test updated to match original code. * remove erroneous division by 64 in `magnitude` calculation for nose collision this makes ship nose swing back out toward center of track again (noticeably) * remove erroneous division by 16 in `magnitude` calculation (wing collision) this restores the behavior of ship rolling on wing collision with side of track there may still be other code to tweak as this seems more sensitive than PSX behavior * use reciprocal multiply as seen in many other lines of rewrite * another place where angle comparison to 30000 was converted differently * angular z component computation did not match original source DYNAM.C * 2 * pi, I also messed up * scale face normal contribution consistently in floor collision code * reimplement camera shake * mistake, messed up roll * LONG/SHORT_SHAKE -> CAMERA_SHAKE_LONG/SHORT * fix indentation * adjust face->normal scaling constant for collision with floor * another fixed point scaling issue? * restore original attract mode/demo behavior With a very small reordering, the original PSX demo behavior is restored (countdown at starting line). Gets rid of the need for the "FIXME" part in the ship loop as well. * Adjust scaling values in ship to ship collision code * Update QOA lib * Add menu option for screen shake * Allow A_MENU_START for highscore entry; close phoboslab#133 * Better analog controls; thanks @mickski56; close phoboslab#77 * add wipegame.exe to .gitignore * Use sdl2-config for L_FLAGS_SDL Additional flags passed by 'sdl2-config --libs' fix an undefined reference to WinMain that prevents the target from successfully linking. * Correct L_FLAGS_SOKOL for MSYS2 libdl and libasound don't exist on Windows. The Sokol build needs gdi32 and ole32 to successfully link. * Remove unnecessary MSYS define '__MSYS__' is pre-defined by the MSYS2 environment's toolchains, and should NOT be defined for MINGW32/64, UCRT64, etc. * Rename client com file for consistency with server com * Tidy up tests a little * Address some minor warnings * Remove unused param * Add unit tests * Move away from custom network structs * Add test for connecting client and too many clients * Account for forgetting to init client array somehow * Remove header * Forward declare server info type * Grab server address in discovery loop * Fix data (server index) * Comment this out for now * Send and receive connect status on client side --------- Co-authored-by: jnmartin84 <[email protected]> Co-authored-by: Dominic Szablewski <[email protected]> Co-authored-by: J.Ingram <[email protected]>
1 parent 19de20a commit bc03897

File tree

20 files changed

+417
-288
lines changed

20 files changed

+417
-288
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ coverage-report/
1313
*.info
1414

1515
/wipegame
16-
17-
# misc OS stuff
18-
.DS_STORE
16+
/wipegame.exe
17+
/save.dat
18+
.DS_STORE
19+
gamecontrollerdb.txt

network/network.c

Lines changed: 8 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static const char *network_get_last_error(void)
6464
#endif
6565
}
6666

67-
static void system_send_packet(int sockfd, int length, const void *data, netadr_t dest_net)
67+
static void system_send_packet(int sockfd, int length, const void *data, struct sockaddr_in dest_net)
6868
{
6969

7070
if(sockfd == INVALID_SOCKET)
@@ -73,52 +73,15 @@ static void system_send_packet(int sockfd, int length, const void *data, netadr_
7373
return;
7474
}
7575

76-
struct sockaddr_in dest_addr;
7776

78-
netadr_to_sockadr(&dest_net, &dest_addr);
79-
80-
int ret = wrap_sendto(sockfd, data, length, 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
77+
int ret = wrap_sendto(sockfd, data, length, 0, (struct sockaddr *)&dest_net, sizeof(dest_net));
8178

8279
if (ret == -1)
8380
{
84-
printf("unable to send packet to %s: %s\n", addr_to_string(dest_net), network_get_last_error());
81+
// printf("unable to send packet to %s: %s\n", addr_to_string(dest_net), network_get_last_error());
8582
}
8683
}
8784

88-
static bool system_get_packet(netadr_t *net_from, msg_t *net_msg)
89-
{
90-
struct sockaddr_in from;
91-
92-
if (client_sockfd == INVALID_SOCKET) {
93-
return false;
94-
}
95-
96-
unsigned int fromlen = sizeof(from);
97-
int ret = wrap_recvfrom(client_sockfd, net_msg->data, net_msg->maxsize, 0, (struct sockaddr *)&from, &fromlen);
98-
99-
sockadr_to_netadr(&from, net_from);
100-
net_msg->readcount = 0;
101-
102-
if (ret == -1)
103-
{
104-
int err = errno;
105-
106-
if (err == EWOULDBLOCK || err == ECONNREFUSED) {
107-
return false;
108-
}
109-
110-
printf("%s from %s\n", network_get_last_error(), addr_to_string(*net_from));
111-
}
112-
113-
if (ret == net_msg->maxsize)
114-
{
115-
printf("oversize packet from %s\n", addr_to_string(*net_from));
116-
return false;
117-
}
118-
119-
net_msg->cursize = ret;
120-
return true;
121-
}
12285

12386
#if defined(WIN32)
12487
bool system_init_winsock(void) {
@@ -204,7 +167,7 @@ int network_get_client_socket(void) {
204167
return new_socket;
205168
}
206169

207-
bool network_bind_socket(int sockfd, char *ip_addr, char* port)
170+
bool network_bind_socket(int sockfd, char* port)
208171
{
209172
if(client_sockfd != INVALID_SOCKET)
210173
{
@@ -271,7 +234,7 @@ void network_close_socket(int* sockfd) {
271234
*sockfd = INVALID_SOCKET;
272235
}
273236

274-
static void network_add_msg_queue_item(const char *buf, int numbytes, const struct sockaddr_storage *their_addr) {
237+
static void network_add_msg_queue_item(const char *buf, const struct sockaddr_in* their_addr) {
275238
msg_queue_item_t *item = (msg_queue_item_t *)malloc(sizeof(msg_queue_item_t));
276239
if (!item) {
277240
perror("Failed to allocate memory for message queue item");
@@ -285,7 +248,7 @@ static void network_add_msg_queue_item(const char *buf, int numbytes, const stru
285248
return;
286249
}
287250

288-
memcpy(&item->dest_addr, their_addr, sizeof(struct sockaddr_storage));
251+
memcpy(&item->dest_addr, their_addr, sizeof(struct sockaddr_in));
289252
msg_queue[msg_queue_size++] = *item;
290253
}
291254

@@ -327,8 +290,6 @@ bool network_get_packet()
327290
socklen_t addr_len = sizeof their_addr;
328291
int numbytes = 0;
329292

330-
char s[INET_ADDRSTRLEN];
331-
332293
if ((numbytes = wrap_recvfrom(client_sockfd, buf, MAXBUFLEN-1 , 0,
333294
(struct sockaddr *)&their_addr, &addr_len)) == -1) {
334295
if (errno == EAGAIN || errno == EWOULDBLOCK) {
@@ -340,36 +301,17 @@ bool network_get_packet()
340301
}
341302
}
342303

343-
struct sockaddr* addr = &((struct sockaddr_in*)&their_addr)->sin_addr;
344-
345-
/*
346-
printf("listener: got packet from %s\n",
347-
inet_ntop(their_addr.ss_family,
348-
addr,
349-
s, sizeof s));
350-
printf("listener: packet is %d bytes long\n", numbytes);
351-
352-
printf("listener: packet contains \"%s\"\n", buf);
353-
*/
354-
355304
buf[numbytes] = '\0';
356-
network_add_msg_queue_item(buf, numbytes, &their_addr);
305+
network_add_msg_queue_item(buf, (struct sockaddr_in*)&their_addr);
357306

358307
return true;
359308
}
360309

361-
void network_send_packet(int sockfd, int length, const void *data, netadr_t dest_net)
310+
void network_send_packet(int sockfd, int length, const void *data, struct sockaddr_in dest_net)
362311
{
363312
system_send_packet(sockfd, length, data, dest_net);
364313
}
365314

366-
void network_send_command(const char *command, netadr_t dest)
367-
{
368-
if(strcmp(command, "server_info") == 0) {
369-
network_send_packet(network_get_bound_ip_socket(), strlen(command), "server_info", dest);
370-
}
371-
}
372-
373315
int network_sleep(int msec)
374316
{
375317
struct timeval timeout;

network/network.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
#define INVALID_SOCKET -1
1212
#endif
1313

14-
static int WIPEOUT_PORT = 8000;
15-
static int WIPEOUT_CLIENT_PORT = 8001;
16-
static int CLIENT_SOCKET_TIMEOUT = 3000; // 3 seconds
14+
#define WIPEOUT_PORT 8000
15+
#define WIPEOUT_CLIENT_PORT 8001
16+
#define CLIENT_SOCKET_TIMEOUT 3000 // 3 seconds
1717

1818
typedef struct {
1919
const char* command;
20-
struct sockaddr_storage dest_addr;
20+
struct sockaddr_in dest_addr;
2121
} msg_queue_item_t;
2222

2323
#if defined(WIN32)
@@ -79,10 +79,9 @@ void network_close_socket(int* sockfd);
7979
* listen for incoming packets.
8080
*
8181
* @param sockfd the socket file descriptor
82-
* @param ip_addr the IP address to bind to
8382
* @param port the port to bind to
8483
*/
85-
bool network_bind_socket(int sockfd, char *ip_addr, char* port);
84+
bool network_bind_socket(int sockfd, char* port);
8685

8786
bool network_get_packet(void);
8887

@@ -94,12 +93,7 @@ bool network_get_packet(void);
9493
* @param data the data to send
9594
* @param dest_net the destination netadr_t
9695
*/
97-
void network_send_packet(int sockfd, int length, const void* data, netadr_t dest_net);
98-
99-
/**
100-
* @brief Send a command to the server or to a client
101-
*/
102-
void network_send_command(const char* command, netadr_t dest);
96+
void network_send_packet(int sockfd, int length, const void* data, struct sockaddr_in dest_net);
10397

10498
/**
10599
* @brief clears the current message queue

server/main.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#include <client.h>
2+
#include <client_com.h>
33

44
#include <msg.h>
55
#include <network.h>
@@ -24,6 +24,8 @@ static void server_init()
2424
{
2525
server.name = "master blaster";
2626
server.num_clients = 0;
27+
28+
client_com_init();
2729
}
2830

2931
int main(int argc, char** argv)
@@ -34,14 +36,13 @@ int main(int argc, char** argv)
3436
printf("welcome to the server!\n");
3537

3638
server_init();
37-
char my_ip[16];
38-
network_get_my_ip(my_ip, sizeof(my_ip));
39+
3940
int sockfd = network_get_client_socket();
4041
if(sockfd == INVALID_SOCKET) {
4142
printf("could not create socket, quitting\n");
4243
return 1;
4344
}
44-
if(!network_bind_socket(sockfd, my_ip, "8000")) {
45+
if(!network_bind_socket(sockfd, "8000")) {
4546
printf("could not start server, quitting\n");
4647
return 1;
4748
}

server/serverlib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
add_library(serverlib STATIC
3-
client.c
3+
client_com.c
44
)
55

66
target_include_directories(serverlib PUBLIC

server/serverlib/client.c

Lines changed: 0 additions & 134 deletions
This file was deleted.

server/serverlib/client.h

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)