本文整理匯總了Golang中github.com/oikomi/FishChatServer/libnet.Json函數的典型用法代碼示例。如果您正苦於以下問題:Golang Json函數的具體用法?Golang Json怎麽用?Golang Json使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Json函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: procCreateTopic
func (self *ProtoProc) procCreateTopic(cmd protocol.Cmd, session *libnet.Session) error {
log.Info("procCreateTopic")
var err error
if len(cmd.GetArgs()) != 1 {
return CMD_NOT_CORRECT
}
topicName := cmd.GetArgs()[0]
topicCacheData := redis_store.NewTopicCacheData(topicName, session.State.(*base.SessionState).ClientID,
self.msgServer.cfg.LocalIP)
t := protocol.NewTopic(topicName, self.msgServer.cfg.LocalIP, session.State.(*base.SessionState).ClientID, session)
t.ClientIDList = append(t.ClientIDList, session.State.(*base.SessionState).ClientID)
t.TSD = topicCacheData
self.msgServer.topics[topicName] = t
self.msgServer.topics[topicName].Channel = libnet.NewChannel(self.msgServer.server.Protocol())
self.msgServer.topics[topicName].Channel.Join(session, nil)
log.Info(topicCacheData)
args := make([]string, 0)
args = append(args, topicName)
CCmd := protocol.NewCmdInternal(protocol.CACHE_TOPIC_CMD, args, topicCacheData)
m := redis_store.NewMember(session.State.(*base.SessionState).ClientID)
CCmd.AnyData.(*redis_store.TopicCacheData).MemberList = append(CCmd.AnyData.(*redis_store.TopicCacheData).MemberList, m)
log.Info(CCmd)
if self.msgServer.channels[protocol.SYSCTRL_TOPIC_STATUS] != nil {
_, err = self.msgServer.channels[protocol.SYSCTRL_TOPIC_STATUS].Channel.Broadcast(libnet.Json(CCmd))
if err != nil {
log.Error(err.Error())
return err
}
}
// store topic
topicStoreData := mongo_store.NewTopicStoreData(topicName, session.State.(*base.SessionState).ClientID,
self.msgServer.cfg.LocalIP)
args = make([]string, 0)
args = append(args, topicName)
CCmd = protocol.NewCmdInternal(protocol.STORE_TOPIC_CMD, args, topicStoreData)
member := mongo_store.NewMember(session.State.(*base.SessionState).ClientID)
CCmd.AnyData.(*mongo_store.TopicStoreData).MemberList = append(CCmd.AnyData.(*mongo_store.TopicStoreData).MemberList, member)
log.Info(CCmd)
if self.msgServer.channels[protocol.STORE_TOPIC_INFO] != nil {
_, err = self.msgServer.channels[protocol.STORE_TOPIC_INFO].Channel.Broadcast(libnet.Json(CCmd))
if err != nil {
log.Error(err.Error())
return err
}
}
return nil
}
示例2: subscribeChannels
func (self *Manager) subscribeChannels() error {
log.Info("subscribeChannels")
var msgServerClientList []*libnet.Session
for _, ms := range self.cfg.MsgServerList {
msgServerClient, err := self.connectMsgServer(ms)
if err != nil {
log.Error(err.Error())
return err
}
cmd := protocol.NewCmdSimple(protocol.SUBSCRIBE_CHANNEL_CMD)
cmd.AddArg(protocol.SYSCTRL_CLIENT_STATUS)
cmd.AddArg(self.cfg.UUID)
err = msgServerClient.Send(libnet.Json(cmd))
if err != nil {
log.Error(err.Error())
return err
}
cmd = protocol.NewCmdSimple(protocol.SUBSCRIBE_CHANNEL_CMD)
cmd.AddArg(protocol.SYSCTRL_TOPIC_STATUS)
cmd.AddArg(self.cfg.UUID)
err = msgServerClient.Send(libnet.Json(cmd))
if err != nil {
log.Error(err.Error())
return err
}
cmd = protocol.NewCmdSimple(protocol.SUBSCRIBE_CHANNEL_CMD)
cmd.AddArg(protocol.STORE_CLIENT_INFO)
cmd.AddArg(self.cfg.UUID)
err = msgServerClient.Send(libnet.Json(cmd))
if err != nil {
log.Error(err.Error())
return err
}
cmd = protocol.NewCmdSimple(protocol.SUBSCRIBE_CHANNEL_CMD)
cmd.AddArg(protocol.STORE_TOPIC_INFO)
cmd.AddArg(self.cfg.UUID)
err = msgServerClient.Send(libnet.Json(cmd))
if err != nil {
log.Error(err.Error())
return err
}
msgServerClientList = append(msgServerClientList, msgServerClient)
}
for _, msc := range msgServerClientList {
go self.handleMsgServerClient(msc)
}
return nil
}
示例3: procClientID
func (self *ProtoProc) procClientID(cmd protocol.Cmd, session *libnet.Session) error {
log.Info("procClientID")
var err error
ID := cmd.GetArgs()[0]
// for cache data
sessionCacheData := redis_store.NewSessionCacheData(cmd.GetArgs()[0], session.Conn().RemoteAddr().String(),
self.msgServer.cfg.LocalIP, strconv.FormatUint(session.Id(), 10))
log.Info(sessionCacheData)
args := make([]string, 0)
args = append(args, cmd.GetArgs()[0])
CCmd := protocol.NewCmdInternal(protocol.CACHE_SESSION_CMD, args, sessionCacheData)
log.Info(CCmd)
if self.msgServer.channels[protocol.SYSCTRL_CLIENT_STATUS] != nil {
_, err = self.msgServer.channels[protocol.SYSCTRL_CLIENT_STATUS].Channel.Broadcast(libnet.Json(CCmd))
if err != nil {
log.Error(err.Error())
return err
}
}
// for store data
sessionStoreData := mongo_store.SessionStoreData{ID, session.Conn().RemoteAddr().String(),
self.msgServer.cfg.LocalIP, true}
log.Info(sessionStoreData)
args = make([]string, 0)
args = append(args, cmd.GetArgs()[0])
CCmd = protocol.NewCmdInternal(protocol.STORE_SESSION_CMD, args, sessionStoreData)
log.Info(CCmd)
if self.msgServer.channels[protocol.STORE_CLIENT_INFO] != nil {
_, err = self.msgServer.channels[protocol.STORE_CLIENT_INFO].Channel.Broadcast(libnet.Json(CCmd))
if err != nil {
log.Error(err.Error())
return err
}
}
self.msgServer.sessions[cmd.GetArgs()[0]] = session
self.msgServer.sessions[cmd.GetArgs()[0]].State = base.NewSessionState(true, cmd.GetArgs()[0])
err = self.procOfflineMsg(session, ID)
if err != nil {
log.Error(err.Error())
return err
}
return nil
}
示例4: procRouteMessageP2P
/*
Router -> MsgServer
ROUTE_SEND_P2P_MSG_CMD
arg0: Sent2ID //接收方用戶ID
arg1: Msg //消息內容
arg2: FromID //發送方用戶ID
arg3: uuid //MsgServer分配的消息uuid
發送給消息接受者的消息
MsgServer -> device/client
REQ_SEND_P2P_MSG_CMD
arg0: Msg //消息內容
arg1: FromID //發送方用戶ID
arg2: uuid //MsgServer分配的消息uuid,可選,如果提供了則須IND_ACK_P2P_STATUS_CMD(ClientID, uuid)
*/
func (self *ProtoProc) procRouteMessageP2P(cmd protocol.Cmd, session *libnet.Session) error {
log.Info("procRouteMessageP2P")
var err error
send2ID := cmd.GetArgs()[0]
send2Msg := cmd.GetArgs()[1]
fromID := cmd.GetArgs()[2]
uuid := cmd.GetArgs()[3]
if self.msgServer.sessions[send2ID] != nil {
resp := protocol.NewCmdSimple(protocol.IND_SEND_P2P_MSG_CMD)
resp.AddArg(send2Msg)
resp.AddArg(fromID)
// add uuid
resp.AddArg(uuid)
err = self.msgServer.sessions[send2ID].Send(libnet.Json(resp))
if err != nil {
log.Fatalln(err.Error())
} else {
self.procP2PAckStatus(fromID, uuid, protocol.P2P_ACK_SENT)
}
}
return nil
}
示例5: 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
}
示例6: 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
}
示例7: procSendMessageTopic
func (self *ProtoProc) procSendMessageTopic(cmd protocol.Cmd, session *libnet.Session) error {
glog.Info("procSendMessageTopic")
var err error
topicName := cmd.GetArgs()[0]
send2Msg := cmd.GetArgs()[1]
glog.Info(send2Msg)
glog.Info(topicName)
if self.msgServer.topics[topicName] == nil {
glog.Warning(topicName + " is not exist")
} else {
resp := protocol.NewCmdSimple(protocol.RESP_MESSAGE_TOPIC_CMD)
resp.AddArg(topicName)
resp.AddArg(send2Msg)
resp.AddArg(session.State.(*base.SessionState).ClientID)
_, err = self.msgServer.topics[topicName].Channel.Broadcast(libnet.Json(resp))
if err != nil {
glog.Error(err.Error())
return err
}
}
return err
}
示例8: procRouteMessageP2P
func (self *ProtoProc) procRouteMessageP2P(cmd protocol.Cmd, session *libnet.Session) error {
log.Info("procRouteMessageP2P")
var err error
send2ID := cmd.GetArgs()[0]
send2Msg := cmd.GetArgs()[1]
fromID := cmd.GetArgs()[2]
uuid := cmd.GetArgs()[3]
_, err = common.GetSessionFromCID(self.msgServer.sessionCache, send2ID)
if err != nil {
log.Warningf("no ID : %s", send2ID)
return err
}
resp := protocol.NewCmdSimple(protocol.RESP_MESSAGE_P2P_CMD)
resp.AddArg(send2Msg)
resp.AddArg(fromID)
// add uuid
resp.AddArg(uuid)
if self.msgServer.sessions[send2ID] != nil {
self.msgServer.sessions[send2ID].Send(libnet.Json(resp))
if err != nil {
log.Fatalln(err.Error())
}
}
return nil
}
示例9: subscribeChannels
func (self *Monitor) subscribeChannels() error {
log.Info("monitor start to subscribeChannels")
for _, ms := range self.cfg.MsgServerList {
msgServerClient, err := self.connectMsgServer(ms)
if err != nil {
log.Error(err.Error())
return err
}
cmd := protocol.NewCmdSimple(protocol.SUBSCRIBE_CHANNEL_CMD)
cmd.AddArg(protocol.SYSCTRL_MONITOR)
cmd.AddArg(self.cfg.UUID)
err = msgServerClient.Send(libnet.Json(cmd))
if err != nil {
log.Error(err.Error())
return err
}
self.msgServerClientMap[ms] = msgServerClient
}
for _, msc := range self.msgServerClientMap {
go self.handleMsgServerClient(msc)
}
return nil
}
示例10: procJoinTopic
/*
client -> MsgServer
REQ_JOIN_TOPIC_CMD
arg0: TopicName //群組名
arg1: ClientName //用戶在Topic中的Name, 比如老爸/老媽
MsgServer -> client
RSP_JOIN_TOPIC_CMD
arg0: SUCCESS/FAILED
*/
func (self *ProtoProc) procJoinTopic(cmd protocol.Cmd, session *libnet.Session) error {
log.Info("procJoinTopic")
var err error
if len(cmd.GetArgs()) != 2 {
err = common.SYNTAX_ERROR
} else {
topicName := cmd.GetArgs()[0]
clientName := cmd.GetArgs()[1]
clientID := session.State.(*base.SessionState).ClientID
clientType := session.State.(*base.SessionState).ClientType
member := mongo_store.NewMember(clientID, clientName, clientType)
err = self.msgServer.procJoinTopic(member, topicName)
}
resp := protocol.NewCmdSimple(protocol.RSP_JOIN_TOPIC_CMD)
if err != nil {
resp.AddArg(err.Error())
} else {
resp.AddArg(protocol.RSP_SUCCESS)
}
err = session.Send(libnet.Json(resp))
if err != nil {
log.Error(err.Error())
}
return err
}
示例11: procOfflineMsg
func (self *ProtoProc) procOfflineMsg(session *libnet.Session, ID string) error {
var err error
exist, err := self.msgServer.offlineMsgStore.IsKeyExist(ID)
if exist.(int64) == 0 {
return err
} else {
omrd, err := common.GetOfflineMsgFromOwnerName(self.msgServer.offlineMsgStore, ID)
if err != nil {
glog.Error(err.Error())
return err
}
for _, v := range omrd.MsgList {
resp := protocol.NewCmdSimple(protocol.RESP_MESSAGE_P2P_CMD)
resp.AddArg(v.Msg)
resp.AddArg(v.FromID)
if self.msgServer.sessions[ID] != nil {
self.msgServer.sessions[ID].Send(libnet.Json(resp))
if err != nil {
glog.Error(err.Error())
return err
}
}
}
omrd.ClearMsg()
self.msgServer.offlineMsgStore.Set(omrd)
}
return err
}
示例12: procGetTopicList
func (self *ProtoProc) procGetTopicList(cmd protocol.Cmd, session *libnet.Session) error {
log.Info("procGetTopicList")
var err error
resp := protocol.NewCmdSimple(protocol.RSP_GET_TOPIC_LIST_CMD)
clientID := session.State.(*base.SessionState).ClientID
//clientType := session.State.(*base.SessionState).ClientType
sessionCacheData, err := self.msgServer.sessionCache.Get(clientID)
if sessionCacheData == nil {
log.Warningf("Client %s not online", clientID)
err = common.NOT_ONLINE
goto ErrOut
}
ErrOut:
if err != nil {
resp.AddArg(err.Error())
} else {
resp.AddArg(protocol.RSP_SUCCESS)
resp.AddArg(strconv.Itoa(len(sessionCacheData.TopicList)))
for _, topic := range sessionCacheData.TopicList {
resp.AddArg(topic)
}
}
err = session.Send(libnet.Json(resp))
if err != nil {
log.Error(err.Error())
}
return err
}
示例13: procQuitTopic
/*
client -> MsgServer
REQ_QUIT_TOPIC_CMD
arg0: TopicName //群組名
MsgServer -> client
RSP_QUIT_TOPIC_CMD
arg0: SUCCESS/ERROR
*/
func (self *ProtoProc) procQuitTopic(cmd protocol.Cmd, session *libnet.Session) error {
log.Info("procQuitTopic")
var err error
if len(cmd.GetArgs()) != 1 {
err = common.SYNTAX_ERROR
} else {
topicName := cmd.GetArgs()[0]
clientID := session.State.(*base.SessionState).ClientID
err = self.msgServer.procQuitTopic(clientID, topicName)
}
resp := protocol.NewCmdSimple(protocol.RSP_QUIT_TOPIC_CMD)
if err != nil {
resp.AddArg(err.Error())
} else {
resp.AddArg(protocol.RSP_SUCCESS)
}
err = session.Send(libnet.Json(resp))
if err != nil {
log.Error(err.Error())
}
return err
}
示例14: procOfflineMsg
/*
發送給消息接受者的消息
MsgServer -> device/client
REQ_SEND_P2P_MSG_CMD
arg0: Msg //消息內容
arg1: FromID //發送方用戶ID
arg2: uuid //MsgServer分配的消息uuid,可選,如果提供了則須IND_ACK_P2P_STATUS_CMD(ClientID, uuid)
*/
func (self *ProtoProc) procOfflineMsg(session *libnet.Session, ID string) error {
var err error
exist, err := self.msgServer.offlineMsgCache.IsKeyExist(ID)
if exist.(int64) == 0 {
return err
} else {
omrd, err := common.GetOfflineMsgFromOwnerName(self.msgServer.offlineMsgCache, ID)
if err != nil {
log.Error(err.Error())
return err
}
for _, v := range omrd.MsgList {
if v.Msg == protocol.IND_ACK_P2P_STATUS_CMD {
resp := protocol.NewCmdSimple(protocol.IND_ACK_P2P_STATUS_CMD)
resp.AddArg(v.Uuid)
resp.AddArg(v.FromID) // v.FromID is status
if self.msgServer.sessions[ID] != nil {
self.msgServer.sessions[ID].Send(libnet.Json(resp))
if err != nil {
log.Error(err.Error())
return err
}
}
} else {
resp := protocol.NewCmdSimple(protocol.IND_SEND_P2P_MSG_CMD)
resp.AddArg(v.Msg)
resp.AddArg(v.FromID)
resp.AddArg(v.Uuid)
if self.msgServer.sessions[ID] != nil {
self.msgServer.sessions[ID].Send(libnet.Json(resp))
if err != nil {
log.Error(err.Error())
return err
} else {
self.procP2PAckStatus(v.FromID, v.Uuid, protocol.P2P_ACK_SENT)
}
}
}
}
omrd.ClearMsg()
self.msgServer.offlineMsgCache.Set(omrd)
}
return err
}
示例15: procAdd2Topic
/*
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/FAILED
arg1: TopicName
arg2: ClientID
arg3: ClientType
*/
func (self *ProtoProc) procAdd2Topic(cmd protocol.Cmd, session *libnet.Session) error {
log.Info("procAdd2Topic")
var err error
topicName := cmd.GetArgs()[0]
mID := cmd.GetArgs()[1]
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)
if len(cmd.GetArgs()) != 3 {
err = common.SYNTAX_ERROR
} else
// only DEV_TYPE_CLIENT CAN create topic
if ClientType != protocol.DEV_TYPE_CLIENT {
err = common.DENY_ACCESS
} else {
// check whether the topic exist
topicCacheData, _ := self.msgServer.topicCache.Get(topicName)
if topicCacheData == nil {
log.Infof("TOPIC %s not exist in CACHE", topicName)
err = common.TOPIC_NOT_EXIST
} else
// only topic creater can do this
if topicCacheData.CreaterID != ClientID {
log.Warningf("ClientID %s is not creater of topic %s", ClientID, topicName)
err = common.DENY_ACCESS
} else {
// New Member MUST be online
sessionCacheData, _ := self.msgServer.sessionCache.Get(mID)
if sessionCacheData == nil {
log.Warningf("Client %s not online", mID)
err = common.NOT_ONLINE
} else {
mType = sessionCacheData.ClientType
member := mongo_store.NewMember(mID, mName, mType)
err = self.msgServer.procJoinTopic(member, topicName)
}
}
}
if err != nil {
resp.AddArg(err.Error())
} 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())
}
return err
}