diff --git a/src/d_clisrv.c b/src/d_clisrv.c index d2f1b1ac1..bd4c5064a 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3853,6 +3853,7 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum) READSTRINGN(*p, player_names[newplayernum], MAXPLAYERNAME); READMEM(*p, players[newplayernum].public_key, PUBKEYLENGTH); + READMEM(*p, clientpowerlevels[newplayernum], sizeof(((serverplayer_t *)0)->powerlevels)); console = READUINT8(*p); splitscreenplayer = READUINT8(*p); @@ -3917,8 +3918,6 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum) HU_AddChatText(joinmsg, false); } - SV_RetrieveStats(newplayernum); - if (server && multiplayer && motd[0] != '\0') COM_BufAddText(va("sayto %d %s\n", newplayernum, motd)); @@ -4011,8 +4010,10 @@ static void Got_AddBot(UINT8 **p, INT32 playernum) } static boolean SV_AddWaitingPlayers(SINT8 node, UINT8 *availabilities, -const char *name, uint8_t *key, const char *name2, uint8_t *key2, -const char *name3, uint8_t *key3, const char *name4, uint8_t *key4) +const char *name, uint8_t *key, UINT16 *pwr, +const char *name2, uint8_t *key2, UINT16 *pwr2, +const char *name3, uint8_t *key3, UINT16 *pwr3, +const char *name4, uint8_t *key4, UINT16 *pwr4) { INT32 n, newplayernum, i; UINT8 buf[4 + MAXPLAYERNAME + PUBKEYLENGTH + MAXAVAILABILITY]; @@ -4079,24 +4080,28 @@ const char *name3, uint8_t *key3, const char *name4, uint8_t *key4) nodetoplayer[node] = newplayernum; WRITESTRINGN(buf_p, name, MAXPLAYERNAME); WRITEMEM(buf_p, key, PUBKEYLENGTH); + WRITEMEM(buf_p, pwr, sizeof(((serverplayer_t *)0)->powerlevels)); } else if (playerpernode[node] < 2) { nodetoplayer2[node] = newplayernum; WRITESTRINGN(buf_p, name2, MAXPLAYERNAME); WRITEMEM(buf_p, key2, PUBKEYLENGTH); + WRITEMEM(buf_p, pwr2, sizeof(((serverplayer_t *)0)->powerlevels)); } else if (playerpernode[node] < 3) { nodetoplayer3[node] = newplayernum; WRITESTRINGN(buf_p, name3, MAXPLAYERNAME); WRITEMEM(buf_p, key3, PUBKEYLENGTH); + WRITEMEM(buf_p, pwr3, sizeof(((serverplayer_t *)0)->powerlevels)); } else if (playerpernode[node] < 4) { nodetoplayer4[node] = newplayernum; WRITESTRINGN(buf_p, name4, MAXPLAYERNAME); WRITEMEM(buf_p, key4, PUBKEYLENGTH); + WRITEMEM(buf_p, pwr4, sizeof(((serverplayer_t *)0)->powerlevels)); } WRITEUINT8(buf_p, nodetoplayer[node]); // consoleplayer @@ -4186,8 +4191,11 @@ boolean SV_SpawnServer(void) UINT8 *availabilitiesbuffer = R_GetSkinAvailabilities(false, false); SINT8 node = 0; for (; node < MAXNETNODES; node++) - result |= SV_AddWaitingPlayers(node, availabilitiesbuffer, cv_playername[0].zstring, PR_GetLocalPlayerProfile(0)->public_key, cv_playername[1].zstring, PR_GetLocalPlayerProfile(1)->public_key, - cv_playername[2].zstring, PR_GetLocalPlayerProfile(2)->public_key, cv_playername[3].zstring, PR_GetLocalPlayerProfile(3)->public_key); + result |= SV_AddWaitingPlayers(node, availabilitiesbuffer, + cv_playername[0].zstring, PR_GetLocalPlayerProfile(0)->public_key, SV_RetrievePWR(PR_GetLocalPlayerProfile(0)->public_key), + cv_playername[1].zstring, PR_GetLocalPlayerProfile(1)->public_key, SV_RetrievePWR(PR_GetLocalPlayerProfile(1)->public_key), + cv_playername[2].zstring, PR_GetLocalPlayerProfile(2)->public_key, SV_RetrievePWR(PR_GetLocalPlayerProfile(2)->public_key), + cv_playername[3].zstring, PR_GetLocalPlayerProfile(3)->public_key, SV_RetrievePWR(PR_GetLocalPlayerProfile(3)->public_key)); } return result; #endif @@ -4268,13 +4276,13 @@ static size_t TotalTextCmdPerTic(tic_t tic) memset(allZero, 0, PUBKEYLENGTH); if (split == 0) - return (memcmp(players[nodetoplayer[node]].public_key, allZero, PUBKEYLENGTH) == 0); + return PR_IsKeyGuest(players[nodetoplayer[node]].public_key); else if (split == 1) - return (memcmp(players[nodetoplayer2[node]].public_key, allZero, PUBKEYLENGTH) == 0); + return PR_IsKeyGuest(players[nodetoplayer2[node]].public_key); else if (split == 2) - return (memcmp(players[nodetoplayer3[node]].public_key, allZero, PUBKEYLENGTH) == 0); + return PR_IsKeyGuest(players[nodetoplayer3[node]].public_key); else if (split == 3) - return (memcmp(players[nodetoplayer4[node]].public_key, allZero, PUBKEYLENGTH) == 0); + return PR_IsKeyGuest(players[nodetoplayer4[node]].public_key); else I_Error("IsSplitPlayerOnNodeGuest: Out of bounds"); return false; // unreachable @@ -4283,10 +4291,7 @@ static size_t TotalTextCmdPerTic(tic_t tic) static boolean IsPlayerGuest(int player) { - char allZero[PUBKEYLENGTH]; - memset(allZero, 0, PUBKEYLENGTH); - - return (memcmp(players[player].public_key, allZero, PUBKEYLENGTH) == 0); + return PR_IsKeyGuest(players[player].public_key); } /** Called when a PT_CLIENTJOIN packet is received @@ -4396,8 +4401,6 @@ static void HandleConnect(SINT8 node) { int sigcheck; boolean newnode = false; - char allZero[PUBKEYLENGTH]; - memset(allZero, 0, sizeof(allZero)); for (i = 0; i < netbuffer->u.clientcfg.localplayers - playerpernode[node]; i++) { @@ -4414,7 +4417,7 @@ static void HandleConnect(SINT8 node) } else // Remote player, gotta check their signature. { - if (memcmp(lastReceivedKey[node][i], allZero, PUBKEYLENGTH) == 0) // IsSplitPlayerOnNodeGuest isn't appropriate here, they're not in-game yet! + if (PR_IsKeyGuest(lastReceivedKey[node][i])) // IsSplitPlayerOnNodeGuest isn't appropriate here, they're not in-game yet! { if (!cv_allowguests.value) { @@ -4437,7 +4440,7 @@ static void HandleConnect(SINT8 node) } // Check non-GUESTS for duplicate pubkeys, they'll create nonsense stats - if (memcmp(lastReceivedKey[node][i], allZero, PUBKEYLENGTH) != 0) + if (!PR_IsKeyGuest(lastReceivedKey[node][i])) { // Players already here for (j = 0; j < MAXPLAYERS; j++) @@ -4452,7 +4455,7 @@ static void HandleConnect(SINT8 node) // Players we're trying to add for (j = 0; j < netbuffer->u.clientcfg.localplayers - playerpernode[node]; j++) { - if (memcmp(lastReceivedKey[node][i], allZero, PUBKEYLENGTH) == 0) + if (PR_IsKeyGuest(lastReceivedKey[node][j])) continue; if (i == j) continue; @@ -4502,8 +4505,11 @@ static void HandleConnect(SINT8 node) DEBFILE("send savegame\n"); } - SV_AddWaitingPlayers(node, availabilitiesbuffer, names[0], lastReceivedKey[node][0], names[1], lastReceivedKey[node][1], - names[2], lastReceivedKey[node][2], names[3], lastReceivedKey[node][3]); + SV_AddWaitingPlayers(node, availabilitiesbuffer, + names[0], lastReceivedKey[node][0], SV_RetrievePWR(lastReceivedKey[node][0]), + names[1], lastReceivedKey[node][1], SV_RetrievePWR(lastReceivedKey[node][1]), + names[2], lastReceivedKey[node][2], SV_RetrievePWR(lastReceivedKey[node][2]), + names[3], lastReceivedKey[node][3], SV_RetrievePWR(lastReceivedKey[node][3])); joindelay += cv_joindelay.value * TICRATE; player_joining = true; } diff --git a/src/d_netcmd.c b/src/d_netcmd.c index c1fa1b7d0..2dbf96b62 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -618,7 +618,6 @@ const char *netxcmdnames[MAXNETXCMD - 1] = "MODIFYVOTE", // XD_MODIFYVOTE "PICKVOTE", // XD_PICKVOTE "REMOVEPLAYER", // XD_REMOVEPLAYER - "POWERLEVEL", // XD_POWERLEVEL "PARTYINVITE", // XD_PARTYINVITE "ACCEPTPARTYINVITE", // XD_ACCEPTPARTYINVITE "LEAVEPARTY", // XD_LEAVEPARTY @@ -657,7 +656,6 @@ void D_RegisterServerCommands(void) RegisterNetXCmd(XD_NAMEANDCOLOR, Got_NameAndColor); RegisterNetXCmd(XD_WEAPONPREF, Got_WeaponPref); - RegisterNetXCmd(XD_POWERLEVEL, Got_PowerLevel); RegisterNetXCmd(XD_PARTYINVITE, Got_PartyInvite); RegisterNetXCmd(XD_ACCEPTPARTYINVITE, Got_AcceptPartyInvite); RegisterNetXCmd(XD_CANCELPARTYINVITE, Got_CancelPartyInvite); @@ -1807,19 +1805,21 @@ static void Got_WeaponPref(UINT8 **cp,INT32 playernum) demo_extradata[playernum] |= DXD_WEAPONPREF; } +// Currently unused, PWR is sent in XD_ADDPLAYER static void Got_PowerLevel(UINT8 **cp,INT32 playernum) { - // Server keeps track of this now, no-sell XD_POWERLEVEL + int i; - /* - UINT16 race = (UINT16)READUINT16(*cp); - UINT16 battle = (UINT16)READUINT16(*cp); + for(i = 0; i < MAXPLAYERS; i++) + { + UINT16 race = (UINT16)READUINT16(*cp); + UINT16 battle = (UINT16)READUINT16(*cp); - clientpowerlevels[playernum][PWRLV_RACE] = min(PWRLVRECORD_MAX, race); - clientpowerlevels[playernum][PWRLV_BATTLE] = min(PWRLVRECORD_MAX, battle); + clientpowerlevels[i][PWRLV_RACE] = min(PWRLVRECORD_MAX, race); + clientpowerlevels[i][PWRLV_BATTLE] = min(PWRLVRECORD_MAX, battle); - CONS_Debug(DBG_GAMELOGIC, "set player %d to power %d\n", playernum, race); - */ + CONS_Debug(DBG_GAMELOGIC, "set player %d to power %d\n", i, race); + } } static void Got_PartyInvite(UINT8 **cp,INT32 playernum) @@ -1980,23 +1980,6 @@ void D_SendPlayerConfig(UINT8 n) SendNameAndColor(n); WeaponPref_Send(n); - - /* - if (pr != NULL) - { - // Send it over - WRITEUINT16(p, pr->powerlevels[PWRLV_RACE]); - WRITEUINT16(p, pr->powerlevels[PWRLV_BATTLE]); - } - else - { - // Guest players have no power level - WRITEUINT16(p, 0); - WRITEUINT16(p, 0); - } - - SendNetXCmdForPlayer(n, XD_POWERLEVEL, buf, p-buf); - */ } void D_Cheat(INT32 playernum, INT32 cheat, ...) diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 8cab1e10f..d4d5fee85 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -169,7 +169,7 @@ typedef enum XD_MODIFYVOTE, // 24 XD_PICKVOTE, // 25 XD_REMOVEPLAYER,// 26 - XD_POWERLEVEL, // 27 + XD_POWERLEVEL, // 27 [No longer used, might be repurposed - PWR is in XD_ADDPLAYER now] XD_PARTYINVITE, // 28 XD_ACCEPTPARTYINVITE, // 29 XD_LEAVEPARTY, // 30 diff --git a/src/deh_soc.c b/src/deh_soc.c index a7962e3af..fea7df30e 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -2458,25 +2458,6 @@ static void readcondition(UINT8 set, UINT32 id, char *word2) return; } } - else if (fastcmp(params[0], "POWERLEVEL")) - { - PARAMCHECK(2); - ty = UC_POWERLEVEL; - re = atoi(params[1]); - x1 = atoi(params[2]); - - if (re < PWRLVRECORD_MIN || re > PWRLVRECORD_MAX) - { - deh_warning("Power level requirement %d out of range (%d - %d) for condition ID %d", re, PWRLVRECORD_MIN, PWRLVRECORD_MAX, id+1); - return; - } - - if (x1 < 0 || x1 >= PWRLV_NUMTYPES) - { - deh_warning("Power level type %d out of range (0 - %d) for condition ID %d", x1, PWRLV_NUMTYPES-1, id+1); - return; - } - } else if (fastcmp(params[0], "GAMECLEAR")) { ty = UC_GAMECLEAR; diff --git a/src/k_menudraw.c b/src/k_menudraw.c index 33cbf3aec..b7e633c47 100644 --- a/src/k_menudraw.c +++ b/src/k_menudraw.c @@ -1673,7 +1673,6 @@ static void M_DrawProfileCard(INT32 x, INT32 y, boolean greyedout, profile_t *p) UINT16 truecol = SKINCOLOR_BLACK; UINT8 *colormap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_BLACK, GTC_CACHE); INT32 skinnum = -1; - INT32 powerlevel = -1; char pname[PROFILENAMELEN+1] = "NEW"; @@ -1683,7 +1682,6 @@ static void M_DrawProfileCard(INT32 x, INT32 y, boolean greyedout, profile_t *p) colormap = R_GetTranslationColormap(TC_DEFAULT, truecol, GTC_CACHE); strcpy(pname, p->profilename); skinnum = R_SkinAvailable(p->skinname); - powerlevel = p->powerlevels[0]; // Only display race power level. } // check setup_player for colormap for the card. @@ -1700,12 +1698,8 @@ static void M_DrawProfileCard(INT32 x, INT32 y, boolean greyedout, profile_t *p) if (greyedout) return; // only used for profiles we can't select. - // Draw pwlv if we can - if (powerlevel > -1) - { - V_DrawFixedPatch((x+30)*FRACUNIT, (y+84)*FRACUNIT, FRACUNIT, 0, pwrlv, colormap); - V_DrawCenteredKartString(x+30, y+87, 0, va("%d\n", powerlevel)); - } + V_DrawFixedPatch((x+30)*FRACUNIT, (y+84)*FRACUNIT, FRACUNIT, 0, pwrlv, colormap); + V_DrawCenteredKartString(x+30, y+87, 0, "TEMP"); // check what setup_player is doing in priority. if (sp->mdepth >= CSSTEP_CHARS) diff --git a/src/k_profiles.c b/src/k_profiles.c index 853306556..d8b421d7c 100644 --- a/src/k_profiles.c +++ b/src/k_profiles.c @@ -630,3 +630,12 @@ char *GetPrettyRRID(const unsigned char *bin, boolean brief) return rrid_buf; } + + +char allZero[PUBKEYLENGTH]; + +boolean PR_IsKeyGuest(uint8_t *key) +{ + memset(allZero, 0, PUBKEYLENGTH); + return (memcmp(key, allZero, PUBKEYLENGTH) == 0); +} \ No newline at end of file diff --git a/src/k_profiles.h b/src/k_profiles.h index 2a866868f..65e1d740f 100644 --- a/src/k_profiles.h +++ b/src/k_profiles.h @@ -166,6 +166,8 @@ boolean PR_IsLocalPlayerGuest(INT32 player); char *GetPrettyRRID(const unsigned char *bin, boolean brief); +boolean PR_IsKeyGuest(uint8_t *key); + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/k_pwrlv.c b/src/k_pwrlv.c index 5aec0e5e9..9e3b3f640 100644 --- a/src/k_pwrlv.c +++ b/src/k_pwrlv.c @@ -400,7 +400,6 @@ void K_CashInPowerLevels(void) { SINT8 powerType = K_UsingPowerLevels(); UINT8 i; - boolean gamedataupdate; //CONS_Printf("\n========\n"); //CONS_Printf("Cashing in power level changes...\n"); @@ -410,29 +409,17 @@ void K_CashInPowerLevels(void) { if (playeringame[i] == true && powerType != PWRLV_DISABLED) { - profile_t *pr = PR_GetPlayerProfile(&players[i]); INT16 inc = K_FinalPowerIncrement(&players[i], clientpowerlevels[i][powerType], clientPowerAdd[i]); clientpowerlevels[i][powerType] += inc; //CONS_Printf("%s: %d -> %d (%d)\n", player_names[i], clientpowerlevels[i][powerType] - inc, clientpowerlevels[i][powerType], inc); - - if (pr != NULL && inc != 0) - { - pr->powerlevels[powerType] = clientpowerlevels[i][powerType]; - - gamedataupdate = true; - } } clientPowerAdd[i] = 0; } - if (gamedataupdate) - { - M_UpdateUnlockablesAndExtraEmblems(true, true); - G_SaveGameData(); - } + SV_UpdateStats(); //CONS_Printf("========\n"); } diff --git a/src/k_serverstats.c b/src/k_serverstats.c index 3e30f9290..f04a3c182 100644 --- a/src/k_serverstats.c +++ b/src/k_serverstats.c @@ -21,6 +21,8 @@ static serverplayer_t trackedList[MAXTRACKEDSERVERPLAYERS]; static UINT32 numtracked = 0; +UINT16 guestpwr[PWRLV_NUMTYPES]; // All-zero power level to reference for guests + // Read stats file to trackedList for ingame use void SV_LoadStats(void) { @@ -106,41 +108,35 @@ void SV_SaveStats(void) } // New player, grab their stats from trackedList or initialize new ones if they're new -void SV_RetrieveStats(int player) +UINT16 *SV_RetrievePWR(uint8_t *key) { - if (!server) - return; - UINT32 j; + // Existing record? for(j = 0; j < numtracked; j++) { - if (memcmp(trackedList[j].public_key, players[player].public_key, PUBKEYLENGTH) == 0) + if (memcmp(trackedList[j].public_key, key, PUBKEYLENGTH) == 0) { - memcpy(clientpowerlevels[player], trackedList[j].powerlevels, sizeof(trackedList[j].powerlevels)); - return; + return trackedList[j].powerlevels; } } - uint8_t allZero[PUBKEYLENGTH]; - memset(allZero, 0, PUBKEYLENGTH); - + // Untracked, make a new record + memcpy(trackedList[numtracked].public_key, key, PUBKEYLENGTH); for(j = 0; j < PWRLV_NUMTYPES; j++) { - if (memcmp(players[player].public_key, allZero, PUBKEYLENGTH) == 0) - clientpowerlevels[player][j] = 0; - else - clientpowerlevels[player][j] = PWRLVRECORD_START; + trackedList[numtracked].powerlevels[j] = PR_IsKeyGuest(key) ? 0 : PWRLVRECORD_START; } + + numtracked++; + return trackedList[numtracked - 1].powerlevels; } // Write player stats to trackedList, then save to disk void SV_UpdateStats(void) { UINT32 i, j; - uint8_t allZero[PUBKEYLENGTH]; - memset(allZero, 0, PUBKEYLENGTH); if (!server) return; @@ -150,29 +146,22 @@ void SV_UpdateStats(void) if (!playeringame[i]) continue; - if (memcmp(players[i].public_key, allZero, PUBKEYLENGTH) == 0) + if (PR_IsKeyGuest(players[i].public_key)) { continue; } - boolean match = false; for(j = 0; j < numtracked; j++) { if (memcmp(trackedList[j].public_key, players[i].public_key, PUBKEYLENGTH) == 0) { memcpy(trackedList[j].powerlevels, clientpowerlevels[i], sizeof(trackedList[j].powerlevels)); - match = true; break; } } - if (match) - continue; - - memcpy(trackedList[numtracked].public_key, players[i].public_key, PUBKEYLENGTH); - memcpy(trackedList[numtracked].powerlevels, clientpowerlevels[i], sizeof(trackedList[numtracked].powerlevels)); - - numtracked++; + // SV_RetrievePWR should always be called for a key before SV_UpdateStats runs, + // so this shouldn't be reachable. } SV_SaveStats(); diff --git a/src/k_serverstats.h b/src/k_serverstats.h index ffaaf571b..73210095b 100644 --- a/src/k_serverstats.h +++ b/src/k_serverstats.h @@ -39,7 +39,7 @@ void SV_SaveStats(void); void SV_LoadStats(void); -void SV_RetrieveStats(int player); +UINT16 *SV_RetrievePWR(uint8_t *key); void SV_UpdateStats(void); diff --git a/src/m_cond.c b/src/m_cond.c index 45db53caf..5b551f646 100644 --- a/src/m_cond.c +++ b/src/m_cond.c @@ -683,25 +683,6 @@ boolean M_CheckCondition(condition_t *cn, player_t *player) } case UC_TOTALRINGS: // Requires grabbing >= x rings return (gamedata->totalrings >= (unsigned)cn->requirement); - case UC_POWERLEVEL: // Requires power level >= x on a certain gametype - { - UINT8 i; - - if (gamestate == GS_LEVEL) - return false; // this one could be laggy with many profiles available - - for (i = PROFILE_GUEST; i < PR_GetNumProfiles(); i++) - { - profile_t *p = PR_GetProfile(i); - - if (p->powerlevels[cn->extrainfo1] >= (unsigned)cn->requirement) - { - return true; - } - } - - return false; - } case UC_GAMECLEAR: // Requires game beaten >= x times return (gamedata->timesBeaten >= (unsigned)cn->requirement); case UC_OVERALLTIME: // Requires overall time <= x @@ -1039,12 +1020,6 @@ static const char *M_GetConditionString(condition_t *cn) return va("collect %u,%03u Rings", (cn->requirement/1000), (cn->requirement%1000)); return va("collect %u Rings", cn->requirement); - case UC_POWERLEVEL: // Requires power level >= x on a certain gametype - return va("get a PWR of %d in %s", cn->requirement, - (cn->extrainfo1 == PWRLV_RACE) - ? "Race" - : "Battle"); - case UC_GAMECLEAR: // Requires game beaten >= x times if (cn->requirement > 1) return va("beat game %d times", cn->requirement); diff --git a/src/m_cond.h b/src/m_cond.h index c7712d5f7..a53e66ad7 100644 --- a/src/m_cond.h +++ b/src/m_cond.h @@ -32,8 +32,6 @@ typedef enum UC_ROUNDSPLAYED, // ROUNDSPLAYED [x played] UC_TOTALRINGS, // TOTALRINGS [x collected] - UC_POWERLEVEL, // SRB2Kart: POWERLEVEL [power level to reach] [gametype, "0" for race, "1" for battle] - UC_GAMECLEAR, // GAMECLEAR UC_OVERALLTIME, // OVERALLTIME [time to beat, tics]