예제 #1
0
        public void ListFactories(IClient client, Packet packetIn)
        {
            Logger.Trace("RPC:GameMaster:ListFactories()");

            var description = bnet.protocol.game_master.GameFactoryDescription.CreateBuilder().SetId(14249086168335147635);

            var atributes = new bnet.protocol.attribute.Attribute[4]
                                {
                                    bnet.protocol.attribute.Attribute.CreateBuilder().SetName("min_players").SetValue(bnet.protocol.attribute.Variant.CreateBuilder().SetIntValue(2)).Build(),
                                    bnet.protocol.attribute.Attribute.CreateBuilder().SetName("max_players").SetValue(bnet.protocol.attribute.Variant.CreateBuilder().SetIntValue(4)).Build(),
                                    bnet.protocol.attribute.Attribute.CreateBuilder().SetName("num_teams").SetValue(bnet.protocol.attribute.Variant.CreateBuilder().SetIntValue(1)).Build(),
                                    bnet.protocol.attribute.Attribute.CreateBuilder().SetName("version").SetValue(bnet.protocol.attribute.Variant.CreateBuilder().SetStringValue("0.3.0")).Build()
                                };

            description.AddRangeAttribute(atributes);
            description.AddStatsBucket(bnet.protocol.game_master.GameStatsBucket.CreateBuilder()
                                           .SetBucketMin(0)
                                           .SetBucketMax(4294967296F)
                                           .SetWaitMilliseconds(1354)
                                           .SetGamesPerHour(0)
                                           .SetActiveGames(1)
                                           .SetActivePlayers(1)
                                           .SetFormingGames(0)
                                           .SetWaitingPlayers(0).Build());

            var response = bnet.protocol.game_master.ListFactoriesResponse.CreateBuilder().AddDescription(description).SetTotalResults(1).Build();

            var packet = new Packet(
                new Header(0xfe, 0x0, packetIn.Header.RequestID, (uint)response.SerializedSize),
                response.ToByteArray());

            client.Send(packet);
        }
예제 #2
0
        public void ListFactoriesRequest(IClient client, Packet packetIn)
        {
            Logger.Trace("RPC:GameMaster:ListFactoriesRequest()");
            //var reqb = bnet.protocol.game_master.ListFactoriesRequest.ParseFrom(packetIn.Payload.ToArray());
            var varib1 = bnet.protocol.attribute.Variant.CreateBuilder();
            varib1.SetIntValue(2);
            var vari1 = varib1.Build();
            var varib2 = bnet.protocol.attribute.Variant.CreateBuilder();
            varib2.SetIntValue(4);
            var vari2 = varib2.Build();
            var varib3 = bnet.protocol.attribute.Variant.CreateBuilder();
            varib3.SetIntValue(1);
            var vari3 = varib3.Build();
            var varib4 = bnet.protocol.attribute.Variant.CreateBuilder();
            varib4.SetStringValue("0.3.0");
            var vari4 = varib4.Build();
            var attrb1 = bnet.protocol.attribute.Attribute.CreateBuilder();
            attrb1.SetName("min_players");
            attrb1.SetValue(vari1);
            var attr1 = attrb1.Build();
            var attrb2 = bnet.protocol.attribute.Attribute.CreateBuilder();
            attrb2.SetName("max_players");
            attrb2.SetValue(vari2);
            var attr2 = attrb2.Build();
            var attrb3 = bnet.protocol.attribute.Attribute.CreateBuilder();
            attrb3.SetName("num_teams");
            attrb3.SetValue(vari3);
            var attr3 = attrb3.Build();
            var attrb4 = bnet.protocol.attribute.Attribute.CreateBuilder();
            attrb4.SetName("version");
            attrb4.SetValue(vari4);
            var attr4 = attrb4.Build();
            var statsb = bnet.protocol.game_master.GameStatsBucket.CreateBuilder();
            statsb.SetBucketMin(0);
            statsb.SetBucketMax(4.2949673e+009f);
            statsb.SetWaitMilliseconds(1000);
            statsb.SetGamesPerHour(0);
            statsb.SetActiveGames(50);
            statsb.SetActivePlayers(60);
            statsb.SetFormingGames(0);
            statsb.SetWaitingPlayers(0);
            var stats = statsb.Build();
            var factb = bnet.protocol.game_master.GameFactoryDescription.CreateBuilder(); // CoopFactoryID - 14249086168335147635 was value on bnet forum error log
            factb.SetId(14249086168335147635);
            factb.AddStatsBucket(stats);
            factb.AddAttribute(attr1);
            factb.AddAttribute(attr2);
            factb.AddAttribute(attr3);
            factb.AddAttribute(attr4);
            var fact = factb.Build();
            var respb = bnet.protocol.game_master.ListFactoriesResponse.CreateBuilder();
            respb.SetTotalResults(1);
            respb.AddDescription(fact);
            var response = respb.Build(); // Seems rescount is optional

            var packet = new Packet(
                new Header(0xfe, 0x0, packetIn.Header.RequestID, (uint)response.SerializedSize),
                response.ToByteArray());
            client.Send(packet);
        }
예제 #3
0
        public void ExecuteRequest(IClient client, Packet packetIn)
        {
            Logger.Trace("RPC:Storage:ExecuteRequest()");
            var request = bnet.protocol.storage.ExecuteRequest.ParseFrom(packetIn.Payload.ToArray());
            //Logger.Debug("request:\n{0}", request.ToString());
            
            bnet.protocol.storage.ExecuteResponse response = null;
            switch (request.QueryName)
            {
                case "GetGameAccountSettings":
                    response = GameAccountSettings(request);
                    break;
                case "LoadAccountDigest":
                    response = LoadAccountDigest(request);
                    break;
                case "GetHeroDigests":
                    response = GetHeroDigest(request);
                    break;
                case "GetToonSettings":
                    response = GetToonSettings(request);
                    break;
                default:
                    Logger.Warn("Unhandled ExecuteRequest: {0}", request.QueryName);
                    break;
            }                
            
            var packet = new Packet(
                new Header(0xfe, 0x0, packetIn.Header.RequestID, (uint)response.SerializedSize),
                response.ToByteArray());

            client.Send(packet);
        }
예제 #4
0
        public static void Identify(IClient client, CodedInputStream stream)
        {
            var header = new Header(stream);
            var payload = new byte[header.PayloadLength];
            payload = stream.ReadRawBytes((int)header.PayloadLength);

            var packet = new Packet(header, payload);
            var service = Service.GetByID(header.ServiceID);

            if (service == null)
            {
                Logger.Error("No service exists with id: 0x{0}", header.ServiceID.ToString("X2"));
                return;
            }

            var method = service.DescriptorForType.Methods[(int)header.MethodID - 1];
            var proto = service.GetRequestPrototype(method);
            var builder = proto.WeakCreateBuilderForType();

            try
            {
                var message = builder.WeakMergeFrom(CodedInputStream.CreateInstance(packet.Payload.ToArray())).WeakBuild();

                ((IServerService) service).Client = client;
                service.CallMethod(method, null, message, (msg => SendResponse(client, header.RequestID, msg)));
            }
            catch (NotImplementedException)
            {
                Logger.Debug(string.Format("Unimplemented service method: {0} {1}", service.GetType().Name, method.Name));
            }
            catch(Exception e)
            {
                Logger.DebugException(e,string.Empty);
            }
        }
예제 #5
0
        public void Bind(IClient client, Packet packetIn)
        {
            var request = bnet.protocol.connection.BindRequest.ParseFrom(packetIn.Payload.ToArray());

            // supply service id's requested by client using service-hashes.
            var requestedServiceIDs = new List<uint>(); 
            foreach (var serviceHash in request.ImportedServiceHashList)
            {
                var serviceID = ServiceManager.GetServerServiceIDByHash(serviceHash);
                Logger.Trace("RPC:Bind() - Hash: 0x{0}  ID: {1,4}  Service: {2} ", serviceHash.ToString("X8"), serviceID, ServiceManager.GetServerServiceByID(serviceID) != null ? ServiceManager.GetServerServiceByID(serviceID).GetType().Name : "N/A");
                requestedServiceIDs.Add(serviceID);
            }

            // read services supplied by client..
            foreach (var service in request.ExportedServiceList)
            {
                if (!client.Services.ContainsKey(service.Id))
                    client.Services.Add(service.Id, service.Hash);
            }

            var builder = bnet.protocol.connection.BindResponse.CreateBuilder();
            foreach (var serviceId in requestedServiceIDs) builder.AddImportedServiceId(serviceId);
            var response = builder.Build();

            var packet =
                new Packet(
                    new Header(0xfe, 0x0, packetIn.Header.RequestID, (uint) response.SerializedSize),
                    response.ToByteArray());

            client.Send(packet);
        }
예제 #6
0
        private static void SendResponse(IClient client, int requestId, IMessage message)
        {
            var packet = new Packet(
                new Header(0xfe, 0x0, requestId, (uint)message.SerializedSize),
                message.ToByteArray());

            client.Send(packet);
        }
예제 #7
0
        public void GetConfiguration(IClient client, Packet packetIn)
        {
            Logger.Trace("RPC:Exchange:GetConfiguration()");
            var response = bnet.protocol.exchange.GetConfigurationResponse.CreateBuilder().Build();

            var packet = new Packet(
                new Header(0xfe, 0x0, packetIn.Header.RequestID, (uint)response.SerializedSize),
                response.ToByteArray());

            client.Send(packet);
        }
예제 #8
0
        public void OpenColumnRequest(IClient client, Packet packetIn)
        {
            Logger.Trace("RPC:Storage:OpenColumnRequest()");
            var response = bnet.protocol.storage.OpenColumnResponse.CreateBuilder().Build();

            var packet = new Packet(
                new Header(0xfe, 0x0, packetIn.Header.RequestID, (uint)response.SerializedSize),
                response.ToByteArray());

            client.Send(packet);
        }
예제 #9
0
        public void ToonListRequest(IClient client, Packet packetIn)
        {            
            Logger.Trace("RPC:ToonExternal:ToonListRequest()");
            var response = bnet.protocol.toon.external.ToonListResponse.CreateBuilder().Build();

            var packet = new Packet(
                new Header(0xfe, 0x0, packetIn.Header.RequestID, (uint)response.SerializedSize),
                response.ToByteArray());

            client.Send(packet);
        }
        public void Subscribe(IClient client, Packet packetIn)
        {
            Logger.Trace("RPC:ChannelInvitation:Subscribe()");
            var response = bnet.protocol.channel_invitation.SubscribeResponse.CreateBuilder().Build();

            var packet = new Packet(
                new Header(0xfe, 0x0, packetIn.Header.RequestID, (uint)response.SerializedSize),
                response.ToByteArray());

            client.Send(packet);
        }  
예제 #11
0
        public void SubscribeToFollowers(IClient client, Packet packetIn)
        {
            var response = bnet.protocol.followers.SubscribeToFollowersResponse.CreateBuilder().Build();

            var packet = new Packet(
                new Header(0xfe, 0x0, packetIn.Header.RequestID, (uint)response.SerializedSize),
                response.ToByteArray());

            Logger.Trace("RPC:Followers:Subscribe()");
            client.Send(packet);
        }
예제 #12
0
        public void SubscribeToUserManager(IClient client, Packet packetIn)
        {
            Logger.Trace("RPC:UserManager:Subscribe()");
            var response = bnet.protocol.user_manager.SubscribeToUserManagerResponse.CreateBuilder().Build();

            var packet = new Packet(
                new Header(0xfe, 0x0, packetIn.Header.RequestID, (uint)response.SerializedSize),
                response.ToByteArray());

            //TODO: Sending this packet crashes my client. This may be a local issue as I haven't heard anyone else mention it.     -Ethos
            //client.Send(packet);
        }
예제 #13
0
파일: Service.cs 프로젝트: elexor/d3sharp
        public void CallMethod(uint methodID, IClient client, Packet packet)
        {
            if (!this.Methods.ContainsKey(methodID))
            {
                Console.WriteLine("Unknown method 0x{0:x2} called on {1} ", methodID, this.GetType());
                return;
            }

            var method = this.Methods[methodID];
            //Console.WriteLine("[Client]: {0}:{1}", method.ReflectedType.FullName, method.Name);
            method.Invoke(this, new object[] {client, packet});
        }
예제 #14
0
        public void UnsubscribeOrderStatusChangeRequest(IClient client, Packet packetIn)
        {
            Logger.Trace("RPC:Exchange:UnsubscribeOrderStatusChangeRequest() Stub");
            var request = bnet.protocol.exchange.UnsubscribeOrderStatusChangeRequest.ParseFrom(packetIn.Payload.ToArray());

            var response = bnet.protocol.NoData.CreateBuilder().Build();

            var packet = new Packet(
                new Header(0xfe, 0x0, packetIn.Header.RequestID, (uint)response.SerializedSize),
                response.ToByteArray());

            client.Send(packet);
        }
예제 #15
0
        public void Connect(IClient client, Packet packetIn)
        {
            Logger.Trace("RPC:Connect()");
            var response = bnet.protocol.connection.ConnectResponse.CreateBuilder()
                .SetServerId(ProcessId.CreateBuilder().SetLabel(0xAAAA).SetEpoch(DateTime.Now.ToUnixTime()))
                .SetClientId(ProcessId.CreateBuilder().SetLabel(0xBBBB).SetEpoch(DateTime.Now.ToUnixTime()))
                .Build();

            var packet = new Packet(
                    new Header(0xfe, 0x0, packetIn.Header.RequestID, (uint)response.SerializedSize),
                    response.ToByteArray());

            client.Send(packet);
        }
예제 #16
0
        public void Logon(IClient client, Packet packetIn)
        {
            Logger.Trace("RPC:Authentication:Logon()");
            var response = bnet.protocol.authentication.LogonResponse.CreateBuilder()
                .SetAccount(EntityId.CreateBuilder().SetHigh(0x100000000000000).SetLow(0))
                .SetGameAccount(EntityId.CreateBuilder().SetHigh(0x200006200004433).SetLow(0))
                .Build();

            var packet = new Packet(
                new Header(0xfe, 0x0, packetIn.Header.RequestID, (uint)response.SerializedSize),
                response.ToByteArray());

            client.Send(packet);
        }       
예제 #17
0
        public void SubscribeToFriends(IClient client, Packet packetIn)
        {
            Logger.Trace("RPC:Friends:SubscribeToFriends()");
            var response = bnet.protocol.friends.SubscribeToFriendsResponse.CreateBuilder()
                .SetMaxFriends(127)
                .SetMaxReceivedInvitations(127)
                .SetMaxSentInvitations(127)
                .Build();

            var packet = new Packet(
                new Header(0xfe, 0x0, packetIn.Header.RequestID, (uint)response.SerializedSize),
                response.ToByteArray());

            client.Send(packet);
        }
예제 #18
0
        public void CreateChannel(IClient client, Packet packetIn)
        {
            Logger.Trace("RPC:Party:CreateChannel()");
            var request = bnet.protocol.channel.CreateChannelRequest.ParseFrom(packetIn.Payload.ToArray());
            //Logger.Debug("request:\n{0}", request.ToString());

            var response = bnet.protocol.channel.CreateChannelResponse.CreateBuilder()
                .SetObjectId(request.ObjectId)
                .SetChannelId(bnet.protocol.EntityId.CreateBuilder().SetHigh(0xCCDD).SetLow(0xAABB))
                .Build();

            var packet = new Packet(
                new Header(0xfe, 0x0, packetIn.Header.RequestID, (uint)response.SerializedSize),
                response.ToByteArray());

            client.Send(packet);
        }
예제 #19
0
        public void ProcessClient(IClient client, Packet packetIn)
        {
            Logger.Trace("RPC:GameUtilities:ProcessClientRequest()");
            //var request = bnet.protocol.game_utilities.ProcessClient.ParseFrom(packetIn.Payload.ToArray());

            var request = bnet.protocol.game_utilities.ClientRequest.ParseFrom(packetIn.Payload.ToArray());

            // TODO: handle the request. this is where banner changing happens (CustomMessageId 4)
            // CustomMessage for banner change is a D3.GameMessages.SaveBannerConfiguration
            var response = bnet.protocol.game_utilities.ClientResponse.CreateBuilder().Build();

            var packet = new Packet(
                new Header(0xfe, 0x0, packetIn.Header.RequestID, (uint)response.SerializedSize),
                response.ToByteArray());

            client.Send(packet);
        }
예제 #20
0
        public void DeleteToon(IClient client, Packet packetIn)
        {
            Logger.Trace("RPC:ToonExternal:DeleteToon()");

            var request = bnet.protocol.toon.external.DeleteToonRequest.ParseFrom(packetIn.Payload.ToArray());
            var id = request.Toon.Low;

            var toon = Toons.ToonManager.GetToon(id);
            Toons.ToonManager.DeleteToon(toon);

            var response = bnet.protocol.toon.external.DeleteToonResponse.CreateBuilder().Build();

            var packet = new Packet(
                new Header(0xfe, 0x0, packetIn.Header.RequestID, (uint)response.SerializedSize),
                response.ToByteArray());

            client.Send(packet);
        }
예제 #21
0
        public static int Identify(IClient client, CodedInputStream stream)
        {
            var header = new Header(stream);
            var payload = new byte[header.PayloadLength];
            payload = stream.ReadRawBytes((int)header.PayloadLength);
            
            var packet = new Packet(header, payload);
            var service = ServiceManager.GetServerServiceByID(header.ServiceID);

            if(service!=null)
            {
                service.CallMethod(header.MethodID, client, packet);
                return packet.Length;
            }

            Console.WriteLine("\n===========[Unknown Crap]===========\nHeader\t: {0}Payload\t: {1}", header.Data.Dump(), payload.Dump());
            return 0;
        }
예제 #22
0
파일: Client.cs 프로젝트: xynoman/d3sharp
        public void CallMethod(MethodDescriptor method, IRpcController controller, IMessage request, IMessage responsePrototype, Action<IMessage> done, ulong objectId)
        {
            var serviceName = method.Service.FullName;
            var serviceHash = StringHashHelper.HashString(serviceName);

            if (!this.Services.ContainsKey(serviceHash))
            {
                Logger.Error("Not bound to client service {0} [0x{1}] yet.", serviceName, serviceHash.ToString("X8"));
                return;
            }

            var serviceId = this.Services[serviceHash];
            var packet = new Packet(
                new Header((byte)serviceId, (uint)(method.Index + 1), this._requestCounter++, (uint)request.SerializedSize, objectId),
                request.ToByteArray());

            this.Send(packet);
        }
예제 #23
0
        public void CreateToon(IClient client, Packet packetIn)
        {
            Logger.Trace("RPC:ToonExternal:CreateToon()");
            
            var request = bnet.protocol.toon.external.CreateToonRequest.ParseFrom(packetIn.Payload.ToArray());
            var heroCreateParams = D3.OnlineService.HeroCreateParams.ParseFrom(request.AttributeList[0].Value.MessageValue);
            var builder = bnet.protocol.toon.external.CreateToonResponse.CreateBuilder();

            var toon = new Toons.Toon(request.Name, (uint)heroCreateParams.GbidClass, heroCreateParams.IsFemale ? Toons.ToonGender.Female : Toons.ToonGender.Male, 1);
            if (Toons.ToonManager.SaveToon(toon)) builder.SetToon(toon.BnetEntityID);

            var response = builder.Build();

            var packet = new Packet(
                new Header(0xfe, 0x0, packetIn.Header.RequestID, (uint)response.SerializedSize),
                response.ToByteArray());

            client.Send(packet);
        }
예제 #24
0
        public static int Identify(IClient client, byte[] buffer)
        {
            var header = new Header(buffer.Take(6));
            var payload = new byte[header.PayloadLength];
            // if our packet contains a payload, get it.
            if (header.PayloadLength > 0)
                Array.Copy(buffer, 6, payload, 0, header.PayloadLength);


            var packet = new Packet(header, payload);
            var service = ServiceManager.GetServerServiceByID(header.ServiceID);

            if(service!=null)
            {
                service.CallMethod(header.MethodID, client, packet);
                return packet.Lenght;
            }

            Console.WriteLine("\n===========[Unknown Crap]===========\nHeader\t: {0}Payload\t: {1}", header.Data.Dump(), payload.Dump());
            return 0;
        }
예제 #25
0
        public void CallMethod(MethodDescriptor method, IMessage request, ulong localObjectId)
        {
            var serviceName = method.Service.FullName;
            var serviceHash = StringHashHelper.HashString(serviceName);           

            if (!this.Services.ContainsKey(serviceHash))
            {
                Logger.Error("Not bound to client service {0} [0x{1}] yet.", serviceName, serviceHash.ToString("X8"));
                return;
            }
            
            var serviceId = this.Services[serviceHash];
            var remoteObjectId = GetRemoteObjectID(localObjectId);

            Logger.Debug("Calling {0} localObjectId={1}, remoteObjectId={2}", method.FullName, localObjectId, remoteObjectId);
            
            var packet = new Packet(
                new Header((byte) serviceId, (uint) (method.Index + 1), this._requestCounter++,(uint) request.SerializedSize, remoteObjectId),
                request.ToByteArray());

            this.Send(packet);
        }
예제 #26
0
        public void ToonList(IClient client, Packet packetIn)
        {            
            Logger.Trace("RPC:ToonExternal:ToonList()");

            var builder = bnet.protocol.toon.external.ToonListResponse.CreateBuilder();

            if (Toons.ToonManager.Toons.Count > 0)
            {
                foreach(var pair in Toons.ToonManager.Toons)
                {                    
                    builder.AddToons(pair.Value.BnetEntityID);
                }
            }

            var response = builder.Build();

            var packet = new Packet(
                new Header(0xfe, 0x0, packetIn.Header.RequestID, (uint)response.SerializedSize),
                response.ToByteArray());

            client.Send(packet);
        }
예제 #27
0
        public void SendInvitationRequest(IClient client, Packet packetIn)
        {
            //TODO: Set these to the corect values.
            const ulong accountHandle = 0x0000000000000000;
            const ulong gameAccountHandle = 0x0000000000000000;

            Logger.Trace("RPC:Friends:SendInvitationRequest() Stub");
            var request = bnet.protocol.invitation.SendInvitationRequest.ParseFrom(packetIn.Payload.ToArray());

            var invitation = bnet.protocol.invitation.Invitation.CreateBuilder()
                .SetCreationTime(DateTime.Now.ToUnixTime())
                .SetExpirationTime(request.ExpirationTime)
                .SetId(0)
                .SetInvitationMessage(request.InvitationMessage)
                .SetInviteeIdentity(bnet.protocol.Identity.CreateBuilder()
                    .SetAccountId(bnet.protocol.EntityId.CreateBuilder().SetHigh(accountHandle).SetLow(0x1).Build())            //TODO: Change SetLow to an actual index in the database.
                    .SetGameAccountId(bnet.protocol.EntityId.CreateBuilder().SetHigh(gameAccountHandle).SetLow(0x1).Build())    //TODO: Change SetLow to an actual index in the database.
                    .Build())
                .SetInviteeName("FriendName")                                                                                   //TODO: Set this to the name retrieved from the database.
                .SetInviterIdentity(bnet.protocol.Identity.CreateBuilder()
                    .SetAccountId(bnet.protocol.EntityId.CreateBuilder().SetHigh(accountHandle).SetLow(0x0).Build())            //TODO: Change SetLow to an actual index in the database.
                    .SetGameAccountId(bnet.protocol.EntityId.CreateBuilder().SetHigh(gameAccountHandle).SetLow(0x0).Build())    //TODO: Change SetLow to an actual index in the database.
                    .Build())
                .SetInviterName("YourName")                                                                                     //TODO: Set this to the name retrieved from the database.
                .Build();

            var response = bnet.protocol.invitation.SendInvitationResponse.CreateBuilder()
                .SetInvitation(invitation)
                .Build();

            var packet = new Packet(
                new Header(0xfe, 0x0, packetIn.Header.RequestID, (uint)response.SerializedSize),
                response.ToByteArray());

            client.Send(packet);
        }
예제 #28
0
 public void GetChannelInfo(IClient client, Packet packetIn)
 {
     Logger.Trace("RPC:Party:GetChannelInfo() Stub");
 }
예제 #29
0
 public void JoinChannel(IClient client, Packet packetIn)
 {
     Logger.Trace("RPC:Party:JoinChannel() Stub");
 }
예제 #30
0
파일: Client.cs 프로젝트: Ehnn/d3sharp
 public int Send(Packet packet)
 {
     if (packet == null) throw new ArgumentNullException("packet");
     return Send(packet.GetRawPacketData());
 }