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