#!/bin/sh # Installs the unlimited 移动戒指 (README.md): run on the server from this directory, then restart db + game. # Replaces quest ring_warp with ./ring_warp.quest (GBK), compiles only ring_warp in an isolated staging directory, and names # item 70058 移动戒指 on the server (item_names.txt and item_proto.locale_name; the client has its own name), and # drops its level 30 limit in item_proto.txt (CHARACTER::CanUseItem refuses it to lower characters). set -eu MODE=${1:-full} case "$MODE" in full|--quest-only) ;; *) echo "usage: $0 [--quest-only]" >&2; exit 2 ;; esac SERVER=${SERVER:-/usr/metin2/server} LOCALE=${LOCALE:-newcibn} QUEST="$SERVER/share/locale/$LOCALE/quest" NAMES="$SERVER/share/conf/item_names.txt" PROTO="$SERVER/share/conf/item_proto.txt" HERE=$(cd "$(dirname "$0")" && pwd) BACKUP=/root/backup-ringwarp/$(date +%Y%m%d-%H%M%S) export LC_ALL=C mkdir -p "$BACKUP" cp -p "$QUEST/ring_warp.quest" "$NAMES" "$PROTO" "$BACKUP/" echo "backup: $BACKUP" # A GBK trail byte 0x5C would be a backslash to qc. iconv -f UTF-8 -t GBK "$HERE/ring_warp.quest" > "$BACKUP/ring_warp.gbk" if grep -q '\\' "$BACKUP/ring_warp.gbk"; then echo "ring_warp.quest: backslash byte in GBK" >&2; exit 1; fi # Compile in isolation before touching any live quest objects. mkdir -p "$BACKUP/stage" "$BACKUP/object/state" "$BACKUP/object/10031/sig_use" "$BACKUP/object/70058/use" "$BACKUP/object/76042/use" [ -f "$QUEST/object/state/ring_warp" ] && cp -p "$QUEST/object/state/ring_warp" "$BACKUP/object/state/" [ -f "$QUEST/object/10031/sig_use/ring_warp.start" ] && cp -p "$QUEST/object/10031/sig_use/ring_warp.start" "$BACKUP/object/10031/sig_use/" [ -f "$QUEST/object/70058/use/ring_warp.start" ] && cp -p "$QUEST/object/70058/use/ring_warp.start" "$BACKUP/object/70058/use/" [ -f "$QUEST/object/76042/use/ring_warp.start" ] && cp -p "$QUEST/object/76042/use/ring_warp.start" "$BACKUP/object/76042/use/" cp "$QUEST/quest_functions" "$BACKUP/stage/" cp "$BACKUP/ring_warp.gbk" "$BACKUP/stage/ring_warp.quest" (cd "$BACKUP/stage" && "$QUEST/qc" ring_warp.quest) > "$BACKUP/qc.log" 2>&1 || { cat "$BACKUP/qc.log" >&2; exit 1; } test -s "$BACKUP/stage/object/state/ring_warp" test -s "$BACKUP/stage/object/10031/sig_use/ring_warp.start" test -s "$BACKUP/stage/object/70058/use/ring_warp.start" test -s "$BACKUP/stage/object/76042/use/ring_warp.start" cat "$BACKUP/ring_warp.gbk" > "$QUEST/ring_warp.quest" cp -r "$BACKUP/stage/object/"* "$QUEST/object/" if [ "$MODE" = "--quest-only" ]; then echo "done; reload quests on every game core, or restart game cores (db/auth need no restart)" exit 0 fi name=$(printf '移动戒指' | iconv -f UTF-8 -t GB2312) awk -F'\t' -v OFS='\t' -v name="$name" '$1 == 70058 { $2 = name; n++ } { print } END { if (n != 1) { print "item_names.txt: 70058 not found" > "/dev/stderr"; exit 1 } }' \ "$NAMES" > "$BACKUP/item_names.new" cat "$BACKUP/item_names.new" > "$NAMES" mysql -uroot player -e "UPDATE item_proto SET locale_name = '$name' WHERE vnum = 70058" # LIMIT_TYPE0 / LIMIT_VALUE0 (columns 15, 16): LEVEL 30 -> none. The db process loads item_proto.txt at boot # and mirrors it into the item_proto table. awk -F'\t' -v OFS='\t' '$1 == 70058 { if ($15 == "LEVEL") { $15 = "LIMIT_NONE"; $16 = 0 }; n++ } { print } END { if (n != 1) { print "item_proto.txt: 70058 not found" > "/dev/stderr"; exit 1 } }' \ "$PROTO" > "$BACKUP/item_proto.new" cat "$BACKUP/item_proto.new" > "$PROTO" mysql -uroot player -e "UPDATE item_proto SET limittype0 = 0, limitvalue0 = 0 WHERE vnum = 70058 AND limittype0 = 1" # Only ring_warp is compiled; other quest objects are preserved. ls "$QUEST/object/10031/sig_use" echo "done; restart db and game"