mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2026-05-08 01:41:41 +00:00
Add a lot of stuff
This commit is contained in:
parent
e9f5cf7370
commit
a57eba091a
8 changed files with 52 additions and 14 deletions
|
|
@ -435,6 +435,8 @@ SORT_BY = "Sort By"
|
|||
NONE = "None"
|
||||
NAME = "Name"
|
||||
GAMEMODE = "Gamemode"
|
||||
TIME = "Time"
|
||||
SIZE = "Size"
|
||||
PLAYERS = "Players"
|
||||
|
||||
[CHANGELOG]
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ class Connection;
|
|||
class Lobby;
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
|
@ -41,7 +42,7 @@ typedef struct {
|
|||
void (*OnLobbyCreated)(uint64_t aLobbyId, const char* aGame, const char* aVersion, const char* aHostName, const char* aMode, uint16_t aMaxConnections);
|
||||
void (*OnLobbyJoined)(uint64_t aLobbyId, uint64_t aUserId, uint64_t aOwnerId, uint64_t aDestId);
|
||||
void (*OnLobbyLeft)(uint64_t aLobbyId, uint64_t aUserId);
|
||||
void (*OnLobbyListGot)(uint64_t aLobbyId, uint64_t aOwnerId, uint16_t aConnections, uint16_t aMaxConnections, int64_t aTimestamp, const char* aGame, const char* aVersion, const char* aHostName, const char* aMode, const char* aDescription);
|
||||
void (*OnLobbyListGot)(uint64_t aLobbyId, uint64_t aOwnerId, uint16_t aConnections, uint16_t aMaxConnections, int64_t aTimestamp, const char* aGame, const char* aVersion, const char* aHostName, const char* aMode, const char* aDescription, size_t aModSize);
|
||||
void (*OnLobbyListFinish)(void);
|
||||
void (*OnReceive)(uint64_t aFromUserId, const uint8_t* aData, uint64_t aSize);
|
||||
void (*OnError)(enum MPacketErrorNumber aErrorNumber, uint64_t tag);
|
||||
|
|
@ -67,8 +68,8 @@ bool coopnet_is_connected(void);
|
|||
CoopNetRc coopnet_begin(const char* aHost, uint32_t aPort, const char* aName, uint64_t aDestId);
|
||||
CoopNetRc coopnet_shutdown(void);
|
||||
CoopNetRc coopnet_update(void);
|
||||
CoopNetRc coopnet_lobby_create(const char* aGame, const char* aVersion, const char* aHostName, const char* aMode, uint16_t aMaxConnections, const char* aPassword, const char* aDescription);
|
||||
CoopNetRc coopnet_lobby_update(uint64_t aLobbyId, const char* aGame, const char* aVersion, const char* aHostName, const char* aMode, const char* aDescription);
|
||||
CoopNetRc coopnet_lobby_create(const char* aGame, const char* aVersion, const char* aHostName, const char* aMode, uint16_t aMaxConnections, const char* aPassword, const char* aDescription, size_t modSize);
|
||||
CoopNetRc coopnet_lobby_update(uint64_t aLobbyId, const char* aGame, const char* aVersion, const char* aHostName, const char* aMode, const char* aDescription, size_t aModSize);
|
||||
CoopNetRc coopnet_lobby_join(uint64_t aLobbyId, const char* aPassword);
|
||||
CoopNetRc coopnet_lobby_leave(uint64_t aLobbyId);
|
||||
CoopNetRc coopnet_lobby_list_get(const char* aGame, const char* aPassword);
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -336,7 +336,7 @@ static const struct ConfigOption options[] = {
|
|||
{.name = "coop_join_port", .type = CONFIG_TYPE_UINT, .uintValue = &configJoinPort},
|
||||
{.name = "coop_network_system", .type = CONFIG_TYPE_UINT, .uintValue = &configNetworkSystem},
|
||||
{.name = "coop_coop_net_sort_selected", .type = CONFIG_TYPE_UINT, .uintValue = &configCoopNetSortSelected},
|
||||
{.name = "coop_coop_net_sort_inverted", .type = CONFIG_TYPE_BOOL, .uintValue = &configCoopNetSortInverted},
|
||||
{.name = "coop_coop_net_sort_inverted", .type = CONFIG_TYPE_BOOL, .boolValue = &configCoopNetSortInverted},
|
||||
{.name = "coop_player_interaction", .type = CONFIG_TYPE_UINT, .uintValue = &configPlayerInteraction},
|
||||
{.name = "coop_player_knockback_strength", .type = CONFIG_TYPE_UINT, .uintValue = &configPlayerKnockbackStrength},
|
||||
{.name = "coop_stay_in_level_after_star", .type = CONFIG_TYPE_UINT, .uintValue = &configStayInLevelAfterStar},
|
||||
|
|
|
|||
|
|
@ -39,6 +39,14 @@ static struct LobbySortType sLobbySorting[] = {
|
|||
"PLAYERS",
|
||||
LOBBY_SORTING_PLAYERS,
|
||||
},
|
||||
{
|
||||
"TIME",
|
||||
LOBBY_SORTING_TIME,
|
||||
},
|
||||
{
|
||||
"SIZE",
|
||||
LOBBY_SORTING_SIZE,
|
||||
},
|
||||
};
|
||||
static const int numSortOptions = sizeof(sLobbySorting) / sizeof(sLobbySorting[0]);
|
||||
|
||||
|
|
@ -85,6 +93,10 @@ static int sort_coopnet_lobby_comp(const void* a, const void* b) {
|
|||
retValue = strcmp(lobbyA->mode, lobbyB->mode);
|
||||
} else if (sortBy == LOBBY_SORTING_PLAYERS) {
|
||||
retValue = lobbyB->playerCount - lobbyA->playerCount;
|
||||
} else if (sortBy == LOBBY_SORTING_TIME) {
|
||||
retValue = lobbyA->timestamp > lobbyB->timestamp ? 1 : -1;
|
||||
} else if (sortBy == LOBBY_SORTING_SIZE) {
|
||||
retValue = lobbyA->modSize > lobbyB->modSize ? 1 : -1;
|
||||
} else if (sortBy == LOBBY_SORTING_NONE) {
|
||||
retValue = lobbyA->lobbyId > lobbyB->lobbyId ? 1 : -1;
|
||||
}
|
||||
|
|
@ -169,7 +181,7 @@ static void djui_panel_join_invert_sort(UNUSED struct DjuiBase* caller) {
|
|||
djui_panel_join_on_sorting_change(NULL);
|
||||
}
|
||||
|
||||
void djui_panel_join_query(uint64_t aLobbyId, UNUSED uint64_t aOwnerId, uint16_t aConnections, uint16_t aMaxConnections, UNUSED int64_t aTimestamp, UNUSED const char* aGame, const char* aVersion, const char* aHostName, const char* aMode, const char* aDescription) {
|
||||
void djui_panel_join_query(uint64_t aLobbyId, UNUSED uint64_t aOwnerId, uint16_t aConnections, uint16_t aMaxConnections, int64_t aTimestamp, UNUSED const char* aGame, const char* aVersion, const char* aHostName, const char* aMode, const char* aDescription, size_t aModSize) {
|
||||
if (!sLobbyLayout) { return; }
|
||||
if (!sLobbyPaginated) { return; }
|
||||
if (aMaxConnections > MAX_PLAYERS) { return; }
|
||||
|
|
@ -200,11 +212,14 @@ void djui_panel_join_query(uint64_t aLobbyId, UNUSED uint64_t aOwnerId, uint16_t
|
|||
lobby->hostName = strdup(aHostName);
|
||||
lobby->mode = strdup(mode);
|
||||
lobby->description = strdup(aDescription);
|
||||
lobby->timestamp = aTimestamp;
|
||||
lobby->modSize = aModSize;
|
||||
lobby->disabled = disabled;
|
||||
|
||||
struct CoopnetLobby** lobbies = realloc(sCoopnetLobbies, (sCoopnetLobbyCount + 1) * sizeof(struct CoopnetLobby*));
|
||||
if (!lobbies) {
|
||||
LOG_ERROR("Failed to reallocate memory to lobbies!");
|
||||
free(lobby);
|
||||
return;
|
||||
}
|
||||
sCoopnetLobbies = lobbies;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ enum LobbySorting {
|
|||
LOBBY_SORTING_NAME,
|
||||
LOBBY_SORTING_GAMEMODE,
|
||||
LOBBY_SORTING_PLAYERS,
|
||||
LOBBY_SORTING_TIME,
|
||||
LOBBY_SORTING_SIZE,
|
||||
LOBBY_SORTING_COUNT,
|
||||
};
|
||||
|
||||
|
|
@ -20,6 +22,8 @@ struct CoopnetLobby {
|
|||
char* mode;
|
||||
char* playerText;
|
||||
char* description;
|
||||
int64_t timestamp;
|
||||
size_t modSize;
|
||||
bool disabled;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -172,20 +172,36 @@ bool ns_coopnet_is_connected(void) {
|
|||
return coopnet_is_connected();
|
||||
}
|
||||
|
||||
static char* get_size_string(size_t size) {
|
||||
static char buffer[32];
|
||||
char* sizeUnits[3] = { "B", "KB", "MB" };
|
||||
f64 convertedSize = (f64)size;
|
||||
u8 sizeType = 0;
|
||||
while (convertedSize >= 1024 && sizeType < 2) {
|
||||
convertedSize /= 1024;
|
||||
sizeType++;
|
||||
}
|
||||
snprintf(buffer, sizeof(buffer), "%.2f %s", convertedSize, sizeUnits[sizeType]);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static void coopnet_populate_description(void) {
|
||||
char* buffer = sCoopNetDescription;
|
||||
int bufferLength = COOPNET_MAX_DESCRIPTION_LEN;
|
||||
// get version
|
||||
const char* version = get_version();
|
||||
int versionLength = snprintf(buffer, bufferLength, "%s\n", version);
|
||||
int versionLength = snprintf(buffer, bufferLength, "%s\n", get_version());
|
||||
buffer += versionLength;
|
||||
bufferLength -= versionLength;
|
||||
|
||||
// get mod size
|
||||
int modsSizeLength = snprintf(buffer, bufferLength, "\nMods Size: %s\n", get_size_string(gActiveMods.size));
|
||||
buffer += modsSizeLength;
|
||||
bufferLength -= modsSizeLength;
|
||||
|
||||
// add seperator
|
||||
char* sep = "\nMods:\n";
|
||||
snprintf(buffer, bufferLength, "%s", sep);
|
||||
buffer += strlen(sep);
|
||||
bufferLength -= strlen(sep);
|
||||
int sepLength = snprintf(buffer, bufferLength, "Mods:\n");
|
||||
buffer += sepLength;
|
||||
bufferLength -= sepLength;
|
||||
|
||||
struct ModCategory sCategories[] = {
|
||||
{ "GAMEMODES", "gamemode" },
|
||||
|
|
@ -272,12 +288,12 @@ void ns_coopnet_update(void) {
|
|||
if (sReconnecting) {
|
||||
LOG_INFO("Update lobby");
|
||||
coopnet_populate_description();
|
||||
coopnet_lobby_update(sLocalLobbyId, GAME_NAME, get_version(), configPlayerName, mode, sCoopNetDescription);
|
||||
coopnet_lobby_update(sLocalLobbyId, GAME_NAME, get_version(), configPlayerName, mode, sCoopNetDescription, gActiveMods.size);
|
||||
} else {
|
||||
LOG_INFO("Create lobby");
|
||||
snprintf(gCoopNetPassword, COOPNET_MAX_PASSWORD_LEN, "%s", configPassword);
|
||||
coopnet_populate_description();
|
||||
coopnet_lobby_create(GAME_NAME, get_version(), configPlayerName, mode, (uint16_t)configAmountOfPlayers, gCoopNetPassword, sCoopNetDescription);
|
||||
coopnet_lobby_create(GAME_NAME, get_version(), configPlayerName, mode, (uint16_t)configAmountOfPlayers, gCoopNetPassword, sCoopNetDescription, gActiveMods.size);
|
||||
}
|
||||
} else if (sNetworkType == NT_CLIENT) {
|
||||
LOG_INFO("Join lobby");
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#define COOPNET_H
|
||||
#ifdef COOPNET
|
||||
|
||||
typedef void (*QueryCallbackPtr)(uint64_t aLobbyId, uint64_t aOwnerId, uint16_t aConnections, uint16_t aMaxConnections, int64_t aTimestamp, const char* aGame, const char* aVersion, const char* aHostName, const char* aMode, const char* aDescription);
|
||||
typedef void (*QueryCallbackPtr)(uint64_t aLobbyId, uint64_t aOwnerId, uint16_t aConnections, uint16_t aMaxConnections, int64_t aTimestamp, const char* aGame, const char* aVersion, const char* aHostName, const char* aMode, const char* aDescription, size_t aModSize);
|
||||
typedef void (*QueryFinishCallbackPtr)(void);
|
||||
|
||||
extern struct NetworkSystem gNetworkSystemCoopNet;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue