Core/Battlegrounds: Move to scripts And a lot of misc commits i couldn't recover.

Port From (https://github.com/TrinityCore/TrinityCore/commit/d0d5d309bb5877dc2fcb27f6cb123707a31ec1e8)
This commit is contained in:
Hondacrx
2024-08-04 15:18:22 -04:00
parent bca02a24b0
commit e9b21a91be
139 changed files with 8322 additions and 8700 deletions
@@ -19,6 +19,7 @@ namespace Game.Networking.Packets
public AuctionHouseFilterMask Filters;
public byte[] KnownPets;
public sbyte MaxPetLevel;
public uint Unused1026;
public AddOnInfo? TaintedBy;
public string Name;
public Array<AuctionListFilterClass> ItemClassFilters = new(7);
@@ -37,6 +38,7 @@ namespace Game.Networking.Packets
Filters = (AuctionHouseFilterMask)_worldPacket.ReadUInt32();
uint knownPetSize = _worldPacket.ReadUInt32();
MaxPetLevel = _worldPacket.ReadInt8();
Unused1026 = _worldPacket.ReadUInt32();
uint sizeLimit = CliDB.BattlePetSpeciesStorage.GetNumRows() / 8 + 1;
if (knownPetSize >= sizeLimit)
@@ -326,12 +326,6 @@ namespace Game.Networking.Packets
public struct RaceLimitDisableInfo
{
enum blah
{
Server,
Level
}
public int RaceID;
public int BlockReason;
@@ -386,6 +380,7 @@ namespace Game.Networking.Packets
bool hasTemplateSet = _worldPacket.HasBit();
CreateInfo.IsTrialBoost = _worldPacket.HasBit();
CreateInfo.UseNPE = _worldPacket.HasBit();
CreateInfo.Unused1026 = _worldPacket.HasBit();
CreateInfo.RaceId = (Race)_worldPacket.ReadUInt8();
CreateInfo.ClassId = (Class)_worldPacket.ReadUInt8();
@@ -1144,6 +1139,7 @@ namespace Game.Networking.Packets
public uint? TemplateSet;
public bool IsTrialBoost;
public bool UseNPE;
public bool Unused1026;
public string Name;
// Server side data
@@ -43,7 +43,7 @@ namespace Game.Networking.Packets
public override void Read()
{
PlayerGuid = _worldPacket.ReadPackedGuid();
DataType = (AccountDataTypes)_worldPacket.ReadBits<uint>(4);
DataType = (AccountDataTypes)_worldPacket.ReadInt32();
}
public ObjectGuid PlayerGuid;
@@ -56,10 +56,10 @@ namespace Game.Networking.Packets
public override void Write()
{
_worldPacket.WritePackedGuid(Player);
_worldPacket.WriteInt64(Time);
_worldPacket.WriteUInt32(Size);
_worldPacket.WriteBits(DataType, 4);
_worldPacket.WritePackedGuid(Player);
_worldPacket.WriteInt32((int)DataType);
if (CompressedData == null)
_worldPacket.WriteUInt32(0);
@@ -84,10 +84,10 @@ namespace Game.Networking.Packets
public override void Read()
{
PlayerGuid = _worldPacket.ReadPackedGuid();
Time = _worldPacket.ReadInt64();
Size = _worldPacket.ReadUInt32();
DataType = (AccountDataTypes)_worldPacket.ReadBits<uint>(4);
PlayerGuid = _worldPacket.ReadPackedGuid();
DataType = (AccountDataTypes)_worldPacket.ReadInt32();
uint compressedSize = _worldPacket.ReadUInt32();
if (compressedSize != 0)
@@ -93,13 +93,22 @@ namespace Game.Networking.Packets
Standing = standing;
}
public FactionStandingData(int index, int standing, int factionId)
{
Index = index;
Standing = standing;
FactionID = factionId;
}
public void Write(WorldPacket data)
{
data.WriteInt32(Index);
data.WriteInt32(Standing);
data.WriteInt32(FactionID);
}
int Index;
int Standing;
int FactionID;
}
}
@@ -65,9 +65,11 @@ namespace Game.Networking.Packets
public override void Read()
{
SceneInstanceID = _worldPacket.ReadUInt32();
TimePassed = _worldPacket.ReadInt32();
}
public uint SceneInstanceID;
public int TimePassed;
}
class ScenePlaybackCanceled : ClientPacket
@@ -77,8 +79,10 @@ namespace Game.Networking.Packets
public override void Read()
{
SceneInstanceID = _worldPacket.ReadUInt32();
TimePassed = _worldPacket.ReadInt32();
}
public uint SceneInstanceID;
public int TimePassed;
}
}
@@ -264,7 +264,7 @@ namespace Game.Networking.Packets
_worldPacket.WriteBit(KioskModeEnabled);
_worldPacket.WriteBit(CompetitiveModeEnabled);
_worldPacket.WriteBit(false); // unused, 10.0.2
_worldPacket.WriteBit(IsBoostEnabled);
_worldPacket.WriteBit(TrialBoostEnabled);
_worldPacket.WriteBit(TokenBalanceEnabled);
_worldPacket.WriteBit(LiveRegionCharacterListEnabled);
@@ -275,7 +275,7 @@ namespace Game.Networking.Packets
_worldPacket.WriteBit(Unknown901CheckoutRelated);
_worldPacket.WriteBit(false); // unused, 10.0.2
_worldPacket.WriteBit(EuropaTicketSystemStatus.HasValue);
_worldPacket.WriteBit(false); // unused, 10.0.2
_worldPacket.WriteBit(IsNameReservationEnabled);
_worldPacket.WriteBit(LaunchETA.HasValue);
_worldPacket.WriteBit(AddonsDisabled);
_worldPacket.WriteBit(Unused1000);
@@ -309,6 +309,7 @@ namespace Game.Networking.Packets
_worldPacket.WriteUInt32((uint)PlayerNameQueryInterval.TotalSeconds);
_worldPacket.WriteInt32(DebugTimeEvents.Count);
_worldPacket.WriteInt32(Unused1007);
_worldPacket.WriteUInt32(EventRealmQueues);
if (LaunchETA.HasValue)
_worldPacket.WriteInt32(LaunchETA.Value);
@@ -336,6 +337,7 @@ namespace Game.Networking.Packets
public bool IsExpansionPreorderInStore; // NYI
public bool KioskModeEnabled; // NYI
public bool CompetitiveModeEnabled; // NYI
public bool IsBoostEnabled; // classic only
public bool TrialBoostEnabled; // NYI
public bool TokenBalanceEnabled; // NYI
public bool LiveRegionCharacterListEnabled; // NYI
@@ -343,6 +345,7 @@ namespace Game.Networking.Packets
public bool LiveRegionAccountCopyEnabled; // NYI
public bool LiveRegionKeyBindingsCopyEnabled;
public bool Unknown901CheckoutRelated; // NYI
public bool IsNameReservationEnabled; // classic only
public bool AddonsDisabled;
public bool Unused1000;
public bool AccountSaveDataExportEnabled;
@@ -366,6 +369,7 @@ namespace Game.Networking.Packets
public int? LaunchETA;
public List<DebugTimeEventInfo> DebugTimeEvents = new();
public int Unused1007;
public uint EventRealmQueues;
public string RealmHiddenAlert;
}
+33 -38
View File
@@ -9,6 +9,7 @@ using Framework.Networking;
using Game.Networking.Packets;
using System;
using System.Net.Sockets;
using System.Threading.Tasks;
namespace Game.Networking
{
@@ -75,12 +76,12 @@ namespace Game.Networking
PreparedStatement stmt = LoginDatabase.GetPreparedStatement(LoginStatements.SEL_IP_INFO);
stmt.AddValue(0, ip_address);
stmt.AddValue(1, BitConverter.ToUInt32(GetRemoteIpAddress().Address.GetAddressBytes(), 0));
stmt.AddValue(1, BitConverter.ToUInt32(GetRemoteIpAddress().GetAddressBytes(), 0));
_queryProcessor.AddCallback(DB.Login.AsyncQuery(stmt).WithCallback(CheckIpCallback));
}
void CheckIpCallback(SQLResult result)
async void CheckIpCallback(SQLResult result)
{
if (!result.IsEmpty())
{
@@ -109,24 +110,18 @@ namespace Game.Networking
ByteBuffer packet = new();
packet.WriteString(ServerConnectionInitialize);
packet.WriteString("\n");
AsyncWrite(packet.GetData());
await AsyncWrite(packet.GetData());
}
void InitializeHandler(SocketAsyncEventArgs args)
async Task InitializeHandler(byte[] data, int receivedLength)
{
if (args.SocketError != SocketError.Success)
{
CloseSocket();
return;
}
if (args.BytesTransferred > 0)
if (receivedLength > 0)
{
if (_packetBuffer.GetRemainingSpace() > 0)
{
// need to receive the header
int readHeaderSize = Math.Min(args.BytesTransferred, _packetBuffer.GetRemainingSpace());
_packetBuffer.Write(args.Buffer, 0, readHeaderSize);
int readHeaderSize = Math.Min(receivedLength, _packetBuffer.GetRemainingSpace());
_packetBuffer.Write(data, 0, readHeaderSize);
if (_packetBuffer.GetRemainingSpace() > 0)
{
@@ -165,25 +160,25 @@ namespace Game.Networking
_packetBuffer.Resize(0);
_packetBuffer.Reset();
HandleSendAuthSession();
AsyncRead();
await AsyncRead();
return;
}
}
}
public override void ReadHandler(SocketAsyncEventArgs args)
public async override void ReadHandler(byte[] data, int receivedLength)
{
if (!IsOpen())
return;
int currentReadIndex = 0;
while (currentReadIndex < args.BytesTransferred)
while (currentReadIndex < receivedLength)
{
if (_headerBuffer.GetRemainingSpace() > 0)
{
// need to receive the header
int readHeaderSize = Math.Min(args.BytesTransferred - currentReadIndex, _headerBuffer.GetRemainingSpace());
_headerBuffer.Write(args.Buffer, currentReadIndex, readHeaderSize);
int readHeaderSize = Math.Min(receivedLength - currentReadIndex, _headerBuffer.GetRemainingSpace());
_headerBuffer.Write(data, currentReadIndex, readHeaderSize);
currentReadIndex += readHeaderSize;
if (_headerBuffer.GetRemainingSpace() > 0)
@@ -201,8 +196,8 @@ namespace Game.Networking
if (_packetBuffer.GetRemainingSpace() > 0)
{
// need more data in the payload
int readDataSize = Math.Min(args.BytesTransferred - currentReadIndex, _packetBuffer.GetRemainingSpace());
_packetBuffer.Write(args.Buffer, currentReadIndex, readDataSize);
int readDataSize = Math.Min(receivedLength - currentReadIndex, _packetBuffer.GetRemainingSpace());
_packetBuffer.Write(data, currentReadIndex, readDataSize);
currentReadIndex += readDataSize;
if (_packetBuffer.GetRemainingSpace() > 0)
@@ -221,7 +216,7 @@ namespace Game.Networking
}
}
AsyncRead();
await AsyncRead();
}
bool ReadHeader()
@@ -254,7 +249,7 @@ namespace Game.Networking
return ReadDataHandlerResult.Error;
}
PacketLog.Write(packet.GetData(), packet.GetOpcode(), GetRemoteIpAddress(), _connectType, true);
PacketLog.Write(packet.GetData(), packet.GetOpcode(), GetRemoteIpEndPoint(), _connectType, true);
ClientOpcodes opcode = (ClientOpcodes)packet.GetOpcode();
@@ -346,7 +341,7 @@ namespace Game.Networking
return ReadDataHandlerResult.Ok;
}
public void SendPacket(ServerPacket packet)
public async void SendPacket(ServerPacket packet)
{
if (!IsOpen())
return;
@@ -356,7 +351,7 @@ namespace Game.Networking
var data = packet.GetData();
ServerOpcodes opcode = packet.GetOpcode();
PacketLog.Write(data, (uint)opcode, GetRemoteIpAddress(), _connectType, false);
PacketLog.Write(data, (uint)opcode, GetRemoteIpEndPoint(), _connectType, false);
ByteBuffer buffer = new();
@@ -368,7 +363,7 @@ namespace Game.Networking
byte[] compressedData;
uint compressedSize = CompressPacket(data, opcode, out compressedData);
buffer.WriteUInt32(ZLib.adler32(0x9827D8F1, compressedData, compressedSize));
buffer.WriteUInt32(ZLib.adler32(0x9827D8F1, compressedData, compressedSize));
buffer.WriteBytes(compressedData, compressedSize);
packetSize = (int)(compressedSize + 12);
@@ -392,7 +387,7 @@ namespace Game.Networking
header.Write(byteBuffer);
byteBuffer.WriteBytes(data);
AsyncWrite(byteBuffer.GetData());
await AsyncWrite(byteBuffer.GetData());
}
public void SetWorldSession(WorldSession session)
@@ -464,7 +459,7 @@ namespace Game.Networking
_queryProcessor.AddCallback(DB.Login.AsyncQuery(stmt).WithCallback(HandleAuthSessionCallback, authSession));
}
void HandleAuthSessionCallback(AuthSession authSession, SQLResult result)
async void HandleAuthSessionCallback(AuthSession authSession, SQLResult result)
{
// Stop if the account is not found
if (result.IsEmpty())
@@ -540,7 +535,7 @@ namespace Game.Networking
{
// As we don't know if attempted login process by ip works, we update last_attempt_ip right away
stmt = LoginDatabase.GetPreparedStatement(LoginStatements.UPD_LAST_ATTEMPT_IP);
stmt.AddValue(0, address.Address.ToString());
stmt.AddValue(0, address.ToString());
stmt.AddValue(1, authSession.RealmJoinTicket);
DB.Login.Execute(stmt);
// This also allows to check for possible "hack" attempts on account
@@ -582,7 +577,7 @@ namespace Game.Networking
//Re-check ip locking (same check as in auth).
if (account.battleNet.IsLockedToIP) // if ip is locked
{
if (account.battleNet.LastIP != address.Address.ToString())
if (account.battleNet.LastIP != address.ToString())
{
SendAuthResponseError(BattlenetRpcErrorCode.RiskAccountLocked);
Log.outDebug(LogFilter.Network, "HandleAuthSession: Sent Auth Response (Account IP differs).");
@@ -643,7 +638,7 @@ namespace Game.Networking
{
// Update the last_ip in the database
stmt = LoginDatabase.GetPreparedStatement(LoginStatements.UPD_LAST_IP);
stmt.AddValue(0, address.Address.ToString());
stmt.AddValue(0, address.ToString());
stmt.AddValue(1, authSession.RealmJoinTicket);
DB.Login.Execute(stmt);
}
@@ -659,7 +654,7 @@ namespace Game.Networking
//_worldSession.InitWarden(_sessionKey);
_queryProcessor.AddCallback(_worldSession.LoadPermissionsAsync().WithCallback(LoadSessionPermissionsCallback));
AsyncRead();
await AsyncRead();
}
void LoadSessionPermissionsCallback(SQLResult result)
@@ -690,7 +685,7 @@ namespace Game.Networking
_queryProcessor.AddCallback(DB.Login.AsyncQuery(stmt).WithCallback(HandleAuthContinuedSessionCallback, authSession));
}
void HandleAuthContinuedSessionCallback(AuthContinuedSession authSession, SQLResult result)
async void HandleAuthContinuedSessionCallback(AuthContinuedSession authSession, SQLResult result)
{
if (result.IsEmpty())
{
@@ -728,7 +723,7 @@ namespace Game.Networking
Buffer.BlockCopy(encryptKeyGen.Digest, 0, _encryptKey, 0, 16);
SendPacket(new EnterEncryptedMode(_encryptKey, true));
AsyncRead();
await AsyncRead();
}
void HandleConnectToFailed(ConnectToFailed connectToFailed)
@@ -752,11 +747,11 @@ namespace Game.Networking
_worldSession.SendConnectToInstance(ConnectToSerial.WorldAttempt5);
break;
case ConnectToSerial.WorldAttempt5:
{
Log.outError(LogFilter.Network, "{0} failed to connect 5 times to world socket, aborting login", _worldSession.GetPlayerInfo());
_worldSession.AbortLogin(LoginFailureReason.NoWorld);
break;
}
{
Log.outError(LogFilter.Network, "{0} failed to connect 5 times to world socket, aborting login", _worldSession.GetPlayerInfo());
_worldSession.AbortLogin(LoginFailureReason.NoWorld);
break;
}
default:
return;
}