초기커밋
This commit is contained in:
132
GameServer/Entity/Building/Helper/BuildingNotifyHelper.cs
Normal file
132
GameServer/Entity/Building/Helper/BuildingNotifyHelper.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Org.BouncyCastle.Asn1.Ocsp;
|
||||
using ServerCommon;
|
||||
using ServerCore; using ServerBase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static ClientToGameMessage.Types;
|
||||
using static ServerMessage.Types;
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
internal static class BuildingNotifyHelper
|
||||
{
|
||||
public static async Task<bool> send_S2C_NTF_BUILDING_INFOS(this Player player)
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
var building_manager = server_logic.getBuildingManager();
|
||||
|
||||
var ntf_packet = new ClientToGame();
|
||||
ntf_packet.Message = new ClientToGameMessage();
|
||||
ntf_packet.Message.NtfBuildingInfos = new GS2C_NTF_BUILDING_INFOS();
|
||||
|
||||
var building_infos = await building_manager.tryGetBuildingInfos();
|
||||
foreach (var building_info in building_infos)
|
||||
{
|
||||
ntf_packet.Message.NtfBuildingInfos.BuildingInfos.Add(building_info.BuildingMetaId, building_info);
|
||||
}
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(player, ntf_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool broadcast_S2C_NTF_BUILDING_INFOS(BuildingInfo buildingInfo)
|
||||
{
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
var users = server_logic.getPlayerManager().getUsers();
|
||||
var players = users.Values.ToArray();
|
||||
|
||||
if (players.Length == 0)
|
||||
return true;
|
||||
|
||||
var ntf_packet = new ClientToGame();
|
||||
ntf_packet.Message = new ClientToGameMessage();
|
||||
ntf_packet.Message.NtfBuildingInfos = new GS2C_NTF_BUILDING_INFOS();
|
||||
|
||||
ntf_packet.Message.NtfBuildingInfos.BuildingInfos.Add(buildingInfo.BuildingMetaId, buildingInfo);
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(players, ntf_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool broadcast_S2C_NTF_BUILDING_INFOS(List<BuildingInfo> buildingInfos)
|
||||
{
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
var users = server_logic.getPlayerManager().getUsers();
|
||||
var players = users.Values.ToArray();
|
||||
|
||||
if (players.Length == 0)
|
||||
return true;
|
||||
|
||||
var ntf_packet = new ClientToGame();
|
||||
ntf_packet.Message = new ClientToGameMessage();
|
||||
ntf_packet.Message.NtfBuildingInfos = new GS2C_NTF_BUILDING_INFOS();
|
||||
|
||||
foreach (var buildingInfo in buildingInfos)
|
||||
{
|
||||
ntf_packet.Message.NtfBuildingInfos.BuildingInfos.Add(buildingInfo.BuildingMetaId, buildingInfo);
|
||||
}
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(players, ntf_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool send_GS2GS_NTF_MODIFY_BUILDING_INFO(List<BuildingInfo> buildingInfos)
|
||||
{
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
var message = new ServerMessage();
|
||||
|
||||
message.NtfModifyBuildingInfo = new GS2GS_NTF_MODIFY_BUILDING_INFO();
|
||||
message.NtfModifyBuildingInfo.ExceptServerName = server_logic.getServerName();
|
||||
message.NtfModifyBuildingInfo.BuildingInfos.AddRange(buildingInfos);
|
||||
|
||||
var rabbit_mq = server_logic.getRabbitMqConnector() as RabbitMQ4Game;
|
||||
NullReferenceCheckHelper.throwIfNull(rabbit_mq, () => $"rabbit_mq is null !!!");
|
||||
|
||||
rabbit_mq.sendMessageToExchangeAllGame(message);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static async Task<bool> sendNtfModifyBuildingInfo(Building building)
|
||||
{
|
||||
var building_info = await building.toBuildingInfo();
|
||||
var building_infos = new List<BuildingInfo>();
|
||||
building_infos.Add(building_info);
|
||||
|
||||
// 현재 서버 유저
|
||||
broadcast_S2C_NTF_BUILDING_INFOS(building_info);
|
||||
|
||||
// 다른 서버
|
||||
send_GS2GS_NTF_MODIFY_BUILDING_INFO(building_infos);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool sendNtfModifyBuildingInfo(List<BuildingInfo> buildingInfos)
|
||||
{
|
||||
broadcast_S2C_NTF_BUILDING_INFOS(buildingInfos);
|
||||
|
||||
send_GS2GS_NTF_MODIFY_BUILDING_INFO(buildingInfos);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user