diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 8ef6e0a..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,59 +0,0 @@ -image: mcr.microsoft.com/dotnet/sdk:6.0 - -variables: - GIT_SUBMODULE_STRATEGY: normal - -stages: - - build_server - - plugins - -before_script: - # https://gitlab.com/TheIndra55/lidgren-network-gen3 - - "dotnet nuget add source https://gitlab.com/api/v4/projects/20574571/packages/nuget/index.json -n gitlab" - -build_windows: - stage: build_server - # run on Windows since while crossbuilding on Linux, apphost customization doesn't work - tags: - - group-windows - - windows - script: - - cd gtaserver.core - - dotnet publish -r win10-x64 -c Release -o publish/windows-Release -p:PublishSingleFile=true - artifacts: - paths: - - "gtaserver.core/publish/windows-Release" - -build_linux: - stage: build_server - script: - - cd gtaserver.core - - dotnet publish -r ubuntu-x64 -c Release -o publish/linux-Release - artifacts: - paths: - - "gtaserver.core/publish/linux-Release" - -build_linux_arm: - stage: build_server - when: manual - script: - - cd gtaserver.core - - dotnet publish -r linux-arm -c Release -o publish/arm-Release - artifacts: - paths: - - "gtaserver.core/publish/arm-Release" - -build_plugins: - stage: plugins - script: - - cd Race - - dotnet publish -c Release -o publish - - cd ../DiscordBot # hm - - dotnet publish -c Release -o publish - artifacts: - paths: - - "Race/publish/race.dll" - - "Race/publish/race.pdb" - - "Race/publish/Maps" - - "DiscordBot/publish/DiscordBot.dll" - - "DiscordBot/publish/DiscordBot.pdb" diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index a8e9ed5..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "NativeUI"] - path = NativeUI - url = https://github.com/Guad/NativeUI.git \ No newline at end of file diff --git a/AdminTools/AdminSettings.cs b/AdminTools/AdminSettings.cs deleted file mode 100644 index 4a2512d..0000000 --- a/AdminTools/AdminSettings.cs +++ /dev/null @@ -1,57 +0,0 @@ -namespace AdminTools -{ - public class AdminSettings - { - public bool Debug { get; set; } - public bool KickOnDefaultNickName { get; set; } - public bool KickOnNameDifference { get; set; } - public bool SocialClubOnly { get; set; } - public string MOTD { get; set; } - public int MaxPing { get; set; } - public bool AntiClones { get; set; } - public bool KickOnDifferentScript { get; set; } - public GTAServer.ScriptVersion NeededScriptVersion { get; set; } - public bool KickOnOutdatedGame { get; set; } - public int MinGameVersion { get; set; } - public bool ColoredNicknames { get; set; } - public bool OnlyAsciiNickName { get; set; } - public bool OnlyAsciiUserName { get; set; } - public bool LimitNickNames { get; set; } - public string CountryRestriction { get; set; } - public string ProtectedNickname { get; set; } - public string ProtectedNicknameIP { get; set; } - - /*public bool WhiteListEnabled { get; set; } -public string[] WhiteList { get; set; } -public bool BlackListEnabled { get; set; } -public string[] BlackList { get; set; }*/ - - public AdminSettings() - { - Debug = false; - KickOnDefaultNickName = true; - KickOnNameDifference = false; - SocialClubOnly = false; - MOTD = "Welcome to this GTA 5 Co-op Server! Max Ping: 250"; - MaxPing = 250; - AntiClones = true; - KickOnDifferentScript = true; - NeededScriptVersion = GTAServer.ScriptVersion.VERSION_0_9_3; - KickOnOutdatedGame = false; - MinGameVersion = 25; - ColoredNicknames = true; - OnlyAsciiNickName = true; - OnlyAsciiUserName = false; - LimitNickNames = true; - CountryRestriction = ""; - ProtectedNickname = ""; - ProtectedNicknameIP = ""; - /*WhiteListEnabled = false; - WhiteList[0] = "Bluscream"; - WhiteList[1] = "Redscream"; - BlackListEnabled = false; - BlackList[0] = "Faggot"; - BlackList[1] = "Bastard";*/ - } - } -} \ No newline at end of file diff --git a/AdminTools/AdminTools.csproj b/AdminTools/AdminTools.csproj deleted file mode 100644 index 124ecd5..0000000 --- a/AdminTools/AdminTools.csproj +++ /dev/null @@ -1,99 +0,0 @@ - - - - - Debug - AnyCPU - {158CCEB2-E6EC-457B-BA61-E448BD6B0F40} - Library - Properties - AdminTools - AdminTools - v4.5.2 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - ..\..\..\..\SERVERS\GameServer\Grand Theft Auto\GTA V\filterscripts\ - TRACE - prompt - 4 - - - false - - - - - - - - ..\packages\Colorful.Console.1.2.9\lib\net452\Colorful.Console.dll - - - ..\packages\Lidgren.Network.1.0.2\lib\net451\Lidgren.Network.dll - True - - - ..\packages\MaxMind.Db.2.4.0\lib\net45\MaxMind.Db.dll - - - ..\packages\MaxMind.GeoIP2.3.0.0\lib\net45\MaxMind.GeoIP2.dll - - - ..\packages\Newtonsoft.Json.12.0.1-beta1\lib\net45\Newtonsoft.Json.dll - - - ..\packages\protobuf-net.3.0.0-alpha.3\lib\net40\protobuf-net.dll - - - - - - - - - - - - - - - - - - - - - - - Designer - - - - - - {559ee224-bf7b-49d8-9cee-11e6ba71fe4e} - GTAServer - - - - - \ No newline at end of file diff --git a/AdminTools/AdminTools.xml b/AdminTools/AdminTools.xml deleted file mode 100644 index 42c3c75..0000000 --- a/AdminTools/AdminTools.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - false - true - false - false - Welcome to this GTA 5 Co-op Server! Max Ping: 250 - 250 - true - true - VERSION_0_9_2 - false - 25 - true - true - false - true - \ No newline at end of file diff --git a/AdminTools/MainFilterscript.cs b/AdminTools/MainFilterscript.cs deleted file mode 100644 index d20b63c..0000000 --- a/AdminTools/MainFilterscript.cs +++ /dev/null @@ -1,1090 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Security.Cryptography; -using System.Text; -using System.Threading; -//using System.Diagnostics; -using System.Text.RegularExpressions; -using System.Xml.Serialization; -using GTAServer; -//using Lidgren.Network; -using System.Drawing; -using System.Globalization; - -namespace AdminTools -{ - public class Lists - { - internal static UserList Accounts = new UserList(); - internal static Banlist Banned = new Banlist(); - internal static List AuthenticatedUsers = new List(); - } - [Serializable] - public class AdminToolsServerScript : ServerScript - { - public static GameServer ServerInstance; - static void LogToConsole(int flag, bool debug, string module, string message) - { - if (module == null || module.Equals("")) { module = "SERVER"; } - if (flag == 1) - { - Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("[" + DateTime.Now + "] (DEBUG) " + module.ToUpper() + ": " + message); - } - else if (flag == 2) - { - Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("[" + DateTime.Now + "] (SUCCESS) " + module.ToUpper() + ": " + message); - } - else if (flag == 3) - { - Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("[" + DateTime.Now + "] (WARNING) " + module.ToUpper() + ": " + message); - } - else if (flag == 4) - { - Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("[" + DateTime.Now + "] (ERROR) " + module.ToUpper() + ": " + message); - } - else - { - Console.WriteLine("[" + DateTime.Now + "] " + module.ToUpper() + ": " + message); - } - Console.ForegroundColor = ConsoleColor.White; - } - public static string Location => AppDomain.CurrentDomain.BaseDirectory; - public override string Name => "Server Administration Tools"; - public int Version => 1; - - public bool Afk { get; private set; } - public AdminSettings Settings = ReadSettings(Location + "/filterscripts/AdminTools.xml"); - public int ServerWeather; - public TimeSpan ServerTime; - - private DateTime _lastCountdown; - - private readonly string[] _weatherNames = new[] - { - "CLEAR", - "EXTRASUNNY", - "CLOUDS", - "OVERCAST", - "RAIN", - "CLEARING", - "THUNDER", - "SMOG", - "FOGGY", - "XMAS", - "SNOWLIGHT", - "BLIZZARD", - }; - - public override void Start(GameServer serverInstance) - { - ServerInstance = serverInstance; - //Console.WriteLine("\x1b[31mRed\x1b[0;37m"); //https://en.wikipedia.org/wiki/ANSI_escape_code - LoadAccounts(Location + "Accounts.xml"); - LogToConsole(2, false, null, "Accounts loaded."); - LoadBanlist(Location + "Banlist.xml"); - LogToConsole(2, false, null, "Bans loaded."); - - ServerWeather = 0; - ServerTime = new TimeSpan(12, 0, 0); - } - public class MasterServerList - { - public List list { get; set; } - } - public int ReadableVersion(ScriptVersion version) - { - var Version = version.ToString(); - Version = Regex.Replace(Version, "VERSION_", "", RegexOptions.IgnoreCase); - Version = Regex.Replace(Version, "_", "", RegexOptions.IgnoreCase); - return Int32.Parse(Version); - } - public override void OnTick() - { - if ((DateTime.Now.ToString("ss:fff").Equals("20:001")) || (DateTime.Now.ToString("ss:fff").Equals("40:001"))) - { - if (Settings.MaxPing > 0 && ServerInstance.Clients.Count > 0) - { - for (var i = 0; i < ServerInstance.Clients.Count; i++) - { - //Console.WriteLine(string.Format("{0} Current Ping: \"{1}\" / Max Ping: \"{2}\"",ServerInstance.Clients[i].DisplayName, Math.Round(ServerInstance.Clients[i].Latency * 1000, MidpointRounding.AwayFromZero).ToString(), Settings.MaxPing)); - if (Math.Round(ServerInstance.Clients[i].Latency * 1000, MidpointRounding.AwayFromZero) > Settings.MaxPing) - { - //ServerInstance.SendChatMessageToAll("SERVER", string.Format("Kicking {0} for Ping {1} too high! Max: {2}", ServerInstance.Clients[i].DisplayName.ToString(), Math.Round(ServerInstance.Clients[i].Latency * 1000, MidpointRounding.AwayFromZero).ToString(), Settings.MaxPing.ToString())); - ServerInstance.KickPlayer(ServerInstance.Clients[i], - $"Ping too high! {Math.Round(ServerInstance.Clients[i].Latency * 1000, MidpointRounding.AwayFromZero).ToString()}/{Settings.MaxPing.ToString()}ms"); - } - } - - } - } - } - public override void OnIncomingConnection(Client player) - { - if (!Settings.ColoredNicknames) - { - player.DisplayName = Regex.Replace(player.DisplayName, "~.~", "", RegexOptions.IgnoreCase); - } - if (player.DisplayName.ToLower().Contains("server") || player.DisplayName.ToLower().Contains("owner") || player.DisplayName.ToLower().Contains("admin") || player.DisplayName.ToLower().Contains("moderator") || player.DisplayName.ToLower().Contains("vip") || player.DisplayName.ToLower().Contains("user") || player.DisplayName.ToLower().Contains("guest")) - { - ServerInstance.SendChatMessageToAll("SERVER", - $"Kicking {player.DisplayName.ToString()} for impersonating."); - ServerInstance.DenyPlayer(player, "Change your nickname to a proper one!", true, null, 30); return; - } - if (Settings.KickOnDefaultNickName) - { - if (player.DisplayName.ToLower().StartsWith("rld!") || player.DisplayName.ToLower().StartsWith("player") || player.DisplayName.ToLower().StartsWith("nosteam") || player.DisplayName.ToLower().StartsWith("3dmgame1") || player.DisplayName.StartsWith("3dm") || player.DisplayName.ToLower().StartsWith("your name")) - { - //ServerInstance.SendChatMessageToAll("SERVER", string.Format("Kicking {0} for default nickname.", player.DisplayName.ToString())); - ServerInstance.DenyPlayer(player, "~r~Change your nickname!~w~ (~h~F9~h~->~h~Settings~h~->~h~Nickname~h~)", true, null, 10); return; - } - } - if (Settings.KickOnDifferentScript == true) - { - //Console.WriteLine(string.Format("[Script Version Check] Got: {0} | Expected: {1}", player.RemoteScriptVersion.ToString(), Settings.NeededScriptVersion.ToString())); - //Console.WriteLine((ScriptVersion)player.RemoteScriptVersion); - //Console.WriteLine((ScriptVersion)Settings.NeededScriptVersion); - //if (readableVersion(player.RemoteScriptVersion) < Int32.Parse(Settings.MinScriptVersion)) - if ((ScriptVersion)player.RemoteScriptVersion != (ScriptVersion)Settings.NeededScriptVersion) - { - //ServerInstance.SendChatMessageToAll("SERVER", string.Format("Kicking {0} for outdated mod.", player.DisplayName.ToString())); - string version = Regex.Replace(Settings.NeededScriptVersion.ToString(), "VERSION_", "", RegexOptions.IgnoreCase); - version = Regex.Replace(version, "_", ".", RegexOptions.IgnoreCase); - ServerInstance.DenyPlayer(player, $"You need GTACoop Mod v~g~{version}~w~ to play on this server.", true, null, 120); return; - } - } - if (Settings.KickOnOutdatedGame) - { - //Console.WriteLine(string.Format("[Game Version Check] Got: {0} | Expected: {1}", player.GameVersion.ToString(), Settings.MinGameVersion.ToString())); - if (player.GameVersion < Settings.MinGameVersion) - { - ServerInstance.SendChatMessageToAll("SERVER", - $"Kicking {player.DisplayName.ToString()} for outdated game."); - ServerInstance.DenyPlayer(player, "Update your GTA V to the newest version!", false, null, 120); return; - } - } - if (Settings.SocialClubOnly) - { - // Console.WriteLine(player.Name); - if (player.Name.ToString() == "RLD!" || player.Name.ToString() == "nosTEAM" || player.Name.ToString() == "Player" || player.Name.ToString() == "3dmgame1") - { - ServerInstance.SendChatMessageToAll("SERVER", - $"Kicking {player.DisplayName.ToString()} for cracked game."); - ServerInstance.DenyPlayer(player, "Buy the game and sign in through social club!"); return; - } - } - if (Settings.KickOnNameDifference) - { - if (!player.DisplayName.Equals(player.Name)) - { - //ServerInstance.SendChatMessageToAll("SERVER", string.Format("Kicking {0} for nickname differs from account name.", player.DisplayName.ToString())); - ServerInstance.DenyPlayer(player, $"Change your nickname to {player.Name}", true, null, 15); return; - } - } - if (player.IsBanned() || player.IsIPBanned()) - { - ServerInstance.SendChatMessageToAll("SERVER", - $"{player.DisplayName.ToString()} is banned for {player.GetBan().Reason}"); - ServerInstance.DenyPlayer(player, "You are banned: " + player.GetBan().Reason, false, null, 120); return; - } - if (Settings.OnlyAsciiNickName) - { - if (Encoding.UTF8.GetByteCount(player.DisplayName) != player.DisplayName.Length) - { - //ServerInstance.SendChatMessageToAll("SERVER", string.Format("{0} was kicked for non-ascii chars in his nickname.", player.DisplayName.ToString())); - ServerInstance.DenyPlayer(player, "Remove all non-ascii characters from your nickname.", true, null, 15); return; - } - } - if (Settings.OnlyAsciiUserName) - { - if (Encoding.UTF8.GetByteCount(player.Name) != player.Name.Length) - { - //ServerInstance.SendChatMessageToAll("SERVER", string.Format("{0} was kicked for non-ascii chars in his username.", player.DisplayName.ToString())); - ServerInstance.DenyPlayer(player, "Remove all non-ascii characters from your Social Club username.", true, null, 120); return; - } - } - if (Settings.LimitNickNames) - { - if (player.DisplayName.Length < 3 || player.DisplayName.Length > 100 || Regex.Replace(player.DisplayName, "~.~", "", RegexOptions.IgnoreCase).Length > 20) - { - ServerInstance.DenyPlayer(player, "Your nickname has to be between 3 and 20 chars long. (Max 100 with colors)", true, null, 20); return; - } - } - if (Settings.AntiClones) - { - var count = 0; - foreach (var t in ServerInstance.Clients) - { - if (player.NetConnection.RemoteEndPoint.Address.Equals(t.NetConnection.RemoteEndPoint.Address) && player.DisplayName.Contains(t.DisplayName)) - { - var last = player; count++; - //Console.WriteLine("Player: "+ player.DisplayName+" | Client: "+ ServerInstance.Clients[i].DisplayName); - if (count <= 1) continue; - ServerInstance.KickPlayer(last, "Clone detected!"); - player.DisplayName = last.DisplayName; last = null; return; - //ServerInstance.SendChatMessageToAll("SERVER", string.Format("Kicking {0} for clone detected!", ServerInstance.Clients[i].DisplayName.ToString())); - } - } - } - if (player.DisplayName.Trim().StartsWith("[") || player.DisplayName.Trim().EndsWith(")")) - { - ServerInstance.SendChatMessageToAll("SERVER", - $"Kicking {player.DisplayName.ToString()} for impersonating."); - ServerInstance.DenyPlayer(player, "Remove the () and [] from your nickname.", false, null, 15); return; - } - try - { - if (!string.IsNullOrEmpty(Settings.CountryRestriction) && !string.IsNullOrEmpty(player.geoIP.Country.Name)) - { - if (!Settings.CountryRestriction.Equals(player.geoIP.Country.Name)) - { - ServerInstance.DenyPlayer(player, "Sorry, but only players from " + Settings.CountryRestriction + " allowed here.", false, null); return; - } - } - } - catch { } - if (!string.IsNullOrWhiteSpace(Settings.ProtectedNickname) && !string.IsNullOrWhiteSpace(Settings.ProtectedNicknameIP)) - { - if (player.DisplayName.Contains(Settings.ProtectedNickname) && !player.NetConnection.RemoteEndPoint.Address.ToString().Equals(Settings.ProtectedNicknameIP)) - { - ServerInstance.DenyPlayer(player, "This nickname is protected! You can't use it.", false, null); return; - } - } - } - public override bool OnPlayerConnect(Client player) - { - //try - //{ - // Console.Write("Nickname: " + player.DisplayName.ToString() + " | "); - // Console.Write("Realname: " + player.Name.ToString() + " | "); - // Console.Write("IP: " + player.NetConnection.RemoteEndPoint.Address.ToString() + " | "); - // Console.Write("Game Version: " + player.GameVersion.ToString() + " | "); - // Console.Write("Script Version: " + player.RemoteScriptVersion.ToString() + "\n"); - //} - //catch (Exception e) { } - //string response = String.Empty; - //try - //{ - // using (var webClient = new System.Net.WebClient()) - // { - // response = webClient.DownloadString("http://ip-api.com/json/"+player.NetConnection.RemoteEndPoint.Address); - // } - //} - //catch (Exception e) - //{ - // Console.WriteLine("Could not contact IP API."); - //} - //if (!string.IsNullOrWhiteSpace(response)) { - // IPInfo dejson = JsonConvert.DeserializeObject(response); - // if (dejson.list != null) - // { - // if (dejson.status.Equals("success")) - // { - // string country = dejson.countryCode; - // Console.WriteLine("Country Code: "+country); - // }else - // { - // Console.WriteLine("Could not query IP infos from API."); - // } - // } - - //} - - //ServerInstance.SendChatMessageToPlayer(player, "INFO", "Current Server Flags: "); - - ServerInstance.SendChatMessageToPlayer(player, "SERVER", Settings.MOTD); - //ServerInstance.SendChatMessageToPlayer(player, "SERVER", string.Format("Welcome to {0}", GTAServer.ServerSettings)); - //var settings = ReadSettings(Program.Location + "Settings.xml"); - - if (player.GetAccount(false) == null) - { - ServerInstance.SendChatMessageToPlayer(player, "SERVER", "You can register an account using /register [password]"); - } - else - { - ServerInstance.SendChatMessageToPlayer(player, "SERVER", "Please authenticate to your account using /login [password]"); - } - - ServerInstance.SendNativeCallToPlayer(player, 0x29B487C359E19889, _weatherNames[ServerWeather]); - - ServerInstance.SendNativeCallToPlayer(player, 0x47C3B5848C3E45D8, ServerTime.Hours, ServerTime.Minutes, ServerTime.Seconds); - ServerInstance.SendNativeCallToPlayer(player, 0x4055E40BD2DBEC1D, true); - return true; - } - - public override ChatMessage OnChatMessage(ChatMessage message) - { - try - { - Account account = message.Sender.GetAccount(); - if (message.Message.ToLower().Equals("/help")) - { - if (account != null) - { - switch ((int)account.Level) - { - case 0: - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Available commands: /help, /register, /q"); message.Supress = true; return message; - case 1: - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Available commands: /help, /logout, /q, /afk, /back"); message.Supress = true; return message; - case 2: - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Available commands: /help, /logout, /q, /afk, /back"); message.Supress = true; return message; - case 3: - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Available commands: /help, /logout, /q, /afk, /back, /kick, /ban, /tp"); message.Supress = true; return message; - case 4: - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Available commands: /help, /logout, /q, /afk, /back, /kick, /ban, /tp, /godmode, /info, /kill, /weather, /time, /nick"); message.Supress = true; return message; - case 5: - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Available commands: /help, /logout, /q, /afk, /back, /kick, /ban, /tp, /godmode, /info, /kill, /weather, /time, /nick, /stop, /l"); message.Supress = true; return message; - default: - break; - } - } - else - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Available commands: /help, /register, /q"); message.Supress = true; return message; - } - } - if (message.Message.ToLower().Equals("/q")) - { - ServerInstance.KickPlayer(message.Sender, "You left the server."); - } - if (message.Message.ToLower().Equals("/afk")) - { - if (account == null || (int)account.Level < 1) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Register to use this command."); message.Supress = true; return message; - } - if (message.Sender.afk) { ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "You are already AFK."); message.Supress = true; return message; } - message.Sender.afk = true; - ServerInstance.SendChatMessageToAll(message.Sender.DisplayName, "has gone AFK."); message.Supress = true; return message; - } - if (message.Message.ToLower().Equals("/back")) - { - if (account == null || (int)account.Level < 1) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Register to use this command."); message.Supress = true; return message; - } - if (!message.Sender.afk) { ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "You are not AFK."); message.Supress = true; return message; } - ServerInstance.SendChatMessageToAll(message.Sender.DisplayName, "is now back."); message.Sender.afk = false; message.Supress = true; return message; - - } - if (message.Message.ToLower().Equals("/l")) - { - if (account == null || (int)account.Level < 5) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Insufficent privileges."); message.Supress = true; return message; - } - for (var i = 0; i < ServerInstance.Clients.Count; i++) - { - try - { - Client target = ServerInstance.Clients[i]; - Console.WriteLine($"Nickname: {target.DisplayName.ToString()} | " + - $"Realname: {target.Name.ToString()} |" + - $"Ping: {Math.Round(target.Latency * 1000, MidpointRounding.AwayFromZero).ToString(CultureInfo.InvariantCulture)}ms | " + - $"IP: {target.NetConnection.RemoteEndPoint.Address.ToString()} | " + - $"Game Version: {target.GameVersion.ToString()} | " + - $"Script Version: {target.RemoteScriptVersion.ToString()} | " + - $"Vehicle Health: {target.VehicleHealth.ToString()} | " + - $"Last Position: {target.LastKnownPosition.ToString()} | "); - } - catch - { - // ignored - } - } - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Printed playerlist to console."); message.Supress = true; return message; - } - if (message.Message.ToLower().StartsWith("/info")) - { - if (account == null || (int)account.Level < 4) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Insufficent privileges."); message.Supress = true; return message; - } - var args = message.Message.Split(); - if (args.Length <= 1) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "USAGE", "/info [Player Name]"); message.Supress = true; return message; - } - Client target = null; - lock (ServerInstance.Clients) target = ServerInstance.Clients.FirstOrDefault(c => c.DisplayName.ToLower().StartsWith(args[1].ToLower())); - - if (target == null) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "ERROR", "No such player found: " + args[1]); - message.Supress = true; return message; - } - ServerInstance.SendChatMessageToPlayer(message.Sender, "1/2", - $"Nickname: {target.DisplayName.ToString()}\n" + $"Realname: {target.Name.ToString()}\n" + - $"Ping: {Math.Round(target.Latency * 1000, MidpointRounding.AwayFromZero).ToString(CultureInfo.InvariantCulture)}ms\n" + - $"IP: {target.NetConnection.RemoteEndPoint.Address.ToString()}"); - ServerInstance.SendChatMessageToPlayer(message.Sender, "2/2", - $"Game Version: {target.GameVersion.ToString()}\n" + - $"Script Version: {target.RemoteScriptVersion.ToString()}\n" + - $"Vehicle Health: {target.VehicleHealth.ToString()}\n" + - $"Last Position: {target.LastKnownPosition.ToString()}\n"); - message.Supress = true; return message; - } - if (message.Message.ToLower().StartsWith("/nick")) - { - if (account == null || (int)account.Level < 4) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Insufficent privileges."); message.Supress = true; return message; - } - var args = message.Message.Split(); - if (args.Length <= 1) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "USAGE", "/tp [Player Name]"); message.Supress = true; return message; - } - message.Sender.DisplayName = args[1]; message.Supress = true; return message; - } - if (message.Message.ToLower().StartsWith("/stop")) - { - if (account == null || (int)account.Level < 5) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Insufficent privileges."); message.Supress = true; return message; - } - ServerInstance.SendChatMessageToAll("SERVER", "This server will stop now!"); - Environment.Exit(-1); message.Supress = true; return message; - } - /*if (message.Message.StartsWith("/restart")) - { - if (account == null || (int)account.Level < 5) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Insufficent privileges."); - message.Supress = true; return message; - } - ServerInstance.SendChatMessageToAll("SERVER", "~p~This server will restart now. Please reconnect!~p~"); - try - { - //process = System.Diagnostics.Process[] GetProcessesByName("GTAServer.exe"; - //Process[] processes = Process.GetProcessesByName("GTAServer.exe"); - //processes[0].WaitForExit(1000); - Environment.Exit(-1); - } - catch (ArgumentException ex) { ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Could not restart."); } - Process.Start("GTAServer.exe", ""); message.Supress = true; return message; - }*/ - if (message.Message.ToLower().StartsWith("/tp")) - { - if (account == null || (int)account.Level < 3) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Insufficent privileges."); - message.Supress = true; return message; - } - - var args = message.Message.Split(); - if (args.Length <= 1) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "USAGE", "/tp [Player Name]"); - message.Supress = true; return message; - } - - Client target = null; - lock (ServerInstance.Clients) target = ServerInstance.Clients.FirstOrDefault(c => c.DisplayName.ToLower().StartsWith(args[1].ToLower())); - - if (target == null) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "ERROR", "No such player found: " + args[1]); - message.Supress = true; return message; - } - - ServerInstance.GetPlayerPosition(target, o => - { - var newPos = (Vector3)o; - ServerInstance.SetPlayerPosition(message.Sender, newPos); - }); - - Console.WriteLine( - $"ADMINTOOLS: {account.Name + " (" + message.Sender.DisplayName + ")"} has teleported to player {target.Name + " (" + target.DisplayName + ")"}"); - - message.Supress = true; return message; - } - - if (message.Message.ToLower().StartsWith("/godmode")) - { - var args = message.Message.Split(); - if (args.Length <= 1) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "USAGE", "/godmode [Player Name]"); - message.Supress = true; return message; - } - - Client target = null; - lock (ServerInstance.Clients) target = ServerInstance.Clients.FirstOrDefault(c => c.DisplayName.ToLower().StartsWith(args[1].ToLower())); - - if (target == null) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "ERROR", "No such player found: " + args[1]); - message.Supress = true; return message; - } - - string salt = "inv+" + target.NetConnection.RemoteUniqueIdentifier; - - ServerInstance.GetNativeCallFromPlayer(target, salt, 0xB721981B2B939E07, new BooleanArgument(), - (o) => - { - bool isInvincible = (bool)o; - ServerInstance.SendChatMessageToPlayer(message.Sender, - $"Player {target.DisplayName} is {(isInvincible ? "~g~invincible." : "~r~mortal.")}"); - }, new LocalGamePlayerArgument()); - - message.Supress = true; return message; - } - - if (message.Message.ToLower().StartsWith("/weather")) - { - if (account == null || (int)account.Level < 4) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Insufficent privileges."); - message.Supress = true; return message; - } - - var args = message.Message.Split(); - if (args.Length <= 1) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "USAGE", "/weather [Weather ID]"); - message.Supress = true; return message; - } - - int newWeather; - if (!int.TryParse(args[1], out newWeather)) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "USAGE", "/weather [Weather ID]"); - message.Supress = true; return message; - } - - if (newWeather < 0 || newWeather >= _weatherNames.Length) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "USAGE", "Weather ID must be between 0 and " + (_weatherNames.Length - 1)); - message.Supress = true; return message; - } - - ServerWeather = newWeather; - ServerInstance.SendNativeCallToAllPlayers(0x29B487C359E19889, _weatherNames[ServerWeather]); - Console.WriteLine( - $"ADMINTOOLS: {account.Name + " (" + message.Sender.DisplayName + ")"} has changed the weather to {ServerWeather}"); - ServerInstance.SendChatMessageToAll("(" + account.Level.ToString() + ") " + message.Sender.DisplayName + " changed the weather to " + ServerWeather); - - message.Supress = true; return message; - } - - if (message.Message.ToLower().StartsWith("/time")) - { - if (account == null || (int)account.Level < 4) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Insufficent privileges."); - message.Supress = true; return message; - } - - var args = message.Message.Split(); - if (args.Length <= 1) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "USAGE", "/time [hours]:[minutes]"); - message.Supress = true; return message; - } - - int hours; - int minutes; - var timeSplit = args[1].Split(':'); - - if (timeSplit.Length < 2 || !int.TryParse(timeSplit[0], out hours) || !int.TryParse(timeSplit[1], out minutes)) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "USAGE", "/time [hours]:[minutes]"); - message.Supress = true; return message; - } - - if (hours < 0 || hours > 24 || minutes < 0 || minutes > 60) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "USAGE", "/time [hours]:[minutes]"); - message.Supress = true; return message; - } - - ServerTime = new TimeSpan(hours, minutes, 0); - - ServerInstance.SendNativeCallToAllPlayers(0x47C3B5848C3E45D8, ServerTime.Hours, ServerTime.Minutes, ServerTime.Seconds); - ServerInstance.SendNativeCallToAllPlayers(0x4055E40BD2DBEC1D, true); - - Console.WriteLine( - $"ADMINTOOLS: {account.Name + " (" + message.Sender.DisplayName + ")"} has changed the time to {ServerTime}"); - ServerInstance.SendChatMessageToAll("(" + account.Level.ToString() + ") " + message.Sender.DisplayName + " changed the time to " + ServerTime); - - message.Supress = true; return message; - } - - if (message.Message.ToLower().StartsWith("/kill")) - { - if (account == null || (int)account.Level < 4) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Insufficent privileges."); - message.Supress = true; return message; - } - - var args = message.Message.Split(); - if (args.Length <= 1) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "USAGE", "/kill [Player Name]"); - message.Supress = true; return message; - } - - Client target = null; - lock (ServerInstance.Clients) target = ServerInstance.Clients.FirstOrDefault(c => c.DisplayName.ToLower().StartsWith(args[1].ToLower())); - - if (target == null) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "ERROR", "No such player found: " + args[1]); - message.Supress = true; return message; - } - - ServerInstance.SetPlayerHealth(target, -1); - Console.WriteLine( - $"ADMINTOOLS: {account.Name + " (" + message.Sender.DisplayName + ")"} has killed player {target.Name + " (" + target.DisplayName + ")"}"); - message.Supress = true; return message; - } - - if (message.Message.ToLower().StartsWith("/ban")) - { - if (account == null || (int)account.Level < 3) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Insufficent privileges."); - message.Supress = true; return message; - } - - var args = message.Message.Split(); - if (args.Length <= 2) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "USAGE", "/ban [Player Name] [Reason]"); - message.Supress = true; return message; - } - - Client target = null; - lock (ServerInstance.Clients) target = ServerInstance.Clients.FirstOrDefault(c => c.DisplayName.ToLower().StartsWith(args[1].ToLower())); - - if (target == null) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "ERROR", "No such player found: " + args[1]); - message.Supress = true; return message; - } - - target.Ban(args[2], message.Sender); - - SaveBanlist(Location + "Banlist.xml"); - - Console.WriteLine( - $"ADMINTOOLS: {account.Name + " (" + message.Sender.DisplayName + ")"} has banned player {target.Name + " (" + target.DisplayName + ")"} with reason: {args[2]}"); - ServerInstance.KickPlayer(target, "You have been banned: " + args[2]); - message.Supress = true; return message; - } - - if (message.Message.ToLower().StartsWith("/kick")) - { - if (account == null || (int)account.Level < 3) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Insufficent privileges."); - message.Supress = true; return message; - } - - var args = message.Message.Split(); - if (args.Length <= 2) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "USAGE", "/kick [Player Name] [Reason]"); - message.Supress = true; return message; - } - - Client target = null; - lock (ServerInstance.Clients) target = ServerInstance.Clients.FirstOrDefault(c => c.DisplayName.ToLower().StartsWith(args[1].ToLower())); - - if (target == null) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "ERROR", "No such player found: " + args[1]); - message.Supress = true; return message; - } - - ServerInstance.KickPlayer(target, args[2], false, message.Sender); - Console.WriteLine( - $"SERVER: {account.Name + " (" + message.Sender.DisplayName + ")"} has kicked player {target.Name + " (" + target.DisplayName + ")"}"); - message.Supress = true; return message; - } - - if (message.Message.ToLower().StartsWith("/register")) - { - account = message.Sender.GetAccount(false); - if (account != null) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "You already have an account."); - message.Supress = true; return message; - } - - var args = message.Message.Split(); - if (args.Length <= 1) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "USAGE", "/register [Password]"); - message.Supress = true; return message; - } - - var password = GetHashSha256(args[1]); - var accObject = new Account() - { - Level = Privilege.User, - Name = message.Sender.DisplayName, - Password = password, - Ban = null - }; - lock (Lists.Accounts.Accounts) Lists.Accounts.Accounts.Add(accObject); - SaveAccounts(Location + "Accounts.xml"); - lock (Lists.AuthenticatedUsers) Lists.AuthenticatedUsers.Add(message.Sender.NetConnection.RemoteUniqueIdentifier); - - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Your account has been created!"); - ServerInstance.PrintPlayerInfo(message.Sender, "New Player registered: "); - message.Supress = true; return message; - } - - if (message.Message.ToLower().StartsWith("/login")) - { - if (account != null) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "You are already authenticated."); - message.Supress = true; return message; - } - - account = message.Sender.GetAccount(false); - - if (account == null) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "No accounts have been found with your name."); - message.Supress = true; return message; - } - - var args = message.Message.Split(); - if (args.Length <= 1) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "USAGE", "/login [Password]"); - message.Supress = true; return message; - } - - var password = GetHashSha256(args[1]); - - if (password != account.Password) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Wrong password."); - message.Supress = true; return message; - } - - lock (Lists.AuthenticatedUsers) if (!Lists.AuthenticatedUsers.Contains(message.Sender.NetConnection.RemoteUniqueIdentifier)) Lists.AuthenticatedUsers.Add(message.Sender.NetConnection.RemoteUniqueIdentifier); - - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "Authentication successful!"); - ServerInstance.PrintPlayerInfo(message.Sender, account.Level.ToString() + " logged in: "); - //LogToConsole(2, false, "Accounting", string.Format("{0} \"{1}\" logged in.", account.Level.ToString(), message.Sender.DisplayName)); - } - - switch (message.Message.ToLower()) - { - case "/logout": - if (message.Sender.IsAuthenticated()) - { - Console.WriteLine($"SERVER: Player has logged out: {message.Sender.Name}"); - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "You have been logged out."); - - lock (Lists.AuthenticatedUsers) if (Lists.AuthenticatedUsers.Contains(message.Sender.NetConnection.RemoteUniqueIdentifier)) Lists.AuthenticatedUsers.Remove(message.Sender.NetConnection.RemoteUniqueIdentifier); - } - else - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "SERVER", "You are not logged in."); - } - message.Supress = true; return message; - case "/countdown": - if (DateTime.Now.Subtract(_lastCountdown).TotalSeconds < 30) - { - ServerInstance.SendChatMessageToPlayer(message.Sender, "COUNTDOWN", "Please wait 30 seconds before starting another countdown."); - message.Supress = true; return message; - } - - _lastCountdown = DateTime.Now; - - var cdThread = new Thread((ThreadStart)delegate - { - for (int i = 3; i >= 0; i--) - { - ServerInstance.SendChatMessageToAll("COUNTDOWN", i == 0 ? "Go!" : i.ToString()); - Thread.Sleep(1000); - } - }); - cdThread.Start(); - message.Supress = true; return message; - } - - if (!message.Sender.NetConnection.RemoteEndPoint.Address.ToString().Equals("127.0.0.1")) - { - try { message.Prefix = message.Sender.geoIP.Country.IsoCode.ToString(); } catch (Exception ex) { LogToConsole(3, false, "GeoIP", ex.Message); } - } - try { message.Suffix = account.Level.ToString(); } catch { message.Suffix = "Guest"; } - if (message.Message.ToLower().Contains("login") || message.Message.ToLower().Contains("register") || message.Message.ToLower().Equals("urtle") || message.Message.ToLower().Equals("turtle")) { message.Supress = true; return message; } - return message; - } - catch (Exception ex) { LogToConsole(4, false, "Chat", "Can't handle message: " + ex.Message); return null; } - } - - public override bool OnPlayerDisconnect(Client player) - { - lock (Lists.AuthenticatedUsers) if (Lists.AuthenticatedUsers.Contains(player.NetConnection.RemoteUniqueIdentifier)) Lists.AuthenticatedUsers.Remove(player.NetConnection.RemoteUniqueIdentifier); - - if (player.IsBanned() || player.IsIPBanned()) return false; - - return true; - } - - public override void OnPlayerSpawned(Client player) - { - try { ServerInstance.SendNativeCallToPlayer(player, 0x29B487C359E19889, _weatherNames[ServerWeather]); } catch { } - try { ServerInstance.SendNativeCallToPlayer(player, 0x47C3B5848C3E45D8, ServerTime.Hours, ServerTime.Minutes, ServerTime.Seconds); } catch { } - try { ServerInstance.SendNativeCallToPlayer(player, 0x4055E40BD2DBEC1D, true); } catch { } - } - - private static AdminSettings ReadSettings(string path) - { - var ser = new XmlSerializer(typeof(AdminSettings)); - - AdminSettings settings = null; - - if (File.Exists(path)) - { - using (var stream = File.OpenRead(path)) settings = (AdminSettings)ser.Deserialize(stream); - - using (var stream = new FileStream(path, File.Exists(path) ? FileMode.Truncate : FileMode.Create, FileAccess.ReadWrite)) ser.Serialize(stream, settings); - } - else - { - using (var stream = File.OpenWrite(path)) ser.Serialize(stream, settings = new AdminSettings()); - } - - return settings; - } - - private void LoadAccounts(string path) - { - XmlSerializer ser = new XmlSerializer(typeof(UserList)); - if (File.Exists(path)) - { - using (var stream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite)) - { - Lists.Accounts = (UserList)ser.Deserialize(stream); - } - } - else - { - Lists.Accounts = new UserList {Accounts = new List()}; - SaveAccounts(path); - } - } - - public void SaveAccounts(string path) - { - XmlSerializer ser = new XmlSerializer(typeof(UserList)); - using (var stream = new FileStream(path, File.Exists(path) ? FileMode.Truncate : FileMode.Create, FileAccess.ReadWrite)) - { - ser.Serialize(stream, Lists.Accounts); - } - } - - private static void LoadBanlist(string path) - { - XmlSerializer ser = new XmlSerializer(typeof(Banlist)); - if (File.Exists(path)) - { - using (var stream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite)) - { - Lists.Banned = (Banlist)ser.Deserialize(stream); - } - - Lists.Accounts.Accounts.ForEach(acc => - { - acc.Ban = null; - Lists.Banned.BannedIps.Any(b => - { - if (b.Name != acc.Name) return false; - acc.Ban = b; - - return true; - }); - }); - } - else - { - Lists.Banned = new Banlist { BannedIps = new List() }; - SaveBanlist(path); - } - } - - private static void SaveBanlist(string path) - { - XmlSerializer ser = new XmlSerializer(typeof(Banlist)); - using (var stream = new FileStream(path, File.Exists(path) ? FileMode.Truncate : FileMode.Create, FileAccess.ReadWrite)) - { - ser.Serialize(stream, Lists.Banned); - } - } - - private static string GetHashSha256(string text) - { - byte[] bytes = Encoding.UTF8.GetBytes(text); - SHA256Managed hashstring = new SHA256Managed(); - byte[] hash = hashstring.ComputeHash(bytes); - - StringBuilder hashString = new StringBuilder(); - foreach (byte x in hash) - { - hashString.Append($"{x:x2}"); - } - return hashString.ToString(); - } - public string SanitizeString(string input) - { - input = Regex.Replace(input, "~.~", "", RegexOptions.IgnoreCase); - return input; - } - public string FormatString(string input) - { - input = Regex.Replace(input, "~b~", "", RegexOptions.IgnoreCase); - input = Regex.Replace(input, "~r~", "", RegexOptions.IgnoreCase); - return input; - } - } - - public class IpInfo - { - public string CountryCode { get; internal set; } - public List List { get; set; } - public object Status { get; internal set; } - } - - public enum Privilege - { - Guest = 0, - User = 1, - VIP = 2, - Moderator = 3, - Administrator = 4, - Owner = 5, - } - - public class UserList - { - public List Accounts { get; set; } - } - - public class Account - { - public string Name { get; set; } - public string Password { get; set; } - public Privilege Level { get; set; } - public Ban Ban { get; set; } - } - - public static class Accounts - { - public static bool IsAuthenticated(this Client client) - { - lock (Lists.AuthenticatedUsers) return Lists.AuthenticatedUsers.Contains(client.NetConnection.RemoteUniqueIdentifier); - } - - public static Account GetAccount(this Client client, bool checkauthentication = true) - { - if (!checkauthentication || client.IsAuthenticated()) lock (Lists.Accounts.Accounts) return Lists.Accounts.Accounts.FirstOrDefault(acc => acc.Name == client.DisplayName); - - return null; - } - - public static bool IsIPBanned(this Client client) - { - bool banned = false; - lock (Lists.Banned.BannedIps) - { - banned = Lists.Banned.BannedIps.Any(b => - { - if (b.Address == client.NetConnection.RemoteEndPoint.Address.ToString()) - { - try - { - client.GetAccount().Ban = b; - } - catch (Exception ex) - { - Console.WriteLine($"Check for ban of player \"{client.DisplayName}\" failed: {ex.Message}"); - } - return true; - } - - return false; - }); - } - - return banned; - } - - public static bool IsBanned(this Client client) - { - return client.GetBan() != null; - } - - public static Ban GetBan(this Client client) - { - Account account = client.GetAccount(); - - return account?.Ban; - } - - public static void Ban(this Client client, string reason, Client issuedBy = null) - { - Ban ban = new Ban() - { - Address = client.NetConnection.RemoteEndPoint.Address.ToString(), - BannedBy = issuedBy == null ? "Server" : issuedBy.DisplayName, - Reason = reason, - TimeIssued = DateTime.Now, - Name = client.DisplayName - }; - - lock (Lists.Banned.BannedIps) Lists.Banned.BannedIps.Add(ban); - try - { - client.GetAccount().Ban = ban; - } - catch (Exception ex) - { - Console.WriteLine($"Ban of player \"{client.DisplayName}\" failed: {ex.ToString()}"); - } - } - - public static Client GetClient(this Account account) - { - Client client = null; - lock (AdminToolsServerScript.ServerInstance.Clients) - { - var any = AdminToolsServerScript.ServerInstance.Clients.Any(c => - { - if (c.DisplayName != account.Name) return false; - client = c; - - return true; - }); - } - - return client; - } - } - - public class Banlist - { - public List BannedIps { get; set; } - } - - public class Ban - { - public string Name { get; set; } - public string Address { get; set; } - public string Reason { get; set; } - public DateTime TimeIssued { get; set; } - public string BannedBy { get; set; } - } -} \ No newline at end of file diff --git a/AdminTools/Properties/AssemblyInfo.cs b/AdminTools/Properties/AssemblyInfo.cs deleted file mode 100644 index 9a43c00..0000000 --- a/AdminTools/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("TestGamemode")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("TestGamemode")] -[assembly: AssemblyCopyright("Copyright © 2015")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("158cceb2-e6ec-457b-ba61-e448bd6b0f40")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/AdminTools/app.config b/AdminTools/app.config deleted file mode 100644 index fc24756..0000000 --- a/AdminTools/app.config +++ /dev/null @@ -1,65 +0,0 @@ - - - - -
- - - - - - True - - - False - - - False - - - Welcome to this GTA 5 Co-op Server! Max Ping: 250 - - - 250 - - - True - - - False - - - False - - - VERSION_0_9_1 - - - True - - - True - - - False - - - True - - - False - - - 25 - - - - - - - - - - - - \ No newline at end of file diff --git a/AdminTools/packages.config b/AdminTools/packages.config deleted file mode 100644 index 70db57a..0000000 --- a/AdminTools/packages.config +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/GTACoOp.sln b/GTACoOp.sln index 7b5be42..c12e645 100644 --- a/GTACoOp.sln +++ b/GTACoOp.sln @@ -5,10 +5,6 @@ VisualStudioVersion = 17.5.33516.290 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GTACoOp", "Client\GTACoOp.csproj", "{1BC495C9-DC44-478A-9E16-3FC482A8B850}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GTAServer", "Server\GTAServer.csproj", "{559EE224-BF7B-49D8-9CEE-11E6BA71FE4E}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdminTools", "AdminTools\AdminTools.csproj", "{158CCEB2-E6EC-457B-BA61-E448BD6B0F40}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "gtaserver.core", "gtaserver.core\gtaserver.core.csproj", "{6FD5243E-F355-4456-BD5A-A6F854103EA8}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Race", "Race\Race.csproj", "{946F653E-62EB-421A-9F5B-65441EE78CD6}" @@ -37,22 +33,6 @@ Global {1BC495C9-DC44-478A-9E16-3FC482A8B850}.Release|Any CPU.Build.0 = Release|Any CPU {1BC495C9-DC44-478A-9E16-3FC482A8B850}.Release|x64.ActiveCfg = Release|Any CPU {1BC495C9-DC44-478A-9E16-3FC482A8B850}.Release|x64.Build.0 = Release|Any CPU - {559EE224-BF7B-49D8-9CEE-11E6BA71FE4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {559EE224-BF7B-49D8-9CEE-11E6BA71FE4E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {559EE224-BF7B-49D8-9CEE-11E6BA71FE4E}.Debug|x64.ActiveCfg = Debug|Any CPU - {559EE224-BF7B-49D8-9CEE-11E6BA71FE4E}.Debug|x64.Build.0 = Debug|Any CPU - {559EE224-BF7B-49D8-9CEE-11E6BA71FE4E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {559EE224-BF7B-49D8-9CEE-11E6BA71FE4E}.Release|Any CPU.Build.0 = Release|Any CPU - {559EE224-BF7B-49D8-9CEE-11E6BA71FE4E}.Release|x64.ActiveCfg = Release|Any CPU - {559EE224-BF7B-49D8-9CEE-11E6BA71FE4E}.Release|x64.Build.0 = Release|Any CPU - {158CCEB2-E6EC-457B-BA61-E448BD6B0F40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {158CCEB2-E6EC-457B-BA61-E448BD6B0F40}.Debug|Any CPU.Build.0 = Debug|Any CPU - {158CCEB2-E6EC-457B-BA61-E448BD6B0F40}.Debug|x64.ActiveCfg = Debug|Any CPU - {158CCEB2-E6EC-457B-BA61-E448BD6B0F40}.Debug|x64.Build.0 = Debug|Any CPU - {158CCEB2-E6EC-457B-BA61-E448BD6B0F40}.Release|Any CPU.ActiveCfg = Release|Any CPU - {158CCEB2-E6EC-457B-BA61-E448BD6B0F40}.Release|Any CPU.Build.0 = Release|Any CPU - {158CCEB2-E6EC-457B-BA61-E448BD6B0F40}.Release|x64.ActiveCfg = Release|Any CPU - {158CCEB2-E6EC-457B-BA61-E448BD6B0F40}.Release|x64.Build.0 = Release|Any CPU {6FD5243E-F355-4456-BD5A-A6F854103EA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6FD5243E-F355-4456-BD5A-A6F854103EA8}.Debug|Any CPU.Build.0 = Debug|Any CPU {6FD5243E-F355-4456-BD5A-A6F854103EA8}.Debug|x64.ActiveCfg = Debug|Any CPU diff --git a/README.md b/README.md index ba3b27c..e2dd825 100644 --- a/README.md +++ b/README.md @@ -6,22 +6,15 @@ Downloads are available from the [releases](https://github.com/oldnapalm/GTACoOp ## Installation and usage -Please refer to the [Wiki](https://github.com/oldnapalm/GTACoOp/wiki). +Please refer to the [wiki](https://github.com/oldnapalm/GTACoOp/wiki). ## Projects -* `Client/` Source of the mod and client -* `DiscordBot/` Plugin for gtaserver.core to create a bridge between discord and gtaserver.core with chat from both sides. Written by [oldnapalm](https://github.com/oldnapalm) +* `Client/` Source of the mod and client +* `DiscordBot/` Plugin for gtaserver.core to create a bridge between discord and gtaserver.core with chat from both sides * `Race/` Source of race gamemode for gtaserver.core * `gtamasterserver/` Small python web application to run a masterserver -* `gtaserver.core/` Source of the current server. - -## Old - -These projects are not maintained and often replaced by newer ones. - -* `Server/` Source of the old server -* `AdminTools/` Source of the old admintools plugin for orginal gtaserver +* `gtaserver.core/` Source of the server ## Contributors diff --git a/Server/App.config b/Server/App.config deleted file mode 100644 index bce372c..0000000 --- a/Server/App.config +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/Server/ChatData.cs b/Server/ChatData.cs deleted file mode 100644 index c41c967..0000000 --- a/Server/ChatData.cs +++ /dev/null @@ -1,27 +0,0 @@ -using ProtoBuf; - -namespace GTAServer -{ - /// - /// Class containing data for each chat message. - /// - [ProtoContract] - public class ChatData - { - /// - /// Message ID - /// - [ProtoMember(1)] - public long Id { get; set; } - /// - /// Message Sender - /// - [ProtoMember(2)] - public string Sender { get; set; } - /// - /// Message Contents - /// - [ProtoMember(3)] - public string Message { get; set; } - } -} \ No newline at end of file diff --git a/Server/GTAServer.csproj b/Server/GTAServer.csproj deleted file mode 100644 index 959799a..0000000 --- a/Server/GTAServer.csproj +++ /dev/null @@ -1,130 +0,0 @@ - - - - - Debug - AnyCPU - {559EE224-BF7B-49D8-9CEE-11E6BA71FE4E} - Exe - Properties - GTAServer - GTAServer - v4.5.2 - 512 - - false - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - AnyCPU - pdbonly - true - ..\..\..\..\SERVERS\GameServer\Grand Theft Auto\GTA V\ - TRACE;__CONSTRAINED__ - prompt - 4 - false - - - - - - false - - - - - - - - ..\packages\Lidgren.Network.1.0.2\lib\net451\Lidgren.Network.dll - True - - - ..\packages\log4net.2.0.8\lib\net45-full\log4net.dll - - - ..\packages\MaxMind.Db.2.4.0\lib\net45\MaxMind.Db.dll - - - ..\packages\MaxMind.GeoIP2.3.0.0\lib\net45\MaxMind.GeoIP2.dll - - - ..\packages\Newtonsoft.Json.12.0.1-beta1\lib\net45\Newtonsoft.Json.dll - - - ..\packages\protobuf-net.3.0.0-alpha.3\lib\net40\protobuf-net.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - False - Microsoft .NET Framework 4.5.2 %28x86 and x64%29 - true - - - False - .NET Framework 3.5 SP1 - false - - - - - \ No newline at end of file diff --git a/Server/GameServer.cs b/Server/GameServer.cs deleted file mode 100644 index f1f6dfa..0000000 --- a/Server/GameServer.cs +++ /dev/null @@ -1,2095 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Reflection; -using System.Text; -using System.Threading; -using Lidgren.Network; -using ProtoBuf; -using System.Text.RegularExpressions; -using MaxMind.GeoIP2; -using System.Security.Principal; -using System.Diagnostics; -using log4net; -using log4net.Config; - -namespace GTAServer -{ - /// - /// Another version of the ChatData class? - /// TODO: Task BluScream about this... - /// - public class ChatMessage - { - /// - /// Sender of the message - /// - public Client Sender { get; set; } - /// - /// Receiver of the message - /// - public Client Reciever { get; set; } - /// - /// If the message is private - /// Note: ReSharper is suggesting IsPrivate as a property name - /// - public bool isPrivate { get; set; } - /// - /// Contents of message - /// - public string Message { get; set; } - /// - /// Color of the message - /// - public ConsoleColor Color { get; set; } - /// - /// Message prefix - /// - public string Prefix { get; set; } - /// - /// Message suffix - /// - public string Suffix { get; set; } - /// - /// If the message should be suppressed - /// TODO: More detailed (where is it suppressed from? just chat? just console? both? - /// - public bool Supress { get; set; } - } - /// - /// Class containing data for the client - /// - public class Client - { - /// - /// Connection from the server to the client - /// - public NetConnection NetConnection { get; private set; } - /// - /// Name of the player (Usually SC name) - /// - public string Name { get; set; } - /// - /// Display name of the player (Usually SC name but can be changed) - /// - public string DisplayName { get; set; } - /// - /// Latency of the client - /// - public float Latency { get; set; } - /// - /// Remote client version - /// - public ScriptVersion RemoteScriptVersion { get; set; } - /// - /// Remote game version - /// - public int GameVersion { get; set; } - /// - /// Last known position of the player - /// - public Vector3 LastKnownPosition { get; internal set; } - /// - /// Health of the player - /// - public int Health { get; internal set; } - /// - /// Vehicle health of the player - /// - public int VehicleHealth { get; internal set; } - /// - /// If the player is in a vehicle - /// - public bool IsInVehicle { get; internal set; } - /// - /// If the player is AFK - /// Note: ReSharper is suggesting 'Afk' as a method name' - /// - public bool afk { get; set; } - /// - /// If they got kicked - /// - public bool Kicked { get; set; } - /// - /// Reason the player was kicked - /// - public string KickReason { get; set; } - /// - /// Who the player was kicked by - /// - public Client KickedBy { get; set; } - /// - /// If the player is silent/muted (?) - /// - public bool Silent { get; set; } - /// - /// GeoIP response - /// - public MaxMind.GeoIP2.Responses.CountryResponse geoIP { get; set; } - - public Client(NetConnection nc) - { - NetConnection = nc; - } - } - - /// - /// Notification icon types - /// - public enum NotificationIconType - { - /// - /// Chatbox notification icon - /// - Chatbox = 1, - /// - /// Email notification icon - /// - Email = 2, - /// - /// Friend request icon - /// - AddFriendRequest = 3, - /// - /// No icon? Not sure - /// TODO: Test this - /// - Nothing = 4, - /// - /// Right jumping arrow icon? Not sure - /// TODO: Test this - /// - RightJumpingArrow = 7, - /// - /// RP icon - /// - RP_Icon = 8, - /// - /// Dollar sign icon - /// - DollarIcon = 9, - } - - /// - /// Notification picture type - /// - public enum NotificationPicType - { - /// - /// Default profile pic - /// - CHAR_DEFAULT, - /// - /// Facebook icon - /// - CHAR_FACEBOOK, - /// - /// Social club star profile pic - /// - CHAR_SOCIAL_CLUB, - /// - /// Super Auto San Andreas car site - /// - CHAR_CARSITE2, - /// - /// Boat site anchor - /// - CHAR_BOATSITE, - /// - /// Maze bank logo - /// - CHAR_BANK_MAZE, - /// - /// Fleeca bank - /// - CHAR_BANK_FLEECA, - /// - /// Bank bell - /// - CHAR_BANK_BOL, - /// - /// Minotaur icon - /// - CHAR_MINOTAUR, - /// - /// Epsilon E - /// - CHAR_EPSILON, - /// - /// Warstock W - /// - CHAR_MILSITE, - /// - /// Legendary Motorsports icon - /// - CHAR_CARSITE, - /// - /// Dr. Freidlander Face - /// - CHAR_DR_FRIEDLANDER, - /// - /// P and M Logo - /// - CHAR_BIKESITE, - /// - /// Lifeinvader - /// - CHAR_LIFEINVADER, - /// - /// Plane site - /// - CHAR_PLANESITE, - /// - /// Michael's Face - /// - CHAR_MICHAEL, - /// - /// Franklin's Face - /// - CHAR_FRANKLIN, - /// - /// Trevor's Face - /// - CHAR_TREVOR, - /// - /// Simeon's Face - /// - CHAR_SIMEON, - /// - /// Ron's Face - /// - CHAR_RON, - /// - /// Jimmy's Face - /// - CHAR_JIMMY, - /// - /// Lester's Face - /// - CHAR_LESTER, - /// - /// Dave's Face - /// - CHAR_DAVE, - /// - /// Chop's Face (...Do dogs have a face?) - /// - CHAR_LAMAR, - /// - /// Devin's Face - /// - CHAR_DEVIN, - /// - /// Amanda's Face - /// - CHAR_AMANDA, - /// - /// Tracey's Face - /// - CHAR_TRACEY, - /// - /// Stretch's Face - /// - CHAR_STRETCH, - /// - /// Wade's Face - /// - CHAR_WADE, - /// - /// Martin's Face - /// - CHAR_MARTIN, - - } - /// - /// Game server class - /// - public class GameServer : MarshalByRefObject - { - /// - /// Location of the current server instance - /// - public string Location => AppDomain.CurrentDomain.BaseDirectory; - public NetPeerConfiguration Config; - public GameServer() - { - Clients = new List(); - MaxPlayers = 32; - SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); - Config = new NetPeerConfiguration("GTAVOnlineRaces"); - Config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); - Config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); - Config.EnableMessageType(NetIncomingMessageType.UnconnectedData); - Config.EnableMessageType(NetIncomingMessageType.ConnectionLatencyUpdated); - } - /*public GameServer(int port, string name, string gamemodeName) - { - Clients = new List(); - MaxPlayers = 32; - Port = port; - GamemodeName = gamemodeName; - Name = name; - WanIP = ""; - LanIP = ""; - geoIP = null; - SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); - NetPeerConfiguration config = new NetPeerConfiguration("GTAVOnlineRaces") {Port = port}; - config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); - config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest); - config.EnableMessageType(NetIncomingMessageType.UnconnectedData); - config.EnableMessageType(NetIncomingMessageType.ConnectionLatencyUpdated); - Server = new NetServer(config); - }*/ - /// - /// Server socket - /// - public NetServer Server; - - /// - /// Maximum players - /// - public int MaxPlayers { get; set; } - /// - /// Port the server is on - /// - public int Port { get; set; } - /// - /// List of clients on the server - /// - public List Clients { get; set; } - /// - /// Name of the server - /// - public string Name { get; set; } - /// - /// Server password - /// - public string Password { get; set; } - /// - /// Password protected - /// - public bool PasswordProtected { get; set; } - /// - /// Server gamemode - /// - public string GamemodeName { get; set; } - /// - /// Master server address - /// - public string MasterServer { get; set; } - /// - /// Backup master server address - /// - public string BackupMasterServer { get; set; } - /// - /// If the server announces itself to the master server - /// - public bool AnnounceSelf { get; set; } - - /// - /// If the server allows nicknames - /// - public bool AllowNickNames { get; set; } - /// - /// If the server allows outdated clients - /// - public bool AllowOutdatedClients { get; set; } - /// - /// Server-side script version - /// - public readonly ScriptVersion ServerVersion = ScriptVersion.VERSION_0_9_3; - /// - /// Gamemode ServerScript object - /// Note: ReSharper is suggesting we change this variable's name to 'Gamemode' - /// - private ServerScript _gamemode { get; set; } - - /// - /// List of loaded filterscripts - /// - private List _filterscripts; - /// - /// Public IP of the server - /// Note: ReSharper is suggesting we change this variable's name to 'WanIp' - /// - public string WanIP { get; set; } - /// - /// Private IP of the server - /// Note: ReSharper is suggesting we change this variable's name to 'LanIp' - /// - public string LanIP { get; set; } - /// - /// IP of the last kicked player - /// - public string LastKicked { get; set; } - /// - /// CountryResponse of the last player to join - /// Note: ReSharper is suggesting we change this variable's name to 'GeoIp' - /// - public MaxMind.GeoIP2.Responses.CountryResponse geoIP { get; set; } - - /// - /// Time since last announcing self to master - /// - private DateTime _lastAnnounceDateTime; - - /// - /// Thread of current server - /// - public Thread Thread; - - public static ILog Log; - /// - /// Sets all the config stuff for the server. - /// Note - You must call this after any update to the config object. - /// - public void ConfigureServer() - { - Server = new NetServer(Config); - } - - /// - /// Starts a server, then runs the main loop. - /// - public void StartAndRunMainLoop() - { - if (Log == null) - { - SetupLogger("UNKNOWN_SERVER_FIXME"); - } - Start(); - while (true) - { - Tick(); - System.Threading.Thread.Sleep(10); - } - - } - - /// - /// Set up logging for server instance - /// - /// Name of the server instance's logger. - public void SetupLogger(string name) - { - XmlConfigurator.Configure(new System.IO.FileInfo("logging.xml")); - Log = LogManager.GetLogger(name); - } - /// - /// Start a game server with no filterscripts loaded. - /// - public void Start() - { - Start(new string[] {}); - } - - /// - /// Start the game server - /// - /// List of filterscritps to load - public void Start(string[] filterscripts) - { - Server.Start(); - if (AnnounceSelf) - { - _lastAnnounceDateTime = DateTime.Now; - Log.Debug("Announcing to master server"); - AnnounceSelfToMaster(); - } - - if (GamemodeName.ToLower() != "freeroam") - { - try - { - Log.Info("Loading gamemode: " + GamemodeName); - - try - { - Program.DeleteFile(Location + "gamemodes" + Path.DirectorySeparatorChar + GamemodeName + ".dll:Zone.Identifier"); - } - catch - { - } - - var asm = Assembly.LoadFrom(Location + "gamemodes" + Path.DirectorySeparatorChar + GamemodeName + ".dll"); - var types = asm.GetExportedTypes(); - var validTypes = types.Where(t => - !t.IsInterface && - !t.IsAbstract) - .Where(t => typeof(ServerScript).IsAssignableFrom(t)); - var enumerable = validTypes as Type[] ?? validTypes.ToArray(); - if (!enumerable.Any()) - { - Log.Error("ERROR: No classes that inherit from ServerScript have been found in the assembly. Starting freeroam."); - return; - } - - _gamemode = Activator.CreateInstance(enumerable.ToArray()[0]) as ServerScript; - if (_gamemode == null) Log.Warn("Could not create gamemode: it is null."); - else _gamemode.Start(this); - } - catch (Exception e) - { - Log.Error("ERROR: Error while loading script: " + e.Message + " at " + e.Source + - ".\nStack Trace:" + e.StackTrace); - Log.Error("Inner Exception: "); - Exception r = e; - while (r != null && r.InnerException != null) - { - Log.Error("at " + r.InnerException); - r = r.InnerException; - - } - } - } - - // Filterscript loading has been moved to whatever starts the script, by calling GameServer.LoadFilterscript. - // Add this to your host server implementations. - /*Console.WriteLine("Loading filterscripts.."); - var list = new List(); - foreach (var path in filterscripts) - { - if (string.IsNullOrWhiteSpace(path)) continue; - - try { - try { - Program.DeleteFile(Location + "filterscripts" + Path.DirectorySeparatorChar + GamemodeName + ".dll:Zone.Identifier"); - } catch { } - - var fsAsm = Assembly.LoadFrom(Location + "filterscripts" + Path.DirectorySeparatorChar + path + ".dll"); - var fsObj = InstantiateScripts(fsAsm); - list.AddRange(fsObj); - } catch (Exception ex) { - Console.WriteLine("Failed to load filterscript \"" + path + "\", error: " + ex.ToString()); - } - } - - list.ForEach(fs => - { - fs.Start(this); - Console.WriteLine("Starting filterscript " + fs.Name + "..."); - }); - _filterscripts = list; - PrintServerInfo(); PrintPlayerList(); */ - } - - /// - /// Inject filterscript into server at run time. - /// - /// Name of the filterscript .dll file. - public void LoadFilterscript(string scriptAssembly) - { - Program.DeleteFile(Location + "filterscripts" + Path.DirectorySeparatorChar + scriptAssembly + - ".dll:Zone.Identifier"); - var fsAsm = Assembly.LoadFrom(Location + "filterscripts" + Path.DirectorySeparatorChar + scriptAssembly + ".dll"); - var fsObj = InstantiateScripts(fsAsm); - foreach (var script in fsObj) - { - script.Start(this); - _filterscripts.Add(script); - } - } - /// - /// Announce server to master - /// - public void AnnounceSelfToMaster() - { - using (var wb = new WebClient()) - { - try - { - wb.UploadData(MasterServer, Encoding.UTF8.GetBytes(Port.ToString())); - } - catch (WebException) - { - Log.Warn("Failed to announce self: master server is not available at this time. Using fallback server..."); - try - { - wb.UploadData(BackupMasterServer, Encoding.UTF8.GetBytes(Port.ToString())); - } - catch (WebException) - { - Log.Warn("Failed to announce self: backup master server is not available at this time. Trying again later..."); - - } - } - } - } - - /// - /// Load a new .dll of server scripts into the server - /// - /// Assembly reference to the dll - /// A list of ServerScript objects - private IEnumerable InstantiateScripts(Assembly targetAssembly) - { - var types = targetAssembly.GetExportedTypes(); - var validTypes = types.Where(t => - !t.IsInterface && - !t.IsAbstract) - .Where(t => typeof(ServerScript).IsAssignableFrom(t)); - if (!validTypes.Any()) - { - yield break; - } - foreach (var type in validTypes) - { - var obj = Activator.CreateInstance(type) as ServerScript; - if (obj != null) - yield return obj; - } - } - /// - /// Log something to the console - /// - /// Flag (TODO: Make a LogFlags enum) - /// If the message is a debug mode - /// Module/plugin the log message is from - /// Message to log - [Obsolete("Use server instance logger or make your own for the filterscript (preferred method is to make your own)")] - static void LogToConsole(int flag, bool debug, string module, string message) - { - Log.Warn("Deprecated method LogToConsole called. Note that this method will be removed in the next release."); - if (module == null || module.Equals("")) { module = "SERVER"; } - if (debug && !Program.Debug) return; - if (flag == 1) - { - Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("[" + DateTime.Now + "] (DEBUG) " + module.ToUpper() + ": " + message); - } - else if (flag == 2) - { - Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("[" + DateTime.Now + "] (SUCCESS) " + module.ToUpper() + ": " + message); - } - else if (flag == 3) - { - Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("[" + DateTime.Now + "] (WARNING) " + module.ToUpper() + ": " + message); - } - else if (flag == 4) - { - Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("[" + DateTime.Now + "] (ERROR) " + module.ToUpper() + ": " + message); - } - else if (flag == 6) - { - Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("[" + DateTime.Now + "] " + module.ToUpper() + ": " + message); - } - else - { - Console.WriteLine("[" + DateTime.Now + "] " + module.ToUpper() + ": " + message); - } - Console.ForegroundColor = ConsoleColor.White; - } - /// - /// Run every tick - /// - public void Tick() - { - try - { - if (AnnounceSelf && DateTime.Now.Subtract(_lastAnnounceDateTime).TotalMinutes >= 5) - { - _lastAnnounceDateTime = DateTime.Now; - AnnounceSelfToMaster(); - } - - NetIncomingMessage msg; - while ((msg = Server.ReadMessage()) != null) - { - Client client = null; - lock (Clients) - { - foreach (Client c in Clients) - { - if (c != null && c.NetConnection != null && - c.NetConnection.RemoteUniqueIdentifier != 0 && - msg.SenderConnection != null && - c.NetConnection.RemoteUniqueIdentifier == msg.SenderConnection.RemoteUniqueIdentifier) - { - client = c; - break; - } - } - } - - if (client == null) client = new Client(msg.SenderConnection); - - switch (msg.MessageType) - { - - case NetIncomingMessageType.UnconnectedData: - var isPing = msg.ReadString(); - if (isPing == "ping") - { - Log.Info("ping received from " + msg.SenderEndPoint.Address.ToString()); - var pong = Server.CreateMessage(); - pong.Write("pong"); - Server.SendMessage(pong, client.NetConnection, NetDeliveryMethod.ReliableOrdered); - } - if (isPing == "query") - { - int playersonline = 0; - lock (Clients) playersonline = Clients.Count; - Log.Info("query received from " + msg.SenderEndPoint.Address.ToString()); - var pong = Server.CreateMessage(); - pong.Write(Name + "%" + PasswordProtected + "%" + playersonline + "%" + MaxPlayers + "%" + GamemodeName); - Server.SendMessage(pong, client.NetConnection, NetDeliveryMethod.ReliableOrdered); - } - break; - case NetIncomingMessageType.VerboseDebugMessage: - Log.Debug("NetworkVerboseDebug - " + msg.ReadString()); - break; - case NetIncomingMessageType.DebugMessage: - Log.Debug("NetworkDebug - " + msg.ReadString()); - break; - case NetIncomingMessageType.WarningMessage: - Log.Warn("NetworkWarning - " + msg.ReadString()); - break; - case NetIncomingMessageType.ErrorMessage: - Log.Error("NetworkError - " + msg.ReadString()); - break; - case NetIncomingMessageType.ConnectionLatencyUpdated: - client.Latency = msg.ReadFloat(); break; - case NetIncomingMessageType.ConnectionApproval: - var type = msg.ReadInt32(); - var leng = msg.ReadInt32(); - var connReq = DeserializeBinary(msg.ReadBytes(leng)) as ConnectionRequest; - if (connReq == null) - { - DenyPlayer(client, "Connection Object is null", true, msg); continue; - } - Console.Write("New connection request: "); - try { Console.Write("Nickname: " + connReq.DisplayName.ToString() + " | "); } catch (Exception) { } - try { Console.Write("Name: " + connReq.Name.ToString() + " | "); } catch (Exception) { } - #if debug - try { Console.Write("Password: " + connReq.Password.ToString() + " | "); } catch (Exception) { } - #endif - try { Console.Write("Game Version: " + connReq.GameVersion.ToString() + " | "); } catch (Exception) { } - try { Console.Write("Script Version: ["+connReq.ScriptVersion.ToString()+ "] "+(ScriptVersion)connReq.ScriptVersion+" | "); } catch (Exception) { } - try { Console.Write("IP: " + msg.SenderEndPoint.Address.ToString() + ":" + msg.SenderEndPoint.Port.ToString() + " | "); } catch (Exception) { } - Console.Write("\n"); - if (!AllowOutdatedClients && (ScriptVersion)connReq.ScriptVersion != Enum.GetValues(typeof(ScriptVersion)).Cast().Last()) - { - var ReadableScriptVersion = Enum.GetValues(typeof(ScriptVersion)).Cast().Last().ToString(); - ReadableScriptVersion = Regex.Replace(ReadableScriptVersion, "VERSION_", "", RegexOptions.IgnoreCase); - ReadableScriptVersion = Regex.Replace(ReadableScriptVersion, "_", ".", RegexOptions.IgnoreCase); - Log.Info("Client " + connReq.DisplayName + " tried to connect with outdated scriptversion " + connReq.ScriptVersion.ToString() + " but the server requires " + Enum.GetValues(typeof(ScriptVersion)).Cast().Last().ToString()); - DenyPlayer(client, string.Format("Update to GTACoop v{0} from bit.ly/gtacoop", ReadableScriptVersion), true, msg); continue; - }else if (AllowOutdatedClients && (ScriptVersion)connReq.ScriptVersion != Enum.GetValues(typeof(ScriptVersion)).Cast().Last()) - { - SendNotificationToPlayer(client, "~r~You are using a outdated version of GTA Coop.~w~"); - SendNotificationToPlayer(client, "~h~If you have lags or issues, update your mod!~h~", true); - } - if ((ScriptVersion)connReq.ScriptVersion == ScriptVersion.VERSION_UNKNOWN) - { - Log.Info("Client " + connReq.DisplayName + " tried to connect with unknown scriptversion " + connReq.ScriptVersion.ToString()); - DenyPlayer(client, "Unknown version. Please redownload GTA Coop from bit.ly/gtacoop", true, msg); continue; - } - - int clients = 0; - lock (Clients) clients = Clients.Count; - if (clients < MaxPlayers) - { - if (PasswordProtected && !string.IsNullOrWhiteSpace(Password)) - { - if (Password != connReq.Password) - { - Log.Info(connReq.DisplayName + " connection refused: Wrong password: " + connReq.Password.ToString()); - DenyPlayer(client, "Wrong password.", true, msg); continue; - } - } - lock (Clients) - { - int duplicate = 0; - string displayname = connReq.DisplayName; - while (AllowNickNames && Clients.Any(c => c.DisplayName == connReq.DisplayName)) - { - duplicate++; - - connReq.DisplayName = displayname + " {" + duplicate + "}"; - } - - Clients.Add(client); - } - client.Name = connReq.Name; - client.DisplayName = AllowNickNames ? connReq.DisplayName : connReq.Name; - - if (client.RemoteScriptVersion != (ScriptVersion)connReq.ScriptVersion) client.RemoteScriptVersion = (ScriptVersion)connReq.ScriptVersion; - if (client.GameVersion != connReq.GameVersion) client.GameVersion = connReq.GameVersion; - PrintPlayerInfo(client, "New incoming connection: "); - - if (_gamemode != null) _gamemode.OnIncomingConnection(client); - if (_filterscripts != null) _filterscripts.ForEach(fs => fs.OnIncomingConnection(client)); - - var channelHail = Server.CreateMessage(); - channelHail.Write(GetChannelIdForConnection(client)); - client.NetConnection.Approve(channelHail); - } - else - { - Log.Info(client.DisplayName + " connection refused: server full with " + clients.ToString() + " of " + MaxPlayers + " players."); - DenyPlayer(client, "No available player slots.", true, msg); - } - break; - case NetIncomingMessageType.StatusChanged: - var newStatus = (NetConnectionStatus)msg.ReadByte(); - - if (newStatus == NetConnectionStatus.Connected) - { - bool sendMsg = true; - - Console.ForegroundColor = ConsoleColor.DarkGreen; PrintPlayerInfo(client, "Connected: "); Console.ResetColor(); - var path = Location + "geoip.mmdb"; - try - { - using (var reader = new DatabaseReader(path)) - { - client.geoIP = reader.Country(client.NetConnection.RemoteEndPoint.Address); - } - } - catch (Exception ex) { Log.Error("GeoIP Error: "+ex.Message); } - if (_gamemode != null) sendMsg = sendMsg && _gamemode.OnPlayerConnect(client); - _filterscripts?.ForEach(fs => sendMsg = sendMsg && fs.OnPlayerConnect(client)); - if (sendMsg && !client.Silent) - try - { - SendNotificationToAll("~h~" + client.DisplayName + "~h~~w~ connected from " + client.geoIP.Country.Name.ToString() + "."); - } - catch - { - SendNotificationToAll("~h~" + client.DisplayName + "~h~~w~ connected."); - } - } - else if (newStatus == NetConnectionStatus.Disconnected) - { - lock (Clients) - { - if (Clients.Contains(client)) - { - var sendMsg = true; - - if (_gamemode != null) sendMsg = sendMsg && _gamemode.OnPlayerDisconnect(client); - _filterscripts?.ForEach(fs => sendMsg = sendMsg && fs.OnPlayerDisconnect(client)); - if (client.NetConnection.RemoteEndPoint.Address.ToString().Equals(LastKicked)) { client.Silent = true; } - if (sendMsg && !client.Silent) - if (client.Kicked) - { - if (!client.KickReason.Equals("")) - { - if(client.KickedBy != null) - { - SendNotificationToAll("~h~" + client.DisplayName + "~h~~w~ was kicked by "+ client.KickedBy.DisplayName +"~w~ for " + client.KickReason); - } else - { - SendNotificationToAll("~h~" + client.DisplayName + "~h~~w~ was kicked for " + client.KickReason); - } - } - else - { - if (client.KickedBy != null) - { - SendNotificationToAll("~h~" + client.DisplayName + "~h~~w~ has been kicked by "+ client.KickedBy.DisplayName+"~w~."); - } - else - { - SendNotificationToAll("~h~" + client.DisplayName + "~h~~w~ has been kicked."); - } - } - } - else - { - SendNotificationToAll("~h~" + client.DisplayName + "~h~~w~ disconnected."); - } - - var dcObj = new PlayerDisconnect() - { - Id = client.NetConnection.RemoteUniqueIdentifier, - }; - - SendToAll(dcObj, PacketType.PlayerDisconnect, true); - - if (client.Kicked) - { - if (!client.KickReason.Equals("")) - { - Log.Info("Player kicked: \"" + client.Name + "\" (" + client.DisplayName + ") for " + client.KickReason); - } - else - { - Console.ForegroundColor = ConsoleColor.Red; PrintPlayerInfo(client, "Kicked: "); Console.ResetColor(); - } - } - else - { - Console.ForegroundColor = ConsoleColor.DarkRed; PrintPlayerInfo(client, "Disconnected: "); Console.ResetColor(); - } - LastKicked = client.NetConnection.RemoteEndPoint.Address.ToString(); - Clients.Remove(client); - } - } - } - break; - case NetIncomingMessageType.DiscoveryRequest: - NetOutgoingMessage response = Server.CreateMessage(); - var obj = new DiscoveryResponse(); - obj.ServerName = Name; - obj.MaxPlayers = MaxPlayers; - obj.PasswordProtected = PasswordProtected; - obj.Gamemode = GamemodeName; - lock (Clients) obj.PlayerCount = Clients.Count; - obj.Port = Port; - - var bin = SerializeBinary(obj); - - response.Write((int)PacketType.DiscoveryResponse); - response.Write(bin.Length); - response.Write(bin); - - Log.Debug("Server Status requested by " + msg.SenderEndPoint.Address); - Server.SendDiscoveryResponse(response, msg.SenderEndPoint); - break; - case NetIncomingMessageType.Data: - var packetType = (PacketType)msg.ReadInt32(); - - switch (packetType) - { - case PacketType.ChatData: - { - try - { - var len = msg.ReadInt32(); - var data = DeserializeBinary(msg.ReadBytes(len)) as ChatData; - if (data != null) - { - var Msg = new ChatMessage(); - Msg.Message = data.Message; - Msg.Sender = client; - if (_gamemode != null) Msg = _gamemode.OnChatMessage(Msg); - - _filterscripts?.ForEach(fs => Msg = fs.OnChatMessage(Msg)); - - if (!Msg.Supress) - { - data.Id = client.NetConnection.RemoteUniqueIdentifier; - if (!string.IsNullOrWhiteSpace(Msg.Prefix)) - data.Sender += "[" + Msg.Prefix + "] "; - data.Sender += client.DisplayName; - if (!string.IsNullOrWhiteSpace(Msg.Suffix)) - data.Sender += " (" + Msg.Suffix + ") "; - SendToAll(data, PacketType.ChatData, true); - Log.Info("[CHAT] <" + data.Sender + ">" + ": " + data.Message); - } - } - } - catch { } - } - break; - case PacketType.VehiclePositionData: - { - try - { - var len = msg.ReadInt32(); - var data = - DeserializeBinary(msg.ReadBytes(len)) as - VehicleData; - if (data != null) - { - data.Id = client.NetConnection.RemoteUniqueIdentifier; - data.Name = client.DisplayName; - data.Latency = client.Latency; - - client.Health = data.PlayerHealth; - client.LastKnownPosition = data.Position; - client.VehicleHealth = data.VehicleHealth; - client.IsInVehicle = true; - - SendToAll(data, PacketType.VehiclePositionData, false, client); - } - } - catch (IndexOutOfRangeException) - { } - } - break; - case PacketType.PedPositionData: - { - try - { - var len = msg.ReadInt32(); - var data = DeserializeBinary(msg.ReadBytes(len)) as PedData; - if (data != null) - { - data.Id = client.NetConnection.RemoteUniqueIdentifier; - data.Name = client.DisplayName; - data.Latency = client.Latency; - - client.Health = data.PlayerHealth; - client.LastKnownPosition = data.Position; - client.IsInVehicle = false; - - SendToAll(data, PacketType.PedPositionData, false, client); - } - } - catch (IndexOutOfRangeException) - { } - } - break; - case PacketType.NpcVehPositionData: - { - try - { - int len = msg.ReadInt32(); - var data = - DeserializeBinary(msg.ReadBytes(len)) as - VehicleData; - if (data != null) - { - data.Id = client.NetConnection.RemoteUniqueIdentifier; - SendToAll(data, PacketType.NpcVehPositionData, false, client); - } - } - catch (IndexOutOfRangeException) - { } - } - break; - case PacketType.VoiceChatData: - { - int len = msg.ReadInt32(); - var data = DeserializeBinary(msg.ReadBytes(len)) as VoiceChatData; - if (data != null) - { - data.Id = msg.SenderConnection.RemoteUniqueIdentifier; - SendToAll(data, PacketType.VoiceChatData, false, client); - } - } - break; - - case PacketType.NpcPedPositionData: - { - try - { - var len = msg.ReadInt32(); - var data = DeserializeBinary(msg.ReadBytes(len)) as PedData; - if (data != null) - { - data.Id = msg.SenderConnection.RemoteUniqueIdentifier; - SendToAll(data, PacketType.NpcPedPositionData, false, client); - } - } - catch (IndexOutOfRangeException) - { } - } - break; - case PacketType.WorldSharingStop: - { - var dcObj = new PlayerDisconnect() - { - Id = client.NetConnection.RemoteUniqueIdentifier, - }; - SendToAll(dcObj, PacketType.WorldSharingStop, true); - } - break; - case PacketType.NativeResponse: - { - var len = msg.ReadInt32(); - var data = DeserializeBinary(msg.ReadBytes(len)) as NativeResponse; - if (data == null || !_callbacks.ContainsKey(data.Id)) continue; - object resp = null; - if (data.Response is IntArgument) - { - resp = ((IntArgument)data.Response).Data; - } - else if (data.Response is UIntArgument) - { - resp = ((UIntArgument)data.Response).Data; - } - else if (data.Response is StringArgument) - { - resp = ((StringArgument)data.Response).Data; - } - else if (data.Response is FloatArgument) - { - resp = ((FloatArgument)data.Response).Data; - } - else if (data.Response is BooleanArgument) - { - resp = ((BooleanArgument)data.Response).Data; - } - else if (data.Response is Vector3Argument) - { - var tmp = (Vector3Argument)data.Response; - resp = new Vector3() - { - X = tmp.X, - Y = tmp.Y, - Z = tmp.Z, - }; - } - if (_callbacks.ContainsKey(data.Id)) - _callbacks[data.Id].Invoke(resp); - _callbacks.Remove(data.Id); - } - break; - case PacketType.PlayerSpawned: - { - if (_gamemode != null) _gamemode.OnPlayerSpawned(client); - if (_filterscripts != null) _filterscripts.ForEach(fs => fs.OnPlayerSpawned(client)); - PrintPlayerInfo(client, "Player spawned: "); - } - break; - } - break; - default: - Log.Warn("Unhandled type: " + msg.MessageType); - break; - } - Server.Recycle(msg); - } - if (_gamemode != null) _gamemode.OnTick(); - if (_filterscripts != null) _filterscripts.ForEach(fs => fs.OnTick()); - }catch(Exception ex) { Log.Error("Can't handle tick: "+ex.ToString()); } - } - - /// - /// Prints info about the server - /// - public void Infoscreen() - { - while (true) - { - PrintServerInfo(); - PrintPlayerList(); - Thread.Sleep(60000); - } - } - /// - /// Prints a list of players - /// - /// - public void PrintPlayerList(string message = "Online Players: ") - { - for (var i = 0; i < Clients.Count; i++) - { - PrintPlayerInfo(Clients[i], "#"+i.ToString()+ " "); - } - } - /// - /// Prints info about a player to the console - /// - /// Client to print info for - /// Prefix to the info - public void PrintPlayerInfo( Client client, string message = "Player Info: ") - { - Console.Write(message); - try { Console.Write("Nickname: " + client.DisplayName.ToString() + " | "); } catch (Exception) { } - try { Console.Write("Name: " + client.Name.ToString() + " | "); } catch (Exception) { } - try { Console.Write("Game Version: " + client.GameVersion.ToString() + " | "); } catch (Exception) { } - try { Console.Write("Script Version: " + client.RemoteScriptVersion.ToString() + " | "); } catch (Exception) { } - try { Console.Write("Health: " + client.Health.ToString() + " | "); } catch (Exception) { } - try { Console.Write("Vehicle: " + client.IsInVehicle.ToString() + " | "); } catch (Exception) { } - try { if(client.IsInVehicle) Console.Write("Veh Health: " + client.VehicleHealth.ToString() + " | "); } catch (Exception) { } - try { Console.Write("Position: X:" + client.LastKnownPosition.X.ToString() + " Y: " + client.LastKnownPosition.Y.ToString() + " Z: " + client.LastKnownPosition.Z.ToString() + " | "); } catch (Exception) { } - try { Console.Write("IP: " + client.NetConnection.RemoteEndPoint.Address.ToString() + ":" + client.NetConnection.RemoteEndPoint.Port.ToString() + " | "); } catch (Exception) { } - try { if((client.Latency * 1000) > 0)Console.Write("Ping: " + (client.Latency*1000).ToString() + " | "); } catch (Exception) { } - try { Console.Write("Status: " + client.NetConnection.Status.ToString() + " | "); } catch (Exception) { } - try { Console.Write("NetUID: " + client.NetConnection.RemoteUniqueIdentifier.ToString() + " | "); } catch (Exception) { } - try { Console.Write("MPU: " + client.NetConnection.CurrentMTU.ToString() + " | "); } catch (Exception) { } - try { Console.Write("Continent: " + client.geoIP.Continent.Name + " | "); } catch (Exception) { } - try { Console.Write("Country: " + client.geoIP.Country.Name + " [" + client.geoIP.Country.IsoCode + "] | "); } catch (Exception) { } - /*try { Console.Write("City: " + client.geoIP.City + " | "); } catch (Exception) { } - try { Console.Write("Sent Messages: " + client.NetConnection.Statistics.SentMessages.ToString() + " | "); } catch (Exception) { } - try { Console.Write("Recieved Messages: " + client.NetConnection.Statistics.ReceivedMessages.ToString() + " | "); } catch (Exception) { } - try { Console.Write("Dropped Messages: " + client.NetConnection.Statistics.DroppedMessages.ToString() + " | "); } catch (Exception) { } - try { Console.Write("Sent Bytes: " + client.NetConnection.Statistics.SentBytes.ToString() + " | "); } catch (Exception) { } - try { Console.Write("Recieved Bytes: " + client.NetConnection.Statistics.ReceivedBytes.ToString() + " | "); } catch (Exception) { }*/ - Console.Write("\n");//Console.Write("\n"); - } - /// - /// Prints server info - /// - /// Message prefix - public void PrintServerInfo( string message = "Server Info: ") - { - Console.Write(message); - try { Console.Write("Name: " + Name.ToString() + " | "); } catch (Exception) { } - try { Console.Write("Password?: " + PasswordProtected.ToString() + " | "); } catch (Exception) { } - try { int playersonline = 0; lock (Clients) playersonline = Clients.Count; - Console.Write("Players: " + playersonline.ToString() + " / " + MaxPlayers + " | "); } catch (Exception) { } - try { Console.Write("Gamemode: " + GamemodeName.ToString() + " | "); } catch (Exception) { } - Console.Write("\n"); - } - - /// - /// Stop the server - /// - public void Stop() - { - foreach (Client player in Clients) - { - KickPlayer(player, "Server shutting down"); - } - Server.Shutdown("Stopping server"); - } - - /// - /// Send a packet to all players - /// - /// Object to send - /// Packet type - /// If the packet is important (does it need to be sent in a specific order) - public void SendToAll(object newData, PacketType packetType, bool important) - { - try - { - var data = SerializeBinary(newData); - NetOutgoingMessage msg = Server.CreateMessage(); - msg.Write((int) packetType); - msg.Write(data.Length); - msg.Write(data); - Server.SendToAll(msg, - important ? NetDeliveryMethod.ReliableOrdered : NetDeliveryMethod.ReliableSequenced); - } - catch (Exception ex) - { - Log.Error("Error in SendToAll: " + ex.Message); - } - } - - /// - /// Send a packet to all but one - /// - /// Object to send - /// Packet type - /// If the packet is important - /// Client to exclude from the message - public void SendToAll(object newData, PacketType packetType, bool important, Client exclude) - { - var data = SerializeBinary(newData); - NetOutgoingMessage msg = Server.CreateMessage(); - msg.Write((int)packetType); - msg.Write(data.Length); - msg.Write(data); - Server.SendToAll(msg, exclude.NetConnection, important ? NetDeliveryMethod.ReliableOrdered : NetDeliveryMethod.ReliableSequenced, GetChannelIdForConnection(exclude)); - } - - /// - /// Deserialize a binary packet - /// - /// Type expected from the packet - /// Byte array of packet data - /// Deserialized object for packet - public object DeserializeBinary(byte[] data) - { - using (var stream = new MemoryStream(data)) - { - try - { - return Serializer.Deserialize(stream); - } - catch (ProtoException e) - { - Log.Warn("WARN: Deserialization failed: " + e.Message); - return null; - } - } - } - - /// - /// Serialize an object into a byte array - /// - /// Object to serialize - /// What the data returns - public byte[] SerializeBinary(object data) - { - using (var stream = new MemoryStream()) - { - Serializer.Serialize(stream, data); - return stream.ToArray(); - } - } - /// - /// Get channel ID for a client connection - /// - /// Client to get the channel ID for - /// Channel ID of client - public int GetChannelIdForConnection(Client conn) - { - lock (Clients) return (Clients.IndexOf(conn) % 31) + 1; - } - - /// - /// Parse native arguments sent from client - /// - /// Object array of native args - /// List of NativeArguments - private List ParseNativeArguments(params object[] args) - { - var list = new List(); - foreach (var o in args) - { - if (o is int) - { - list.Add(new IntArgument() { Data = ((int)o) }); - } - else if (o is uint) - { - list.Add(new UIntArgument() { Data = ((uint)o) }); - } - else if (o is string) - { - list.Add(new StringArgument() { Data = ((string)o) }); - } - else if (o is float) - { - list.Add(new FloatArgument() { Data = ((float)o) }); - } - else if (o is bool) - { - list.Add(new BooleanArgument() { Data = ((bool)o) }); - } - else if (o is Vector3) - { - var tmp = (Vector3)o; - list.Add(new Vector3Argument() - { - X = tmp.X, - Y = tmp.Y, - Z = tmp.Z, - }); - } - else if (o is LocalPlayerArgument) - { - list.Add((LocalPlayerArgument)o); - } - else if (o is OpponentPedHandleArgument) - { - list.Add((OpponentPedHandleArgument)o); - } - else if (o is LocalGamePlayerArgument) - { - list.Add((LocalGamePlayerArgument)o); - } - } - - return list; - } - - /// - /// Send a native call to a player - /// - /// Client to send the call to - /// Native call hash - /// Arguments to native call - public void SendNativeCallToPlayer(Client player, ulong hash, params object[] arguments) - { - var obj = new NativeData - { - Hash = hash, - Arguments = ParseNativeArguments(arguments) - }; - - var bin = SerializeBinary(obj); - - var msg = Server.CreateMessage(); - - msg.Write((int)PacketType.NativeCall); - msg.Write(bin.Length); - msg.Write(bin); - - player.NetConnection.SendMessage(msg, NetDeliveryMethod.ReliableOrdered, GetChannelIdForConnection(player)); - } - - /// - /// Send a native call to all players - /// - /// Hash of the native call - /// Arguments to the native call - public void SendNativeCallToAllPlayers(ulong hash, params object[] arguments) - { - var obj = new NativeData - { - Hash = hash, - Arguments = ParseNativeArguments(arguments), - ReturnType = null, - Id = null - }; - - var bin = SerializeBinary(obj); - - var msg = Server.CreateMessage(); - - msg.Write((int)PacketType.NativeCall); - msg.Write(bin.Length); - msg.Write(bin); - - Server.SendToAll(msg, NetDeliveryMethod.ReliableOrdered); - } - - /// - /// Set a native call to be run on a tick - /// - /// Player to run the call - /// Unique ID for the call - /// Hash of the native - /// Arguments to the native - public void SetNativeCallOnTickForPlayer(Client player, string identifier, ulong hash, params object[] arguments) - { - var obj = new NativeData - { - Hash = hash, - Arguments = ParseNativeArguments(arguments) - }; - - - var wrapper = new NativeTickCall(); - wrapper.Identifier = identifier; - wrapper.Native = obj; - - var bin = SerializeBinary(wrapper); - - var msg = Server.CreateMessage(); - - msg.Write((int)PacketType.NativeTick); - msg.Write(bin.Length); - msg.Write(bin); - - player.NetConnection.SendMessage(msg, NetDeliveryMethod.ReliableOrdered, GetChannelIdForConnection(player)); - } - - /// - /// Set a native call to be run on a tick for all players - /// - /// Unique ID for the call - /// Hash of the native - /// Arguments to the native call - public void SetNativeCallOnTickForAllPlayers(string identifier, ulong hash, params object[] arguments) - { - var obj = new NativeData - { - Hash = hash, - Arguments = ParseNativeArguments(arguments) - }; - - - var wrapper = new NativeTickCall - { - Identifier = identifier, - Native = obj - }; - - var bin = SerializeBinary(wrapper); - - var msg = Server.CreateMessage(); - - msg.Write((int)PacketType.NativeTick); - msg.Write(bin.Length); - msg.Write(bin); - - Server.SendToAll(msg, NetDeliveryMethod.ReliableOrdered); - } - /// - /// Remove a native call from being run on a tick for a specific player - /// - /// Client the native was being run on - /// Identifier for the native call - public void RecallNativeCallOnTickForPlayer(Client player, string identifier) - { - var wrapper = new NativeTickCall {Identifier = identifier}; - - var bin = SerializeBinary(wrapper); - - var msg = Server.CreateMessage(); - msg.Write((int)PacketType.NativeTickRecall); - msg.Write(bin.Length); - msg.Write(bin); - - player.NetConnection.SendMessage(msg, NetDeliveryMethod.ReliableOrdered, GetChannelIdForConnection(player)); - } - /// - /// Remove a native call from being run on a tick for all players - /// - /// Identifier for the native call - public void RecallNativeCallOnTickForAllPlayers(string identifier) - { - var wrapper = new NativeTickCall {Identifier = identifier}; - - var bin = SerializeBinary(wrapper); - - var msg = Server.CreateMessage(); - msg.Write((int)PacketType.NativeTickRecall); - msg.Write(bin.Length); - msg.Write(bin); - - Server.SendToAll(msg, NetDeliveryMethod.ReliableOrdered); - } - /// - /// Set a native call to be run on disconnect for a player - /// - /// Player to run the native on - /// Identifier for the native - /// Hash of the native call - /// Arguments to the native call - public void SetNativeCallOnDisconnectForPlayer(Client player, string identifier, ulong hash, params object[] arguments) - { - var obj = new NativeData - { - Hash = hash, - Id = identifier, - Arguments = ParseNativeArguments(arguments) - }; - - - var bin = SerializeBinary(obj); - - var msg = Server.CreateMessage(); - - msg.Write((int)PacketType.NativeOnDisconnect); - msg.Write(bin.Length); - msg.Write(bin); - - player.NetConnection.SendMessage(msg, NetDeliveryMethod.ReliableOrdered, GetChannelIdForConnection(player)); - } - /// - /// Set a native call to be run no disconnect for all players - /// - /// Identifier for the native call - /// Hash for the native call - /// Arguments for the native - public void SetNativeCallOnDisconnectForAllPlayers(string identifier, ulong hash, params object[] arguments) - { - var obj = new NativeData - { - Hash = hash, - Id = identifier, - Arguments = ParseNativeArguments(arguments) - }; - - var bin = SerializeBinary(obj); - - var msg = Server.CreateMessage(); - - msg.Write((int)PacketType.NativeOnDisconnect); - msg.Write(bin.Length); - msg.Write(bin); - - Server.SendToAll(msg, NetDeliveryMethod.ReliableOrdered); - } - /// - /// Remove a native call from being run on disconnect for a player - /// - /// Player to remove it from - /// Identifier for the native call - public void RecallNativeCallOnDisconnectForPlayer(Client player, string identifier) - { - var obj = new NativeData {Id = identifier}; - - var bin = SerializeBinary(obj); - - var msg = Server.CreateMessage(); - msg.Write((int)PacketType.NativeOnDisconnectRecall); - msg.Write(bin.Length); - msg.Write(bin); - - player.NetConnection.SendMessage(msg, NetDeliveryMethod.ReliableOrdered, GetChannelIdForConnection(player)); - } - /// - /// Remove a native call from being run on disconnect for all players - /// - /// Identifier for the native call - public void RecallNativeCallOnDisconnectForAllPlayers(string identifier) - { - var obj = new NativeData {Id = identifier}; - - var bin = SerializeBinary(obj); - - var msg = Server.CreateMessage(); - msg.Write((int)PacketType.NativeOnDisconnectRecall); - msg.Write(bin.Length); - msg.Write(bin); - - Server.SendToAll(msg, NetDeliveryMethod.ReliableOrdered); - } - - /// - /// List of callbacks for data returned from native calls - /// - private Dictionary> _callbacks = new Dictionary>(); - - /// - /// Run a native on a player, then get the response - /// - /// Player to run the native on - /// Salt for the native call - /// Hash of the native call - /// NativeArgument return type - /// Callback to call with the native response. - /// Arguments to the native call - public void GetNativeCallFromPlayer(Client player, string salt, ulong hash, NativeArgument returnType, Action callback, - params object[] arguments) - { - var obj = new NativeData - { - Hash = hash, - ReturnType = returnType - }; - salt = Environment.TickCount.ToString() + - salt + - player.NetConnection.RemoteUniqueIdentifier.ToString() + - DateTime.Now.Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalMilliseconds.ToString(); - obj.Id = salt; - obj.Arguments = ParseNativeArguments(arguments); - - var bin = SerializeBinary(obj); - - var msg = Server.CreateMessage(); - - msg.Write((int)PacketType.NativeCall); - msg.Write(bin.Length); - msg.Write(bin); - - _callbacks.Add(salt, callback); - player.NetConnection.SendMessage(msg, NetDeliveryMethod.ReliableOrdered, GetChannelIdForConnection(player)); - } - - // SCRIPTING - /// - /// Send a chat message to all players - /// - /// Message to send - public void SendChatMessageToAll(string message) - { - SendChatMessageToAll("", message); - } - /// - /// Send a chat message to all players - /// - /// Who sent the message - /// Message contents - public void SendChatMessageToAll(string sender, string message) - { - var chatObj = new ChatData() - { - Sender = sender, - Message = message, - }; - - SendToAll(chatObj, PacketType.ChatData, true); - } - /// - /// Send a chat message to a player - /// - /// Player to send the chat message to - /// Message contents - public void SendChatMessageToPlayer(Client player, string message) - { - SendChatMessageToPlayer(player, "", message); - } - /// - /// Send a chat message to a player - /// - /// Player to send chat message to - /// Who sent the message - /// Message contents - public void SendChatMessageToPlayer(Client player, string sender, string message) - { - var chatObj = new ChatData() - { - Sender = sender, - Message = message, - }; - - var data = SerializeBinary(chatObj); - - NetOutgoingMessage msg = Server.CreateMessage(); - msg.Write((int)PacketType.ChatData); - msg.Write(data.Length); - msg.Write(data); - player.NetConnection.SendMessage(msg, NetDeliveryMethod.ReliableOrdered, 0); - } - /// - /// Give a player a weapon - /// - /// Player to give weapon to - /// Hash of the weapon - /// How much ammo to give them - /// Whether we want the player to equip the weapon now - /// Whether we want the ammo to be loaded now or not - public void GivePlayerWeapon(Client player, uint weaponHash, int ammo, bool equipNow, bool ammoLoaded) - { - SendNativeCallToPlayer(player, 0xBF0FD6E56C964FCB, new LocalPlayerArgument(), weaponHash, ammo, equipNow, ammo); - } - /// - /// Kick a player from the server - /// - /// Player to kick from the server - /// Reason for kicking the player - /// Whether or not the kick is silent - /// - public void KickPlayer(Client player, string reason, bool silent = false, Client sender = null) - { - player.Kicked = true; // Wtf Bluscream, are you allergic to newlines? This was all one line before... - player.KickReason = reason.ToString(); - player.Silent = silent; - player.KickedBy = sender; - player.NetConnection.Disconnect("Kicked: " + reason); - } - /// - /// Deny a player from connecting - /// - /// Player to deny from connecting - /// Reason for connection denial - /// Whether to silently deny the player - /// Message the player was denied with (only passed for recycling) - /// How long to deny the player (default: 60, currently unused) - public void DenyPlayer(Client player, string reason, bool silent = true, NetIncomingMessage msg = null, int duration = 60) - { - _gamemode?.OnConnectionRefused(player, reason); - _filterscripts?.ForEach(fs => fs.OnConnectionRefused(player, reason)); - player.NetConnection.Deny(reason); - - Console.ForegroundColor = ConsoleColor.DarkRed; - PrintPlayerInfo(player, "Connection Denied: "+ reason + " || "); - Console.ResetColor(); - - if (!silent) - SendNotificationToAll(player.DisplayName + " was rejected by the server: " + reason); - - string _ip = player.NetConnection.RemoteEndPoint.Address.ToString(); - Clients.Remove(player); - if (msg != null) Server.Recycle(msg); - //BlockIP(_ip, "GTAServer Block (" + _ip + ")", duration); - } - - /*public void DenyConnection(Client player, string reason, bool silent = true, NetIncomingMessage msg = null) - { - player. (reason); - Console.ForegroundColor = ConsoleColor.DarkRed; PrintPlayerInfo(player, "Connection Denied: " + reason + " || "); Console.ResetColor(); - if (!silent) SendNotificationToAll(player.DisplayName + " was rejected by the server: " + reason); - Clients.Remove(player);if (msg != null) Server.Recycle(msg); - }*/ - /// - /// Teleport a player - /// - /// Player to teleport - /// New player position - public void SetPlayerPosition(Client player, Vector3 newPosition) - { - SendNativeCallToPlayer(player, 0x06843DA7060A026B, new LocalPlayerArgument(), newPosition.X, newPosition.Y, newPosition.Z, 0, 0, 0, 1); - } - - /// - /// Get a player's position - /// - /// Player to get position of - /// Callback to call with the result - /// Salt of the native call - public void GetPlayerPosition(Client player, Action callback, string salt = "salt") - { - GetNativeCallFromPlayer(player, - salt, - 0x3FEF770D40960D5A, new Vector3Argument(), callback, new LocalPlayerArgument(), 0); - } - - /// - /// Checks if a player control has been pressed - /// - /// Player to check if a control has been pressed on - /// Control ID - /// Callback to call with the result - /// Salt of the native call - public void HasPlayerControlBeenPressed(Client player, int controlId, Action callback, string salt = "salt") - { - GetNativeCallFromPlayer(player, salt, - 0x580417101DDB492F, new BooleanArgument(), callback, 0, controlId); - } - - /// - /// Set a player's health - /// - /// Player - /// New health - public void SetPlayerHealth(Client player, int health) - { - SendNativeCallToPlayer(player, 0x6B76DC1F3AE6E6A3, new LocalPlayerArgument(), health + 100); - } - - /// - /// Send a notification to a player - /// - /// Player to send notification to - /// Message in the notification - /// Whether to flash the notification - public void SendNotificationToPlayer(Client player, string message, bool flashing = false) - { - for (int i = 0; i < message.Length; i += 99) - { - SendNativeCallToPlayer(player, 0x202709F4C58A0424, "STRING"); - SendNativeCallToPlayer(player, 0x6C188BE134E074AA, message.Substring(i, Math.Min(99, message.Length - i))); - SendNativeCallToPlayer(player, 0xF020C96915705B3A, flashing, true); - } - } - /// - /// Send a notification to all players - /// - /// Message in the notification - /// Whether to flash the notification - public void SendNotificationToAll(string message, bool flashing = false) - { - for (int i = 0; i < message.Length; i += 99) - { - SendNativeCallToAllPlayers(0x202709F4C58A0424, "STRING"); - SendNativeCallToAllPlayers(0x6C188BE134E074AA, message.Substring(i, Math.Min(99, message.Length - i))); - SendNativeCallToAllPlayers(0xF020C96915705B3A, flashing, true); - } - } - - /// - /// Send a picture notification to a player - /// - /// Player to send the notification to - /// Body of message - /// NotificationPicType for message - /// Times to flash the message - /// NotificationIconType of the message - /// Sender of the message - /// Subject of them essage - public void SendPictureNotificationToPlayer(Client player, string body, NotificationPicType pic, int flash, NotificationIconType iconType, string sender, string subject) - { - //Crash with new LocalPlayerArgument()! - SendNativeCallToPlayer(player, 0x202709F4C58A0424, "STRING"); - SendNativeCallToPlayer(player, 0x6C188BE134E074AA, body); - SendNativeCallToPlayer(player, 0x1CCD9A37359072CF, pic.ToString(), pic.ToString(), flash, (int)iconType, sender, subject); - SendNativeCallToPlayer(player, 0xF020C96915705B3A, false, true); - } - /// - /// Send a picture notification to all players - /// - /// Body of message - /// NotificationPicType for message - /// Times to flash the message - /// NotificationIconType of the message - /// Sender of the message - /// Subject of them essage - public void SendPictureNotificationToAll(string body, NotificationPicType pic, int flash, NotificationIconType iconType, string sender, string subject) - { - //Crash with new LocalPlayerArgument()! - SendNativeCallToAllPlayers(0x202709F4C58A0424, "STRING"); - SendNativeCallToAllPlayers(0x6C188BE134E074AA, body); - SendNativeCallToAllPlayers(0x1CCD9A37359072CF, pic.ToString(), pic.ToString(), flash, (int)iconType, sender, subject); - SendNativeCallToAllPlayers(0xF020C96915705B3A, false, true); - } - /// - /// Send a picture notification to all players - /// - /// Body of message - /// NotificationPicType for message - /// Times to flash the message - /// NotificationIconType of the message - /// Sender of the message - /// Subject of them essage - public void SendPictureNotificationToAll(string body, string pic, int flash, int iconType, string sender, string subject) - { - //Crash with new LocalPlayerArgument()! - SendNativeCallToAllPlayers(0x202709F4C58A0424, "STRING"); - SendNativeCallToAllPlayers(0x6C188BE134E074AA, body); - SendNativeCallToAllPlayers(0x1CCD9A37359072CF, pic, pic, flash, iconType, sender, subject); - SendNativeCallToAllPlayers(0xF020C96915705B3A, false, true); - } - - /// - /// Get a player's health - /// - /// Player to get health of - /// Callback to call with result - /// Salt of native call - public void GetPlayerHealth(Client player, Action callback, string salt = "salt") - { - GetNativeCallFromPlayer(player, salt, - 0xEEF059FAD016D209, new IntArgument(), callback, new LocalPlayerArgument()); - } - /// - /// Set night vision status of player - /// - /// Player to set night vision of - /// Night vision true/false - public void ToggleNightVisionForPlayer(Client player, bool status) - { - SendNativeCallToPlayer(player, 0x18F621F7A5B1F85D, status); - } - /// - /// Toggle night vision for all players - /// - /// Night vision true/false - public void ToggleNightVisionForAll(bool status) - { - SendNativeCallToAllPlayers(0x18F621F7A5B1F85D, status); - } - /// - /// Checks if night vision is active - /// - /// Player to check if night vision is active on - /// Callback to call with result - /// Salt for native call - public void IsNightVisionActive(Client player, Action callback, string salt = "salt") - { - GetNativeCallFromPlayer(player, salt, 0x2202A3F42C8E5F79, new BooleanArgument(), callback, new LocalPlayerArgument()); - } - /*const string guidFWPolicy2 = "{E2B3C97F-6AE1-41AC-817A-F6F92166D7DD}"; - const string guidRWRule = "{2C5BC43E-3369-4C33-AB0C-BE9469677AF4}"; - public void BlockIPviaFirewall(string ip, string name = "Blocked by GTAServer", int duration = -1, string port = "4499") - { - Type typeFWPolicy2 = Type.GetTypeFromCLSID(new Guid(guidFWPolicy2)); - Type typeFWRule = Type.GetTypeFromCLSID(new Guid(guidRWRule)); - NetFwTypeLib.INetFwPolicy2 fwPolicy2 = (NetFwTypeLib.INetFwPolicy2)Activator.CreateInstance(typeFWPolicy2); - NetFwTypeLib.INetFwRule newRule = (NetFwTypeLib.INetFwRule)Activator.CreateInstance(typeFWRule); - newRule.Name = "InBound_Rule"; - newRule.Description = "Block inbound traffic from "+ip+" over TCP port "+port; - newRule.Protocol = (int)NetFwTypeLib.NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_TCP; - newRule.LocalPorts = port; - newRule.RemoteAddresses = ip; - newRule.Direction = NetFwTypeLib.NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_IN; - newRule.Enabled = true; - newRule.Grouping = "@firewallapi.dll,-23255"; - newRule.Profiles = fwPolicy2.CurrentProfileTypes; - newRule.Action = NetFwTypeLib.NET_FW_ACTION_.NET_FW_ACTION_BLOCK; - fwPolicy2.Rules.Add(newRule); - if(duration != -1) - { - ThreadStart StartPointMethod = null; - Thread t = new Thread(StartPointMethod); - t.Join(duration * 1000); - } - }*/ - - /// - /// Block an IP in the firewall - /// TODO: Make this not use the firewall and instead do an IP ban on the application side, like most software. - /// TODO: Make this work with more than just windows if we decide for some reason to keep using the firewall... - /// - /// IP to block - /// Name of firewall rule - /// Length to block IP - /// Port to block them on - private void BlockIP(string ip, string name = "Blocked by GTAServer", int duration = -1, string port = "") - { - if (!IsAdministrator()) { LogToConsole(3, false, "Firewall", "Not blocking " + ip + " cause the app is not started as admin."); return; } - if (string.IsNullOrEmpty(port)) { port = Port.ToString(); } - if (duration != -1) - { - cmdExec(null, "advfirewall firewall add rule name=\""+name+ "\" description=\"Block inbound traffic from " + ip+" over UDP port "+port+" for "+(duration).ToString()+ " seconds.\" dir=in interface=any action=block protocol=udp localport=" + port+" remoteip="+ip, "netsh.exe", true); - cmdExec(null, "ping 127.0.0.1 - n " + (duration + 1).ToString() + " > nul & netsh advfirewall firewall delete rule name = all dir =in protocol = udp localport = " + port + " remoteip = " + ip, "cmd.exe"); - LogToConsole(2, false, "Firewall", "Blocked " + ip + " for "+duration+ " seconds!"); - } - else { - cmdExec("netsh advfirewall firewall add rule name=\"" +name +"\" description=\"Block inbound traffic from "+ip+" over UDP port "+port+"\" dir=in interface=any action=block localport="+port+" remoteip="+ip); - LogToConsole(2, false, "Firewall", "Blocked " + ip + " permanently!"); - } - } - /// - /// Checks if server is running as admin. - /// IMO the only reason that this should be used is to check if the user is _not_ admin when they start a server... servers running as admin is a terrible idea in general - /// (think: any exploits in the server? person who exploits them gets admin.) - /// - /// If the server is running as admin - public static bool IsAdministrator() - { - return (new WindowsPrincipal(WindowsIdentity.GetCurrent())) - .IsInRole(WindowsBuiltInRole.Administrator); - } - /*public static void cmdExec2(string exec, string arg = null, string app = @"C:\Windows\System32\cmd.exe", bool waitForExit = false) - { - var psi = new ProcessStartupInfo - { - Arguments = $"advfirewall firewall add rule name={name} description=Block inbound traffic from {ip} over TCP port {port} dir=in interface=any action=block localport={port} remoteip={ip} && ping 127.0.0.1 -n {duration * 1000 + 1} > nul && advfirewall firewall delete rule dir=in localport={port} remoteip={ip}", - FileName = "netsh.exe", - using (var process = Process.Start(psi)) - { - process.WaitForExit(); - } - }*/ - /// - /// Run a command on the system - /// - /// Command to run - /// Command arguments - /// Application to run the command in (default: cmd.exe) - /// Wait for the command to exit - public static void cmdExec(string exec, string arg = null, string app = @"C:\Windows\System32\cmd.exe", bool waitForExit = false) - { - ProcessStartInfo cmdStartInfo = new ProcessStartInfo(); - cmdStartInfo.FileName = app; - if (!string.IsNullOrEmpty(arg)) { cmdStartInfo.Arguments = arg; } - cmdStartInfo.RedirectStandardOutput = true; - cmdStartInfo.RedirectStandardInput = true; - cmdStartInfo.UseShellExecute = false; - cmdStartInfo.CreateNoWindow = true; - Process cmdProcess = new Process(); - cmdProcess.StartInfo = cmdStartInfo; - /*using (var process = cmdProcess.Start()) - { - process.WaitForExit(); - }*/ - if (!string.IsNullOrEmpty(exec)) - { - cmdProcess.StandardInput.WriteLine(exec); - } - if (waitForExit) - { - cmdProcess.WaitForExit(); - } - } - /// - /// Read from a command - /// - /// Command to run - /// Arguments to command - /// Application to run the command in (default: cmd.exe) - public static void ReadFromCMD(string exec, string arg = null, string app = @"C:\Windows\System32\cmd.exe") - { - ProcessStartInfo cmdStartInfo = new ProcessStartInfo(); - cmdStartInfo.FileName = app; - if (!string.IsNullOrEmpty(arg)) { cmdStartInfo.Arguments = arg; } - cmdStartInfo.RedirectStandardOutput = true; - cmdStartInfo.RedirectStandardError = true; - cmdStartInfo.RedirectStandardInput = true; - cmdStartInfo.UseShellExecute = false; - cmdStartInfo.CreateNoWindow = true; - - Process cmdProcess = new Process(); - cmdProcess.StartInfo = cmdStartInfo; - cmdProcess.ErrorDataReceived += cmd_Error; - cmdProcess.OutputDataReceived += cmd_DataReceived; - cmdProcess.EnableRaisingEvents = true; - cmdProcess.Start(); - cmdProcess.BeginOutputReadLine(); - cmdProcess.BeginErrorReadLine(); - - if (!string.IsNullOrEmpty(exec)) - { - cmdProcess.StandardInput.WriteLine(exec); - } - //cmdProcess.WaitForExit(); - } - - /// - /// No idea, to be honest. Called with a DataReceivedEventArgs... - /// - /// Unused... - /// DataReceivedEventArgs - static void cmd_DataReceived(object sender, DataReceivedEventArgs e) - { - Log.Debug("Output from other process"); - Log.Debug(e.Data); - } - - /// - /// No idea, to be honest. Called with a DataReceivedEventArgs... - /// - /// Unused... - /// DataReceivedEventArgs - static void cmd_Error(object sender, DataReceivedEventArgs e) - { - Log.Debug("Error from other process"); - Log.Debug(e.Data); - } - } - } diff --git a/Server/NativeData.cs b/Server/NativeData.cs deleted file mode 100644 index 5ab9425..0000000 --- a/Server/NativeData.cs +++ /dev/null @@ -1,208 +0,0 @@ -using System; -using System.Collections.Generic; -using ProtoBuf; - -namespace GTAServer -{ - /// - /// Native call response - /// - [ProtoContract] - public class NativeResponse - { - /// - /// Response contents - /// - [ProtoMember(1)] - public NativeArgument Response { get; set; } - /// - /// Response ID - /// - [ProtoMember(2)] - public string Id { get; set; } - } - - /// - /// Native tick call - /// - [ProtoContract] - public class NativeTickCall - { - /// - /// Native data - /// - [ProtoMember(1)] - public NativeData Native { get; set; } - /// - /// Native identifier - /// - [ProtoMember(2)] - public string Identifier { get; set; } - } - - /// - /// Native data - /// - [ProtoContract] - public class NativeData - { - /// - /// Hash to call - /// - [ProtoMember(1)] - public ulong Hash { get; set; } - /// - /// Arguments - /// - [ProtoMember(2)] - public List Arguments { get; set; } - /// - /// Native argument return type - /// - [ProtoMember(3)] - public NativeArgument ReturnType { get; set; } - /// - /// Native call ID - /// - [ProtoMember(4)] - public string Id { get; set; } - } - - /// - /// Native argument - /// - [ProtoContract] - [ProtoInclude(2, typeof(IntArgument))] - [ProtoInclude(3, typeof(UIntArgument))] - [ProtoInclude(4, typeof(StringArgument))] - [ProtoInclude(5, typeof(FloatArgument))] - [ProtoInclude(6, typeof(BooleanArgument))] - [ProtoInclude(7, typeof(LocalPlayerArgument))] - [ProtoInclude(8, typeof(Vector3Argument))] - [ProtoInclude(9, typeof(LocalGamePlayerArgument))] - public class NativeArgument - { - /// - /// Native argument ID - /// - [ProtoMember(1)] - public string Id { get; set; } - } - - /// - /// Local player argument - /// - [ProtoContract] - public class LocalPlayerArgument : NativeArgument - { - } - /// - /// Local game player argument - /// - [ProtoContract] - public class LocalGamePlayerArgument : NativeArgument - { - } - /// - /// Opponent ped handle argument - /// - [ProtoContract] - public class OpponentPedHandleArgument : NativeArgument - { - public OpponentPedHandleArgument(long opponentHandle) - { - Data = opponentHandle; - } - /// - /// Ped data - /// - [ProtoMember(1)] - public long Data { get; set; } - } - - /// - /// Int argument - /// - [ProtoContract] - public class IntArgument : NativeArgument - { - /// - /// Integer - /// - [ProtoMember(1)] - public int Data { get; set; } - } - /// - /// UInt argument - /// - [ProtoContract] - public class UIntArgument : NativeArgument - { - /// - /// Unsigned integer - /// - [ProtoMember(1)] - public uint Data { get; set; } - } - - /// - /// String argument - /// - [ProtoContract] - public class StringArgument : NativeArgument - { - /// - /// String - /// - [ProtoMember(1)] - public string Data { get; set; } - } - /// - /// Float argument - /// - [ProtoContract] - public class FloatArgument : NativeArgument - { - /// - /// Float - /// - [ProtoMember(1)] - public float Data { get; set; } - } - - /// - /// Boolean argument - /// - [ProtoContract] - public class BooleanArgument : NativeArgument - { - /// - /// Bool - /// - [ProtoMember(1)] - public bool Data { get; set; } - } - - /// - /// Vector3 - /// - [ProtoContract] - public class Vector3Argument : NativeArgument - { - /// - /// Vector3's X - /// - [ProtoMember(1)] - public float X { get; set; } - /// - /// Vector3's Y - /// - [ProtoMember(2)] - public float Y { get; set; } - /// - /// Vector3's Z - /// - [ProtoMember(3)] - public float Z { get; set; } - } -} \ No newline at end of file diff --git a/Server/Program.cs b/Server/Program.cs deleted file mode 100644 index dae619a..0000000 --- a/Server/Program.cs +++ /dev/null @@ -1,145 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Runtime.Remoting; -using System.Security.Policy; -using System.Threading; -using System.Xml.Serialization; -using log4net; -using log4net.Config; - -namespace GTAServer -{ - public static class Program - { - /// - /// Location of the virtual server host - /// - public static string ServerHostLocation => AppDomain.CurrentDomain.BaseDirectory; - /// - /// Dictionary of all the virtual servers currently running - /// - public static Dictionary VirtualServerDomains = new Dictionary(); - /// - /// Dictionary of all the virtual server handles. - /// - public static Dictionary VirtualServerHandles = new Dictionary(); - /// - /// Dictionary of all the virtual servers - /// - public static Dictionary VirtualServers = new Dictionary(); - /// - /// Dictionary of threads for the virtual servers. - /// - public static Dictionary VirtualServerThreads = new Dictionary(); - /// - /// Server debug mode - /// - public static bool Debug = false; - /// - /// If the server should allow the config option to allow old clients - /// - public static bool AllowOutdatedClients = false; - - /// - /// Delete a file - /// - /// File to delete - /// If the file was deleted - [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - public static extern bool DeleteFile(string name); - - public static readonly ILog Log = LogManager.GetLogger("ServerManager"); - /// - /// Read server settings from XML - /// - /// Server settings path - /// ServerSettings instance - private static InstanceSettings ReadSettings(string path) - { - var ser = new XmlSerializer(typeof(InstanceSettings)); - - InstanceSettings settings = null; - Log.Debug(path); - if (File.Exists(path)) - { - using (var stream = File.OpenRead(path)) settings = (InstanceSettings)ser.Deserialize(stream); - using (var stream = new FileStream(path, File.Exists(path) ? FileMode.Truncate : FileMode.Create, FileAccess.ReadWrite)) ser.Serialize(stream, settings); - } - else - { - Log.Debug("No settings.xml found, creating a new one."); - using (var stream = File.OpenWrite(path)) ser.Serialize(stream, settings = new InstanceSettings()); - } - //LogToConsole(1, false, "FILE", "Settings loaded from " + path); - return settings; - } - - public static InstanceSettings GlobalSettings; - /// - /// Master server list - /// - public class MasterServerList - { - public List List { get; set; } - } - - public static void Main(string[] args) - { - XmlConfigurator.Configure(new System.IO.FileInfo("logging.xml")); - Log.Debug("Loading settings"); - GlobalSettings = ReadSettings(Program.ServerHostLocation + ((args.Length > 0) ? args[0] : "Settings.xml")); - foreach (var server in GlobalSettings.Servers) - { - StartServer(server); - } - foreach (var thread in VirtualServerThreads) thread.Value.Join(100); - } - - public static void StartServer(ServerSettings settings) - { - Log.Info("Creating new server instance: "); - Log.Info(" - Handle: " + settings.Handle); - Log.Info(" - Name: " + settings.Name); - Log.Info(" - Player Limit: " + settings.MaxPlayers); - if (settings.AllowOutdatedClients && !AllowOutdatedClients) - { - Log.Warn("Server config for " + settings.Handle + " is set to allow outdated clients, yet it has been disabled on the master server."); - settings.AllowOutdatedClients = false; - } - VirtualServerDomains[settings.Handle]=AppDomain.CreateDomain(settings.Handle); - var domain = VirtualServerDomains[settings.Handle]; - - VirtualServerHandles[settings.Handle] = domain.CreateInstanceFrom(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath, - "GTAServer.GameServer"); - var handle = VirtualServerHandles[settings.Handle]; - VirtualServers[settings.Handle] = (GameServer)handle.Unwrap(); - var curServer = VirtualServers[settings.Handle]; - curServer.Name = settings.Name; - curServer.MaxPlayers = settings.MaxPlayers; - curServer.Port = settings.Port; - curServer.PasswordProtected = settings.PasswordProtected; - curServer.Password = settings.Password; - curServer.AnnounceSelf = settings.Announce; - curServer.MasterServer = settings.MasterServer; - curServer.AllowNickNames = settings.AllowDisplayNames; - curServer.AllowOutdatedClients = settings.AllowOutdatedClients; - curServer.GamemodeName = settings.Gamemode; - curServer.ConfigureServer(); - curServer.SetupLogger(settings.Handle); - Log.Debug("Finished configuring server: " + settings.Handle + ", starting."); - VirtualServerThreads[settings.Handle] = new Thread(curServer.StartAndRunMainLoop); - VirtualServerThreads[settings.Handle].Start(); - Log.Debug("Server started, injecting filterscripts into " + settings.Handle); - foreach (var script in settings.Filterscripts) - { - if (string.IsNullOrEmpty(script) || string.IsNullOrWhiteSpace(script)) continue; - Log.Info("Filterscript " + script + " loading into server instance " + settings.Handle); - curServer.LoadFilterscript(script); - } - } - } -} \ No newline at end of file diff --git a/Server/Properties/AssemblyInfo.cs b/Server/Properties/AssemblyInfo.cs deleted file mode 100644 index 3ba185b..0000000 --- a/Server/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("GTAServer")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("GTAServer")] -[assembly: AssemblyCopyright("Copyright © 2018")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("559ee224-bf7b-49d8-9cee-11e6ba71fe4e")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Server/ServerScript.cs b/Server/ServerScript.cs deleted file mode 100644 index 99ce53b..0000000 --- a/Server/ServerScript.cs +++ /dev/null @@ -1,61 +0,0 @@ -using Lidgren.Network; - -namespace GTAServer -{ - /// - /// ServerScript class used for server-side scripting. - /// - public class ServerScript - { - /// - /// Script name - /// - public virtual string Name { get; set; } - /// - /// Init functon for script - /// - public virtual void Start(GameServer serverInstance) { } - - /// - /// Called on an incoming connection. - /// - /// Player that is connecting - public virtual void OnIncomingConnection(Client player) { } - /// - /// Called on successful connection - /// - /// Player that connected - /// Currently discarded. To be implemented: Connection rejections - public virtual bool OnPlayerConnect(Client player) { return true; } - /// - /// Called when a player is refused connection. - /// - /// Player who was refused - /// Reason for being refused connection - public virtual void OnConnectionRefused(Client player, string reason) { } - - /// - /// Called when a player disconnects - /// - /// Player who disconnected - /// ... Literally thrown out. Will be changed to return void. - public virtual bool OnPlayerDisconnect(Client player) { return true; } - - /// - /// Called when a player is spawned. - /// - /// Player who spawned. - public virtual void OnPlayerSpawned(Client player) { } - /// - /// Called on a chat message - /// - /// ChatMessage object - /// A new chat message, currently discarded. TODO: Allow message rewriting. - public virtual ChatMessage OnChatMessage(ChatMessage message) { return message; } - - /// - /// Called every tick. - /// - public virtual void OnTick() { } - } -} \ No newline at end of file diff --git a/Server/ServerSettings.cs b/Server/ServerSettings.cs deleted file mode 100644 index 8e3f7a1..0000000 --- a/Server/ServerSettings.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace GTAServer -{ - public class InstanceSettings - { - public ServerSettings[] Servers; - - public InstanceSettings() - { - Servers = new ServerSettings[] {new ServerSettings()}; - } - } - - - /// - /// Contains server settings - /// - [Serializable] - public class ServerSettings - { - /// - /// Server name - /// - public string Name { get; set; } - /// - /// Server max players - /// - public int MaxPlayers { get; set; } - /// - /// Server port - /// - public int Port { get; set; } - /// - /// If the server is password protected - /// - public bool PasswordProtected { get; set; } - /// - /// Server password - /// - public string Password { get; set; } - /// - /// If the server should announce itself - /// - public bool Announce { get; set; } - /// - /// Master server address - /// - public string MasterServer { get; set; } - - /// - /// If the server should allow display names - /// - public bool AllowDisplayNames { get; set; } - /// - /// If the server should allow outdated clients - /// - public bool AllowOutdatedClients { get; set; } - - /// - /// Server gamemode - /// - public string Gamemode { get; set; } - /// - /// Filterscripts to load - /// - public string[] Filterscripts { get; set; } - /// - /// Server LAN IP - /// - public string LANIP { get; set; } - /// - /// Server WAN IP - /// - public string WANIP { get; set; } - /// - /// Internal server handle - /// - public string Handle { get; set; } - - - public ServerSettings() - { - Port = 4499; - MaxPlayers = 16; - Name = "Simple GTA Server"; - Password = "changeme"; - PasswordProtected = false; - Gamemode = "freeroam"; - Announce = true; - AllowDisplayNames = true; - AllowOutdatedClients = false; - MasterServer = "http://46.101.1.92/"; - Filterscripts = new string[] {""}; - Handle = "default"; - } - } -} \ No newline at end of file diff --git a/Server/VehicleData.cs b/Server/VehicleData.cs deleted file mode 100644 index 2f0e08d..0000000 --- a/Server/VehicleData.cs +++ /dev/null @@ -1,452 +0,0 @@ -using System; -using System.Collections.Generic; -using ProtoBuf; - -namespace GTAServer -{ - /// - /// Server packet types - /// - public enum PacketType - { - /// - /// VehiclePositionData - /// - VehiclePositionData = 0, - /// - /// ChatData packet - /// - ChatData = 1, - /// - /// PlayerDisconnect packet - /// - PlayerDisconnect = 2, - /// - /// PedPositionData packet - /// - PedPositionData = 3, - /// - /// NpcVehPositionData packet - /// - NpcVehPositionData = 4, - /// - /// NpcPedPositionData packet - /// - NpcPedPositionData = 5, - /// - /// WorldSharingStop packet - /// - WorldSharingStop = 6, - /// - /// DiscoveryResponse packet - /// - DiscoveryResponse = 7, - /// - /// ConnectionRequest packet - /// - ConnectionRequest = 8, - /// - /// NativeCall packet - /// - NativeCall = 9, - /// - /// NativeResponse packet - /// - NativeResponse = 10, - /// - /// PlayerSpawned packet - /// - PlayerSpawned = 11, - /// - /// NativeTick packet - /// - NativeTick = 12, - /// - /// NativeTickRecall packet - /// - NativeTickRecall = 13, - /// - /// NativeOnDisconnect packet - /// - NativeOnDisconnect = 14, - /// - /// NativeOnDisconnectRecall packet - /// - NativeOnDisconnectRecall = 15, - /// - /// VoiceChatData packet - /// - VoiceChatData = 16, - } - - /// - /// Script versions - /// - public enum ScriptVersion - { - /// - /// Unknown version (Too old to send version) - /// - VERSION_UNKNOWN = 0, - /// - /// v0.6 - /// - VERSION_0_6 = 1, - /// - /// v0.6.1 - /// - VERSION_0_6_1 = 2, - /// - /// v0.7 - /// - VERSION_0_7 = 3, - /// - /// v0.8.1 - /// - VERSION_0_8_1 = 4, - /// - /// v0.9 - /// - VERSION_0_9 = 5, - /// - /// v0.9.1 - /// - VERSION_0_9_1 = 6, - /// - /// v0.9.2 - /// - VERSION_0_9_2 = 7, - /// - /// v0.9.3 - /// - VERSION_0_9_3 = 8, - } - - /// - /// DiscoveryResponse packet - /// - [ProtoContract] - public class DiscoveryResponse - { - /// - /// Server name - /// - [ProtoMember(1)] - public string ServerName { get; set; } - /// - /// Server max players - /// - [ProtoMember(2)] - public int MaxPlayers { get; set; } - /// - /// Server player count - /// - [ProtoMember(3)] - public int PlayerCount { get; set; } - /// - /// If the server has a password - /// - [ProtoMember(4)] - public bool PasswordProtected { get; set; } - /// - /// Server port - /// - [ProtoMember(5)] - public int Port { get; set; } - /// - /// Server gamemode - /// - [ProtoMember(6)] - public string Gamemode { get; set; } - } - - /// - /// ConnectionRequest packet - /// - [ProtoContract] - public class ConnectionRequest - { - /// - /// Player name - /// - [ProtoMember(1)] - public string Name { get; set; } - /// - /// Password to connect - /// - [ProtoMember(2)] - public string Password { get; set; } - /// - /// Player display name - /// - [ProtoMember(3)] - public string DisplayName { get; set; } - /// - /// Player game version - /// - [ProtoMember(4)] - public int GameVersion { get; set; } - /// - /// Player script version - /// - [ProtoMember(5)] - public byte ScriptVersion { get; set; } - } - - /// - /// PlayerDisconnect packet - /// - [ProtoContract] - public class PlayerDisconnect - { - /// - /// Player ID? Don't remember. - /// - [ProtoMember(1)] - public long Id { get; set; } - } - - /// - /// VehicleData packet - /// - [ProtoContract] - public class VehicleData - { - /// - /// Vehicle ID - /// - [ProtoMember(1)] - public long Id { get; set; } - /// - /// Vehicle name - /// - [ProtoMember(2)] - public string Name { get; set; } - - /// - /// Vehicle model hash - /// - [ProtoMember(3)] - public int VehicleModelHash { get; set; } - /// - /// Ped model hash - /// - [ProtoMember(4)] - public int PedModelHash { get; set; } - /// - /// Primary color - /// - [ProtoMember(5)] - public int PrimaryColor { get; set; } - /// - /// Secondary color - /// - [ProtoMember(6)] - public int SecondaryColor { get; set; } - - /// - /// Vehicle position - /// - [ProtoMember(7)] - public Vector3 Position { get; set; } - /// - /// Vehicle rotation - /// - [ProtoMember(8)] - public Quaternion Quaternion { get; set; } - - /// - /// Vehicle seat - /// - [ProtoMember(9)] - public int VehicleSeat { get; set; } - /// - /// Vehicle health - /// - [ProtoMember(10)] - public int VehicleHealth { get; set; } - /// - /// Player health - /// - [ProtoMember(11)] - public int PlayerHealth { get; set; } - /// - /// Vehicle latency - /// - [ProtoMember(12)] - public float Latency { get; set; } - /// - /// Vehicle mods - /// - [ProtoMember(13)] - public Dictionary VehicleMods { get; set; } - /// - /// If the horn is being pressed - /// - [ProtoMember(14)] - public bool IsPressingHorn { get; set; } - /// - /// If the siren is active - /// - [ProtoMember(15)] - public bool IsSirenActive { get; set; } - /// - /// Vehicle speed - /// - [ProtoMember(16)] - public float Speed { get; set; } - } - - /// - /// Pedestrian data - /// - [ProtoContract] - public class PedData - { - /// - /// Ped ID - /// - [ProtoMember(1)] - public long Id { get; set; } - /// - /// Ped name - /// - [ProtoMember(2)] - public string Name { get; set; } - - /// - /// Ped model hash - /// - [ProtoMember(3)] - public int PedModelHash { get; set; } - - /// - /// Ped position - /// - [ProtoMember(4)] - public Vector3 Position { get; set; } - /// - /// Ped rotation - /// - [ProtoMember(5)] - public Quaternion Quaternion { get; set; } - - /// - /// If the ped is jumping - /// - [ProtoMember(6)] - public bool IsJumping { get; set; } - /// - /// If the ped is shooting - /// - [ProtoMember(7)] - public bool IsShooting { get; set; } - /// - /// If the ped is aiming - /// - [ProtoMember(8)] - public bool IsAiming { get; set; } - /// - /// Where the ped is aiming - /// - [ProtoMember(9)] - public Vector3 AimCoords { get; set; } - /// - /// Hash of the ped's weapon - /// - [ProtoMember(10)] - public int WeaponHash { get; set; } - /// - /// Health of the ped - /// - [ProtoMember(11)] - public int PlayerHealth { get; set; } - /// - /// Ped latency - /// - [ProtoMember(12)] - public float Latency { get; set; } - /// - /// Ped props - /// - [ProtoMember(13)] - public Dictionary PedProps { get; set; } - /// - /// If the parachute is open - /// - [ProtoMember(14)] - public bool IsParachuteOpen { get; set; } - } - - /// - /// Vector3 - /// - [ProtoContract] - public class Vector3 - { - public Vector3() - { - X = 0f; - Y = 0f; - Z = 0f; - } - - public Vector3(float x, float y, float z) - { - X = x; - Y = y; - Z = z; - } - /// - /// X - /// - [ProtoMember(1)] - public float X { get; set; } - /// - /// Y - /// - [ProtoMember(2)] - public float Y { get; set; } - /// - /// Z - /// - [ProtoMember(3)] - public float Z { get; set; } - } - - public class VoiceChatData - { - [ProtoMember(1)] - public long Id { get; set; } - [ProtoMember(2)] - public byte[] Buffer { get; set; } - } - - /// - /// Quaternion (usually used for rotation) - /// - [ProtoContract] - public class Quaternion - { - /// - /// X - /// - [ProtoMember(1)] - public float X { get; set; } - /// - /// Y - /// - [ProtoMember(2)] - public float Y { get; set; } - /// - /// Z - /// - [ProtoMember(3)] - public float Z { get; set; } - /// - /// W - /// - [ProtoMember(4)] - public float W { get; set; } - } -} \ No newline at end of file diff --git a/Server/packages.config b/Server/packages.config deleted file mode 100644 index 678cfbe..0000000 --- a/Server/packages.config +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file