Beispiel #1
0
        private static void ProcessRequest(IAsyncResult ar)
        {
            var ctx = _listener.EndGetContext(ar);

            _listener.BeginGetContext(ProcessRequest, null);
            try
            {
                var request          = ctx.Request;
                VoicePaketConfig cfg = new VoicePaketConfig();

                foreach (var item in ctx.Request.QueryString.AllKeys)
                {
                    var val = ctx.Request.QueryString[item];
                    switch (item.ToUpperInvariant())
                    {
                    case "SERVER":
                        cfg.ServerIP = val;
                        break;

                    case "PORT":
                        if (!int.TryParse(val, out var tInt))
                        {
                            return;
                        }
                        cfg.ServerPort = tInt;
                        break;

                    case "SECRET":
                        cfg.ServerSecret = val;
                        break;

                    case "CLIENTGUID":
                        cfg.ClientGUID = val;
                        break;

                    case "VERSION":
                        cfg._ClientVersionRequired = val;
                        if (Version.TryParse(val, out var v))
                        {
                            cfg.ClientVersionRequired = v;
                        }
                        break;
                    }
                }
                var replyText = "OK";
                switch (ctx.Request.Url.LocalPath)
                {
                case "/CONNECT":
                    ConnectionRequestReceived?.Invoke(null, cfg);
                    break;

                case "/IDENTIFY":
                {
                    var c = VoicePlugin.GetConnection(cfg.ServerSecret);
                    if (c == null)
                    {
                        break;
                    }
                    replyText = "OK<script>alt.emit(\"j_PureVoiceConnect\",\"" + c.LocalClient.GUID + "\",\"" + VoicePlugin.PluginVersion + "\");</script>";
                    break;
                }
                }
                var buf = Encoding.UTF8.GetBytes(replyText);
                ctx.Response.ContentEncoding = Encoding.UTF8;
                ctx.Response.ContentType     = "text/html";
                ctx.Response.ContentEncoding = Encoding.UTF8;
                ctx.Response.AddHeader("Access-Control-Allow-Origin", "*");
                ctx.Response.ContentLength64 = buf.Length;
                ctx.Response.OutputStream.Write(buf, 0, buf.Length);
                ctx.Response.Close();
                return;
            }
            catch (Exception ex)
            {
                VoicePlugin.Log(ex.ToString());
            }
        }
Beispiel #2
0
        private static void ProcessRequest(IAsyncResult ar)
        {
            var ctx = _listener.EndGetContext(ar);

            _listener.BeginGetContext(ProcessRequest, null);
            try
            {
                var request          = ctx.Request;
                VoicePaketConfig cfg = new VoicePaketConfig();

                foreach (var item in ctx.Request.QueryString.AllKeys)
                {
                    var val = ctx.Request.QueryString[item];
                    switch (item.ToUpperInvariant())
                    {
                    case "SERVER":
                        cfg.ServerIP = val;
                        break;

                    case "PORT":
                        if (!int.TryParse(val, out var tInt))
                        {
                            return;
                        }
                        cfg.ServerPort = tInt;
                        break;

                    case "SECRET":
                        cfg.ServerSecret = val;
                        break;

                    case "CLIENTGUID":
                        cfg.ClientGUID = val;
                        break;

                    case "VERSION":
                        cfg._ClientVersionRequired = val;
                        if (Version.TryParse(val, out var v))
                        {
                            cfg.ClientVersionRequired = v;
                        }
                        break;
                    }
                }
                switch (ctx.Request.Url.LocalPath)
                {
                case "/CONNECT":
                    ConnectionRequestReceived?.Invoke(null, cfg);
                    break;
                }
                var buf = Encoding.UTF8.GetBytes("OK");
                ctx.Response.ContentEncoding = Encoding.UTF8;
                ctx.Response.ContentType     = "application/text";
                ctx.Response.ContentEncoding = Encoding.UTF8;
                ctx.Response.ContentLength64 = buf.Length;
                ctx.Response.OutputStream.Write(buf, 0, buf.Length);
                ctx.Response.Close();
                return;
            }
            catch (Exception ex)
            {
                VoicePlugin.Log(ex.ToString());
            }
        }