Index: pycgibattler/trunk/index.cgi
===================================================================
--- pycgibattler/trunk/index.cgi	(revision 86)
+++ pycgibattler/trunk/index.cgi	(revision 89)
@@ -24,6 +24,8 @@
 import copy
 import fcntl
+import base64
 import shutil
 import hashlib
+import xmlrpclib
 import ConfigParser
 
@@ -131,8 +133,8 @@
 
     @classmethod
-    def dump(klass, name, code):
+    def dump(klass, name, code, data):
         self = klass(hashlib.sha512(code).hexdigest())
         cname = os.path.join(self._prefix, os.path.basename(name))
-        warrior = self.make_warrior(code)
+        warrior = self.make_warrior(code, data)
 
         with open(self._locker, 'w') as fp:
@@ -157,5 +159,5 @@
 
     @classmethod
-    def make_warrior(klass, code):
+    def make_warrior(klass, code, data):
         chara_names = [x.strip() for x in open(os.path.expanduser(
             CONFIG.get('character', 'name_list_file'))).xreadlines()]
@@ -177,6 +179,15 @@
             skills.append(sk)
 
-        return pycodebattler.warrior.Warrior.make(
-            name, _StringIO.StringIO(code), skills)
+        return pycodebattler.warrior.Warrior(
+            name,
+            int(data['hitpoint']),
+            int(data['skillpoint']),
+            int(data['strength']),
+            int(data['concentration']),
+            int(data['defense']),
+            int(data['agility']),
+            int(data['luck']),
+            skills,
+        )
 
     @classmethod
@@ -247,44 +258,88 @@
 
 
+def scouter(lang, code):
+    if lang not in CONFIG.options('scouter_api'):
+        raise ValueError('invalid language')
+
+    proxy = xmlrpclib.ServerProxy(CONFIG.get('scouter_api', lang))
+    data = proxy.Scout({'version': 1.0,
+                        'code': base64.standard_b64encode(code)})
+
+    if type(data) is not dict:
+        raise ValueError('invalid api response')
+    if 'version' not in data:
+        raise ValueError('invalid api response (version not found)')
+    if data['version'] != 1.0:
+        raise ValueError('invalid api response (invalid version)')
+    if 'result' not in data:
+        raise ValueError('invalid api response (result not found)')
+    if type(data['result']) is not dict:
+        raise ValueError('invalid api response (invalid result)')
+    return data['result']
+
+
+def handle_mode_json(form):
+    if 'id' not in form:
+        ids = [cm.id() for cm in CharacterManager.list()]
+    else:
+        tmp = form['id']
+        if type(tmp) is not list:
+            tmp = [form['id']]
+        ids = [id_.value for id_ in tmp]
+
+    data = {}
+    try:
+        for id_ in ids:
+            data[id_] = CharacterManager(id_).flatten()
+    except:
+        return jsondump({'result': {}})
+
+    return jsondump({'result': data})
+
+
+def handle_id(form):
+    entries = [CharacterManager(form.getfirst('id')).entry()]
+    return httpdump(CONFIG.get('template', 'character'), entries=entries)
+
+
+def handle_warrior(form):
+    ids = form['warrior']
+
+    if type(ids) is not list:
+        ids = [ids]
+
+    if len(ids) > CONFIG.getint('battle', 'max_entries'):
+        raise ValueError('battle warriors too long')
+
+    warriors = [CharacterManager(id_.value).load()[1] for id_ in ids]
+    result = do_battle(warriors)
+    return httpdump(CONFIG.get('template', 'battle'), result=result)
+
+
+def handle_file(form):
+    item = form['filename']
+    lang = form.getfirst('lang')
+
+    if not item.file or not item.filename or not lang:
+        raise ValueError('missing parameter')
+
+    code = item.file.read(CONFIG.getint('limit', 'max_size'))
+    data = scouter(lang, code)
+    CharacterManager.dump(item.filename, code, data)
+    return True
+
+
 def main():
     form = cgi.FieldStorage()
 
     if 'mode' in form and form.getfirst('mode') == 'json':
-        if 'id' not in form:
-            ids = [cm.id() for cm in CharacterManager.list()]
-        else:
-            tmp = form['id']
-            if type(tmp) is not list:
-                tmp = [form['id']]
-            ids = [id_.value for id_ in tmp]
-
-        data = {}
-        try:
-            for id_ in ids:
-                data[id_] = CharacterManager(id_).flatten()
-        except:
-            return jsondump({'result': {}})
-        return jsondump({'result': data})
-
+        return handle_mode_json(form)
     if 'id' in form:
-        entries = [CharacterManager(form.getfirst('id')).entry()]
-        return httpdump(CONFIG.get('template', 'character'), entries=entries)
-
+        return handle_id(form)
     if 'warrior' in form:
-        ids = form['warrior']
-        if type(ids) is not list:
-            ids = [ids]
-        if len(ids) > CONFIG.getint('battle', 'max_entries'):
-            raise ValueError('battle warriors too long')
-        warriors = [CharacterManager(id_.value).load()[1] for id_ in ids]
-        result = do_battle(warriors)
-        return httpdump(CONFIG.get('template', 'battle'), result=result)
-
-    if 'filename' in form:
-        item = form['filename']
-        if item.file and item.filename:
-            code = item.file.read(CONFIG.getint('limit', 'max_size'))
-            if code:
-                CharacterManager.dump(item.filename, code)
+        return handle_warrior(form)
+    if 'filename' in form and 'lang' in form:
+        if not handle_file(form):
+            return httpdump(CONFIG.get('template', 'error'))
 
     CharacterManager.sweep()
