mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Merge pull request #3776 from IntelOrca/feature/chatlogs
Save chat logs
This commit is contained in:
@@ -4173,6 +4173,8 @@ STR_5861 :Key verification failure.
|
||||
STR_5862 :Block unknown players.
|
||||
STR_5863 :{SMALLFONT}{BLACK}Only allow players with known keys to join.
|
||||
STR_5864 :This server only allows whitelisted players to connect.
|
||||
STR_5865 :Log chat history
|
||||
STR_5866 :{SMALLFONT}{BLACK}Logs all chat history to files in your user directory.
|
||||
|
||||
#############
|
||||
# Scenarios #
|
||||
|
||||
@@ -254,6 +254,7 @@ config_property_definition _networkDefinitions[] = {
|
||||
{ offsetof(network_configuration, provider_email), "provider_email", CONFIG_VALUE_TYPE_STRING, {.value_string = NULL }, NULL },
|
||||
{ offsetof(network_configuration, provider_website), "provider_website", CONFIG_VALUE_TYPE_STRING, {.value_string = NULL }, NULL },
|
||||
{ offsetof(network_configuration, known_keys_only), "known_keys_only", CONFIG_VALUE_TYPE_BOOLEAN, false, NULL },
|
||||
{ offsetof(network_configuration, log_chat), "log_chat", CONFIG_VALUE_TYPE_BOOLEAN, false, NULL },
|
||||
};
|
||||
|
||||
config_property_definition _notificationsDefinitions[] = {
|
||||
|
||||
@@ -230,6 +230,7 @@ typedef struct network_configuration {
|
||||
utf8string provider_email;
|
||||
utf8string provider_website;
|
||||
uint8 known_keys_only;
|
||||
uint8 log_chat;
|
||||
} network_configuration;
|
||||
|
||||
typedef struct notification_configuration {
|
||||
|
||||
@@ -125,6 +125,7 @@ void chat_history_add(const char *src)
|
||||
_chatHistoryTime[index] = SDL_GetTicks();
|
||||
_chatHistoryIndex++;
|
||||
Mixer_Play_Effect(SOUND_NEWS_ITEM, 0, SDL_MIX_MAXVOLUME, 0, 1.5f, true);
|
||||
network_append_chat_log(src);
|
||||
}
|
||||
|
||||
void chat_input(int c)
|
||||
|
||||
@@ -2637,6 +2637,8 @@ enum {
|
||||
STR_ALLOW_KNOWN_KEYS_ONLY = 5862,
|
||||
STR_ALLOW_KNOWN_KEYS_ONLY_TIP = 5863,
|
||||
STR_MULTIPLAYER_UNKNOWN_KEY_DISALLOWED = 5864,
|
||||
STR_LOG_CHAT = 5865,
|
||||
STR_LOG_CHAT_TIP = 5866,
|
||||
|
||||
// Have to include resource strings (from scenarios and objects) for the time being now that language is partially working
|
||||
STR_COUNT = 32768
|
||||
|
||||
@@ -178,6 +178,7 @@ void Network::Close()
|
||||
}
|
||||
#endif
|
||||
|
||||
CloseChatLog();
|
||||
gfx_invalidate_screen();
|
||||
}
|
||||
|
||||
@@ -200,6 +201,8 @@ bool Network::BeginClient(const char* host, unsigned short port)
|
||||
gNetwork.Close();
|
||||
});
|
||||
|
||||
BeginChatLog();
|
||||
|
||||
mode = NETWORK_MODE_CLIENT;
|
||||
utf8 keyPath[MAX_PATH];
|
||||
network_get_private_key_path(keyPath, sizeof(keyPath), gConfigNetwork.player_name);
|
||||
@@ -302,6 +305,7 @@ bool Network::BeginServer(unsigned short port, const char* address)
|
||||
|
||||
cheats_reset();
|
||||
LoadGroups();
|
||||
BeginChatLog();
|
||||
|
||||
NetworkPlayer *player = AddPlayer(gConfigNetwork.player_name, "");
|
||||
player->flags |= NETWORK_PLAYER_FLAG_ISSERVER;
|
||||
@@ -325,6 +329,7 @@ bool Network::BeginServer(unsigned short port, const char* address)
|
||||
advertise_status = ADVERTISE_STATUS_UNREGISTERED;
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -921,6 +926,57 @@ void Network::LoadGroups()
|
||||
json_decref(json);
|
||||
}
|
||||
|
||||
void Network::BeginChatLog()
|
||||
{
|
||||
utf8 filename[32];
|
||||
time_t timer;
|
||||
struct tm * tmInfo;
|
||||
time(&timer);
|
||||
tmInfo = localtime(&timer);
|
||||
strftime(filename, sizeof(filename), "%Y%m%d-%H%M%S.txt", tmInfo);
|
||||
|
||||
utf8 path[MAX_PATH];
|
||||
platform_get_user_directory(path, "chatlogs");
|
||||
Path::Append(path, sizeof(path), filename);
|
||||
|
||||
_chatLogPath = std::string(path);
|
||||
}
|
||||
|
||||
void Network::AppendChatLog(const utf8 *text)
|
||||
{
|
||||
if (!gConfigNetwork.log_chat) {
|
||||
return;
|
||||
}
|
||||
|
||||
const utf8 *chatLogPath = _chatLogPath.c_str();
|
||||
|
||||
utf8 directory[MAX_PATH];
|
||||
Path::GetDirectory(directory, sizeof(directory), chatLogPath);
|
||||
if (platform_ensure_directory_exists(directory)) {
|
||||
_chatLogStream = SDL_RWFromFile(chatLogPath, "a");
|
||||
if (_chatLogStream != nullptr) {
|
||||
utf8 buffer[256];
|
||||
|
||||
time_t timer;
|
||||
struct tm * tmInfo;
|
||||
time(&timer);
|
||||
tmInfo = localtime(&timer);
|
||||
strftime(buffer, sizeof(buffer), "[%Y/%m/%d %H:%M:%S] ", tmInfo);
|
||||
|
||||
String::Append(buffer, sizeof(buffer), text);
|
||||
utf8_remove_formatting(buffer);
|
||||
String::Append(buffer, sizeof(buffer), platform_get_new_line());
|
||||
|
||||
SDL_RWwrite(_chatLogStream, buffer, strlen(buffer), 1);
|
||||
SDL_RWclose(_chatLogStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Network::CloseChatLog()
|
||||
{
|
||||
}
|
||||
|
||||
void Network::Client_Send_TOKEN()
|
||||
{
|
||||
log_verbose("requesting token");
|
||||
@@ -2306,6 +2362,11 @@ void network_set_password(const char* password)
|
||||
gNetwork.SetPassword(password);
|
||||
}
|
||||
|
||||
void network_append_chat_log(const utf8 *text)
|
||||
{
|
||||
gNetwork.AppendChatLog(text);
|
||||
}
|
||||
|
||||
static void network_get_keys_directory(utf8 *buffer, size_t bufferSize)
|
||||
{
|
||||
platform_get_user_directory(buffer, "keys");
|
||||
@@ -2379,4 +2440,5 @@ void network_shutdown_client() {}
|
||||
void network_set_password(const char* password) {}
|
||||
uint8 network_get_current_player_id() { return 0; }
|
||||
int network_get_current_player_group_index() { return 0; }
|
||||
void network_append_chat_log(const utf8 *text) { }
|
||||
#endif /* DISABLE_NETWORK */
|
||||
|
||||
@@ -119,6 +119,10 @@ public:
|
||||
void SaveGroups();
|
||||
void LoadGroups();
|
||||
|
||||
void BeginChatLog();
|
||||
void AppendChatLog(const utf8 *text);
|
||||
void CloseChatLog();
|
||||
|
||||
void Client_Send_TOKEN();
|
||||
void Client_Send_AUTH(const char* name, const char* password, const char *pubkey, const char *sig, size_t sigsize);
|
||||
void Client_Send_AUTH(const char* name, const char* password, const char *pubkey);
|
||||
@@ -199,6 +203,8 @@ private:
|
||||
int advertise_status = 0;
|
||||
uint32 last_heartbeat_time = 0;
|
||||
uint8 default_group = 0;
|
||||
SDL_RWops *_chatLogStream;
|
||||
std::string _chatLogPath;
|
||||
|
||||
void UpdateServer();
|
||||
void UpdateClient();
|
||||
@@ -285,6 +291,7 @@ void network_send_password(const char* password);
|
||||
void network_set_password(const char* password);
|
||||
|
||||
void network_print_error();
|
||||
void network_append_chat_log(const utf8 *text);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -50,7 +50,8 @@ enum WINDOW_MULTIPLAYER_WIDGET_IDX {
|
||||
WIDX_SELECTED_GROUP_DROPDOWN,
|
||||
WIDX_PERMISSIONS_LIST,
|
||||
|
||||
WIDX_KNOWN_KEYS_ONLY_CHECKBOX = 7,
|
||||
WIDX_LOG_CHAT_CHECKBOX = 7,
|
||||
WIDX_KNOWN_KEYS_ONLY_CHECKBOX,
|
||||
};
|
||||
|
||||
#define MAIN_MULTIPLAYER_WIDGETS \
|
||||
@@ -83,7 +84,8 @@ static rct_widget window_multiplayer_groups_widgets[] = {
|
||||
|
||||
static rct_widget window_multiplayer_options_widgets[] = {
|
||||
MAIN_MULTIPLAYER_WIDGETS,
|
||||
{ WWT_CHECKBOX, 1, 3, 297, 50, 61, STR_ALLOW_KNOWN_KEYS_ONLY, STR_ALLOW_KNOWN_KEYS_ONLY_TIP },
|
||||
{ WWT_CHECKBOX, 1, 3, 297, 50, 61, STR_LOG_CHAT, STR_LOG_CHAT_TIP },
|
||||
{ WWT_CHECKBOX, 1, 3, 297, 64, 75, STR_ALLOW_KNOWN_KEYS_ONLY, STR_ALLOW_KNOWN_KEYS_ONLY_TIP },
|
||||
{ WIDGETS_END }
|
||||
};
|
||||
|
||||
@@ -96,7 +98,7 @@ static rct_widget *window_multiplayer_page_widgets[] = {
|
||||
const uint64 window_multiplayer_page_enabled_widgets[] = {
|
||||
(1 << WIDX_CLOSE) | (1 << WIDX_TAB1) | (1 << WIDX_TAB2) | (1 << WIDX_TAB3),
|
||||
(1 << WIDX_CLOSE) | (1 << WIDX_TAB1) | (1 << WIDX_TAB2) | (1 << WIDX_TAB3) | (1 << WIDX_DEFAULT_GROUP) | (1 << WIDX_DEFAULT_GROUP_DROPDOWN) | (1 << WIDX_ADD_GROUP) | (1 << WIDX_REMOVE_GROUP) | (1 << WIDX_RENAME_GROUP) | (1 << WIDX_SELECTED_GROUP) | (1 << WIDX_SELECTED_GROUP_DROPDOWN),
|
||||
(1 << WIDX_CLOSE) | (1 << WIDX_TAB1) | (1 << WIDX_TAB2) | (1 << WIDX_TAB3) | (1 << WIDX_KNOWN_KEYS_ONLY_CHECKBOX),
|
||||
(1 << WIDX_CLOSE) | (1 << WIDX_TAB1) | (1 << WIDX_TAB2) | (1 << WIDX_TAB3) | (1 << WIDX_LOG_CHAT_CHECKBOX) | (1 << WIDX_KNOWN_KEYS_ONLY_CHECKBOX),
|
||||
};
|
||||
|
||||
static uint8 _selectedGroup = 0;
|
||||
@@ -264,11 +266,6 @@ static void window_multiplayer_set_page(rct_window* w, int page){
|
||||
w->pressed_widgets = 0;
|
||||
w->widgets = window_multiplayer_page_widgets[page];
|
||||
|
||||
if (network_get_mode() == NETWORK_MODE_CLIENT) {
|
||||
w->widgets[WIDX_TAB3].type = WWT_EMPTY;
|
||||
w->disabled_widgets |= (1 << WIDX_TAB3);
|
||||
}
|
||||
|
||||
window_event_resize_call(w);
|
||||
window_event_invalidate_call(w);
|
||||
window_init_scroll_widgets(w);
|
||||
@@ -761,6 +758,10 @@ static void window_multiplayer_options_mouseup(rct_window *w, int widgetIndex)
|
||||
window_multiplayer_set_page(w, widgetIndex - WIDX_TAB1);
|
||||
}
|
||||
break;
|
||||
case WIDX_LOG_CHAT_CHECKBOX:
|
||||
gConfigNetwork.log_chat = !gConfigNetwork.log_chat;
|
||||
config_save_default();
|
||||
break;
|
||||
case WIDX_KNOWN_KEYS_ONLY_CHECKBOX:
|
||||
gConfigNetwork.known_keys_only = !gConfigNetwork.known_keys_only;
|
||||
config_save_default();
|
||||
@@ -785,6 +786,11 @@ static void window_multiplayer_options_invalidate(rct_window *w)
|
||||
window_multiplayer_anchor_border_widgets(w);
|
||||
window_align_tabs(w, WIDX_TAB1, WIDX_TAB3);
|
||||
|
||||
if (network_get_mode() == NETWORK_MODE_CLIENT) {
|
||||
w->widgets[WIDX_KNOWN_KEYS_ONLY_CHECKBOX].type = WWT_EMPTY;
|
||||
}
|
||||
|
||||
widget_set_checkbox_value(w, WIDX_LOG_CHAT_CHECKBOX, gConfigNetwork.log_chat);
|
||||
widget_set_checkbox_value(w, WIDX_KNOWN_KEYS_ONLY_CHECKBOX, gConfigNetwork.known_keys_only);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user