package main
import (
"fmt"
"net"
"strconv"
"strings"
)
type user struct {
conn net.Conn
name string
} //定义用户结构体
var online map[string]*user //该map储存在线用户
var msg chan string //定义全局的消息channel,接受到的消息会储存在这里,然后通过manager读取消息,做出相应处理
func manager() {
online = make(map[string]*user)
msg = make(chan string)
//初始化online和msg
for { //从msg中不断地取数据
m := <-msg
var name = ""
for _, ss := range m {
if ss != ' ' {
name += string(ss)
} else {
break
}
}
fmt.Println(name)
if name == "online" {
use := strings.Split(m, " ")[1]
for _, u := range online {
if u.name == use {
var joint string = "当前在线人数为:"
joint += strconv.Itoa(len(online)) + "人\n"
u.conn.Write([]byte(joint))
}
//u.conn.Write([]byte("当前在线人数为:" + string(rune(