public static void ExecuteMatch(object state) { var queues = CacheSet.PVPMathcQueueCache.FindAll(); //PlayerSinglePvpLogic psp = new PlayerSinglePvpLogic(); foreach (var queue in queues) { queue.MatchedGroupCount = 0; if (queue.InQueueGroups.Count <= 1) { continue; } var groups = new List <PVPGroup>(); groups.AddRange(queue.InQueueGroups); groups.Sort(); for (int i = 0; i < groups.Count; i++) { while ((groups[i + 1].Player.Score - groups[i].Player.Score) > 200 && i + 1 < groups.Count) { queue.MatchedGroupCount += 1; i++; } if (i + 1 >= groups.Count) { break; } WRCreateNewRoom userData = new WRCreateNewRoom(); userData.RoomPlayerInfo.Add(groups[i].Player); userData.RoomPlayerInfo.Add(groups[i + 1].Player); userData.Token = GetToken(); var room = RoomServerManager.GetLowestLoadedRoomServer(); RoomServerSender.Send(room.Id, "LRCreateNewRoomHandler", userData, delegate(RemotePackage callback) { //TraceLog.ReleaseWrite("Player:{0} and Player:{1} match success", groups[i].Player.PlayerInfo.Id.ToString(), groups[i + 1].Player.PlayerInfo.Id.ToString()); var res = RemoteCommunication.ParseRemotePackage <RWCreateNewRoom>(callback.Message as byte[]); WLMatchSuccess package = new WLMatchSuccess() { RoomId = res.RoomId, InstanceId = res.InstanceId, Token = userData.Token, RoomServerHost = room.Host, RoomServerPort = room.Port, }; package.EnemyInfo = groups[queue.MatchedGroupCount + 1].Player; package.PlayerId = groups[queue.MatchedGroupCount].Player.PlayerInfo.Id; LobbyServerSender.Send(groups[queue.MatchedGroupCount].Player.LobbyServerId, "WLMatchSuccessHandler", package, delegate(RemotePackage cb) { }); package.EnemyInfo = groups[queue.MatchedGroupCount].Player; package.PlayerId = groups[queue.MatchedGroupCount + 1].Player.PlayerInfo.Id; LobbyServerSender.Send(groups[queue.MatchedGroupCount + 1].Player.LobbyServerId, "WLMatchSuccessHandler", package, delegate(RemotePackage cb) { }); queue.InQueueGroups.Remove(groups[queue.MatchedGroupCount]); queue.InQueueGroups.Remove(groups[queue.MatchedGroupCount + 1]); }); i++; } } }