Represents a Tox ID (38 bytes long)
예제 #1
0
 public new int AddFriend(ToxId id, string message, out ToxErrorFriendAdd error)
 {
     var friendNumber = base.AddFriend(id, message, out error);
     if (error == ToxErrorFriendAdd.Ok)
         FriendListChanged(friendNumber, FriendListChangedAction.Add);
     return friendNumber;
 }
예제 #2
0
 public ToxDataInfo(ToxId id, string name, string statusMessage, ToxUserStatus status, ToxKey secretKey)
 {
     this.Id            = id;
     this.Name          = name;
     this.StatusMessage = statusMessage;
     this.Status        = status;
     this.SecretKey     = secretKey;
 }
예제 #3
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            ToxId id = obj as ToxId;

            if ((object)id == null)
            {
                return(false);
            }

            return(this == id);
        }
예제 #4
0
 public int AddFriend(ToxId id, string message, out bool success)
 {
     ToxErrorFriendAdd error;
     var retVal = _tox.AddFriend(id, message, out error);
     ToxErrorViewModel.Instance.RelayError(error);
     success = error == ToxErrorFriendAdd.Ok;
     return retVal;
 }
예제 #5
0
        public void TestToxId()
        {
            var tox = new Tox(ToxOptions.Default);
            var toxId = new ToxId(tox.Id.PublicKey.GetBytes(), tox.Id.Nospam);

            if (toxId != tox.Id)
                Assert.Fail("Tox id's are not equal");
        }
예제 #6
0
        public static ToxDataInfo FromToxData(IToxData data)
        {
            try
            {
                ToxId         id            = null;
                string        name          = null;
                string        statusMessage = null;
                ToxUserStatus status        = ToxUserStatus.None;
                byte[]        secretKey     = null;

                using (var stream = new MemoryStream(data.Bytes))
                    using (var reader = new BinaryReader(stream))
                    {
                        stream.Position += sizeof(uint);

                        uint cookie = reader.ReadUInt32();
                        if (cookie != ToxConstants.Cookie)
                        {
                            throw new Exception("Invalid cookie, this doesn't look like a tox profile");
                        }

                        uint length = reader.ReadUInt32();
                        long left   = reader.BaseStream.Length - reader.BaseStream.Position;

                        while (left >= length)
                        {
                            var type = ReadStateType(reader);

                            if (type == StateType.EOF)
                            {
                                break;
                            }

                            switch (type)
                            {
                            case StateType.NospamKeys:
                                uint   nospam   = reader.ReadUInt32();
                                byte[] keyBytes = reader.ReadBytes(ToxConstants.PublicKeySize);

                                secretKey = reader.ReadBytes(ToxConstants.SecretKeySize);
                                id        = new ToxId(new ToxKey(ToxKeyType.Public, keyBytes), nospam);
                                break;

                            case StateType.Name:
                                name = Encoding.UTF8.GetString(reader.ReadBytes((int)length), 0, (int)length);
                                break;

                            case StateType.StatusMessage:
                                statusMessage = Encoding.UTF8.GetString(reader.ReadBytes((int)length), 0, (int)length);
                                break;

                            case StateType.Status:
                                status = (ToxUserStatus)reader.ReadByte();
                                break;

                            default:
                            case StateType.Dht:
                            case StateType.Friends:
                            case StateType.TcpRelay:
                            case StateType.PathNode:
                                stream.Position += length; //skip this
                                break;

                            case StateType.Corrupt:
                                throw new Exception("This Tox save file is corrupt");
                            }

                            left = reader.BaseStream.Length - reader.BaseStream.Position;
                            if (left < sizeof(uint))
                            {
                                break;
                            }
                            else
                            {
                                length = reader.ReadUInt32();
                            }
                        }
                    }

                return(new ToxDataInfo(id, name, statusMessage, status, new ToxKey(ToxKeyType.Secret, secretKey)));
            }
            catch { return(null); }
        }
예제 #7
0
파일: Tox.cs 프로젝트: hexafluoride/Detox
 /// <summary>
 /// Adds a friend to the friend list and sends a friend request.
 /// </summary>
 /// <param name="id">The Tox id of the friend to add.</param>
 /// <param name="message">The message that will be sent along with the friend request.</param>
 /// <returns>The friend number.</returns>
 public int AddFriend(ToxId id, string message)
 {
     var error = ToxErrorFriendAdd.Ok;
     return AddFriend(id, message, out error);
 }
예제 #8
0
파일: Tox.cs 프로젝트: hexafluoride/Detox
        /// <summary>
        /// Adds a friend to the friend list and sends a friend request.
        /// </summary>
        /// <param name="id">The Tox id of the friend to add.</param>
        /// <param name="message">The message that will be sent along with the friend request.</param>
        /// <param name="error"></param>
        /// <returns>The friend number.</returns>
        public int AddFriend(ToxId id, string message, out ToxErrorFriendAdd error)
        {
            ThrowIfDisposed();

            if (id == null)
                throw new ArgumentNullException("id");

            byte[] msg = Encoding.UTF8.GetBytes(message);
            error = ToxErrorFriendAdd.Ok;

            return (int)ToxFunctions.FriendAdd(_tox, id.Bytes, msg, (uint)msg.Length, ref error);
        }
예제 #9
0
 public new int AddFriend(ToxId id, string message)
 {
     var friendNumber = base.AddFriend(id, message);
     FriendListChanged(friendNumber, FriendListChangedAction.Add);
     return friendNumber;
 }
예제 #10
0
        internal static ToxDataInfo FromToxData(ToxData data)
        {
            try
            {
                ToxId id = null;
                string name = null;
                string statusMessage = null;
                ToxUserStatus status = ToxUserStatus.None;
                byte[] secretKey = null;

                using (var stream = new MemoryStream(data.Bytes))
                using (var reader = new BinaryReader(stream))
                {
                    stream.Position += sizeof(uint);

                    uint cookie = reader.ReadUInt32();
                    if (cookie != ToxConstants.Cookie)
                        throw new Exception("Invalid cookie, this doesn't look like a tox profile");

                    uint length = reader.ReadUInt32();
                    long left = reader.BaseStream.Length - reader.BaseStream.Position;

                    while (left >= length)
                    {
                        var type = ReadStateType(reader);

                        switch (type)
                        {
                            case StateType.NospamKeys:
                                uint nospam = reader.ReadUInt32();
                                byte[] publicKey = reader.ReadBytes(ToxConstants.PublicKeySize);

                                secretKey = reader.ReadBytes(ToxConstants.SecretKeySize);
                                id = new ToxId(publicKey, nospam);
                                break;
                            case StateType.Dht:
                                stream.Position += length; //skip this
                                break;
                            case StateType.Friends:
                                stream.Position += length; //skip this
                                break;
                            case StateType.Name:
                                name = Encoding.UTF8.GetString(reader.ReadBytes((int)length), 0, (int)length);
                                break;
                            case StateType.StatusMessage:
                                statusMessage = Encoding.UTF8.GetString(reader.ReadBytes((int)length), 0, (int)length);
                                break;
                            case StateType.Status:
                                status = (ToxUserStatus)reader.ReadByte();
                                break;
                            case StateType.TcpRelay:
                                stream.Position += length; //skip this
                                break;
                            case StateType.PathNode:
                                stream.Position += length; //skip this
                                break;
                            case StateType.Corrupt:
                                throw new Exception("This Tox save file is corrupt");
                            default:
                                break;
                        }

                        left = reader.BaseStream.Length - reader.BaseStream.Position;
                        if (left < sizeof(uint))
                            break;
                        else
                            length = reader.ReadUInt32();
                    }
                }

                return new ToxDataInfo()
                {
                    Id = id,
                    Name = name,
                    StatusMessage = statusMessage,
                    Status = status,
                    SecretKey = new ToxKey(ToxKeyType.Secret, secretKey)
                };
            }
            catch { return null; }
        }