Fixed encoding conversion fallback, added mcp session
This commit is contained in:
parent
e7cbc28042
commit
a0b238e444
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "gm-world.h"
|
#include "gm-world.h"
|
||||||
#include "gm-app.h"
|
#include "gm-app.h"
|
||||||
|
#include "mcp/gm-mcp-session.h"
|
||||||
#include "gm-triggers.h"
|
#include "gm-triggers.h"
|
||||||
#include "gm-marshal.h"
|
#include "gm-marshal.h"
|
||||||
#include "gm-net.h"
|
#include "gm-net.h"
|
||||||
|
@ -36,7 +37,7 @@ struct _GmWorldPrivate {
|
||||||
GmOptions *options;
|
GmOptions *options;
|
||||||
GmTriggers *triggers;
|
GmTriggers *triggers;
|
||||||
GmNet *net;
|
GmNet *net;
|
||||||
GmMcp *mcp;
|
GmMcpSession *mcp;
|
||||||
GList *history;
|
GList *history;
|
||||||
GList *editors;
|
GList *editors;
|
||||||
GmWorldInfo info;
|
GmWorldInfo info;
|
||||||
|
@ -93,6 +94,8 @@ gm_world_finalize(GObject *object) {
|
||||||
g_object_unref(world->priv->triggers);
|
g_object_unref(world->priv->triggers);
|
||||||
g_object_unref(world->priv->options);
|
g_object_unref(world->priv->options);
|
||||||
g_object_unref(world->priv->net);
|
g_object_unref(world->priv->net);
|
||||||
|
g_object_unref(world->priv->mcp);
|
||||||
|
|
||||||
G_OBJECT_CLASS(gm_world_parent_class)->finalize(object);
|
G_OBJECT_CLASS(gm_world_parent_class)->finalize(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,7 +258,7 @@ gm_world_init(GmWorld *world) {
|
||||||
world->priv->activity = 0;
|
world->priv->activity = 0;
|
||||||
world->priv->triggers = gm_triggers_new();
|
world->priv->triggers = gm_triggers_new();
|
||||||
world->priv->net = gm_net_new();
|
world->priv->net = gm_net_new();
|
||||||
world->priv->mcp = gm_mcp_new(world);
|
world->priv->mcp = gm_mcp_session_new(G_OBJECT(world));
|
||||||
world->priv->buffer = NULL;
|
world->priv->buffer = NULL;
|
||||||
world->priv->editing_info.is_editing = FALSE;
|
world->priv->editing_info.is_editing = FALSE;
|
||||||
|
|
||||||
|
@ -623,7 +626,7 @@ gm_world_process_line(GmWorld *world, gchar *line) {
|
||||||
if (strncasecmp(non_text_start + 3, " edit ", 6) == 0) {
|
if (strncasecmp(non_text_start + 3, " edit ", 6) == 0) {
|
||||||
gm_world_parse_legacy_editing_start(world, non_text_start + 9);
|
gm_world_parse_legacy_editing_start(world, non_text_start + 9);
|
||||||
} else {
|
} else {
|
||||||
gm_mcp_handle(world->priv->mcp, non_text_start + 3);
|
gm_mcp_session_handle_oob(world->priv->mcp, non_text_start + 3);
|
||||||
//gm_world_log(world, LOG_MCP_IN, non_text_start);
|
//gm_world_log(world, LOG_MCP_IN, non_text_start);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -713,19 +716,13 @@ gm_world_add_editor(GmWorld *world, GmEditor *editor) {
|
||||||
void
|
void
|
||||||
gm_world_sendln(GmWorld *world, gchar *text) {
|
gm_world_sendln(GmWorld *world, gchar *text) {
|
||||||
gchar *normal;
|
gchar *normal;
|
||||||
GError *err = NULL;
|
|
||||||
gint written;
|
|
||||||
|
|
||||||
// Convert text from utf-8 to the correct locale
|
// Convert text from utf-8 to the correct locale
|
||||||
normal = g_convert_with_fallback(text, g_utf8_strlen(text, -1),
|
normal = gm_to_utf8_with_fallback(text, -1,
|
||||||
gm_options_get(world->priv->options, "charset"), "UTF-8", "?",
|
gm_options_get(world->priv->options, "charset"), "?");
|
||||||
NULL, &written, &err);
|
|
||||||
|
|
||||||
if (!normal) {
|
if (!normal) {
|
||||||
debug_msg(1, "GmWorld.Send: conversion failed: %s (written %d)!",
|
debug_msg(1, "GmWorld.Send: conversion failed!");
|
||||||
err->message, written);
|
|
||||||
g_error_free(err);
|
|
||||||
err = NULL;
|
|
||||||
normal = g_strdup(text);
|
normal = g_strdup(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -818,19 +815,13 @@ void
|
||||||
on_gm_world_net_bytes_recv(GmNet *net, gchar *text, gint len,
|
on_gm_world_net_bytes_recv(GmNet *net, gchar *text, gint len,
|
||||||
GmWorld *world) {
|
GmWorld *world) {
|
||||||
gchar *all, *utext, *ptr, *line, *p;
|
gchar *all, *utext, *ptr, *line, *p;
|
||||||
gsize read, written;
|
|
||||||
GError *err = NULL;
|
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
utext = g_convert_with_fallback(text, len, "UTF-8",
|
utext = gm_to_utf8_with_fallback(text, len,
|
||||||
gm_options_get(world->priv->options, "charset"),
|
gm_options_get(world->priv->options, "charset"), "?");
|
||||||
NULL, &read, &written, &err);
|
|
||||||
|
|
||||||
if (!utext) {
|
if (!utext) {
|
||||||
debug_msg(1, "GmWorld.NetBytesRecv: conversion failed: %s (written %d, "
|
debug_msg(1, "GmWorld.NetBytesRecv: conversion failed!");
|
||||||
"read %d)!", err->message, written, read);
|
|
||||||
g_error_free(err);
|
|
||||||
err = NULL;
|
|
||||||
utext = g_strndup(text, len);
|
utext = g_strndup(text, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -853,7 +844,6 @@ on_gm_world_net_bytes_recv(GmNet *net, gchar *text, gint len,
|
||||||
line[i] = '\n';
|
line[i] = '\n';
|
||||||
line[i + 1] = '\0';
|
line[i + 1] = '\0';
|
||||||
|
|
||||||
gm_world_log(world, LOG_MCP_IN, line);
|
|
||||||
gm_world_process_line(world, line);
|
gm_world_process_line(world, line);
|
||||||
p = ptr + 1;
|
p = ptr + 1;
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
Reference in New Issue
Block a user