Fixed changing realms. Temp fix till i can come up with a better way.
This commit is contained in:
@@ -43,7 +43,6 @@ namespace BNetServer.Services
|
|||||||
|
|
||||||
public void Dispatch(Session session, uint serviceHash, uint token, uint methodId, CodedInputStream stream)
|
public void Dispatch(Session session, uint serviceHash, uint token, uint methodId, CodedInputStream stream)
|
||||||
{
|
{
|
||||||
Log.outInfo(LogFilter.Server, "ServiceHash = {0}, methodId = {1}", serviceHash, methodId);
|
|
||||||
var action = _dispatchers.LookupByKey(serviceHash);
|
var action = _dispatchers.LookupByKey(serviceHash);
|
||||||
if (action != null)
|
if (action != null)
|
||||||
action(session, serviceHash, token, methodId, stream);
|
action(session, serviceHash, token, methodId, stream);
|
||||||
|
|||||||
+2
-2
@@ -50,7 +50,7 @@
|
|||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Google.Protobuf">
|
<Reference Include="Google.Protobuf">
|
||||||
@@ -191,7 +191,7 @@
|
|||||||
<Compile Include="Scenarios\Scenario.cs" />
|
<Compile Include="Scenarios\Scenario.cs" />
|
||||||
<Compile Include="Scenarios\ScenarioManager.cs" />
|
<Compile Include="Scenarios\ScenarioManager.cs" />
|
||||||
<Compile Include="Services\GameUtilitiesService.cs" />
|
<Compile Include="Services\GameUtilitiesService.cs" />
|
||||||
<Compile Include="Services\ServiceManager.cs" />
|
<Compile Include="Services\ServiceDispatcher.cs" />
|
||||||
<Compile Include="Text\ChatTextBuilder.cs" />
|
<Compile Include="Text\ChatTextBuilder.cs" />
|
||||||
<Compile Include="Chat\CommandAttribute.cs" />
|
<Compile Include="Chat\CommandAttribute.cs" />
|
||||||
<Compile Include="Chat\CommandHandler.cs" />
|
<Compile Include="Chat\CommandHandler.cs" />
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ using Game.PvP;
|
|||||||
using Game.Scenarios;
|
using Game.Scenarios;
|
||||||
using Game.Scripting;
|
using Game.Scripting;
|
||||||
using Game.SupportSystem;
|
using Game.SupportSystem;
|
||||||
|
using Game.Services;
|
||||||
|
|
||||||
public static class Global
|
public static class Global
|
||||||
{
|
{
|
||||||
@@ -42,6 +43,7 @@ public static class Global
|
|||||||
public static ObjectManager ObjectMgr { get { return ObjectManager.Instance; } }
|
public static ObjectManager ObjectMgr { get { return ObjectManager.Instance; } }
|
||||||
public static WorldManager WorldMgr { get { return WorldManager.Instance; } }
|
public static WorldManager WorldMgr { get { return WorldManager.Instance; } }
|
||||||
public static RealmManager RealmMgr { get { return RealmManager.Instance; } }
|
public static RealmManager RealmMgr { get { return RealmManager.Instance; } }
|
||||||
|
public static ServiceDispatcher ServiceMgr { get { return ServiceDispatcher.Instance; } }
|
||||||
|
|
||||||
//Guild
|
//Guild
|
||||||
public static GuildManager GuildMgr { get { return GuildManager.Instance; } }
|
public static GuildManager GuildMgr { get { return GuildManager.Instance; } }
|
||||||
|
|||||||
@@ -29,17 +29,7 @@ namespace Game
|
|||||||
[WorldPacketHandler(ClientOpcodes.BattlenetRequest, Status = SessionStatus.Authed)]
|
[WorldPacketHandler(ClientOpcodes.BattlenetRequest, Status = SessionStatus.Authed)]
|
||||||
void HandleBattlenetRequest(BattlenetRequest request)
|
void HandleBattlenetRequest(BattlenetRequest request)
|
||||||
{
|
{
|
||||||
var handler = ServiceManager.GetHandler((NameHash)request.Method.GetServiceHash(), request.Method.GetMethodId());
|
Global.ServiceMgr.Dispatch(this, request.Method.GetServiceHash(), request.Method.Token, request.Method.GetMethodId(), new CodedInputStream(request.Data));
|
||||||
if (handler == null)
|
|
||||||
{
|
|
||||||
Log.outError(LogFilter.Server, "No defined handler ServiceHash {0} MethodId {1} Sent by {2}", (NameHash)request.Method.GetServiceHash(), request.Method.GetMethodId(), GetPlayerInfo());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var status = handler.Invoke(this, new CodedInputStream(request.Data));
|
|
||||||
if (status != BattlenetRpcErrorCode.Ok)
|
|
||||||
SendBattlenetResponse(request.Method.GetServiceHash(), request.Method.GetMethodId(), status);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[WorldPacketHandler(ClientOpcodes.BattlenetRequestRealmListTicket, Status = SessionStatus.Authed)]
|
[WorldPacketHandler(ClientOpcodes.BattlenetRequestRealmListTicket, Status = SessionStatus.Authed)]
|
||||||
@@ -56,13 +46,13 @@ namespace Game
|
|||||||
SendPacket(realmListTicket);
|
SendPacket(realmListTicket);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendBattlenetResponse(uint serviceHash, uint methodId, IMessage response)
|
public void SendBattlenetResponse(uint serviceHash, uint methodId, uint token, IMessage response)
|
||||||
{
|
{
|
||||||
Response bnetResponse = new Response();
|
Response bnetResponse = new Response();
|
||||||
bnetResponse.BnetStatus = BattlenetRpcErrorCode.Ok;
|
bnetResponse.BnetStatus = BattlenetRpcErrorCode.Ok;
|
||||||
bnetResponse.Method.Type = MathFunctions.MakePair64(methodId, serviceHash);
|
bnetResponse.Method.Type = MathFunctions.MakePair64(methodId, serviceHash);
|
||||||
bnetResponse.Method.ObjectId = 1;
|
bnetResponse.Method.ObjectId = 1;
|
||||||
bnetResponse.Method.Token = _battlenetRequestToken++;
|
bnetResponse.Method.Token = token;
|
||||||
|
|
||||||
if (response.CalculateSize() != 0)
|
if (response.CalculateSize() != 0)
|
||||||
bnetResponse.Data.WriteBytes(response.ToByteArray());
|
bnetResponse.Data.WriteBytes(response.ToByteArray());
|
||||||
@@ -70,13 +60,13 @@ namespace Game
|
|||||||
SendPacket(bnetResponse);
|
SendPacket(bnetResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendBattlenetResponse(uint serviceHash, uint methodId, BattlenetRpcErrorCode status)
|
public void SendBattlenetResponse(uint serviceHash, uint methodId, uint token, BattlenetRpcErrorCode status)
|
||||||
{
|
{
|
||||||
Response bnetResponse = new Response();
|
Response bnetResponse = new Response();
|
||||||
bnetResponse.BnetStatus = status;
|
bnetResponse.BnetStatus = status;
|
||||||
bnetResponse.Method.Type = MathFunctions.MakePair64(methodId, serviceHash);
|
bnetResponse.Method.Type = MathFunctions.MakePair64(methodId, serviceHash);
|
||||||
bnetResponse.Method.ObjectId = 1;
|
bnetResponse.Method.ObjectId = 1;
|
||||||
bnetResponse.Method.Token = _battlenetRequestToken++;
|
bnetResponse.Method.Token = token;
|
||||||
|
|
||||||
SendPacket(bnetResponse);
|
SendPacket(bnetResponse);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,10 +25,144 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace Game
|
namespace Game
|
||||||
{
|
{
|
||||||
public partial class WorldSession
|
class GameUtilitiesService : ServiceBase
|
||||||
{
|
{
|
||||||
[BnetService(NameHash.GameUtilitiesService, 1)]
|
public GameUtilitiesService(WorldSession session, uint serviceHash) : base(session, serviceHash) { }
|
||||||
BattlenetRpcErrorCode HandleProcessClientRequest(ClientRequest request)
|
|
||||||
|
public override void CallServerMethod(uint token, uint methodId, CodedInputStream stream)
|
||||||
|
{
|
||||||
|
switch (methodId)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
ClientRequest request = new ClientRequest();
|
||||||
|
request.MergeFrom(stream);
|
||||||
|
|
||||||
|
|
||||||
|
ClientResponse response = new ClientResponse();
|
||||||
|
BattlenetRpcErrorCode status = HandleProcessClientRequest(request, response);
|
||||||
|
Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method GameUtilitiesService.ProcessClientRequest(bgs.protocol.game_utilities.v1.ClientRequest: {1}) returned bgs.protocol.game_utilities.v1.ClientResponse: {2} status: {3}.",
|
||||||
|
GetCallerInfo(), request.ToString(), response.ToString(), status);
|
||||||
|
if (status == 0)
|
||||||
|
SendResponse(1, token, response);
|
||||||
|
else
|
||||||
|
SendResponse(1, token, status);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
PresenceChannelCreatedRequest request = new PresenceChannelCreatedRequest();
|
||||||
|
request.MergeFrom(stream);
|
||||||
|
|
||||||
|
|
||||||
|
Bgs.Protocol.NoData response = new Bgs.Protocol.NoData();
|
||||||
|
BattlenetRpcErrorCode status = HandlePresenceChannelCreated(request, response);
|
||||||
|
Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method GameUtilitiesService.PresenceChannelCreated(bgs.protocol.game_utilities.v1.PresenceChannelCreatedRequest: {1}) returned bgs.protocol.NoData: {2} status: {3}.",
|
||||||
|
GetCallerInfo(), request.ToString(), response.ToString(), status);
|
||||||
|
if (status == 0)
|
||||||
|
SendResponse(2, token, response);
|
||||||
|
else
|
||||||
|
SendResponse(2, token, status);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
GetPlayerVariablesRequest request = new GetPlayerVariablesRequest();
|
||||||
|
request.MergeFrom(stream);
|
||||||
|
|
||||||
|
|
||||||
|
GetPlayerVariablesResponse response = new GetPlayerVariablesResponse();
|
||||||
|
BattlenetRpcErrorCode status = HandleGetPlayerVariables(request, response);
|
||||||
|
Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method GameUtilitiesService.GetPlayerVariables(bgs.protocol.game_utilities.v1.GetPlayerVariablesRequest: {1}) returned bgs.protocol.game_utilities.v1.GetPlayerVariablesResponse: {2} status: {3}.",
|
||||||
|
GetCallerInfo(), request.ToString(), response.ToString(), status);
|
||||||
|
if (status == 0)
|
||||||
|
SendResponse(3, token, response);
|
||||||
|
else
|
||||||
|
SendResponse(3, token, status);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 6:
|
||||||
|
{
|
||||||
|
ServerRequest request = new ServerRequest();
|
||||||
|
request.MergeFrom(stream);
|
||||||
|
|
||||||
|
|
||||||
|
ServerResponse response = new ServerResponse();
|
||||||
|
BattlenetRpcErrorCode status = HandleProcessServerRequest(request, response);
|
||||||
|
Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method GameUtilitiesService.ProcessServerRequest(bgs.protocol.game_utilities.v1.ServerRequest: {1}) returned bgs.protocol.game_utilities.v1.ServerResponse: {2} status: {3}.",
|
||||||
|
GetCallerInfo(), request.ToString(), response.ToString(), status);
|
||||||
|
if (status == 0)
|
||||||
|
SendResponse(6, token, response);
|
||||||
|
else
|
||||||
|
SendResponse(6, token, status);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 7:
|
||||||
|
{
|
||||||
|
GameAccountOnlineNotification request = new GameAccountOnlineNotification();
|
||||||
|
request.MergeFrom(stream);
|
||||||
|
|
||||||
|
|
||||||
|
BattlenetRpcErrorCode status = HandleOnGameAccountOnline(request);
|
||||||
|
Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method GameUtilitiesService.OnGameAccountOnline(bgs.protocol.game_utilities.v1.GameAccountOnlineNotification: {1}) status: {2}.",
|
||||||
|
GetCallerInfo(), request.ToString(), status);
|
||||||
|
if (status != 0)
|
||||||
|
SendResponse(7, token, status);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 8:
|
||||||
|
{
|
||||||
|
GameAccountOfflineNotification request = new GameAccountOfflineNotification();
|
||||||
|
request.MergeFrom(stream);
|
||||||
|
|
||||||
|
|
||||||
|
BattlenetRpcErrorCode status = HandleOnGameAccountOffline(request);
|
||||||
|
Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method GameUtilitiesService.OnGameAccountOffline(bgs.protocol.game_utilities.v1.GameAccountOfflineNotification: {1}) status: {2}.",
|
||||||
|
GetCallerInfo(), request.ToString(), status);
|
||||||
|
if (status != 0)
|
||||||
|
SendResponse(8, token, status);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 9:
|
||||||
|
{
|
||||||
|
GetAchievementsFileRequest request = new GetAchievementsFileRequest();
|
||||||
|
request.MergeFrom(stream);
|
||||||
|
|
||||||
|
|
||||||
|
GetAchievementsFileResponse response = new GetAchievementsFileResponse();
|
||||||
|
BattlenetRpcErrorCode status = HandleGetAchievementsFile(request, response);
|
||||||
|
Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method GameUtilitiesService.GetAchievementsFile(bgs.protocol.game_utilities.v1.GetAchievementsFileRequest: {1}) returned bgs.protocol.game_utilities.v1.GetAchievementsFileResponse: {2} status: {3}.",
|
||||||
|
GetCallerInfo(), request.ToString(), response.ToString(), status);
|
||||||
|
if (status == 0)
|
||||||
|
SendResponse(9, token, response);
|
||||||
|
else
|
||||||
|
SendResponse(9, token, status);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 10:
|
||||||
|
{
|
||||||
|
GetAllValuesForAttributeRequest request = new GetAllValuesForAttributeRequest();
|
||||||
|
request.MergeFrom(stream);
|
||||||
|
|
||||||
|
|
||||||
|
GetAllValuesForAttributeResponse response = new GetAllValuesForAttributeResponse();
|
||||||
|
BattlenetRpcErrorCode status = HandleGetAllValuesForAttribute(request, response);
|
||||||
|
Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method GameUtilitiesService.GetAllValuesForAttribute(bgs.protocol.game_utilities.v1.GetAllValuesForAttributeRequest: {1}) returned bgs.protocol.game_utilities.v1.GetAllValuesForAttributeResponse: {2} status: {3}.",
|
||||||
|
GetCallerInfo(), request.ToString(), response.ToString(), status);
|
||||||
|
if (status == 0)
|
||||||
|
SendResponse(10, token, response);
|
||||||
|
else
|
||||||
|
SendResponse(10, token, status);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
Log.outError(LogFilter.ServiceProtobuf, "Bad method id {0}.", methodId);
|
||||||
|
SendResponse(methodId, token, BattlenetRpcErrorCode.RpcInvalidMethod);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BattlenetRpcErrorCode HandleProcessClientRequest(ClientRequest request, ClientResponse response)
|
||||||
{
|
{
|
||||||
Bgs.Protocol.Attribute command = null;
|
Bgs.Protocol.Attribute command = null;
|
||||||
Dictionary<string, Bgs.Protocol.Variant> Params = new Dictionary<string, Bgs.Protocol.Variant>();
|
Dictionary<string, Bgs.Protocol.Variant> Params = new Dictionary<string, Bgs.Protocol.Variant>();
|
||||||
@@ -43,73 +177,65 @@ namespace Game
|
|||||||
|
|
||||||
if (command == null)
|
if (command == null)
|
||||||
{
|
{
|
||||||
Log.outError(LogFilter.SessionRpc, "{0} sent ClientRequest with no command.", GetPlayerInfo());
|
Log.outError(LogFilter.SessionRpc, "{0} sent ClientRequest with no command.", GetCallerInfo());
|
||||||
return BattlenetRpcErrorCode.RpcMalformedRequest;
|
return BattlenetRpcErrorCode.RpcMalformedRequest;
|
||||||
}
|
}
|
||||||
ClientResponse response = new ClientResponse();
|
|
||||||
|
|
||||||
var status = BattlenetRpcErrorCode.RpcNotImplemented;
|
|
||||||
if (command.Name == "Command_RealmListRequest_v1_b9")
|
if (command.Name == "Command_RealmListRequest_v1_b9")
|
||||||
status= HandleRealmListRequest(Params, response);
|
return HandleRealmListRequest(Params, response);
|
||||||
else if (command.Name == "Command_RealmJoinRequest_v1_b9")
|
else if (command.Name == "Command_RealmJoinRequest_v1_b9")
|
||||||
status= HandleRealmJoinRequest(Params, response);
|
return HandleRealmJoinRequest(Params, response);
|
||||||
|
|
||||||
if (status == 0)
|
|
||||||
SendBattlenetResponse((uint)NameHash.GameUtilitiesService, 1, response);
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BnetService(NameHash.GameUtilitiesService, 2)]
|
|
||||||
BattlenetRpcErrorCode HandlePresenceChannelCreated(PresenceChannelCreatedRequest request)
|
|
||||||
{
|
|
||||||
Log.outError(LogFilter.ServiceProtobuf, "{0} Client tried to call not implemented method GameUtilitiesService.PresenceChannelCreated: {1}", GetPlayerInfo(), request.ToString());
|
|
||||||
return BattlenetRpcErrorCode.RpcNotImplemented;
|
return BattlenetRpcErrorCode.RpcNotImplemented;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BnetService(NameHash.GameUtilitiesService, 3)]
|
BattlenetRpcErrorCode HandlePresenceChannelCreated(PresenceChannelCreatedRequest request, Bgs.Protocol.NoData response)
|
||||||
BattlenetRpcErrorCode HandleGetPlayerVariables(GetPlayerVariablesRequest request)
|
|
||||||
{
|
{
|
||||||
Log.outError(LogFilter.ServiceProtobuf, "{0} Client tried to call not implemented method GameUtilitiesService.GetPlayerVariables: {1}", GetPlayerInfo(), request.ToString());
|
Log.outError(LogFilter.ServiceProtobuf, "{0} Client tried to call not implemented method GameUtilitiesService.PresenceChannelCreated: {1}",
|
||||||
|
GetCallerInfo(), request.ToString());
|
||||||
return BattlenetRpcErrorCode.RpcNotImplemented;
|
return BattlenetRpcErrorCode.RpcNotImplemented;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BnetService(NameHash.GameUtilitiesService, 6)]
|
BattlenetRpcErrorCode HandleGetPlayerVariables(GetPlayerVariablesRequest request, GetPlayerVariablesResponse response)
|
||||||
BattlenetRpcErrorCode HandleProcessServerRequest(ServerRequest request)
|
|
||||||
{
|
{
|
||||||
Log.outError(LogFilter.ServiceProtobuf, "{0} Client tried to call not implemented method GameUtilitiesService.ProcessServerRequest: {1}", GetPlayerInfo(), request.ToString());
|
Log.outError(LogFilter.ServiceProtobuf, "{0} Client tried to call not implemented method GameUtilitiesService.GetPlayerVariables: {1}",
|
||||||
|
GetCallerInfo(), request.ToString());
|
||||||
|
return BattlenetRpcErrorCode.RpcNotImplemented;
|
||||||
|
}
|
||||||
|
|
||||||
|
BattlenetRpcErrorCode HandleProcessServerRequest(ServerRequest request, ServerResponse response)
|
||||||
|
{
|
||||||
|
Log.outError(LogFilter.ServiceProtobuf, "{0} Client tried to call not implemented method GameUtilitiesService.ProcessServerRequest: {1}",
|
||||||
|
GetCallerInfo(), request.ToString());
|
||||||
return BattlenetRpcErrorCode.RpcNotImplemented;
|
return BattlenetRpcErrorCode.RpcNotImplemented;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BnetService(NameHash.GameUtilitiesService, 7)]
|
|
||||||
BattlenetRpcErrorCode HandleOnGameAccountOnline(GameAccountOnlineNotification request)
|
BattlenetRpcErrorCode HandleOnGameAccountOnline(GameAccountOnlineNotification request)
|
||||||
{
|
{
|
||||||
Log.outError(LogFilter.ServiceProtobuf, "{0} Client tried to call not implemented method GameUtilitiesService.OnGameAccountOnline: {1}", GetPlayerInfo(), request.ToString());
|
Log.outError(LogFilter.ServiceProtobuf, "{0} Client tried to call not implemented method GameUtilitiesService.OnGameAccountOnline: {1}",
|
||||||
|
GetCallerInfo(), request.ToString());
|
||||||
return BattlenetRpcErrorCode.RpcNotImplemented;
|
return BattlenetRpcErrorCode.RpcNotImplemented;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BnetService(NameHash.GameUtilitiesService, 8)]
|
|
||||||
BattlenetRpcErrorCode HandleOnGameAccountOffline(GameAccountOfflineNotification request)
|
BattlenetRpcErrorCode HandleOnGameAccountOffline(GameAccountOfflineNotification request)
|
||||||
{
|
{
|
||||||
Log.outError(LogFilter.ServiceProtobuf, "{0} Client tried to call not implemented method GameUtilitiesService.OnGameAccountOffline: {1}", GetPlayerInfo(), request.ToString());
|
Log.outError(LogFilter.ServiceProtobuf, "{0} Client tried to call not implemented method GameUtilitiesService.OnGameAccountOffline: {1}",
|
||||||
|
GetCallerInfo(), request.ToString());
|
||||||
return BattlenetRpcErrorCode.RpcNotImplemented;
|
return BattlenetRpcErrorCode.RpcNotImplemented;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BnetService(NameHash.GameUtilitiesService, 9)]
|
BattlenetRpcErrorCode HandleGetAchievementsFile(GetAchievementsFileRequest request, GetAchievementsFileResponse response)
|
||||||
BattlenetRpcErrorCode HandleGetAchievementsFile(GetAchievementsFileRequest request)
|
|
||||||
{
|
{
|
||||||
Log.outError(LogFilter.ServiceProtobuf, "{0} Client tried to call not implemented method GameUtilitiesService.GetAchievementsFile: {1}", GetPlayerInfo(), request.ToString());
|
Log.outError(LogFilter.ServiceProtobuf, "{0} Client tried to call not implemented method GameUtilitiesService.GetAchievementsFile: {1}",
|
||||||
|
GetCallerInfo(), request.ToString());
|
||||||
return BattlenetRpcErrorCode.RpcNotImplemented;
|
return BattlenetRpcErrorCode.RpcNotImplemented;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BnetService(NameHash.GameUtilitiesService, 10)]
|
BattlenetRpcErrorCode HandleGetAllValuesForAttribute(GetAllValuesForAttributeRequest request, GetAllValuesForAttributeResponse response)
|
||||||
BattlenetRpcErrorCode HandleGetAllValuesForAttribute(GetAllValuesForAttributeRequest request)
|
|
||||||
{
|
{
|
||||||
if (request.AttributeKey == "Command_RealmListRequest_v1_b9")
|
if (request.AttributeKey == "Command_RealmListRequest_v1_b9")
|
||||||
{
|
{
|
||||||
GetAllValuesForAttributeResponse response = new GetAllValuesForAttributeResponse();
|
|
||||||
Global.RealmMgr.WriteSubRegions(response);
|
Global.RealmMgr.WriteSubRegions(response);
|
||||||
SendBattlenetResponse((uint)NameHash.GameUtilitiesService, 10, response);
|
|
||||||
return BattlenetRpcErrorCode.Ok;
|
return BattlenetRpcErrorCode.Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,7 +260,7 @@ namespace Game
|
|||||||
response.Attribute.Add(attribute);
|
response.Attribute.Add(attribute);
|
||||||
|
|
||||||
var realmCharacterCounts = new RealmCharacterCountList();
|
var realmCharacterCounts = new RealmCharacterCountList();
|
||||||
foreach (var characterCount in GetRealmCharacterCounts())
|
foreach (var characterCount in _session.GetRealmCharacterCounts())
|
||||||
{
|
{
|
||||||
RealmCharacterCountEntry countEntry = new RealmCharacterCountEntry();
|
RealmCharacterCountEntry countEntry = new RealmCharacterCountEntry();
|
||||||
countEntry.WowRealmAddress = (int)characterCount.Key;
|
countEntry.WowRealmAddress = (int)characterCount.Key;
|
||||||
@@ -155,8 +281,8 @@ namespace Game
|
|||||||
{
|
{
|
||||||
var realmAddress = Params.LookupByKey("Param_RealmAddress");
|
var realmAddress = Params.LookupByKey("Param_RealmAddress");
|
||||||
if (realmAddress != null)
|
if (realmAddress != null)
|
||||||
return Global.RealmMgr.JoinRealm((uint)realmAddress.UintValue, Global.WorldMgr.GetRealm().Build, System.Net.IPAddress.Parse(GetRemoteAddress()), GetRealmListSecret(),
|
return Global.RealmMgr.JoinRealm((uint)realmAddress.UintValue, Global.WorldMgr.GetRealm().Build, System.Net.IPAddress.Parse(_session.GetRemoteAddress()), _session.GetRealmListSecret(),
|
||||||
GetSessionDbcLocale(), GetOS(), GetAccountName(), response);
|
_session.GetSessionDbcLocale(), _session.GetOS(), _session.GetAccountName(), response);
|
||||||
|
|
||||||
return BattlenetRpcErrorCode.Ok;
|
return BattlenetRpcErrorCode.Ok;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012-2016 CypherCore <http://github.com/CypherCore>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using Framework.Constants;
|
||||||
|
using Google.Protobuf;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Game.Services
|
||||||
|
{
|
||||||
|
public class ServiceDispatcher : Singleton<ServiceDispatcher>
|
||||||
|
{
|
||||||
|
ServiceDispatcher()
|
||||||
|
{
|
||||||
|
AddService<GameUtilitiesService>(NameHash.GameUtilitiesService);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispatch(WorldSession session, uint serviceHash, uint token, uint methodId, CodedInputStream stream)
|
||||||
|
{
|
||||||
|
var action = _dispatchers.LookupByKey(serviceHash);
|
||||||
|
if (action != null)
|
||||||
|
action(session, serviceHash, token, methodId, stream);
|
||||||
|
else
|
||||||
|
Log.outDebug(LogFilter.SessionRpc, "{0} tried to call invalid service {1}", session.GetPlayerInfo(), serviceHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddService<Service>(NameHash OriginalHash) where Service : ServiceBase
|
||||||
|
{
|
||||||
|
_dispatchers[(uint)OriginalHash] = Dispatch<Service>;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dispatch<Service>(WorldSession session, uint serviceHash, uint token, uint methodId, CodedInputStream stream) where Service : ServiceBase
|
||||||
|
{
|
||||||
|
var obj = (Service)Activator.CreateInstance(typeof(Service), session, serviceHash);
|
||||||
|
obj.CallServerMethod(token, methodId, stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
Dictionary<uint, DispatcherHandler> _dispatchers = new Dictionary<uint, DispatcherHandler>();
|
||||||
|
|
||||||
|
delegate void DispatcherHandler(WorldSession session, uint serviceHash, uint token, uint methodId, CodedInputStream stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class ServiceBase
|
||||||
|
{
|
||||||
|
public ServiceBase(WorldSession session, uint serviceHash)
|
||||||
|
{
|
||||||
|
_session = session;
|
||||||
|
_serviceHash = serviceHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void CallServerMethod(uint token, uint methodId, CodedInputStream stream);
|
||||||
|
|
||||||
|
public void SendRequest(uint methodId, IMessage request, Action<CodedInputStream> callback) { _session.SendBattlenetRequest(_serviceHash, methodId, request, callback); }
|
||||||
|
public void SendRequest(uint methodId, IMessage request) { _session.SendBattlenetRequest(_serviceHash, methodId, request); }
|
||||||
|
public void SendResponse(uint methodId, uint token, BattlenetRpcErrorCode status) { _session.SendBattlenetResponse(_serviceHash, methodId, token, status); }
|
||||||
|
public void SendResponse(uint methodId, uint token, IMessage response) { _session.SendBattlenetResponse(_serviceHash, methodId, token, response); }
|
||||||
|
|
||||||
|
public string GetCallerInfo()
|
||||||
|
{
|
||||||
|
return _session.GetPlayerInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected WorldSession _session;
|
||||||
|
protected uint _serviceHash;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
using Framework.Constants;
|
|
||||||
using Google.Protobuf;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Concurrent;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace Game.Services
|
|
||||||
{
|
|
||||||
class ServiceManager
|
|
||||||
{
|
|
||||||
public static void Initialize()
|
|
||||||
{
|
|
||||||
Assembly currentAsm = Assembly.GetExecutingAssembly();
|
|
||||||
foreach (var type in currentAsm.GetTypes())
|
|
||||||
{
|
|
||||||
foreach (var methodInfo in type.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic))
|
|
||||||
{
|
|
||||||
foreach (var msgAttr in methodInfo.GetCustomAttributes<BnetServiceAttribute>())
|
|
||||||
{
|
|
||||||
if (msgAttr == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (_clientPacketTable.ContainsKey(msgAttr.Hash) && _clientPacketTable[msgAttr.Hash].ContainsKey(msgAttr.MethodId))
|
|
||||||
{
|
|
||||||
//Log.outError(LogFilter.Network, "Tried to override OpcodeHandler of {0} with {1} (Opcode {2})", _clientPacketTable[msgAttr.Opcode].ToString(), methodInfo.Name, msgAttr.Opcode);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var parameters = methodInfo.GetParameters();
|
|
||||||
if (parameters.Length == 0)
|
|
||||||
{
|
|
||||||
Log.outError(LogFilter.Network, "Method: {0} Has no paramters", methodInfo.Name);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_clientPacketTable.ContainsKey(msgAttr.Hash))
|
|
||||||
_clientPacketTable[msgAttr.Hash] = new Dictionary<uint, ServiceHandler>();
|
|
||||||
|
|
||||||
_clientPacketTable[msgAttr.Hash][msgAttr.MethodId] = new ServiceHandler(methodInfo, parameters[0].ParameterType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ServiceHandler GetHandler(NameHash hash, uint methodId)
|
|
||||||
{
|
|
||||||
if (!_clientPacketTable.ContainsKey(hash))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return _clientPacketTable[hash].LookupByKey(methodId);
|
|
||||||
}
|
|
||||||
|
|
||||||
static ConcurrentDictionary<NameHash, Dictionary<uint, ServiceHandler>> _clientPacketTable = new ConcurrentDictionary<NameHash, Dictionary<uint, ServiceHandler>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ServiceHandler
|
|
||||||
{
|
|
||||||
public ServiceHandler(MethodInfo info, Type type)
|
|
||||||
{
|
|
||||||
methodCaller = (Func<WorldSession, IMessage, BattlenetRpcErrorCode>)GetType().GetMethod("CreateDelegate", BindingFlags.Static | BindingFlags.NonPublic).MakeGenericMethod(type).Invoke(null, new object[] { info });
|
|
||||||
packetType = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BattlenetRpcErrorCode Invoke(WorldSession session, CodedInputStream stream)
|
|
||||||
{
|
|
||||||
var request = (IMessage)Activator.CreateInstance(packetType);
|
|
||||||
request.MergeFrom(stream);
|
|
||||||
|
|
||||||
return methodCaller(session, request);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Func<WorldSession, IMessage, BattlenetRpcErrorCode> CreateDelegate<P1>(MethodInfo method) where P1 : IMessage
|
|
||||||
{
|
|
||||||
// create first delegate. It is not fine because its
|
|
||||||
// signature contains unknown types T and P1
|
|
||||||
Func<WorldSession, P1, BattlenetRpcErrorCode> d = (Func<WorldSession, P1, BattlenetRpcErrorCode>)method.CreateDelegate(typeof(Func<WorldSession, P1, BattlenetRpcErrorCode>));
|
|
||||||
// create another delegate having necessary signature.
|
|
||||||
// It encapsulates first delegate with a closure
|
|
||||||
return delegate (WorldSession target, IMessage p) { return d(target, (P1)p); };
|
|
||||||
}
|
|
||||||
|
|
||||||
Func<WorldSession, IMessage, BattlenetRpcErrorCode> methodCaller;
|
|
||||||
Type packetType;
|
|
||||||
}
|
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Method)]
|
|
||||||
public class BnetServiceAttribute : Attribute
|
|
||||||
{
|
|
||||||
public BnetServiceAttribute(NameHash hash, uint methodId)
|
|
||||||
{
|
|
||||||
Hash = hash;
|
|
||||||
MethodId = methodId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NameHash Hash { get; }
|
|
||||||
public uint MethodId { get; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user