static void Matchalgorithm() { while (true) { lock (matchLock) { for (int j = 0; j < AllWaitforMatchpools.Count; j++) { int len = AllWaitforMatchpools[j].MatchHashsetPool.Count; // Console.WriteLine("for ahead AllWaitforMatchpools len" + len.ToString()); for (int i = 0; i < len; i++) { // Console.WriteLine("AllWaitforMatchpools len"+ len.ToString()); if (AllWaitforMatchpools[j].currentroom == null || AllWaitforMatchpools[j].currentroom.mprocess.HasExited) { int nvn = 0; if (!Int32.TryParse(AllWaitforMatchpools[j].nvn, out nvn)) { nvn = 16; } AllWaitforMatchpools[j].currentroom = new Room(nvn, LanchServer.CreateOneRoom());//the client who create room determine the nvn AllWaitforMatchpools[j].currentroom.listroom = roomlist; AllWaitforMatchpools[j].currentroom.tcpclienttype = AllWaitforMatchpools[j]; roomlist.Add(AllWaitforMatchpools[j].currentroom); //Thread.Sleep(100);//wait IP port take effect } TCPClient temp = AllWaitforMatchpools[j].MatchHashsetPool.ElementAt(i);; int maxnumber = AllWaitforMatchpools[j].currentroom.getroommaxpeoplenumber(); int currentnumber = AllWaitforMatchpools[j].currentroom.getnumberofpeopleinroom(); if (currentnumber < maxnumber) { AllWaitforMatchpools[j].currentroom.Add(temp); } else//full { FMessagePackage mp = new FMessagePackage(); mp.MT = MessageType.MAPISFULL; String str = JsonConvert.SerializeObject(mp); temp.Send(str);// tell client the number of people in current map has reach the ceilling } temp.isinmatchpool = true; AllWaitforMatchpools[j].MatchHashsetPool.Remove(temp); len = AllWaitforMatchpools[j].MatchHashsetPool.Count; i = 0; //if (!notfull) //{ // roomlist.Add(AllWaitforMatchpools[j].currentroom); // AllWaitforMatchpools[j].currentroom = null; //} } } } Thread.Sleep(200); } }
public bool Add(TCPClient mtc) { mtc.room = this; mPeopleinroom.Add(mtc); mtc.onjoinroom.Invoke(this); entrycounter++; #if MODE1 /////////////////// /// FMessagePackage mp = new FMessagePackage(); mp.MT = MessageType.EntryMAP; mp.PayLoad = roomipaddress; String str = JsonConvert.SerializeObject(mp); mtc.Send(str); #endif if (pker.runing == false) { pker.runing = true; pker.threadkiller.Start(); } //////////////////////////// int len = mPeopleinroom.Count; Console.WriteLine("Room :" + len.ToString()); if (len < maxpeople) { return(true); } else { #if MODE1 #else Thread mt = new Thread(new ThreadStart(allpeoplepresentjustgo)); mt.Start(); Console.WriteLine("allpeoplepresentjustgo :"); #endif return(false); } }