Skip to content

Commit

Permalink
Error 7 fix by gaddas
Browse files Browse the repository at this point in the history
  • Loading branch information
xynoman committed Sep 19, 2011
1 parent c0b6d9c commit 4ba7387
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 20 deletions.
17 changes: 14 additions & 3 deletions source/D3Sharp/Core/Channels/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void NotifyChannelState(Client client)
client.CallMethod(bnet.protocol.channel.ChannelSubscriber.Descriptor.FindMethodByName("NotifyUpdateChannelState"), null, builder, null, r => { });
}

public void Add(Client client)
public void Add(Client client, ulong objectId)
{
var builder = bnet.protocol.channel.AddNotification.CreateBuilder();
var identity = bnet.protocol.Identity.CreateBuilder();
Expand All @@ -77,10 +77,21 @@ public void Add(Client client)
var selfBuilder = bnet.protocol.channel.Member.CreateBuilder().SetIdentity(identity.Build()).SetState(state.Build());
var self = selfBuilder.Build();
builder.SetSelf(self);
builder.AddMember(self);

if (client.Account.Toons.Count > 0)
{
var memberIdentity = bnet.protocol.Identity.CreateBuilder();
memberIdentity.SetToonId(client.Account.Toons.First().Value.BnetEntityID);

var memberState = bnet.protocol.channel.MemberState.CreateBuilder().AddRole(2).SetPrivileges(64511);

var member = bnet.protocol.channel.Member.CreateBuilder().SetIdentity(memberIdentity).SetState(memberState.Build());
builder.AddMember(self);
}

builder.SetChannelState(this.State);

client.CallMethod(bnet.protocol.channel.ChannelSubscriber.Descriptor.FindMethodByName("NotifyAdd"), null, builder.Build(), null, r => { });
client.CallMethod(bnet.protocol.channel.ChannelSubscriber.Descriptor.FindMethodByName("NotifyAdd"), null, builder.Build(), null, r => { }, objectId);
}
}
}
16 changes: 15 additions & 1 deletion source/D3Sharp/Core/Services/ChannelOwnerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,21 @@ public override void GetChannelInfo(Google.ProtocolBuffers.IRpcController contro

public override void JoinChannel(Google.ProtocolBuffers.IRpcController controller, bnet.protocol.channel.JoinChannelRequest request, System.Action<bnet.protocol.channel.JoinChannelResponse> done)
{
throw new System.NotImplementedException();
Logger.Trace("JoinChannel()");

////>>> JoinChannelRequest
////channel_id {
//// high: 433661094641971304
//// low: 11017467167309309688
////}
////object_id: 15


////>>> JoinChannelResponse
////object_id: 67122

var builder = bnet.protocol.channel.JoinChannelResponse.CreateBuilder().SetObjectId(67122);
done(builder.Build());
}
}
}
64 changes: 63 additions & 1 deletion source/D3Sharp/Core/Services/GameMasterService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using D3Sharp.Net;
using D3Sharp.Net.Packets;
using D3Sharp.Utils;
Expand Down Expand Up @@ -49,7 +50,68 @@ public override void ListFactories(IRpcController controller, ListFactoriesReque

public override void FindGame(IRpcController controller, FindGameRequest request, Action<FindGameResponse> done)
{
throw new NotImplementedException();
Logger.Trace("FindGame()");

////>>> FindGameResponse
////request_id: 12526585062881647236

var findGameResponse = bnet.protocol.game_master.FindGameResponse.CreateBuilder();
findGameResponse.SetRequestId(12526585062881647236);

done(findGameResponse.Build());

var gameFoundNotification = bnet.protocol.game_master.GameFoundNotification.CreateBuilder();

var gameHandle = bnet.protocol.game_master.GameHandle.CreateBuilder();
gameHandle.SetFactoryId(request.FactoryId);
gameHandle.SetGameId(bnet.protocol.EntityId.CreateBuilder().SetHigh(433661094641971304).SetLow(11017467167309309688).Build());

var connectInfo = bnet.protocol.game_master.ConnectInfo.CreateBuilder();
connectInfo.SetToonId(Client.Account.Toons.First().Value.BnetEntityID);
connectInfo.SetHost("127.0.0.1");
connectInfo.SetPort(1345);
connectInfo.SetToken(ByteString.CopyFrom(new byte[] { 0x07, 0x34, 0x02, 0x60, 0x91, 0x93, 0x76, 0x46, 0x28, 0x84 }));
connectInfo.AddAttribute(bnet.protocol.attribute.Attribute
.CreateBuilder()
.SetName("SGameId")
.SetValue(bnet.protocol.attribute.Variant
.CreateBuilder()
.SetIntValue(2014314530)
.Build())
.Build());

gameFoundNotification.SetRequestId(12526585062881647236);
gameFoundNotification.SetGameHandle(gameHandle.Build());
gameFoundNotification.AddConnectInfo(connectInfo.Build());

var c = this.Client as Client;
c.CallMethod(bnet.protocol.game_master.GameFactorySubscriber.Descriptor.FindMethodByName("NotifyGameFound"), null, gameFoundNotification.Build(), null, r => { }, 1);


//// >>> GameFoundNotification
////request_id: 12526585062881647236
////game_handle {
//// factory_id: 14249086168335147635
//// game_id {
//// high: 433661094641971304
//// low: 11017467167309309688
//// }
////}
////connect_info {
//// toon_id {
//// high: 216174302532224051
//// low: 2345959482769161802
//// }
//// host: "12.129.237.197"
//// port: 1119
//// token: "7340260919376462884"
//// attribute {
//// name: "SGameId"
//// value {
//// int_value: 2014314530
//// }
//// }
////}
}

public override void CancelFindGame(IRpcController controller, CancelFindGameRequest request, Action<NoData> done)
Expand Down
3 changes: 2 additions & 1 deletion source/D3Sharp/Core/Services/PartyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ public override void CreateChannel(IRpcController controller, CreateChannelReque

var channel = ChannelsManager.CreateNewChannel(Client);
var builder = CreateChannelResponse.CreateBuilder()
.SetObjectId(request.ObjectId)
.SetObjectId(channel.ID)
.SetChannelId(channel.BnetEntityID);

done(builder.Build());

channel.Add((Client)this.Client, request.ObjectId);
channel.NotifyChannelState((Client)this.Client);
}

Expand Down
11 changes: 8 additions & 3 deletions source/D3Sharp/Net/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public Client(Server server, Socket socket)
this.Services = new Dictionary<uint, uint>();
}

// rpc to client
public void CallMethod(MethodDescriptor method, IRpcController controller, IMessage request, IMessage responsePrototype, Action<IMessage> done)
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);
Expand All @@ -51,10 +50,16 @@ public void CallMethod(MethodDescriptor method, IRpcController controller, IMess

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

this.Send(packet);
}

// rpc to client
public void CallMethod(MethodDescriptor method, IRpcController controller, IMessage request, IMessage responsePrototype, Action<IMessage> done)
{
this.CallMethod(method, controller, request, responsePrototype, done, 0);
}

#region socket stuff
Expand Down
22 changes: 12 additions & 10 deletions source/D3Sharp/Net/Packets/Header.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,39 @@ public class Header
public byte ServiceID { get; set; }
public uint MethodID { get; set; }
public int RequestID { get; set; }
public ulong Unknown { get; set; }
public ulong ObjectID { get; set; }
public uint PayloadLength { get; set; }

public Header()
{
this.Unknown = 0x00;
{
this.ObjectID = 0x00;
this.PayloadLength = 0x00;
}

public Header(byte serviceId, uint methodId, int requestId, uint payloadLenght)
public Header(byte serviceId, uint methodId, int requestId, uint payloadLenght, ulong objectId)
{
this.SetData(serviceId, methodId, requestId, payloadLenght);
this.SetData(serviceId, methodId, requestId, payloadLenght, objectId);
}

public Header(CodedInputStream stream)
{
var serviceId = stream.ReadRawByte();
var methodId = stream.ReadRawVarint32();
var requestId = stream.ReadRawByte() | (stream.ReadRawByte() << 8);
if (serviceId != 0xfe) this.Unknown = stream.ReadRawVarint64();
var objectId = 0UL;

if (serviceId != 0xfe) objectId = stream.ReadRawVarint64();
var payloadLength = stream.ReadRawVarint32();

this.SetData(serviceId, methodId, requestId, payloadLength);
this.SetData(serviceId, methodId, requestId, payloadLength, objectId);
}

private void SetData(byte serviceId, uint methodId, int requestId, uint payloadLenght)
private void SetData(byte serviceId, uint methodId, int requestId, uint payloadLenght, ulong objectId)
{
this.ServiceID = serviceId;
this.MethodID = methodId;
this.RequestID = requestId;
this.Unknown = 0x0;
this.ObjectID = objectId;
this.PayloadLength = payloadLenght;

this.Data = this.ServiceID != 0xfe ? new byte[6] : new byte[5];
Expand All @@ -56,7 +58,7 @@ private void SetData(byte serviceId, uint methodId, int requestId, uint payloadL
output.WriteRawVarint32(this.MethodID);
output.WriteRawByte((byte)(this.RequestID & 0xff));
output.WriteRawByte((byte)(this.RequestID >> 8));
if (serviceId != 0xfe) output.WriteRawVarint64(this.Unknown);
if (serviceId != 0xfe) output.WriteRawVarint64(this.ObjectID);
output.WriteRawVarint32(this.PayloadLength);
output.Flush();

Expand Down
2 changes: 1 addition & 1 deletion source/D3Sharp/Net/Packets/PacketRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static void Identify(IClient client, CodedInputStream stream)
private static void SendResponse(IClient client, int requestId, IMessage message)
{
var packet = new Packet(
new Header(0xfe, 0x0, requestId, (uint)message.SerializedSize),
new Header(0xfe, 0x0, requestId, (uint)message.SerializedSize, 0),
message.ToByteArray());

client.Send(packet);
Expand Down
9 changes: 9 additions & 0 deletions source/D3Sharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ internal class Program

public static void Main(string[] args)
{
////var y = D3Sharp.Utils.Helpers.StringHashHelper.HashString("bnet.protocol.game_master.GameFactorySubscriber");

////var x = bnet.protocol.game_master.GameMasterSubscriber.Descriptor.FindMethodByName("NotifyFactoryUpdate");
////x = bnet.protocol.notification.NotificationListener.Descriptor.FindMethodByName("");

////var serviceName = x.Service.FullName;
////var serviceHash = D3Sharp.Utils.Helpers.StringHashHelper.HashString(serviceName);


AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; // watch for unhandled-exceptions.

LogManager.Enabled = true; // enable the logger.
Expand Down

0 comments on commit 4ba7387

Please sign in to comment.