-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
143 lines (127 loc) · 3.64 KB
/
main.go
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
package main
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"strconv"
"strings"
"time"
"github.com/Qingluan/SChat/controller"
"github.com/fatih/color"
)
func Input(msg string) string {
read := bufio.NewReader(os.Stdin)
fmt.Print(color.New(color.FgHiCyan).Sprint(msg))
line, _, _ := read.ReadLine()
return string(line)
}
func main() {
page := "https://localhost:37777/ccc"
ssh := ""
sendToName := ""
name := ""
Pass := ""
// R := false
flag.StringVar(&page, "p", "resources/pages/index.html", "set page")
flag.StringVar(&sendToName, "s", "", "set name")
flag.StringVar(&name, "u", "a", "set user name")
flag.StringVar(&ssh, "H", "://115.236.8.148:50022/docker-hub", "set page")
flag.StringVar(&Pass, "P", "", "set password ")
flag.Parse()
if Pass != "" {
ssh += ":" + Pass
}
// // astilog.FlagInit()
chat, err := controller.NewChatRoom(name + ssh)
if err != nil {
log.Fatal(err)
}
if !chat.Login() {
return
}
chat.SetWacher(func(msg *controller.Message) {
line := color.New(color.FgGreen).Sprintf("[%s]", msg.From)
line += color.New(color.FgYellow).Sprintf(" -- %s\n\t", msg.Date)
line += color.New(color.FgHiWhite, color.Bold).Sprintln(msg.Data)
fmt.Print(line, color.New(color.FgHiCyan).Sprint("\nsend msg or cmd $ls/$ >"))
})
for {
// fmt.Print(color.New(color.FgHiCyan).Sprintf("(%s)>", user))
// fmt.Scanln(&line)
line := Input("send msg or cmd $ls/$ >")
if strings.HasPrefix(line, "$") {
if line == "$ls" {
for _, user := range chat.Contact() {
fmt.Println(user.Name, time.Since(user.Last()))
}
} else if line == "$files" {
for _, f := range chat.CloudFiles() {
fmt.Println("[file]", f)
}
fmt.Println()
} else if line == "$hist" {
fmt.Println("[history ] pulling")
chat.History()
} else if strings.HasPrefix(line, "$get") {
name := strings.TrimSpace(strings.SplitN(line, "$get", 2)[1])
chat.GetFile(name)
} else if strings.HasPrefix(line, "$put") {
name := strings.TrimSpace(strings.SplitN(line, "$put", 2)[1])
if err := chat.SendFile(name); err != nil {
log.Println("send file er:", err)
}
} else if strings.HasPrefix(line, "$clear") {
fs := strings.SplitN(line, "$clear", 2)
t, err := strconv.Atoi(fs[1])
if err != nil {
t = 5
}
chat.CloseWithClear(t)
fmt.Println("bye~~~", t, "second will clear all data")
} else {
chat.TalkTo(line[1:])
line = ""
}
} else {
chat.Write(line)
line = ""
}
}
// chat.Server.Init()
// chat.Server.OnMessage(func(from, msg string, date time.Time) {
// line := color.New(color.FgGreen).Sprintf("[%s]", from)
// line += color.New(color.FgYellow).Sprintf(" -- %s\n\t", date.Format("2006年1月2号 15:04:05"))
// line += color.New(color.FgHiWhite, color.Bold).Sprintln(msg)
// fmt.Println(msg)
// })
// // line := ""
// users, err := chat.Server.Contact()
// if err != nil {
// log.Fatal("contanct err:", err)
// }
// for _, u := range users {
// fmt.Println(u.Name, u.Acivte(), "login:", u.State)
// }
// ip, err := chat.Server.ContactTo(string(line))
// if err != nil {
// log.Fatal("can not send to", err)
// } else {
// fmt.Println(line, "'s ip is ", ip)
// }
// user := string(line)
// for {
// fmt.Print(color.New(color.FgHiCyan).Sprintf("(%s)>", user))
// // fmt.Scanln(&line)
// line, _, _ := read.ReadLine()
// chat.Server.SendMsg(string(line))
// }
// key := base64.StdEncoding.EncodeToString([]byte("hello write this !!!"))
// stream, err := controller.NewStreamWithAuthor("check-onea-fasfsdfsadfads")
// if err != nil {
// log.Fatal(err)
// }
// stream.EncryptFile("SshChat", "test1")
// stream.DecryptFile("test1", "test2")
}