• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Return-To-The-Roots / s25client / 22518049176

28 Feb 2026 09:27AM UTC coverage: 50.149%. First build
22518049176

Pull #1890

github

web-flow
Merge 0b97c9676 into 8a6c9b6f2
Pull Request #1890: Add support for borderless Windows

155 of 626 new or added lines in 44 files covered. (24.76%)

23038 of 45939 relevant lines covered (50.15%)

42060.08 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.75
/libs/s25main/ingameWindows/iwDirectIPConnect.cpp
1
// Copyright (C) 2005 - 2026 Settlers Freaks (sf-team at siedler25.org)
2
//
3
// SPDX-License-Identifier: GPL-2.0-or-later
4

5
#include "iwDirectIPConnect.h"
6
#include "Loader.h"
7
#include "RttrLobbyClient.hpp"
8
#include "Settings.h"
9
#include "WindowManager.h"
10
#include "controls/ctrlButton.h"
11
#include "controls/ctrlEdit.h"
12
#include "controls/ctrlOptionGroup.h"
13
#include "controls/ctrlText.h"
14
#include "drivers/VideoDriverWrapper.h"
15
#include "iwConnecting.h"
16
#include "network/GameClient.h"
17
#include "ogl/FontStyle.h"
18
#include "gameData/const_gui_ids.h"
19
#include "liblobby/LobbyClient.h"
20
#include "s25util/StringConversion.h"
21
#include "s25util/colors.h"
22

23
namespace {
24
enum : unsigned
25
{
26
    ID_txtIp,
27
    ID_edtIp,
28
    ID_txtPort,
29
    ID_edtPort,
30
    ID_txtPw,
31
    ID_edtPw,
32
    ID_txtIpv6,
33
    ID_grpIpv6,
34
    ID_txtStatus,
35
    ID_btConnect,
36
    ID_btBack,
37
};
38
}
39

40
iwDirectIPConnect::iwDirectIPConnect(ServerType serverType)
1✔
41
    : IngameWindow(CGI_DIRECTIPCONNECT, IngameWindow::posLastOrCenter, Extent(300, 285), _("Join Game"),
1✔
42
                   LOADER.GetImageN("resource", 41), true),
1✔
43
      serverType_(serverType)
3✔
44
{
45
    AddText(ID_txtIp, DrawPoint(20, 30), _("IP Address of Host:"), COLOR_YELLOW, FontStyle{}, NormalFont);
1✔
46
    ctrlEdit* host = AddEdit(ID_edtIp, DrawPoint(20, 45), Extent(260, 22), TextureColor::Green2, NormalFont, 0, false,
1✔
47
                             (serverType != ServerType::Direct), true);
48

49
    AddText(ID_txtPort, DrawPoint(20, 80), _("Server-Port:"), COLOR_YELLOW, FontStyle{}, NormalFont);
1✔
50
    ctrlEdit* port = AddEdit(ID_edtPort, DrawPoint(20, 95), Extent(260, 22), TextureColor::Green2, NormalFont, 0, false,
1✔
51
                             (serverType != ServerType::Direct), true);
52

53
    AddText(ID_txtPw, DrawPoint(20, 130), _("Password (if needed):"), COLOR_YELLOW, FontStyle{}, NormalFont);
1✔
54
    AddEdit(ID_edtPw, DrawPoint(20, 145), Extent(260, 22), TextureColor::Green2, NormalFont, 0, false, false, true);
1✔
55

56
    AddText(ID_txtIpv6, DrawPoint(20, 185), _("Use IPv6:"), COLOR_YELLOW, FontStyle{}, NormalFont);
1✔
57

58
    ctrlOptionGroup* ipv6 = AddOptionGroup(ID_grpIpv6, GroupSelectType::Check);
1✔
59
    ipv6->AddTextButton(0, DrawPoint(120, 180), Extent(75, 22), TextureColor::Green2, _("IPv4"), NormalFont);
1✔
60
    ipv6->AddTextButton(1, DrawPoint(205, 180), Extent(75, 22), TextureColor::Green2, _("IPv6"), NormalFont);
1✔
61
    ipv6->SetSelection((SETTINGS.server.ipv6 ? 1 : 0));
1✔
62

63
    AddText(ID_txtStatus, DrawPoint(150, 215), "", COLOR_RED, FontStyle::CENTER, NormalFont);
1✔
64
    AddTextButton(ID_btConnect, DrawPoint(20, 240), Extent(125, 22), TextureColor::Green2, _("Connect"), NormalFont);
1✔
65
    AddTextButton(ID_btBack, DrawPoint(155, 240), Extent(125, 22), TextureColor::Red1, _("Back"), NormalFont);
1✔
66

67
    host->SetFocus();
1✔
68
    host->SetText(SETTINGS.server.lastIP);
1✔
69
    port->SetText(SETTINGS.server.localPort);
1✔
70
}
1✔
71

72
void iwDirectIPConnect::Msg_EditChange(const unsigned /*ctrl_id*/)
4✔
73
{
74
    // Reset status
75
    SetStatus("", COLOR_RED);
4✔
76
}
4✔
77

78
void iwDirectIPConnect::Msg_EditEnter(const unsigned ctrl_id)
×
79
{
80
    switch(ctrl_id)
×
81
    {
82
        case ID_edtIp: GetCtrl<ctrlEdit>(ID_edtPort)->SetFocus(true); break;
×
83
        case ID_edtPort: GetCtrl<ctrlEdit>(ID_edtPw)->SetFocus(true); break;
×
84
        case ID_edtPw: GetCtrl<ctrlEdit>(ID_btConnect)->SetFocus(true); break;
×
85
    }
86
}
×
87

88
void iwDirectIPConnect::Msg_ButtonClick(const unsigned ctrl_id)
×
89
{
90
    switch(ctrl_id)
×
91
    {
92
        case ID_btConnect:
×
93
        {
94
            auto* edtHost = GetCtrl<ctrlEdit>(ID_edtIp);
×
95
            auto* edtPort = GetCtrl<ctrlEdit>(ID_edtPort);
×
96
            auto* edtPw = GetCtrl<ctrlEdit>(ID_edtPw);
×
97
            boost::optional<uint16_t> port = validate::checkPort(edtPort->GetText());
×
98
            if(!port)
×
99
            {
100
                SetStatus(_("Invalid port. The valid port-range is 1 to 65535!"), COLOR_RED);
×
101
                edtHost->SetFocus(false);
×
102
                edtPort->SetFocus(true);
×
103
                edtPw->SetFocus(false);
×
104
                break;
×
105
            }
106

107
            // save settings
NEW
108
            SETTINGS.server.lastIP = edtHost->GetText();
×
109

110
            if(!GAMECLIENT.Connect(edtHost->GetText(), edtPw->GetText(), serverType_, *port, false,
×
111
                                   SETTINGS.server.ipv6))
×
112
            {
113
                SetStatus(_("Connection failed!"), COLOR_RED);
×
114
            } else
115
            {
116
                SetStatus(_("Connecting with Host..."), COLOR_YELLOW);
×
117
                GetCtrl<ctrlButton>(ID_btConnect)->SetEnabled(false);
×
118
                std::unique_ptr<ILobbyClient> lobbyClient;
×
119
                if(serverType_ == ServerType::Lobby)
×
120
                    lobbyClient = std::make_unique<RttrLobbyClient>(LOBBYCLIENT);
×
121
                iwConnecting& wnd =
122
                  WINDOWMANAGER.Show(std::make_unique<iwConnecting>(serverType_, std::move(lobbyClient)));
×
123
                onErrorConnection_ = wnd.onError.connect([this](ClientError error) {
×
124
                    SetStatus(ClientErrorToStr(error), COLOR_RED);
×
125
                    this->GetCtrl<ctrlButton>(ID_btConnect)->SetEnabled();
×
126
                });
×
127
            }
128
        }
129
        break;
×
130
        case ID_btBack: Close(); break;
×
131
    }
132
}
×
133

134
void iwDirectIPConnect::Msg_OptionGroupChange(const unsigned ctrl_id, const unsigned selection)
1✔
135
{
136
    if(ctrl_id == ID_grpIpv6)
1✔
137
        SETTINGS.server.ipv6 = (selection == 1);
1✔
138
}
1✔
139

140
void iwDirectIPConnect::SetStatus(const std::string& text, unsigned color)
4✔
141
{
142
    auto* txtStatus = GetCtrl<ctrlText>(ID_txtStatus);
4✔
143
    txtStatus->SetTextColor(color);
4✔
144
    txtStatus->SetText(text);
4✔
145
}
4✔
146

147
void iwDirectIPConnect::Connect(const std::string& hostOrIp, const unsigned short port, const bool isIPv6,
1✔
148
                                const bool hasPwd)
149
{
150
    GetCtrl<ctrlEdit>(ID_edtIp)->SetText(hostOrIp);
1✔
151
    GetCtrl<ctrlEdit>(ID_edtPort)->SetText(s25util::toStringClassic(port));
1✔
152
    GetCtrl<ctrlOptionGroup>(ID_grpIpv6)->SetSelection(isIPv6 ? 1 : 0, true);
1✔
153
    auto* btConnect = GetCtrl<ctrlButton>(ID_btConnect);
1✔
154
    VIDEODRIVER.SetMousePos(btConnect->GetDrawPos() + DrawPoint(btConnect->GetSize()) / 2);
1✔
155
    if(hasPwd)
1✔
156
        GetCtrl<ctrlEdit>(ID_edtPw)->SetFocus(true);
1✔
157
    else
158
        Msg_ButtonClick(ID_btConnect);
×
159
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc