Exemple #1
0
        private void WebListener_ConnectionRequestReceived(object sender, VoicePaketConfig e)
        {
            try
            {
                if (_ShutDown)
                {
                    return;
                }
                _lastPureVoicePing = DateTime.Now;

                VoicePlugin.Log("Accept Configuration via Web");
                if (IsConnected)
                {
                    VoicePlugin.Log("Already connected");
                    return;
                }

                if (e.ClientVersionRequired > VoicePlugin.PluginVersion)
                {
                    if (!_GotWarning)
                    {
                        _GotWarning = true;
                        MessageBox.Show($"{VoicePlugin.Name} outdated. Version {e.ClientVersionRequired} is required. Please update.", "PureVoice Plugin Outdated");
                    }
                    return;
                }
                _lastPureVoicePing = DateTime.Now;
                //VoicePlugin.Log("process VoicePaketConfig {0}", _configuration);
                _configuration  = e;
                _needConnection = true;
                // StartServerConnection();
            }
            catch (Exception ex)
            {
                VoicePlugin.Log(ex.ToString());
            }
        }
Exemple #2
0
        private void ServerListener_NetworkReceiveUnconnectedEvent(NetEndPoint remoteEndPoint, NetDataReader reader, UnconnectedMessageType messageType)
        {
            try
            {
                if (_ShutDown)
                {
                    return;
                }
                if ((remoteEndPoint.Host != "127.0.0.1") && (remoteEndPoint.Host != "[::1]"))
                {
                    VoicePlugin.Log("Refused from {0}", remoteEndPoint);
                    return;
                }
                if (messageType != UnconnectedMessageType.BasicMessage)
                {
                    VoicePlugin.Log("Refused {1} from {0}", remoteEndPoint, messageType);
                    return;
                }

                var hello        = reader.GetString();
                var voiceVersion = reader.GetInt();
                if (voiceVersion != 1)
                {
                    VoicePlugin.Log("Refused v {1} from {0}", remoteEndPoint, voiceVersion);
                    return;
                }
                if ((hello == "GTMPVOICECOMMAND") || (hello == "PUREVOICECOMMAND"))
                {
                    VoicePlugin.Log("Command from {0}", remoteEndPoint);
                    if (IsConnected)
                    {
                        var Connection = Client?.GetFirstPeer();
                        if ((Connection != null) && (Connection.ConnectionState == ConnectionState.Connected))
                        {
                            _netPacketProcessor.Send(Connection, new VoicePaketCommand()
                            {
                                Command = reader.GetString(), Data = reader.GetString()
                            }, DeliveryMethod.ReliableOrdered);
                        }
                    }
                    return;
                }
                if ((hello != "GTMPVOICE") && (hello != "PUREVOICE"))
                {
                    VoicePlugin.Log("Invalid configuration from {0}", remoteEndPoint);
                    return;
                }
                _configuration = new VoicePaketConfig();
                _configuration.Deserialize(reader);

                _lastPureVoicePing = DateTime.Now;

                VoicePlugin.Log("Accept Configuration from {0}", remoteEndPoint);
                if (IsConnected)
                {
                    VoicePlugin.Log("Already connected");
                    return;
                }

                if (_configuration.ClientVersionRequired > VoicePlugin.PluginVersion)
                {
                    if (!_GotWarning)
                    {
                        _GotWarning = true;
                        MessageBox.Show($"{VoicePlugin.Name} outdated. Version {_configuration.ClientVersionRequired} is required. Please update.", "PureVoice Plugin Outdated");
                    }
                    return;
                }
                _lastPureVoicePing = DateTime.Now;
                //VoicePlugin.Log("process VoicePaketConfig {0}", _configuration);
                _needConnection = true;
                StartServerConnection();
            }
            catch (Exception ex)
            {
                VoicePlugin.Log("Invalid Serverpaket from {0}: {1}", remoteEndPoint, ex.Message);
            }
        }
Exemple #3
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());
            }
        }
Exemple #4
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());
            }
        }