mirror of
https://github.com/RGBCube/serenity
synced 2025-05-23 18:35:07 +00:00
IRCClient: Connect to IRC server URL specified in command line argument
The IRCClient application can now connect to a specified IRC server using a URL with `irc://` protocol as a command line argument.
This commit is contained in:
parent
c3b2bfabfe
commit
3c9693c6c7
5 changed files with 39 additions and 10 deletions
|
@ -49,8 +49,8 @@ IRCAppWindow& IRCAppWindow::the()
|
||||||
return *s_the;
|
return *s_the;
|
||||||
}
|
}
|
||||||
|
|
||||||
IRCAppWindow::IRCAppWindow()
|
IRCAppWindow::IRCAppWindow(String server, int port)
|
||||||
: m_client(IRCClient::construct())
|
: m_client(IRCClient::construct(server, port))
|
||||||
{
|
{
|
||||||
ASSERT(!s_the);
|
ASSERT(!s_the);
|
||||||
s_the = this;
|
s_the = this;
|
||||||
|
|
|
@ -41,7 +41,7 @@ public:
|
||||||
void set_active_window(IRCWindow&);
|
void set_active_window(IRCWindow&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IRCAppWindow();
|
IRCAppWindow(String server, int port);
|
||||||
|
|
||||||
void setup_client();
|
void setup_client();
|
||||||
void setup_actions();
|
void setup_actions();
|
||||||
|
|
|
@ -67,7 +67,7 @@ enum IRCNumeric {
|
||||||
ERR_NICKNAMEINUSE = 433,
|
ERR_NICKNAMEINUSE = 433,
|
||||||
};
|
};
|
||||||
|
|
||||||
IRCClient::IRCClient()
|
IRCClient::IRCClient(String server, int port)
|
||||||
: m_nickname("seren1ty")
|
: m_nickname("seren1ty")
|
||||||
, m_client_window_list_model(IRCWindowListModel::create(*this))
|
, m_client_window_list_model(IRCWindowListModel::create(*this))
|
||||||
, m_log(IRCLogBuffer::create())
|
, m_log(IRCLogBuffer::create())
|
||||||
|
@ -76,8 +76,14 @@ IRCClient::IRCClient()
|
||||||
struct passwd* user_pw = getpwuid(getuid());
|
struct passwd* user_pw = getpwuid(getuid());
|
||||||
m_socket = Core::TCPSocket::construct(this);
|
m_socket = Core::TCPSocket::construct(this);
|
||||||
m_nickname = m_config->read_entry("User", "Nickname", String::format("%s_seren1ty", user_pw->pw_name));
|
m_nickname = m_config->read_entry("User", "Nickname", String::format("%s_seren1ty", user_pw->pw_name));
|
||||||
m_hostname = m_config->read_entry("Connection", "Server", "");
|
|
||||||
m_port = m_config->read_num_entry("Connection", "Port", 6667);
|
if (server.is_empty()) {
|
||||||
|
m_hostname = m_config->read_entry("Connection", "Server", "");
|
||||||
|
m_port = m_config->read_num_entry("Connection", "Port", 6667);
|
||||||
|
} else {
|
||||||
|
m_hostname = server;
|
||||||
|
m_port = port ? port : 6667;
|
||||||
|
}
|
||||||
|
|
||||||
m_show_join_part_messages = m_config->read_bool_entry("Messaging", "ShowJoinPartMessages", 1);
|
m_show_join_part_messages = m_config->read_bool_entry("Messaging", "ShowJoinPartMessages", 1);
|
||||||
m_show_nick_change_messages = m_config->read_bool_entry("Messaging", "ShowNickChangeMessages", 1);
|
m_show_nick_change_messages = m_config->read_bool_entry("Messaging", "ShowNickChangeMessages", 1);
|
||||||
|
|
|
@ -138,7 +138,7 @@ public:
|
||||||
void add_server_message(const String&, Color = Color::Black);
|
void add_server_message(const String&, Color = Color::Black);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IRCClient();
|
IRCClient(String server, int port);
|
||||||
|
|
||||||
struct Message {
|
struct Message {
|
||||||
String prefix;
|
String prefix;
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if (pledge("stdio inet dns unix shared_buffer cpath rpath fattr", nullptr) < 0) {
|
if (pledge("stdio inet dns unix shared_buffer cpath rpath fattr wpath cpath", nullptr) < 0) {
|
||||||
perror("pledge");
|
perror("pledge");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -44,12 +44,35 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
GUI::Application app(argc, argv);
|
GUI::Application app(argc, argv);
|
||||||
|
|
||||||
if (pledge("stdio inet dns unix shared_buffer rpath", nullptr) < 0) {
|
if (pledge("stdio inet dns unix shared_buffer rpath wpath cpath", nullptr) < 0) {
|
||||||
perror("pledge");
|
perror("pledge");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto app_window = IRCAppWindow::construct();
|
URL url = "";
|
||||||
|
if (app.args().size() >= 1) {
|
||||||
|
url = URL::create_with_url_or_path(app.args()[0]);
|
||||||
|
|
||||||
|
if (url.protocol().to_lowercase() == "ircs") {
|
||||||
|
fprintf(stderr, "Secure IRC over SSL/TLS (ircs) is not supported\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url.protocol().to_lowercase() != "irc") {
|
||||||
|
fprintf(stderr, "Unsupported protocol\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url.host().is_empty()) {
|
||||||
|
fprintf(stderr, "Invalid URL\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!url.port() || url.port() == 80)
|
||||||
|
url.set_port(6667);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto app_window = IRCAppWindow::construct(url.host(), url.port());
|
||||||
app_window->show();
|
app_window->show();
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue