Example #1
0
        public static byte[] _CreateRPCMessageTemplate(RPCOpcode op, byte filterType, ushort filterSize, uint payloadSize, out int filterOffset, out int payloadOffset)
        {
            //1     Byte    Command Opcode
            //1     Byte    Flags
            //4     Int32   RPC Opcode
            //1     Byte    Filter Type
            //1     Byte    <Reserved>
            //2     UInt16  Filter Size
            //^     <blob>  Filter
            //4     UInt32  Payload Size
            //^     <blob>  Payload
            filterOffset  = 10;
            payloadOffset = 10 + filterSize + 4;

            //Generate buffer
            byte[] payload = new byte[10 + filterSize + 4 + payloadSize];
            payload[0] = TYPECODE_MESSAGE;
            payload[1] = 0x00;
            BitConverter.GetBytes((int)op).CopyTo(payload, 2);
            payload[6] = filterType;
            payload[7] = 0x00;
            BitConverter.GetBytes(filterSize).CopyTo(payload, 8);
            //User writes filter
            BitConverter.GetBytes(payloadSize).CopyTo(payload, 10 + filterSize);
            //User writes payload

            return(payload);
        }
Example #2
0
        public static void SendRPCMsgToServer(DeltaConnection conn, RPCOpcode opcode, object payload, ObjectId server_id)
        {
            //Calculate
            string data    = JsonConvert.SerializeObject(payload);
            int    dataLen = Encoding.UTF8.GetByteCount(data);

            //Get buffer
            byte[] buffer = _CreateRPCMessageTemplate(opcode, FILTERCODE_SERVER, 12, (uint)dataLen, out int filterOffset, out int payloadOffset);

            //Write filter
            BinaryTool.WriteMongoID(buffer, filterOffset, server_id);

            //Write payload
            Encoding.UTF8.GetBytes(data, 0, data.Length, buffer, payloadOffset);

            //Send
            conn.net.SendRPCCommand(buffer);
        }
Example #3
0
        private static void OnIncomingRPCCommand_RPCMessage(byte[] payload)
        {
            //Read header
            RPCOpcode opcode      = (RPCOpcode)BitConverter.ToInt32(payload, 2);
            byte      filterType  = payload[6];
            byte      reserved    = payload[7];
            ushort    filterSize  = BitConverter.ToUInt16(payload, 8);
            uint      payloadSize = BitConverter.ToUInt32(payload, 10 + filterSize);

            //Read filter
            ISockFilter filter = DecodeCommandFilter(payload, filterType, (byte)filterSize, 10, out ObjectId? serverId);

            //Read payload
            JObject data = JsonConvert.DeserializeObject <JObject>(Encoding.UTF8.GetString(payload, 10 + filterSize + 4, (int)payloadSize));

            //Handle
            DispatchMessage(filter, new SendRPCMessageCommand(opcode.ToString(), serverId, data));
        }
Example #4
0
        private static void OnIncomingRPCCommand_PrivledgedMessage(byte[] payload)
        {
            //Read header
            RPCOpcode opcode       = (RPCOpcode)BitConverter.ToInt32(payload, 2);
            ObjectId  serverId     = BinaryTool.ReadMongoID(payload, 6);
            int       payloadCount = BitConverter.ToInt32(payload, 18);

            //Clone list
            List <RPCConnection> clientsSafe = new List <RPCConnection>();

            lock (connections)
                clientsSafe.AddRange(connections);

            //Begin reading array
            int offset = 22;

            for (int i = 0; i < payloadCount; i++)
            {
                //Read header data
                int tribeId       = BitConverter.ToInt32(payload, offset + 0);
                int payloadLength = BitConverter.ToInt32(payload, offset + 4);
                offset += 8;

                //Decode payload
                JObject data = JsonConvert.DeserializeObject <JObject>(Encoding.UTF8.GetString(payload, offset, payloadLength));

                //Create filter and command
                ISockFilter filter = new ServerTribeSockFilter(serverId, tribeId);
                var         cmd    = new SendRPCMessageCommand(opcode.ToString(), serverId, data);

                //Search to send messages
                foreach (var c in clientsSafe)
                {
                    //Filter
                    if (!filter.CheckFilter(c))
                    {
                        continue;
                    }

                    //Send
                    c.EnqueueMessage(cmd);
                }
            }
        }
Example #5
0
        public static byte[] _CreatePrivilegedMessageServerTemplate(RPCOpcode op, ObjectId guild, int[] payloadSizes, int[] payloadTribes, out int[] payloadOffsets)
        {
            //1     Byte    Command Opcode
            //1     Byte    Flags
            //4     Int32   RPC Opcode
            //12    MongoID Guild ID
            //4     Int32   Payload Count
            // === ARRAY BEGIN ===
            //4     Int32   Tribe ID
            //4     Int32   Payload Size
            //^     <blob>  Payload data
            // === ARRAY END ===
            payloadOffsets = new int[payloadSizes.Length];

            //Calculate the total size of all payloads, plus their headers
            int totalLength = 0;

            for (int i = 0; i < payloadSizes.Length; i++)
            {
                totalLength += 8 + payloadSizes[i];
            }

            //Generate buffer
            byte[] payload = new byte[22 + totalLength];
            payload[0] = TYPECODE_GROUP_RESET;
            payload[1] = 0x00;
            BitConverter.GetBytes((int)op).CopyTo(payload, 2);
            BinaryTool.WriteMongoID(payload, 6, guild);
            BitConverter.GetBytes((int)payloadSizes.Length).CopyTo(payload, 18);
            int offset = 22;

            for (int i = 0; i < payloadSizes.Length; i++)
            {
                BitConverter.GetBytes(payloadTribes[i]).CopyTo(payload, offset + 0);
                BitConverter.GetBytes(payloadSizes[i]).CopyTo(payload, offset + 4);
                payloadOffsets[i] = offset + 8;
                offset           += 8 + payloadSizes[i];
            }

            return(payload);
        }