Esempio n. 1
0
        /// <summary>
        /// Verlässt den Raum
        /// </summary>
        /// <param name="pGameId">Dei GameID des Raum's</param>
        public void LeaveRoom(string pGameId)
        {
            KnModule leaveRoom = _parentModule.CreateModule("LEAVE_ROOM");

            leaveRoom.Add("GAME_ID", pGameId);
            Send(leaveRoom);
        }
Esempio n. 2
0
        /// <summary>
        /// Betritt einen Raum
        /// </summary>
        /// <param name="pGameId">Die GameID des Raum's</param>
        public void JoinRoom(string pGameId)
        {
            KnModule joinRoom = _parentModule.CreateModule("JOIN_ROOM");

            joinRoom.Add("GAME_ID", pGameId);
            Send(joinRoom);
        }
Esempio n. 3
0
        public void ClickButton(string ControllerID)
        {
            KnModule voidController = _client._parentModule.CreateModule("VOID_CONTROLLER");

            voidController.Add("CONTROLLER_ID", long.Parse(ControllerID));
            GameServerClient.Send(voidController);
        }
Esempio n. 4
0
        /// <summary>
        /// Sendet eine Login-Instanz an den Server
        /// </summary>
        /// <param name="pUsername">Der Username der für den Login genutzer werden soll</param>
        /// <param name="pPassword">Das Passwort das für den Login genutzer werden soll</param>
        public void Login(string pUsername, string pPassword)
        {
            KnModule login = _parentModule.CreateModule("LOGIN");

            login.Add("USER_NAME", pUsername);
            login.Add("PASSWORD", pPassword);
            Send(login);
        }
Esempio n. 5
0
        private void Action(long action)
        {
            KnModule longController = GameServerClient.ParentModule.CreateModule("LONG_CONTROLLER");

            longController.Add("CONTROLLER_ID", _turnActionControllerId);
            longController.Add("LONG", action);
            GameServerClient.Send(longController);
        }
Esempio n. 6
0
        internal static GSClient FromModule(KnModule pModule, KnuddelsClient pClient)
        {
            Dictionary <string, object> keyValueDic = pModule.GetKeyValue();
            GSClient client = new GSClient()
            {
                _channel        = pModule.GetValue <string>("CHANNEL_NAME"),
                _client         = pClient,
                _gameId         = keyValueDic["gameId"].ToString(),
                _clientUser     = new ClientUser(pClient.ClientUser.Username, keyValueDic["oneTimePassword"].ToString()),
                _serverHost     = pClient.ServerHost,
                _serverPort     = int.Parse(keyValueDic["serverPort"].ToString()),
                _formToInvoke   = pClient.FormToInvoke,
                _windowToInvoke = pClient.WindowToInvoke
            };

            pClient.CardServerClients.Add(client.Channel, client);
            return(client);
        }
Esempio n. 7
0
        private void HandleIncomingData(KnModule data)
        {
            switch (data.Name)
            {
            case "CHANGE_PROTOCOL":
            case "PROTOCOL_CONFIRMED":
                if (data.Name.Equals("CHANGE_PROTOCOL"))
                {
                    _parentModule.ParseTree(data.GetValue <string>("PROTOCOL_DATA"));
                }

                if (OnConnectionStateChanged != null)
                {
                    OnConnectionStateChanged(this, new ConnectionStateChangedEventArgs(false, true));
                }
                break;

            case "LOGGIN_PROCESSED":
                if (!_loggedIn)
                {
                    if (data.GetValue <byte>("LOGGIN_RESULT") == _parentModule.GetValue("LOGGIN_RESULT", "LOGGED_IN"))
                    {
                        _loggedIn = true;
                        if (OnConnectionStateChanged != null)
                        {
                            OnConnectionStateChanged(this, new ConnectionStateChangedEventArgs(true, true));
                        }
                    }
                    else
                    {
                        if (OnConnectionStateChanged != null)
                        {
                            OnConnectionStateChanged(this, new ConnectionStateChangedEventArgs(false, true));
                        }
                    }
                }
                break;
            }

            if (OnModuleReceived != null)
            {
                OnModuleReceived(this, new ModuleReceivedEventArgs(data));
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Sendet eine Instanz der KnModule an den Server
 /// </summary>
 /// <param name="pModule">Die Instanz was zum Server gesendet werden soll.</param>
 public void Send(KnModule pModule)
 {
     try
     {
         byte[] arrayOfByte1 = _parentModule.WriteBytes(pModule);
         byte[] arrayOfByte2 = encode(arrayOfByte1.Length);
         byte[] arrayOfByte3 = new byte[arrayOfByte2.Length + arrayOfByte1.Length];
         Array.Copy(arrayOfByte2, 0, arrayOfByte3, 0, arrayOfByte2.Length);
         Array.Copy(arrayOfByte1, 0, arrayOfByte3, arrayOfByte2.Length, arrayOfByte1.Length);
         if (arrayOfByte3.Length == 0)
         {
             throw new IOException("z9.a(21815)");
         }
         else
         {
             _knDataStream.Write(arrayOfByte3, 0, arrayOfByte3.Length);
         }
     }
     catch
     {
         Disconnect();
     }
 }
Esempio n. 9
0
        private void Receive()
        {
            KnModule confirmProtocolHash = _parentModule.CreateModule("CONFIRM_PROTOCOL_HASH");

            confirmProtocolHash.Add("PROTOCOL_HASH", long.Parse(_parentModule.Hash));
            Send(confirmProtocolHash);

            while (_knSocket.Connected)
            {
                try
                {
                    KnModule received = _parentModule.Parse(decode(_knDataStream));
                    if (received != null)
                    {
                        if (_formToInvoke != null)
                        {
                            if (_formToInvoke.InvokeRequired)
                            {
                                _formToInvoke.Invoke((MethodInvoker) delegate
                                {
                                    HandleIncomingData(received);
                                });
                            }
                        }
                        else if (_windowToInvoke != null)
                        {
                            _windowToInvoke.Dispatcher.Invoke((MethodInvoker) delegate
                            {
                                HandleIncomingData(received);
                            });
                        }
                        else
                        {
                            HandleIncomingData(received);
                        }
                        _connected = true;
                    }
                }
                catch (Exception ex)
                {
                    _loggedIn = false;

                    if (OnConnectionStateChanged != null)
                    {
                        if (_formToInvoke != null)
                        {
                            if (_formToInvoke.InvokeRequired)
                            {
                                _formToInvoke.Invoke((MethodInvoker) delegate
                                {
                                    OnConnectionStateChanged(this, new ConnectionStateChangedEventArgs(false, false));
                                });
                            }
                        }
                        else if (_windowToInvoke != null)
                        {
                            _windowToInvoke.Dispatcher.Invoke((MethodInvoker) delegate
                            {
                                OnConnectionStateChanged(this, new ConnectionStateChangedEventArgs(false, false));
                            });
                        }
                        else
                        {
                            OnConnectionStateChanged(this, new ConnectionStateChangedEventArgs(false, false));
                        }
                    }
                    _client.CardServerClients.Remove(_channel);
                    if (_onGlobalException != null)
                    {
                        _onGlobalException(this, new GlobalExceptionEventArgs(ex, KDFModule.Networks));
                    }
                    Disconnect();
                }
            }
        }
Esempio n. 10
0
 /// <summary>
 /// Erstellt eine neue Instanz des Clients
 /// </summary>
 public GSClient()
 {
     _parentModule = KnModule.StartUp("1686426172;20;PROTOCOL_HASH;CONFIRM_PROTOCOL_HASH;PROTOCOL_CONFIRMED;PROTOCOL_DATA;CHANGE_PROTOCOL;;5;;20;;;9;;23;;:;;");
 }
Esempio n. 11
0
        void CardserverClient_OnModuleReceived(object sender, ModuleReceivedEventArgs e)
        {
            try
            {
                ArrayList fillTextLabels;
                ArrayList textLabelInfos;

                switch (e.Module.Name)
                {
                    #region LOGGIN_PROCESSED
                case "LOGGIN_PROCESSED":
                    if (GameServerClient.LoggedIn)
                    {
                        GameServerClient.JoinRoom();
                    }
                    break;

                    #endregion
                    #region OUT_OF_TURN_CONTROLS
                case "OUT_OF_TURN_CONTROLS":
                    foreach (KnModule regularButton in e.Module.GetValue <ArrayList>("REGULAR_BUTTON"))
                    {
                        string btnText = regularButton.GetValue <KnModule>("FULL_BUTTON_SETTINGS").GetValue <string>("TEXT");
                        if (btnText.Contains("Anmelden"))
                        {
                            _clickMsgRegister     = regularButton.GetValue <string>("CLICK_MSG");
                            _registrationPossible = true;
                            if (RestrationPossible != null)
                            {
                                RestrationPossible();
                            }
                        }
                        else if (btnText.Contains("Abmelden"))
                        {
                            _clickMsgUnregister   = regularButton.GetValue <string>("CLICK_MSG");
                            _registrationPossible = false;
                            GamsteRegistrationStatusChanged(true);
                            Console.WriteLine("[Info] Erfolgreich angemeldet");
                        }
                    }
                    break;

                    #endregion
                    #region TURN_CHANGES
                case "TURN_CHANGES":
                    #region FILL_TEXT_LABEL
                    fillTextLabels = e.Module.GetValue <ArrayList>("FILL_TEXT_LABEL");
                    textLabelInfos = e.Module.GetValue <ArrayList>("TEXT_LABEL");
                    if (fillTextLabels.Count != textLabelInfos.Count)
                    {
                        break;
                    }

                    for (int i = 0; i < fillTextLabels.Count; i++)
                    {
                        KnModule textLabel = (KnModule)fillTextLabels[i];
                        KnModule labelInfo = (KnModule)textLabelInfos[i];

                        string labelText = textLabel.GetValue <string>("TEXT");
                        if (labelText.StartsWith("TotalPot#"))
                        {
                            string potSize = labelText.Split('#')[1].Replace(".", ",");
                            if (potSize.StartsWith("$ "))
                            {
                                potSize = potSize.Substring(2);
                            }

                            _turnPot = double.Parse(potSize);
                            Console.WriteLine("[INFO] Aktueller Pot: " + _turnPot);
                        }
                        else if (labelText.StartsWith("Deine Tickets"))
                        {
                            ClientPlayer.Tickets = int.Parse(labelText.Split(' ')[2]);
                            Console.WriteLine("[INFO] Eigene Tickets: " + ClientPlayer.Tickets);
                        }
                        else if (labelText.Contains("$ ") && labelText.Contains(".") && !labelText.Contains("#"))
                        {
                            labelText = labelText.Substring(2).Replace(".", ",");

                            double.TryParse(labelText, out _lastMoney);
                        }
                        else if (labelText.Contains("#$ "))
                        {
                            string[] splitText = labelText.Split('#');

                            string playerStack = splitText[1].Replace(".", ",");
                            if (playerStack.StartsWith("$ "))
                            {
                                playerStack = playerStack.Substring(2);
                            }

                            var pokerPlayer    = GetPlayerFromId(textLabel.GetValue <short>("COMPONENT_ID"));
                            var playerPosition = labelInfo.GetValue <KnModule>("BASE_COMPONENT").GetValue <KnModule>("POSITION");
                            if (pokerPlayer != null)
                            {
                                pokerPlayer.Stack = double.Parse(playerStack);
                            }
                            else
                            {
                                pokerPlayer = new PokerPlayer()
                                {
                                    Username      = splitText[0],
                                    Stack         = double.Parse(playerStack),
                                    Position      = new System.Drawing.Point(playerPosition.GetValue <short>("POS_X"), playerPosition.GetValue <short>("POS_Y")),
                                    ComponentId   = textLabel.GetValue <short>("COMPONENT_ID"),
                                    TablePosition = PlayerSeatFromPosition(new System.Drawing.Point(playerPosition.GetValue <short>("POS_X"), playerPosition.GetValue <short>("POS_Y")), _isNineTable)
                                };

                                if (splitText[0] == _client.ClientUser.Username)
                                {
                                    ClientPlayer = pokerPlayer;
                                }
                                else
                                {
                                    Players.Add(pokerPlayer);
                                }
                            }
                            Console.WriteLine("[TableInfo] Update Player | Username: "******", Stack: " + pokerPlayer.Stack);
                        }
                    }
                    #endregion

                    #region ZIMAGE
                    ArrayList zImageList = e.Module.GetValue <ArrayList>("ZIMAGE");
                    foreach (KnModule zImage in zImageList)
                    {
                        string   imgName = zImage.GetValue <string>("IMAGE").Split('/')[1];
                        KnModule imgPos  = zImage.GetValue <KnModule>("BASE_COMPONENT").GetValue <KnModule>("POSITION");

                        int x = imgPos.GetValue <short>("POS_X");
                        int y = imgPos.GetValue <short>("POS_Y");

                        if (imgName.Contains("timecircle_"))
                        {
                            if (y > 300)
                            {
                                y += 45;
                            }
                            else
                            {
                                y -= 52;
                            }
                        }
                        else
                        {
                            //Holecards
                            if (Hand.Count == 2 && HoleCards.Count < 5)
                            {
                                PokerCard cardReceived = CardParser.Parse(imgName);
                                HoleCards.Add(cardReceived);
                                //Flop
                                if (x == -1 && y == 2 || x == 63 && y == 2 || x == 127 && y == 2)
                                {
                                    if (Flop != null && HoleCards.Count == 3)
                                    {
                                        Flop(HoleCards);
                                    }
                                }
                                //Turn
                                else if (x == 191 && y == 2)
                                {
                                    if (Turn != null)
                                    {
                                        Turn(cardReceived);
                                    }
                                }
                                //River
                                else if (x == 255 && y == 2)
                                {
                                    if (River != null)
                                    {
                                        River(cardReceived);
                                    }
                                }
                            }
                            //Hand
                            else if (Hand.Count < 2)
                            {
                                Hand.Add(CardParser.Parse(imgName));
                                if (HandReceived != null && Hand.Count == 2)
                                {
                                    HandReceived(Hand);
                                }
                            }
                        }

                        if (ActivePlayer != null)
                        {
                            if (imgName.Contains("action_call"))
                            {
                                Console.WriteLine("[TableInfo][Action] " + ActivePlayer.Username + " callt (" + _lastMoney + ")");
                            }
                            else if (imgName.Contains("action_check"))
                            {
                                Console.WriteLine("[TableInfo][Action] " + ActivePlayer.Username + " checkt");
                            }
                            else if (imgName.Contains("action_bet"))
                            {
                                Console.WriteLine("[TableInfo][Action] " + ActivePlayer.Username + " bet (" + _lastMoney + ")");
                                ActivePlayer.Bet = _lastMoney;
                            }
                            else if (imgName.Contains("action_fold"))
                            {
                                Console.WriteLine("[TableInfo][Action] " + ActivePlayer.Username + " foldet");
                                ActivePlayer.Folded = true;
                            }
                            else if (imgName.Contains("action_raise"))
                            {
                                Console.WriteLine("[TableInfo][Action] " + ActivePlayer.Username + " raised (" + _lastMoney + ")");
                                ActivePlayer.Bet = _lastMoney;
                            }
                            else if (imgName.Contains("action_bigblind"))
                            {
                                Console.WriteLine("[TableInfo][Action] " + ActivePlayer.Username + " set bigblind");
                            }
                            else if (imgName.Contains("action_smallblind"))
                            {
                                Console.WriteLine("[TableInfo][Action] " + ActivePlayer.Username + " set smallblind");
                            }
                            else if (imgName.Contains("action_sitout"))
                            {
                                if (y > 300)
                                {
                                    y += 45;
                                }
                                else
                                {
                                    y -= 52;
                                }
                                ActivePlayer = GetPlayerFromPosition(x, y);
                                if (ActivePlayer != null)
                                {
                                    Console.WriteLine("[TableInfo][Action] " + ActivePlayer.Username + " sitout");
                                }
                            }
                        }
                    }
                    #endregion
                    break;

                    #endregion
                    #region ADD_TO_TEXT_LOG
                case "ADD_TO_TEXT_LOG":
                    string logText = e.Module.GetValue <string>("TEXT");
                    if (logText.Contains("|/serverpp \"|/w \""))
                    {
                        string nickname = logText.Substring(logText.IndexOf('h'));
                        nickname     = nickname.Substring(1, nickname.IndexOf("|/serverpp") - 1);
                        ActivePlayer = GetPlayerFromName(nickname);
                        if (ActivePlayer != null)
                        {
                            Console.WriteLine("[Info] Active Player " + ActivePlayer.Username);
                        }

                        Console.WriteLine("[Info-Log] " + logText);
                    }
                    break;

                    #endregion
                    #region ROOM_INIT
                case "ROOM_INIT":
                    Players.Clear();
                    _isNineTable = !e.Module.GetValue <string>("CHANNEL_NAME").Contains("6max");

                    fillTextLabels = e.Module.GetValue <ArrayList>("FILL_TEXT_LABEL");
                    textLabelInfos = e.Module.GetValue <ArrayList>("TEXT_LABEL");
                    if (fillTextLabels.Count != textLabelInfos.Count)
                    {
                        break;
                    }

                    for (int i = 0; i < fillTextLabels.Count; i++)
                    {
                        KnModule textLabel = (KnModule)fillTextLabels[i];
                        KnModule labelInfo = (KnModule)textLabelInfos[i];

                        string labelText = textLabel.GetValue <string>("TEXT");
                        Console.WriteLine(labelText);
                        if (labelText.Contains("#$ ") || labelText.EndsWith("₭"))
                        {     //Nickname
                            if (!labelText.Contains("#"))
                            {
                                break;
                            }

                            string[] splitText = labelText.Split('#');

                            if (splitText.Contains("TotalPot"))
                            {
                                continue;
                            }

                            string playerStack = splitText[1].Replace(".", ",");
                            if (playerStack.StartsWith("$ "))
                            {
                                playerStack = playerStack.Substring(2);
                            }
                            else
                            {
                                playerStack = playerStack.Split(' ')[0];
                            }

                            var playerPosition = labelInfo.GetValue <KnModule>("BASE_COMPONENT").GetValue <KnModule>("POSITION");
                            var pokerPlayer    = new PokerPlayer()
                            {
                                Username      = splitText[0],
                                Position      = new System.Drawing.Point(playerPosition.GetValue <short>("POS_X"), playerPosition.GetValue <short>("POS_Y")),
                                Stack         = double.Parse(playerStack),
                                ComponentId   = textLabel.GetValue <short>("COMPONENT_ID"),
                                TablePosition = PlayerSeatFromPosition(new System.Drawing.Point(playerPosition.GetValue <short>("POS_X"), playerPosition.GetValue <short>("POS_Y")), _isNineTable)
                            };

                            if (splitText[0] == _client.ClientUser.Username)
                            {
                                ClientPlayer = pokerPlayer;
                            }
                            else
                            {
                                Players.Add(pokerPlayer);
                            }
                        }
                        else if (labelText.StartsWith("#Gewinne:#"))
                        {
                            string[] prices = labelText.Split(new string[] { "#" }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (string price in prices)
                            {
                                Console.WriteLine(price);
                            }
                        }
                    }
                    CalcPositions();
                    Console.WriteLine("[TableInfo] Players: ");
                    foreach (PokerPlayer player in Players)
                    {
                        Console.WriteLine("\t{ Username: "******", Stack: " + player.Stack + ", X: " + player.Position.X + ", Y: " + player.Position.Y + " }");
                    }
                    break;

                    #endregion
                    #region OUT_OF_GAME_FLEXFRAME
                case "OUT_OF_GAME_FLEXFRAME":
                    //Hier wird ein Inagme-Pop-Up angezeigt

                    string text = e.Module.GetValue <string>("TEXT").ToLower();
                    //Keine Anmeldung möglich
                    if (text.Contains("du kannst dich nicht anmelden"))
                    {
                    }

                    //Du hast das Spiel als Xter beendet / gewonnen
                    //Punktzahl
                    //Gewinn
                    //Knuddels
                    //Tickets
                    else if (text.Contains("punkte"))
                    {
                    }
                    break;

                    #endregion
                    #region DIRECT_CONTROLS
                case "DIRECT_CONTROLS":
                    long CLICK_BET_INCREMENT = e.Module.GetValue <KnModule>("CLICK_BET_INCREMENT").GetValue <long>("MONEY_AMOUNT");
                    long CALL_DISPLAY_AMOUNT = e.Module.GetValue <KnModule>("CALL_DISPLAY_AMOUNT").GetValue <long>("MONEY_AMOUNT");
                    long MIN_BET_AMOUNT      = e.Module.GetValue <KnModule>("MIN_BET_AMOUNT").GetValue <long>("MONEY_AMOUNT");
                    long MAX_BET_AMOUNT      = e.Module.GetValue <KnModule>("MAX_BET_AMOUNT").GetValue <long>("MONEY_AMOUNT");
                    long SELECTED_BET_AMOUNT = e.Module.GetValue <KnModule>("SELECTED_BET_AMOUNT").GetValue <long>("MONEY_AMOUNT");
                    byte BET_TYPE            = e.Module.GetValue <byte>("BET_TYPE"); //KP ?
                    bool MAX_IS_ALLIN        = e.Module.GetValue <bool>("MAX_IS_ALLIN");

                    _turnActionControllerId = e.Module.GetValue <long>("CONTROLLER_ID");
                    _turnCallAmount         = e.Module.GetValue <KnModule>("CALL_AMOUNT").GetValue <long>("MONEY_AMOUNT");
                    _turnMinBetAmount       = e.Module.GetValue <KnModule>("MIN_BET_AMOUNT").GetValue <long>("MONEY_AMOUNT");
                    //_turnPot
                    //_turnPlayerStack

                    break;

                    #endregion
                    #region SIT_OUT_CONTROLS
                case "SIT_OUT_CONTROLS":
                    ArrayList sitOutCheckBoxList = e.Module.GetValue <ArrayList>("SIT_OUT_CHECKBOX");
                    if (sitOutCheckBoxList == null || sitOutCheckBoxList.Count <= 0)
                    {
                        break;
                    }

                    KnModule sitOutCheckBox = (KnModule)sitOutCheckBoxList[0];
                    if (sitOutCheckBox.GetValue <long>("SIT_OUT_STATE") == 0)
                    {
                        _sitOutId = long.Parse(sitOutCheckBox.GetValue <KnModule>("DISABLE_MSG").GetValue <string>("CLICK_MSG"));
                        _isSitout = true;
                    }
                    else
                    {
                        _sitOutId = long.Parse(sitOutCheckBox.GetValue <KnModule>("ENABLE_MSG").GetValue <string>("CLICK_MSG"));
                        _isSitout = false;
                    }
                    break;

                    #endregion
                default:
                    Debug.WriteLine("Unknown: " + e.Module.Name);
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
        }
 /// <summary>
 /// Initialisiert eine neue Instanz der ModuleReceivedEventArgs-Klasse.
 /// </summary>
 /// <param name="module">Gibt die empfangene Instanz der KnModule Klasse an</param>
 public ModuleReceivedEventArgs(KnModule module)
 {
     _module = module;
 }
Esempio n. 13
0
        internal void HandleIncomingDataSavely(string data)
        {
            if (data != null)
            {
                try
                {
                    object   _object = null;
                    string   _type   = null;
                    string[] packets = data.Split(_nullChar);
                    string   packeID = packets[0];
                    if (OnDataReceived != null)
                    {
                        OnDataReceived(this, new KDF.ClientEventArgs.DataReceivedEventArgs(data));
                    }

                    switch (packeID)
                    {
                    //-------------------------------------------------------
                    //----------------------Systembezogen--------------------
                    //-------------------------------------------------------
                    case "(":
                        if (OnConnectionStateChanged != null)
                        {
                            OnConnectionStateChanged(this, new ConnectionStateChangedEventArgs(false, true));
                        }
                        _object = new ConnectionStateChangedEventArgs(false, true);
                        _type   = "ConnectionStateChanged";
                        UpdateModule();
                        break;

                    //Wird direkt von der Connection-Klasse verarbeitet
                    case "5":
                        _systemButler = packets[1];
                        break;

                    case ",":
                        Send("h" + _nullChar + (data.Length == 1 ? "-" : data.Substring(2)));
                        break;

                    //-------------------------------------------------------
                    //-----------------------Nachrichten---------------------
                    //-------------------------------------------------------
                    case "e":

                        PublicMessage publicMessage = new PublicMessage(packets, _clientUser.SelectedChannel.Name);
                        if (OnPublicMessageReceived != null)
                        {
                            OnPublicMessageReceived(this, new PublicMessageReceivedEventArgs(publicMessage));
                        }
                        _object = new PublicMessage(packets, _clientUser.SelectedChannel.Name);
                        _type   = "PublicMessageReceived";
                        //if (_guiConnector.Active)
                        //    _guiConnector.AddLineToHistory(publicMessage, true);
                        break;

                    case "r":

                        PrivateMessage p = new PrivateMessage(packets, _clientUser.SelectedChannel.Name);
                        if (!_loggedIn && packets[1] == "James")
                        {
                            _loggedIn = true;
                            if (OnConnectionStateChanged != null)
                            {
                                OnConnectionStateChanged(this, new ConnectionStateChangedEventArgs(true, true));
                            }
                        }
                        if (OnPrivateMessageReceived != null)
                        {
                            OnPrivateMessageReceived(this, new PrivateMessageReceivedEventArgs(p));
                        }
                        _object = p;
                        _type   = "PrivateMessageReceived";

                        break;

                    case "t":

                        PublicMessage publicMessageF = new PublicMessage(packets, _clientUser.SelectedChannel.Name);
                        if (OnPublicMessageReceived != null)
                        {
                            OnPublicMessageReceived(this, new PublicMessageReceivedEventArgs(publicMessageF));
                        }
                        _object = new PublicMessage(packets, _clientUser.SelectedChannel.Name);
                        _type   = "PublicFunctionReceived";
                        //if (_guiConnector.Active)
                        //    _guiConnector.AddLineToHistory(publicMessageF, true);
                        break;

                    //-------------------------------------------------------
                    //-----------------------Channelbezogen------------------
                    //-------------------------------------------------------
                    case "b":
                        if (OnGlobalChannelListReceived != null)
                        {
                            OnGlobalChannelListReceived(this, new GlobalChannelListReceivedEventArgs(_parser.ParseGlobalChannelList(data)));
                        }
                        _object = _parser.ParseGlobalChannelList(data);
                        _type   = "GlobalChannelListReceived";
                        break;

                    case "a":
                        System.Diagnostics.Debug.WriteLine(data.Replace("\0", "\\0"));
                        Channel joinedChannel = _parser.ParseChannel(data, false);
                        if (!this._clientUser.OnlineChannels.ContainsKey(joinedChannel.Name))
                        {
                            this._clientUser.OnlineChannels.Add(joinedChannel.Name, joinedChannel);
                        }
                        else
                        {
                            this._clientUser.OnlineChannels[joinedChannel.Name] = joinedChannel;
                        }
                        if (OnChannelJoined != null)
                        {
                            OnChannelJoined(this, new ChannelJoinedEventArgs(joinedChannel));
                        }
                        ChangeSelectedChannel(joinedChannel.Name);
                        _object = joinedChannel;
                        _type   = "ChannelJoined";
                        //if (!_guiConnector.Active)
                        //    _guiConnector.Activate(joinedChannel);
                        break;

                    case "d":
                        _clientUser.OnlineChannels.Remove(packets[1]);
                        Channel joined = new Channel(packets[2]);
                        _clientUser.OnlineChannels.Add(packets[2], joined);
                        _clientUser.SelectedChannel = joined;
                        _object = packets[1] + "|" + packets[2];
                        _type   = "ChannelSwitched";
                        //Console.WriteLine(_object.ToString());
                        //if (_guiConnector.Active)
                        //    _guiConnector.DeleteChannel(packets[1]);
                        break;

                    case "1":
                        Channel changedChannel = _parser.ParseChannel(data, true);
                        _clientUser.OnlineChannels[changedChannel.Name] = changedChannel;
                        if (OnChannelChangedLayout != null)
                        {
                            OnChannelChangedLayout(this, new ChannelChangedLayoutEventArgs(changedChannel));
                        }
                        _object = changedChannel;
                        _type   = "ChannelChangedLayout";
                        break;

                    case "j":
                        if (packets[2] != "pics/-")
                        {
                            _clientUser.OnlineChannels[packets[1]].BackgroundImage = packets[3];
                        }
                        if (OnChannelBackGroundChanged != null)
                        {
                            OnChannelBackGroundChanged(this, new ChannelBackGroundChangedEventArgs(packets[2], packets[1]));
                        }
                        _object = new ChannelBackGroundChangedEventArgs(packets[2], packets[1]);
                        _type   = "ChannelBackgroundChanged";
                        break;

                    //-------------------------------------------------------
                    //-----------------------Userbezogen---------------------
                    //-------------------------------------------------------
                    case "u":
                        UserList receivedUserList = _parser.ParseUserList(data);
                        _clientUser.OnlineChannels[receivedUserList.OwnerChannel].UserList = receivedUserList;
                        if (OnUserListReceived != null)
                        {
                            OnUserListReceived(this, new UserListReceivedEventArgs(receivedUserList));
                        }
                        _object = receivedUserList;
                        _type   = "UserListReceived";
                        //if (_guiConnector.Active)
                        //    _guiConnector.AddUserList(_clientUser.OnlineChannels[receivedUserList.OwnerChannel]);
                        break;

                    case ".":
                        _clientUser.ByNames.AddRange(packets);
                        _clientUser.ByNames.RemoveAt(0);
                        _object = _clientUser.ByNames;
                        _type   = "ByNamesReceived";
                        break;

                    case "l":

                        ChannelUser channelUser = _parser.ParseUser(data);
                        if (channelUser.ChannelJoined == null || channelUser.ChannelJoined == "-")
                        {
                            channelUser.ChannelJoined = _clientUser.SelectedChannel.Name;
                        }
                        _clientUser.OnlineChannels[channelUser.ChannelJoined].UserList.ChannelUserList.Add(channelUser);
                        if (OnUserJoinedChannel != null)
                        {
                            OnUserJoinedChannel(this, new UserJoinedChannelEventArgs(channelUser));
                        }
                        _object = channelUser;
                        _type   = "UserJoinedChannel";
                        //if (_guiConnector.Active)
                        //    _guiConnector.AddUserToUserList(channelUser);

                        break;

                    case "w":

                        UserLeftChannel userLeftChannel = _parser.ParseUserLeftChannel(packets);
                        if (userLeftChannel.ChannelLeft == null || userLeftChannel.ChannelLeft == "-")
                        {
                            userLeftChannel.ChannelLeft = _clientUser.SelectedChannel.Name;
                        }
                        _clientUser.OnlineChannels[userLeftChannel.ChannelLeft].UserList.RemoveByName(userLeftChannel.Name);
                        if (OnUserLeftChannel != null)
                        {
                            OnUserLeftChannel(this, new UserLeftChannelEventArgs(userLeftChannel));
                        }
                        _object = userLeftChannel;
                        _type   = "UserLeftChannel";
                        //if (_guiConnector.Active)
                        //    _guiConnector.RemoveUserFromUserList(userLeftChannel);
                        break;

                    case "m":
                        UserListImage userListImageToAdd = _parser.ParseUserListImage(packets);
                        _clientUser.OnlineChannels[userListImageToAdd.Channel].UserList.GetByName(userListImageToAdd.User).UserListImages.Add(userListImageToAdd.Image);
                        if (OnChangeUserListImage != null)
                        {
                            OnChangeUserListImage(this, new ChangeUserListImageEventArgs(userListImageToAdd, true));
                        }
                        _object = new ChangeUserListImageEventArgs(userListImageToAdd, true);
                        _type   = "ChangeUserListImage";
                        break;

                    case "z":
                        UserListImage userListImageToRemove = _parser.ParseUserListImage(packets);
                        if (OnChangeUserListImage != null)
                        {
                            OnChangeUserListImage(this, new ChangeUserListImageEventArgs(userListImageToRemove, false));
                        }
                        _object = new ChangeUserListImageEventArgs(userListImageToRemove, false);
                        _type   = "ChangeUserListImage";
                        break;

                    //-------------------------------------------------------
                    //------------------------Sonstiges----------------------
                    //-------------------------------------------------------
                    case "x":
                        if (OnOpenBrowserWindow != null)
                        {
                            OnOpenBrowserWindow(this, new OpenBrowserWindowEventArgs(packets[1]));
                        }
                        _object = packets[1];
                        _type   = "OpenBrowserWindow";
                        break;

                    case "k":
                        if (!_loggedIn && (packets.Length >= 34 || data.Contains("Applet")))
                        {
                            LoginFailedEventArgs lfe = new LoginFailedEventArgs(LoginFailReason.Unknown);

                            if (data.Contains("Channellogin nicht möglich"))
                            {
                                if (data.Contains("_Unsichtbare Channels_"))
                                {
                                    lfe = new LoginFailedEventArgs(LoginFailReason.ChannelDoesntExist);
                                }
                                else
                                {
                                    lfe = new LoginFailedEventArgs(LoginFailReason.UserDoesntMeetChannelRestrictions);
                                }
                            }
                            else if (data.Contains("Der Channel"))
                            {
                                lfe = new LoginFailedEventArgs(LoginFailReason.ChannelDoesntExist);
                            }
                            else if (data.Contains("Falsches Passwort"))
                            {
                                lfe = new LoginFailedEventArgs(LoginFailReason.WrongUsernameOrPassword);
                            }
                            else if (data.Contains("Nick Gesperrt"))
                            {
                                //Admin
                                string admin = data.Substring(data.IndexOf("den Admin ") + 10);
                                admin = admin.Substring(0, admin.IndexOf(" als Ansprechpartner per /m"));
                                //Grund
                                string reason = data.Substring(data.IndexOf("_:#") + 3);
                                reason = reason.Substring(0, reason.IndexOf("##Bei Rückfragen"));
                                //Sperrzeit
                                string duration = "Unknown";
                                if (data.Contains("_permanent gesperrt_"))
                                {
                                    duration = "Permanent";
                                }
                                lfe = new LoginFailedEventArgs(LoginFailReason.UserLocked, reason, admin, duration);
                            }
                            else if (data.Contains("Applet"))
                            {
                                lfe = new LoginFailedEventArgs(LoginFailReason.AppletTooOld);
                            }
                            else if (data.Contains("maximal"))
                            {
                                lfe = new LoginFailedEventArgs(LoginFailReason.ChannelIsFull);
                            }
                            else if (data.Contains("Internetzugang") || data.Contains("Zugang gesperrt"))
                            {
                                lfe = new LoginFailedEventArgs(LoginFailReason.IPLock);
                            }
                            if (OnLoginFailed != null)
                            {
                                OnLoginFailed(this, lfe);
                            }
                            _object = lfe;
                            _type   = "LoginFailed";
                        }

                        _object = new WindowOpenedEventArgs(packets[1].Replace("õf", ""), data, new HelperClasses.Parser.Popup.PopupParser(data));
                        if (OnWindowOpened != null)
                        {
                            OnWindowOpened(this, (WindowOpenedEventArgs)_object);
                        }
                        _type = "WindowOpened";
                        break;

                    case ":":
                        if (packets.Length > 2 && packets[2].Contains("PROTOCOL_HASH"))
                        {
                            Console.WriteLine("Empfange aktuelles Protokoll");
                            SetupModule(packets[2]);
                        }


                        if (_parentModule != null)
                        {
                            KnModule receivedModule = _parentModule.Parse(data);

                            if (OnChatComponentCommandReceived != null)
                            {
                                OnChatComponentCommandReceived(this, new ChatComponentReceivedEventArgs(receivedModule));
                            }


                            switch (receivedModule.Name)
                            {
                            case "MODULE_INIT":
                                if (receivedModule.GetKeyValue().ContainsKey("serverPort"))
                                {
                                    if (OnCardServerConnectionEstablished != null)
                                    {
                                        OnCardServerConnectionEstablished(this, new GameServerConnectionEventArgs(GameServer.GSClient.FromModule(receivedModule, this)));
                                    }
                                }
                                break;
                            }

                            _object = receivedModule;
                            _type   = "ChatComponentReceived";
                        }
                        break;

                    //Noch nicht implementiert
                    case "q": _object = data; _type = "NotImplemented"; break;

                    case "+": _object = data; _type = "NotImplemented"; break;

                    case ";": _object = data; _type = "NotImplemented"; break;

                    case "6": _object = data; _type = "NotImplemented"; break;

                    case "!":
                        _clientUser.OnlineChannels.Remove(packets[1]);
                        if (_clientUser.SelectedChannel.Name == packets[1])
                        {
                            _clientUser.SelectedChannel = null;
                        }
                        if (_clientUser.OnlineChannels.Count < 1)
                        {
                            _loggedIn = false;
                        }
                        else
                        {
                            _clientUser.SelectedChannel = _clientUser.OnlineChannels.Last().Value;
                        }
                        break;

                    default:
                        Console.WriteLine(data);
                        break;
                    }
                    if (OnObjectFormed != null)
                    {
                        OnObjectFormed(this, new ObjectFormedEventArgs(_type, _object));
                    }
                }
                catch (WrongTokenException ex)
                {
                    if (OnGlobalException != null)
                    {
                        OnGlobalException(this, new GlobalExceptionEventArgs(ex, KDFModule.Parsing));
                    }
                }
            }
 /// <summary>
 /// Initialisiert eine neue Instanz der ChatComponentCommandReceivedEventArgs-Klasse.
 /// </summary>
 /// <param name="data">Gibt das empfangene :-Token an</param>
 public ChatComponentReceivedEventArgs(KnModule module)
 {
     _module = module;
 }