mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 19:13:07 +01:00
save chat logs
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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,53 @@ 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, "logs");
|
||||
Path::Append(path, sizeof(path), filename);
|
||||
|
||||
_chatLogPath = std::string(path);
|
||||
}
|
||||
|
||||
void Network::AppendChatLog(const utf8 *text)
|
||||
{
|
||||
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 +2358,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 +2436,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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user