Bueno uno de mis aportes mientras aprendo en el cual solicito a mejores programadores que me digan si cometi errores o si se puede mejorar... gracias.
Se que funciona porque lo probe de mil maneras incluso editando los datos de los paquetes para abusar del sistema y como valido bien en el servidor, no deja hacerlo.
También se puede transferir así ... /TRANSFERIRORO [email protected] (Y por boton en el tirar oro).
Comenzamos....
CLIENTE
Vamos a buscar el formulario "frmCantidad" y adentro le vamos a dibujar agrandando el espacio del mismo... los siguientes componentes.
Un TextBox llamado "txtNombre" y un Label llamado "btnTransferirOro"
Le damos doble click al btnTransferirOro y así debe quedar el Private Sub...
En el "ClientPacketID" tenemos que declarar lo siguiente dentro....
Pueden hacerlo antes del "End Enum" y esto hay que respetar su orden en el servidor tmb, respetando el orden obviamente.
Luego en el ProtocolCmdParse hay que agregar abajo del case donde se declaro...
y por último en el modulo "Protocol" agregamos abajo del write correspondiente al orden que pusimos...
AHORA AL SERVIDOR
Ahora identificamos donde declaramos la variable en el "ClientPacketID" del cliente y en el servidor respetamos el orden y agregamos ...
Luego tenemos que declarar el CASE en el modulo Protocol
Y por último abajo del handle donde estamos basandonos al ordenar los paquetes enviados y recibidos agregamos.....
En modulo Protocol también...
Por favor, vean si me falto algo, aunque se que funciona correctamente sin errores.
Cambien el "FONTTYPE_CENTINELA" a su gusto.
Saludos!
Espero que les sea de utilidad, se que lo habia aportado Lauti de DSAO pero éste lo hice independiente a su método, tiene cosas similares pero es diferente.
Se que funciona porque lo probe de mil maneras incluso editando los datos de los paquetes para abusar del sistema y como valido bien en el servidor, no deja hacerlo.
También se puede transferir así ... /TRANSFERIRORO [email protected] (Y por boton en el tirar oro).
Comenzamos....
CLIENTE
Vamos a buscar el formulario "frmCantidad" y adentro le vamos a dibujar agrandando el espacio del mismo... los siguientes componentes.
Un TextBox llamado "txtNombre" y un Label llamado "btnTransferirOro"
Le damos doble click al btnTransferirOro y así debe quedar el Private Sub...
Código:
Private Sub btnTransferirOro_Click()
Call Audio.PlayWave(SND_CLICK)
If LenB(txtCantidad.Text) > 0 Then
If Not IsNumeric(txtCantidad.Text) Then Exit Sub 'Should never happen
Call WriteTransferirOro(frmCantidad.txtNombre.Text, frmCantidad.txtCantidad.Text)
frmCantidad.txtCantidad.Text = ""
frmCantidad.txtNombre.Text = ""
End If
Unload Me
End Sub
En el "ClientPacketID" tenemos que declarar lo siguiente dentro....
Pueden hacerlo antes del "End Enum" y esto hay que respetar su orden en el servidor tmb, respetando el orden obviamente.
Luego en el ProtocolCmdParse hay que agregar abajo del case donde se declaro...
Código:
Case "/TRANSFERIRORO"
If notNullArguments Then
tmpArr = Split(ArgumentosRaw, "@", 2)
If UBound(tmpArr) = 1 Then
If ValidNumber(tmpArr(1), eNumber_Types.ent_Long) Then
Call WriteTransferirOro(tmpArr(0), tmpArr(1))
Else
'Faltan o sobran los parametros con el formato propio
Call ShowConsoleMsg("Formato incorrecto. Utilice /TRANSFERIRORO [email protected]")
End If
Else
'Faltan o sobran los parametros con el formato propio
Call ShowConsoleMsg("Formato incorrecto. Utilice /TRANSFERIRORO [email protected]")
End If
Else
'Faltan los parametros con el formato propio
Call ShowConsoleMsg("Formato incorrecto. Utilice /TRANSFERIRORO [email protected]")
End If
y por último en el modulo "Protocol" agregamos abajo del write correspondiente al orden que pusimos...
Código:
Public Sub WriteTransferirOro(ByVal Nombre As String, ByVal cantidad As Long)
With outgoingData
Call .WriteByte(ClientPacketID.TransferirOro)
Call .WriteASCIIString(Nombre)
Call .WriteLong(cantidad)
End With
End Sub
AHORA AL SERVIDOR
Ahora identificamos donde declaramos la variable en el "ClientPacketID" del cliente y en el servidor respetamos el orden y agregamos ...
Luego tenemos que declarar el CASE en el modulo Protocol
Código:
Case ClientPacketID.TransferirOro 'Transferiroro [email protected]
Call HandleTransferirOro(UserIndex)
Y por último abajo del handle donde estamos basandonos al ordenar los paquetes enviados y recibidos agregamos.....
En modulo Protocol también...
Código:
Public Sub HandleTransferirOro(ByVal UserIndex As Integer)
If UserList(UserIndex).incomingData.length < 7 Then
Err.Raise UserList(UserIndex).incomingData.NotEnoughDataErrCode
Exit Sub
End If
On Error GoTo Errhandler
With UserList(UserIndex)
'This packet contains strings, make a copy of the data to prevent losses if it's not complete yet...
Dim buffer As New clsByteQueue
Call buffer.CopyBuffer(.incomingData)
'Remove packet ID
Call buffer.ReadByte
Dim nombreDestino As String
Dim cantidadOro As Long
Dim idUserDestino As Integer
Dim rutaPath As String
Dim oroBancoDestino As Long
nombreDestino = buffer.ReadASCIIString()
cantidadOro = buffer.ReadLong()
'solo para usuarios...
If .Flags.Privilegios And (PlayerType.Consejero Or PlayerType.SemiDios Or PlayerType.Dios Or PlayerType.Admin) Then
Call .incomingData.CopyBuffer(buffer)
Set buffer = Nothing
Exit Sub
End If
'estas muerto?
If .Flags.Muerto = 1 Then
Call WriteConsoleMsg(UserIndex, "¡No puedes transferir oro estando muerto!", FontTypeNames.FONTTYPE_CENTINELA)
Call .incomingData.CopyBuffer(buffer)
Set buffer = Nothing
Exit Sub
End If
'¿Me queres alterar el campo fracasado? jaja
If cantidadOro <= 0 Then
cantidadOro = 0
End If
'Estas en un Mapa Seguro?
If MapInfo(.Pos.map).Pk = True Then
Call WriteConsoleMsg(UserIndex, "¡Debes estar en un mapa seguro para transferir oro!", FontTypeNames.FONTTYPE_CENTINELA)
Call .incomingData.CopyBuffer(buffer)
Set buffer = Nothing
Exit Sub
End If
If .Stats.GLD = 0 Then
Call WriteConsoleMsg(UserIndex, "¡No puedes transferir oro si no tienes!", FontTypeNames.FONTTYPE_CENTINELA)
Call .incomingData.CopyBuffer(buffer)
Set buffer = Nothing
Exit Sub
End If
'Verificamos que no nos editen el oro
If .Stats.GLD < cantidadOro Then
Call WriteConsoleMsg(UserIndex, "¡No tienes el oro que deseas mandar!", FontTypeNames.FONTTYPE_CENTINELA)
Call .incomingData.CopyBuffer(buffer)
Set buffer = Nothing
Exit Sub
End If
'tiene campos vacios?
If nombreDestino = "" Or cantidadOro = 0 Then
Call WriteConsoleMsg(UserIndex, "Los valores no deben ser nulos ni 0.", FontTypeNames.FONTTYPE_CENTINELA)
Call .incomingData.CopyBuffer(buffer)
Set buffer = Nothing
Exit Sub
End If
'Obtenemos el usuario
idUserDestino = NameIndex(nombreDestino)
rutaPath = CharPath & nombreDestino & ".chr"
'Veamos si el destinatario existe..
If PersonajeExiste(nombreDestino) Then
If idUserDestino = UserIndex Then
Call WriteConsoleMsg(UserIndex, "¡¡No puedes mandarte oro a vos mismo!!, sal de Artemis y consigue amigos, que puedan prestarte dinero.", FontTypeNames.FONTTYPE_CENTINELA)
Call .incomingData.CopyBuffer(buffer)
Set buffer = Nothing
Exit Sub
Else
'El personaje destinatario está offline
If idUserDestino <= 0 Then
oroBancoDestino = GetVar(CharPath & nombreDestino & ".chr", "STATS", "BANCO")
Call WriteVar(rutaPath, "STATS", "BANCO", oroBancoDestino + val(cantidadOro))
Call WriteConsoleMsg(UserIndex, "El destino se encuentra offline, igual se tranfirio a su banco " & cantidadOro & " monedas de oro.", FontTypeNames.FONTTYPE_INFO)
.Stats.GLD = .Stats.GLD - cantidadOro
Call WriteUpdateGold(UserIndex)
Else
UserList(idUserDestino).Stats.GLD = UserList(idUserDestino).Stats.GLD + cantidadOro
.Stats.GLD = .Stats.GLD - cantidadOro
Call WriteUpdateGold(UserIndex)
Call WriteUpdateGold(idUserDestino)
Call WriteConsoleMsg(UserIndex, "Le has transferido " & cantidadOro & " monedas de oro a " & UserList(idUserDestino).Name & ".", FontTypeNames.FONTTYPE_INFO)
Call WriteConsoleMsg(idUserDestino, "" & .Name & " te ha transferido " & cantidadOro & " monedas De oro .", FontTypeNames.FONTTYPE_INFO)
End If
End If
Else
Call WriteConsoleMsg(UserIndex, "El jugador destinatario no existe, verifique si ingresó el nombre correcto.", FontTypeNames.FONTTYPE_CENTINELA)
'If we got here then packet is complete, copy data back to original queue
Call .incomingData.CopyBuffer(buffer)
Set buffer = Nothing
Exit Sub
End If
'If we got here then packet is complete, copy data back to original queue
Call .incomingData.CopyBuffer(buffer)
Set buffer = Nothing
End With
Exit Sub
Errhandler:
Dim error As Long
error = Err.Number
On Error GoTo 0
'Destroy auxiliar buffer
Set buffer = Nothing
If error <> 0 Then Err.Raise error
End Sub
Por favor, vean si me falto algo, aunque se que funciona correctamente sin errores.
Cambien el "FONTTYPE_CENTINELA" a su gusto.
Saludos!
Espero que les sea de utilidad, se que lo habia aportado Lauti de DSAO pero éste lo hice independiente a su método, tiene cosas similares pero es diferente.
Última edición: