elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  Pseudosockets PHP+VBS - (alternativa a socket server PHP VBScript)
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Pseudosockets PHP+VBS - (alternativa a socket server PHP VBScript)  (Leído 1,855 veces)
John1Connor

Desconectado Desconectado

Mensajes: 11


El que no dice la verdad, es porque esta mintiendo


Ver Perfil
Pseudosockets PHP+VBS - (alternativa a socket server PHP VBScript)
« en: 22 Junio 2015, 23:50 pm »

Código:
#include <iostream>

int main()
{
  std::cout << "Buenas foro!";
}
en mi tiempo libre , a modo de hobby programo juegos 2d en VBS+HTA y hace poco quise volver a hacer uno con sockets y me encontre con que desde windows 7 en adelante la cosa de los sockets se complica. Y pense hago un "socket server" y para que sea online y gratuito hice una simple base de datos en un server gratuito y un script php que se encarga de leer y actualizar en la base de datos las posiciones y estados de todos los elementos del juego.
 en fin. nada del otro mundo pero una solucion rapida para los que quieren un atajo bastante ineficiente pero mucho mucho mas corto  :P


index.php

Código:
<HTML>
<HEAD>
<TITLE>Servidor - Pseudo Socket by JohnConnor</TITLE>
</HEAD>
<BODY>
<?
$con = mysqli_connect("mysql.h********.com.ar","usuario_data","*******");
mysqli_select_db($con,"basededatos_sisdb");
$conexión = $_GET['tc'];
If ($conexión == "crear") {
$ns = $_GET['ns'];
$ds = $_GET['ds'];
mysqli_query($con,"insert into servidores (servername,dataserver,dataclient) values ('$ns','$ds','vacio')");
}
If ($conexión == "jugador1") {
$idserver = $_GET['sid'];
$ds = $_GET['ds'];
$result = mysqli_query($con,"Update servidores Set dataserver='$ds' Where id='$idserver'");
mysqli_query($con,$result);
$result2 = mysqli_query($con,"SELECT *
FROM  `servidores`
WHERE  `id` = ".$idserver."
LIMIT 1");
while($row = mysqli_fetch_array($result2)) {
echo $idserver;
echo "@";
echo $row[servername];
echo "@";
echo $row[dataserver];
echo "@";
echo $row[dataclient];
}
}
If ($conexión == "jugador2") {
$idserver = $_GET['sid'];
$dc = $_GET['dc'];
$resultdc = mysqli_query($con,"Update servidores Set dataclient='$dc' Where id='$idserver'");
mysqli_query($con,$resultdc);
$result2dc = mysqli_query($con,"SELECT *
FROM  `servidores`
WHERE  `id` = ".$idserver."
LIMIT 1");
while($row = mysqli_fetch_array($result2dc)) {
echo $idserver;
echo "@";
echo $row[servername];
echo "@";
echo $row[dataserver];
echo "@";
echo $row[dataclient];
}
}
If ($conexión == "spectator") {
$idserver = $_GET['sid'];
$resultsp = mysqli_query($con,"SELECT *
FROM  `servidores`
WHERE  `id` = ".$idserver."
LIMIT 1");
while($row = mysqli_fetch_array($resultsp)) {
echo $idserver;
echo "@";
echo $row[servername];
echo "@";
echo $row[dataserver];
echo "@";
echo $row[dataclient];
}
}




mysqli_close($con);
?>
</BODY>
</HTML>



Server VBS (a modo de demostración)

Código
  1. <HTML>
  2.  
  3. <HEAD>
  4.   <TITLE>JugadorUno Socket_Server by JohnConnor</TITLE>
  5.  
  6.   <HTA:APPLICATION
  7.   ID = "JCApp"
  8.   APPLICATIONNAME = "JugadorUno Socket_Server by JohnConnor"
  9.   BORDER = "thick"
  10.   CAPTION = "yes"
  11.   ICON = "app.ico"
  12.   SHOWINTASKBAR = "yes"
  13.   SINGLEINSTANCE = "yes"
  14.   SYSMENU = "yes"
  15.   WINDOWSTATE = "normal"
  16.   SCROLL = "yes"
  17.   SCROLLFLAT = "yes"
  18.   VERSION = "1.0"
  19.   INNERBORDER = "yes"
  20.   SELECTION = "no"
  21.   MAXIMIZEBUTTON = "yes"
  22.   MINIMIZEBUTTON = "yes"
  23.   NAVIGABLE = "yes"
  24.   CONTEXTMENU = "yes"
  25.   BORDERSTYLE = "normal"
  26.   >
  27. </HEAD>
  28.  
  29. <BODY>
  30.  <DIV id="pos">0</div>
  31. <img src="ju.png" id="jugadoruno">
  32.  
  33. <img src="jd.png" id="jugadordos">
  34. </BODY>
  35.  
  36. </HTML>
  37. <SCRIPT LANGUAGE="VBScript">
  38. Dim Socket
  39. Set Socket = CreateObject("MSXML2.XMLHTTP")
  40.  
  41. Dim TeclaW
  42. Dim TeclaS
  43. Dim TeclaA
  44. Dim TeclaD
  45. Dim JUposX
  46. Dim JUposY
  47. Dim JDposX
  48. Dim JDposY
  49. jugadoruno.Style.Position = "Absolute"
  50. jugadordos.Style.Position = "Absolute"
  51.  
  52. Public Sub Window_OnLoad()
  53. Self.ResizeTo 800,600
  54. Call SocketServer()
  55. Call Main()
  56. End Sub
  57.  
  58. Public Sub Main()
  59. On Error Resume Next
  60. jugadoruno.style.top = cint(JUposY)
  61. jugadoruno.style.left = cint(JUposX)
  62. jugadordos.style.top = cint(JDposY)
  63. jugadordos.style.left = cint(JDposX)
  64. If TeclaW = 1 Then : Call juMovY(-5) : ENd If
  65. If TeclaS = 1 Then : Call juMovY(5) : End If
  66. If TeclaA = 1 Then : Call juMovX(-5) : End If
  67. If TeclaD = 1 Then : Call juMovX(5) : End If
  68. Tiempo = Window.SetTimeOut("Main()",27)
  69. End Sub
  70.  
  71.  
  72. Public Sub juMovX(mov)
  73. JUposX = JuposX + cInt(mov)
  74. End Sub
  75. Public Sub juMovY(mov)
  76. JUposY = JuposY + cInt(mov)
  77. End Sub
  78.  
  79.  
  80.  
  81. Public Sub Document_OnKeyPress
  82. If Window.Event.KeyCode = "119"  Or Window.Event.KeyCode = "87"  Then : TeclaW = 1 : End If
  83. If Window.Event.KeyCode = "115"  Or Window.Event.KeyCode = "83"  Then : TeclaS = 1 : End If
  84. If Window.Event.KeyCode = "97"  Or Window.Event.KeyCode = "65"  Then : TeclaA = 1 : End If
  85. If Window.Event.KeyCode = "100"  Or Window.Event.KeyCode = "68"  Then : TeclaD = 1 : End If
  86. End Sub
  87. Public Sub Document_OnKeyUp
  88. If Window.Event.KeyCode = "87" Then : TeclaW = 0 : End If
  89. If Window.Event.KeyCode = "83" Then : TeclaS = 0 :  End If
  90. If Window.Event.KeyCode = "65" Then : TeclaA = 0 : End If
  91. If Window.Event.KeyCode = "68" Then : TeclaD = 0 : End If
  92. End Sub
  93.  
  94.  
  95. Public Sub SocketServer()
  96. Socket.Open "GET", "http://spaceinvaders2.hol.es/?sid=2&tc=jugador1&ds=" & JuposX & ":" & JUposY , False
  97. Socket.Send
  98. A_JUPOS = Split(Socket.ResponseText,"@")
  99. B_JUPOS = Split(A_JUPOS(3),":")
  100. JDposX = B_JUPOS(0)
  101. JDposYa = Split(B_JUPOS(1),"<")
  102. JDposY = JDposYa(0)
  103. pos.innerhtml = JDposX & " - " & JDposY
  104. TiempoS = Window.SetTimeOut("SocketServer()",500)
  105. End Sub
  106.  
  107. </SCRIPT>
  108.  
  109.  




y por utlimo el cliente:

Código
  1. <HTML>
  2.  
  3. <HEAD>
  4.   <TITLE>JugadorDos Socket_Client by JohnConnor</TITLE>
  5.  
  6.   <HTA:APPLICATION
  7.   ID = "JCApp"
  8.   APPLICATIONNAME = "JugadorDos Socket_Client by JohnConnor"
  9.   BORDER = "thick"
  10.   CAPTION = "yes"
  11.   ICON = "app.ico"
  12.   SHOWINTASKBAR = "yes"
  13.   SINGLEINSTANCE = "yes"
  14.   SYSMENU = "yes"
  15.   WINDOWSTATE = "normal"
  16.   SCROLL = "yes"
  17.   SCROLLFLAT = "yes"
  18.   VERSION = "1.0"
  19.   INNERBORDER = "yes"
  20.   SELECTION = "no"
  21.   MAXIMIZEBUTTON = "yes"
  22.   MINIMIZEBUTTON = "yes"
  23.   NAVIGABLE = "yes"
  24.   CONTEXTMENU = "yes"
  25.   BORDERSTYLE = "normal"
  26.   >
  27. </HEAD>
  28.  
  29. <BODY>
  30. <img src="ju.png" id="jugadoruno">
  31.  
  32. <img src="jd.png" id="jugadordos">
  33. </BODY>
  34.  
  35. </HTML>
  36. <SCRIPT LANGUAGE="VBScript">
  37. Dim Socket
  38. Set Socket = CreateObject("MSXML2.XMLHTTP")
  39.  
  40. Dim TeclaW
  41. Dim TeclaS
  42. Dim TeclaA
  43. Dim TeclaD
  44. Dim JUposX
  45. Dim JUposY
  46. Dim JDposX
  47. Dim JDposY
  48. jugadoruno.Style.Position = "Absolute"
  49. jugadordos.Style.Position = "Absolute"
  50.  
  51. Public Sub Window_OnLoad()
  52. Self.ResizeTo 800,600
  53. Call SocketServer()
  54. Call Main()
  55. End Sub
  56.  
  57. Public Sub Main()
  58. On Error Resume Next
  59. jugadordos.style.top = cint(JUposY)
  60. jugadordos.style.left = cint(JUposX)
  61.  
  62. If TeclaW = 1 Then : Call juMovY(-5) : ENd If
  63. If TeclaS = 1 Then : Call juMovY(5) : End If
  64. If TeclaA = 1 Then : Call juMovX(-5) : End If
  65. If TeclaD = 1 Then : Call juMovX(5) : End If
  66. Tiempo = Window.SetTimeOut("Main()",27)
  67. End Sub
  68.  
  69.  
  70. Public Sub juMovX(mov)
  71. JUposX = JuposX + cInt(mov)
  72. End Sub
  73. Public Sub juMovY(mov)
  74. JUposY = JuposY + cInt(mov)
  75. End Sub
  76.  
  77.  
  78.  
  79. Public Sub Document_OnKeyPress
  80. If Window.Event.KeyCode = "119"  Or Window.Event.KeyCode = "87"  Then : TeclaW = 1 : End If
  81. If Window.Event.KeyCode = "115"  Or Window.Event.KeyCode = "83"  Then : TeclaS = 1 : End If
  82. If Window.Event.KeyCode = "97"  Or Window.Event.KeyCode = "65"  Then : TeclaA = 1 : End If
  83. If Window.Event.KeyCode = "100"  Or Window.Event.KeyCode = "68"  Then : TeclaD = 1 : End If
  84. End Sub
  85. Public Sub Document_OnKeyUp
  86. If Window.Event.KeyCode = "87" Then : TeclaW = 0 : End If
  87. If Window.Event.KeyCode = "83" Then : TeclaS = 0 :  End If
  88. If Window.Event.KeyCode = "65" Then : TeclaA = 0 : End If
  89. If Window.Event.KeyCode = "68" Then : TeclaD = 0 : End If
  90. End Sub
  91.  
  92.  
  93. Public Sub SocketServer()
  94. Socket.Open "GET", "http://spaceinvaders2.hol.es/?sid=2&tc=jugador2&dc=" & JuposX & ":" & JUposY , False
  95. Socket.Send
  96. A_JUPOS = Split(Socket.ResponseText,"@")
  97. B_JUPOS = Split(A_JUPOS(2),":")
  98. JDposX = B_JUPOS(0)
  99. JDposY = B_JUPOS(1)
  100. On Error Resume Next
  101. jugadoruno.style.top = cint(JDposY)
  102. jugadoruno.style.left = cint(JDposX)
  103. TiempoS = Window.SetTimeOut("SocketServer()",500)
  104. End Sub
  105.  
  106. </SCRIPT>




Aclaro que es una demostracion simplemente porque solo se mueven dos jugadores por una ventana, y solo se actualiza al pular una tecla.


Bueno, como ven no soy bueno explicando pero cualquier duda concreta que tengan o ayuda que necesiten comenten. Saludos


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Cliente-Server (Socket) « 1 2 »
Programación Visual Basic
ZiroViI 10 4,512 Último mensaje 25 Octubre 2008, 22:34 pm
por ZiroViI
389 Directory Server: Alternativa libre al Active Directory de Microsoft
Noticias
nicolas_cof 0 2,815 Último mensaje 16 Junio 2010, 04:19 am
por nicolas_cof
Socket c++ server y navegador web (chrome)...
Programación C/C++
shiro51 6 5,804 Último mensaje 18 Abril 2012, 14:51 pm
por shiro51
problema server socket thread
Java
momo1234 1 2,829 Último mensaje 12 Mayo 2012, 17:20 pm
por momo1234
VBScript: Angry Birds Pong in VBScript [HTA + VBS] (100% Notepad) by JohnConnor
Scripting
JohnConnor 1 4,850 Último mensaje 4 Marzo 2013, 23:34 pm
por dato000
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines