Example #1
0
        private static void SendConnectionRequest(ClientInfo client, byte sessionID)
        {
            QPacket qp = new QPacket();

            qp.m_oSourceVPort      = new QPacket.VPort(0x11);
            qp.m_oDestinationVPort = new QPacket.VPort(0x11);
            qp.type  = QPacket.PACKETTYPE.SYN;
            qp.flags = new List <QPacket.PACKETFLAG>()
            {
                QPacket.PACKETFLAG.FLAG_ACK, QPacket.PACKETFLAG.FLAG_HAS_SIZE
            };
            qp.m_uiConnectionSignature = client.IDsend;
            qp.payload = new byte[0];
            DO.Send(qp, client);
            qp = new QPacket();
            qp.m_bySessionID       = sessionID;
            qp.m_oSourceVPort      = new QPacket.VPort(0x11);
            qp.m_oDestinationVPort = new QPacket.VPort(0x11);
            qp.type  = QPacket.PACKETTYPE.CONNECT;
            qp.flags = new List <QPacket.PACKETFLAG>()
            {
                QPacket.PACKETFLAG.FLAG_RELIABLE, QPacket.PACKETFLAG.FLAG_NEED_ACK, QPacket.PACKETFLAG.FLAG_HAS_SIZE
            };
            qp.m_uiSignature           = client.IDsend;
            qp.m_uiConnectionSignature = client.IDrecv;
            MemoryStream m = new MemoryStream();

            Helper.WriteU32(m, 8);
            Helper.WriteU32(m, new DupObj(DupObjClass.Station, 1));
            Helper.WriteU32(m, new DupObj(DupObjClass.Station, 2));
            DO.MakeAndSend(client, qp, m.ToArray());
        }
        public static byte[] HandleMessage(ClientInfo client, QPacket p, byte[] data)
        {
            Log.WriteLine(1, "[DO] Handling DO_RMCRequestMessage...");
            MemoryStream m = new MemoryStream(data);

            m.Seek(1, 0);
            ushort     callID       = Helper.ReadU16(m);
            uint       flags        = Helper.ReadU32(m);
            uint       station      = Helper.ReadU32(m);
            uint       targetObject = Helper.ReadU32(m);
            DOC_METHOD method       = (DOC_METHOD)Helper.ReadU16(m);

            Log.WriteLine(2, "[DO] RMC Call ID      : 0x" + callID.ToString("X4"));
            Log.WriteLine(2, "[DO] RMC Call Flags   : 0x" + flags.ToString("X8"));
            Log.WriteLine(2, "[DO] RMC Call Station : 0x" + station.ToString("X8"));
            Log.WriteLine(2, "[DO] RMC Call DupObj  : 0x" + targetObject.ToString("X8") + " " + new DupObj(targetObject).getDesc());
            byte[]        buff;
            MemoryStream  m2;
            List <byte[]> msgs;

            switch (method)
            {
            case DOC_METHOD.SyncRequest:
                Log.WriteLine(1, "[DO] Handling SyncRequest...");
                ulong time = Helper.ReadU64(m);
                buff = Create(client.callCounterDO_RMC++, 0x83C, new DupObj(DupObjClass.Station, 1), new DupObj(DupObjClass.SessionClock, 1), 6, new Payload_SyncResponse(time).toBuffer());
                m2   = new MemoryStream();
                Helper.WriteU32(m2, (uint)buff.Length);
                m2.Write(buff, 0, buff.Length);
                m2.WriteByte((byte)QPacket.MakeChecksum(m2.ToArray(), 0));
                p.payload       = m2.ToArray();
                p.payloadSize   = (ushort)p.payload.Length;
                p.m_uiSignature = client.IDsend;
                DO.Send(p, client);
                return(null);

            case DOC_METHOD.RequestIDRangeFromMaster:
                Log.WriteLine(1, "[DO] Handling RequestIDRangeFromMaster...");
                return(DO_RMCResponseMessage.Create(callID, 0x60001, new byte[] { 0x01, 0x01, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00 }));

            case DOC_METHOD.IncreasePlayerNb:
                Log.WriteLine(1, "[DO] Handling IncreasePlayerNb...");
                msgs = new List <byte[]>();
                msgs.Add(new byte[] { 0x02, 0x02, 0x00, 0x40, 0x05, 0x01, 0x01, 0x00, 0x00, 0x00 });
                msgs.Add(DO_RMCResponseMessage.Create(callID, 0x60001, new byte[] { 0x00 }));
                return(DO_BundleMessage.Create(client, msgs));

            case DOC_METHOD.AskForSettingPlayerParameters:
                Log.WriteLine(1, "[DO] Handling AskForSettingPlayerParameters...");
                int len = (int)(data.Length - m.Position);
                buff = new byte[len];
                m.Read(buff, 0, len);
                client.settings = buff;
                msgs            = new List <byte[]>();
                msgs.Add(DO_RMCRequestMessage.Create(client.callCounterDO_RMC++,
                                                     0x1006,
                                                     new DupObj(DupObjClass.Station, 1),
                                                     new DupObj(DupObjClass.SES_cl_Player_NetZ, 257),
                                                     (ushort)DO_RMCRequestMessage.DOC_METHOD.SetPlayerParameters,
                                                     client.settings
                                                     ));
                msgs.Add(DO_RMCResponseMessage.Create(callID, 0x60001, new byte[] { 0x00 }));
                return(DO_BundleMessage.Create(client, msgs));

            case DOC_METHOD.AskForSettingPlayerState:
                Log.WriteLine(1, "[DO] Handling AskForSettingPlayerState...");
                msgs = new List <byte[]>();
                msgs.Add(DO_RMCRequestMessage.Create(client.callCounterDO_RMC++,
                                                     0x1006,
                                                     new DupObj(DupObjClass.Station, 1),
                                                     new DupObj(DupObjClass.SES_cl_Player_NetZ, 257),
                                                     (ushort)DO_RMCRequestMessage.DOC_METHOD.SetPlayerState,
                                                     BitConverter.GetBytes(Helper.ReadU32(m))
                                                     ));
                msgs.Add(DO_RMCResponseMessage.Create(callID, 0x60001, new byte[] { 0x00 }));
                return(DO_BundleMessage.Create(client, msgs));

            default:
                Log.WriteLine(1, "[DO] Error: Unhandled DOC method: " + method + "!");
                return(null);
            }
        }