public NetworkRunner(CvarcClient client) { this.client = client; factory = new SoloNetworkControllerFactory(client); var configProposal = client.Read<ConfigurationProposal>(); var loadingData = configProposal.LoadingData; var competitions = Dispatcher.Loader.GetCompetitions(loadingData); var settings = competitions.Logic.CreateDefaultSettings(); if (configProposal.SettingsProposal != null) configProposal.SettingsProposal.Push(settings, true); configuration = new Configuration { LoadingData = loadingData, Settings = settings }; //configuration.Settings.EnableLog = true; //configuration.Settings.LogFile = UnityConstants.LogFolderRoot + "cvarclog1"; var worldSettingsType = competitions.Logic.WorldStateType; worldState = (IWorldState)client.Read(worldSettingsType); Name = loadingData.AssemblyName + loadingData.Level; CanInterrupt = true; CanStart = true; }
public override IController Create(string controllerId, IActor actor) { // if bot is assigned for controller, get it var settings = GetSettings(controllerId); if (settings.Type == ControllerType.Bot) return CreateBot(controllerId); // running process var process = new Process(); var directory = "Solutions\\" + settings.Name ; if (!Directory.Exists(directory)) throw new Exception("Directory "+directory+" for robot "+controllerId+" is not found"); var batFile = directory+"\\run.bat"; if (!File.Exists(batFile)) throw new Exception("run.bat is not found in directory "+directory+" for robot "+controllerId); process.StartInfo.FileName = "run.bat"; process.StartInfo.WorkingDirectory = directory; process.StartInfo.Arguments = Port.ToString(); process.Start(); //waiting for incoming connection var watch = new Stopwatch(); watch.Start(); while(!listener.Pending()) { if (watch.ElapsedMilliseconds>1000) { watch.Stop(); if (!process.HasExited) process.Kill(); throw new Exception("Process " + batFile + " for controller " + controllerId + " haven't established connection for "+timeToEstablishConnection+" millisecond"); } } watch.Stop(); processes.Add(process); var socketClient = listener.AcceptTcpClient(); var client = new CvarcClient(socketClient); clients.Add(client); // skipping config so the client's protocol won't change from SoloNetwork mode client.Read<ConfigurationProposal>(); client.Read(World.Competitions.Logic.WorldStateType); var controller = World.Competitions.Logic.Actors[controllerId].CreateNetworkController(); controller.InitializeClient(client); return controller; }
protected override void HandleClient(CvarcClient client) { var configProposal = client.Read<ConfigurationProposal>(); var loadingData = configProposal.LoadingData; //RoboMoviesLevel1 var competitions = Dispatcher.Loader.GetCompetitions(loadingData); var worldSettingsType = competitions.Logic.WorldStateType; var worldState = (IWorldState)client.Read(worldSettingsType); var settings = competitions.Logic.CreateDefaultSettings(); // таким образом игнорируются все настйроки пользователя сейчас. var configuration = new Configuration { LoadingData = loadingData, Settings = settings }; TournamentPool.AddPlayerToPool(client, configuration, worldState, configProposal); }
public static void AddPlayerToPool(CvarcClient client) { var configProposal = client.Read<ConfigurationProposal>(); var loadingData = configProposal.LoadingData; var competitions = Dispatcher.Loader.GetCompetitions(loadingData); var worldSettingsType = competitions.Logic.WorldStateType; var worldState = (IWorldState)client.Read(worldSettingsType); lock (pool) { if (!pool.ContainsKey(loadingData)) { pool.Add(loadingData, new TournamentRunner(loadingData, worldState)); Dispatcher.AddRunner(pool[loadingData]); } if (pool[loadingData].AddPlayerAndCheck(new TournamentPlayer(client, configProposal, worldState))) pool.Remove(loadingData); } }
protected override void HandleClient(CvarcClient client) { var configProposal = client.Read<ConfigurationProposal>(); var loadingData = configProposal.LoadingData; //RoboMoviesLevel1 var competitions = Dispatcher.Loader.GetCompetitions(loadingData); var worldSettingsType = competitions.Logic.WorldStateType; var worldState = (IWorldState)client.Read(worldSettingsType); var settings = competitions.Logic.CreateDefaultSettings(); if (configProposal.SettingsProposal != null) configProposal.SettingsProposal.Push(settings, true); var configuration = new Configuration { LoadingData = loadingData, Settings = settings }; TournamentPool.AddForceGame(worldState, configuration); client.Close(); }