private static void Main() { XmlConfigurator.Configure(); try { var settings = SimpleSettings.Create("settings"); CryptoConfig.AddAlgorithm(typeof(RHHE), RHHE.Name); var sleepPeriod = int.Parse(settings.GetValue("sleep")); var ttl = int.Parse(settings.GetValue("ttl")); var server = PrepareServer(settings); var wsServer = PrepareWsServer(settings); SecretHolder.Init(settings.GetValue("secret")); CredentialsHolder.Init(settings.GetValue("credentials"), sleepPeriod); PointHolder.Init(settings.GetValue("points"), sleepPeriod, ttl, (point, msg) => wsServer.BroadcastAsync(point, msg, CancellationToken.None)); Task .WhenAll( server.AcceptLoopAsync(CancellationToken.None), wsServer.AcceptLoopAsync(CancellationToken.None) ) .Wait(); } catch (Exception ex) { Console.Error.WriteLine(ex); Log.Fatal("Unexpected exception", ex); Environment.Exit(ex.HResult == 0 ? ex.HResult : -1); } }
private static Connection?CreateConnection(WebSocket ws) { var login = ws.HttpRequest.GetLogin(); if (login == null) { return(null); } if (ws.HttpRequest.RequestUri.OriginalString == "/ws/publics") { return new Connection { NeedSend = point => point.IsPublic, Lock = new AsyncLockSource(), InitData = () => PointHolder.GetPublics() } } ; if (ws.HttpRequest.RequestUri.OriginalString == "/ws/points") { return new Connection { NeedSend = point => point.User == login, Lock = new AsyncLockSource(), InitData = () => PointHolder.GetPoints(login) } } ; return(null); }
void CreatePoints(int id, object[] positions) { GameObject pointHolder = PhotonView.Find(id).gameObject; PointHolder phScript = pointHolder.GetComponent <PointHolder>(); Transform cubeTransform = phScript.cube.transform; foreach (Vector3 p in positions) { Instantiate(point, p, Quaternion.identity, cubeTransform); //Instantiate(point, p, Quaternion.identity); } }
protected override async Task HandleInternal(HttpListenerContext context, string login) { var point = await JsonHelper.TryParseJsonAsync <Point>(context.Request.InputStream).ConfigureAwait(false); if (!IsCorrectRequest(point)) { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; return; } var p = new Db.Models.Point { X = point.X, Y = point.Y, Message = point.Message, IsPublic = point.IsPublic != null && point.IsPublic.Value, User = login }; var id = PointHolder.Add(p); await context.WriteStringAsync(id).ConfigureAwait(false); }
protected override Task HandleInternal(HttpListenerContext context, string login) => context.Response.WriteObjectAsync(PointHolder.GetPoints(login).Select(PointConverter.Convert).ToList());