The basic implementation of the IProxyConnection interface
Inheritance: IProxyConnection
コード例 #1
0
        /// <summary>
        ///   checks if a user account is valid using plugins and the minecraft.net services
        /// </summary>
        /// <param name="proxyConnection"> The proxy server which should be checked. </param>
        /// <param name="hash"> The 'serverId' hash </param>
        /// <returns> true if the user account is okay, otherwise false </returns>
        public async Task<bool> CheckUserAccountAsync(ProxyConnection proxyConnection, string hash)
        {
            var args = new CheckAccountEventArgs(null, hash, proxyConnection);

            await PluginManager.TriggerPlugin.OnUserAccountCheckAsync(args);

            args.EnsureSuccess ();

            if (args.Result == null)
            {
                try
                {
                    bool? result = await UserAccountServices.CheckAccountAsync(proxyConnection.Username, hash);

                    if (result.HasValue) return result.Value;
                    _logger.Error("Could not access minecraft.net");
                    return false;
                }
                catch (Exception ex)
                {
                    _logger.Error("minecraft.net not accessible", ex);

                    return false;
                }
            }
            return (bool) args.Result;
        }
コード例 #2
0
 internal void RemoveConnection(ProxyConnection proxyConnection)
 {
     _openConnection.Remove(proxyConnection);
     if (_connectedUsers.Contains(proxyConnection))
     {
         PluginManager.TriggerPlugin.OnConnectionLost(new UserEventArgs(proxyConnection));
         _connectedUsers.Remove(proxyConnection);
     }
 }
コード例 #3
0
 internal void PromoteConnection(ProxyConnection proxyConnection)
 {
     _connectedUsers.Add(proxyConnection);
 }
コード例 #4
0
        private async void ReceiveClientsAsync()
        {
            _acceptingNewClients = true;
            while (true)
            {
                try
                {
                    Socket remote = await _listeningSocket.AcceptTaskAsync ();

                    IPAddress address = ((IPEndPoint) remote.RemoteEndPoint).Address;
                    var args = new CheckIPEventArgs(address, true);

                    PluginManager.TriggerPlugin.AllowJoining(args);

                    if (!args.AllowJoining)
                    {
                        remote.Close ();
                        _logger.Warn("Denied access from " + address);
                        continue;
                    }
                    //Connection accepted

                    var proxyConnection = new ProxyConnection(remote, this);

                    _openConnection.Add(proxyConnection);


                    proxyConnection.HandleClient ();
                }
                catch (TaskCanceledException)
                {
                    _acceptingNewClients = false;
                    return;
                }
                catch (Exception)
                {
                }
            }
        }