From 2844eecb65501f7dafa4de15d7377bfb810e1158 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 18 Dec 2024 13:36:52 -0500 Subject: Make IPC opt-in and configurable --- src/tracker_frame.cpp | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'src/tracker_frame.cpp') diff --git a/src/tracker_frame.cpp b/src/tracker_frame.cpp index d0fd5a6..587d87b 100644 --- a/src/tracker_frame.cpp +++ b/src/tracker_frame.cpp @@ -14,6 +14,7 @@ #include "achievements_pane.h" #include "ap_state.h" #include "connection_dialog.h" +#include "ipc_dialog.h" #include "ipc_state.h" #include "settings_dialog.h" #include "subway_map.h" @@ -38,18 +39,20 @@ std::string GetStatusMessage() { } // namespace enum TrackerFrameIds { - ID_CONNECT = 1, + ID_AP_CONNECT = 1, ID_CHECK_FOR_UPDATES = 2, ID_SETTINGS = 3, ID_ZOOM_IN = 4, ID_ZOOM_OUT = 5, ID_OPEN_SAVE_FILE = 6, + ID_IPC_CONNECT = 7, }; wxDEFINE_EVENT(STATE_RESET, wxCommandEvent); wxDEFINE_EVENT(STATE_CHANGED, wxCommandEvent); wxDEFINE_EVENT(STATUS_CHANGED, wxCommandEvent); wxDEFINE_EVENT(REDRAW_POSITION, wxCommandEvent); +wxDEFINE_EVENT(CONNECT_TO_AP, ApConnectEvent); TrackerFrame::TrackerFrame() : wxFrame(nullptr, wxID_ANY, "Lingo Archipelago Tracker", wxDefaultPosition, @@ -57,9 +60,11 @@ TrackerFrame::TrackerFrame() ::wxInitAllImageHandlers(); AP_SetTrackerFrame(this); + IPC_SetTrackerFrame(this); wxMenu *menuFile = new wxMenu(); - menuFile->Append(ID_CONNECT, "&Connect"); + menuFile->Append(ID_AP_CONNECT, "&Connect to Archipelago"); + menuFile->Append(ID_IPC_CONNECT, "&Connect to Lingo"); menuFile->Append(ID_OPEN_SAVE_FILE, "&Open Save Data\tCtrl-O"); menuFile->Append(ID_SETTINGS, "&Settings"); menuFile->Append(wxID_EXIT); @@ -86,7 +91,8 @@ TrackerFrame::TrackerFrame() Bind(wxEVT_MENU, &TrackerFrame::OnAbout, this, wxID_ABOUT); Bind(wxEVT_MENU, &TrackerFrame::OnExit, this, wxID_EXIT); - Bind(wxEVT_MENU, &TrackerFrame::OnConnect, this, ID_CONNECT); + Bind(wxEVT_MENU, &TrackerFrame::OnApConnect, this, ID_AP_CONNECT); + Bind(wxEVT_MENU, &TrackerFrame::OnIpcConnect, this, ID_IPC_CONNECT); Bind(wxEVT_MENU, &TrackerFrame::OnSettings, this, ID_SETTINGS); Bind(wxEVT_MENU, &TrackerFrame::OnCheckForUpdates, this, ID_CHECK_FOR_UPDATES); @@ -98,6 +104,7 @@ TrackerFrame::TrackerFrame() Bind(STATE_CHANGED, &TrackerFrame::OnStateChanged, this); Bind(STATUS_CHANGED, &TrackerFrame::OnStatusChanged, this); Bind(REDRAW_POSITION, &TrackerFrame::OnRedrawPosition, this); + Bind(CONNECT_TO_AP, &TrackerFrame::OnConnectToAp, this); wxChoicebook *choicebook = new wxChoicebook(this, wxID_ANY); achievements_pane_ = new AchievementsPane(choicebook); @@ -134,11 +141,15 @@ TrackerFrame::TrackerFrame() CheckForUpdates(/*manual=*/false); } - IPC_Start(this); - SetStatusText(GetStatusMessage()); } +void TrackerFrame::ConnectToAp(std::string server, std::string user, + std::string pass) { + QueueEvent(new ApConnectEvent(CONNECT_TO_AP, GetId(), std::move(server), + std::move(user), std::move(pass))); +} + void TrackerFrame::UpdateStatusMessage() { QueueEvent(new wxCommandEvent(STATUS_CHANGED)); } @@ -172,7 +183,7 @@ void TrackerFrame::OnAbout(wxCommandEvent &event) { void TrackerFrame::OnExit(wxCommandEvent &event) { Close(true); } -void TrackerFrame::OnConnect(wxCommandEvent &event) { +void TrackerFrame::OnApConnect(wxCommandEvent &event) { ConnectionDialog dlg; if (dlg.ShowModal() == wxID_OK) { @@ -202,6 +213,17 @@ void TrackerFrame::OnConnect(wxCommandEvent &event) { } } +void TrackerFrame::OnIpcConnect(wxCommandEvent &event) { + IpcDialog dlg; + + if (dlg.ShowModal() == wxID_OK) { + GetTrackerConfig().ipc_address = dlg.GetIpcAddress(); + GetTrackerConfig().Save(); + + IPC_Connect(dlg.GetIpcAddress()); + } +} + void TrackerFrame::OnSettings(wxCommandEvent &event) { SettingsDialog dlg; @@ -306,6 +328,10 @@ void TrackerFrame::OnRedrawPosition(wxCommandEvent &event) { } } +void TrackerFrame::OnConnectToAp(ApConnectEvent &event) { + AP_Connect(event.GetServer(), event.GetUser(), event.GetPass()); +} + void TrackerFrame::CheckForUpdates(bool manual) { wxWebRequest request = wxWebSession::GetDefault().CreateRequest( this, "https://code.fourisland.com/lingo-ap-tracker/plain/VERSION"); -- cgit 1.4.1