private async Task processBotRequest() { string requestPath = Constants.SERVER_PATH + Constants.GAME_JOIN_PATH; try { dynamic values = new JObject(); values.username = SelectedBot; values.Add("isPrivate", false); values.lobbyName = this.LobbyName; values.password = ""; var content = JsonConvert.SerializeObject(values); var buffer = System.Text.Encoding.UTF8.GetBytes(content); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = await ServerService.instance.client.PostAsync(requestPath, byteContent); if (response.IsSuccessStatusCode) { Bots.Remove(SelectedBot); } if (!response.IsSuccessStatusCode) { var message = await response.Content.ReadAsStringAsync(); ErrorServerMessage serverMessage = JsonConvert.DeserializeObject <ErrorServerMessage>(message); ShowMessageBox(serverMessage.message); } } catch (Exception e) { ShowMessageBox(e.Message); } }
/// <summary> /// Removes the bot. /// </summary> /// <param name="file">The file.</param> private static void RemoveBot(string file) { try { Bots.Remove(Path.GetFileName(file)); } catch (Exception ex) { LogService.Warning(ex.ToString()); } }
public async Task UpdateBot(InventoryBot bot) { await _dao.UpdatePlayerBotAsync(bot); if (bot.RoomId != 0) { Bots.Remove(bot.Id); } else { if (!Bots.ContainsKey(bot.Id)) { Bots.Add(bot.Id, bot); } } }
private async void fetchUsername() { App.Current.Dispatcher.Invoke(delegate { Usernames.Clear(); }); ObservableCollection <UserLobby> usernames = new ObservableCollection <UserLobby>(); try { var response = await ServerService.instance.client.GetAsync(Constants.SERVER_PATH + Constants.USERS_LOBBY_PATH + LobbyName); if (response.IsSuccessStatusCode) { StreamReader streamReader = new StreamReader(await response.Content.ReadAsStreamAsync()); String responseData = streamReader.ReadToEnd(); var myData = JsonConvert.DeserializeObject <List <String> >(responseData); foreach (var item in myData) { App.Current.Dispatcher.Invoke(delegate { usernames.Add(new UserLobby(item, item == ServerService.instance.username)); if (Bots.Contains(item)) { Bots.Remove(item); } }); } Usernames = usernames; string firstUser = findFirstNotBot(Usernames); IsGameMaster = ServerService.instance.username == firstUser; } else if (!response.IsSuccessStatusCode) { var message = await response.Content.ReadAsStringAsync(); ErrorServerMessage serverMessage = JsonConvert.DeserializeObject <ErrorServerMessage>(message); ShowMessageBox(serverMessage.message); } } catch (Exception e) { ShowMessageBox(e.Message); } }
public void CmdHalt(int bid) { if (!Bots.TryGetValue(bid, out var bot)) { throw new CommandException("wait", "bot does not exist"); } if (bot.Position != Matrix.Get(0, 0, 0)) { throw new CommandException("halt", "bot not at 0,0,0"); } if (Bots.Count > 1) { throw new CommandException("halt", "more than one bot active"); } if (Harmonics) { throw new CommandException("halt", "tried to halt with high harmonics"); } Bots.Remove(bid); }
/// <summary> /// Removes all elements in scope from the instance. /// </summary> /// <param name="theTier">The tier to remove the elements from.</param> /// <param name="xMin">The min x-value of the scope.</param> /// <param name="xMax">The max x-value of the scope.</param> /// <param name="yMin">The min y-value of the scope.</param> /// <param name="yMax">The max y-value of the scope.</param> public void ModRemoveWaypoints(ITierInfo theTier, double xMin, double yMin, double xMax, double yMax) { Tier tier = theTier as Tier; // Remove waypoints List <Waypoint> remWaypoints = Waypoints.Where(w => w.Tier == tier && xMin <= w.X && w.X <= xMax && yMin <= w.Y && w.Y <= yMax).ToList(); // Remove all of them foreach (var waypoint in remWaypoints) { // Remove the waypoint - the waypoint graph handles all cascading path removals waypoint.Tier.RemoveWaypoint(waypoint); // Remove all elements that were connected to the waypoint foreach (var guard in Semaphores.SelectMany(s => s.Guards).Where(guard => guard.From == waypoint || guard.To == waypoint).ToArray()) { guard.Semaphore.UnregisterGuard(guard); if (guard.Semaphore.Guards.Count() == 0) { Semaphores.Remove(guard.Semaphore); } } foreach (var station in InputStations.Where(s => s.Waypoint == waypoint).ToArray()) { station.Tier.RemoveInputStation(station); InputStations.Remove(station); } foreach (var station in OutputStations.Where(s => s.Waypoint == waypoint).ToArray()) { station.Tier.RemoveOutputStation(station); OutputStations.Remove(station); } foreach (var pod in Pods.Where(p => p.Waypoint == waypoint).ToArray()) { pod.Tier.RemovePod(pod); Pods.Remove(pod); } foreach (var elevator in Elevators.Where(e => e.ConnectedPoints.Contains(waypoint))) { elevator.UnregisterPoint(waypoint); if (elevator.ConnectedPoints.Count == 0) { Elevators.Remove(elevator); } } // Make sure it is not on the list of storage locations anymore if (waypoint.PodStorageLocation) { ResourceManager.RemovePodStorageLocation(waypoint); } // Finally remove from the overall waypoint list Waypoints.Remove(waypoint); } // Also remove movables in scope List <Bot> remBots = Bots.Where(b => b.Tier == tier && xMin <= b.X && b.X <= xMax && yMin <= b.Y && b.Y <= yMax).ToList(); foreach (var bot in remBots) { Bots.Remove(bot); bot.Tier.RemoveBot(bot); } List <Pod> remPods = Pods.Where(p => p.Tier == tier && xMin <= p.X && p.X <= xMax && yMin <= p.Y && p.Y <= yMax).ToList(); foreach (var pod in remPods) { Pods.Remove(pod); pod.Tier.RemovePod(pod); } }