2017-11-25 20:29:58 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2018-08-03 22:11:58 -04:00
|
|
|
|
using System.ComponentModel;
|
2017-11-25 20:29:58 -05:00
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2018-04-08 02:44:42 -04:00
|
|
|
|
namespace SharedLibraryCore.Objects
|
2017-11-29 19:35:50 -05:00
|
|
|
|
{
|
2017-11-25 20:29:58 -05:00
|
|
|
|
public class Player : Database.Models.EFClient
|
|
|
|
|
{
|
2018-06-30 21:55:16 -04:00
|
|
|
|
public enum ClientState
|
|
|
|
|
{
|
2018-08-27 18:07:54 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// represents when the client has been detected as joining
|
|
|
|
|
/// by the log file, but has not be authenticated by RCon
|
|
|
|
|
/// </summary>
|
2018-06-30 21:55:16 -04:00
|
|
|
|
Connecting,
|
2018-08-27 18:07:54 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// represents when the client has been parsed by RCon,
|
|
|
|
|
/// but has not been validated against the database
|
|
|
|
|
/// </summary>
|
|
|
|
|
Authenticated,
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// represents when the client has been authenticated by RCon
|
|
|
|
|
/// and validated by the database
|
|
|
|
|
/// </summary>
|
2018-06-30 21:55:16 -04:00
|
|
|
|
Connected,
|
2018-08-27 18:07:54 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// represents when the client is leaving (either through RCon or log file)
|
|
|
|
|
/// </summary>
|
2018-06-30 21:55:16 -04:00
|
|
|
|
Disconnecting,
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
public enum Permission
|
|
|
|
|
{
|
|
|
|
|
Banned = -1,
|
|
|
|
|
User = 0,
|
|
|
|
|
Flagged = 1,
|
|
|
|
|
Trusted = 2,
|
|
|
|
|
Moderator = 3,
|
|
|
|
|
Administrator = 4,
|
|
|
|
|
SeniorAdmin = 5,
|
|
|
|
|
Owner = 6,
|
|
|
|
|
Creator = 7,
|
2018-08-03 22:11:58 -04:00
|
|
|
|
Console = 8
|
2017-11-25 20:29:58 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Player()
|
|
|
|
|
{
|
|
|
|
|
ConnectionTime = DateTime.UtcNow;
|
2017-11-29 19:35:50 -05:00
|
|
|
|
ClientNumber = -1;
|
2018-07-04 22:09:42 -04:00
|
|
|
|
DelayedEvents = new Queue<GameEvent>();
|
2017-11-25 20:29:58 -05:00
|
|
|
|
}
|
2017-11-29 19:35:50 -05:00
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return $"{Name}::{NetworkId}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String GetLastConnection()
|
|
|
|
|
{
|
|
|
|
|
return Utilities.GetTimePassed(LastConnection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Tell(String Message)
|
|
|
|
|
{
|
2018-05-10 01:34:29 -04:00
|
|
|
|
// this is console or remote so send immediately
|
|
|
|
|
if (ClientNumber < 0)
|
|
|
|
|
{
|
|
|
|
|
await CurrentServer.Tell(Message, this);
|
|
|
|
|
}
|
2018-05-08 00:58:46 -04:00
|
|
|
|
|
2018-05-10 01:34:29 -04:00
|
|
|
|
else
|
2018-05-04 00:22:10 -04:00
|
|
|
|
{
|
2018-05-10 01:34:29 -04:00
|
|
|
|
var e = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Message = Message,
|
|
|
|
|
Target = this,
|
|
|
|
|
Owner = CurrentServer,
|
|
|
|
|
Type = GameEvent.EventType.Tell,
|
|
|
|
|
Data = Message
|
|
|
|
|
};
|
2018-05-04 00:22:10 -04:00
|
|
|
|
|
2018-05-10 01:34:29 -04:00
|
|
|
|
CurrentServer.Manager.GetEventHandler().AddEvent(e);
|
|
|
|
|
}
|
2017-11-25 20:29:58 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Kick(String Message, Player Sender)
|
|
|
|
|
{
|
|
|
|
|
await CurrentServer.Kick(Message, this, Sender);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task TempBan(String Message, TimeSpan Length, Player Sender)
|
|
|
|
|
{
|
|
|
|
|
await CurrentServer.TempBan(Message, Length, this, Sender);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Warn(String Message, Player Sender)
|
|
|
|
|
{
|
|
|
|
|
await CurrentServer.Warn(Message, this, Sender);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Ban(String Message, Player Sender)
|
|
|
|
|
{
|
|
|
|
|
await CurrentServer.Ban(Message, this, Sender);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NotMapped]
|
2017-11-29 19:35:50 -05:00
|
|
|
|
public int ClientNumber { get; set; }
|
2017-11-25 20:29:58 -05:00
|
|
|
|
[NotMapped]
|
|
|
|
|
public int Ping { get; set; }
|
|
|
|
|
[NotMapped]
|
|
|
|
|
public int Warnings { get; set; }
|
|
|
|
|
[NotMapped]
|
|
|
|
|
public DateTime ConnectionTime { get; set; }
|
|
|
|
|
[NotMapped]
|
|
|
|
|
public Server CurrentServer { get; set; }
|
2018-02-09 02:21:25 -05:00
|
|
|
|
[NotMapped]
|
|
|
|
|
public int Score { get; set; }
|
2018-02-14 14:01:26 -05:00
|
|
|
|
[NotMapped]
|
2018-04-15 21:27:43 -04:00
|
|
|
|
public bool IsBot { get; set; }
|
2018-02-10 23:33:42 -05:00
|
|
|
|
private int _ipaddress;
|
|
|
|
|
public override int IPAddress
|
2017-11-29 19:35:50 -05:00
|
|
|
|
{
|
|
|
|
|
get { return _ipaddress; }
|
|
|
|
|
set { _ipaddress = value; }
|
|
|
|
|
}
|
|
|
|
|
private string _name;
|
|
|
|
|
public override string Name
|
|
|
|
|
{
|
|
|
|
|
get { return _name; }
|
2018-08-03 22:11:58 -04:00
|
|
|
|
set { _name = value; }
|
2017-11-29 19:35:50 -05:00
|
|
|
|
}
|
2018-06-30 21:55:16 -04:00
|
|
|
|
[NotMapped]
|
|
|
|
|
public ClientState State { get; set; }
|
2018-07-04 22:09:42 -04:00
|
|
|
|
[NotMapped]
|
|
|
|
|
public Queue<GameEvent> DelayedEvents { get; set; }
|
2018-08-03 22:11:58 -04:00
|
|
|
|
[NotMapped]
|
|
|
|
|
// this is kinda dirty, but I need localizable level names
|
|
|
|
|
public ClientPermission ClientPermission => new ClientPermission()
|
|
|
|
|
{
|
|
|
|
|
Level = Level,
|
|
|
|
|
Name = Utilities.CurrentLocalization
|
|
|
|
|
.LocalizationIndex[$"GLOBAL_PERMISSION_{Level.ToString().ToUpper()}"]
|
|
|
|
|
};
|
2018-02-10 23:33:42 -05:00
|
|
|
|
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
|
|
|
|
return ((Player)obj).NetworkId == NetworkId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
|
|
|
|
return NetworkId.GetHashCode();
|
|
|
|
|
}
|
2017-11-25 20:29:58 -05:00
|
|
|
|
}
|
|
|
|
|
}
|