Added a static text and template handling bundle skeleton
Signed-off-by: Gergely Polonkai (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
parent
7fa4ffd9fd
commit
f3ab981580
1
data/texts/motd
Normal file
1
data/texts/motd
Normal file
@ -0,0 +1 @@
|
|||||||
|
Hello, and welcome to Iminiru!
|
@ -1,5 +1,5 @@
|
|||||||
bin_PROGRAMS = wmud
|
bin_PROGRAMS = wmud
|
||||||
AM_CPPFLAGS = -DWMUD_STATEDIR=\""$(localstatedir)"\" -DWMUD_CONFDIR=\""$(sysconfdir)"\" $(MEMCACHED_CFLAGS) $(GLIB_CFLAGS) $(GIO_CFLAGS) $(GTHREAD_CFLAGS) $(SQLITE3_CFLAGS) $(CURL_CFLAGS)
|
AM_CPPFLAGS = -DWMUD_STATEDIR=\""$(localstatedir)"\" -DWMUD_CONFDIR=\""$(sysconfdir)"\" $(MEMCACHED_CFLAGS) $(GLIB_CFLAGS) $(GIO_CFLAGS) $(GTHREAD_CFLAGS) $(SQLITE3_CFLAGS) $(CURL_CFLAGS)
|
||||||
|
|
||||||
wmud_SOURCES = main.c game-networking.c interpreter.c db.c players.c maintenance.c game.c configuration.c world.c menu.c
|
wmud_SOURCES = main.c game-networking.c interpreter.c db.c players.c maintenance.c game.c configuration.c world.c menu.c texts.c
|
||||||
wmud_LDADD = $(MEMCACHED_LIBS) $(GLIB_LIBS) $(GIO_LIBS) $(GTHREAD_LIBS) $(SQLITE3_LIBS) $(CURL_LIBS)
|
wmud_LDADD = $(MEMCACHED_LIBS) $(GLIB_LIBS) $(GIO_LIBS) $(GTHREAD_LIBS) $(SQLITE3_LIBS) $(CURL_LIBS)
|
||||||
|
@ -231,6 +231,7 @@ wmud_client_callback(GSocket *client_socket, GIOCondition condition, wmudClient
|
|||||||
wmud_client_send(client, "There %s %d failed login attempt%s with your account since your last visit\r\n", (client->player->fail_count == 1) ? "was" : "were", client->player->fail_count, (client->player->fail_count == 1) ? "" : "s");
|
wmud_client_send(client, "There %s %d failed login attempt%s with your account since your last visit\r\n", (client->player->fail_count == 1) ? "was" : "were", client->player->fail_count, (client->player->fail_count == 1) ? "" : "s");
|
||||||
}
|
}
|
||||||
/* TODO: send MOTD */
|
/* TODO: send MOTD */
|
||||||
|
wmud_text_send_to_client("motd", client);
|
||||||
/* TODO: send menu items */
|
/* TODO: send menu items */
|
||||||
g_slist_foreach(game_menu, (GFunc)send_menu_item, client);
|
g_slist_foreach(game_menu, (GFunc)send_menu_item, client);
|
||||||
client->state = WMUD_CLIENT_STATE_MENU;
|
client->state = WMUD_CLIENT_STATE_MENU;
|
||||||
|
@ -221,6 +221,8 @@ main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wmud_texts_init();
|
||||||
|
|
||||||
/* Non-thread initialization ends here */
|
/* Non-thread initialization ends here */
|
||||||
|
|
||||||
wmud_game_init(&game_thread, &game_context);
|
wmud_game_init(&game_thread, &game_context);
|
||||||
|
81
wmud/texts.c
Normal file
81
wmud/texts.c
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/* wMUD - Yet another MUD codebase by W00d5t0ck
|
||||||
|
* Copyright (C) 2012 - Gergely POLONKAI
|
||||||
|
*
|
||||||
|
* texts.c: static text and template handling functions
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include <glib.h>
|
||||||
|
#include <gio/gio.h>
|
||||||
|
|
||||||
|
#include "wmud-types.h"
|
||||||
|
#include "game-networking.h"
|
||||||
|
#include "texts.h"
|
||||||
|
|
||||||
|
static const gchar *text_files[] = {
|
||||||
|
"motd",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
GHashTable *text_table = NULL;
|
||||||
|
|
||||||
|
void
|
||||||
|
wmud_texts_init(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
gchar *texts_dir = g_strconcat(WMUD_STATEDIR, "/texts/", NULL);
|
||||||
|
|
||||||
|
text_table = g_hash_table_new(g_str_hash, g_str_equal);
|
||||||
|
|
||||||
|
for (i = 0; i < g_strv_length((gchar **)text_files); i++)
|
||||||
|
{
|
||||||
|
GFile *tf;
|
||||||
|
GFileInfo *tfi;
|
||||||
|
GError *err = NULL;
|
||||||
|
guint64 tfs;
|
||||||
|
gchar *contents;
|
||||||
|
gsize length;
|
||||||
|
|
||||||
|
gchar *text_file = g_strconcat(texts_dir, text_files[i], NULL);
|
||||||
|
g_debug("Loading text file %s from %s", text_files[i], text_file);
|
||||||
|
tf = g_file_new_for_path(text_file);
|
||||||
|
tfi = g_file_query_info(tf, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, &err);
|
||||||
|
/* TODO: Error checking! */
|
||||||
|
tfs = g_file_info_get_attribute_uint64(tfi, G_FILE_ATTRIBUTE_STANDARD_SIZE);
|
||||||
|
|
||||||
|
contents = g_malloc0(tfs + 1);
|
||||||
|
|
||||||
|
g_clear_error(&err);
|
||||||
|
if (!g_file_load_contents(tf, NULL, &contents, &length, NULL, &err))
|
||||||
|
{
|
||||||
|
g_object_unref(tfi);
|
||||||
|
g_object_unref(tf);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
g_hash_table_insert(text_table, (char *)text_files[i], contents);
|
||||||
|
|
||||||
|
g_object_unref(tfi);
|
||||||
|
g_object_unref(tf);
|
||||||
|
g_free(text_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free(texts_dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wmud_text_send_to_client(gchar *text_name, wmudClient *client)
|
||||||
|
{
|
||||||
|
gchar *text = g_hash_table_lookup(text_table, text_name);
|
||||||
|
wmud_client_send(client, "%s\r\n", text);
|
||||||
|
}
|
||||||
|
|
27
wmud/texts.h
Normal file
27
wmud/texts.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/* wMUD - Yet another MUD codebase by W00d5t0ck
|
||||||
|
* Copyright (C) 2012 - Gergely POLONKAI
|
||||||
|
*
|
||||||
|
* texts.h: static text and template handling functions
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#ifndef __WMUD_TEXTS_H__
|
||||||
|
#define __WMUD_TEXTS_H__
|
||||||
|
|
||||||
|
#include "wmud-types.h"
|
||||||
|
|
||||||
|
void wmud_texts_init(void);
|
||||||
|
void wmud_text_send_to_client(gchar *text, wmudClient *client);
|
||||||
|
|
||||||
|
#endif /* __WMUD_TEXTS_H__ */
|
Loading…
Reference in New Issue
Block a user