Skip to content

Commit ba22f41

Browse files
author
raistlinthewiz
committed
Fixed the BindRequest logic.. working all good now..
1 parent fb261af commit ba22f41

File tree

10 files changed

+71
-46
lines changed

10 files changed

+71
-46
lines changed

docs/services 2.url

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[InternetShortcut]
2+
URL=http://pastie.org/2538697

source/D3Sharp/D3Sharp.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<Compile Include="Net\Packets\PacketOut.cs" />
7272
<Compile Include="Net\Packets\Protocol\Followers\Followers.cs" />
7373
<Compile Include="Net\Packets\Protocol\Friends\Friends.cs" />
74+
<Compile Include="Net\Packets\Protocol\Toon\Toon.cs" />
7475
<Compile Include="Net\Packets\Protocol\UserManager\UserManager.cs" />
7576
<Compile Include="Program.cs" />
7677
<Compile Include="Net\Client.cs" />

source/D3Sharp/Net/Client.cs

+13-21
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@ public Client(Server server, Socket socket)
5050

5151
this._server = server;
5252
this._socket = socket;
53-
this.Services = new Dictionary<uint, uint>
54-
{
55-
{0x0, 0x0} // base service.
56-
};
53+
this.Services = new Dictionary<uint, uint>();
5754
}
5855

56+
private static uint _importedServiceCounter = 99;
57+
5958
public void Process(PacketIn packet)
6059
{
6160
Console.WriteLine(packet);
@@ -67,32 +66,25 @@ public void Process(PacketIn packet)
6766
Console.WriteLine(response);
6867
}
6968
else if (packet is BindRequest)
70-
{
71-
var importedServicesIDs = new List<uint>();
72-
foreach (var service in packet.Request.ExportedServiceList) // add list of imported services supplied by client.
69+
{
70+
var requestedServiceIDs = new List<uint>();
71+
72+
foreach (var serviceHash in packet.Request.ImportedServiceHashList) // supply service id's requested by client using service-hashes.
7373
{
74-
importedServicesIDs.Add(service.Id);
75-
if (!this.Services.ContainsKey(service.Id)) this.Services.Add(service.Id, service.Hash);
74+
requestedServiceIDs.Add(Server.Services.ContainsValue(serviceHash) ? Server.Services.Where(pair => pair.Value == serviceHash).FirstOrDefault().Key : _importedServiceCounter++);
7675
}
7776

78-
if (importedServicesIDs.Count > 0)
77+
if (requestedServiceIDs.Count > 0)
7978
{
80-
var response = new BindResponse(packet.Header.RequestID, importedServicesIDs);
79+
var response = new BindResponse(packet.Header.RequestID, requestedServiceIDs);
8180
this.Send(response.GetRawPacketData());
8281
Console.WriteLine(response);
8382
}
84-
85-
var requestedServices = new Dictionary<uint,uint>();
86-
if (requestedServices.Count > 0)
83+
84+
foreach (var service in packet.Request.ExportedServiceList) // add list of imported services supplied by client.
8785
{
88-
foreach (var serviceHash in packet.Request.ImportedServiceHashList) // supply service id's requested by client using service-hashes.
89-
{
90-
requestedServices.Add(Server.Services.ContainsKey(serviceHash) ? Server.Services[serviceHash] : (uint) 255, serviceHash);
91-
// probably we should reply with a BoundService.
92-
}
86+
if (!this.Services.ContainsKey(service.Id)) this.Services.Add(service.Id, service.Hash);
9387
}
94-
95-
9688
}
9789

9890
else if (packet is LogonRequest)

source/D3Sharp/Net/Packets/Header.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class Header
1010
{
1111
public byte[] Data { get; private set; }
1212

13-
public byte Service { get; set; }
13+
public byte ServiceID { get; set; }
1414
public uint Method { get; set; }
1515
public int RequestID { get; set; }
1616
public ulong Unknown { get; set; }
@@ -27,10 +27,10 @@ public Header(byte[] data)
2727
this.Data = data;
2828

2929
var stream = CodedInputStream.CreateInstance(data);
30-
this.Service = stream.ReadRawByte();
30+
this.ServiceID = stream.ReadRawByte();
3131
this.Method = stream.ReadRawVarint32();
32-
this.RequestID = stream.ReadRawByte() | (stream.ReadRawByte() << 8);
33-
if (Service != 0xfe) this.Unknown = stream.ReadRawVarint64();
32+
this.RequestID = stream.ReadRawByte() | (stream.ReadRawByte() << 8);
33+
if (ServiceID != 0xfe) this.Unknown = stream.ReadRawVarint64();
3434
this.PayloadLength = stream.ReadRawVarint32();
3535
}
3636

@@ -51,7 +51,7 @@ public void Build()
5151

5252
public override string ToString()
5353
{
54-
return string.Format("[S]: 0x{0}, [M]: 0x{1}, [R]: 0x{2}, [L]: 0x{3}", this.Service.ToString("X2"), this.Method.ToString("X2"), this.RequestID.ToString("X2"), this.PayloadLength.ToString("X2"));
54+
return string.Format("[S]: 0x{0}, [M]: 0x{1}, [R]: 0x{2}, [L]: 0x{3}", this.ServiceID.ToString("X2"), this.Method.ToString("X2"), this.RequestID.ToString("X2"), this.PayloadLength.ToString("X2"));
5555
}
5656
}
5757
}

source/D3Sharp/Net/Packets/Parser.cs

+10-6
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,18 @@ public static int Identify(IClient client, byte[] buffer)
4949
var payload = new byte[header.PayloadLength];
5050
if (header.PayloadLength > 0) Array.Copy(buffer, 6, payload, 0, header.PayloadLength); // if our packet contains a payload, get it.
5151

52-
if (client.Services.ContainsKey(header.Service)) // if matching service exists for the request.
52+
53+
if(Server.Services.ContainsKey(header.ServiceID))
5354
{
54-
foreach (var packet in from pair in Packets
55-
where client.Services[header.Service] == pair.Value.ServiceHash && header.Method == pair.Value.Method
56-
select Activator.CreateInstance(pair.Key, new object[] { header, payload })) // try to match requested service against know packet classes.
55+
var serviceHash = Server.Services[header.ServiceID];
56+
foreach(var pair in Packets)
5757
{
58-
client.Process((PacketIn) packet);
59-
return header.Data.Length + payload.Length;
58+
if(pair.Value.ServiceHash==serviceHash && pair.Value.Method == header.Method)
59+
{
60+
var packet = Activator.CreateInstance(pair.Key, new object[] {header, payload});
61+
client.Process((PacketIn)packet);
62+
return header.Data.Length + payload.Length;
63+
}
6064
}
6165
}
6266

source/D3Sharp/Net/Packets/Protocol/Authentication/Authentication.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace D3Sharp.Net.Packets.Protocol.Authentication
66
{
7-
[Service(serviceID: -1, serviceHash: 0x71240e35, method: 0x1)]
7+
[Service(serviceID: -1, serviceHash: 0xDECFC01, method: 0x1)]
88
public class LogonRequest : PacketIn
99
{
1010
public LogonRequest(Header header, IEnumerable<byte> payload)

source/D3Sharp/Net/Packets/Protocol/Connection/Connections.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ public BindRequest(Header header, IEnumerable<byte> payload)
3939

4040
public class BindResponse : PacketOut
4141
{
42-
public BindResponse(int requestID, IEnumerable<uint> importedServices)
42+
public BindResponse(int requestID, IEnumerable<uint> requestedServiceIDs)
4343
: base(requestID)
4444
{
45-
var builder = bnet.protocol.connection.BindResponse.CreateBuilder();
46-
foreach (var serviceId in importedServices) { builder.AddImportedServiceId(serviceId); }
45+
var builder = bnet.protocol.connection.BindResponse.CreateBuilder();
46+
foreach (var serviceId in requestedServiceIDs) { builder.AddImportedServiceId(serviceId); }
4747
this.Response = builder.Build();
4848

4949
this.Header = new Header(new byte[] { 0xfe, 0x0, (byte)requestID, 0x0, (byte)this.Response.SerializedSize });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace D3Sharp.Net.Packets.Protocol.Toon
7+
{
8+
[Service(serviceID: -1, serviceHash: 0x83040608, method: 0x1)]
9+
public class ToonListRequest : PacketIn
10+
{
11+
public ToonListRequest(Header header, IEnumerable<byte> payload)
12+
: base(header, payload)
13+
{
14+
this.Request = bnet.protocol.toon.external.ToonListRequest.CreateBuilder().MergeFrom(this.Payload.ToArray()).Build();
15+
}
16+
}
17+
}

source/D3Sharp/Net/Server.cs

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ public class Server : IDisposable
2525
public event ConnectionDataEventHandler DataReceived;
2626
public event ConnectionDataEventHandler DataSent;
2727

28+
29+
public static Dictionary<uint, uint> Services = new Dictionary<uint, uint>
30+
{
31+
{0x0, 0x0}, // base service
32+
{0x1, 0xB732DB32}, // connection service
33+
{0x2, 0xDECFC01}, // authentication service
34+
{0x3, 0x83040608 } // toon service
35+
};
36+
2837
private static readonly Logger Logger = LogManager.CreateLogger();
2938
private bool _disposed;
3039

tools/d3watchproto/DefProf.ini

+10-10
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ Win0RTop=162
2626
Win0RRight=1229
2727
Win0RBottom=767
2828
Win0Max=0
29-
Win0Dock0RLeft=1132
30-
Win0Dock0RTop=751
31-
Win0Dock0RRight=1332
32-
Win0Dock0RBottom=1351
29+
Win0Dock0RLeft=1597
30+
Win0Dock0RTop=963
31+
Win0Dock0RRight=1797
32+
Win0Dock0RBottom=1563
3333
Win0Dock0Val=52494338
3434
Win0Dock0Docked=1
35-
Win0Dock1RLeft=1080
36-
Win0Dock1RTop=574
37-
Win0Dock1RRight=1280
38-
Win0Dock1RBottom=1174
35+
Win0Dock1RLeft=1545
36+
Win0Dock1RTop=786
37+
Win0Dock1RRight=1745
38+
Win0Dock1RBottom=1386
3939
Win0Dock1Val=52494337
4040
Win0Dock1Docked=1
4141
[CusFuncs]
@@ -53,8 +53,8 @@ Font_Under=0
5353
Font_CharSet=0
5454
Font_PF=2
5555
FontColor=0
56-
MiscPath=C:\Users\shalafi\Desktop\d3watchproto\
57-
UddPath=C:\Users\shalafi\Desktop\d3watchproto\
56+
MiscPath=C:\Users\shalafi\Desktop\d3sharp\tools\d3watchproto\
57+
UddPath=C:\Users\shalafi\Desktop\d3sharp\tools\d3watchproto\
5858
ColBack=16777215
5959
ColFront=0
6060
ColSel=12937777

0 commit comments

Comments
 (0)