Merge branch 'general-devel' into fix-build
This commit is contained in:
commit
4f3fa06028
9 changed files with 134 additions and 20 deletions
|
|
@ -3872,7 +3872,7 @@ namespace TShockAPI
|
|||
if (!Main.dayTime)
|
||||
time += 15.0;
|
||||
time = time % 24.0;
|
||||
args.Player.SendInfoMessage("The current time is {0}:{1:D2}.", (int)Math.Floor(time), (int)Math.Round((time % 1.0) * 60.0));
|
||||
args.Player.SendInfoMessage("The current time is {0}:{1:D2}.", (int)Math.Floor(time), (int)Math.Floor((time % 1.0) * 60.0));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -363,7 +363,7 @@ namespace TShockAPI.DB
|
|||
}
|
||||
|
||||
/// <summary>A database user.</summary>
|
||||
public class User
|
||||
public class User : IEquatable<User>
|
||||
{
|
||||
/// <summary>The database ID of the user.</summary>
|
||||
public int ID { get; set; }
|
||||
|
|
@ -581,6 +581,67 @@ namespace TShockAPI.DB
|
|||
return HashPassword(Encoding.UTF8.GetBytes(password));
|
||||
}
|
||||
|
||||
#region IEquatable
|
||||
|
||||
/// <summary>Indicates whether the current <see cref="User"/> is equal to another <see cref="User"/>.</summary>
|
||||
/// <returns>true if the <see cref="User"/> is equal to the <paramref name="other" /> parameter; otherwise, false.</returns>
|
||||
/// <param name="other">An <see cref="User"/> to compare with this <see cref="User"/>.</param>
|
||||
public bool Equals(User other)
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
return ID == other.ID && string.Equals(Name, other.Name);
|
||||
}
|
||||
|
||||
/// <summary>Indicates whether the current <see cref="User"/> is equal to another object.</summary>
|
||||
/// <returns>true if the <see cref="User"/> is equal to the <paramref name="obj" /> parameter; otherwise, false.</returns>
|
||||
/// <param name="obj">An <see cref="object"/> to compare with this <see cref="User"/>.</param>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj)) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
if (obj.GetType() != this.GetType()) return false;
|
||||
return Equals((User)obj);
|
||||
}
|
||||
|
||||
/// <summary>Serves as the hash function. </summary>
|
||||
/// <returns>A hash code for the current <see cref="User"/>.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return (ID * 397) ^ (Name != null ? Name.GetHashCode() : 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares equality of two <see cref="User"/> objects.
|
||||
/// </summary>
|
||||
/// <param name="left">Left hand of the comparison.</param>
|
||||
/// <param name="right">Right hand of the comparison.</param>
|
||||
/// <returns>true if the <see cref="User"/> objects are equal; otherwise, false.</returns>
|
||||
public static bool operator ==(User left, User right)
|
||||
{
|
||||
return Equals(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares equality of two <see cref="User"/> objects.
|
||||
/// </summary>
|
||||
/// <param name="left">Left hand of the comparison.</param>
|
||||
/// <param name="right">Right hand of the comparison.</param>
|
||||
/// <returns>true if the <see cref="User"/> objects aren't equal; otherwise, false.</returns>
|
||||
public static bool operator !=(User left, User right)
|
||||
{
|
||||
return !Equals(left, right);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>UserManagerException - An exception generated by the user manager.</summary>
|
||||
|
|
@ -643,4 +704,4 @@ namespace TShockAPI.DB
|
|||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -895,14 +895,14 @@ namespace TShockAPI
|
|||
/// <summary>
|
||||
/// Time the buff lasts
|
||||
/// </summary>
|
||||
public short Time { get; set; }
|
||||
public int Time { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// PlayerBuff - Called when a player is buffed
|
||||
/// </summary>
|
||||
public static HandlerList<PlayerBuffEventArgs> PlayerBuff;
|
||||
|
||||
private static bool OnPlayerBuff(byte id, byte type, short time)
|
||||
private static bool OnPlayerBuff(byte id, byte type, int time)
|
||||
{
|
||||
if (PlayerBuff == null)
|
||||
return false;
|
||||
|
|
@ -911,7 +911,7 @@ namespace TShockAPI
|
|||
{
|
||||
ID = id,
|
||||
Type = type,
|
||||
Time = time,
|
||||
Time = time
|
||||
};
|
||||
PlayerBuff.Invoke(null, args);
|
||||
return args.Handled;
|
||||
|
|
@ -3425,7 +3425,7 @@ namespace TShockAPI
|
|||
{
|
||||
var id = args.Data.ReadInt8();
|
||||
var type = args.Data.ReadInt8();
|
||||
var time = args.Data.ReadInt16();
|
||||
var time = args.Data.ReadInt32();
|
||||
|
||||
if (OnPlayerBuff(id, type, time))
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -12,23 +12,23 @@ namespace TShockAPI.Sockets
|
|||
{
|
||||
public class LinuxTcpSocket : ISocket
|
||||
{
|
||||
private byte[] _packetBuffer = new byte[1024];
|
||||
public byte[] _packetBuffer = new byte[1024];
|
||||
|
||||
private int _packetBufferLength;
|
||||
public int _packetBufferLength;
|
||||
|
||||
private List<object> _callbackBuffer = new List<object>();
|
||||
public List<object> _callbackBuffer = new List<object>();
|
||||
|
||||
private int _messagesInQueue;
|
||||
public int _messagesInQueue;
|
||||
|
||||
private TcpClient _connection;
|
||||
public TcpClient _connection;
|
||||
|
||||
private TcpListener _listener;
|
||||
public TcpListener _listener;
|
||||
|
||||
private SocketConnectionAccepted _listenerCallback;
|
||||
public SocketConnectionAccepted _listenerCallback;
|
||||
|
||||
private RemoteAddress _remoteAddress;
|
||||
public RemoteAddress _remoteAddress;
|
||||
|
||||
private bool _isListening;
|
||||
public bool _isListening;
|
||||
|
||||
public int MessagesInQueue
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@ using System.Runtime.InteropServices;
|
|||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using TShockAPI.Extensions;
|
||||
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace TShockAPI
|
||||
{
|
||||
|
|
@ -177,7 +178,50 @@ namespace TShockAPI
|
|||
return plugins;
|
||||
}
|
||||
|
||||
private long GetTotalSystemRam(bool isMono)
|
||||
/// <summary>
|
||||
/// Returns the amount of free RAM, in megabytes.
|
||||
/// </summary>
|
||||
/// <param name="mono">Whether or not this program is being executed in a Mono runtime</param>
|
||||
/// <returns>Free RAM memory amount, in megabytes</returns>
|
||||
public long GetFreeSystemRam(bool mono)
|
||||
{
|
||||
if (mono)
|
||||
{
|
||||
//Temporary in case mono won't work
|
||||
if (File.Exists("/proc/meminfo"))
|
||||
{
|
||||
var l = File.ReadAllLines("/proc/meminfo");
|
||||
foreach (string s in l)
|
||||
{
|
||||
if (s.StartsWith("MemFree:"))
|
||||
{
|
||||
var m = Regex.Match(s, "MemFree:(\\s*)(\\d*) kB");
|
||||
if (m.Success)
|
||||
{
|
||||
long val;
|
||||
if (long.TryParse(m.Groups[2].Value, out val))
|
||||
{
|
||||
return val / 1024;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
var pc = new PerformanceCounter("Memory", "Available MBytes");
|
||||
return pc.RawValue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the total amount of installed RAM, in gigabytes.
|
||||
/// </summary>
|
||||
/// <param name="isMono">Whether or not this program is being executed in a Mono runtime</param>
|
||||
/// <returns>Total RAM memory amount, in gigabytes</returns>
|
||||
public long GetTotalSystemRam(bool isMono)
|
||||
{
|
||||
if (totalMem != 0)
|
||||
{
|
||||
|
|
@ -267,4 +311,4 @@ namespace TShockAPI
|
|||
/// </summary>
|
||||
public bool mono;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -329,6 +329,12 @@ namespace TShockAPI
|
|||
|
||||
Log.ConsoleInfo("TShock {0} ({1}) now running.", Version, VersionCodename);
|
||||
|
||||
var systemRam = StatTracker.GetFreeSystemRam(ServerApi.RunningMono);
|
||||
if (systemRam > -1 && systemRam < 2048)
|
||||
{
|
||||
Log.ConsoleError("This machine has less than 2 gigabytes of RAM free. Be advised that it might not be enough to run TShock.");
|
||||
}
|
||||
|
||||
ServerApi.Hooks.GamePostInitialize.Register(this, OnPostInit);
|
||||
ServerApi.Hooks.GameUpdate.Register(this, OnUpdate);
|
||||
ServerApi.Hooks.GameHardmodeTileUpdate.Register(this, OnHardUpdate);
|
||||
|
|
|
|||
|
|
@ -465,7 +465,7 @@ namespace TShockAPI
|
|||
/// <returns>description</returns>
|
||||
public string GetBuffDescription(int id)
|
||||
{
|
||||
return (id > 0 && id < Main.maxBuffTypes) ? Lang.GetBuffName(id) : "null";
|
||||
return (id > 0 && id < Main.maxBuffTypes) ? Lang.GetBuffDescription(id) : "null";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue