Пример #1
0
        public int RemoveEventListeners()
        {
            DebugLog("Removing event listeners...");
            ChatLog chatLog = ChatLog.Instance_;

            PrivateUtilities.removeParticularSubscriber <WelcomeClient.Data>(chatLog);
            PrivateUtilities.removeParticularSubscriber <SetServerChat.Data>(chatLog);
            var chatInputV2s = PrivateUtilities.getComponents <ChatInputV2>();

            PrivateUtilities.removeParticularSubscribers <SetServerChat.Data, ChatInputV2>(chatInputV2s);
            return(chatInputV2s.Count);
        }
Пример #2
0
        public void Initialize(IManager manager, string ipcIdentifier)
        {
            IPCIdentifier = ipcIdentifier;
            if (Instance != null)
            {
                Console.WriteLine("Attempt to create a second Entry");
                throw new Exception("There should only be one Entry");
            }
            Instance = this;
            GeneralUtilities.logExceptions(() =>
            {
                var levelFilters = new LevelFilter[]
                {
                    new LevelFilterAll(),
                    new LevelFilterAuthor(),
                    new LevelFilterCreated(),
                    new LevelFilterDifficulty(),
                    new LevelFilterIndex(),
                    new LevelFilterIsNew(),
                    new LevelFilterIsUpdated(),
                    new LevelFilterLast(),
                    new LevelFilterMode(),
                    new LevelFilterName(),
                    new LevelFilterPage(),
                    new LevelFilterPlaylist(),
                    new LevelFilterRegex(),
                    new LevelFilterSaved(),
                    new LevelFilterStars(),
                    new LevelFilterTime(),
                    new LevelFilterUpdated(),

                    new LevelSortFilterAuthor(),
                    new LevelSortFilterCreated(),
                    new LevelSortFilterDifficulty(),
                    new LevelSortFilterIndex(),
                    new LevelSortFilterMode(),
                    new LevelSortFilterName(),
                    new LevelSortFilterShuffle(),
                    new LevelSortFilterStars(),
                    new LevelSortFilterTime(),
                    new LevelSortFilterUpdated()
                };
                foreach (var filter in levelFilters)
                {
                    FilteredPlaylist.AddFilterType(filter);
                }
            });

            load();  // load existing data
            save();  // save defaults that were not loaded

            // player data list stuff

            Events.Player.AddRemovePlayerData.Subscribe((data) =>
            {
                if (data.added_)
                {
                    playerInfos.Add(new PlayerInfo(data.player_));
                }
                else
                {
                    playerInfos.RemoveAll((info) => info.playerData == data.player_);
                }
            });

            // chat stuff

            Events.Local.ChatSubmitMessage.Subscribe(data =>
            {
                GeneralUtilities.logExceptions(() =>
                {
                    Chat_MessageSent(data);
                });
            });

            var sendingClientToAllClientsMessage = false;

            AddMessage.Subscribe(data =>
            {
                if (!sendingClientToAllClientsMessage &&
                    (MessageUtilities.currentState == null || !MessageUtilities.currentState.forPlayer))
                {
                    chatReplicationManager.AddPublic(data.message_);
                }
            });

            ChatMessage.Subscribe(data =>
            {
                GeneralUtilities.logExceptions(() =>
                {
                    sendingClientToAllClientsMessage = true;
                    var author = MessageUtilities.ExtractMessageAuthor(data.message_);

                    if (!MessageUtilities.IsSystemMessage(data.message_) && !sendingLocalChat && !string.IsNullOrEmpty(author))
                    {
                        Chat_MessageReceived(author, MessageUtilities.ExtractMessageBody(data.message_), data);
                    }
                    else
                    {
                        addMessageFromRemote(data);
                        chatReplicationManager.AddPublic(data.message_);
                    }

                    sendingLocalChat = false;
                    sendingClientToAllClientsMessage = false;
                });
            });

            Events.Network.ServerInitialized.Subscribe(data =>
            {
                chatReplicationManager.Clear();
                G.Sys.GameManager_.StartCoroutine(serverInit());
            });

            replicateLocalChatFunc = PrivateUtilities.removeParticularSubscriber <ChatSubmitMessage.Data>(PrivateUtilities.getComponent <ClientLogic>());
            addMessageFromRemote   = PrivateUtilities.removeParticularSubscriber <ChatMessage.Data>(G.Sys.NetworkingManager_);

            chatReplicationManager = new ChatReplicationManager();
            chatReplicationManager.Setup();

            Events.Game.LevelLoaded.Subscribe(data =>
            {
                UnstuckCmd.PatchLoadSequence();
            });
        }