summaryrefslogtreecommitdiff
path: root/test/tmw-info
blob: e66e49f250ea5248d89c881966be3a6e72b6e87b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
#!/bin/bash
# TMW GM Log Downloader (original): https://gitlab.com/liviorecchia/tmw-gm-log-downloader
# TMW GM Log Downloader(deprecated): https://gitlab.com/Ledmitz/tmw-gm-log-downloader
# tmw-gmlog(deprecated): https://gitlab.com/Ledmitz/tmw-gmlog
# tmw-info: https://gitlab.com/Ledmitz/tmw-info
# The Mana World: https://themanaworld.org]
# Ledmitz (2020) - GPL 3.0


months=(01 02 03 04 05 06 07 08 09 10 11 12)
thisYear=$(date -u +'%Y')
thisMonth=$(date -u +'%m')
# Main DIR
TMW_INFO="$HOME/.tmw-info"
# Items DB DIR
ITEM_DIR="$TMW_INFO/item"
# Monster DB DIR
MOB_DIR="$TMW_INFO/mob"
# Chat logs DIR
CHAT_LOGS="$HOME/.local/share/mana/logs/server.themanaworld.org/"









# GM Log DIR
TMW_GM_LOGS="$TMW_INFO/logs"
GM_LOG_LIST="$TMW_INFO/gm_log_list"
# Current month's GM log
GM_LOG="$TMW_INFO/gm_log.tmp"
# File to be read as report
GM_REPORT="$TMW_INFO/gm_report.txt"

# Runs on exit (deletes tmp files)
function FINISH
{
    rm -f "$TMW_INFO"/*.tmp
}
trap FINISH EXIT


help(){
    echo "tmw-info [command] [STRING]"
    echo "    help / --help / -h (this help screen)"
    echo "    cmds (ManaPlus and GM command reference)"
    echo "    news (reads game news)"
    echo "    online (shows online players)"
    echo "    gm-update (downloads all GM logs. Should be run before searching)"
    echo "    gm-search TERM1 TERM2 TERM3 ... (results contain any of the terms)"
    echo "    gm-asearch TERM1 TERM2 TERM3 ... (results contain all of the terms)"
    echo "    gm-esearch TERM1 TERM2 TERM3 ... (results contain the exact term)"
    echo "    gm-show (if zenity is installed, displays a GUI pop-up of the last 10 issued GM CMDs), otherwise in terminal"
    echo "    chat-search TERM1 TERM2 TERM3 ... (chat: results contain all of the terms)"
    echo "    item-update (downloads item DB. Must be run before searching)"
    echo "    item-search TERM1 TERM2 TERM3 ... (items: results contain all of the terms)"
    echo "    mob-update (downloads monster DB. Must be run before searching)"
    echo "    mob-search TERM1 TERM2 TERM3 ... (monsters: results contain all of the terms)"
    echo 'If you get and error while searching, it may contain special characters and needs to be quoted'
}


if [ -z "$1" ]; then
    echo "Missing command"
    help
    exit 0
fi
# If no search term is given
if [ "$1" == "gm-search" ] || [ "$1" == "gm-asearch" ] || [ "$1" == "gm-esearch" ] || [ "$1" == "item-search" ] || [ "$1" == "mob-search" ]; then
    if [ -z "$2" ]; then
        echo "Missing search terms"
        help
        exit 0
    fi
    # If either the "logs" DIR doesn't exist or there are no files in the DIR
fi

# Create a DIR to save files in
mkdir -p "$TMW_INFO"

if [ "$1" == "help" ] || [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
    help
elif [ "$1" == "news" ]; then
    curl -s 'https://themanaworld.github.io/tmwa-server-data/news.html' | sed 's/<\/*[^>]*>//g' | less
elif [ "$1" == "online" ]; then
    curl -s 'https://server.themanaworld.org/' | sed 's/<\/*[^>]*>//g' | sed -r '/^\s*$/d' | sed -r '/^\s*Name\s*$/d' | sed 1d
elif [ "$1" == "gm-update" ]; then
    mkdir -p "$TMW_GM_LOGS"
    # Get list of files from server to read the byte counts from
    wget -c -q -O "$GM_LOG_LIST.tmp" 'https://server.themanaworld.org/gm'
    sed 's/<\/*[^>]*>//g' "$GM_LOG_LIST.tmp" > "$GM_LOG_LIST"
    # Download the very first one without updating it if already exists
    #This is the only gmlog without a byte count check. If it becomes corrupted, it must be deleted
    wget -nc -q -P "$TMW_GM_LOGS" 'https://server.themanaworld.org/gm/gm.log.2008-12'
    for (( year = 2009; year <= thisYear; year++ ))
    do
        for month in ${months[*]}
        do
                # If the log is from this year and the month hasn't come yet, do nothing
                if [[ "$year" == "$thisYear" ]] && [[ "$month" > "$thisMonth" ]]; then
                    :
                else
                    # Get the bytecounts reported by server to compare with local file
                    BYTECOUNT_WEB=$(grep "gm.log.$year-$month" "$GM_LOG_LIST" | awk '{print $4}' | sed -E 's/\s//g')
                    BYTECOUNT_LOCAL=$(ls -l "$TMW_GM_LOGS/gm.log.$year-$month" 2> '/dev/null' | awk '{print $5}' | sed -E 's/\s//g')
                    #echo $BYTECOUNT_WEB
                    #echo $BYTECOUNT_LOCAL
                    if [[ "$BYTECOUNT_WEB" != "$BYTECOUNT_LOCAL" ]]; then
                        echo "Downloading $month/$year"
                        wget -q -c -P "$TMW_GM_LOGS" "https://server.themanaworld.org/gm/gm.log.$year-$month"
                    fi
                fi
        done
    done
# All searches cancel special grep characters, [ and ], which are read by grep, even in single quoted text
# When echoing back, the \ are again removed to show what was originally typed by the user correctly
# only [ and ] regex characters seemed to pose a problem
elif [ "$1" == "gm-search" ]; then
    if [ ! -d "$TMW_GM_LOGS" ] || [ -z "$(ls "$TMW_GM_LOGS")" ]; then
        echo 'You must run gm-update before searching'
        exit 0
    fi
    # Any terms: This must be an array because each term is searched separately in the for loop.
    SEARCH_TERMS=($(echo "$*" | sed -E 's/^gm-search\s//g' | sed 's/\[/\\\[/g' | sed 's/\]/\\\]/g'))
        for WORD in "${SEARCH_TERMS[@]}"
        do
            echo "========== Results (any): $WORD ==========" | sed 's/\\//g'
            grep -hi "$WORD" "$TMW_GM_LOGS"/*
        done
elif [ "$1" == "gm-asearch" ]; then
    if [ ! -d "$TMW_GM_LOGS" ] || [ -z "$(ls "$TMW_GM_LOGS")" ]; then
        echo 'You must run gm-update before searching'
        exit 0
    fi
    ## Livio > You can probably tidy this up as a for loop and an array? I'm more used to while loops
    # All terms: This must not be an array
    SEARCH_TERMS=$(echo "$*" | sed -E 's/^gm-asearch\s//g' | sed 's/\[/\\\[/g' | sed 's/\]/\\\]/g')
    WORD_COUNT=$(echo "$SEARCH_TERMS" | wc -w)
    COUNT='1'
    #echo "SEARCH_TERMS: $SEARCH_TERMS"
    #echo "WORD_COUNT: $WORD_COUNT"
    #echo "COUNT: $COUNT"
    echo "========== Results (all): $SEARCH_TERMS ==========" | sed 's/\\//g'
        while [ "$COUNT" -le "$WORD_COUNT" ]
        do
            WORD=$(echo "$SEARCH_TERMS" | awk "{print \$$COUNT}")
            #echo "WORD: $WORD"
                if [ "$COUNT" = '1' ]; then
                    grep -hi "$WORD" "$TMW_GM_LOGS"/* > "$TMW_INFO/gm-asearch$COUNT.tmp"
                else
                    grep -hi "$WORD" "$TMW_INFO/gm-asearch$LAST_COUNT.tmp" > "$TMW_INFO/gm-asearch$COUNT.tmp"
                fi
            LAST_COUNT="$COUNT"
            COUNT=$(( COUNT + 1 ))
            #echo "COUNT: $COUNT"
            #echo "LAST_COUNT: $LAST_COUNT"
        done
    cat "$TMW_INFO/gm-asearch$LAST_COUNT.tmp"
elif [ "$1" == "gm-esearch" ]; then
    if [ ! -d "$TMW_GM_LOGS" ] || [ -z "$(ls "$TMW_GM_LOGS")" ]; then
        echo 'You must run gm-update before searching'
        exit 0
    fi
    # Exact search: Must not be an array. Used once.
    SEARCH_TERMS=$(echo "$*" | sed -E 's/^gm-esearch\s//g' | sed 's/\[/\\\[/g' | sed 's/\]/\\\]/g')
    echo "========== Results (exact): $SEARCH_TERMS ==========" | sed 's/\\//g'
    grep -hi "$SEARCH_TERMS" "$TMW_GM_LOGS"/*
elif [ "$1" == 'gm-show' ]; then
    ## This shows a GUI window with the last 10 GM commands. The amount of lines can be changed with "LINE_COUNT"
    # Root URL of the GM logs (no date)
    GM_LOG_URL='https://server.themanaworld.org/gm/gm.log.'
    # Date scheme used in URL
    LOG_DATE=$(date -u +%Y-%m)
    # The current day
    TODAY=$(date -u +%d)
    # Yesterday
    YESTERDAY=$(date -u --date yesterday +%d)
    # Last month
    LAST_MONTH=$(date -u --date 'last month' +%m)
    # Last year
    LAST_YEAR=$(date -u --date 'last year' +%Y)
    # Maximum number of new lines to report
    LINE_COUNT='10'
    # Download the GM log
    curl -s "$GM_LOG_URL$LOG_DATE" > "$GM_LOG"
        # Check if no posts made this month yet
        if [[ $(grep '<head><title>404 Not Found</title></head>' "$GM_LOG") != '' ]]; then
            LINE_COUNT_TODAY='0'
            # Check if no posts made today yet
        elif [[ $(grep "$LOG_DATE-$TODAY" "$GM_LOG") == '' ]]; then
            LINE_COUNT_TODAY='0'
        else
            # Number of commands issued today
            LINE_COUNT_TODAY=$(grep "$LOG_DATE-$TODAY" "$GM_LOG" | wc -l)
        fi

        # If lines for today are at maximum, just get max lines
        if [ "$LINE_COUNT_TODAY" -ge "$LINE_COUNT" ]; then
            tail -n "$LINE_COUNT" "$GM_LOG" > "$GM_REPORT"
            # If line aren't maxed yet...
        else
            # If today isn't the first of the month, just get the lines from the current month's log
            if [[ "$TODAY" != '01' ]]; then
                tail -n "$LINE_COUNT" "$GM_LOG" > "$GM_REPORT"
                # If it is the 1st of the month...
            else
                # Number of lines to report from yesterday's commands (total - today = yesterday)
                LINE_COUNT_YESTERDAY=$(( "$LINE_COUNT" - "$LINE_COUNT_TODAY" ))
                    # Make sure it isn't January, download last month's log and append lines to file
                    if [[ $(date -u +%m) != '01' ]]; then
                                    curl -s "$GM_LOG_URL$(date -u +%Y)-$LAST_MONTH" > "$GM_LOG"'_last_month'
                        grep "$(date -u +%Y)-$LAST_MONTH-$YESTERDAY" "$GM_LOG"'_last_month' | tail -n "$LINE_COUNT_YESTERDAY" > "$GM_REPORT"
                        grep "$LOG_DATE-$TODAY" "$GM_LOG" >> "$GM_REPORT"
                    # If it is January, last month is also last year
                    else
                        curl -s "$GM_LOG_URL$LAST_YEAR-12" > "$GM_LOG"'_last_month'
                        grep "$LAST_YEAR-12-31" "$GM_LOG"'_last_month' | tail -n "$LINE_COUNT_YESTERDAY" > "$GM_REPORT"
                        grep "$LOG_DATE-$TODAY" "$GM_LOG" >> "$GM_REPORT"
                    fi
            fi  
        fi
    if [[ $(dpkg -l 'zenity' | grep -Eo '^ii') == 'ii' ]]; then
        zenity --text-info 'tmw-gmlog' --width '600' --height '300' --filename "$GM_REPORT"
    else
        cat < "$GM_REPORT"
    fi
elif [ "$1" == "chat-search" ]; then
    if [ ! -d "$CHAT_LOGS" ] || [ -z "$(ls "$CHAT_LOGS")" ]; then
        echo 'There are no chat logs to search'
        exit 0
    fi
    # All terms: This must not be an array
    SEARCH_TERMS=$(echo "$*" | sed -E 's/^chat-search\s//g' | sed 's/\[/\\\[/g' | sed 's/\]/\\\]/g')
    WORD_COUNT=$(echo "$SEARCH_TERMS" | wc -w)
    COUNT='1'
    #echo "SEARCH_TERMS: $SEARCH_TERMS"
    #echo "WORD_COUNT: $WORD_COUNT"
    #echo "COUNT: $COUNT"
    echo "========== Results (chat): $SEARCH_TERMS ==========" | sed 's/\\//g'
        while [ "$COUNT" -le "$WORD_COUNT" ]
        do
            WORD=$(echo "$SEARCH_TERMS" | awk "{print \$$COUNT}")
            #echo "WORD: $WORD"
                if [ "$COUNT" = '1' ]; then
                    grep -ir "$WORD" "$CHAT_LOGS"/* | sed -E 's/^.*server.themanaworld.org\/\///g' > "$TMW_INFO/chat-search$COUNT.tmp"
                else
                    grep -hi "$WORD" "$TMW_INFO/chat-search$LAST_COUNT.tmp" > "$TMW_INFO/chat-search$COUNT.tmp"
                fi
            LAST_COUNT="$COUNT"
            COUNT=$(( COUNT + 1 ))
            #echo "COUNT: $COUNT"
            #echo "LAST_COUNT: $LAST_COUNT"
        done
    cat "$TMW_INFO/chat-search$LAST_COUNT.tmp"
elif [ "$1" == 'item-update' ]; then
    mkdir -p "$ITEM_DIR"
    ITEM_FILES=($(curl -s 'https://github.com/themanaworld/tmwa-server-data/tree/master/world/map/db' | sed 's/<\/*[^>]*>//g' | grep -o 'item_db.*\.txt'))
        for ITEM_FILE in "${ITEM_FILES[@]}"; do
            echo "Downloading $ITEM_FILE"
            curl -s "https://github.com/themanaworld/tmwa-server-data/blob/master/world/map/db/$ITEM_FILE"\
            | grep -Eo '[0-9]+,\s*[a-zA-Z0-9]+,\s*[0-9]+,\s*[0-9]+,.*$|//ID,\s*Name.*$' | sed -E 's/<\/td>//g' | sed 's/&quot;//g'\
            | sort -nu > "$ITEM_DIR/$ITEM_FILE"
        done
elif [ "$1" == "item-search" ]; then
    if [ ! -d "$ITEM_DIR" ] || [ -z "$(ls "$ITEM_DIR")" ]; then
        echo 'You must run item-update before searching'
        exit 0
    fi
    # All terms: This must not be an array
    SEARCH_TERMS=$(echo "$*" | sed -E 's/^item-search\s//g' | sed 's/\[/\\\[/g' | sed 's/\]/\\\]/g')
    WORD_COUNT=$(echo "$SEARCH_TERMS" | wc -w)
    COUNT='1'
    #echo "SEARCH_TERMS: $SEARCH_TERMS"
    #echo "WORD_COUNT: $WORD_COUNT"
    #echo "COUNT: $COUNT"
    echo "========== Results (item): $SEARCH_TERMS ==========" | sed 's/\\//g'
        while [ "$COUNT" -le "$WORD_COUNT" ]
        do
            WORD=$(echo "$SEARCH_TERMS" | awk "{print \$$COUNT}")
            #echo "WORD: $WORD"
                if [ "$COUNT" = '1' ]; then
                    grep -hi "$WORD" "$ITEM_DIR"/* > "$TMW_INFO/item-search$COUNT.tmp"
                else
                    grep -hi "$WORD" "$TMW_INFO/item-search$LAST_COUNT.tmp" > "$TMW_INFO/item-search$COUNT.tmp"
                fi
            LAST_COUNT="$COUNT"
            COUNT=$(( COUNT + 1 ))
            #echo "COUNT: $COUNT"
            #echo "LAST_COUNT: $LAST_COUNT"
        done
        while IFS= read -r LINE; do
            echo -e "ID: $(echo "$LINE" | awk '{print $1}') Name: $(echo "$LINE" | awk '{print $2}') Type: $(echo "$LINE" | awk '{print $3}') \
Buy: $(echo "$LINE" | awk '{print $4}' | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta') Sell: $(echo "$LINE" | awk '{print $5}' | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta') \
Weight: $(echo "$LINE" | awk '{print $6}') Attack: $(echo "$LINE" | awk '{print $7}') Defense: $(echo "$LINE" | awk '{print $8}') \
Range: $(echo "$LINE" | awk '{print $9}') Magic Bonus: $(echo "$LINE" | awk '{print $10}') Slot: $(echo "$LINE" | awk '{print $11}') \
Gender: $(echo "$LINE" | awk '{print $12}') W Level: $(echo "$LINE" | awk '{print $14}') E Level: $(echo "$LINE" | awk '{print $15}') \
View: $(echo "$LINE" | awk '{print $16}') Script: $(echo "$LINE" | awk '{print $17}' | sed 's/[{}]//g') \
Other attributes:\n\
$(echo "$LINE" | grep -o '{.*}' | sed 's/[,{}]//g' | sed 's/^\s*//g')\n"
        done < "$TMW_INFO/item-search$LAST_COUNT.tmp"
elif [ "$1" == 'mob-update' ]; then
    mkdir -p "$MOB_DIR"
    MOB_FILES="$(curl -s 'https://github.com/themanaworld/tmwa-server-data/tree/master/world/map/db' | sed 's/<\/*[^>]*>//g' | grep -o 'mob_db.*\.txt')"
        for MOB_FILE in $MOB_FILES; do
            echo "Downloading $MOB_FILE"
            curl -s "https://github.com/themanaworld/tmwa-server-data/blob/master/world/map/db/$MOB_FILE" \
            | grep -Eo '[0-9]+,\s*[a-zA-Z0-9]+,\s*[a-zA-Z0-9]+,\s*[0-9]+,.*$|//ID,\s*Name.*$' | sed -E 's/<\/td>//g' | sed 's/&quot;//g' \
            | sort -nu > "$MOB_DIR/$MOB_FILE"
        done
elif [ "$1" == "mob-search" ]; then
    if [ ! -d "$MOB_DIR" ] || [ -z "$(ls "$MOB_DIR")" ]; then
        echo 'You must run mob-update before searching'
        exit 0
    fi
    # All terms: This must not be an array
    SEARCH_TERMS=$(echo "$*" | sed -E 's/^mob-search\s//g' | sed 's/\[/\\\[/g' | sed 's/\]/\\\]/g')
    WORD_COUNT=$(echo "$SEARCH_TERMS" | wc -w)
    COUNT='1'
    #echo "SEARCH_TERMS: $SEARCH_TERMS"
    #echo "WORD_COUNT: $WORD_COUNT"
    #echo "COUNT: $COUNT"
    echo "========== Results (monster): $SEARCH_TERMS ==========" | sed 's/\\//g'
        while [ "$COUNT" -le "$WORD_COUNT" ]
        do
            WORD=$(echo "$SEARCH_TERMS" | awk "{print \$$COUNT}")
            #echo "WORD: $WORD"
                if [ "$COUNT" = '1' ]; then
                    grep -hi "$WORD" "$MOB_DIR"/* > "$TMW_INFO/mob-search$COUNT.tmp"
                else
                    grep -hi "$WORD" "$TMW_INFO/mob-search$LAST_COUNT.tmp" > "$TMW_INFO/mob-search$COUNT.tmp"
                fi
            LAST_COUNT="$COUNT"
            COUNT=$(( COUNT + 1 ))
            #echo "COUNT: $COUNT"
            #echo "LAST_COUNT: $LAST_COUNT"
        done
        while IFS= read -r LINE; do
            MOB_ID=$(echo "$LINE" | awk '{print $1}' | sed 's/,//g')
            DROP_IDS=($(echo "$LINE" | awk -F ',' '{print $30 $32 $34 $36 $38 $40 $42 $44}' | sed -E 's/ 0,//g' | sed 's/,//g' | sed -E 's/^\s*//g'))
            DROP_PERCS=$(echo "$LINE" | awk -F ','  '{print $31 $33 $35 $37 $39 $41 $43 $45}' | sed -E 's/ 0,//g' | sed 's/,//g' | sed -E 's/^\s*//g')
                if [[ $(ls "$ITEM_DIR"/* 2> '/dev/null') != '' ]]; then
                    for DROP_ID in "${DROP_IDS[@]}"; do
                        grep -hE "^$DROP_ID, " "$ITEM_DIR"/* | awk '{print $2}' >> "$TMW_INFO/mob-drop-names-$MOB_ID.tmp"
                    done
                    cat < "$TMW_INFO/mob-drop-names-$MOB_ID.tmp" | tr ',\n' ' ' > "$TMW_INFO/mob-drop-names-$MOB_ID.tmp.tmp"
                    mv "$TMW_INFO/mob-drop-names-$MOB_ID.tmp.tmp" "$TMW_INFO/mob-drop-names-$MOB_ID.tmp"
                    DROP_NAMES=$(sed 's/^$//g' "$TMW_INFO/mob-drop-names-$MOB_ID.tmp")
                else
                    echo 'Warning: To get the names of item drops, rather than just their IDs, you must run item-update first'
                    DROP_NAMES="${DROP_IDS[@]}"
                fi
                DROP_COUNT='1'
                DROP_COUNT_MAX=$(echo "$DROP_NAMES" | wc -w)
                #echo "MOB_ID: $MOB_ID"
                #echo "DROP_IDS: ${DROP_IDS[@]}"
                #echo "DROP_NAMES: $DROP_NAMES"
                #echo "DROP_PERCS: $DROP_PERCS"
                #echo "DROP_COUNT_MAX: $DROP_COUNT_MAX"
                    while [ "$DROP_COUNT" -le "$DROP_COUNT_MAX" ]; do
                        DROP_NAME=$(echo "$DROP_NAMES" | awk "{print $"$DROP_COUNT"}")
                        DROP_PERC=$(echo "$DROP_PERCS" | awk "{print $"$DROP_COUNT"}")
                        DROP_PERCENT=$(echo "scale=2; $DROP_PERC / 100" | bc)
                        DROP_RATIO=$(echo "scale=2; 100 / $DROP_PERCENT" | bc | sed 's/.00$//g' )
                        #echo "DROP_NAME: $DROP_NAME"
                        #echo "DROP_PERC: $DROP_PERC"
                        echo "$DROP_NAME($DROP_PERCENT% | $DROP_RATIO:1)," >> "$TMW_INFO/mob-drops-$MOB_ID.tmp"
                        cat < "$TMW_INFO/mob-drops-$MOB_ID.tmp" | tr '\n' ' ' > "$TMW_INFO/mob-drops-$MOB_ID.tmp.tmp"
                        mv "$TMW_INFO/mob-drops-$MOB_ID.tmp.tmp" "$TMW_INFO/mob-drops-$MOB_ID.tmp"
                        DROP_COUNT=$(( DROP_COUNT + 1 ))
                    done
                DROPS=$(sed 's/^$//g' "$TMW_INFO/mob-drops-$MOB_ID.tmp" 2> '/dev/null' | sed -E 's/,\s*$//g')
            echo -e "\
ID: $(echo "$LINE" | awk '{print $1}') NAME: $(echo "$LINE" | awk '{print $2 $3}') LVL: $(echo "$LINE" | awk '{print $4}')\n\
HP: $(echo "$LINE" | awk '{print $5}') SP: $(echo "$LINE" | awk '{print $6}') \
EXP: $(echo "$LINE" | awk '{print $7}') JOB EXP: $(echo "$LINE" | awk '{print $8}') EXP %: $(echo "$LINE" | awk '{print $47}') \
MAG EXP: $(echo "$LINE" | awk '{print $46}')\n\
RANGE: $(echo "$LINE" | awk '{print $9}') ATTK 1: $(echo "$LINE" | awk '{print $10}') ATTK 2: $(echo "$LINE" | awk '{print $11}')\n\
DEF: $(echo "$LINE" | awk '{print $12}') MAG DEF: $(echo "$LINE" | awk '{print $13}') ATTK DELAY: $(echo "$LINE" | awk '{print $27}') \
SPD: $(echo "$LINE" | awk '{print $26}')\n\
STATS: STR=$(echo "$LINE" | awk '{print $14}') AGI=$(echo "$LINE" | awk '{print $15}') VIT=$(echo "$LINE" | awk '{print $16}') \
INT=$(echo "$LINE" | awk '{print $17}') DEX=$(echo "$LINE" | awk '{print $18}') LUK=$(echo "$LINE" | awk '{print $19}')\n\
MUTATIONS: $(echo "$LINE" | awk '{print $56}') MUTATION STR: $(echo "$LINE" | awk '{print $57}')\n\
DROPS: $DROPS\n\
"
        done < "$TMW_INFO/mob-search$LAST_COUNT.tmp"
elif [ "$1" == 'cmds' ];then
    echo '
/closeall - close all whispers.
/ignoreall - add all whispers to ignore list.
/msg NICK text, /whisper NICK text, /w NICK text - send whisper message to nick.
/query NICK, /q NICK - open new whisper tab for nick.
/help - show small help about chat commands. 
/target NICK - select nick as target. Can be monster or player nick.
/targetmercenary - target closest mercenary.
/targetpet - target pet.
/outfit N - wear outfit number N.
/outfit next - wear next outfit.
/outfit prev - wear previous outfit.
/talkpet TEXT - talk from your pet.
/emote N - use emotion number N.
/emotepet N - use emotion number N from your pet.
/away, /away MSG - set away mode.
/pseudoaway, /pseudoaway MSG - set/unset pseudo away mode.
/follow NICK - start follow mode.
/imitation NICK - start imitation mode.
/heal NICK - heal nick.
/move X Y - move to X,Y position in short distance.
/movetotarget - move to target position.
/movetohome - move to home position.
/sethome - set home position.
/navigate x y - move to position x,y in current map in any distance.
/mail NICK MSG - send offline message to NICK. Working only in tmw server.
/disconnect - quick disconnect from server.
/attack - attack target.
/atkhuman - select and attack nearest player.
/magicattack - attack target with magic.
/undress NICK - remove all clothes from nick. Local effect only.
/addattack NAME - add monster to attack list.
/addpriorityattack NAME - add monster to priority attack list.
/removeattack NAME - remove monster from attack list.
/addignoreattack NAME - add monster to ignore attack list.
/setdrop N - set drop counter to requested value.
/drop - drop N items from 0 slot.
/dropn - drop N items from any slot.
/info - show guild info. Only for native guilds only.
/wait NAME - wait for nick or moster with name.
/gm MESSAGE - send message to all online gms.
/catchpet - try to catch pet.
/trade NICK - start trade with nick.
/priceload - load shop price from disc.
/pricesave - save shop price to disc.
/ignore NICK - add nick to ignore list.
/unignore NICK - Remove nick from ignore list.
/friend NICK, /befriend NICK - add nick to friends list.
/disregard NICK - add nick to disregarded list.
/neutral NICK - add nick to neutral relation list.
/blacklist NICK - add nick to blacklist relation list.
/erase NICK - add nick to erased list.
/enemy NICK - add nick to enemies list.
/createparty NAME - create party with selected name.
/me text - send text to chat as /me command in irc.
/serverignoreall - ignore all whispers on server side.
/serverunignoreall - unignore all whispers on server side.
/who - print online players number to chat.
/present - print visible players number to chat.
/all - show visible beings list in debug tab.
/where - print current player position to chat.
/cacheinfo - show text cache info.
/uptime - show client uptime.
/dumpe - dump environment variables into chat.
/dumpg - dump graphics and some other settings to chat.
/dumpgl - dump OpenGL version into chat.
/dumpt - dump tests info into chat.
/dumpogl - dump all OpenGL variables into log file.
/dumpmods - dump all enabled mod names into chat.
/dirs - show client dirs in debug chat tab.
/uploadconfig - upload main config into pastebin service.
/uploadserverconfig - upload server config into pastebin service.
/uploadlog - upload log into pastebin service.
/announce MESSAGE - show global message.
/createitems - open dialog for creating items.
/clear - clear current chat tab.
/enablehighlight - enable highlight in current tab.
/disablehighlight - disable highlight in current tab.
/enableaway - enable away messages in current tab.
/disableaway - disable away messages in current tab.
/cleangraphics - remove all cached graphics. Useful for content developers.
/testparticle FILENAME - set test particle on player.
/mercenaryfire - fire mercenary.
/firehomunculus - fire homunculus.
/sethomunname NAME - set homunculus name.
/setpetname NAME - set new pet name.
/petaistart - enable pet ai.
/petaistop - disable pet ai.
/petmoveup - move pet one tile up.
/petmovedown - move pet one tile down.
/petmoveleft - move pet one tile left.
/petmoveright - move pet one tile right.
/petdirectup - rotate pet up.
/petdirectdown - rotate pet down.
/petdirectleft - rotate pet left.
/petdirectright - rorate pet right.
/cleanfonts - remove all cached render strings.
/url URL - insert url into chat.
/open URL - open url in browser.
/help - show this help.
/invite NICK - invite a player to your party.
/leave - leave the party you are in.
/kick NICK - kick someone from the party you are in.
/notice TEXT - set notice guild text.
/item - show party item sharing options.
/item 0 - disable party item sharing options.
/item 1 - enable party item sharing options.
/exp - show party experience sharing options.
/exp 0 - disable party experience sharing options.
/exp 1 - enable party experience sharing options.
@spawn 
@item 
@hugo
@linus
@warp 
@goto 
@jump 
@save
@storage
@gstorage
@hide
@visible
@invisible
@die
@kill 
@alive
@blvl 
@jlvl 
@pvpon
@pvpoff
@killmonster
@kick 
@broadcast 
@localbroadcast 
@hairstyle 
@haircolor 
@ignorelist
@killer
@killable
@summon 
@skill-learn 
@ipcheck
'\
    | less
else
    echo 'Incorrect syntax'
    help
    exit 0
fi