Exemplo n.º 1
0
        private static void InviteToSession(MessageData mdata, DWMessage packet)
        {
            var sidBlob = packet.ByteBuffer.ReadBlob();
            var sid     = BitConverter.ToUInt64(sidBlob, 0);

            var attachment = packet.ByteBuffer.ReadBlob();

            var onlineIDs = new List <ulong>();

            while (packet.ByteBuffer.PeekByte() == 10)
            {
                onlineIDs.Add(packet.ByteBuffer.ReadUInt64());
            }

            foreach (var onlineID in onlineIDs)
            {
                var ourID   = DWRouter.GetIDForData(mdata);
                var ourName = DWRouter.CIDToName[mdata.Get <string>("cid")];
                var theirID = DWRouter.Connections[onlineID];
                var treply  = packet.MakeReply(2, false, theirID); // 2 is 'push message'
                treply.ByteBuffer.Write((uint)6);
                treply.ByteBuffer.Write(ourID);
                treply.ByteBuffer.Write(ourName);
                treply.ByteBuffer.WriteBlob(sidBlob);
                treply.ByteBuffer.WriteBlob(attachment);
                treply.Send(true);

                Log.Debug("sent an invite to " + onlineID.ToString("X16") + " from " + ourID.ToString("X16"));
            }

            var reply = packet.MakeReply(1, false);

            reply.ByteBuffer.Write(0x8000000000000001);
            reply.ByteBuffer.Write((uint)0);
            reply.ByteBuffer.Write((byte)21);
            reply.ByteBuffer.Write((uint)0);
            reply.ByteBuffer.Write((uint)0);
            reply.Send(true);
        }
Exemplo n.º 2
0
        private static void SetGroups(MessageData data, DWMessage packet)
        {
            ulong userID = DWRouter.GetIDForData(data);

            /*lock (DWRouter.Connections)
             * {
             *  userID = (from conn in DWRouter.Connections
             *            where conn.Value == data.Get<string>("cid")
             *            select conn.Key).FirstOrDefault();
             * }*/

            RemoveUserGroups(userID);

            packet.ByteBuffer.DataTypePackingEnabled = true;
            var a     = packet.ByteBuffer.ReadByte();   // 108
            var b     = packet.ByteBuffer.ReadUInt32(); // count * 4
            var count = packet.ByteBuffer.ReadUInt32();

            var groups = new List <GroupUser>();

            for (int i = 0; i < count; i++)
            {
                groups.Add(new GroupUser()
                {
                    groupID = (int)packet.ByteBuffer.ReadUInt32(), userID = (long)userID
                });
            }

            Database.AGroupUser.InsertBatch(groups);

            var reply = packet.MakeReply(1, false);

            reply.ByteBuffer.Write(0x8000000000000001);
            reply.ByteBuffer.Write((uint)0);
            reply.ByteBuffer.Write((byte)28);
            reply.ByteBuffer.Write((uint)0);
            reply.ByteBuffer.Write((uint)0);
            reply.Send(true);
        }
Exemplo n.º 3
0
        private static void GetFile(MessageData mdata, DWMessage packet)
        {
            var filename = packet.ByteBuffer.ReadString();
            var user     = packet.ByteBuffer.ReadUInt64();

            if (user == 0)
            {
                user = DWRouter.GetIDForData(mdata);
            }

            var path = filename + "_" + user.ToString("x16");
            var e    = r.Next(1, 164);

            Log.Debug("Trying to send " + path + "... (originID " + e + ")");

            var query = Query.EQ("filename", path);
            var files = Database.AFiles.Find(query);

            if (files.Count() > 0)
            {
                var file  = files.First();
                var reply = packet.MakeReply(1, false);
                reply.ByteBuffer.Write(0x8000000000000001);
                reply.ByteBuffer.Write((uint)0);
                reply.ByteBuffer.Write((byte)7);
                reply.ByteBuffer.Write((uint)1);
                reply.ByteBuffer.Write((uint)1);
                reply.ByteBuffer.WriteBlob(file.data);
                reply.Send(true);
            }
            else
            {
                var reply = packet.MakeReply(1, false);
                reply.ByteBuffer.Write(0x8000000000000001);
                reply.ByteBuffer.Write((uint)0x3E8);
                reply.Send(true);
            }
        }
Exemplo n.º 4
0
        private static void UploadFile(MessageData mdata, DWMessage packet)
        {
            var filename = packet.ByteBuffer.ReadString();
            var test     = packet.ByteBuffer.ReadBool();
            var data     = packet.ByteBuffer.ReadBlob();
            // NOTE: AN UINT64 MIGHT FOLLOW HERE. THIS COULD BE USED BY DEDICATED SERVER-STYLE LICENSES FOR WRITING USER STATS.
            var user = (ulong)0;

            try
            {
                user = packet.ByteBuffer.ReadUInt64();
            }
            catch { }

            if (user == 0)
            {
                /*lock (DWRouter.Connections)
                 * {
                 *  user = (from conn in DWRouter.Connections
                 *          where conn.Value == mdata.Get<string>("cid")
                 *          select conn.Key).FirstOrDefault();
                 * }*/
                user = DWRouter.GetIDForData(mdata);
            }
            //var user = 0x1100001ded1ca7e;//packet.ByteBuffer.ReadUInt64();
            var path = filename + "_" + user.ToString("x16");

            /*MySqlDataReader query = Database.Query("SELECT * FROM files WHERE filename='" + path + "'");
             * if (query.HasRows)
             * {
             *  query.Close();
             *  Log.Debug("Trying to update " + path + "... for user ");
             *  Database.UploadQuery("UPDATE files SET data = ?filedata, filesize = '" + data.Length + "', userid='" + Convert.ToString((int)user) + "' WHERE filename='" + path + "'", data);
             * }
             * else
             * {
             *  query.Close();
             *  Log.Debug("Trying to write " + path + "... for user ");
             *  Database.UploadQuery("INSERT INTO files(userid, filename, data, filesize) VALUES('" + Convert.ToString((int)user) + "', '" + path + "', ?filedata, '" + data.Length + "')", data);
             * }*/

            Log.Debug("Trying to write " + path + "...");

            var file = new File()
            {
                filename = path,
                userid   = (int)user,
                filesize = data.Length,
                data     = data
            };

            var query = Query.EQ("filename", path);
            var files = Database.AFiles.Find(query);

            if (files.Count() > 0)
            {
                file.id = files.First().id;
            }

            Database.AFiles.Save(file);


            var reply = packet.MakeReply(1, false);

            reply.ByteBuffer.Write(0x8000000000000001);
            reply.ByteBuffer.Write((uint)0);
            reply.ByteBuffer.Write((byte)1);
            reply.ByteBuffer.Write((uint)0);
            reply.ByteBuffer.Write((uint)0);
            reply.Send(true);
        }