private static async Task <ArgumentHandleResult> ProcessRaceOnlineJoin(NameValueCollection p) { // Required arguments var ip = p.Get(@"ip"); var httpPort = FlexibleParser.TryParseInt(p.Get(@"httpPort")); var password = p.Get(@"plainPassword"); var encryptedPassword = p.Get(@"password"); if (string.IsNullOrWhiteSpace(ip)) { throw new InformativeException("IP is missing"); } if (!httpPort.HasValue) { throw new InformativeException("HTTP port is missing or is in invalid format"); } if (string.IsNullOrWhiteSpace(password) && !string.IsNullOrWhiteSpace(encryptedPassword)) { password = OnlineServer.DecryptSharedPassword(ip, httpPort.Value, encryptedPassword); } await JoinInvitation(ip, httpPort.Value, password); return(ArgumentHandleResult.Successful); }
protected override void Handle(TcpRequest <ServerInfo> request) { var onlineServer = new OnlineServer(request.Message, request.ConnectedClient); var id = new PolychatServerIdString(request.Message.ServerId); var sanitisedId = id.ToSanitisedUppercase(); _logger.LogInformation("Adding server {id} to the list of online servers...", sanitisedId); _polychatService.AddOrUpdateOnlineServer(sanitisedId, onlineServer); _logger.LogInformation("Added server {id} to the list of online servers.", sanitisedId); }
/// <inheritdoc /> public async ValueTask SendMessage(OnlineServer destinationServer, byte[] packedMsgBytes) { try { // if this bit of code ever goes t**s up with a NullReferenceException, please send an email to // [email protected] as he has personally assured me that ConnectedClient // can't be null (Discord message ID: 818759362839183360); await destinationServer.ConnectedClient !.SendMessage(packedMsgBytes); } catch (Exception e) { _logger.LogError($"Failed to send a message to server with {destinationServer.ServerId}", e); } }
static void Main(string[] args) { //TODO: Update argument checking to allow for extensible argument parameters if (args.Length > 0 && args[0] == "-server") { Server server = new OnlineServer(); server.Run(); } else { using (var game = new KappaGame()) game.Run(); } }
private static async Task <ArgumentHandleResult> ProcessRaceOnline(NameValueCollection p) { // Required arguments var ip = p.Get(@"ip"); var port = FlexibleParser.TryParseInt(p.Get(@"port")); var httpPort = FlexibleParser.TryParseInt(p.Get(@"httpPort")); var carId = p.Get(@"car"); // Optional arguments var allowWithoutSteamId = p.GetFlag("allowWithoutSteamId"); var carSkinId = p.Get(@"skin"); var trackId = p.Get(@"track"); var name = p.Get(@"name"); var nationality = p.Get(@"nationality"); var password = p.Get(@"plainPassword"); var encryptedPassword = p.Get(@"password"); if (string.IsNullOrWhiteSpace(ip)) { throw new InformativeException("IP is missing"); } if (!port.HasValue) { throw new InformativeException("Port is missing or is in invalid format"); } if (!httpPort.HasValue) { throw new InformativeException("HTTP port is missing or is in invalid format"); } if (string.IsNullOrWhiteSpace(password) && !string.IsNullOrWhiteSpace(encryptedPassword)) { password = OnlineServer.DecryptSharedPassword(ip, httpPort.Value, encryptedPassword); } if (string.IsNullOrWhiteSpace(carId)) { throw new InformativeException("Car ID is missing"); } var car = CarsManager.Instance.GetById(carId); if (car == null) { throw new InformativeException("Car is missing"); } if (!string.IsNullOrWhiteSpace(carSkinId) && car.GetSkinById(carSkinId) == null) { throw new InformativeException("Car skin is missing"); } var track = string.IsNullOrWhiteSpace(trackId) ? null : TracksManager.Instance.GetLayoutByKunosId(trackId); if (!string.IsNullOrWhiteSpace(trackId) && track == null) { throw new InformativeException("Track is missing"); } if (!SteamIdHelper.Instance.IsReady && !allowWithoutSteamId) { throw new InformativeException(ToolsStrings.Common_SteamIdIsMissing); } await GameWrapper.StartAsync(new Game.StartProperties { BasicProperties = new Game.BasicProperties { CarId = carId, TrackId = track?.MainTrackObject.Id ?? @"imola", TrackConfigurationId = track?.LayoutId, CarSkinId = carSkinId, DriverName = name, DriverNationality = nationality }, ModeProperties = new Game.OnlineProperties { Guid = SteamIdHelper.Instance.Value, ServerIp = ip, ServerPort = port.Value, ServerHttpPort = httpPort.Value, Password = password, RequestedCar = carId } }); return(ArgumentHandleResult.Successful); }
public static async Task JoinInvitation([NotNull] string ip, int port, [CanBeNull] string password) { OnlineManager.EnsureInitialized(); var list = OnlineManager.Instance.List; var source = new FakeSource(ip, port); var wrapper = new OnlineSourceWrapper(list, source); ServerEntry server; using (var waiting = new WaitingDialog()) { waiting.Report(ControlsStrings.Common_Loading); await wrapper.EnsureLoadedAsync(); server = list.GetByIdOrDefault(source.Id); if (server == null) { throw new Exception(@"Unexpected"); } } if (password != null) { server.Password = password; } var content = new OnlineServer(server) { Margin = new Thickness(0, 0, 0, -38), ToolBar = { FitWidth = true }, // Values taken from ModernDialog.xaml // TODO: Extract them to some style? Title = { FontSize = 24, FontWeight = FontWeights.Light, Margin = new Thickness(6, 0, 0, 8) } }; content.Title.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Ideal); var dlg = new ModernDialog { ShowTitle = false, Content = content, MinHeight = 400, MinWidth = 450, MaxHeight = 99999, MaxWidth = 700, Padding = new Thickness(0), ButtonsMargin = new Thickness(8), SizeToContent = SizeToContent.Manual, ResizeMode = ResizeMode.CanResizeWithGrip, LocationAndSizeKey = @".OnlineServerDialog" }; dlg.SetBinding(Window.TitleProperty, new Binding { Path = new PropertyPath(nameof(server.DisplayName)), Source = server }); dlg.ShowDialog(); await wrapper.ReloadAsync(true); }
public record Command(OnlineServer ServerToNotify, TimeSpan TimeUntilRestart) : IRequest <Result>;
/// <inheritdoc /> public async ValueTask SendMessage <T>(OnlineServer destinationServer, T message) where T : IMessage <T> => await SendMessage(destinationServer, Any.Pack(message).ToByteArray());
/// <inheritdoc /> public async ValueTask SendMessage(OnlineServer destinationServer, Any message) => await SendMessage(destinationServer, message.ToByteArray());
/// <inheritdoc /> public OnlineServer AddOrUpdateOnlineServer(string id, OnlineServer onlineServer) => _onlineServers.AddOrUpdate(id, onlineServer, (_, _) => onlineServer);
public async Task <ArgumentHandleResult> ProgressRaceOnlineJoin(NameValueCollection p) { /* required arguments */ var ip = p.Get(@"ip"); var httpPort = FlexibleParser.TryParseInt(p.Get(@"httpPort")); var password = p.Get(@"plainPassword"); var encryptedPassword = p.Get(@"password"); if (string.IsNullOrWhiteSpace(ip)) { throw new InformativeException("IP is missing"); } if (!httpPort.HasValue) { throw new InformativeException("HTTP port is missing or is in invalid format"); } OnlineManager.EnsureInitialized(); if (string.IsNullOrWhiteSpace(password) && !string.IsNullOrWhiteSpace(encryptedPassword)) { password = OnlineServer.DecryptSharedPassword(ip, httpPort.Value, encryptedPassword); } var list = OnlineManager.Instance.List; var source = new FakeSource(ip, httpPort.Value); var wrapper = new OnlineSourceWrapper(list, source); ServerEntry server; using (var waiting = new WaitingDialog()) { waiting.Report(ControlsStrings.Common_Loading); await wrapper.EnsureLoadedAsync(); server = list.GetByIdOrDefault(source.Id); if (server == null) { throw new Exception(@"Unexpected"); } } if (password != null) { server.Password = password; } var content = new OnlineServer(server) { Margin = new Thickness(0, 0, 0, -43), ToolBar = { FitWidth = true }, // Values taken from ModernDialog.xaml // TODO: Extract them to some style? Title = { FontSize = 24, FontWeight = FontWeights.Light, Margin = new Thickness(6, 0, 0, 8) } }; content.Title.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Ideal); var dlg = new ModernDialog { ShowTitle = false, Content = content, MinHeight = 400, MinWidth = 450, MaxHeight = 99999, MaxWidth = 700, Padding = new Thickness(0), ButtonsMargin = new Thickness(8), SizeToContent = SizeToContent.Manual, ResizeMode = ResizeMode.CanResizeWithGrip, LocationAndSizeKey = @".OnlineServerDialog" }; dlg.SetBinding(Window.TitleProperty, new Binding { Path = new PropertyPath(nameof(server.DisplayName)), Source = server }); dlg.ShowDialog(); await wrapper.ReloadAsync(true); return(ArgumentHandleResult.Successful); }