From 9b5fcffdf63fee592a3e23c80a48687227a1ff7c Mon Sep 17 00:00:00 2001 From: CroniX Date: Thu, 21 Jan 2021 19:37:32 +0100 Subject: [PATCH 1/3] Onlinelist add faction remove level --- ReallifeGamemode.Client/Gui/playerlist.ts | 4 ++-- .../assets/html/Playerlist/Tabliste.html | 1 - .../assets/html/Playerlist/script.js | 12 ++++-------- ReallifeGamemode.Server/Events/Key.cs | 11 ++++++++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ReallifeGamemode.Client/Gui/playerlist.ts b/ReallifeGamemode.Client/Gui/playerlist.ts index a674b624..8ed01339 100644 --- a/ReallifeGamemode.Client/Gui/playerlist.ts +++ b/ReallifeGamemode.Client/Gui/playerlist.ts @@ -9,7 +9,7 @@ export default function playerList(globalData: IGlobalData): void { var playerlistBrowser: BrowserMp = null; var pList; - mp.events.add("showPlayerlist", (playersJson) => { + mp.events.add("showPlayerlist", (playersJson, factionname) => { if (playerlistBrowser !== null) { playerlistBrowser.destroy(); @@ -25,7 +25,7 @@ export default function playerList(globalData: IGlobalData): void { mp.gui.cursor.show(true, true); pList = JSON.parse(playersJson); pList.forEach((player) => { - playerlistBrowser.execute(`ad_row('${JSON.stringify(player.Id)}','${JSON.stringify(player.Name)}',0,0,'${JSON.stringify(player.Ping)}');`); + playerlistBrowser.execute(`ad_row('${JSON.stringify(player.Id)}','${JSON.stringify(player.Name)}',${JSON.stringify(factionname)},'${JSON.stringify(player.Ping)}');`); }); } }); diff --git a/ReallifeGamemode.Client/assets/html/Playerlist/Tabliste.html b/ReallifeGamemode.Client/assets/html/Playerlist/Tabliste.html index 33d0bb9b..764b197a 100644 --- a/ReallifeGamemode.Client/assets/html/Playerlist/Tabliste.html +++ b/ReallifeGamemode.Client/assets/html/Playerlist/Tabliste.html @@ -16,7 +16,6 @@ ID Spielername - Level Fraktion Ping diff --git a/ReallifeGamemode.Client/assets/html/Playerlist/script.js b/ReallifeGamemode.Client/assets/html/Playerlist/script.js index 5cd805e7..2a0e2c30 100644 --- a/ReallifeGamemode.Client/assets/html/Playerlist/script.js +++ b/ReallifeGamemode.Client/assets/html/Playerlist/script.js @@ -1,7 +1,7 @@ -function ad_row(id, name, level, faction, ping) { +function ad_row(id, name, faction, ping) { var table_id = "t1"; var table = document.getElementById(table_id); var rows = table.getElementsByTagName('tr').length; @@ -10,17 +10,13 @@ function ad_row(id, name, level, faction, ping) { var td2 = document.createElement('td'); var td3 = document.createElement('td'); var td4 = document.createElement('td'); - var td5 = document.createElement('td'); - var test = level; - var test2 = faction; + var test = faction; td1.innerHTML = ''+id; td2.innerHTML = name.slice(1, -1); - td3.innerHTML = 'WIP'; - td4.innerHTML = 'WIP'; - td5.innerHTML = ''+ping; + td3.innerHTML = ''+faction; + td4.innerHTML = ''+ping; tr.appendChild(td1); tr.appendChild(td2); tr.appendChild(td3); tr.appendChild(td4); - tr.appendChild(td5); } \ No newline at end of file diff --git a/ReallifeGamemode.Server/Events/Key.cs b/ReallifeGamemode.Server/Events/Key.cs index c3905a01..4e812795 100644 --- a/ReallifeGamemode.Server/Events/Key.cs +++ b/ReallifeGamemode.Server/Events/Key.cs @@ -604,17 +604,22 @@ namespace ReallifeGamemode.Server.Events } [RemoteEvent("keyPress:O")] - public void KeyPressJ(Player player) + public void KeyPressO(Player player) { if (!player.IsLoggedIn()) return; + using (var dbContext = new DatabaseContext()) + { + string factionname = player.GetUser(dbContext).Faction.Name; + List players = NAPI.Pools.GetAllPlayers(); var listPlayers = players.Select(p => new { Id = p.Handle.Value, p.Name, p.Ping, - }); - player.TriggerEvent("showPlayerlist", JsonConvert.SerializeObject(listPlayers)); + }) ; + player.TriggerEvent("showPlayerlist", JsonConvert.SerializeObject(listPlayers), JsonConvert.SerializeObject(factionname)); + } } [RemoteEvent("keyPress:K")] From dfc9be29c6d7f83e7f82b67dd7acb00c7112446e Mon Sep 17 00:00:00 2001 From: CroniX Date: Sat, 23 Jan 2021 17:06:09 +0100 Subject: [PATCH 2/3] Fix online list show faction --- ReallifeGamemode.Client/Gui/playerlist.ts | 4 ++-- ReallifeGamemode.Server/Events/Key.cs | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/ReallifeGamemode.Client/Gui/playerlist.ts b/ReallifeGamemode.Client/Gui/playerlist.ts index 8ed01339..454b0df0 100644 --- a/ReallifeGamemode.Client/Gui/playerlist.ts +++ b/ReallifeGamemode.Client/Gui/playerlist.ts @@ -9,7 +9,7 @@ export default function playerList(globalData: IGlobalData): void { var playerlistBrowser: BrowserMp = null; var pList; - mp.events.add("showPlayerlist", (playersJson, factionname) => { + mp.events.add("showPlayerlist", (playersJson) => { if (playerlistBrowser !== null) { playerlistBrowser.destroy(); @@ -25,7 +25,7 @@ export default function playerList(globalData: IGlobalData): void { mp.gui.cursor.show(true, true); pList = JSON.parse(playersJson); pList.forEach((player) => { - playerlistBrowser.execute(`ad_row('${JSON.stringify(player.Id)}','${JSON.stringify(player.Name)}',${JSON.stringify(factionname)},'${JSON.stringify(player.Ping)}');`); + playerlistBrowser.execute(`ad_row('${JSON.stringify(player.Id)}','${JSON.stringify(player.Name)}',${JSON.stringify(player.FactionName)},'${JSON.stringify(player.Ping)}');`); }); } }); diff --git a/ReallifeGamemode.Server/Events/Key.cs b/ReallifeGamemode.Server/Events/Key.cs index 4e812795..7d67e9ac 100644 --- a/ReallifeGamemode.Server/Events/Key.cs +++ b/ReallifeGamemode.Server/Events/Key.cs @@ -609,16 +609,17 @@ namespace ReallifeGamemode.Server.Events if (!player.IsLoggedIn()) return; using (var dbContext = new DatabaseContext()) { - string factionname = player.GetUser(dbContext).Faction.Name; + string FactionName; List players = NAPI.Pools.GetAllPlayers(); - var listPlayers = players.Select(p => new - { - Id = p.Handle.Value, - p.Name, - p.Ping, - }) ; - player.TriggerEvent("showPlayerlist", JsonConvert.SerializeObject(listPlayers), JsonConvert.SerializeObject(factionname)); + var listPlayers = players.Select(p => new + { + Id = p.Handle.Value, + p.Name, + p.Ping, + FactionName = p.GetUser().Faction.Name, + }) ; + player.TriggerEvent("showPlayerlist", JsonConvert.SerializeObject(listPlayers)); } } From 1b4bf43d5dfbb1b5b99c4b3d7eded34b6a6df919 Mon Sep 17 00:00:00 2001 From: CroniX Date: Sat, 23 Jan 2021 17:15:18 +0100 Subject: [PATCH 3/3] Online list remove dbcontext --- ReallifeGamemode.Server/Events/Key.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ReallifeGamemode.Server/Events/Key.cs b/ReallifeGamemode.Server/Events/Key.cs index 7d67e9ac..d3969a02 100644 --- a/ReallifeGamemode.Server/Events/Key.cs +++ b/ReallifeGamemode.Server/Events/Key.cs @@ -607,10 +607,6 @@ namespace ReallifeGamemode.Server.Events public void KeyPressO(Player player) { if (!player.IsLoggedIn()) return; - using (var dbContext = new DatabaseContext()) - { - string FactionName; - List players = NAPI.Pools.GetAllPlayers(); var listPlayers = players.Select(p => new { @@ -620,7 +616,6 @@ namespace ReallifeGamemode.Server.Events FactionName = p.GetUser().Faction.Name, }) ; player.TriggerEvent("showPlayerlist", JsonConvert.SerializeObject(listPlayers)); - } } [RemoteEvent("keyPress:K")]