Skip to content
Snippets Groups Projects
Commit e984dd5f authored by Michael Alexander's avatar Michael Alexander
Browse files

JSON Classes done, some TBD

Login Register works
parent 56fb2919
Branches
No related merge requests found
Module GlobalVariables
' sets the Form's text property (title)
Public TOKEN As String = "Hello World!"
Public NETIO_SUCCESS As Integer = 0
Public SERVER_IP As String
Public SERVER_PORT As Integer
Public NETWORK As NetIO
End Module
Public Class Login
Imports Newtonsoft.Json
Public Class Login
Private Sub Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Login_Click(sender As Object, e As EventArgs) Handles LoginButton.Click
If (UsernameInput.Text = String.Empty Or PasswordInput.Text = String.Empty Or PortInput.Text = String.Empty Or ServerIPInput.Text = String.Empty) Then
MsgBox("Please fill Username, Password, and Server Details")
Else
InitializeConnection()
SERVER_IP = ServerIPInput.Text
SERVER_PORT = PortInput.Text
Dim loginjson As New LoginJSONSend
loginjson.username = UsernameInput.Text
loginjson.password = PasswordInput.Text
Dim recv As String
recv = NETWORK.SendRecv(loginjson)
Dim recvjson As New LoginJSONRecv
recvjson = JsonConvert.DeserializeObject(Of LoginJSONRecv)(recv)
If (recvjson.status = "ok") Then
TOKEN = recvjson.token
Map.Show()
Me.Close()
ElseIf (recvjson.status = "fail") Then
MsgBox(recvjson.description)
Else
MsgBox("Unknown error occured!")
End If
End If
End Sub
Private Sub RegisterButton_Click(sender As Object, e As EventArgs) Handles RegisterButton.Click
If (UsernameInput.Text = String.Empty Or PasswordInput.Text = String.Empty Or PortInput.Text = String.Empty Or ServerIPInput.Text = String.Empty) Then
MsgBox("Please fill Username, Password, and Server Details")
Else
InitializeConnection()
Dim net As New NetIO
MsgBox(net.SendRecv("ASD"))
Map.Show()
Me.Close()
Dim regjson As New RegisterJSONSend
regjson.username = UsernameInput.Text
regjson.password = PasswordInput.Text
Dim recv As String
recv = NETWORK.SendRecv(regjson)
Dim recvjson As New RegisterJSONRecv
recvjson = JsonConvert.DeserializeObject(Of RegisterJSONRecv)(recv)
If (recvjson.status = "ok") Then
MsgBox("Registration success!")
LoginButton.PerformClick()
ElseIf (recvjson.status = "fail") Then
MsgBox(recvjson.description)
Else
MsgBox("Unknown error occured!")
End If
End If
End Sub
Private Sub InitializeConnection()
'Initialize connection
SERVER_IP = ServerIPInput.Text
SERVER_PORT = PortInput.Text
NETWORK = New NetIO
End Sub
End Class
Imports System.Net.Sockets
Imports System.Text
Imports Newtonsoft.Json
Public Class NetIO
Private ClientSocket As New TcpClient
Private ServerStream As NetworkStream
Public Sub New()
MsgBox("Connecting")
ClientSocket.Connect(SERVER_IP, SERVER_PORT)
MsgBox("Connected")
Try
ClientSocket.Connect(SERVER_IP, SERVER_PORT)
Catch ex As Exception
MsgBox("Error connecting to server!")
End Try
End Sub
Public Function SendRecv(ByVal param As String) As String
MsgBox("Sending")
Dim toSend As String = "{""method"": ""login"",""username"": ""nozirohilol"", ""password"": ""a8f064bbec9819f488e6402a7c570da9""}"
Public Function SendRecv(ByVal param As Object) As String
Dim toSend As String
toSend = JsonConvert.SerializeObject(param)
Dim OutStream As Byte() = Encoding.UTF8.GetBytes(toSend)
Dim ReceivedData As String
......@@ -24,7 +28,7 @@ Public Class NetIO
ServerStream.Flush()
ServerStream.Read(inStream, 0, CInt(ClientSocket.ReceiveBufferSize))
ReceivedData = Encoding.ASCII.GetString(inStream)
ReceivedData = Encoding.UTF8.GetString(inStream)
Return ReceivedData
End Function
......
......@@ -49,6 +49,10 @@
<ApplicationManifest>My Project\app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>.\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
......@@ -74,6 +78,18 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Globals.vb" />
<Compile Include="JSONClasses\FetchItemJSON.vb" />
<Compile Include="JSONClasses\FieldJSON.vb" />
<Compile Include="JSONClasses\InventoryJSON.vb" />
<Compile Include="JSONClasses\LoginJSON.vb" />
<Compile Include="JSONClasses\MapJSON.vb" />
<Compile Include="JSONClasses\MixItemJSON.vb" />
<Compile Include="JSONClasses\MoveJSON.vb" />
<Compile Include="JSONClasses\OfferJSON.vb" />
<Compile Include="JSONClasses\RegisterJSON.vb" />
<Compile Include="JSONClasses\SendAcceptJSON.vb" />
<Compile Include="JSONClasses\SendFindJSON.vb" />
<Compile Include="JSONClasses\TradeboxJSON.vb" />
<Compile Include="Map.Designer.vb">
<DependentUpon>Map.vb</DependentUpon>
</Compile>
......@@ -132,7 +148,9 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Content Include="Newtonsoft.Json.dll" />
<Content Include="Newtonsoft.Json.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Resources\Chara\Idle\idle1.gif" />
<Content Include="Resources\Chara\Idle\idle2.gif" />
<Content Include="Resources\Chara\Idle\idle3.gif" />
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment