Security Update #6
|
@ -14,6 +14,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -69,6 +70,12 @@ func startSecureServer() (net.Listener, error) {
|
|||
return ln, err
|
||||
}
|
||||
|
||||
func getTime() string {
|
||||
t := time.Now()
|
||||
currentTime := fmt.Sprintf("%d-%02d-%02d | %02d:%02d:%02d", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
|
||||
return currentTime
|
||||
}
|
||||
|
||||
func Server() {
|
||||
var ln net.Listener
|
||||
var err error
|
||||
|
@ -188,8 +195,8 @@ func handleConn(conn net.Conn, chatChan chan string) {
|
|||
|
||||
newUserTemplate := new(User)
|
||||
newUser := newUserTemplate.CreateUser(userName, userIP)
|
||||
joinMessage := fmt.Sprintf("%v has joined the chat!", newUser.Username)
|
||||
fmt.Println(joinMessage)
|
||||
joinMessage := fmt.Sprintf("[%v] %v has joined the chat!", getTime(), newUser.Username)
|
||||
fmt.Println(joinMessage + " [" + newUser.IP + "]")
|
||||
addToLog(fmt.Sprintln(joinMessage))
|
||||
//conn.Write([]byte(joinMessage))
|
||||
sendMessage(joinMessage)
|
||||
|
@ -198,8 +205,8 @@ func handleConn(conn net.Conn, chatChan chan string) {
|
|||
for {
|
||||
message, err := getUserInput(conn)
|
||||
if err != nil {
|
||||
quitMessage := fmt.Sprintf("%v has disconnected!", newUser.Username)
|
||||
fmt.Println(quitMessage)
|
||||
quitMessage := fmt.Sprintf("[%v] %v has disconnected!", getTime(), newUser.Username)
|
||||
fmt.Println(quitMessage + " [" + newUser.IP + "]")
|
||||
addToLog(fmt.Sprintln(quitMessage))
|
||||
sendMessage(quitMessage)
|
||||
//removeFromList(chatChan)
|
||||
|
@ -208,7 +215,7 @@ func handleConn(conn net.Conn, chatChan chan string) {
|
|||
// }
|
||||
return
|
||||
}
|
||||
finalMessage := fmt.Sprintf("[%v] %v: %v", newUser.IP, newUser.Username, strings.TrimRight(message, "\n"))
|
||||
finalMessage := fmt.Sprintf("[%v] %v: %v", getTime(), newUser.Username, strings.TrimRight(message, "\n"))
|
||||
fm := fmt.Sprintf("%v\n", finalMessage)
|
||||
fmt.Print(fm)
|
||||
addToLog(fm)
|
||||
|
|
Loading…
Reference in New Issue