Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed some code analysis warnings

  • Loading branch information...
commit 0fe92f30bf8fd2ab98adaa9a7a1f99443a2cdcd6 1 parent 852368c
@Strilanc authored
View
84 CKL/CKL Server.vb
@@ -87,49 +87,53 @@ Namespace CKL
AsyncProduceConsumeUntilError(
producer:=AddressOf socket.AsyncReadPacket,
- consumer:=Function(packetData) inQueue.QueueAction(
- Sub()
- Dim flag = packetData(0)
- Dim id = packetData(0)
- Dim data = packetData.SubView(4)
- Dim responseData As Byte() = Nothing
- Dim errorMessage As String = Nothing
- If flag <> PacketPrefixValue Then
- errorMessage = "Invalid header id."
+ consumer:=Function(packetData) inQueue.QueueAction(Sub() HandlePacket(socket, packetData)),
+ errorHandler:=Sub(exception) Logger.Log("Error receiving from {0}: {1}".Frmt(socket.Name, exception.Message), LogMessageType.Problem)
+ )
+ End Sub
+ Private Sub HandlePacket(ByVal socket As PacketSocket, ByVal packetData As IReadableList(Of Byte))
+ Contract.Requires(socket IsNot Nothing)
+ Contract.Requires(packetData IsNot Nothing)
+ Contract.Assume(packetData.Count >= 4)
+
+ Dim flag = packetData(0)
+ Dim id = packetData(0)
+ Dim data = packetData.SubView(4)
+ Dim responseData As Byte() = Nothing
+ Dim errorMessage As String = Nothing
+ If flag <> PacketPrefixValue Then
+ errorMessage = "Invalid header id."
+ Else
+ Select Case CType(id, CKLPacketId)
+ Case CKLPacketId.[Error]
+ 'ignore
+ Case CKLPacketId.Keys
+ If _keys.Count <= 0 Then
+ errorMessage = "No keys to lend."
+ ElseIf data.Count <> 8 Then
+ errorMessage = "Invalid length. Require client token [4] + server token [4]."
Else
- Select Case CType(id, CKLPacketId)
- Case CKLPacketId.[Error]
- 'ignore
- Case CKLPacketId.Keys
- If _keys.Count <= 0 Then
- errorMessage = "No keys to lend."
- ElseIf data.Count <> 8 Then
- errorMessage = "Invalid length. Require client token [4] + server token [4]."
- Else
- If _keyIndex >= _keys.Count Then _keyIndex = 0
- Dim credentials = _keys(_keyIndex).GenerateCredentials(clientToken:=data.SubView(0, 4).ToUInt32,
- serverToken:=data.SubView(4, 4).ToUInt32)
- responseData = {jar.Pack(credentials.AuthenticationROC).Data,
- jar.Pack(credentials.AuthenticationTFT).Data
- }.Fold.ToArray
- logger.Log("Provided key '{0}' to {1}".Frmt(_keys(_keyIndex).Name, socket.Name), LogMessageType.Positive)
- _keyIndex += 1
- End If
- Case Else
- errorMessage = "Invalid packet id."
- End Select
+ If _keyIndex >= _keys.Count Then _keyIndex = 0
+ Dim credentials = _keys(_keyIndex).GenerateCredentials(clientToken:=data.SubView(0, 4).ToUInt32,
+ serverToken:=data.SubView(4, 4).ToUInt32)
+ responseData = {jar.Pack(credentials.AuthenticationROC).Data,
+ jar.Pack(credentials.AuthenticationTFT).Data
+ }.Fold.ToArray
+ Logger.Log("Provided key '{0}' to {1}".Frmt(_keys(_keyIndex).Name, socket.Name), LogMessageType.Positive)
+ _keyIndex += 1
End If
+ Case Else
+ errorMessage = "Invalid packet id."
+ End Select
+ End If
- If responseData IsNot Nothing Then
- socket.WritePacket(Concat({PacketPrefixValue, id, 0, 0}, responseData))
- End If
- If errorMessage IsNot Nothing Then
- logger.Log("Error parsing data from client: " + errorMessage, LogMessageType.Negative)
- socket.WritePacket(Concat({PacketPrefixValue, CKLPacketId.[Error]}, System.Text.UTF8Encoding.UTF8.GetBytes(errorMessage)))
- End If
- End Sub),
- errorHandler:=Sub(exception) logger.Log("Error receiving from {0}: {1}".Frmt(socket.Name, exception.Message), LogMessageType.Problem)
- )
+ If responseData IsNot Nothing Then
+ socket.WritePacket(Concat({PacketPrefixValue, id, 0, 0}, responseData))
+ End If
+ If errorMessage IsNot Nothing Then
+ Logger.Log("Error parsing data from client: " + errorMessage, LogMessageType.Negative)
+ socket.WritePacket(Concat({PacketPrefixValue, CKLPacketId.[Error]}, System.Text.UTF8Encoding.UTF8.GetBytes(errorMessage)))
+ End If
End Sub
Public Sub [Stop]()
View
1  Code Analysis Rules.ruleset
@@ -20,6 +20,7 @@
<Rule Id="CA1303" Action="None" />
<Rule Id="CA1710" Action="None" />
<Rule Id="CA1711" Action="None" />
+ <Rule Id="CA1724" Action="None" />
<Rule Id="CA1804" Action="None" />
<Rule Id="CA1811" Action="None" />
<Rule Id="CA1815" Action="None" />
View
2  Components/Component Extensions.vb
@@ -1,7 +1,7 @@
Namespace Components
Public Module IBotComponentExtensions
<Extension()>
- <System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")>
+ <CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")>
Public Sub UIInvokeCommand(ByVal component As IBotComponent, ByVal argument As String)
Contract.Requires(component IsNot Nothing)
Contract.Requires(argument IsNot Nothing)
View
1  Interface/ClientForm.Designer.vb
@@ -3,6 +3,7 @@ Partial Class ClientForm
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
+ <CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId:="_bot")>
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
View
3  Interface/ClientForm.vb
@@ -5,6 +5,7 @@ Public Class ClientForm
Private _bot As Bot.MainBot
Private ReadOnly _exceptionForm As New ExceptionForm()
+ <CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")>
Private Shadows Sub OnLoad() Handles Me.Load
Contract.Assume(_bot Is Nothing)
Try
@@ -106,7 +107,7 @@ Public Class ClientForm
_bot.Logger.Log("Failed to add plugin '{0}' to bot: {1}".Frmt(pluginName_, ex), LogMessageType.Problem)
End Sub)
_bot.Logger.Log("Loaded plugin '{0}'.".Frmt(pluginName), LogMessageType.Positive)
- Catch ex As Exception
+ Catch ex As Plugins.PluginException
_bot.Logger.Log("Failed to load plugin profile '{0}': {1}".Frmt(pluginName, ex.Message), LogMessageType.Problem)
ex.RaiseAsUnexpected("Loading plugin profile '{0}'".Frmt(pluginName))
End Try
View
1  Interface/LoggerControl.Designer.vb
@@ -3,6 +3,7 @@ Partial Class LoggerControl
Inherits System.Windows.Forms.UserControl
'UserControl overrides dispose to clean up the component list.
+ <CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId:="filestream")>
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
View
13 Interface/SettingsForm.vb
@@ -254,16 +254,19 @@ Public Class SettingsForm
If newPath = path Then
gridPlugins.Rows.Add(pluginName, rel_path, "")
ElseIf IO.File.Exists(newPath) Then
- If MessageBox.Show("There is already a plugin with that filename in the plugins folder. Do you want to replace it?", "Replace", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
- Return
+ If MessageBox.Show(text:="There is already a plugin with that filename in the plugins folder. Do you want to replace it?",
+ caption:="Replace",
+ buttons:=MessageBoxButtons.YesNo,
+ icon:=MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
+ IO.File.Copy(path, newPath, overwrite:=True)
End If
- IO.File.Delete(newPath)
- IO.File.Copy(path, newPath)
Else
IO.File.Copy(path, newPath)
gridPlugins.Rows.Add(pluginName, rel_path, "")
End If
- Catch ex As Exception
+ Catch ex As Exception When TypeOf ex Is IO.IOException OrElse
+ TypeOf ex Is NotSupportedException OrElse
+ TypeOf ex Is UnauthorizedAccessException
ex.RaiseAsUnexpected("Importing plugin from settings form.")
MessageBox.Show("Error importing plugin: {0}".Frmt(ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
View
3  My Project/AssemblyInfo.vb
@@ -9,7 +9,7 @@ Imports System.Runtime.InteropServices
' Review the values of the assembly attributes
<Assembly: AssemblyTitle("Tinker")>
-<Assembly: AssemblyDescription("")>
+<Assembly: AssemblyDescription("A warcraft 3 hostbot.")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("Tinker")>
<Assembly: AssemblyCopyright("")>
@@ -34,4 +34,5 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyVersion("1.0.0.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")>
+<Assembly: CLSCompliant(False)>
<Assembly: ContractVerification(True)>
View
4 Plugins/Plugin Socket.vb
@@ -24,8 +24,8 @@ Namespace Plugins
Dim classType = asm.GetType("TinkerPluginFactory")
If classType Is Nothing Then Throw New OperationFailedException("The target assembly doesn't contain a TinkerPluginFactory.")
Me._plugin = CType(Activator.CreateInstance(classType), IPluginFactory).AssumeNotNull.CreatePlugin(bot)
- Catch e As Exception
- Throw New PluginException("Error loading plugin assembly from '{0}': {1}.".Frmt(assemblyPath, e), e)
+ Catch ex As Exception
+ Throw New PluginException("Error loading plugin assembly from '{0}': {1}.".Frmt(assemblyPath, ex), ex)
End Try
End Sub
View
2  Tinker.vbproj.user
@@ -14,7 +14,7 @@
<FallbackCulture>en-US</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles>
<ErrorReportUrlHistory />
- <ProjectView>ProjectFiles</ProjectView>
+ <ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
View
1  Warcraft3/Server/GameSettings.vb
@@ -252,6 +252,7 @@
Return _greeting
End Get
End Property
+ <CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId:="Multi")>
Public ReadOnly Property UseMultiObs As Boolean
Get
Return _useMultiObs
View
30 Warcraft3/W3ConnectionAccepter.vb
@@ -67,28 +67,20 @@ Namespace WC3
SyncLock lock
_sockets.Add(socket)
End SyncLock
- socket.AsyncReadPacket().CallWhenValueReady(
- Sub(packetData, readException)
+
+ socket.AsyncReadPacket().CallOnValueSuccess(
+ Sub(packetData)
If Not TryRemoveSocket(socket) Then Return
- If readException IsNot Nothing Then
- socket.Disconnect(expected:=False, reason:=readException.Message)
- Return
- End If
-
- Try
- Dim id = CType(packetData(1), Protocol.PacketId)
- Dim pickle = ProcessConnectingPlayer(socket, packetData)
- _logger.Log(Function() "Received {0} from {1}".Frmt(id, socket.Name), LogMessageType.DataEvent)
- _logger.Log(Function() "Received {0} from {1}: {2}".Frmt(id, socket.Name, pickle.Description.Value), LogMessageType.DataParsed)
- Catch ex As Exception When TypeOf ex Is Net.Sockets.SocketException OrElse
- TypeOf ex Is ObjectDisposedException OrElse
- TypeOf ex Is PicklingException OrElse
- TypeOf ex Is IO.IOException OrElse
- TypeOf ex Is IO.InvalidDataException
- socket.Disconnect(expected:=False, reason:=ex.Message)
- End Try
+ Dim id = CType(packetData(1), Protocol.PacketId)
+ Dim pickle = ProcessConnectingPlayer(socket, packetData)
+ _logger.Log(Function() "Received {0} from {1}".Frmt(id, socket.Name), LogMessageType.DataEvent)
+ _logger.Log(Function() "Received {0} from {1}: {2}".Frmt(id, socket.Name, pickle.Description.Value), LogMessageType.DataParsed)
End Sub
+ ).Catch(
+ Sub(ex) socket.Disconnect(expected:=False, reason:=ex.Message)
)
+
+
_clock.AsyncWait(FirstPacketTimeout).CallWhenReady(
Sub()
If Not TryRemoveSocket(socket) Then Return
Please sign in to comment.
Something went wrong with that request. Please try again.