#!/bin/bash

[ "$4" == "" ] && exec echo "Usage: $0 <Region Name> <Zone ID> <MS IP> <WS IP Initialize> <Parallel Numbers>"

REGION_NAME=$1
ZONE_ID=$2
MS_IP=$3
WS_IP_INIT=$4
[ ! -z "$5" ] && PARA_NUM=$(($5 - 1)) || PARA_NUM=9

OUTPUT=""
OUTPUT="## ${REGION_NAME}\n"
OUTPUT="${OUTPUT}${MS_IP} GDS${ZONE_ID} MS${ZONE_ID} GAMEDB${ZONE_ID} SOCIETYS${ZONE_ID} SOCIETYDB${ZONE_ID} RANKS${ZONE_ID} CHATS${ZONE_ID}\n"

WID_OUTPUT_ALL=""
## 控制 WS INT IP
for ADD_NUM in $(seq 0 9); do
    PREFIX=${WS_IP_INIT%.*}.
    LAST=${WS_IP_INIT##*.}
    REAL=$((LAST + ADD_NUM))
    INT_IP="${PREFIX}${REAL}"

    # 控制 WS ID
    WID_OUTPUT=""
    for LOOP_NUM in $(seq 0 ${PARA_NUM}); do
        REAL_NUM=$((ADD_NUM + 1 + LOOP_NUM * 10))
        #echo "REAL_NUM: ${REAL_NUM}"
        WID=$(printf "%02d\n" "$REAL_NUM")
        #echo "WID: ${WID}"
        WID_OUTPUT="${WID_OUTPUT} WS${ZONE_ID}${WID} WHS${ZONE_ID}${WID}1 WHS${ZONE_ID}${WID}2 WORLDDB${ZONE_ID}${WID} WWEBSPS${ZONE_ID}${WID}1 "
    done
    WID_OUTPUT_ALL="${WID_OUTPUT_ALL}${INT_IP} ${WID_OUTPUT}\n"
done
OUTPUT="${OUTPUT}${WID_OUTPUT_ALL}"

echo -e ${OUTPUT}
