public void Matching() { //没有匹配到就继续匹配 while (!isMatched) { lock (LocObj) { CTUser man = mPool[GlobalVar.SEX_MALE].MatchUser(); CTUser stranger = mPool[GlobalVar.SEX_FEMALE].MatchUser(); if (stranger != null && stranger != 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 CTPushMsg.Send(man.ConnectionId, "匹配成功了铁子"); CTPushMsg.Send(stranger.ConnectionId, "匹配成功了铁子"); } } if (mPool[GlobalVar.SEX_MALE].isPendingEmpty() || mPool[GlobalVar.SEX_FEMALE].isPendingEmpty()) { Thread.Sleep(3000); } Thread.Sleep(2000); } }
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("推送成功"); }
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); } }
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); } }
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) { 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); CTPushMsg.Send(tu.ConnectionId, "结束聊天"); } } mChattingRoom.Remove(user.Chatid); } } } return(true); } else { return(false); } }