コード例 #1
0
ファイル: IMChatServer.cs プロジェクト: atpx0001/XGames
 void ClearInvalidChannels()
 {
     for (int i = channels.Count; --i >= 0;)
     {
         IMChannel ch = im.GetChannel(channels[i]);
         if (ch == null || ch.url != http.url)
         {
             channels.RemoveAt(i);
         }
     }
 }
コード例 #2
0
ファイル: IMChatServer.cs プロジェクト: atpx0001/XGames
        protected override Base_Upload MakeHeatbeatUL()
        {
            ClearInvalidChannels();
            UL_Chat_getNewChannelMsgs ul = new UL_Chat_getNewChannelMsgs();

            ul.lastIds = new Dictionary <string, long>();
            for (int i = channels.Count; --i >= 0;)
            {
                IMChannel ch = im.GetChannel(channels[i]);
                ul.lastIds[ch.id] = im.GetSession(ch).lastId;
            }
            return(ul);
        }
コード例 #3
0
ファイル: IMChatServer.cs プロジェクト: atpx0001/XGames
 void ClearAll()
 {
     foreach (var m in sendingMsgs)
     {
         m.Distributed = false;
     }
     sendingMsgs.Clear();
     for (int i = channels.Count; --i >= 0;)
     {
         IMChannel ch2 = im.GetChannel(channels[i]);
         ch2.SetOffline();
     }
     channels.Clear();
 }
コード例 #4
0
ファイル: IMChatServer.cs プロジェクト: atpx0001/XGames
        int SyncChannelMsgs(BonDocument chd, IMChannel ch)
        {
            IMChatSession session = im.GetSession(ch);

            session.lastId = chd["lastId"].AsLong;
            newMsgs.Clear();
            BonUtil.ToObj(chd["msgs"], newMsgs);
            for (int i = newMsgs.Count; --i >= 0;)
            {
                newMsgs[i].im     = im;
                newMsgs[i].recTgt = IMChatTarget.频道;
            }
            im.AddNewMsgs(newMsgs);
            return(newMsgs.Count);
        }
コード例 #5
0
ファイル: IMChatServer.cs プロジェクト: atpx0001/XGames
        protected override bool OnHeatbeatDone(IMHttpContext ctx)
        {
            ClearInvalidChannels();
            if (ctx.code != 0)
            {
                Debug.Log("获取频道新聊天失败");
                ClearAll();
                return(false);
            }

            BonDocument chds = ctx.response.GetBonDocument("channels");

            if (chds == null)
            {
                ClearAll();
                return(false);
            }
            bool haveMsg = false;

            for (int i = channels.Count; --i >= 0;)
            {
                IMChannel ch = im.GetChannel(channels[i]);
                try {
                    if (!chds.Contains(ch.id))
                    {
                        ch.SetOffline();
                        continue;
                    }
                    if (SyncChannelMsgs(chds[ch.id].AsBonDocument, ch) > 0)
                    {
                        haveMsg = true;
                    }
                } catch (Exception e) {
                    Debug.Log(e);
                    ch.SetOffline();
                    continue;
                }
            }
            return(haveMsg);
        }
コード例 #6
0
ファイル: IMChatServer.cs プロジェクト: atpx0001/XGames
        protected override void OnSendDone(IMMsgForSend msg, IMHttpContext ctx)
        {
            IMChannel ch = im.GetChannel(msg.recId);

            if (ch == null)
            {
                return;
            }
            ClearInvalidChannels();
            if (ctx.code < 0)
            {
                Debug.Log("发送聊天致命错误");
                msg.Distributed = false;
                ClearAll();
                return;
            }
            if (ctx.code > 0)
            {
                Debug.Log("发送聊天错误");
                msg.Distributed = false;
                ch.SetOffline();
                return;
            }
            msg.Sent = true;
            try {
                BonDocument chd = ctx.response.GetBonDocument("channel");
                if (chd == null)
                {
                    msg.Distributed = false;
                    ch.SetOffline();
                    return;
                }
                SyncChannelMsgs(chd, ch);
            } catch (Exception e) {
                Debug.Log(e);
                msg.Distributed = false;
                ch.SetOffline();
            }
        }