本文整理汇总了Golang中FishChatServer/protocol.Cmd.ChangeCmdName方法的典型用法代码示例。如果您正苦于以下问题:Golang Cmd.ChangeCmdName方法的具体用法?Golang Cmd.ChangeCmdName怎么用?Golang Cmd.ChangeCmdName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FishChatServer/protocol.Cmd
的用法示例。
在下文中一共展示了Cmd.ChangeCmdName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: procRouteTopicMsg
/*
通过Router转发消息(对终端开发者不可见)
Router -> MsgServer
ROUTE_SEND_TOPIC_MSG_CMD
arg0: Msg //消息内容
arg1: TopicName //群组名
arg2: ClientID //发送方用户ID
arg3: ClientType //发送方终端类型,是client还是device
*/
func (self *ProtoProc) procRouteTopicMsg(cmd protocol.Cmd, session *libnet.Session) error {
log.Info("procRouteTopicMsg")
var err error
//send2Msg := cmd.GetArgs()[0]
topicName := cmd.GetArgs()[1]
//fromID := cmd.GetArgs()[2]
//fromType := cmd.GetArgs()[3]
// check whether the topic exist
topicCacheData, err := self.msgServer.topicCache.Get(topicName)
if topicCacheData == nil {
log.Warningf("TOPIC %s not exist: %s", topicName, err.Error())
return common.TOPIC_NOT_EXIST
}
cmd.ChangeCmdName(protocol.REQ_SEND_TOPIC_MSG_CMD)
// exactly in this server, just broadcasting
log.Warningf("topic %s has %d member(s) in this server", topicName, topicCacheData.AliveMemberNumMap[self.msgServer.cfg.LocalIP])
for _, mID := range topicCacheData.MemberList {
if self.msgServer.sessions[mID.ID] != nil {
self.msgServer.sessions[mID.ID].Send(libnet.Json(cmd))
if err != nil {
log.Fatalln(err.Error())
}
}
}
return nil
}
示例2: procSendMsgP2P
/*
MsgServer -> Router
REQ_SEND_P2P_MSG_CMD
arg0: Sent2ID //接收方用户ID
arg1: Msg //消息内容
arg2: FromID //发送方用户ID
arg3: uuid //MsgServer分配的消息uuid
*/
func (self *ProtoProc) procSendMsgP2P(cmd protocol.Cmd, session *libnet.Session) error {
log.Info("procSendMsgP2P")
var err error
send2ID := cmd.GetArgs()[0]
send2Msg := cmd.GetArgs()[1]
log.Info(send2Msg)
self.Router.readMutex.Lock()
defer self.Router.readMutex.Unlock()
cacheSession, err := self.Router.sessionCache.Get(send2ID)
if cacheSession == nil || cacheSession.Alive == false {
storeSession, err := self.Router.mongoStore.GetSessionFromCid(send2ID)
if err != nil {
log.Warningf("ID %s not registered, msg dropped", send2ID)
return err
}
log.Info(storeSession)
log.Warningf("ID registered but offline: %s", send2ID)
cmd.ChangeCmdName(protocol.ROUTE_SEND_P2P_MSG_CMD)
//ms := self.Router.cfg.MsgServerList[0]
ms := session.Conn().RemoteAddr().String()
err = self.Router.msgServerClientMap[ms].Send(libnet.Json(cmd))
if err != nil {
log.Error("error:", err)
return err
}
} else {
log.Info(cacheSession.MsgServerAddr)
cmd.ChangeCmdName(protocol.ROUTE_SEND_P2P_MSG_CMD)
log.Info(cmd)
err = self.Router.msgServerClientMap[cacheSession.MsgServerAddr].Send(libnet.Json(cmd))
if err != nil {
log.Error("error:", err)
return err
}
}
return nil
}
示例3: procSendMsgTopic
/*
Router -> MsgServer
ROUTE_SEND_TOPIC_MSG_CMD
arg0: ClientID //发送方用户ID
arg1: ClientType //发送方终端类型,是client还是device
arg2: Msg //消息内容
arg3: TopicName //群组名, device无须提供
*/
func (self *ProtoProc) procSendMsgTopic(cmd protocol.Cmd, session *libnet.Session) error {
log.Info("procSendMsgTopic")
var err error
ms := session.Conn().RemoteAddr().String()
//send2Msg := cmd.GetArgs()[0]
topicName := cmd.GetArgs()[1]
//fromID := cmd.GetArgs()[2]
//fromType := cmd.GetArgs()[3]
// check whether the topic exist
topicCacheData, err := self.Router.topicCache.Get(topicName)
if topicCacheData == nil {
log.Warningf("TOPIC %s not exist: %s", topicName, err.Error())
return err
}
cmd.ChangeCmdName(protocol.ROUTE_SEND_TOPIC_MSG_CMD)
log.Info(protocol.ROUTE_SEND_TOPIC_MSG_CMD)
log.Info(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 != ms {
// not in this server, routing it
err = self.Router.msgServerClientMap[ip].Send(libnet.Json(cmd))
if err != nil {
log.Error("error:", err)
return err
}
}
}
}
return nil
}