private byte[] GetBytes()
        {
            List <byte> buffer = new List <byte>();

            byte[] nameBuffer = Encoding.UTF8.GetBytes(playerName);
            buffer.AddRange(BitConverter.GetBytes(nameBuffer.Length));
            buffer.AddRange(nameBuffer);
            buffer.AddRange(BitConverter.GetBytes(playerId));

            buffer.AddRange(BitConverter.GetBytes(playerScore));
            buffer.AddRange(BitConverter.GetBytes(playerCutBlocks));
            buffer.AddRange(BitConverter.GetBytes(playerMaxComboBlocks));
            buffer.AddRange(BitConverter.GetBytes(playerComboBlocks));
            buffer.AddRange(BitConverter.GetBytes(playerTotalBlocks));
            buffer.AddRange(BitConverter.GetBytes(playerEnergy));

            buffer.AddRange(BitConverter.GetBytes(playerProgress));

            buffer.AddRange(Serialization.Combine(
                                Serialization.ToBytes(rightHandPos),
                                Serialization.ToBytes(leftHandPos),
                                Serialization.ToBytes(headPos),
                                Serialization.ToBytes(rightHandRot),
                                Serialization.ToBytes(leftHandRot),
                                Serialization.ToBytes(headRot)));

            buffer.AddRange(HexConverter.ConvertHexToBytesX(avatarHash));

            buffer.AddRange(BitConverter.GetBytes(Ready));
            buffer.AddRange(BitConverter.GetBytes(SongFailed));
            buffer.AddRange(BitConverter.GetBytes(InSong));

            return(buffer.ToArray());
        }
        public void AddToMessage(NetOutgoingMessage msg)
        {
            msg.Write(playerName);
            msg.Write(playerId);

            updateInfo.AddToMessage(msg);

            msg.Write(HexConverter.ConvertHexToBytesX(avatarHash));

            if (hitsLastUpdate != null)
            {
                msg.Write((byte)hitsLastUpdate.Count);

                for (int i = 0; i < (byte)hitsLastUpdate.Count; i++)
                {
                    hitsLastUpdate[i].AddToMessage(msg);
                }

                hitsLastUpdate.Clear();
            }
            else
            {
                msg.Write((byte)0);
            }
        }
Exemple #3
0
        public void AddToMessage(NetOutgoingMessage msg)
        {
            msg.Write(playerName);
            msg.Write(playerId);

            msg.Write(playerNameColor.r);
            msg.Write(playerNameColor.g);
            msg.Write(playerNameColor.b);

            msg.Write((byte)playerState);

            msg.Write(fullBodyTracking);
            msg.WriteVariableUInt32(playerScore);
            msg.WriteVariableUInt32(playerCutBlocks);
            msg.WriteVariableUInt32(playerComboBlocks);
            msg.WriteVariableUInt32(playerTotalBlocks);
            msg.WritePadBits();
            msg.Write(playerEnergy);
            msg.Write(playerProgress);

            if (playerLevelOptions == null)
            {
                new LevelOptionsInfo(BeatmapDifficulty.Hard, GameplayModifiers.defaultModifiers, "Standard").AddToMessage(msg);
            }
            else
            {
                playerLevelOptions.AddToMessage(msg);
            }

            rightHandPos.AddToMessage(msg);
            leftHandPos.AddToMessage(msg);
            headPos.AddToMessage(msg);

            rightHandRot.AddToMessage(msg);
            leftHandRot.AddToMessage(msg);
            headRot.AddToMessage(msg);

            if (fullBodyTracking)
            {
                pelvisPos.AddToMessage(msg);
                leftLegPos.AddToMessage(msg);
                rightLegPos.AddToMessage(msg);

                pelvisRot.AddToMessage(msg);
                leftLegRot.AddToMessage(msg);
                rightLegRot.AddToMessage(msg);
            }

            msg.Write(HexConverter.ConvertHexToBytesX(avatarHash));

            msg.Write((byte)hitsLastUpdate.Count);

            for (int i = 0; i < (byte)hitsLastUpdate.Count; i++)
            {
                hitsLastUpdate[i].AddToMessage(msg);
            }

            hitsLastUpdate.Clear();
        }
Exemple #4
0
 public void AddToMessage(NetOutgoingMessage msg)
 {
     msg.Write(songName);
     msg.Write(songSubName);
     msg.Write(authorName);
     msg.Write(key);
     msg.Write(HexConverter.ConvertHexToBytesX(levelId));
     msg.Write(songDuration);
 }
        public void AddToMessage(NetOutgoingMessage msg)
        {
            msg.Write(playerName);
            msg.Write(playerId);

            msg.Write(playerNameColor.r);
            msg.Write(playerNameColor.g);
            msg.Write(playerNameColor.b);

            msg.Write((byte)playerState);

            msg.Write(fullBodyTracking);
            msg.WriteVariableUInt32(playerScore);
            msg.WriteVariableUInt32(playerCutBlocks);
            msg.WriteVariableUInt32(playerComboBlocks);
            msg.WriteVariableUInt32(playerTotalBlocks);
            msg.WritePadBits();
            msg.Write(playerEnergy);
            msg.Write(playerProgress);

            rightHandPos.AddToMessage(msg);
            leftHandPos.AddToMessage(msg);
            headPos.AddToMessage(msg);

            rightHandRot.AddToMessage(msg);
            leftHandRot.AddToMessage(msg);
            headRot.AddToMessage(msg);

            if (fullBodyTracking)
            {
                Vector3.zero.AddToMessage(msg);        //Pelvis Pos
                Vector3.zero.AddToMessage(msg);        //Left Leg Pos
                Vector3.zero.AddToMessage(msg);        //Right Leg Pos

                Quaternion.identity.AddToMessage(msg); //Pelvis Rot
                Quaternion.identity.AddToMessage(msg); //Left Leg Rot
                Quaternion.identity.AddToMessage(msg); //Left Leg Pos
            }

            msg.Write(HexConverter.ConvertHexToBytesX(avatarHash));

            msg.Write((byte)hitsLastUpdate.Count);

            for (int i = 0; i < (byte)hitsLastUpdate.Count; i++)
            {
                hitsLastUpdate[i].AddToMessage(msg);
            }

            hitsLastUpdate.Clear();
        }
Exemple #6
0
        public void AddToMessage(NetOutgoingMessage msg)
        {
            msg.Write(songName);


            if (levelId.Length >= 32)
            {
                msg.Write(HexConverter.ConvertHexToBytesX(levelId));
            }
            else
            {
                msg.Write(HexConverter.GetStringHashBytes(levelId));
            }
            msg.Write(songDuration);
        }
        public void AddToMessage(NetOutgoingMessage msg)
        {
            msg.Write(playerName);
            msg.Write(playerId);

            msg.Write((byte)playerState);

            msg.Write(playerScore);
            msg.Write(playerCutBlocks);
            msg.Write(playerComboBlocks);
            msg.Write(playerTotalBlocks);
            msg.Write(playerEnergy);
            msg.Write(playerProgress);

            msg.Write(Serialization.Combine(
                          Serialization.ToBytes(rightHandPos),
                          Serialization.ToBytes(leftHandPos),
                          Serialization.ToBytes(headPos),
                          Serialization.ToBytes(rightHandRot),
                          Serialization.ToBytes(leftHandRot),
                          Serialization.ToBytes(headRot),
                          HexConverter.ConvertHexToBytesX(avatarHash)));
        }
Exemple #8
0
        public void Update()
        {
            if (_receivedMessages.Count > 0)
            {
                networkClient.Recycle(_receivedMessages);
                _receivedMessages.Clear();
            }

            if (networkClient.ReadMessages(_receivedMessages) > 0)
            {
                for (int i = _receivedMessages.Count - 1; i >= 0; i--)
                {
                    if (_receivedMessages[i].MessageType == NetIncomingMessageType.Data && _receivedMessages[i].PeekByte() == (byte)CommandType.UpdatePlayerInfo)
                    {
                        if (_packets > 150)
                        {
                            _averagePacketTime = 0f;
                            _packets           = 0;
                        }

                        if (Time.realtimeSinceStartup - _lastPacketTime < 0.2f)
                        {
                            _averagePacketTime += Time.realtimeSinceStartup - _lastPacketTime;
                            _packets++;

                            if (_averagePacketTime != 0f && _packets != 0)
                            {
                                tickrate = 1f / (_averagePacketTime / _packets);
                            }
                        }
                        else
                        {
                            _averagePacketTime = 0f;
                            _packets           = 0;
                        }
                        _lastPacketTime = Time.realtimeSinceStartup;

                        MessageReceived?.Invoke(_receivedMessages[i]);
                        _receivedMessages[i].Position = 0;

                        break;
                    }
                }

                if (Config.Instance.SpectatorMode)
                {
                    for (int i = 0; i < _receivedMessages.Count; i++)
                    {
                        _receivedMessages[i].Position = 0;
                        if (_receivedMessages[i].MessageType == NetIncomingMessageType.Data && _receivedMessages[i].PeekByte() == (byte)CommandType.GetPlayerUpdates)
                        {
                            PlayerInfoUpdateReceived?.Invoke(_receivedMessages[i]);
                            _receivedMessages[i].Position = 0;
                        }
                    }
                }

                foreach (NetIncomingMessage msg in _receivedMessages)
                {
                    switch (msg.MessageType)
                    {
                    case NetIncomingMessageType.StatusChanged:
                    {
                        NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte();

                        if (status == NetConnectionStatus.Connected && !connected)
                        {
                            connected = true;
                            ConnectedToServerHub?.Invoke();
                        }
                        else if (status == NetConnectionStatus.Disconnected && connected)
                        {
#if DEBUG
                            Plugin.log.Info("Disconnecting...");
#endif
                            Disconnect();

                            MessageReceived?.Invoke(null);
                        }
                        else if (status == NetConnectionStatus.Disconnected && !connected)
                        {
                            Plugin.log.Error("ServerHub refused connection! Reason: " + msg.ReadString());
                        }
                    }
                    break;

                    case NetIncomingMessageType.Data:
                    {
                        CommandType commandType = (CommandType)msg.PeekByte();

                        switch (commandType)
                        {
                        case CommandType.Disconnect:
                        {
#if DEBUG
                            Plugin.log.Info("Disconnecting...");
#endif
                            Disconnect();

                            MessageReceived?.Invoke(msg);
                        }
                        break;

                        case CommandType.SendEventMessage:
                        {
                            string header = msg.ReadString();
                            string data   = msg.ReadString();

#if DEBUG
                            Plugin.log.Info($"Received event message! Header=\"{header}\", Data=\"{data}\"");
#endif

                            foreach (Action <string, string> nextDel in EventMessageReceived.GetInvocationList())
                            {
                                try
                                {
                                    nextDel?.Invoke(header, data);
                                }
                                catch (Exception e)
                                {
                                    if (nextDel != null)
                                    {
                                        Plugin.log.Error($"Exception in {nextDel.Target.GetType()}.{nextDel.Method.Name} on event message received event: {e}");
                                    }
                                    else
                                    {
                                        Plugin.log.Error($"Exception in {nextDel.Target.GetType()}.{nextDel.Method.Name} on event message received event: {e}");
                                    }
                                }
                            }
                        }
                        break;

                        case CommandType.JoinRoom:
                        {
                            msg.Position = 8;
                            if (msg.PeekByte() == 0 && ClientJoinedRoom != null)
                            {
                                foreach (Action nextDel in ClientJoinedRoom.GetInvocationList())
                                {
                                    try
                                    {
                                        nextDel?.Invoke();
                                    }
                                    catch (Exception e)
                                    {
                                        if (nextDel != null)
                                        {
                                            Plugin.log.Error($"Exception in {nextDel.Target.GetType()}.{nextDel.Method.Name} on client joined room event: {e}");
                                        }
                                        else
                                        {
                                            Plugin.log.Error($"Exception on client joined room event: {e}");
                                        }
                                    }
                                }
                            }

                            MessageReceived?.Invoke(msg);
                        }
                        break;

                        case CommandType.StartLevel:
                        {
#if DEBUG
                            startNewDump = true;
                            packetsBuffer.Clear();
                            msg.Position = 8;
                            LevelOptionsInfo levelInfo = new LevelOptionsInfo(msg);
                            SongInfo         songInfo  = new SongInfo(msg);
                            List <byte>      buffer    = new List <byte>();
                            buffer.AddRange(levelInfo.ToBytes());
                            buffer.AddRange(HexConverter.ConvertHexToBytesX(songInfo.hash));

                            Plugin.log.Info("LevelID: " + songInfo.levelId + ", Bytes: " + BitConverter.ToString(buffer.ToArray()));

                            packetsBuffer.Enqueue(buffer.ToArray());
                            msg.Position = 0;
#endif
                            if (playerInfo != null && playerInfo.updateInfo.playerState == PlayerState.Room && ClientLevelStarted != null)
                            {
                                foreach (Action nextDel in ClientLevelStarted.GetInvocationList())
                                {
                                    try
                                    {
                                        nextDel?.Invoke();
                                    }
                                    catch (Exception e)
                                    {
                                        if (nextDel != null)
                                        {
                                            Plugin.log.Error($"Exception in {nextDel.Target.GetType()}.{nextDel.Method.Name} on client level started event: {e}");
                                        }
                                        else
                                        {
                                            Plugin.log.Error($"Exception on client level started event: {e}");
                                        }
                                    }
                                }
                            }

                            MessageReceived?.Invoke(msg);
                        }
                        break;

                        case CommandType.UpdatePlayerInfo:
                            break;

                        default:
                        {
                            MessageReceived?.Invoke(msg);
                        }
                        break;
                        }
                    };
                        break;

                    case NetIncomingMessageType.WarningMessage:
                        Plugin.log.Warn(msg.ReadString());
                        break;

                    case NetIncomingMessageType.ErrorMessage:
                        Plugin.log.Error(msg.ReadString());
                        break;

#if DEBUG
                    case NetIncomingMessageType.VerboseDebugMessage:
                    case NetIncomingMessageType.DebugMessage:
                        Plugin.log.Info(msg.ReadString());
                        break;

                    default:
                        Plugin.log.Info("Unhandled message type: " + msg.MessageType);
                        break;
#endif
                    }
                }

                networkClient.Recycle(_receivedMessages);
                _receivedMessages.Clear();
            }

            if (connected && networkClient.ConnectionsCount == 0)
            {
#if DEBUG
                Plugin.log.Info("Connection lost! Disconnecting...");
#endif
                Disconnect();

                MessageReceived?.Invoke(null);
            }

            if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && Input.GetKeyDown(KeyCode.F1))
            {
                GarbageCollector.GCMode = GarbageCollector.GCMode == GarbageCollector.Mode.Enabled ? GarbageCollector.Mode.Disabled : GarbageCollector.Mode.Enabled;
                Plugin.log.Notice($"Garbage collector {GarbageCollector.GCMode.ToString()}!");
            }
        }
Exemple #9
0
        public void Update()
        {
            if (networkClient.ReadMessages(_receivedMessages) > 0)
            {
                try
                {
                    if (_receivedMessages.Any(x => x.PeekByte() != (byte)CommandType.UpdateVoIPData))
                    {
                        float packetTime = (float)DateTime.UtcNow.Subtract(_lastPacketTime).TotalMilliseconds;
                        if (packetTime > 2f)
                        {
                            _averagePacketTimes.Add(packetTime);

                            if (_averagePacketTimes.Count > 150)
                            {
                                _averagePacketTimes.RemoveAt(0);
                            }

                            tickrate = (float)Math.Round(1000f / _averagePacketTimes.Where(x => x > 2f).Average(), 2);
                        }
                        _lastPacketTime = DateTime.UtcNow;
                    }

                    try
                    {
                        if (Config.Instance.SpectatorMode)
                        {
                            foreach (var lastPlayerHistoryUpdates in _receivedMessages.Where(x => x.MessageType == NetIncomingMessageType.Data && x.PeekByte() == (byte)CommandType.GetPlayerUpdates))
                            {
                                foreach (Action <NetIncomingMessage> nextDel in PlayerInfoUpdateReceived.GetInvocationList())
                                {
                                    try
                                    {
                                        lastPlayerHistoryUpdates.Position = 0;
                                        nextDel?.Invoke(lastPlayerHistoryUpdates);
                                    }
                                    catch (Exception e)
                                    {
                                        if (nextDel != null)
                                        {
                                            Plugin.log.Error($"Exception in {nextDel.Target.GetType()}.{nextDel.Method.Name} on update received event: {e}");
                                        }
                                        else
                                        {
                                            Plugin.log.Error($"Exception on update received event: {e}");
                                        }
                                    }
                                }
                                lastPlayerHistoryUpdates.Position = 0;
                            }
                        }
                    }catch (Exception e)
                    {
                        Plugin.log.Error("Unable to parse GetPlayerUpdates message! Exception: " + e);
                    }

                    try
                    {
                        NetIncomingMessage lastUpdate = _receivedMessages.LastOrDefault(x => x.MessageType == NetIncomingMessageType.Data && x.PeekByte() == (byte)CommandType.UpdatePlayerInfo);

                        if (lastUpdate != null)
                        {
                            _receivedMessages.RemoveAll(x => x.MessageType == NetIncomingMessageType.Data && x.PeekByte() == (byte)CommandType.UpdatePlayerInfo);

                            foreach (Action <NetIncomingMessage> nextDel in MessageReceived.GetInvocationList())
                            {
                                try
                                {
                                    lastUpdate.Position = 0;
                                    nextDel?.Invoke(lastUpdate);
                                }
                                catch (Exception e)
                                {
                                    if (nextDel != null)
                                    {
                                        Plugin.log.Error($"Exception in {nextDel.Target.GetType()}.{nextDel.Method.Name} on update received event: {e}");
                                    }
                                    else
                                    {
                                        Plugin.log.Error($"Exception on update received event: {e}");
                                    }
                                }
                            }
                            lastUpdate.Position = 0;
                        }
                    }catch (Exception e)
                    {
                        Plugin.log.Error("Unable to parse UpdatePlayerInfo message! Exception: " + e);
                    }

                    foreach (NetIncomingMessage msg in _receivedMessages)
                    {
                        switch (msg.MessageType)
                        {
                        case NetIncomingMessageType.StatusChanged:
                        {
                            NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte();

                            if (status == NetConnectionStatus.Connected && !connected)
                            {
                                connected = true;
                                ConnectedToServerHub?.Invoke();
                            }
                            else if (status == NetConnectionStatus.Disconnected && connected)
                            {
#if DEBUG
                                Plugin.log.Info("Disconnecting...");
#endif
                                Disconnect();

                                foreach (Action <NetIncomingMessage> nextDel in MessageReceived.GetInvocationList())
                                {
                                    try
                                    {
                                        nextDel?.Invoke(null);
                                    }
                                    catch (Exception e)
                                    {
                                        if (nextDel != null)
                                        {
                                            Plugin.log.Error($"Exception in {nextDel.Target.GetType()}.{nextDel.Method.Name} on message received event: {e}");
                                        }
                                        else
                                        {
                                            Plugin.log.Error($"Exception on message received event: {e}");
                                        }
                                    }
                                }
                            }
                            else if (status == NetConnectionStatus.Disconnected && !connected)
                            {
                                Plugin.log.Error("ServerHub refused connection! Reason: " + msg.ReadString());
                            }
                        }
                        break;

                        case NetIncomingMessageType.Data:
                        {
                            CommandType commandType = (CommandType)msg.PeekByte();

                            if (commandType == CommandType.Disconnect)
                            {
#if DEBUG
                                Plugin.log.Info("Disconnecting...");
#endif
                                Disconnect();

                                foreach (Action <NetIncomingMessage> nextDel in MessageReceived.GetInvocationList())
                                {
                                    try
                                    {
                                        msg.Position = 0;
                                        nextDel?.Invoke(msg);
                                    }
                                    catch (Exception e)
                                    {
                                        if (nextDel != null)
                                        {
                                            Plugin.log.Error($"Exception in {nextDel.Target.GetType()}.{nextDel.Method.Name} on message received event: {e}");
                                        }
                                        else
                                        {
                                            Plugin.log.Error($"Exception on message received event: {e}");
                                        }
                                    }
                                }

                                return;
                            }
                            else if (commandType == CommandType.SendEventMessage)
                            {
                                string header = msg.ReadString();
                                string data   = msg.ReadString();

#if DEBUG
                                Plugin.log.Info($"Received event message! Header=\"{header}\", Data=\"{data}\"");
#endif
                                foreach (Action <string, string> nextDel in EventMessageReceived.GetInvocationList())
                                {
                                    try
                                    {
                                        nextDel?.Invoke(header, data);
                                    }
                                    catch (Exception e)
                                    {
                                        if (nextDel != null)
                                        {
                                            Plugin.log.Error($"Exception in {nextDel.Target.GetType()}.{nextDel.Method.Name} on event message received event: {e}");
                                        }
                                        else
                                        {
                                            Plugin.log.Error($"Exception in {nextDel.Target.GetType()}.{nextDel.Method.Name} on event message received event: {e}");
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (MessageReceived != null)
                                {
                                    foreach (Action <NetIncomingMessage> nextDel in MessageReceived.GetInvocationList())
                                    {
                                        try
                                        {
                                            msg.Position = 0;
                                            nextDel?.Invoke(msg);
                                        }
                                        catch (Exception e)
                                        {
                                            if (nextDel != null)
                                            {
                                                Plugin.log.Error($"Exception in {nextDel.Target.GetType()}.{nextDel.Method.Name} on message received event: {e}");
                                            }
                                            else
                                            {
                                                Plugin.log.Error($"Exception on message received event: {e}");
                                            }
                                        }
                                    }
                                }
                            }


                            if (commandType == CommandType.JoinRoom)
                            {
                                msg.Position = 8;
                                if (msg.PeekByte() == 0 && ClientJoinedRoom != null)
                                {
                                    foreach (Action nextDel in ClientJoinedRoom.GetInvocationList())
                                    {
                                        try
                                        {
                                            nextDel?.Invoke();
                                        }
                                        catch (Exception e)
                                        {
                                            if (nextDel != null)
                                            {
                                                Plugin.log.Error($"Exception in {nextDel.Target.GetType()}.{nextDel.Method.Name} on client joined room event: {e}");
                                            }
                                            else
                                            {
                                                Plugin.log.Error($"Exception on client joined room event: {e}");
                                            }
                                        }
                                    }
                                }
                            }
                            else if (commandType == CommandType.StartLevel)
                            {
#if DEBUG
                                startNewDump = true;
                                packetsBuffer.Clear();
                                msg.Position = 8;
                                LevelOptionsInfo levelInfo = new LevelOptionsInfo(msg);
                                SongInfo         songInfo  = new SongInfo(msg);
                                List <byte>      buffer    = new List <byte>();
                                buffer.AddRange(levelInfo.ToBytes());
                                buffer.AddRange(HexConverter.ConvertHexToBytesX(songInfo.levelId));

                                Plugin.log.Info("LevelID: " + songInfo.levelId + ", Bytes: " + BitConverter.ToString(buffer.ToArray()));

                                packetsBuffer.Enqueue(buffer.ToArray());
                                msg.Position = 0;
#endif
                                if (playerInfo.playerState == PlayerState.Room)
                                {
                                    foreach (Action nextDel in ClientLevelStarted.GetInvocationList())
                                    {
                                        try
                                        {
                                            nextDel?.Invoke();
                                        }
                                        catch (Exception e)
                                        {
                                            if (nextDel != null)
                                            {
                                                Plugin.log.Error($"Exception in {nextDel.Target.GetType()}.{nextDel.Method.Name} on client level started event: {e}");
                                            }
                                            else
                                            {
                                                Plugin.log.Error($"Exception on client level started event: {e}");
                                            }
                                        }
                                    }
                                }
                            }
                        };
                            break;

                        case NetIncomingMessageType.WarningMessage:
                            Plugin.log.Warn(msg.ReadString());
                            break;

                        case NetIncomingMessageType.ErrorMessage:
                            Plugin.log.Error(msg.ReadString());
                            break;

#if DEBUG
                        case NetIncomingMessageType.VerboseDebugMessage:
                        case NetIncomingMessageType.DebugMessage:
                            Plugin.log.Info(msg.ReadString());
                            break;

                        default:
                            Plugin.log.Info("Unhandled message type: " + msg.MessageType);
                            break;
#endif
                        }
                        networkClient.Recycle(msg);
                    }
                }catch (Exception e)
                {
#if DEBUG
                    Plugin.log.Critical($"Exception on message received event: {e}");
#endif
                }
                _receivedMessages.Clear();
            }

            if (connected && networkClient.ConnectionsCount == 0)
            {
#if DEBUG
                Plugin.log.Info("Connection lost! Disconnecting...");
#endif
                Disconnect();

                foreach (Action <NetIncomingMessage> nextDel in MessageReceived.GetInvocationList())
                {
                    try
                    {
                        nextDel.Invoke(null);
                    }
                    catch (Exception e)
                    {
                        if (nextDel != null)
                        {
                            Plugin.log.Error($"Exception in {nextDel.Target.GetType()}.{nextDel.Method.Name} on message received event: {e}");
                        }
                        else
                        {
                            Plugin.log.Error($"Exception on message received event: {e}");
                        }
                    }
                }
            }
        }