stuff
This commit is contained in:
@ -1,11 +1,52 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Xml.Serialization;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Lidgren.Network;
|
||||
|
||||
namespace CoopServer
|
||||
{
|
||||
class Util
|
||||
{
|
||||
public static NetConnection GetConnectionByUsername(string username)
|
||||
{
|
||||
long? userID = GetIdByUsername(username);
|
||||
if (userID == null || !Server.MainNetServer.Connections.Any(x => x.RemoteUniqueIdentifier == userID))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return Server.MainNetServer.Connections.First(x => x.RemoteUniqueIdentifier == userID);
|
||||
}
|
||||
|
||||
public static long? GetIdByUsername(string username)
|
||||
{
|
||||
return Server.Players.Any(x => x.Value.Username == username) ? Server.Players.First(x => x.Value.Username == username).Key : null;
|
||||
}
|
||||
|
||||
// Return a list of all connections but not the local connection
|
||||
public static List<NetConnection> FilterAllLocal(NetConnection local)
|
||||
{
|
||||
return new(Server.MainNetServer.Connections.Where(e => e != local));
|
||||
}
|
||||
public static List<NetConnection> FilterAllLocal(long local)
|
||||
{
|
||||
return new(Server.MainNetServer.Connections.Where(e => e.RemoteUniqueIdentifier != local));
|
||||
}
|
||||
|
||||
// Return a list of players within range of ...
|
||||
public static List<NetConnection> GetAllInRange(LVector3 position, float range)
|
||||
{
|
||||
return new(Server.MainNetServer.Connections.FindAll(e => Server.Players[e.RemoteUniqueIdentifier].Ped.IsInRangeOf(position, range)));
|
||||
}
|
||||
// Return a list of players within range of ... but not the local one
|
||||
public static List<NetConnection> GetAllInRange(LVector3 position, float range, NetConnection local)
|
||||
{
|
||||
return new(Server.MainNetServer.Connections.Where(e => e != local && Server.Players[e.RemoteUniqueIdentifier].Ped.IsInRangeOf(position, range)));
|
||||
}
|
||||
|
||||
public static T Read<T>(string file) where T : new()
|
||||
{
|
||||
XmlSerializer ser = new(typeof(T));
|
||||
|
Reference in New Issue
Block a user