Fixed Discord join and download problems
This commit is contained in:
parent
1549081539
commit
015383b0dd
|
@ -8,6 +8,7 @@
|
|||
|
||||
#define HASH_LENGTH 8
|
||||
struct DiscordActivity gCurActivity = { 0 };
|
||||
bool gActivityLock = false;
|
||||
|
||||
static void on_activity_update_callback(UNUSED void* data, enum EDiscordResult result) {
|
||||
LOGFILE_INFO(LFT_DISCORD, "> on_activity_update_callback returned %d", result);
|
||||
|
@ -15,6 +16,7 @@ static void on_activity_update_callback(UNUSED void* data, enum EDiscordResult r
|
|||
}
|
||||
|
||||
static void on_activity_join_callback(UNUSED void* data, enum EDiscordResult result, struct DiscordLobby* lobby) {
|
||||
gActivityLock = false;
|
||||
LOGFILE_INFO(LFT_DISCORD, "> on_activity_join_callback returned %d, lobby " DISCORD_ID_FORMAT ", owner " DISCORD_ID_FORMAT, result, lobby->id, lobby->owner_id);
|
||||
DISCORD_REQUIRE(result);
|
||||
if (gNetworkType != NT_NONE) {
|
||||
|
@ -47,6 +49,8 @@ static void on_activity_join_callback(UNUSED void* data, enum EDiscordResult res
|
|||
|
||||
static void on_activity_join(UNUSED void* data, const char* secret) {
|
||||
LOGFILE_INFO(LFT_DISCORD, "> on_activity_join, secret: %s", secret);
|
||||
if (gActivityLock) { return; }
|
||||
gActivityLock = true;
|
||||
djui_connect_menu_open();
|
||||
app.lobbies->connect_lobby_with_activity_secret(app.lobbies, (char*)secret, NULL, on_activity_join_callback);
|
||||
}
|
||||
|
|
|
@ -6,5 +6,6 @@ extern struct DiscordActivity gCurActivity;
|
|||
|
||||
void discord_activity_update(bool hosting);
|
||||
struct IDiscordActivityEvents* discord_activity_initialize(void);
|
||||
extern bool gActivityLock;
|
||||
|
||||
#endif
|
|
@ -205,6 +205,7 @@ static bool ns_discord_initialize(enum NetworkType networkType) {
|
|||
// create lobby
|
||||
if (networkType == NT_SERVER) { discord_lobby_create(); }
|
||||
|
||||
gActivityLock = false;
|
||||
gDiscordInitialized = true;
|
||||
LOGFILE_INFO(LFT_DISCORD, "initialized");
|
||||
|
||||
|
@ -214,6 +215,7 @@ static bool ns_discord_initialize(enum NetworkType networkType) {
|
|||
static void ns_discord_shutdown(void) {
|
||||
if (!gDiscordInitialized) { return; }
|
||||
discord_lobby_leave();
|
||||
gActivityLock = false;
|
||||
LOGFILE_INFO(LFT_DISCORD, "shutdown");
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ bool gNetworkAreaSyncing = true;
|
|||
u32 gNetworkAreaTimerClock = 0;
|
||||
u32 gNetworkAreaTimer = 0;
|
||||
void* gNetworkServerAddr = NULL;
|
||||
bool gNetworkSentJoin = false;
|
||||
|
||||
struct StringLinkedList gRegisteredMods = { 0 };
|
||||
|
||||
|
@ -83,6 +84,7 @@ bool network_init(enum NetworkType inNetworkType) {
|
|||
Cheats.EnableCheats = gServerSettings.enableCheats;
|
||||
|
||||
// initialize the network system
|
||||
gNetworkSentJoin = false;
|
||||
int rc = gNetworkSystem->initialize(inNetworkType);
|
||||
if (!rc) {
|
||||
LOG_ERROR("failed to initialize network system");
|
||||
|
@ -142,7 +144,8 @@ bool network_allow_unknown_local_index(enum PacketType packetType) {
|
|||
|| (packetType == PACKET_MOD_LIST_REQUEST)
|
||||
|| (packetType == PACKET_MOD_LIST)
|
||||
|| (packetType == PACKET_DOWNLOAD_REQUEST)
|
||||
|| (packetType == PACKET_DOWNLOAD);
|
||||
|| (packetType == PACKET_DOWNLOAD)
|
||||
|| (packetType == PACKET_KEEP_ALIVE);
|
||||
}
|
||||
|
||||
void network_send_to(u8 localIndex, struct Packet* p) {
|
||||
|
@ -375,6 +378,8 @@ void network_shutdown(bool sendLeaving) {
|
|||
gDjuiChatBox = NULL;
|
||||
}
|
||||
|
||||
gNetworkSentJoin = false;
|
||||
|
||||
network_forget_all_reliable();
|
||||
if (gNetworkType == NT_NONE) { return; }
|
||||
if (gNetworkSystem == NULL) { LOG_ERROR("no network system attached"); return; }
|
||||
|
|
|
@ -105,6 +105,7 @@ extern void* gNetworkServerAddr;
|
|||
extern struct SyncObject gSyncObjects[];
|
||||
extern struct ServerSettings gServerSettings;
|
||||
extern struct StringLinkedList gRegisteredMods;
|
||||
extern bool gNetworkSentJoin;
|
||||
|
||||
// network.c
|
||||
void network_set_system(enum NetworkSystemType nsType);
|
||||
|
|
|
@ -115,7 +115,7 @@ void network_player_update(void) {
|
|||
network_send_keep_alive(np->localIndex);
|
||||
}
|
||||
}
|
||||
} else if (gNetworkType == NT_CLIENT) {
|
||||
} else if (gNetworkType == NT_CLIENT && gNetworkSentJoin) {
|
||||
struct NetworkPlayer* np = gNetworkPlayerServer;
|
||||
if (!np->connected) { return; }
|
||||
float elapsed = (clock_elapsed() - np->lastReceived);
|
||||
|
|
|
@ -16,9 +16,11 @@ void network_send_next_download_request(void) {
|
|||
for (int i = 0; i < gModTableRemote.entryCount; i++) {
|
||||
struct ModListEntry* entry = &gModTableRemote.entries[i];
|
||||
if (entry->complete) { continue; }
|
||||
//LOG_INFO("sending download request: %d, %d, %lld", i, entry->remoteIndex, entry->curOffset);
|
||||
network_send_download_request(i, entry->remoteIndex, entry->curOffset);
|
||||
return;
|
||||
}
|
||||
//LOG_INFO("sending join request");
|
||||
network_send_join_request();
|
||||
}
|
||||
|
||||
|
@ -130,6 +132,8 @@ void network_receive_download(struct Packet* p) {
|
|||
packet_read(p, &chunkSize, sizeof(u16));
|
||||
packet_read(p, chunk, chunkSize * sizeof(u8));
|
||||
|
||||
//LOG_ERROR("Received download %u:%llu", clientIndex, offset);
|
||||
|
||||
if (clientIndex >= gModTableRemote.entryCount) {
|
||||
LOG_ERROR("Received download of invalid index %u:%llu", clientIndex, offset);
|
||||
return;
|
||||
|
@ -177,7 +181,8 @@ void network_receive_download(struct Packet* p) {
|
|||
|
||||
if (!waiting) {
|
||||
// check if we're finished with this file
|
||||
if (sOffset[OFFSET_COUNT - 1] >= entry->size) {
|
||||
//LOG_INFO("Checking download of '%s': %lld, %lld", entry->name, sOffset[OFFSET_COUNT - 1] + CHUNK_SIZE, entry->size);
|
||||
if (sOffset[OFFSET_COUNT - 1] + CHUNK_SIZE >= entry->size) {
|
||||
LOG_INFO("Finished download of '%s'", entry->name);
|
||||
fclose(entry->fp);
|
||||
entry->fp = NULL;
|
||||
|
|
|
@ -29,6 +29,7 @@ static char sJoinRequestPlayerName[MAX_PLAYER_STRING];
|
|||
void network_send_join_request(void) {
|
||||
SOFT_ASSERT(gNetworkType == NT_CLIENT);
|
||||
|
||||
gNetworkSentJoin = true;
|
||||
gOverrideEeprom = eeprom;
|
||||
|
||||
struct Packet p = { 0 };
|
||||
|
|
Loading…
Reference in New Issue