Skip to content

Commit

Permalink
1. protocol updated for CreateTopic/Add2Topic/GetTopicProfile
Browse files Browse the repository at this point in the history
2. r.sh script support new command --- status
  • Loading branch information
alvinwsz committed Aug 2, 2016
1 parent 245823e commit 877dcd5
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 69 deletions.
32 changes: 15 additions & 17 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,41 +231,39 @@ func cmd_topic_rsp(self *Client, c *protocol.CmdSimple) error {
return nil
}

func cmd_list(self *Client, args []string) error {
func cmd_topic_profile(self *Client, args []string) error {
if self.bLogin == false {
fmt.Println("NOT login yet. Please login first.")
return nil
}
if len(args) != 2 {
return common.SYNTAX_ERROR
}
cmd := protocol.NewCmdSimple(protocol.REQ_GET_TOPIC_MEMBER_CMD)
cmd := protocol.NewCmdSimple(protocol.REQ_GET_TOPIC_PROFILE_CMD)
cmd.AddArg(args[1])
err := self.session.Send(libnet.Json(cmd))

return err
}

func cmd_list_rsp(self *Client, c *protocol.CmdSimple) error {
func cmd_topic_profile_rsp(self *Client, c *protocol.CmdSimple) error {
var num int
var err error

fmt.Println(c.GetCmdName() + " returns: " + c.GetArgs()[0])
if c.GetArgs()[0] != protocol.RSP_SUCCESS {
return errors.New(c.GetArgs()[0])
}
if num, err = strconv.Atoi(c.GetArgs()[1]); err != nil {
fmt.Println(err.Error())
log.Error(err.Error())
return err
}
fmt.Println("GET_TOPIC_MEMBER returns (" + c.GetArgs()[1] + "): ")
fmt.Println("GET_TOPIC_PROFILE returns : ")
fmt.Println(" topicName: " + c.GetArgs()[1])
fmt.Println(" creator: " + c.GetArgs()[2])
fmt.Println(" members[]: ")
num = (len(c.GetArgs()) - 3) / 3
index := 0
for {
if index == num {
break
} else {
fmt.Println("ID=" + c.GetArgs()[2+2*index] + "\t\t\t, Name=" + c.GetArgs()[2+2*index+1])
fmt.Println(" " + c.GetArgs()[3+3*index] + "\t, " + c.GetArgs()[3+3*index+1] + "\t, " + c.GetArgs()[3+3*index+2])
index++
}
}
Expand Down Expand Up @@ -548,8 +546,8 @@ func cmd_login(self *Client, args []string) error {
case protocol.RSP_GET_TOPIC_LIST_CMD:
cmd_topic_rsp(self, &c)

case protocol.RSP_GET_TOPIC_MEMBER_CMD:
cmd_list_rsp(self, &c)
case protocol.RSP_GET_TOPIC_PROFILE_CMD:
cmd_topic_profile_rsp(self, &c)

case protocol.RSP_CREATE_TOPIC_CMD:
cmd_new_rsp(self, &c)
Expand Down Expand Up @@ -647,10 +645,10 @@ func main() {
"delete <topic_name>\n",
cmd_delete,
},
"list": {
"Get member list of specific topic. You MUST be a member of the topic.\n",
"list <topic_name>\n",
cmd_list,
"profile": {
"Get specific topic profile. You MUST be a member of the topic.\n",
"profile <topic_name>\n",
cmd_topic_profile,
},
"add": {
"Add someone into the topic, only for topic creator\n",
Expand Down
2 changes: 1 addition & 1 deletion client/client.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"TransportProtocols" : "tcp",
"LogFile" : "client.log",
"GatewayServer" : "127.0.0.1:17000",
"GatewayServer" : "192.168.10.100:17000",
"HeartBeatTime" : 20,
"Expire" : 40
}
6 changes: 3 additions & 3 deletions gateway/gateway.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"LogFile" : "gateway.log",
"UUID" : "17000",
"MsgServerList" : [
"127.0.0.1:19000",
"127.0.0.1:19001"
"192.168.10.100:19000",
"192.168.10.100:19001"
],
"MsgServerNum" : 2,

Expand All @@ -18,7 +18,7 @@
},

"Mongo" : {
"Addr" : "127.0.0.1",
"Addr" : "192.168.10.100",
"Port" : ":27017",
"User" : "",
"Password" : ""
Expand Down
6 changes: 3 additions & 3 deletions manager/manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"LogFile" : "manager.log",
"UUID" : "18000",
"MsgServerList" : [
"127.0.0.1:19000",
"127.0.0.1:19001"
"192.168.10.100:19000",
"192.168.10.100:19001"
],

"Redis" : {
Expand All @@ -17,7 +17,7 @@
},

"Mongo" : {
"Addr" : "127.0.0.1",
"Addr" : "192.168.10.100",
"Port" : ":27017",
"User" : "",
"Password" : ""
Expand Down
4 changes: 2 additions & 2 deletions monitor/monitor.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"LogFile" : "monitor.log",
"UUID" : "21000",
"MsgServerList" : [
"127.0.0.1:19000",
"127.0.0.1:19001"
"192.168.10.100:19000",
"192.168.10.100:19001"
],
"Redis" : {
"Addr" : "127.0.0.1",
Expand Down
6 changes: 3 additions & 3 deletions msg_server/msg_server.19000.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"LocalIP" : "127.0.0.1:19000",
"LocalIP" : "192.168.10.100:19000",
"TransportProtocols" : "tcp",
"Listen" : "0.0.0.0:19000",
"LogFile" : "msg_server.log",
Expand All @@ -9,7 +9,7 @@
"MonitorBeatTime" : 5,

"SessionManagerServerList" : [
"127.0.0.1:18000"
"192.168.10.100:18000"
],

"Redis" : {
Expand All @@ -21,7 +21,7 @@
},

"Mongo" : {
"Addr" : "127.0.0.1",
"Addr" : "192.168.10.100",
"Port" : ":27017",
"User" : "",
"Password" : ""
Expand Down
6 changes: 3 additions & 3 deletions msg_server/msg_server.19001.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"LocalIP" : "127.0.0.1:19001",
"LocalIP" : "192.168.10.100:19001",
"TransportProtocols" : "tcp",
"Listen" : "0.0.0.0:19001",
"LogFile" : "msg_server.log",
Expand All @@ -9,7 +9,7 @@
"MonitorBeatTime" : 5,

"SessionManagerServerList" : [
"127.0.0.1:18000"
"192.168.10.100:18000"
],

"Redis" : {
Expand All @@ -21,7 +21,7 @@
},

"Mongo" : {
"Addr" : "127.0.0.1",
"Addr" : "192.168.10.100",
"Port" : ":27017",
"User" : "",
"Password" : ""
Expand Down
29 changes: 22 additions & 7 deletions msg_server/proto_proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,11 @@ func (self *ProtoProc) procCreateTopic(cmd protocol.Cmd, session *libnet.Session
ErrOut:
if err != nil {
resp.AddArg(err.Error())
resp.AddArg(topicName)
} else {
resp.AddArg(protocol.RSP_SUCCESS)
resp.AddArg(topicName)
resp.AddArg(ClientName)
}
err = session.Send(libnet.Json(resp))
if err != nil {
Expand Down Expand Up @@ -655,7 +658,10 @@ ErrOut:
MsgServer -> client
RSP_ADD_2_TOPIC_CMD
arg0: SUCCESS/FAILED
arg0: SUCCESS/FAILED
arg1: TopicName
arg2: ClientID
arg3: ClientType
*/
func (self *ProtoProc) procAdd2Topic(cmd protocol.Cmd, session *libnet.Session) error {
log.Info("procAdd2Topic")
Expand All @@ -666,6 +672,7 @@ func (self *ProtoProc) procAdd2Topic(cmd protocol.Cmd, session *libnet.Session)
mName := cmd.GetArgs()[2]
ClientID := session.State.(*base.SessionState).ClientID
ClientType := session.State.(*base.SessionState).ClientType
mType := protocol.DEV_TYPE_CLIENT

resp := protocol.NewCmdSimple(protocol.RSP_ADD_2_TOPIC_CMD)

Expand Down Expand Up @@ -693,7 +700,8 @@ func (self *ProtoProc) procAdd2Topic(cmd protocol.Cmd, session *libnet.Session)
log.Warningf("Client %s not online", mID)
err = common.NOT_ONLINE
} else {
member := mongo_store.NewMember(mID, mName, sessionCacheData.ClientType)
mType = sessionCacheData.ClientType
member := mongo_store.NewMember(mID, mName, mType)
err = self.msgServer.procJoinTopic(member, topicName)
}
}
Expand All @@ -704,6 +712,9 @@ func (self *ProtoProc) procAdd2Topic(cmd protocol.Cmd, session *libnet.Session)
} else {
resp.AddArg(protocol.RSP_SUCCESS)
}
resp.AddArg(topicName)
resp.AddArg(mID)
resp.AddArg(mType)
err = session.Send(libnet.Json(resp))
if err != nil {
log.Error(err.Error())
Expand Down Expand Up @@ -1078,16 +1089,17 @@ ErrOut:
arg4: Member3
*/

func (self *ProtoProc) procGetTopicMember(cmd protocol.Cmd, session *libnet.Session) error {
log.Info("procGetTopicMember")
func (self *ProtoProc) procGetTopicProfile(cmd protocol.Cmd, session *libnet.Session) error {
log.Info("procGetTopicProfile")
var err error
var topicCacheData *redis_store.TopicCacheData

resp := protocol.NewCmdSimple(protocol.RSP_GET_TOPIC_MEMBER_CMD)
topicName := "<N/A>"
resp := protocol.NewCmdSimple(protocol.RSP_GET_TOPIC_PROFILE_CMD)
if len(cmd.GetArgs()) != 1 {
err = common.SYNTAX_ERROR
} else {
topicName := cmd.GetArgs()[0]
topicName = cmd.GetArgs()[0]

clientID := session.State.(*base.SessionState).ClientID
//clientType := session.State.(*base.SessionState).ClientType
Expand All @@ -1106,12 +1118,15 @@ func (self *ProtoProc) procGetTopicMember(cmd protocol.Cmd, session *libnet.Sess

if err != nil {
resp.AddArg(err.Error())
resp.AddArg(topicName)
} else {
resp.AddArg(protocol.RSP_SUCCESS)
resp.AddArg(strconv.Itoa(len(topicCacheData.MemberList)))
resp.AddArg(topicName)
resp.AddArg(topicCacheData.CreaterID)
for _, member := range topicCacheData.MemberList {
resp.AddArg(member.ID)
resp.AddArg(member.Name)
resp.AddArg(member.Type)
}
}
err = session.Send(libnet.Json(resp))
Expand Down
4 changes: 2 additions & 2 deletions msg_server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ func (self *MsgServer) parseProtocol(cmd []byte, session *libnet.Session) error
return err
}

case protocol.REQ_GET_TOPIC_MEMBER_CMD:
err = pp.procGetTopicMember(&c, session)
case protocol.REQ_GET_TOPIC_PROFILE_CMD:
err = pp.procGetTopicProfile(&c, session)
if err != nil {
log.Error("error:", err)
return err
Expand Down
50 changes: 26 additions & 24 deletions protocol/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,18 @@ const (
RSP_ADD_2_TOPIC_CMD = "RSP_ADD_2_TOPIC"
/*
client -> MsgServer
REQ_ADD_2_TOPIC_CMD
arg0: TopicName //群组名
arg1: NewClientID //用户ID
arg2: NewClientName //用户在Topic中的Name, 对于device, 可以是儿子/女儿
MsgServer -> client
RSP_ADD_2_TOPIC_CMD
arg0: SUCCESS/ERROR
client -> MsgServer
REQ_ADD_2_TOPIC_CMD
arg0: TopicName //群组名
arg1: NewClientID //用户ID
arg2: NewClientName //用户在Topic中的Name, 对于device, 可以是儿子/女儿
MsgServer -> client
RSP_ADD_2_TOPIC_CMD
arg0: SUCCESS/ERROR
arg1: TopicName
arg2: ClientID
arg3: ClientType
*/

REQ_KICK_TOPIC_CMD = "REQ_KICK_TOPIC"
Expand Down Expand Up @@ -245,23 +248,22 @@ const (
arg4: TopicName3
*/

REQ_GET_TOPIC_MEMBER_CMD = "REQ_GET_TOPIC_MEMBER"
RSP_GET_TOPIC_MEMBER_CMD = "RSP_GET_TOPIC_MEMBER"
REQ_GET_TOPIC_PROFILE_CMD = "REQ_GET_TOPIC_PROFILE"
RSP_GET_TOPIC_PROFILE_CMD = "RSP_GET_TOPIC_PROFILE"

/*
device/client -> MsgServer
REQ_GET_TOPIC_MEMBER_CMD
arg0: TopicName
如果ClientID不是TopicName的成员,则返回失败
MsgServer -> device/client
RSP_GET_TOPIC_MEMBER_CMD
arg0: SUCCESS/ERROR
arg1: MemberNum // topic member数目,后面跟随该数目的member
arg2: Member1ID
arg3: Member1Name
arg4: Member2ID
arg5: Member2Name
device/client -> MsgServer
REQ_GET_TOPIC_MEMBER_CMD
arg0: TopicName
如果ClientID不是TopicName的成员,则返回失败
MsgServer -> device/client
RSP_GET_TOPIC_MEMBER_CMD
arg0: SUCCESS/ERROR
// followed by topic profile
// topicName
// creator
// members[]
*/

)
Expand Down
Loading

0 comments on commit 877dcd5

Please sign in to comment.