Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

Commit

Permalink
Improved username parsing with logic for [Op] etc. tags
Browse files Browse the repository at this point in the history
  • Loading branch information
navhaxs committed Feb 5, 2015
1 parent ecd59c4 commit efcb44b
Show file tree
Hide file tree
Showing 19 changed files with 197 additions and 142 deletions.
3 changes: 2 additions & 1 deletion DummyApp/Module1.vb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Module Module1
Case "doerror"
DoRandomErrorTextRightNow("ErrorText.txt")
Case "list"
Console.WriteLine(TimeNow() & " [INFO] Players...")
Console.WriteLine(TimeNow() & " [INFO] There are 4/20 players online:")
Console.WriteLine(TimeNow() & " [INFO] Developers: [Developer] Coolguy95691 [Op] Notch NormalGuy [Admin] SmileyGuy")
End Select
System.Threading.Thread.Sleep("1000")
End While
Expand Down
14 changes: 9 additions & 5 deletions MinecraftServerDashboard/Controls/OnlinePlayerList.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<GradientStop Offset="1" />
</LinearGradientBrush>
</Grid.Background>
<Label x:Name="lblPlayerCounter" Padding="5,7,5,5" Foreground="#FFBBC3C8" Margin="0,0,22,8" FontFamily="Segoe WP Black" FontSize="48" d:LayoutOverrides="Width" VerticalAlignment="Bottom" HorizontalAlignment="Right" />
<Label x:Name="lblPlayerCounter" Padding="5,7,5,5" Foreground="#FFBBC3C8" Margin="0,0,22,8" FontFamily="Segoe WP Black" FontSize="48" d:LayoutOverrides="Width" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
<!-- Left stripe -->
<Label BorderThickness="1,1,1,0">
<Label.BorderBrush>
Expand All @@ -43,11 +43,15 @@
</LinearGradientBrush>
</Label.BorderBrush>
</Label>
<!-- Label BorderBrush="#FF339933" BorderThickness="0,4,0,0" Height="28" HorizontalContentAlignment="Left" x:Name="Label6" Padding="5,5,0,5" VerticalAlignment="Top" Margin="2,0,0,0" / -->

<ScrollViewer Margin="0,28,0,0" x:Name="ScrollViewer1" Background="{x:Null}">
<StackPanel x:Name="StackPanel1">
</StackPanel>
<ScrollViewer Margin="0,28,4,0" Background="{x:Null}"
VerticalScrollBarVisibility="Auto">
<ScrollViewer.Resources>
<!-- Reset ScrollBar Styles -->
<Style TargetType="ScrollBar">
</Style>
</ScrollViewer.Resources>
<StackPanel x:Name="StackPanel" Margin="0,2,0,0" />
</ScrollViewer>
<!-- Heading -->
<Label Background="{x:Null}" Content="Who's online" Height="28" x:Name="Label3" VerticalAlignment="Top" Margin="4,0,4,0" BorderBrush="#FF335D99" BorderThickness="0,0,0,1" />
Expand Down
23 changes: 14 additions & 9 deletions MinecraftServerDashboard/Controls/OnlinePlayerList.xaml.vb
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@

Public Class OnlinePlayerList

Dim b As New ServerProperties(MyServer.MyStartupParameters.ServerProperties)
Sub New()

' This call is required by the designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.
Me.DataContext = MyServer
If Not System.ComponentModel.DesignerProperties.GetIsInDesignMode(Me) Then

' Add any initialization after the InitializeComponent() call.
Me.DataContext = MyServer

' Intial value of online player counter
Dim b As New ServerProperties(MyServer.MyStartupParameters.ServerProperties)

Dim s As String = b.ReturnConfigValue("max-players")
If s = Nothing Then
lblPlayerCounter.Content = ""
Else
lblPlayerCounter.Content = "0/" & b.ReturnConfigValue("max-players")
End If

' Intial value of online player counter
Dim s As String = b.ReturnConfigValue("max-players")
If s = Nothing Then
lblPlayerCounter.Content = ""
Else
lblPlayerCounter.Content = "0/" & b.ReturnConfigValue("max-players")
End If
End Sub

Expand Down
4 changes: 2 additions & 2 deletions MinecraftServerDashboard/Controls/PlayerLists.xaml.vb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ Public Class PlayerLists
Else
EmptyMessage.Text = "Nobody is online at the moment."

For Each i As Object In navpageDashboard.MyOnlinePlayerList.StackPanel1.Children
For Each i As Object In navpageDashboard.MyOnlinePlayerList.StackPanel.Children
If TypeOf i Is PlayerTile Then
PlayerListBox.Items.Add(CType(i, PlayerTile).username)
PlayerListBox.Items.Add(CType(i, PlayerTile).thisplayer.Username)
End If
Next

Expand Down
8 changes: 4 additions & 4 deletions MinecraftServerDashboard/Controls/PlayerTile.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="48" d:DesignWidth="290" Background="#FF1A6D93" Foreground="White" Height="48" Margin="2,0,0,0">
d:DesignHeight="48" d:DesignWidth="290" Foreground="White" Height="48" Margin="2,1,0,1">
<UserControl.ContextMenu>
<ContextMenu Name="PlayerItemContextmenu">
<!--<ContextMenu.Style>
Expand All @@ -17,8 +17,8 @@
</ContextMenu>
</UserControl.ContextMenu>
<Grid>
<Label Margin="0" BorderBrush="#F09609" BorderThickness="6,0,0,0" />
<Image Name="Image1" Stretch="Uniform" HorizontalAlignment="Left" Width="48" Height="48" Margin="2,0,0,0" />
<Label Content="Username" Margin="54,0,0,0" Name="Label1" VerticalContentAlignment="Center" FontSize="15" Foreground="White" />
<Label Margin="0" BorderThickness="2,0,0,0" />
<Image Name="Image1" Stretch="Uniform" HorizontalAlignment="Left" Width="48" Height="48" Margin="2,0,0,0" Source="/MinecraftServerDashboard;component/Images/Blank.png" />
<Label Content="Username" Margin="50,0,0,0" Name="Label1" VerticalContentAlignment="Center" FontSize="15" Foreground="White" Background="#B21A6D93" />
</Grid>
</UserControl>
34 changes: 17 additions & 17 deletions MinecraftServerDashboard/Controls/PlayerTile.xaml.vb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
Imports System.IO

Public Class PlayerTile
Public Property username As String
Public Property thisplayer As Player

Sub New(_username As String)
Sub New(_thisplayer As Player)

' This call is required by the designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.
username = _username
Label1.Content = _username
thisplayer = _thisplayer
Label1.Content = thisplayer.DisplayName

' Load the player's AVARTAR (skin) from the internet
Dim UserTileImage As New BitmapImage()
Expand All @@ -36,7 +36,7 @@ Public Class PlayerTile
'UserTileImage = New BitmapImage(myuri)
Else
UserTileImage.BeginInit()
UserTileImage.UriSource = New Uri("http://minotar.net/avatar/" & _username & "/" & Image1.Height & ".png", UriKind.Absolute)
UserTileImage.UriSource = New Uri("http://minotar.net/avatar/" & thisplayer.Username & "/" & Image1.Height & ".png", UriKind.Absolute)
UserTileImage.CacheOption = BitmapCacheOption.OnDemand
UserTileImage.EndInit()

Expand All @@ -58,38 +58,38 @@ Public Class PlayerTile
End Sub

Private Sub PlayerItemContextmenu_Opened(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles PlayerItemContextmenu.Opened
Dim bc As New BrushConverter
Me.Background = bc.ConvertFrom("#FF2A90C1")
'Dim bc As New BrushConverter
'Me.Background = bc.ConvertFrom("#FF2A90C1")
End Sub

Private Sub PlayerItemContextmenu_Closed(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles PlayerItemContextmenu.Closed
Dim bc As New BrushConverter
Me.Background = bc.ConvertFrom("#FF1A6D93")
'Dim bc As New BrushConverter
'Me.Background = bc.ConvertFrom("#FF1A6D93")
End Sub

Private Sub UserControl_MouseEnter(sender As System.Object, e As System.Windows.Input.MouseEventArgs) Handles MyBase.MouseEnter
Dim bc As New BrushConverter
Me.Background = bc.ConvertFrom("#FF2A90C1")
'Dim bc As New BrushConverter
'Me.Background = bc.ConvertFrom("#FF2A90C1")
End Sub

Private Sub UserControl_MouseLeave(sender As System.Object, e As System.Windows.Input.MouseEventArgs) Handles MyBase.MouseLeave
Dim bc As New BrushConverter
Me.Background = bc.ConvertFrom("#FF1A6D93")
'Dim bc As New BrushConverter
'Me.Background = bc.ConvertFrom("#FF1A6D93")
End Sub

Private Sub btnKick_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnKick.Click
MyServer.SendCommand("kick " + username)
MyServer.SendCommand("kick """ + thisplayer.Username + """")
End Sub

Private Sub btnBan_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnBan.Click
MyServer.SendCommand("ban " + username)
MyServer.SendCommand("ban """ + thisplayer.Username + """")
End Sub

Private Sub btnOp_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnOp.Click
MyServer.SendCommand("op " + username)
MyServer.SendCommand("op """ + thisplayer.Username + """")
End Sub

Private Sub btnDeOp_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnDeOp.Click
MyServer.SendCommand("deop " + username)
MyServer.SendCommand("deop """ + thisplayer.Username + """")
End Sub
End Class
1 change: 1 addition & 0 deletions MinecraftServerDashboard/MinecraftServerDashboard.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@
<Compile Include="Screens\Screens\QuickSetUp\WelcomeFrame.xaml.vb">
<DependentUpon>WelcomeFrame.xaml</DependentUpon>
</Compile>
<Compile Include="ServerProccess\DataTypes\PlayerInfo.vb" />
<Compile Include="ServerProccess\ServerRestartHelper.vb" />
<Compile Include="ServerProccess\TaskScheduler.vb">
<SubType>Component</SubType>
Expand Down
2 changes: 1 addition & 1 deletion MinecraftServerDashboard/Modules/PlayerListEditor.vb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Public Class PlayerListEditor
thisFilename = MyServer.MyStartupParameters.ServerPath & filename(type, TXT_INDEX)
If Not My.Computer.FileSystem.FileExists(MyServer.MyStartupParameters.ServerPath & filename(type, TXT_INDEX)) Then
' Create a new blank file
System.IO.File.WriteAllText(My.Computer.FileSystem.CurrentDirectory & "\" & thisFilename, "")
System.IO.File.WriteAllText(thisFilename, "")
End If
End If

Expand Down
83 changes: 51 additions & 32 deletions MinecraftServerDashboard/Modules/ProcessPlayerList.vb
Original file line number Diff line number Diff line change
@@ -1,53 +1,72 @@
Public Module PlayerList

Public Function ProcessPlayerList(input As String) As List(Of String)
Dim PlayerList As New List(Of String)

' Remove [INFO] string if it exists
' e.g. 2013-07-09 16:46:13 [INFO] bearbear12345
' or:
' e.g. 2013-07-09 16:46:13 [INFO] [Minecraft-Server] bearbear12345
Dim f As String
If input.Contains("INFO]:") Then
f = "INFO]: "
ElseIf input.Contains("INFO] [Minecraft-Server] ") Then
f = "INFO] [Minecraft-Server] "
Imports System.Text.RegularExpressions

Public Module PlayerList
'"[^A-Z0-9.$ ]$"
Const VALIDCHARS As String = "[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.$]"

Public Function ProcessPlayerList(consoleOutput As String) As List(Of Player)
Dim playerList As New List(Of Player)

Dim s As String = ""

'First, strip of any prefixing "[INFO]" tag strings if required
' e.g. 2013-07-09 16:46:13 [INFO] bearbear12345
' or
' e.g. 2013-07-09 16:46:13 [INFO] [Minecraft-Server] bearbear12345
Dim prefix As String
If consoleOutput.Contains("INFO]:") Then
prefix = "INFO]: "
ElseIf consoleOutput.Contains("INFO] [Minecraft-Server] ") Then
prefix = "INFO] [Minecraft-Server] "
Else
f = "INFO] "
prefix = "INFO] "
End If

Dim i As Integer = input.IndexOf(f)
Dim s As String = ""
If input.Contains(f) Then
If Not ((i + f.Length) = (input.Length - (i + f.Length))) Then
s = input.Substring(i + f.Length, input.Length - (i + f.Length))
Dim i As Integer = consoleOutput.IndexOf(prefix)

If consoleOutput.Contains(prefix) Then
If Not ((i + prefix.Length) = (consoleOutput.Length - (i + prefix.Length))) Then
s = consoleOutput.Substring(i + prefix.Length, consoleOutput.Length - (i + prefix.Length))
Else
s = ""
End If
Else
s = input
s = consoleOutput
End If

'If Not i + 8 = input.Length Then

'Break up the string into its separate words
Dim wordList As New List(Of String)
If Not s Is Nothing Then
Dim words = s.Split({" "c}, StringSplitOptions.RemoveEmptyEntries)

'Dim m As Integer
For Each f In words
'm += 1
'Dim x As String = "17:19:53 [INFO] Connected players: "
'Dim e As String = "2012-06-01 17:19:53 [INFO] Connected players: "
If f.EndsWith(",") Then
PlayerList.Add(f.Substring(0, f.Length - 1))
For Each prefix In words
'Remove any trailing comma
If prefix.EndsWith(",") Then
wordList.Add(prefix.Substring(0, prefix.Length - 1))
Else
PlayerList.Add(f)
wordList.Add(prefix)
End If
Next

End If

Return PlayerList
'Filter through words with invalid characters, until the next proper username is found.
'Combine this proper username with the current set of invalid words ('tags'), and add this. Repeat.
Dim r As Regex = New Regex(VALIDCHARS)
Dim curr As String = ""

For Each item In wordList
If (r.IsMatch(item)) Then
' validation failed
curr &= item & " "
Else
playerList.Add(New Player(curr & item, item))
curr = ""
End If

Next

Return playerList
End Function

End Module
4 changes: 2 additions & 2 deletions MinecraftServerDashboard/Pages/PageConsole.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</LinearGradientBrush>
</Page.Background>
<Grid>
<Border x:Name="InfoTip_EmptyConsole_N00b" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Border x:Name="InfoTip_EmptyConsole_N00b" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
<Grid>
<Border Height="41" VerticalAlignment="Top">
<Border.Background>
Expand All @@ -50,7 +50,7 @@
</Grid>
</Grid>
</Border>
<Grid Margin="0" Background="Black" Visibility="{Binding ServerColdBoot, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, FallbackValue=Collapsed}">
<Grid Margin="0" Background="Black" Visibility="{Binding ServerColdBoot, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, FallbackValue=Visible}">
<!--<Grid Margin="12,0,0,0">-->
<DockPanel LastChildFill="True">
<TextBox
Expand Down
Loading

0 comments on commit efcb44b

Please sign in to comment.