/// <summary> /// Tries to connect to every single configured server. /// If one of them fails the Server will remove them from the list /// so the client will not see It upon authorization. /// </summary> private void ValidateServers() { Logger.Log("Validating configured servers... Please stand by."); List <string> invalidservers = new List <string>(SquadServerLoader.AllServers.Values.Count); foreach (var x in SquadServerLoader.AllServers.Values) { RconServerConnector connector = new RconServerConnector(); ServerConnectionInfo info = new ServerConnectionInfo(x.DomainIPContainer.IP, x.RconPort, x.QueryPort, x.RconPassword); if (!connector.Connect(info)) { invalidservers.Add(x.ServerNickName); Logger.Log("[ServerValidation] " + x.ServerNickName + " is invalid. Unable to connect, removing."); } else { Logger.Log("[ServerValidation] " + x.ServerNickName + " is valid. Connection established."); ValidServers[x.ServerNickName] = connector; } } foreach (var x in invalidservers.Where(x => SquadServerLoader.AllServers.ContainsKey(x))) { SquadServerLoader.AllServers.Remove(x); } }
static void Main(string[] args) { Server_MessageHandler handler = new Server_MessageHandler(); ILogger logger = new ConsoleLogger(); ServerCore serverCore = new ServerCore(handler, ServerConnectionInfo.MatchMakerConnectionInfo(), logger); MatchMakerCore matchMaker = new MatchMakerCore(serverCore, logger, serverCore.messageSender); handler.Setup(serverCore, matchMaker); int tickrate = 33; int secondToWait = 1000 / tickrate; Console.WriteLine("Server started!"); var DBThread = new DBThread(logger); Thread matchThread = new Thread(new ThreadStart(DBThread.ThreadStart)); matchThread.Start(); while (true) { serverCore.Update(); matchMaker.Update(); System.Threading.Thread.Sleep(secondToWait); } }
/// <summary> /// Creates a reciever /// On creation it will start listening /// </summary> /// <param name="clientManager">The manager of the clients connected</param> /// <param name="connectionInfo">Information used to determine ip and port</param> public Server_Connection(Server_ClientManager clientManager, ServerConnectionInfo connectionInfo) { this.clientManager = clientManager; this.connectionInfo = connectionInfo; StartsListening(); }
private bool CreateDb() { if (string.IsNullOrEmpty(_couchDbSettings.Username) || string.IsNullOrEmpty(_couchDbSettings.Password)) { throw new CouchDbSetupException( "Please add the admin username and password for the database to the CouchDbSettings in appsettings.json [DONT CHECK IT IN!!!]"); } var connectionInfo = new ServerConnectionInfo(_couchDbSettings.Server) { BasicAuth = new BasicAuthString(_couchDbSettings.Username, _couchDbSettings.Password) }; using (var client = new MyCouchServerClient(connectionInfo)) { var databaseInfo = client.Databases.HeadAsync(_couchDbSettings.DatabaseName).Result; if (databaseInfo.IsSuccess) { return(false); } var createResult = client.Databases.PutAsync(_couchDbSettings.DatabaseName).Result; if (!createResult.IsSuccess) { throw new CouchDbSetupException( $"unable to create database: {_couchDbSettings.DatabaseName} reason: {createResult.Reason}"); } return(true); } }
/// <summary> /// Connects to the game server with the given <see cref="ServerConnectionInfo"/>. /// This should be called from the main Unity thread. /// </summary> /// <param name="connectArgs"></param> public void Connect(ServerConnectionInfo connectArgs) { if (IsConnecting || IsConnected) { Debug.Log("Connect in SyncClient"); Debug.Log($"IsConnecting: {IsConnecting}"); Debug.Log($"IsConnected: {IsConnected}"); return; } this.connectArgs = connectArgs; InitializeFields(); ReadTimeoutMs = 5000; DidTimeOut = false; SocketForceClosed = false; IsConnecting = true; IsReconnecting = false; Debug.Log("Starting connection attempts..."); AttemptConnect(true); }
public void When_injected_with_connection_info_with_https_It_extracts_values_properly() { var cnInfo = new ServerConnectionInfo(new Uri("https://foo:5555")); SUT = new ServerConnection(cnInfo); SUT.Address.Should().Be(new Uri("https://foo:5555")); }
public ServerCore(IMessageHandler messageHandler, ServerConnectionInfo connectionInfo, ILogger logger, IServerEventHandler eventHandler = null) { gameInfo = new Server_GameInfo(); clientManager = new Server_ClientManager(this); this.connectionInfo = connectionInfo; this.messageHandler = messageHandler; connection = new Server_Connection(clientManager, connectionInfo); messageReciever = new Server_MessageReciever(connection, messageHandler); messageSender = new Server_MessageSender(clientManager, logger); this.eventHandler = eventHandler == null ? eventHandler = new ServerCoreShellHandler() : this.eventHandler = eventHandler; }
public bool Connect(ServerConnectionInfo serverInfo, Player player, int protocolVersion, ForgeInfo forgeInfo, IMinecraftComHandler minecraftComHandler) { client = ProxyHandler.startNewTcpClient(serverInfo.ServerIP, serverInfo.ServerPort); //client.Connect(serverInfo.ServerIP, serverInfo.ServerPort); client.ReceiveBufferSize = 1024 * 1024; communicationHandler = ProtocolHandler.GetProtocolHandler(client, protocolVersion, forgeInfo, minecraftComHandler, player); return(login()); //send login packets }
private void LibraryList_Tap(object sender, System.Windows.Input.GestureEventArgs e) { ServerConnectionInfo info = LibraryList.SelectedItem as ServerConnectionInfo; if (info == null) { return; } ServerManager.ChooseServer(info); NavigationManager.GoToFirstPage(); }
public void When_injected_with_connection_info_with_timeout_It_extracts_value_properly() { var expectedTimeout = TimeSpan.FromSeconds(13); var cnInfo = new ServerConnectionInfo(new Uri("https://foo:5555")) { Timeout = expectedTimeout }; SUT = new ServerConnection(cnInfo); SUT.Timeout.Should().Be(expectedTimeout); }
private void DeleteMenuItem_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = (MenuItem)sender; ServerConnectionInfo info = menuItem.Tag as ServerConnectionInfo; if (info == null) { return; } ServerManager.RemoveServerInfo(info); }
public MyCouchCloudantServerClient(ServerConnectionInfo connectionInfo, MyCouchCloudantClientBootstrapper bootstrapper = null) { Ensure.That(connectionInfo, "connectionInfo").IsNotNull(); IsDisposed = false; bootstrapper = bootstrapper ?? MyCouchCloudantClientBootstrappers.Default; Connection = bootstrapper.ServerConnectionFn(connectionInfo); Serializer = bootstrapper.SerializerFn(); Databases = bootstrapper.DatabasesFn(Connection); Replicator = bootstrapper.ReplicatorFn(Connection); Security = bootstrapper.SecurityFn(Connection); }
internal static IMyCouchServerClient CreateServerClient() { var config = Environment; var connectionInfo = new ServerConnectionInfo(config.ServerUrl) { BasicAuth = new BasicAuthString(Config.GetUsername(), Config.GetPassword()) }; return(new MyCouchServerClient(connectionInfo, new MyCouchClientBootstrapper { ServerConnectionFn = cnInfo => new CustomServerConnection(cnInfo) })); }
public MyCouchCloudantServerClient(ServerConnectionInfo connectionInfo, MyCouchCloudantClientBootstrapper bootstrapper = null) { Ensure.That(connectionInfo, "connectionInfo").IsNotNull(); IsDisposed = false; bootstrapper = bootstrapper ?? MyCouchCloudantClientBootstrappers.Default; Connection = bootstrapper.ServerConnectionFn(connectionInfo); Serializer = bootstrapper.SerializerFn(); Databases = bootstrapper.DatabasesFn(Connection); Replicator = bootstrapper.ReplicatorFn(Connection); Security = bootstrapper.SecurityFn(Connection); }
public AgentServer Listen(ServerConnectionInfo info = null) { if (this.info == null && info != null) this.info = info; if (this.info == null) throw new InvalidConnectionInfoException("Please supply a connection info object."); InstanceRegistry.Publish(this.info); this.info.State = ServerStateType.Listening; server = ServerFactory.Create(this.info.ToServerUrl()); return this; }
/// <summary> /// Only call this method on an another thread /// Starts the thread running the match /// </summary> public void ThreadStart() { var DBHandler = new DBMessageHandler(logger, this); server = new ServerCore(DBHandler, ServerConnectionInfo.DBConnectionInfo(), logger); DBHandler.Init(server); logger.Log("Database setup and running"); while (true) { server.Update(); System.Threading.Thread.Sleep(miliSecondPerTick); } }
internal static IMyCouchServerClient CreateServerClient() { var config = Environment; var connectionInfo = new ServerConnectionInfo(config.ServerUrl); if (config.HasCredentials()) { connectionInfo.BasicAuth = new BasicAuthString(config.User, config.Password); } return(new MyCouchServerClient(connectionInfo, new MyCouchClientBootstrapper { ServerConnectionFn = cnInfo => new CustomServerConnection(cnInfo) })); }
public IActionResult TestServerBind([FromBody] ServerConnectionInfo body) { var configuration = LdapPlugin.Instance.Configuration; configuration.LdapServer = body.LdapServer; configuration.LdapPort = body.LdapPort; configuration.UseSsl = body.UseSsl; configuration.UseStartTls = body.UseStartTls; configuration.SkipSslVerify = body.SkipSslVerify; configuration.LdapBindUser = body.LdapBindUser; configuration.LdapBindPassword = body.LdapBindPassword; configuration.LdapBaseDn = body.LdapBaseDn; LdapPlugin.Instance.UpdateConfiguration(configuration); return(Ok(_ldapAuthenticationProvider.TestServerBind())); }
private static async void HttpServer_RequestReceived(object sender, HttpRequestEventArgs e) { if (sender != _httpServer) { return; } if (IsValidPairingRequest(e.Request)) { string servicename = e.Request.QueryString["servicename"]; _log.Info("Paired with service ID: " + servicename); // Stop HTTP server and Bonjour publisher Stop(); // Generate new pairing code ulong pairingCode = GetRandomUInt64(); // Build response List <byte> bodyBytes = new List <byte>(); bodyBytes.AddRange(GetDACPFormattedBytes("cmpg", pairingCode)); bodyBytes.AddRange(GetDACPFormattedBytes("cmnm", DeviceName)); bodyBytes.AddRange(GetDACPFormattedBytes("cmty", "iPhone")); byte[] responseBytes = GetDACPFormattedBytes("cmpa", bodyBytes.ToArray()); // Send response HttpResponse response = new HttpResponse(); response.Body.Write(responseBytes, 0, responseBytes.Length); await e.Request.SendResponse(response); // Save server connection info ServerConnectionInfo info = new ServerConnectionInfo(); info.ServiceID = servicename; info.PairingCode = pairingCode.ToString("X16"); ServerManager.AddServerInfo(info); PairingComplete.Raise(null, new ServerConnectionInfoEventArgs(info)); } else { await e.Request.SendResponse(HttpStatusCode.NotFound, string.Empty); } }
internal static IMyCouchServerClient CreateServerClient() { var config = Environment; var connectionInfo = new ServerConnectionInfo(config.ServerUrl); if (config.HasCredentials()) connectionInfo.BasicAuth = new BasicAuthString(config.User, config.Password); if (config.IsAgainstCloudant()) { var bootstrapper = new MyCouchCloudantClientBootstrapper { ServerConnectionFn = cnInfo => new CustomCloudantServerConnection(cnInfo) }; return new MyCouchCloudantServerClient(connectionInfo, bootstrapper); } return new MyCouchServerClient(connectionInfo); }
public CustomCloudantServerConnection(ServerConnectionInfo connectionInfo) : base(connectionInfo) { }
public bool Connect(ServerConnectionInfo connectionInfo) { this.serverConnectionInfo = connectionInfo; this.squadServer = ServerQuery.GetServerInstance(EngineType.Source, new IPEndPoint(this.serverConnectionInfo.ServerIP, this.serverConnectionInfo.ServerPort)); return(this.squadServer.GetControl(this.serverConnectionInfo.Password)); }
public AgentServer Create() { var serverInfo = new ServerConnectionInfo(ipAddress, port); return new AgentServer(serverInfo); }
public AgentServer(ServerConnectionInfo info = null) { this.info = info; servers.Add(info); }
private static void HandleServerList(XElement node) { ServerConnectionInfoCollection servers = new ServerConnectionInfoCollection(); var serverNodes = node.Descendants().Where(n => n.Name.LocalName == "DACPServerInfo"); foreach (var serverNode in serverNodes) { ServerConnectionInfo info = new ServerConnectionInfo(); Guid id = Guid.Empty; var serverNodeDataNodes = serverNode.Descendants(); foreach (var serverNodeDataNode in serverNodeDataNodes) { var key = serverNodeDataNode.Name.LocalName; var value = serverNodeDataNode.Value; switch (key) { case "ID": id = Guid.Parse(value); break; case "ServiceID": info.ServiceID = value; break; case "HostName": // Look for a specified port int port = 3689; string[] hostParts = value.Split(':'); if (hostParts.Length > 1) { port = int.Parse(hostParts[1]); } info.LastPort = port; // Determine whether this is an IP address or a hostname IPAddress ip; if (IPAddress.TryParse(hostParts[0], out ip)) { info.LastIPAddress = ip.ToString(); } info.LastHostname = hostParts[0]; break; case "LibraryName": info.Name = value; break; case "PIN": int pin = int.Parse(value); info.PairingCode = string.Format("{0:0000}{0:0000}{0:0000}{0:0000}", pin); break; } } // Check to see whether we have all the necessary parts if (string.IsNullOrEmpty(info.ServiceID) || string.IsNullOrEmpty(info.LastHostname) || string.IsNullOrEmpty(info.PairingCode)) { continue; } // Store the old GUID for later _discoveredServerIDs[id] = info.ServiceID; // Make sure we don't have any duplicates var oldInfo = servers.FirstOrDefault(s => s.ServiceID == info.ServiceID); if (oldInfo != null) { servers.Remove(oldInfo); } // Add the server to the list servers.Add(info); } if (servers.Count > 0) { XmlSerializer xml = new XmlSerializer(typeof(ServerConnectionInfoCollection)); string serversXML = xml.SerializeToString(servers); SaveValue("PairedServerList", serversXML); } }
public CustomCloudantServerConnection(ServerConnectionInfo connectionInfo) : base(connectionInfo) { }
private async void HandleServerConnection(Task <ConnectionResult> task) { var result = await task; switch (result) { case ConnectionResult.Success: _log.Info("Successfully connected to server at {0}:{1}", _server.Hostname, _server.Port); // Notify the pairing utility so it can close if (_currentUtility != null) { _currentUtility.SendPairedNotification(_server.PairingCode); } // Save the server connection info ServerConnectionInfo info = new ServerConnectionInfo(); info.Name = _server.LibraryName; info.ServiceID = _libraryService.Name; info.PairingCode = _server.PairingCode; info.LastHostname = _libraryService.Hostname; info.LastIPAddress = _server.Hostname; info.LastPort = _server.Port; _server = null; ServerManager.AddServerInfo(info); ServerManager.ChooseServer(info); Hide(); NavigationManager.GoToFirstPage(); break; case ConnectionResult.InvalidPIN: MessageBox.Show(LocalizedStrings.LibraryPINErrorBody, LocalizedStrings.LibraryPINErrorTitle, MessageBoxButton.OK); _server = null; UpdateWizardItem(true); break; case ConnectionResult.ConnectionError: // Check whether there are any other IP addresses we could try var ipStrings = _libraryService.IPAddresses.Select(ip => ip.ToString()).ToList(); var ipIndex = ipStrings.IndexOf(_server.Hostname); if (ipIndex >= 0 && ipIndex < (ipStrings.Count - 1)) { ipIndex++; string nextIP = ipStrings[ipIndex]; _server.Hostname = nextIP; _server.Port = _libraryService.Port; _log.Info("Retrying connection on new IP: {0}:{1}", _server.Hostname, _server.Port); HandleServerConnection(_server.ConnectAsync()); return; } // No other IPs, so we can't do anything else // TODO: Display error _server = null; UpdateWizardItem(true); break; } }
protected async void ConnectToServer() { if (_server != null) { return; } if (!HasValidData()) { return; } string host; int port; ParseHostname(out host, out port); string pairingCode = string.Format("{0:0000}{0:0000}{0:0000}{0:0000}", pinTextBox.IntValue.Value); try { _server = new DACPServer(host, port, pairingCode); } catch { MessageBox.Show(LocalizedStrings.LibraryConnectionErrorBody, LocalizedStrings.LibraryConnectionErrorTitle, MessageBoxButton.OK); _server = null; UpdateWizardItem(true); return; } UpdateWizardItem(true); var result = await _server.ConnectAsync(); switch (result) { case ConnectionResult.Success: // Save the server connection info ServerConnectionInfo info = new ServerConnectionInfo(); info.Name = _server.LibraryName; info.PairingCode = _server.PairingCode; info.LastHostname = _server.Hostname; info.LastIPAddress = _server.Hostname; info.LastPort = _server.Port; // Get the service ID for Bonjour // In iTunes 10.1 and later, the service name comes from ServiceID (parameter aeIM). // In foo_touchremote the service name is the same as the database ID (parameter mper). // In MonkeyTunes, the service ID is not available from the database query. TODO. if (_server.MainDatabase.ServiceID > 0) { info.ServiceID = _server.MainDatabase.ServiceID.ToString("x16").ToUpper(); } else { info.ServiceID = _server.MainDatabase.PersistentID.ToString("x16").ToUpper(); } ServerManager.AddServerInfo(info); ServerManager.ChooseServer(info); Hide(); NavigationManager.GoToFirstPage(); break; case ConnectionResult.InvalidPIN: MessageBox.Show(LocalizedStrings.LibraryPINErrorBody, LocalizedStrings.LibraryPINErrorTitle, MessageBoxButton.OK); _server = null; UpdateWizardItem(true); break; case ConnectionResult.ConnectionError: MessageBox.Show(LocalizedStrings.LibraryConnectionErrorBody, LocalizedStrings.LibraryConnectionErrorTitle, MessageBoxButton.OK); _server = null; UpdateWizardItem(true); break; } }
public CustomServerConnection(ServerConnectionInfo connectionInfo) : base(connectionInfo) { }
public ServerConnection(ServerConnectionInfo connectionInfo) : base(connectionInfo) { }