📄 mainclient.vb.svn-base
字号:
'### Visual Basic.NET and Direct X9 Legend of MiR Project ###'
'### Mir Unleashed Client Main Client Module ###'
'### http://www.lomcn.co.uk ###' '### Credits to TrueADM and DeathWish ###'
'This is where the main client does its work. Sorting out packets recieved etc.
'Once the packet matches the case under "Process Game Packets" it will then go on todo that Process.
Module MainClient
'client
Public WithEvents Socket As New SocketClient
Public LastPacket As String = ""
Private Sub Socket_onConnect(ByVal sNow As String) Handles Socket.onConnect
If LoginStage = LoginStageType.LOGIN Then
Connected = True
ConnectionState.Text = "Connected To Login Server."
ElseIf LoginStage = LoginStageType.LOAD_GAME Then
LoginStage = LoginStageType.NOTICE
'SendStartGame()
End If
End Sub
Private Sub Socket_onConnecting(ByVal sNow As String) Handles Socket.onConnecting
End Sub
Private Sub Socket_onTimeOut(ByVal sNow As String) Handles Socket.onTimeOut
ConnectionState.Text = "Unable To Connect, Please try again."
End Sub
Private Sub Socket_onDisconnect(ByVal sNow As String) Handles Socket.onDisconnect
ConnectionState.Text = "Connection To The Server Has Been Lost."
End Sub
Private Sub Socket_onError(ByVal sDescription As String, ByVal iNumber As Integer, ByVal sNow As String) Handles Socket.onError
End Sub
Public Sub ProcessPacket(ByVal sData() As Byte, ByVal iTotalBytes As Integer, ByVal sNow As String) Handles Socket.onDataArrival
Dim Packet As String
Dim Pieces() As String
ReDim Preserve sData(iTotalBytes - 1)
Packet = System.Text.Encoding.ASCII.GetString(sData)
If Not LastPacket = "" Then
Packet = LastPacket & Packet
LastPacket = ""
End If
If Not Right(Packet, 1) = Chr(30) Then
LastPacket = Packet
Exit Sub
End If
Packet = LastPacket & Packet
Pieces = Split(Packet, Chr(30))
Dim R As Integer
For R = LBound(Pieces) To UBound(Pieces)
Packet = Pieces(R)
If Not Packet = "" Then ProcessGamePackets(Packet)
Next R
End Sub
Public Sub ProcessGamePackets(ByVal Packet As String)
Dim Header As Header
Header = DecodePacketHeader(Packet)
Select Case Header.wIdent
Case GameMsg.SM_CLIENT_VERSION_REQUEST
Dim Body As String
Body = DecodePacketBody(Packet)
Packets.SendClientVersion(Body)
Case GameMsg.SM_LOGIN_OK
Packets.SendSelectServer(ServerName)
Case GameMsg.SM_LOGIN_FAIL
Dim ErrorNumber As Integer
Select Case ErrorNumber
Case 0
ShowMessage("Incorrect Username or Password." & vbCrLf & "Please Enter the correct details you registered with to continue!" & vbCrLf & "If you enter the incorrect details three times your account will be locked!", "Wrong Login Details Used!")
Case 1
ShowMessage("Your Account Has Been Locked." & vbCrLf & "You entered the incorrect details too many times, please wait 15 minutes and try again!", "Account Locked")
Case 2
ShowMessage("Your Account Has Been Banned." & vbCrLf & "Your account has been suspened if you have any disputes please contact the developers.", "Account Banned!")
Case 3
ShowMessage("Unknown Error! Report Error Number: 1", "Uknown Error")
End Select
Case GameMsg.SM_NEWACCOUNT_FAIL
Dim ErrorNumber As Integer
Select Case ErrorNumber
Case 0
ShowMessage("This Account already exists." & vbCrLf & "Please use a different account name!" & vbCrLf & vbCrLf & "If this is your account you can use the reset password feature on our website!", "Account Already Exists!")
Case 1
ShowMessage("The Account creation system is currently offline." & vbCrLf & "Please try again later", "Account Creation Offline!")
Case 2
ShowMessage("Unknown Error! Report Error Number: 2", "Uknown Error")
End Select
Case GameMsg.SM_NEWACCOUNT_OK
ShowMessage("Your Account Has Been Successfully Created, You Can Now Log In." & vbCrLf & "If you experience any problems please contact the developers!" & vbCrLf & vbCrLf & "Homepage: http://www.levelme.net/forum", "Account Created!")
Window(2).Show = False
Textbox(2).Text = ""
Textbox(3).Text = ""
Textbox(4).Text = ""
Textbox(5).Text = ""
Textbox(6).Text = ""
Textbox(7).Text = ""
Textbox(8).Text = ""
Textbox(9).Text = ""
Case GameMsg.SM_CHANGEPASSWORD_OK
ShowMessage("Password changed sucessfully.")
Case GameMsg.SM_CHANGEPASSWORD_FAIL
Case GameMsg.SM_GOSELCHAR
Dim Body As String
Dim SelChrIP As String = ServerIP
Dim SelChrPort As Integer
Body = DecodePacketBody(Packet)
Header = DecodePacketHeader(Packet)
Cert = Header.nRecog
SelChrIP = GetTok(Body, 0, "/")
SelChrPort = GetTok(Body, 1, "/")
SelChrIP = SelChrIP
SelChrPort = SelChrPort
Socket.Disconnect()
Socket.RemoteHost = ServerIP
Socket.RemotePort = SelChrPort
Socket.Connect()
System.Threading.Thread.Sleep(1000)
If Socket.Connected = True Then
Connected = True
LoginStage = LoginStageType.CHAR_SEL
ShowMessage("Welcome to the Legend of Mir Character selection!" & vbCrLf & "You are currently playing on the server: '" & ServerName & "'.")
Packets.SendQueryChar(Username, Password, Cert)
Else
ShowMessage("Connection To The Server Has Been Lost.")
End If
Case GameMsg.SM_QUERYCHR_OK
CharacterCount = Header.nRecog
If CharacterCount = 0 Then
ShowMessage("It appear's that you do not yet have a character!" & vbCrLf & "To continue into the world of Mir you will need a hero!'" & vbCrLf & "Please create your hero with our Create 'New Hero' System!")
Exit Sub
End If
Packet = DecodePacketBody(Packet)
Packet = Packet.TrimStart("*")
Select Case CharacterCount
Case 1
Character(0).Name = GetTok(Packet, 0, "/")
Character(0).Job = GetTok(Packet, 1, "/")
Character(0).Hair = GetTok(Packet, 2, "/")
Character(0).Level = GetTok(Packet, 3, "/")
Character(0).Gender = GetTok(Packet, 4, "/")
Case 2
Dim Chr1, Chr2 As String
Chr1 = GetTok(Packet, 0, "*")
Chr2 = GetTok(Packet, 1, "*")
Character(0).Name = GetTok(Packet, 0, "/")
Character(0).Job = GetTok(Packet, 1, "/")
Character(0).Hair = GetTok(Packet, 2, "/")
Character(0).Level = GetTok(Packet, 3, "/")
Character(0).Gender = GetTok(Packet, 4, "/")
Character(1).Name = GetTok(Chr2, 0, "/")
Character(1).Job = GetTok(Chr2, 1, "/")
Character(1).Hair = GetTok(Chr2, 2, "/")
Character(1).Level = GetTok(Chr2, 3, "/")
Character(1).Gender = GetTok(Chr2, 4, "/")
End Select
Case GameMsg.SM_START_PLAY
Packet = DecodePacketBody(Packet)
Dim GameIP As String = ServerIP
Dim GamePort As Integer
GameIP = GetTok(Packet, 0, "/")
GamePort = GetTok(Packet, 1, "/")
GameIP = GameIP
GamePort = GamePort
Socket.Disconnect()
Socket.RemoteHost = ServerIP
Socket.RemotePort = GamePort
Socket.Connect()
System.Threading.Thread.Sleep(1000)
If Socket.Connected = True Then
Packets.SendRequestNotice()
Connected = True
Else
'ShowMessage("Connection Closed...")
'AddLog("Socket Error", "Could not connect to remote host")
End If
Case GameMsg.SM_START_FAIL
ShowMessage("Failed to enter server.")
Case GameMsg.SM_NOTICE_OK
Connected = True
Notice = DecodePacketBody(Packet)
LoginStage = LoginStageType.LOAD_GAME
Case GameMsg.SM_NOTICE_FAIL
Running = False
Case GameMsg.SM_NEWMAP
Dim Body As String = DecodePacketBody(Packet)
Actor.ServerID = Header.nRecog
Actor.X = Header.wParam
Actor.Y = Header.wTag
Actor.CurrentX = Actor.X
Actor.CurrentY = Actor.Y
AddTilePlayerCollsion(Actor.X, Actor.Y)
Actor.Light = Header.wSeries
Actor.MapFileName = GetTok(Body, 0, "/")
Actor.MapName = GetTok(Body, 1, "/")
QueueLoadMap = True
Case GameMsg.SM_MAPLIGHT
'Dim Body As String = DecodePacketBody(Packet)
Actor.MapLight = Header.nRecog
Case GameMsg.SM_MOVE
Packet = DecodePacketBody(Packet)
Dim Part() As String = Split(Packet, "/")
Dim Race As Races = Part(2)
Select Case Race
Case Races.Player
Dim Id As Integer = Header.nRecog
If Id = Actor.ServerID Then Exit Sub
Dim Dir As Byte = Header.wTag
Dim Steps As Byte = Header.wParam
Dim X, Y As Short
Dim NextMove As Boolean = Header.wSeries
X = Part(0)
Y = Part(1)
ProcessPlayerAction(PlayerActionType.Move, Id, Dir, Steps, X, Y)
Case Races.Monster
Dim Id As Long = Header.nRecog
Dim Dir As Byte = Header.wTag
Dim Steps As Byte = Header.wParam
Dim X, Y As Short
Dim NextMove As Boolean = Header.wSeries
X = Part(0)
Y = Part(1)
ProcessMobAction(PlayerActionType.Move, Id, Dir, X, Y)
End Select
Case GameMsg.SM_MOVE_FAIL
Packet = DecodePacketBody(Packet)
Dim CordX As Short = Header.nRecog
Dim CordY As Short = Header.wParam
Dim mDir As Byte = Header.wTag
Actor.X = CordX
Actor.Y = CordY
Actor.CurrentX = CordX
Actor.CurrentY = CordY
Actor.Direction = mDir
Actor.ActionState = 0
'clear the stack
Dim I As Integer
For I = 0 To 15
Actor.StackExist(I) = False
Actor.StackItems = 0
Next I
Case GameMsg.SM_CHARSTATUS
Dim Body As String = DecodePacketBody(Packet)
Dim Part() As String = Split(Body, "/")
If Actor.ServerID = Header.nRecog Then
Actor.Light = Header.wParam
Actor.HealthBarOpen = Trim(Header.wTag)
Actor.IsDead = Trim(Header.wSeries)
Actor.Name = Part(0)
Actor.NameColour = Part(1)
Actor.Gender = Part(2)
Actor.Guild = Part(3)
Actor.GuildRankName = Part(4)
Actor.GuildRankNumber = Part(5)
End If
Case GameMsg.SM_CHARSTATS
Dim Body As String = DecodePacketBody(Packet)
Dim Part() As String = Split(Body, "/")
Dim i As Integer = 0
Actor.Gold = Header.wParam
Actor.GameClass = Header.wTag
Actor.AC = Part(i)
i += 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -