Exemple #1
0
 /// <summary>
 /// This will host an API server, that can be accessed with the given API keys.
 /// </summary>
 /// <param name="port">The port to host the server on.</param>
 /// <param name="listenInterface">The interface to bind the socket to.</param>
 /// <param name="keys">The accepted API keys.</param>
 /// <param name="logger">The global logger.</param>
 public WebApiServer(ushort port, string listenInterface, string[] keys, ILogger <Class> logger, IGameManager manager, Class masterClass, QuiteEffectiveDetector detector, bool secure, X509Certificate2 certificate)
 {
     this.StartTime = DateTime.UtcNow;
     this.Counters  = new PerformanceMonitors();
     this.Running   = true;
     this.Commands  = new Dictionary <string, string>();
     Options        = new ParallelOptions
     {
         MaxDegreeOfParallelism = Environment.ProcessorCount
     };
     this.Logger        = logger;
     this.GameManager   = manager;
     this.QEDector      = detector;
     this.QEData        = new QuodEratDemonstrandum.QuiteEnigmaticData(keys);
     GlobalMessage      = new Structures.BaseMessage();
     ApiKeys            = new List <string>();
     GlobalMessage.Type = Structures.MessageFlag.ConsoleLogMessage;
     ApiKeys.AddRange(keys);
     if (!secure)
     {
         Server = new WebSocketServer($"ws://{listenInterface}:{port}");
         Logger.LogInformation("! WebApi server: bound insecure listener.");
     }
     else
     {
         Server = new WebSocketServer($"wss://{listenInterface}:{port}")
         {
             Certificate = certificate
         };
         Server.EnabledSslProtocols = SslProtocols.Tls12;
         Logger.LogInformation("! WebApi server: bound secure listener.");
     }
     //we start the listener.
     Server.Start(socket =>
     {
         //a client connects.
         socket.OnOpen += () => OnOpen(socket);
     });
     HeartbeatThread = new Thread(DoHeartbeat);
     HeartbeatThread.Start();
     this.Master = masterClass;
 }
Exemple #2
0
 public async Task Send(string data, QuodEratDemonstrandum.QuiteEnigmaticData qed)
 {
     await Connection.Send(qed.Encrypt(data, Key)).ConfigureAwait(false);
 }