コード例 #1
0
        public static void OnConnectRequest(Client pClient, Header pHeader, MemoryStream pData)
        {
            ConnectRequest connectRequest = new ConnectRequest();
            if (!connectRequest.Read(pData)) return;

            ConnectResponse connectResponse = new ConnectResponse();
            connectResponse.ServerId.Label = 0;
            connectResponse.ServerId.Epoch = DateTime.Now.ToUnixTime();
            connectResponse.HasClientId = true;
            connectResponse.ClientId.Label = 1;
            connectResponse.ClientId.Epoch = connectResponse.ServerId.Epoch;
            if (connectRequest.HasClientId) connectResponse.ClientId.Label = connectResponse.ClientId.Label;
            ContentHandle contentHandle = new ContentHandle();
            byte[] region = Encoding.ASCII.GetBytes("US");
            contentHandle.Region = (uint)(region[0] << 8) | region[1];
            byte[] usage = Encoding.ASCII.GetBytes("mtrz");
            contentHandle.Usage = (uint)(usage[0] << 24) | (uint)(usage[1] << 16) | (uint)(usage[2] << 8) | usage[3];
            contentHandle.Hash = new byte[] { 0x18, 0xe9, 0x8c, 0xde, 0x12, 0x83, 0x71, 0x49, 0x62, 0x19, 0x88, 0xce, 0xee, 0x55, 0x12, 0x3b,
                                              0xf2, 0xbe, 0x83, 0x9a, 0x6d, 0xc1, 0xd6, 0xbb, 0x00, 0xa3, 0x99, 0x52, 0x06, 0x56, 0xb2, 0xa6 };
            connectResponse.HasConnectionMeteringContentHandles = true;
            connectResponse.ConnectionMeteringContentHandles.ContentHandles.Add(contentHandle);

            pClient.PermittedServices.Add(ClientImportedServiceIds.AuthenticationServer);
            //pClient.PermittedServices.Add(ClientServiceIds.ChallengeService);
            //pClient.PermittedServices.Add(ClientServiceIds.ChannelService);
            //pClient.PermittedServices.Add(ClientServiceIds.AchievementsService);
            //pClient.PermittedServices.Add(ClientServiceIds.ReportService);

            MemoryStream response = new MemoryStream(128);
            connectResponse.Write(response);
            pClient.SendResponse(pHeader.Token, 0, 0, null, response);
        }
コード例 #2
0
        public static void OnBindRequest(Client pClient, Header pHeader, MemoryStream pData)
        {
            BindRequest bindRequest = new BindRequest();
            if (!bindRequest.Read(pData)) return;

            BindResponse bindResponse = new BindResponse();
            foreach (uint hash in bindRequest.ImportedServiceHashes)
            {
                uint serviceId = 0;
                if (Program.GetClientServiceId(hash, out serviceId) && !pClient.ImportedServices.Contains(serviceId))
                {
                    if (pClient.PermittedServices.Contains(serviceId))
                    {
                        pClient.Log(ELogLevel.Debug, "Importing Service {0}", serviceId);
                        pClient.ImportedServices.Add(serviceId);
                        bindResponse.ImportedServiceIds.Add(serviceId);
                    }
                    else pClient.RequestedServices.Add(new Tuple<uint, uint>(serviceId, pHeader.Token));
                }
            }
            if (bindResponse.HasImportedServiceIds)
            {
                MemoryStream response = new MemoryStream(128);
                bindResponse.Write(response);
                pClient.SendResponse(pHeader.Token, 0, 0, null, response);
            }
        }
コード例 #3
0
ファイル: Client.cs プロジェクト: Astaelan/Tristram
        public void SendResponse(uint pToken, ulong pObjectId, uint pStatus, List<ErrorInfo> pErrors, MemoryStream pData)
        {
            Header header = new Header();
            header.ServiceId = ClientImportedServiceIds.Response;
            header.Token = pToken;
            if (pObjectId != 0)
            {
                header.HasObjectId = true;
                header.ObjectId = pObjectId;
            }
            if (pData != null && pData.Length > 0)
            {
                header.HasSize = true;
                header.Size = (uint)pData.Length;
            }
            header.HasStatus = true;
            header.Status = pStatus;
            if (pErrors != null) pErrors.ForEach(e => header.Errors.Add(e));

            int size = 16;
            if (pData != null) size += (int)pData.Length;
            MemoryStream packet = new MemoryStream(size);
            packet.Seek(2, SeekOrigin.Begin);
            header.Write(packet);
            packet.Seek(0, SeekOrigin.Begin);
            packet.WriteByte((byte)(((packet.Length - 2) >> 8) & 0xFF));
            packet.WriteByte((byte)((packet.Length - 2) & 0xFF));
            packet.Seek(0, SeekOrigin.End);
            if (pData != null) pData.WriteTo(packet);
            Send(packet.ToArray());

            Log(ELogLevel.Debug, "Sent Message: {0}.{1} Token = {2}, {3} Bytes", header.ServiceId, header.MethodId, header.Token, header.Size);
            if (pData != null) Logger.Dump(pData.ToArray(), 0, (int)pData.Length);
        }
コード例 #4
0
 private static void LogonRequestCallback(Client pClient, Header pHeader, LogonRequest pLogonRequest)
 {
     Account account = AccountCache.RetrieveAccountByEmail(pLogonRequest.Email);
     if (account == null)
     {
         pClient.PermittedServices.Clear();
         pClient.ImportedServices.Clear();
         pClient.SendAuthenticationClientLogonComplete(new LogonResult(EErrorCode.LoginInformationWasIncorrect));
         return;
     }
 }
コード例 #5
0
 public static void OnLogonRequest(Client pClient, Header pHeader, MemoryStream pData)
 {
     LogonRequest logonRequest = new LogonRequest();
     if (!logonRequest.Read(pData) || !logonRequest.HasEmail) return;
     Program.AddCallback(() => LogonRequestCallback(pClient, pHeader, logonRequest));
 }
コード例 #6
0
ファイル: Client.cs プロジェクト: Astaelan/Tristram
        private void OnMessage(Header pHeader, MemoryStream pData)
        {
            Log(ELogLevel.Debug, "Received Message: {0}.{1} Token = {2}, {3} Bytes", pHeader.ServiceId, pHeader.MethodId, pHeader.Token, pHeader.Size);

            if (!mImportedServices.Contains(pHeader.ServiceId))
            {
                Log(ELogLevel.Warn, "Unavailable Service: {0}", pHeader.ServiceId);
                return;
            }
            ClientImportedServiceMethodAttribute clientServiceMethod = null;
            if (!Program.GetClientServiceMethod(pHeader.ServiceId, pHeader.MethodId, out clientServiceMethod))
            {
                Log(ELogLevel.Warn, "Unknown Service Method: {0}.{1}", pHeader.ServiceId, pHeader.MethodId);
                return;
            }
            if (clientServiceMethod.Dump) Logger.Dump(pData.ToArray(), 0, (int)pData.Length);
            clientServiceMethod.Method(this, pHeader, pData);
        }
コード例 #7
0
ファイル: Client.cs プロジェクト: Astaelan/Tristram
        protected override int OnDataReceived(byte[] pBuffer, int pStart, int pLength)
        {
            int consumed = 0;
            while (pLength > 2)
            {
                int totalSize = 2;
                if (pLength < totalSize) return consumed;

                ushort headerSize = (ushort)((pBuffer[pStart + 0] << 8) | pBuffer[pStart + 1]);
                totalSize += headerSize;
                if (pLength < totalSize) return consumed;

                Header header = new Header();
                if (!header.Read(new MemoryStream(pBuffer, pStart + 2, headerSize))) return consumed;
                totalSize += (int)header.Size;
                if (pLength < totalSize) return consumed;

                MemoryStream data = new MemoryStream((int)header.Size);
                data.Write(pBuffer, pStart + 2 + headerSize, (int)header.Size);
                data.Seek(0, SeekOrigin.Begin);
                Program.AddCallback(() => OnMessage(header, data));

                pStart += totalSize;
                pLength -= totalSize;
                consumed += totalSize;
            }

            return consumed;
        }
コード例 #8
0
ファイル: Client.cs プロジェクト: Astaelan/Tristram
        public void SendRPC(uint pServiceId, uint pMethodId, uint pToken, ulong pObjectId, MemoryStream pData)
        {
            Header header = new Header();
            header.ServiceId = pServiceId;
            header.HasMethodId = true;
            header.MethodId = pMethodId;
            header.Token = pToken;
            if (pObjectId != 0)
            {
                header.HasObjectId = true;
                header.ObjectId = pObjectId;
            }
            if (pData != null && pData.Length > 0)
            {
                header.HasSize = true;
                header.Size = (uint)pData.Length;
            }

            int size = 16;
            if (pData != null) size += (int)pData.Length;
            MemoryStream packet = new MemoryStream(size);
            packet.Seek(2, SeekOrigin.Begin);
            header.Write(packet);
            packet.Seek(0, SeekOrigin.Begin);
            packet.WriteByte((byte)(((packet.Length - 2) >> 8) & 0xFF));
            packet.WriteByte((byte)((packet.Length - 2) & 0xFF));
            packet.Seek(0, SeekOrigin.End);
            if (pData != null) pData.WriteTo(packet);
            Send(packet.ToArray());

            Log(ELogLevel.Debug, "Sent Message: {0}.{1} Token = {2}, {3} Bytes", header.ServiceId, header.MethodId, header.Token, header.Size);
            if (pData != null) Logger.Dump(pData.ToArray(), 0, (int)pData.Length);
        }