-
-
Save sskras/b5e9fb20fb09b401b6992e849ece9e83 to your computer and use it in GitHub Desktop.
Revisions
-
wrfly revised this gist
Jul 10, 2015 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #!/bin/bash # A little chat progream via ncat # Author:wrfly Date:2015.7 # Usage: # Server: ncat -e chat.sh -lk & # Client: ncat server_ip @@ -45,7 +45,7 @@ echo -e "\033[1;36m Now, chose a username first (visitor by default): \033[0m" visitor=visitor.$RANDOM username=${username:-$visitor} check_lenth "$username" 20 if [[ $username =~ ^visitor\. ]]; then : @@ -61,7 +61,7 @@ echo -e "\033[1;36m Enter a chat room(public by default): \033[0m" read -e chat_room chat_room=${chat_room:-public} check_lenth "$chat_room" 20 if [[ ! -z $(echo $chat_room | grep "\.\./") ]] ;then echo "NO way" @@ -75,7 +75,7 @@ if [[ -z $(grep ^"$chat_room"$ $db_rooms) ]]; then try_times=0 while true;do read -e chat_room_again check_lenth "$chat_room_again" 20 if [[ $chat_room_again == $chat_room ]]; then touch ${rooms_dir}/$chat_room &> /dev/null echo $chat_room >> $db_rooms @@ -103,7 +103,7 @@ echo -e "\033[1;34m$msg_date\033[0m\033[1;31m User \"$username\" \033[0m\ \033[1;34m has came into \033[0m\033[1;36m\"$user_room\"\033[0m" >> $chat_room while read -e msg; do check_lenth "$msg" 200 if [[ $msg =~ ^: ]]; then case $msg in ":help") -
wrfly revised this gist
Jul 9, 2015 . 1 changed file with 9 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,10 +14,16 @@ trap clean_up SIGQUIT EXIT function clean_up { if [[ -z $chat_room ]]; then cat bye exit else echo -e "\033[1;34m$msg_date\033[0m\033[1;31m $username \033[0m\ \033[1;34mleaved room\033[0m \033[1;36m \"$user_room\" \033[0m" >> $chat_room cat bye exit fi } function check_lenth { @@ -29,7 +35,7 @@ function check_lenth { } # Welcome cat welcome # Login @@ -97,7 +103,7 @@ echo -e "\033[1;34m$msg_date\033[0m\033[1;31m User \"$username\" \033[0m\ \033[1;34m has came into \033[0m\033[1;36m\"$user_room\"\033[0m" >> $chat_room while read -e msg; do check_lenth $msg if [[ $msg =~ ^: ]]; then case $msg in ":help") -
wrfly revised this gist
Jul 9, 2015 . 1 changed file with 25 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #!/bin/bash # A little chat progream via ncat # Author:wrfly Date:2015.7.7 # Usage: # Server: ncat -e chat.sh -lk & # Client: ncat server_ip @@ -10,53 +10,66 @@ db_users=user_lists db_rooms=db_rooms room_dir=chat_rooms trap clean_up SIGQUIT EXIT function clean_up { echo -e "\033[1;34m$msg_date\033[0m\033[1;31m $username \033[0m\ \033[1;34mleaved room\033[0m \033[1;36m \"$user_room\" \033[0m" >> $chat_room # cat bye exit } function check_lenth { count=$(echo $1 | wc -m) if [[ $count -gt $2 ]]; then echo "Argument too long, 40 limit." exit 2 fi } # Welcome # cat welcome # Login echo -e "\033[1;36m Now, chose a username first (visitor by default): \033[0m" read -e username visitor=visitor.$RANDOM username=${username:-$visitor} check_lenth $username 20 if [[ $username =~ ^visitor\. ]]; then : else echo $username >> $db_users fi echo -e "\033[1;36m Hi, $username! Which room do you prefer?\033[0m" echo -e "\033[1;36m Enter a chat room(public by default): \033[0m" # Enter_room read -e chat_room chat_room=${chat_room:-public} check_lenth $chat_room 20 if [[ ! -z $(echo $chat_room | grep "\.\./") ]] ;then echo "NO way" chat_room=${room_dir}/"bad" exit 2 fi if [[ -z $(grep ^"$chat_room"$ $db_rooms) ]]; then echo -e "\033[1;36m Sorry, There is no room named \033[1;31m\"$chat_room\"\033[0m. \033[1;36mIf you want to create a chat_room named \"$chat_room\", enter it again: \033[0m" try_times=0 while true;do read -e chat_room_again check_lenth $chat_room_again 200 if [[ $chat_room_again == $chat_room ]]; then touch ${rooms_dir}/$chat_room &> /dev/null echo $chat_room >> $db_rooms @@ -83,7 +96,8 @@ msg_date=$(date +"%R:%S") echo -e "\033[1;34m$msg_date\033[0m\033[1;31m User \"$username\" \033[0m\ \033[1;34m has came into \033[0m\033[1;36m\"$user_room\"\033[0m" >> $chat_room while read -e msg; do msg_check_lenth $msg if [[ $msg =~ ^: ]]; then case $msg in ":help") -
wrfly revised this gist
Jul 8, 2015 . 1 changed file with 9 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #!/bin/bash # A little chat progream via ncat # Author:wrfly Date:2015.7.8 # Usage: # Server: ncat -e chat.sh -lk & # Client: ncat server_ip @@ -10,7 +10,7 @@ db_users=user_lists db_rooms=db_rooms room_dir=chat_rooms trap clean_up SIGINT function clean_up { @@ -28,7 +28,7 @@ function clean_up echo -ne "\033[1;36m Now, chose a username first (visitor by default): \033[0m" read -n 20 -e username visitor=visitor.$RANDOM username=${username:-$visitor} @@ -43,18 +43,20 @@ echo -ne "\033[1;36m Enter a chat room(public by default): \033[0m" # Enter_room read -n 20 -e chat_room chat_room=${chat_room:-public} if [[ ! -z $(echo $chat_room | grep "\.\./") ]] ;then echo "NO way" exit 2 fi if [[ -z $(grep ^"$chat_room"$ $db_rooms) ]]; then echo -en "\033[1;36m Sorry, There is no room named \033[1;31m\"$chat_room\"\033[0m. \033[1;36mIf you want to create a chat_room named \"$chat_room\", enter it again: \033[0m" try_times=0 while true;do read -n 20 -e chat_room_again if [[ $chat_room_again == $chat_room ]]; then touch ${rooms_dir}/$chat_room &> /dev/null echo $chat_room >> $db_rooms @@ -81,7 +83,7 @@ msg_date=$(date +"%R:%S") echo -e "\033[1;34m$msg_date\033[0m\033[1;31m User \"$username\" \033[0m\ \033[1;34m has came into \033[0m\033[1;36m\"$user_room\"\033[0m" >> $chat_room while read -n 200 -e msg; do if [[ $msg =~ ^: ]]; then case $msg in ":help") -
wrfly revised this gist
Jul 8, 2015 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -45,6 +45,10 @@ echo -ne "\033[1;36m Enter a chat room(public by default): \033[0m" # Enter_room read -n 20 chat_room chat_room=${chat_room:-public} if [[ ! -z $(echo $chat_room | grep "\.\./") ]] ;then echo "NO way" exit 2 fi if [[ -z $(grep ^"$chat_room"$ $db_rooms) ]]; then echo -en "\033[1;36m Sorry, There is no room named \033[1;31m\"$chat_room\"\033[0m. \033[1;36mIf you want to create a chat_room named \"$chat_room\", enter it again: \033[0m" -
wrfly revised this gist
Jul 7, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ #!/bin/bash # A little chat script via netcat # Author:wrfly Date:2015.7.7 # Usage: # Server: ncat -e chat.sh -lk & -
wrfly revised this gist
Jul 7, 2015 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,9 @@ #!/bin/bash # a little chat progream via netcat # Author:wrfly Date:2015.7.7 # Usage: # Server: ncat -e chat.sh -lk & # Client: ncat server_ip #config db_users=user_lists -
wrfly created this gist
Jul 7, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,101 @@ #!/bin/bash # a little chat progream via netcat # Author:wrfly Date:2015.7.7 #config db_users=user_lists db_rooms=db_rooms room_dir=chat_rooms trap clean_up SIGINT EXIT SIGQUIT function clean_up { echo -e "\033[1;34m$msg_date\033[0m\033[1;31m $username \033[0m\ \033[1;34mleaved room\033[0m \033[1;36m $user_room \033[0m" >> $chat_room # cat bye exit } # Welcome # cat welcome # Login echo -ne "\033[1;36m Now, chose a username first (visitor by default): \033[0m" read -n 20 username visitor=visitor.$RANDOM username=${username:-$visitor} if [[ $username =~ ^visitor\. ]]; then : else echo $username >> $db_users fi echo -e "\033[1;36m Hi, $username! Which room do you prefer?\033[0m" echo -ne "\033[1;36m Enter a chat room(public by default): \033[0m" # Enter_room read -n 20 chat_room chat_room=${chat_room:-public} if [[ -z $(grep ^"$chat_room"$ $db_rooms) ]]; then echo -en "\033[1;36m Sorry, There is no room named \033[1;31m\"$chat_room\"\033[0m. \033[1;36mIf you want to create a chat_room named \"$chat_room\", enter it again: \033[0m" try_times=0 while true;do read -n 20 chat_room_again if [[ $chat_room_again == $chat_room ]]; then touch ${rooms_dir}/$chat_room &> /dev/null echo $chat_room >> $db_rooms break else echo -e "\033[1;36m Not match. Try again:\033[0m" fi try_times=$((try_times+1)) if [[ $try_times -gt 5 ]]; then echo -e "\033[1;31mToo many tries.\033[0m" exit 1 fi done fi # Chating...... user_room=$chat_room chat_room=${room_dir}/${chat_room} touch $chat_room tail -f --pid=$$ $chat_room & msg_date=$(date +"%R:%S") echo -e "\033[1;34m$msg_date\033[0m\033[1;31m User \"$username\" \033[0m\ \033[1;34m has came into \033[0m\033[1;36m\"$user_room\"\033[0m" >> $chat_room while read msg; do if [[ $msg =~ ^: ]]; then case $msg in ":help") echo "Help messages." ;; ":lists") echo "User lists." ;; ":q") exit ;; *) echo "Default" ;; esac elif [[ -z $msg ]]; then : else msg_date=$(date +"%R:%S") echo -e "\033[1;34m$msg_date\033[0m\033[1;31m $username \033[0m\ \033[1;34msaid:\033[0m \033[1;36m $msg \033[0m" >> $chat_room fi msg= #clear msg for tailf done