« 2008年05月 | メイン | 2008年07月 »

2008年06月 アーカイブ

2008年06月27日

QStat UTF-8対応

たぶん、超ニッチな情報だと思うんですが、一応書いておこう :)

QStat の UTF-8 対応はかなりいい加減になっているようなので、以下のように修正すると、Source 系のゲームで日本語のサーバ名等が表示できます。あまりよくわからんのですが、Source 系は既に UTF-8 でサーバ名等を返してくるので、わざわざ Unicode から UTF-8 に変換しなくてもいいって感じなのかな。

% svn diff qstat.c
Index: qstat.c
===================================================================
--- qstat.c     (revision 310)
+++ qstat.c     (working copy)
@@ -11771,7 +11771,7 @@
        static unsigned char _buf[4][MAXSTRLEN + 8];
        static int _buf_index = 0;
        unsigned char *result, *b, *end;
-       unsigned int c;
+       unsigned char c;
 
        if (string == NULL)
        {
@@ -11843,7 +11843,7 @@
                {
                        fprintf(stderr, "Encoding error (%d) for U+%x, D+%d\n", 1, c, c);
                }
-               else if (xml_encoding == ENCODING_LATIN_1)
+               else if (xml_encoding == ENCODING_LATIN_1 || xml_encoding == ENCODING_UTF_8)
                {
                        if (!name_xforms)
                        {

実行例はこんな感じ。

% qstat -utf8 -xml -a2s 121.113.186.235:27015 
<?xml version="1.0" encoding="UTF-8"?>
<qstat>
        <server type="A2S" address="121.113.186.235:27015" status="UP">
                <hostname>121.113.186.235:27015</hostname>
                <name>[JP](test-L) 鉄砲倶楽部/部室</name>
                <gametype>cstrike</gametype>
                <map>de_dust2</map>
                <numplayers>0</numplayers>
                <maxplayers>32</maxplayers>
                <numspectators>0</numspectators>
                <maxspectators>0</maxspectators>
                <ping>47</ping>
                <retries>0</retries>
        </server>
</qstat>

ちなみに -utf8 をつけないとこんな感じ。

% qstat -xml -a2s 121.113.186.235:27015 
<?xml version="1.0" encoding="iso-8859-1"?>
<qstat>
        <server type="A2S" address="121.113.186.235:27015" status="UP">
                <hostname>121.113.186.235:27015</hostname>
                <name>[JP](test-L) IG 2E(6F%=I(/I(E.$</name>
                <gametype>cstrike</gametype>
                <map>de_dust2</map>
                <numplayers>0</numplayers>
                <maxplayers>32</maxplayers>
                <numspectators>0</numspectators>
                <maxspectators>0</maxspectators>
                <ping>31</ping>
                <retries>0</retries>
        </server>
</qstat>