mirror of
https://github.com/MrOkiDoki/BattleBit-Community-Server-API.git
synced 2025-01-24 10:07:48 -03:00
Player Spawn callback
This commit is contained in:
parent
f2611313cf
commit
6200ad380a
49 changed files with 1503 additions and 82 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
74
BattleBitAPI/Common/Data/Attachment.cs
Normal file
74
BattleBitAPI/Common/Data/Attachment.cs
Normal file
|
@ -0,0 +1,74 @@
|
|||
using BattleBitAPI.Common;
|
||||
using System;
|
||||
|
||||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public class Attachment : IEquatable<string>, IEquatable<Attachment>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public AttachmentType AttachmentType { get; private set; }
|
||||
public Attachment(string name, AttachmentType attachmentType)
|
||||
{
|
||||
Name = name;
|
||||
AttachmentType = attachmentType;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this.Name;
|
||||
}
|
||||
public bool Equals(string other)
|
||||
{
|
||||
if (other == null)
|
||||
return false;
|
||||
return this.Name.Equals(other);
|
||||
}
|
||||
public bool Equals(Attachment other)
|
||||
{
|
||||
if (other == null)
|
||||
return false;
|
||||
return this.Name.Equals(other.Name);
|
||||
}
|
||||
|
||||
public static bool operator ==(string left, Attachment right)
|
||||
{
|
||||
bool leftNull = object.ReferenceEquals(left, null);
|
||||
bool rightNull = object.ReferenceEquals(right, null);
|
||||
if (leftNull && rightNull)
|
||||
return true;
|
||||
if (leftNull || rightNull)
|
||||
return false;
|
||||
return right.Name.Equals(left);
|
||||
}
|
||||
public static bool operator !=(string left, Attachment right)
|
||||
{
|
||||
bool leftNull = object.ReferenceEquals(left, null);
|
||||
bool rightNull = object.ReferenceEquals(right, null);
|
||||
if (leftNull && rightNull)
|
||||
return true;
|
||||
if (leftNull || rightNull)
|
||||
return false;
|
||||
return right.Name.Equals(left);
|
||||
}
|
||||
public static bool operator ==(Attachment right, string left)
|
||||
{
|
||||
bool leftNull = object.ReferenceEquals(left, null);
|
||||
bool rightNull = object.ReferenceEquals(right, null);
|
||||
if (leftNull && rightNull)
|
||||
return true;
|
||||
if (leftNull || rightNull)
|
||||
return false;
|
||||
return right.Name.Equals(left);
|
||||
}
|
||||
public static bool operator !=(Attachment right, string left)
|
||||
{
|
||||
bool leftNull = object.ReferenceEquals(left, null);
|
||||
bool rightNull = object.ReferenceEquals(right, null);
|
||||
if (leftNull && rightNull)
|
||||
return true;
|
||||
if (leftNull || rightNull)
|
||||
return false;
|
||||
return right.Name.Equals(left);
|
||||
}
|
||||
}
|
||||
}
|
69
BattleBitAPI/Common/Data/Gadget.cs
Normal file
69
BattleBitAPI/Common/Data/Gadget.cs
Normal file
|
@ -0,0 +1,69 @@
|
|||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public class Gadget : IEquatable<string>, IEquatable<Gadget>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public Gadget(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this.Name;
|
||||
}
|
||||
public bool Equals(string other)
|
||||
{
|
||||
if (other == null)
|
||||
return false;
|
||||
return this.Name.Equals(other);
|
||||
}
|
||||
public bool Equals(Gadget other)
|
||||
{
|
||||
if (other == null)
|
||||
return false;
|
||||
return this.Name.Equals(other.Name);
|
||||
}
|
||||
|
||||
public static bool operator ==(string left, Gadget right)
|
||||
{
|
||||
bool leftNull = object.ReferenceEquals(left,null);
|
||||
bool rightNull = object.ReferenceEquals(right, null);
|
||||
if (leftNull && rightNull)
|
||||
return true;
|
||||
if (leftNull || rightNull)
|
||||
return false;
|
||||
return right.Name.Equals(left);
|
||||
}
|
||||
public static bool operator !=(string left, Gadget right)
|
||||
{
|
||||
bool leftNull = object.ReferenceEquals(left, null);
|
||||
bool rightNull = object.ReferenceEquals(right, null);
|
||||
if (leftNull && rightNull)
|
||||
return true;
|
||||
if (leftNull || rightNull)
|
||||
return false;
|
||||
return right.Name.Equals(left);
|
||||
}
|
||||
public static bool operator ==(Gadget right, string left)
|
||||
{
|
||||
bool leftNull = object.ReferenceEquals(left, null);
|
||||
bool rightNull = object.ReferenceEquals(right, null);
|
||||
if (leftNull && rightNull)
|
||||
return true;
|
||||
if (leftNull || rightNull)
|
||||
return false;
|
||||
return right.Name.Equals(left);
|
||||
}
|
||||
public static bool operator !=(Gadget right, string left)
|
||||
{
|
||||
bool leftNull = object.ReferenceEquals(left, null);
|
||||
bool rightNull = object.ReferenceEquals(right, null);
|
||||
if (leftNull && rightNull)
|
||||
return true;
|
||||
if (leftNull || rightNull)
|
||||
return false;
|
||||
return right.Name.Equals(left);
|
||||
}
|
||||
}
|
||||
}
|
349
BattleBitAPI/Common/Data/PlayerLoadout.cs
Normal file
349
BattleBitAPI/Common/Data/PlayerLoadout.cs
Normal file
|
@ -0,0 +1,349 @@
|
|||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public struct PlayerLoadout
|
||||
{
|
||||
public WeaponItem PrimaryWeapon;
|
||||
public WeaponItem SecondaryWeapon;
|
||||
public string FirstAidName;
|
||||
public string LightGadgetName;
|
||||
public string HeavyGadgetName;
|
||||
public string ThrowableName;
|
||||
|
||||
public byte PrimaryExtraMagazines;
|
||||
public byte SecondaryExtraMagazines;
|
||||
public byte FirstAidExtra;
|
||||
public byte LightGadgetExtra;
|
||||
public byte HeavyGadgetExtra;
|
||||
public byte ThrowableExtra;
|
||||
|
||||
public Gadget FirstAid
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Gadgets.TryFind(FirstAidName, out var gadget))
|
||||
return gadget;
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
this.FirstAidName = "none";
|
||||
else
|
||||
this.FirstAidName = value.Name;
|
||||
}
|
||||
}
|
||||
public Gadget LightGadget
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Gadgets.TryFind(LightGadgetName, out var gadget))
|
||||
return gadget;
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
this.LightGadgetName = "none";
|
||||
else
|
||||
this.LightGadgetName = value.Name;
|
||||
}
|
||||
}
|
||||
public Gadget HeavyGadget
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Gadgets.TryFind(HeavyGadgetName, out var gadget))
|
||||
return gadget;
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
this.HeavyGadgetName = "none";
|
||||
else
|
||||
this.HeavyGadgetName = value.Name;
|
||||
}
|
||||
}
|
||||
public Gadget Throwable
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Gadgets.TryFind(ThrowableName, out var gadget))
|
||||
return gadget;
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
this.ThrowableName = "none";
|
||||
else
|
||||
this.ThrowableName = value.Name;
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasGadget(Gadget gadget)
|
||||
{
|
||||
if (this.FirstAid == gadget)
|
||||
return true;
|
||||
if (this.LightGadget == gadget)
|
||||
return true;
|
||||
if (this.HeavyGadget == gadget)
|
||||
return true;
|
||||
if (this.Throwable == gadget)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Write(Common.Serialization.Stream ser)
|
||||
{
|
||||
this.PrimaryWeapon.Write(ser);
|
||||
this.SecondaryWeapon.Write(ser);
|
||||
ser.WriteStringItem(this.FirstAidName);
|
||||
ser.WriteStringItem(this.LightGadgetName);
|
||||
ser.WriteStringItem(this.HeavyGadgetName);
|
||||
ser.WriteStringItem(this.ThrowableName);
|
||||
|
||||
ser.Write(this.PrimaryExtraMagazines);
|
||||
ser.Write(this.SecondaryExtraMagazines);
|
||||
ser.Write(this.FirstAidExtra);
|
||||
ser.Write(this.LightGadgetExtra);
|
||||
ser.Write(this.HeavyGadgetExtra);
|
||||
ser.Write(this.ThrowableExtra);
|
||||
}
|
||||
public void Read(Common.Serialization.Stream ser)
|
||||
{
|
||||
this.PrimaryWeapon.Read(ser);
|
||||
this.SecondaryWeapon.Read(ser);
|
||||
ser.TryReadString(out this.FirstAidName);
|
||||
ser.TryReadString(out this.LightGadgetName);
|
||||
ser.TryReadString(out this.HeavyGadgetName);
|
||||
ser.TryReadString(out this.ThrowableName);
|
||||
|
||||
this.PrimaryExtraMagazines = ser.ReadInt8();
|
||||
this.SecondaryExtraMagazines = ser.ReadInt8();
|
||||
this.FirstAidExtra = ser.ReadInt8();
|
||||
this.LightGadgetExtra = ser.ReadInt8();
|
||||
this.HeavyGadgetExtra = ser.ReadInt8();
|
||||
this.ThrowableExtra = ser.ReadInt8();
|
||||
}
|
||||
|
||||
public struct WeaponItem
|
||||
{
|
||||
public string ToolName;
|
||||
public string MainSightName;
|
||||
public string TopSightName;
|
||||
public string CantedSightName;
|
||||
public string BarrelName;
|
||||
public string SideRailName;
|
||||
public string UnderRailName;
|
||||
public string BoltActionName;
|
||||
public byte SkinIndex;
|
||||
public byte MagazineIndex;
|
||||
|
||||
public Weapon Tool
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Weapons.TryFind(ToolName, out var weapon))
|
||||
return weapon;
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
this.ToolName = "none";
|
||||
else
|
||||
this.ToolName = value.Name;
|
||||
}
|
||||
}
|
||||
public Attachment MainSight
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Attachments.TryFind(MainSightName, out var attachment))
|
||||
return attachment;
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
this.MainSightName = "none";
|
||||
else
|
||||
this.MainSightName = value.Name;
|
||||
}
|
||||
}
|
||||
public Attachment TopSight
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Attachments.TryFind(TopSightName, out var attachment))
|
||||
return attachment;
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
this.TopSightName = "none";
|
||||
else
|
||||
this.TopSightName = value.Name;
|
||||
}
|
||||
}
|
||||
public Attachment CantedSight
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Attachments.TryFind(CantedSightName, out var attachment))
|
||||
return attachment;
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
this.CantedSightName = "none";
|
||||
else
|
||||
this.CantedSightName = value.Name;
|
||||
}
|
||||
}
|
||||
public Attachment Barrel
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Attachments.TryFind(BarrelName, out var attachment))
|
||||
return attachment;
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
this.BarrelName = "none";
|
||||
else
|
||||
this.BarrelName = value.Name;
|
||||
}
|
||||
}
|
||||
public Attachment SideRail
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Attachments.TryFind(SideRailName, out var attachment))
|
||||
return attachment;
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
this.SideRailName = "none";
|
||||
else
|
||||
this.SideRailName = value.Name;
|
||||
}
|
||||
}
|
||||
public Attachment UnderRail
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Attachments.TryFind(UnderRailName, out var attachment))
|
||||
return attachment;
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
this.UnderRailName = "none";
|
||||
else
|
||||
this.UnderRailName = value.Name;
|
||||
}
|
||||
}
|
||||
public Attachment BoltAction
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Attachments.TryFind(BoltActionName, out var attachment))
|
||||
return attachment;
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
this.BoltActionName = "none";
|
||||
else
|
||||
this.BoltActionName = value.Name;
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAttachment(Attachment attachment)
|
||||
{
|
||||
switch (attachment.AttachmentType)
|
||||
{
|
||||
case AttachmentType.MainSight:
|
||||
return this.MainSight == attachment;
|
||||
case AttachmentType.TopSight:
|
||||
return this.TopSight == attachment;
|
||||
case AttachmentType.CantedSight:
|
||||
return this.CantedSight == attachment;
|
||||
case AttachmentType.Barrel:
|
||||
return this.Barrel == attachment;
|
||||
case AttachmentType.UnderRail:
|
||||
return this.Barrel == attachment;
|
||||
case AttachmentType.SideRail:
|
||||
return this.SideRail == attachment;
|
||||
case AttachmentType.Bolt:
|
||||
return this.BoltAction == attachment;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void SetAttachment(Attachment attachment)
|
||||
{
|
||||
switch (attachment.AttachmentType)
|
||||
{
|
||||
case AttachmentType.MainSight:
|
||||
this.MainSight = attachment;
|
||||
break;
|
||||
case AttachmentType.TopSight:
|
||||
this.TopSight = attachment;
|
||||
break;
|
||||
case AttachmentType.CantedSight:
|
||||
this.CantedSight = attachment;
|
||||
break;
|
||||
case AttachmentType.Barrel:
|
||||
this.Barrel = attachment;
|
||||
break;
|
||||
case AttachmentType.UnderRail:
|
||||
this.Barrel = attachment;
|
||||
break;
|
||||
case AttachmentType.SideRail:
|
||||
this.SideRail = attachment;
|
||||
break;
|
||||
case AttachmentType.Bolt:
|
||||
this.BoltAction = attachment;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(Common.Serialization.Stream ser)
|
||||
{
|
||||
ser.WriteStringItem(this.ToolName);
|
||||
ser.WriteStringItem(this.MainSightName);
|
||||
ser.WriteStringItem(this.TopSightName);
|
||||
ser.WriteStringItem(this.CantedSightName);
|
||||
ser.WriteStringItem(this.BarrelName);
|
||||
ser.WriteStringItem(this.SideRailName);
|
||||
ser.WriteStringItem(this.UnderRailName);
|
||||
ser.WriteStringItem(this.BoltActionName);
|
||||
ser.Write(this.SkinIndex);
|
||||
ser.Write(this.MagazineIndex);
|
||||
}
|
||||
public void Read(Common.Serialization.Stream ser)
|
||||
{
|
||||
ser.TryReadString(out this.ToolName);
|
||||
ser.TryReadString(out this.MainSightName);
|
||||
ser.TryReadString(out this.TopSightName);
|
||||
ser.TryReadString(out this.CantedSightName);
|
||||
ser.TryReadString(out this.BarrelName);
|
||||
ser.TryReadString(out this.SideRailName);
|
||||
ser.TryReadString(out this.UnderRailName);
|
||||
ser.TryReadString(out this.BoltActionName);
|
||||
this.SkinIndex = ser.ReadInt8();
|
||||
this.MagazineIndex = ser.ReadInt8();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
50
BattleBitAPI/Common/Data/PlayerSpawnRequest.cs
Normal file
50
BattleBitAPI/Common/Data/PlayerSpawnRequest.cs
Normal file
|
@ -0,0 +1,50 @@
|
|||
using System.Numerics;
|
||||
|
||||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public struct PlayerSpawnRequest
|
||||
{
|
||||
public PlayerSpawningPosition RequestedPoint;
|
||||
public PlayerLoadout Loadout;
|
||||
public PlayerWearings Wearings;
|
||||
public Vector3 SpawnPosition;
|
||||
public Vector3 LookDirection;
|
||||
public PlayerStand SpawnStand;
|
||||
public float SpawnProtection;
|
||||
|
||||
public void Write(Common.Serialization.Stream ser)
|
||||
{
|
||||
ser.Write((byte)this.RequestedPoint);
|
||||
this.Loadout.Write(ser);
|
||||
this.Wearings.Write(ser);
|
||||
ser.Write(this.SpawnPosition.X);
|
||||
ser.Write(this.SpawnPosition.Y);
|
||||
ser.Write(this.SpawnPosition.Z);
|
||||
ser.Write(this.LookDirection.X);
|
||||
ser.Write(this.LookDirection.Y);
|
||||
ser.Write(this.LookDirection.Z);
|
||||
ser.Write((byte)this.SpawnStand);
|
||||
ser.Write(this.SpawnProtection);
|
||||
}
|
||||
public void Read(Common.Serialization.Stream ser)
|
||||
{
|
||||
this.RequestedPoint = (PlayerSpawningPosition)ser.ReadInt8();
|
||||
this.Loadout.Read(ser);
|
||||
this.Wearings.Read(ser);
|
||||
this.SpawnPosition = new Vector3()
|
||||
{
|
||||
X = ser.ReadFloat(),
|
||||
Y = ser.ReadFloat(),
|
||||
Z = ser.ReadFloat()
|
||||
};
|
||||
this.LookDirection = new Vector3()
|
||||
{
|
||||
X = ser.ReadFloat(),
|
||||
Y = ser.ReadFloat(),
|
||||
Z = ser.ReadFloat()
|
||||
};
|
||||
this.SpawnStand = (PlayerStand)ser.ReadInt8();
|
||||
this.SpawnProtection = ser.ReadFloat();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,9 @@
|
|||
{
|
||||
public class PlayerStats
|
||||
{
|
||||
public PlayerStats() { }
|
||||
public PlayerStats(byte[] data) { Load(data); }
|
||||
|
||||
public bool IsBanned;
|
||||
public Roles Roles;
|
||||
public PlayerProgess Progress = new PlayerProgess();
|
||||
|
@ -63,6 +66,26 @@
|
|||
this.Selections = ser.ReadByteArray(size);
|
||||
}
|
||||
|
||||
public byte[] SerializeToByteArray()
|
||||
{
|
||||
using (var ser = Common.Serialization.Stream.Get())
|
||||
{
|
||||
Write(ser);
|
||||
return ser.AsByteArrayData();
|
||||
}
|
||||
}
|
||||
public void Load(byte[] data)
|
||||
{
|
||||
var ser = new Common.Serialization.Stream()
|
||||
{
|
||||
Buffer = data,
|
||||
InPool = false,
|
||||
ReadPosition = 0,
|
||||
WritePosition = data.Length,
|
||||
};
|
||||
Read(ser);
|
||||
}
|
||||
|
||||
public class PlayerProgess
|
||||
{
|
||||
private const uint ParamCount = 42;
|
||||
|
|
43
BattleBitAPI/Common/Data/PlayerWearings.cs
Normal file
43
BattleBitAPI/Common/Data/PlayerWearings.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public struct PlayerWearings
|
||||
{
|
||||
public string Head;
|
||||
public string Chest;
|
||||
public string Belt;
|
||||
public string Backbag;
|
||||
public string Eye;
|
||||
public string Face;
|
||||
public string Hair;
|
||||
public string Skin;
|
||||
public string Uniform;
|
||||
public string Camo;
|
||||
|
||||
public void Write(Common.Serialization.Stream ser)
|
||||
{
|
||||
ser.WriteStringItem(this.Head);
|
||||
ser.WriteStringItem(this.Chest);
|
||||
ser.WriteStringItem(this.Belt);
|
||||
ser.WriteStringItem(this.Backbag);
|
||||
ser.WriteStringItem(this.Eye);
|
||||
ser.WriteStringItem(this.Face);
|
||||
ser.WriteStringItem(this.Hair);
|
||||
ser.WriteStringItem(this.Skin);
|
||||
ser.WriteStringItem(this.Uniform);
|
||||
ser.WriteStringItem(this.Camo);
|
||||
}
|
||||
public void Read(Common.Serialization.Stream ser)
|
||||
{
|
||||
ser.TryReadString(out this.Head);
|
||||
ser.TryReadString(out this.Chest);
|
||||
ser.TryReadString(out this.Belt);
|
||||
ser.TryReadString(out this.Backbag);
|
||||
ser.TryReadString(out this.Eye);
|
||||
ser.TryReadString(out this.Face);
|
||||
ser.TryReadString(out this.Hair);
|
||||
ser.TryReadString(out this.Skin);
|
||||
ser.TryReadString(out this.Uniform);
|
||||
ser.TryReadString(out this.Camo);
|
||||
}
|
||||
}
|
||||
}
|
73
BattleBitAPI/Common/Data/Weapon.cs
Normal file
73
BattleBitAPI/Common/Data/Weapon.cs
Normal file
|
@ -0,0 +1,73 @@
|
|||
using System;
|
||||
|
||||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public class Weapon : IEquatable<string>, IEquatable<Weapon>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public WeaponType WeaponType { get; private set; }
|
||||
public Weapon(string name, WeaponType weaponType)
|
||||
{
|
||||
Name = name;
|
||||
WeaponType = weaponType;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this.Name;
|
||||
}
|
||||
public bool Equals(string other)
|
||||
{
|
||||
if (other == null)
|
||||
return false;
|
||||
return this.Name.Equals(other);
|
||||
}
|
||||
public bool Equals(Weapon other)
|
||||
{
|
||||
if (other == null)
|
||||
return false;
|
||||
return this.Name.Equals(other.Name);
|
||||
}
|
||||
|
||||
public static bool operator ==(string left, Weapon right)
|
||||
{
|
||||
bool leftNull = object.ReferenceEquals(left, null);
|
||||
bool rightNull = object.ReferenceEquals(right, null);
|
||||
if (leftNull && rightNull)
|
||||
return true;
|
||||
if (leftNull || rightNull)
|
||||
return false;
|
||||
return right.Name.Equals(left);
|
||||
}
|
||||
public static bool operator !=(string left, Weapon right)
|
||||
{
|
||||
bool leftNull = object.ReferenceEquals(left, null);
|
||||
bool rightNull = object.ReferenceEquals(right, null);
|
||||
if (leftNull && rightNull)
|
||||
return true;
|
||||
if (leftNull || rightNull)
|
||||
return false;
|
||||
return right.Name.Equals(left);
|
||||
}
|
||||
public static bool operator ==(Weapon right, string left)
|
||||
{
|
||||
bool leftNull = object.ReferenceEquals(left, null);
|
||||
bool rightNull = object.ReferenceEquals(right, null);
|
||||
if (leftNull && rightNull)
|
||||
return true;
|
||||
if (leftNull || rightNull)
|
||||
return false;
|
||||
return right.Name.Equals(left);
|
||||
}
|
||||
public static bool operator !=(Weapon right, string left)
|
||||
{
|
||||
bool leftNull = object.ReferenceEquals(left, null);
|
||||
bool rightNull = object.ReferenceEquals(right, null);
|
||||
if (leftNull && rightNull)
|
||||
return true;
|
||||
if (leftNull || rightNull)
|
||||
return false;
|
||||
return right.Name.Equals(left);
|
||||
}
|
||||
}
|
||||
}
|
127
BattleBitAPI/Common/Datasets/Attachments.cs
Normal file
127
BattleBitAPI/Common/Datasets/Attachments.cs
Normal file
|
@ -0,0 +1,127 @@
|
|||
using System.Reflection;
|
||||
|
||||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public static class Attachments
|
||||
{
|
||||
// ----- Private Variables -----
|
||||
private static Dictionary<string, Attachment> mAttachments;
|
||||
|
||||
// ----- Barrels -----
|
||||
public static readonly Attachment Basic = new Attachment("Basic", AttachmentType.Barrel);
|
||||
public static readonly Attachment Compensator = new Attachment("Compensator", AttachmentType.Barrel);
|
||||
public static readonly Attachment Heavy = new Attachment("Heavy", AttachmentType.Barrel);
|
||||
public static readonly Attachment LongBarrel = new Attachment("Long_Barrel", AttachmentType.Barrel);
|
||||
public static readonly Attachment MuzzleBreak = new Attachment("Muzzle_Break", AttachmentType.Barrel);
|
||||
public static readonly Attachment Ranger = new Attachment("Ranger", AttachmentType.Barrel);
|
||||
public static readonly Attachment SuppressorLong = new Attachment("Suppressor_Long", AttachmentType.Barrel);
|
||||
public static readonly Attachment SuppressorShort = new Attachment("Suppressor_Short", AttachmentType.Barrel);
|
||||
public static readonly Attachment Tactical = new Attachment("Tactical", AttachmentType.Barrel);
|
||||
public static readonly Attachment FlashHider = new Attachment("Flash_Hider", AttachmentType.Barrel);
|
||||
public static readonly Attachment Osprey9 = new Attachment("Osprey_9", AttachmentType.Barrel);
|
||||
public static readonly Attachment DGN308 = new Attachment("DGN-308", AttachmentType.Barrel);
|
||||
public static readonly Attachment VAMB762 = new Attachment("VAMB-762", AttachmentType.Barrel);
|
||||
public static readonly Attachment SDN6762 = new Attachment("SDN-6_762", AttachmentType.Barrel);
|
||||
public static readonly Attachment NT4556 = new Attachment("NT-4_556", AttachmentType.Barrel);
|
||||
|
||||
// ----- Canted Sights -----
|
||||
public static readonly Attachment Ironsight = new Attachment("Ironsight", AttachmentType.CantedSight);
|
||||
public static readonly Attachment CantedRedDot = new Attachment("Canted_Red_Dot", AttachmentType.CantedSight);
|
||||
public static readonly Attachment FYouCanted = new Attachment("FYou_Canted", AttachmentType.CantedSight);
|
||||
public static readonly Attachment HoloDot = new Attachment("Holo_Dot", AttachmentType.CantedSight);
|
||||
|
||||
// ----- Scope -----
|
||||
public static readonly Attachment _6xScope = new Attachment("6x_Scope", AttachmentType.MainSight);
|
||||
public static readonly Attachment _8xScope = new Attachment("8x_Scope", AttachmentType.MainSight);
|
||||
public static readonly Attachment _15xScope = new Attachment("15x_Scope", AttachmentType.MainSight);
|
||||
public static readonly Attachment _20xScope = new Attachment("20x_Scope", AttachmentType.MainSight);
|
||||
public static readonly Attachment PTR40Hunter = new Attachment("PTR-40_Hunter", AttachmentType.MainSight);
|
||||
public static readonly Attachment _1P78 = new Attachment("1P78", AttachmentType.MainSight);
|
||||
public static readonly Attachment Acog = new Attachment("Acog", AttachmentType.MainSight);
|
||||
public static readonly Attachment M125 = new Attachment("M_125", AttachmentType.MainSight);
|
||||
public static readonly Attachment Prisma = new Attachment("Prisma", AttachmentType.MainSight);
|
||||
public static readonly Attachment Slip = new Attachment("Slip", AttachmentType.MainSight);
|
||||
public static readonly Attachment PistolDeltaSight = new Attachment("Pistol_Delta_Sight", AttachmentType.MainSight);
|
||||
public static readonly Attachment PistolRedDot = new Attachment("Pistol_Red_Dot", AttachmentType.MainSight);
|
||||
public static readonly Attachment AimComp = new Attachment("Aim_Comp", AttachmentType.MainSight);
|
||||
public static readonly Attachment Holographic = new Attachment("Holographic", AttachmentType.MainSight);
|
||||
public static readonly Attachment Kobra = new Attachment("Kobra", AttachmentType.MainSight);
|
||||
public static readonly Attachment OKP7 = new Attachment("OKP7", AttachmentType.MainSight);
|
||||
public static readonly Attachment PKAS = new Attachment("PK-AS", AttachmentType.MainSight);
|
||||
public static readonly Attachment RedDot = new Attachment("Red_Dot", AttachmentType.MainSight);
|
||||
public static readonly Attachment Reflex = new Attachment("Reflex", AttachmentType.MainSight);
|
||||
public static readonly Attachment Strikefire = new Attachment("Strikefire", AttachmentType.MainSight);
|
||||
public static readonly Attachment Razor = new Attachment("Razor", AttachmentType.MainSight);
|
||||
public static readonly Attachment Flir = new Attachment("Flir", AttachmentType.MainSight);
|
||||
public static readonly Attachment Echo = new Attachment("Echo", AttachmentType.MainSight);
|
||||
public static readonly Attachment TRI4X32 = new Attachment("TRI4X32", AttachmentType.MainSight);
|
||||
public static readonly Attachment FYouSight = new Attachment("FYou_Sight", AttachmentType.MainSight);
|
||||
public static readonly Attachment HoloPK120 = new Attachment("Holo_PK-120", AttachmentType.MainSight);
|
||||
public static readonly Attachment Pistol8xScope = new Attachment("Pistol_8x_Scope", AttachmentType.MainSight);
|
||||
public static readonly Attachment BurrisAR332 = new Attachment("BurrisAR332", AttachmentType.MainSight);
|
||||
public static readonly Attachment HS401G5 = new Attachment("HS401G5", AttachmentType.MainSight);
|
||||
|
||||
// ----- Top Scope -----
|
||||
public static readonly Attachment DeltaSightTop = new Attachment("Delta_Sight_Top", AttachmentType.TopSight);
|
||||
public static readonly Attachment RedDotTop = new Attachment("Red_Dot_Top", AttachmentType.TopSight);
|
||||
public static readonly Attachment CRedDotTop = new Attachment("C_Red_Dot_Top", AttachmentType.TopSight);
|
||||
public static readonly Attachment FYouTop = new Attachment("FYou_Top", AttachmentType.TopSight);
|
||||
|
||||
// ----- Under Rails -----
|
||||
public static readonly Attachment AngledGrip = new Attachment("Angled_Grip", AttachmentType.UnderRail);
|
||||
public static readonly Attachment Bipod = new Attachment("Bipod", AttachmentType.UnderRail);
|
||||
public static readonly Attachment VerticalGrip = new Attachment("Vertical_Grip", AttachmentType.UnderRail);
|
||||
public static readonly Attachment StubbyGrip = new Attachment("Stubby_Grip", AttachmentType.UnderRail);
|
||||
public static readonly Attachment StabilGrip = new Attachment("Stabil_Grip", AttachmentType.UnderRail);
|
||||
public static readonly Attachment VerticalSkeletonGrip = new Attachment("Vertical_Skeleton_Grip", AttachmentType.UnderRail);
|
||||
public static readonly Attachment FABDTFG = new Attachment("FAB-DTFG", AttachmentType.UnderRail);
|
||||
public static readonly Attachment MagpulAngled = new Attachment("Magpul_Angled", AttachmentType.UnderRail);
|
||||
public static readonly Attachment BCMGunFighter = new Attachment("BCM-Gun_Fighter", AttachmentType.UnderRail);
|
||||
public static readonly Attachment ShiftShortAngledGrip = new Attachment("Shift_Short_Angled_Grip", AttachmentType.UnderRail);
|
||||
public static readonly Attachment SE5Grip = new Attachment("SE-5_Grip", AttachmentType.UnderRail);
|
||||
public static readonly Attachment RK6Foregrip = new Attachment("RK-6_Foregrip", AttachmentType.UnderRail);
|
||||
public static readonly Attachment HeraCQRFront = new Attachment("HeraCQR_Front", AttachmentType.UnderRail);
|
||||
public static readonly Attachment B25URK = new Attachment("B-25URK", AttachmentType.UnderRail);
|
||||
public static readonly Attachment VTACUVGTacticalGrip = new Attachment("VTAC_UVG_TacticalGrip", AttachmentType.UnderRail);
|
||||
|
||||
// ----- Side Rails -----
|
||||
public static readonly Attachment Flashlight = new Attachment("Flashlight", AttachmentType.SideRail);
|
||||
public static readonly Attachment Rangefinder = new Attachment("Rangefinder", AttachmentType.SideRail);
|
||||
public static readonly Attachment Redlaser = new Attachment("Redlaser", AttachmentType.SideRail);
|
||||
public static readonly Attachment TacticalFlashlight = new Attachment("Tactical_Flashlight", AttachmentType.SideRail);
|
||||
public static readonly Attachment Greenlaser = new Attachment("Greenlaser", AttachmentType.SideRail);
|
||||
public static readonly Attachment Searchlight = new Attachment("Searchlight", AttachmentType.SideRail);
|
||||
|
||||
// ----- Bolts -----
|
||||
public static readonly Attachment BoltActionA = new Attachment("Bolt_Action_A", AttachmentType.Bolt);
|
||||
public static readonly Attachment BoltActionB = new Attachment("Bolt_Action_B", AttachmentType.Bolt);
|
||||
public static readonly Attachment BoltActionC = new Attachment("Bolt_Action_C", AttachmentType.Bolt);
|
||||
public static readonly Attachment BoltActionD = new Attachment("Bolt_Action_D", AttachmentType.Bolt);
|
||||
public static readonly Attachment BoltActionE = new Attachment("Bolt_Action_E", AttachmentType.Bolt);
|
||||
|
||||
// ----- Public Calls -----
|
||||
public static bool TryFind(string name, out Attachment item)
|
||||
{
|
||||
return mAttachments.TryGetValue(name, out item);
|
||||
}
|
||||
|
||||
// ----- Init -----
|
||||
static Attachments()
|
||||
{
|
||||
var members = typeof(Attachments).GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
|
||||
mAttachments = new Dictionary<string, Attachment>(members.Length);
|
||||
foreach (var memberInfo in members)
|
||||
{
|
||||
if (memberInfo.MemberType == System.Reflection.MemberTypes.Field)
|
||||
{
|
||||
var field = ((FieldInfo)memberInfo);
|
||||
if (field.FieldType == typeof(Attachment))
|
||||
{
|
||||
var att = (Attachment)field.GetValue(null);
|
||||
mAttachments.Add(att.Name, att);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
76
BattleBitAPI/Common/Datasets/Gadgets.cs
Normal file
76
BattleBitAPI/Common/Datasets/Gadgets.cs
Normal file
|
@ -0,0 +1,76 @@
|
|||
using System.Reflection;
|
||||
|
||||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public static class Gadgets
|
||||
{
|
||||
// ----- Private Variables -----
|
||||
private static Dictionary<string, Gadget> mGadgets;
|
||||
|
||||
// ----- Public Variables -----
|
||||
public static readonly Gadget Bandage = new Gadget("Bandage");
|
||||
public static readonly Gadget Binoculars = new Gadget("Binoculars");
|
||||
public static readonly Gadget RangeFinder = new Gadget("Range Finder");
|
||||
public static readonly Gadget RepairTool = new Gadget("Repair Tool");
|
||||
public static readonly Gadget C4 = new Gadget("C4");
|
||||
public static readonly Gadget Claymore = new Gadget("Claymore");
|
||||
public static readonly Gadget M320SmokeGrenadeLauncher = new Gadget("M320 Smoke Grenade Launcher");
|
||||
public static readonly Gadget SmallAmmoKit = new Gadget("Small Ammo Kit");
|
||||
public static readonly Gadget AntiPersonnelMine = new Gadget("Anti Personnel Mine");
|
||||
public static readonly Gadget AntiVehicleMine = new Gadget("Anti Vehicle Mine");
|
||||
public static readonly Gadget MedicKit = new Gadget("Medic Kit");
|
||||
public static readonly Gadget Rpg7HeatExplosive = new Gadget("Rpg7 Heat Explosive");
|
||||
public static readonly Gadget RiotShield = new Gadget("Riot Shield");
|
||||
public static readonly Gadget FragGrenade = new Gadget("Frag Grenade");
|
||||
public static readonly Gadget ImpactGrenade = new Gadget("Impact Grenade");
|
||||
public static readonly Gadget AntiVehicleGrenade = new Gadget("Anti Vehicle Grenade");
|
||||
public static readonly Gadget SmokeGrenadeBlue = new Gadget("Smoke Grenade Blue");
|
||||
public static readonly Gadget SmokeGrenadeGreen = new Gadget("Smoke Grenade Green");
|
||||
public static readonly Gadget SmokeGrenadeRed = new Gadget("Smoke Grenade Red");
|
||||
public static readonly Gadget SmokeGrenadeWhite = new Gadget("Smoke Grenade White");
|
||||
public static readonly Gadget Flare = new Gadget("Flare");
|
||||
public static readonly Gadget SledgeHammer = new Gadget("Sledge Hammer");
|
||||
public static readonly Gadget AdvancedBinoculars = new Gadget("Advanced Binoculars");
|
||||
public static readonly Gadget Mdx201 = new Gadget("Mdx 201");
|
||||
public static readonly Gadget BinoSoflam = new Gadget("Bino Soflam");
|
||||
public static readonly Gadget HeavyAmmoKit = new Gadget("Heavy Ammo Kit");
|
||||
public static readonly Gadget Rpg7Pgo7Tandem = new Gadget("Rpg7 Pgo7 Tandem");
|
||||
public static readonly Gadget Rpg7Pgo7HeatExplosive = new Gadget("Rpg7 Pgo7 Heat Explosive");
|
||||
public static readonly Gadget Rpg7Pgo7Fragmentation = new Gadget("Rpg7 Pgo7 Fragmentation");
|
||||
public static readonly Gadget Rpg7Fragmentation = new Gadget("Rpg7 Fragmentation");
|
||||
public static readonly Gadget GrapplingHook = new Gadget("Grappling Hook");
|
||||
public static readonly Gadget AirDrone = new Gadget("Air Drone");
|
||||
public static readonly Gadget Flashbang = new Gadget("Flashbang");
|
||||
public static readonly Gadget Pickaxe = new Gadget("Pickaxe");
|
||||
public static readonly Gadget SuicideC4 = new Gadget("SuicideC4");
|
||||
public static readonly Gadget SledgeHammerSkinA = new Gadget("Sledge Hammer SkinA");
|
||||
public static readonly Gadget SledgeHammerSkinB = new Gadget("Sledge Hammer SkinB");
|
||||
public static readonly Gadget SledgeHammerSkinC = new Gadget("Sledge Hammer SkinC");
|
||||
public static readonly Gadget PickaxeIronPickaxe = new Gadget("Pickaxe IronPickaxe");
|
||||
|
||||
// ----- Public Calls -----
|
||||
public static bool TryFind(string name, out Gadget item)
|
||||
{
|
||||
return mGadgets.TryGetValue(name, out item);
|
||||
}
|
||||
|
||||
// ----- Init -----
|
||||
static Gadgets()
|
||||
{
|
||||
var members = typeof(Gadgets).GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
|
||||
mGadgets = new Dictionary<string, Gadget>(members.Length);
|
||||
foreach (var memberInfo in members)
|
||||
{
|
||||
if (memberInfo.MemberType == System.Reflection.MemberTypes.Field)
|
||||
{
|
||||
var field = ((FieldInfo)memberInfo);
|
||||
if (field.FieldType == typeof(Gadget))
|
||||
{
|
||||
var gad = (Gadget)field.GetValue(null);
|
||||
mGadgets.Add(gad.Name, gad);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
82
BattleBitAPI/Common/Datasets/Weapons.cs
Normal file
82
BattleBitAPI/Common/Datasets/Weapons.cs
Normal file
|
@ -0,0 +1,82 @@
|
|||
using Microsoft.VisualBasic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public static class Weapons
|
||||
{
|
||||
// ----- Private Variables -----
|
||||
private static Dictionary<string, Weapon> mWeapons;
|
||||
|
||||
// ----- Public Variables -----
|
||||
public readonly static Weapon ACR = new Weapon("ACR", WeaponType.Rifle);
|
||||
public readonly static Weapon AK15 = new Weapon("AK15", WeaponType.Rifle);
|
||||
public readonly static Weapon AK74 = new Weapon("AK74", WeaponType.Rifle);
|
||||
public readonly static Weapon G36C = new Weapon("G36C", WeaponType.Rifle);
|
||||
public readonly static Weapon HoneyBadger = new Weapon("Honey Badger", WeaponType.PersonalDefenseWeapon_PDW);
|
||||
public readonly static Weapon KrissVector = new Weapon("Kriss Vector", WeaponType.SubmachineGun_SMG);
|
||||
public readonly static Weapon L86A1 = new Weapon("L86A1", WeaponType.LightSupportGun_LSG);
|
||||
public readonly static Weapon L96 = new Weapon("L96", WeaponType.SniperRifle);
|
||||
public readonly static Weapon M4A1 = new Weapon("M4A1", WeaponType.Rifle);
|
||||
public readonly static Weapon M9 = new Weapon("M9", WeaponType.Pistol);
|
||||
public readonly static Weapon M110 = new Weapon("M110", WeaponType.DMR);
|
||||
public readonly static Weapon M249 = new Weapon("M249", WeaponType.LightMachineGun_LMG);
|
||||
public readonly static Weapon MK14EBR = new Weapon("MK14 EBR", WeaponType.DMR);
|
||||
public readonly static Weapon MK20 = new Weapon("MK20", WeaponType.DMR);
|
||||
public readonly static Weapon MP7 = new Weapon("MP7", WeaponType.SubmachineGun_SMG);
|
||||
public readonly static Weapon PP2000 = new Weapon("PP2000", WeaponType.SubmachineGun_SMG);
|
||||
public readonly static Weapon SCARH = new Weapon("SCAR-H", WeaponType.Rifle);
|
||||
public readonly static Weapon SSG69 = new Weapon("SSG 69", WeaponType.SniperRifle);
|
||||
public readonly static Weapon SV98 = new Weapon("SV-98", WeaponType.SniperRifle);
|
||||
public readonly static Weapon UMP45 = new Weapon("UMP-45", WeaponType.SubmachineGun_SMG);
|
||||
public readonly static Weapon Unica = new Weapon("Unica", WeaponType.HeavyPistol);
|
||||
public readonly static Weapon USP = new Weapon("USP", WeaponType.Pistol);
|
||||
public readonly static Weapon AsVal = new Weapon("As Val", WeaponType.Carbine);
|
||||
public readonly static Weapon AUGA3 = new Weapon("AUG A3", WeaponType.Rifle);
|
||||
public readonly static Weapon DesertEagle = new Weapon("Desert Eagle", WeaponType.HeavyPistol);
|
||||
public readonly static Weapon FAL = new Weapon("FAL", WeaponType.Rifle);
|
||||
public readonly static Weapon Glock18 = new Weapon("Glock 18", WeaponType.AutoPistol);
|
||||
public readonly static Weapon M200 = new Weapon("M200", WeaponType.SniperRifle);
|
||||
public readonly static Weapon MP443 = new Weapon("MP 443", WeaponType.Pistol);
|
||||
public readonly static Weapon FAMAS = new Weapon("FAMAS", WeaponType.Rifle);
|
||||
public readonly static Weapon MP5 = new Weapon("MP5", WeaponType.SubmachineGun_SMG);
|
||||
public readonly static Weapon P90 = new Weapon("P90", WeaponType.PersonalDefenseWeapon_PDW);
|
||||
public readonly static Weapon MSR = new Weapon("MSR", WeaponType.SniperRifle);
|
||||
public readonly static Weapon PP19 = new Weapon("PP19", WeaponType.SubmachineGun_SMG);
|
||||
public readonly static Weapon SVD = new Weapon("SVD", WeaponType.DMR);
|
||||
public readonly static Weapon Rem700 = new Weapon("Rem700", WeaponType.SniperRifle);
|
||||
public readonly static Weapon SG550 = new Weapon("SG550", WeaponType.Rifle);
|
||||
public readonly static Weapon Groza = new Weapon("Groza", WeaponType.PersonalDefenseWeapon_PDW);
|
||||
public readonly static Weapon HK419 = new Weapon("HK419", WeaponType.Rifle);
|
||||
public readonly static Weapon ScorpionEVO = new Weapon("ScorpionEVO", WeaponType.Carbine);
|
||||
public readonly static Weapon Rsh12 = new Weapon("Rsh12", WeaponType.HeavyPistol);
|
||||
public readonly static Weapon MG36 = new Weapon("MG36", WeaponType.LightSupportGun_LSG);
|
||||
public readonly static Weapon AK5C = new Weapon("AK5C", WeaponType.Rifle);
|
||||
public readonly static Weapon Ultimax100 = new Weapon("Ultimax100", WeaponType.LightMachineGun_LMG);
|
||||
|
||||
// ----- Public Calls -----
|
||||
public static bool TryFind(string name, out Weapon item)
|
||||
{
|
||||
return mWeapons.TryGetValue(name, out item);
|
||||
}
|
||||
|
||||
// ----- Init -----
|
||||
static Weapons()
|
||||
{
|
||||
var members = typeof(Weapons).GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
|
||||
mWeapons = new Dictionary<string, Weapon>(members.Length);
|
||||
foreach (var memberInfo in members)
|
||||
{
|
||||
if (memberInfo.MemberType == System.Reflection.MemberTypes.Field)
|
||||
{
|
||||
var field = ((FieldInfo)memberInfo);
|
||||
if (field.FieldType == typeof(Weapon))
|
||||
{
|
||||
var wep = (Weapon)field.GetValue(null);
|
||||
mWeapons.Add(wep.Name, wep);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
BattleBitAPI/Common/Enums/AttachmentType.cs
Normal file
13
BattleBitAPI/Common/Enums/AttachmentType.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public enum AttachmentType
|
||||
{
|
||||
MainSight,
|
||||
TopSight,
|
||||
CantedSight,
|
||||
Barrel,
|
||||
UnderRail,
|
||||
SideRail,
|
||||
Bolt,
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
namespace BattleBitAPI.Common.Enums
|
||||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public enum ChatChannel
|
||||
{
|
||||
|
|
7
BattleBitAPI/Common/Enums/GameRole.cs
Normal file
7
BattleBitAPI/Common/Enums/GameRole.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public enum GameRole
|
||||
{
|
||||
Assault = 0, Medic = 1, Support = 2, Engineer = 3, Recon = 4, Leader = 5
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
namespace BattleBitAPI.Common.Enums
|
||||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public enum MapDayNight : byte
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
namespace BattleBitAPI.Common.Enums
|
||||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public enum MapSize : byte
|
||||
{
|
||||
|
|
7
BattleBitAPI/Common/Enums/PlayerSpawningPoint.cs
Normal file
7
BattleBitAPI/Common/Enums/PlayerSpawningPoint.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public enum PlayerSpawningPosition : byte
|
||||
{
|
||||
SpawnAtPoint, SpawnAtRally, SpawnAtFriend, SpawnAtVehicle, Null
|
||||
}
|
||||
}
|
7
BattleBitAPI/Common/Enums/PlayerStand.cs
Normal file
7
BattleBitAPI/Common/Enums/PlayerStand.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public enum PlayerStand : byte
|
||||
{
|
||||
Standing = 0, Crouching = 1, Proning = 2
|
||||
}
|
||||
}
|
72
BattleBitAPI/Common/Enums/Squads.cs
Normal file
72
BattleBitAPI/Common/Enums/Squads.cs
Normal file
|
@ -0,0 +1,72 @@
|
|||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public enum Squads
|
||||
{
|
||||
NoSquad = 0,
|
||||
|
||||
Alpha = 1,
|
||||
Bravo = 2,
|
||||
Charlie = 3,
|
||||
Delta = 4,
|
||||
Echo = 5,
|
||||
Foxtrot = 6,
|
||||
Golf = 7,
|
||||
Hotel = 8,
|
||||
India = 9,
|
||||
Juliett = 10,
|
||||
Kilo = 11,
|
||||
Lima = 12,
|
||||
Mike = 13,
|
||||
November = 14,
|
||||
Oscar = 15,
|
||||
Papa = 16,
|
||||
Quebec = 17,
|
||||
Romeo = 18,
|
||||
Sierra = 19,
|
||||
Tango = 20,
|
||||
Uniform = 21,
|
||||
Whiskey = 22,
|
||||
Xray = 23,
|
||||
Yankee = 24,
|
||||
Zulu = 25,
|
||||
Ash = 26,
|
||||
Baker = 27,
|
||||
Cast = 28,
|
||||
Diver = 29,
|
||||
Eagle = 30,
|
||||
Fisher = 31,
|
||||
George = 32,
|
||||
Hanover = 33,
|
||||
Ice = 34,
|
||||
Jake = 35,
|
||||
King = 36,
|
||||
Lash = 37,
|
||||
Mule = 38,
|
||||
Neptune = 39,
|
||||
Ostend = 40,
|
||||
Page = 41,
|
||||
Quail = 42,
|
||||
Raft = 43,
|
||||
Scout = 44,
|
||||
Tare = 45,
|
||||
Unit = 46,
|
||||
William = 47,
|
||||
Xaintrie = 48,
|
||||
Yoke = 49,
|
||||
Zebra = 50,
|
||||
Ace = 51,
|
||||
Beer = 52,
|
||||
Cast2 = 53,
|
||||
Duff = 54,
|
||||
Edward = 55,
|
||||
Freddy = 56,
|
||||
Gustav = 57,
|
||||
Henry = 58,
|
||||
Ivar = 59,
|
||||
Jazz = 60,
|
||||
Key = 61,
|
||||
Lincoln = 62,
|
||||
Mary = 63,
|
||||
Nora = 64
|
||||
}
|
||||
}
|
9
BattleBitAPI/Common/Enums/Team.cs
Normal file
9
BattleBitAPI/Common/Enums/Team.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public enum Team : byte
|
||||
{
|
||||
TeamA = 0,
|
||||
TeamB = 1,
|
||||
None = 2
|
||||
}
|
||||
}
|
17
BattleBitAPI/Common/Enums/WeaponType.cs
Normal file
17
BattleBitAPI/Common/Enums/WeaponType.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public enum WeaponType : int
|
||||
{
|
||||
Rifle,
|
||||
DMR,
|
||||
SniperRifle,
|
||||
LightSupportGun_LSG,
|
||||
LightMachineGun_LMG,
|
||||
SubmachineGun_SMG,
|
||||
Pistol,
|
||||
AutoPistol,
|
||||
HeavyPistol,
|
||||
Carbine,
|
||||
PersonalDefenseWeapon_PDW,
|
||||
}
|
||||
}
|
|
@ -182,6 +182,13 @@ namespace BattleBitAPI.Common.Serialization
|
|||
System.Array.Copy(source.Buffer, 0, this.Buffer, this.WritePosition, source.WritePosition);
|
||||
this.WritePosition += source.WritePosition;
|
||||
}
|
||||
public void WriteStringItem(string value)
|
||||
{
|
||||
if (value == null)
|
||||
this.Write("none");
|
||||
else
|
||||
this.Write(value);
|
||||
}
|
||||
|
||||
public unsafe void WriteAt(byte value, int position)
|
||||
{
|
||||
|
@ -624,13 +631,11 @@ namespace BattleBitAPI.Common.Serialization
|
|||
System.Array.Copy(this.Buffer, 0, data, 0, this.WritePosition);
|
||||
return data;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
this.ReadPosition = 0;
|
||||
this.WritePosition = 0;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (InPool)
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
ExecuteCommand = 10,
|
||||
SendPlayerStats = 11,
|
||||
SpawnPlayer = 12,
|
||||
|
||||
PlayerConnected = 50,
|
||||
PlayerDisconnected = 51,
|
||||
|
@ -16,6 +17,11 @@
|
|||
OnPlayerKilledAnotherPlayer = 53,
|
||||
GetPlayerStats = 54,
|
||||
SavePlayerStats = 55,
|
||||
|
||||
OnPlayerAskingToChangeRole = 56,
|
||||
OnPlayerChangedRole = 57,
|
||||
OnPlayerJoinedASquad = 58,
|
||||
OnPlayerLeftSquad = 59,
|
||||
OnPlayerChangedTeam = 60,
|
||||
OnPlayerRequestingToSpawn = 61,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,22 @@
|
|||
using BattleBitAPI.Server;
|
||||
using BattleBitAPI.Common;
|
||||
using BattleBitAPI.Server;
|
||||
using System.Numerics;
|
||||
|
||||
namespace BattleBitAPI
|
||||
{
|
||||
public class Player
|
||||
{
|
||||
public ulong SteamID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public GameServer GameServer { get; set; }
|
||||
public ulong SteamID { get; internal set; }
|
||||
public string Name { get; internal set; }
|
||||
public GameServer GameServer { get; internal set; }
|
||||
public GameRole Role { get; internal set; }
|
||||
public Team Team { get; internal set; }
|
||||
public Squads Squad { get; internal set; }
|
||||
|
||||
internal virtual void OnInitialized()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Kick(string reason = "")
|
||||
{
|
||||
|
@ -41,6 +50,10 @@ namespace BattleBitAPI
|
|||
{
|
||||
this.GameServer.MessageToPlayer(this, msg);
|
||||
}
|
||||
public void SetNewRole(GameRole role)
|
||||
{
|
||||
this.GameServer.SetRoleTo(this, role);
|
||||
}
|
||||
public void Teleport(Vector3 target)
|
||||
{
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Numerics;
|
||||
using BattleBitAPI.Common.Enums;
|
||||
using BattleBitAPI.Common;
|
||||
using BattleBitAPI.Common.Extentions;
|
||||
using BattleBitAPI.Networking;
|
||||
using CommunityServerAPI.BattleBitAPI;
|
||||
|
@ -204,6 +203,14 @@ namespace BattleBitAPI.Server
|
|||
}
|
||||
}
|
||||
|
||||
// ---- Team ----
|
||||
public IEnumerable<Player> GetAllPlayers()
|
||||
{
|
||||
var list = new List<Player>(254);
|
||||
list.AddRange(this.mInternal.Players.Values);
|
||||
return list;
|
||||
}
|
||||
|
||||
// ---- Functions ----
|
||||
public void WriteToSocket(Common.Serialization.Stream pck)
|
||||
{
|
||||
|
@ -336,6 +343,14 @@ namespace BattleBitAPI.Server
|
|||
{
|
||||
MessageToPlayer(player.SteamID, msg);
|
||||
}
|
||||
public void SetRoleTo(ulong steamID, GameRole role)
|
||||
{
|
||||
ExecuteCommand("setrole " + steamID + " " + role);
|
||||
}
|
||||
public void SetRoleTo(Player player, GameRole role)
|
||||
{
|
||||
SetRoleTo(player.SteamID, role);
|
||||
}
|
||||
|
||||
// ---- Closing ----
|
||||
private void mClose(string reason)
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
using System.Net.Sockets;
|
||||
using System.Numerics;
|
||||
using BattleBitAPI.Common;
|
||||
using BattleBitAPI.Common.Enums;
|
||||
using BattleBitAPI.Common.Extentions;
|
||||
using BattleBitAPI.Common.Serialization;
|
||||
using BattleBitAPI.Networking;
|
||||
|
@ -59,20 +58,6 @@ namespace BattleBitAPI.Server
|
|||
/// </remarks>
|
||||
public Func<GameServer, Task> OnGameServerDisconnected { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a new instance of PlayerClass is being created.
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// ulong - SteamID of the player <br/>
|
||||
/// string - Username of the player <br/>
|
||||
/// Gameserver - The game server instance that player in <br/>
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// Returns: An instance of Player class where 'SteamID', 'Username', 'Gameserver' assiged.
|
||||
/// </value>
|
||||
public Func<ulong, string, GameServer, TPlayer> OnCreateClient { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a player connects to a server.<br/>
|
||||
/// Check player.GameServer get the server that player joined.
|
||||
|
@ -123,11 +108,12 @@ namespace BattleBitAPI.Server
|
|||
///
|
||||
/// <remarks>
|
||||
/// ulong - SteamID of the player<br/>
|
||||
/// PlayerStats - The official stats of the player<br/>
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// Returns: The stats of the player.
|
||||
/// Returns: The modified stats of the player.
|
||||
/// </value>
|
||||
public Func<ulong, Task<PlayerStats>> OnGetPlayerStats { get; set; }
|
||||
public Func<ulong, PlayerStats, Task<PlayerStats>> OnGetPlayerStats { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Fired when game server requests to save the stats of a player.
|
||||
|
@ -142,6 +128,72 @@ namespace BattleBitAPI.Server
|
|||
/// </value>
|
||||
public Func<ulong, PlayerStats, Task> OnSavePlayerStats { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a player requests server to change role.
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// TPlayer - The player requesting<br/>
|
||||
/// GameRole - The role the player asking to change<br/>
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// Returns: True if you accept if, false if you don't.
|
||||
/// </value>
|
||||
public Func<TPlayer, GameRole, Task<bool>> OnPlayerRequestingToChangeRole { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a player changes their game role.
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// TPlayer - The player<br/>
|
||||
/// GameRole - The new role of the player<br/>
|
||||
/// </remarks>
|
||||
public Func<TPlayer, GameRole, Task> OnPlayerChangedRole { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a player joins a squad.
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// TPlayer - The player<br/>
|
||||
/// Squads - The squad player joined<br/>
|
||||
/// </remarks>
|
||||
public Func<TPlayer, Squads, Task> OnPlayerJoinedASquad { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a player leaves their squad.
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// TPlayer - The player<br/>
|
||||
/// Squads - The squad that player left<br/>
|
||||
/// </remarks>
|
||||
public Func<TPlayer, Squads, Task> OnPlayerLeftSquad { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a player changes team.
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// TPlayer - The player<br/>
|
||||
/// Team - The new team that player joined<br/>
|
||||
/// </remarks>
|
||||
public Func<TPlayer, Team, Task> OnPlayerChangedTeam { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a player is spawning.
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// TPlayer - The player<br/>
|
||||
/// PlayerSpawnRequest - The request<br/>
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// Returns: The new spawn response
|
||||
/// </value>
|
||||
public Func<TPlayer, PlayerSpawnRequest, Task<PlayerSpawnRequest>> OnPlayerSpawning { get; set; }
|
||||
|
||||
// --- Private ---
|
||||
private TcpListener mSocket;
|
||||
private Dictionary<ulong, GameServer> mActiveConnections;
|
||||
|
@ -451,20 +503,45 @@ namespace BattleBitAPI.Server
|
|||
}
|
||||
}
|
||||
|
||||
if (OnCreateClient != null)
|
||||
//Team
|
||||
Team team;
|
||||
{
|
||||
var player = OnCreateClient(steamid, username, server);
|
||||
resources.AddPlayer(player);
|
||||
readStream.Reset();
|
||||
if (!await networkStream.TryRead(readStream, 1, source.Token))
|
||||
throw new Exception("Unable to read the Team");
|
||||
team = (Team)readStream.ReadInt8();
|
||||
}
|
||||
else
|
||||
{
|
||||
TPlayer player = Activator.CreateInstance<TPlayer>();
|
||||
player.SteamID = steamid;
|
||||
player.Name = username;
|
||||
player.GameServer = server;
|
||||
|
||||
resources.AddPlayer(player);
|
||||
//Squad
|
||||
Squads squad;
|
||||
{
|
||||
readStream.Reset();
|
||||
if (!await networkStream.TryRead(readStream, 1, source.Token))
|
||||
throw new Exception("Unable to read the Squad");
|
||||
squad = (Squads)readStream.ReadInt8();
|
||||
}
|
||||
|
||||
//Role
|
||||
GameRole role;
|
||||
{
|
||||
readStream.Reset();
|
||||
if (!await networkStream.TryRead(readStream, 1, source.Token))
|
||||
throw new Exception("Unable to read the Role");
|
||||
role = (GameRole)readStream.ReadInt8();
|
||||
}
|
||||
|
||||
TPlayer player = Activator.CreateInstance<TPlayer>();
|
||||
player.SteamID = steamid;
|
||||
player.Name = username;
|
||||
player.GameServer = server;
|
||||
|
||||
player.Team = team;
|
||||
player.Squad = squad;
|
||||
player.Role = role;
|
||||
|
||||
player.OnInitialized();
|
||||
|
||||
resources.AddPlayer(player);
|
||||
}
|
||||
|
||||
//Send accepted notification.
|
||||
|
@ -563,29 +640,29 @@ namespace BattleBitAPI.Server
|
|||
{
|
||||
case NetworkCommuncation.PlayerConnected:
|
||||
{
|
||||
if (stream.CanRead(8))
|
||||
if (stream.CanRead(8 + 2 + (1 + 1 + 1)))
|
||||
{
|
||||
ulong steamID = stream.ReadUInt64();
|
||||
if (stream.TryReadString(out var username))
|
||||
{
|
||||
if (OnCreateClient != null)
|
||||
{
|
||||
var player = OnCreateClient(steamID, username, server);
|
||||
resources.AddPlayer(player);
|
||||
if (OnPlayerConnected != null)
|
||||
await OnPlayerConnected.Invoke(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
TPlayer player = Activator.CreateInstance<TPlayer>();
|
||||
player.SteamID = steamID;
|
||||
player.Name = username;
|
||||
player.GameServer = server;
|
||||
Team team = (Team)stream.ReadInt8();
|
||||
Squads squad = (Squads)stream.ReadInt8();
|
||||
GameRole role = (GameRole)stream.ReadInt8();
|
||||
|
||||
resources.AddPlayer(player);
|
||||
if (OnPlayerConnected != null)
|
||||
await OnPlayerConnected.Invoke(player);
|
||||
}
|
||||
TPlayer player = Activator.CreateInstance<TPlayer>();
|
||||
player.SteamID = steamID;
|
||||
player.Name = username;
|
||||
player.GameServer = server;
|
||||
|
||||
player.Team = team;
|
||||
player.Squad = squad;
|
||||
player.Role = role;
|
||||
|
||||
player.OnInitialized();
|
||||
|
||||
resources.AddPlayer(player);
|
||||
if (OnPlayerConnected != null)
|
||||
await OnPlayerConnected.Invoke(player);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -641,7 +718,7 @@ namespace BattleBitAPI.Server
|
|||
if (resources.TryGetPlayer(killer, out var killerClient))
|
||||
if (resources.TryGetPlayer(victim, out var victimClient))
|
||||
if (OnAPlayerKilledAnotherPlayer != null)
|
||||
OnAPlayerKilledAnotherPlayer.Invoke((TPlayer)killerClient, killerPos, (TPlayer)victimClient, victimPos, tool);
|
||||
await OnAPlayerKilledAnotherPlayer.Invoke((TPlayer)killerClient, killerPos, (TPlayer)victimClient, victimPos, tool);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -649,22 +726,22 @@ namespace BattleBitAPI.Server
|
|||
}
|
||||
case NetworkCommuncation.GetPlayerStats:
|
||||
{
|
||||
if (stream.CanRead(8))
|
||||
if (stream.CanRead(8 + 2))
|
||||
{
|
||||
ulong steamID = stream.ReadUInt64();
|
||||
|
||||
var stats = new PlayerStats();
|
||||
stats.Read(stream);
|
||||
|
||||
if (OnGetPlayerStats != null)
|
||||
stats = await OnGetPlayerStats.Invoke(steamID, stats);
|
||||
|
||||
using (var response = Common.Serialization.Stream.Get())
|
||||
{
|
||||
var stats = await OnGetPlayerStats.Invoke(steamID);
|
||||
|
||||
using (var response = Common.Serialization.Stream.Get())
|
||||
{
|
||||
response.Write((byte)NetworkCommuncation.SendPlayerStats);
|
||||
response.Write(steamID);
|
||||
stats.Write(response);
|
||||
|
||||
server.WriteToSocket(response);
|
||||
}
|
||||
response.Write((byte)NetworkCommuncation.SendPlayerStats);
|
||||
response.Write(steamID);
|
||||
stats.Write(response);
|
||||
server.WriteToSocket(response);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -682,6 +759,121 @@ namespace BattleBitAPI.Server
|
|||
}
|
||||
break;
|
||||
}
|
||||
case NetworkCommuncation.OnPlayerAskingToChangeRole:
|
||||
{
|
||||
if (stream.CanRead(8 + 1))
|
||||
{
|
||||
ulong steamID = stream.ReadUInt64();
|
||||
GameRole role = (GameRole)stream.ReadInt8();
|
||||
|
||||
if (resources.TryGetPlayer(steamID, out var client))
|
||||
{
|
||||
bool accepted = true;
|
||||
|
||||
if (OnPlayerRequestingToChangeRole != null)
|
||||
accepted = await OnPlayerRequestingToChangeRole.Invoke((TPlayer)client, role);
|
||||
|
||||
if (accepted)
|
||||
server.SetRoleTo(steamID, role);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NetworkCommuncation.OnPlayerChangedRole:
|
||||
{
|
||||
if (stream.CanRead(8 + 1))
|
||||
{
|
||||
ulong steamID = stream.ReadUInt64();
|
||||
GameRole role = (GameRole)stream.ReadInt8();
|
||||
|
||||
if (resources.TryGetPlayer(steamID, out var client))
|
||||
{
|
||||
client.Role = role;
|
||||
if (OnPlayerChangedRole != null)
|
||||
await OnPlayerChangedRole.Invoke((TPlayer)client, role);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NetworkCommuncation.OnPlayerJoinedASquad:
|
||||
{
|
||||
if (stream.CanRead(8 + 1))
|
||||
{
|
||||
ulong steamID = stream.ReadUInt64();
|
||||
Squads squad = (Squads)stream.ReadInt8();
|
||||
|
||||
if (resources.TryGetPlayer(steamID, out var client))
|
||||
{
|
||||
client.Squad = squad;
|
||||
if (OnPlayerJoinedASquad != null)
|
||||
await OnPlayerJoinedASquad.Invoke((TPlayer)client, squad);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NetworkCommuncation.OnPlayerLeftSquad:
|
||||
{
|
||||
if (stream.CanRead(8))
|
||||
{
|
||||
ulong steamID = stream.ReadUInt64();
|
||||
|
||||
if (resources.TryGetPlayer(steamID, out var client))
|
||||
{
|
||||
var oldSquad = client.Squad;
|
||||
var oldRole = client.Role;
|
||||
client.Squad = Squads.NoSquad;
|
||||
client.Role = GameRole.Assault;
|
||||
|
||||
if (OnPlayerLeftSquad != null)
|
||||
await OnPlayerLeftSquad.Invoke((TPlayer)client, oldSquad);
|
||||
|
||||
if (oldRole != GameRole.Assault)
|
||||
if (OnPlayerChangedRole != null)
|
||||
await OnPlayerChangedRole.Invoke((TPlayer)client, GameRole.Assault);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NetworkCommuncation.OnPlayerChangedTeam:
|
||||
{
|
||||
if (stream.CanRead(8 + 1))
|
||||
{
|
||||
ulong steamID = stream.ReadUInt64();
|
||||
Team team = (Team)stream.ReadInt8();
|
||||
|
||||
if (resources.TryGetPlayer(steamID, out var client))
|
||||
{
|
||||
client.Team = team;
|
||||
if (OnPlayerChangedTeam != null)
|
||||
await OnPlayerChangedTeam.Invoke((TPlayer)client, team);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NetworkCommuncation.OnPlayerRequestingToSpawn:
|
||||
{
|
||||
if (stream.CanRead(2))
|
||||
{
|
||||
ulong steamID = stream.ReadUInt64();
|
||||
|
||||
var request = new PlayerSpawnRequest();
|
||||
request.Read(stream);
|
||||
|
||||
if (resources.TryGetPlayer(steamID, out var client))
|
||||
if (this.OnPlayerSpawning != null)
|
||||
request = await OnPlayerSpawning.Invoke((TPlayer)client, request);
|
||||
|
||||
//Respond back.
|
||||
using (var response = Common.Serialization.Stream.Get())
|
||||
{
|
||||
response.Write((byte)NetworkCommuncation.SpawnPlayer);
|
||||
response.Write(steamID);
|
||||
request.Write(response);
|
||||
server.WriteToSocket(response);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
41
BattleBitAPI/Storage/DiskStorage.cs
Normal file
41
BattleBitAPI/Storage/DiskStorage.cs
Normal file
|
@ -0,0 +1,41 @@
|
|||
using BattleBitAPI.Common;
|
||||
|
||||
namespace BattleBitAPI.Storage
|
||||
{
|
||||
public class DiskStorage : IPlayerStatsDatabase
|
||||
{
|
||||
private string mDirectory;
|
||||
public DiskStorage(string directory)
|
||||
{
|
||||
var info = new DirectoryInfo(directory);
|
||||
if (!info.Exists)
|
||||
info.Create();
|
||||
|
||||
this.mDirectory = info.FullName + Path.DirectorySeparatorChar;
|
||||
}
|
||||
|
||||
public async Task<PlayerStats> GetPlayerStatsOf(ulong steamID)
|
||||
{
|
||||
var file = this.mDirectory + steamID + ".data";
|
||||
if (File.Exists(file))
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = await File.ReadAllBytesAsync(file);
|
||||
return new PlayerStats(data);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public async Task SavePlayerStatsOf(ulong steamID, PlayerStats stats)
|
||||
{
|
||||
var file = this.mDirectory + steamID + ".data";
|
||||
try
|
||||
{
|
||||
await File.WriteAllBytesAsync(file, stats.SerializeToByteArray());
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
10
BattleBitAPI/Storage/IPlayerStatsDatabase.cs
Normal file
10
BattleBitAPI/Storage/IPlayerStatsDatabase.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using BattleBitAPI.Common;
|
||||
|
||||
namespace BattleBitAPI.Storage
|
||||
{
|
||||
public interface IPlayerStatsDatabase
|
||||
{
|
||||
public Task<PlayerStats> GetPlayerStatsOf(ulong steamID);
|
||||
public Task SavePlayerStatsOf(ulong steamID, PlayerStats stats);
|
||||
}
|
||||
}
|
65
Program.cs
65
Program.cs
|
@ -1,37 +1,78 @@
|
|||
using BattleBitAPI;
|
||||
using BattleBitAPI.Common;
|
||||
using BattleBitAPI.Common.Enums;
|
||||
using BattleBitAPI.Server;
|
||||
using BattleBitAPI.Storage;
|
||||
using System.Numerics;
|
||||
|
||||
class Program
|
||||
{
|
||||
|
||||
static DiskStorage playerStats;
|
||||
static void Main(string[] args)
|
||||
{
|
||||
playerStats = new DiskStorage("Players\\");
|
||||
var listener = new ServerListener<MyPlayer>();
|
||||
listener.OnGetPlayerStats += OnGetPlayerStats;
|
||||
listener.OnSavePlayerStats += OnSavePlayerStats;
|
||||
listener.OnPlayerSpawning += OnPlayerSpawning;
|
||||
listener.Start(29294);//Port
|
||||
|
||||
Thread.Sleep(-1);
|
||||
}
|
||||
|
||||
public static PlayerStats Stats;
|
||||
|
||||
private static async Task OnSavePlayerStats(ulong steamID, PlayerStats stats)
|
||||
|
||||
private static async Task<PlayerSpawnRequest> OnPlayerSpawning(MyPlayer player, PlayerSpawnRequest request)
|
||||
{
|
||||
Stats = stats;
|
||||
if (request.Loadout.PrimaryWeapon.Tool == Weapons.M4A1)
|
||||
{
|
||||
//Don't allow M4A1
|
||||
request.Loadout.PrimaryWeapon.Tool = null;
|
||||
}
|
||||
else if (request.Loadout.PrimaryWeapon.Tool.WeaponType == WeaponType.SniperRifle)
|
||||
{
|
||||
//Force 6x if weapon is sniper.
|
||||
request.Loadout.PrimaryWeapon.MainSight = Attachments._6xScope;
|
||||
}
|
||||
|
||||
//Override pistol with deagle
|
||||
request.Loadout.SecondaryWeapon.Tool = Weapons.DesertEagle;
|
||||
|
||||
//Force everyone to use RPG
|
||||
request.Loadout.LightGadget = Gadgets.Rpg7HeatExplosive;
|
||||
|
||||
//Don't allow C4s
|
||||
if (request.Loadout.HeavyGadget == Gadgets.C4)
|
||||
request.Loadout.HeavyGadget = null;
|
||||
|
||||
//Spawn player 2 meter above than the original position.
|
||||
request.SpawnPosition.Y += 2f;
|
||||
|
||||
//Remove spawn protection
|
||||
request.SpawnProtection = 0f;
|
||||
|
||||
//Remove chest armor
|
||||
request.Wearings.Chest = null;
|
||||
|
||||
//Give extra 10 more magazines on primary
|
||||
request.Loadout.PrimaryExtraMagazines += 10;
|
||||
|
||||
//Give extra 5 more throwables
|
||||
request.Loadout.ThrowableExtra += 5;
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
private static async Task<PlayerStats> OnGetPlayerStats(ulong steamID)
|
||||
|
||||
|
||||
|
||||
private async static Task<PlayerStats> OnGetPlayerStats(ulong steamID, PlayerStats officialStats)
|
||||
{
|
||||
if (Stats == null)
|
||||
Stats = new PlayerStats();
|
||||
Stats.Progress.Rank = 155;
|
||||
Stats.Roles = Roles.Moderator;
|
||||
Stats.IsBanned = true;
|
||||
return Stats;
|
||||
officialStats.Progress.Rank = 200;
|
||||
return officialStats;
|
||||
}
|
||||
}
|
||||
class MyPlayer : Player
|
||||
{
|
||||
public int Cash;
|
||||
public bool InJail = false;
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
BIN
bin/Debug/net6.0/Database/Players/0.data
Normal file
BIN
bin/Debug/net6.0/Database/Players/0.data
Normal file
Binary file not shown.
BIN
bin/Debug/net6.0/Database/Players/76561000000045304.data
Normal file
BIN
bin/Debug/net6.0/Database/Players/76561000000045304.data
Normal file
Binary file not shown.
BIN
bin/Debug/net6.0/Database/Players/76561000000217991.data
Normal file
BIN
bin/Debug/net6.0/Database/Players/76561000000217991.data
Normal file
Binary file not shown.
BIN
bin/Debug/net6.0/Players/76561000000073947.data
Normal file
BIN
bin/Debug/net6.0/Players/76561000000073947.data
Normal file
Binary file not shown.
BIN
bin/Debug/net6.0/Players/76561000000811832.data
Normal file
BIN
bin/Debug/net6.0/Players/76561000000811832.data
Normal file
Binary file not shown.
|
@ -1 +1 @@
|
|||
6499f830a3ef23dc09747dba385a33c80022cbb9
|
||||
037b534b95ed15aafcef5ecdb4d5a0fad75c5328
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Reference in a new issue