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-app.h"
|
||||
#include "mcp/gm-mcp-session.h"
|
||||
#include "gm-triggers.h"
|
||||
#include "gm-marshal.h"
|
||||
#include "gm-net.h"
|
||||
|
@ -36,7 +37,7 @@ struct _GmWorldPrivate {
|
|||
GmOptions *options;
|
||||
GmTriggers *triggers;
|
||||
GmNet *net;
|
||||
GmMcp *mcp;
|
||||
GmMcpSession *mcp;
|
||||
GList *history;
|
||||
GList *editors;
|
||||
GmWorldInfo info;
|
||||
|
@ -93,6 +94,8 @@ gm_world_finalize(GObject *object) {
|
|||
g_object_unref(world->priv->triggers);
|
||||
g_object_unref(world->priv->options);
|
||||
g_object_unref(world->priv->net);
|
||||
g_object_unref(world->priv->mcp);
|
||||
|
||||
G_OBJECT_CLASS(gm_world_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
|
@ -255,7 +258,7 @@ gm_world_init(GmWorld *world) {
|
|||
world->priv->activity = 0;
|
||||
world->priv->triggers = gm_triggers_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->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) {
|
||||
gm_world_parse_legacy_editing_start(world, non_text_start + 9);
|
||||
} 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);
|
||||
}
|
||||
} else {
|
||||
|
@ -713,19 +716,13 @@ gm_world_add_editor(GmWorld *world, GmEditor *editor) {
|
|||
void
|
||||
gm_world_sendln(GmWorld *world, gchar *text) {
|
||||
gchar *normal;
|
||||
GError *err = NULL;
|
||||
gint written;
|
||||
|
||||
// Convert text from utf-8 to the correct locale
|
||||
normal = g_convert_with_fallback(text, g_utf8_strlen(text, -1),
|
||||
gm_options_get(world->priv->options, "charset"), "UTF-8", "?",
|
||||
NULL, &written, &err);
|
||||
normal = gm_to_utf8_with_fallback(text, -1,
|
||||
gm_options_get(world->priv->options, "charset"), "?");
|
||||
|
||||
if (!normal) {
|
||||
debug_msg(1, "GmWorld.Send: conversion failed: %s (written %d)!",
|
||||
err->message, written);
|
||||
g_error_free(err);
|
||||
err = NULL;
|
||||
debug_msg(1, "GmWorld.Send: conversion failed!");
|
||||
normal = g_strdup(text);
|
||||
}
|
||||
|
||||
|
@ -818,19 +815,13 @@ void
|
|||
on_gm_world_net_bytes_recv(GmNet *net, gchar *text, gint len,
|
||||
GmWorld *world) {
|
||||
gchar *all, *utext, *ptr, *line, *p;
|
||||
gsize read, written;
|
||||
GError *err = NULL;
|
||||
gint i;
|
||||
|
||||
utext = g_convert_with_fallback(text, len, "UTF-8",
|
||||
gm_options_get(world->priv->options, "charset"),
|
||||
NULL, &read, &written, &err);
|
||||
utext = gm_to_utf8_with_fallback(text, len,
|
||||
gm_options_get(world->priv->options, "charset"), "?");
|
||||
|
||||
if (!utext) {
|
||||
debug_msg(1, "GmWorld.NetBytesRecv: conversion failed: %s (written %d, "
|
||||
"read %d)!", err->message, written, read);
|
||||
g_error_free(err);
|
||||
err = NULL;
|
||||
debug_msg(1, "GmWorld.NetBytesRecv: conversion failed!");
|
||||
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 + 1] = '\0';
|
||||
|
||||
gm_world_log(world, LOG_MCP_IN, line);
|
||||
gm_world_process_line(world, line);
|
||||
p = ptr + 1;
|
||||
i = 0;
|
||||
|
|
Reference in New Issue