Permalink
Browse files

Fixed a startpage with server status and two links to playerlist or m…

…aplist
  • Loading branch information...
RickardPettersson committed Nov 15, 2011
1 parent ad4cc3f commit 573125582859504921acd040303c087c834a0bcd
View
@@ -49,9 +49,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
- <Reference Include="BF3Rcon, Version=3.0.2.0, Culture=neutral, processorArchitecture=MSIL">
+ <Reference Include="BF3Rcon, Version=3.2.6.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>Vendor\bf3rcon-4997\BF3Rcon.dll</HintPath>
+ <HintPath>Vendor\BF3Rcon-dev-5371\BF3Rcon.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@@ -78,10 +78,13 @@
<Content Include="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
+ <Content Include="www\page.htm">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Content>
<Content Include="www\do.htm">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
- <Content Include="www\index.htm">
+ <Content Include="www\playerlist.htm">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
View
Binary file not shown.
@@ -6,6 +6,7 @@
using Microsoft.VisualBasic;
using System.Configuration;
using System.IO;
+using System.Net.Battlefield3;
namespace BFAdmin.Helpers
{
@@ -21,13 +22,86 @@ public WebserviceResponse(WebserviceRequest myRequest)
// Try to find path
if (new Regex("/$").Match(myRequest.URL).Success)
{
- // Create a stringbuilder to put the answer stuff in
+ try
+ {
+ // Read the html file in to a string
+ answer = File.ReadAllText("www/page.htm");
+ }
+ catch (Exception ex)
+ {
+ string apa = string.Empty;
+ }
+
StringBuilder sb = new StringBuilder();
+
+ string serverName = string.Empty;
+ int serverSlots = -1;
+
+ Packet serverInfo = Program.rconClient.SendRequestSync("serverInfo");
+ if (serverInfo.Success())
+ {
+ serverName = serverInfo.Words[1];
+ serverSlots = Convert.ToInt32(serverInfo.Words[3]);
+ }
+
+ if (string.IsNullOrEmpty(serverName))
+ {
+ sb.Append("<h3>Server status</h3>");
+ }
+ else
+ {
+ sb.Append("<h3>" + serverName + "</h3>");
+ }
+
+ MapCollection mapCollextion = Program.rconClient.Maps;
+ Map currentMap = mapCollextion.CurrentMap;
+
+ sb.Append("<div class=\"ui-grid-a\">");
+
+ try
+ {
+ if (currentMap != null)
+ {
+ sb.Append("<div class=\"ui-block-a\">Current map:</div><div class=\"ui-block-b\">" + currentMap.FriendlyName + "</div>");
+ sb.Append("<div class=\"ui-block-a\">Current mode:</div><div class=\"ui-block-b\">" + currentMap.FriendlyMode + "</div>");
+ sb.Append("<div class=\"ui-block-a\">Round:</div><div class=\"ui-block-b\">" + currentMap.CurrentRound + "/" + currentMap.TotalRounds + "</div>");
+ }
+ }
+ catch (Exception ex)
+ {
+ string tmp = string.Empty;
+ }
+
+ if (serverSlots > -1)
+ {
+ sb.Append("<div class=\"ui-block-a\">Number of players:</div><div class=\"ui-block-b\">" + Program.rconClient.Players.Count + "/" + serverSlots + "</div>");
+ }
+ else
+ {
+ sb.Append("<div class=\"ui-block-a\">Number of players:</div><div class=\"ui-block-b\">" + Program.rconClient.Players.Count + "</div>");
+ }
+
+ sb.Append("</div>");
+ sb.Append("<ul data-role=\"listview\" data-inset=\"true\" data-theme=\"d\">");
+ sb.Append("<li><a href=\"/Playerlist\">Playerlist</a></li>");
+ sb.Append("<li><a href=\"/Maplist\">Maplist</a></li>");
+ sb.Append("</ul>");
+
+ // Add playerlist to the answer with some replace
+ answer = answer.Replace("<CONTENT>", sb.ToString());
+ }
+ else if (new Regex("/Playerlist").Match(myRequest.URL).Success)
+ {
+ // Create a stringbuilder to put the answer stuff in
+ StringBuilder sb = new StringBuilder();
+
+ sb.Append("<h2>Playerlist</h2>");
+
try
{
// Read the html file in to a string
- answer = File.ReadAllText("www/index.htm");
+ answer = File.ReadAllText("www/playerlist.htm");
}
catch (Exception ex)
{
@@ -38,20 +112,37 @@ public WebserviceResponse(WebserviceRequest myRequest)
if (Program.Playerlist.Count == 0)
{
// /do?player=apa
+ sb.Append("<ul data-role=\"listview\" data-inset=\"true\" data-theme=\"d\">");
sb.Append("<li><a href=\"#\">No players on the server</a></li>");
+ sb.Append("</ul>");
}
else
{
+ var players = from player in Program.Playerlist orderby player.TeamId, player.Score descending select player;
+
+ int teamId = 0;
+
// Loop each player in the player list
- foreach (var p in Program.Playerlist)
+ foreach (var p in players)
{
+ if (teamId == 0)
+ {
+ sb.Append("<h3>Team 1</h3><ul data-role=\"listview\" data-inset=\"true\" data-theme=\"d\">");
+ teamId = p.TeamId;
+ }
+ else if (teamId != p.TeamId)
+ {
+ sb.Append("</ul><br/><h3>Team 2</h3>");
+ sb.Append("<ul data-role=\"listview\" data-inset=\"true\" data-theme=\"d\">");
+ }
// Add item to the list
- sb.Append("<li><a href=\"/do?player=" + p.Name + "\">" + p.Name + "</a></li>");
+ sb.Append("<li><a href=\"/do?player=" + p.Name + "\">" + p.Score + " - " + p.Name + " - " + p.Kills + "/" + p.Deaths + "</a></li>");
}
+ sb.Append("</ul>");
}
// Add playerlist to the answer with some replace
- answer = answer.Replace("<PLAYERLIST>", sb.ToString());
+ answer = answer.Replace("<CONTENT>", sb.ToString());
}
else if (new Regex("/do").Match(myRequest.URL).Success)
@@ -109,8 +200,45 @@ public WebserviceResponse(WebserviceRequest myRequest)
// Add the command dictionary to the queue system
Program.PlayerCommandsQueue.Enqueue(command);
- answer = "redirect=/";
+ answer = "redirect=/Playerlist";
+ }
+ }
+ else if (new Regex("/Maplist").Match(myRequest.URL).Success)
+ {
+ // rconClient.Maps.NextMap
+ // maps.RunNextRound
+ // rconClient.Maps.EndRound(-1);
+ // rconClient.Maps[0].CurrentRound
+ // rconClient.Maps[0].FriendlyMode
+ // rconClient.Maps[0].FriendlyName
+ // rconClient.Maps[0].TotalRounds
+
+ try
+ {
+ // Read the html file in to a string
+ answer = File.ReadAllText("www/page.htm");
+ }
+ catch (Exception ex)
+ {
+ string apa = string.Empty;
+ }
+
+ StringBuilder sb = new StringBuilder();
+
+ sb.Append("<h2>Maplist</h2>");
+
+ sb.Append("<ul data-role=\"listview\" data-inset=\"true\" data-theme=\"d\">");
+
+ MapCollection maps = Program.rconClient.Maps;
+ foreach (Map map in maps)
+ {
+ sb.Append("<li><a href=\"#\">" + map.FriendlyName + " - " + map.FriendlyMode + " (" + map.CurrentRound + "/" + map.TotalRounds + ")</a></li>");
}
+
+ sb.Append("</ul>");
+
+ // Add content to the page
+ answer = answer.Replace("<CONTENT>", sb.ToString());
}
}
View
@@ -4,13 +4,13 @@
<targets>
<target name="file" xsi:type="File"
- layout="${longdate} - ${logger} - ${level} - ${message}"
+ layout="${longdate} - ${level} - ${message}"
fileName="${basedir}/logs/${shortdate}.log"
keepFileOpen="false"
encoding="iso-8859-2" />
<target name="file2" xsi:type="File"
- layout="${longdate} - ${logger} - ${message}"
+ layout="${longdate} - ${message}"
fileName="${basedir}/logs/${shortdate}-${level}.log"
keepFileOpen="false"
encoding="iso-8859-2" />
View
@@ -21,7 +21,7 @@ class Program
private static int webservicePort = 0;
// Create the rcon client object
- private static RconClient rconClient;
+ public static RconClient rconClient;
// Create a timer object
private static System.Timers.Timer aTimer;
@@ -148,6 +148,9 @@ static void rconClient_PlayerKilled(object sender, PlayerKilledEventArgs e)
static void rconClient_PlayerJoined(object sender, PlayerEventArgs e)
{
+ // If there is players on the server then heck for players every 5 seconds
+ aTimer.Interval = 5000;
+
Log.Info("PlayerJoined - Player: " + e.Player.Name);
}
Binary file not shown.
Binary file not shown.
Oops, something went wrong.

0 comments on commit 5731255

Please sign in to comment.