Пример #1
0
        public override void Close(string msg = null)
        {
            if (netServer == null)
            {
                return;
            }

            for (int i = pendingClients.Count - 1; i >= 0; i--)
            {
                RemovePendingClient(pendingClients[i], DisconnectReason.ServerShutdown, msg);
            }

            for (int i = connectedClients.Count - 1; i >= 0; i--)
            {
                Disconnect(connectedClients[i], msg ?? DisconnectReason.ServerShutdown.ToString());
            }

            netServer.Shutdown(msg ?? DisconnectReason.ServerShutdown.ToString());

            pendingClients.Clear();
            connectedClients.Clear();

            netServer = null;

            if (steamServer != null)
            {
                steamServer.Auth.OnAuthChange = null;
            }
            steamServer = null;

            OnShutdown?.Invoke();
        }
Пример #2
0
        public static void Shutdown()
        {
            //check if the device was already shutdown
            if (!_init)
            {
                return;
            }

            //call the OnShutdown Method
            OnShutdown?.Invoke();
            OnShutdown = null;

            //free all handles...
            for (int i = 0; i < OutPorts.Length; i++)
            {
                MidiInternal.rtmidi_out_free(OutPorts[i]);
                OutPorts[i] = IntPtr.Zero;
            }



            //erase everything
            OutPorts = null;
            _handler = null;

            //set init flag to false
            _init = false;
        }
Пример #3
0
        public override void Close(string msg = null)
        {
            if (netServer == null)
            {
                return;
            }

            if (OwnerConnection != null)
            {
                OwnerConnection.Status = NetworkConnectionStatus.Disconnected;
            }

            for (int i = pendingClients.Count - 1; i >= 0; i--)
            {
                RemovePendingClient(pendingClients[i], DisconnectReason.ServerShutdown, msg);
            }

            for (int i = connectedClients.Count - 1; i >= 0; i--)
            {
                Disconnect(connectedClients[i], msg ?? DisconnectReason.ServerShutdown.ToString());
            }

            netServer.Shutdown(msg ?? DisconnectReason.ServerShutdown.ToString());

            pendingClients.Clear();
            connectedClients.Clear();

            netServer = null;

            OnShutdown?.Invoke();
        }
Пример #4
0
        public Task SubscribeAsync()
        {
            var consumer = new EventingBasicConsumer(_channel);

            consumer.Received += (sender, e) => OnDelivered?.Invoke(this, new DeliverEventArgs(e.Body,
                                                                                               new
            {
                e.BasicProperties,
                e.ConsumerTag,
                e.DeliveryTag,
                e.Exchange,
                e.Redelivered,
                e.RoutingKey,
            }, _channel));
            consumer.Shutdown += (sender, e) => OnShutdown?.Invoke(this, new Infrastructure.ShutdownEventArgs(e.Cause, new
            {
                e.ClassId,
                e.Initiator,
                e.MethodId,
                e.ReplyCode,
                e.ReplyText
            }));
            return(Task.Run(() =>
            {
                _channel.BasicConsume(_queue.QueueName, false, consumer);
            }));
        }
Пример #5
0
        public override void Close(string msg = null)
        {
            if (netServer == null)
            {
                return;
            }

            for (int i = pendingClients.Count - 1; i >= 0; i--)
            {
                RemovePendingClient(pendingClients[i], DisconnectReason.ServerShutdown, msg);
            }

            for (int i = connectedClients.Count - 1; i >= 0; i--)
            {
                Disconnect(connectedClients[i], msg ?? DisconnectReason.ServerShutdown.ToString());
            }

            netServer.Shutdown(msg ?? DisconnectReason.ServerShutdown.ToString());

            pendingClients.Clear();
            connectedClients.Clear();

            netServer = null;

            Steamworks.SteamServer.OnValidateAuthTicketResponse -= OnAuthChange;

            OnShutdown?.Invoke();
        }
 internal void Awake()
 {
     Instance = this;
     Provider.onServerDisconnected += (CSteamID r) =>
     {
         if (r != CSteamID.Nil)
         {
             OnPlayerDisconnected.TryInvoke(UnturnedPlayer.FromCSteamID(r));
         }
     };
     Provider.onServerShutdown  += () => { OnShutdown.TryInvoke(); };
     Provider.onServerConnected += (CSteamID r) =>
     {
         if (r != CSteamID.Nil)
         {
             UnturnedPlayer p  = UnturnedPlayer.FromCSteamID(r);
             var            go = p.Player.gameObject;
             go.TryAddComponent <UnturnedPlayerFeatures>();
             go.TryAddComponent <UnturnedPlayerMovement>();
             go.TryAddComponent <UnturnedPlayerEvents>();
             OnBeforePlayerConnected.TryInvoke(p);
         }
     };
     DamageTool.damagePlayerRequested += newOnDamage;
 }
Пример #7
0
 private void Shutdown()
 {
     if (OnShutdown != null)
     {
         OnShutdown.Invoke();
     }
 }
        public Task OnServerInitializedAsync()
        {
            _serverShutdownDisposable = _server !.OnShutdown.Subscribe((_) => ServerShutdown());

            ServerStarted();

            return(Task.CompletedTask);
        }
Пример #9
0
 protected void onShutdown()
 {
     if (null != OnShutdown)
     {
         OnShutdown.Invoke();
         OnShutdown = null;
     }
 }
Пример #10
0
        public void Shutdown()
        {
            _Schedule.Stop();

            if (OnShutdown != null)
            {
                OnShutdown.Invoke(null, null);
            }
        }
 /// <summary>
 /// Does the on shutdown.
 /// </summary>
 static internal void DoOnShutdown()
 {
     try
     {
         OnShutdown?.Invoke();
     }
     catch (Exception ex)
     {
         RIExceptionManager.Publish(ex, "Failed during: RIEventManager.DoOnShutdown()");
     }
 }
        /// <summary>
        /// Destroy the singleton instance.
        /// </summary>
        public static void ShutdownRemoteRendering()
        {
            if (!IsInitialized)
            {
                return;
            }

            OnShutdown?.Invoke();

            // Destroy all memory associated with the system backend
            NativeLibraryExtensions.RemoteRendering_Shutdown();
            IsInitialized = false;
        }
Пример #13
0
 private void mk_play_event(IntPtr userdata, int err_code, string err_msg)
 {
     if (userdata == this._resultData)
     {
         if (err_code == 0)
         {
             this.Status = EM_PlayStatus.Playing;
         }
         OnPlayResult?.Invoke(err_code, err_msg);
     }
     else if (userdata == this._shutdownData)
     {
         this.Status = EM_PlayStatus.Closed;
         OnShutdown?.Invoke(err_code, err_msg);
     }
 }
Пример #14
0
 /// <summary>
 /// 推流结果或推流中断事件的回调
 /// </summary>
 /// <param name="userData"></param>
 /// <param name="code">错误代码,0为成功</param>
 /// <param name="message">错误提示</param>
 private void mk_push_event(IntPtr userData, int code, string message)
 {
     if (userData == this._result)
     {
         this._pusherMessage = message;
         this._pusherCode    = code;
         this.StartTime      = DateTime.Now;
     }
     else if (userData == this._shutdown)
     {
         this.StopTime = DateTime.Now;
         if (OnShutdown != null)
         {
             OnShutdown.Invoke(code, message);
         }
     }
     return;
 }
Пример #15
0
        /// <summary>
        /// Shuts all the threads down after they end calculationg their last task.
        /// </summary>
        public void Shutdown()
        {
            lock (locker)
            {
                cancelTokenSource.Cancel();
            }

            OnShutdown?.Invoke();

            for (int i = 0; i < threads.Length; i++)
            {
                reset.Set();
            }

            foreach (var thread in threads)
            {
                thread.Join();
            }
        }
Пример #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cred"></param>
        public virtual void Start(Credentials cred)
        {
            OnStartup?.Invoke(this);

            Connect();

            this.cred = cred;

            Login(true);
            Join(superusers);
            RequestTags("twitch.tv/tags", "twitch.tv/commands");

            foreach (var msg in messages)
            {
                EH.InvokePlugins(msg);
            }

            Disconnect();

            OnShutdown?.Invoke(this);
        }
Пример #17
0
        private void OnChatMessage(ClientGCMsgProtobuf <CMsgDOTAChatMessage> response)
        {
            if (!string.IsNullOrEmpty(response.Body.persona_name))
            {
                _logger.Info("Incoming chat message - Person: " + response.Body.persona_name + " - Message: " + response.Body.text);
                var accountId = SteamHelper.ConvertIDToUint64(response.Body.account_id);
                switch (response.Body.text.Trim().ToLower().Split(' ')[0])
                {
                case "!shutdown":
                    if (_config.Admins.Contains(accountId))
                    {
                        _logger.Info("Shutdown requested");
                        DotaClient.Disconnect(true);
                        OnShutdown?.Invoke();
                    }
                    else
                    {
                        _logger.Warn("Shutdown not allowed for Steam ID: " + accountId);
                    }
                    break;

                case "!host":
                    ProcessLobbyCommand(response.Body.channel_id, accountId, response.Body.persona_name, response.Body.text);
                    break;

                case "!lobbies":
                    ProcessLobbiesCommand(response.Body.channel_id, response.Body.persona_name);
                    break;

                case "!me":
                    ProcessMeCommand(response.Body.channel_id, accountId, response.Body.persona_name);
                    break;

                case "!help":
                    DotaClient.QueueChatMessage(response.Body.channel_id, String.Format(_config.HelpMessage, response.Body.persona_name), false);
                    break;
                }
            }
        }
Пример #18
0
        public string Dispatch(string s)
        {
            string rsp;

            if (s == SHUTDOWN)
            {
                OnShutdown?.Invoke();
                rsp = "Done.";
            }
            else if (s.StartsWith(STATUSCODE))
            {
                var sc = int.Parse(s.Substring(STATUSCODE.Length));
                OnForceStatusCode?.Invoke(sc);
                rsp = string.Format("Done. {0}{1}", STATUSCODE, sc);
            }
            else if (s.StartsWith(REASONPHRASE))
            {
                var rp = s.Substring(REASONPHRASE.Length);
                OnForceReasonPhrase?.Invoke(rp);
                rsp = string.Format("Done. {0}{1}", REASONPHRASE, rp);
            }
            else if (s.StartsWith(DELAY))
            {
                var ms = int.Parse(s.Substring(DELAY.Length));
                OnDelay?.Invoke(ms);
                rsp = string.Format("Done. {0}{1}", DELAY, ms);
            }
            else if (s.StartsWith(DELAYURI))
            {
                var uri = s.Substring(DELAYURI.Length);
                OnDelayUri?.Invoke(uri);
                rsp = string.Format("Done. {0}{1}", DELAYURI, uri);
            }
            else
            {
                rsp = "No such command.";
            }
            return(rsp);
        }
Пример #19
0
 public static extern void HP_Set_FN_Agent_OnShutdown(IntPtr pListener, OnShutdown fn);
Пример #20
0
 void IHostListener.OnHostShutdown()
 {
     OnShutdown?.Invoke();
 }
Пример #21
0
 public static extern void HP_Set_FN_HttpServer_OnShutdown(IntPtr pListener, OnShutdown fn);
Пример #22
0
 public static void InvokeShutdown()
 {
     OnShutdown?.Invoke();
 }
Пример #23
0
 /// <inheritdoc />
 public virtual void Shutdown()
 {
     OnShutdown?.Invoke(new ComponentShutdownEventArgs(this));
     OnShutdown = null;
 }
Пример #24
0
        public bool Start()
        {
            if (!Running)
            {
                var readyEvent = new ManualResetEventSlim();

                taskFactory.StartNew(() =>
                {
                    var processHandle = Process.GetCurrentProcess().Handle;

                    var windowClass = new WndClassEx
                    {
                        lpszMenuName  = null,
                        hInstance     = processHandle,
                        cbSize        = WndClassEx.Size,
                        lpfnWndProc   = windowCallback,
                        lpszClassName = Guid.NewGuid().ToString()
                    };

                    // Register the dummy window class
                    var classAtom = RegisterClassEx(ref windowClass);

                    // Check whether the class was registered successfully
                    if (classAtom != 0u)
                    {
                        // Create the dummy window
                        Handle  = CreateWindowEx(0x08000000, classAtom, "", 0, -1, -1, -1, -1, IntPtr.Zero, IntPtr.Zero, processHandle, IntPtr.Zero);
                        Running = Handle != IntPtr.Zero;

                        // Unblock calling thread as everything is ready to go
                        readyEvent.Set();

                        // If window has been created, initialize the message window loop
                        if (Running)
                        {
                            Message message = new Message();

                            OnStarted?.Invoke(this, EventArgs.Empty);

                            while (GetMessage(out message, IntPtr.Zero, 0, 0) != 0)
                            {
                                TranslateMessage(ref message);
                                DispatchMessage(ref message);
                            }

                            OnShutdown?.Invoke(this, EventArgs.Empty);
                        }
                    }
                    else
                    {
                        // Failed to create the dummy window class. Unblock calling thread
                        readyEvent.Set();
                    }
                });

                // Block calling thread untill we have the window creation result
                readyEvent.Wait();
            }

            return(Running);
        }
 private void Shutdown()
 {
     View.PutLine("Command {0} received.", CommandProcessor.SHUTDOWN);
     OnShutdown?.Invoke();
 }
Пример #26
0
 internal static void Shutdown()
 => OnShutdown?.Invoke();
Пример #27
0
 public static extern void HP_Set_FN_Server_OnShutdown(IntPtr pListener, OnShutdown fn);
Пример #28
0
        public void ReadEvent(Dictionary <string, object> rawData)
        {
            if (!rawData.ContainsKey("event"))
            {
                return;
            }

            switch (rawData["event"])
            {
            case "FSDJump":
                OnFsdJump?.Invoke(this, Parser.ParseJournalEvent <FsdJump>(rawData));
                break;

            case "FSSDiscoveryScan":
                OnFssDiscoveryScan?.Invoke(this, Parser.ParseJournalEvent <FssDiscoveryScan>(rawData));
                break;

            case "Scan":
                var body = Parser.ParseScanBody(rawData);

                if (rawData.ContainsKey("StarType"))
                {
                    var subType = (string)rawData["StarType"];
                    body.Type    = Parser.ParseStarType(subType);
                    body.SubType = subType;
                    body.Mass    = (double)rawData["StellarMass"];
                }
                else if (rawData.ContainsKey("PlanetClass"))
                {
                    var subType = (string)rawData["PlanetClass"];
                    body.Type          = Parser.ParseWorldType(subType);
                    body.SubType       = subType;
                    body.Terraformable = rawData.ContainsKey("TerraformState") ? (string)rawData["TerraformState"] : string.Empty;
                    body.Mass          = (double)rawData["MassEM"];
                }
                else
                {
                    body.Type = BodyType.Belt;
                }

                OnBodyScan?.Invoke(this, body);
                break;

            case "FSSAllBodiesFound":
                OnAllBodiesFound?.Invoke(this, true);
                break;

            case "SAAScanComplete":
                OnDssScan?.Invoke(this, Parser.ParseJournalEvent <DssScan>(rawData));
                break;

            case "StartJump":
                OnStartJump?.Invoke(this, Parser.ParseJournalEvent <StartJump>(rawData));
                break;

            case "Shutdown":
                OnShutdown?.Invoke(this, true);
                break;

            default:
                return;
            }
        }
 protected virtual void OnShutdownInvoke()
 {
     OnShutdown?.Invoke(this, null);
 }