當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Cmd.ChangeCmdName方法代碼示例

本文整理匯總了Golang中github.com/oikomi/FishChatServer/protocol.Cmd.ChangeCmdName方法的典型用法代碼示例。如果您正苦於以下問題:Golang Cmd.ChangeCmdName方法的具體用法?Golang Cmd.ChangeCmdName怎麽用?Golang Cmd.ChangeCmdName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/oikomi/FishChatServer/protocol.Cmd的用法示例。


在下文中一共展示了Cmd.ChangeCmdName方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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.IND_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
}
開發者ID:alvin921,項目名稱:FishChatServer,代碼行數:40,代碼來源:proto_proc.go

示例2: procSendMsgP2P

func (self *ProtoProc) procSendMsgP2P(cmd protocol.Cmd, session *libnet.Session) error {
	glog.Info("procSendMsgP2P")
	var err error
	send2ID := cmd.GetArgs()[0]
	send2Msg := cmd.GetArgs()[1]
	glog.Info(send2Msg)
	self.Monitor.readMutex.Lock()
	defer self.Monitor.readMutex.Unlock()
	store_session, err := common.GetSessionFromCID(self.Monitor.sessionStore, send2ID)
	if err != nil {
		glog.Warningf("no ID : %s", send2ID)

		return err
	}
	glog.Info(store_session.MsgServerAddr)

	cmd.ChangeCmdName(protocol.ROUTE_MESSAGE_P2P_CMD)

	err = self.Monitor.msgServerClientMap[store_session.MsgServerAddr].Send(libnet.Json(cmd))
	if err != nil {
		glog.Error("error:", err)
		return err
	}

	return nil
}
開發者ID:iguchunhui,項目名稱:FishChatServer,代碼行數:26,代碼來源:proto_proc.go

示例3: 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
}
開發者ID:alvin921,項目名稱:FishChatServer,代碼行數:49,代碼來源:proto_proc.go

示例4: procSendMsgP2P

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 := common.GetSessionFromCID(self.Router.sessionCache, send2ID)
	if err != nil {
		log.Warningf("no ID in cache : %s", send2ID)
		storeSession, err := self.Router.mongoStore.GetSessionFromCid(mongo_store.DATA_BASE_NAME,
			mongo_store.TOPIC_INFO_COLLECTION, send2ID)
		if err != nil {
			return err
		}
		log.Info(storeSession.MsgServerAddr)

		cmd.ChangeCmdName(protocol.ROUTE_MESSAGE_P2P_CMD)

		err = self.Router.msgServerClientMap[storeSession.MsgServerAddr].Send(libnet.Json(cmd))
		if err != nil {
			log.Error("error:", err)
			return err
		}
	} else {
		log.Info(cacheSession.MsgServerAddr)

		cmd.ChangeCmdName(protocol.ROUTE_MESSAGE_P2P_CMD)

		err = self.Router.msgServerClientMap[cacheSession.MsgServerAddr].Send(libnet.Json(cmd))
		if err != nil {
			log.Error("error:", err)
			return err
		}
	}

	return nil
}
開發者ID:ZhangTingkuo,項目名稱:FishChatServer,代碼行數:39,代碼來源:proto_proc.go

示例5: 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
}
開發者ID:alvin921,項目名稱:FishChatServer,代碼行數:45,代碼來源:proto_proc.go


注:本文中的github.com/oikomi/FishChatServer/protocol.Cmd.ChangeCmdName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。