Imports System.Net.Sockets Imports System.IO Imports System.Net Public Class PatchServer Public Sub Main() Dim FileList As New ArrayList() FileList.Add("cfg.txt") FileList.Add("plist.txt") For i As Integer = 0 To FileList.Count - 1 If Not File.Exists(FileList(i)) Then WriteConsole(FileList(i) & " not exists! Please check your Files!", 0) System.Threading.Thread.Sleep(3000) Environment.Exit(0) End If Next For i As Integer = 0 To FileList.Count - 1 If Not File.Exists(FileList(i)) Then WriteConsole(FileList(i) & " not exists! Please check your Files!", 0) System.Threading.Thread.Sleep(3000) End If Next If MyFunction.TestSQLConnection = False Then WriteConsole("SQL Connection not stable", 0) System.Threading.Thread.Sleep(3000) End If Dim cfg As String = IO.File.ReadAllText("cfg.txt") Dim plist As String = IO.File.ReadAllText("plist.txt") Dim ConnectionList As New Dictionary(Of String, DateTime) Dim TCPListen As New TcpListener(IPAddress.Any, 11100) TCPListen.Start() WriteConsole("Successfully started Patch Server", 3) While True Try Dim TCP As TcpClient = TCPListen.AcceptTcpClient() TCP.ReceiveTimeout = 3000 Dim NetStream As NetworkStream = TCP.GetStream() Dim swriter As New StreamWriter(NetStream) Dim sreader As New StreamReader(NetStream) If ConnectionList.ContainsKey(TCP.Client.RemoteEndPoint.ToString.Split(":")(0)) AndAlso ConnectionList(TCP.Client.RemoteEndPoint.ToString.Split(":")(0)) < DateTime.Now Then ConnectionList.Remove(TCP.Client.RemoteEndPoint.ToString.Split(":")(0)) End If If ConnectionList.ContainsKey(TCP.Client.RemoteEndPoint.ToString.Split(":")(0)) Then swriter.Close() sreader.Close() NetStream.Close() TCP.Close() Else ConnectionList.Add(TCP.Client.RemoteEndPoint.ToString.Split(":")(0), DateTime.Now.AddSeconds(30)) Dim message As String = Nothing message = MyFunction.Decrypt(sreader.ReadLine) If message = "getPatches" Then WriteConsole("New Session from " & TCP.Client.RemoteEndPoint.ToString.Split(":")(0), 2) swriter.WriteLine(MyFunction.Encrypt(cfg)) swriter.Flush() swriter.WriteLine(MyFunction.Encrypt(plist)) swriter.Flush() ConnectionList.Remove(TCP.Client.RemoteEndPoint.ToString.Split(":")(0)) ElseIf message = "getToken" Then message = MyFunction.Decrypt(sreader.ReadLine) swriter.WriteLine(MyFunction.Encrypt(MyFunction.ConnectToSQL(message.Split(vbTab)(0), message.Split(vbTab)(1)))) swriter.Flush() End If swriter.Close() sreader.Close() NetStream.Close() TCP.Close() End If Catch ex As Exception WriteConsole(ex.Message, 0) End Try End While End Sub Private Sub WriteConsole(ByVal Text As String, ByVal Type As Integer) If Type = 0 Then Console.ForegroundColor = ConsoleColor.Red ElseIf Type = 1 Then Console.ForegroundColor = ConsoleColor.Yellow ElseIf Type = 2 Then Console.ForegroundColor = ConsoleColor.Green ElseIf Type = 3 Then Console.ForegroundColor = ConsoleColor.Cyan Else Console.ForegroundColor = ConsoleColor.Blue End If Console.Write(DateTime.Now.ToString & vbTab) Console.WriteLine(Text) Console.ForegroundColor = ConsoleColor.White End Sub End Class