Exemplo n.º 1
0
 private void Connection_ReceivedLogin(object sender, LoginEventArgs e)
 {
     if (e.Error == LoginErrors.None)
         IsLoggedIn = true;
     WriteLine("Login request was answered with error: " + EnumName(e.Error));
 }
Exemplo n.º 2
0
 private void Shitchat_ReceivedLogin(object sender, LoginEventArgs e)
 {
     
 }
Exemplo n.º 3
0
        private void OnReceived_Async(object sender, SocketAsyncEventArgs e)
        {
            if (e.SocketError != SocketError.Success)
            {
                Disconnect("Probably expected disconnection");
            }

            if (e.BytesTransferred == 0)
            {
                Disconnect("Probably expected disconnection");
            }

            using (Packet packet = new Packet(e.BufferList[0].Array, e.BytesTransferred))
            {
                if (packet.Valid)
                {
                    EventArgs eArgs = new EventArgs();

                    if (packet.PacketType == PacketTypes.Login)
                    {
                        eArgs = new LoginEventArgs();
                        LoginEventArgs lArgs = eArgs as LoginEventArgs;

                        lArgs.Error = (LoginErrors)Enum.Parse(typeof(LoginErrors), packet.Pars[0]);
                    }
                    else if (packet.PacketType == PacketTypes.Register)
                    {
                        eArgs = new RegisterEventArgs();
                        RegisterEventArgs rArgs = eArgs as RegisterEventArgs;

                        rArgs.Error = (RegisterErrors)Enum.Parse(typeof(RegisterErrors), packet.Pars[0]);
                    }
                    else if (packet.PacketType == PacketTypes.Message)
                    {
                        eArgs = new MessageEventArgs();
                        MessageEventArgs msgArgs = eArgs as MessageEventArgs;

                        msgArgs.Type = (MessageTypes)Enum.Parse(typeof(MessageTypes), packet.Pars[0]);
                        msgArgs.Error = (MessageErrors)Enum.Parse(typeof(MessageErrors), packet.Pars[1]);
                        msgArgs.Pars = new string[packet.Pars.Length - 2];
                        if (packet.Pars.Length > 2)
                        {
                            Array.Copy(packet.Pars, 2, msgArgs.Pars, 0, packet.Pars.Length - 2);
                        }
                    }
                    else if (packet.PacketType == PacketTypes.Command)
                    {
                        eArgs = new CommandEventArgs();
                        CommandEventArgs cArgs = eArgs as CommandEventArgs;

                        cArgs.Type = (Commands)Enum.Parse(typeof(Commands), packet.Pars[0]);
                        cArgs.Error = (CommandErrors)Enum.Parse(typeof(CommandErrors), packet.Pars[1]);

                        if (cArgs.Type == Commands.AccountList)
                        {
                            eArgs = new AccountListEventArgs();
                            AccountListEventArgs olArgs = eArgs as AccountListEventArgs;

                            olArgs.Error = (AccountListErrors)Enum.Parse(typeof(AccountListErrors), packet.Pars[1]);

                            List<Account> accounts = new List<Account>();
                            if (packet.Pars != null)
                            {
                                for (int i = 2; i < packet.Pars.Length; i++)
                                {
                                    string username = packet.Pars[i++];
                                    string userType = packet.Pars[i++];
                                    bool isFriend = bool.Parse(packet.Pars[i++]);
                                    bool isOnline = bool.Parse(packet.Pars[i++]);

                                    List<string> channels = new List<string>();
                                    while (packet.Pars[i] != ";" && i < packet.Pars.Length)
                                    {
                                        channels.Add(packet.Pars[i]);
                                        i++;
                                    }

                                    accounts.Add(new Account(username, (AccountTypes)Enum.Parse(typeof(AccountTypes), userType, true), isFriend, isOnline, channels));
                                }
                            }

                            olArgs.List = accounts.ToArray();
                        }
                        else
                        {
                            cArgs.Pars = new string[packet.Pars.Length - 2];
                            if (packet.Pars.Length > 2)
                            {
                                Array.Copy(packet.Pars, 2, cArgs.Pars, 0, packet.Pars.Length - 2);
                            }
                        }
                    }
                    else if (packet.PacketType == PacketTypes.Version)
                    {
                        eArgs = new CommandEventArgs();

                        CommandEventArgs cArgs = eArgs as CommandEventArgs;
                        cArgs.Type = Commands.Version;

                        if (packet.Pars[0] == "FAIL")
                        {
                            Disconnect("Old Version");
                            cArgs.Error = CommandErrors.OldVersion;
                        }
                        else
                        {
                            cArgs.Error = CommandErrors.None;
                        }
                    }
                    else if (packet.PacketType == PacketTypes.Voice)
                    {
                        //nothing here :(
                    }
                    else if (packet.PacketType == PacketTypes.ConnectionUpdate)
                    {
                        Packet returnPacket = new Packet(PacketTypes.ConnectionUpdate, "DummyPar");
                        socket.Send(returnPacket.Data);
                    }

                    if (syncContext != null && eArgs.GetType() != typeof(EventArgs))
                    {
                        syncContext.Post(new SendOrPostCallback(OnReceived_Sync), eArgs);
                    }
                    else
                    {
                        OnReceived_Sync(eArgs);
                    }
                }
            }

            SocketAsyncEventArgs seArgs = new SocketAsyncEventArgs();
            seArgs.BufferList = new List<ArraySegment<byte>> { new ArraySegment<byte>(new byte[1000]) };
            seArgs.Completed += new EventHandler<SocketAsyncEventArgs>(OnReceived_Async);

            if (!socket.ReceiveAsync(seArgs))
                Disconnect();
        }
Exemplo n.º 4
0
 static void shitchat_ReceivedLogin(object sender, LoginEventArgs e)
 {
     if (e.Error == LoginErrors.None)
     {
         Console.WriteLine("Successfully logged in as {0}", username);
         loggedIn = true;
     }
     else if (e.Error == LoginErrors.InvalidSyntax)
     {
         Console.WriteLine("You either have the wrong amount of parameters, or the username or password contains other than letters and digits.");
     }
     else if (e.Error == LoginErrors.NonExistent)
     {
         Console.WriteLine("The account you try to login to doesn't exist.");
     }
     else if (e.Error == LoginErrors.WrongPassword)
     {
         Console.WriteLine("The wrong password was entered.");
     }
     else if (e.Error == LoginErrors.Banned)
     {
         Console.WriteLine("The account has been banned and can be unbanned by an admin.");
     }
     else if (e.Error == LoginErrors.AlreadyLoggedIn)
     {
         Console.WriteLine("The account is already in use.");
     }
 }