Continue uncrustifying
This commit is contained in:
parent
c68b577fb3
commit
73b7c3db39
@ -96,13 +96,14 @@ wmud_configdata_free(ConfigData **config_data)
|
|||||||
gboolean
|
gboolean
|
||||||
wmud_config_init(ConfigData **config_data, GError **err)
|
wmud_config_init(ConfigData **config_data, GError **err)
|
||||||
{
|
{
|
||||||
GString *config_file = g_string_new(WMUD_CONFDIR);
|
GString *config_file = g_string_new(WMUD_CONFDIR);
|
||||||
GKeyFile *config;
|
GKeyFile *config;
|
||||||
GError *in_err = NULL;
|
GError *in_err = NULL;
|
||||||
gchar *pos;
|
gchar *pos;
|
||||||
|
|
||||||
if (!config_data)
|
if (!config_data) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (*config_data) {
|
if (*config_data) {
|
||||||
g_clear_error(err);
|
g_clear_error(err);
|
||||||
@ -255,8 +256,8 @@ wmud_config_init(ConfigData **config_data, GError **err)
|
|||||||
|
|
||||||
if ((pos = g_strstr_len((*config_data)->database_dsn,
|
if ((pos = g_strstr_len((*config_data)->database_dsn,
|
||||||
-1, "{statedir}")) != NULL) {
|
-1, "{statedir}")) != NULL) {
|
||||||
guint real_pos = pos - (*config_data)->database_dsn;
|
guint real_pos = pos - (*config_data)->database_dsn;
|
||||||
GString *tmp = g_string_new((*config_data)->database_dsn);
|
GString *tmp = g_string_new((*config_data)->database_dsn);
|
||||||
|
|
||||||
g_string_erase(tmp, real_pos, 10);
|
g_string_erase(tmp, real_pos, 10);
|
||||||
g_string_insert(tmp, real_pos, WMUD_STATEDIR);
|
g_string_insert(tmp, real_pos, WMUD_STATEDIR);
|
||||||
|
236
wmud/db.c
236
wmud/db.c
@ -39,8 +39,8 @@
|
|||||||
* different (e.g MySQL or PostgreSQL) database.
|
* different (e.g MySQL or PostgreSQL) database.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static GdaConnection *dbh = NULL;
|
static GdaConnection *dbh = NULL;
|
||||||
static GdaSqlParser *parser = NULL;
|
static GdaSqlParser *parser = NULL;
|
||||||
|
|
||||||
GQuark
|
GQuark
|
||||||
wmud_db_error_quark()
|
wmud_db_error_quark()
|
||||||
@ -98,33 +98,34 @@ wmud_db_init(GError **err)
|
|||||||
gboolean
|
gboolean
|
||||||
wmud_db_load_players(GError **err)
|
wmud_db_load_players(GError **err)
|
||||||
{
|
{
|
||||||
GdaStatement *sth = NULL;
|
GdaStatement *sth = NULL;
|
||||||
GdaDataModel *res;
|
GdaDataModel *res;
|
||||||
GdaDataModelIter *iter;
|
GdaDataModelIter *iter;
|
||||||
GError *local_err = NULL;
|
GError *local_err = NULL;
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading players");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading players");
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err) {
|
||||||
g_set_error(err,
|
g_set_error(err,
|
||||||
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
"Database backend not initialized");
|
"Database backend not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sth = gda_sql_parser_parse_string(
|
sth = gda_sql_parser_parse_string(
|
||||||
parser,
|
parser,
|
||||||
"SELECT id, login, password, email FROM players",
|
"SELECT id, login, password, email FROM players",
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
/* TODO: error checking! */
|
/* TODO: error checking! */
|
||||||
if ((res = gda_connection_statement_execute_select(
|
if ((res = gda_connection_statement_execute_select(
|
||||||
dbh,
|
dbh,
|
||||||
sth,
|
sth,
|
||||||
NULL,
|
NULL,
|
||||||
&local_err)) == NULL) {
|
&local_err)) == NULL) {
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
|
||||||
"Unable to load players: %s",
|
"Unable to load players: %s",
|
||||||
local_err->message);
|
local_err->message);
|
||||||
@ -141,7 +142,7 @@ wmud_db_load_players(GError **err)
|
|||||||
|
|
||||||
while (gda_data_model_iter_is_valid(iter)) {
|
while (gda_data_model_iter_is_valid(iter)) {
|
||||||
const GValue *val;
|
const GValue *val;
|
||||||
WmudPlayer *player;
|
WmudPlayer *player;
|
||||||
|
|
||||||
player = wmud_player_new();
|
player = wmud_player_new();
|
||||||
|
|
||||||
@ -192,20 +193,21 @@ wmud_db_save_player(WmudPlayer *player, GError **err)
|
|||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Saving player");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Saving player");
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err) {
|
||||||
g_set_error(err,
|
g_set_error(err,
|
||||||
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
"Database backend not initialized");
|
"Database backend not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
login_value = gda_value_new_from_string(
|
login_value = gda_value_new_from_string(
|
||||||
wmud_player_get_player_name(player),
|
wmud_player_get_player_name(player),
|
||||||
G_TYPE_STRING);
|
G_TYPE_STRING);
|
||||||
email_value = gda_value_new_from_string(
|
email_value = gda_value_new_from_string(
|
||||||
wmud_player_get_email(player),
|
wmud_player_get_email(player),
|
||||||
G_TYPE_STRING);
|
G_TYPE_STRING);
|
||||||
|
|
||||||
if (!gda_connection_insert_row_into_table(dbh,
|
if (!gda_connection_insert_row_into_table(dbh,
|
||||||
"players",
|
"players",
|
||||||
@ -228,8 +230,8 @@ wmud_db_save_player(WmudPlayer *player, GError **err)
|
|||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
wmud_db_update_player_password(WmudPlayer *player,
|
wmud_db_update_player_password(WmudPlayer *player,
|
||||||
gchar *crypted_password,
|
gchar *crypted_password,
|
||||||
GError **err)
|
GError **err)
|
||||||
{
|
{
|
||||||
GValue *cpw,
|
GValue *cpw,
|
||||||
*player_id;
|
*player_id;
|
||||||
@ -271,16 +273,17 @@ wmud_db_update_player_password(WmudPlayer *player,
|
|||||||
gboolean
|
gboolean
|
||||||
wmud_db_load_planes(GSList **planes, GError **err)
|
wmud_db_load_planes(GSList **planes, GError **err)
|
||||||
{
|
{
|
||||||
GdaStatement *sth = NULL;
|
GdaStatement *sth = NULL;
|
||||||
GdaDataModel *res = NULL;
|
GdaDataModel *res = NULL;
|
||||||
GdaDataModelIter *iter;
|
GdaDataModelIter *iter;
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading planes");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading planes");
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err) {
|
||||||
g_set_error(err,
|
g_set_error(err,
|
||||||
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
"Database backend not initialized");
|
"Database backend not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -289,20 +292,20 @@ wmud_db_load_planes(GSList **planes, GError **err)
|
|||||||
"SELECT id, name FROM planes",
|
"SELECT id, name FROM planes",
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
||||||
iter = gda_data_model_create_iter(res);
|
iter = gda_data_model_create_iter(res);
|
||||||
gda_data_model_iter_move_next(iter);
|
gda_data_model_iter_move_next(iter);
|
||||||
|
|
||||||
while (gda_data_model_iter_is_valid(iter)) {
|
while (gda_data_model_iter_is_valid(iter)) {
|
||||||
const GValue *val;
|
const GValue *val;
|
||||||
wmudPlane *plane;
|
wmudPlane *plane;
|
||||||
|
|
||||||
plane = g_new0(wmudPlane, 1);
|
plane = g_new0(wmudPlane, 1);
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 0);
|
val = gda_data_model_iter_get_value_at(iter, 0);
|
||||||
plane->id = g_value_get_int(val);
|
plane->id = g_value_get_int(val);
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 1);
|
val = gda_data_model_iter_get_value_at(iter, 1);
|
||||||
plane->name = g_strdup(g_value_get_string(val));
|
plane->name = g_strdup(g_value_get_string(val));
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
||||||
@ -323,16 +326,17 @@ wmud_db_load_planes(GSList **planes, GError **err)
|
|||||||
gboolean
|
gboolean
|
||||||
wmud_db_load_planets(GSList **planets, GError **err)
|
wmud_db_load_planets(GSList **planets, GError **err)
|
||||||
{
|
{
|
||||||
GdaStatement *sth = NULL;
|
GdaStatement *sth = NULL;
|
||||||
GdaDataModel *res = NULL;
|
GdaDataModel *res = NULL;
|
||||||
GdaDataModelIter *iter;
|
GdaDataModelIter *iter;
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading planets");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading planets");
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err) {
|
||||||
g_set_error(err,
|
g_set_error(err,
|
||||||
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
"Database backend not initialized");
|
"Database backend not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -341,20 +345,20 @@ wmud_db_load_planets(GSList **planets, GError **err)
|
|||||||
"SELECT id, name FROM planets",
|
"SELECT id, name FROM planets",
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
||||||
iter = gda_data_model_create_iter(res);
|
iter = gda_data_model_create_iter(res);
|
||||||
gda_data_model_iter_move_next(iter);
|
gda_data_model_iter_move_next(iter);
|
||||||
|
|
||||||
while (gda_data_model_iter_is_valid(iter)) {
|
while (gda_data_model_iter_is_valid(iter)) {
|
||||||
const GValue *val;
|
const GValue *val;
|
||||||
wmudPlanet *planet;
|
wmudPlanet *planet;
|
||||||
|
|
||||||
planet = g_new0(wmudPlanet, 1);
|
planet = g_new0(wmudPlanet, 1);
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 0);
|
val = gda_data_model_iter_get_value_at(iter, 0);
|
||||||
planet->id = g_value_get_int(val);
|
planet->id = g_value_get_int(val);
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 1);
|
val = gda_data_model_iter_get_value_at(iter, 1);
|
||||||
planet->name = g_strdup(g_value_get_string(val));
|
planet->name = g_strdup(g_value_get_string(val));
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
||||||
@ -375,31 +379,32 @@ wmud_db_load_planets(GSList **planets, GError **err)
|
|||||||
gboolean
|
gboolean
|
||||||
wmud_db_load_directions(GSList **directions, GError **err)
|
wmud_db_load_directions(GSList **directions, GError **err)
|
||||||
{
|
{
|
||||||
GdaStatement *sth = NULL;
|
GdaStatement *sth = NULL;
|
||||||
GdaDataModel *res = NULL;
|
GdaDataModel *res = NULL;
|
||||||
GdaDataModelIter *iter;
|
GdaDataModelIter *iter;
|
||||||
GError *local_err = NULL;
|
GError *local_err = NULL;
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading directions");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading directions");
|
||||||
|
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err) {
|
||||||
g_set_error(err,
|
g_set_error(err,
|
||||||
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
"Database backend not initialized");
|
"Database backend not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sth = gda_sql_parser_parse_string(
|
sth = gda_sql_parser_parse_string(
|
||||||
parser,
|
parser,
|
||||||
"SELECT id, short_name, name FROM directions",
|
"SELECT id, short_name, name FROM directions",
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if ((res = gda_connection_statement_execute_select(
|
if ((res = gda_connection_statement_execute_select(
|
||||||
dbh, sth,
|
dbh, sth,
|
||||||
NULL, &local_err)) == NULL) {
|
NULL, &local_err)) == NULL) {
|
||||||
g_set_error(err,
|
g_set_error(err,
|
||||||
WMUD_DB_ERROR, WMUD_DB_ERROR_SELECT_ERROR,
|
WMUD_DB_ERROR, WMUD_DB_ERROR_SELECT_ERROR,
|
||||||
"Unable to load directions: %s",
|
"Unable to load directions: %s",
|
||||||
@ -412,18 +417,18 @@ wmud_db_load_directions(GSList **directions, GError **err)
|
|||||||
gda_data_model_iter_move_next(iter);
|
gda_data_model_iter_move_next(iter);
|
||||||
|
|
||||||
while (gda_data_model_iter_is_valid(iter)) {
|
while (gda_data_model_iter_is_valid(iter)) {
|
||||||
const GValue *val;
|
const GValue *val;
|
||||||
wmudDirection *dir;
|
wmudDirection *dir;
|
||||||
|
|
||||||
dir = g_new0(wmudDirection, 1);
|
dir = g_new0(wmudDirection, 1);
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 0);
|
val = gda_data_model_iter_get_value_at(iter, 0);
|
||||||
dir->id = g_value_get_int(val);
|
dir->id = g_value_get_int(val);
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 1);
|
val = gda_data_model_iter_get_value_at(iter, 1);
|
||||||
dir->short_name = g_strdup(g_value_get_string(val));
|
dir->short_name = g_strdup(g_value_get_string(val));
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 2);
|
val = gda_data_model_iter_get_value_at(iter, 2);
|
||||||
dir->name = g_strdup(g_value_get_string(val));
|
dir->name = g_strdup(g_value_get_string(val));
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
||||||
@ -444,39 +449,40 @@ wmud_db_load_directions(GSList **directions, GError **err)
|
|||||||
gboolean
|
gboolean
|
||||||
wmud_db_load_areas(GSList **areas, GError **err)
|
wmud_db_load_areas(GSList **areas, GError **err)
|
||||||
{
|
{
|
||||||
GdaStatement *sth = NULL;
|
GdaStatement *sth = NULL;
|
||||||
GdaDataModel *res = NULL;
|
GdaDataModel *res = NULL;
|
||||||
GdaDataModelIter *iter;
|
GdaDataModelIter *iter;
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading areas");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading areas");
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err) {
|
||||||
g_set_error(err,
|
g_set_error(err,
|
||||||
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
"Database backend not initialized");
|
"Database backend not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sth = gda_sql_parser_parse_string(
|
sth = gda_sql_parser_parse_string(
|
||||||
parser,
|
parser,
|
||||||
"SELECT id, name FROM areas",
|
"SELECT id, name FROM areas",
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
||||||
iter = gda_data_model_create_iter(res);
|
iter = gda_data_model_create_iter(res);
|
||||||
gda_data_model_iter_move_next(iter);
|
gda_data_model_iter_move_next(iter);
|
||||||
|
|
||||||
while (gda_data_model_iter_is_valid(iter)) {
|
while (gda_data_model_iter_is_valid(iter)) {
|
||||||
const GValue *val;
|
const GValue *val;
|
||||||
wmudArea *area;
|
wmudArea *area;
|
||||||
|
|
||||||
area = g_new0(wmudArea, 1);
|
area = g_new0(wmudArea, 1);
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 0);
|
val = gda_data_model_iter_get_value_at(iter, 0);
|
||||||
area->id = g_value_get_int(val);
|
area->id = g_value_get_int(val);
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 1);
|
val = gda_data_model_iter_get_value_at(iter, 1);
|
||||||
area->name = g_strdup(g_value_get_string(val));
|
area->name = g_strdup(g_value_get_string(val));
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loaded area _%s_", area->name);
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loaded area _%s_", area->name);
|
||||||
@ -495,48 +501,49 @@ wmud_db_load_areas(GSList **areas, GError **err)
|
|||||||
gboolean
|
gboolean
|
||||||
wmud_db_load_rooms(GSList **rooms, GError **err)
|
wmud_db_load_rooms(GSList **rooms, GError **err)
|
||||||
{
|
{
|
||||||
GdaStatement *sth = NULL;
|
GdaStatement *sth = NULL;
|
||||||
GdaDataModel *res = NULL;
|
GdaDataModel *res = NULL;
|
||||||
GdaDataModelIter *iter;
|
GdaDataModelIter *iter;
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading rooms");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading rooms");
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err) {
|
||||||
g_set_error(err,
|
g_set_error(err,
|
||||||
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
"Database backend not initialized");
|
"Database backend not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sth = gda_sql_parser_parse_string(
|
sth = gda_sql_parser_parse_string(
|
||||||
parser,
|
parser,
|
||||||
"SELECT id, area, name, distant_description, close_description FROM rooms",
|
"SELECT id, area, name, distant_description, close_description FROM rooms",
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
||||||
iter = gda_data_model_create_iter(res);
|
iter = gda_data_model_create_iter(res);
|
||||||
gda_data_model_iter_move_next(iter);
|
gda_data_model_iter_move_next(iter);
|
||||||
|
|
||||||
while (gda_data_model_iter_is_valid(iter)) {
|
while (gda_data_model_iter_is_valid(iter)) {
|
||||||
const GValue *val;
|
const GValue *val;
|
||||||
wmudRoom *room;
|
wmudRoom *room;
|
||||||
|
|
||||||
room = g_new0(wmudRoom, 1);
|
room = g_new0(wmudRoom, 1);
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 0);
|
val = gda_data_model_iter_get_value_at(iter, 0);
|
||||||
room->id = g_value_get_int(val);
|
room->id = g_value_get_int(val);
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 1);
|
val = gda_data_model_iter_get_value_at(iter, 1);
|
||||||
room->area_id = g_value_get_int(val);
|
room->area_id = g_value_get_int(val);
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 2);
|
val = gda_data_model_iter_get_value_at(iter, 2);
|
||||||
room->name = g_strdup(g_value_get_string(val));
|
room->name = g_strdup(g_value_get_string(val));
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 3);
|
val = gda_data_model_iter_get_value_at(iter, 3);
|
||||||
room->distant_description = g_strdup(g_value_get_string(val));
|
room->distant_description = g_strdup(g_value_get_string(val));
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 4);
|
val = gda_data_model_iter_get_value_at(iter, 4);
|
||||||
room->close_description = g_strdup(g_value_get_string(val));
|
room->close_description = g_strdup(g_value_get_string(val));
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
||||||
@ -558,42 +565,43 @@ wmud_db_load_rooms(GSList **rooms, GError **err)
|
|||||||
gboolean
|
gboolean
|
||||||
wmud_db_load_exits(GSList **exits, GError **err)
|
wmud_db_load_exits(GSList **exits, GError **err)
|
||||||
{
|
{
|
||||||
GdaStatement *sth = NULL;
|
GdaStatement *sth = NULL;
|
||||||
GdaDataModel *res = NULL;
|
GdaDataModel *res = NULL;
|
||||||
GdaDataModelIter *iter;
|
GdaDataModelIter *iter;
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading exits");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading exits");
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err) {
|
||||||
g_set_error(err,
|
g_set_error(err,
|
||||||
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
"Database backend not initialized");
|
"Database backend not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sth = gda_sql_parser_parse_string(
|
sth = gda_sql_parser_parse_string(
|
||||||
parser,
|
parser,
|
||||||
"SELECT room_id, direction, other_side FROM room_exits",
|
"SELECT room_id, direction, other_side FROM room_exits",
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
||||||
iter = gda_data_model_create_iter(res);
|
iter = gda_data_model_create_iter(res);
|
||||||
gda_data_model_iter_move_next(iter);
|
gda_data_model_iter_move_next(iter);
|
||||||
|
|
||||||
while (gda_data_model_iter_is_valid(iter)) {
|
while (gda_data_model_iter_is_valid(iter)) {
|
||||||
const GValue *val;
|
const GValue *val;
|
||||||
wmudExit *room_exit;
|
wmudExit *room_exit;
|
||||||
|
|
||||||
room_exit = g_new0(wmudExit, 1);
|
room_exit = g_new0(wmudExit, 1);
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 0);
|
val = gda_data_model_iter_get_value_at(iter, 0);
|
||||||
room_exit->source_room_id = g_value_get_int(val);
|
room_exit->source_room_id = g_value_get_int(val);
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 1);
|
val = gda_data_model_iter_get_value_at(iter, 1);
|
||||||
room_exit->direction_id = g_value_get_int(val);
|
room_exit->direction_id = g_value_get_int(val);
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 2);
|
val = gda_data_model_iter_get_value_at(iter, 2);
|
||||||
room_exit->destination_room_id = g_value_get_int(val);
|
room_exit->destination_room_id = g_value_get_int(val);
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
||||||
@ -616,40 +624,41 @@ wmud_db_load_exits(GSList **exits, GError **err)
|
|||||||
gboolean
|
gboolean
|
||||||
wmud_db_load_planet_planes(GSList **planet_planes, GError **err)
|
wmud_db_load_planet_planes(GSList **planet_planes, GError **err)
|
||||||
{
|
{
|
||||||
GdaStatement *sth = NULL;
|
GdaStatement *sth = NULL;
|
||||||
GdaDataModel *res = NULL;
|
GdaDataModel *res = NULL;
|
||||||
GdaDataModelIter *iter;
|
GdaDataModelIter *iter;
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
||||||
"Loading planet<->plane associations");
|
"Loading planet<->plane associations");
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err) {
|
||||||
g_set_error(err,
|
g_set_error(err,
|
||||||
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
"Database backend not initialized");
|
"Database backend not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sth = gda_sql_parser_parse_string(
|
sth = gda_sql_parser_parse_string(
|
||||||
parser,
|
parser,
|
||||||
"SELECT planet_id, plane_id FROM planet_planes",
|
"SELECT planet_id, plane_id FROM planet_planes",
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
||||||
iter = gda_data_model_create_iter(res);
|
iter = gda_data_model_create_iter(res);
|
||||||
gda_data_model_iter_move_next(iter);
|
gda_data_model_iter_move_next(iter);
|
||||||
|
|
||||||
while (gda_data_model_iter_is_valid(iter)) {
|
while (gda_data_model_iter_is_valid(iter)) {
|
||||||
const GValue *val;
|
const GValue *val;
|
||||||
wmudPlanetPlaneAssoc *planet_plane;
|
wmudPlanetPlaneAssoc *planet_plane;
|
||||||
|
|
||||||
planet_plane = g_new0(wmudPlanetPlaneAssoc, 1);
|
planet_plane = g_new0(wmudPlanetPlaneAssoc, 1);
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 0);
|
val = gda_data_model_iter_get_value_at(iter, 0);
|
||||||
planet_plane->planet_id = g_value_get_int(val);
|
planet_plane->planet_id = g_value_get_int(val);
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 1);
|
val = gda_data_model_iter_get_value_at(iter, 1);
|
||||||
planet_plane->plane_id = g_value_get_int(val);
|
planet_plane->plane_id = g_value_get_int(val);
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
||||||
@ -671,51 +680,52 @@ wmud_db_load_planet_planes(GSList **planet_planes, GError **err)
|
|||||||
gboolean
|
gboolean
|
||||||
wmud_db_load_menu(GSList **menu_items, GError **err)
|
wmud_db_load_menu(GSList **menu_items, GError **err)
|
||||||
{
|
{
|
||||||
GdaStatement *sth = NULL;
|
GdaStatement *sth = NULL;
|
||||||
GdaDataModel *res = NULL;
|
GdaDataModel *res = NULL;
|
||||||
GdaDataModelIter *iter;
|
GdaDataModelIter *iter;
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading menu items");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading menu items");
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err) {
|
||||||
g_set_error(err,
|
g_set_error(err,
|
||||||
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
"Database backend not initialized");
|
"Database backend not initialized");
|
||||||
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sth = gda_sql_parser_parse_string(
|
sth = gda_sql_parser_parse_string(
|
||||||
parser,
|
parser,
|
||||||
"SELECT id, menuchar, need_active_char, placement, display_text, fnctn FROM menu ORDER BY placement",
|
"SELECT id, menuchar, need_active_char, placement, display_text, fnctn FROM menu ORDER BY placement",
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
||||||
iter = gda_data_model_create_iter(res);
|
iter = gda_data_model_create_iter(res);
|
||||||
gda_data_model_iter_move_next(iter);
|
gda_data_model_iter_move_next(iter);
|
||||||
|
|
||||||
while (gda_data_model_iter_is_valid(iter)) {
|
while (gda_data_model_iter_is_valid(iter)) {
|
||||||
const GValue *val;
|
const GValue *val;
|
||||||
wmudMenu *menu_item;
|
wmudMenu *menu_item;
|
||||||
|
|
||||||
menu_item = g_new0(wmudMenu, 1);
|
menu_item = g_new0(wmudMenu, 1);
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 0);
|
val = gda_data_model_iter_get_value_at(iter, 0);
|
||||||
menu_item->id = g_value_get_int(val);
|
menu_item->id = g_value_get_int(val);
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 1);
|
val = gda_data_model_iter_get_value_at(iter, 1);
|
||||||
menu_item->menuchar = *(g_value_get_string(val));
|
menu_item->menuchar = *(g_value_get_string(val));
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 2);
|
val = gda_data_model_iter_get_value_at(iter, 2);
|
||||||
menu_item->need_active_char = g_value_get_boolean(val);
|
menu_item->need_active_char = g_value_get_boolean(val);
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 3);
|
val = gda_data_model_iter_get_value_at(iter, 3);
|
||||||
menu_item->placement = g_value_get_int(val);
|
menu_item->placement = g_value_get_int(val);
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 4);
|
val = gda_data_model_iter_get_value_at(iter, 4);
|
||||||
menu_item->text = g_strdup(g_value_get_string(val));
|
menu_item->text = g_strdup(g_value_get_string(val));
|
||||||
|
|
||||||
val = gda_data_model_iter_get_value_at(iter, 5);
|
val = gda_data_model_iter_get_value_at(iter, 5);
|
||||||
menu_item->func = g_strdup(g_value_get_string(val));
|
menu_item->func = g_strdup(g_value_get_string(val));
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
||||||
|
@ -6,28 +6,28 @@
|
|||||||
|
|
||||||
/* enumerations from "wmudclientstate.h" */
|
/* enumerations from "wmudclientstate.h" */
|
||||||
GType
|
GType
|
||||||
wmud_client_state_get_type (void)
|
wmud_client_state_get_type(void)
|
||||||
{
|
{
|
||||||
static volatile gsize g_define_type_id__volatile = 0;
|
static volatile gsize g_define_type_id__volatile = 0;
|
||||||
|
|
||||||
if (g_once_init_enter(&g_define_type_id__volatile)) {
|
if (g_once_init_enter(&g_define_type_id__volatile)) {
|
||||||
static const GEnumValue values[] = {
|
static const GEnumValue values[] = {
|
||||||
{ WMUD_CLIENT_STATE_FRESH, "WMUD_CLIENT_STATE_FRESH", "fresh" },
|
{ WMUD_CLIENT_STATE_FRESH, "WMUD_CLIENT_STATE_FRESH", "fresh" },
|
||||||
{ WMUD_CLIENT_STATE_PASSWAIT, "WMUD_CLIENT_STATE_PASSWAIT", "passwait" },
|
{ WMUD_CLIENT_STATE_PASSWAIT, "WMUD_CLIENT_STATE_PASSWAIT", "passwait" },
|
||||||
{ WMUD_CLIENT_STATE_MENU, "WMUD_CLIENT_STATE_MENU", "menu" },
|
{ WMUD_CLIENT_STATE_MENU, "WMUD_CLIENT_STATE_MENU", "menu" },
|
||||||
{ WMUD_CLIENT_STATE_INGAME, "WMUD_CLIENT_STATE_INGAME", "ingame" },
|
{ WMUD_CLIENT_STATE_INGAME, "WMUD_CLIENT_STATE_INGAME", "ingame" },
|
||||||
{ WMUD_CLIENT_STATE_YESNO, "WMUD_CLIENT_STATE_YESNO", "yesno" },
|
{ WMUD_CLIENT_STATE_YESNO, "WMUD_CLIENT_STATE_YESNO", "yesno" },
|
||||||
{ WMUD_CLIENT_STATE_REGISTERING, "WMUD_CLIENT_STATE_REGISTERING", "registering" },
|
{ WMUD_CLIENT_STATE_REGISTERING, "WMUD_CLIENT_STATE_REGISTERING", "registering" },
|
||||||
{ WMUD_CLIENT_STATE_REGEMAIL_CONFIRM, "WMUD_CLIENT_STATE_REGEMAIL_CONFIRM", "regemail-confirm" },
|
{ WMUD_CLIENT_STATE_REGEMAIL_CONFIRM, "WMUD_CLIENT_STATE_REGEMAIL_CONFIRM", "regemail-confirm" },
|
||||||
{ 0, NULL, NULL }
|
{ 0, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
GType g_define_type_id = g_enum_register_static(g_intern_static_string("WmudClientState"), values);
|
GType g_define_type_id = g_enum_register_static(g_intern_static_string("WmudClientState"), values);
|
||||||
|
|
||||||
g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
|
g_once_init_leave(&g_define_type_id__volatile, g_define_type_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return g_define_type_id__volatile;
|
return g_define_type_id__volatile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
struct AcceptData {
|
struct AcceptData {
|
||||||
GMainContext *context;
|
GMainContext *context;
|
||||||
GSocketListener *listener;
|
GSocketListener *listener;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ struct AcceptData {
|
|||||||
*
|
*
|
||||||
* The full #GSList of the currently connected #WmudClient objects.
|
* The full #GSList of the currently connected #WmudClient objects.
|
||||||
*/
|
*/
|
||||||
GSList *clients = NULL;
|
GSList *clients = NULL;
|
||||||
|
|
||||||
static GRegex *email_regex = NULL;
|
static GRegex *email_regex = NULL;
|
||||||
|
|
||||||
@ -91,11 +91,11 @@ hup_client(WmudClient *client)
|
|||||||
static void
|
static void
|
||||||
recv_client(WmudClient *client)
|
recv_client(WmudClient *client)
|
||||||
{
|
{
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
GSocket *client_socket;
|
GSocket *client_socket;
|
||||||
gssize len;
|
gssize len;
|
||||||
gchar *buf2;
|
gchar *buf2;
|
||||||
gchar *buf = g_malloc0(sizeof(gchar) * (MAX_RECV_LEN + 1));
|
gchar *buf = g_malloc0(sizeof(gchar) * (MAX_RECV_LEN + 1));
|
||||||
|
|
||||||
client_socket = wmud_client_get_socket(client);
|
client_socket = wmud_client_get_socket(client);
|
||||||
|
|
||||||
@ -120,29 +120,32 @@ recv_client(WmudClient *client)
|
|||||||
sloc = -1;
|
sloc = -1;
|
||||||
|
|
||||||
if ((r < n) && r) {
|
if ((r < n) && r) {
|
||||||
if (wmud_client_get_buffer_length(client) > 0)
|
if (wmud_client_get_buffer_length(client) > 0) {
|
||||||
g_string_append_len(wmud_client_get_buffer(client),
|
g_string_append_len(wmud_client_get_buffer(client),
|
||||||
buf2,
|
buf2,
|
||||||
(r - buf2));
|
(r - buf2));
|
||||||
else
|
} else {
|
||||||
g_string_overwrite_len(
|
g_string_overwrite_len(
|
||||||
wmud_client_get_buffer(client),
|
wmud_client_get_buffer(client),
|
||||||
0,
|
0,
|
||||||
buf2,
|
buf2,
|
||||||
(r - buf2));
|
(r - buf2));
|
||||||
|
}
|
||||||
|
|
||||||
buf2 = r;
|
buf2 = r;
|
||||||
} else if (n) {
|
} else if (n) {
|
||||||
if (wmud_client_get_buffer_length(client) > 0)
|
if (wmud_client_get_buffer_length(client) > 0) {
|
||||||
g_string_append_len(
|
g_string_append_len(
|
||||||
wmud_client_get_buffer(client),
|
wmud_client_get_buffer(client),
|
||||||
buf2,
|
buf2,
|
||||||
(n - buf2));
|
(n - buf2));
|
||||||
else
|
} else {
|
||||||
g_string_overwrite_len(
|
g_string_overwrite_len(
|
||||||
wmud_client_get_buffer(client),
|
wmud_client_get_buffer(client),
|
||||||
0,
|
0,
|
||||||
buf2,
|
buf2,
|
||||||
(n - buf2));
|
(n - buf2));
|
||||||
|
}
|
||||||
buf2 = n;
|
buf2 = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,57 +154,67 @@ recv_client(WmudClient *client)
|
|||||||
guchar c = (wmud_client_get_buffer(client)->str)[i];
|
guchar c = (wmud_client_get_buffer(client)->str)[i];
|
||||||
|
|
||||||
if ((c >= 240) || (c == 1)) {
|
if ((c >= 240) || (c == 1)) {
|
||||||
if (sloc == -1)
|
if (sloc == -1) {
|
||||||
sloc = i;
|
sloc = i;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (sloc != -1) {
|
if (sloc != -1) {
|
||||||
g_string_erase(
|
g_string_erase(
|
||||||
wmud_client_get_buffer(client),
|
wmud_client_get_buffer(client),
|
||||||
sloc,
|
sloc,
|
||||||
i - sloc);
|
i - sloc);
|
||||||
sloc = -1;
|
sloc = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sloc != -1)
|
if (sloc != -1) {
|
||||||
g_string_erase(wmud_client_get_buffer(client), sloc, -1);
|
g_string_erase(wmud_client_get_buffer(client), sloc, -1);
|
||||||
|
}
|
||||||
|
|
||||||
switch (wmud_client_get_state(client))
|
switch (wmud_client_get_state(client)) {
|
||||||
{
|
|
||||||
case WMUD_CLIENT_STATE_FRESH:
|
case WMUD_CLIENT_STATE_FRESH:
|
||||||
state_fresh(client);
|
state_fresh(client);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case WMUD_CLIENT_STATE_PASSWAIT:
|
case WMUD_CLIENT_STATE_PASSWAIT:
|
||||||
state_passwait(client);
|
state_passwait(client);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case WMUD_CLIENT_STATE_MENU:
|
case WMUD_CLIENT_STATE_MENU:
|
||||||
state_menu(client);
|
state_menu(client);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case WMUD_CLIENT_STATE_INGAME:
|
case WMUD_CLIENT_STATE_INGAME:
|
||||||
wmud_interpret_game_command(client);
|
wmud_interpret_game_command(client);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case WMUD_CLIENT_STATE_YESNO:
|
case WMUD_CLIENT_STATE_YESNO:
|
||||||
state_yesno(client);
|
state_yesno(client);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case WMUD_CLIENT_STATE_REGISTERING:
|
case WMUD_CLIENT_STATE_REGISTERING:
|
||||||
state_registering(client);
|
state_registering(client);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case WMUD_CLIENT_STATE_REGEMAIL_CONFIRM:
|
case WMUD_CLIENT_STATE_REGEMAIL_CONFIRM:
|
||||||
state_regemail_confirm(client);
|
state_regemail_confirm(client);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
g_string_erase(wmud_client_get_buffer(client), 0, -1);
|
g_string_erase(wmud_client_get_buffer(client), 0, -1);
|
||||||
|
|
||||||
for (; ((*buf2 == '\r') || (*buf2 == '\n')) && *buf2; buf2++);
|
for (; ((*buf2 == '\r') || (*buf2 == '\n')) && *buf2; buf2++);
|
||||||
|
|
||||||
if (!*buf2)
|
if (!*buf2) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (wmud_client_get_buffer_length(client) > 0)
|
if (wmud_client_get_buffer_length(client) > 0) {
|
||||||
g_string_append(wmud_client_get_buffer(client), buf2);
|
g_string_append(wmud_client_get_buffer(client), buf2);
|
||||||
else
|
} else {
|
||||||
g_string_overwrite(wmud_client_get_buffer(client), 0, buf2);
|
g_string_overwrite(wmud_client_get_buffer(client), 0, buf2);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -222,14 +235,14 @@ recv_client(WmudClient *client)
|
|||||||
* Return value: this function always returns %TRUE
|
* Return value: this function always returns %TRUE
|
||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
game_source_callback(GSocket *socket,
|
game_source_callback(GSocket *socket,
|
||||||
GIOCondition condition,
|
GIOCondition condition,
|
||||||
struct AcceptData *accept_data)
|
struct AcceptData *accept_data)
|
||||||
{
|
{
|
||||||
GSocket *client_socket;
|
GSocket *client_socket;
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
GSocketAddress *remote_addr;
|
GSocketAddress *remote_addr;
|
||||||
WmudClient *client;
|
WmudClient *client;
|
||||||
|
|
||||||
/* This function should never return an error. If so, it is a huge bug,
|
/* This function should never return an error. If so, it is a huge bug,
|
||||||
* and will trigger a higher level error. */
|
* and will trigger a higher level error. */
|
||||||
@ -247,19 +260,20 @@ game_source_callback(GSocket *socket,
|
|||||||
|
|
||||||
if ((remote_addr = g_socket_get_remote_address(client_socket, &err)) != NULL) {
|
if ((remote_addr = g_socket_get_remote_address(client_socket, &err)) != NULL) {
|
||||||
GInetAddress *addr;
|
GInetAddress *addr;
|
||||||
gchar *ip_addr;
|
gchar *ip_addr;
|
||||||
|
|
||||||
addr = g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(remote_addr));
|
addr = g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(remote_addr));
|
||||||
ip_addr = g_inet_address_to_string(addr);
|
ip_addr = g_inet_address_to_string(addr);
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "New game connection from %s", ip_addr);
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "New game connection from %s", ip_addr);
|
||||||
g_free(ip_addr);
|
g_free(ip_addr);
|
||||||
g_object_unref(addr);
|
g_object_unref(addr);
|
||||||
g_object_unref(remote_addr);
|
g_object_unref(remote_addr);
|
||||||
} else {
|
} else {
|
||||||
if (err)
|
if (err) {
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "New game connection. The remote address is unknown. This is a bug. Message from upper level: %s", err->message);
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "New game connection. The remote address is unknown. This is a bug. Message from upper level: %s", err->message);
|
||||||
else
|
} else {
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "New game connection. The remote address is unknown. This is a bug.");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "New game connection. The remote address is unknown. This is a bug.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_clear_error(&err);
|
g_clear_error(&err);
|
||||||
@ -284,34 +298,34 @@ gboolean
|
|||||||
wmud_networking_init(guint port_number, GMainContext *game_context, GSList *menu_items, GError **err)
|
wmud_networking_init(guint port_number, GMainContext *game_context, GSList *menu_items, GError **err)
|
||||||
{
|
{
|
||||||
struct AcceptData *accept_data;
|
struct AcceptData *accept_data;
|
||||||
GSocketListener *game_listener;
|
GSocketListener *game_listener;
|
||||||
gboolean need_ipv4_socket = TRUE;
|
gboolean need_ipv4_socket = TRUE;
|
||||||
GSocket *game_socket6,
|
GSocket *game_socket6,
|
||||||
*game_socket4;
|
*game_socket4;
|
||||||
GError *in_err = NULL;
|
GError *in_err = NULL;
|
||||||
GSource *game_net_source4 = NULL,
|
GSource *game_net_source4 = NULL,
|
||||||
*game_net_source6 = NULL;
|
*game_net_source6 = NULL;
|
||||||
|
|
||||||
clients = NULL;
|
clients = NULL;
|
||||||
game_listener = g_socket_listener_new();
|
game_listener = g_socket_listener_new();
|
||||||
|
|
||||||
/* The following snippet is borrowed from GLib 2.30's gsocketlistener.c
|
/* The following snippet is borrowed from GLib 2.30's gsocketlistener.c
|
||||||
* code, to create the necessary sockets to listen on both IPv4 and
|
* code, to create the necessary sockets to listen on both IPv4 and
|
||||||
* IPv6 address */
|
* IPv6 address */
|
||||||
if ((game_socket6 = g_socket_new(G_SOCKET_FAMILY_IPV6, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_DEFAULT, NULL)) != NULL) {
|
if ((game_socket6 = g_socket_new(G_SOCKET_FAMILY_IPV6, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_DEFAULT, NULL)) != NULL) {
|
||||||
GInetAddress *inet_address;
|
GInetAddress *inet_address;
|
||||||
GSocketAddress *address;
|
GSocketAddress *address;
|
||||||
gboolean result;
|
gboolean result;
|
||||||
|
|
||||||
inet_address = g_inet_address_new_any(G_SOCKET_FAMILY_IPV6);
|
inet_address = g_inet_address_new_any(G_SOCKET_FAMILY_IPV6);
|
||||||
address = g_inet_socket_address_new(inet_address, port_number);
|
address = g_inet_socket_address_new(inet_address, port_number);
|
||||||
g_object_unref(inet_address);
|
g_object_unref(inet_address);
|
||||||
|
|
||||||
g_socket_set_listen_backlog(game_socket6, 10);
|
g_socket_set_listen_backlog(game_socket6, 10);
|
||||||
|
|
||||||
result =
|
result =
|
||||||
g_socket_bind(game_socket6, address, TRUE, NULL)
|
g_socket_bind(game_socket6, address, TRUE, NULL) &&
|
||||||
&& g_socket_listen(game_socket6, NULL);
|
g_socket_listen(game_socket6, NULL);
|
||||||
|
|
||||||
g_object_unref(address);
|
g_object_unref(address);
|
||||||
|
|
||||||
@ -322,8 +336,9 @@ wmud_networking_init(guint port_number, GMainContext *game_context, GSList *menu
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_socket_speaks_ipv4(game_socket6))
|
if (g_socket_speaks_ipv4(game_socket6)) {
|
||||||
need_ipv4_socket = FALSE;
|
need_ipv4_socket = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
game_net_source6 = g_socket_create_source(game_socket6, G_IO_IN, NULL);
|
game_net_source6 = g_socket_create_source(game_socket6, G_IO_IN, NULL);
|
||||||
|
|
||||||
@ -334,26 +349,27 @@ wmud_networking_init(guint port_number, GMainContext *game_context, GSList *menu
|
|||||||
|
|
||||||
if (need_ipv4_socket) {
|
if (need_ipv4_socket) {
|
||||||
if ((game_socket4 = g_socket_new(G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_DEFAULT, NULL)) != NULL) {
|
if ((game_socket4 = g_socket_new(G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_DEFAULT, NULL)) != NULL) {
|
||||||
GInetAddress *inet_address;
|
GInetAddress *inet_address;
|
||||||
GSocketAddress *address;
|
GSocketAddress *address;
|
||||||
gboolean result;
|
gboolean result;
|
||||||
|
|
||||||
inet_address = g_inet_address_new_any(G_SOCKET_FAMILY_IPV4);
|
inet_address = g_inet_address_new_any(G_SOCKET_FAMILY_IPV4);
|
||||||
address = g_inet_socket_address_new(inet_address, port_number);
|
address = g_inet_socket_address_new(inet_address, port_number);
|
||||||
g_object_unref(inet_address);
|
g_object_unref(inet_address);
|
||||||
|
|
||||||
g_socket_set_listen_backlog(game_socket4, 10);
|
g_socket_set_listen_backlog(game_socket4, 10);
|
||||||
|
|
||||||
result = g_socket_bind(game_socket4, address, TRUE, NULL)
|
result = g_socket_bind(game_socket4, address, TRUE, NULL) &&
|
||||||
&& g_socket_listen(game_socket4, NULL);
|
g_socket_listen(game_socket4, NULL);
|
||||||
|
|
||||||
g_object_unref(address);
|
g_object_unref(address);
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
g_object_unref(game_socket4);
|
g_object_unref(game_socket4);
|
||||||
|
|
||||||
if (!game_socket6)
|
if (!game_socket6) {
|
||||||
g_object_unref(game_socket6);
|
g_object_unref(game_socket6);
|
||||||
|
}
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Unable to create listener IPv4 socket!\n");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Unable to create listener IPv4 socket!\n");
|
||||||
|
|
||||||
@ -364,15 +380,16 @@ wmud_networking_init(guint port_number, GMainContext *game_context, GSList *menu
|
|||||||
g_socket_listener_add_socket(game_listener, game_socket4, NULL, NULL);
|
g_socket_listener_add_socket(game_listener, game_socket4, NULL, NULL);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (game_socket6 != NULL)
|
if (game_socket6 != NULL) {
|
||||||
g_clear_error(&in_err);
|
g_clear_error(&in_err);
|
||||||
else
|
} else {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
accept_data = g_new(struct AcceptData, 1);
|
accept_data = g_new(struct AcceptData, 1);
|
||||||
accept_data->listener = game_listener;
|
accept_data->listener = game_listener;
|
||||||
accept_data->context = game_context;
|
accept_data->context = game_context;
|
||||||
|
|
||||||
if (game_net_source6) {
|
if (game_net_source6) {
|
||||||
g_source_set_callback(game_net_source6, (GSourceFunc)game_source_callback, (gpointer)accept_data, NULL);
|
g_source_set_callback(game_net_source6, (GSourceFunc)game_source_callback, (gpointer)accept_data, NULL);
|
||||||
@ -423,12 +440,12 @@ state_fresh(WmudClient *client)
|
|||||||
|
|
||||||
if ((player = wmud_player_exists(wmud_client_get_buffer(client)->str)) != NULL) {
|
if ((player = wmud_player_exists(wmud_client_get_buffer(client)->str)) != NULL) {
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Trying to"
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Trying to"
|
||||||
" login with playername '%s'",
|
" login with playername '%s'",
|
||||||
wmud_client_get_buffer(client)->str);
|
wmud_client_get_buffer(client)->str);
|
||||||
|
|
||||||
if (wmud_player_get_cpassword(player) == NULL) {
|
if (wmud_player_get_cpassword(player) == NULL) {
|
||||||
wmud_client_send(client, "Your registration is"
|
wmud_client_send(client, "Your registration is"
|
||||||
" not finished yet.\r\n");
|
" not finished yet.\r\n");
|
||||||
remove_client(client, TRUE);
|
remove_client(client, TRUE);
|
||||||
} else {
|
} else {
|
||||||
wmud_client_set_state(client, WMUD_CLIENT_STATE_PASSWAIT);
|
wmud_client_set_state(client, WMUD_CLIENT_STATE_PASSWAIT);
|
||||||
@ -457,21 +474,21 @@ state_passwait(WmudClient *client)
|
|||||||
player = wmud_client_get_player(client);
|
player = wmud_client_get_player(client);
|
||||||
|
|
||||||
if (wmud_player_password_valid(player, wmud_client_get_buffer(client)->str)) {
|
if (wmud_player_password_valid(player, wmud_client_get_buffer(client)->str)) {
|
||||||
gint fail_count;
|
gint fail_count;
|
||||||
GSocketAddress *socket_address;
|
GSocketAddress *socket_address;
|
||||||
GInetAddress *inet_address;
|
GInetAddress *inet_address;
|
||||||
gchar *ip_addr;
|
gchar *ip_addr;
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
|
|
||||||
wmud_client_send(client, "%c%c%c\r\nLogin successful."
|
wmud_client_send(client, "%c%c%c\r\nLogin successful."
|
||||||
"\r\n", TELNET_IAC, TELNET_WONT,
|
"\r\n", TELNET_IAC, TELNET_WONT,
|
||||||
TELNET_ECHO);
|
TELNET_ECHO);
|
||||||
wmud_client_set_authenticated(client, TRUE);
|
wmud_client_set_authenticated(client, TRUE);
|
||||||
|
|
||||||
socket_address = g_socket_get_remote_address(wmud_client_get_socket(client), &err);
|
socket_address = g_socket_get_remote_address(wmud_client_get_socket(client), &err);
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "socket family: %d", g_socket_address_get_family(socket_address));
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "socket family: %d", g_socket_address_get_family(socket_address));
|
||||||
inet_address = g_object_ref(g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(socket_address)));
|
inet_address = g_object_ref(g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(socket_address)));
|
||||||
ip_addr = g_inet_address_to_string(inet_address);
|
ip_addr = g_inet_address_to_string(inet_address);
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Login by %s from %s", wmud_player_get_player_name(player), ip_addr);
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Login by %s from %s", wmud_player_get_player_name(player), ip_addr);
|
||||||
|
|
||||||
@ -480,30 +497,30 @@ state_passwait(WmudClient *client)
|
|||||||
|
|
||||||
if ((fail_count = wmud_player_get_fail_count(player)) > 0) {
|
if ((fail_count = wmud_player_get_fail_count(player)) > 0) {
|
||||||
wmud_client_send(client, "There %s %d failed"
|
wmud_client_send(client, "There %s %d failed"
|
||||||
" login attempt%s with your"
|
" login attempt%s with your"
|
||||||
" account since your last"
|
" account since your last"
|
||||||
" visit\r\n",
|
" visit\r\n",
|
||||||
(fail_count == 1) ? "was" : "were",
|
(fail_count == 1) ? "was" : "were",
|
||||||
fail_count,
|
fail_count,
|
||||||
(fail_count == 1) ? "" : "s");
|
(fail_count == 1) ? "" : "s");
|
||||||
}
|
}
|
||||||
|
|
||||||
wmud_text_send_to_client("motd", client);
|
wmud_text_send_to_client("motd", client);
|
||||||
wmud_menu_present(client);
|
wmud_menu_present(client);
|
||||||
} else {
|
} else {
|
||||||
wmud_client_send(client, "%c%c%cThis password doesn't"
|
wmud_client_send(client, "%c%c%cThis password doesn't"
|
||||||
" seem to be valid. Let's try it again..."
|
" seem to be valid. Let's try it again..."
|
||||||
" \r\nBy what name would you like to be"
|
" \r\nBy what name would you like to be"
|
||||||
" be called? ", TELNET_IAC,
|
" be called? ", TELNET_IAC,
|
||||||
TELNET_WONT, TELNET_ECHO);
|
TELNET_WONT, TELNET_ECHO);
|
||||||
wmud_client_set_state(client, WMUD_CLIENT_STATE_FRESH);
|
wmud_client_set_state(client, WMUD_CLIENT_STATE_FRESH);
|
||||||
wmud_player_increase_fail_count(player);
|
wmud_player_increase_fail_count(player);
|
||||||
wmud_client_increase_login_fail_count(client);
|
wmud_client_increase_login_fail_count(client);
|
||||||
if (wmud_client_get_login_fail_count(client) == 3) {
|
if (wmud_client_get_login_fail_count(client) == 3) {
|
||||||
wmud_client_send(client, "You are trying "
|
wmud_client_send(client, "You are trying "
|
||||||
" these bad passwords for"
|
" these bad passwords for"
|
||||||
" too many times. Please"
|
" too many times. Please"
|
||||||
" stop that!\r\n");
|
" stop that!\r\n");
|
||||||
remove_client(client, TRUE);
|
remove_client(client, TRUE);
|
||||||
|
|
||||||
/* TODO: Increase IP fail count, and ban IP if it's too high */
|
/* TODO: Increase IP fail count, and ban IP if it's too high */
|
||||||
@ -515,7 +532,7 @@ state_passwait(WmudClient *client)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
wmud_client_send(client, "\r\nEmpty passwords are"
|
wmud_client_send(client, "\r\nEmpty passwords are"
|
||||||
" not valid.\r\nTry again: ");
|
" not valid.\r\nTry again: ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -524,51 +541,55 @@ state_menu(WmudClient *client)
|
|||||||
{
|
{
|
||||||
gchar *menu_command;
|
gchar *menu_command;
|
||||||
|
|
||||||
if ((menu_command = wmud_menu_get_command_by_menuchar(*(wmud_client_get_buffer(client)->str), game_menu)) != NULL)
|
if ((menu_command = wmud_menu_get_command_by_menuchar(*(wmud_client_get_buffer(client)->str), game_menu)) != NULL) {
|
||||||
wmud_menu_execute_command(client, menu_command);
|
wmud_menu_execute_command(client, menu_command);
|
||||||
else
|
} else {
|
||||||
wmud_client_send(client, "Unknown menu command.\r\n");
|
wmud_client_send(client, "Unknown menu command.\r\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
state_yesno(WmudClient *client)
|
state_yesno(WmudClient *client)
|
||||||
{
|
{
|
||||||
if (g_ascii_strcasecmp(wmud_client_get_buffer(client)->str, "y") == 0)
|
if (g_ascii_strcasecmp(wmud_client_get_buffer(client)->str, "y") == 0) {
|
||||||
(wmud_client_get_yesno_callback(client))(client, TRUE);
|
(wmud_client_get_yesno_callback(client))(client, TRUE);
|
||||||
else if (g_ascii_strcasecmp(wmud_client_get_buffer(client)->str, "n") == 0)
|
} else if (g_ascii_strcasecmp(wmud_client_get_buffer(client)->str, "n") == 0) {
|
||||||
(wmud_client_get_yesno_callback(client))(client, FALSE);
|
(wmud_client_get_yesno_callback(client))(client, FALSE);
|
||||||
else
|
} else {
|
||||||
wmud_client_send(client, "Please enter a 'Y' or 'N'"
|
wmud_client_send(client, "Please enter a 'Y' or 'N'"
|
||||||
" character: ");
|
" character: ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
state_registering(WmudClient *client)
|
state_registering(WmudClient *client)
|
||||||
{
|
{
|
||||||
if (!*(wmud_client_get_buffer(client)->str) && (wmud_client_get_bademail(client) == TRUE))
|
if (!*(wmud_client_get_buffer(client)->str) && (wmud_client_get_bademail(client) == TRUE)) {
|
||||||
remove_client(client, TRUE);
|
remove_client(client, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
if (g_regex_match(email_regex, wmud_client_get_buffer(client)->str, 0, NULL)) {
|
if (g_regex_match(email_regex, wmud_client_get_buffer(client)->str, 0, NULL)) {
|
||||||
wmud_player_set_email(wmud_client_get_player(client), wmud_client_get_buffer(client)->str);
|
wmud_player_set_email(wmud_client_get_player(client), wmud_client_get_buffer(client)->str);
|
||||||
wmud_client_set_state(client, WMUD_CLIENT_STATE_REGEMAIL_CONFIRM);
|
wmud_client_set_state(client, WMUD_CLIENT_STATE_REGEMAIL_CONFIRM);
|
||||||
wmud_client_send(client, "It seems to be a valid"
|
wmud_client_send(client, "It seems to be a valid"
|
||||||
" address to me, but could you"
|
" address to me, but could you"
|
||||||
" write it again? ");
|
" write it again? ");
|
||||||
} else {
|
} else {
|
||||||
wmud_client_send(client, "\r\nSorry, but this"
|
wmud_client_send(client, "\r\nSorry, but this"
|
||||||
"e-mail address doesn't seem to be"
|
"e-mail address doesn't seem to be"
|
||||||
" valid to me.\r\n\r\nIf you think"
|
" valid to me.\r\n\r\nIf you think"
|
||||||
" this is a valid address, simply"
|
" this is a valid address, simply"
|
||||||
" press enter to quit, and send an"
|
" press enter to quit, and send an"
|
||||||
" e-mail to %s from that address,"
|
" e-mail to %s from that address,"
|
||||||
" so we can fix our e-mail"
|
" so we can fix our e-mail"
|
||||||
" validation code.\r\n\r\nIf you"
|
" validation code.\r\n\r\nIf you"
|
||||||
" just mistyped your address, type"
|
" just mistyped your address, type"
|
||||||
" it now: ",
|
" it now: ",
|
||||||
active_config->admin_email);
|
active_config->admin_email);
|
||||||
|
|
||||||
if (*(wmud_client_get_buffer(client)->str))
|
if (*(wmud_client_get_buffer(client)->str)) {
|
||||||
wmud_client_set_bademail(client, TRUE);
|
wmud_client_set_bademail(client, TRUE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -594,4 +615,3 @@ state_regemail_confirm(WmudClient *client)
|
|||||||
wmud_client_set_state(client, WMUD_CLIENT_STATE_REGISTERING);
|
wmud_client_set_state(client, WMUD_CLIENT_STATE_REGISTERING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,12 +106,12 @@ gboolean
|
|||||||
wmud_game_init(GThread **game_thread, GMainContext **game_context)
|
wmud_game_init(GThread **game_thread, GMainContext **game_context)
|
||||||
{
|
{
|
||||||
GMainLoop *game_loop;
|
GMainLoop *game_loop;
|
||||||
GSource *timeout_source;
|
GSource *timeout_source;
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
|
|
||||||
/* Create the game context and main loop */
|
/* Create the game context and main loop */
|
||||||
*game_context = g_main_context_new();
|
*game_context = g_main_context_new();
|
||||||
game_loop = g_main_loop_new(*game_context, FALSE);
|
game_loop = g_main_loop_new(*game_context, FALSE);
|
||||||
|
|
||||||
/* Create the timeout source which keeps track of elapsed real-world
|
/* Create the timeout source which keeps track of elapsed real-world
|
||||||
* time */
|
* time */
|
||||||
|
@ -35,20 +35,20 @@
|
|||||||
WMUD_COMMAND(quit);
|
WMUD_COMMAND(quit);
|
||||||
|
|
||||||
struct findData {
|
struct findData {
|
||||||
GSList *list;
|
GSList *list;
|
||||||
guint found;
|
guint found;
|
||||||
gchar *last;
|
gchar *last;
|
||||||
};
|
};
|
||||||
|
|
||||||
static wmudCommand command_list[] = {
|
static wmudCommand command_list[] = {
|
||||||
{ "quit", gcmd_quit },
|
{ "quit", gcmd_quit },
|
||||||
{ NULL, NULL },
|
{ NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
GQuark
|
GQuark
|
||||||
wmud_interpreter_error_quark()
|
wmud_interpreter_error_quark()
|
||||||
{
|
{
|
||||||
return g_quark_from_static_string("wmud-interpreter-error");
|
return g_quark_from_static_string("wmud-interpreter-error");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,56 +60,60 @@ wmud_interpreter_error_quark()
|
|||||||
static void
|
static void
|
||||||
destroy_string(GString *string)
|
destroy_string(GString *string)
|
||||||
{
|
{
|
||||||
g_string_free(string, TRUE);
|
g_string_free(string, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
check_direction_dups2(wmudDirection *dir1, wmudDirection *dir2)
|
check_direction_dups2(wmudDirection *dir1, wmudDirection *dir2)
|
||||||
{
|
{
|
||||||
gint check;
|
gint check;
|
||||||
|
|
||||||
if ((check = g_ascii_strcasecmp(dir1->short_name, dir2->short_name)) != 0)
|
if ((check = g_ascii_strcasecmp(dir1->short_name, dir2->short_name)) != 0) {
|
||||||
return check;
|
return check;
|
||||||
|
}
|
||||||
|
|
||||||
if ((check = g_ascii_strcasecmp(dir1->name, dir2->name)) != 0)
|
if ((check = g_ascii_strcasecmp(dir1->name, dir2->name)) != 0) {
|
||||||
return check;
|
return check;
|
||||||
|
}
|
||||||
|
|
||||||
if ((check = g_ascii_strcasecmp(dir1->short_name, dir2->name)) != 0)
|
if ((check = g_ascii_strcasecmp(dir1->short_name, dir2->name)) != 0) {
|
||||||
return check;
|
return check;
|
||||||
|
}
|
||||||
|
|
||||||
return g_ascii_strcasecmp(dir1->name, dir2->short_name);
|
return g_ascii_strcasecmp(dir1->name, dir2->short_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
check_direction_dups1(wmudDirection *dir, struct findData *find_data)
|
check_direction_dups1(wmudDirection *dir, struct findData *find_data)
|
||||||
{
|
{
|
||||||
if (find_data->last != dir->name) {
|
if (find_data->last != dir->name) {
|
||||||
find_data->found = (find_data->found > 1) ? find_data->found : 0;
|
find_data->found = (find_data->found > 1) ? find_data->found : 0;
|
||||||
find_data->last = dir->name;
|
find_data->last = dir->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_slist_find_custom(find_data->list, dir, (GCompareFunc)check_direction_dups2))
|
if (g_slist_find_custom(find_data->list, dir, (GCompareFunc)check_direction_dups2)) {
|
||||||
find_data->found++;
|
find_data->found++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
check_direction_command(wmudDirection *dir, gboolean *found)
|
check_direction_command(wmudDirection *dir, gboolean *found)
|
||||||
{
|
{
|
||||||
wmudCommand *cmd;
|
wmudCommand *cmd;
|
||||||
|
|
||||||
for (cmd = command_list; cmd->command; cmd++) {
|
for (cmd = command_list; cmd->command; cmd++) {
|
||||||
if (g_ascii_strcasecmp(dir->short_name, cmd->command) == 0) {
|
if (g_ascii_strcasecmp(dir->short_name, cmd->command) == 0) {
|
||||||
*found = TRUE;
|
*found = TRUE;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_ascii_strcasecmp(dir->name, cmd->command) == 0) {
|
if (g_ascii_strcasecmp(dir->name, cmd->command) == 0) {
|
||||||
*found = TRUE;
|
*found = TRUE;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -119,31 +123,31 @@ check_direction_command(wmudDirection *dir, gboolean *found)
|
|||||||
*
|
*
|
||||||
* Checks if the given directions are already registered commands.
|
* Checks if the given directions are already registered commands.
|
||||||
*
|
*
|
||||||
* Return value: If the directions are acceptable at the time of the check, the function returns %TRUE. Otherwise %FALSE is returned, and
|
* Return value: If the directions are acceptable at the time of the check, the function returns %TRUE. Otherwise %FALSE is returned, and
|
||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
wmud_interpreter_check_directions(GSList *directions, GError **err)
|
wmud_interpreter_check_directions(GSList *directions, GError **err)
|
||||||
{
|
{
|
||||||
gboolean command_found = FALSE;
|
gboolean command_found = FALSE;
|
||||||
struct findData find_data = {directions, 0, NULL};
|
struct findData find_data = {directions, 0, NULL};
|
||||||
|
|
||||||
g_slist_foreach(directions, (GFunc)check_direction_command, &command_found);
|
g_slist_foreach(directions, (GFunc)check_direction_command, &command_found);
|
||||||
|
|
||||||
if (command_found) {
|
if (command_found) {
|
||||||
g_set_error(err, WMUD_INTERPRETER_ERROR, WMUD_INTERPRETER_ERROR_DUPCMD, "Direction commands are not unique. Please check the database!");
|
g_set_error(err, WMUD_INTERPRETER_ERROR, WMUD_INTERPRETER_ERROR_DUPCMD, "Direction commands are not unique. Please check the database!");
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Direction command are not unique. Please check the database!");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Direction command are not unique. Please check the database!");
|
||||||
}
|
}
|
||||||
|
|
||||||
g_slist_foreach(directions, (GFunc)check_direction_dups1, &find_data);
|
g_slist_foreach(directions, (GFunc)check_direction_dups1, &find_data);
|
||||||
|
|
||||||
if (find_data.found > 1) {
|
if (find_data.found > 1) {
|
||||||
g_set_error(err, WMUD_INTERPRETER_ERROR, WMUD_INTERPRETER_ERROR_DUPCMD, "Direction commands defined in the database are not unique!");
|
g_set_error(err, WMUD_INTERPRETER_ERROR, WMUD_INTERPRETER_ERROR_DUPCMD, "Direction commands defined in the database are not unique!");
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Direction commands defined in the databsae are not unique.");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Direction commands defined in the databsae are not unique.");
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return !command_found;
|
return !command_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -156,132 +160,138 @@ wmud_interpreter_check_directions(GSList *directions, GError **err)
|
|||||||
void
|
void
|
||||||
wmud_interpret_game_command(WmudClient *client)
|
wmud_interpret_game_command(WmudClient *client)
|
||||||
{
|
{
|
||||||
GSList *command_parts = NULL;
|
GSList *command_parts = NULL;
|
||||||
gchar *a,
|
gchar *a,
|
||||||
*start,
|
*start,
|
||||||
*end;
|
*end;
|
||||||
gchar str_delim = 0;
|
gchar str_delim = 0;
|
||||||
wmudCommand *cmd;
|
wmudCommand *cmd;
|
||||||
int command_parts_count = 0,
|
int command_parts_count = 0,
|
||||||
match_count = 0;
|
match_count = 0;
|
||||||
GSList *matches = NULL;
|
GSList *matches = NULL;
|
||||||
|
|
||||||
if (strchr(wmud_client_get_buffer(client)->str, '\r') || strchr(wmud_client_get_buffer(client)->str, '\n')) {
|
if (strchr(wmud_client_get_buffer(client)->str, '\r') || strchr(wmud_client_get_buffer(client)->str, '\n')) {
|
||||||
/* We should NEVER reach this point! */
|
/* We should NEVER reach this point! */
|
||||||
g_assert_not_reached();
|
g_assert_not_reached();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
a = wmud_client_get_buffer(client)->str;
|
a = wmud_client_get_buffer(client)->str;
|
||||||
|
|
||||||
GString *token;
|
GString *token;
|
||||||
|
|
||||||
while (*a) {
|
while (*a) {
|
||||||
for (start = a; *start; start++) {
|
for (start = a; *start; start++) {
|
||||||
if (!str_delim) {
|
if (!str_delim) {
|
||||||
if ((*start == '"') || (*start == '\'')) {
|
if ((*start == '"') || (*start == '\'')) {
|
||||||
str_delim = *start;
|
str_delim = *start;
|
||||||
start++;
|
start++;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
} else if (g_ascii_isspace(*start) || (!*start)) {
|
} else if (g_ascii_isspace(*start) || (!*start)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (end = start; *end; end++) {
|
for (end = start; *end; end++) {
|
||||||
if (!str_delim && strchr("'\" \t", *end)) {
|
if (!str_delim && strchr("'\" \t", *end)) {
|
||||||
break;
|
break;
|
||||||
} else if (str_delim && (*end == str_delim)) {
|
} else if (str_delim && (*end == str_delim)) {
|
||||||
str_delim = 0;
|
str_delim = 0;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
} else if (!*end) {
|
} else if (!*end) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*start) {
|
if (*start) {
|
||||||
token = g_string_new_len(start, end - start);
|
token = g_string_new_len(start, end - start);
|
||||||
command_parts = g_slist_prepend(command_parts, token);
|
command_parts = g_slist_prepend(command_parts, token);
|
||||||
command_parts_count++;
|
command_parts_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
a = end;
|
a = end;
|
||||||
if (((*a == '"') || (*a == '\'')) && str_delim)
|
if (((*a == '"') || (*a == '\'')) && str_delim) {
|
||||||
a++;
|
a++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (str_delim) {
|
if (str_delim) {
|
||||||
wmud_client_send(client, "You should close quotes of any kind, like %c, shouldn't you?\r\n", str_delim);
|
wmud_client_send(client, "You should close quotes of any kind, like %c, shouldn't you?\r\n", str_delim);
|
||||||
#if GLIB_CHECK_VERSION(2, 28, 0)
|
#if GLIB_CHECK_VERSION(2, 28, 0)
|
||||||
g_slist_free_full(command_parts, (GDestroyNotify)destroy_string);
|
g_slist_free_full(command_parts, (GDestroyNotify)destroy_string);
|
||||||
#else
|
#else
|
||||||
g_slist_foreach(command_parts, (GFunc)destroy_string, NULL);
|
g_slist_foreach(command_parts, (GFunc)destroy_string, NULL);
|
||||||
g_slist_free(command_parts);
|
g_slist_free(command_parts);
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command_parts_count == 0) {
|
if (command_parts_count == 0) {
|
||||||
/* TODO: handle empty command */
|
/* TODO: handle empty command */
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
command_parts = g_slist_reverse(command_parts);
|
command_parts = g_slist_reverse(command_parts);
|
||||||
|
|
||||||
for (cmd = command_list; cmd->command; cmd++) {
|
for (cmd = command_list; cmd->command; cmd++) {
|
||||||
GString *input = (GString *)(command_parts->data);
|
GString *input = (GString *)(command_parts->data);
|
||||||
gint cmp;
|
gint cmp;
|
||||||
|
|
||||||
if (((cmp = g_ascii_strncasecmp(input->str, cmd->command, input->len)) == 0) && !cmd->command[input->len]) {
|
if (((cmp = g_ascii_strncasecmp(input->str, cmd->command, input->len)) == 0) && !cmd->command[input->len]) {
|
||||||
g_slist_free(matches);
|
g_slist_free(matches);
|
||||||
match_count = 1;
|
match_count = 1;
|
||||||
matches = NULL;
|
matches = NULL;
|
||||||
matches = g_slist_prepend(matches, cmd);
|
matches = g_slist_prepend(matches, cmd);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
} else if (cmp == 0) {
|
} else if (cmp == 0) {
|
||||||
matches = g_slist_prepend(matches, cmd);
|
matches = g_slist_prepend(matches, cmd);
|
||||||
match_count++;
|
match_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (match_count) {
|
switch (match_count) {
|
||||||
case 0:
|
case 0:
|
||||||
switch (random_number(1, 3)) {
|
switch (random_number(1, 3)) {
|
||||||
case 1:
|
case 1:
|
||||||
wmud_client_send(client, "Huh?\r\n");
|
wmud_client_send(client, "Huh?\r\n");
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
wmud_client_send(client, "What?\r\n");
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
wmud_client_send(client, "I can hardly understand you...\r\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
((wmudCommand *)(matches->data))->commandFunc(client, ((GString *)(command_parts->data))->str, command_parts->next);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
wmud_client_send(client, "This command could mean several things, please try a more exact form!\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
g_slist_free(matches);
|
break;
|
||||||
|
case 2:
|
||||||
|
wmud_client_send(client, "What?\r\n");
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
wmud_client_send(client, "I can hardly understand you...\r\n");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
((wmudCommand *)(matches->data))->commandFunc(client, ((GString *)(command_parts->data))->str, command_parts->next);
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
wmud_client_send(client, "This command could mean several things, please try a more exact form!\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
g_slist_free(matches);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gcmd_quit:
|
* gcmd_quit:
|
||||||
*
|
*
|
||||||
* The QUIT game command's handler
|
* The QUIT game command's handler
|
||||||
*/
|
*/
|
||||||
WMUD_COMMAND(quit)
|
WMUD_COMMAND(quit)
|
||||||
{
|
{
|
||||||
wmud_client_send(client, "Are you sure you want to get back to that freaky other reality? [y/N] ");
|
wmud_client_send(client, "Are you sure you want to get back to that freaky other reality? [y/N] ");
|
||||||
wmud_client_set_state(client, WMUD_CLIENT_STATE_YESNO);
|
wmud_client_set_state(client, WMUD_CLIENT_STATE_YESNO);
|
||||||
wmud_client_set_yesno_callback(client, wmud_client_quitanswer);
|
wmud_client_set_yesno_callback(client, wmud_client_quitanswer);
|
||||||
}
|
}
|
||||||
|
32
wmud/main.c
32
wmud/main.c
@ -53,7 +53,7 @@
|
|||||||
*/
|
*/
|
||||||
struct {
|
struct {
|
||||||
char *file;
|
char *file;
|
||||||
int line;
|
int line;
|
||||||
} debug_context_loc = {NULL, 0};
|
} debug_context_loc = {NULL, 0};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,15 +66,16 @@ gchar *
|
|||||||
wmud_random_string(gint len)
|
wmud_random_string(gint len)
|
||||||
{
|
{
|
||||||
gchar *ret = g_malloc0(len + 1);
|
gchar *ret = g_malloc0(len + 1);
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
gchar c = 0;
|
gchar c = 0;
|
||||||
/* Include only printable characters, but exclude $ because of
|
/* Include only printable characters, but exclude $ because of
|
||||||
* salt generation, and space to avoid misunderstanding in the
|
* salt generation, and space to avoid misunderstanding in the
|
||||||
* random generated passwords */
|
* random generated passwords */
|
||||||
while (!g_ascii_isprint(c) || (c == '$') || (c == ' ') || (c == '\t'))
|
while (!g_ascii_isprint(c) || (c == '$') || (c == ' ') || (c == '\t')) {
|
||||||
c = random_number(1, 127);
|
c = random_number(1, 127);
|
||||||
|
}
|
||||||
|
|
||||||
ret[i] = c;
|
ret[i] = c;
|
||||||
}
|
}
|
||||||
@ -97,8 +98,9 @@ void
|
|||||||
*/
|
*/
|
||||||
debug_context(char *file, int line)
|
debug_context(char *file, int line)
|
||||||
{
|
{
|
||||||
if (debug_context_loc.file != NULL)
|
if (debug_context_loc.file != NULL) {
|
||||||
g_free(debug_context_loc.file);
|
g_free(debug_context_loc.file);
|
||||||
|
}
|
||||||
|
|
||||||
debug_context_loc.file = g_strdup(file);
|
debug_context_loc.file = g_strdup(file);
|
||||||
debug_context_loc.line = line;
|
debug_context_loc.line = line;
|
||||||
@ -125,19 +127,19 @@ wmud_type_init(void)
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_logger(const gchar *log_domain,
|
wmud_logger(const gchar *log_domain,
|
||||||
GLogLevelFlags log_level,
|
GLogLevelFlags log_level,
|
||||||
const gchar *message,
|
const gchar *message,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
static char timestamp[20];
|
static char timestamp[20];
|
||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
time_t ts = time(NULL);
|
time_t ts = time(NULL);
|
||||||
size_t last_char;
|
size_t last_char;
|
||||||
|
|
||||||
tm = localtime(&ts);
|
tm = localtime(&ts);
|
||||||
|
|
||||||
last_char = strftime((char *)×tamp, 20, "%F %T", tm);
|
last_char = strftime((char *)×tamp, 20, "%F %T", tm);
|
||||||
timestamp[last_char] = '\0';
|
timestamp[last_char] = '\0';
|
||||||
|
|
||||||
switch (log_level) {
|
switch (log_level) {
|
||||||
@ -200,12 +202,12 @@ wmud_logger(const gchar *log_domain,
|
|||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
GThread *game_thread;
|
GThread *game_thread;
|
||||||
GMainContext *game_context;
|
GMainContext *game_context;
|
||||||
GSList *game_menu = NULL;
|
GSList *game_menu = NULL;
|
||||||
|
|
||||||
g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_MASK , wmud_logger, NULL);
|
g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_MASK, wmud_logger, NULL);
|
||||||
/* Initialize the thread and type system */
|
/* Initialize the thread and type system */
|
||||||
wmud_type_init();
|
wmud_type_init();
|
||||||
|
|
||||||
|
@ -52,30 +52,30 @@
|
|||||||
void
|
void
|
||||||
wmud_maintenance_check_players(WmudPlayer *player, gpointer user_data)
|
wmud_maintenance_check_players(WmudPlayer *player, gpointer user_data)
|
||||||
{
|
{
|
||||||
if (wmud_player_get_cpassword(player) == NULL) {
|
if (wmud_player_get_cpassword(player) == NULL) {
|
||||||
gchar *pw,
|
gchar *pw,
|
||||||
*salt,
|
*salt,
|
||||||
*cpw;
|
*cpw;
|
||||||
GString *full_salt;
|
GString *full_salt;
|
||||||
|
|
||||||
pw = wmud_random_string(8);
|
pw = wmud_random_string(8);
|
||||||
salt = wmud_random_string(8);
|
salt = wmud_random_string(8);
|
||||||
full_salt = g_string_new("$1$");
|
full_salt = g_string_new("$1$");
|
||||||
g_string_append(full_salt, salt);
|
g_string_append(full_salt, salt);
|
||||||
cpw = g_strdup(crypt(pw, full_salt->str));
|
cpw = g_strdup(crypt(pw, full_salt->str));
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Player %s has no"
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Player %s has no"
|
||||||
" password set", wmud_player_get_player_name(player));
|
" password set", wmud_player_get_player_name(player));
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "New password will be %s", pw);
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "New password will be %s", pw);
|
||||||
wmud_player_set_cpassword(player, cpw);
|
wmud_player_set_cpassword(player, cpw);
|
||||||
/* TODO: Send e-mail about the new password. Upon completion, set it in
|
/* TODO: Send e-mail about the new password. Upon completion, set it in
|
||||||
* the database */
|
* the database */
|
||||||
wmud_db_update_player_password(player, cpw, NULL);
|
wmud_db_update_player_password(player, cpw, NULL);
|
||||||
|
|
||||||
g_free(pw);
|
g_free(pw);
|
||||||
g_free(salt);
|
g_free(salt);
|
||||||
g_string_free(full_salt, TRUE);
|
g_string_free(full_salt, TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,14 +87,14 @@ wmud_maintenance_check_players(WmudPlayer *player, gpointer user_data)
|
|||||||
gboolean
|
gboolean
|
||||||
wmud_maintenance(gpointer user_data)
|
wmud_maintenance(gpointer user_data)
|
||||||
{
|
{
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Starting maintenance...");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Starting maintenance...");
|
||||||
/* Run through the player list, and generate a random password for each
|
/* Run through the player list, and generate a random password for each
|
||||||
* newly registered player */
|
* newly registered player */
|
||||||
g_slist_foreach(players, (GFunc)wmud_maintenance_check_players, NULL);
|
g_slist_foreach(players, (GFunc)wmud_maintenance_check_players, NULL);
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Finished maintenance...");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Finished maintenance...");
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,102 +108,106 @@ wmud_maintenance(gpointer user_data)
|
|||||||
gpointer
|
gpointer
|
||||||
maint_thread_func(GMainLoop *maint_loop)
|
maint_thread_func(GMainLoop *maint_loop)
|
||||||
{
|
{
|
||||||
g_main_loop_run(maint_loop);
|
g_main_loop_run(maint_loop);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *text[] = {
|
const char *text[] = {
|
||||||
"To: Polonkai Gergely <polonkai.gergely@brokernet-group.com>\n",
|
"To: Polonkai Gergely <polonkai.gergely@brokernet-group.com>\n",
|
||||||
"Subject: Teszt\n",
|
"Subject: Teszt\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Hello!\n"
|
"Hello!\n"
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WriteThis {
|
struct WriteThis {
|
||||||
int counter;
|
int counter;
|
||||||
};
|
};
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
wmud_smtp_read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
|
wmud_smtp_read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
|
||||||
{
|
{
|
||||||
struct WriteThis *pooh = (struct WriteThis *)userp;
|
struct WriteThis *pooh = (struct WriteThis *)userp;
|
||||||
const char *data;
|
const char *data;
|
||||||
|
|
||||||
if (size * nmemb < 1)
|
if (size * nmemb < 1) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
data = text[pooh->counter];
|
data = text[pooh->counter];
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
size_t len = strlen(data);
|
size_t len = strlen(data);
|
||||||
memcpy(ptr, data, len);
|
memcpy(ptr, data, len);
|
||||||
pooh->counter++;
|
pooh->counter++;
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_maintenance_init(void)
|
wmud_maintenance_init(void)
|
||||||
{
|
{
|
||||||
GSource *timeout_source;
|
GSource *timeout_source;
|
||||||
GMainLoop *maint_loop;
|
GMainLoop *maint_loop;
|
||||||
GMainContext *maint_context;
|
GMainContext *maint_context;
|
||||||
CURL *curl;
|
CURL *curl;
|
||||||
CURLM *mcurl;
|
CURLM *mcurl;
|
||||||
gchar *smtp_server_real;
|
gchar *smtp_server_real;
|
||||||
struct WriteThis pooh = {0};
|
struct WriteThis pooh = {0};
|
||||||
|
|
||||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||||
|
|
||||||
if (!(curl = curl_easy_init()))
|
if (!(curl = curl_easy_init())) {
|
||||||
g_error("Could not initialize the CURL library!");
|
g_error("Could not initialize the CURL library!");
|
||||||
|
}
|
||||||
|
|
||||||
if (!(mcurl = curl_multi_init()))
|
if (!(mcurl = curl_multi_init())) {
|
||||||
g_error("Could not initialize the CURL library!");
|
g_error("Could not initialize the CURL library!");
|
||||||
|
}
|
||||||
|
|
||||||
smtp_server_real = g_strconcat("smtp://", active_config->smtp_server, NULL);
|
smtp_server_real = g_strconcat("smtp://", active_config->smtp_server, NULL);
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, smtp_server_real);
|
curl_easy_setopt(curl, CURLOPT_URL, smtp_server_real);
|
||||||
g_free(smtp_server_real);
|
g_free(smtp_server_real);
|
||||||
|
|
||||||
if (active_config->smtp_username && active_config->smtp_password) {
|
if (active_config->smtp_username && active_config->smtp_password) {
|
||||||
curl_easy_setopt(curl, CURLOPT_USERNAME, active_config->smtp_username);
|
curl_easy_setopt(curl, CURLOPT_USERNAME, active_config->smtp_username);
|
||||||
curl_easy_setopt(curl, CURLOPT_PASSWORD, active_config->smtp_password);
|
curl_easy_setopt(curl, CURLOPT_PASSWORD, active_config->smtp_password);
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, active_config->smtp_sender);
|
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, active_config->smtp_sender);
|
||||||
curl_easy_setopt(curl, CURLOPT_USE_SSL, (CURLUSESSL_ALL && active_config->smtp_tls));
|
curl_easy_setopt(curl, CURLOPT_USE_SSL, (CURLUSESSL_ALL && active_config->smtp_tls));
|
||||||
|
|
||||||
/* TODO: Maybe these could go into the configuration as well */
|
/* TODO: Maybe these could go into the configuration as well */
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||||
curl_easy_setopt(curl, CURLOPT_SSLVERSION, 0L);
|
curl_easy_setopt(curl, CURLOPT_SSLVERSION, 0L);
|
||||||
curl_easy_setopt(curl, CURLOPT_SSL_SESSIONID_CACHE, 0L);
|
curl_easy_setopt(curl, CURLOPT_SSL_SESSIONID_CACHE, 0L);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||||
#else
|
#else
|
||||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
|
||||||
#endif
|
#endif
|
||||||
curl_easy_setopt(curl, CURLOPT_READFUNCTION, wmud_smtp_read_callback);
|
curl_easy_setopt(curl, CURLOPT_READFUNCTION, wmud_smtp_read_callback);
|
||||||
curl_easy_setopt(curl, CURLOPT_READDATA, &pooh);
|
curl_easy_setopt(curl, CURLOPT_READDATA, &pooh);
|
||||||
curl_multi_add_handle(mcurl, curl);
|
curl_multi_add_handle(mcurl, curl);
|
||||||
|
|
||||||
/* Create the maintenance context and main loop */
|
/* Create the maintenance context and main loop */
|
||||||
maint_context = g_main_context_new();
|
maint_context = g_main_context_new();
|
||||||
maint_loop = g_main_loop_new(maint_context, FALSE);
|
maint_loop = g_main_loop_new(maint_context, FALSE);
|
||||||
|
|
||||||
/* Create the timeout source which will do the maintenance tasks */
|
/* Create the timeout source which will do the maintenance tasks */
|
||||||
timeout_source = g_timeout_source_new_seconds(WMUD_MAINTENANCE_TIME);
|
timeout_source = g_timeout_source_new_seconds(WMUD_MAINTENANCE_TIME);
|
||||||
g_source_set_callback(timeout_source, wmud_maintenance, NULL, NULL);
|
g_source_set_callback(timeout_source, wmud_maintenance, NULL, NULL);
|
||||||
g_source_attach(timeout_source, maint_context);
|
g_source_attach(timeout_source, maint_context);
|
||||||
g_source_unref(timeout_source);
|
g_source_unref(timeout_source);
|
||||||
|
|
||||||
#if GLIB_CHECK_VERSION(2, 32, 0)
|
#if GLIB_CHECK_VERSION(2, 32, 0)
|
||||||
g_thread_new("maintenance", (GThreadFunc)maint_thread_func, maint_loop);
|
g_thread_new("maintenance", (GThreadFunc)maint_thread_func, maint_loop);
|
||||||
#else
|
#else
|
||||||
g_thread_create((GThreadFunc)maint_thread_func, maint_loop, TRUE, NULL);
|
g_thread_create((GThreadFunc)maint_thread_func, maint_loop, TRUE, NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
242
wmud/menu.c
242
wmud/menu.c
@ -46,98 +46,103 @@ GSList *game_menu = NULL;
|
|||||||
GQuark
|
GQuark
|
||||||
wmud_menu_error_quark()
|
wmud_menu_error_quark()
|
||||||
{
|
{
|
||||||
return g_quark_from_static_string("wmud-menu-error");
|
return g_quark_from_static_string("wmud-menu-error");
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
wmud_menu_items_check(GSList *menu_items, GError **err)
|
wmud_menu_items_check(GSList *menu_items, GError **err)
|
||||||
{
|
{
|
||||||
/* TODO: Check for duplicate menuchars */
|
/* TODO: Check for duplicate menuchars */
|
||||||
/* TODO: Check for duplicate menu texts */
|
/* TODO: Check for duplicate menu texts */
|
||||||
/* TODO: Check for duplicate placements */
|
/* TODO: Check for duplicate placements */
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
menu_item_free(wmudMenu *menu_item)
|
menu_item_free(wmudMenu *menu_item)
|
||||||
{
|
{
|
||||||
if (menu_item->text)
|
if (menu_item->text) {
|
||||||
g_free(menu_item->text);
|
g_free(menu_item->text);
|
||||||
|
}
|
||||||
|
|
||||||
if (menu_item->display_text)
|
if (menu_item->display_text) {
|
||||||
g_free(menu_item->display_text);
|
g_free(menu_item->display_text);
|
||||||
|
}
|
||||||
|
|
||||||
if (menu_item->display_text_ansi)
|
if (menu_item->display_text_ansi) {
|
||||||
g_free(menu_item->display_text_ansi);
|
g_free(menu_item->display_text_ansi);
|
||||||
|
}
|
||||||
|
|
||||||
if (menu_item->func)
|
if (menu_item->func) {
|
||||||
g_free(menu_item->func);
|
g_free(menu_item->func);
|
||||||
|
}
|
||||||
|
|
||||||
g_free(menu_item);
|
g_free(menu_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_menu_items_free(GSList **menu_items)
|
wmud_menu_items_free(GSList **menu_items)
|
||||||
{
|
{
|
||||||
if (menu_items)
|
if (menu_items) {
|
||||||
{
|
|
||||||
#if GLIB_CHECK_VERSION(2, 28, 0)
|
#if GLIB_CHECK_VERSION(2, 28, 0)
|
||||||
g_slist_free_full(*menu_items, (GDestroyNotify)menu_item_free);
|
g_slist_free_full(*menu_items, (GDestroyNotify)menu_item_free);
|
||||||
#else
|
#else
|
||||||
g_slist_foreach(*menu_items, (GFunc)menu_item_free, NULL);
|
g_slist_foreach(*menu_items, (GFunc)menu_item_free, NULL);
|
||||||
g_slist_free(*menu_items);
|
g_slist_free(*menu_items);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
*menu_items = NULL;
|
*menu_items = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
menu_item_prepare(wmudMenu *item, GHashTable *cmdtable)
|
menu_item_prepare(wmudMenu *item, GHashTable *cmdtable)
|
||||||
{
|
{
|
||||||
gchar m1, m2;
|
gchar m1, m2;
|
||||||
gchar *a,
|
gchar *a,
|
||||||
*found = NULL;
|
*found = NULL;
|
||||||
GString *ds, *dsa;
|
GString *ds, *dsa;
|
||||||
|
|
||||||
g_debug("Preparing menu item %s", item->text);
|
g_debug("Preparing menu item %s", item->text);
|
||||||
m1 = g_ascii_tolower(item->menuchar);
|
m1 = g_ascii_tolower(item->menuchar);
|
||||||
m2 = g_ascii_toupper(item->menuchar);
|
m2 = g_ascii_toupper(item->menuchar);
|
||||||
for (a = item->text; *a; a++)
|
for (a = item->text; *a; a++) {
|
||||||
if ((*a == m1) || (*a == m2)) {
|
if ((*a == m1) || (*a == m2)) {
|
||||||
found = a;
|
found = a;
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (found) {
|
break;
|
||||||
gchar *tmp;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tmp = g_ascii_strdown(item->text, -1);
|
if (found) {
|
||||||
ds = g_string_new(tmp);
|
gchar *tmp;
|
||||||
dsa = g_string_new(tmp);
|
|
||||||
g_free(tmp);
|
|
||||||
|
|
||||||
ds->str[found - item->text] = g_ascii_toupper(item->menuchar);
|
tmp = g_ascii_strdown(item->text, -1);
|
||||||
dsa->str[found - item->text] = g_ascii_toupper(item->menuchar);
|
ds = g_string_new(tmp);
|
||||||
} else {
|
dsa = g_string_new(tmp);
|
||||||
found = item->text;
|
g_free(tmp);
|
||||||
ds = g_string_new(item->text);
|
|
||||||
dsa = g_string_new(item->text);
|
|
||||||
|
|
||||||
g_string_prepend_c(ds, ' ');
|
ds->str[found - item->text] = g_ascii_toupper(item->menuchar);
|
||||||
g_string_prepend_c(ds, g_ascii_toupper(item->menuchar));
|
dsa->str[found - item->text] = g_ascii_toupper(item->menuchar);
|
||||||
g_string_prepend_c(dsa, ' ');
|
} else {
|
||||||
g_string_prepend_c(dsa, g_ascii_toupper(item->menuchar));
|
found = item->text;
|
||||||
}
|
ds = g_string_new(item->text);
|
||||||
|
dsa = g_string_new(item->text);
|
||||||
|
|
||||||
g_string_insert_c(ds, found - item->text, '(');
|
g_string_prepend_c(ds, ' ');
|
||||||
g_string_insert_c(ds, found - item->text + 2, ')');
|
g_string_prepend_c(ds, g_ascii_toupper(item->menuchar));
|
||||||
|
g_string_prepend_c(dsa, ' ');
|
||||||
|
g_string_prepend_c(dsa, g_ascii_toupper(item->menuchar));
|
||||||
|
}
|
||||||
|
|
||||||
g_string_insert(dsa, found - item->text, "\x1b[31;1m");
|
g_string_insert_c(ds, found - item->text, '(');
|
||||||
g_string_insert(dsa, found - item->text + 8, "\x1b[0m");
|
g_string_insert_c(ds, found - item->text + 2, ')');
|
||||||
item->display_text = g_string_free(ds, FALSE);
|
|
||||||
item->display_text_ansi = g_string_free(dsa, FALSE);
|
g_string_insert(dsa, found - item->text, "\x1b[31;1m");
|
||||||
|
g_string_insert(dsa, found - item->text + 8, "\x1b[0m");
|
||||||
|
item->display_text = g_string_free(ds, FALSE);
|
||||||
|
item->display_text_ansi = g_string_free(dsa, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
WMUD_MENU_COMMAND(enter_world)
|
WMUD_MENU_COMMAND(enter_world)
|
||||||
@ -190,117 +195,120 @@ WMUD_MENU_COMMAND(change_name)
|
|||||||
|
|
||||||
WMUD_MENU_COMMAND(quit)
|
WMUD_MENU_COMMAND(quit)
|
||||||
{
|
{
|
||||||
wmud_client_set_state(client, WMUD_CLIENT_STATE_YESNO);
|
wmud_client_set_state(client, WMUD_CLIENT_STATE_YESNO);
|
||||||
wmud_client_set_yesno_callback(client, wmud_client_quitanswer);
|
wmud_client_set_yesno_callback(client, wmud_client_quitanswer);
|
||||||
wmud_client_send(client, "Are you sure you want to get back to the real world? [y/N] ");
|
wmud_client_send(client, "Are you sure you want to get back to the real world? [y/N] ");
|
||||||
}
|
}
|
||||||
|
|
||||||
WMUD_MENU_COMMAND(redisplay_menu)
|
WMUD_MENU_COMMAND(redisplay_menu)
|
||||||
{
|
{
|
||||||
wmud_menu_present(client);
|
wmud_menu_present(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
wmud_menu_init(GSList **menu)
|
wmud_menu_init(GSList **menu)
|
||||||
{
|
{
|
||||||
GSList *menu_items = NULL;
|
GSList *menu_items = NULL;
|
||||||
GError *in_err = NULL;
|
GError *in_err = NULL;
|
||||||
GHashTable *cmdtable;
|
GHashTable *cmdtable;
|
||||||
|
|
||||||
if (!wmud_db_load_menu(&menu_items, &in_err)) {
|
if (!wmud_db_load_menu(&menu_items, &in_err)) {
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "Unable to load menu items from the database: %s", in_err->message);
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "Unable to load menu items from the database: %s", in_err->message);
|
||||||
wmud_menu_items_free(&menu_items);
|
wmud_menu_items_free(&menu_items);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!menu_items) {
|
if (!menu_items) {
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "No menu items were found in the database!");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "No menu items were found in the database!");
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!wmud_menu_items_check(menu_items, &in_err)) {
|
if (!wmud_menu_items_check(menu_items, &in_err)) {
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "Menu items pre-flight check error: %s", in_err->message);
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "Menu items pre-flight check error: %s", in_err->message);
|
||||||
wmud_menu_items_free(&menu_items);
|
wmud_menu_items_free(&menu_items);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*menu)
|
if (*menu) {
|
||||||
wmud_menu_items_free(menu);
|
wmud_menu_items_free(menu);
|
||||||
|
}
|
||||||
|
|
||||||
*menu = menu_items;
|
*menu = menu_items;
|
||||||
|
|
||||||
cmdtable = g_hash_table_new(g_str_hash, g_str_equal);
|
cmdtable = g_hash_table_new(g_str_hash, g_str_equal);
|
||||||
|
|
||||||
g_slist_foreach(*menu, (GFunc)menu_item_prepare, cmdtable);
|
g_slist_foreach(*menu, (GFunc)menu_item_prepare, cmdtable);
|
||||||
|
|
||||||
g_hash_table_insert(cmdtable, "enter-world", wmud_mcmd_enter_world);
|
g_hash_table_insert(cmdtable, "enter-world", wmud_mcmd_enter_world);
|
||||||
g_hash_table_insert(cmdtable, "change-password", wmud_mcmd_change_password);
|
g_hash_table_insert(cmdtable, "change-password", wmud_mcmd_change_password);
|
||||||
g_hash_table_insert(cmdtable, "toggle-colour", wmud_mcmd_toggle_colour);
|
g_hash_table_insert(cmdtable, "toggle-colour", wmud_mcmd_toggle_colour);
|
||||||
g_hash_table_insert(cmdtable, "documentation", wmud_mcmd_documentation);
|
g_hash_table_insert(cmdtable, "documentation", wmud_mcmd_documentation);
|
||||||
g_hash_table_insert(cmdtable, "caracter-select", wmud_mcmd_character_select);
|
g_hash_table_insert(cmdtable, "caracter-select", wmud_mcmd_character_select);
|
||||||
g_hash_table_insert(cmdtable, "character-create", wmud_mcmd_character_create);
|
g_hash_table_insert(cmdtable, "character-create", wmud_mcmd_character_create);
|
||||||
g_hash_table_insert(cmdtable, "character-delete", wmud_mcmd_character_delete);
|
g_hash_table_insert(cmdtable, "character-delete", wmud_mcmd_character_delete);
|
||||||
g_hash_table_insert(cmdtable, "chat", wmud_mcmd_chat);
|
g_hash_table_insert(cmdtable, "chat", wmud_mcmd_chat);
|
||||||
g_hash_table_insert(cmdtable, "player-mail", wmud_mcmd_player_mail);
|
g_hash_table_insert(cmdtable, "player-mail", wmud_mcmd_player_mail);
|
||||||
g_hash_table_insert(cmdtable, "colour-test", wmud_mcmd_colour_test);
|
g_hash_table_insert(cmdtable, "colour-test", wmud_mcmd_colour_test);
|
||||||
g_hash_table_insert(cmdtable, "change-email", wmud_mcmd_change_email);
|
g_hash_table_insert(cmdtable, "change-email", wmud_mcmd_change_email);
|
||||||
g_hash_table_insert(cmdtable, "change-name", wmud_mcmd_change_name);
|
g_hash_table_insert(cmdtable, "change-name", wmud_mcmd_change_name);
|
||||||
g_hash_table_insert(cmdtable, "quit", wmud_mcmd_quit);
|
g_hash_table_insert(cmdtable, "quit", wmud_mcmd_quit);
|
||||||
g_hash_table_insert(cmdtable, "redisplay-menu", wmud_mcmd_redisplay_menu);
|
g_hash_table_insert(cmdtable, "redisplay-menu", wmud_mcmd_redisplay_menu);
|
||||||
|
|
||||||
/* TODO: Free previous hash table, if exists */
|
/* TODO: Free previous hash table, if exists */
|
||||||
mcmd_table = cmdtable;
|
mcmd_table = cmdtable;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
find_by_menuchar(wmudMenu *item, gchar *menuchar)
|
find_by_menuchar(wmudMenu *item, gchar *menuchar)
|
||||||
{
|
{
|
||||||
if (g_ascii_toupper(*menuchar) == g_ascii_toupper(item->menuchar))
|
if (g_ascii_toupper(*menuchar) == g_ascii_toupper(item->menuchar)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar *
|
gchar *
|
||||||
wmud_menu_get_command_by_menuchar(gchar menuchar, GSList *game_menu)
|
wmud_menu_get_command_by_menuchar(gchar menuchar, GSList *game_menu)
|
||||||
{
|
{
|
||||||
GSList *item;
|
GSList *item;
|
||||||
|
|
||||||
if ((item = g_slist_find_custom(game_menu, &menuchar, (GCompareFunc)find_by_menuchar)) != NULL)
|
if ((item = g_slist_find_custom(game_menu, &menuchar, (GCompareFunc)find_by_menuchar)) != NULL) {
|
||||||
return ((wmudMenu *)(item->data))->func;
|
return ((wmudMenu *)(item->data))->func;
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_menu_execute_command(WmudClient *client, gchar *command)
|
wmud_menu_execute_command(WmudClient *client, gchar *command)
|
||||||
{
|
{
|
||||||
wmudMenuCommandFunc func;
|
wmudMenuCommandFunc func;
|
||||||
|
|
||||||
if ((func = g_hash_table_lookup(mcmd_table, command)) == NULL)
|
if ((func = g_hash_table_lookup(mcmd_table, command)) == NULL) {
|
||||||
wmud_client_send(client, "Unknown menu command.\r\n");
|
wmud_client_send(client, "Unknown menu command.\r\n");
|
||||||
else
|
} else {
|
||||||
func(client);
|
func(client);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
send_menu_item(wmudMenu *item, WmudClient *client)
|
send_menu_item(wmudMenu *item, WmudClient *client)
|
||||||
{
|
{
|
||||||
/* TODO: Send ANSI menu item only to ANSI players! */
|
/* TODO: Send ANSI menu item only to ANSI players! */
|
||||||
wmud_client_send(client, "%s\r\n", item->display_text_ansi);
|
wmud_client_send(client, "%s\r\n", item->display_text_ansi);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_menu_present(WmudClient *client)
|
wmud_menu_present(WmudClient *client)
|
||||||
{
|
{
|
||||||
g_slist_foreach(game_menu, (GFunc)send_menu_item, client);
|
g_slist_foreach(game_menu, (GFunc)send_menu_item, client);
|
||||||
wmud_client_set_state(client, WMUD_CLIENT_STATE_MENU);
|
wmud_client_set_state(client, WMUD_CLIENT_STATE_MENU);
|
||||||
|
|
||||||
/* TODO: send menu prologue */
|
/* TODO: send menu prologue */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ GSList *players = NULL;
|
|||||||
static gint
|
static gint
|
||||||
find_player_by_name(WmudPlayer *player, gchar *player_name)
|
find_player_by_name(WmudPlayer *player, gchar *player_name)
|
||||||
{
|
{
|
||||||
return g_ascii_strcasecmp(wmud_player_get_player_name(player), player_name);
|
return g_ascii_strcasecmp(wmud_player_get_player_name(player), player_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,12 +60,11 @@ find_player_by_name(WmudPlayer *player, gchar *player_name)
|
|||||||
WmudPlayer *
|
WmudPlayer *
|
||||||
wmud_player_exists(gchar *player_name)
|
wmud_player_exists(gchar *player_name)
|
||||||
{
|
{
|
||||||
GSList *player_elem;
|
GSList *player_elem;
|
||||||
|
|
||||||
if ((player_elem = g_slist_find_custom(players, player_name, (GCompareFunc)find_player_by_name)) == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return player_elem->data;
|
if ((player_elem = g_slist_find_custom(players, player_name, (GCompareFunc)find_player_by_name)) == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return player_elem->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
77
wmud/texts.c
77
wmud/texts.c
@ -24,62 +24,65 @@
|
|||||||
#include "wmudclient.h"
|
#include "wmudclient.h"
|
||||||
|
|
||||||
static const gchar *text_files[] = {
|
static const gchar *text_files[] = {
|
||||||
"motd",
|
"motd",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
GHashTable *text_table = NULL;
|
GHashTable *text_table = NULL;
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_texts_init(void)
|
wmud_texts_init(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
gchar *texts_dir = g_strconcat(WMUD_STATEDIR, "/texts/", NULL);
|
gchar *texts_dir = g_strconcat(WMUD_STATEDIR, "/texts/", NULL);
|
||||||
|
|
||||||
text_table = g_hash_table_new(g_str_hash, g_str_equal);
|
text_table = g_hash_table_new(g_str_hash, g_str_equal);
|
||||||
|
|
||||||
for (i = 0; i < g_strv_length((gchar **)text_files); i++) {
|
for (i = 0; i < g_strv_length((gchar **)text_files); i++) {
|
||||||
GFile *tf;
|
GFile *tf;
|
||||||
GFileInfo *tfi;
|
GFileInfo *tfi;
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
guint64 tfs;
|
guint64 tfs;
|
||||||
gchar *contents;
|
gchar *contents;
|
||||||
gsize length;
|
gsize length;
|
||||||
|
gchar *text_file = g_strconcat(texts_dir, text_files[i], NULL);
|
||||||
|
|
||||||
gchar *text_file = g_strconcat(texts_dir, text_files[i], NULL);
|
g_debug("Loading text file %s from %s", text_files[i], text_file);
|
||||||
g_debug("Loading text file %s from %s", text_files[i], text_file);
|
tf = g_file_new_for_path(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);
|
||||||
tfi = g_file_query_info(tf, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, &err);
|
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
g_warning("Error loading %s: %s", text_files[i], err->message);
|
g_warning("Error loading %s: %s", text_files[i], err->message);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
tfs = g_file_info_get_attribute_uint64(tfi, G_FILE_ATTRIBUTE_STANDARD_SIZE);
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
contents = g_malloc0(tfs + 1);
|
tfs = g_file_info_get_attribute_uint64(tfi, G_FILE_ATTRIBUTE_STANDARD_SIZE);
|
||||||
|
|
||||||
g_clear_error(&err);
|
contents = g_malloc0(tfs + 1);
|
||||||
|
|
||||||
if (!g_file_load_contents(tf, NULL, &contents, &length, NULL, &err)) {
|
g_clear_error(&err);
|
||||||
g_object_unref(tfi);
|
|
||||||
g_object_unref(tf);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_hash_table_insert(text_table, (char *)text_files[i], contents);
|
if (!g_file_load_contents(tf, NULL, &contents, &length, NULL, &err)) {
|
||||||
|
g_object_unref(tfi);
|
||||||
|
g_object_unref(tf);
|
||||||
|
|
||||||
g_object_unref(tfi);
|
continue;
|
||||||
g_object_unref(tf);
|
}
|
||||||
g_free(text_file);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free(texts_dir);
|
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
|
void
|
||||||
wmud_text_send_to_client(gchar *text_name, WmudClient *client)
|
wmud_text_send_to_client(gchar *text_name, WmudClient *client)
|
||||||
{
|
{
|
||||||
gchar *text = g_hash_table_lookup(text_table, text_name);
|
gchar *text = g_hash_table_lookup(text_table, text_name);
|
||||||
wmud_client_send(client, "%s\r\n", text);
|
|
||||||
|
wmud_client_send(client, "%s\r\n", text);
|
||||||
}
|
}
|
||||||
|
@ -33,178 +33,179 @@
|
|||||||
G_DEFINE_TYPE(WmudClient, wmud_client, G_TYPE_OBJECT);
|
G_DEFINE_TYPE(WmudClient, wmud_client, G_TYPE_OBJECT);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
SIG_CONNECTED,
|
SIG_CONNECTED,
|
||||||
SIG_NET_HUP,
|
SIG_NET_HUP,
|
||||||
SIG_NET_RECV,
|
SIG_NET_RECV,
|
||||||
SIG_STATE_CHANGE,
|
SIG_STATE_CHANGE,
|
||||||
SIG_LAST
|
SIG_LAST
|
||||||
};
|
};
|
||||||
|
|
||||||
static guint signals[SIG_LAST] = { 0 };
|
static guint signals[SIG_LAST] = { 0 };
|
||||||
|
|
||||||
#define WMUD_CLIENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WMUD_TYPE_CLIENT, WmudClientPrivate))
|
#define WMUD_CLIENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WMUD_TYPE_CLIENT, WmudClientPrivate))
|
||||||
|
|
||||||
struct _WmudClientPrivate
|
struct _WmudClientPrivate {
|
||||||
{
|
GSocket *socket;
|
||||||
GSocket *socket;
|
GSource *socket_source;
|
||||||
GSource *socket_source;
|
GString *buffer;
|
||||||
GString *buffer;
|
WmudClientState state;
|
||||||
WmudClientState state;
|
gboolean authenticated;
|
||||||
gboolean authenticated;
|
WmudPlayer *player;
|
||||||
WmudPlayer *player;
|
gboolean bademail;
|
||||||
gboolean bademail;
|
gint login_try_count;
|
||||||
gint login_try_count;
|
WmudClientYesnoCallback yesno_callback;
|
||||||
WmudClientYesnoCallback yesno_callback;
|
time_t last_recv;
|
||||||
time_t last_recv;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wmud_client_dispose(GObject *gobject)
|
wmud_client_dispose(GObject *gobject)
|
||||||
{
|
{
|
||||||
WmudClient *self = WMUD_CLIENT(gobject);
|
WmudClient *self = WMUD_CLIENT(gobject);
|
||||||
|
|
||||||
if (self->priv->socket) {
|
if (self->priv->socket) {
|
||||||
g_object_unref(self->priv->socket);
|
g_object_unref(self->priv->socket);
|
||||||
|
|
||||||
self->priv->socket = NULL;
|
self->priv->socket = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
G_OBJECT_CLASS(wmud_client_parent_class)->dispose(gobject);
|
G_OBJECT_CLASS(wmud_client_parent_class)->dispose(gobject);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wmud_client_finalize(GObject *gobject)
|
wmud_client_finalize(GObject *gobject)
|
||||||
{
|
{
|
||||||
WmudClient *self = WMUD_CLIENT(gobject);
|
WmudClient *self = WMUD_CLIENT(gobject);
|
||||||
|
|
||||||
g_string_free(self->priv->buffer, TRUE);
|
g_string_free(self->priv->buffer, TRUE);
|
||||||
g_source_destroy(self->priv->socket_source);
|
g_source_destroy(self->priv->socket_source);
|
||||||
|
|
||||||
G_OBJECT_CLASS(wmud_client_parent_class)->finalize(gobject);
|
G_OBJECT_CLASS(wmud_client_parent_class)->finalize(gobject);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void net_recv(WmudClient *self)
|
static void
|
||||||
|
net_recv(WmudClient *self)
|
||||||
{
|
{
|
||||||
self->priv->last_recv = time(NULL);
|
self->priv->last_recv = time(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wmud_client_class_init(WmudClientClass *klass)
|
wmud_client_class_init(WmudClientClass *klass)
|
||||||
{
|
{
|
||||||
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
|
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
|
||||||
|
|
||||||
gobject_class->dispose = wmud_client_dispose;
|
gobject_class->dispose = wmud_client_dispose;
|
||||||
gobject_class->finalize = wmud_client_finalize;
|
gobject_class->finalize = wmud_client_finalize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WmudClient::connected:
|
* WmudClient::connected:
|
||||||
* @client: The client emitting the signal
|
* @client: The client emitting the signal
|
||||||
*
|
*
|
||||||
* Emitted when a new client connection is accepted
|
* Emitted when a new client connection is accepted
|
||||||
**/
|
**/
|
||||||
signals[SIG_CONNECTED] = g_signal_newv("connected",
|
signals[SIG_CONNECTED] = g_signal_newv("connected",
|
||||||
WMUD_TYPE_CLIENT,
|
WMUD_TYPE_CLIENT,
|
||||||
G_SIGNAL_RUN_LAST,
|
G_SIGNAL_RUN_LAST,
|
||||||
NULL,
|
NULL,
|
||||||
NULL, NULL,
|
NULL, NULL,
|
||||||
NULL,
|
NULL,
|
||||||
G_TYPE_NONE, 0, NULL);
|
G_TYPE_NONE, 0, NULL);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WmudClient::net-hup:
|
* WmudClient::net-hup:
|
||||||
* @client: The client emitting the signal
|
* @client: The client emitting the signal
|
||||||
*
|
*
|
||||||
* Emitted when the remote side closes the connection
|
* Emitted when the remote side closes the connection
|
||||||
**/
|
**/
|
||||||
signals[SIG_NET_HUP] = g_signal_newv("net-hup",
|
signals[SIG_NET_HUP] = g_signal_newv("net-hup",
|
||||||
WMUD_TYPE_CLIENT,
|
WMUD_TYPE_CLIENT,
|
||||||
G_SIGNAL_RUN_LAST,
|
G_SIGNAL_RUN_LAST,
|
||||||
NULL,
|
NULL,
|
||||||
NULL, NULL,
|
NULL, NULL,
|
||||||
NULL,
|
NULL,
|
||||||
G_TYPE_NONE, 0, NULL);
|
G_TYPE_NONE, 0, NULL);
|
||||||
/**
|
/**
|
||||||
* WmudClient::net-recv:
|
* WmudClient::net-recv:
|
||||||
* @client: The client emitting the signal
|
* @client: The client emitting the signal
|
||||||
*
|
*
|
||||||
* Emitted when data is received through the client socket
|
* Emitted when data is received through the client socket
|
||||||
**/
|
**/
|
||||||
signals[SIG_NET_RECV] = g_signal_newv("net-recv",
|
signals[SIG_NET_RECV] = g_signal_newv("net-recv",
|
||||||
WMUD_TYPE_CLIENT,
|
WMUD_TYPE_CLIENT,
|
||||||
G_SIGNAL_RUN_LAST,
|
G_SIGNAL_RUN_LAST,
|
||||||
g_cclosure_new(G_CALLBACK(net_recv), NULL, NULL),
|
g_cclosure_new(G_CALLBACK(net_recv), NULL, NULL),
|
||||||
NULL, NULL,
|
NULL, NULL,
|
||||||
NULL,
|
NULL,
|
||||||
G_TYPE_NONE, 0, NULL);
|
G_TYPE_NONE, 0, NULL);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WmudClient::state-change:
|
* WmudClient::state-change:
|
||||||
* @client: The client emitting the signal
|
* @client: The client emitting the signal
|
||||||
* @old_state: The state which we are changing from.
|
* @old_state: The state which we are changing from.
|
||||||
* @new_state: The state which we are changing to.
|
* @new_state: The state which we are changing to.
|
||||||
*
|
*
|
||||||
* Emitted when the client changes state
|
* Emitted when the client changes state
|
||||||
**/
|
**/
|
||||||
signals[SIG_STATE_CHANGE] = g_signal_new("state-change",
|
signals[SIG_STATE_CHANGE] = g_signal_new("state-change",
|
||||||
WMUD_TYPE_CLIENT,
|
WMUD_TYPE_CLIENT,
|
||||||
G_SIGNAL_RUN_LAST,
|
G_SIGNAL_RUN_LAST,
|
||||||
0,
|
0,
|
||||||
NULL, NULL,
|
NULL, NULL,
|
||||||
NULL,
|
NULL,
|
||||||
G_TYPE_NONE, 2, WMUD_TYPE_CLIENT_STATE, WMUD_TYPE_CLIENT_STATE);
|
G_TYPE_NONE, 2, WMUD_TYPE_CLIENT_STATE, WMUD_TYPE_CLIENT_STATE);
|
||||||
|
|
||||||
g_type_class_add_private(klass, sizeof(WmudClientPrivate));
|
g_type_class_add_private(klass, sizeof(WmudClientPrivate));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wmud_client_init(WmudClient *self)
|
wmud_client_init(WmudClient *self)
|
||||||
{
|
{
|
||||||
self->priv = WMUD_CLIENT_GET_PRIVATE(self);
|
self->priv = WMUD_CLIENT_GET_PRIVATE(self);
|
||||||
self->priv->socket_source = NULL;
|
self->priv->socket_source = NULL;
|
||||||
self->priv->state = WMUD_CLIENT_STATE_FRESH;
|
self->priv->state = WMUD_CLIENT_STATE_FRESH;
|
||||||
self->priv->buffer = g_string_new("");
|
self->priv->buffer = g_string_new("");
|
||||||
self->priv->last_recv = time(NULL);
|
self->priv->last_recv = time(NULL);
|
||||||
|
|
||||||
g_signal_emit_by_name(self, "connected", G_TYPE_NONE);
|
g_signal_emit_by_name(self, "connected", G_TYPE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
net_emitter(GSocket *client_socket, GIOCondition condition, WmudClient *self)
|
net_emitter(GSocket *client_socket, GIOCondition condition, WmudClient *self)
|
||||||
{
|
{
|
||||||
if (condition & G_IO_HUP)
|
if (condition & G_IO_HUP) {
|
||||||
g_signal_emit_by_name(self, "net-close", G_TYPE_NONE);
|
g_signal_emit_by_name(self, "net-close", G_TYPE_NONE);
|
||||||
else if ((condition & G_IO_IN) || (condition & G_IO_PRI))
|
} else if ((condition & G_IO_IN) || (condition & G_IO_PRI)) {
|
||||||
g_signal_emit_by_name(self, "net-recv", G_TYPE_NONE);
|
g_signal_emit_by_name(self, "net-recv", G_TYPE_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
WmudClient *
|
WmudClient *
|
||||||
wmud_client_new(void)
|
wmud_client_new(void)
|
||||||
{
|
{
|
||||||
return g_object_new(WMUD_TYPE_CLIENT, NULL, NULL);
|
return g_object_new(WMUD_TYPE_CLIENT, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_client_set_socket(WmudClient *self, GSocket *socket)
|
wmud_client_set_socket(WmudClient *self, GSocket *socket)
|
||||||
{
|
{
|
||||||
/* TODO: Check if a socket is already set! */
|
/* TODO: Check if a socket is already set! */
|
||||||
self->priv->socket = socket;
|
self->priv->socket = socket;
|
||||||
self->priv->socket_source = g_socket_create_source(socket, G_IO_IN | G_IO_OUT | G_IO_PRI | G_IO_ERR | G_IO_HUP | G_IO_NVAL, NULL);
|
self->priv->socket_source = g_socket_create_source(socket, G_IO_IN | G_IO_OUT | G_IO_PRI | G_IO_ERR | G_IO_HUP | G_IO_NVAL, NULL);
|
||||||
|
|
||||||
g_source_set_callback(self->priv->socket_source, (GSourceFunc)net_emitter, self, NULL);
|
g_source_set_callback(self->priv->socket_source, (GSourceFunc)net_emitter, self, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
GSocket *
|
GSocket *
|
||||||
wmud_client_get_socket(WmudClient *self)
|
wmud_client_get_socket(WmudClient *self)
|
||||||
{
|
{
|
||||||
return self->priv->socket;
|
return self->priv->socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
GSource *
|
GSource *
|
||||||
wmud_client_get_socket_source(WmudClient *self)
|
wmud_client_get_socket_source(WmudClient *self)
|
||||||
{
|
{
|
||||||
return self->priv->socket_source;
|
return self->priv->socket_source;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -218,16 +219,16 @@ wmud_client_get_socket_source(WmudClient *self)
|
|||||||
void
|
void
|
||||||
wmud_client_send(WmudClient *self, const gchar *fmt, ...)
|
wmud_client_send(WmudClient *self, const gchar *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
GString *buf = g_string_new("");
|
GString *buf = g_string_new("");
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
g_string_vprintf(buf, fmt, ap);
|
g_string_vprintf(buf, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
/* TODO: error checking */
|
/* TODO: error checking */
|
||||||
g_socket_send(self->priv->socket, buf->str, buf->len, NULL, NULL);
|
g_socket_send(self->priv->socket, buf->str, buf->len, NULL, NULL);
|
||||||
g_string_free(buf, TRUE);
|
g_string_free(buf, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -242,92 +243,94 @@ wmud_client_send(WmudClient *self, const gchar *fmt, ...)
|
|||||||
void
|
void
|
||||||
wmud_client_close(WmudClient *self, gboolean send_goodbye)
|
wmud_client_close(WmudClient *self, gboolean send_goodbye)
|
||||||
{
|
{
|
||||||
if (send_goodbye)
|
if (send_goodbye) {
|
||||||
wmud_client_send(self, "\r\nHave a nice real-world day!\r\n\r\n");
|
wmud_client_send(self, "\r\nHave a nice real-world day!\r\n\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
g_socket_shutdown(self->priv->socket, TRUE, TRUE, NULL);
|
g_socket_shutdown(self->priv->socket, TRUE, TRUE, NULL);
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Connection closed.");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Connection closed.");
|
||||||
|
|
||||||
if (self->priv->player && !wmud_player_get_registered(self->priv->player))
|
if (self->priv->player && !wmud_player_get_registered(self->priv->player)) {
|
||||||
g_object_unref(self->priv->player);
|
g_object_unref(self->priv->player);
|
||||||
|
}
|
||||||
|
|
||||||
g_object_unref(self);
|
g_object_unref(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
gsize
|
gsize
|
||||||
wmud_client_get_buffer_length(WmudClient *self)
|
wmud_client_get_buffer_length(WmudClient *self)
|
||||||
{
|
{
|
||||||
return self->priv->buffer->len;
|
return self->priv->buffer->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
GString *
|
GString *
|
||||||
wmud_client_get_buffer(WmudClient *self)
|
wmud_client_get_buffer(WmudClient *self)
|
||||||
{
|
{
|
||||||
return self->priv->buffer;
|
return self->priv->buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
WmudClientState
|
WmudClientState
|
||||||
wmud_client_get_state(WmudClient *self)
|
wmud_client_get_state(WmudClient *self)
|
||||||
{
|
{
|
||||||
return self->priv->state;
|
return self->priv->state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_client_set_state(WmudClient *self, WmudClientState new_state)
|
wmud_client_set_state(WmudClient *self, WmudClientState new_state)
|
||||||
{
|
{
|
||||||
WmudClientState old_state = self->priv->state;
|
WmudClientState old_state = self->priv->state;
|
||||||
|
|
||||||
self->priv->state = new_state;
|
self->priv->state = new_state;
|
||||||
|
|
||||||
g_signal_emit_by_name(self, "state-change", old_state, new_state, G_TYPE_NONE);
|
g_signal_emit_by_name(self, "state-change", old_state, new_state, G_TYPE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_client_set_player(WmudClient *self, WmudPlayer *player)
|
wmud_client_set_player(WmudClient *self, WmudPlayer *player)
|
||||||
{
|
{
|
||||||
self->priv->player = player;
|
self->priv->player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
WmudPlayer *
|
WmudPlayer *
|
||||||
wmud_client_get_player(WmudClient *self)
|
wmud_client_get_player(WmudClient *self)
|
||||||
{
|
{
|
||||||
return self->priv->player;
|
return self->priv->player;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_client_set_yesno_callback(WmudClient *self, WmudClientYesnoCallback yesno_callback)
|
wmud_client_set_yesno_callback(WmudClient *self, WmudClientYesnoCallback yesno_callback)
|
||||||
{
|
{
|
||||||
self->priv->yesno_callback = yesno_callback;
|
self->priv->yesno_callback = yesno_callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
WmudClientYesnoCallback
|
WmudClientYesnoCallback
|
||||||
wmud_client_get_yesno_callback(WmudClient *self)
|
wmud_client_get_yesno_callback(WmudClient *self)
|
||||||
{
|
{
|
||||||
return self->priv->yesno_callback;
|
return self->priv->yesno_callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_client_set_authenticated(WmudClient *self, gboolean authenticated)
|
wmud_client_set_authenticated(WmudClient *self, gboolean authenticated)
|
||||||
{
|
{
|
||||||
self->priv->authenticated = authenticated;
|
self->priv->authenticated = authenticated;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_client_increase_login_fail_count(WmudClient *self)
|
wmud_client_increase_login_fail_count(WmudClient *self)
|
||||||
{
|
{
|
||||||
self->priv->login_try_count++;
|
self->priv->login_try_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint
|
gint
|
||||||
wmud_client_get_login_fail_count(WmudClient *self)
|
wmud_client_get_login_fail_count(WmudClient *self)
|
||||||
{
|
{
|
||||||
return self->priv->login_try_count;
|
return self->priv->login_try_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_client_set_bademail(WmudClient *self, gboolean bademail)
|
wmud_client_set_bademail(WmudClient *self, gboolean bademail)
|
||||||
{
|
{
|
||||||
self->priv->bademail = bademail;
|
self->priv->bademail = bademail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -340,18 +343,17 @@ wmud_client_set_bademail(WmudClient *self, gboolean bademail)
|
|||||||
gboolean
|
gboolean
|
||||||
wmud_client_get_bademail(WmudClient *client)
|
wmud_client_get_bademail(WmudClient *client)
|
||||||
{
|
{
|
||||||
return client->priv->bademail;
|
return client->priv->bademail;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_client_set_context(WmudClient *self, GMainContext *context)
|
wmud_client_set_context(WmudClient *self, GMainContext *context)
|
||||||
{
|
{
|
||||||
g_source_attach(self->priv->socket_source, context);
|
g_source_attach(self->priv->socket_source, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
guint32
|
guint32
|
||||||
wmud_client_get_last_recv_age(WmudClient *self)
|
wmud_client_get_last_recv_age(WmudClient *self)
|
||||||
{
|
{
|
||||||
return (time(NULL) - self->priv->last_recv);
|
return time(NULL) - self->priv->last_recv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,14 +24,13 @@
|
|||||||
|
|
||||||
#define WMUD_PLAYER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WMUD_TYPE_PLAYER, WmudPlayerPrivate))
|
#define WMUD_PLAYER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WMUD_TYPE_PLAYER, WmudPlayerPrivate))
|
||||||
|
|
||||||
struct _WmudPlayerPrivate
|
struct _WmudPlayerPrivate {
|
||||||
{
|
guint32 id;
|
||||||
guint32 id;
|
gchar *player_name;
|
||||||
gchar *player_name;
|
gchar *cpassword;
|
||||||
gchar *cpassword;
|
gchar *email;
|
||||||
gchar *email;
|
gint fail_count;
|
||||||
gint fail_count;
|
gboolean registered;
|
||||||
gboolean registered;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE(WmudPlayer, wmud_player, G_TYPE_OBJECT);
|
G_DEFINE_TYPE(WmudPlayer, wmud_player, G_TYPE_OBJECT);
|
||||||
@ -39,133 +38,136 @@ G_DEFINE_TYPE(WmudPlayer, wmud_player, G_TYPE_OBJECT);
|
|||||||
static void
|
static void
|
||||||
wmud_player_dispose(GObject *gobject)
|
wmud_player_dispose(GObject *gobject)
|
||||||
{
|
{
|
||||||
//WmudPlayer *self = WMUD_PLAYER(gobject);
|
G_OBJECT_CLASS(wmud_player_parent_class)->dispose(gobject);
|
||||||
|
|
||||||
G_OBJECT_CLASS(wmud_player_parent_class)->dispose(gobject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wmud_player_finalize(GObject *gobject)
|
wmud_player_finalize(GObject *gobject)
|
||||||
{
|
{
|
||||||
WmudPlayer *self = WMUD_PLAYER(gobject);
|
WmudPlayer *self = WMUD_PLAYER(gobject);
|
||||||
|
|
||||||
if (self->priv->player_name)
|
if (self->priv->player_name) {
|
||||||
g_free(self->priv->player_name);
|
g_free(self->priv->player_name);
|
||||||
|
}
|
||||||
|
|
||||||
if (self->priv->cpassword)
|
if (self->priv->cpassword) {
|
||||||
g_free(self->priv->cpassword);
|
g_free(self->priv->cpassword);
|
||||||
|
}
|
||||||
|
|
||||||
if (self->priv->email)
|
if (self->priv->email) {
|
||||||
g_free(self->priv->email);
|
g_free(self->priv->email);
|
||||||
|
}
|
||||||
|
|
||||||
G_OBJECT_CLASS(wmud_player_parent_class)->finalize(gobject);
|
G_OBJECT_CLASS(wmud_player_parent_class)->finalize(gobject);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wmud_player_class_init(WmudPlayerClass *klass)
|
wmud_player_class_init(WmudPlayerClass *klass)
|
||||||
{
|
{
|
||||||
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
|
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
|
||||||
|
|
||||||
gobject_class->dispose = wmud_player_dispose;
|
gobject_class->dispose = wmud_player_dispose;
|
||||||
gobject_class->finalize = wmud_player_finalize;
|
gobject_class->finalize = wmud_player_finalize;
|
||||||
|
|
||||||
g_type_class_add_private(klass, sizeof(WmudPlayerPrivate));
|
g_type_class_add_private(klass, sizeof(WmudPlayerPrivate));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wmud_player_init(WmudPlayer *self)
|
wmud_player_init(WmudPlayer *self)
|
||||||
{
|
{
|
||||||
self->priv = WMUD_PLAYER_GET_PRIVATE(self);
|
self->priv = WMUD_PLAYER_GET_PRIVATE(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
WmudPlayer *
|
WmudPlayer *
|
||||||
wmud_player_new(void)
|
wmud_player_new(void)
|
||||||
{
|
{
|
||||||
return g_object_new(WMUD_TYPE_PLAYER, NULL, NULL);
|
return g_object_new(WMUD_TYPE_PLAYER, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_player_set_cpassword(WmudPlayer *self, const gchar *cpassword)
|
wmud_player_set_cpassword(WmudPlayer *self, const gchar *cpassword)
|
||||||
{
|
{
|
||||||
if (self->priv->cpassword)
|
if (self->priv->cpassword) {
|
||||||
g_free(self->priv->cpassword);
|
g_free(self->priv->cpassword);
|
||||||
|
}
|
||||||
|
|
||||||
self->priv->cpassword = g_strdup(cpassword);
|
self->priv->cpassword = g_strdup(cpassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar *
|
gchar *
|
||||||
wmud_player_get_cpassword(WmudPlayer *self)
|
wmud_player_get_cpassword(WmudPlayer *self)
|
||||||
{
|
{
|
||||||
return self->priv->cpassword;
|
return self->priv->cpassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_player_set_registered(WmudPlayer *self, gboolean registered)
|
wmud_player_set_registered(WmudPlayer *self, gboolean registered)
|
||||||
{
|
{
|
||||||
self->priv->registered = registered;
|
self->priv->registered = registered;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
wmud_player_get_registered(WmudPlayer *self)
|
wmud_player_get_registered(WmudPlayer *self)
|
||||||
{
|
{
|
||||||
return self->priv->registered;
|
return self->priv->registered;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_player_set_player_name(WmudPlayer *self, const gchar *name)
|
wmud_player_set_player_name(WmudPlayer *self, const gchar *name)
|
||||||
{
|
{
|
||||||
self->priv->player_name = g_strdup(name);
|
self->priv->player_name = g_strdup(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar *
|
gchar *
|
||||||
wmud_player_get_player_name(WmudPlayer *self)
|
wmud_player_get_player_name(WmudPlayer *self)
|
||||||
{
|
{
|
||||||
return self->priv->player_name;
|
return self->priv->player_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_player_reset_fail_count(WmudPlayer *self)
|
wmud_player_reset_fail_count(WmudPlayer *self)
|
||||||
{
|
{
|
||||||
self->priv->fail_count = 0;
|
self->priv->fail_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_player_increase_fail_count(WmudPlayer *self)
|
wmud_player_increase_fail_count(WmudPlayer *self)
|
||||||
{
|
{
|
||||||
self->priv->fail_count++;
|
self->priv->fail_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint
|
gint
|
||||||
wmud_player_get_fail_count(WmudPlayer *self)
|
wmud_player_get_fail_count(WmudPlayer *self)
|
||||||
{
|
{
|
||||||
return self->priv->fail_count;
|
return self->priv->fail_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_player_set_email(WmudPlayer *self, const gchar *email)
|
wmud_player_set_email(WmudPlayer *self, const gchar *email)
|
||||||
{
|
{
|
||||||
if (self->priv->email)
|
if (self->priv->email) {
|
||||||
g_free(self->priv->email);
|
g_free(self->priv->email);
|
||||||
|
}
|
||||||
|
|
||||||
self->priv->email = g_strdup(email);
|
self->priv->email = g_strdup(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar *
|
gchar *
|
||||||
wmud_player_get_email(WmudPlayer *self)
|
wmud_player_get_email(WmudPlayer *self)
|
||||||
{
|
{
|
||||||
return self->priv->email;
|
return self->priv->email;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_player_set_id(WmudPlayer *self, guint32 id)
|
wmud_player_set_id(WmudPlayer *self, guint32 id)
|
||||||
{
|
{
|
||||||
self->priv->id = id;
|
self->priv->id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
guint32
|
guint32
|
||||||
wmud_player_get_id(WmudPlayer *self)
|
wmud_player_get_id(WmudPlayer *self)
|
||||||
{
|
{
|
||||||
return self->priv->id;
|
return self->priv->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -179,18 +181,19 @@ wmud_player_get_id(WmudPlayer *self)
|
|||||||
WmudPlayer *
|
WmudPlayer *
|
||||||
wmud_player_dup(WmudPlayer *self)
|
wmud_player_dup(WmudPlayer *self)
|
||||||
{
|
{
|
||||||
WmudPlayer *new_player;
|
WmudPlayer *new_player;
|
||||||
|
|
||||||
if (!self)
|
if (!self) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
new_player = wmud_player_new();
|
new_player = wmud_player_new();
|
||||||
new_player->priv->id = self->priv->id;
|
new_player->priv->id = self->priv->id;
|
||||||
new_player->priv->player_name = g_strdup(self->priv->player_name);
|
new_player->priv->player_name = g_strdup(self->priv->player_name);
|
||||||
new_player->priv->cpassword = g_strdup(self->priv->cpassword);
|
new_player->priv->cpassword = g_strdup(self->priv->cpassword);
|
||||||
new_player->priv->email = g_strdup(self->priv->email);
|
new_player->priv->email = g_strdup(self->priv->email);
|
||||||
|
|
||||||
return new_player;
|
return new_player;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -206,6 +209,5 @@ wmud_player_dup(WmudPlayer *self)
|
|||||||
gboolean
|
gboolean
|
||||||
wmud_player_password_valid(WmudPlayer *player, const gchar *password)
|
wmud_player_password_valid(WmudPlayer *player, const gchar *password)
|
||||||
{
|
{
|
||||||
return (g_strcmp0(crypt(password, player->priv->cpassword), player->priv->cpassword) == 0);
|
return g_strcmp0(crypt(password, player->priv->cpassword), player->priv->cpassword) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,41 +30,40 @@ G_DEFINE_TYPE(WmudWorld, wmud_world, G_TYPE_OBJECT);
|
|||||||
|
|
||||||
#define WMUD_WORLD_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WMUD_TYPE_WORLD, WmudWorldPrivate))
|
#define WMUD_WORLD_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WMUD_TYPE_WORLD, WmudWorldPrivate))
|
||||||
|
|
||||||
struct _WmudWorldPrivate
|
struct _WmudWorldPrivate {
|
||||||
{
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wmud_world_dispose(GObject *gobject)
|
wmud_world_dispose(GObject *gobject)
|
||||||
{
|
{
|
||||||
G_OBJECT_CLASS(wmud_world_parent_class)->dispose(gobject);
|
G_OBJECT_CLASS(wmud_world_parent_class)->dispose(gobject);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wmud_world_finalize(GObject *gobject)
|
wmud_world_finalize(GObject *gobject)
|
||||||
{
|
{
|
||||||
G_OBJECT_CLASS(wmud_world_parent_class)->finalize(gobject);
|
G_OBJECT_CLASS(wmud_world_parent_class)->finalize(gobject);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wmud_world_class_init(WmudWorldClass *klass)
|
wmud_world_class_init(WmudWorldClass *klass)
|
||||||
{
|
{
|
||||||
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
|
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
|
||||||
|
|
||||||
gobject_class->dispose = wmud_world_dispose;
|
gobject_class->dispose = wmud_world_dispose;
|
||||||
gobject_class->finalize = wmud_world_finalize;
|
gobject_class->finalize = wmud_world_finalize;
|
||||||
|
|
||||||
g_type_class_add_private(klass, sizeof(WmudWorldPrivate));
|
g_type_class_add_private(klass, sizeof(WmudWorldPrivate));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wmud_world_init(WmudWorld *self)
|
wmud_world_init(WmudWorld *self)
|
||||||
{
|
{
|
||||||
self->priv = WMUD_WORLD_GET_PRIVATE(self);
|
self->priv = WMUD_WORLD_GET_PRIVATE(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
WmudWorld *
|
WmudWorld *
|
||||||
wmud_world_new(void)
|
wmud_world_new(void)
|
||||||
{
|
{
|
||||||
return g_object_new(WMUD_TYPE_WORLD, NULL, NULL);
|
return g_object_new(WMUD_TYPE_WORLD, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
1072
wmud/world.c
1072
wmud/world.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user