Add a dedicated ShareHostDlg with a "Use Shine protocol" checkbox (default checked) so the operator can choose Shine (0) or HELL (1) when sharing or transferring a host. The chosen protocol is appended to the wire payload as a trailing colon field: "IP:PORT:0/1" for share and "IP:PORT:days:0/1" for transfer. The client parses the trailing field from COMMAND_SHARE and COMMAND_ASSIGN_MASTER, applies it to new connections, and persists it so auto-share/auto-transfer on restart keeps the same protocol. Old clients ignore the extra field, and old/missing payloads fall back to -1 (baked-in HELL), preserving compatibility with existing servers and share_list entries. Co-Authored-By: deepseek-v4-pro
126 lines
3.3 KiB
C++
126 lines
3.3 KiB
C++
// ShareHostDlg.cpp: 分享主机 / 转移主机 专用对话框实现
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "ShareHostDlg.h"
|
|
#include "2015Remote.h"
|
|
#include <algorithm>
|
|
|
|
CShareHostDlg::CShareHostDlg(CWnd* pParent /*=nullptr*/, BOOL bNeedDays /*=FALSE*/)
|
|
: CDialogLangEx(IDD_DIALOG_SHARE_HOST, pParent)
|
|
, m_bNeedDays(bNeedDays)
|
|
, m_bShine(TRUE)
|
|
{
|
|
}
|
|
|
|
CShareHostDlg::~CShareHostDlg()
|
|
{
|
|
}
|
|
|
|
void CShareHostDlg::Init(LPCTSTR caption, LPCTSTR prompt)
|
|
{
|
|
m_sCaption = caption;
|
|
m_sPrompt = prompt;
|
|
}
|
|
|
|
void CShareHostDlg::InitDays(LPCTSTR name, LPCTSTR defaultValue)
|
|
{
|
|
m_sDaysName = name;
|
|
m_sDays = defaultValue;
|
|
}
|
|
|
|
void CShareHostDlg::SetHistoryKey(LPCTSTR historyKey)
|
|
{
|
|
m_sHistoryKey = historyKey;
|
|
}
|
|
|
|
void CShareHostDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialogLangEx::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_EDIT_SHARE_ADDRESS, m_ComboInput);
|
|
DDX_Control(pDX, IDC_STATIC_SHARE_DAYS, m_StaticDays);
|
|
DDX_Control(pDX, IDC_EDIT_SHARE_DAYS, m_EditDays);
|
|
DDX_Control(pDX, IDC_CHECK_USE_SHINE, m_CheckShine);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CShareHostDlg, CDialogLangEx)
|
|
END_MESSAGE_MAP()
|
|
|
|
BOOL CShareHostDlg::OnInitDialog()
|
|
{
|
|
CDialogLangEx::OnInitDialog();
|
|
|
|
SetWindowText(m_sCaption);
|
|
SetDlgItemText(IDC_STATIC_SHARE_ADDRESS, m_sPrompt);
|
|
SetDlgItemText(IDC_CHECK_USE_SHINE, _TR("使用 Shine 协议(兼容 Go 服务端)"));
|
|
SetDlgItemText(IDOK, _TR("确定"));
|
|
SetDlgItemText(IDCANCEL, _TR("取消"));
|
|
|
|
// 天数(仅转移主机显示)
|
|
m_StaticDays.SetWindowTextA(m_sDaysName);
|
|
m_StaticDays.ShowWindow(m_bNeedDays ? SW_SHOW : SW_HIDE);
|
|
m_EditDays.SetWindowTextA(m_sDays);
|
|
m_EditDays.ShowWindow(m_bNeedDays ? SW_SHOW : SW_HIDE);
|
|
|
|
// 默认勾选 Shine
|
|
m_CheckShine.SetCheck(m_bShine ? BST_CHECKED : BST_UNCHECKED);
|
|
|
|
LoadHistory();
|
|
m_ComboInput.SetWindowText(m_str);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CShareHostDlg::OnOK()
|
|
{
|
|
m_ComboInput.GetWindowText(m_str);
|
|
m_bShine = (m_CheckShine.GetCheck() == BST_CHECKED);
|
|
if (m_bNeedDays)
|
|
m_EditDays.GetWindowText(m_sDays);
|
|
|
|
SaveHistory();
|
|
CDialogLangEx::OnOK();
|
|
}
|
|
|
|
void CShareHostDlg::LoadHistory()
|
|
{
|
|
if (m_sHistoryKey.IsEmpty()) return;
|
|
|
|
std::string history = THIS_CFG.GetStr("history", m_sHistoryKey.GetString());
|
|
if (history.empty()) return;
|
|
|
|
auto items = StringToVector(history, '|');
|
|
for (size_t i = 0; i < items.size() && i < 16; i++) {
|
|
if (!items[i].empty()) {
|
|
m_ComboInput.AddString(items[i].c_str());
|
|
}
|
|
}
|
|
}
|
|
|
|
void CShareHostDlg::SaveHistory()
|
|
{
|
|
if (m_sHistoryKey.IsEmpty() || m_str.IsEmpty()) return;
|
|
|
|
std::string newValue = m_str.GetString();
|
|
if (newValue.find('|') != std::string::npos) return;
|
|
|
|
std::string history = THIS_CFG.GetStr("history", m_sHistoryKey.GetString());
|
|
auto items = StringToVector(history, '|');
|
|
|
|
items.erase(std::remove(items.begin(), items.end(), newValue), items.end());
|
|
items.erase(std::remove(items.begin(), items.end(), std::string("")), items.end());
|
|
|
|
items.insert(items.begin(), newValue);
|
|
|
|
if (items.size() > 16) {
|
|
items.resize(16);
|
|
}
|
|
|
|
std::string result;
|
|
for (size_t i = 0; i < items.size(); i++) {
|
|
if (i > 0) result += '|';
|
|
result += items[i];
|
|
}
|
|
THIS_CFG.SetStr("history", m_sHistoryKey.GetString(), result);
|
|
}
|