Skip to content

Commit

Permalink
Merge with aspyr-debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Alpha5k authored Sep 14, 2024
2 parents 5822877 + 094be5f commit 7099138
Show file tree
Hide file tree
Showing 38 changed files with 783 additions and 233 deletions.
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ DllLoader/bin
DllLoader/obj
SWBF2Admin/bin
SWBF2Admin/obj
IngameControllerServer/bin
IngameControllerServer/obj
RconServer/Debug
RconServer/Release
RconServer/x64
RconServer/x86
RconServer/out
rconserver-aspyr/out
rconserver-galaxy/out
packages
.vs
.tmp
Expand Down
Binary file modified DebugFiles/SWBF2Admin.sqlite
Binary file not shown.
7 changes: 6 additions & 1 deletion DebugFiles/web/bans.htm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ <h2>Bans</h2>
<td><input type="text" id="bans_input_reason" class="bans_autorf"><i class="material-icons">youtube_searched_for</i></td>
<td><input type="date" id="bans_input_date" class="bans_autorf"></td>
<td><input type="checkbox" id="bans_input_expired"></td>
<td><select id="bans_select_type"><option value="-1">All</option><option value="0">Keyhash</option><option value="1">IP-Address</option></select></td>
<td><select id="bans_select_type">
<option value="-1">All</option>
<option value="0">Keyhash</option>
<option value="1">IP-Address</option>
<option value="2">Alias</option>
</select></td>
</tr>
</table>
</div>
Expand Down
1 change: 1 addition & 0 deletions DebugFiles/web/players.htm
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ <h2>Players</h2>
<select id="players_select_ban_type">
<option value="0" selected>Keyhash</option>
<option value="1">IP Address</option>
<option value="2">Alias</option>
</select>
</td>
</tr>
Expand Down
8 changes: 7 additions & 1 deletion DebugFiles/web/res/bans.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
var BansUrl = "/db/bans";
var BansFilterTimeout = 300;

var BanTypes = [
"Key",
"IP",
"Alias"
]

function Bans() {
var base = this;
this.quickAdminId = null;
Expand Down Expand Up @@ -73,7 +79,7 @@ function Bans() {
"<td>" + (b.Duration < 0 ? "permanent" : b.Duration) + "</td>" +
"<td>" + b.PlayerKeyhash + "</td>" +
"<td>" + b.PlayerIPAddress + "</td>" +
"<td>" + (b.TypeId == 0 ? "Key" : "IP") + "</td>" +
"<td>" + BanTypes[b.TypeId] + "</td>" +
"</tr>";
i++;
legend |= b.Expired;
Expand Down
7 changes: 6 additions & 1 deletion DllLoader/DllLoader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<GenerateAssemblyInfo>True</GenerateAssemblyInfo>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AssemblyTitle>DllLoader</AssemblyTitle>
<Product>DllLoader</Product>
<Copyright>Copyright © 2018</Copyright>
<AssemblyVersion>1.3.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
Expand Down
5 changes: 0 additions & 5 deletions DllLoader/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ static void Main(string[] args)
Console.WriteLine("ERROR");
Console.WriteLine(e.ToString());
}

#if DEBUG
Console.WriteLine("Press [return] to exit.");
Console.ReadLine();
#endif
}
}
}
13 changes: 13 additions & 0 deletions DllLoader/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[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("e6f07cf4-2b80-4134-8d0d-52562fa16b8f")]
18 changes: 0 additions & 18 deletions DllLoader/Properties/PublishProfiles/Windows.pubxml

This file was deleted.

27 changes: 17 additions & 10 deletions SWBF2Admin/AdminCore.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This file is part of SWBF2Admin (https://github.com/jweigelt/swbf2admin).
* This file is part of SWBF2Admin (https://github.com/jweigelt/swbf2admin).
* Copyright(C) 2017, 2018 Jan Weigelt <[email protected]>
*
* SWBF2Admin is free software: you can redistribute it and/or modify
Expand All @@ -15,25 +15,23 @@
* You should have received a copy of the GNU General Public License
* along with SWBF2Admin. If not, see<http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;

using SWBF2Admin.Utility;
using SWBF2Admin.Config;
using SWBF2Admin.Web;
using SWBF2Admin.Database;
using SWBF2Admin.Gameserver;
using SWBF2Admin.Scheduler;
using SWBF2Admin.Structures;

using SWBF2Admin.Runtime.Players;
using SWBF2Admin.Runtime.Rcon;
using SWBF2Admin.Runtime.Game;
using SWBF2Admin.Runtime.Announce;
using SWBF2Admin.Runtime.Commands;
using SWBF2Admin.Runtime.ApplyMods;
using SWBF2Admin.Runtime.Watchdog;

using SWBF2Admin.Plugins;

namespace SWBF2Admin
Expand All @@ -43,7 +41,12 @@ public class AdminCore
private const string ARG_RESET_WEBUSER = "--reset-webcredentials";

private CoreConfiguration config;
public CoreConfiguration Config { get { return config; } }

public CoreConfiguration Config
{
get { return config; }
}

public FileHandler Files { get; } = new FileHandler();
public TaskScheduler Scheduler { get; } = new TaskScheduler();

Expand Down Expand Up @@ -168,6 +171,11 @@ public void Run(string[] args)

while ((cmd = Console.ReadLine()) != "quit")
{
if (string.IsNullOrEmpty(cmd))
{
continue;
}

if (cmd == "import maps")
{
Database.ImportMaps(ServerMap.ReadServerMapConfig(this));
Expand All @@ -185,9 +193,9 @@ public void Run(string[] args)


#region "Events"

private void Server_Started(object sender, EventArgs e)
{

Logger.Log(LogLevel.Verbose, "Starting runtime management...");
Scheduler.PushDelayedTask(() =>
{
Expand All @@ -214,7 +222,7 @@ private void Server_Stopped(object sender, EventArgs e)
Logger.Log(LogLevel.Verbose, "Restarting server...");
Server.Start();
}
}
}
}

private void Server_Crashed(object sender, EventArgs e)
Expand All @@ -223,24 +231,23 @@ private void Server_Crashed(object sender, EventArgs e)
if (Config.AutoRestartServer)
{
Logger.Log(LogLevel.Info, "Automatic restart is enabled. Restarting server...");
Scheduler.PushDelayedTask(() => Server.Start(), 90000);
Scheduler.PushDelayedTask(() => Server.Start(), Config.AutoRestartDelay);
}
}

private void Rcon_Disconnected(object sender, EventArgs e)
{

}

private void Rcon_Chat(object sender, EventArgs e)
{

}

private void Announce_Broadcast(object sender, EventArgs e)
{
Rcon.Say(((AnnounceEventArgs)e).Announce.ParseMessage(this));
}

#endregion
}
}
3 changes: 3 additions & 0 deletions SWBF2Admin/Config/CoreConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ public class CoreConfiguration
#region Gameserver
public bool AutoLaunchServer { get; set; } = false;
public bool AutoRestartServer { get; set; } = true;
public int AutoRestartDelay { get; set; } = 30000;
public string ServerPath { get; set; } = @"C:\Program Files (x86)\Steam\steamapps\common\Battle";
public string ServerArgs { get; set; } = "/win /norender /nosound /nointro /autonet dedicated /resolution 640 480";

public string SteamPath { get; set; } = @"C:\Program Files (x86)\Steam";

public bool EnableHighPriority { get; set; } = true;
public bool SetAffinity { get; set; } = false;
public int ProcessAffinity { get; set; } = 0x0;
public bool EnableRuntime { get; set; } = false;
public GameserverType ServerType { get; set; } = GameserverType.Aspyr;

Expand Down
13 changes: 11 additions & 2 deletions SWBF2Admin/Config/FileHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void UnpackConfigDefault<T>()
/// T's standard constructor
/// </para>
/// </summary>
public T ReadConfig<T>(string fileName = "")
public T ReadConfig<T>(string fileName = "", string template = "")
{
if (fileName == "")
{
Expand All @@ -185,7 +185,16 @@ public T ReadConfig<T>(string fileName = "")
else
{
if (!File.Exists(fileName))
WriteConfigDefault<T>(fileName);
{
if (template == "")
{
WriteConfigDefault<T>(fileName);
}
else
{
UnpackResource(fileName, template);
}
}
}
return ReadXmlFile<T>(fileName);
}
Expand Down
39 changes: 26 additions & 13 deletions SWBF2Admin/Database/SQLHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,11 @@ public bool IsBanned(Player player)
"INNER JOIN swbf_players ON prefix_bans.player_id = prefix_players.id " +
"WHERE " +
"((player_keyhash = @keyhash AND ban_type = " + ((int)BanType.Keyhash).ToString() + ") " +
"OR (player_last_ip = @ip AND ban_type = " + ((int)BanType.IPAddress).ToString() + ")) " +
"OR (player_last_ip = @ip AND ban_type = " + ((int)BanType.IPAddress).ToString() + ") " +
"OR (player_last_name = @name AND ban_type = " + ((int)BanType.Alias).ToString() + ")) " +
"AND ((ban_timestamp + ban_duration) > @timestamp OR ban_duration < 0)";

return (HasRows(Query(sql, "@keyhash", player.KeyHash, "@ip", player.RemoteAddressStr, "@timestamp", GetTimestamp())));
return (HasRows(Query(sql, "@keyhash", player.KeyHash, "@ip", player.RemoteAddressStr, "@name", player.Name, "@timestamp", GetTimestamp())));
}
public void InsertBan(PlayerBan ban)
{
Expand Down Expand Up @@ -916,28 +917,40 @@ public WebUser GetWebUser(string username, string password)
"prefix_web_users " +
"WHERE user_name = @username";

string hash;
WebUser user;
bool update_user = false;

using (DbDataReader reader = Query(sql, "@username", username))
{
if (reader.Read())
{
var hash = RS(reader, "user_password");
hash = RS(reader, "user_password");

//update legacy hash
if (hash.Length == 32)
{
hash = PBKDF2.HashPassword(hash);
UpdateWebUser(
new WebUser(RL(reader, "id"), RS(reader, "user_name"), hash, GetDateTime(RU(reader, "user_lastvisit"))),
true);
update_user = true;
}

if (PBKDF2.VerifyPassword(password, hash))
{
return new WebUser(RL(reader, "id"), RS(reader, "user_name"), hash, GetDateTime(RU(reader, "user_lastvisit")));
}
user = new WebUser(RL(reader, "id"), RS(reader, "user_name"), hash, GetDateTime(RU(reader, "user_lastvisit")));
} else
{
return null;
}
}

if (update_user)
{
UpdateWebUser(user, true);
}

if (PBKDF2.VerifyPassword(password, hash))
{
return user;
}

return null;
}
public void UpdateLastSeen(WebUser user)
Expand Down Expand Up @@ -971,9 +984,9 @@ public void InsertWebUser(WebUser user)
public void UpdateWebUser(WebUser user, bool updatePwd)
{
string sql = "UPDATE prefix_web_users SET " +
"user_name = @username ";
if (updatePwd) sql += ",user_password = @password ";
sql += "WHERE id = @user_id";
"user_name = @username";
if (updatePwd) sql += ", user_password = @password";
sql += " WHERE id = @user_id";

NonQuery(sql, "@username", user.Username, "@password", user.PasswordHash, "@user_id", user.Id);
}
Expand Down
Loading

0 comments on commit 7099138

Please sign in to comment.