public static async Task <string> CreateWebServerAsync(string remoteUrl, string baseAddress, CancellationToken ct) { Uri remoteUri = new Uri(remoteUrl); UriBuilder localUri = new UriBuilder(remoteUri); if (!remoteUri.Scheme.EqualsIgnoreCase("http")) { // TODO: reject } WebServer server = null; if (Servers.ContainsKey(remoteUri.Port)) { server = Servers[remoteUri.Port]; } else { server = new WebServer(remoteUri.Host, remoteUri.Port, baseAddress); await server.InitializeAsync(ct); Servers.Add(remoteUri.Port, server); } await server.DoWorkAsync(ct); localUri.Host = server.LocalHost; localUri.Port = server.LocalPort; return(localUri.Uri.ToString()); }
private async Task DoWorkAsync(CancellationToken ct = default(CancellationToken)) { try { while (_listener.IsListening) { if (ct.IsCancellationRequested) { _listener.Stop(); break; } HttpListenerContext context = await _listener.GetContextAsync(); string localUrl = $"{LocalHost}:{LocalPort}"; string remoteUrl = $"{RemoteHost}:{RemotePort}"; _remoteUriService.GetResponseAsync(context, localUrl, remoteUrl, ct).DoNotWait(); } } catch (Exception ex) { if (Servers.ContainsKey(RemotePort)) { // Log only if we expect this web server to be running and it fails. _log.WriteLine(LogVerbosity.Minimal, MessageCategory.Error, Resources.Error_RemoteWebServerFailed.FormatInvariant(_name, ex.Message)); _console.WriteErrorLine(Resources.Error_RemoteWebServerFailed.FormatInvariant(_name, ex.Message)); } } finally { Stop(RemotePort); } }
public void NotifyClients(uint sessionId, ServerInfoBase info) { var serverName = ""; if (info is WorldServerInfo) { serverName = "WorldServer"; } else if (info is WorldNodeInfo) { serverName = "NodeServer"; } if (info == null) { if (Servers.TryRemove(sessionId, out info)) { Log.Message($"{serverName} (Realm: {info.RealmId}, Host: {info.IPAddress}, Port: {info.Port}) disconnected."); } } else { var status = "connected"; if (Servers.ContainsKey(sessionId)) { status = "updated"; } Servers.AddOrUpdate(sessionId, info, (k, v) => info); Log.Message($"{serverName} (Host: {info.IPAddress}, Port: {info.Port}, Connections: {info.ActiveConnections}) {status}."); } }
public void SetActiveServer(IPEndPoint server) { if (Servers.ContainsKey(server.ToString())) { ActiveServer = Servers[server.ToString()].Item1; } }
public Uri GetInfoUri(string serverName) { if (serverName != null && Servers.ContainsKey(serverName) && Servers[serverName].Info != null) { return(Servers[serverName].Info.ToUri()); } return(Config.Homepage?.ToUri()); }
public CoflnetServer FindServer(long identifier) { if (!Servers.ContainsKey(identifier)) { Servers.TryAdd(identifier, new CoflnetServer(identifier)); } return(Servers[identifier]); }
/// <summary> /// Initializes the OSC Handler. /// Here you can create the OSC servers and clientes. /// </summary> public void Init() { //Initialize OSC clients (transmitters) //Example: //CreateClient("Test", IPAddress.Parse("127.0.0.1"), 6000); //Initialize OSC servers (listeners) //Example: if (!Servers.ContainsKey("AssemblyOSC")) { CreateServer("AssemblyOSC", 6000); } }
void _srvWatcher_OnServersRemoved(List <IServerWithConnection> removedServers) { foreach (var removedServer in removedServers) { if (Servers.ContainsKey(removedServer)) { Servers.Remove(removedServer); } } if (Servers.Count == 0) { GC.Collect(); } OnServersRemoved(removedServers.Cast <IServer>().ToList()); }
public void StartServer(INetContext context) { var key = context.IPAddress + ":" + context.Port; lock (Servers) { if (Servers.ContainsKey(key)) { throw new Exception("Server already exists with that IP:Port endpoint"); } Servers.Add(key, this); } Clients = new List <DirectClientProvider>(); AcceptIncomingConnections = true; IsActive = true; }
private COMCLSIDServerEntry GetDefaultServer() { if (Servers.ContainsKey(COMServerType.InProcServer32)) { return(Servers[COMServerType.InProcServer32]); } if (Servers.ContainsKey(COMServerType.LocalServer32)) { return(Servers[COMServerType.LocalServer32]); } if (Servers.ContainsKey(COMServerType.InProcHandler32)) { return(Servers[COMServerType.InProcHandler32]); } return(new COMCLSIDServerEntry(COMServerType.UnknownServer)); }
public void SendCommandToServer(CommandData data, long serverId = 0) { if (serverId == 0) { serverId = ConfigController.PrimaryServer; } if (serverId == 0) { throw new System.Exception("There is no server with the id " + serverId.ToString("X")); } if (!Servers.ContainsKey(serverId)) { Servers.AddOrUpdate(serverId, new CoflnetServer(serverId), (sid, s) => s); } SendCommandToServer(data, Servers[serverId]); }
public void Init() { foreach (var server in ServerIds) { while (!Servers.ContainsKey(server)) { Thread.Sleep(100); } Servers[server].WaitForReady(); } foreach (var serverId in ServerIds) { Servers[serverId].SendInformationToServer(); } lock (this) { Ready = true; Monitor.PulseAll(this); } }
private void GenerateServers(Random rand) { Console.WriteLine("Generating servers..."); var serverCount = new Random().Next(0, 10000); for (int i = 0; i < serverCount; ++i) { string ip; while (true) { ip = Helper.GenerateIPV4(rand); if (!Servers.ContainsKey(ip)) { break; } } Servers.Add(ip, new GameServer(ip)); } Console.WriteLine("Servers generated!"); }
private static void QueryReceived(IAsyncResult result) { try { var bytes = _connection.EndReceiveFrom(result, ref obtainedIP); var obtainedEP = (IPEndPoint)obtainedIP; Log.Info("Received packet from address " + obtainedEP.ToString()); if (PendingSessions.ContainsKey(obtainedEP)) { var strData = Encoding.ASCII.GetString(obtainedData, 0, bytes); Log.Debug("Received data: " + strData.Substring(4)); var lines = strData.Substring(4).Split('\n'); var xuid = PendingSessions[obtainedEP].XUID; var client = Client.Get(xuid); var gt = client.GamerTag; if (lines[0].StartsWith("statusResponse")) { Log.Info("Received a statusResponse."); if (lines.Length >= 2) { var dictionary = GetParams(lines[1].Split('\\')); if (!dictionary.ContainsKey("fs_game")) { dictionary.Add("fs_game", ""); } try { using (GeoIPCountry geo = new GeoIPCountry("GeoIP.dat")) { var countrycode = geo.GetCountryCode(obtainedEP.Address); Console.WriteLine("Country code of IP address " + obtainedEP.Address.ToString() + ": " + countrycode); dictionary.Add("countrycode", countrycode); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } dictionary.Add("xuid", xuid.ToString("X16")); lock (Servers) { /* * if (Servers.ContainsKey(obtainedEP)) * { * Servers.Remove(obtainedEP); * } */ ServerData info = null; if (!Servers.ContainsKey(obtainedEP)) { info = new ServerData(); Servers.Add(obtainedEP, info); } else { info = Servers[obtainedEP]; } info.GameData = dictionary; info.Address = obtainedEP; info.HostName = gt; info.HostXUID = xuid; info.LastUpdated = DateTime.UtcNow; Servers[obtainedEP] = info; /* * Servers.Add(obtainedEP, new ServerData() * { * GameData = dictionary, * Address = obtainedEP, * HostName = gt, * HostXUID = xuid, * LastUpdated = DateTime.UtcNow * }); */ } } } else if (lines[0].StartsWith("0hpong")) { Log.Info("Received a 0hpong."); var data = lines[0].Split(' '); var ingame = (data[3] == "1"); var players = int.Parse(data[4]); var maxPlayers = int.Parse(data[5]); if (ingame) { ServerData info = null; if (!Servers.ContainsKey(obtainedEP)) { info = new ServerData(); Servers.Add(obtainedEP, info); } else { info = Servers[obtainedEP]; } info.GameData = new Dictionary <string, string>(); //info.Address = obtainedEP; //info.HostName = gt; //info.HostXUID = xuid; //info.LastUpdated = DateTime.UtcNow; // hpong-exclusive data info.InGame = ingame; info.CurrentPlayers = players; info.MaxPlayers = maxPlayers; Servers[obtainedEP] = info; // send getstatus if in-game StartAdvancedQuery(PendingSessions[obtainedEP]); } } } } catch (Exception ex) { Log.Error(ex.ToString()); } _connection.BeginReceiveFrom(obtainedData, 0, obtainedData.Length, SocketFlags.None, ref obtainedIP, new AsyncCallback(QueryReceived), null); }