When client selects to save, server will save

This commit is contained in:
MysterD 2020-09-23 20:44:44 -07:00
parent 7fbae9cc05
commit 20ab5ec9f6
4 changed files with 29 additions and 0 deletions

View File

@ -346,6 +346,11 @@ static void save_file_bswap(struct SaveBuffer *buf) {
} }
void save_file_do_save(s32 fileIndex) { void save_file_do_save(s32 fileIndex) {
if (gNetworkType != NT_SERVER) {
if (gNetworkType == NT_CLIENT) { network_send_save_file(fileIndex); }
return;
}
if (fileIndex < 0 || fileIndex >= NUM_SAVE_FILES) if (fileIndex < 0 || fileIndex >= NUM_SAVE_FILES)
return; return;

View File

@ -30,6 +30,7 @@ void packet_receive(struct Packet* p) {
case PACKET_KICK: network_receive_kick(p); break; case PACKET_KICK: network_receive_kick(p); break;
case PACKET_KEEP_ALIVE: network_receive_keep_alive(p); break; case PACKET_KEEP_ALIVE: network_receive_keep_alive(p); break;
case PACKET_LEAVING: network_receive_leaving(p); break; case PACKET_LEAVING: network_receive_leaving(p); break;
case PACKET_SAVE_FILE: network_receive_save_file(p); break;
/// ///
case PACKET_CUSTOM: network_receive_custom(p); break; case PACKET_CUSTOM: network_receive_custom(p); break;
default: LOG_ERROR("received unknown packet: %d", p->buffer[0]); default: LOG_ERROR("received unknown packet: %d", p->buffer[0]);

View File

@ -28,6 +28,7 @@ enum PacketType {
PACKET_KICK, PACKET_KICK,
PACKET_KEEP_ALIVE, PACKET_KEEP_ALIVE,
PACKET_LEAVING, PACKET_LEAVING,
PACKET_SAVE_FILE,
/// ///
PACKET_CUSTOM = 255, PACKET_CUSTOM = 255,
}; };
@ -143,4 +144,8 @@ void network_receive_keep_alive(struct Packet* p);
void network_send_leaving(u8 globalIndex); void network_send_leaving(u8 globalIndex);
void network_receive_leaving(struct Packet* p); void network_receive_leaving(struct Packet* p);
// packet_save_file.c
void network_send_save_file(s32 fileIndex);
void network_receive_save_file(struct Packet* p);
#endif #endif

View File

@ -0,0 +1,18 @@
#include <stdio.h>
#include "../network.h"
#include "game/save_file.h"
void network_send_save_file(s32 fileIndex) {
assert(gNetworkType == NT_CLIENT);
struct Packet p;
packet_init(&p, PACKET_SAVE_FILE, true);
packet_write(&p, &fileIndex, sizeof(s32));
network_send_to(gNetworkPlayerServer->localIndex, &p);
}
void network_receive_save_file(struct Packet* p) {
if (gNetworkType != NT_SERVER) { return; }
s32 fileIndex = 0;
packet_read(p, &fileIndex, sizeof(s32));
save_file_do_save(fileIndex);
}