Poll: Is it any good?
You do not have permission to vote in this poll.
Yeah
62.50%
15 62.50%
No
8.33%
2 8.33%
A little
29.17%
7 29.17%
Total 24 vote(s) 100%
* You voted for this item. [Show Results]

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Socket for Movement - Completed
#1
Completed! Not Tested yet! But I think it works.

By: William
Difficulty: 3/5
Source: http://www.key2heaven.net/Socket2.rar

Thanks to Bhenur for the idea and explanation behind it.

Introduction
Backup your source!
Currently, the movement is handled through the same socket as everything else that sends from the client to the server. This tutorial will add two new sockets. One to the client and one to the server that handles the movement. So the sending delays decreases.

Client Side
Begin with adding a new socket to frmMirage. Name it "Socket2" without the quote tags.
Find:
Code:
frmMirage.Socket.RemoteHost = GAME_IP
    frmMirage.Socket.RemotePort = GAME_PORT
Below add:
Code:
frmMirage.Socket2.RemoteHost = GAME_IP
    frmMirage.Socket2.RemotePort = GAME_PORT2
Find:
Code:
Sub TcpDestroy()
    frmMirage.Socket.Close
Replace it with:
Code:
Sub TcpDestroy()
    frmMirage.Socket.Close
    frmMirage.Socket2.Close
Under:
Code:
Sub IncomingData(ByVal DataLength As Long)
Add this sub:
Code:
Sub IncomingData2(ByVal DataLength As Long)
Dim Buffer As String
Dim Packet As String
Dim top As String * 3
Dim Start As Integer

    frmMirage.Socket2.GetData Buffer, vbString, DataLength
    PlayerBuffer = PlayerBuffer & Buffer
        
    Start = InStr(PlayerBuffer, END_CHAR)
    Do While Start > 0
        Packet = Mid(PlayerBuffer, 1, Start - 1)
        PlayerBuffer = Mid(PlayerBuffer, Start + 1, Len(PlayerBuffer))
        Start = InStr(PlayerBuffer, END_CHAR)
        If Len(Packet) > 0 Then
            Call HandleData(Packet)
        End If
    Loop
End Sub
Under:
Code:
Public Function ConnectToServer() As Boolean
Add:
[code]Public Function ConnectToServer2() As Boolean
'****************************************************************
'* WHEN WHO WHAT
'* ---- --- ----
'* 07/12/2005 Shannara Optimized function.
'****************************************************************

Dim Wait As Long

' Check to see if we are already connected, if so just exit
If IsConnected2 Then
ConnectToServer2 = True
Exit Function
End If

Wait = GetTickCount
With frmMirage.Socket2
.Close
.Connect
End With

' Wait until connected or 3 seconds have passed and report the server being down
Do While (Not IsConnected2) And (GetTickCount = Player(Index).DataTimer + 1000 Then
Player(Index).DataTimer = GetTickCount
Player(Index).DataBytes = 0
Player(Index).DataPackets = 0
Exit Sub
End If

' Check for data flooding
If Player(Index).DataBytes > 1000 And GetPlayerAccess(Index)
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)