Exemple #1
0
 private void Connection_ReceivedAccountList(object sender, AccountListEventArgs e)
 {
     if (e.Error == AccountListErrors.None)
         this.friendList = e.List;
 }
Exemple #2
0
 private void Shitchat_ReceivedAccountList(object sender, AccountListEventArgs e)
 {
     
 }
Exemple #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();
        }
Exemple #4
0
 static void shitchat_ReceivedAccountList(object sender, AccountListEventArgs e)
 {
     accountList = e.List.ToList();
 }