コード例 #1
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));
                    }
                }
            }
コード例 #2
0
 void _client_OnChannelBackGroundChanged(object sender, ChannelBackGroundChangedEventArgs e)
 {
     tbxLog.AppendText(string.Format("The channel '{0}' got a new background\r\n", e.ChannelName));
 }