Skip to content

Commit

Permalink
Add new external server url (dragon-tea.farboxgames)
Browse files Browse the repository at this point in the history
Append patch (fix)
Add: libnotify for notification
Add: Customize logs window
Fix: Apply new changes
Fix: Cloud Build
Fix Some bug's
  • Loading branch information
badcast committed Mar 24, 2024
1 parent 52246ad commit 50c191d
Show file tree
Hide file tree
Showing 18 changed files with 308 additions and 122 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- name: Install build tools
run: |
sudo apt-get update -y
sudo apt-get install -y cmake pkg-config libgtk-3-dev libcurl4-openssl-dev libjson-c-dev
sudo apt-get install -y cmake pkg-config libgtk-3-dev libcurl4-openssl-dev libjson-c-dev libnotify-dev
- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
Expand Down
9 changes: 6 additions & 3 deletions client-frontend/dragon-tea/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pkg_check_modules(gtk3ui REQUIRED gtk+-3.0)
pkg_check_modules(libcurl REQUIRED libcurl)
pkg_check_modules(json REQUIRED json-c)
pkg_check_modules(gthread REQUIRED gthread-2.0)
pkg_check_modules(libnotify REQUIRED libnotify)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
Expand Down Expand Up @@ -48,10 +49,12 @@ target_sources(dragontea PUBLIC ${DRAGONTEA_SOURCES})
target_include_directories(
dragontea
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/" ${gtk3ui_INCLUDE_DIRS}
${gthread_INCLUDE_DIRS} ${libcurl_INCLUDE_DIRS} ${json_INCLUDE_DIRS})
${gthread_INCLUDE_DIRS} ${libcurl_INCLUDE_DIRS} ${json_INCLUDE_DIRS}
${libnotify_INCLUDE_DIRS})

target_link_libraries(dragontea ${gtk3ui_LIBRARIES} ${libcurl_LIBRARIES}
${json_LIBRARIES} ${gthread_LIBRARIES})
target_link_libraries(
dragontea ${gtk3ui_LIBRARIES} ${libcurl_LIBRARIES} ${json_LIBRARIES}
${gthread_LIBRARIES} ${libnotify_LIBRARIES})

target_compile_definitions(dragontea
PUBLIC DRAGON_TEA_VERSION="${DRAGON_TEA_VERSION}")
Expand Down
1 change: 1 addition & 0 deletions client-frontend/dragon-tea/builtin/server4.url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://dragontea.farboxgames.repl.co/
7 changes: 6 additions & 1 deletion client-frontend/dragon-tea/include/tea.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ typedef DWORD uid_t;
#include <glib.h>
#include <gtk/gtk.h>
#include <json-c/json.h>
#include <libnotify/notify.h>

#include "tea_structs.h"
#include "tea_api.h"
Expand Down Expand Up @@ -58,11 +59,13 @@ typedef DWORD uid_t;

extern struct tea_net_stats net_stats;
extern struct tea_server_info cur_server;
extern struct tea_settings app_settings;
extern struct tea_settings env;
extern struct tea_app_widgets widgets;

void tea_init();

void tea_free();

const char *tea_version();

// User Interface Implementation
Expand All @@ -87,6 +90,8 @@ int tea_get_server_id(const char *serverURI);

int tea_get_builtin_server_list(char list[3][64]);

void tea_read_urls(struct tea_server_urls *wrData);

void tea_load();

void tea_save();
Expand Down
2 changes: 0 additions & 2 deletions client-frontend/dragon-tea/include/tea_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,4 @@ int tea_switch_server(int newServerID);

int tea_fetch_server();

void tea_read_urls(struct tea_server_urls *wrData);

#endif
9 changes: 9 additions & 0 deletions client-frontend/dragon-tea/include/tea_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ struct tea_settings
int active_server;
// loaded from configurations
char servers[32][255];
// show log window
int show_logs;
// remove old notification
int old_notify_remove;
// User messages
GArray *local_msg_db;
// Log I/O
Expand Down Expand Up @@ -162,11 +166,14 @@ struct tea_app_widgets
GtkWidget *top_label_user_state;
guint timeout_periodic_sync;
gboolean chat_synched;
gboolean firstTime;
} chat_tab;

struct
{
GtkWidget *combx_server_list;
GtkWidget *toggle_log;
GtkWidget *toggle_notify;
GtkWidget *button_apply;
} settings_tab;

Expand All @@ -175,6 +182,8 @@ struct tea_app_widgets
GtkWidget *widget_settings;
GtkWindow *main_window;

GtkWindow *log_window;

GtkWidget *notebook;
};

Expand Down
2 changes: 0 additions & 2 deletions client-frontend/dragon-tea/include/ui_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

void tea_on_authenticate(const struct tea_id_info *user_info);

void tea_on_logouted();

void ui_on_close_window(GtkWidget *window, gpointer data);

void ui_on_notebook_switch_page(GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer user_data);
Expand Down
63 changes: 40 additions & 23 deletions client-frontend/dragon-tea/src/core/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,11 @@ void tea_ui_init()
tea_try_login();
tea_ui_focus_tab(UI_TAB_AUTH);

show_log_dialog();
}
// libnotify init
notify_init("Dragon Tea Messenger");

void tea_ui_update_settings()
{
int selServer = 0;
for(int x = 0; x < 32; ++x)
{
if(strlen(app_settings.servers[x]) == 0)
break;

if(tea_get_server_id(app_settings.servers[x]) == app_settings.active_server)
{
selServer = x;
break;
}
}
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets.settings_tab.combx_server_list), selServer);
if(env.show_logs)
show_log_dialog();
}

void tea_ui_focus_tab(enum UiTabs tabIndex)
Expand Down Expand Up @@ -126,7 +113,9 @@ void tea_ui_chat_interactable(int value)
void tea_ui_chat_sync()
{
widgets.chat_tab.chat_synched = FALSE;
on_chat_message_handler_async(NULL);

if(tea_is_connected())
on_chat_message_handler_async(NULL);
}

void tea_ui_chat_status_text(const char *status_text)
Expand Down Expand Up @@ -167,7 +156,7 @@ void tea_ui_chat_push_block(const struct tea_message_id *message)
{
/*
* FORMAT VIEW for Message Block
* bad@(21:16): Hello
* bad@[21:16]: Hello
*/

if(message == NULL)
Expand All @@ -176,12 +165,40 @@ void tea_ui_chat_push_block(const struct tea_message_id *message)
return;
}

static const char format_message_block[] = "\n\n%s@(%s): %s\n";
GDateTime *_gdatetime = g_date_time_new_from_unix_local(message->time_received);
gchar *date_time = g_date_time_format(_gdatetime, "%H:%M");
static const char format_message_block[] = "\n\n>>%s@[%s]: %s\n";

int require_size = snprintf(NULL, 0, format_message_block, message->sent_user_name, date_time, message->message_text);
gchar *date_time;
GDateTime *prevgtime, *_gdatetime = g_date_time_new_from_unix_utc(message->time_received);

if(env.local_msg_db->len == 0)
{
prevgtime = _gdatetime;
}
else
{
prevgtime = g_date_time_new_from_unix_utc(
g_array_index(env.local_msg_db, struct tea_message_id, (env.local_msg_db->len - 1)).time_received);
}

// TODO: sort by date

if(prevgtime == _gdatetime ||
!(g_date_time_get_day_of_month(prevgtime) == g_date_time_get_day_of_month(_gdatetime) &&
g_date_time_get_month(prevgtime) == g_date_time_get_month(_gdatetime) &&
g_date_time_get_year(prevgtime) == g_date_time_get_year(_gdatetime)))
{
date_time = g_date_time_format(prevgtime, "\n\n\t::::%d.%m.%Y::::\n");

tea_ui_chat_push_text_raw(date_time, -1);

g_free(date_time);
}

if(prevgtime != _gdatetime)
g_free(prevgtime);

date_time = g_date_time_format(_gdatetime, "%H:%M");
int require_size = snprintf(NULL, 0, format_message_block, message->sent_user_name, date_time, message->message_text);
char *text_buffer = (char *) malloc(require_size + 1);
if(text_buffer == NULL)
ui_error_fail("Out of memory!");
Expand Down
67 changes: 47 additions & 20 deletions client-frontend/dragon-tea/src/core/ui_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ gpointer async_send(const char *text)

int len = strlen(text);
// send message to
net_api_write_message(&app_settings.id_info, -1, text, len, &last_send_result);
net_api_write_message(&env.id_info, -1, text, len, &last_send_result);
// set work complete
thread_send_msg = NULL;

Expand All @@ -33,17 +33,17 @@ gpointer async_reply(gpointer)
// Последнее сообщение на локальной машине (когда на сервере она устарело)
int last_local_msg_id;

if(app_settings.local_msg_db->len == 0)
if(env.local_msg_db->len == 0)
{
last_local_msg_id = 0;
}
else
{
last_local_msg_id = (&g_array_index(app_settings.local_msg_db, struct tea_message_id, app_settings.local_msg_db->len - 1))->msg_id;
last_local_msg_id = (&g_array_index(env.local_msg_db, struct tea_message_id, env.local_msg_db->len - 1))->msg_id;
}

// Читаем сообщение других пользователей и поддерживаем коммуникацию
net_api_read_messages(&app_settings.id_info, -1, last_local_msg_id, MESSAGES_PER_REQUEST, &last_read_result);
net_api_read_messages(&env.id_info, -1, last_local_msg_id, MESSAGES_PER_REQUEST, &last_read_result);

thread_reply_msg = NULL;

Expand Down Expand Up @@ -106,6 +106,12 @@ gboolean on_chat_sending_async(const gchar *text)
return worked == FALSE;
}

void notify_action(NotifyNotification *notification, const char *action, gpointer user_data)
{
ui_error(action);
gtk_window_set_focus(widgets.main_window, NULL);
}

gboolean on_chat_message_handler_async(gpointer)
{
char buffer[128];
Expand Down Expand Up @@ -138,10 +144,14 @@ gboolean on_chat_message_handler_async(gpointer)
if(last_chance_state != CHANCE_TO_LOGOUT)
strcpy(buffer, _("Your network has been restored. "));
else
buffer[0] = 0;
buffer[0] = NULL;

strcat(buffer, _("You're online."));
tea_ui_chat_status_text(buffer);

if(widgets.chat_tab.firstTime)
widgets.chat_tab.firstTime = FALSE;

break;
}

Expand All @@ -152,15 +162,31 @@ gboolean on_chat_message_handler_async(gpointer)
break;
}

// Добавление сообщений из загруженных в локальные
g_array_append_vals(app_settings.local_msg_db, last_read_result.messages->data, last_read_result.messages->len);

NotifyNotification *gnotify;
struct tea_message_id *message;
// Отображение собщений
for(int x = 0; x < last_read_result.messages->len; ++x)
{
tea_ui_chat_push_block(&g_array_index(last_read_result.messages, struct tea_message_id, x));
message = &g_array_index(last_read_result.messages, struct tea_message_id, x);
tea_ui_chat_push_block(message);
if(!widgets.chat_tab.firstTime && message->sent_user_id != env.id_info.user_id &&
!gtk_window_is_active(widgets.main_window))
{
gnotify = notify_notification_new(
message->sent_user_name, message->message_text, gtk_window_get_icon_name(widgets.main_window));
notify_notification_add_action(gnotify, "custom_action", _("Read message"), notify_action, NULL, NULL);

if(!env.old_notify_remove)
notify_notification_set_timeout(gnotify, 0);

notify_notification_show(gnotify, NULL);
g_object_unref(gnotify);
}
g_array_append_val(env.local_msg_db, *message);
}

// Have notify

// Освобождение старого массива
g_array_free(last_read_result.messages, TRUE);
last_read_result.messages = NULL;
Expand Down Expand Up @@ -211,7 +237,7 @@ gboolean on_chat_message_handler_async(gpointer)
thread_reply_msg = g_thread_new(NULL, (GThreadFunc) async_reply, NULL);
}
}
return TRUE; // EVERYTHING
return tea_is_connected(); // EVERYTHING
}

void ui_on_close_window(GtkWidget *window, gpointer data)
Expand Down Expand Up @@ -257,7 +283,7 @@ void on_chat_send_button(GtkWidget *widget, gpointer data)
void tea_on_authenticate(const struct tea_id_info *user_info)
{
char buffer[300], buf2[32];
app_settings.connected = TRUE;
env.connected = TRUE;

tea_ui_chat_clear();

Expand Down Expand Up @@ -304,19 +330,20 @@ void tea_on_authenticate(const struct tea_id_info *user_info)

// reset chances
check_chance_logouting = CHANCE_TO_LOGOUT;
widgets.chat_tab.firstTime = TRUE;

// sync
tea_ui_chat_sync();

widgets.chat_tab.timeout_periodic_sync = g_timeout_add(INTERVAL_CHAT_SYNC, (GSourceFunc) on_chat_message_handler_async, NULL);
}

void tea_on_logouted()
void tea_logout()
{
if(!app_settings.connected)
if(!env.connected)
return;

app_settings.connected = FALSE;
env.connected = FALSE;

// remove message handler
if(widgets.chat_tab.timeout_periodic_sync)
Expand All @@ -335,24 +362,24 @@ void tea_on_logouted()
GThread *sender = thread_reply_msg;
if(sender)
g_thread_join(sender);
// saved old data, reset at
// saved old data, reset it
if(last_read_result.messages)
{
for(int x = 0; x < last_read_result.messages->len; ++x)
{
free(g_array_index(last_read_result.messages, struct tea_message_id, x).message_text);
}
g_array_free(last_read_result.messages, TRUE);
memset(&last_read_result, 0, sizeof(last_read_result));
}
memset(&last_read_result, 0, sizeof(last_read_result));

// Clear local messages
for(size_t x = 0; x < app_settings.local_msg_db->len; ++x)
for(size_t x = 0; x < env.local_msg_db->len; ++x)
{
free(g_array_index(app_settings.local_msg_db, struct tea_message_id, x).message_text);
free(g_array_index(env.local_msg_db, struct tea_message_id, x).message_text);
}
g_array_free(app_settings.local_msg_db, TRUE);
app_settings.local_msg_db = g_array_new(FALSE, FALSE, sizeof(struct tea_message_id));
g_array_free(env.local_msg_db, TRUE);
env.local_msg_db = g_array_new(FALSE, FALSE, sizeof(struct tea_message_id));

#ifdef TEA_OS_LINUX
// Release RESIDENT SET SIZE (RSS) and put to System
Expand Down
Loading

0 comments on commit 50c191d

Please sign in to comment.