Esempio n. 1
0
 public override void OnStartClient()
 {
     base.OnStartClient();
     connectionWindow.SetActive(false);
     disconnectWindow.SetActive(true);
     SetupClientNetworkMessages();
     OnClientStarted?.Invoke();
 }
Esempio n. 2
0
    public void StartClientPhoton(string roomName)
    {
        var netManager = NetworkManager.Singleton;

        netManager.GetComponent <PhotonRealtimeTransport>().RoomName = roomName;
        netManager.StartClient();
        OnDisconnected += StopClient;
        OnClientStarted?.Invoke();
    }
Esempio n. 3
0
    public void StartClient(string serverAddress)
    {
        var netManager = NetworkManager.Singleton;

        netManager.GetComponent <UNetTransport>().ConnectAddress = serverAddress;
        netManager.StartClient();
        OnDisconnected += StopClient;
        OnClientStarted?.Invoke();
    }
Esempio n. 4
0
    public void StartClient(string serverAddress)
    {
        var netManager = NetworkManager.Singleton;

        netManager.GetComponent <UNetTransport>().ConnectAddress = serverAddress;
        netManager.StartClient();

        OnClientStarted?.Invoke();
        //NetworkManager.Singleton.OnClientConnectedCallback += clientId => OnClientStarted?.Invoke();
    }
Esempio n. 5
0
        private bool SetUpClient()
        {
            _status = "Setting up client";

            bool BotTokenIsNull = string.IsNullOrWhiteSpace(DLConfig.Data.BotToken);

            if (BotTokenIsNull)
            {
                DLConfig.Instance.VerifyConfig(DLConfig.VerificationFlags.Static); // Make the user aware of the empty bot token
            }

            if (BotTokenIsNull)
            {
                return(false);                // Do not attempt to initialize if the bot token is empty
            }
            try
            {
                // Create the new client
                DiscordClient = new DiscordClient(new DiscordConfiguration
                {
                    AutoReconnect   = true,
                    Token           = DLConfig.Data.BotToken,
                    TokenType       = TokenType.Bot,
                    MinimumLogLevel = DLConfig.Data.BackendLogLevel
                });

                DiscordClient.ClientErrored += async(client, args) => { Logger.Debug("A Discord client error occurred. Error messages was: " + args.EventName + " " + args.Exception.ToString()); };
                DiscordClient.SocketErrored += async(client, args) => { Logger.Debug("A socket error occurred. Error message was: " + args.Exception.ToString()); };
                DiscordClient.SocketClosed  += async(client, args) => { Logger.DebugVerbose("Socket Closed: " + args.CloseMessage + " " + args.CloseCode); };
                DiscordClient.Resumed       += async(client, args) => { Logger.Debug("Resumed connection"); };
                DiscordClient.Ready         += async(client, args) =>
                {
                    _status = "Awaiting Discord Caching...";
                    DLConfig.Instance.EnqueueFullVerification();

                    _discordDataMaybeAvailable = new Timer(innerArgs =>
                    {
                        OnDiscordMaybeReady?.Invoke(this, EventArgs.Empty);
                        SystemUtil.StopAndDestroyTimer(ref _discordDataMaybeAvailable);
                        _status = "Connected and running";
                    }, null, FIRST_DISPLAY_UPDATE_DELAY_MS, Timeout.Infinite);
                };

                DiscordClient.GuildAvailable += async(client, args) =>
                {
                    DLConfig.Instance.EnqueueGuildVerification();
                };

                DiscordClient.MessageDeleted += async(client, args) =>
                {
                    Modules.ForEach(async module => await module.OnMessageDeleted(args.Message));
                };

                // Set up the client to use CommandsNext
                _commands = DiscordClient.UseCommandsNext(new CommandsNextConfiguration
                {
                    StringPrefixes = DLConfig.Data.DiscordCommandPrefix.SingleItemAsEnumerable()
                });
                _commands.RegisterCommands <DiscordCommands>();

                OnClientStarted?.Invoke(this, EventArgs.Empty);
                return(true);
            }
            catch (Exception e)
            {
                Logger.Error("Error occurred while creating the Discord client. Error message: " + e);
            }

            return(false);
        }