public override bool TakeAction() { LWGetWorldSinglePvpRank package = new LWGetWorldSinglePvpRank() { UserId = m_UserId, ServerId = int.Parse(ConfigUtils.GetSetting("Server.Id")) }; WorldServerSender.Send("LWGetWorldSinglePvpRankHandler", package, delegate(RemotePackage callback) { var res = RemoteCommunication.ParseRemotePackage <WLGetWorldSinglePvpRank>(callback.Message as byte[]); m_ResponsePacket.MyRank = res.MyRank; m_ResponsePacket.MyScore = res.MyScore; for (int i = 0; i < res.PlayerInfo.Count; i++) { m_ResponsePacket.PlayerInfo.Add(new PBPlayerInfo() { Id = res.PlayerInfo[i].Id, Name = res.PlayerInfo[i].Name, PortraitType = res.PlayerInfo[i].PortraitType, }); m_ResponsePacket.ServerId.Add(res.ServerId[i]); m_ResponsePacket.Score.Add(res.Score[i]); } var buff = CustomActionDispatcher.GeneratePackageStream(actionGetter.GetActionId(), ProtoBufUtils.Serialize(m_ResponsePacket)); GameSession.Get(m_UserId).SendAsync(buff, 0, buff.Length); }); return(true); }
public CffRemoteCommunication() { RemoteCommunication = new RemoteCommunication(); RemoteCommunicationSection = new PairSection( CffKeywords.OPENING_REMOTE_COMMUNICATION, CffKeywords.CLOSING_REMOTE_COMMUNICATION); }
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++; } } }
public static bool StopSingleMatch(int userId) { bool success = false; LWCancelSinglePvpMatching package = new LWCancelSinglePvpMatching(); package.PlayerId = userId; WorldServerSender.Send("LWCancelSinglePvpMatchingHandler", package, delegate(RemotePackage callback) { var res = RemoteCommunication.ParseRemotePackage <WLCancelSinglePvpMatching>(callback.Message as byte[]); success = res.Success; }); return(success); }
public static bool StartSingleMatch(int userId) { bool success = false; LWStartSinglePvpMatching package = new LWStartSinglePvpMatching(); package.RoomPlayerInfo = GetPlayerRoomData(userId); WorldServerSender.Send("LWStartSinglePvpMatchingHandler", package, delegate(RemotePackage callback) { var res = RemoteCommunication.ParseRemotePackage <WLStartSinglePvpMatching>(callback.Message as byte[]); success = res.Success; }); return(success); }
private static Dictionary <string, string> GetAllConfigs() { Dictionary <string, string> ret = new Dictionary <string, string>(); RequestParam param = new RequestParam(); LobbyServerSender.Send("RLGetGameConfigsHandler", param, callback => { var res = RemoteCommunication.ParseRemotePackage <LRGetGameConfigs>(callback.Message as byte[]); for (int i = 0; i < res.Keys.Count; i++) { ret.Add(res.Keys[i], res.Values[i]); } }); return(ret); }
protected override void TakeRemote() { PvpPlayer player1 = null; PvpPlayer player2 = null; if (m_RequestPacket.PlayerIds.Count < 2) { return; } for (int i = 0; i < m_RequestPacket.PlayerIds.Count; i++) { PvpPlayer p = CacheSet.PvpPlayerCache.FindKey(m_RequestPacket.PlayerIds[i], m_RequestPacket.ServerId[i]); if (p == null) { return; } if (i == 0) { player1 = p; } else if (i == 1) { player2 = p; } } int p1score = PVPLogic.GetDeltaScore(player1.Score, player2.Score, m_RequestPacket.Result[0]); int p2score = PVPLogic.GetDeltaScore(player2.Score, player1.Score, m_RequestPacket.Result[1]); WLPvpResult package = new WLPvpResult(); for (int i = 0; i < m_RequestPacket.PlayerIds.Count; i++) { package.PlayerId = m_RequestPacket.PlayerIds[i]; package.Result = m_RequestPacket.Result[i]; package.Score = i == 0 ? p1score : p2score; LobbyServerSender.Send(m_RequestPacket.ServerId[i], "WLPvpResultHandler", package, delegate(RemotePackage callback) { LWPvpResult res = RemoteCommunication.ParseRemotePackage <LWPvpResult>(callback.Message as byte[]); if (res.PlayerId == player1.Id) { player1.Score = res.Score; } else if (res.PlayerId == player2.Id) { player2.Score = res.Score; } RankingFactory.Get <SinglePvpRankUser>("SinglePvpRanking").Refresh(); }); } }
public bool ValidateFile(string cffFilename, Validations validations) { if (cffFilename == null) { return(false); } CffLogFile cffLogFile = new CffLogFile(); CffLimits cffLimits = new CffLimits(); CffProgram cffProgram = new CffProgram(); CffTasks cffTasks = new CffTasks(); CffProcessors cffProcessors = new CffProcessors(); CffProcessorTypes cffProcessorTypes = new CffProcessorTypes(); CffLocalCommunication cffLocalCommunication = new CffLocalCommunication(); CffRemoteCommunication cffRemoteCommunication = new CffRemoteCommunication(); int beforeNumOfError, afterNumOfError; int lineNumber = 1; string line; StreamReader streamReader = new StreamReader(cffFilename); string EXPECTED_LOGFILE_FORMAT = $"\"[name].{cffLogFile.LOGFILE_EXTENSION}\""; validations.Filename = cffFilename; beforeNumOfError = validations.ErrorValidationManager.Errors.Count; while (!streamReader.EndOfStream) { line = streamReader.ReadLine(); line = line.Trim(); validations.LineNumber = lineNumber.ToString(); // Check if keyword is valid or not validations.CheckValidKeyword(line, CffKeywords.KEYWORD_DICT); // Extract and validate the LOGFILE section // If the LOGFILE section is already visited, then ignore if (!cffLogFile.LogFileSection.ValidSectionPair[1]) { LogFilename = cffLogFile.ExtractLogFile(cffFilename, line, validations); } // Extract and validate the LIMITS section // If the LIMITS sections is already visited, then ignore if (!cffLimits.LimitPairSection.ValidSectionPair[1]) { LimitData = cffLimits.ExtractLimitData(line, validations); } // Extract and validate the PROGRAM section // If the LIMITS sections is already visited, then ignore if (!cffProgram.ProgramPairSection.ValidSectionPair[1]) { Program = cffProgram.ExtractProgramData(line, validations); } // Extract and validate the TASKS section // If the TASKS sections is already visited, then ignore if (!cffTasks.TasksSection.ValidSectionPair[1]) { Tasks = cffTasks.ExtractTasks(line, validations); } // Extract and validate the PROCESSORS section // If the PROCESSORS sections is already visited, then ignore if (!cffProcessors.ProcessorsSection.ValidSectionPair[1]) { Processors = cffProcessors.ExtractProcessors(line, validations); } // Extract and validate the PROCESSOR-TYPES section // If the PROCESSOR-TYPES sections is already visited, then ignore if (!cffProcessorTypes.ProcessorTypesSection.ValidSectionPair[1]) { ProcessorTypes = cffProcessorTypes.ExtractProcessorTypes(line, validations); } // Extract and validate the LOCAL-COMMUNICATION section // If the LOCAL-COMMUNICATION sections is already visited, then ignore if (!cffLocalCommunication.LocalCommunicationSection.ValidSectionPair[1]) { LocalCommunicationInfo = cffLocalCommunication.ExtractLocalCommunication(line, Program.Tasks, validations); } // Extract and validate the REMOTE-COMMUNICATION section // If the REMOTE-COMMUNICATION sections is already visited, then ignore if (!cffRemoteCommunication.RemoteCommunicationSection.ValidSectionPair[1]) { RemoteCommunicationInfo = cffRemoteCommunication.ExtractRemoteCommunication(line, Program.Tasks, validations); } lineNumber++; } streamReader.Close(); // Assign the corresponding Processor Type object to Processor AssignProcessType(); // Console.WriteLine(RemoteCommunicationInfo); // Check whether the LOGFILE section exists cffLogFile.LogFileSection.CheckValidPair(validations, cffFilename); // Check whether the LIMITS section exists cffLimits.LimitPairSection.CheckValidPair(validations, cffFilename); // Check whether the PROGRAM section exists cffProgram.ProgramPairSection.CheckValidPair(validations, cffFilename); // Check whether the TASKS section exists cffTasks.TasksSection.CheckValidPair(validations, cffFilename); // Check whether the PROCCESORS section exists cffProcessors.ProcessorsSection.CheckValidPair(validations, cffFilename); // Check whether the PROCESSOR-TYPES section exists cffProcessorTypes.ProcessorTypesSection.CheckValidPair(validations, cffFilename); // Check whether the LOCAL-COMMUNICATION section exists cffLocalCommunication.LocalCommunicationSection.CheckValidPair(validations, cffFilename); // Check whether the REMOTE-COMMUNICATION section exists cffRemoteCommunication.RemoteCommunicationSection.CheckValidPair(validations, cffFilename); // Check whether the log file has been assigned a value or not validations.CheckProcessedFileExists(LogFilename, EXPECTED_LOGFILE_FORMAT); // Check whether the Limits object has all valid property values cffLimits.ValidateLimitData(validations); // Check whether the Program object has all valid property values cffProgram.ValidateProgramData(validations); // Check whether the number of tasks extracted is equal to the required number validations.CheckValidQuantity( cffTasks.TaskPair.CalculateNumOfPair().ToString(), cffProgram.Program.Tasks.ToString(), CffKeywords.OPENING_TASKS, ErrorCode.MISSING_SECTION); // Check whether the number of processors extracted is equal to the required number validations.CheckValidQuantity( cffProcessors.ProcessorPair.CalculateNumOfPair().ToString(), cffProgram.Program.Processors.ToString(), CffKeywords.OPENING_PROCESSORS, ErrorCode.MISSING_SECTION); // Check whether the processor type of each processor is missing CheckMissingProcessorType(validations); // Check whether the local communication is missing cffLocalCommunication.ValidateLocalCommunication(validations); // Check whether the remote communication is missing cffRemoteCommunication.ValidateRemoteCommunication(validations); // Configuration values must be within their corresponding limit ValidateConfigurationValues(validations); afterNumOfError = validations.ErrorValidationManager.Errors.Count; return(beforeNumOfError == afterNumOfError); }
public static void ExecuteMatch(object state) { var queues = CacheSet.PVPMathcQueueCache.FindAll(); PlayerSinglePvpLogic psp = new PlayerSinglePvpLogic(); foreach (var queue in queues) { if (queue.InQueueGroups.Count <= 1) { continue; } if (queue.MatchedGroupCount > 0) { ClearMatchedGroups(queue); } var groups = new List <PVPGroup>(); groups.AddRange(queue.InQueueGroups); groups.Sort(); for (int i = 0; i < groups.Count; i++) { if (i + 1 >= groups.Count) { break; } bool success = true; LRCreateNewRoom userData = new LRCreateNewRoom(); foreach (int playerId in groups[i].Players) { if (!GameSession.Get(playerId).Connected) { queue.InQueueGroups.RemoveAt(i); success = false; break; } PBRoomPlayerInfo playerRoomData = GetPlayerRoomData(playerId); userData.RoomPlayerInfo.Add(playerRoomData); } if (!success) { continue; } foreach (int playerId in groups[++i].Players) { if (!GameSession.Get(playerId).Connected) { queue.InQueueGroups.RemoveAt(i); success = false; break; } PBRoomPlayerInfo playerRoomData = GetPlayerRoomData(playerId); userData.RoomPlayerInfo.Add(playerRoomData); } if (!success) { continue; } userData.Token = GetToken(); var room = RoomServerManager.GetLowestLoadedRoomServer(); TraceLog.Write("room" + room.Id.ToString() + "::" + room.IP); RoomServerSender.Send(room.Id, "LRCreateNewRoomHandler", userData, delegate(RemotePackage callback) { var res = RemoteCommunication.ParseRemotePackage <RLCreateNewRoom>(callback.Message as byte[]); LCPushPvpMatchSuccess package = new LCPushPvpMatchSuccess() { RoomId = res.RoomId, RoomServerHost = room.Host, RoomServerPort = room.Port, Token = userData.Token, InstanceId = res.InstanceId }; var rank = RankingFactory.Get <SinglePvpRankUser>("SinglePvpRanking"); foreach (int playerId in groups[queue.MatchedGroupCount].Players) { foreach (var rp in userData.RoomPlayerInfo) { if (rp.PlayerInfo.Id != playerId) { package.EnemyInfo = rp; } } byte[] buffer = CustomActionDispatcher.GeneratePackageStream(package.PacketActionId, ProtoBufUtils.Serialize(package)); try { GameSession.Get(playerId).SendAsync(buffer, 0, buffer.Length); } catch { continue; } } foreach (int playerId in groups[queue.MatchedGroupCount + 1].Players) { foreach (var rp in userData.RoomPlayerInfo) { if (rp.PlayerInfo.Id != playerId) { package.EnemyInfo = rp; } } byte[] buffer = CustomActionDispatcher.GeneratePackageStream(package.PacketActionId, ProtoBufUtils.Serialize(package)); try { GameSession.Get(playerId).SendAsync(buffer, 0, buffer.Length); } catch { continue; } } queue.MatchedGroupCount += 2; }); } ClearMatchedGroups(queue); } }