Пример #1
0
        private async void SendMessagesThread(CancellationToken token)
        {
            while (ConnectionStatus == ConnectionStatus.Connected)
            {
                while (SendMessageQueue.TryDequeue(out var message) && message != null)
                {
                    try
                    {
                        LidgrenServer.SendMessageToClient(this, message);
                    }
                    catch (Exception e)
                    {
                        ClientException.HandleDisconnectException("Send network message error: ", this, e);
                        return;
                    }

                    LmpPluginHandler.FireOnMessageSent(this, message);
                }
                try
                {
                    await Task.Delay(IntervalSettings.SettingsStore.SendReceiveThreadTickMs, token);
                }
                catch (TaskCanceledException)
                {
                    break;
                }
            }
        }
Пример #2
0
        private async void SendMessagesThread()
        {
            while (ConnectionStatus == ConnectionStatus.Connected)
            {
                if (SendMessageQueue.TryDequeue(out var message) && message != null)
                {
                    try
                    {
                        ServerContext.LidgrenServer.SendMessageToClient(this, message);
                    }
                    catch (Exception e)
                    {
                        ClientException.HandleDisconnectException("Send network message error: ", this, e);
                        return;
                    }

                    LmpPluginHandler.FireOnMessageSent(this, message);
                }
Пример #3
0
        private static void SendNetworkMessage(ClientStructure client, IServerMessageBase message)
        {
            if (client.ConnectionStatus == ConnectionStatus.CONNECTED)
            {
                try
                {
                    ServerContext.LidgrenServer.SendMessageToClient(client, message);
                }
                catch (Exception e)
                {
                    ClientException.HandleDisconnectException("Send network message error: ", client, e);
                    return;
                }
            }
            else
            {
                LunaLog.Normal($"Tried to send a message to client {client.PlayerName}, with connection status: {client.ConnectionStatus}");
            }

            LmpPluginHandler.FireOnMessageSent(client, message);
        }