The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
chat_command_handler.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 - 2025
3 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY.
11
12 See the COPYING file for more details.
13*/
14
16
17#include "chat_events.hpp"
19#include "game_version.hpp"
24
25namespace events {
26
31
32void chat_command_handler::print(const std::string& title, const std::string& message)
33{
34 chat_handler_.add_chat_message(std::chrono::system_clock::now(), title, 0, message);
35}
36
41
46
51
57
65
70
72{
73 if (get_arg(1).empty()) {
74 do_display();
75 }
76 else {
78 symbols["nick"] = get_arg(1);
79
80 if (prefs::get().add_acquaintance(get_arg(1), "ignore", get_data(2)).first) {
81 print(_("ignores list"), VGETTEXT("Added to ignore list: $nick", symbols));
83 }
84 else {
85 command_failed(VGETTEXT("Invalid username: $nick", symbols));
86 }
87 }
88}
89
91{
92 if (get_arg(1).empty()) {
93 do_display();
94 }
95 else {
97 symbols["nick"] = get_arg(1);
98
99 if (prefs::get().add_acquaintance(get_arg(1), "friend", get_data(2)).first) {
100 print(_("friends list"), VGETTEXT("Added to friends list: $nick", symbols));
102 }
103 else {
104 command_failed(VGETTEXT("Invalid username: $nick", symbols));
105 }
106 }
107}
108
110{
111 for (int i = 1;!get_arg(i).empty();i++) {
112 prefs::get().remove_acquaintance(get_arg(i));
115 symbols["nick"] = get_arg(i);
116 print(_("friends and ignores list"), VGETTEXT("Removed from list: $nick", symbols));
117 }
118}
119
121{
122 gui2::dialogs::preferences_dialog::display(pref_constants::VIEW_FRIENDS);
123}
124
128
130 if (get_data(1).empty()) return command_failed_need_arg(1);
131
133 symbols["nick"] = get_arg(1);
134 print(_("nick registration"), VGETTEXT("requesting information for user $nick", symbols));
135
136 chat_handler_.send_to_server(config{"nickserv", config{"info", config{"name", get_data(1)}}});
137}
138
142
144 std::string report_text;
145 gui2::dialogs::mp_report::execute(report_text);
146
147 if(!report_text.empty()) {
148 do_network_send(report_text);
149 }
150}
151
152}
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
void do_info()
Request information about a user from the server.
map_command_handler< chat_command_handler > map
bool is_enabled(const map_command_handler< chat_command_handler >::command &c) const
void print(const std::string &title, const std::string &message)
virtual void add_chat_message(const std::chrono::system_clock::time_point &time, const std::string &speaker, int side, const std::string &message, MESSAGE_TYPE type=MESSAGE_PRIVATE)=0
virtual void clear_messages()=0
virtual void user_relation_changed(const std::string &name)
Called when a processed command results in a relation (friend/ignore) change for a user whose name is...
virtual void add_whisper_sent(const std::string &receiver, const std::string &message)
void change_logging(const std::string &data)
Change the log level of a log domain.
virtual void send_chat_message(const std::string &message, bool allies_only=false)=0
virtual void send_whisper(const std::string &receiver, const std::string &message)
virtual void send_to_server(const config &cfg)=0
void send_command(const std::string &cmd, const std::string &args="")
virtual std::string get_arg(unsigned argn) const
virtual std::string get_data(unsigned argn=1) const
void command_failed(const std::string &message, bool=false)
static prefs & get()
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
Interfaces for manipulating version numbers of engine, add-ons, etc.
static std::string _(const char *str)
Definition gettext.hpp:100
Handling of system events.
const std::string revision
bool logged_in_as_moderator()
Gets whether the currently logged-in user is a moderator.
std::map< std::string, t_string > string_map
std::string_view data
Definition picture.cpp:188
#define i
#define c