本文整理匯總了Golang中github.com/oikomi/FishChatServer/protocol.Cmd.GetCmdName方法的典型用法代碼示例。如果您正苦於以下問題:Golang Cmd.GetCmdName方法的具體用法?Golang Cmd.GetCmdName怎麽用?Golang Cmd.GetCmdName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/oikomi/FishChatServer/protocol.Cmd
的用法示例。
在下文中一共展示了Cmd.GetCmdName方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: procSendTopicMsg
/*
device/client -> MsgServer -> Router
REQ_SEND_TOPIC_MSG_CMD
arg0: Msg //消息內容
arg1: TopicName //群組名, device無須提供
返回給消息發送者的消息
MsgServer -> device/client
RSP_SEND_TOPIC_MSG_CMD
arg0: SUCCESS/FAILED
通過Router轉發消息(對終端開發者不可見)
Router -> MsgServer
ROUTE_SEND_TOPIC_MSG_CMD
arg0: Msg //消息內容
arg1: TopicName //群組名
arg2: ClientID //發送方用戶ID
arg3: ClientType //發送方終端類型,是client還是device
發送給消息接受者的消息
MsgServer -> device/client
REQ_SEND_TOPIC_MSG_CMD
arg0: Msg //消息內容
arg1: TopicName //群組名
arg2: ClientID //發送方用戶ID
arg3: ClientType //發送方終端類型,是client還是device
*/
func (self *ProtoProc) procSendTopicMsg(cmd protocol.Cmd, session *libnet.Session) error {
log.Info("procSendTopicMsg")
var err error
var topicName string
var topicCacheData *redis_store.TopicCacheData
var sessionCacheData *redis_store.SessionCacheData
//var sessionStoreData *mongo_store.SessionStoreData
msg := cmd.GetArgs()[0]
resp := protocol.NewCmdSimple(protocol.RSP_SEND_TOPIC_MSG_CMD)
ClientID := session.State.(*base.SessionState).ClientID
ClientType := session.State.(*base.SessionState).ClientType
if ClientType == protocol.DEV_TYPE_CLIENT {
if len(cmd.GetArgs()) != 2 {
err = common.SYNTAX_ERROR
goto ErrOut
}
} else if len(cmd.GetArgs()) != 1 {
err = common.SYNTAX_ERROR
goto ErrOut
}
// get session cache
sessionCacheData, err = self.msgServer.sessionCache.Get(ClientID)
if sessionCacheData == nil {
log.Errorf("ID %s cache missing", ClientID)
err = common.NOT_ONLINE
goto ErrOut
} else if ClientType == protocol.DEV_TYPE_WATCH {
topicName = sessionCacheData.GetTopics()[0]
} else {
topicName = cmd.GetArgs()[1]
}
// check whether the topic exist
topicCacheData, err = self.msgServer.topicCache.Get(topicName)
if topicCacheData == nil {
log.Warningf("TOPIC %s not exist", topicName)
err = common.TOPIC_NOT_EXIST
} else {
topic_msg_resp := protocol.NewCmdSimple(cmd.GetCmdName())
topic_msg_resp.AddArg(msg)
topic_msg_resp.AddArg(topicName)
topic_msg_resp.AddArg(ClientID)
topic_msg_resp.AddArg(ClientType)
if topicCacheData.AliveMemberNumMap[self.msgServer.cfg.LocalIP] > 1 {
// exactly in this server, just broadcasting
topic_msg_resp.ChangeCmdName(protocol.IND_SEND_TOPIC_MSG_CMD)
log.Warningf("topic %s has %d member(s) in this server", topicName, topicCacheData.AliveMemberNumMap[self.msgServer.cfg.LocalIP])
for _, mID := range topicCacheData.MemberList {
if mID.ID != ClientID && self.msgServer.sessions[mID.ID] != nil {
self.msgServer.sessions[mID.ID].Send(libnet.Json(topic_msg_resp))
if err != nil {
log.Fatalln(err.Error())
}
}
}
}
if self.msgServer.channels[protocol.SYSCTRL_SEND] != nil {
//topic_msg_resp.ChangeCmdName(protocol.ROUTE_SEND_TOPIC_MSG_CMD)
topic_msg_resp.ChangeCmdName(protocol.REQ_SEND_TOPIC_MSG_CMD)
for ip, num := range topicCacheData.AliveMemberNumMap {
if num > 0 {
log.Warningf("topic %s has %d member(s) in ip %s", topicName, num, ip)
if ip != self.msgServer.cfg.LocalIP {
// not in this server, routing it
_, err = self.msgServer.channels[protocol.SYSCTRL_SEND].Channel.Broadcast(libnet.Json(topic_msg_resp))
if err != nil {
log.Error(err.Error())
}
//.........這裏部分代碼省略.........