|
You last visited: Today at 12:12
Advertisement
[C#] Using drew's proxy
Discussion on [C#] Using drew's proxy within the SRO Coding Corner forum part of the Silkroad Online category.
09/29/2012, 20:50
|
#1
|
elite*gold: 0
Join Date: Apr 2009
Posts: 120
Received Thanks: 17
|
[C#] Using drew's proxy
I'm using  to connect to a pserver based on blackrogue files (Creddy PvP)
it waits forever at this line (no exceptions are thrown)
Code:
local_context.Socket = server.Accept();
any help ? thanks.
|
|
|
09/30/2012, 00:52
|
#2
|
elite*gold: 166
Join Date: Apr 2009
Posts: 2,339
Received Thanks: 2,661
|
My old CREDDY_CLIENTLESS project's proxies:
Gateway:
Code:
Option Infer On
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports SilkroadSecurityApi
Imports System.Diagnostics
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports System.IO
Public Class Gateway
Shared gw_security As New Security()
Shared gw_recv_buffer As New TransferBuffer(4096, 0, 0)
Shared gw_packets As New List(Of Packet)()
Shared gw_socket As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Public Shared version As UInteger = UInt32.Parse("197")a
Shared locale As UInteger = UInt32.Parse("22")
Shared [loop] As Thread
Public Sub Start(ByVal IP As String, ByVal Port As String)
[loop] = New Thread(AddressOf Gateway_thread)
gw_socket.Connect(IP, Int32.Parse(Port))
[loop].Start()
gw_socket.Blocking = False
gw_socket.NoDelay = True
End Sub
Public Sub Gateway_thread()
While True
Dim err As SocketError
gw_recv_buffer.Size = gw_socket.Receive(gw_recv_buffer.Buffer, 0, gw_recv_buffer.Buffer.Length, SocketFlags.None, err)
If err <> SocketError.Success Then
If err <> SocketError.WouldBlock Then
Exit While
End If
Else
If gw_recv_buffer.Size > 0 Then
gw_security.Recv(gw_recv_buffer)
Else
Exit While
End If
End If
Dim tmp_packets As List(Of Packet) = gw_security.TransferIncoming()
If tmp_packets IsNot Nothing Then
gw_packets.AddRange(tmp_packets)
End If
If gw_packets.Count > 0 Then
For Each packet As Packet In gw_packets
Dim packet_bytes As Byte() = packet.GetBytes()
Main.LogPacket("[S->C][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", packet.Opcode, packet_bytes.Length, If(packet.Encrypted, "[Encrypted]", ""), If(packet.Massive, "[Massive]", ""), Environment.NewLine, _
Utility.HexDump(packet_bytes), Environment.NewLine)
If packet.Opcode = &H5000 OrElse packet.Opcode = &H9000 Then
Continue For
End If
If packet.Opcode = &H2001 Then
If packet.ReadAscii() = "GatewayServer" Then
Globals.Server = Globals.ServerEnum.Gateway
Dim response As New Packet(&H6100, True, False)
response.WriteUInt8(locale)
response.WriteAscii("SR_Client")
response.WriteUInt32(version)
gw_security.Send(response)
Main.GUI.Ping.Enabled = True
End If
ElseIf packet.Opcode = &HA100 Then
Dim result As Byte = packet.ReadUInt8()
If result = 1 Then
Dim response As New Packet(&H6101, True)
gw_security.Send(response)
Else : Return
End If
ElseIf packet.Opcode = &HA101 Then
Dim ms As New MemoryStream(packet.GetBytes)
Dim readPacket As New BinaryReader(ms)
readPacket.ReadByte()
readPacket.ReadByte()
readPacket.ReadChars(readPacket.ReadUInt16())
readPacket.ReadByte()
readPacket.ReadByte()
Dim SvrID = readPacket.ReadUInt16()
Dim NameLen = readPacket.ReadUInt16()
Dim Name As Char() = readPacket.ReadChars(NameLen)
Dim RealName As New String(Name)
Dim CurOnServ As Integer = readPacket.ReadUInt16()
Dim MaxOnServ As Integer = readPacket.ReadUInt16()
Dim ServStat As Integer = readPacket.ReadByte()
Dim ServerStatus As String = ""
Select Case ServStat
Case 0
ServerStatus = "Check"
Case 1
ServerStatus = "Online"
Case 2
ServerStatus = "Offline"
End Select
Dim RetString As String = String.Concat(New String() {"Connected to ", RealName, " - ", CurOnServ, "/", MaxOnServ, " ", ServerStatus})
' Main.Log(RetString)
Main.GUI.btn_login.Enabled = True
Main.GUI.btn_connect.Enabled = False
ElseIf packet.Opcode = &HA102 Then
If packet.ReadUInt8() = 1 Then
Dim LoginID As UInteger = packet.ReadUInt32()
Dim ip As String = packet.ReadAscii()
Dim port As UShort = packet.ReadUInt16()
Dim ag As New Agent()
ag.Start(ip, port.ToString(), LoginID, Main.id, Main.pw)
Exit For
End If
ElseIf packet.Opcode = &H2322 Then
Main.GUI.Button1.Enabled = True
Dim pixels As UInt32() = Captcha.GeneratePacketCaptcha(packet)
Dim rnd As New Random()
Captcha.SaveCaptchaToBMP(pixels, Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & rnd.[Next](0, 999999) & ".bmp")
End If
Next
gw_packets.Clear()
End If
Dim tmp_buffers As List(Of KeyValuePair(Of TransferBuffer, Packet)) = gw_security.TransferOutgoing()
If tmp_buffers IsNot Nothing Then
Dim kvp
For Each kvp In tmp_buffers
Dim buffer As TransferBuffer = kvp.Key
Dim packet As Packet = kvp.Value
err = SocketError.Success
While buffer.Offset <> buffer.Size
Dim sent As Integer = gw_socket.Send(buffer.Buffer, buffer.Offset, buffer.Size - buffer.Offset, SocketFlags.None, err)
If err <> SocketError.Success Then
If err <> SocketError.WouldBlock Then
Exit While
End If
End If
buffer.Offset += sent
Thread.Sleep(1)
End While
If err <> SocketError.Success Then
Exit For
End If
Dim packet_bytes As Byte() = packet.GetBytes()
Main.LogPacket("[C->S][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", packet.Opcode, packet_bytes.Length, If(packet.Encrypted, "[Encrypted]", ""), If(packet.Massive, "[Massive]", ""), Environment.NewLine, _
Utility.HexDump(packet_bytes), Environment.NewLine)
Next
If err <> SocketError.Success Then
Exit While
End If
End If
Thread.Sleep(1)
End While
End Sub
Public Shared Sub SendToServer(ByVal packet As Packet)
gw_security.Send(packet)
End Sub
End Class
Agent:
[code][/Option Infer On
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports SilkroadSecurityApi
Imports System.Diagnostics
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Public Class Agent
Shared ag_security As New Security()
Shared ag_recv_buffer As New TransferBuffer(4096, 0, 0)
Shared ag_packets As New List(Of Packet)()
Shared ag_socket As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Public Shared version As UInteger = UInt32.Parse("197")
Shared locale As UInteger = UInt32.Parse("22")
Shared [loop] As Thread
Shared loginID As UInteger
Shared username As String
Shared password As String
Public Sub Start(ByVal IP As String, ByVal Port As String, ByVal _loginID As UInteger, ByVal _username As String, ByVal _password As String)
loginID = _loginID
username = _username
password = _password
[loop] = New Thread(AddressOf Agent_thread)
ag_socket.Connect(IP, Int32.Parse(Port))
[loop].Start()
ag_socket.Blocking = False
ag_socket.NoDelay = True
End Sub
Public Sub Agent_thread()
While True
Dim err As SocketError
' Receive logic, try to receive as much as possible, then pass to the security object
ag_recv_buffer.Size = ag_socket.Receive(ag_recv_buffer.Buffer, 0, ag_recv_buffer.Buffer.Length, SocketFlags.None, err)
If err <> SocketError.Success Then
If err <> SocketError.WouldBlock Then
' Console.WriteLine("Error: Receive returned error code {0}.", err);
Exit While
End If
Else
If ag_recv_buffer.Size > 0 Then
ag_security.Recv(ag_recv_buffer)
Else
' Console.WriteLine("Status: The connection has been closed.");
Exit While
End If
End If
' Obtain all queued packets and add them to our own queue to process later.
Dim tmp_packets As List(Of Packet) = ag_security.TransferIncoming()
If tmp_packets IsNot Nothing Then
ag_packets.AddRange(tmp_packets)
End If
If ag_packets.Count > 0 Then
For Each packet As Packet In ag_packets
Dim packet_bytes As Byte() = packet.GetBytes()
' Debug
Main.LogPacket("[S->C][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", packet.Opcode, packet_bytes.Length, If(packet.Encrypted, "[Encrypted]", ""), If(packet.Massive, "[Massive]", ""), Environment.NewLine, _
Utility.HexDump(packet_bytes), Environment.NewLine)
If packet.Opcode = &H5000 OrElse packet.Opcode = &H9000 Then
Continue For
End If
' Identify
If packet.Opcode = &H2001 Then
If packet.ReadAscii() = "GatewayServer" Then
Globals.Server = Globals.ServerEnum.Gateway
Dim response As New Packet(&H6100, True, False)
response.WriteUInt8(locale)
response.WriteAscii("SR_Client")
response.WriteUInt32(version)
ag_security.Send(response)
Else
Globals.Server = Globals.ServerEnum.Agent
Dim p As New Packet(&H6103)
p.WriteUInt32(loginID)
p.WriteAscii(username)
p.WriteAscii(password)
p.WriteUInt8(22)
p.WriteUInt32(0)
p.WriteUInt16(0)
ag_security.Send(p)
End If
ElseIf packet.Opcode = &HA103 Then
If packet.ReadUInt8() = 1 Then
Dim response As New Packet(&H7007)
response.WriteUInt8(2)
ag_security.Send(response)
End If
ElseIf packet.Opcode = &HB007 Then
Login.HandleCharList(packet)
ElseIf packet.Opcode = &H3020 Then
Dim p As New Packet(&H3012)
Send(p)
ElseIf packet.Opcode = &H3013 Then
PacketHandler.HandleCharPacket(packet.GetBytes)
End If
Next
ag_packets.Clear()
End If
' Check to see if we have any packets to send
Dim tmp_buffers As List(Of KeyValuePair(Of TransferBuffer, Packet)) = ag_security.TransferOutgoing()
If tmp_buffers IsNot Nothing Then
Dim kvp
For Each kvp In tmp_buffers
Dim buffer As TransferBuffer = kvp.Key
Dim packet As Packet = kvp.Value
err = SocketError.Success
' Since TCP is a stream protocol, we have to support partial sends. To do this, we
' will just loop until we send all the data or an exception is generated.
While buffer.Offset <> buffer.Size
Dim sent As Integer = ag_socket.Send(buffer.Buffer, buffer.Offset, buffer.Size - buffer.Offset, SocketFlags.None, err)
If err <> SocketError.Success Then
If err <> SocketError.WouldBlock Then
' Console.WriteLine("Error: Send returned error code {0}.", err);
Exit While
End If
End If
buffer.Offset += sent
Thread.Sleep(1)
End While
' We need to check for an error to break out of the foreach loop
If err <> SocketError.Success Then
Exit For
End If
Dim packet_bytes As Byte() = packet.GetBytes()
' Debug (logical packet)
'Console.WriteLine("*** Logical ***");
' If we should be ping'ing, we can reset the ping timer
Main.LogPacket("[C->S][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", packet.Opcode, packet_bytes.Length, If(packet.Encrypted, "[Encrypted]", ""), If(packet.Massive, "[Massive]", ""), Environment.NewLine, _
Utility.HexDump(packet_bytes), Environment.NewLine)
Next
' We need to check for an error to break out of the main loop
If err <> SocketError.Success Then
Exit While
End If
End If
Thread.Sleep(1)
End While
End Sub
Public Shared Sub Send(ByVal packet As Packet)
ag_security.Send(packet)
End Sub
End Class[code]
You just have to edit versiondata, from both threads, and start the proxy. Like this:
Dim gw As New Gateway()
gw.Start(ip, "15779")
|
|
|
09/30/2012, 20:49
|
#3
|
elite*gold: 0
Join Date: Apr 2009
Posts: 120
Received Thanks: 17
|
that's not what i meant, im having trouble to connect to the remote server:
"No connection could be made because the target machine actively refused it 69.64.58.191:15779"
|
|
|
09/30/2012, 21:30
|
#4
|
elite*gold: 166
Join Date: Apr 2009
Posts: 2,339
Received Thanks: 2,661
|
Quote:
Originally Posted by supermando
that's not what i meant, im having trouble to connect to the remote server:
"No connection could be made because the target machine actively refused it 69.64.58.191:15779"
|

Creddy pvp login port is 7100, not 15779.
|
|
|
09/30/2012, 21:45
|
#5
|
elite*gold: 0
Join Date: Apr 2009
Posts: 120
Received Thanks: 17
|
strange because the pk2 said 15779 
doesn't work anyway xD
|
|
|
09/30/2012, 21:49
|
#6
|
elite*gold: 166
Join Date: Apr 2009
Posts: 2,339
Received Thanks: 2,661
|
Quote:
Originally Posted by supermando
strange because the pk2 said 15779 
|
Creddy pk2 is like a maze
|
|
|
10/02/2012, 15:02
|
#7
|
elite*gold: 0
Join Date: Apr 2009
Posts: 120
Received Thanks: 17
|
I tried connecting to another blackrogue based server today (esro), it worked fine. Connecting to creddy still fails though.
|
|
|
 |
Similar Threads
|
[C#] Login Packet - Silkroad Security by drew
10/15/2012 - SRO Coding Corner - 5 Replies
hey i am using Drew's Silkroad Security to make a packet based login.( i extend his simple_proxy example)
So i made a new gui with a button. the func of the button is:
Packet p = new Packet(0x6102);
p.WriteUInt8(18);//Locale
p.WriteAscii(ID);
p.WriteAscii(PW);
p.WriteUInt16(11);//ServerID?
Program.gw_remote_security.Send(p);
|
How to build .pk2 File by Drew's Benton Tools?
02/27/2012 - SRO Private Server - 3 Replies
I have Drew's Benton pk2 tools and there is aplication called Builder.exe witch should build new .pk2 file from Files in one folder, but how to use it?
I know i should enter patch to file for e.g. C:\Desktop\Data "Data" 0 , but when i start Builder.exe i can't write there anything, and after 3 sec there show up message " Press Any Key to Continue" i press key and then Builder.exe just close, and i can't do anything. So how i should write there something?
|
Drew's 10$ Ijji Card Giveaway!
03/21/2010 - GunZ - 3 Replies
Alright, well I just started off my youtube channel and to start promoting it and getting some subscribers and whatnot, I'm going to be giving away some free stuff.
Right now, I have several ijji cards, so I'm just going to be giving away those for now.
I will move up to bigger and better giveaways later on in the future when my channel has grown and whatnot.
Anyways, here's my first video.
YouTube - Drew's 10$ Ijji Card Giveaway!
|
All times are GMT +1. The time now is 12:13.
|
|