Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Online: Fix DNS server default, show revival team credits on pause screen #19875

Merged
merged 5 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Common/Net/HTTPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,18 @@ void Server::SetFallbackHandler(UrlHandlerFunc handler) {
fallback_ = handler;
}

bool Server::Listen(int port, net::DNSType type) {
bool Server::Listen(int port, const char *reason, net::DNSType type) {
bool success = false;
if (type == net::DNSType::ANY || type == net::DNSType::IPV6) {
success = Listen6(port, type == net::DNSType::IPV6);
success = Listen6(port, type == net::DNSType::IPV6, reason);
}
if (!success && (type == net::DNSType::ANY || type == net::DNSType::IPV4)) {
success = Listen4(port);
success = Listen4(port, reason);
}
return success;
}

bool Server::Listen4(int port) {
bool Server::Listen4(int port, const char *reason) {
listener_ = socket(AF_INET, SOCK_STREAM, 0);
if (listener_ < 0)
return false;
Expand All @@ -190,7 +190,7 @@ bool Server::Listen4(int port) {
#else
int err = errno;
#endif
ERROR_LOG(Log::IO, "Failed to bind to port %d, error=%d - Bailing (ipv4)", port, err);
ERROR_LOG(Log::IO, "%s: Failed to bind to port %d, error=%d - Bailing (ipv4)", reason, port, err);
closesocket(listener_);
return false;
}
Expand All @@ -208,13 +208,13 @@ bool Server::Listen4(int port) {
port = ntohs(server_addr.sin_port);
}

INFO_LOG(Log::IO, "HTTP server started on port %d", port);
INFO_LOG(Log::IO, "HTTP server started on port %d: %s", port, reason);
port_ = port;

return true;
}

bool Server::Listen6(int port, bool ipv6_only) {
bool Server::Listen6(int port, bool ipv6_only, const char *reason) {
#if !PPSSPP_PLATFORM(SWITCH)
listener_ = socket(AF_INET6, SOCK_STREAM, 0);
if (listener_ < 0)
Expand All @@ -240,7 +240,7 @@ bool Server::Listen6(int port, bool ipv6_only) {
#else
int err = errno;
#endif
ERROR_LOG(Log::IO, "Failed to bind to port %d, error=%d - Bailing (ipv6)", port, err);
ERROR_LOG(Log::IO, "%s: Failed to bind to port %d, error=%d - Bailing (ipv6)", reason, port, err);
closesocket(listener_);
return false;
}
Expand All @@ -258,7 +258,7 @@ bool Server::Listen6(int port, bool ipv6_only) {
port = ntohs(server_addr.sin6_port);
}

INFO_LOG(Log::IO, "HTTP server started on port %d", port);
INFO_LOG(Log::IO, "HTTP server started on port %d: %s", port, reason);
port_ = port;

return true;
Expand Down Expand Up @@ -299,7 +299,7 @@ bool Server::RunSlice(double timeout) {
}

bool Server::Run(int port) {
if (!Listen(port)) {
if (!Listen(port, "websocket")) {
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions Common/Net/HTTPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Server {
// May run for (significantly) longer than timeout, but won't wait longer than that
// for a new connection to handle.
bool RunSlice(double timeout);
bool Listen(int port, net::DNSType type = net::DNSType::ANY);
bool Listen(int port, const char *reason, net::DNSType type = net::DNSType::ANY);
void Stop();

void RegisterHandler(const char *url_path, UrlHandlerFunc handler);
Expand All @@ -101,8 +101,8 @@ class Server {
}

private:
bool Listen6(int port, bool ipv6_only);
bool Listen4(int port);
bool Listen6(int port, bool ipv6_only, const char *reason);
bool Listen4(int port, const char *reason);

void HandleConnection(int conn_fd);

Expand Down
134 changes: 128 additions & 6 deletions Core/Dialog/PSPDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Common/Serialize/Serializer.h"
#include "Common/Serialize/SerializeFuncs.h"
#include "Common/StringUtils.h"
#include "Common/Data/Encoding/Utf8.h"
#include "Core/Config.h"
#include "Core/System.h"
#include "Core/CoreTiming.h"
Expand All @@ -31,13 +32,8 @@
#include "Core/Util/PPGeDraw.h"

#define FADE_TIME 1.0
const float FONT_SCALE = 0.55f;

PSPDialog::PSPDialog(UtilityDialogType type) : dialogType_(type) {
}

PSPDialog::~PSPDialog() {
}
constexpr float FONT_SCALE = 0.55f;

void PSPDialog::InitCommon() {
UpdateCommon();
Expand Down Expand Up @@ -340,3 +336,129 @@ int PSPDialog::GetCancelButton() {
}
return g_Config.iButtonPreference == PSP_SYSTEMPARAM_BUTTON_CROSS ? CTRL_CIRCLE : CTRL_CROSS;
}

void PSPDialog::DisplayMessage2(std::string_view text1, std::string_view text2a, std::string_view text2b, std::string_view text3a, std::string_view text3b, bool hasYesNo, bool hasOK) {
auto di = GetI18NCategory(I18NCat::DIALOG);

PPGeStyle buttonStyle = FadedStyle(PPGeAlign::BOX_CENTER, FONT_SCALE);
PPGeStyle messageStyle = FadedStyle(PPGeAlign::BOX_HCENTER, FONT_SCALE);
PPGeStyle messageStyleRight = FadedStyle(PPGeAlign::BOX_RIGHT, FONT_SCALE);
PPGeStyle messageStyleLeft = FadedStyle(PPGeAlign::BOX_LEFT, FONT_SCALE);

std::string text2 = std::string(text2a) + " " + std::string(text2b);
std::string text3 = std::string(text3a) + " " + std::string(text3b);

// Without the scrollbar, we have 350 total pixels.
float WRAP_WIDTH = 300.0f;
if (UTF8StringNonASCIICount(text1) >= (int)text1.size() / 4) {
WRAP_WIDTH = 336.0f;
if (text1.size() > 12) {
messageStyle.scale = 0.6f;
}
}

float totalHeight1 = 0.0f;
PPGeMeasureText(nullptr, &totalHeight1, text1, FONT_SCALE, PPGE_LINE_WRAP_WORD, WRAP_WIDTH);
float totalHeight2 = 0.0f;
if (text2 != " ")
PPGeMeasureText(nullptr, &totalHeight2, text2, FONT_SCALE, PPGE_LINE_USE_ELLIPSIS, WRAP_WIDTH);
float totalHeight3 = 0.0f;
if (text3 != " ")
PPGeMeasureText(nullptr, &totalHeight3, text3, FONT_SCALE, PPGE_LINE_USE_ELLIPSIS, WRAP_WIDTH);
float marginTop = 0.0f;
if (text2 != " " || text3 != " ")
marginTop = 11.0f;
float totalHeight = totalHeight1 + totalHeight2 + totalHeight3 + marginTop;
// The PSP normally only shows about 8 lines at a time.
// For improved UX, we intentionally show part of the next line.
float visibleHeight = std::min(totalHeight, 175.0f);
float h2 = visibleHeight / 2.0f;

float centerY = 135.0f;
float sy = centerY - h2 - 15.0f;
float ey = centerY + h2 + 20.0f;
float buttonY = centerY + h2 + 5.0f;

auto drawSelectionBoxAndAdjust = [&](float x) {
// Box has a fixed size.
float w = 15.0f;
float h = 8.0f;
PPGeDrawRect(x - w, buttonY - h, x + w, buttonY + h, CalcFadedColor(0x6DCFCFCF));

centerY -= h + 5.0f;
sy -= h + 5.0f;
ey = buttonY + h * 2.0f + 5.0f;
};

if (hasYesNo) {
if (yesnoChoice == 1) {
drawSelectionBoxAndAdjust(204.0f);
} else {
drawSelectionBoxAndAdjust(273.0f);
}

PPGeDrawText(di->T("Yes"), 203.0f, buttonY - 1.0f, buttonStyle);
PPGeDrawText(di->T("No"), 272.0f, buttonY - 1.0f, buttonStyle);
if (IsButtonPressed(CTRL_LEFT) && yesnoChoice == 0) {
yesnoChoice = 1;
} else if (IsButtonPressed(CTRL_RIGHT) && yesnoChoice == 1) {
yesnoChoice = 0;
}
buttonY += 8.0f + 5.0f;
}

if (hasOK) {
drawSelectionBoxAndAdjust(240.0f);

PPGeDrawText(di->T("OK"), 239.0f, buttonY - 1.0f, buttonStyle);
buttonY += 8.0f + 5.0f;
}

PPGeScissor(0, (int)(centerY - h2 - 2), 480, (int)(centerY + h2 + 2));
PPGeDrawTextWrapped(text1, 240.0f, centerY - h2 - scrollPos_, WRAP_WIDTH, 0, messageStyle);
if (!text2a.empty()) {
if (!text2b.empty())
PPGeDrawTextWrapped(text2a, 240.0f - 5.0f, centerY - h2 - scrollPos_ + totalHeight1 + marginTop, WRAP_WIDTH, 0, messageStyleRight);
else
PPGeDrawTextWrapped(text2a, 240.0f, centerY - h2 - scrollPos_ + totalHeight1 + marginTop, WRAP_WIDTH, 0, messageStyle);
}
if (!text2b.empty())
PPGeDrawTextWrapped(text2b, 240.0f + 5.0f, centerY - h2 - scrollPos_ + totalHeight1 + marginTop, WRAP_WIDTH, 0, messageStyleLeft);
if (!text3a.empty()) {
if (!text3b.empty())
PPGeDrawTextWrapped(text3a, 240.0f - 5.0f, centerY - h2 - scrollPos_ + totalHeight1 + totalHeight2 + marginTop, WRAP_WIDTH, 0, messageStyleRight);
else
PPGeDrawTextWrapped(text3a, 240.0f, centerY - h2 - scrollPos_ + totalHeight1 + totalHeight2 + marginTop, WRAP_WIDTH, 0, messageStyle);
}
if (!text3b.empty())
PPGeDrawTextWrapped(text3b, 240.0f + 5.0f, centerY - h2 - scrollPos_ + totalHeight1 + totalHeight2 + marginTop, WRAP_WIDTH, 0, messageStyleLeft);
PPGeScissorReset();

// Do we need a scrollbar?
if (visibleHeight < totalHeight) {
float scrollSpeed = 5.0f;
float scrollMax = totalHeight - visibleHeight;

float bobHeight = (visibleHeight / totalHeight) * visibleHeight;
float bobOffset = (scrollPos_ / scrollMax) * (visibleHeight - bobHeight);
float bobY1 = centerY - h2 + bobOffset;
PPGeDrawRect(415.0f, bobY1, 420.0f, bobY1 + bobHeight, CalcFadedColor(0xFFCCCCCC));

auto buttonDown = [this](int btn, int& held) {
if (IsButtonPressed(btn)) {
held = 0;
return true;
}
return IsButtonHeld(btn, held, 1, 1);
};
if (buttonDown(CTRL_DOWN, framesDownHeld_) && scrollPos_ < scrollMax) {
scrollPos_ = std::min(scrollMax, scrollPos_ + scrollSpeed);
}
if (buttonDown(CTRL_UP, framesUpHeld_) && scrollPos_ > 0.0f) {
scrollPos_ = std::max(0.0f, scrollPos_ - scrollSpeed);
}
}

PPGeDrawRect(60.0f, sy, 420.0f, sy + 1.0f, CalcFadedColor(0xFFFFFFFF));
PPGeDrawRect(60.0f, ey, 420.0f, ey + 1.0f, CalcFadedColor(0xFFFFFFFF));
}
25 changes: 14 additions & 11 deletions Core/Dialog/PSPDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,17 @@ struct pspUtilityDialogCommon
s32_le reserved[4]; /** Set to 0 */
};


class PSPDialog
{
class PSPDialog {
public:
PSPDialog(UtilityDialogType type);
virtual ~PSPDialog();
PSPDialog(UtilityDialogType type) : dialogType_(type) {}
virtual ~PSPDialog() {}

virtual int Update(int animSpeed) = 0;
virtual int Shutdown(bool force = false);
virtual void DoState(PointerWrap &p);
virtual pspUtilityDialogCommon *GetCommonParam();

enum DialogStatus
{
enum DialogStatus {
SCE_UTILITY_STATUS_NONE = 0,
SCE_UTILITY_STATUS_INITIALIZE = 1,
SCE_UTILITY_STATUS_RUNNING = 2,
Expand All @@ -70,8 +67,7 @@ class PSPDialog
SCE_UTILITY_STATUS_SCREENSHOT_UNKNOWN = 5,
};

enum DialogStockButton
{
enum DialogStockButton {
DS_BUTTON_NONE = 0x00,
DS_BUTTON_OK = 0x01,
DS_BUTTON_CANCEL = 0x02,
Expand All @@ -98,6 +94,7 @@ class PSPDialog
bool IsButtonHeld(int checkButton, int &framesHeld, int framesHeldThreshold = 30, int framesHeldRepeatRate = 10);
// The caption override is assumed to have a size of 64 bytes.
void DisplayButtons(int flags, std::string_view caption = "");
void DisplayMessage2(std::string_view text1, std::string_view text2a = "", std::string_view text2b = "", std::string_view text3a = "", std::string_view text3b = "", bool hasYesNo = false, bool hasOK = false);
void ChangeStatus(DialogStatus newStatus, int delayUs);
void ChangeStatusInit(int delayUs);
void ChangeStatusShutdown(int delayUs);
Expand Down Expand Up @@ -129,8 +126,14 @@ class PSPDialog

ImageID okButtonImg;
ImageID cancelButtonImg;
int okButtonFlag;
int cancelButtonFlag;
int okButtonFlag = 0;
int cancelButtonFlag = 0;

// DisplayMessage2 variables
int yesnoChoice = 0;
float scrollPos_ = 0.0f;
int framesUpHeld_ = 0;
int framesDownHeld_ = 0;

private:
DialogStatus status = SCE_UTILITY_STATUS_NONE;
Expand Down
7 changes: 1 addition & 6 deletions Core/Dialog/PSPMsgDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ class PSPMsgDialog: public PSPDialog {
void FormatErrorCode(uint32_t code);
void DisplayMessage(const std::string &text, bool hasYesNo = false, bool hasOK = false);

enum Flags
{
enum Flags {
DS_MSG = 0x1,
DS_ERRORMSG = 0x2,
DS_YESNO = 0x4,
Expand All @@ -98,9 +97,5 @@ class PSPMsgDialog: public PSPDialog {
int messageDialogAddr = 0;

char msgText[512];
int yesnoChoice = 0;
float scrollPos_ = 0.0f;
int framesUpHeld_ = 0;
int framesDownHeld_ = 0;
};

Loading
Loading