Ejemplo n.º 1
0
        protected void btn_push_Click(object sender, EventArgs e)
        {
            //推送功能
            CTData <CTPushMessage> d = new CTData <CTPushMessage>();
            string title             = tvTitle.Text.ToString();
            string msg = tvContent.Text.ToString();

            if (title == null || title.Equals(""))
            {
                showBox("标题不能为空~");
                return;
            }
            if (msg == null || msg.Equals(""))
            {
                showBox("内容不能为空~");
                return;
            }
            btn_push.Text = "正在推送...";
            d.DataType    = CTData <CTPushMsg> .DATATYPE_PUSH;
            CTPushMessage ctpm = new CTPushMessage();

            ctpm.Title = title;
            ctpm.Body  = msg;
            d.Body     = ctpm;
            msg        = JsonConvert.SerializeObject(d);
            foreach (KeyValuePair <string, CTUserBase> who in GlobalVar.mClients)
            {
                CTPushMsg.Send(who.Key, msg);
            }
            btn_push.Text = "推送";
            showBox("推送成功");
        }
Ejemplo n.º 2
0
    protected override Task OnReceived(IRequest request, string connectionId, string data)
    {
        /***********************2017-09-08  邵国鑫***/
        //1.转发消息到对应id
        //2.连接信息 添加新用户

        try
        {
            CTData <Object> d = new CTData <Object>();
            d = JsonConvert.DeserializeObject <CTData <Object> >(data);
            //初始json
            if (d != null)
            {
                switch (d.DataType)
                {
                case CTData <Object> .DATATYPE_CONNECTED:
                    CTData <CTUser> s    = JsonConvert.DeserializeObject <CTData <CTUser> >(data);
                    CTUser          user = s.Body;
                    CTAreaPool.getInstance().addUser(user);
                    CTUserBase userbase = new CTUserBase();
                    userbase.Sex    = user.Sex;
                    userbase.Uid    = user.Uid;
                    userbase.School = user.School;
                    if (!mClients.ContainsKey(connectionId))
                    {
                        mClients.Add(connectionId, userbase);
                    }
                    if (!mFastClients.ContainsKey(user.Uid))
                    {
                        mFastClients.Add(user.Uid, connectionId);
                    }
                    break;

                case CTData <Object> .DATATYPE_MESSAGE:
                    CTData <CTMessage> ctmsg = JsonConvert.DeserializeObject <CTData <CTMessage> >(data);
                    //文本信息
                    CTMessage msg = ctmsg.Body;
                    if (mFastClients.Count > 0 && mFastClients.ContainsKey(msg.To))
                    {
                        Connection.Send(mFastClients[msg.To], ctmsg.Body.Body);
                    }
                    break;
                }
            }
        }
        catch (Exception e)
        {
            string x = e.Message;
        }

        return(base.OnReceived(request, connectionId, data));
    }
Ejemplo n.º 3
0
    public void Matching()
    {
        //没有匹配到就继续匹配

        while (!IsMatched)
        {
            lock (LocObj)
            {
                try
                {
                    CTUser man      = mPool[GlobalVar.SEX_MALE].MatchUser();
                    CTUser stranger = mPool[GlobalVar.SEX_FEMALE].MatchUser();
                    if (stranger != null && man != null)
                    {
                        string id = System.Guid.NewGuid().ToString();
                        man.Chatid      = id;
                        stranger.Chatid = id;
                        moveUser(GlobalVar.STATE_BUSY, man.Uid);
                        moveUser(GlobalVar.STATE_BUSY, stranger.Uid);
                        //推送给用户匹配成功通知
                        List <CTUser> listuser = new List <CTUser>();
                        listuser.Add(man);
                        listuser.Add(stranger);
                        mChattingRoom.Add(id, listuser);
                        //推送信息包括:State:success,Stranger:uid
                        CTData <string> data = new CTData <string>();
                        data.DataType = CTData <string> .DATATYPE_REPLY;
                        data.Body     = stranger.Uid;
                        CTPushMsg.Send(man.ConnectionId, JsonConvert.SerializeObject(data));
                        data.Body = man.Uid;
                        CTPushMsg.Send(stranger.ConnectionId, JsonConvert.SerializeObject(data));
                    }
                }
                catch
                {
                    mMatchThread = new Thread(Matching);
                    mMatchThread.Start();
                }
            }
            if (mPool[GlobalVar.SEX_MALE].isPendingEmpty() || mPool[GlobalVar.SEX_FEMALE].isPendingEmpty())
            {
                Thread.Sleep(2000);
            }
            Thread.Sleep(1000);
        }
    }
Ejemplo n.º 4
0
    public bool moveUser(int to, string uid)
    {
        Dictionary <string, CTUser> tmp = null;

        tmp = mPool[ctUtils.getSexbyUid(uid)].hasUser(uid);
        if (tmp != null)
        {
            CTUser user = mPool[ctUtils.getSexbyUid(uid)].MoveUser(tmp, to, uid);

            //解决聊天室 单向关闭
            if (user != null && to == GlobalVar.STATE_NONE)
            {
                lock (LocObj)
                {
                    if (mChattingRoom.ContainsKey(user.Chatid))
                    {
                        List <CTUser> list = mChattingRoom[user.Chatid];
                        foreach (CTUser tu in list)
                        {
                            if (!tu.Uid.Equals(user.Uid))
                            {
                                tu.Chatid = "";
                                tu.State  = GlobalVar.STATE_PENDING + "";
                                moveUser(GlobalVar.STATE_PENDING, tu.Uid);
                                CTData <string> msg = new CTData <string>();
                                msg.DataType = CTData <string> .DATATYPE_CONNECTED;
                                msg.Body     = "next";
                                CTPushMsg.Send(tu.ConnectionId, JsonConvert.SerializeObject(msg));
                            }
                        }
                        mChattingRoom.Remove(user.Chatid);
                        user.Chatid = "";
                    }
                }
            }
            return(true);
        }
        else
        {
            return(false);
        }
    }
Ejemplo n.º 5
0
    protected override Task OnReceived(IRequest request, string connectionId, string data)
    {
        /***********************2017-09-08  邵国鑫***/
        //1.转发消息到对应id
        //2.连接信息 添加新用户
        lock (LocObj)
        {
            try
            {
                CTData <Object> d = new CTData <Object>();
                d = JsonConvert.DeserializeObject <CTData <Object> >(data);
                //初始json
                if (d != null)
                {
                    switch (d.DataType)
                    {
                    case CTData <Object> .DATATYPE_CONNECTED:
                        lock (LocObj)
                        {
                            CTData <CTUser> s    = JsonConvert.DeserializeObject <CTData <CTUser> >(data);
                            CTUser          user = s.Body;
                            user.ConnectionId = connectionId;
                            CTAreaPool.getInstance().addUser(user);
                            CTUserBase userbase = new CTUserBase();
                            userbase.Sex    = user.Sex;
                            userbase.Uid    = user.Uid;
                            userbase.School = user.School;
                            if (!GlobalVar.mClients.ContainsKey(connectionId))
                            {
                                GlobalVar.mClients.Add(connectionId, userbase);
                            }
                            else
                            {
                                GlobalVar.mClients[connectionId] = userbase;
                            }
                            if (!mFastClients.ContainsKey(user.Uid))
                            {
                                mFastClients.Add(user.Uid, connectionId);
                            }
                            else
                            {
                                mFastClients[user.Uid] = connectionId;
                            }
                        }
                        break;

                    case CTData <Object> .DATATYPE_MESSAGE:
                        CTData <CTMessage> ctmsg = JsonConvert.DeserializeObject <CTData <CTMessage> >(data);
                        CTMessage          msg   = ctmsg.Body;
                        if (mFastClients.Count > 0 && mFastClients.ContainsKey(msg.To))
                        {
                            Connection.Send(mFastClients[msg.To], data);
                        }

                        /*
                         *
                         *
                         * switch (msg.Type)
                         * {
                         *  //文本信息
                         *  case CTMessage.MESSAGE_TYPE_TEXT:
                         *
                         *      break;
                         *  case CTMessage.MESSAGE_TYPE_EMOJI: break;
                         *  case CTMessage.MESSAGE_TYPE_AUDIO: break;
                         *  case CTMessage.MESSAGE_TYPE_PHOTO: break;
                         * }*/
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                string x = e.Message;
            }
        }
        return(base.OnReceived(request, connectionId, data));
    }