fix(server): keep the build dialog's default protocol at TCP
Commit 46f4bf2 swapped InsertString for AddString on IDC_COMBO_PROTO while
attaching protocol values as item data. That combo carries CBS_SORT, and the two
messages differ there: CB_ADDSTRING inserts in alphabetical order and returns
the sorted position, while CB_INSERTSTRING ignores CBS_SORT entirely. The list
went from TCP/UDP/HTTP/random/KCP/WebSocket/WS+TLS to HTTP/KCP/TCP/UDP/...,
so SetCurSel(0) landed on HTTP and every newly opened build dialog defaulted to
the wrong protocol.
Revert both hunks of that commit for this dialog. The items are appended with
InsertStringL like every other combo on the form, and OnBnClickedOk reads
GetCurSel() again: with no item data attached GetItemData returns 0 for every
row, so the previous guard (0 != CB_ERR) would have written TCP no matter what
the user picked. PROTO_TCP..PROTO_WSS are 0..6 without gaps and PROTO_HTTPS
sits outside the list, so the index still equals the protocol value.
Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
389de9d456
commit
6a3d536d38
1 file changed
+12
-25
@@ -542,14 +542,7 @@ void CBuildDlg::OnBnClickedOk()
|
||||
g_ConnectAddress.SetAdminId(GetMasterHash().c_str());
|
||||
g_ConnectAddress.SetServer(m_strIP, atoi(m_strPort));
|
||||
g_ConnectAddress.runningType = m_ComboRunType.GetCurSel();
|
||||
// 协议值取自 item data(见 OnInitDialog 里的 addProto)。取不到时退回序号,保持旧行为。
|
||||
int protoSel = m_ComboProto.GetCurSel();
|
||||
if (protoSel >= 0) {
|
||||
DWORD_PTR protoData = m_ComboProto.GetItemData(protoSel);
|
||||
if (protoData != (DWORD_PTR)CB_ERR)
|
||||
protoSel = (int)protoData;
|
||||
}
|
||||
g_ConnectAddress.protoType = protoSel;
|
||||
g_ConnectAddress.protoType = m_ComboProto.GetCurSel();
|
||||
g_ConnectAddress.iHeaderEnc = m_ComboEncrypt.GetCurSel();
|
||||
memcpy(g_ConnectAddress.pwdHash, GetPwdHash().c_str(), sizeof(g_ConnectAddress.pwdHash));
|
||||
memcpy(g_ConnectAddress.szGroupName, m_sGroupName, m_sGroupName.GetLength());
|
||||
@@ -844,23 +837,17 @@ BOOL CBuildDlg::OnInitDialog()
|
||||
m_ComboRunType.InsertStringL(RUNNING_PARALLEL, "并发上线");
|
||||
m_ComboRunType.SetCurSel(RUNNING_RANDOM);
|
||||
|
||||
// 协议值挂在 item data 上,不再依赖「下拉框序号 == protoType」。两者目前确实相等,
|
||||
// 但只要以后有 PROTO_* 常量没进这个下拉框(PROTO_HTTPS 就已经是这种情况),
|
||||
// 后加项序号与协议值就会错位,而错误的值只会在客户端连不上时才暴露。
|
||||
auto addProto = [this](int proto, LPCSTR text) {
|
||||
// AddString 追加到末尾并返回新条目下标;用它定位,不依赖任何「下标 == 枚举值」约定。
|
||||
int idx = m_ComboProto.AddStringL(text);
|
||||
if (idx >= 0)
|
||||
m_ComboProto.SetItemData(idx, (DWORD_PTR)proto);
|
||||
};
|
||||
addProto(PROTO_TCP, "TCP");
|
||||
addProto(PROTO_UDP, "UDP");
|
||||
addProto(PROTO_HTTP, "HTTP");
|
||||
addProto(PROTO_RANDOM, "随机");
|
||||
addProto(PROTO_KCP, "KCP");
|
||||
addProto(PROTO_WS, "WebSocket");
|
||||
addProto(PROTO_WSS, "WS+TLS");
|
||||
m_ComboProto.SetCurSel(0);
|
||||
m_ComboProto.InsertStringL(PROTO_TCP, "TCP");
|
||||
m_ComboProto.InsertStringL(PROTO_UDP, "UDP");
|
||||
m_ComboProto.InsertStringL(PROTO_HTTP, "HTTP");
|
||||
m_ComboProto.InsertStringL(PROTO_RANDOM, "随机");
|
||||
m_ComboProto.InsertStringL(PROTO_KCP, "KCP");
|
||||
// 序号即 protoType,中间不能有空洞(下方 GetCurSel 直接当协议值用)。
|
||||
// 该下拉框资源带 CBS_SORT 样式:InsertString 不受它影响,能保持这里的顺序,
|
||||
// 换成 AddString 会按字母序重排,HTTP 抢到第 0 项,默认协议就错了。
|
||||
m_ComboProto.InsertStringL(PROTO_WS, "WebSocket");
|
||||
m_ComboProto.InsertStringL(PROTO_WSS, "WS+TLS");
|
||||
m_ComboProto.SetCurSel(PROTO_TCP);
|
||||
|
||||
m_ComboEncrypt.InsertStringL(PROTOCOL_SHINE, "Shine");
|
||||
m_ComboEncrypt.InsertStringL(PROTOCOL_HELL, "HELL");
|
||||
|
||||
Reference in new issue
Block a user