OSDN Git Service

[feature]スコアDBのdead_placeカラムに死亡場所を記録する
authorHabu <habu@users.sourceforge.jp>
Thu, 12 Apr 2018 23:03:05 +0000 (08:03 +0900)
committerHabu <habu@users.sourceforge.jp>
Thu, 12 Apr 2018 23:03:05 +0000 (08:03 +0900)
score/db_common.inc
score/dump_file.inc
score/register_score.php

index 40bab0e..26fec69 100644 (file)
@@ -521,4 +521,36 @@ EOM
 
         return FALSE;
     }
+
+
+    /**
+     * 死亡場所を更新する
+     *
+     * @param integer $score_id 死亡場所を更新するスコアのscore_id
+     * @param string|FALSE $dead_place 死亡場所を表す文字列。
+     *                     FALSEの場合はなにもしない。
+     *
+     * @return integer 更新した行数。
+     */
+    public function update_dead_place($score_id, $dead_place)
+    {
+        if ($dead_place === FALSE) {
+            return FALSE;
+}
+        $stmt = $this->dbh->prepare(
+            <<<EOM
+UPDATE scores
+SET dead_place = :dead_place
+WHERE score_id = :score_id
+EOM
+        );
+
+        $result = $stmt->execute(
+            [':score_id' => $score_id,
+             ':dead_place' => $dead_place,
+             ]
+        );
+
+        return $result;
+    }
 }
index f611b12..72ec4c6 100644 (file)
@@ -153,6 +153,35 @@ class DumpFile
         }
     }
 
+
+    /**
+     * キャラクタダンプから死んだ場所を得る
+     *
+     * @return string|FALSE 死んだ場所を表す文字列。
+     *                死んだ場所が得られなかった場合FALSE。
+     */
+    public function get_dead_place()
+    {
+
+        $death_reason_detail = $this->get_death_reason_detail();
+        if ($death_reason_detail === FALSE) {
+            return FALSE;
+        }
+        $places = implode("|", [
+            "階", "荒野", "地上", "街",
+            "辺境の地", "モリバント", "アングウィル", "テルモラ", "ズル",
+            "クエスト「.+」", "クエスト",
+        ]);
+
+        if (preg_match("/^(.*(?:{$places})\s*)で.+$/u",
+                        $death_reason_detail, $matches)) {
+            return $matches[1];
+        } else {
+            return FALSE;
+        }
+    }
+
+
     private static function browser_accept_encodings()
     {
         $accept_encoding = filter_input(INPUT_SERVER, 'HTTP_ACCEPT_ENCODING');
index fb8d898..a913fd0 100644 (file)
@@ -205,6 +205,9 @@ if ($score_id === FALSE) {
     exit;
 }
 
+// 登録成功、HTTPレスポンスコード 200 OK を返す
+http_response_code(200);
+
 $dumpfile = new DumpFile($score_id);
 $dumpfile->save('dumps', 'txt', $split_contents[1]);
 if (validate_screen_dump($split_contents[2])) {
@@ -213,8 +216,8 @@ if (validate_screen_dump($split_contents[2])) {
     $dumpfile->save('screens', 'html.bad', $split_contents[2]);
 }
 
-// 登録成功、HTTPレスポンスコード 200 OK を返す
-http_response_code(200);
+$dead_place = $dumpfile->get_dead_place();
+$db->update_dead_place($score_id, $dead_place);
 
 exec("nohup python tools/tweet_score.py -c tools/tweet_score.cfg -l tweet_score.log -s {$score_id} > /dev/null &");