Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
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);
                }
            }
        }